From ab57c29092eb9185375de86d82ff32e6079f5cec Mon Sep 17 00:00:00 2001 From: Shishir Agrawal Date: Tue, 18 Nov 2014 11:40:50 -0800 Subject: [PATCH] Carrierprivileges: Addressing API council suggestions. - hasCarrierPrivileges - renamed to getCarrierPrivilegeStatus - setLine1NumberForDisplay should not be usable by apps that have MODIFY_PHONE_STATE - setVoiceMailNumber should not be usable by apps that have MODIFY_PHONE_STATE - setOperatorBrandOverride should not be usable by apps that have MODIFY_PHONE_STATE Not addressed: - setGlobalPreferredNetworkType() should not be usable by apps that have MODIFY_PHONE_STATE The underlying call is needed by system apps (OMADM) too. Bug: 18356155 Change-Id: Idc6468a0bd0b0c52b9de1d8446f98c90ac0b3238 --- api/current.txt | 6 +- .../android/telephony/TelephonyManager.java | 59 +++++++++---------- .../internal/telephony/ITelephony.aidl | 2 +- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/api/current.txt b/api/current.txt index c480a1bbd196a..c6d414a5dfbf9 100644 --- a/api/current.txt +++ b/api/current.txt @@ -28689,7 +28689,7 @@ package android.telephony { method public java.lang.String getSubscriberId(); method public java.lang.String getVoiceMailAlphaTag(); method public java.lang.String getVoiceMailNumber(); - method public int hasCarrierPrivileges(); + method public boolean hasCarrierPrivileges(); method public boolean hasIccCard(); method public boolean iccCloseLogicalChannel(int); method public byte[] iccExchangeSimIO(int, int, int, int, int, java.lang.String); @@ -28709,10 +28709,6 @@ package android.telephony { field public static final int CALL_STATE_IDLE = 0; // 0x0 field public static final int CALL_STATE_OFFHOOK = 2; // 0x2 field public static final int CALL_STATE_RINGING = 1; // 0x1 - field public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; // 0xfffffffe - field public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; // 0x1 - field public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; // 0x0 - field public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; // 0xffffffff field public static final int DATA_ACTIVITY_DORMANT = 4; // 0x4 field public static final int DATA_ACTIVITY_IN = 1; // 0x1 field public static final int DATA_ACTIVITY_INOUT = 3; // 0x3 diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index f2d859fe3413b..7c03d42553f60 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -1797,10 +1797,9 @@ public class TelephonyManager { * for display purpose only, for example, displayed in Phone Status. It won't * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null * value. - *

- * Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * Or the calling app has carrier privileges. @see #hasCarrierPrivileges + * + *

Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @param alphaTag alpha-tagging of the dailing nubmer * @param number The dialing number @@ -1814,10 +1813,9 @@ public class TelephonyManager { * for display purpose only, for example, displayed in Phone Status. It won't * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null * value. - *

- * Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * Or the calling app has carrier privileges. @see #hasCarrierPrivileges + * + *

Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @param subId the subscriber that the alphatag and dialing number belongs to. * @param alphaTag alpha-tagging of the dailing nubmer @@ -1974,10 +1972,9 @@ public class TelephonyManager { /** * Sets the voice mail number. - *

- * Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * Or the calling app has carrier privileges. @see #hasCarrierPrivileges + * + *

Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @param alphaTag The alpha tag to display. * @param number The voicemail number. @@ -1988,10 +1985,9 @@ public class TelephonyManager { /** * Sets the voicemail number for the given subscriber. - *

- * Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * Or the calling app has carrier privileges. @see #hasCarrierPrivileges + * + *

Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @param subId The subscriber id. * @param alphaTag The alpha tag to display. @@ -3072,9 +3068,8 @@ public class TelephonyManager { * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. * *

- * Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * Or the calling app has carrier privileges. @see #hasCarrierPrivileges + * Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @return true on success; false on any failure. */ @@ -3085,9 +3080,13 @@ public class TelephonyManager { /** * Values used to return status for hasCarrierPrivileges call. */ + /** @hide */ public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; + /** @hide */ public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; + /** @hide */ public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; + /** @hide */ public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; /** @@ -3099,21 +3098,18 @@ public class TelephonyManager { * * TODO: Add a link to documentation. * - * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. - * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. - * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. - * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier - * rules (or if there are no rules). + * @return true if the app has carrier privileges. */ - public int hasCarrierPrivileges() { + public boolean hasCarrierPrivileges() { try { - return getITelephony().hasCarrierPrivileges(); + return getITelephony().getCarrierPrivilegeStatus() == + CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; } catch (RemoteException ex) { Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); } catch (NullPointerException ex) { Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); } - return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; + return false; } /** @@ -3124,9 +3120,8 @@ public class TelephonyManager { * brand value input. To unset the value, the same function should be * called with a null brand value. * - *

Requires Permission: - * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} - * or has to be carrier app - see #hasCarrierPrivileges. + *

Requires that the calling app has carrier privileges. + * @see #hasCarrierPrivileges * * @param brand The brand name to display/set. * @return true if the operation was executed correctly. @@ -3188,9 +3183,9 @@ public class TelephonyManager { try { return getITelephony().checkCarrierPrivilegesForPackage(pkgname); } catch (RemoteException ex) { - Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); + Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); } catch (NullPointerException ex) { - Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); + Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); } return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index cbfa9f6bf6e4e..adb3bc408efc6 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -713,7 +713,7 @@ interface ITelephony { * * @return carrier privilege status defined in TelephonyManager. */ - int hasCarrierPrivileges(); + int getCarrierPrivilegeStatus(); /** * Similar to above, but check for pkg whose name is pkgname.