summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2014-12-04 21:12:46 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2014-12-04 21:12:46 -0800
commit0f33e257b1dba6ef97b8f6d647f6d95254dd05ab (patch)
tree894867f2b45218e98e55aa08c62de4920c170858
parent6cd308edabb50f49026accf7e2a656df89587fd6 (diff)
parent3b55b8546e06e691cb655a0d5983f09401452ead (diff)
downloadandroid_hardware_qcom_fm-0f33e257b1dba6ef97b8f6d647f6d95254dd05ab.tar.gz
android_hardware_qcom_fm-0f33e257b1dba6ef97b8f6d647f6d95254dd05ab.tar.bz2
android_hardware_qcom_fm-0f33e257b1dba6ef97b8f6d647f6d95254dd05ab.zip
Merge "FM: Handle MEDIA Key Events"
-rw-r--r--fmapp2/src/com/caf/fmradio/FMRadioService.java117
1 files changed, 86 insertions, 31 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 9154c26..9727050 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -83,6 +83,7 @@ import android.os.SystemClock;
import android.os.Process;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
+import android.media.session.MediaSession;
/**
* Provides "background" FM Radio (that uses the hardware) capabilities,
@@ -179,6 +180,7 @@ public class FMRadioService extends Service
private Thread mRecordServiceCheckThread = null;
private boolean mUnMuteOnFocusLoss = false;
private boolean mSpeakerOnFocusLoss = false;
+ private MediaSession mSession;
public FMRadioService() {
}
@@ -207,6 +209,11 @@ public class FMRadioService extends Service
// 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 |
+ MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
+ mSession.setActive(true);
registerAudioBecomeNoisy();
if ( false == SystemProperties.getBoolean("ro.fm.mulinst.recording.support",true)) {
mSingleRecordingInstanceSupported = true;
@@ -431,37 +438,9 @@ public class FMRadioService extends Service
int keycode = event.getKeyCode();
switch (keycode) {
case KeyEvent.KEYCODE_HEADSETHOOK :
- 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();
- }
- } else if( 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();
- }
+ toggleFM();
+ if (isOrderedBroadcast()) {
+ abortBroadcast();
}
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE :
@@ -782,6 +761,78 @@ public class FMRadioService extends Service
getApplicationContext().sendBroadcast(intent);
}
+ private void toggleFM() {
+ Log.d(LOGTAG, "Toggle FM");
+ if (isFmOn()){
+ fmOff();
+ try {
+ if ((mServiceInUse) && (mCallbacks != null) ) {
+ mCallbacks.onDisabled();
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ } else if( mServiceInUse ) {
+ fmOn();
+ try {
+ if (mCallbacks != null ) {
+ mCallbacks.onEnabled();
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private final MediaSession.Callback mSessionCallback = new MediaSession.Callback() {
+ @Override
+ public boolean onMediaButtonEvent(Intent intent) {
+ KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+ Log.d(LOGTAG, "SessionCallback.onMediaButton()... event = " +event);
+ int key_action = event.getAction();
+ if ((event != null) && ((event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK)
+ || (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))
+ && (key_action == KeyEvent.ACTION_DOWN)) {
+ Log.d(LOGTAG, "SessionCallback: HEADSETHOOK/MEDIA_PLAY_PAUSE");
+ toggleFM();
+ return true;
+ } else if((event != null) && (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE)
+ && (key_action == KeyEvent.ACTION_DOWN)) {
+ Log.d(LOGTAG, "SessionCallback: MEDIA_PAUSE");
+ if (mServiceInUse ) {
+ fmOn();
+ try {
+ if (mCallbacks != null ) {
+ mCallbacks.onEnabled();
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+ } else if ((event != null) && (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY)
+ && (key_action == KeyEvent.ACTION_DOWN)) {
+ Log.d(LOGTAG, "SessionCallback: MEDIA_PLAY");
+ if (isFmOn()){
+ //FM should be off when Headset hook pressed.
+ fmOff();
+ 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();
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
private void startFM(){
Log.d(LOGTAG, "In startFM");
if(true == mAppShutdown) { // not to send intent to AudioManager in Shutdown
@@ -1328,6 +1379,10 @@ public class FMRadioService extends Service
ComponentName fmRadio = new ComponentName(this.getPackageName(),
FMMediaButtonIntentReceiver.class.getName());
mAudioManager.unregisterMediaButtonEventReceiver(fmRadio);
+ if (mSession.isActive()) {
+ Log.d(LOGTAG,"mSession is not active");
+ mSession.setActive(false);
+ }
}
gotoIdleState();
mFMOn = false;