Merge "Remove NFC Slice jank"
diff --git a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
index 35ff2ec..e21bb75 100644
--- a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
@@ -61,6 +61,17 @@
             LayoutPreference pref = screen.findPreference(getPreferenceKey());
             if (pref != null) {
                 mSettingObserver = new SettingObserver(pref);
+                pref.setOnPreferenceClickListener(preference -> {
+                    int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
+                            Settings.Secure.VOLUME_HUSH_GESTURE,
+                            Settings.Secure.VOLUME_HUSH_VIBRATE);
+                    boolean isChecked = preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
+                    Settings.Secure.putInt(mContext.getContentResolver(),
+                            Settings.Secure.VOLUME_HUSH_GESTURE, isChecked
+                                    ? Settings.Secure.VOLUME_HUSH_OFF
+                                    : Settings.Secure.VOLUME_HUSH_VIBRATE);
+                    return true;
+                });
                 mSwitch = pref.findViewById(R.id.switch_bar);
                 if (mSwitch != null) {
                     mSwitch.addOnSwitchChangeListener(this);
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
index 5f221f5..85eeacc 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
@@ -18,6 +18,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
@@ -29,8 +30,10 @@
 import android.provider.Settings;
 
 import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
 
 import com.android.settings.widget.SwitchBar;
+import com.android.settingslib.widget.LayoutPreference;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -95,4 +98,16 @@
         mController.updateState(mPreference);
         verify(mController.mSwitch, times(1)).setChecked(true);
     }
+
+    @Test
+    public void testPreferenceClickListenerAttached() {
+        PreferenceScreen preferenceScreen = mock(PreferenceScreen.class);
+        LayoutPreference mLayoutPreference = mock(LayoutPreference.class);
+        when(preferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mLayoutPreference);
+        mController.displayPreference(preferenceScreen);
+
+        verify(mLayoutPreference, times(1))
+                .setOnPreferenceClickListener(any());
+    }
 }
diff --git a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
index ede4631..19b1360 100644
--- a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
@@ -41,6 +41,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.espresso.intent.Intents;
@@ -55,7 +56,9 @@
 @RunWith(AndroidJUnit4.class)
 @SmallTest
 public class AppNotificationSettingsTest {
+    private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
 
+    private UiDevice mUiDevice;
     private Context mTargetContext;
     private Instrumentation mInstrumentation;
 
@@ -68,9 +71,14 @@
     private NotificationChannel mUngroupedChannel;
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mTargetContext = mInstrumentation.getTargetContext();
+
+        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mUiDevice.wakeUp();
+        mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
         mNm  = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
 
         mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
@@ -87,7 +95,8 @@
     @Test
     public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
         final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
-                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
         mInstrumentation.startActivitySync(intent);
 
@@ -99,60 +108,38 @@
     @Test
     public void launchNotificationSetting_showGroupsWithMultipleChannels() {
         final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
-                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mInstrumentation.startActivitySync(intent);
         onView(allOf(withText(mGroup1.getName().toString()))).check(
                 matches(isDisplayed()));
-        try {
-            onView(allOf(withText(mGroup1Channel1.getName().toString())))
-                    .check(matches(isDisplayed()));
-            fail("Channel erroneously appearing");
-        } catch (Exception e) {
-            // expected
-        }
-        // links to group page
-        Intents.init();
-        onView(allOf(withText(mGroup1.getName().toString()))).perform(click());
-        intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT,
-                ChannelGroupNotificationSettings.class.getName())));
-        Intents.release();
+        onView(allOf(withText(mGroup1Channel1.getName().toString()))).check(
+                matches(isDisplayed()));
+        onView(allOf(withText(mGroup1Channel2.getName().toString()))).check(
+                matches(isDisplayed()));
     }
 
     @Test
     public void launchNotificationSetting_showUngroupedChannels() {
         final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
-                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mInstrumentation.startActivitySync(intent);
         onView(allOf(withText(mUngroupedChannel.getName().toString())))
                 .check(matches(isDisplayed()));
-        // links directly to channel page
-        Intents.init();
-        onView(allOf(withText(mUngroupedChannel.getName().toString()))).perform(click());
-        intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
-        Intents.release();
     }
 
     @Test
     public void launchNotificationSetting_showGroupsWithOneChannel() {
         final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
-                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+                .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mInstrumentation.startActivitySync(intent);
 
+        onView(allOf(withText(mGroup2.getName().toString())))
+                .check(matches(isDisplayed()));
         onView(allOf(withText(mGroup2Channel1.getName().toString())))
                 .check(matches(isDisplayed()));
-        try {
-            onView(allOf(withText(mGroup2.getName().toString()))).check(
-                    matches(isDisplayed()));
-            fail("Group erroneously appearing");
-        } catch (Exception e) {
-            // expected
-        }
-
-        // links directly to channel page
-        Intents.init();
-        onView(allOf(withText(mGroup2Channel1.getName().toString()))).perform(click());
-        intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
-        Intents.release();
     }
 
     private NotificationChannel createChannel(NotificationChannelGroup group,
diff --git a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
index f7a5a82..9a3a994 100644
--- a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
@@ -36,6 +36,7 @@
 import android.os.Process;
 import android.os.ServiceManager;
 import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
@@ -48,17 +49,23 @@
 @RunWith(AndroidJUnit4.class)
 @SmallTest
 public class ChannelNotificationSettingsTest {
+    private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
 
+    private UiDevice mUiDevice;
     private Context mTargetContext;
     private Instrumentation mInstrumentation;
     private NotificationChannel mNotificationChannel;
     private NotificationManager mNm;
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mTargetContext = mInstrumentation.getTargetContext();
 
+        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mUiDevice.wakeUp();
+        mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
         mNm  = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
         mNotificationChannel = new NotificationChannel(this.getClass().getName(),
                 this.getClass().getName(), IMPORTANCE_MIN);
@@ -69,7 +76,8 @@
     public void launchNotificationSetting_shouldNotCrash() {
         final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
                 .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
-                .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId());
+                .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mInstrumentation.startActivitySync(intent);
 
         onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
@@ -90,12 +98,12 @@
 
         final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
                 .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
-                .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId());
+                .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId())
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mInstrumentation.startActivitySync(intent);
 
