Merge "Wait to unlock before changing notification importance" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-03-30 16:13:59 +00:00
committed by Android (Google) Code Review
3 changed files with 93 additions and 67 deletions

View File

@@ -76,6 +76,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
private TextView mNumChannelsView; private TextView mNumChannelsView;
private View mChannelDisabledView; private View mChannelDisabledView;
private Switch mChannelEnabledSwitch; private Switch mChannelEnabledSwitch;
private CheckSaveListener mCheckSaveListener;
private NotificationGuts mGutsContainer; private NotificationGuts mGutsContainer;
@@ -83,6 +84,13 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
super(context, attrs); super(context, attrs);
} }
// Specify a CheckSaveListener to override when/if the user's changes are committed.
public interface CheckSaveListener {
// Invoked when importance has changed and the NotificationInfo wants to try to save it.
// Listener should run saveImportance unless the change should be canceled.
void checkSave(Runnable saveImportance);
}
public interface OnSettingsClickListener { public interface OnSettingsClickListener {
void onClick(View v, NotificationChannel channel, int appUid); void onClick(View v, NotificationChannel channel, int appUid);
} }
@@ -92,11 +100,14 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
final String pkg, final String pkg,
final List<NotificationChannel> notificationChannels, final List<NotificationChannel> notificationChannels,
OnSettingsClickListener onSettingsClick, OnSettingsClickListener onSettingsClick,
OnClickListener onDoneClick, final Set<String> nonBlockablePkgs) OnClickListener onDoneClick,
CheckSaveListener checkSaveListener,
final Set<String> nonBlockablePkgs)
throws RemoteException { throws RemoteException {
mINotificationManager = iNotificationManager; mINotificationManager = iNotificationManager;
mPkg = pkg; mPkg = pkg;
mNotificationChannels = notificationChannels; mNotificationChannels = notificationChannels;
mCheckSaveListener = checkSaveListener;
boolean isSingleDefaultChannel = false; boolean isSingleDefaultChannel = false;
if (mNotificationChannels.isEmpty()) { if (mNotificationChannels.isEmpty()) {
throw new IllegalArgumentException("bindNotification requires at least one channel"); throw new IllegalArgumentException("bindNotification requires at least one channel");
@@ -238,7 +249,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
doneButton.setOnClickListener(onDoneClick); doneButton.setOnClickListener(onDoneClick);
} }
public boolean hasImportanceChanged() { private boolean hasImportanceChanged() {
return mSingleNotificationChannel != null && return mSingleNotificationChannel != null &&
mStartingUserImportance != getSelectedImportance(); mStartingUserImportance != getSelectedImportance();
} }
@@ -316,9 +327,13 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
@Override @Override
public boolean handleCloseControls(boolean save) { public boolean handleCloseControls(boolean save) {
if (save) { if (save && hasImportanceChanged()) {
if (mCheckSaveListener != null) {
mCheckSaveListener.checkSave(() -> { saveImportance(); });
} else {
saveImportance(); saveImportance();
} }
}
return false; return false;
} }
} }

View File

@@ -5778,21 +5778,19 @@ public class StatusBar extends SystemUI implements DemoMode,
startAppNotificationSettingsActivity(pkg, appUid, channel); startAppNotificationSettingsActivity(pkg, appUid, channel);
}; };
final View.OnClickListener onDoneClick = (View v) -> { final View.OnClickListener onDoneClick = (View v) -> {
saveAndCloseNotificationMenu(info, row, guts, v);
};
final NotificationInfo.CheckSaveListener checkSaveListener = (Runnable saveImportance) -> {
// If the user has security enabled, show challenge if the setting is changed. // If the user has security enabled, show challenge if the setting is changed.
if (info.hasImportanceChanged() if (isLockscreenPublicMode(userHandle.getIdentifier())
&& isLockscreenPublicMode(userHandle.getIdentifier())
&& (mState == StatusBarState.KEYGUARD && (mState == StatusBarState.KEYGUARD
|| mState == StatusBarState.SHADE_LOCKED)) { || mState == StatusBarState.SHADE_LOCKED)) {
OnDismissAction dismissAction = new OnDismissAction() { onLockedNotificationImportanceChange(() -> {
@Override saveImportance.run();
public boolean onDismiss() {
saveAndCloseNotificationMenu(info, row, guts, v);
return true; return true;
} });
};
onLockedNotificationImportanceChange(dismissAction);
} else { } else {
saveAndCloseNotificationMenu(info, row, guts, v); saveImportance.run();
} }
}; };
@@ -5815,7 +5813,7 @@ public class StatusBar extends SystemUI implements DemoMode,
} }
try { try {
info.bindNotification(pmUser, iNotificationManager, pkg, new ArrayList(channels), info.bindNotification(pmUser, iNotificationManager, pkg, new ArrayList(channels),
onSettingsClick, onDoneClick, mNonBlockablePkgs); onSettingsClick, onDoneClick, checkSaveListener, mNonBlockablePkgs);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
} }

