Merge "Fix NPE in AnomalyDetectionReceiver."
diff --git a/res/drawable/ic_sim_card.xml b/res/drawable/ic_sim_card.xml
new file mode 100644
index 0000000..1fc7249
--- /dev/null
+++ b/res/drawable/ic_sim_card.xml
@@ -0,0 +1,43 @@
+<!--
+  Copyright (C) 2020 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.
+  -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?android:attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M14.5,2H8L4,6v10.5C4,17.33 4.67,18 5.5,18h9c0.83,0 1.5,-0.67 1.5,-1.5v-13C16,2.67 15.33,2 14.5,2zM14.5,16.5h-9V6.62L8.62,3.5h5.88V16.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M6.5,9h1.5v3h-1.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M6.5,13.5h1.5v1.5h-1.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M12,13.5h1.5v1.5h-1.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M9.25,9h1.5v1.5h-1.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M12,9h1.5v3h-1.5z"/>
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M9.25,12h1.5v3h-1.5z"/>
+</vector>
diff --git a/res/xml/network_provider_internet.xml b/res/xml/network_provider_internet.xml
index 3e798ab..8a7cdb8 100644
--- a/res/xml/network_provider_internet.xml
+++ b/res/xml/network_provider_internet.xml
@@ -48,7 +48,7 @@
         android:key="mobile_network_list"
         android:title="@string/provider_network_settings_title"
         android:summary="@string/summary_placeholder"
-        android:icon="@drawable/ic_network_cell"
+        android:icon="@drawable/ic_sim_card"
         android:order="-15"
         settings:keywords="@string/keywords_more_mobile_networks"
         settings:userRestriction="no_config_mobile_networks"
diff --git a/res/xml/transcode_settings.xml b/res/xml/transcode_settings.xml
index 9fff3fd..c6fbdfd 100644
--- a/res/xml/transcode_settings.xml
+++ b/res/xml/transcode_settings.xml
@@ -29,5 +29,5 @@
     <PreferenceCategory
         android:key="transcode_skip_apps"
         android:title="@string/transcode_skip_apps"
-        settings:controller="com.android.settings.development.transcode.TranscodeSkipAppsPreferenceController" />
+        settings:controller="com.android.settings.development.transcode.TranscodeAppsPreferenceController" />
 </PreferenceScreen>
diff --git a/src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeAppsPreferenceController.java
similarity index 74%
rename from src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceController.java
rename to src/com/android/settings/development/transcode/TranscodeAppsPreferenceController.java
index defe821..5593d7a 100644
--- a/src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeAppsPreferenceController.java
@@ -33,19 +33,19 @@
 import java.util.List;
 
 /**
- * The controller for the "Skip transcoding for apps" section on the transcode settings
+ * The controller for the "Enable transcoding for apps" section on the transcode settings
  * screen.
  */
-public class TranscodeSkipAppsPreferenceController extends BasePreferenceController implements
+public class TranscodeAppsPreferenceController extends BasePreferenceController implements
         Preference.OnPreferenceChangeListener {
 
-    private static final String SKIP_SELECTED_APPS_PROP_KEY =
-            "persist.sys.fuse.transcode_skip_uids";
+    private static final String TRANSCODE_SELECTED_APPS_PROP_KEY =
+            "persist.sys.fuse.transcode_uids";
 
     private final PackageManager mPackageManager;
-    private final List<String> mUidsToSkip = new ArrayList<>();
+    private final List<String> mUids = new ArrayList<>();
 
-    public TranscodeSkipAppsPreferenceController(Context context,
+    public TranscodeAppsPreferenceController(Context context,
             String preferenceKey) {
         super(context, preferenceKey);
         mPackageManager = context.getPackageManager();
@@ -60,8 +60,8 @@
     public void displayPreference(PreferenceScreen screen) {
         super.displayPreference(screen);
         final Context context = screen.getContext();
-        mUidsToSkip.addAll(Arrays.asList(
-                SystemProperties.get(SKIP_SELECTED_APPS_PROP_KEY).split(",")));
+        mUids.addAll(Arrays.asList(
+                SystemProperties.get(TRANSCODE_SELECTED_APPS_PROP_KEY).split(",")));
         Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
         launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
         List<ResolveInfo> apps = mPackageManager.queryIntentActivities(launcherIntent, 0);
@@ -71,7 +71,7 @@
             preference.setTitle(app.loadLabel(mPackageManager));
             preference.setIcon(app.loadIcon(mPackageManager));
             preference.setKey(uid);
-            preference.setChecked(isSkippedForTranscoding(uid));
+            preference.setChecked(isSelectedForTranscoding(uid));
             preference.setOnPreferenceChangeListener(this);
 
             screen.addPreference(preference);
@@ -83,15 +83,15 @@
         boolean value = (Boolean) o;
         String uidStr = preference.getKey();
         if (value) {
-            mUidsToSkip.add(uidStr);
+            mUids.add(uidStr);
         } else {
-            mUidsToSkip.remove(uidStr);
+            mUids.remove(uidStr);
         }
-        SystemProperties.set(SKIP_SELECTED_APPS_PROP_KEY, String.join(",", mUidsToSkip));
+        SystemProperties.set(TRANSCODE_SELECTED_APPS_PROP_KEY, String.join(",", mUids));
         return true;
     }
 
-    private boolean isSkippedForTranscoding(String uid) {
-        return mUidsToSkip.contains(uid);
+    private boolean isSelectedForTranscoding(String uid) {
+        return mUids.contains(uid);
     }
 }
diff --git a/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java b/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
index b11bb58..643adfc 100644
--- a/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
+++ b/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceController.java
@@ -22,7 +22,7 @@
 import com.android.settings.core.TogglePreferenceController;
 
 /**
- * The controller for the "Enable transcode for all apps" switch on the transcode settings
+ * The controller for the "Disable transcoding for all apps" switch on the transcode settings
  * screen.
  */
 public class TranscodeGlobalTogglePreferenceController extends TogglePreferenceController {
@@ -41,12 +41,12 @@
 
     @Override
     public boolean isChecked() {
-        return SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false);
+        return !SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false);
     }
 
     @Override
     public boolean setChecked(boolean isChecked) {
-        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, String.valueOf(isChecked));
+        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, String.valueOf(!isChecked));
         return true;
     }
 }
