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

Commit 692d36d7 authored by Felix Stern's avatar Felix Stern Committed by Gerrit Code Review
Browse files

Revert "Clean up unused code of PRIORITY"

Revert submission 2737117-bt-clean-up-priority

Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.corp.google.com/builds/quarterdeck?branch=git_udc-mainline-prod&target=test_suites_arm&lkgb=10777828&lkbb=10779852&fkbb=10779852, bug b/299586546

BUG: b/299586546

Reverted changes: /q/submissionid:2737117-bt-clean-up-priority

Change-Id: Ib6e500bec83580198568755c676eb29c11cb5f8e
parent 1ad69edd
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -723,16 +723,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
@@ -758,16 +757,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;
@@ -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