Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55b23f52 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Handle volume changes for multiple devices"

parents 378d3a23 57187246
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -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;

@@ -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();
@@ -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)) {
@@ -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);
                }
            }
        }
+7 −30
Original line number Diff line number Diff line
@@ -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;
@@ -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);

@@ -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 =
@@ -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;
@@ -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.
@@ -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.
@@ -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:
+3 −5
Original line number Diff line number Diff line
@@ -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) {