Redesign the setPreferredNetworkType
Some APPs(like OMA DM) might enable or disable 5G settings, so redesign
the setPreferredNetworkType behavior.
1. Create allowed_network_type in telephonyprovider
2. Create get/set allowed network type API
3. When APPs call setPreferredNetworkType() that will AND with allowed
network type.
Bug: 136730709
Test: By Manual
1. setAllowedNetwork to disable 5G
2. setPreferredNetworkTypeBitmask to set NR_LTE_GSM_WCDMA
3. framework set LTE_GSM_WCDMA to modem
Change-Id: Iaec153d001ced49908dcb9a4410d857b3aea9b05
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 301387f..b679ba3 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5071,21 +5071,81 @@
final long identity = Binder.clearCallingIdentity();
try {
- if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
- Boolean success = (Boolean) sendRequest(
- CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
- if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
- if (success) {
- Settings.Global.putInt(mApp.getContentResolver(),
- Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
- }
- return success;
+ Settings.Global.putInt(mApp.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
+ return setPreferredNetworkTypesInternal(subId);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
/**
+ * Get the allowed network types that store in the telephony provider.
+ *
+ * @param subId the id of the subscription.
+ * @return allowedNetworkTypes the allowed network types.
+ */
+ @Override
+ public long getAllowedNetworkTypes(int subId) {
+ TelephonyPermissions
+ .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
+ mApp, subId, "getAllowedNetworkTypes");
+
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ return SubscriptionManager.getLongSubscriptionProperty(
+ subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
+ /**
+ * Set the allowed network types.
+ *
+ * @param subId the id of the subscription.
+ * @param allowedNetworkTypes the allowed network types.
+ * @return true on success; false on any failure.
+ */
+ @Override
+ public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
+ TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
+ mApp, subId, "setAllowedNetworkTypes");
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ SubscriptionManager.setSubscriptionProperty(subId,
+ SubscriptionManager.ALLOWED_NETWORK_TYPES,
+ String.valueOf(allowedNetworkTypes));
+ return setPreferredNetworkTypesInternal(subId);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
+ private boolean setPreferredNetworkTypesInternal(int subId) {
+ long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
+ Settings.Global.getInt(mApp.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + subId,
+ RILConstants.PREFERRED_NETWORK_MODE));
+ long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
+ subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
+ int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
+ (int) (networkTypeBitMask & allowedNetworkTypes));
+
+ if (DBG) {
+ log("setPreferredNetworkTypesInternal: subId " + subId
+ + " networkTypes " + networkTypeBitMask
+ + " allowedNetworkTypes " + allowedNetworkTypes
+ + " networkMode " + networkMode);
+ }
+
+ Boolean success = (Boolean) sendRequest(
+ CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
+ if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
+ return success;
+ }
+
+ /**
* Check whether DUN APN is required for tethering with subId.
*
* @param subId the id of the subscription to require tethering.