Fix to show the network selection no service notification
NotificationMgr uses the CallManager's default phone which could
be IMSPhone if IMSphone registers first. The notification wasn't
shown because of TelephonyCapabilities.supportsNetworkSelection
failed because the phone used is IMSPhone. The fix uses the phone
derived from the subId of ACTION_SERVICE_STATE_CHANGED intent
instead of using CallManager's default phone.
Test: Manually selected a forbidden PLMN and verified the network
selection no service notifcation.
Bug: 38117310
Change-Id: I62dce24cab349322ee3f4f59ebee1524abb55f91
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 69c0871..bc67fd5 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -53,6 +53,7 @@
import android.widget.Toast;
import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.TelephonyCapabilities;
import com.android.internal.telephony.util.NotificationChannelController;
import com.android.phone.settings.VoicemailSettingsActivity;
@@ -92,7 +93,6 @@
private static NotificationMgr sInstance;
private PhoneGlobals mApp;
- private Phone mPhone;
private Context mContext;
private NotificationManager mNotificationManager;
@@ -121,7 +121,6 @@
mStatusBarManager =
(StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE);
mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
- mPhone = app.mCM.getDefaultPhone();
mSubscriptionManager = SubscriptionManager.from(mContext);
mTelecomManager = TelecomManager.from(mContext);
mTelephonyManager = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE);
@@ -574,8 +573,9 @@
/**
* Display the network selection "no service" notification
* @param operator is the numeric operator number
+ * @param subId is the subscription ID
*/
- private void showNetworkSelection(String operator) {
+ private void showNetworkSelection(String operator, int subId) {
if (DBG) log("showNetworkSelection(" + operator + ")...");
Notification.Builder builder = new Notification.Builder(mContext)
@@ -595,7 +595,7 @@
intent.setComponent(new ComponentName(
mContext.getString(R.string.network_operator_settings_package),
mContext.getString(R.string.network_operator_settings_class)));
- intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, mPhone.getSubId());
+ intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, subId);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
List<UserInfo> users = mUserManager.getUsers(true);
@@ -627,10 +627,13 @@
* Update notification about no service of user selected operator
*
* @param serviceState Phone service state
+ * @param subId The subscription ID
*/
- void updateNetworkSelection(int serviceState) {
- if (TelephonyCapabilities.supportsNetworkSelection(mPhone)) {
- int subId = mPhone.getSubId();
+ void updateNetworkSelection(int serviceState, int subId) {
+ int phoneId = SubscriptionManager.getPhoneId(subId);
+ Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
+ PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
+ if (TelephonyCapabilities.supportsNetworkSelection(phone)) {
if (SubscriptionManager.isValidSubscriptionId(subId)) {
// get the shared preference of network_selection.
// empty is auto mode, otherwise it is the operator alpha name
@@ -649,7 +652,7 @@
if (serviceState == ServiceState.STATE_OUT_OF_SERVICE
&& !TextUtils.isEmpty(networkSelection)) {
- showNetworkSelection(networkSelection);
+ showNetworkSelection(networkSelection, subId);
mSelectedUnavailableNotify = true;
} else {
if (mSelectedUnavailableNotify) {