Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientService.java +7 −10 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ public class HeadsetClientService extends ProfileService { private NativeInterface mNativeInterface = null; private HandlerThread mSmThread = null; private HeadsetClientStateMachineFactory mSmFactory = null; private AudioManager mAudioManager = null; // Maxinum number of devices we can try connecting to in one session private static final int MAX_STATE_MACHINES_POSSIBLE = 100; Loading @@ -86,6 +87,7 @@ public class HeadsetClientService extends ProfileService { } // Setup the JNI service NativeInterface.initializeNative(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mSmFactory = new HeadsetClientStateMachineFactory(); mStateMachineMap.clear(); Loading Loading @@ -156,8 +158,7 @@ public class HeadsetClientService extends ProfileService { String action = intent.getAction(); // We handle the volume changes for Voice calls here since HFP audio volume control does // not go through audio manager (audio mixer). We check if the voice call volume has // changed and subsequently change the SCO volume see // not go through audio manager (audio mixer). see // ({@link HeadsetClientStateMachine#SET_SPEAKER_VOLUME} in // {@link HeadsetClientStateMachine} for details. if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { Loading @@ -167,14 +168,10 @@ public class HeadsetClientService extends ProfileService { if (streamType == AudioManager.STREAM_VOICE_CALL) { int streamValue = intent .getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1); int streamPrevValue = intent.getIntExtra( AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, -1); if (streamValue != -1 && streamValue != streamPrevValue) { // TODO: Fix this // sm.sendMessage(sm.obtainMessage( // HeadsetClientStateMachine.SET_SPEAKER_VOLUME, streamValue, 0)); } int hfVol = HeadsetClientStateMachine.amToHfVol(streamValue); Log.d(TAG, "Setting volume to audio manager: " + streamValue + " hands free: " + hfVol); mAudioManager.setParameters("hfp_volume=" + hfVol); } } } Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +7 −30 Original line number Diff line number Diff line Loading @@ -132,14 +132,11 @@ public class HeadsetClientStateMachine extends StateMachine { private int mIndicatorNetworkSignal; private int mIndicatorBatteryLevel; private boolean mVgsFromStack = false; private boolean mVgmFromStack = false; private String mOperatorName; private String mSubscriberInfo; private int mMaxAmVcVol; private int mMinAmVcVol; private static int mMaxAmVcVol; private static int mMinAmVcVol; // queue of send actions (pair action, action_data) private Queue<Pair<Integer, Object>> mQueuedActions; Loading Loading @@ -174,8 +171,6 @@ public class HeadsetClientStateMachine extends StateMachine { ProfileService.println(sb, "mIndicatorNetworkType: " + mIndicatorNetworkType); ProfileService.println(sb, "mIndicatorNetworkSignal: " + mIndicatorNetworkSignal); ProfileService.println(sb, "mIndicatorBatteryLevel: " + mIndicatorBatteryLevel); ProfileService.println(sb, "mVgsFromStack: " + mVgsFromStack); ProfileService.println(sb, "mVgmFromStack: " + mVgmFromStack); ProfileService.println(sb, "mOperatorName: " + mOperatorName); ProfileService.println(sb, "mSubscriberInfo: " + mSubscriberInfo); Loading Loading @@ -730,7 +725,7 @@ public class HeadsetClientStateMachine extends StateMachine { public static void cleanup() { } private int hfToAmVol(int hfVol) { static int hfToAmVol(int hfVol) { int amRange = mMaxAmVcVol - mMinAmVcVol; int hfRange = MAX_HFP_SCO_VOICE_CALL_VOLUME - MIN_HFP_SCO_VOICE_CALL_VOLUME; int amOffset = Loading @@ -740,7 +735,7 @@ public class HeadsetClientStateMachine extends StateMachine { return amVol; } private int amToHfVol(int amVol) { static int amToHfVol(int amVol) { int amRange = mMaxAmVcVol - mMinAmVcVol; int hfRange = MAX_HFP_SCO_VOICE_CALL_VOLUME - MIN_HFP_SCO_VOICE_CALL_VOLUME; int hfOffset = (hfRange * (amVol - mMinAmVcVol)) / amRange; Loading Loading @@ -1109,16 +1104,6 @@ public class HeadsetClientStateMachine extends StateMachine { // Called only for Mute/Un-mute - Mic volume change is not allowed. case SET_MIC_VOLUME: if (mVgmFromStack) { mVgmFromStack = false; break; } if (NativeInterface.setVolumeNative( getByteAddress(mCurrentDevice), HeadsetClientHalConstants.VOLUME_TYPE_MIC, message.arg1)) { addQueuedAction(SET_MIC_VOLUME); } break; case SET_SPEAKER_VOLUME: // This message should always contain the volume in AudioManager max normalized. Loading @@ -1126,14 +1111,9 @@ public class HeadsetClientStateMachine extends StateMachine { int hfVol = amToHfVol(amVol); Log.d(TAG,"HF volume is set to " + hfVol); mAudioManager.setParameters("hfp_volume=" + hfVol); if (mVgsFromStack) { mVgsFromStack = false; break; } if (NativeInterface.setVolumeNative(getByteAddress(mCurrentDevice), HeadsetClientHalConstants.VOLUME_TYPE_SPK, hfVol)) { addQueuedAction(SET_SPEAKER_VOLUME); } // We do not set the volume in native because multiple devices might be // connected and it does not make sense to synchronize them. Car becomes the // master in such case. break; case DIAL_NUMBER: // Add the call as an outgoing call. Loading Loading @@ -1320,12 +1300,9 @@ public class HeadsetClientStateMachine extends StateMachine { AudioManager.STREAM_VOICE_CALL, hfToAmVol(event.valueInt2), AudioManager.FLAG_SHOW_UI); mVgsFromStack = true; } else if (event.valueInt == HeadsetClientHalConstants.VOLUME_TYPE_MIC) { mAudioManager.setMicrophoneMute(event.valueInt2 == 0); mVgmFromStack = true; } break; case StackEvent.EVENT_TYPE_CMD_RESULT: Loading android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java +3 −5 Original line number Diff line number Diff line Loading @@ -311,11 +311,9 @@ class NativeInterface { Log.d(TAG, "onVolumeChange: address " + address + " event " + event); } HeadsetClientService service = HeadsetClientService.getHeadsetClientService(); if (service != null) { service.messageFromNative(event); } else { Log.w(TAG, "onVolumeChange: Ignoring message because service not available: " + event); } // Ignore volume changes from the Phone. This is to avoid the scenario where we may have two // phones connected each tries to set different volumes. Log.w(TAG, "onVolumeChange: Ignoring message: " + event); } private void onCmdResult(int type, int cme, byte[] address) { Loading Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientService.java +7 −10 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ public class HeadsetClientService extends ProfileService { private NativeInterface mNativeInterface = null; private HandlerThread mSmThread = null; private HeadsetClientStateMachineFactory mSmFactory = null; private AudioManager mAudioManager = null; // Maxinum number of devices we can try connecting to in one session private static final int MAX_STATE_MACHINES_POSSIBLE = 100; Loading @@ -86,6 +87,7 @@ public class HeadsetClientService extends ProfileService { } // Setup the JNI service NativeInterface.initializeNative(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mSmFactory = new HeadsetClientStateMachineFactory(); mStateMachineMap.clear(); Loading Loading @@ -156,8 +158,7 @@ public class HeadsetClientService extends ProfileService { String action = intent.getAction(); // We handle the volume changes for Voice calls here since HFP audio volume control does // not go through audio manager (audio mixer). We check if the voice call volume has // changed and subsequently change the SCO volume see // not go through audio manager (audio mixer). see // ({@link HeadsetClientStateMachine#SET_SPEAKER_VOLUME} in // {@link HeadsetClientStateMachine} for details. if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { Loading @@ -167,14 +168,10 @@ public class HeadsetClientService extends ProfileService { if (streamType == AudioManager.STREAM_VOICE_CALL) { int streamValue = intent .getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1); int streamPrevValue = intent.getIntExtra( AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, -1); if (streamValue != -1 && streamValue != streamPrevValue) { // TODO: Fix this // sm.sendMessage(sm.obtainMessage( // HeadsetClientStateMachine.SET_SPEAKER_VOLUME, streamValue, 0)); } int hfVol = HeadsetClientStateMachine.amToHfVol(streamValue); Log.d(TAG, "Setting volume to audio manager: " + streamValue + " hands free: " + hfVol); mAudioManager.setParameters("hfp_volume=" + hfVol); } } } Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +7 −30 Original line number Diff line number Diff line Loading @@ -132,14 +132,11 @@ public class HeadsetClientStateMachine extends StateMachine { private int mIndicatorNetworkSignal; private int mIndicatorBatteryLevel; private boolean mVgsFromStack = false; private boolean mVgmFromStack = false; private String mOperatorName; private String mSubscriberInfo; private int mMaxAmVcVol; private int mMinAmVcVol; private static int mMaxAmVcVol; private static int mMinAmVcVol; // queue of send actions (pair action, action_data) private Queue<Pair<Integer, Object>> mQueuedActions; Loading Loading @@ -174,8 +171,6 @@ public class HeadsetClientStateMachine extends StateMachine { ProfileService.println(sb, "mIndicatorNetworkType: " + mIndicatorNetworkType); ProfileService.println(sb, "mIndicatorNetworkSignal: " + mIndicatorNetworkSignal); ProfileService.println(sb, "mIndicatorBatteryLevel: " + mIndicatorBatteryLevel); ProfileService.println(sb, "mVgsFromStack: " + mVgsFromStack); ProfileService.println(sb, "mVgmFromStack: " + mVgmFromStack); ProfileService.println(sb, "mOperatorName: " + mOperatorName); ProfileService.println(sb, "mSubscriberInfo: " + mSubscriberInfo); Loading Loading @@ -730,7 +725,7 @@ public class HeadsetClientStateMachine extends StateMachine { public static void cleanup() { } private int hfToAmVol(int hfVol) { static int hfToAmVol(int hfVol) { int amRange = mMaxAmVcVol - mMinAmVcVol; int hfRange = MAX_HFP_SCO_VOICE_CALL_VOLUME - MIN_HFP_SCO_VOICE_CALL_VOLUME; int amOffset = Loading @@ -740,7 +735,7 @@ public class HeadsetClientStateMachine extends StateMachine { return amVol; } private int amToHfVol(int amVol) { static int amToHfVol(int amVol) { int amRange = mMaxAmVcVol - mMinAmVcVol; int hfRange = MAX_HFP_SCO_VOICE_CALL_VOLUME - MIN_HFP_SCO_VOICE_CALL_VOLUME; int hfOffset = (hfRange * (amVol - mMinAmVcVol)) / amRange; Loading Loading @@ -1109,16 +1104,6 @@ public class HeadsetClientStateMachine extends StateMachine { // Called only for Mute/Un-mute - Mic volume change is not allowed. case SET_MIC_VOLUME: if (mVgmFromStack) { mVgmFromStack = false; break; } if (NativeInterface.setVolumeNative( getByteAddress(mCurrentDevice), HeadsetClientHalConstants.VOLUME_TYPE_MIC, message.arg1)) { addQueuedAction(SET_MIC_VOLUME); } break; case SET_SPEAKER_VOLUME: // This message should always contain the volume in AudioManager max normalized. Loading @@ -1126,14 +1111,9 @@ public class HeadsetClientStateMachine extends StateMachine { int hfVol = amToHfVol(amVol); Log.d(TAG,"HF volume is set to " + hfVol); mAudioManager.setParameters("hfp_volume=" + hfVol); if (mVgsFromStack) { mVgsFromStack = false; break; } if (NativeInterface.setVolumeNative(getByteAddress(mCurrentDevice), HeadsetClientHalConstants.VOLUME_TYPE_SPK, hfVol)) { addQueuedAction(SET_SPEAKER_VOLUME); } // We do not set the volume in native because multiple devices might be // connected and it does not make sense to synchronize them. Car becomes the // master in such case. break; case DIAL_NUMBER: // Add the call as an outgoing call. Loading Loading @@ -1320,12 +1300,9 @@ public class HeadsetClientStateMachine extends StateMachine { AudioManager.STREAM_VOICE_CALL, hfToAmVol(event.valueInt2), AudioManager.FLAG_SHOW_UI); mVgsFromStack = true; } else if (event.valueInt == HeadsetClientHalConstants.VOLUME_TYPE_MIC) { mAudioManager.setMicrophoneMute(event.valueInt2 == 0); mVgmFromStack = true; } break; case StackEvent.EVENT_TYPE_CMD_RESULT: Loading
android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java +3 −5 Original line number Diff line number Diff line Loading @@ -311,11 +311,9 @@ class NativeInterface { Log.d(TAG, "onVolumeChange: address " + address + " event " + event); } HeadsetClientService service = HeadsetClientService.getHeadsetClientService(); if (service != null) { service.messageFromNative(event); } else { Log.w(TAG, "onVolumeChange: Ignoring message because service not available: " + event); } // Ignore volume changes from the Phone. This is to avoid the scenario where we may have two // phones connected each tries to set different volumes. Log.w(TAG, "onVolumeChange: Ignoring message: " + event); } private void onCmdResult(int type, int cme, byte[] address) { Loading