Merge "Don't do un-needed work" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d4cfd70d69
@@ -3815,15 +3815,18 @@ public class NotificationManagerService extends SystemService {
|
||||
enforceDeletingChannelHasNoFgService(pkg, callingUser, channelId);
|
||||
cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true,
|
||||
callingUser, REASON_CHANNEL_REMOVED, null);
|
||||
mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId);
|
||||
// Remove from both recent notification archive and notification history
|
||||
mArchive.removeChannelNotifications(pkg, callingUser, channelId);
|
||||
mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId);
|
||||
mListeners.notifyNotificationChannelChanged(pkg,
|
||||
UserHandle.getUserHandleForUid(callingUid),
|
||||
mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true),
|
||||
NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
|
||||
handleSavePolicyFile();
|
||||
boolean previouslyExisted = mPreferencesHelper.deleteNotificationChannel(
|
||||
pkg, callingUid, channelId);
|
||||
if (previouslyExisted) {
|
||||
// Remove from both recent notification archive and notification history
|
||||
mArchive.removeChannelNotifications(pkg, callingUser, channelId);
|
||||
mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId);
|
||||
mListeners.notifyNotificationChannelChanged(pkg,
|
||||
UserHandle.getUserHandleForUid(callingUid),
|
||||
mPreferencesHelper.getNotificationChannel(pkg, callingUid, channelId, true),
|
||||
NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
|
||||
handleSavePolicyFile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1126,20 +1126,21 @@ public class PreferencesHelper implements RankingConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteNotificationChannel(String pkg, int uid, String channelId) {
|
||||
public boolean deleteNotificationChannel(String pkg, int uid, String channelId) {
|
||||
synchronized (mPackagePreferences) {
|
||||
PackagePreferences r = getPackagePreferencesLocked(pkg, uid);
|
||||
if (r == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
NotificationChannel channel = r.channels.get(channelId);
|
||||
if (channel != null) {
|
||||
deleteNotificationChannelLocked(channel, pkg, uid);
|
||||
return deleteNotificationChannelLocked(channel, pkg, uid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) {
|
||||
private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) {
|
||||
if (!channel.isDeleted()) {
|
||||
channel.setDeleted(true);
|
||||
channel.setDeletedTimeMs(System.currentTimeMillis());
|
||||
@@ -1151,7 +1152,9 @@ public class PreferencesHelper implements RankingConfig {
|
||||
if (mAreChannelsBypassingDnd && channel.canBypassDnd()) {
|
||||
updateChannelsBypassingDnd();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface RankingConfig {
|
||||
NotificationChannel getConversationNotificationChannel(String pkg, int uid, String channelId,
|
||||
String conversationId, boolean returnParentIfNoConversationChannel,
|
||||
boolean includeDeleted);
|
||||
void deleteNotificationChannel(String pkg, int uid, String channelId);
|
||||
boolean deleteNotificationChannel(String pkg, int uid, String channelId);
|
||||
void permanentlyDeleteNotificationChannel(String pkg, int uid, String channelId);
|
||||
void permanentlyDeleteNotificationChannels(String pkg, int uid);
|
||||
ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid,
|
||||
|
||||
@@ -94,6 +94,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
@@ -2425,6 +2426,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
|
||||
eq(mTestNotificationChannel.getId()), anyBoolean()))
|
||||
.thenReturn(mTestNotificationChannel);
|
||||
when(mPreferencesHelper.deleteNotificationChannel(eq(PKG), anyInt(),
|
||||
eq(mTestNotificationChannel.getId()))).thenReturn(true);
|
||||
reset(mListeners);
|
||||
mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId());
|
||||
verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
|
||||
@@ -2432,6 +2435,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteChannelOnlyDoExtraWorkIfExisted() throws Exception {
|
||||
List<String> associations = new ArrayList<>();
|
||||
associations.add("a");
|
||||
when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
|
||||
.thenReturn(associations);
|
||||
mService.setPreferencesHelper(mPreferencesHelper);
|
||||
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
|
||||
eq(mTestNotificationChannel.getId()), anyBoolean()))
|
||||
.thenReturn(null);
|
||||
reset(mListeners);
|
||||
mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId());
|
||||
verifyNoMoreInteractions(mListeners);
|
||||
verifyNoMoreInteractions(mHistoryManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteChannelGroupNotifyListener() throws Exception {
|
||||
List<String> associations = new ArrayList<>();
|
||||
|
||||
@@ -3332,6 +3332,17 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
||||
assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, "id", true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleted_twice() throws Exception {
|
||||
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
|
||||
mAppOpsManager, mStatsEventBuilderFactory);
|
||||
|
||||
mHelper.createNotificationChannel(
|
||||
PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false);
|
||||
assertTrue(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id"));
|
||||
assertFalse(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleted_recentTime() throws Exception {
|
||||
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
|
||||
|
||||
Reference in New Issue
Block a user