diff options
| author | 2017-03-22 17:41:02 +0900 | |
|---|---|---|
| committer | 2017-03-23 13:50:38 +0900 | |
| commit | 01d3c73576a74c48d3029484a0a361080c17244c (patch) | |
| tree | 85c712096f46c51d1dbb5b0a4578d1c0a34078b8 | |
| parent | 6099e75df2c12f5b4b9e73cf3f8acdbaea4b3146 (diff) | |
MediaBrowser: Add a disconnecting state
By adding a CONNECT_STATE_DISCONNECTING, we could prevent
the ConnectionCallback to be called after disconnect().
Bug: 36106103
Test: manual using Support4Demos
Change-Id: Ia6f9864dce90b1e58437c07bbcaf6300e162ab92
| -rw-r--r-- | media/java/android/media/browse/MediaBrowser.java | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/media/java/android/media/browse/MediaBrowser.java b/media/java/android/media/browse/MediaBrowser.java index 7122eaf3563b..5bf205e12799 100644 --- a/media/java/android/media/browse/MediaBrowser.java +++ b/media/java/android/media/browse/MediaBrowser.java @@ -87,10 +87,11 @@ public final class MediaBrowser { */ public static final String EXTRA_PAGE_SIZE = "android.media.browse.extra.PAGE_SIZE"; - private static final int CONNECT_STATE_DISCONNECTED = 0; - private static final int CONNECT_STATE_CONNECTING = 1; - private static final int CONNECT_STATE_CONNECTED = 2; - private static final int CONNECT_STATE_SUSPENDED = 3; + private static final int CONNECT_STATE_DISCONNECTING = 0; + private static final int CONNECT_STATE_DISCONNECTED = 1; + private static final int CONNECT_STATE_CONNECTING = 2; + private static final int CONNECT_STATE_CONNECTED = 3; + private static final int CONNECT_STATE_SUSPENDED = 4; private final Context mContext; private final ComponentName mServiceComponent; @@ -213,6 +214,7 @@ public final class MediaBrowser { // It's ok to call this any state, because allowing this lets apps not have // to check isConnected() unnecessarily. They won't appreciate the extra // assertions for this. We do everything we can here to go back to a sane state. + mState = CONNECT_STATE_DISCONNECTING; mHandler.post(new Runnable() { @Override public void run() { @@ -535,7 +537,7 @@ public final class MediaBrowser { // If we are connected, tell the service that we are watching. If we aren't connected, // the service will be told when we connect. - if (mState == CONNECT_STATE_CONNECTED) { + if (isConnected()) { try { if (options == null) { mServiceBinder.addSubscriptionDeprecated(parentId, mServiceCallbacks); @@ -563,7 +565,7 @@ public final class MediaBrowser { // Tell the service if necessary. try { if (callback == null) { - if (mState == CONNECT_STATE_CONNECTED) { + if (isConnected()) { mServiceBinder.removeSubscriptionDeprecated(parentId, mServiceCallbacks); mServiceBinder.removeSubscription(parentId, null, mServiceCallbacks); } @@ -572,7 +574,7 @@ public final class MediaBrowser { final List<Bundle> optionsList = sub.getOptionsList(); for (int i = callbacks.size() - 1; i >= 0; --i) { if (callbacks.get(i) == callback) { - if (mState == CONNECT_STATE_CONNECTED) { + if (isConnected()) { mServiceBinder.removeSubscription( parentId, callback.mToken, mServiceCallbacks); } @@ -597,6 +599,8 @@ public final class MediaBrowser { */ private static String getStateLabel(int state) { switch (state) { + case CONNECT_STATE_DISCONNECTING: + return "CONNECT_STATE_DISCONNECTING"; case CONNECT_STATE_DISCONNECTED: return "CONNECT_STATE_DISCONNECTED"; case CONNECT_STATE_CONNECTING: |