-        onView(allOf(withText("Off"), isDisplayed())).check(matches(isDisplayed()));
-        onView(allOf(withText("Android is blocking this category of notifications from"
-                + " appearing on this device"))).check(matches(isDisplayed()));
+        onView(allOf(withText("At your request, Android is blocking this category of notifications"
+                + " from appearing on this device"))).check(matches(isDisplayed()));
 
         try {
             onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
diff --git a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
index 2fe4074..4120a07 100644
--- a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
+++ b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
@@ -37,27 +37,29 @@
     @Test
     public void testZenModeSettingsPreferences() {
         launchZenSettings();
-        onView(withText("Behavior")).check(matches(isDisplayed()));
-        onView(withText("Turn on automatically")).check(matches(isDisplayed()));
+        onView(withText("Calls")).check(matches(isDisplayed()));
+        onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+        onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+        onView(withText("Duration")).check(matches(isDisplayed()));
+        onView(withText("Schedules")).check(matches(isDisplayed()));
     }
 
     @Test
     public void testZenModeBehaviorPreferences() {
         launchZenBehaviorSettings();
-        onView(withText("Alarms")).check(matches(isDisplayed()));
-        onView(withText("Media and system feedback")).check(matches(isDisplayed()));
-        onView(withText("Reminders")).check(matches(isDisplayed()));
-        onView(withText("Events")).check(matches(isDisplayed()));
-        onView(withText("Messages")).check(matches(isDisplayed()));
         onView(withText("Calls")).check(matches(isDisplayed()));
-        onView(withText("Repeat callers")).check(matches(isDisplayed()));
+        onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+        onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+        onView(withText("Duration")).check(matches(isDisplayed()));
+        onView(withText("Schedules")).check(matches(isDisplayed()));
     }
 
     @Test
     public void testZenModeAutomationPreferences() {
         launchZenAutomationSettings();
-        onView(withText("Weekend")).check(matches(isDisplayed()));
-        onView(withText("Add rule")).check(matches(isDisplayed()));
+        onView(withText("Sleeping")).check(matches(isDisplayed()));
+        onView(withText("Event")).check(matches(isDisplayed()));
+        onView(withText("Add more")).check(matches(isDisplayed()));
     }
 
     private void launchZenSettings() {