method public final int getCurrentInterruptionFilter();
method public final int getCurrentListenerHints();
method public android.service.notification.NotificationListenerService.RankingMap getCurrentRanking();
- method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String);
- method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
+ method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String, android.os.UserHandle);
+ method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String, android.os.UserHandle);
method public final android.service.notification.StatusBarNotification[] getSnoozedNotifications();
method public android.os.IBinder onBind(android.content.Intent);
method public void onInterruptionFilterChanged(int);
method public void onListenerConnected();
method public void onListenerDisconnected();
method public void onListenerHintsChanged(int);
- method public void onNotificationChannelGroupModified(java.lang.String, android.app.NotificationChannelGroup, int);
- method public void onNotificationChannelModified(java.lang.String, android.app.NotificationChannel, int);
+ method public void onNotificationChannelGroupModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannelGroup, int);
+ method public void onNotificationChannelModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannel, int);
method public void onNotificationPosted(android.service.notification.StatusBarNotification);
method public void onNotificationPosted(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap);
method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap);
method public final void requestUnbind();
method public final void setNotificationsShown(java.lang.String[]);
method public final void snoozeNotification(java.lang.String, long);
- method public final void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
+ method public final void updateNotificationChannel(java.lang.String, android.os.UserHandle, android.app.NotificationChannel);
field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
method public final int getCurrentInterruptionFilter();
method public final int getCurrentListenerHints();
method public android.service.notification.NotificationListenerService.RankingMap getCurrentRanking();
- method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String);
- method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
+ method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String, android.os.UserHandle);
+ method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String, android.os.UserHandle);
method public final android.service.notification.StatusBarNotification[] getSnoozedNotifications();
method public android.os.IBinder onBind(android.content.Intent);
method public void onInterruptionFilterChanged(int);
method public void onListenerConnected();
method public void onListenerDisconnected();
method public void onListenerHintsChanged(int);
- method public void onNotificationChannelGroupModified(java.lang.String, android.app.NotificationChannelGroup, int);
- method public void onNotificationChannelModified(java.lang.String, android.app.NotificationChannel, int);
+ method public void onNotificationChannelGroupModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannelGroup, int);
+ method public void onNotificationChannelModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannel, int);
method public void onNotificationPosted(android.service.notification.StatusBarNotification);
method public void onNotificationPosted(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap);
method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap);
method public final void snoozeNotification(java.lang.String, java.lang.String);
method public final void snoozeNotification(java.lang.String, long);
method public void unregisterAsSystemService() throws android.os.RemoteException;
- method public final void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
+ method public final void updateNotificationChannel(java.lang.String, android.os.UserHandle, android.app.NotificationChannel);
field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
method public final int getCurrentInterruptionFilter();
method public final int getCurrentListenerHints();
method public android.service.notification.NotificationListenerService.RankingMap getCurrentRanking();
- method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String);
- method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String);
+ method public final java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups(java.lang.String, android.os.UserHandle);
+ method public final java.util.List<android.app.NotificationChannel> getNotificationChannels(java.lang.String, android.os.UserHandle);
method public final android.service.notification.StatusBarNotification[] getSnoozedNotifications();
method public android.os.IBinder onBind(android.content.Intent);
method public void onInterruptionFilterChanged(int);
method public void onListenerConnected();
method public void onListenerDisconnected();
method public void onListenerHintsChanged(int);
- method public void onNotificationChannelGroupModified(java.lang.String, android.app.NotificationChannelGroup, int);
- method public void onNotificationChannelModified(java.lang.String, android.app.NotificationChannel, int);
+ method public void onNotificationChannelGroupModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannelGroup, int);
+ method public void onNotificationChannelModified(java.lang.String, android.os.UserHandle, android.app.NotificationChannel, int);
method public void onNotificationPosted(android.service.notification.StatusBarNotification);
method public void onNotificationPosted(android.service.notification.StatusBarNotification, android.service.notification.NotificationListenerService.RankingMap);
method public void onNotificationRankingUpdate(android.service.notification.NotificationListenerService.RankingMap);
method public final void setNotificationsShown(java.lang.String[]);
method public final void snoozeNotification(java.lang.String, java.lang.String);
method public final void snoozeNotification(java.lang.String, long);
- method public final void updateNotificationChannel(java.lang.String, android.app.NotificationChannel);
+ method public final void updateNotificationChannel(java.lang.String, android.os.UserHandle, android.app.NotificationChannel);
field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
import android.content.pm.ParceledListSlice;
import android.net.Uri;
import android.os.Bundle;
+import android.os.UserHandle;
import android.service.notification.Adjustment;
import android.service.notification.Condition;
import android.service.notification.IConditionListener;
void setOnNotificationPostedTrimFromListener(in INotificationListener token, int trim);
void setInterruptionFilter(String pkg, int interruptionFilter);
- void updateNotificationChannelFromPrivilegedListener(in INotificationListener token, String pkg, in NotificationChannel channel);
- ParceledListSlice getNotificationChannelsFromPrivilegedListener(in INotificationListener token, String pkg);
- ParceledListSlice getNotificationChannelGroupsFromPrivilegedListener(in INotificationListener token, String pkg);
+ void updateNotificationChannelFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user, in NotificationChannel channel);
+ ParceledListSlice getNotificationChannelsFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user);
+ ParceledListSlice getNotificationChannelGroupsFromPrivilegedListener(in INotificationListener token, String pkg, in UserHandle user);
void applyEnqueuedAdjustmentFromAssistant(in INotificationListener token, in Adjustment adjustment);
void applyAdjustmentFromAssistant(in INotificationListener token, in Adjustment adjustment);
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
+import android.os.UserHandle;
import android.service.notification.IStatusBarNotificationHolder;
import android.service.notification.StatusBarNotification;
import android.service.notification.NotificationRankingUpdate;
void onInterruptionFilterChanged(int interruptionFilter);
// companion device managers only
- void onNotificationChannelModification(String pkgName, in NotificationChannel channel, int modificationType);
- void onNotificationChannelGroupModification(String pkgName, in NotificationChannelGroup group, int modificationType);
+ void onNotificationChannelModification(String pkgName, in UserHandle user, in NotificationChannel channel, int modificationType);
+ void onNotificationChannelGroupModification(String pkgName, in UserHandle user, in NotificationChannelGroup group, int modificationType);
// rankers only
void onNotificationEnqueued(in IStatusBarNotificationHolder notificationHolder);
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
/**
* Channel or group modification reason provided to
- * {@link #onNotificationChannelModified(String, NotificationChannel, int)} or
- * {@link #onNotificationChannelGroupModified(String, NotificationChannelGroup, int)}- the
- * provided object was created.
+ * {@link #onNotificationChannelModified(String, UserHandle,NotificationChannel, int)} or
+ * {@link #onNotificationChannelGroupModified(String, UserHandle, NotificationChannelGroup,
+ * int)}- the provided object was created.
*/
public static final int NOTIFICATION_CHANNEL_OR_GROUP_ADDED = 1;
/**
* Channel or group modification reason provided to
- * {@link #onNotificationChannelModified(String, NotificationChannel, int)} or
- * {@link #onNotificationChannelGroupModified(String, NotificationChannelGroup, int)}- the
- * provided object was updated.
+ * {@link #onNotificationChannelModified(String, UserHandle, NotificationChannel, int)} or
+ * {@link #onNotificationChannelGroupModified(String, UserHandle,NotificationChannelGroup, int)}
+ * - the provided object was updated.
*/
public static final int NOTIFICATION_CHANNEL_OR_GROUP_UPDATED = 2;
/**
* Channel or group modification reason provided to
- * {@link #onNotificationChannelModified(String, NotificationChannel, int)} or
- * {@link #onNotificationChannelGroupModified(String, NotificationChannelGroup, int)}- the
- * provided object was deleted.
+ * {@link #onNotificationChannelModified(String, UserHandle, NotificationChannel, int)} or
+ * {@link #onNotificationChannelGroupModified(String, UserHandle, NotificationChannelGroup,
+ * int)}- the provided object was deleted.
*/
public static final int NOTIFICATION_CHANNEL_OR_GROUP_DELETED = 3;
* device} in order to receive this callback.
*
* @param pkg The package the channel belongs to.
+ * @param user The user on which the change was made.
* @param channel The channel that has changed.
* @param modificationType One of {@link #NOTIFICATION_CHANNEL_OR_GROUP_ADDED},
* {@link #NOTIFICATION_CHANNEL_OR_GROUP_UPDATED},
* {@link #NOTIFICATION_CHANNEL_OR_GROUP_DELETED}.
*/
- public void onNotificationChannelModified(String pkg, NotificationChannel channel,
- @ChannelOrGroupModificationTypes int modificationType) {
+ public void onNotificationChannelModified(String pkg, UserHandle user,
+ NotificationChannel channel, @ChannelOrGroupModificationTypes int modificationType) {
// optional
}
* device} in order to receive this callback.
*
* @param pkg The package the group belongs to.
+ * @param user The user on which the change was made.
* @param group The group that has changed.
* @param modificationType One of {@link #NOTIFICATION_CHANNEL_OR_GROUP_ADDED},
* {@link #NOTIFICATION_CHANNEL_OR_GROUP_UPDATED},
* {@link #NOTIFICATION_CHANNEL_OR_GROUP_DELETED}.
*/
- public void onNotificationChannelGroupModified(String pkg, NotificationChannelGroup group,
- @ChannelOrGroupModificationTypes int modificationType) {
+ public void onNotificationChannelGroupModified(String pkg, UserHandle user,
+ NotificationChannelGroup group, @ChannelOrGroupModificationTypes int modificationType) {
// optional
}
/**
- * Updates a notification channel for a given package. This should only be used to reflect
- * changes a user has made to the channel via the listener's user interface.
+ * Updates a notification channel for a given package for a given user. This should only be used
+ * to reflect changes a user has made to the channel via the listener's user interface.
*
+ * <p>This method will throw a security exception if you don't have access to notifications
+ * for the given user.</p>
* <p>The caller must have {@link CompanionDeviceManager#getAssociations() an associated
* device} in order to use this method.
*
* @param pkg The package the channel belongs to.
+ * @param user The user the channel belongs to.
* @param channel the channel to update.
*/
- public final void updateNotificationChannel(@NonNull String pkg,
+ public final void updateNotificationChannel(@NonNull String pkg, @NonNull UserHandle user,
@NonNull NotificationChannel channel) {
if (!isBound()) return;
try {
getNotificationInterface().updateNotificationChannelFromPrivilegedListener(
- mWrapper, pkg, channel);
+ mWrapper, pkg, user, channel);
} catch (RemoteException e) {
Log.v(TAG, "Unable to contact notification manager", e);
throw e.rethrowFromSystemServer();
}
/**
- * Returns all notification channels belonging to the given package.
+ * Returns all notification channels belonging to the given package for a given user.
*
+ * <p>This method will throw a security exception if you don't have access to notifications
+ * for the given user.</p>
* <p>The caller must have {@link CompanionDeviceManager#getAssociations() an associated
* device} in order to use this method.
*
* @param pkg The package to retrieve channels for.
*/
- public final List<NotificationChannel> getNotificationChannels(@NonNull String pkg) {
+ public final List<NotificationChannel> getNotificationChannels(@NonNull String pkg,
+ @NonNull UserHandle user) {
if (!isBound()) return null;
try {
return getNotificationInterface().getNotificationChannelsFromPrivilegedListener(
- mWrapper, pkg).getList();
+ mWrapper, pkg, user).getList();
} catch (RemoteException e) {
Log.v(TAG, "Unable to contact notification manager", e);
throw e.rethrowFromSystemServer();
}
/**
- * Returns all notification channel groups belonging to the given package.
+ * Returns all notification channel groups belonging to the given package for a given user.
*
+ * <p>This method will throw a security exception if you don't have access to notifications
+ * for the given user.</p>
* <p>The caller must have {@link CompanionDeviceManager#getAssociations() an associated
* device} in order to use this method.
*
* @param pkg The package to retrieve channel groups for.
*/
- public final List<NotificationChannelGroup> getNotificationChannelGroups(@NonNull String pkg) {
+ public final List<NotificationChannelGroup> getNotificationChannelGroups(@NonNull String pkg,
+ @NonNull UserHandle user) {
if (!isBound()) return null;
try {
return getNotificationInterface().getNotificationChannelGroupsFromPrivilegedListener(
- mWrapper, pkg).getList();
+ mWrapper, pkg, user).getList();
} catch (RemoteException e) {
Log.v(TAG, "Unable to contact notification manager", e);
throw e.rethrowFromSystemServer();
}
@Override
- public void onNotificationChannelModification(String pkgName, NotificationChannel channel,
+ public void onNotificationChannelModification(String pkgName, UserHandle user,
+ NotificationChannel channel,
@ChannelOrGroupModificationTypes int modificationType) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = pkgName;
- args.arg2 = channel;
- args.arg3 = modificationType;
+ args.arg2 = user;
+ args.arg3 = channel;
+ args.arg4 = modificationType;
mHandler.obtainMessage(
MyHandler.MSG_ON_NOTIFICATION_CHANNEL_MODIFIED, args).sendToTarget();
}
@Override
- public void onNotificationChannelGroupModification(String pkgName,
+ public void onNotificationChannelGroupModification(String pkgName, UserHandle user,
NotificationChannelGroup group,
@ChannelOrGroupModificationTypes int modificationType) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = pkgName;
- args.arg2 = group;
- args.arg3 = modificationType;
+ args.arg2 = user;
+ args.arg3 = group;
+ args.arg4 = modificationType;
mHandler.obtainMessage(
MyHandler.MSG_ON_NOTIFICATION_CHANNEL_GROUP_MODIFIED, args).sendToTarget();
}
case MSG_ON_NOTIFICATION_CHANNEL_MODIFIED: {
SomeArgs args = (SomeArgs) msg.obj;
String pkgName = (String) args.arg1;
- NotificationChannel channel = (NotificationChannel) args.arg2;
- int modificationType = (int) args.arg3;
- onNotificationChannelModified(pkgName, channel, modificationType);
+ UserHandle user= (UserHandle) args.arg2;
+ NotificationChannel channel = (NotificationChannel) args.arg3;
+ int modificationType = (int) args.arg4;
+ onNotificationChannelModified(pkgName, user, channel, modificationType);
} break;
case MSG_ON_NOTIFICATION_CHANNEL_GROUP_MODIFIED: {
SomeArgs args = (SomeArgs) msg.obj;
String pkgName = (String) args.arg1;
- NotificationChannelGroup group = (NotificationChannelGroup) args.arg2;
- int modificationType = (int) args.arg3;
- onNotificationChannelGroupModified(pkgName, group, modificationType);
+ UserHandle user = (UserHandle) args.arg2;
+ NotificationChannelGroup group = (NotificationChannelGroup) args.arg3;
+ int modificationType = (int) args.arg4;
+ onNotificationChannelGroupModified(pkgName, user, group, modificationType);
} break;
}
}
if (!fromListener) {
mListeners.notifyNotificationChannelChanged(
- pkg, modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED);
+ pkg, UserHandle.getUserHandleForUid(uid),
+ modifiedChannel, NOTIFICATION_CHANNEL_OR_GROUP_UPDATED);
}
synchronized (mNotificationLock) {
Preconditions.checkNotNull(group, "group in list is null");
mRankingHelper.createNotificationChannelGroup(pkg, Binder.getCallingUid(), group,
true /* fromTargetApp */);
- mListeners.notifyNotificationChannelGroupChanged(pkg, group,
+ mListeners.notifyNotificationChannelGroupChanged(pkg,
+ UserHandle.of(UserHandle.getCallingUserId()), group,
NOTIFICATION_CHANNEL_OR_GROUP_ADDED);
}
savePolicyFile();
mRankingHelper.createNotificationChannel(pkg, uid, channel,
true /* fromTargetApp */);
mListeners.notifyNotificationChannelChanged(pkg,
+ UserHandle.getUserHandleForUid(uid),
mRankingHelper.getNotificationChannel(pkg, uid, channel.getId(), false),
NOTIFICATION_CHANNEL_OR_GROUP_ADDED);
}
UserHandle.getUserId(callingUid), REASON_CHANNEL_BANNED, null);
mRankingHelper.deleteNotificationChannel(pkg, callingUid, channelId);
mListeners.notifyNotificationChannelChanged(pkg,
+ UserHandle.getUserHandleForUid(callingUid),
mRankingHelper.getNotificationChannel(pkg, callingUid, channelId, true),
NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
savePolicyFile();
true,
UserHandle.getUserId(Binder.getCallingUid()), REASON_CHANNEL_BANNED,
null);
- mListeners.notifyNotificationChannelChanged(pkg, deletedChannel,
+ mListeners.notifyNotificationChannelChanged(pkg,
+ UserHandle.getUserHandleForUid(callingUid),
+ deletedChannel,
NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
}
mListeners.notifyNotificationChannelGroupChanged(
- pkg, groupToDelete, NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
+ pkg, UserHandle.getUserHandleForUid(callingUid), groupToDelete,
+ NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
savePolicyFile();
}
}
@Override
public void updateNotificationChannelFromPrivilegedListener(INotificationListener token,
- String pkg, NotificationChannel channel) throws RemoteException {
+ String pkg, UserHandle user, NotificationChannel channel) throws RemoteException {
Preconditions.checkNotNull(channel);
+ Preconditions.checkNotNull(pkg);
+ Preconditions.checkNotNull(user);
- ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token);
- if (!hasCompanionDevice(info)) {
- throw new SecurityException(info + " does not have access");
- }
-
- int uid = mPackageManager.getPackageUid(pkg, 0, info.userid);
- updateNotificationChannelInt(pkg, uid, channel, true);
+ verifyPrivilegedListener(token, user);
+ updateNotificationChannelInt(pkg, getUidForPackageAndUser(pkg, user), channel, true);
}
@Override
public ParceledListSlice<NotificationChannel> getNotificationChannelsFromPrivilegedListener(
- INotificationListener token, String pkg) throws RemoteException {
- ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token);
- if (!hasCompanionDevice(info)) {
- throw new SecurityException(info + " does not have access");
- }
+ INotificationListener token, String pkg, UserHandle user) throws RemoteException {
+ Preconditions.checkNotNull(pkg);
+ Preconditions.checkNotNull(user);
+ verifyPrivilegedListener(token, user);
- int uid = mPackageManager.getPackageUid(pkg, 0, info.userid);
- return mRankingHelper.getNotificationChannels(pkg, uid, false /* includeDeleted */);
+ return mRankingHelper.getNotificationChannels(pkg, getUidForPackageAndUser(pkg, user),
+ false /* includeDeleted */);
}
@Override
public ParceledListSlice<NotificationChannelGroup>
getNotificationChannelGroupsFromPrivilegedListener(
- INotificationListener token, String pkg) throws RemoteException {
+ INotificationListener token, String pkg, UserHandle user) throws RemoteException {
+ Preconditions.checkNotNull(pkg);
+ Preconditions.checkNotNull(user);
+ verifyPrivilegedListener(token, user);
+
+ List<NotificationChannelGroup> groups = new ArrayList<>();
+ groups.addAll(mRankingHelper.getNotificationChannelGroups(
+ pkg, getUidForPackageAndUser(pkg, user)));
+ return new ParceledListSlice<>(groups);
+ }
+
+ private void verifyPrivilegedListener(INotificationListener token, UserHandle user) {
ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token);
if (!hasCompanionDevice(info)) {
throw new SecurityException(info + " does not have access");
}
+ if (!info.enabledAndUserMatches(user.getIdentifier())) {
+ throw new SecurityException(info + " does not have access");
+ }
+ }
- List<NotificationChannelGroup> groups = new ArrayList<>();
- int uid = mPackageManager.getPackageUid(pkg, 0, info.userid);
- groups.addAll(mRankingHelper.getNotificationChannelGroups(pkg, uid));
- return new ParceledListSlice<>(groups);
+ private int getUidForPackageAndUser(String pkg, UserHandle user) throws RemoteException {
+ int uid = 0;
+ long identity = Binder.clearCallingIdentity();
+ try {
+ uid = mPackageManager.getPackageUid(pkg, 0, user.getIdentifier());
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ return uid;
}
};
}
}
- protected void notifyNotificationChannelChanged(final String pkg,
+ protected void notifyNotificationChannelChanged(final String pkg, final UserHandle user,
final NotificationChannel channel, final int modificationType) {
if (channel == null) {
return;
mHandler.post(new Runnable() {
@Override
public void run() {
- notifyNotificationChannelChanged(serviceInfo, pkg, channel,
- modificationType);
+ notifyNotificationChannelChanged(
+ serviceInfo, pkg, user, channel, modificationType);
}
});
}
}
- protected void notifyNotificationChannelGroupChanged(final String pkg,
- final NotificationChannelGroup group, final int modificationType) {
+ protected void notifyNotificationChannelGroupChanged(
+ final String pkg, final UserHandle user, final NotificationChannelGroup group,
+ final int modificationType) {
if (group == null) {
return;
}
mHandler.post(new Runnable() {
@Override
public void run() {
- notifyNotificationChannelGroupChanged(serviceInfo, pkg, group,
- modificationType);
+ notifyNotificationChannelGroupChanged(
+ serviceInfo, pkg, user, group, modificationType);
}
});
}
}
void notifyNotificationChannelChanged(ManagedServiceInfo info,
- final String pkg, final NotificationChannel channel,
+ final String pkg, final UserHandle user, final NotificationChannel channel,
final int modificationType) {
final INotificationListener listener = (INotificationListener) info.service;
try {
- listener.onNotificationChannelModification(pkg, channel, modificationType);
+ listener.onNotificationChannelModification(pkg, user, channel, modificationType);
} catch (RemoteException ex) {
Log.e(TAG, "unable to notify listener (channel changed): " + listener, ex);
}
}
private void notifyNotificationChannelGroupChanged(ManagedServiceInfo info,
- final String pkg, final NotificationChannelGroup group,
+ final String pkg, final UserHandle user, final NotificationChannelGroup group,
final int modificationType) {
final INotificationListener listener = (INotificationListener) info.service;
try {
- listener.onNotificationChannelGroupModification(pkg, group, modificationType);
+ listener.onNotificationChannelGroupModification(pkg, user, group, modificationType);
} catch (RemoteException ex) {
Log.e(TAG, "unable to notify listener (channel group changed): " + listener, ex);
}
import android.content.pm.ParceledListSlice;
import android.graphics.Color;
import android.os.Binder;
+import android.os.Process;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
mBinderService.createNotificationChannels(PKG,
new ParceledListSlice(Arrays.asList(mTestNotificationChannel, channel2)));
verify(mNotificationListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
- eq(mTestNotificationChannel),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED));
verify(mNotificationListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
- eq(channel2),
+ eq(Process.myUserHandle()), eq(channel2),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED));
}
mBinderService.createNotificationChannelGroups(PKG,
new ParceledListSlice(Arrays.asList(group1, group2)));
verify(mNotificationListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG),
- eq(group1),
+ eq(Process.myUserHandle()), eq(group1),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED));
verify(mNotificationListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG),
- eq(group2),
+ eq(Process.myUserHandle()), eq(group2),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED));
}
reset(mNotificationListeners);
mBinderService.updateNotificationChannelForPackage(PKG, 0, mTestNotificationChannel);
verify(mNotificationListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
- eq(mTestNotificationChannel),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
}
reset(mNotificationListeners);
mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId());
verify(mNotificationListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
- eq(mTestNotificationChannel),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED));
}
reset(mNotificationListeners);
mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId());
verify(mNotificationListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG),
- eq(ncg),
+ eq(Process.myUserHandle()), eq(ncg),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED));
}
when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
mBinderService.updateNotificationChannelFromPrivilegedListener(
- null, PKG, mTestNotificationChannel);
+ null, PKG, Process.myUserHandle(), mTestNotificationChannel);
verify(mRankingHelper, times(1)).updateNotificationChannel(anyString(), anyInt(), any());
verify(mNotificationListeners, never()).notifyNotificationChannelChanged(eq(PKG),
- eq(mTestNotificationChannel),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
}
try {
mBinderService.updateNotificationChannelFromPrivilegedListener(
- null, PKG, mTestNotificationChannel);
+ null, PKG, Process.myUserHandle(), mTestNotificationChannel);
fail("listeners that don't have a companion device shouldn't be able to call this");
} catch (SecurityException e) {
// pass
verify(mRankingHelper, never()).updateNotificationChannel(anyString(), anyInt(), any());
verify(mNotificationListeners, never()).notifyNotificationChannelChanged(eq(PKG),
- eq(mTestNotificationChannel),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
+ eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
+ }
+
+ @Test
+ @UiThreadTest
+ public void testUpdateNotificationChannelFromPrivilegedListener_badUser() throws Exception {
+ mNotificationManagerService.setRankingHelper(mRankingHelper);
+ List<String> associations = new ArrayList<>();
+ associations.add("a");
+ when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
+ mListener = mock(ManagedServices.ManagedServiceInfo.class);
+ when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
+ when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
+
+ try {
+ mBinderService.updateNotificationChannelFromPrivilegedListener(
+ null, PKG, UserHandle.ALL, mTestNotificationChannel);
+ fail("incorrectly allowed a change to a user listener cannot see");
+ } catch (SecurityException e) {
+ // pass
+ }
+
+ verify(mRankingHelper, never()).updateNotificationChannel(anyString(), anyInt(), any());
+
+ verify(mNotificationListeners, never()).notifyNotificationChannelChanged(eq(PKG),
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
}
associations.add("a");
when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
- mBinderService.getNotificationChannelsFromPrivilegedListener(null, PKG);
+ mBinderService.getNotificationChannelsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
verify(mRankingHelper, times(1)).getNotificationChannels(
anyString(), anyInt(), anyBoolean());
when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
try {
- mBinderService.getNotificationChannelsFromPrivilegedListener(null, PKG);
+ mBinderService.getNotificationChannelsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
fail("listeners that don't have a companion device shouldn't be able to call this");
} catch (SecurityException e) {
// pass
@Test
@UiThreadTest
+ public void testGetNotificationChannelFromPrivilegedListener_badUser() throws Exception {
+ mNotificationManagerService.setRankingHelper(mRankingHelper);
+ List<String> associations = new ArrayList<>();
+ associations.add("a");
+ when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
+ mListener = mock(ManagedServices.ManagedServiceInfo.class);
+ when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
+ when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
+
+ try {
+ mBinderService.getNotificationChannelsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
+ fail("listener getting channels from a user they cannot see");
+ } catch (SecurityException e) {
+ // pass
+ }
+
+ verify(mRankingHelper, never()).getNotificationChannels(
+ anyString(), anyInt(), anyBoolean());
+ }
+
+ @Test
+ @UiThreadTest
public void testGetNotificationChannelGroupsFromPrivilegedListener_success() throws Exception {
mNotificationManagerService.setRankingHelper(mRankingHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
- mBinderService.getNotificationChannelGroupsFromPrivilegedListener(null, PKG);
+ mBinderService.getNotificationChannelGroupsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
verify(mRankingHelper, times(1)).getNotificationChannelGroups(anyString(), anyInt());
}
when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
try {
- mBinderService.getNotificationChannelGroupsFromPrivilegedListener(null, PKG);
+ mBinderService.getNotificationChannelGroupsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
+ fail("listeners that don't have a companion device shouldn't be able to call this");
+ } catch (SecurityException e) {
+ // pass
+ }
+
+ verify(mRankingHelper, never()).getNotificationChannelGroups(anyString(), anyInt());
+ }
+
+ @Test
+ @UiThreadTest
+ public void testGetNotificationChannelGroupsFromPrivilegedListener_badUser() throws Exception {
+ mNotificationManagerService.setRankingHelper(mRankingHelper);
+ List<String> associations = new ArrayList<>();
+ when(mCompanionMgr.getAssociations(PKG, uid)).thenReturn(associations);
+ mListener = mock(ManagedServices.ManagedServiceInfo.class);
+ when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
+ when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
+
+ try {
+ mBinderService.getNotificationChannelGroupsFromPrivilegedListener(
+ null, PKG, Process.myUserHandle());
fail("listeners that don't have a companion device shouldn't be able to call this");
} catch (SecurityException e) {
// pass