From 5def2c6004ad7855de6258c14917b68e46cde676 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 8 Nov 2019 09:56:02 -0800 Subject: [PATCH] Throw illegal argument exception when slot index is invalid Test: Manual Bug: 144097779 Merged-In: I5c5c4eb313fd42317a2b0feed0946b8e4003ad62 Change-Id: I5c5c4eb313fd42317a2b0feed0946b8e4003ad62 (cherry picked from commit 0d75aee571eb6a7048a618af894c41a24e8e5cbd) --- telephony/java/android/telephony/TelephonyManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 58f1e8407d13a..7232ea7141800 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2367,6 +2367,8 @@ public class TelephonyManager { * * @return the lowercase 2 character ISO-3166 country code, or empty string if not available. * + * @throws IllegalArgumentException when the slotIndex is invalid. + * * {@hide} */ @SystemApi @@ -2374,6 +2376,10 @@ public class TelephonyManager { @NonNull public String getNetworkCountryIso(int slotIndex) { try { + if (!SubscriptionManager.isValidSlotIndex(slotIndex)) { + throw new IllegalArgumentException("invalid slot index " + slotIndex); + } + ITelephony telephony = getITelephony(); if (telephony == null) return ""; return telephony.getNetworkCountryIsoForPhone(slotIndex);