From e161df7fb2a2eab1516a0d3681e86b7afdf2d94a Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 8 Dec 2022 00:14:04 -0800 Subject: [PATCH] Migrate getSimStateForSlotIndex to TelephonyManager Most of the SIM APIs are in TelephonyManager. SubscriptionManager handles subscription related information only. Test: Manual Bug: 239607619 Change-Id: If654ac4ef65b5be3cda99cbfd8694e4027fd4d65 --- .../telephony/SubscriptionManager.java | 31 -------------- .../android/telephony/TelephonyManager.java | 40 ++++++++++++++----- .../com/android/internal/telephony/ISub.aidl | 5 --- .../internal/telephony/ITelephony.aidl | 9 ++++- 4 files changed, 38 insertions(+), 47 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 5244f415e8e23..8107a849ced84 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -2604,37 +2604,6 @@ public class SubscriptionManager { return TelephonyManager.getDefault().isNetworkRoaming(subId); } - /** - * Returns a constant indicating the state of sim for the slot index. - * - * @param slotIndex - * - * {@See TelephonyManager#SIM_STATE_UNKNOWN} - * {@See TelephonyManager#SIM_STATE_ABSENT} - * {@See TelephonyManager#SIM_STATE_PIN_REQUIRED} - * {@See TelephonyManager#SIM_STATE_PUK_REQUIRED} - * {@See TelephonyManager#SIM_STATE_NETWORK_LOCKED} - * {@See TelephonyManager#SIM_STATE_READY} - * {@See TelephonyManager#SIM_STATE_NOT_READY} - * {@See TelephonyManager#SIM_STATE_PERM_DISABLED} - * {@See TelephonyManager#SIM_STATE_CARD_IO_ERROR} - * - * {@hide} - */ - public static int getSimStateForSlotIndex(int slotIndex) { - int simState = TelephonyManager.SIM_STATE_UNKNOWN; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - simState = iSub.getSimStateForSlotIndex(slotIndex); - } - } catch (RemoteException ex) { - } - - return simState; - } - /** * Store properties associated with SubscriptionInfo in database * @param subId Subscription Id of Subscription diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 3024b896d1cfa..851697a0f25d1 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -71,7 +71,6 @@ import android.os.PersistableBundle; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.SystemProperties; -import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings.SettingNotFoundException; import android.service.carrier.CarrierIdentifier; @@ -127,7 +126,6 @@ import com.android.internal.telephony.IccLogicalChannelRequest; import com.android.internal.telephony.OperatorInfo; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RILConstants; -import com.android.internal.telephony.SmsApplication; import com.android.telephony.Rlog; import java.io.IOException; @@ -3558,7 +3556,7 @@ public class TelephonyManager { "state as absent"); return SIM_STATE_ABSENT; } - return SubscriptionManager.getSimStateForSlotIndex(slotIndex); + return getSimStateForSlotIndex(slotIndex); } /** @@ -3705,9 +3703,7 @@ public class TelephonyManager { @Deprecated public @SimState int getSimApplicationState(int physicalSlotIndex) { int activePort = getFirstActivePortIndex(physicalSlotIndex); - int simState = - SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, - activePort)); + int simState = getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, activePort)); return getSimApplicationStateFromSimState(simState); } @@ -3733,9 +3729,7 @@ public class TelephonyManager { @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) public @SimState int getSimApplicationState(int physicalSlotIndex, int portIndex) { - int simState = - SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, - portIndex)); + int simState = getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, portIndex)); return getSimApplicationStateFromSimState(simState); } @@ -3804,7 +3798,7 @@ public class TelephonyManager { */ @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) public @SimState int getSimState(int slotIndex) { - int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); + int simState = getSimStateForSlotIndex(slotIndex); if (simState == SIM_STATE_LOADED) { simState = SIM_STATE_READY; } @@ -17747,4 +17741,30 @@ public class TelephonyManager { } return null; } + + /** + * Returns a constant indicating the state of sim for the slot index. + * + * @param slotIndex Logical SIM slot index. + * + * @see TelephonyManager.SimState + * + * @hide + */ + @SimState + public static int getSimStateForSlotIndex(int slotIndex) { + try { + ITelephony telephony = ITelephony.Stub.asInterface( + TelephonyFrameworkInitializer + .getTelephonyServiceManager() + .getTelephonyServiceRegisterer() + .get()); + if (telephony != null) { + return telephony.getSimStateForSlotIndex(slotIndex); + } + } catch (RemoteException e) { + Log.e(TAG, "Error in getSimStateForSlotIndex: " + e); + } + return TelephonyManager.SIM_STATE_UNKNOWN; + } } diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index e9cea6843a829..280d259502281 100644 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -274,11 +274,6 @@ interface ISub { boolean isSubscriptionEnabled(int subId); int getEnabledSubscriptionId(int slotIndex); - /** - * Get the SIM state for the slot index - * @return SIM state as the ordinal of IccCardConstants.State - */ - int getSimStateForSlotIndex(int slotIndex); boolean isActiveSubId(int subId, String callingPackage, String callingFeatureId); diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 616ea50e4185f..7ede4abd1dc2e 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2628,5 +2628,12 @@ interface ITelephony { * {@code null} if the functionality is not supported. * @hide */ - ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded); + ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded); + + /** + * Get the SIM state for the logical SIM slot index. + * + * @param slotIndex Logical SIM slot index. + */ + int getSimStateForSlotIndex(int slotIndex); }