Add settings page for notification channel groups

Bug: 63927402
Test: tests/unit/src/com/android/settings/notification/.*
Change-Id: Iebf7d8ba54f0cf5801a42f3161354d3cc5e5c848
This commit is contained in:
Julia Reynolds
2017-08-25 09:40:24 -04:00
parent 8fabdba0de
commit 0c3f4bce57
14 changed files with 751 additions and 127 deletions

View File

@@ -16,7 +16,29 @@
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import android.support.test.espresso.intent.Intents;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT;
import static org.hamcrest.Matchers.allOf;
import static org.junit.Assert.fail;
import android.app.Instrumentation;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
@@ -29,12 +51,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppNotificationSettingsTest {
@@ -42,10 +58,29 @@ public class AppNotificationSettingsTest {
private Context mTargetContext;
private Instrumentation mInstrumentation;
NotificationManager mNm;
private NotificationChannelGroup mGroup1;
private NotificationChannel mGroup1Channel1;
private NotificationChannel mGroup1Channel2;
private NotificationChannelGroup mGroup2;
private NotificationChannel mGroup2Channel1;
private NotificationChannel mUngroupedChannel;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
mGroup2 = new NotificationChannelGroup(this.getClass().getName() + "2", "group2");
mNm.createNotificationChannelGroup(mGroup1);
mNm.createNotificationChannelGroup(mGroup2);
mGroup1Channel1 = createChannel(mGroup1, this.getClass().getName()+ "c1-1");
mGroup1Channel2 = createChannel(mGroup1, this.getClass().getName()+ "c1-2");
mGroup2Channel1 = createChannel(mGroup2, this.getClass().getName()+ "c2-1");
mUngroupedChannel = createChannel(null, this.getClass().getName()+ "c");
}
@Test
@@ -60,4 +95,72 @@ public class AppNotificationSettingsTest {
.check(doesNotExist());
}
@Test
public void launchNotificationSetting_showGroupsWithMultipleChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
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();
}
@Test
public void launchNotificationSetting_showUngroupedChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
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());
mInstrumentation.startActivitySync(intent);
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,
String id) {
NotificationChannel channel = new NotificationChannel(id, id, IMPORTANCE_DEFAULT);
if (group != null) {
channel.setGroup(group.getId());
}
mNm.createNotificationChannel(channel);
return channel;
}
}