summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenson Huang <benson.huang@mediatek.com>2015-03-24 23:40:56 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-24 23:40:56 +0000
commit3e8557504374f2f746f3775dac0bcc97975c2430 (patch)
tree66c3c4640a94085a8ab7949c70c74f13a87d6422
parent4b39e4c8aeb9bf827c3ce664b118680b4672b2c6 (diff)
parent4f33aa31c5cc96bfb7abca4ad1c8f6f8c04e46af (diff)
downloadFMRadio-3e8557504374f2f746f3775dac0bcc97975c2430.tar.gz
am 4f33aa31: [FM] Earphone mode incoming call ringtone issue in loudspeaker
* commit '4f33aa31c5cc96bfb7abca4ad1c8f6f8c04e46af': [FM] Earphone mode incoming call ringtone issue in loudspeaker
-rw-r--r--src/com/android/fmradio/FmService.java18
-rw-r--r--src/com/android/fmradio/FmUtils.java24
2 files changed, 42 insertions, 0 deletions
diff --git a/src/com/android/fmradio/FmService.java b/src/com/android/fmradio/FmService.java
index 7f2ef78..35efe56 100644
--- a/src/com/android/fmradio/FmService.java
+++ b/src/com/android/fmradio/FmService.java
@@ -1927,6 +1927,10 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
* @return true, success; false, fail;
*/
public boolean requestAudioFocus() {
+ if (FmUtils.getIsSpeakerModeOnFocusLost(mContext)) {
+ setForceUse(true);
+ FmUtils.setIsSpeakerModeOnFocusLost(mContext, false);
+ }
if (mIsAudioFocusHeld) {
return true;
}
@@ -2034,6 +2038,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
}
}
handlePowerDown();
+ forceToHeadsetMode();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
@@ -2055,9 +2060,14 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
}
}
handlePowerDown();
+ forceToHeadsetMode();
break;
case AudioManager.AUDIOFOCUS_GAIN:
+ if (FmUtils.getIsSpeakerModeOnFocusLost(mContext)) {
+ setForceUse(true);
+ FmUtils.setIsSpeakerModeOnFocusLost(mContext, false);
+ }
if ((mPowerStatus != POWER_UP) && mPausedByTransientLossOfFocus) {
final int bundleSize = 1;
mFmServiceHandler.removeMessages(FmListener.MSGID_POWERUP_FINISHED);
@@ -2078,6 +2088,14 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
}
}
+ private void forceToHeadsetMode() {
+ if (mIsSpeakerUsed && isHeadSetIn()) {
+ AudioSystem.setForceUse(FOR_PROPRIETARY, AudioSystem.FORCE_NONE);
+ // save user's option to shared preferences.
+ FmUtils.setIsSpeakerModeOnFocusLost(mContext, true);
+ }
+ }
+
/**
* FM Radio listener record
*/
diff --git a/src/com/android/fmradio/FmUtils.java b/src/com/android/fmradio/FmUtils.java
index 608ced7..b6219fd 100644
--- a/src/com/android/fmradio/FmUtils.java
+++ b/src/com/android/fmradio/FmUtils.java
@@ -61,6 +61,7 @@ public class FmUtils {
private static final String FM_LOCATION_LATITUDE = "fm_location_latitude";
private static final String FM_LOCATION_LONGITUDE = "fm_location_longitude";
private static final String FM_IS_FIRST_TIME_PLAY = "fm_is_first_time_play";
+ private static final String FM_IS_SPEAKER_MODE = "fm_is_speaker_mode";
private static final String FM_IS_FIRST_ENTER_STATION_LIST = "fm_is_first_enter_station_list";
// StorageManager For FM record
private static StorageManager sStorageManager = null;
@@ -298,4 +299,27 @@ public class FmUtils {
iconLayout.destroyDrawingCache();
return largeIcon;
}
+
+ /**
+ * Get whether speaker mode is in use when audio focus lost.
+ * @param context the Context
+ * @return true for speaker mode, false for non speaker mode
+ */
+ public static boolean getIsSpeakerModeOnFocusLost(Context context) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ return prefs.getBoolean(FM_IS_SPEAKER_MODE, false);
+ }
+
+ /**
+ * Set whether speaker mode is in use.
+ * @param context the Context
+ * @param isSpeaker speaker state
+ */
+ public static void setIsSpeakerModeOnFocusLost(Context context, boolean isSpeaker) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(FM_IS_SPEAKER_MODE, isSpeaker);
+ editor.commit();
+ }
}