View File

@@ -135,7 +135,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testBindNotification_SetsTextApplicationName() throws Exception { public void testBindNotification_SetsTextApplicationName() throws Exception {
when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.pkgname); final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.pkgname);
assertTrue(textView.getText().toString().contains("App Name")); assertTrue(textView.getText().toString().contains("App Name"));
} }
@@ -146,7 +146,7 @@ public class NotificationInfoTest extends SysuiTestCase {
when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
.thenReturn(iconDrawable); .thenReturn(iconDrawable);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final ImageView iconView = (ImageView) mNotificationInfo.findViewById(R.id.pkgicon); final ImageView iconView = (ImageView) mNotificationInfo.findViewById(R.id.pkgicon);
assertEquals(iconDrawable, iconView.getDrawable()); assertEquals(iconDrawable, iconView.getDrawable());
} }
@@ -154,7 +154,7 @@ public class NotificationInfoTest extends SysuiTestCase {
@Test @Test
public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name); final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name);
assertEquals(View.GONE, groupNameView.getVisibility()); assertEquals(View.GONE, groupNameView.getVisibility());
final TextView groupDividerView = final TextView groupDividerView =
@@ -171,7 +171,7 @@ public class NotificationInfoTest extends SysuiTestCase {
eq("test_group_id"), eq(TEST_PACKAGE_NAME), anyInt())) eq("test_group_id"), eq(TEST_PACKAGE_NAME), anyInt()))
.thenReturn(notificationChannelGroup); .thenReturn(notificationChannelGroup);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name); final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name);
assertEquals(View.VISIBLE, groupNameView.getVisibility()); assertEquals(View.VISIBLE, groupNameView.getVisibility());
assertEquals("Test Group Name", groupNameView.getText()); assertEquals("Test Group Name", groupNameView.getText());
@@ -183,7 +183,7 @@ public class NotificationInfoTest extends SysuiTestCase {
@Test @Test
public void testBindNotification_SetsTextChannelName() throws Exception { public void testBindNotification_SetsTextChannelName() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name); final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
assertEquals(TEST_CHANNEL_NAME, textView.getText()); assertEquals(TEST_CHANNEL_NAME, textView.getText());
} }
@@ -196,7 +196,7 @@ public class NotificationInfoTest extends SysuiTestCase {
(View v, NotificationChannel c, int appUid) -> { (View v, NotificationChannel c, int appUid) -> {
assertEquals(mNotificationChannel, c); assertEquals(mNotificationChannel, c);
latch.countDown(); latch.countDown();
}, null, null); }, null, null, null);
final TextView settingsButton = final TextView settingsButton =
(TextView) mNotificationInfo.findViewById(R.id.more_settings); (TextView) mNotificationInfo.findViewById(R.id.more_settings);
@@ -214,7 +214,7 @@ public class NotificationInfoTest extends SysuiTestCase {
(View v, NotificationChannel c, int appUid) -> { (View v, NotificationChannel c, int appUid) -> {
assertEquals(null, c); assertEquals(null, c);
latch.countDown(); latch.countDown();
}, null, null); }, null, null, null);
final TextView settingsButton = final TextView settingsButton =
(TextView) mNotificationInfo.findViewById(R.id.more_settings); (TextView) mNotificationInfo.findViewById(R.id.more_settings);
@@ -227,7 +227,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testBindNotification_SettingsTextWithOneChannel() throws Exception { public void testBindNotification_SettingsTextWithOneChannel() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
(View v, NotificationChannel c, int appUid) -> {}, null, null); (View v, NotificationChannel c, int appUid) -> {}, null, null, null);
final TextView settingsButton = final TextView settingsButton =
(TextView) mNotificationInfo.findViewById(R.id.more_settings); (TextView) mNotificationInfo.findViewById(R.id.more_settings);
assertEquals(getStringById(R.string.notification_more_settings), settingsButton.getText()); assertEquals(getStringById(R.string.notification_more_settings), settingsButton.getText());
@@ -239,7 +239,7 @@ public class NotificationInfoTest extends SysuiTestCase {
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2); eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
(View v, NotificationChannel c, int appUid) -> {}, null, null); (View v, NotificationChannel c, int appUid) -> {}, null, null, null);
final TextView settingsButton = final TextView settingsButton =
(TextView) mNotificationInfo.findViewById(R.id.more_settings); (TextView) mNotificationInfo.findViewById(R.id.more_settings);
assertEquals(getStringById(R.string.notification_all_categories), settingsButton.getText()); assertEquals(getStringById(R.string.notification_all_categories), settingsButton.getText());
@@ -251,7 +251,7 @@ public class NotificationInfoTest extends SysuiTestCase {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null,
(View v) -> { latch.countDown(); }, (View v) -> { latch.countDown(); },
null); null, null);
final TextView doneButton = (TextView) mNotificationInfo.findViewById(R.id.done); final TextView doneButton = (TextView) mNotificationInfo.findViewById(R.id.done);
doneButton.performClick(); doneButton.performClick();
@@ -262,7 +262,8 @@ public class NotificationInfoTest extends SysuiTestCase {
@Test @Test
public void testBindNotification_NumChannelsTextUniqueWhenDefaultChannel() throws Exception { public void testBindNotification_NumChannelsTextUniqueWhenDefaultChannel() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals(View.VISIBLE, numChannelsView.getVisibility()); assertEquals(View.VISIBLE, numChannelsView.getVisibility());
@@ -274,7 +275,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel() public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel()
throws Exception { throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals(numChannelsView.getVisibility(), View.VISIBLE); assertEquals(numChannelsView.getVisibility(), View.VISIBLE);
@@ -287,7 +288,7 @@ public class NotificationInfoTest extends SysuiTestCase {
when(mMockINotificationManager.getNumNotificationChannelsForPackage( when(mMockINotificationManager.getNumNotificationChannelsForPackage(
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2); eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals(getNumChannelsDescString(2), numChannelsView.getText()); assertEquals(getNumChannelsDescString(2), numChannelsView.getText());
@@ -299,7 +300,7 @@ public class NotificationInfoTest extends SysuiTestCase {
throws Exception { throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
null, null, null); null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals(getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel), assertEquals(getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel),
@@ -315,7 +316,7 @@ public class NotificationInfoTest extends SysuiTestCase {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel), Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel),
null, null, null); null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals( assertEquals(
@@ -336,7 +337,7 @@ public class NotificationInfoTest extends SysuiTestCase {
TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel,
fourthChannel), fourthChannel),
null, null, null); null, null, null, null);
final TextView numChannelsView = final TextView numChannelsView =
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
assertEquals( assertEquals(
@@ -351,7 +352,7 @@ public class NotificationInfoTest extends SysuiTestCase {
throws Exception { throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
null, null, null); null, null, null, null);
final TextView channelNameView = final TextView channelNameView =
(TextView) mNotificationInfo.findViewById(R.id.channel_name); (TextView) mNotificationInfo.findViewById(R.id.channel_name);
assertEquals(getNumChannelsString(2), channelNameView.getText()); assertEquals(getNumChannelsString(2), channelNameView.getText());
@@ -362,7 +363,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledSwitchInvisibleIfBundleFromDifferentChannels() throws Exception { public void testEnabledSwitchInvisibleIfBundleFromDifferentChannels() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel),
null, null, null); null, null, null, null);
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
assertEquals(View.INVISIBLE, enabledSwitch.getVisibility()); assertEquals(View.INVISIBLE, enabledSwitch.getVisibility());
} }
@@ -370,7 +371,7 @@ public class NotificationInfoTest extends SysuiTestCase {
@Test @Test
public void testbindNotification_ChannelDisabledTextGoneWhenNotDisabled() throws Exception { public void testbindNotification_ChannelDisabledTextGoneWhenNotDisabled() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView channelDisabledView = final TextView channelDisabledView =
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled); (TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
assertEquals(channelDisabledView.getVisibility(), View.GONE); assertEquals(channelDisabledView.getVisibility(), View.GONE);
@@ -380,7 +381,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testbindNotification_ChannelDisabledTextVisibleWhenDisabled() throws Exception { public void testbindNotification_ChannelDisabledTextVisibleWhenDisabled() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
final TextView channelDisabledView = final TextView channelDisabledView =
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled); (TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
assertEquals(channelDisabledView.getVisibility(), View.VISIBLE); assertEquals(channelDisabledView.getVisibility(), View.VISIBLE);
@@ -396,35 +397,17 @@ public class NotificationInfoTest extends SysuiTestCase {
throws Exception { throws Exception {
mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
null, null, null, null);
final TextView channelDisabledView = final TextView channelDisabledView =
(TextView) mNotificationInfo.findViewById(R.id.channel_disabled); (TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
assertEquals(View.VISIBLE, channelDisabledView.getVisibility()); assertEquals(View.VISIBLE, channelDisabledView.getVisibility());
} }
@Test
@UiThreadTest
public void testHasImportanceChanged_DefaultsToFalse() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
assertFalse(mNotificationInfo.hasImportanceChanged());
}
@Test
public void testHasImportanceChanged_ReturnsTrueAfterChannelDisabled() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null);
// Find the high button and check it.
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
enabledSwitch.setChecked(false);
assertTrue(mNotificationInfo.hasImportanceChanged());
}
@Test @Test
public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
anyString(), anyInt(), any()); anyString(), anyInt(), any());
} }
@@ -433,7 +416,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
enabledSwitch.setChecked(false); enabledSwitch.setChecked(false);
@@ -445,7 +428,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
throws Exception { throws Exception {
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
mNotificationInfo.handleCloseControls(true); mNotificationInfo.handleCloseControls(true);
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
@@ -457,7 +440,7 @@ public class NotificationInfoTest extends SysuiTestCase {
throws Exception { throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
mNotificationInfo.handleCloseControls(true); mNotificationInfo.handleCloseControls(true);
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
@@ -468,7 +451,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledSwitchOnByDefault() throws Exception { public void testEnabledSwitchOnByDefault() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
assertTrue(enabledSwitch.isChecked()); assertTrue(enabledSwitch.isChecked());
@@ -478,7 +461,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledButtonOffWhenAlreadyBanned() throws Exception { public void testEnabledButtonOffWhenAlreadyBanned() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
assertFalse(enabledSwitch.isChecked()); assertFalse(enabledSwitch.isChecked());
@@ -488,7 +471,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledSwitchVisibleByDefault() throws Exception { public void testEnabledSwitchVisibleByDefault() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null, null);
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
assertEquals(View.VISIBLE, enabledSwitch.getVisibility()); assertEquals(View.VISIBLE, enabledSwitch.getVisibility());
@@ -498,7 +481,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledSwitchInvisibleIfNonBlockable() throws Exception { public void testEnabledSwitchInvisibleIfNonBlockable() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null,
Collections.singleton(TEST_PACKAGE_NAME)); Collections.singleton(TEST_PACKAGE_NAME));
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
@@ -509,7 +492,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null,
Collections.singleton(TEST_PACKAGE_NAME)); Collections.singleton(TEST_PACKAGE_NAME));
mNotificationInfo.handleCloseControls(true); mNotificationInfo.handleCloseControls(true);
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
@@ -520,7 +503,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testEnabledSwitchChangedCallsUpdateNotificationChannel() throws Exception { public void testEnabledSwitchChangedCallsUpdateNotificationChannel() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null,
Collections.singleton(TEST_PACKAGE_NAME)); Collections.singleton(TEST_PACKAGE_NAME));
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
@@ -534,7 +517,7 @@ public class NotificationInfoTest extends SysuiTestCase {
public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null, null,
Collections.singleton(TEST_PACKAGE_NAME)); Collections.singleton(TEST_PACKAGE_NAME));
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
@@ -543,4 +526,34 @@ public class NotificationInfoTest extends SysuiTestCase {
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel)); eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
} }
@Test
public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
(Runnable saveImportance) -> {},
Collections.singleton(TEST_PACKAGE_NAME));
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
enabledSwitch.setChecked(false);
mNotificationInfo.handleCloseControls(true);
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
}
@Test
public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), null, null,
(Runnable saveImportance) -> { saveImportance.run(); },
Collections.singleton(TEST_PACKAGE_NAME));
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
enabledSwitch.setChecked(false);
mNotificationInfo.handleCloseControls(true);
verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
}
} }