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

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

Merge "Only send default audio policy once" into main

parents 47b1e39a 797096e8
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -1349,17 +1349,6 @@ public class HeadsetClientStateMachine extends StateMachine {
                        + " to Connected, mCurrentDevice=" + mCurrentDevice);
            }
            mService.updateBatteryLevel();

            // Send default policies to the remote if
            //   1. need to set audio policy from system props
            //   2. remote device supports audio policy
            if (mForceSetAudioPolicyProperty
                    && getAudioPolicyRemoteSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED) {
                setAudioPolicy(new BluetoothSinkAudioPolicy.Builder(mHsClientAudioPolicy)
                        .setActiveDevicePolicyAfterConnection(mConnectingTimePolicyProperty)
                        .setInBandRingtonePolicy(mInBandRingtonePolicyProperty)
                        .build());
            }
        }

        @Override
@@ -2061,6 +2050,15 @@ public class HeadsetClientStateMachine extends StateMachine {
            Log.i(TAG, "processAndroidAtFeature:"
                    + BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID + " supported");
            setAudioPolicyRemoteSupported(true);

            // Send default policies to the remote if it supports
            if (getForceSetAudioPolicyProperty()) {
                setAudioPolicy(
                        new BluetoothSinkAudioPolicy.Builder(mHsClientAudioPolicy)
                                .setActiveDevicePolicyAfterConnection(mConnectingTimePolicyProperty)
                                .setInBandRingtonePolicy(mInBandRingtonePolicyProperty)
                                .build());
            }
        }
    }

+39 −0
Original line number Diff line number Diff line
@@ -1211,6 +1211,45 @@ public class HeadsetClientStateMachineTest {
        Assert.assertEquals(0, mHeadsetClientStateMachine.mQueuedActions.size());
    }

    @Test
    public void testTestDefaultAudioPolicy() {
        mHeadsetClientStateMachine.setForceSetAudioPolicyProperty(true);
        initToConnectedState();

        // Check if set default policy when Connecting -> Connected
        // The testing sys prop is 0. It is ok to check if set audio policy while leaving connecting
        // state.
        verify(mNativeInterface, times(1))
                .sendAndroidAt(mTestDevice, "+ANDROID=SINKAUDIOPOLICY,0,0,0");

        // Check if won't set default policy when AudioOn -> Connected
        // Transit to AudioOn
        mHeadsetClientStateMachine.setAudioRouteAllowed(true);
        StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED);
        event.valueInt = HeadsetClientHalConstants.AUDIO_STATE_CONNECTED;
        event.device = mTestDevice;
        mHeadsetClientStateMachine.sendMessage(
                mHeadsetClientStateMachine.obtainMessage(StackEvent.STACK_EVENT, event));
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        Assert.assertThat(
                mHeadsetClientStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(HeadsetClientStateMachine.AudioOn.class));

        // Back to Connected
        event = new StackEvent(StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED);
        event.valueInt = HeadsetClientHalConstants.AUDIO_STATE_DISCONNECTED;
        event.device = mTestDevice;
        mHeadsetClientStateMachine.sendMessage(
                mHeadsetClientStateMachine.obtainMessage(StackEvent.STACK_EVENT, event));
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        Assert.assertThat(
                mHeadsetClientStateMachine.getCurrentState(),
                IsInstanceOf.instanceOf(HeadsetClientStateMachine.Connected.class));

        verify(mNativeInterface, times(1))
                .sendAndroidAt(mTestDevice, "+ANDROID=SINKAUDIOPOLICY,0,0,0");
    }

    @Test
    public void testDumpDoesNotCrash() {
        mHeadsetClientStateMachine.dump(new StringBuilder());