diff options
author | RoboErik <epastern@google.com> | 2014-08-08 15:56:54 -0700 |
---|---|---|
committer | Erik Pasternak <roboerik@android.com> | 2014-08-11 22:32:55 +0000 |
commit | 7aef77bbf5b983b9f949936ed6cd174251697ca8 (patch) | |
tree | ac9f7959c12b1b4a94c27615c13294025ad30434 /services/core/java/com/android/server/media | |
parent | 3afd00e9f2b55a21ca378d6e520d24283dbb62e0 (diff) | |
download | frameworks_base-7aef77bbf5b983b9f949936ed6cd174251697ca8.zip frameworks_base-7aef77bbf5b983b9f949936ed6cd174251697ca8.tar.gz frameworks_base-7aef77bbf5b983b9f949936ed6cd174251697ca8.tar.bz2 |
Remove sessions listeners that are disabled
Removes sessions listeners when their notification listener is
disabled. Also updates the dump for media sessions.
bug:15549450
Change-Id: Ibe51a4a42ef333e75a09f0fffa0f2b9b8939b85c
Diffstat (limited to 'services/core/java/com/android/server/media')
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionRecord.java | 8 | ||||
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 58 |
2 files changed, 63 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java index d71f66a..e549ead 100644 --- a/services/core/java/com/android/server/media/MediaSessionRecord.java +++ b/services/core/java/com/android/server/media/MediaSessionRecord.java @@ -412,16 +412,22 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { pw.println(prefix + mTag + " " + this); final String indent = prefix + " "; - // We print the hashcode for matching with the list in user records pw.println(indent + "ownerPid=" + mOwnerPid + ", ownerUid=" + mOwnerUid + ", userId=" + mUserId); pw.println(indent + "package=" + mPackageName); + pw.println(indent + "launchIntent=" + mLaunchIntent); + pw.println(indent + "mediaButtonReceiver=" + mMediaButtonReceiver); pw.println(indent + "active=" + mIsActive); pw.println(indent + "flags=" + mFlags); pw.println(indent + "rating type=" + mRatingType); pw.println(indent + "controllers: " + mControllerCallbacks.size()); pw.println(indent + "state=" + (mPlaybackState == null ? null : mPlaybackState.toString())); + pw.println(indent + "audioAttrs=" + mAudioAttrs); + pw.println(indent + "volumeType=" + mVolumeType + ", controlType=" + mVolumeControlType + + ", max=" + mMaxVolume + ", current=" + mCurrentVolume); pw.println(indent + "metadata:" + getShortMetadataString()); + pw.println(indent + "queueTitle=" + mQueueTitle + ", size=" + + (mQueue == null ? 0 : mQueue.getList().size())); } @Override diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 92644ce..277344e 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -29,6 +29,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.database.ContentObserver; import android.media.AudioManager; import android.media.IAudioService; import android.media.IRemoteVolumeController; @@ -37,6 +38,7 @@ import android.media.session.ISession; import android.media.session.ISessionCallback; import android.media.session.ISessionManager; import android.media.session.MediaSession; +import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -86,6 +88,7 @@ public class MediaSessionService extends SystemService implements Monitor { private KeyguardManager mKeyguardManager; private IAudioService mAudioService; private ContentResolver mContentResolver; + private SettingsObserver mSettingsObserver; private MediaSessionRecord mPrioritySession; private int mCurrentUserId = -1; @@ -111,6 +114,8 @@ public class MediaSessionService extends SystemService implements Monitor { (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE); mAudioService = getAudioService(); mContentResolver = getContext().getContentResolver(); + mSettingsObserver = new SettingsObserver(); + mSettingsObserver.observe(); } private IAudioService getAudioService() { @@ -229,6 +234,28 @@ public class MediaSessionService extends SystemService implements Monitor { } } + private void updateActiveSessionListeners() { + synchronized (mLock) { + for (int i = mSessionsListeners.size() - 1; i >= 0; i--) { + SessionsListenerRecord listener = mSessionsListeners.get(i); + try { + enforceMediaPermissions(listener.mComponentName, listener.mPid, listener.mUid, + listener.mUserId); + } catch (SecurityException e) { + Log.i(TAG, "ActiveSessionsListener " + listener.mComponentName + + " is no longer authorized. Disconnecting."); + mSessionsListeners.remove(i); + try { + listener.mListener + .onActiveSessionsChanged(new ArrayList<MediaSession.Token>()); + } catch (Exception e1) { + // ignore + } + } + } + } + } + /** * Stop the user and unbind from everything. * @@ -525,11 +552,19 @@ public class MediaSessionService extends SystemService implements Monitor { final class SessionsListenerRecord implements IBinder.DeathRecipient { private final IActiveSessionsListener mListener; + private final ComponentName mComponentName; private final int mUserId; + private final int mPid; + private final int mUid; - public SessionsListenerRecord(IActiveSessionsListener listener, int userId) { + public SessionsListenerRecord(IActiveSessionsListener listener, + ComponentName componentName, + int userId, int pid, int uid) { mListener = listener; + mComponentName = componentName; mUserId = userId; + mPid = pid; + mUid = uid; } @Override @@ -540,6 +575,25 @@ 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, UserHandle.USER_ALL); + } + + @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"; @@ -607,7 +661,7 @@ public class MediaSessionService extends SystemService implements Monitor { return; } SessionsListenerRecord record = new SessionsListenerRecord(listener, - resolvedUserId); + componentName, resolvedUserId, pid, uid); try { listener.asBinder().linkToDeath(record, 0); } catch (RemoteException e) { |