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
Change-Id: I8bc50d270edd9bbd556bad235122b0bfe366222e
diff --git a/src/com/android/phone/NetworkOperators.java b/src/com/android/phone/NetworkOperators.java
index 3004cd5..34c92c0 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 8d947f7..a2a1080 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -404,8 +404,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 6aaaf9d..97c1bd1 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -218,7 +218,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();
                 });
 
@@ -269,7 +269,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);
@@ -618,21 +617,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 ba36f1b..0792019 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -864,6 +864,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 abfa8d7..038f8b1 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -767,7 +767,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: