Loading android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -781,16 +781,15 @@ public class PhonePolicyTest { // - testDevices[2] - connected for A2DP: setConnectionPolicy() should not be called // - testDevices[3] - not connected for HFP nor A2DP: setConnectionPolicy() should not be // called verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, never()) .setConnectionPolicy( eq(testDevices[1]), eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED)); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[1]), eq(BluetoothProfile.PRIORITY_AUTO_CONNECT)); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); clearInvocations(mHeadsetService, mA2dpService); // Generate connection state changed for A2DP for testDevices[2] and trigger Loading @@ -816,16 +815,15 @@ public class PhonePolicyTest { // active device change intent // - testDevices[3] - not connected for HFP nor A2DP: setConnectionPolicy() should not be // called verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, never()) .setConnectionPolicy( eq(testDevices[2]), eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED)); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[2]), eq(BluetoothProfile.PRIORITY_AUTO_CONNECT)); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); clearInvocations(mHeadsetService, mA2dpService); } Loading android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -359,13 +359,13 @@ public class LeAudioServiceTest { when(mDatabaseManager.getProfileConnectionPolicy(mLeftDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); assertWithMessage("Setting device priority to CONNECTION_POLICY_FORBIDDEN") assertWithMessage("Setting device priority to PRIORITY_OFF") .that(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) .isEqualTo(mService.getConnectionPolicy(mLeftDevice)); when(mDatabaseManager.getProfileConnectionPolicy(mLeftDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); assertWithMessage("Setting device priority to CONNECTION_POLICY_ALLOWED") assertWithMessage("Setting device priority to PRIORITY_ON") .that(BluetoothProfile.CONNECTION_POLICY_ALLOWED) .isEqualTo(mService.getConnectionPolicy(mLeftDevice)); } Loading framework/java/android/bluetooth/BluetoothA2dp.java +40 −0 Original line number Diff line number Diff line Loading @@ -553,6 +553,27 @@ public final class BluetoothA2dp implements BluetoothProfile { return defaultValue; } /** * Set priority of the profile * * <p> The device should already be paired. * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF} * * @param device Paired bluetooth device * @param priority * @return true if priority is set, false on error * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public boolean setPriority(BluetoothDevice device, int priority) { if (DBG) log("setPriority(" + device + ", " + priority + ")"); return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority)); } /** * Set connection policy of the profile * Loading Loading @@ -593,6 +614,25 @@ public final class BluetoothA2dp implements BluetoothProfile { return defaultValue; } /** * Get the priority of the profile. * * <p> The priority can be any of: * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} * * @param device Bluetooth device * @return priority of the device * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public int getPriority(BluetoothDevice device) { if (VDBG) log("getPriority(" + device + ")"); return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); } /** * Get the connection policy of the profile. * Loading framework/java/android/bluetooth/BluetoothA2dpSink.java +41 −0 Original line number Diff line number Diff line Loading @@ -328,6 +328,27 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return defaultValue; } /** * Set priority of the profile * * <p> The device should already be paired. * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF} * * @param device Paired bluetooth device * @param priority * @return true if priority is set, false on error * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public boolean setPriority(BluetoothDevice device, int priority) { if (DBG) log("setPriority(" + device + ", " + priority + ")"); return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority)); } /** * Set connection policy of the profile * Loading Loading @@ -368,6 +389,26 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return defaultValue; } /** * Get the priority of the profile. * * <p> The priority can be any of: * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} * * @param device Bluetooth device * @return priority of the device * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public int getPriority(BluetoothDevice device) { if (VDBG) log("getPriority(" + device + ")"); return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); } /** * Get the connection policy of the profile. * Loading framework/java/android/bluetooth/BluetoothAdapter.java +45 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.annotation.SystemApi; import android.app.PendingIntent; import android.bluetooth.BluetoothDevice.AddressType; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; Loading Loading @@ -5584,6 +5585,50 @@ public final class BluetoothAdapter { BluetoothQualityReport bluetoothQualityReport, int status); } /** * Converts old constant of priority to the new for connection policy * * @param priority is the priority to convert to connection policy * @return the equivalent connection policy constant to the priority * * @hide */ public static @ConnectionPolicy int priorityToConnectionPolicy(int priority) { switch(priority) { case BluetoothProfile.PRIORITY_AUTO_CONNECT: return BluetoothProfile.CONNECTION_POLICY_ALLOWED; case BluetoothProfile.PRIORITY_ON: return BluetoothProfile.CONNECTION_POLICY_ALLOWED; case BluetoothProfile.PRIORITY_OFF: return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; case BluetoothProfile.PRIORITY_UNDEFINED: return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; default: Log.e(TAG, "setPriority: Invalid priority: " + priority); return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } } /** * Converts new constant of connection policy to the old for priority * * @param connectionPolicy is the connection policy to convert to priority * @return the equivalent priority constant to the connectionPolicy * * @hide */ public static int connectionPolicyToPriority(@ConnectionPolicy int connectionPolicy) { switch(connectionPolicy) { case BluetoothProfile.CONNECTION_POLICY_ALLOWED: return BluetoothProfile.PRIORITY_ON; case BluetoothProfile.CONNECTION_POLICY_FORBIDDEN: return BluetoothProfile.PRIORITY_OFF; case BluetoothProfile.CONNECTION_POLICY_UNKNOWN: return BluetoothProfile.PRIORITY_UNDEFINED; } return BluetoothProfile.PRIORITY_UNDEFINED; } /** * Sets the desired mode of the HCI snoop logging applied at Bluetooth startup. * Loading Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -781,16 +781,15 @@ public class PhonePolicyTest { // - testDevices[2] - connected for A2DP: setConnectionPolicy() should not be called // - testDevices[3] - not connected for HFP nor A2DP: setConnectionPolicy() should not be // called verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, never()) .setConnectionPolicy( eq(testDevices[1]), eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED)); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[1]), eq(BluetoothProfile.PRIORITY_AUTO_CONNECT)); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); clearInvocations(mHeadsetService, mA2dpService); // Generate connection state changed for A2DP for testDevices[2] and trigger Loading @@ -816,16 +815,15 @@ public class PhonePolicyTest { // active device change intent // - testDevices[3] - not connected for HFP nor A2DP: setConnectionPolicy() should not be // called verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, never()) .setConnectionPolicy( eq(testDevices[2]), eq(BluetoothProfile.CONNECTION_POLICY_ALLOWED)); verify(mHeadsetService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, never()).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[0]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[1]), anyInt()); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[2]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[2]), eq(BluetoothProfile.PRIORITY_AUTO_CONNECT)); verify(mHeadsetService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); verify(mA2dpService, times(0)).setConnectionPolicy(eq(testDevices[3]), anyInt()); clearInvocations(mHeadsetService, mA2dpService); } Loading
android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -359,13 +359,13 @@ public class LeAudioServiceTest { when(mDatabaseManager.getProfileConnectionPolicy(mLeftDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); assertWithMessage("Setting device priority to CONNECTION_POLICY_FORBIDDEN") assertWithMessage("Setting device priority to PRIORITY_OFF") .that(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) .isEqualTo(mService.getConnectionPolicy(mLeftDevice)); when(mDatabaseManager.getProfileConnectionPolicy(mLeftDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); assertWithMessage("Setting device priority to CONNECTION_POLICY_ALLOWED") assertWithMessage("Setting device priority to PRIORITY_ON") .that(BluetoothProfile.CONNECTION_POLICY_ALLOWED) .isEqualTo(mService.getConnectionPolicy(mLeftDevice)); } Loading
framework/java/android/bluetooth/BluetoothA2dp.java +40 −0 Original line number Diff line number Diff line Loading @@ -553,6 +553,27 @@ public final class BluetoothA2dp implements BluetoothProfile { return defaultValue; } /** * Set priority of the profile * * <p> The device should already be paired. * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF} * * @param device Paired bluetooth device * @param priority * @return true if priority is set, false on error * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public boolean setPriority(BluetoothDevice device, int priority) { if (DBG) log("setPriority(" + device + ", " + priority + ")"); return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority)); } /** * Set connection policy of the profile * Loading Loading @@ -593,6 +614,25 @@ public final class BluetoothA2dp implements BluetoothProfile { return defaultValue; } /** * Get the priority of the profile. * * <p> The priority can be any of: * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} * * @param device Bluetooth device * @return priority of the device * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public int getPriority(BluetoothDevice device) { if (VDBG) log("getPriority(" + device + ")"); return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); } /** * Get the connection policy of the profile. * Loading
framework/java/android/bluetooth/BluetoothA2dpSink.java +41 −0 Original line number Diff line number Diff line Loading @@ -328,6 +328,27 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return defaultValue; } /** * Set priority of the profile * * <p> The device should already be paired. * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF} * * @param device Paired bluetooth device * @param priority * @return true if priority is set, false on error * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public boolean setPriority(BluetoothDevice device, int priority) { if (DBG) log("setPriority(" + device + ", " + priority + ")"); return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority)); } /** * Set connection policy of the profile * Loading Loading @@ -368,6 +389,26 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return defaultValue; } /** * Get the priority of the profile. * * <p> The priority can be any of: * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} * * @param device Bluetooth device * @return priority of the device * @hide */ @RequiresBluetoothConnectPermission @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public int getPriority(BluetoothDevice device) { if (VDBG) log("getPriority(" + device + ")"); return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); } /** * Get the connection policy of the profile. * Loading
framework/java/android/bluetooth/BluetoothAdapter.java +45 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.annotation.SystemApi; import android.app.PendingIntent; import android.bluetooth.BluetoothDevice.AddressType; import android.bluetooth.BluetoothDevice.Transport; import android.bluetooth.BluetoothProfile.ConnectionPolicy; import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission; import android.bluetooth.annotations.RequiresBluetoothConnectPermission; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; Loading Loading @@ -5584,6 +5585,50 @@ public final class BluetoothAdapter { BluetoothQualityReport bluetoothQualityReport, int status); } /** * Converts old constant of priority to the new for connection policy * * @param priority is the priority to convert to connection policy * @return the equivalent connection policy constant to the priority * * @hide */ public static @ConnectionPolicy int priorityToConnectionPolicy(int priority) { switch(priority) { case BluetoothProfile.PRIORITY_AUTO_CONNECT: return BluetoothProfile.CONNECTION_POLICY_ALLOWED; case BluetoothProfile.PRIORITY_ON: return BluetoothProfile.CONNECTION_POLICY_ALLOWED; case BluetoothProfile.PRIORITY_OFF: return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; case BluetoothProfile.PRIORITY_UNDEFINED: return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; default: Log.e(TAG, "setPriority: Invalid priority: " + priority); return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } } /** * Converts new constant of connection policy to the old for priority * * @param connectionPolicy is the connection policy to convert to priority * @return the equivalent priority constant to the connectionPolicy * * @hide */ public static int connectionPolicyToPriority(@ConnectionPolicy int connectionPolicy) { switch(connectionPolicy) { case BluetoothProfile.CONNECTION_POLICY_ALLOWED: return BluetoothProfile.PRIORITY_ON; case BluetoothProfile.CONNECTION_POLICY_FORBIDDEN: return BluetoothProfile.PRIORITY_OFF; case BluetoothProfile.CONNECTION_POLICY_UNKNOWN: return BluetoothProfile.PRIORITY_UNDEFINED; } return BluetoothProfile.PRIORITY_UNDEFINED; } /** * Sets the desired mode of the HCI snoop logging applied at Bluetooth startup. * Loading