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

Commit 1ad69edd authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Clean up unused code of PRIORITY

Bug: 297983179
Test: atest BluetoothInstrumentationTests
Change-Id: If4a31483dfb3794b6c490b8cf4f790477a17f101
parent 27f9032b
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -723,15 +723,16 @@ 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, 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());
        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());
        clearInvocations(mHeadsetService, mA2dpService);

        // Generate connection state changed for A2DP for testDevices[2] and trigger
@@ -757,15 +758,16 @@ public class PhonePolicyTest {
        //                    active device change intent
        // - testDevices[3] - not connected for HFP nor A2DP: setConnectionPolicy() should not be
        //                    called
        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());
        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());
        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 PRIORITY_OFF")
        assertWithMessage("Setting device priority to CONNECTION_POLICY_FORBIDDEN")
                .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 PRIORITY_ON")
        assertWithMessage("Setting device priority to CONNECTION_POLICY_ALLOWED")
                .that(BluetoothProfile.CONNECTION_POLICY_ALLOWED)
                .isEqualTo(mService.getConnectionPolicy(mLeftDevice));
    }
+0 −40
Original line number Diff line number Diff line
@@ -553,27 +553,6 @@ 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
     *
@@ -614,25 +593,6 @@ 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.
     *
+0 −41
Original line number Diff line number Diff line
@@ -328,27 +328,6 @@ 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
     *
@@ -389,26 +368,6 @@ 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.
     *
+0 −45
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ 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;
@@ -5585,50 +5584,6 @@ 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