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

Commit 0e9f86f7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove flag allow_switching_hid_and_hogp" into main am: 7f007c1e

parents 6ba5c810 7f007c1e
Loading
Loading
Loading
Loading
+61 −129
Original line number Diff line number Diff line
@@ -87,10 +87,6 @@ public class HidHostService extends ProfileService {
            }
        }

        void setState(int state) {
            setState(mSelectedTransport, state);
        }

        @Override
        public String toString() {
            return ("Selected transport=" + mSelectedTransport)
@@ -198,20 +194,6 @@ public class HidHostService extends ProfileService {
    private byte[] getByteAddress(BluetoothDevice device, int transport) {
        final ParcelUuid[] uuids = mAdapterService.getRemoteUuids(device);

        if (!Flags.allowSwitchingHidAndHogp()) {
            boolean hogpSupported = Utils.arrayContains(uuids, BluetoothUuid.HOGP);
            boolean headtrackerSupported =
                    Utils.arrayContains(uuids, HidHostService.ANDROID_HEADTRACKER_UUID);

            if (hogpSupported || headtrackerSupported) {
                // Use pseudo address when HOGP is available
                return Utils.getByteAddress(device);
            } else {
                // Otherwise use identity address
                return getIdentityAddress(device);
            }
        }

        if (transport == BluetoothDevice.TRANSPORT_LE) {
            // Use pseudo address when HOGP is to be used
            return Utils.getByteAddress(device);
@@ -331,11 +313,6 @@ public class HidHostService extends ProfileService {
                    "nativeConnect: Connection attempt failed."
                            + (" device=" + device)
                            + (" transport=" + transport));

            if (!Flags.allowSwitchingHidAndHogp()) {
                updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTING);
                updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTED);
            }
            return false;
        }
        return true;
@@ -362,10 +339,6 @@ public class HidHostService extends ProfileService {
                    "nativeDisconnect: Disconnection attempt failed."
                            + (" device=" + device)
                            + (" transport=" + transport));
            if (!Flags.allowSwitchingHidAndHogp()) {
                updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTING);
                updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTED);
            }
            return false;
        }
        return true;
