Merge "[Provider Model] Update the string to latest." into sc-dev am: e1880f026e am: 1b604e33ac

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/13417066

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4e7eaea4f90b14535810f030e337a881815f513b
diff --git a/src/com/android/settings/network/telephony/NetworkProviderWorker.java b/src/com/android/settings/network/telephony/NetworkProviderWorker.java
index e2e0264..50c56cf 100644
--- a/src/com/android/settings/network/telephony/NetworkProviderWorker.java
+++ b/src/com/android/settings/network/telephony/NetworkProviderWorker.java
@@ -43,8 +43,6 @@
 import com.android.settingslib.mobile.MobileMappings.Config;
 
 import java.util.Collections;
-import java.util.concurrent.Executor;
-
 
 /**
  * BackgroundWorker for Provider Model slice.
@@ -63,6 +61,7 @@
     private DataConnectivityListener mConnectivityListener;
     private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
     private final Context mContext;
+    final Handler mHandler;
     @VisibleForTesting
     final PhoneStateListener mPhoneStateListener;
     private TelephonyManager mTelephonyManager;
@@ -76,15 +75,15 @@
     public NetworkProviderWorker(Context context, Uri uri) {
         super(context, uri);
         // Mobile data worker
-        final Handler handler = new Handler(Looper.getMainLooper());
-        mMobileDataObserver = new DataContentObserver(handler, this);
+        mHandler = new Handler(Looper.getMainLooper());
+        mMobileDataObserver = new DataContentObserver(mHandler, this);
 
         mContext = context;
         mDefaultDataSubid = getDefaultDataSubscriptionId();
 
         mTelephonyManager = mContext.getSystemService(
                 TelephonyManager.class).createForSubscriptionId(mDefaultDataSubid);
-        mPhoneStateListener = new NetworkProviderPhoneStateListener(handler::post);
+        mPhoneStateListener = new NetworkProviderPhoneStateListener();
         mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
         mDataEnabledListener = new MobileDataEnabledListener(context, this);
         mConnectivityListener = new DataConnectivityListener(context, this);
@@ -102,9 +101,7 @@
         mDataEnabledListener.start(mDefaultDataSubid);
         mConnectivityListener.start();
         mSignalStrengthListener.resume();
-        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE
-                | PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
-
+        mTelephonyManager.registerPhoneStateListener(mHandler::post, mPhoneStateListener);
         super.onSlicePinned();
     }
 
@@ -115,7 +112,7 @@
         mDataEnabledListener.stop();
         mConnectivityListener.stop();
         mSignalStrengthListener.pause();
-        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+        mTelephonyManager.unregisterPhoneStateListener(mPhoneStateListener);
         super.onSliceUnpinned();
     }
 
@@ -145,13 +142,12 @@
             return;
         }
         if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) {
-            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+            mTelephonyManager.unregisterPhoneStateListener(mPhoneStateListener);
             mMobileDataObserver.unregister(mContext);
 
             mSignalStrengthListener.updateSubscriptionIds(Collections.singleton(defaultDataSubId));
             mTelephonyManager = mTelephonyManager.createForSubscriptionId(defaultDataSubId);
-            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE
-                    | PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
+            mTelephonyManager.registerPhoneStateListener(mHandler::post, mPhoneStateListener);
             mMobileDataObserver.register(mContext, mDefaultDataSubid);
             mConfig = getConfig(mContext);
         } else {
@@ -221,11 +217,10 @@
         }
     }
 
-    class NetworkProviderPhoneStateListener extends PhoneStateListener {
-        NetworkProviderPhoneStateListener(Executor executor) {
-            super(executor);
-        }
-
+    class NetworkProviderPhoneStateListener extends PhoneStateListener implements
+            PhoneStateListener.DataConnectionStateChangedListener,
+            PhoneStateListener.DisplayInfoChangedListener,
+            PhoneStateListener.ServiceStateChangedListener {
         @Override
         public void onServiceStateChanged(ServiceState state) {
             Log.d(TAG, "onServiceStateChanged voiceState=" + state.getState()
@@ -239,6 +234,13 @@
             mTelephonyDisplayInfo = telephonyDisplayInfo;
             updateSlice();
         }
+
+        @Override
+        public void onDataConnectionStateChanged(int state, int networkType) {
+            Log.d(TAG,
+                    "onDataConnectionStateChanged: networkType=" + networkType + " state=" + state);
+            updateSlice();
+        }
     }
 
     @VisibleForTesting
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java
index 1905e44..2ce9a51 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWorkerTest.java
@@ -229,6 +229,18 @@
     }
 
     @Test
+    @UiThreadTest
+    public void onDataConnectionStateChanged_notifyPhoneStateListener_callUpdateSlice() {
+        mMockNetworkProviderWorker.onSlicePinned();
+        mMockNetworkProviderWorker.receiveNotification(false);
+
+        mMockNetworkProviderWorker.mPhoneStateListener.onDataConnectionStateChanged(
+                TelephonyManager.DATA_DISCONNECTED, TelephonyManager.NETWORK_TYPE_LTE);
+
+        assertThat(mMockNetworkProviderWorker.hasNotification()).isTrue();
+    }
+
+    @Test
     public void onInternetTypeChanged_connectedFromWifiToEthernet_callUpdateSlice() {
         mMockNetworkProviderWorker.receiveNotification(false);
         mMockNetworkProviderWorker.onInternetTypeChanged(INTERNET_WIFI);