From 3590fa4d72e251a35ea493fed1bb1ede14bc2a6e Mon Sep 17 00:00:00 2001 From: Michele Date: Mon, 28 Jan 2019 13:07:30 -0800 Subject: [PATCH] Add check for slot index value Verify that slot index passed in setAllowedCarrier() and in getAllowedCarrier() has a valid value or return error code. Bug: 123097251 Test: compilation Change-Id: I322ecd11c49301a7d5bf5edb75d32a72a9f813c3 --- .../java/android/telephony/TelephonyManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index b9ffd4d21890d..e063f568588c8 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -8919,6 +8919,9 @@ public class TelephonyManager { @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setAllowedCarriers(int slotIndex, List carriers) { + if (carriers == null || !SubscriptionManager.isValidPhoneId(slotIndex)) { + return -1; + } // Execute the method setCarrierRestrictionRules with an empty excluded list and // indicating priority for the allowed list. CarrierRestrictionRules carrierRestrictionRules = CarrierRestrictionRules.newBuilder() @@ -8929,7 +8932,7 @@ public class TelephonyManager { int result = setCarrierRestrictionRules(carrierRestrictionRules); - // Convert boolean result into int, as required by this method. + // Convert result into int, as required by this method. if (result == SET_CARRIER_RESTRICTION_SUCCESS) { return carriers.size(); } else { @@ -9022,9 +9025,11 @@ public class TelephonyManager { @SystemApi @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public List getAllowedCarriers(int slotIndex) { - CarrierRestrictionRules carrierRestrictionRule = getCarrierRestrictionRules(); - if (carrierRestrictionRule != null) { - return carrierRestrictionRule.getAllowedCarriers(); + if (SubscriptionManager.isValidPhoneId(slotIndex)) { + CarrierRestrictionRules carrierRestrictionRule = getCarrierRestrictionRules(); + if (carrierRestrictionRule != null) { + return carrierRestrictionRule.getAllowedCarriers(); + } } return new ArrayList(0); }