From dc50a87495c23068b4150a0fc197e51ace2ae47b Mon Sep 17 00:00:00 2001 From: Shishir Agrawal Date: Tue, 12 Apr 2016 11:55:01 -0700 Subject: [PATCH] Fixing few TelephonyManager calls to work when there is no SIM. * getDeviceSoftwareVersion - Fixed to work for no SIM by not looking up subId. * getImei - Fixed to work for no SIM by not looking up subId. * getActivePhoneTypeForSlot - Adding a method (hidden). * getCallState - Adding slotId version (hidden). Bug: 27378995 Change-Id: Ib67ae3df5562d75727dc7e4ac023021fb331d3b5 --- .../android/telephony/TelephonyManager.java | 57 ++++++++++++------- .../internal/telephony/ITelephony.aidl | 30 ++++++++-- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 865af7821ac2f..638b286987b68 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -717,16 +717,11 @@ public class TelephonyManager { */ /** {@hide} */ public String getDeviceSoftwareVersion(int slotId) { - // FIXME methods taking slot id should not use subscription, instead us Uicc directly - int[] subId = SubscriptionManager.getSubId(slotId); - if (subId == null || subId.length == 0) { - return null; - } + ITelephony telephony = getITelephony(); + if (telephony == null) return null; + try { - IPhoneSubInfo info = getSubscriberInfo(); - if (info == null) - return null; - return info.getDeviceSvnUsingSubId(subId[0], mContext.getOpPackageName()); + return telephony.getDeviceSoftwareVersionForSlot(slotId, getOpPackageName()); } catch (RemoteException ex) { return null; } catch (NullPointerException ex) { @@ -798,12 +793,11 @@ public class TelephonyManager { */ /** {@hide} */ public String getImei(int slotId) { - int[] subId = SubscriptionManager.getSubId(slotId); + ITelephony telephony = getITelephony(); + if (telephony == null) return null; + try { - IPhoneSubInfo info = getSubscriberInfo(); - if (info == null) - return null; - return info.getImeiForSubscriber(subId[0], mContext.getOpPackageName()); + return telephony.getImeiForSlot(slotId, getOpPackageName()); } catch (RemoteException ex) { return null; } catch (NullPointerException ex) { @@ -1014,22 +1008,32 @@ public class TelephonyManager { } else { phoneId = SubscriptionManager.getPhoneId(subId); } + + return getCurrentPhoneTypeForSlot(phoneId); + } + + /** + * See getCurrentPhoneType. + * + * @hide + */ + public int getCurrentPhoneTypeForSlot(int slotId) { try{ ITelephony telephony = getITelephony(); - if (telephony != null && subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { - return telephony.getActivePhoneTypeForSubscriber(subId); + if (telephony != null) { + return telephony.getActivePhoneTypeForSlot(slotId); } else { // This can happen when the ITelephony interface is not up yet. - return getPhoneTypeFromProperty(phoneId); + return getPhoneTypeFromProperty(slotId); } } catch (RemoteException ex) { // This shouldn't happen in the normal case, as a backup we // read from the system property. - return getPhoneTypeFromProperty(phoneId); + return getPhoneTypeFromProperty(slotId); } catch (NullPointerException ex) { // This shouldn't happen in the normal case, as a backup we // read from the system property. - return getPhoneTypeFromProperty(phoneId); + return getPhoneTypeFromProperty(slotId); } } @@ -2555,20 +2559,31 @@ public class TelephonyManager { * @param subId whose call state is returned */ public int getCallState(int subId) { + int phoneId = SubscriptionManager.getPhoneId(subId); + return getCallStateForSlot(phoneId); + } + + /** + * See getCallState. + * + * @hide + */ + public int getCallStateForSlot(int slotId) { try { ITelephony telephony = getITelephony(); if (telephony == null) return CALL_STATE_IDLE; - return telephony.getCallStateForSubscriber(subId); + return telephony.getCallStateForSlot(slotId); } catch (RemoteException ex) { // the phone process is restarting. return CALL_STATE_IDLE; } catch (NullPointerException ex) { // the phone process is restarting. return CALL_STATE_IDLE; - } + } } + /** Data connection activity: No traffic. */ public static final int DATA_ACTIVITY_NONE = 0x00000000; /** Data connection activity: Currently receiving IP PPP traffic. */ diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 2727319ad0a62..b41d361f6a16f 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -360,9 +360,9 @@ interface ITelephony { int getCallState(); /** - * Returns the call state for a subId. + * Returns the call state for a slot. */ - int getCallStateForSubscriber(int subId); + int getCallStateForSlot(int slotId); int getDataActivity(); int getDataState(); @@ -375,12 +375,12 @@ interface ITelephony { int getActivePhoneType(); /** - * Returns the current active phone type as integer for particular subId. + * Returns the current active phone type as integer for particular slot. * Returns TelephonyManager.PHONE_TYPE_CDMA if RILConstants.CDMA_PHONE * and TelephonyManager.PHONE_TYPE_GSM if RILConstants.GSM_PHONE - * @param subId user preferred subId. + * @param slotId - slot to query. */ - int getActivePhoneTypeForSubscriber(int subId); + int getActivePhoneTypeForSlot(int slotId); /** * Returns the CDMA ERI icon index to display @@ -991,6 +991,26 @@ interface ITelephony { */ String getDeviceId(String callingPackage); + /** + * Returns the IMEI for the given slot. + * + * @param slotId - device slot. + * @param callingPackage The package making the call. + *

Requires Permission: + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + */ + String getImeiForSlot(int slotId, String callingPackage); + + /** + * Returns the device software version. + * + * @param slotId - device slot. + * @param callingPackage The package making the call. + *

Requires Permission: + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + */ + String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage); + /** * Returns the subscription ID associated with the specified PhoneAccount. */