summaryrefslogtreecommitdiffstats
path: root/fmapp2/src
diff options
context:
space:
mode:
authorRupesh Tatiya <rtatiya@codeaurora.org>2015-11-04 17:51:44 +0530
committerArne Coucheron <arco68@gmail.com>2016-03-22 00:14:13 +0100
commitd7dd0544ff3b6470a74bbc2b5f751f6d8d76ecf8 (patch)
tree821762fc02942839c361a3655ea7dcaf460b0bff /fmapp2/src
parenta8ad0bd883b602a22b802c19b47c9cf51e42830d (diff)
downloadandroid_hardware_qcom_fm-d7dd0544ff3b6470a74bbc2b5f751f6d8d76ecf8.tar.gz
android_hardware_qcom_fm-d7dd0544ff3b6470a74bbc2b5f751f6d8d76ecf8.tar.bz2
android_hardware_qcom_fm-d7dd0544ff3b6470a74bbc2b5f751f6d8d76ecf8.zip
Change FM off button to release media and audio resources.
When FM application is launched, no other Media consuming application can receive key events (play, pause etc.) because FM service is the owner of MediaSession and AudioFocus. This does not bode well for user experience. Change the behaviour of FM off button so that we release MediaSession and AudioFocus so that other applications can work. The same behaviour is enabled when antenna is pulled out. We differentiate FM off from remote bluetooth headset start/stop i.e. when remote headset does start/stop, it starts/stops FM. This means that if user presses FM off button, user has to explicitly turn it on again. Also remove old FM Media Button Intent receiver as it is deprecated. CRs-Fixed: 936190 Change-Id: I32fef8e43b226a260d5483b40f5825926c023e62
Diffstat (limited to 'fmapp2/src')
-rw-r--r--fmapp2/src/com/caf/fmradio/FMRadio.java2
-rw-r--r--fmapp2/src/com/caf/fmradio/FMRadioService.java92
2 files changed, 23 insertions, 71 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index 54cee9e..7814418 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -2661,7 +2661,7 @@ public class FMRadio extends Activity
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
- Log.d(LOGTAG, "KEY event received" + keyCode);
+ Log.d(LOGTAG, "KEY event received " + keyCode);
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case 126: //KeyEvent.KEYCODE_MEDIA_PLAY:
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 65b7086..0510a6b 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -220,6 +220,9 @@ public class FMRadioService extends Service
private Notification mNotificationInstance;
private NotificationManager mNotificationManager;
+ private static final int FM_OFF_FROM_APPLICATION = 1;
+ private static final int FM_OFF_FROM_ANTENNA = 2;
+
public FMRadioService() {
}
@@ -245,9 +248,7 @@ public class FMRadioService extends Service
registerDelayedServiceStop();
registerExternalStorageListener();
registerAirplaneModeStatusChanged();
- // registering media button receiver seperately as we need to set
- // different priority for receiving media events
- registerFmMediaButtonReceiver();
+
mSession = new MediaSession(getApplicationContext(), this.getClass().getName());
mSession.setCallback(mSessionCallback);
mSession.setFlags(MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY |
@@ -672,71 +673,6 @@ public class FMRadioService extends Service
}
}
- public void registerFmMediaButtonReceiver() {
- if (mFmMediaButtonListener == null) {
- mFmMediaButtonListener = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- Log.d(LOGTAG, "FMMediaButtonIntentReceiver.FM_MEDIA_BUTTON");
- Log.d(LOGTAG, "KeyEvent = " +intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT));
- String action = intent.getAction();
- if (action.equals(FMMediaButtonIntentReceiver.FM_MEDIA_BUTTON)) {
- KeyEvent event = (KeyEvent)
- intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
- int keycode = event.getKeyCode();
- switch (keycode) {
- case KeyEvent.KEYCODE_HEADSETHOOK :
- toggleFM();
- if (isOrderedBroadcast()) {
- abortBroadcast();
- }
- break;
- case KeyEvent.KEYCODE_MEDIA_PAUSE :
- if (isFmOn()){
- //FM should be off when Headset hook pressed.
- fmOff();
- if (isOrderedBroadcast()) {
- abortBroadcast();
- }
- try {
- /* Notify the UI/Activity, only if the service is "bound"
- by an activity and if Callbacks are registered
- */
- if ((mServiceInUse) && (mCallbacks != null) ) {
- mCallbacks.onDisabled();
- }
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- break;
- case KeyEvent.KEYCODE_MEDIA_PLAY:
- if (isAntennaAvailable() && mServiceInUse) {
- fmOn();
- if (isOrderedBroadcast()) {
- abortBroadcast();
- }
- try {
- /* Notify the UI/Activity, only if the service is "bound"
- by an activity and if Callbacks are registered
- */
- if (mCallbacks != null ) {
- mCallbacks.onEnabled();
- }
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- break;
- } // end of switch
- } // end of FMMediaButtonIntentReceiver.FM_MEDIA_BUTTON
- } // end of onReceive
- };
- IntentFilter iFilter = new IntentFilter();
- iFilter.addAction(FMMediaButtonIntentReceiver.FM_MEDIA_BUTTON);
- registerReceiver(mFmMediaButtonListener, iFilter);
- }
- }
-
public void registerAudioBecomeNoisy() {
if (mAudioBecomeNoisyListener == null) {
mAudioBecomeNoisyListener = new BroadcastReceiver() {
@@ -749,7 +685,7 @@ public class FMRadioService extends Service
if (isFmOn())
{
/* Disable FM and let the UI know */
- fmOff();
+ fmOff(FM_OFF_FROM_ANTENNA);
try
{
/* Notify the UI/Activity, only if the service is "bound"
@@ -1099,12 +1035,14 @@ public class FMRadioService extends Service
Log.d(LOGTAG, "audio focuss couldnot be granted");
return;
}
+ mSession.setActive(true);
Log.d(LOGTAG,"FM registering for registerMediaButtonEventReceiver");
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
ComponentName fmRadio = new ComponentName(this.getPackageName(),
FMMediaButtonIntentReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(fmRadio);
+
mStoppedOnFocusLoss = false;
if (!mA2dpDeviceState.isDeviceAvailable()) {
@@ -1721,6 +1659,7 @@ public class FMRadioService extends Service
private void stop() {
Log.d(LOGTAG,"in stop");
+
if (!mServiceInUse) {
Log.d(LOGTAG,"calling unregisterMediaButtonEventReceiver in stop");
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -1777,7 +1716,7 @@ public class FMRadioService extends Service
public boolean fmOff() throws RemoteException
{
- return(mService.get().fmOff());
+ return(mService.get().fmOff(FM_OFF_FROM_APPLICATION));
}
public boolean fmRadioReset() throws RemoteException
@@ -2299,6 +2238,19 @@ public class FMRadioService extends Service
return(bStatus);
}
+
+ private boolean fmOff(int off_from) {
+ if (off_from == FM_OFF_FROM_APPLICATION || off_from == FM_OFF_FROM_ANTENNA) {
+ Log.d(LOGTAG, "FM application close button pressed or antenna removed");
+ mSession.setActive(false);
+ AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ if (audioManager != null)
+ audioManager.abandonAudioFocus(mAudioFocusListener);
+ else
+ Log.d(LOGTAG, "Failed to get Audio Service");
+ }
+ return fmOff();
+ }
/*
* Turn OFF FM: Disable the FM Host when hardware resets asynchronously .
* .