Merge "Use SettingsLib's MainSwitchPreference to replace the Switches which use LayoutPreference."
diff --git a/src/com/android/settings/TestingSettingsBroadcastReceiver.java b/src/com/android/settings/TestingSettingsBroadcastReceiver.java
index 0e1296b..30a0d79 100644
--- a/src/com/android/settings/TestingSettingsBroadcastReceiver.java
+++ b/src/com/android/settings/TestingSettingsBroadcastReceiver.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
 package com.android.settings;
 
 import android.content.BroadcastReceiver;
@@ -15,7 +31,8 @@
 
     @Override
     public void onReceive(Context context, Intent intent) {
-        if (intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE)) {
+        if (intent != null && intent.getAction() != null
+                && intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE)) {
             Intent i = new Intent(Intent.ACTION_MAIN);
             i.setClass(context, TestingSettingsActivity.class);
             i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
diff --git a/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java b/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java
index 0ad241e..1b3ee10 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java
@@ -143,8 +143,8 @@
     private static RowBuilder buildRowBuilder(CharSequence title, CharSequence subTitle,
             IconCompat icon, Context context, Intent intent) {
         final SliceAction primarySliceAction = SliceAction.createDeeplink(
-                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED), icon, ListBuilder.ICON_IMAGE,
-                title);
+                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE),
+                icon, ListBuilder.ICON_IMAGE, title);
         return new RowBuilder()
                 .setTitleItem(icon, ListBuilder.ICON_IMAGE)
                 .setTitle(title)
diff --git a/tests/robotests/src/com/android/settings/TestingSettingsBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/TestingSettingsBroadcastReceiverTest.java
new file mode 100644
index 0000000..10fdffb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/TestingSettingsBroadcastReceiverTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package com.android.settings;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Application;
+import android.content.Context;
+import android.content.Intent;
+import android.telephony.TelephonyManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+
+@RunWith(RobolectricTestRunner.class)
+public class TestingSettingsBroadcastReceiverTest {
+
+    private Context mContext;
+    private Application mApplication;
+    private TestingSettingsBroadcastReceiver mReceiver;
+
+    @Before
+    public void setUp() {
+        mContext = RuntimeEnvironment.application;
+        mApplication = RuntimeEnvironment.application;
+        mReceiver = new TestingSettingsBroadcastReceiver();
+    }
+
+    @Test
+    public void onReceive_nullIntent_shouldNotCrash() {
+        final Intent intent = new Intent();
+
+        mReceiver.onReceive(mContext, null);
+        mReceiver.onReceive(mContext, intent);
+
+        final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
+        assertThat(next).isNull();
+    }
+
+    @Test
+    public void onReceive_wrongIntent_shouldNotStartActivity() {
+        final Intent intent = new Intent();
+        intent.setAction("");
+
+        mReceiver.onReceive(mContext, intent);
+
+        final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
+        assertThat(next).isNull();
+    }
+
+    @Test
+    public void onReceive_correctIntent_shouldStartActivity() {
+        final Intent intent = new Intent();
+        intent.setAction(TelephonyManager.ACTION_SECRET_CODE);
+
+        mReceiver.onReceive(mContext, intent);
+
+        final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
+        assertThat(next).isNotNull();
+        final String dest = next.getComponent().getClassName();
+        assertThat(dest).isEqualTo(Settings.TestingSettingsActivity.class.getName());
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
index 15e9bda..dffd7fb 100644
--- a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
+++ b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
@@ -88,14 +88,16 @@
     public void setUp() throws RemoteException, NameNotFoundException {
         MockitoAnnotations.initMocks(this);
         mChanges = new CompatibilityChangeInfo[5];
-        mChanges[0] = new CompatibilityChangeInfo(1L, "Default_Enabled", 0, 0, false, false, "");
-        mChanges[1] = new CompatibilityChangeInfo(2L, "Default_Disabled", 0, 0, true, false, "");
-        mChanges[2] = new CompatibilityChangeInfo(3L, "Enabled_Since_SDK_1_1", -1, 1, false, false,
-                                                  "");
-        mChanges[3] = new CompatibilityChangeInfo(4L, "Enabled_Since_SDK_1_2", -1, 1, false, false,
-                                                  "");
-        mChanges[4] = new CompatibilityChangeInfo(5L, "Enabled_Since_SDK_2", -1, 2, false, false,
-                                                  "");
+        mChanges[0] = new CompatibilityChangeInfo(
+                1L, "Default_Enabled", 0, 0, false, false, "", false);
+        mChanges[1] = new CompatibilityChangeInfo(
+                2L, "Default_Disabled", 0, 0, true, false, "", false);
+        mChanges[2] = new CompatibilityChangeInfo(
+                3L, "Enabled_Since_SDK_1_1", -1, 1, false, false, "", false);
+        mChanges[3] = new CompatibilityChangeInfo(
+                4L, "Enabled_Since_SDK_1_2", -1, 1, false, false, "", false);
+        mChanges[4] = new CompatibilityChangeInfo(
+                5L, "Enabled_Since_SDK_2", -1, 2, false, false, "", false);
         when(mPlatformCompat.listUIChanges()).thenReturn(mChanges);
         when(mPlatformCompat.getOverrideValidator()).thenReturn(mOverrideValidator);
         // By default, allow any change
@@ -208,7 +210,8 @@
         for (int i = 0; i < mChanges.length; ++i) {
             changesToAdd.add(new CompatibilityChangeInfo(mChanges[i].getId(), mChanges[i].getName(),
                     -1, mChanges[i].getEnableSinceTargetSdk(), mChanges[i].getDisabled(),
-                    mChanges[i].getLoggingOnly(), mChanges[i].getDescription()));
+                    mChanges[i].getLoggingOnly(), mChanges[i].getDescription(),
+                    mChanges[i].getOverridable()));
         }
 
         PreferenceCategory category = mDashboard.createChangeCategoryPreference(changesToAdd,
diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
index 84e88cb..e08893b 100644
--- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
+++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
@@ -59,6 +59,7 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.util.DisplayMetrics;
 
 import com.android.settings.R;
 import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
@@ -89,6 +90,8 @@
     private Resources mResources;
     @Mock
     private SubscriptionInfo mSubInfo;
+    @Mock
+    private DisplayMetrics mDisplayMetrics;
 
     private final String mFakeDisplayName = "fake_display_name";
     private final CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title";
@@ -141,6 +144,9 @@
                 .thenReturn(mFakeDualCdmaWarningTitle);
         when(mResources.getString(R.string.dual_cdma_sim_warning_notification_summary,
                 mSimCombinationName)).thenReturn(mFakeDualCdmaWarningSummary);
+
+        when(mResources.getDisplayMetrics()).thenReturn(mDisplayMetrics);
+        mDisplayMetrics.density = 1.5f;
     }
 
     @Test
@@ -275,4 +281,3 @@
         assertThat(notification.getValue().contentIntent).isNotNull();
     }
 }
-