@@ -434,9 +407,6 @@ public class HidHostService extends ProfileService {
            };

    private void handleMessageSendData(Message msg) {
        if (!Flags.allowSwitchingHidAndHogp()) {
            return;
        }
        BluetoothDevice device = mAdapterService.getDeviceFromByte((byte[]) msg.obj);

        Bundle data = msg.getData();
@@ -630,7 +600,6 @@ public class HidHostService extends ProfileService {
        int state = msg.arg2;
        int prevState = getState(device, transport);

        if (Flags.allowSwitchingHidAndHogp()) {
        InputDevice inputDevice = mInputDevices.get(device);
        if (inputDevice != null) {
            // Update transport if it was not resolved already
@@ -663,11 +632,6 @@ public class HidHostService extends ProfileService {
                            + (" newState=" + state)
                            + (" prevState=" + prevState));
        }
        } else {
            // Only TRANSPORT_AUTO should be used when allowSwitchingHidAndHogp is disabled
            transport = BluetoothDevice.TRANSPORT_AUTO;
            setTransport(device, BluetoothDevice.TRANSPORT_AUTO);
        }

        Log.d(
                TAG,
@@ -676,11 +640,10 @@ public class HidHostService extends ProfileService {
                        + (" newState=" + state)
                        + (" prevState=" + prevState));

        boolean connectionAllowed = true;
        // Process connection
        if (prevState == BluetoothProfile.STATE_DISCONNECTED
                && state == BluetoothProfile.STATE_CONNECTED) {
            connectionAllowed = processConnection(device, transport);
            processConnection(device, transport);
        }

        // ACCEPTING state has to be treated as DISCONNECTED state
@@ -688,23 +651,17 @@ public class HidHostService extends ProfileService {
        if (state == STATE_ACCEPTING) {
            reportedState = BluetoothProfile.STATE_DISCONNECTED;
        }

        if (Flags.allowSwitchingHidAndHogp() || connectionAllowed) {
        updateConnectionState(device, transport, reportedState);
    }
    }

    private void handleMessageDisconnect(Message msg) {
        BluetoothDevice device = (BluetoothDevice) msg.obj;
        int connectionPolicy = msg.arg1;

        boolean reconnectAllowed = true;
        if (Flags.allowSwitchingHidAndHogp()) {
        if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            reconnectAllowed = false;
        }
        }

        nativeDisconnect(device, getTransport(device), reconnectAllowed);
    }

@@ -712,7 +669,6 @@ public class HidHostService extends ProfileService {
        BluetoothDevice device = (BluetoothDevice) msg.obj;
        InputDevice inputDevice = getOrCreateInputDevice(device);

        if (Flags.allowSwitchingHidAndHogp()) {
        int connectionPolicy = getConnectionPolicy(device);
        if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            Log.e(
@@ -723,8 +679,6 @@ public class HidHostService extends ProfileService {

            return;
        }
        }

        nativeConnect(device, inputDevice.mSelectedTransport);
    }

@@ -737,7 +691,7 @@ public class HidHostService extends ProfileService {
     * @return true if transport matches, otherwise false
     */
    private boolean checkTransport(BluetoothDevice device, int transport, int message) {
        if (Flags.allowSwitchingHidAndHogp() && getTransport(device) != transport) {
        if (getTransport(device) != transport) {
            Log.w(
                    TAG,
                    "checkTransport:"
@@ -763,12 +717,7 @@ public class HidHostService extends ProfileService {
                            + (" device=" + device)
                            + (" connectionPolicy=" + getConnectionPolicy(device)));

            if (Flags.allowSwitchingHidAndHogp()) {
            nativeDisconnect(device, transport, false);
            } else {
                mNativeInterface.virtualUnPlug(
                        getByteAddress(device), getAddressType(device), getTransport(device));
            }
            return false;
        }
        return true;
@@ -1217,11 +1166,6 @@ public class HidHostService extends ProfileService {
            return false;
        }

        if (!Flags.allowSwitchingHidAndHogp()) {
            return mNativeInterface.sendData(
                    getByteAddress(device), getAddressType(device), getTransport(device), report);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_SEND_DATA, device);
        Bundle data = new Bundle();
        data.putString(BluetoothHidHost.EXTRA_REPORT, report);
@@ -1321,9 +1265,7 @@ public class HidHostService extends ProfileService {
     */
    private void updateConnectionState(BluetoothDevice device, int transport, int newState) {
        InputDevice inputDevice = mInputDevices.get(device);
        int prevState = BluetoothProfile.STATE_DISCONNECTED;

        if (Flags.allowSwitchingHidAndHogp()) {
        if (inputDevice == null) {
            Log.w(
                    TAG,
@@ -1343,16 +1285,8 @@ public class HidHostService extends ProfileService {
            return;
        }

            prevState = inputDevice.getState(transport);
        int prevState = inputDevice.getState(transport);
        inputDevice.setState(transport, newState);
        } else {
            if (inputDevice == null) {
                inputDevice = getOrCreateInputDevice(device);
            }
            prevState = inputDevice.getState();
            setTransport(device, transport);
            inputDevice.setState(newState);
        }

        if (prevState == newState) {
            Log.d(
@@ -1393,9 +1327,7 @@ public class HidHostService extends ProfileService {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        if (Flags.allowSwitchingHidAndHogp()) {
        intent.putExtra(BluetoothDevice.EXTRA_TRANSPORT, transport);
        }
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
        sendBroadcastAsUser(
                intent,
+0 −2
Original line number Diff line number Diff line
@@ -110,7 +110,6 @@ public class HidHostServiceBinderTest {

    @Test
    public void setPreferredTransport_callsServiceMethod() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP);
        int preferredTransport = BluetoothDevice.TRANSPORT_AUTO;
        mBinder.setPreferredTransport(mRemoteDevice, preferredTransport, null);

@@ -119,7 +118,6 @@ public class HidHostServiceBinderTest {

    @Test
    public void getPreferredTransport_callsServiceMethod() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP);
        mBinder.getPreferredTransport(mRemoteDevice, null);

        verify(mService).getPreferredTransport(mRemoteDevice);
+2 −2
Original line number Diff line number Diff line
@@ -514,9 +514,9 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]);
    method @FlaggedApi("com.android.bluetooth.flags.allow_switching_hid_and_hogp") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getPreferredTransport(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getPreferredTransport(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @FlaggedApi("com.android.bluetooth.flags.allow_switching_hid_and_hogp") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPreferredTransport(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPreferredTransport(@NonNull android.bluetooth.BluetoothDevice, int);
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED";
  }

+0 −2
Original line number Diff line number Diff line
@@ -465,7 +465,6 @@ public final class BluetoothHidHost implements BluetoothProfile {
     * @throws IllegalArgumentException if the {@code device} invalid.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP)
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(
@@ -569,7 +568,6 @@ public final class BluetoothHidHost implements BluetoothProfile {
     * @throws IllegalArgumentException if the {@code device} invalid.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP)
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(
+0 −6
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.Log;
@@ -63,7 +62,6 @@ import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.bluetooth.flags.Flags;
import com.android.compatibility.common.util.AdoptShellPermissionsRule;

import org.hamcrest.CustomTypeSafeMatcher;
@@ -292,9 +290,7 @@ public class HidHeadTrackerTest {
     */
    @SuppressLint("MissingPermission")
    @Test
    @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP})
    public void connectWithoutHidServiceTest() {

        registerIntentActions(
                BluetoothDevice.ACTION_ACL_CONNECTED,
                BluetoothDevice.ACTION_ACL_DISCONNECTED,
@@ -385,9 +381,7 @@ public class HidHeadTrackerTest {
     */
    @SuppressLint("MissingPermission")
    @Test
    @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP})
    public void connectWithHidServiceTest() {

        registerIntentActions(
                BluetoothDevice.ACTION_ACL_CONNECTED,
                BluetoothDevice.ACTION_UUID,
Loading