Merge "FM: Query and apply STREAM_MUSIC volume when output device routing changes."
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 2273f3c..5f591fe 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -391,7 +391,7 @@
" DeviceLoopbackActive = " + mIsFMDeviceLoopbackActive +
" mStoppedOnFocusLoss = "+mStoppedOnFocusLoss);
int mAudioDeviceType;
-
+
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if(enable) {
if(mIsFMDeviceLoopbackActive || mStoppedOnFocusLoss) {
@@ -436,6 +436,16 @@
return true;
}
+ private void setCurrentFMVolume() {
+ if(isFmOn()) {
+ AudioManager maudioManager =
+ (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ int mCurrentVolumeIndex =
+ maudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+ setFMVolume(mCurrentVolumeIndex);
+ }
+ }
+
/**
* Registers an intent to listen for ACTION_MEDIA_UNMOUNTED notifications.
* The intent will call closeExternalStorageFiles() if the external media
@@ -609,8 +619,19 @@
intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
setFMVolume(mCurrentVolumeIndex);
}
- }
+ } else if (action.equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
+ mHandler.removeCallbacks(mFmVolumeHandler);
+ mHandler.post(mFmVolumeHandler);
+ } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
+ int state =
+ intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
+ Log.d(LOGTAG, "ACTION_STATE_CHANGED state :"+ state);
+ if (state == BluetoothAdapter.STATE_OFF) {
+ mHandler.removeCallbacks(mFmVolumeHandler);
+ mHandler.post(mFmVolumeHandler);
+ }
+ }
}
};
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -620,6 +641,8 @@
iFilter.addAction("HDMI_CONNECTED");
iFilter.addAction(Intent.ACTION_SHUTDOWN);
iFilter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
+ iFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+ iFilter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
iFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(mHeadsetReceiver, iFilter);
}
@@ -723,7 +746,17 @@
}
}
-
+ final Runnable mFmVolumeHandler = new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (Exception ex) {
+ Log.d( LOGTAG, "RunningThread InterruptedException");
+ return;
+ }
+ setCurrentFMVolume();
+ }
+ };
final Runnable mHeadsetPluginHandler = new Runnable() {
public void run() {