diff options
| -rw-r--r-- | api/module-lib-current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/app/NotificationManager.java | 10 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 1 | ||||
| -rw-r--r-- | non-updatable-api/module-lib-current.txt | 1 | ||||
| -rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 39 | ||||
| -rwxr-xr-x | services/core/java/com/android/server/notification/NotificationManagerService.java | 12 |
6 files changed, 39 insertions, 25 deletions
diff --git a/api/module-lib-current.txt b/api/module-lib-current.txt index b587ea1f3b74..7cd8a628c9fc 100644 --- a/api/module-lib-current.txt +++ b/api/module-lib-current.txt @@ -7,6 +7,7 @@ package android.app { public class NotificationManager { method public boolean hasEnabledNotificationListener(@NonNull String, @NonNull android.os.UserHandle); + field public static final String ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED = "android.app.action.NOTIFICATION_LISTENER_ENABLED_CHANGED"; } } diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 8ee995d6e6be..0627bc855934 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -282,6 +282,16 @@ public class NotificationManager { = "android.app.action.INTERRUPTION_FILTER_CHANGED"; /** + * Intent that is broadcast when the state of + * {@link #hasEnabledNotificationListener(String, UserHandle)} changes. + * @hide + */ + @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + public static final String ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED = + "android.app.action.NOTIFICATION_LISTENER_ENABLED_CHANGED"; + + /** * Intent that is broadcast when the state of getCurrentInterruptionFilter() changes. * @hide */ diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index edb972730f69..32c1e4a1411c 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -558,6 +558,7 @@ <protected-broadcast android:name="android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED" /> <protected-broadcast android:name="android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED" /> <protected-broadcast android:name="android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED" /> + <protected-broadcast android:name="android.app.action.NOTIFICATION_LISTENER_ENABLED_CHANGED" /> <protected-broadcast android:name="android.app.action.APP_BLOCK_STATE_CHANGED" /> <protected-broadcast android:name="android.permission.GET_APP_GRANTED_URI_PERMISSIONS" /> diff --git a/non-updatable-api/module-lib-current.txt b/non-updatable-api/module-lib-current.txt index 35b483b9fb84..617a83f05791 100644 --- a/non-updatable-api/module-lib-current.txt +++ b/non-updatable-api/module-lib-current.txt @@ -7,6 +7,7 @@ package android.app { public class NotificationManager { method public boolean hasEnabledNotificationListener(@NonNull String, @NonNull android.os.UserHandle); + field public static final String ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED = "android.app.action.NOTIFICATION_LISTENER_ENABLED_CHANGED"; } } diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index eb4ab1ceac28..a8a0e2e937d0 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -32,14 +32,15 @@ import android.app.KeyguardManager; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ActivityNotFoundException; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; import android.content.pm.UserInfo; -import android.database.ContentObserver; import android.media.AudioManager; import android.media.AudioManagerInternal; import android.media.AudioPlaybackConfiguration; @@ -58,7 +59,6 @@ import android.media.session.ISessionManager; import android.media.session.MediaController; import android.media.session.MediaSession; import android.media.session.MediaSessionManager; -import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -138,7 +138,6 @@ public class MediaSessionService extends SystemService implements Monitor { private KeyguardManager mKeyguardManager; private AudioManagerInternal mAudioManagerInternal; private ContentResolver mContentResolver; - private SettingsObserver mSettingsObserver; private boolean mHasFeatureLeanback; // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile) @@ -192,8 +191,6 @@ public class MediaSessionService extends SystemService implements Monitor { } }, null /* handler */); mContentResolver = mContext.getContentResolver(); - mSettingsObserver = new SettingsObserver(); - mSettingsObserver.observe(); mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_LEANBACK); @@ -202,8 +199,20 @@ public class MediaSessionService extends SystemService implements Monitor { instantiateCustomProvider(null); instantiateCustomDispatcher(null); mRecordThread.start(); + + final IntentFilter filter = new IntentFilter( + NotificationManager.ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED); + mContext.registerReceiver(mNotificationListenerEnabledChangedReceiver, filter); } + private final BroadcastReceiver mNotificationListenerEnabledChangedReceiver = + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + updateActiveSessionListeners(); + } + }; + private boolean isGlobalPriorityActiveLocked() { return mGlobalPrioritySession != null && mGlobalPrioritySession.isActive(); } @@ -1082,25 +1091,6 @@ public class MediaSessionService extends SystemService implements Monitor { } } - final class SettingsObserver extends ContentObserver { - private final Uri mSecureSettingsUri = Settings.Secure.getUriFor( - Settings.Secure.ENABLED_NOTIFICATION_LISTENERS); - - private SettingsObserver() { - super(null); - } - - private void observe() { - mContentResolver.registerContentObserver(mSecureSettingsUri, - false, this, ALL.getIdentifier()); - } - - @Override - public void onChange(boolean selfChange, Uri uri) { - updateActiveSessionListeners(); - } - } - class SessionManagerImpl extends ISessionManager.Stub { private static final String EXTRA_WAKELOCK_ACQUIRED = "android.media.AudioService.WAKELOCK_ACQUIRED"; @@ -2710,5 +2700,4 @@ public class MediaSessionService extends SystemService implements Monitor { obtainMessage(msg, userIdInteger).sendToTarget(); } } - } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 52928dc45131..9f9235dc852f 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -31,6 +31,7 @@ import static android.app.NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED import static android.app.NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL; import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED; import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED; +import static android.app.NotificationManager.ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED; import static android.app.NotificationManager.ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.EXTRA_AUTOMATIC_ZEN_RULE_ID; @@ -9180,6 +9181,17 @@ public class NotificationManagerService extends SystemService { } @Override + protected void setPackageOrComponentEnabled(String pkgOrComponent, int userId, + boolean isPrimary, boolean enabled) { + super.setPackageOrComponentEnabled(pkgOrComponent, userId, isPrimary, enabled); + + getContext().sendBroadcastAsUser( + new Intent(ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED) + .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), + UserHandle.ALL, null); + } + + @Override protected void loadDefaultsFromConfig() { String defaultListenerAccess = mContext.getResources().getString( R.string.config_defaultListenerAccessPackages); |