From 83bb093cc5fb86ed63a94bfb98f94cbb301663a7 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Fri, 25 Sep 2020 10:46:54 -0700 Subject: [PATCH 1/2] Add new methods for setting mobile data policy Add isMobileDataPolicyEnabled and setMobileDataPolicyEnabledStatus in TelephonyManager. These are intended to replace the mms-always-allowed and data-during-voice-call setters/getters. Old methods will be removed in a follow up commit. Fixes: 169367013 Test: atest TelephonyManagerTest Change-Id: I6033a84f0a0163e460343ebf603d66078455fe38 Merged-In: I6033a84f0a0163e460343ebf603d66078455fe38 --- api/system-current.txt | 4 + api/test-current.txt | 4 + non-updatable-api/system-current.txt | 4 + telephony/api/system-current.txt | 4 + .../android/telephony/TelephonyManager.java | 99 ++++++++++++++++++- .../internal/telephony/ITelephony.aidl | 4 + 6 files changed, 115 insertions(+), 4 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 11b2828e62472..74b6d67fb2f97 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -11237,6 +11237,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @WorkerThread public boolean isIccLockEnabled(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isIdle(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isLteCdmaEvdoGsmWcdmaEnabled(); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isMobileDataPolicyEnabled(int); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isOffhook(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isOpportunisticNetworkEnabled(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isPotentialEmergencyNumber(@NonNull String); @@ -11265,6 +11266,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataActivationState(int); method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunisticNetworkState(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setPreferredNetworkTypeBitmask(long); @@ -11311,6 +11313,8 @@ package android.telephony { field public static final int INVALID_EMERGENCY_NUMBER_DB_VERSION = -1; // 0xffffffff field public static final int KEY_TYPE_EPDG = 1; // 0x1 field public static final int KEY_TYPE_WLAN = 2; // 0x2 + field public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; // 0x1 + field public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; // 0x2 field public static final long NETWORK_TYPE_BITMASK_1xRTT = 64L; // 0x40L field public static final long NETWORK_TYPE_BITMASK_CDMA = 8L; // 0x8L field public static final long NETWORK_TYPE_BITMASK_EDGE = 2L; // 0x2L diff --git a/api/test-current.txt b/api/test-current.txt index bdf797e80ccc4..9ab6010762d23 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1658,10 +1658,14 @@ package android.telephony { method @NonNull public java.util.List getDevicePolicyOverrideApns(@NonNull android.content.Context); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag(); method public android.util.Pair getRadioHalVersion(); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isMobileDataPolicyEnabled(int); method public boolean modifyDevicePolicyOverrideApn(@NonNull android.content.Context, int, @NonNull android.telephony.data.ApnSetting); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void refreshUiccProfile(); method @Deprecated public void setCarrierTestOverride(String, String, String, String, String, String, String); method public void setCarrierTestOverride(String, String, String, String, String, String, String, String, String); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean); + field public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; // 0x1 + field public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; // 0x2 field public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1; // 0xffffffff } diff --git a/non-updatable-api/system-current.txt b/non-updatable-api/system-current.txt index 515d368db9e27..9875a88ff972c 100644 --- a/non-updatable-api/system-current.txt +++ b/non-updatable-api/system-current.txt @@ -10119,6 +10119,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @WorkerThread public boolean isIccLockEnabled(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isIdle(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isLteCdmaEvdoGsmWcdmaEnabled(); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isMobileDataPolicyEnabled(int); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isOffhook(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isOpportunisticNetworkEnabled(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isPotentialEmergencyNumber(@NonNull String); @@ -10147,6 +10148,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataActivationState(int); method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunisticNetworkState(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setPreferredNetworkTypeBitmask(long); @@ -10193,6 +10195,8 @@ package android.telephony { field public static final int INVALID_EMERGENCY_NUMBER_DB_VERSION = -1; // 0xffffffff field public static final int KEY_TYPE_EPDG = 1; // 0x1 field public static final int KEY_TYPE_WLAN = 2; // 0x2 + field public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; // 0x1 + field public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; // 0x2 field public static final long NETWORK_TYPE_BITMASK_1xRTT = 64L; // 0x40L field public static final long NETWORK_TYPE_BITMASK_CDMA = 8L; // 0x8L field public static final long NETWORK_TYPE_BITMASK_EDGE = 2L; // 0x2L diff --git a/telephony/api/system-current.txt b/telephony/api/system-current.txt index f4b7b509be56b..b092ec635d9eb 100644 --- a/telephony/api/system-current.txt +++ b/telephony/api/system-current.txt @@ -694,6 +694,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @WorkerThread public boolean isIccLockEnabled(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isIdle(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isLteCdmaEvdoGsmWcdmaEnabled(); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isMobileDataPolicyEnabled(int); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isOffhook(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isOpportunisticNetworkEnabled(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isPotentialEmergencyNumber(@NonNull String); @@ -722,6 +723,7 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataActivationState(int); method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunisticNetworkState(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setPreferredNetworkTypeBitmask(long); @@ -768,6 +770,8 @@ package android.telephony { field public static final int INVALID_EMERGENCY_NUMBER_DB_VERSION = -1; // 0xffffffff field public static final int KEY_TYPE_EPDG = 1; // 0x1 field public static final int KEY_TYPE_WLAN = 2; // 0x2 + field public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; // 0x1 + field public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; // 0x2 field public static final long NETWORK_TYPE_BITMASK_1xRTT = 64L; // 0x40L field public static final long NETWORK_TYPE_BITMASK_CDMA = 8L; // 0x8L field public static final long NETWORK_TYPE_BITMASK_EDGE = 2L; // 0x2L diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index fc20f8a4a2fcb..1d812f28182ee 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -12938,10 +12938,101 @@ public class TelephonyManager { } /** - * Set allowing mobile data during voice call. This is used for allowing data on the non-default - * data SIM. When a voice call is placed on the non-default data SIM on DSDS devices, users will - * not be able to use mobile data. By calling this API, data will be temporarily enabled on the - * non-default data SIM during the life cycle of the voice call. + * Controls whether mobile data on the non-default SIM is allowed during a voice call. + * + * This is used for allowing data on the non-default data SIM when a voice call is placed on + * the non-default data SIM on DSDS devices. If this policy is disabled, users will not be able + * to use mobile data via the non-default data SIM during the call, which may mean no mobile + * data at all since some modem implementations disallow mobile data via the default data SIM + * during voice calls. + * If this policy is enabled, data will be temporarily enabled on the non-default data SIM + * during any voice calls. + * + * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabledStatus}. + * @hide + */ + @SystemApi + @TestApi + public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; + + /** + * Controls whether MMS messages bypass the user-specified "mobile data" toggle. + * + * When enabled, requests for connections to the MMS APN will be accepted by telephony even if + * the user has turned "mobile data" off on this specific sim card. {@link #isDataEnabledForApn} + * will also return true for {@link ApnSetting#TYPE_MMS}. + * When disabled, the MMS APN will be governed by the same rules as all other APNs. + * + * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabledStatus}. + * @hide + */ + @SystemApi + @TestApi + public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; + + /** + * @hide + */ + @IntDef(prefix = { "MOBILE_DATA_POLICY_" }, value = { + MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL, + MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface MobileDataPolicy { } + + /** + * Enables or disables a piece of mobile data policy. + * + * Enables or disables the mobile data policy specified in {@code policy}. See the detailed + * description of each policy constant for what they do. + * + * @param policy The data policy to enable. + * @param enabled Whether to enable or disable the policy. + * @hide + */ + @SystemApi + @TestApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + public void setMobileDataPolicyEnabledStatus(@MobileDataPolicy int policy, boolean enabled) { + try { + ITelephony service = getITelephony(); + if (service != null) { + service.setMobileDataPolicyEnabledStatus(getSubId(), policy, enabled); + } + } catch (RemoteException ex) { + // This could happen if binder process crashes. + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + } + + /** + * Fetches the status of a piece of mobile data policy. + * + * @param policy The data policy that you want the status for. + * @return {@code true} if enabled, {@code false} otherwise. + * @hide + */ + @SystemApi + @TestApi + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public boolean isMobileDataPolicyEnabled(@MobileDataPolicy int policy) { + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.isMobileDataPolicyEnabled(getSubId(), policy); + } + } catch (RemoteException ex) { + // This could happen if binder process crashes. + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return false; + } + + /** * * @param allow {@code true} if allowing using data during voice call, {@code false} if * disallowed. diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 934103ebe2b61..7d873b6eecb7f 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2233,6 +2233,10 @@ interface ITelephony { */ String getMmsUAProfUrl(int subId); + void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, boolean enabled); + + boolean isMobileDataPolicyEnabled(int subscriptionId, int policy); + /** * Set allowing mobile data during voice call. */ From c4587ed1c9c1ee4a265dfb80ccc35fe02a8cf673 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Fri, 25 Sep 2020 11:14:29 -0700 Subject: [PATCH 2/2] Remove old methods for mobile data Bug: 169367013 Test: builds Change-Id: I9aa69c9bd8d31e6bbdd9a237b0aa2c3922431227 Merged-In: I9aa69c9bd8d31e6bbdd9a237b0aa2c3922431227 --- .../android/telephony/TelephonyManager.java | 82 +------------------ .../internal/telephony/ITelephony.aidl | 16 ---- 2 files changed, 1 insertion(+), 97 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 1d812f28182ee..ca47b83b20e70 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -12607,7 +12607,7 @@ public class TelephonyManager { * 1) User data is turned on, or * 2) APN is un-metered for this subscription, or * 3) APN type is whitelisted. E.g. MMS is whitelisted if - * {@link #setAlwaysAllowMmsData(boolean)} is turned on. + * {@link #MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. * * @param apnType Value indicating the apn type. Apn types are defined in {@link ApnSetting}. * @return whether data is enabled for a apn type. @@ -13032,86 +13032,6 @@ public class TelephonyManager { return false; } - /** - * - * @param allow {@code true} if allowing using data during voice call, {@code false} if - * disallowed. - * - * @return {@code true} if operation is successful. otherwise {@code false}. - * - * @throws SecurityException if the caller doesn't have the permission. - * - * @hide - */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public boolean setDataAllowedDuringVoiceCall(boolean allow) { - try { - ITelephony service = getITelephony(); - if (service != null) { - return service.setDataAllowedDuringVoiceCall(getSubId(), allow); - } - } catch (RemoteException ex) { - // This could happen if binder process crashes. - if (!isSystemProcess()) { - ex.rethrowAsRuntimeException(); - } - } - return false; - } - - /** - * Check whether data is allowed during voice call. This is used for allowing data on the - * non-default data SIM. When a voice call is placed on the non-default data SIM on DSDS - * devices, users will not be able to use mobile data. By calling this API, data will be - * temporarily enabled on the non-default data SIM during the life cycle of the voice call. - * - * @return {@code true} if data is allowed during voice call. - * - * @throws SecurityException if the caller doesn't have the permission. - * - * @hide - */ - @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) - public boolean isDataAllowedInVoiceCall() { - try { - ITelephony service = getITelephony(); - if (service != null) { - return service.isDataAllowedInVoiceCall(getSubId()); - } - } catch (RemoteException ex) { - // This could happen if binder process crashes. - if (!isSystemProcess()) { - ex.rethrowAsRuntimeException(); - } - } - return false; - } - - /** - * Set whether the specific sim card always allows MMS connection. If true, MMS network - * request will be accepted by telephony even if user turns "mobile data" off - * on this specific sim card. - * - * @param alwaysAllow whether Mms data is always allowed. - * @return whether operation is successful. - * - * @hide - */ - @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) - public boolean setAlwaysAllowMmsData(boolean alwaysAllow) { - try { - ITelephony service = getITelephony(); - if (service != null) { - return service.setAlwaysAllowMmsData(getSubId(), alwaysAllow); - } - } catch (RemoteException ex) { - if (!isSystemProcess()) { - ex.rethrowAsRuntimeException(); - } - } - return false; - } - /** * The IccLock state or password was changed successfully. * @hide diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 7d873b6eecb7f..5c31c46f293cc 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2237,22 +2237,6 @@ interface ITelephony { boolean isMobileDataPolicyEnabled(int subscriptionId, int policy); - /** - * Set allowing mobile data during voice call. - */ - boolean setDataAllowedDuringVoiceCall(int subId, boolean allow); - - /** - * Check whether data is allowed during voice call. Note this is for dual sim device that - * data might be disabled on non-default data subscription but explicitly turned on by settings. - */ - boolean isDataAllowedInVoiceCall(int subId); - - /** - * Set whether a subscription always allows MMS connection. - */ - boolean setAlwaysAllowMmsData(int subId, boolean allow); - /** * Command line command to enable or disable handling of CEP data for test purposes. */