Bug 1290467 - part5 : change service's life time. r=sebastian

Now the life time of the MediaControlService would be as same as the Fennec app.
To make code flow more easily, requesting/abandoning the audio focus wouldn't
affect the media control.

We would mainly communicate with the media control via TabEvents.

MozReview-Commit-ID: KT59bII0HuN

--HG--
extra : rebase_source : d8f2c810f24ef6ea72a274db2b432ca8f8876d8e
This commit is contained in:
Alastor Wu 2016-09-09 09:50:30 +08:00
Родитель 5c5e340476
Коммит 97207d40a6
2 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -78,6 +78,7 @@ public class AudioFocusAgent {
}
}
};
notifyMediaControlService(MediaControlService.ACTION_INIT);
}
@RobocopTarget
@ -113,7 +114,6 @@ public class AudioFocusAgent {
Log.d(LOGTAG, focusMsg);
if (result == AudioManager.AUDIOFOCUS_GAIN) {
mAudioFocusState = OWN_FOCUS;
notifyMediaControlService(MediaControlService.ACTION_START);
}
}
@ -125,7 +125,6 @@ public class AudioFocusAgent {
Log.d(LOGTAG, "Abandon AudioFocus");
mAudioManager.abandonAudioFocus(mAfChangeListener);
mAudioFocusState = LOST_FOCUS;
notifyMediaControlService(MediaControlService.ACTION_STOP);
}
private void notifyMediaControlService(String action) {

Просмотреть файл

@ -32,6 +32,7 @@ import java.lang.ref.WeakReference;
public class MediaControlService extends Service implements Tabs.OnTabsChangedListener {
private static final String LOGTAG = "MediaControlService";
public static final String ACTION_INIT = "action_init";
public static final String ACTION_START = "action_start";
public static final String ACTION_PLAY = "action_play";
public static final String ACTION_PAUSE = "action_pause";
@ -155,6 +156,10 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
Log.d(LOGTAG, "HandleIntent, action = " + intent.getAction() + ", actionState = " + mActionState);
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 tab events.
break;
case ACTION_START :
mController.getTransportControls().sendCustomAction(ACTION_START, null);
break;
@ -248,7 +253,6 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
notifyObservers("MediaControl", "mediaControlStopped");
mActionState = ACTION_STOP;
mTabReference = new WeakReference<>(null);
stopSelf();
}
});
}
@ -270,6 +274,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
Log.d(LOGTAG, "notifyControlInterfaceChanged, action = " + action);
if (isNeedToRemoveControlInterface(action)) {
stopForeground(false);
NotificationManagerCompat.from(this).cancel(MEDIA_CONTROL_ID);
return;
}