Separate conversations from channels

Test: atest
Bug: 137397357
Change-Id: I15c360e8ef89f9fcb8db92678dd02a2c6fe083c5
This commit is contained in:
Julia Reynolds
2020-02-05 12:41:06 -05:00
parent c1313b41a5
commit 976a07baa6
52 changed files with 2338 additions and 318 deletions

View File

@@ -0,0 +1,87 @@
/*
* 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.
*/
package com.android.settings.notification.app;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class AddToHomeScreenPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
private AddToHomeScreenPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new AddToHomeScreenPreferenceController(mContext, mBackend);
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
}
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
assertTrue(mController.isAvailable());
}
@Test
public void testHandlePreferenceTreeClick() {
ShortcutInfo si = mock(ShortcutInfo.class);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
Preference pref = new Preference(RuntimeEnvironment.application);
pref.setKey("add_to_home");
mController.handlePreferenceTreeClick(pref);
verify(mBackend).requestPinShortcut(any(), eq(si));
}
}

View File

@@ -92,10 +92,10 @@ public class AllowSoundPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, mock(NotificationChannel.class), null, null);
mController.onResume(null, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -103,7 +103,7 @@ public class AllowSoundPreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +112,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something new");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -122,7 +122,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -130,7 +130,7 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext);
@@ -145,7 +145,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -158,7 +158,7 @@ public class AllowSoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -170,7 +170,7 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_checkedForHighImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -181,7 +181,7 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -192,7 +192,7 @@ public class AllowSoundPreferenceControllerTest {
public void testUpdateState_notCheckedForLowImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -203,7 +203,7 @@ public class AllowSoundPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -220,7 +220,7 @@ public class AllowSoundPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -36,7 +36,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.AppLinkPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -76,7 +75,7 @@ public class AppLinkPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -84,7 +83,7 @@ public class AppLinkPreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -93,7 +92,7 @@ public class AppLinkPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -103,7 +102,7 @@ public class AppLinkPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -114,7 +113,7 @@ public class AppLinkPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -123,7 +122,7 @@ public class AppLinkPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
Intent intent = new Intent("action");
appRow.settingsIntent = intent;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -44,7 +44,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.BadgePreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -94,7 +93,7 @@ public class BadgePreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -103,7 +102,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -113,7 +112,7 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -123,7 +122,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
assertFalse(mController.isAvailable());
@@ -132,7 +131,7 @@ public class BadgePreferenceControllerTest {
@Test
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -145,7 +144,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -157,7 +156,7 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertTrue(mController.isAvailable());
@@ -169,7 +168,7 @@ public class BadgePreferenceControllerTest {
appRow.showBadge = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
assertFalse(mController.isAvailable());
@@ -180,7 +179,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -194,7 +193,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -207,7 +206,7 @@ public class BadgePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canShowBadge()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -215,7 +214,7 @@ public class BadgePreferenceControllerTest {
assertTrue(pref.isChecked());
when(channel.canShowBadge()).thenReturn(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -225,14 +224,14 @@ public class BadgePreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertTrue(pref.isChecked());
appRow.showBadge = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -245,7 +244,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setShowBadge(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -264,7 +263,7 @@ public class BadgePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setShowBadge(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -280,7 +279,7 @@ public class BadgePreferenceControllerTest {
public void testOnPreferenceChange_on_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -297,7 +296,7 @@ public class BadgePreferenceControllerTest {
public void testOnPreferenceChange_off_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.showBadge = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -45,8 +45,6 @@ import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.BlockPreferenceController;
import com.android.settings.notification.app.NotificationSettings;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.widget.LayoutPreference;
@@ -99,7 +97,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -109,7 +107,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -119,7 +117,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -129,7 +127,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -137,7 +135,7 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
assertTrue(mController.isAvailable());
}
@@ -145,7 +143,7 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_AppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -155,7 +153,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -165,7 +163,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -174,7 +172,7 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@@ -183,7 +181,7 @@ public class BlockPreferenceControllerTest {
public void testIsEnabled_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@@ -192,7 +190,7 @@ public class BlockPreferenceControllerTest {
public void testIsEnabled_systemAppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@@ -203,7 +201,7 @@ public class BlockPreferenceControllerTest {
appRow.systemApp = true;
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setBlockableSystem(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isEnabled());
}
@@ -214,7 +212,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
@@ -227,7 +225,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
@@ -239,7 +237,7 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
@@ -249,7 +247,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testIsEnabled_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(mPreference);
@@ -260,7 +258,7 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(mPreference);
assertNotNull(mPreference.findViewById(R.id.switch_bar));
@@ -268,7 +266,7 @@ public class BlockPreferenceControllerTest {
assertFalse(mSwitch.isChecked());
appRow.banned = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isChecked());
@@ -279,20 +277,20 @@ public class BlockPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isChecked());
appRow.banned = true;
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
when(group.isBlocked()).thenReturn(true);
mController.updateState(mPreference);
assertFalse(mSwitch.isChecked());
appRow.banned = false;
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
when(group.isBlocked()).thenReturn(false);
mController.updateState(mPreference);
@@ -303,21 +301,21 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_channelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isChecked());
appRow.banned = true;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isChecked());
appRow.banned = false;
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isChecked());
@@ -327,7 +325,7 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_noCrashIfCalledTwice() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
mController.updateState(mPreference);
}
@@ -336,7 +334,7 @@ public class BlockPreferenceControllerTest {
public void testUpdateState_doesNotResetImportance() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
assertEquals(IMPORTANCE_LOW, channel.getImportance());
@@ -349,7 +347,7 @@ public class BlockPreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
when(mBackend.onlyHasDefaultChannel(anyString(), anyInt())).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);
@@ -370,7 +368,7 @@ public class BlockPreferenceControllerTest {
public void testOnSwitchChanged_channel_nonDefault() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
mController.onSwitchChanged(null, false);

View File

@@ -45,7 +45,6 @@ import android.os.UserManager;
import android.provider.Settings;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.BubblePreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -108,7 +107,7 @@ public class BubblePreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -118,7 +117,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -129,7 +128,7 @@ public class BubblePreferenceControllerTest {
appRow.allowBubbles = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -137,7 +136,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsNotAvailable_ifOffGlobally_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -149,7 +148,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -159,7 +158,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsAvailable_app_evenIfOffGlobally() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mAppPageController.onResume(appRow, null, null, null);
mAppPageController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
@@ -169,7 +168,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -182,7 +181,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -194,7 +193,7 @@ public class BubblePreferenceControllerTest {
appRow.allowBubbles = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -206,7 +205,7 @@ public class BubblePreferenceControllerTest {
appRow.allowBubbles = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertFalse(mController.isAvailable());
@@ -217,7 +216,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -231,7 +230,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -245,7 +244,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBubble()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -253,7 +252,7 @@ public class BubblePreferenceControllerTest {
assertTrue(pref.isChecked());
when(channel.canBubble()).thenReturn(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -265,14 +264,14 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "App!";
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertTrue(pref.isChecked());
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
@@ -288,7 +287,7 @@ public class BubblePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "App!";
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -303,7 +302,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -323,7 +322,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setAllowBubbles(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -340,7 +339,7 @@ public class BubblePreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -358,7 +357,7 @@ public class BubblePreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -377,7 +376,7 @@ public class BubblePreferenceControllerTest {
SYSTEM_WIDE_OFF);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -40,7 +40,6 @@ import android.content.Context;
import android.provider.Settings;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.BubbleSummaryPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -80,7 +79,7 @@ public class BubbleSummaryPreferenceControllerTest {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -89,7 +88,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
@@ -99,7 +98,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -108,7 +107,7 @@ public class BubbleSummaryPreferenceControllerTest {
@Test
public void testIsNotAvailable_app_globalOff() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
@@ -122,7 +121,7 @@ public class BubbleSummaryPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
@@ -132,7 +131,7 @@ public class BubbleSummaryPreferenceControllerTest {
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Preference pref = new Preference(mContext);
mController.updateState(pref);
@@ -144,7 +143,7 @@ public class BubbleSummaryPreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertEquals("On", mController.getSummary());
@@ -154,7 +153,7 @@ public class BubbleSummaryPreferenceControllerTest {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertEquals("Off", mController.getSummary());
}

View File

@@ -0,0 +1,126 @@
/*
* 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.
*/
package com.android.settings.notification.app;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.content.Context;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class ConversationDemotePreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
@Mock
SettingsPreferenceFragment mFragment;
private ConversationDemotePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = RuntimeEnvironment.application;
when(mFragment.getActivity()).thenReturn(mock(FragmentActivity.class));
mController = spy(new ConversationDemotePreferenceController(
mContext, mFragment, mBackend));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
mController.handlePreferenceTreeClick(mock(Preference.class));
}
@Test
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_conversation_demoted() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_conversation_notDemoted() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(false);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("demote");
assertTrue(mController.handlePreferenceTreeClick(pref));
ArgumentCaptor<NotificationChannel> captor =
ArgumentCaptor.forClass(NotificationChannel.class);
verify(mBackend).updateChannel(eq(null), anyInt(), captor.capture());
assertTrue(captor.getValue().isDemoted());
verify(mFragment).getActivity();
}
}

View File

@@ -0,0 +1,141 @@
/*
* 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.
*/
package com.android.settings.notification.app;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.os.UserManager;
import android.view.View;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class ConversationHeaderPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationManager mNm;
@Mock
private UserManager mUm;
private ConversationHeaderPreferenceController mController;
@Mock
private LayoutPreference mPreference;
@Mock
private View mView;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
DashboardFragment fragment = mock(DashboardFragment.class);
when(fragment.getContext()).thenReturn(mContext);
FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getApplicationContext()).thenReturn(mContext);
when(fragment.getActivity()).thenReturn(activity);
mController = spy(new ConversationHeaderPreferenceController(mContext, fragment));
when(mPreference.findViewById(anyInt())).thenReturn(mView);
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(LayoutPreference.class));
}
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testGetLabel() {
ShortcutInfo si = mock(ShortcutInfo.class);
when(si.getShortLabel()).thenReturn("hello");
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, si, null);
assertEquals(si.getShortLabel(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
}
@Test
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null, null, null);
assertEquals("", mController.getSummary());
}
}

View File

@@ -0,0 +1,169 @@
/*
* 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.
*/
package com.android.settings.notification.app;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
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.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class ConversationImportantPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
@Mock
private NotificationManager mNm;
@Mock
private UserManager mUm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
private ConversationImportantPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new ConversationImportantPreferenceController(mContext, mBackend));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
mController.onPreferenceChange(mock(Preference.class), true);
}
@Test
public void testIsAvailable_notChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setImportantConversation(true);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
assertTrue(pref.isChecked());
channel.setImportantConversation(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
}
@Test
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setImportantConversation(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
mController.onPreferenceChange(pref, true);
assertTrue(channel.isImportantConversation());
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
@Test
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setImportantConversation(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, false);
assertFalse(channel.isImportantConversation());
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
}

View File

@@ -0,0 +1,125 @@
/*
* 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.
*/
package com.android.settings.notification.app;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.content.Context;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.NotificationBackend;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class ConversationPromotePreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
@Mock
SettingsPreferenceFragment mFragment;
private ConversationPromotePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = RuntimeEnvironment.application;
when(mFragment.getActivity()).thenReturn(mock(FragmentActivity.class));
mController = spy(new ConversationPromotePreferenceController(
mContext, mFragment, mBackend));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
mController.handlePreferenceTreeClick(mock(Preference.class));
}
@Test
public void testIsAvailable_notConversation() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_conversation_notDemoted() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_conversation_demoted() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testHandlePreferenceClick() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setConversationId("a", "a");
channel.setDemoted(true);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = mock(Preference.class);
when(pref.getKey()).thenReturn("convo_promote");
assertTrue(mController.handlePreferenceTreeClick(pref));
ArgumentCaptor<NotificationChannel> captor =
ArgumentCaptor.forClass(NotificationChannel.class);
verify(mBackend).updateChannel(eq(null), anyInt(), captor.capture());
assertFalse(captor.getValue().isDemoted());
verify(mFragment).getActivity();
}
}

View File

@@ -0,0 +1,246 @@
/*
* 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.notification.app;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
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.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class DefaultImportancePreferenceControllerTest {
private Context mContext;
@Mock
private NotificationManager mNm;
@Mock
private NotificationBackend mBackend;
@Mock
private NotificationSettings.ImportanceListener mImportanceListener;
@Mock
private UserManager mUm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
private DefaultImportancePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new DefaultImportancePreferenceController(
mContext, mImportanceListener, mBackend));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
}
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_notIfChannelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_notForDefaultChannel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState_notConfigurable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState_systemButConfigurable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_defaultApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_default() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertTrue(pref.isChecked());
}
@Test
public void testUpdateState_low() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertFalse(pref.isChecked());
}
@Test
public void onPreferenceChange_onToOff() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, false);
assertEquals(IMPORTANCE_LOW, channel.getImportance());
verify(mImportanceListener, times(1)).onImportanceChanged();
}
@Test
public void onPreferenceChange_offToOn() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, true);
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
verify(mImportanceListener, times(1)).onImportanceChanged();
}
}

View File

@@ -35,7 +35,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.DeletedChannelsPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -80,42 +79,43 @@ public class DeletedChannelsPreferenceControllerTest {
public void isAvailable_appScreen_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_groupScreen_never() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_channelScreen_never() {
mController.onResume(
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null);
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null, null,
null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen_notIfNoDeletedChannels() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
mController.onResume(new NotificationBackend.AppRow(), null, null, null);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_appScreen() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
mController.onResume(new NotificationBackend.AppRow(), null, null, null);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void updateState() {
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
mController.onResume(new NotificationBackend.AppRow(), null, null, null);
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
Preference pref = mock(Preference.class);
mController.updateState(pref);

View File

@@ -35,7 +35,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.DescriptionPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -75,7 +74,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -83,7 +82,7 @@ public class DescriptionPreferenceControllerTest {
public void testIsAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -92,7 +91,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -101,7 +100,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -109,7 +108,7 @@ public class DescriptionPreferenceControllerTest {
public void testIsAvailable_notIfNoChannelGroupDesc() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -119,7 +118,7 @@ public class DescriptionPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -129,7 +128,7 @@ public class DescriptionPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -139,7 +138,7 @@ public class DescriptionPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getDescription()).thenReturn("AAA");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -154,7 +153,7 @@ public class DescriptionPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -41,7 +41,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.DndPreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -84,7 +83,7 @@ public class DndPreferenceControllerTest {
public void testIsAvailable_app() {
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -94,7 +93,7 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -102,7 +101,7 @@ public class DndPreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -116,7 +115,7 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -129,7 +128,7 @@ public class DndPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -141,7 +140,7 @@ public class DndPreferenceControllerTest {
public void testUpdateState_bypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -153,7 +152,7 @@ public class DndPreferenceControllerTest {
public void testUpdateState_noBypassDnd() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBypassDnd()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -165,7 +164,7 @@ public class DndPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -183,7 +182,7 @@ public class DndPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);

View File

@@ -37,7 +37,6 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.HeaderPreferenceController;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
@@ -88,7 +87,7 @@ public class HeaderPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -96,7 +95,7 @@ public class HeaderPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -104,20 +103,20 @@ public class HeaderPreferenceControllerTest {
public void testGetLabel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertEquals(group.getName(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null);
mController.onResume(appRow, defaultChannel, null, null, null, null);
assertEquals(appRow.label, mController.getLabel());
}
@@ -125,25 +124,25 @@ public class HeaderPreferenceControllerTest {
public void testGetSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null);
mController.onResume(appRow, defaultChannel, null, null, null, null);
assertEquals("", mController.getSummary());
}
}

View File

@@ -36,8 +36,6 @@ import android.content.Context;
import android.os.UserManager;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.HighImportancePreferenceController;
import com.android.settings.notification.app.NotificationSettings;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -90,7 +88,7 @@ public class HighImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -98,7 +96,7 @@ public class HighImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -107,7 +105,7 @@ public class HighImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -117,7 +115,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -126,7 +124,7 @@ public class HighImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -134,7 +132,7 @@ public class HighImportancePreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext, null);
@@ -149,7 +147,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -164,7 +162,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -179,7 +177,7 @@ public class HighImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -191,7 +189,7 @@ public class HighImportancePreferenceControllerTest {
public void testUpdateState_high() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -203,7 +201,7 @@ public class HighImportancePreferenceControllerTest {
public void testUpdateState_default() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -215,7 +213,7 @@ public class HighImportancePreferenceControllerTest {
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -46,9 +46,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.ImportancePreference;
import com.android.settings.notification.app.ImportancePreferenceController;
import com.android.settings.notification.app.NotificationSettings;
import com.android.settingslib.RestrictedLockUtils;
import org.junit.Before;
@@ -97,7 +94,7 @@ public class ImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -105,7 +102,7 @@ public class ImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +113,7 @@ public class ImportancePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -125,7 +122,7 @@ public class ImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -135,7 +132,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -144,7 +141,7 @@ public class ImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -152,7 +149,7 @@ public class ImportancePreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new ImportancePreference(mContext, null);
@@ -167,7 +164,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -182,7 +179,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -197,7 +194,7 @@ public class ImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
@@ -209,7 +206,7 @@ public class ImportancePreferenceControllerTest {
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
ImportancePreference pref = mock(ImportancePreference.class);
mController.updateState(pref);
@@ -224,7 +221,7 @@ public class ImportancePreferenceControllerTest {
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);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -242,7 +239,7 @@ public class ImportancePreferenceControllerTest {
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);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ImportancePreference pref = new ImportancePreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -42,7 +42,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.LightsPreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -108,7 +107,7 @@ public class LightsPreferenceControllerTest {
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -117,7 +116,7 @@ public class LightsPreferenceControllerTest {
Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -125,7 +124,7 @@ public class LightsPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -134,7 +133,7 @@ public class LightsPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -142,7 +141,7 @@ public class LightsPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -151,7 +150,7 @@ public class LightsPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null,
mock(RestrictedLockUtils.EnforcedAdmin.class));
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -164,7 +163,7 @@ public class LightsPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -176,7 +175,7 @@ public class LightsPreferenceControllerTest {
public void testUpdateState_lightsOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -187,7 +186,7 @@ public class LightsPreferenceControllerTest {
public void testUpdateState_lightsOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldShowLights()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -198,7 +197,7 @@ public class LightsPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
@@ -215,7 +214,7 @@ public class LightsPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(mContext);

View File

@@ -36,8 +36,6 @@ import android.content.Context;
import android.os.UserManager;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.MinImportancePreferenceController;
import com.android.settings.notification.app.NotificationSettings;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -90,7 +88,7 @@ public class MinImportancePreferenceControllerTest {
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -98,7 +96,7 @@ public class MinImportancePreferenceControllerTest {
public void testIsAvailable_ifAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -107,7 +105,7 @@ public class MinImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -117,7 +115,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -126,7 +124,7 @@ public class MinImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -134,7 +132,7 @@ public class MinImportancePreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext, null);
@@ -149,7 +147,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -164,7 +162,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -179,7 +177,7 @@ public class MinImportancePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
@@ -191,7 +189,7 @@ public class MinImportancePreferenceControllerTest {
public void testUpdateState_min() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -203,7 +201,7 @@ public class MinImportancePreferenceControllerTest {
public void testUpdateState_low() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
@@ -215,7 +213,7 @@ public class MinImportancePreferenceControllerTest {
public void onPreferenceChange() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);

View File

@@ -42,7 +42,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.NotificationPreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import org.junit.Before;
@@ -91,7 +90,7 @@ public class NotificationPreferenceControllerTest {
@Test
public void isAvailable_notIfNull() {
mController.onResume(null, null, null, null);
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -100,7 +99,7 @@ public class NotificationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class),
mock(NotificationChannelGroup.class), null);
mock(NotificationChannelGroup.class), null, null, null);
assertFalse(mController.isAvailable());
}
@@ -112,7 +111,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -123,7 +122,7 @@ public class NotificationPreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
when(group.isBlocked()).thenReturn(true);
assertFalse(mController.isAvailable());
}
@@ -136,7 +135,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, channel, group, null);
mController.onResume(appRow, channel, group, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -147,7 +146,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
mController.onResume(appRow, channel, group, admin);
mController.onResume(appRow, channel, group, null, null, admin);
assertEquals(appRow, mController.mAppRow);
assertEquals(channel, mController.mChannel);
@@ -161,7 +160,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -171,7 +170,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
}
@@ -181,7 +180,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
}
@@ -191,7 +190,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
}
@@ -201,7 +200,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
mController.saveChannel();
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
}
@@ -213,11 +212,11 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isChannelBlockable());
when(channel.isImportanceLockedByOEM()).thenReturn(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -228,7 +227,7 @@ public class NotificationPreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -239,7 +238,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockableSystem()).thenReturn(false);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -251,7 +250,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isBlockableSystem()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -262,7 +261,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isBlockableSystem()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -274,7 +273,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isBlockableSystem()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isChannelBlockable());
}
@@ -285,7 +284,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@@ -297,7 +296,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -309,7 +308,7 @@ public class NotificationPreferenceControllerTest {
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isChannelBlockable());
}
@@ -320,7 +319,7 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertFalse(mController.isChannelGroupBlockable());
}
@@ -331,13 +330,13 @@ public class NotificationPreferenceControllerTest {
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertTrue(mController.isChannelGroupBlockable());
}
@Test
public void testIsDefaultChannel_noChannel() {
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
assertFalse(mController.isDefaultChannel());
}
@@ -345,7 +344,7 @@ public class NotificationPreferenceControllerTest {
@Test
public void testIsDefaultChannel_nonDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
assertFalse(mController.isDefaultChannel());
}
@@ -354,7 +353,7 @@ public class NotificationPreferenceControllerTest {
public void testIsDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
assertTrue(mController.isDefaultChannel());
}

View File

@@ -33,7 +33,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.NotificationsOffPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -73,7 +72,7 @@ public class NotificationsOffPreferenceControllerTest {
public void testIsAvailable_yesIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -82,7 +81,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -91,7 +90,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertThat(mController.isAvailable()).isTrue();
}
@@ -100,7 +99,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -114,7 +113,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
mController.onResume(appRow, null, group, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -127,7 +126,7 @@ public class NotificationsOffPreferenceControllerTest {
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);

View File

@@ -108,7 +108,7 @@ public class SoundPreferenceControllerTest {
@Test
public void testIsAvailable_notIfChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +116,7 @@ public class SoundPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -125,7 +125,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -133,7 +133,7 @@ public class SoundPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -151,7 +151,7 @@ public class SoundPreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
@@ -166,7 +166,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -182,7 +182,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
when(channel.getSound()).thenReturn(sound);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref = new NotificationSoundPreference(mContext, attributeSet);
@@ -198,7 +198,7 @@ public class SoundPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -238,7 +238,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_ALARM).build());
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -259,7 +259,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =
@@ -280,7 +280,7 @@ public class SoundPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setSound(null, new AudioAttributes.Builder().setUsage(
AudioAttributes.USAGE_UNKNOWN).build());
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
NotificationSoundPreference pref =

View File

@@ -42,7 +42,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.VibrationPreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -99,7 +98,7 @@ public class VibrationPreferenceControllerTest {
when(mVibrator.hasVibrator()).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -107,7 +106,7 @@ public class VibrationPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -116,7 +115,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -124,7 +123,7 @@ public class VibrationPreferenceControllerTest {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -132,7 +131,7 @@ public class VibrationPreferenceControllerTest {
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -146,7 +145,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -159,7 +158,7 @@ public class VibrationPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
@@ -171,7 +170,7 @@ public class VibrationPreferenceControllerTest {
public void testUpdateState_vibrateOn() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -183,7 +182,7 @@ public class VibrationPreferenceControllerTest {
public void testUpdateState_vibrateOff() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.shouldVibrate()).thenReturn(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -195,7 +194,7 @@ public class VibrationPreferenceControllerTest {
public void testOnPreferenceChange_on() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
@@ -211,7 +210,7 @@ public class VibrationPreferenceControllerTest {
public void testOnPreferenceChange_off() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);

View File

@@ -48,7 +48,6 @@ import android.provider.Settings;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.RestrictedListPreference;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.VisibilityPreferenceController;
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
import com.android.settingslib.RestrictedLockUtils;
@@ -122,7 +121,7 @@ public class VisibilityPreferenceControllerTest {
when(mLockUtils.isSecure(anyInt())).thenReturn(false);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -130,7 +129,7 @@ public class VisibilityPreferenceControllerTest {
public void testIsAvailable_notIfNotImportant() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@@ -139,11 +138,11 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -160,7 +159,7 @@ public class VisibilityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedListPreference pref = mock(RestrictedListPreference.class);
@@ -182,7 +181,7 @@ public class VisibilityPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
RestrictedListPreference pref = mock(RestrictedListPreference.class);
@@ -198,7 +197,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -223,7 +222,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -246,7 +245,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -263,7 +262,7 @@ public class VisibilityPreferenceControllerTest {
public void testUpdateState_noGlobalRestriction() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -294,7 +293,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -313,7 +312,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -332,7 +331,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);
@@ -351,7 +350,7 @@ public class VisibilityPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", 4);
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
mController.onResume(appRow, channel, null, null);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedListPreference pref = mock(RestrictedListPreference.class);
mController.updateState(pref);