From be98b3af70d0fb280dd688040b04880a9e4d543f Mon Sep 17 00:00:00 2001 From: Keyvan Amiri Date: Wed, 10 Feb 2016 12:35:48 -0800 Subject: [PATCH] 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 --- .../com/example/android/leanback/GuidedStepActivity.java | 6 ++++-- .../example/android/leanback/GuidedStepSupportActivity.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java index c4e0d0093..7436d38be 100644 --- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java @@ -420,8 +420,10 @@ public class GuidedStepActivity extends Activity { boolean isPaymentValid() { CharSequence paymentType = findActionById(PAYMENT).getDescription(); - return paymentType.subSequence(0, 4).toString().equals("Visa") || - paymentType.subSequence(0, 6).toString().equals("Master"); + return (paymentType.length() >= 4 && + paymentType.subSequence(0, 4).toString().equals("Visa")) || + (paymentType.length() >= 6 && + paymentType.subSequence(0, 6).toString().equals("Master")); } boolean isPasswordValid() { diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java index 09eed7922..189db8946 100644 --- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java +++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java @@ -422,8 +422,10 @@ public class GuidedStepSupportActivity extends FragmentActivity { boolean isPaymentValid() { CharSequence paymentType = findActionById(PAYMENT).getDescription(); - return paymentType.subSequence(0, 4).toString().equals("Visa") || - paymentType.subSequence(0, 6).toString().equals("Master"); + return (paymentType.length() >= 4 && + paymentType.subSequence(0, 4).toString().equals("Visa")) || + (paymentType.length() >= 6 && + paymentType.subSequence(0, 6).toString().equals("Master")); } boolean isPasswordValid() {