Bug 1311245 - part2 : make sure the mActionState would be modified everytime the UI interface changed. r=sebastian
authorAlastor Wu <alwu@mozilla.com>
Thu, 27 Oct 2016 10:12:23 +0800
changeset 319673 b2066343565f4442de99a02e5950ba338a47835e
parent 319672 4f36768e04076aaa6f41cba2758589b6f4f5e99c
child 319674 e86ad7e506451c029bef8363bc60c52a6881d52c
push id33581
push useralwu@mozilla.com
push dateThu, 27 Oct 2016 08:45:55 +0000
treeherderautoland@f06568be1513 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1311245
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1311245 - part2 : make sure the mActionState would be modified everytime the UI interface changed. r=sebastian Make sure the value of |mActionState| is correct after we modified the media control's interface. MozReview-Commit-ID: 6Nhu1gqCFrD
mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -243,17 +243,16 @@ public class MediaControlService extends
                                           mSession.getSessionToken());
 
         mSession.setCallback(new MediaSession.Callback() {
             @Override
             public void onCustomAction(String action, Bundle extras) {
                 if (action.equals(ACTION_START)) {
                     Log.d(LOGTAG, "Controller, onStart");
                     notifyControlInterfaceChanged(ACTION_PAUSE);
-                    mActionState = ACTION_RESUME;
                 } else if (action.equals(ACTION_PAUSE_BY_AUDIO_FOCUS)) {
                     Log.d(LOGTAG, "Controller, pause by audio focus changed");
                     notifyControlInterfaceChanged(ACTION_RESUME);
                     mActionState = ACTION_PAUSE_BY_AUDIO_FOCUS;
                 } else if (action.equals(ACTION_RESUME_BY_AUDIO_FOCUS)) {
                     Log.d(LOGTAG, "Controller, resume by audio focus changed");
                     notifyControlInterfaceChanged(ACTION_PAUSE);
                     mActionState = ACTION_RESUME_BY_AUDIO_FOCUS;
@@ -261,61 +260,59 @@ public class MediaControlService extends
             }
 
             @Override
             public void onPlay() {
                 Log.d(LOGTAG, "Controller, onPlay");
                 super.onPlay();
                 notifyControlInterfaceChanged(ACTION_PAUSE);
                 notifyObservers("MediaControl", "resumeMedia");
-                mActionState = ACTION_RESUME;
                 // To make sure we always own audio focus during playing.
                 AudioFocusAgent.notifyStartedPlaying();
             }
 
             @Override
             public void onPause() {
                 Log.d(LOGTAG, "Controller, onPause");
                 super.onPause();
                 notifyControlInterfaceChanged(ACTION_RESUME);
                 notifyObservers("MediaControl", "mediaControlPaused");
-                mActionState = ACTION_PAUSE;
                 AudioFocusAgent.notifyStoppedPlaying();
             }
 
             @Override
             public void onStop() {
                 Log.d(LOGTAG, "Controller, onStop");
                 super.onStop();
                 notifyControlInterfaceChanged(ACTION_STOP);
                 notifyObservers("MediaControl", "mediaControlStopped");
-                mActionState = ACTION_STOP;
                 mTabReference = new WeakReference<>(null);
             }
         });
     }
 
     private void notifyObservers(String topic, String data) {
         GeckoAppShell.notifyObservers(topic, data);
     }
 
     private boolean isNeedToRemoveControlInterface(String action) {
         return action.equals(ACTION_STOP);
     }
 
-    private void notifyControlInterfaceChanged(final String action) {
+    private void notifyControlInterfaceChanged(final String uiAction) {
         if (!mInitialize) {
             return;
         }
 
-        Log.d(LOGTAG, "notifyControlInterfaceChanged, action = " + action);
+        Log.d(LOGTAG, "notifyControlInterfaceChanged, action = " + uiAction);
 
-        if (isNeedToRemoveControlInterface(action)) {
+        if (isNeedToRemoveControlInterface(uiAction)) {
             stopForeground(false);
             NotificationManagerCompat.from(this).cancel(MEDIA_CONTROL_ID);
+            setActionState(uiAction);
             return;
         }
 
         if (!mIsMediaControlPrefOn) {
             return;
         }
 
         // TODO : remove this checking when the media control is ready to ship,
@@ -325,24 +322,40 @@ public class MediaControlService extends
         }
 
         final Tab tab = mTabReference.get();
 
         if (tab == null) {
             return;
         }
 
+        setActionState(uiAction);
+
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                updateNotification(tab, action);
+                updateNotification(tab, uiAction);
             }
         });
     }
 
+    private void setActionState(final String uiAction) {
+        switch (uiAction) {
+            case ACTION_PAUSE:
+                mActionState = ACTION_RESUME;
+                break;
+            case ACTION_RESUME:
+                mActionState = ACTION_PAUSE;
+                break;
+            case ACTION_STOP:
+                mActionState = ACTION_STOP;
+                break;
+        }
+    }
+
     private void updateNotification(Tab tab, String action) {
         ThreadUtils.assertNotOnUiThread();
 
         final Notification.MediaStyle style = new Notification.MediaStyle();
         style.setShowActionsInCompactView(0);
 
         final boolean isPlaying = isMediaPlaying();
         final int visibility = tab.isPrivate() ?