Apply new network selection api on NetworkSelect fragment

This applies the new manual network selection api on NetworkSelect
fragment.

We also notifies the NotificationMgr when the network selection is
changed by the user, so the Network selection fragment no need to call
NotificationMgr.updateNetworkSelection when the network selection is
failed.

Bug: 110820484
Test: manually test
Merged-In: I8bc50d270edd9bbd556bad235122b0bfe366222e
Change-Id: I8bc50d270edd9bbd556bad235122b0bfe366222e
diff --git a/src/com/android/phone/NetworkOperators.java b/src/com/android/phone/NetworkOperators.java
index 7e54a1b..6d798b0 100644
--- a/src/com/android/phone/NetworkOperators.java
+++ b/src/com/android/phone/NetworkOperators.java
@@ -195,12 +195,6 @@
     // Used by both mAutoSelect and mNetworkSelect buttons.
     protected void displayNetworkSelectionFailed() {
         Toast.makeText(getContext(), R.string.connect_later, Toast.LENGTH_LONG).show();
-
-        final PhoneGlobals app = PhoneGlobals.getInstance();
-        ServiceState ss = mTelephonyManager.getServiceStateForSubscriber(mSubId);
-        if (ss != null) {
-            app.notificationMgr.updateNetworkSelection(ss.getState(), mSubId);
-        }
     }
 
     // Used by both mAutoSelect and mNetworkSelect buttons.
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index cec914a..5b841c9 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -403,8 +403,7 @@
                 final OperatorInfo operatorInfo = getOperatorInfoFromCellInfo(mCellInfo);
                 if (DBG) logd("manually selected network: " + operatorInfo.toString());
                 boolean isSuccessed = mTelephonyManager.setNetworkSelectionModeManual(
-                        operatorInfo.getOperatorNumeric(), true /* persistSelection */);
-                int mode = mTelephonyManager.getNetworkSelectionMode();
+                        operatorInfo, true /* persistSelection */);
                 Message msg = mHandler.obtainMessage(EVENT_MANUALLY_NETWORK_SELECTION_DONE);
                 msg.obj = isSuccessed;
                 msg.sendToTarget();
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 56f0187..cd848ef 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -217,7 +217,7 @@
                 ThreadUtils.postOnBackgroundThread(() -> {
                     Message msg = mHandler.obtainMessage(EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE);
                     msg.obj = mTelephonyManager.setNetworkSelectionModeManual(
-                            operatorInfo.getOperatorNumeric(), true /* persistSelection */);
+                            operatorInfo, true /* persistSelection */);
                     msg.sendToTarget();
                 });
 
@@ -268,7 +268,6 @@
                         mSelectedNetworkOperatorPreference.setSummary(R.string.network_connected);
                     } else {
                         if (DBG) logd("manual network selection: failed! ");
-                        updateNetworkSelection();
                         // Set summary as "Couldn't connect" to the selected network.
                         mSelectedNetworkOperatorPreference.setSummary(
                                 R.string.network_could_not_connect);
@@ -617,21 +616,6 @@
         }
     }
 
-    /**
-     * Call {@link NotificationMgr#updateNetworkSelection(int, int)} to send notification about
-     * no service of user selected operator
-     */
-    private void updateNetworkSelection() {
-        if (DBG) logd("Update notification about no service of user selected operator");
-        final PhoneGlobals app = PhoneGlobals.getInstance();
-        if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
-            ServiceState ss = mTelephonyManager.getServiceState();
-            if (ss != null) {
-                app.notificationMgr.updateNetworkSelection(ss.getState(), mSubId);
-            }
-        }
-    }
-
     private void stopNetworkQuery() {
         // Stop the network query process
         try {
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index d0b236f..67ec932 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -865,6 +865,20 @@
     }
 
     /**
+     * Called when the network selection on the subscription {@code subId} is changed by the user.
+     *
+     * @param subId the subscription id.
+     */
+    public void onNetworkSelectionChanged(int subId) {
+        Phone phone = getPhone(subId);
+        if (phone != null) {
+            notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
+        } else {
+            Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
+        }
+    }
+
+    /**
      * Dismisses the message waiting (voicemail) indicator.
      *
      * @param subId the subscription id we should dismiss the notification for.
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 0653735..353f4b5 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -764,7 +764,16 @@
                     break;
 
                 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
-                    handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
+                    ar = (AsyncResult) msg.obj;
+                    request = (MainThreadRequest) ar.userObj;
+                    if (ar.exception == null) {
+                        request.result = true;
+                    } else {
+                        request.result = false;
+                        loge("setNetworkSelectionModeManual " + ar.exception);
+                    }
+                    notifyRequester(request);
+                    mApp.onNetworkSelectionChanged(request.subId);
                     break;
 
                 case CMD_GET_MODEM_ACTIVITY_INFO: