Notification settings updates

- Footer preferences were too dim
- Fix text and target on recently sent apps
- Make 'behavior' a dialog
- reorder settings on apps page

Change-Id: Idf8056bc77ead89fe2025bbde3346861e23a3c8d
Fixes: 72652526
Fixes: 72651810
Fixes: 72652024
Bug: 72651953
Test: make RunSettingsRoboTests
This commit is contained in:
Julia Reynolds
2018-01-30 11:28:38 -05:00
parent 3b04494ac6
commit 4f3b556388
23 changed files with 147 additions and 461 deletions

View File

@@ -10,7 +10,6 @@ com.android.settings.development.featureflags.FeatureFlagsDashboard
com.android.settings.development.qstile.DevelopmentTileConfigFragment
com.android.settings.deviceinfo.StorageProfileFragment
com.android.settings.notification.ChannelNotificationSettings
com.android.settings.notification.ChannelImportanceSettings
com.android.settings.notification.ChannelGroupNotificationSettings
com.android.settings.notification.AppNotificationSettings
com.android.settings.wifi.details.WifiNetworkDetailsFragment

View File

@@ -1,114 +0,0 @@
/*
* Copyright (C) 2017 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.applications;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.UserInfo;
import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import java.util.List;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationAppsTest {
@Mock
private PackageManagerWrapper mPackageManager;
@Mock
private UserManager mUserManager;
@Mock
private SummaryLoader mSummaryLoader;
@Mock
private NotificationBackend mBackend;
private Context mContext;
private NotificationApps.SummaryProvider mSummaryProvider;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.USER_SERVICE, mUserManager);
mContext = shadowApplication.getApplicationContext();
mSummaryProvider = spy(new NotificationApps.SummaryProvider(mContext, mSummaryLoader));
ReflectionHelpers.setField(mSummaryProvider, "mNotificationBackend", mBackend);
ReflectionHelpers.setField(mSummaryProvider, "mPackageManager", mPackageManager);
}
@Test
public void setListening_shouldSetSummary() {
List<UserInfo> userInfos = new ArrayList<>();
userInfos.add(new UserInfo(1, "user1", 0));
when(mUserManager.getProfiles(anyInt())).thenReturn(userInfos);
List<ApplicationInfo> appInfos = new ArrayList<>();
ApplicationInfo info1 = new ApplicationInfo();
info1.packageName = "package1";
appInfos.add(info1);
ApplicationInfo info2 = new ApplicationInfo();
info2.packageName = "package2";
appInfos.add(info2);
when(mPackageManager.getInstalledApplicationsAsUser(anyInt(), anyInt()))
.thenReturn(appInfos);
// no notification off
when(mBackend.getNotificationsBanned(anyString(), anyInt())).thenReturn(false);
mSummaryProvider.setListening(true);
ShadowApplication.runBackgroundTasks();
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.notification_summary_none));
// some notification off
when(mBackend.getNotificationsBanned(eq("package1"), anyInt())).thenReturn(true);
mSummaryProvider.setListening(true);
ShadowApplication.runBackgroundTasks();
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getResources().getQuantityString(R.plurals.notification_summary, 1, 1));
when(mBackend.getNotificationsBanned(eq("package2"), anyInt())).thenReturn(true);
mSummaryProvider.setListening(true);
ShadowApplication.runBackgroundTasks();
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getResources().getQuantityString(R.plurals.notification_summary, 2, 2));
}
}

View File

@@ -119,7 +119,6 @@ public class DeletedChannelsPreferenceControllerTest {
Preference pref = mock(Preference.class);
mController.updateState(pref);
verify(pref, times(1)).setEnabled(false);
verify(pref, times(1)).setSelectable(false);
verify(mBackend, times(1)).getDeletedChannelCount(any(), anyInt());
ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);

View File

@@ -21,6 +21,7 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -30,13 +31,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.settings.RestrictedListPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.RestrictedLockUtils;
@@ -44,6 +48,7 @@ import com.android.settingslib.RestrictedLockUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -58,7 +63,13 @@ public class ImportancePreferenceControllerTest {
@Mock
private NotificationManager mNm;
@Mock
private NotificationBackend mBackend;
@Mock
NotificationSettingsBase.ImportanceListener mImportanceListener;
@Mock
private UserManager mUm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
private ImportancePreferenceController mController;
@@ -69,7 +80,8 @@ public class ImportancePreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = shadowApplication.getApplicationContext();
mController = spy(new ImportancePreferenceController(mContext));
mController = spy(new ImportancePreferenceController(
mContext, mImportanceListener, mBackend));
}
@Test
@@ -123,14 +135,15 @@ public class ImportancePreferenceControllerTest {
@Test
public void testUpdateState_disabledByAdmin() throws Exception {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new Preference(RuntimeEnvironment.application);
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
assertNull(pref.getIntent());
assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
@Test
@@ -140,13 +153,14 @@ public class ImportancePreferenceControllerTest {
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
assertNull(pref.getIntent());
assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
@Test
@@ -155,11 +169,50 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
assertNotNull(pref.getIntent());
assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
@Test
public void testImportanceLowToHigh() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
RestrictedListPreference pref =
new RestrictedListPreference(RuntimeEnvironment.application, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
pref.setValue(String.valueOf(IMPORTANCE_HIGH));
mController.onPreferenceChange(pref, pref.getValue());
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
assertNotNull(channel.getSound());
}
@Test
public void testImportanceHightToLow() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
RestrictedListPreference pref =
new RestrictedListPreference(RuntimeEnvironment.application, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
pref.setValue(String.valueOf(IMPORTANCE_LOW));
mController.onPreferenceChange(pref, pref.getValue());
assertEquals(IMPORTANCE_LOW, channel.getImportance());
assertNull(channel.getSound());
}
}

View File

@@ -110,7 +110,6 @@ public class NotificationsOffPreferenceControllerTest {
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("category"));
assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
@@ -125,7 +124,6 @@ public class NotificationsOffPreferenceControllerTest {
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("group"));
assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
@@ -139,7 +137,6 @@ public class NotificationsOffPreferenceControllerTest {
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("app"));
assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
}