Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +9 −11 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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()); } } } Loading android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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()); Loading Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +9 −11 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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()); } } } Loading
android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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()); Loading