diff --git a/src/com/android/settings/network/MobileNetworkSummaryController.java b/src/com/android/settings/network/MobileNetworkSummaryController.java
index 9e3f1e8..405d365 100644
--- a/src/com/android/settings/network/MobileNetworkSummaryController.java
+++ b/src/com/android/settings/network/MobileNetworkSummaryController.java
@@ -45,6 +45,7 @@
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 public class MobileNetworkSummaryController extends AbstractPreferenceController implements
         SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver,
@@ -124,12 +125,20 @@
                 return subs.get(0).getDisplayName();
             }
         } else {
+            if (com.android.settings.Utils.isProviderModelEnabled(mContext)) {
+                return getSummaryForProviderModel(subs);
+            }
             final int count = subs.size();
             return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count,
                     count, count);
         }
     }
 
+    private CharSequence getSummaryForProviderModel(List<SubscriptionInfo> subs) {
+        return String.join(", ", subs.stream().map(SubscriptionInfo::getDisplayName)
+                .collect(Collectors.toList()));
+    }
+
     private void startAddSimFlow() {
         final Intent intent = new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION);
         intent.putExtra(EuiccManager.EXTRA_FORCE_PROVISION, true);
diff --git a/tests/robotests/src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/transcode/TranscodeAppsPreferenceControllerTest.java
similarity index 82%
rename from tests/robotests/src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/development/transcode/TranscodeAppsPreferenceControllerTest.java
index f1fce9f..b31f727 100644
--- a/tests/robotests/src/com/android/settings/development/transcode/TranscodeSkipAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/transcode/TranscodeAppsPreferenceControllerTest.java
@@ -51,24 +51,24 @@
 import java.util.Collections;
 
 @RunWith(RobolectricTestRunner.class)
-public class TranscodeSkipAppsPreferenceControllerTest {
+public class TranscodeAppsPreferenceControllerTest {
 
     private static final int APPLICATION_UID = 1234;
-    private static final String SKIP_SELECTED_APPS_PROP_KEY =
-            "persist.sys.fuse.transcode_skip_uids";
+    private static final String TRANSCODE_SELECTED_APPS_PROP_KEY =
+            "persist.sys.fuse.transcode_uids";
 
     @Mock
     private PreferenceScreen mScreen;
     private Context mContext;
     private ShadowPackageManager mShadowPackageManager;
-    private TranscodeSkipAppsPreferenceController mController;
+    private TranscodeAppsPreferenceController mController;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = ApplicationProvider.getApplicationContext();
         mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
-        mController = new TranscodeSkipAppsPreferenceController(mContext, "test_key");
+        mController = new TranscodeAppsPreferenceController(mContext, "test_key");
         Preference preference = new Preference(mContext);
 
         when(mScreen.getContext()).thenReturn(mContext);
@@ -99,28 +99,28 @@
     }
 
     @Test
-    public void preferenceChecked_shouldSkipApp() {
-        // First ensure that the app is not in skip list.
-        SystemProperties.set(SKIP_SELECTED_APPS_PROP_KEY, String.valueOf(-1));
+    public void preferenceChecked_shouldSelectApp() {
+        // First ensure that the app is not selected.
+        SystemProperties.set(TRANSCODE_SELECTED_APPS_PROP_KEY, String.valueOf(-1));
         SwitchPreference switchPreference = createPreference(/* defaultCheckedState = */ false);
 
         switchPreference.performClick();
 
-        // Verify that the app is added to skip list.
-        assertThat(SystemProperties.get(SKIP_SELECTED_APPS_PROP_KEY)).contains(
+        // Verify that the app is selected.
+        assertThat(SystemProperties.get(TRANSCODE_SELECTED_APPS_PROP_KEY)).contains(
                 String.valueOf(APPLICATION_UID));
     }
 
     @Test
-    public void preferenceUnchecked_shouldNotSkipApp() {
-        // First ensure that the app is in skip list.
-        SystemProperties.set(SKIP_SELECTED_APPS_PROP_KEY, String.valueOf(APPLICATION_UID));
+    public void preferenceUnchecked_shouldUnSelectApp() {
+        // First ensure that the app is selected.
+        SystemProperties.set(TRANSCODE_SELECTED_APPS_PROP_KEY, String.valueOf(APPLICATION_UID));
         SwitchPreference switchPreference = createPreference(/* defaultCheckedState = */ true);
 
         switchPreference.performClick();
 
-        // Verify that the app is removed from skip list.
-        assertThat(SystemProperties.get(SKIP_SELECTED_APPS_PROP_KEY)).doesNotContain(
+        // Verify that the app is not selected.
+        assertThat(SystemProperties.get(TRANSCODE_SELECTED_APPS_PROP_KEY)).doesNotContain(
                 String.valueOf(APPLICATION_UID));
     }
 
diff --git a/tests/robotests/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
index f4e3e71..b22bf9d 100644
--- a/tests/robotests/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/transcode/TranscodeGlobalTogglePreferenceControllerTest.java
@@ -47,14 +47,14 @@
     }
 
     @Test
-    public void isChecked_whenEnabled_shouldReturnTrue() {
-        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "true");
+    public void isChecked_whenDisabled_shouldReturnTrue() {
+        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "false");
         assertThat(mController.isChecked()).isTrue();
     }
 
     @Test
-    public void isChecked_whenDisabled_shouldReturnTrue() {
-        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "false");
+    public void isChecked_whenEnabled_shouldReturnFalse() {
+        SystemProperties.set(TRANSCODE_ENABLED_PROP_KEY, "true");
         assertThat(mController.isChecked()).isFalse();
     }
 
@@ -63,8 +63,8 @@
         // Simulate the UI being clicked.
         mController.setChecked(true);
 
-        // Verify the system property was updated with the UI value.
-        assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false)).isTrue();
+        // Verify the system property was updated.
+        assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, true)).isFalse();
     }
 
     @Test
