Merge "Protect all calls to mShortcutHelper with null check" into rvc-dev

This commit is contained in:
Mady Mellor
2020-04-02 19:10:45 +00:00
committed by Android (Google) Code Review
2 changed files with 51 additions and 16 deletions

View File

@@ -107,7 +107,6 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.RequiresPermission; import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.annotation.WorkerThread; import android.annotation.WorkerThread;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManagerInternal; import android.app.ActivityManagerInternal;
@@ -155,6 +154,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice; import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver; import android.database.ContentObserver;
@@ -1729,6 +1729,11 @@ public class NotificationManagerService extends SystemService {
return mShortcutHelper; return mShortcutHelper;
} }
@VisibleForTesting
void setShortcutHelper(ShortcutHelper helper) {
mShortcutHelper = helper;
}
@VisibleForTesting @VisibleForTesting
void setHints(int hints) { void setHints(int hints) {
mListenerHints = hints; mListenerHints = hints;
@@ -3459,10 +3464,14 @@ public class NotificationManagerService extends SystemService {
ArrayList<ConversationChannelWrapper> conversations = ArrayList<ConversationChannelWrapper> conversations =
mPreferencesHelper.getConversations(onlyImportant); mPreferencesHelper.getConversations(onlyImportant);
for (ConversationChannelWrapper conversation : conversations) { for (ConversationChannelWrapper conversation : conversations) {
conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo( if (mShortcutHelper == null) {
conversation.getNotificationChannel().getConversationId(), conversation.setShortcutInfo(null);
conversation.getPkg(), } else {
UserHandle.of(UserHandle.getUserId(conversation.getUid())))); conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo(
conversation.getNotificationChannel().getConversationId(),
conversation.getPkg(),
UserHandle.of(UserHandle.getUserId(conversation.getUid()))));
}
} }
return new ParceledListSlice<>(conversations); return new ParceledListSlice<>(conversations);
} }
@@ -3482,10 +3491,14 @@ public class NotificationManagerService extends SystemService {
ArrayList<ConversationChannelWrapper> conversations = ArrayList<ConversationChannelWrapper> conversations =
mPreferencesHelper.getConversations(pkg, uid); mPreferencesHelper.getConversations(pkg, uid);
for (ConversationChannelWrapper conversation : conversations) { for (ConversationChannelWrapper conversation : conversations) {
conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo( if (mShortcutHelper == null) {
conversation.getNotificationChannel().getConversationId(), conversation.setShortcutInfo(null);
pkg, } else {
UserHandle.of(UserHandle.getUserId(uid)))); conversation.setShortcutInfo(mShortcutHelper.getValidShortcutInfo(
conversation.getNotificationChannel().getConversationId(),
pkg,
UserHandle.of(UserHandle.getUserId(uid))));
}
} }
return new ParceledListSlice<>(conversations); return new ParceledListSlice<>(conversations);
} }
@@ -5680,8 +5693,10 @@ public class NotificationManagerService extends SystemService {
} }
} }
r.setShortcutInfo(mShortcutHelper.getValidShortcutInfo( ShortcutInfo info = mShortcutHelper != null
notification.getShortcutId(), pkg, user)); ? mShortcutHelper.getValidShortcutInfo(notification.getShortcutId(), pkg, user)
: null;
r.setShortcutInfo(info);
if (!checkDisqualifyingFeatures(userId, notificationUid, id, tag, r, if (!checkDisqualifyingFeatures(userId, notificationUid, id, tag, r,
r.getSbn().getOverrideGroupKey() != null)) { r.getSbn().getOverrideGroupKey() != null)) {
@@ -6214,8 +6229,11 @@ public class NotificationManagerService extends SystemService {
cancelGroupChildrenLocked(r, mCallingUid, mCallingPid, listenerName, cancelGroupChildrenLocked(r, mCallingUid, mCallingPid, listenerName,
mSendDelete, childrenFlagChecker); mSendDelete, childrenFlagChecker);
updateLightsLocked(); updateLightsLocked();
mShortcutHelper.maybeListenForShortcutChangesForBubbles(r, true /* isRemoved */, if (mShortcutHelper != null) {
mHandler); mShortcutHelper.maybeListenForShortcutChangesForBubbles(r,
true /* isRemoved */,
mHandler);
}
} else { } else {
// No notification was found, assume that it is snoozed and cancel it. // No notification was found, assume that it is snoozed and cancel it.
if (mReason != REASON_SNOOZED) { if (mReason != REASON_SNOOZED) {
@@ -6453,9 +6471,11 @@ public class NotificationManagerService extends SystemService {
+ n.getPackageName()); + n.getPackageName());
} }
mShortcutHelper.maybeListenForShortcutChangesForBubbles(r, if (mShortcutHelper != null) {
false /* isRemoved */, mShortcutHelper.maybeListenForShortcutChangesForBubbles(r,
mHandler); false /* isRemoved */,
mHandler);
}
maybeRecordInterruptionLocked(r); maybeRecordInterruptionLocked(r);

View File

@@ -6504,4 +6504,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertNull(conversations.get(0).getShortcutInfo()); assertNull(conversations.get(0).getShortcutInfo());
assertNull(conversations.get(1).getShortcutInfo()); assertNull(conversations.get(1).getShortcutInfo());
} }
@Test
public void testShortcutHelperNull_doesntCrashEnqueue() throws RemoteException {
mService.setShortcutHelper(null);
NotificationRecord nr =
generateMessageBubbleNotifRecord(mTestNotificationChannel,
"testShortcutHelperNull_doesntCrashEnqueue");
try {
mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
waitForIdle();
} catch (Exception e) {
fail(e.getMessage());
}
}
} }