From 7611d69c7515297ece790373b186454b06d87100 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 9 Apr 2019 19:27:57 -0700 Subject: [PATCH 1/2] Add API to set alwaysAllowMms Add API in SubscriptionManager setAlwaysAllowMmsData and isMmsDataAllowed. Bug: 128616035 Test: unittest Change-Id: Ie56c2d0619a68b188c35e8e24db6c2012d22538b Merged-In: Ie56c2d0619a68b188c35e8e24db6c2012d22538b --- .../telephony/SubscriptionManager.java | 38 +++++++++++++++++++ .../android/telephony/TelephonyManager.java | 29 ++++++++++++++ .../internal/telephony/DctConstants.java | 1 + .../com/android/internal/telephony/ISub.aidl | 2 + .../internal/telephony/ITelephony.aidl | 2 + 5 files changed, 72 insertions(+) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 586c815ae7b59..58c05aa3ccba1 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -293,6 +293,19 @@ public class SubscriptionManager { /** @hide */ public static final String SUBSCRIPTION_TYPE = "subscription_type"; + /** + * TelephonyProvider column name white_listed_apn_data. + * It's a bitmask of APN types that will be allowed on this subscription even if it's metered + * and mobile data is turned off by the user. + *

Type: INTEGER (int)

For example, if TYPE_MMS is is true, Telephony will allow MMS + * data connection to setup even if MMS is metered and mobile_data is turned off on that + * subscription. + * + * Default value is 0. + */ + /** @hide */ + public static final String WHITE_LISTED_APN_DATA = "white_listed_apn_data"; + /** * This constant is to designate a subscription as a Local-SIM Subscription. *

A Local-SIM can be a physical SIM inserted into a sim-slot in the device, or eSIM on the @@ -3087,6 +3100,31 @@ public class SubscriptionManager { return subId; } + /** + * Set whether a subscription always allows MMS connection. If true, MMS network + * request will be accepted by telephony even if user turns "mobile data" off + * on this subscription. + * + * @param subId which subscription it's setting to. + * @param alwaysAllow whether Mms data is always allowed. + * @return whether operation is successful. + * + * @hide + */ + public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { + try { + ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); + if (iSub != null) { + return iSub.setAlwaysAllowMmsData(subId, alwaysAllow); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return false; + } + private interface CallISubMethodHelper { int callMethod(ISub iSub) throws RemoteException; } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index e1425b9755256..11fd28be338a6 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -10888,4 +10888,33 @@ public class TelephonyManager { } return new Pair(-1, -1); } + + + /** + * Return whether MMS data is enabled. This will tell if framework will accept a MMS network + * request on a subId. + * + * Mms is enabled if: + * 1) user data is turned on, or + * 2) MMS is un-metered for this subscription, or + * 3) alwaysAllowMms setting {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. + * + * @return whether MMS data is allowed. + * + * @hide + */ + public boolean isMmsDataEnabled() { + String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.isMmsDataEnabled(getSubId(), pkgForDebug); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return false; + } } diff --git a/telephony/java/com/android/internal/telephony/DctConstants.java b/telephony/java/com/android/internal/telephony/DctConstants.java index 6e8d038eda4f3..bb5c251b69e1e 100644 --- a/telephony/java/com/android/internal/telephony/DctConstants.java +++ b/telephony/java/com/android/internal/telephony/DctConstants.java @@ -94,6 +94,7 @@ public class DctConstants { public static final int EVENT_ROAMING_SETTING_CHANGE = BASE + 48; public static final int EVENT_DATA_SERVICE_BINDING_CHANGED = BASE + 49; public static final int EVENT_DEVICE_PROVISIONED_CHANGE = BASE + 50; + public static final int EVENT_APN_WHITE_LIST_CHANGE = BASE + 51; /***** Constants *****/ diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index 118f5e26e6e72..f248893ec6382 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -283,4 +283,6 @@ interface ISub { int getSimStateForSlotIndex(int slotIndex); boolean isActiveSubId(int subId, String callingPackage); + + boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow); } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index d173cc9c44e5c..57211636d5f14 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1958,4 +1958,6 @@ interface ITelephony { int getRadioHalVersion(); boolean isModemEnabledForSlot(int slotIndex, String callingPackage); + + boolean isMmsDataEnabled(int subId, String callingPackage); } From 4d6ff22849a098a4f1b8c5ee754589124a3f7fcf Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Thu, 18 Apr 2019 13:49:17 -0700 Subject: [PATCH 2/2] Adding @hide API to return whether an APN is metered or not. In addition, make isMmsDataEnabled more generic: isDataEnabledForApn Bug: 128616035 Test: manual Change-Id: Icd520c3094dd761a13435fae79b7b6b3ba2ebda9 Merged-In: Icd520c3094dd761a13435fae79b7b6b3ba2ebda9 --- .../android/telephony/TelephonyManager.java | 46 +++++++++++++++---- .../internal/telephony/ITelephony.aidl | 4 +- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 11fd28be338a6..82cc1df08f4f4 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -64,6 +64,7 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.VisualVoicemailService.VisualVoicemailTask; +import android.telephony.data.ApnSetting; import android.telephony.emergency.EmergencyNumber; import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; import android.telephony.ims.aidl.IImsConfig; @@ -10889,26 +10890,31 @@ public class TelephonyManager { return new Pair(-1, -1); } - /** - * Return whether MMS data is enabled. This will tell if framework will accept a MMS network - * request on a subId. + * Return whether data is enabled for certain APN type. This will tell if framework will accept + * corresponding network requests on a subId. * - * Mms is enabled if: - * 1) user data is turned on, or - * 2) MMS is un-metered for this subscription, or - * 3) alwaysAllowMms setting {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. + * {@link #isDataEnabled()} is directly associated with users' Mobile data toggle on / off. If + * {@link #isDataEnabled()} returns false, it means in general all meter-ed data are disabled. * - * @return whether MMS data is allowed. + * This per APN type API gives a better idea whether data is allowed on a specific APN type. + * It will return true if: + * + * 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 SubscriptionManager#setAlwaysAllowMmsData} is turned on. + * + * @return whether data is enabled for a apn type. * * @hide */ - public boolean isMmsDataEnabled() { + public boolean isDataEnabledForApn(@ApnSetting.ApnType int apnType) { String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; try { ITelephony service = getITelephony(); if (service != null) { - return service.isMmsDataEnabled(getSubId(), pkgForDebug); + return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); } } catch (RemoteException ex) { if (!isSystemProcess()) { @@ -10917,4 +10923,24 @@ public class TelephonyManager { } return false; } + + /** + * Whether an APN type is metered or not. It will be evaluated with the subId associated + * with the TelephonyManager instance. + * + * @hide + */ + public boolean isApnMetered(@ApnSetting.ApnType int apnType) { + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.isApnMetered(apnType, getSubId()); + } + } catch (RemoteException ex) { + if (!isSystemProcess()) { + ex.rethrowAsRuntimeException(); + } + } + return true; + } } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 57211636d5f14..0ad60963c398d 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1959,5 +1959,7 @@ interface ITelephony { boolean isModemEnabledForSlot(int slotIndex, String callingPackage); - boolean isMmsDataEnabled(int subId, String callingPackage); + boolean isDataEnabledForApn(int apnType, int subId, String callingPackage); + + boolean isApnMetered(int apnType, int subId); }