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

Commit 7197bec1 authored by Felix Stern's avatar Felix Stern Committed by Automerger Merge Worker
Browse files

Merge "Revert "Clean up unused code of PRIORITY"" into main am: 5da20d02

parents a5121f5c 5da20d02
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -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
@@ -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);
    }

+2 −2
Original line number Diff line number Diff line
@@ -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));
    }
+40 −0
Original line number Diff line number Diff line
@@ -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
     *
@@ -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.
     *
+41 −0
Original line number Diff line number Diff line
@@ -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
     *
@@ -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.
     *
+45 −0
Original line number Diff line number Diff line
@@ -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;
@@ -5588,6 +5589,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