@@ -72,7 +72,7 @@
         // Simulate the UI being clicked.
         mController.setChecked(false);
 
-        // Verify the system property was updated with the UI value.
-        assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, true)).isFalse();
+        // Verify the system property was updated.
+        assertThat(SystemProperties.getBoolean(TRANSCODE_ENABLED_PROP_KEY, false)).isTrue();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
index f6bc05a..6cf5896 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
@@ -23,6 +23,7 @@
 import static org.mockito.ArgumentMatchers.notNull;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
@@ -39,10 +40,12 @@
 import android.telephony.TelephonyManager;
 import android.telephony.euicc.EuiccManager;
 import android.text.TextUtils;
+import android.util.FeatureFlagUtils;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.preference.PreferenceScreen;
 
+import com.android.settings.core.FeatureFlags;
 import com.android.settings.network.telephony.MobileNetworkActivity;
 import com.android.settings.widget.AddPreference;
 import com.android.settingslib.RestrictedLockUtils;
@@ -61,7 +64,6 @@
 import java.util.Arrays;
 
 @RunWith(RobolectricTestRunner.class)
-@Ignore
 public class MobileNetworkSummaryControllerTest {
     @Mock
     private Lifecycle mLifecycle;
@@ -84,10 +86,11 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
-        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
-        when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
-        when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
-        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
+        doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
+        doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
+        doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
+
         when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
         when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
         when(mEuiccManager.isEnabled()).thenReturn(true);
@@ -211,6 +214,7 @@
 
     @Test
     public void getSummary_twoSubscriptions_correctSummaryAndFragment() {
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
         final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
         final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
         when(sub1.getSubscriptionId()).thenReturn(1);
@@ -225,6 +229,7 @@
 
     @Test
     public void getSummaryAfterUpdate_twoSubscriptionsBecomesOne_correctSummaryAndFragment() {
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
         final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
         final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
         when(sub1.getSubscriptionId()).thenReturn(1);
@@ -253,6 +258,7 @@
 
     @Test
     public void getSummaryAfterUpdate_oneSubscriptionBecomesTwo_correctSummaryAndFragment() {
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
         final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
         final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
         when(sub1.getSubscriptionId()).thenReturn(1);
@@ -280,6 +286,27 @@
     }
 
     @Test
+    public void getSummary_providerModel_Enabled() {
+        final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
+        final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
+        when(sub1.getSubscriptionId()).thenReturn(1);
+        when(sub2.getSubscriptionId()).thenReturn(2);
+        when(sub1.getDisplayName()).thenReturn("sub1");
+        when(sub2.getDisplayName()).thenReturn("sub2");
+
+        SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
+        mController.displayPreference(mPreferenceScreen);
+        mController.onResume();
+        assertThat(mController.getSummary()).isEqualTo("sub1, sub2");
+
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
+        mController.displayPreference(mPreferenceScreen);
+        mController.onResume();
+        assertThat(mController.getSummary()).isEqualTo("2 SIMs");
+    }
+
+    @Test
     public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() {
         when(mEuiccManager.isEnabled()).thenReturn(false);
         mController.displayPreference(mPreferenceScreen);