From b78890c159f9f06617712261e6c9f284841f2357 Mon Sep 17 00:00:00 2001 From: Anthony Lee Date: Thu, 11 Sep 2014 09:21:38 -0700 Subject: isValidSlotId() and isValidPhoneId() updated to handle negatives. The old version of the code wanted to just check to make sure that the slot/phone id is greater than INVALID_SLOT_ID or INVALID_PHONE_ID that are both currently defined to be -1000. The changes are made for 2 reasons. First, INVALID_SLOT_ID and/or INVALID_PHONE_ID might not always be defined to be a negative value so there is a big assumption. Secondly, anything greater than -1000 allows other negative values to be considered valid ids. Bug: 17243556 Change-Id: I2bbfcc2cfd2d7c4772dfb9c50af2dc88c0f315e2 --- telephony/java/android/telephony/SubscriptionManager.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'telephony') diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index d0f355e..fe68263 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -930,13 +930,20 @@ public class SubscriptionManager implements BaseColumns { /** @hide */ public static boolean isValidSlotId(int slotId) { - return slotId > INVALID_SLOT_ID && slotId < TelephonyManager.getDefault().getSimCount(); + // We are testing INVALID_SLOT_ID and slotId >= 0 independently because we should + // not assume that INVALID_SLOT_ID will always be a negative value. Any negative + // value is invalid. + return slotId != INVALID_SLOT_ID && slotId >= 0 && + slotId < TelephonyManager.getDefault().getSimCount(); } /** @hide */ public static boolean isValidPhoneId(int phoneId) { - return phoneId > INVALID_PHONE_ID - && phoneId < TelephonyManager.getDefault().getPhoneCount(); + // We are testing INVALID_PHONE_ID and phoneId >= 0 independently because we should + // not assume that INVALID_PHONE_ID will always be a negative value. Any negative + // value is invalid. + return phoneId != INVALID_PHONE_ID && phoneId >= 0 && + phoneId < TelephonyManager.getDefault().getPhoneCount(); } /** @hide */ -- cgit v1.1