SupportLeanbackDemos: Fixed password crash when no payment is selected

The second Guided Step fragment crashed when a password was entered but
no credit card info was selected, because it was trying to extract "Visa"
or "Master" substrings from an empty string. Put a check for string
sizes before this extraction is performed.

Change-Id: I9b93a302f5f855b1853885ff4e5fc9a04c200766
This commit is contained in:
Keyvan Amiri
2016-02-10 12:35:48 -08:00
parent 64cae78d53
commit be98b3af70
2 changed files with 8 additions and 4 deletions

View File

@@ -420,8 +420,10 @@ public class GuidedStepActivity extends Activity {
boolean isPaymentValid() { boolean isPaymentValid() {
CharSequence paymentType = findActionById(PAYMENT).getDescription(); CharSequence paymentType = findActionById(PAYMENT).getDescription();
return paymentType.subSequence(0, 4).toString().equals("Visa") || return (paymentType.length() >= 4 &&
paymentType.subSequence(0, 6).toString().equals("Master"); paymentType.subSequence(0, 4).toString().equals("Visa")) ||
(paymentType.length() >= 6 &&
paymentType.subSequence(0, 6).toString().equals("Master"));
} }
boolean isPasswordValid() { boolean isPasswordValid() {

View File

@@ -422,8 +422,10 @@ public class GuidedStepSupportActivity extends FragmentActivity {
boolean isPaymentValid() { boolean isPaymentValid() {
CharSequence paymentType = findActionById(PAYMENT).getDescription(); CharSequence paymentType = findActionById(PAYMENT).getDescription();
return paymentType.subSequence(0, 4).toString().equals("Visa") || return (paymentType.length() >= 4 &&
paymentType.subSequence(0, 6).toString().equals("Master"); paymentType.subSequence(0, 4).toString().equals("Visa")) ||
(paymentType.length() >= 6 &&
paymentType.subSequence(0, 6).toString().equals("Master"));
} }
boolean isPasswordValid() { boolean isPasswordValid() {