Bug 1416169 - Part 4 - Switch the MediaControlService to running only on demand. r=snorp

Now that the AudioFocusAgent keeps monitoring all relevant tab events and
notifies the MediaControlService as necessary, we can revert to only running the
service when actually required to show the notification and keep us alive during
(background) media playback.

MozReview-Commit-ID: KV6ars2BbMW

--HG--
extra : rebase_source : 3d3681b960605c4c4e4caff0e96804b6b4770d7c
This commit is contained in:
Jan Henning 2018-03-11 12:50:22 +01:00
parent 8c5b7ccb59
commit 5397936515
2 changed files with 5 additions and 9 deletions

View File

@ -99,7 +99,6 @@ public class AudioFocusAgent implements Tabs.OnTabsChangedListener {
}
}
};
notifyMediaControlService(MediaControlService.ACTION_INIT);
}
@RobocopTarget

View File

@ -35,7 +35,6 @@ import org.mozilla.gecko.util.ThreadUtils;
public class MediaControlService extends Service {
private static final String LOGTAG = "MediaControlService";
public static final String ACTION_INIT = "action_init";
public static final String ACTION_RESUME = "action_resume";
public static final String ACTION_PAUSE = "action_pause";
public static final String ACTION_STOP = "action_stop";
@ -134,14 +133,16 @@ public class MediaControlService extends Service {
if (!mInitialize) {
return;
}
mInitialize = false;
Log.d(LOGTAG, "shutdown");
setState(State.STOPPED);
if (!mMediaState.equals(State.STOPPED)) {
setState(State.STOPPED);
}
PrefsHelper.removeObserver(mPrefsObserver);
mHeadSetStateReceiver.unregisterReceiver(getApplicationContext());
mSession.release();
mInitialize = false;
stopSelf();
}
@ -156,11 +157,6 @@ public class MediaControlService extends Service {
Log.d(LOGTAG, "HandleIntent, action = " + intent.getAction() + ", mediaState = " + mMediaState);
switch (intent.getAction()) {
case ACTION_INIT :
// This action is used to create a service and do the initialization,
// the actual operation would be executed via control interface's
// pending intent.
break;
case ACTION_RESUME :
mController.getTransportControls().play();
break;
@ -342,6 +338,7 @@ public class MediaControlService extends Service {
if (isNeedToRemoveControlInterface(mMediaState)) {
stopForeground(false);
NotificationManagerCompat.from(this).cancel(R.id.mediaControlNotification);
shutdown();
return;
}