Loading core/java/android/app/NotificationManager.java +26 −3 Original line number Diff line number Diff line Loading @@ -25,8 +25,12 @@ import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; import android.annotation.UserHandleAware; import android.annotation.WorkerThread; import android.app.Notification.Builder; import android.app.compat.CompatChanges; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -1658,6 +1662,19 @@ public class NotificationManager { setNotificationListenerAccessGranted(listener, granted, true); } /** * For apps targeting {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, the * {@code setNotificationListenerAccessGranted} method will use the user contained within the * context. * For apps targeting an SDK version <em>below</em> this, the user of the calling process will * be used (Process.myUserHandle()). * * @hide */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) public static final long SET_LISTENER_ACCESS_GRANTED_IS_USER_AWARE = 302563478L; /** * Grants/revokes Notification Listener access to the given component for current user. * To grant access for a particular user, obtain this service by using the {@link Context} Loading @@ -1670,12 +1687,18 @@ public class NotificationManager { */ @SystemApi @TestApi @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted( @NonNull ComponentName listener, boolean granted, boolean userSet) { INotificationManager service = getService(); try { if (CompatChanges.isChangeEnabled(SET_LISTENER_ACCESS_GRANTED_IS_USER_AWARE)) { service.setNotificationListenerAccessGrantedForUser(listener, mContext.getUserId(), granted, userSet); } else { service.setNotificationListenerAccessGranted(listener, granted, userSet); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +8 −4 Original line number Diff line number Diff line Loading @@ -5734,13 +5734,18 @@ public class NotificationManagerService extends SystemService { public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId, boolean granted, boolean userSet) { Objects.requireNonNull(listener); if (UserHandle.getCallingUserId() != userId) { getContext().enforceCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS, "setNotificationListenerAccessGrantedForUser for user " + userId); } checkNotificationListenerAccess(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } if (!userSet && isNotificationListenerAccessUserSet(listener)) { if (!userSet && isNotificationListenerAccessUserSet(listener, userId)) { // Don't override user's choice return; } Loading @@ -5766,9 +5771,8 @@ public class NotificationManagerService extends SystemService { } } private boolean isNotificationListenerAccessUserSet(ComponentName listener) { return mListeners.isPackageOrComponentUserSet(listener.flattenToString(), getCallingUserHandle().getIdentifier()); private boolean isNotificationListenerAccessUserSet(ComponentName listener, int userId) { return mListeners.isPackageOrComponentUserSet(listener.flattenToString(), userId); } @Override Loading Loading
core/java/android/app/NotificationManager.java +26 −3 Original line number Diff line number Diff line Loading @@ -25,8 +25,12 @@ import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; import android.annotation.UserHandleAware; import android.annotation.WorkerThread; import android.app.Notification.Builder; import android.app.compat.CompatChanges; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -1658,6 +1662,19 @@ public class NotificationManager { setNotificationListenerAccessGranted(listener, granted, true); } /** * For apps targeting {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, the * {@code setNotificationListenerAccessGranted} method will use the user contained within the * context. * For apps targeting an SDK version <em>below</em> this, the user of the calling process will * be used (Process.myUserHandle()). * * @hide */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) public static final long SET_LISTENER_ACCESS_GRANTED_IS_USER_AWARE = 302563478L; /** * Grants/revokes Notification Listener access to the given component for current user. * To grant access for a particular user, obtain this service by using the {@link Context} Loading @@ -1670,12 +1687,18 @@ public class NotificationManager { */ @SystemApi @TestApi @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted( @NonNull ComponentName listener, boolean granted, boolean userSet) { INotificationManager service = getService(); try { if (CompatChanges.isChangeEnabled(SET_LISTENER_ACCESS_GRANTED_IS_USER_AWARE)) { service.setNotificationListenerAccessGrantedForUser(listener, mContext.getUserId(), granted, userSet); } else { service.setNotificationListenerAccessGranted(listener, granted, userSet); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +8 −4 Original line number Diff line number Diff line Loading @@ -5734,13 +5734,18 @@ public class NotificationManagerService extends SystemService { public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId, boolean granted, boolean userSet) { Objects.requireNonNull(listener); if (UserHandle.getCallingUserId() != userId) { getContext().enforceCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS, "setNotificationListenerAccessGrantedForUser for user " + userId); } checkNotificationListenerAccess(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } if (!userSet && isNotificationListenerAccessUserSet(listener)) { if (!userSet && isNotificationListenerAccessUserSet(listener, userId)) { // Don't override user's choice return; } Loading @@ -5766,9 +5771,8 @@ public class NotificationManagerService extends SystemService { } } private boolean isNotificationListenerAccessUserSet(ComponentName listener) { return mListeners.isPackageOrComponentUserSet(listener.flattenToString(), getCallingUserHandle().getIdentifier()); private boolean isNotificationListenerAccessUserSet(ComponentName listener, int userId) { return mListeners.isPackageOrComponentUserSet(listener.flattenToString(), userId); } @Override Loading