Loading android/app/src/com/android/bluetooth/Utils.java +11 −12 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.DeviceConfig; import android.provider.Telephony; import android.util.Log; Loading Loading @@ -87,22 +88,14 @@ public final class Utils { private static final String TAG = "BluetoothUtils"; private static final int MICROS_PER_UNIT = 625; private static final String PTS_TEST_MODE_PROPERTY = "persist.bluetooth.pts"; private static final String KEY_TEMP_ALLOW_LIST_DURATION_MS = "temp_allow_list_duration_ms"; private static final long DEFAULT_TEMP_ALLOW_LIST_DURATION_MS = 10_000; static final int BD_ADDR_LEN = 6; // bytes static final int BD_UUID_LEN = 16; // bytes public static final Bundle sTempAllowlistBroadcastOptions; static { final long durationMs = 10_000; final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); sTempAllowlistBroadcastOptions = bOptions.toBundle(); } /* * Special characters * Special character * * (See "What is a phone number?" doc) * 'p' --- GSM pause character, same as comma Loading Loading @@ -929,6 +922,12 @@ public final class Utils { } public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return sTempAllowlistBroadcastOptions; final long durationMs = DeviceConfig.getLong(DeviceConfig.NAMESPACE_BLUETOOTH, KEY_TEMP_ALLOW_LIST_DURATION_MS, DEFAULT_TEMP_ALLOW_LIST_DURATION_MS); final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); return bOptions.toBundle(); } } android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java +5 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaControllerCompat; Loading @@ -40,10 +41,8 @@ import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; import com.android.bluetooth.TestUtils; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.storage.DatabaseManager; import org.hamcrest.core.IsInstanceOf; Loading Loading @@ -200,7 +199,7 @@ public class AvrcpControllerStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mAvrcpStateMachine.getHandler().getLooper()); verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertThat(mAvrcpStateMachine.getCurrentState(), IsInstanceOf.instanceOf(AvrcpControllerStateMachine.Connected.class)); Assert.assertEquals(mAvrcpStateMachine.getState(), BluetoothProfile.STATE_CONNECTED); Loading Loading @@ -332,7 +331,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading Loading @@ -361,7 +360,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading Loading @@ -390,7 +389,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.content.pm.PermissionInfo; import android.content.res.Resources; import android.media.AudioManager; import android.os.Binder; import android.os.Bundle; import android.os.Looper; import android.os.PowerManager; import android.os.Process; Loading Loading @@ -246,7 +247,7 @@ public class AdapterServiceTest { verify(mMockContext, timeout(CONTEXT_SWITCH_MS).times(2 * invocationNumber + 2)) .sendBroadcast(any(), eq(BLUETOOTH_SCAN), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); final int scanMode = mServiceBinder.getScanMode(mAttributionSource); Assert.assertTrue(scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE || scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import androidx.test.filters.MediumTest; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.TestUtils; import com.android.bluetooth.Utils; import org.junit.After; import org.junit.Assert; Loading Loading @@ -286,7 +285,7 @@ public class BondStateMachineTest { if (shouldBroadcast) { verify(mAdapterService, times(++mVerifyCount)).sendBroadcastAsUser( intentArgument.capture(), eq(UserHandle.ALL), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); eq(BLUETOOTH_CONNECT), any(Bundle.class)); verifyBondStateChangeIntent(broadcastOldState, broadcastNewState, intentArgument.getValue()); } else { Loading android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothProfile; import android.content.Intent; import android.os.Bundle; import android.os.HandlerThread; import android.os.Message; import android.os.TestLooperManager; Loading Loading @@ -85,7 +86,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -102,7 +103,7 @@ public class RemoteDevicesTest { batteryLevel = 15; mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Loading Loading @@ -169,7 +170,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -183,7 +184,7 @@ public class RemoteDevicesTest { mRemoteDevices.resetBatteryLevel(mDevice1); // Verify BATTERY_LEVEL_CHANGED intent is sent after first reset verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -200,7 +201,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -217,7 +218,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -233,7 +234,7 @@ public class RemoteDevicesTest { BluetoothProfile.STATE_DISCONNECTING, BluetoothProfile.STATE_DISCONNECTED)); // Verify BATTERY_LEVEL_CHANGED intent is sent after first reset verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -245,7 +246,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -262,7 +263,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -278,7 +279,7 @@ public class RemoteDevicesTest { AbstractionLayer.BT_ACL_STATE_DISCONNECTED, 19); // HCI code 19 remote terminated // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verify(mAdapterService, times(2)).obfuscateAddress(mDevice1); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2)); Loading @@ -295,7 +296,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(4)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading @@ -311,7 +312,7 @@ public class RemoteDevicesTest { mRemoteDevices.onHfIndicatorValueChanged(getHfIndicatorIntent(mDevice1, batteryLevel, HeadsetHalConstants.HF_INDICATOR_BATTERY_LEVEL_STATUS)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading Loading @@ -341,7 +342,7 @@ public class RemoteDevicesTest { BluetoothAssignedNumbers.PLANTRONICS, BluetoothHeadset.AT_CMD_TYPE_SET, getXEventArray(3, 8), mDevice1)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, 42, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading @@ -364,7 +365,7 @@ public class RemoteDevicesTest { 10 }, mDevice1)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, 60, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading Loading
android/app/src/com/android/bluetooth/Utils.java +11 −12 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.DeviceConfig; import android.provider.Telephony; import android.util.Log; Loading Loading @@ -87,22 +88,14 @@ public final class Utils { private static final String TAG = "BluetoothUtils"; private static final int MICROS_PER_UNIT = 625; private static final String PTS_TEST_MODE_PROPERTY = "persist.bluetooth.pts"; private static final String KEY_TEMP_ALLOW_LIST_DURATION_MS = "temp_allow_list_duration_ms"; private static final long DEFAULT_TEMP_ALLOW_LIST_DURATION_MS = 10_000; static final int BD_ADDR_LEN = 6; // bytes static final int BD_UUID_LEN = 16; // bytes public static final Bundle sTempAllowlistBroadcastOptions; static { final long durationMs = 10_000; final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); sTempAllowlistBroadcastOptions = bOptions.toBundle(); } /* * Special characters * Special character * * (See "What is a phone number?" doc) * 'p' --- GSM pause character, same as comma Loading Loading @@ -929,6 +922,12 @@ public final class Utils { } public static @NonNull Bundle getTempAllowlistBroadcastOptions() { return sTempAllowlistBroadcastOptions; final long durationMs = DeviceConfig.getLong(DeviceConfig.NAMESPACE_BLUETOOTH, KEY_TEMP_ALLOW_LIST_DURATION_MS, DEFAULT_TEMP_ALLOW_LIST_DURATION_MS); final BroadcastOptions bOptions = BroadcastOptions.makeBasic(); bOptions.setTemporaryAppAllowlist(durationMs, TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, PowerExemptionManager.REASON_BLUETOOTH_BROADCAST, ""); return bOptions.toBundle(); } }
android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java +5 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaControllerCompat; Loading @@ -40,10 +41,8 @@ import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; import com.android.bluetooth.TestUtils; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.storage.DatabaseManager; import org.hamcrest.core.IsInstanceOf; Loading Loading @@ -200,7 +199,7 @@ public class AvrcpControllerStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mAvrcpStateMachine.getHandler().getLooper()); verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertThat(mAvrcpStateMachine.getCurrentState(), IsInstanceOf.instanceOf(AvrcpControllerStateMachine.Connected.class)); Assert.assertEquals(mAvrcpStateMachine.getState(), BluetoothProfile.STATE_CONNECTED); Loading Loading @@ -332,7 +331,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading Loading @@ -361,7 +360,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading Loading @@ -390,7 +389,7 @@ public class AvrcpControllerStateMachineTest { verify(mAvrcpControllerService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(numBroadcastsSent)).sendBroadcast( mIntentArgument.capture(), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); Assert.assertEquals(mTestDevice, mIntentArgument.getValue().getParcelableExtra( BluetoothDevice.EXTRA_DEVICE)); Assert.assertEquals(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED, Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.content.pm.PermissionInfo; import android.content.res.Resources; import android.media.AudioManager; import android.os.Binder; import android.os.Bundle; import android.os.Looper; import android.os.PowerManager; import android.os.Process; Loading Loading @@ -246,7 +247,7 @@ public class AdapterServiceTest { verify(mMockContext, timeout(CONTEXT_SWITCH_MS).times(2 * invocationNumber + 2)) .sendBroadcast(any(), eq(BLUETOOTH_SCAN), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); final int scanMode = mServiceBinder.getScanMode(mAttributionSource); Assert.assertTrue(scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE || scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import androidx.test.filters.MediumTest; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.TestUtils; import com.android.bluetooth.Utils; import org.junit.After; import org.junit.Assert; Loading Loading @@ -286,7 +285,7 @@ public class BondStateMachineTest { if (shouldBroadcast) { verify(mAdapterService, times(++mVerifyCount)).sendBroadcastAsUser( intentArgument.capture(), eq(UserHandle.ALL), eq(BLUETOOTH_CONNECT), same(Utils.sTempAllowlistBroadcastOptions)); eq(BLUETOOTH_CONNECT), any(Bundle.class)); verifyBondStateChangeIntent(broadcastOldState, broadcastNewState, intentArgument.getValue()); } else { Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothProfile; import android.content.Intent; import android.os.Bundle; import android.os.HandlerThread; import android.os.Message; import android.os.TestLooperManager; Loading Loading @@ -85,7 +86,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -102,7 +103,7 @@ public class RemoteDevicesTest { batteryLevel = 15; mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Loading Loading @@ -169,7 +170,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -183,7 +184,7 @@ public class RemoteDevicesTest { mRemoteDevices.resetBatteryLevel(mDevice1); // Verify BATTERY_LEVEL_CHANGED intent is sent after first reset verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -200,7 +201,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -217,7 +218,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -233,7 +234,7 @@ public class RemoteDevicesTest { BluetoothProfile.STATE_DISCONNECTING, BluetoothProfile.STATE_DISCONNECTED)); // Verify BATTERY_LEVEL_CHANGED intent is sent after first reset verify(mAdapterService, times(2)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -245,7 +246,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -262,7 +263,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); Loading @@ -278,7 +279,7 @@ public class RemoteDevicesTest { AbstractionLayer.BT_ACL_STATE_DISCONNECTED, 19); // HCI code 19 remote terminated // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verify(mAdapterService, times(2)).obfuscateAddress(mDevice1); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2)); Loading @@ -295,7 +296,7 @@ public class RemoteDevicesTest { // Verify that updating battery level triggers ACTION_BATTERY_LEVEL_CHANGED intent again mRemoteDevices.updateBatteryLevel(mDevice1, batteryLevel); verify(mAdapterService, times(4)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); mStringArgument.capture(), any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading @@ -311,7 +312,7 @@ public class RemoteDevicesTest { mRemoteDevices.onHfIndicatorValueChanged(getHfIndicatorIntent(mDevice1, batteryLevel, HeadsetHalConstants.HF_INDICATOR_BATTERY_LEVEL_STATUS)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, batteryLevel, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading Loading @@ -341,7 +342,7 @@ public class RemoteDevicesTest { BluetoothAssignedNumbers.PLANTRONICS, BluetoothHeadset.AT_CMD_TYPE_SET, getXEventArray(3, 8), mDevice1)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, 42, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading @@ -364,7 +365,7 @@ public class RemoteDevicesTest { 10 }, mDevice1)); verify(mAdapterService).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture(), same(Utils.sTempAllowlistBroadcastOptions)); any(Bundle.class)); verifyBatteryLevelChangedIntent(mDevice1, 60, mIntentArgument); Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue()); } Loading