diff options
author | Dongwon Kang <dwkang@google.com> | 2015-07-07 22:10:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-07 22:10:23 +0000 |
commit | 7a64e9769f8fe5a400320de9ebd025b0b7af045d (patch) | |
tree | ab75db3131709a20d660b399b8fa9f55f5cf6ef9 /media/java | |
parent | e9cbf41561e4b4ac605b075d3d2531aef32dd32d (diff) | |
parent | d2ed690187c41d1cd260f1d754d7ef9ef5aa383f (diff) | |
download | frameworks_base-7a64e9769f8fe5a400320de9ebd025b0b7af045d.zip frameworks_base-7a64e9769f8fe5a400320de9ebd025b0b7af045d.tar.gz frameworks_base-7a64e9769f8fe5a400320de9ebd025b0b7af045d.tar.bz2 |
Merge "MediaSessionManager: make the binder implementation static" into mnc-dev
Diffstat (limited to 'media/java')
-rw-r--r-- | media/java/android/media/session/MediaSessionManager.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java index 6ac0efb..2364a13 100644 --- a/media/java/android/media/session/MediaSessionManager.java +++ b/media/java/android/media/session/MediaSessionManager.java @@ -202,7 +202,8 @@ public final class MediaSessionManager { Log.w(TAG, "Attempted to add session listener twice, ignoring."); return; } - SessionsChangedWrapper wrapper = new SessionsChangedWrapper(sessionListener, handler); + SessionsChangedWrapper wrapper = new SessionsChangedWrapper(mContext, sessionListener, + handler); try { mService.addSessionsListener(wrapper.mStub, notificationListener, userId); mListeners.put(sessionListener, wrapper); @@ -229,6 +230,8 @@ public final class MediaSessionManager { mService.removeSessionsListener(wrapper.mStub); } catch (RemoteException e) { Log.e(TAG, "Error in removeOnActiveSessionsChangedListener.", e); + } finally { + wrapper.release(); } } } @@ -317,11 +320,14 @@ public final class MediaSessionManager { public void onActiveSessionsChanged(@Nullable List<MediaController> controllers); } - private final class SessionsChangedWrapper { - private final OnActiveSessionsChangedListener mListener; - private final Handler mHandler; + private static final class SessionsChangedWrapper { + private Context mContext; + private OnActiveSessionsChangedListener mListener; + private Handler mHandler; - public SessionsChangedWrapper(OnActiveSessionsChangedListener listener, Handler handler) { + public SessionsChangedWrapper(Context context, OnActiveSessionsChangedListener listener, + Handler handler) { + mContext = context; mListener = listener; mHandler = handler; } @@ -333,17 +339,25 @@ public final class MediaSessionManager { mHandler.post(new Runnable() { @Override public void run() { - ArrayList<MediaController> controllers - = new ArrayList<MediaController>(); - int size = tokens.size(); - for (int i = 0; i < size; i++) { - controllers.add(new MediaController(mContext, tokens.get(i))); + if (mListener != null) { + ArrayList<MediaController> controllers + = new ArrayList<MediaController>(); + int size = tokens.size(); + for (int i = 0; i < size; i++) { + controllers.add(new MediaController(mContext, tokens.get(i))); + } + mListener.onActiveSessionsChanged(controllers); } - mListener.onActiveSessionsChanged(controllers); } }); } } }; + + private void release() { + mContext = null; + mListener = null; + mHandler = null; + } } } |