Merge "Fix typo"
diff --git a/proto/src/telephony.proto b/proto/src/telephony.proto
index 9c8c65a..78dee95 100644
--- a/proto/src/telephony.proto
+++ b/proto/src/telephony.proto
@@ -1743,7 +1743,7 @@
optional bool is_network_unmetered = 1;
}
- // Time when event happened on device, in milliseconds since epoch
+ // Time when event happened on device, in milliseconds since boot
optional int64 timestamp_millis = 1;
// In Multi-SIM devices this indicates SIM slot
diff --git a/src/java/com/android/internal/telephony/CarrierServiceStateTracker.java b/src/java/com/android/internal/telephony/CarrierServiceStateTracker.java
index bfa89e0..ddf9797 100644
--- a/src/java/com/android/internal/telephony/CarrierServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/CarrierServiceStateTracker.java
@@ -24,12 +24,14 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
-import android.database.ContentObserver;
import android.os.Handler;
+import android.os.HandlerExecutor;
import android.os.Message;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
+import android.telephony.PhoneStateListener;
+import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
@@ -71,9 +73,37 @@
@VisibleForTesting
public static final String PREF_NETWORK_NOTIFICATION_TAG = "PrefNetworkNotification";
+ private long mAllowedNetworkType = -1;
+ private AllowedNetworkTypesChangedListener mAllowedNetworkTypesChangedListenerListener;
+ private TelephonyManager mTelephonyManager;
+
+ /**
+ * The listener for allowed network types changed
+ */
+ @VisibleForTesting
+ public class AllowedNetworkTypesChangedListener extends PhoneStateListener
+ implements PhoneStateListener.AllowedNetworkTypesChangedListener {
+ @Override
+ public void onAllowedNetworkTypesChanged(Map<Integer, Long> allowedNetworkTypesList) {
+ if (!allowedNetworkTypesList.containsKey(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER)) {
+ return;
+ }
+
+ long newAllowedNetworkType = allowedNetworkTypesList.get(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
+ if (mAllowedNetworkType != newAllowedNetworkType) {
+ mAllowedNetworkType = newAllowedNetworkType;
+ handlePrefNetworkModeChanged();
+ }
+ }
+ }
+
public CarrierServiceStateTracker(Phone phone, ServiceStateTracker sst) {
this.mPhone = phone;
this.mSST = sst;
+ mTelephonyManager = mPhone.getContext().getSystemService(
+ TelephonyManager.class).createForSubscriptionId(mPhone.getSubId());
phone.getContext().registerReceiver(mBroadcastReceiver, new IntentFilter(
CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
// Listen for subscriber changes
@@ -84,44 +114,42 @@
int subId = mPhone.getSubId();
if (mPreviousSubId != subId) {
mPreviousSubId = subId;
- registerPrefNetworkModeObserver();
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(
+ mPhone.getSubId());
+ registerAllowedNetworkTypesListener();
}
}
});
registerNotificationTypes();
- registerPrefNetworkModeObserver();
+ mAllowedNetworkType = RadioAccessFamily.getNetworkTypeFromRaf(
+ (int) mPhone.getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER));
+ mAllowedNetworkTypesChangedListenerListener = new AllowedNetworkTypesChangedListener();
+ registerAllowedNetworkTypesListener();
}
- private ContentObserver mPrefNetworkModeObserver = new ContentObserver(this) {
- @Override
- public void onChange(boolean selfChange) {
- handlePrefNetworkModeChanged();
- }
- };
-
/**
- * Return preferred network mode observer
+ * Return preferred network mode listener
*/
@VisibleForTesting
- public ContentObserver getContentObserver() {
- return mPrefNetworkModeObserver;
+ public AllowedNetworkTypesChangedListener getAllowedNetworkTypesChangedListener() {
+ return mAllowedNetworkTypesChangedListenerListener;
}
- private void registerPrefNetworkModeObserver() {
+ private void registerAllowedNetworkTypesListener() {
int subId = mPhone.getSubId();
- unregisterPrefNetworkModeObserver();
+ unregisterAllowedNetworkTypesListener();
if (SubscriptionManager.isValidSubscriptionId(subId)) {
- mPhone.getContext().getContentResolver().registerContentObserver(
- Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE + subId),
- true,
- mPrefNetworkModeObserver);
+ if (mTelephonyManager != null) {
+ mTelephonyManager.registerPhoneStateListener(new HandlerExecutor(this),
+ mAllowedNetworkTypesChangedListenerListener);
+ }
}
}
- private void unregisterPrefNetworkModeObserver() {
- mPhone.getContext().getContentResolver().unregisterContentObserver(
- mPrefNetworkModeObserver);
+ private void unregisterAllowedNetworkTypesListener() {
+ mTelephonyManager.unregisterPhoneStateListener(mAllowedNetworkTypesChangedListenerListener);
}
/**
@@ -196,13 +224,10 @@
* Returns true if the preferred network is set to 'Global'.
*/
private boolean isGlobalMode() {
- Context context = mPhone.getContext();
int preferredNetworkSetting = -1;
try {
- preferredNetworkSetting =
- android.provider.Settings.Global.getInt(context.getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE
- + mPhone.getSubId(), Phone.PREFERRED_NT_MODE);
+ preferredNetworkSetting = PhoneFactory.calculatePreferredNetworkType(
+ mPhone.getPhoneId());
} catch (Exception e) {
Rlog.e(LOG_TAG, "Unable to get PREFERRED_NETWORK_MODE.");
return true;
@@ -210,9 +235,11 @@
if (isNrSupported()) {
return (preferredNetworkSetting
- == RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
+ == RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
} else {
- return (preferredNetworkSetting == RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
+ return (preferredNetworkSetting == RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
}
}
@@ -225,7 +252,9 @@
boolean isRadioAccessFamilySupported = checkSupportedBitmask(
tm.getSupportedRadioAccessFamily(), TelephonyManager.NETWORK_TYPE_BITMASK_NR);
boolean isNrNetworkTypeAllowed = checkSupportedBitmask(
- tm.getAllowedNetworkTypes(), TelephonyManager.NETWORK_TYPE_BITMASK_NR);
+ tm.getAllowedNetworkTypesForReason(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER),
+ TelephonyManager.NETWORK_TYPE_BITMASK_NR);
Rlog.i(LOG_TAG, "isNrSupported: " + " carrierConfigEnabled: " + isCarrierConfigEnabled
+ ", AccessFamilySupported: " + isRadioAccessFamilySupported
@@ -246,7 +275,8 @@
Rlog.e(LOG_TAG, "isCarrierConfigEnableNr: Cannot get config " + mPhone.getSubId());
return false;
}
- return config.getBoolean(CarrierConfigManager.KEY_NR_ENABLED_BOOL);
+ return config.getInt(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITY_INT)
+ != CarrierConfigManager.CARRIER_NR_AVAILABILITY_NONE;
}
private boolean checkSupportedBitmask(@NetworkTypeBitMask long supportedBitmask,
@@ -369,7 +399,7 @@
* Dispose the CarrierServiceStateTracker.
*/
public void dispose() {
- unregisterPrefNetworkModeObserver();
+ unregisterAllowedNetworkTypesListener();
}
/**
diff --git a/src/java/com/android/internal/telephony/CommandsInterface.java b/src/java/com/android/internal/telephony/CommandsInterface.java
index e60dff4..7572d11 100644
--- a/src/java/com/android/internal/telephony/CommandsInterface.java
+++ b/src/java/com/android/internal/telephony/CommandsInterface.java
@@ -1568,15 +1568,15 @@
* @param networkTypeBitmask {@link TelephonyManager.NetworkTypeBitMask}
* @param response is callback message
*/
- void setAllowedNetworkTypeBitmask(
+ void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response);
/**
* Query the allowed network types setting.
*
- * @param response is callback message to report one of NT_*_TYPE
+ * @param response is callback message to report allowed network types bitmask
*/
- void getAllowedNetworkTypeBitmask(Message response);
+ void getAllowedNetworkTypesBitmap(Message response);
/**
* Enable/Disable E-UTRA-NR Dual Connectivity
diff --git a/src/java/com/android/internal/telephony/DefaultPhoneNotifier.java b/src/java/com/android/internal/telephony/DefaultPhoneNotifier.java
index 8fe089a..4947c38 100644
--- a/src/java/com/android/internal/telephony/DefaultPhoneNotifier.java
+++ b/src/java/com/android/internal/telephony/DefaultPhoneNotifier.java
@@ -40,6 +40,7 @@
import com.android.telephony.Rlog;
import java.util.List;
+import java.util.Map;
/**
* broadcast intents
@@ -250,6 +251,13 @@
enabled, reason);
}
+ @Override
+ public void notifyAllowedNetworkTypesChanged(Phone sender,
+ Map<Integer, Long> allowedNetworkTypeList) {
+ mTelephonyRegistryMgr.notifyAllowedNetworkTypesChanged(sender.getSubId(),
+ sender.getPhoneId(), allowedNetworkTypeList);
+ }
+
/**
* Convert the {@link DataActivityState} enum into the TelephonyManager.DATA_* constants for the
* public API.
diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
index 16ad065..6ece2d3 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
@@ -15,7 +15,6 @@
*/
package com.android.internal.telephony;
-
import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE;
import static com.android.internal.telephony.CommandException.Error.SIM_BUSY;
import static com.android.internal.telephony.CommandsInterface.CF_ACTION_DISABLE;
@@ -70,6 +69,7 @@
import android.telephony.ImsiEncryptionInfo;
import android.telephony.NetworkScanRequest;
import android.telephony.PhoneNumberUtils;
+import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.ServiceState.RilRadioTechnology;
import android.telephony.SignalThresholdInfo;
@@ -2742,6 +2742,7 @@
// If this is on APM off, SIM may already be loaded. Send setPreferredNetworkType
// request to RIL to preserve user setting across APM toggling
setPreferredNetworkTypeIfSimLoaded();
+ notifyAllowedNetworkTypesChanged();
}
private void handleRadioOffOrNotAvailable() {
@@ -2882,58 +2883,16 @@
mCi.getVoiceRadioTechnology(obtainMessage(EVENT_REQUEST_VOICE_RADIO_TECH_DONE));
}
- // Update broadcastEmergencyCallStateChanges
CarrierConfigManager configMgr = (CarrierConfigManager)
getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
PersistableBundle b = configMgr.getConfigForSubId(getSubId());
- if (b != null) {
- boolean broadcastEmergencyCallStateChanges = b.getBoolean(
- CarrierConfigManager.KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL);
- logd("broadcastEmergencyCallStateChanges = " +
- broadcastEmergencyCallStateChanges);
- setBroadcastEmergencyCallStateChanges(broadcastEmergencyCallStateChanges);
- } else {
- loge("didn't get broadcastEmergencyCallStateChanges from carrier config");
- }
- // Changing the cdma roaming settings based carrier config.
- if (b != null) {
- int config_cdma_roaming_mode = b.getInt(
- CarrierConfigManager.KEY_CDMA_ROAMING_MODE_INT);
- int current_cdma_roaming_mode =
- Settings.Global.getInt(getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT);
- switch (config_cdma_roaming_mode) {
- // Carrier's cdma_roaming_mode will overwrite the user's previous settings
- // Keep the user's previous setting in global variable which will be used
- // when carrier's setting is turn off.
- case TelephonyManager.CDMA_ROAMING_MODE_HOME:
- case TelephonyManager.CDMA_ROAMING_MODE_AFFILIATED:
- case TelephonyManager.CDMA_ROAMING_MODE_ANY:
- logd("cdma_roaming_mode is going to changed to "
- + config_cdma_roaming_mode);
- setCdmaRoamingPreference(config_cdma_roaming_mode,
- obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
- break;
+ updateBroadcastEmergencyCallStateChangesAfterCarrierConfigChanged(b);
- // When carrier's setting is turn off, change the cdma_roaming_mode to the
- // previous user's setting
- case TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT:
- if (current_cdma_roaming_mode != config_cdma_roaming_mode) {
- logd("cdma_roaming_mode is going to changed to "
- + current_cdma_roaming_mode);
- setCdmaRoamingPreference(current_cdma_roaming_mode,
- obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
- }
+ updateCdmaRoamingSettingsAfterCarrierConfigChanged(b);
- default:
- loge("Invalid cdma_roaming_mode settings: "
- + config_cdma_roaming_mode);
- }
- } else {
- loge("didn't get the cdma_roaming_mode changes from the carrier config.");
- }
+ updateNrSettingsAfterCarrierConfigChanged();
+
break;
case EVENT_SET_ROAMING_PREFERENCE_DONE:
@@ -3498,7 +3457,8 @@
*/
public boolean shouldForceAutoNetworkSelect() {
- int nwMode = Phone.PREFERRED_NT_MODE;
+ int networkTypeBitmask = RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.PREFERRED_NETWORK_MODE);
int subId = getSubId();
// If it's invalid subId, we shouldn't force to auto network select mode.
@@ -3506,21 +3466,23 @@
return false;
}
- nwMode = android.provider.Settings.Global.getInt(mContext.getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId, nwMode);
+ networkTypeBitmask = (int) getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
- logd("shouldForceAutoNetworkSelect in mode = " + nwMode);
+ logd("shouldForceAutoNetworkSelect in mode = " + networkTypeBitmask);
/*
* For multimode targets in global mode manual network
* selection is disallowed. So we should force auto select mode.
*/
if (isManualSelProhibitedInGlobalMode()
- && ((nwMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA)
- || (nwMode == TelephonyManager.NETWORK_MODE_GLOBAL)) ){
- logd("Should force auto network select mode = " + nwMode);
+ && ((networkTypeBitmask == RadioAccessFamily.getRafFromNetworkType(
+ TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA))
+ || (networkTypeBitmask == RadioAccessFamily.getRafFromNetworkType(
+ TelephonyManager.NETWORK_MODE_GLOBAL)))) {
+ logd("Should force auto network select mode = " + networkTypeBitmask);
return true;
} else {
- logd("Should not force auto network select mode = " + nwMode);
+ logd("Should not force auto network select mode = " + networkTypeBitmask);
}
/*
@@ -4611,4 +4573,63 @@
}
return Collections.emptyList();
}
+
+ private void updateBroadcastEmergencyCallStateChangesAfterCarrierConfigChanged(
+ PersistableBundle config) {
+ if (config == null) {
+ loge("didn't get broadcastEmergencyCallStateChanges from carrier config");
+ return;
+ }
+
+ // get broadcastEmergencyCallStateChanges
+ boolean broadcastEmergencyCallStateChanges = config.getBoolean(
+ CarrierConfigManager.KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL);
+ logd("broadcastEmergencyCallStateChanges = " + broadcastEmergencyCallStateChanges);
+ setBroadcastEmergencyCallStateChanges(broadcastEmergencyCallStateChanges);
+ }
+
+ private void updateNrSettingsAfterCarrierConfigChanged() {
+ updateAllowedNetworkTypes(null);
+ }
+
+ private void updateCdmaRoamingSettingsAfterCarrierConfigChanged(PersistableBundle config) {
+ if (config == null) {
+ loge("didn't get the cdma_roaming_mode changes from the carrier config.");
+ return;
+ }
+
+ // Changing the cdma roaming settings based carrier config.
+ int config_cdma_roaming_mode = config.getInt(
+ CarrierConfigManager.KEY_CDMA_ROAMING_MODE_INT);
+ int current_cdma_roaming_mode =
+ Settings.Global.getInt(getContext().getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT);
+ switch (config_cdma_roaming_mode) {
+ // Carrier's cdma_roaming_mode will overwrite the user's previous settings
+ // Keep the user's previous setting in global variable which will be used
+ // when carrier's setting is turn off.
+ case TelephonyManager.CDMA_ROAMING_MODE_HOME:
+ case TelephonyManager.CDMA_ROAMING_MODE_AFFILIATED:
+ case TelephonyManager.CDMA_ROAMING_MODE_ANY:
+ logd("cdma_roaming_mode is going to changed to "
+ + config_cdma_roaming_mode);
+ setCdmaRoamingPreference(config_cdma_roaming_mode,
+ obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
+ break;
+
+ // When carrier's setting is turn off, change the cdma_roaming_mode to the
+ // previous user's setting
+ case TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT:
+ if (current_cdma_roaming_mode != config_cdma_roaming_mode) {
+ logd("cdma_roaming_mode is going to changed to "
+ + current_cdma_roaming_mode);
+ setCdmaRoamingPreference(current_cdma_roaming_mode,
+ obtainMessage(EVENT_SET_ROAMING_PREFERENCE_DONE));
+ }
+ break;
+ default:
+ loge("Invalid cdma_roaming_mode settings: " + config_cdma_roaming_mode);
+ }
+ }
}
diff --git a/src/java/com/android/internal/telephony/Phone.java b/src/java/com/android/internal/telephony/Phone.java
index b1800f0..8166b61 100644
--- a/src/java/com/android/internal/telephony/Phone.java
+++ b/src/java/com/android/internal/telephony/Phone.java
@@ -116,6 +116,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
/**
* (<em>Not for SDK use</em>)
@@ -441,8 +442,13 @@
protected SimulatedRadioControl mSimulatedRadioControl;
- private boolean mUnitTestMode;
private Map<Integer, Long> mAllowedNetworkTypesForReasons = new HashMap<>();
+ private static final String ALLOWED_NETWORK_TYPES_TEXT_USER = "user";
+ private static final String ALLOWED_NETWORK_TYPES_TEXT_POWER = "power";
+ private static final String ALLOWED_NETWORK_TYPES_TEXT_CARRIER = "carrier";
+ private static final int INVALID_ALLOWED_NETWORK_TYPES = -1;
+
+ private boolean mUnitTestMode;
private final CarrierPrivilegesTracker mCarrierPrivilegesTracker;
protected VoiceCallSessionStats mVoiceCallSessionStats;
@@ -1756,23 +1762,6 @@
}
}
- private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes() {
- long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask();
- if (SubscriptionController.getInstance() != null) {
- String result = SubscriptionController.getInstance().getSubscriptionProperty(
- getSubId(),
- SubscriptionManager.ALLOWED_NETWORK_TYPES);
-
- if (result != null) {
- try {
- allowedNetworkTypes = Long.parseLong(result);
- } catch (NumberFormatException err) {
- Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception");
- }
- }
- }
- return allowedNetworkTypes;
- }
/**
* Set the properties by matching the carrier string in
* a string-array resource
@@ -2090,16 +2079,6 @@
editor.apply();
}
- private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypesForAllReasons() {
- long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask();
- synchronized (mAllowedNetworkTypesForReasons) {
- for (long networkTypes: mAllowedNetworkTypesForReasons.values()) {
- allowedNetworkTypes = allowedNetworkTypes & networkTypes;
- }
- }
- return allowedNetworkTypes;
- }
-
public void setVoiceCallForwardingFlag(int line, boolean enable, String number) {
setCallForwardingIndicatorInSharedPref(enable);
IccRecords r = getIccRecords();
@@ -2225,11 +2204,34 @@
/**
* Get the effective allowed network types on the device.
+ *
* @return effective network type
*/
- public @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() {
- long allowedNetworkTypes = getAllowedNetworkTypes();
- return allowedNetworkTypes & getAllowedNetworkTypesForAllReasons();
+ private @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() {
+ long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask();
+ synchronized (mAllowedNetworkTypesForReasons) {
+ for (long networkTypes : mAllowedNetworkTypesForReasons.values()) {
+ allowedNetworkTypes = allowedNetworkTypes & networkTypes;
+ }
+ }
+ Rlog.d(LOG_TAG, "getEffectiveAllowedNetworkTypes: " + allowedNetworkTypes);
+ return allowedNetworkTypes;
+ }
+
+ /**
+ * Notify the allowed network types changed.
+ */
+ public void notifyAllowedNetworkTypesChanged() {
+ List<Integer> listOfAllowedNetworkTypesForReasons = new ArrayList<>(
+ Arrays.asList(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER));
+ Map<Integer, Long> allowedNetworkTypeList = new HashMap<>();
+ for (Integer reasonItem : listOfAllowedNetworkTypesForReasons) {
+ allowedNetworkTypeList.put(reasonItem, getAllowedNetworkTypes(reasonItem));
+ }
+ Rlog.d(LOG_TAG, "notifyAllowedNetworkTypesChanged: " + allowedNetworkTypeList.toString());
+ mNotifier.notifyAllowedNetworkTypesChanged(this, allowedNetworkTypeList);
}
/**
@@ -2271,59 +2273,150 @@
*/
public @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes(
@TelephonyManager.AllowedNetworkTypesReason int reason) {
+ long allowedNetworkTypes = INVALID_ALLOWED_NETWORK_TYPES;
+ long defaultAllowedNetworkTypes = RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.PREFERRED_NETWORK_MODE);
+
+ if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
+ throw new IllegalArgumentException("AllowedNetworkTypes NumberFormat exception");
+ }
+
synchronized (mAllowedNetworkTypesForReasons) {
- switch (reason) {
- case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER:
- return mAllowedNetworkTypesForReasons.getOrDefault(
- TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
- TelephonyManager.getAllNetworkTypesBitmask());
- default:
- Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
- return TelephonyManager.getAllNetworkTypesBitmask();
+ // Try to load ALLOWED_NETWORK_TYPES from SIMINFO.
+ if (SubscriptionController.getInstance() != null
+ && !mAllowedNetworkTypesForReasons.containsKey(reason)) {
+ String result = SubscriptionController.getInstance().getSubscriptionProperty(
+ getSubId(),
+ SubscriptionManager.ALLOWED_NETWORK_TYPES);
+ if (result != null) {
+ try {
+ filterAllowedNetworkTypesFromDb(result);
+ } catch (NumberFormatException err) {
+ Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception");
+ }
+ }
+ }
+
+ allowedNetworkTypes = mAllowedNetworkTypesForReasons.getOrDefault(
+ reason,
+ defaultAllowedNetworkTypes);
+ }
+
+ if (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER) {
+ allowedNetworkTypes = updateAllowedNetworkTypeForCarrierWithCarrierConfig(reason,
+ allowedNetworkTypes);
+ }
+ Rlog.d(LOG_TAG,
+ "get allowed network types " + convertAllowedNetworkTypeMapIndexToDbName(reason)
+ + ": value = " + allowedNetworkTypes);
+
+ return allowedNetworkTypes;
+ }
+
+ private void filterAllowedNetworkTypesFromDb(String result) {
+ if (TextUtils.isEmpty(result)) {
+ return;
+ }
+ // Format: "REASON=VALUE,REASON2=VALUE2"
+ for (String pair : result.trim().split(",")) {
+ String[] networkTypesValues = (pair.trim().toLowerCase()).split("=");
+ if (networkTypesValues.length != 2) {
+ Rlog.e(LOG_TAG, "Invalid ALLOWED_NETWORK_TYPES from DB, value = " + pair);
+ continue;
+ }
+ int key = convertAllowedNetworkTypeDbNameToMapIndex(networkTypesValues[0]);
+ long value = Long.parseLong(networkTypesValues[1]);
+ if (key != INVALID_ALLOWED_NETWORK_TYPES && value != INVALID_ALLOWED_NETWORK_TYPES) {
+ synchronized (mAllowedNetworkTypesForReasons) {
+ mAllowedNetworkTypesForReasons.put(key, value);
+ }
}
}
}
+ private int convertAllowedNetworkTypeDbNameToMapIndex(String name) {
+ switch (name) {
+ case ALLOWED_NETWORK_TYPES_TEXT_USER:
+ return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER;
+ case ALLOWED_NETWORK_TYPES_TEXT_POWER:
+ return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER;
+ case ALLOWED_NETWORK_TYPES_TEXT_CARRIER:
+ return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER;
+ default:
+ return INVALID_ALLOWED_NETWORK_TYPES;
+ }
+ }
+
+ private String convertAllowedNetworkTypeMapIndexToDbName(int reason) {
+ switch (reason) {
+ case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER:
+ return ALLOWED_NETWORK_TYPES_TEXT_USER;
+ case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER:
+ return ALLOWED_NETWORK_TYPES_TEXT_POWER;
+ case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER:
+ return ALLOWED_NETWORK_TYPES_TEXT_CARRIER;
+ default:
+ return Integer.toString(INVALID_ALLOWED_NETWORK_TYPES);
+ }
+ }
+
+ private long updateAllowedNetworkTypeForCarrierWithCarrierConfig(
+ @TelephonyManager.AllowedNetworkTypesReason int reason,
+ @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
+ CarrierConfigManager configMgr = (CarrierConfigManager)
+ getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ PersistableBundle config = configMgr.getConfigForSubId(getSubId());
+ if (config == null) {
+ return allowedNetworkTypes;
+ }
+ boolean isNrSupported = config.getInt(
+ CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITY_INT,
+ CarrierConfigManager.CARRIER_NR_AVAILABILITY_NSA)
+ != CarrierConfigManager.CARRIER_NR_AVAILABILITY_NONE;
+ if (!isNrSupported) {
+ allowedNetworkTypes =
+ allowedNetworkTypes & ~TelephonyManager.NETWORK_TYPE_BITMASK_NR;
+ Rlog.d(LOG_TAG, reason + " with carrier config value = " + allowedNetworkTypes);
+ }
+ return allowedNetworkTypes;
+ }
+
/**
* Requests to set the allowed network types for a specific reason
+ *
* @param reason reason to configure allowed network type
* @param networkTypes one of the network types
*/
public void setAllowedNetworkTypes(@TelephonyManager.AllowedNetworkTypesReason int reason,
- @TelephonyManager.NetworkTypeBitMask long networkTypes) {
- synchronized (mAllowedNetworkTypesForReasons) {
- switch (reason) {
- case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER:
- mAllowedNetworkTypesForReasons.put(
- TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, networkTypes);
- break;
- default:
- Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
- break;
- }
+ @TelephonyManager.NetworkTypeBitMask long networkTypes, Message response) {
+ if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
+ Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
+ return;
}
+ String mapAsString = "";
+ synchronized (mAllowedNetworkTypesForReasons) {
+ mAllowedNetworkTypesForReasons.put(reason, networkTypes);
+ mapAsString = mAllowedNetworkTypesForReasons.keySet().stream()
+ .map(key -> convertAllowedNetworkTypeMapIndexToDbName(key) + "="
+ + mAllowedNetworkTypesForReasons.get(key))
+ .collect(Collectors.joining(","));
+ }
+ SubscriptionManager.setSubscriptionProperty(getSubId(),
+ SubscriptionManager.ALLOWED_NETWORK_TYPES,
+ mapAsString);
+ Rlog.d(LOG_TAG, "setAllowedNetworkTypes " + mapAsString);
+ notifyAllowedNetworkTypesChanged();
+
+ updateAllowedNetworkTypes(response);
}
- /**
- * Requests to set the preferred network type for searching and registering
- * (CS/PS domain, RAT, and operation mode)
- * @param networkType one of NT_*_TYPE
- * @param response is callback message
- */
- @UnsupportedAppUsage
- public void setPreferredNetworkType(int networkType, Message response) {
- // Only set preferred network types to that which the modem supports
+ protected void updateAllowedNetworkTypes(Message response) {
int modemRaf = getRadioAccessFamily();
- int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType);
-
- long allowedNetworkTypes = getAllowedNetworkTypes();
- if (modemRaf == RadioAccessFamily.RAF_UNKNOWN
- || rafFromType == RadioAccessFamily.RAF_UNKNOWN) {
+ if (modemRaf == RadioAccessFamily.RAF_UNKNOWN) {
Rlog.d(LOG_TAG, "setPreferredNetworkType: Abort, unknown RAF: "
- + modemRaf + " " + rafFromType);
+ + modemRaf);
if (response != null) {
CommandException ex;
-
ex = new CommandException(CommandException.Error.GENERIC_FAILURE);
AsyncResult.forMessage(response, null, ex);
response.sendToTarget();
@@ -2331,28 +2424,22 @@
return;
}
- int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes
- & getAllowedNetworkTypesForAllReasons());
- int filteredType = RadioAccessFamily.getNetworkTypeFromRaf(filteredRaf);
- long powerAllowedNetworkTypes = getAllowedNetworkTypes(
- TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER);
- Rlog.d(LOG_TAG, "setPreferredNetworkType: networkType = " + networkType
- + " modemRaf = " + modemRaf
- + " rafFromType = " + rafFromType
- + " allowedNetworkTypes = " + allowedNetworkTypes
- + " power allowedNetworkTypes = " + powerAllowedNetworkTypes
- + " filteredType = " + filteredType);
+ int filteredRaf = (int) (modemRaf & getEffectiveAllowedNetworkTypes());
- mCi.setPreferredNetworkType(filteredType, response);
+ Rlog.d(LOG_TAG, "setAllowedNetworkTypes: modemRaf = " + modemRaf
+ + " filteredRaf = " + filteredRaf);
+ //TODO: Change to setAllowedNetworkTypeBitmap after 1.6 HAL is ready.
+ mCi.setPreferredNetworkType(RadioAccessFamily.getNetworkTypeFromRaf(filteredRaf), response);
mPreferredNetworkTypeRegistrants.notifyRegistrants();
}
/**
- * Query the preferred network type setting
+ * Query the allowed network types bitmask setting
*
- * @param response is callback message to report one of NT_*_TYPE
+ * @param response is callback message to report network types bitmask
*/
- public void getPreferredNetworkType(Message response) {
+ public void getAllowedNetworkTypesBitmask(Message response) {
+ //TODO: Change to getAllowedNetworkTypesBitmap after 1.6 HAL ready.
mCi.getPreferredNetworkType(response);
}
@@ -4225,8 +4312,7 @@
public void sendSubscriptionSettings(boolean restoreNetworkSelection) {
// Send settings down
- int type = PhoneFactory.calculatePreferredNetworkType(mContext, getSubId());
- setPreferredNetworkType(type, null);
+ updateAllowedNetworkTypes(null);
if (restoreNetworkSelection) {
restoreSavedNetworkSelection(null);
@@ -4236,8 +4322,7 @@
protected void setPreferredNetworkTypeIfSimLoaded() {
int subId = getSubId();
if (SubscriptionManager.isValidSubscriptionId(subId)) {
- int type = PhoneFactory.calculatePreferredNetworkType(mContext, getSubId());
- setPreferredNetworkType(type, null);
+ updateAllowedNetworkTypes(null);
}
}
diff --git a/src/java/com/android/internal/telephony/PhoneFactory.java b/src/java/com/android/internal/telephony/PhoneFactory.java
index 2ec2ecb..c3e2d3a 100644
--- a/src/java/com/android/internal/telephony/PhoneFactory.java
+++ b/src/java/com/android/internal/telephony/PhoneFactory.java
@@ -35,6 +35,7 @@
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.AnomalyReporter;
+import android.telephony.RadioAccessFamily;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.LocalLog;
@@ -407,32 +408,22 @@
}
/**
- * Returns the preferred network type that should be set in the modem.
+ * Returns the preferred network type bitmask that should be set in the modem.
*
- * @param context The current {@link Context}.
- * @return the preferred network mode that should be set.
+ * @param phoneId The phone's id.
+ * @return the preferred network mode bitmask that should be set.
*/
// TODO: Fix when we "properly" have TelephonyDevController/SubscriptionController ..
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
- public static int calculatePreferredNetworkType(Context context, int phoneSubId) {
- int networkType = android.provider.Settings.Global.getInt(context.getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
- -1 /* invalid network mode */);
- Rlog.d(LOG_TAG, "calculatePreferredNetworkType: phoneSubId = " + phoneSubId +
- " networkType = " + networkType);
-
- if (networkType == -1) {
- networkType = RILConstants.PREFERRED_NETWORK_MODE;
- try {
- networkType = TelephonyManager.getIntAtIndex(context.getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE,
- SubscriptionController.getInstance().getPhoneId(phoneSubId));
- } catch (SettingNotFoundException retrySnfe) {
- Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for "
- + "Settings.Global.PREFERRED_NETWORK_MODE");
- }
+ public static int calculatePreferredNetworkType(int phoneId) {
+ if (getPhone(phoneId) == null) {
+ Rlog.d(LOG_TAG, "Invalid phoneId return default network mode ");
+ return RadioAccessFamily.getRafFromNetworkType(RILConstants.PREFERRED_NETWORK_MODE);
}
-
+ int networkType = (int) getPhone(phoneId).getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
+ Rlog.d(LOG_TAG, "calculatePreferredNetworkType: phoneId = " + phoneId + " networkType = "
+ + networkType);
return networkType;
}
diff --git a/src/java/com/android/internal/telephony/PhoneNotifier.java b/src/java/com/android/internal/telephony/PhoneNotifier.java
index 3b2ab3d..82b1882 100644
--- a/src/java/com/android/internal/telephony/PhoneNotifier.java
+++ b/src/java/com/android/internal/telephony/PhoneNotifier.java
@@ -34,6 +34,7 @@
import android.telephony.ims.ImsReasonInfo;
import java.util.List;
+import java.util.Map;
/**
* {@hide}
@@ -123,5 +124,9 @@
void notifyPhysicalChannelConfig(Phone sender, List<PhysicalChannelConfig> configs);
/** Notify DataEnabled has changed. */
+
void notifyDataEnabled(Phone sender, boolean enabled, @DataEnabledReason int reason);
+
+ /** Notify Allowed Network Type has changed. */
+ void notifyAllowedNetworkTypesChanged(Phone sender, Map<Integer, Long> allowedNetworkType);
}
diff --git a/src/java/com/android/internal/telephony/RIL.java b/src/java/com/android/internal/telephony/RIL.java
index 48b4e2e..43e7276 100644
--- a/src/java/com/android/internal/telephony/RIL.java
+++ b/src/java/com/android/internal/telephony/RIL.java
@@ -3509,16 +3509,14 @@
}
@Override
- public void setAllowedNetworkTypeBitmask(
+ public void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message result) {
IRadio radioProxy = getRadioProxy(result);
if (radioProxy != null) {
if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
- if (result != null) {
- AsyncResult.forMessage(result, null,
- CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
- result.sendToTarget();
- }
+ // For older HAL, redirects the call to setPreferredNetworkType.
+ setPreferredNetworkType(
+ RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmask), result);
return;
}
@@ -3540,7 +3538,7 @@
}
@Override
- public void getAllowedNetworkTypeBitmask(Message result) {
+ public void getAllowedNetworkTypesBitmap(Message result) {
IRadio radioProxy = getRadioProxy(result);
if (radioProxy != null) {
if (mRadioVersion.less(RADIO_HAL_VERSION_1_6)) {
@@ -6932,6 +6930,10 @@
return "RIL_REQUEST_CANCEL_HANDOVER";
case RIL_REQUEST_SET_DATA_THROTTLING:
return "RIL_REQUEST_SET_DATA_THROTTLING";
+ case RIL_REQUEST_SET_ALLOWED_NETWORK_TYPE_BITMAP:
+ return "RIL_REQUEST_SET_ALLOWED_NETWORK_TYPE_BITMAP";
+ case RIL_REQUEST_GET_ALLOWED_NETWORK_TYPE_BITMAP:
+ return "RIL_REQUEST_GET_ALLOWED_NETWORK_TYPE_BITMAP";
default: return "<unknown request>";
}
}
diff --git a/src/java/com/android/internal/telephony/RadioResponse.java b/src/java/com/android/internal/telephony/RadioResponse.java
index 20e0568..974abb3 100644
--- a/src/java/com/android/internal/telephony/RadioResponse.java
+++ b/src/java/com/android/internal/telephony/RadioResponse.java
@@ -1048,7 +1048,7 @@
*/
public void getPreferredNetworkTypeResponse(RadioResponseInfo responseInfo, int nwType) {
mRil.mPreferredNetworkType = nwType;
- responseInts(responseInfo, nwType);
+ responseInts(responseInfo, RadioAccessFamily.getRafFromNetworkType(nwType));
}
/**
@@ -1060,10 +1060,9 @@
public void getPreferredNetworkTypeBitmapResponse(
RadioResponseInfo responseInfo, int halRadioAccessFamilyBitmap) {
- int networkType = RadioAccessFamily.getNetworkTypeFromRaf(
- RIL.convertToNetworkTypeBitMask(halRadioAccessFamilyBitmap));
- mRil.mPreferredNetworkType = networkType;
- responseInts(responseInfo, networkType);
+ int networkTypeBitmask = RIL.convertToNetworkTypeBitMask(halRadioAccessFamilyBitmap);
+ mRil.mPreferredNetworkType = RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmask);
+ responseInts(responseInfo, networkTypeBitmask);
}
/**
diff --git a/src/java/com/android/internal/telephony/ServiceStateTracker.java b/src/java/com/android/internal/telephony/ServiceStateTracker.java
index 5b91a7d..55d71b3 100755
--- a/src/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -76,6 +76,7 @@
import android.telephony.DataSpecificRegistrationInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhysicalChannelConfig;
+import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.ServiceState.RilRadioTechnology;
import android.telephony.SignalStrength;
@@ -265,9 +266,9 @@
protected static final int EVENT_SIM_RECORDS_LOADED = 16;
protected static final int EVENT_SIM_READY = 17;
protected static final int EVENT_LOCATION_UPDATES_ENABLED = 18;
- protected static final int EVENT_GET_PREFERRED_NETWORK_TYPE = 19;
- protected static final int EVENT_SET_PREFERRED_NETWORK_TYPE = 20;
- protected static final int EVENT_RESET_PREFERRED_NETWORK_TYPE = 21;
+ protected static final int EVENT_GET_ALLOWED_NETWORK_TYPE = 19;
+ protected static final int EVENT_SET_ALLOWED_NETWORK_TYPE = 20;
+ protected static final int EVENT_RESET_ALLOWED_NETWORK_TYPE = 21;
protected static final int EVENT_CHECK_REPORT_GPRS = 22;
protected static final int EVENT_RESTRICTED_STATE_CHANGED = 23;
@@ -1077,8 +1078,8 @@
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void reRegisterNetwork(Message onComplete) {
- mCi.getPreferredNetworkType(
- obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE, onComplete));
+ mCi.getAllowedNetworkTypesBitmap(
+ obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPE, onComplete));
}
/**
@@ -1477,14 +1478,14 @@
}
break;
- case EVENT_SET_PREFERRED_NETWORK_TYPE:
+ case EVENT_SET_ALLOWED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
// Don't care the result, only use for dereg network (COPS=2)
- message = obtainMessage(EVENT_RESET_PREFERRED_NETWORK_TYPE, ar.userObj);
- mCi.setPreferredNetworkType(mPreferredNetworkType, message);
+ message = obtainMessage(EVENT_RESET_ALLOWED_NETWORK_TYPE, ar.userObj);
+ mCi.setAllowedNetworkTypesBitmap(mPreferredNetworkType, message);
break;
- case EVENT_RESET_PREFERRED_NETWORK_TYPE:
+ case EVENT_RESET_ALLOWED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception
@@ -1493,19 +1494,21 @@
}
break;
- case EVENT_GET_PREFERRED_NETWORK_TYPE:
+ case EVENT_GET_ALLOWED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mPreferredNetworkType = ((int[])ar.result)[0];
} else {
- mPreferredNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
+ mPreferredNetworkType = RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.NETWORK_MODE_GLOBAL);
}
- message = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE, ar.userObj);
- int toggledNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
+ message = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPE, ar.userObj);
+ int toggledNetworkType = RadioAccessFamily.getRafFromNetworkType(
+ RILConstants.NETWORK_MODE_GLOBAL);
- mCi.setPreferredNetworkType(toggledNetworkType, message);
+ mCi.setAllowedNetworkTypesBitmap(toggledNetworkType, message);
break;
case EVENT_CHECK_REPORT_GPRS:
diff --git a/src/java/com/android/internal/telephony/SubscriptionController.java b/src/java/com/android/internal/telephony/SubscriptionController.java
index 2fbe9ab..8d79d22 100644
--- a/src/java/com/android/internal/telephony/SubscriptionController.java
+++ b/src/java/com/android/internal/telephony/SubscriptionController.java
@@ -3012,7 +3012,7 @@
value.put(propKey, Integer.parseInt(propValue));
break;
case SubscriptionManager.ALLOWED_NETWORK_TYPES:
- value.put(propKey, Long.parseLong(propValue));
+ value.put(propKey, propValue);
break;
default:
if (DBG) logd("Invalid column name");
diff --git a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
index 83d5c2b..923b835 100644
--- a/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
+++ b/src/java/com/android/internal/telephony/SubscriptionInfoUpdater.java
@@ -36,9 +36,6 @@
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.preference.PreferenceManager;
-import android.provider.Settings;
-import android.provider.Settings.Global;
-import android.provider.Settings.SettingNotFoundException;
import android.service.carrier.CarrierIdentifier;
import android.service.carrier.CarrierService;
import android.service.euicc.EuiccProfileInfo;
@@ -564,35 +561,17 @@
int storedSubId = sp.getInt(CURR_SUBID + phoneId, -1);
if (storedSubId != subId) {
- int networkType = Settings.Global.getInt(
- PhoneFactory.getPhone(phoneId).getContext().getContentResolver(),
- Settings.Global.PREFERRED_NETWORK_MODE + subId,
- -1 /* invalid network mode */);
-
- if (networkType == -1) {
- networkType = RILConstants.PREFERRED_NETWORK_MODE;
- try {
- networkType = TelephonyManager.getIntAtIndex(
- sContext.getContentResolver(),
- Settings.Global.PREFERRED_NETWORK_MODE, phoneId);
- } catch (SettingNotFoundException retrySnfe) {
- Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for "
- + "Settings.Global.PREFERRED_NETWORK_MODE");
- }
- Settings.Global.putInt(
- PhoneFactory.getPhone(phoneId).getContext().getContentResolver(),
- Global.PREFERRED_NETWORK_MODE + subId,
- networkType);
- }
+ long networkType = PhoneFactory.getPhone(phoneId).getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
// Set the modem network mode
- PhoneFactory.getPhone(phoneId).setPreferredNetworkType(networkType, null);
+ PhoneFactory.getPhone(phoneId).setAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, networkType, null);
// Only support automatic selection mode on SIM change.
PhoneFactory.getPhone(phoneId).getNetworkSelectionMode(
obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE,
new Integer(phoneId)));
-
// Update stored subId
SharedPreferences.Editor editor = sp.edit();
editor.putInt(CURR_SUBID + phoneId, subId);
diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCommandInterface.java b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCommandInterface.java
index 62a0fb5..f2f8738 100644
--- a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCommandInterface.java
+++ b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCommandInterface.java
@@ -459,12 +459,12 @@
}
@Override
- public void setAllowedNetworkTypeBitmask(
+ public void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response) {
}
@Override
- public void getAllowedNetworkTypeBitmask(Message response) {
+ public void getAllowedNetworkTypesBitmap(Message response) {
}
@Override
diff --git a/src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java b/src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java
index 7578690..627d20d 100644
--- a/src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java
+++ b/src/java/com/android/internal/telephony/metrics/TelephonyMetrics.java
@@ -790,7 +790,8 @@
Integer lastSimState = mLastSimState.get(phoneId);
if (lastSimState == null || !lastSimState.equals(state)) {
mLastSimState.put(phoneId, state);
- addTelephonyEvent(new TelephonyEventBuilder().setSimStateChange(mLastSimState).build());
+ addTelephonyEvent(
+ new TelephonyEventBuilder(phoneId).setSimStateChange(mLastSimState).build());
}
}
diff --git a/src/java/com/android/internal/telephony/sip/SipCommandInterface.java b/src/java/com/android/internal/telephony/sip/SipCommandInterface.java
index 4d0b9c5..342ddb8 100644
--- a/src/java/com/android/internal/telephony/sip/SipCommandInterface.java
+++ b/src/java/com/android/internal/telephony/sip/SipCommandInterface.java
@@ -460,12 +460,12 @@
}
@Override
- public void setAllowedNetworkTypeBitmask(
+ public void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response) {
}
@Override
- public void getAllowedNetworkTypeBitmask(Message response) {
+ public void getAllowedNetworkTypesBitmap(Message response) {
}
@Override
diff --git a/tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java
index 27ffeef..6f39f82 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java
@@ -31,9 +31,10 @@
import android.content.Intent;
import android.os.Message;
import android.os.PersistableBundle;
-import android.provider.Settings;
import android.telephony.CarrierConfigManager;
+import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
+import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -44,6 +45,7 @@
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -69,12 +71,15 @@
super.setUp(getClass().getSimpleName());
mBundle = mContextFixture.getCarrierConfigBundle();
when(mPhone.getSubId()).thenReturn(SUB_ID);
+
mCarrierSST = new CarrierServiceStateTracker(mPhone, mSST);
mSpyCarrierSST = spy(mCarrierSST);
mNotificationManager = (NotificationManager) mContext.getSystemService(
Context.NOTIFICATION_SERVICE);
+ setCarrierPrivilegesForSubId(true, SUB_ID);
+
setDefaultValues();
processAllMessages();
}
@@ -150,21 +155,30 @@
doReturn(true).when(mSST).isRadioOn();
doReturn(mNotificationBuilder).when(spyPrefNetworkNotification).getNotificationBuilder();
- String prefNetworkMode = Settings.Global.PREFERRED_NETWORK_MODE + mPhone.getSubId();
- Settings.Global.putInt(mContext.getContentResolver(), prefNetworkMode,
- RILConstants.NETWORK_MODE_LTE_CDMA_EVDO);
- mSpyCarrierSST.getContentObserver().dispatchChange(false,
- Settings.Global.getUriFor(prefNetworkMode));
+ Map<Integer, Long> allowedNetworkTypesList = new HashMap<>();
+ long networkType = (long) RadioAccessFamily.getRafFromNetworkType(
+ TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO);
+ allowedNetworkTypesList.put(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
+ networkType);
+ doReturn(networkType).when(mPhone).getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
+ mSpyCarrierSST.getAllowedNetworkTypesChangedListener().onAllowedNetworkTypesChanged(
+ allowedNetworkTypesList);
+
processAllMessages();
verify(mNotificationManager, atLeast(1)).notify(
eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG),
eq(SUB_ID), isA(Notification.class));
+ networkType = (long) RadioAccessFamily.getRafFromNetworkType(
+ TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
+ allowedNetworkTypesList.put(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
+ networkType);
+ doReturn(networkType).when(mPhone).getAllowedNetworkTypes(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
+ mSpyCarrierSST.getAllowedNetworkTypesChangedListener().onAllowedNetworkTypesChanged(
+ allowedNetworkTypesList);
- Settings.Global.putInt(mContext.getContentResolver(), prefNetworkMode,
- RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
- mSpyCarrierSST.getContentObserver().dispatchChange(false,
- Settings.Global.getUriFor(prefNetworkMode));
processAllMessages();
verify(mNotificationManager, atLeast(1)).cancel(
CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java b/tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java
index 5abcf16..5ec14e6 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/FakeTelephonyProvider.java
@@ -112,9 +112,10 @@
+ Telephony.SimInfo.COLUMN_IMSI + " TEXT,"
+ Telephony.SimInfo.COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS + " BLOB,"
+ Telephony.SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED + " INTEGER DEFAULT 1,"
- + Telephony.SimInfo.COLUMN_ALLOWED_NETWORK_TYPES + " BIGINT DEFAULT -1, "
+ + Telephony.SimInfo.COLUMN_ALLOWED_NETWORK_TYPES + " BIGINT DEFAULT -1,"
+ Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED + " INTEGER DEFAULT 0, "
- + Telephony.SimInfo.COLUMN_RCS_CONFIG + " BLOB"
+ + Telephony.SimInfo.COLUMN_RCS_CONFIG + " BLOB,"
+ + Telephony.SimInfo.COLUMN_ALLOWED_NETWORK_TYPES_FOR_REASONS + " TEXT"
+ ");";
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommands.java b/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommands.java
index e05872b..d2c65ee 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommands.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommands.java
@@ -1246,17 +1246,17 @@
}
@Override
- public void setAllowedNetworkTypeBitmask(
+ public void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response) {
SimulatedCommandsVerifier.getInstance()
- .setAllowedNetworkTypeBitmask(networkTypeBitmask, response);
+ .setAllowedNetworkTypesBitmap(networkTypeBitmask, response);
mAllowedNetworkType = networkTypeBitmask;
resultSuccess(response, null);
}
@Override
- public void getAllowedNetworkTypeBitmask(Message response) {
- SimulatedCommandsVerifier.getInstance().getAllowedNetworkTypeBitmask(response);
+ public void getAllowedNetworkTypesBitmap(Message response) {
+ SimulatedCommandsVerifier.getInstance().getAllowedNetworkTypesBitmap(response);
int[] ret = new int[1];
ret[0] = mAllowedNetworkType;
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommandsVerifier.java b/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommandsVerifier.java
index 0c73bbb..5d40fe6 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommandsVerifier.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/SimulatedCommandsVerifier.java
@@ -1061,13 +1061,13 @@
}
@Override
- public void setAllowedNetworkTypeBitmask(
+ public void setAllowedNetworkTypesBitmap(
@TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response) {
}
@Override
- public void getAllowedNetworkTypeBitmask(Message response) {
+ public void getAllowedNetworkTypesBitmap(Message response) {
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SipMessageParsingUtilsTest.java b/tests/telephonytests/src/com/android/internal/telephony/SipMessageParsingUtilsTest.java
deleted file mode 100644
index 50ca36a..0000000
--- a/tests/telephonytests/src/com/android/internal/telephony/SipMessageParsingUtilsTest.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.telephony;
-
-import static org.junit.Assert.assertEquals;
-
-import android.telephony.ims.SipMessage;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Test SIP Message parsing utilities in frameworks/base. see {@link SipMessageParsingUtils}.
- */
-@RunWith(AndroidJUnit4.class)
-public class SipMessageParsingUtilsTest {
-
- // Sample messages from RFC 3261 modified for parsing use cases.
- public static final SipMessage SIP_MESSAGE_1 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- // Typical Via
- "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds\n"
- + "Max-Forwards: 70\n"
- + "To: Bob <sip:bob@biloxi.com>\n"
- + "From: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- + "Call-ID: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "Contact: <sip:alice@pc33.atlanta.com>\n"
- + "Content-Type: application/sdp\n"
- + "Content-Length: 142",
- new byte[0]);
- public static final String SIP_MESSAGE_1_TRANSACTION_ID = "z9hG4bK776asdhds";
- public static final SipMessage SIP_MESSAGE_2 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- // include leading whitespace.
- " Max-Forwards: 70\n"
- + "To: Bob <sip:bob@biloxi.com>\n"
- + "From: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- + "Call-ID: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "Contact: <sip:alice@pc33.atlanta.com>\n"
- + "Content-Type: application/sdp\n"
- + "Content-Length: 142\n"
- // transaction ID should be returned for the first "Via"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKabcdefghi\n"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds\n",
-
- new byte[0]);
- public static final String SIP_MESSAGE_2_TRANSACTION_ID = "z9hG4bKabcdefghi";
- public static final SipMessage SIP_MESSAGE_3 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- "Max-Forwards: 70\n"
- + "To: Bob <sip:bob@biloxi.com>\n"
- + "From: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- // Subject line is split into multiple lines via space and tab.
- + "Subject: I know you're there,\n"
- + " pick up the phone\n"
- + "\tand talk to me!\n"
- // transaction ID should be returned for the first "Via"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKzyxwvutsr\n"
- + "Call-ID: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "Contact: <sip:alice@pc33.atlanta.com>\n"
- + "Content-Type: application/sdp\n"
- + "Content-Length: 142\n"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKabcdefghi\n",
- new byte[0]);
- public static final String SIP_MESSAGE_3_TRANSACTION_ID = "z9hG4bKzyxwvutsr";
- // compact form
- public static final SipMessage SIP_MESSAGE_4 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- "Max-Forwards: 70\n"
- + "t: Bob <sip:bob@biloxi.com>\n"
- + "f: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- // compat form of via
- + "v: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKAbCdEfGiJ\n"
- + "v: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKabcdefghi\n"
- + "i: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "m: <sip:alice@pc33.atlanta.com>\n"
- + "c: application/sdp\n"
- + "l: 142\n",
- new byte[0]);
- public static final String SIP_MESSAGE_4_TRANSACTION_ID = "z9hG4bKAbCdEfGiJ";
- public static final SipMessage SIP_MESSAGE_5 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- "Max-Forwards: 70\n"
- + "To: Bob <sip:bob@biloxi.com>\n"
- + "From: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- // Malformed lines
- + "Subject: I know you're there,\n"
- + "pick up the phone\n"
- + "and talk to me!\n"
- // transaction ID should be returned for the first "Via"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKzyxwvutsr\n"
- + "Call-ID: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "Contact: <sip:alice@pc33.atlanta.com>\n"
- + "Content-Type: application/sdp\n"
- + "Content-Length: 142\n"
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKabcdefghi\n",
- new byte[0]);
- public static final String SIP_MESSAGE_5_TRANSACTION_ID = "z9hG4bKzyxwvutsr";
- // Not practical, but ensure that parsing works, even in special cases like one line.
- public static final SipMessage SIP_MESSAGE_6 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKabcdefghi\n",
- new byte[0]);
- public static final String SIP_MESSAGE_6_TRANSACTION_ID = "z9hG4bKabcdefghi";
- public static final SipMessage SIP_MESSAGE_7 = new SipMessage(
- "INVITE sip:bob@biloxi.com SIP/2.0",
- "Max-Forwards: 70\n"
- + "To: Bob <sip:bob@biloxi.com>\n"
- + "From: Alice <sip:alice@atlanta.com>;tag=1928301774\n"
- + "Call-ID: a84b4c76e66710@pc33.atlanta.com\n"
- + "CSeq: 314159 INVITE\n"
- + "Contact: <sip:alice@pc33.atlanta.com>\n"
- + "Content-Type: application/sdp\n"
- + "Content-Length: 142\n"
- // Typical Via, but on last line to test edge conditions
- + "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds",
- new byte[0]);
- public static final String SIP_MESSAGE_7_TRANSACTION_ID = "z9hG4bK776asdhds";
- // SIP Message from RFC 4475 "A Short Tortuous INVITE"
- public static final SipMessage SIP_MESSAGE_8 = new SipMessage(
- "INVITE sip:vivekg@chair-dnrc.example.com;unknownparam SIP/2.0",
- "TO :\n"
- + " sip:vivekg@chair-dnrc.example.com ; tag = 1918181833n\n"
- + "from : \"J Rosenberg \\\\\\\"\" <sip:jdrosen@example.com>\n"
- + " ;\n"
- + " tag = 98asjd8\n"
- + "MaX-fOrWaRdS: 0068\n"
- + "Call-ID: wsinv.ndaksdj@192.0.2.1\n"
- + "Content-Length : 150\n"
- + "cseq: 0009\n"
- + " INVITE\n"
- + "s :\n"
- + "NewFangledHeader: newfangled value\n"
- + " continued newfangled value\n"
- + "UnknownHeaderWithUnusualValue: ;;,,;;,;\n"
- + "Content-Type: application/sdp\n"
- + "Route:\n"
- + " <sip:services.example.com;lr;unknownwith=value;unknown-no-value>\n"
- // Note, this has multiple Via headers concatenated with one header key, we
- // should return the first in the list.
- + "v: SIP / 2.0 / TCP spindle.example.com ;\n"
- + " branch = z9hG4bK9ikj8 ,\n"
- + " SIP / 2.0 / UDP 192.168.255.111 ; branch=\n"
- + " z9hG4bK30239\n"
- + "Via : SIP / 2.0\n"
- + " /UDP\n"
- + " 192.0.2.2;branch=z9hG4bK390skdjuw\n"
- + "m:\"Quoted string \\\"\\\"\" <sip:jdrosen@example.com> ; newparam =\n"
- + " newvalue ;\n"
- + " secondparam ; q = 0.33",
- new byte[0]);
- public static final String SIP_MESSAGE_8_TRANSACTION_ID = "z9hG4bK9ikj8";
-
- @Test
- @SmallTest
- public void testGetTransactionId() {
- assertEquals(SIP_MESSAGE_1_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_1.getHeaderSection()));
- assertEquals(SIP_MESSAGE_2_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_2.getHeaderSection()));
- assertEquals(SIP_MESSAGE_3_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_3.getHeaderSection()));
- assertEquals(SIP_MESSAGE_4_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_4.getHeaderSection()));
- assertEquals(SIP_MESSAGE_5_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_5.getHeaderSection()));
- assertEquals(SIP_MESSAGE_6_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_6.getHeaderSection()));
- assertEquals(SIP_MESSAGE_7_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_7.getHeaderSection()));
- assertEquals(SIP_MESSAGE_8_TRANSACTION_ID, SipMessageParsingUtils.getTransactionId(
- SIP_MESSAGE_8.getHeaderSection()));
- }
-}