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

Commit 1f4711b2 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Refactoring usages of priority methods and constants to use connection...

Merge "Refactoring usages of priority methods and constants to use connection policy instead." am: 622e5190 am: 58e645f3

Change-Id: If359374da210df094394612fbb6b21e42c7bbe4f
parents e74c7a61 58e645f3
Loading
Loading
Loading
Loading
+44 −19
Original line number Diff line number Diff line
@@ -229,8 +229,8 @@ public class A2dpService extends ProfileService {
            Log.d(TAG, "connect(): " + device);
        }

        if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) {
            Log.e(TAG, "Cannot connect to " + device + " : PRIORITY_OFF");
        if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            Log.e(TAG, "Cannot connect to " + device + " : CONNECTION_POLICY_FORBIDDEN");
            return false;
        }
        if (!BluetoothUuid.isUuidPresent(mAdapterService.getRemoteUuids(device),
@@ -356,19 +356,18 @@ public class A2dpService extends ProfileService {
                    + " : too many connected devices");
            return false;
        }
        // Check priority and accept or reject the connection.
        int priority = getPriority(device);
        // Check connectionPolicy and accept or reject the connection.
        int connectionPolicy = getConnectionPolicy(device);
        int bondState = mAdapterService.getBondState(device);
        // Allow this connection only if the device is bonded. Any attempt to connect while
        // bonding would potentially lead to an unauthorized connection.
        if (bondState != BluetoothDevice.BOND_BONDED) {
            Log.w(TAG, "okToConnect: return false, bondState=" + bondState);
            return false;
        } else if (priority != BluetoothProfile.PRIORITY_UNDEFINED
                && priority != BluetoothProfile.PRIORITY_ON
                && priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) {
            // Otherwise, reject the connection if priority is not valid.
            Log.w(TAG, "okToConnect: return false, priority=" + priority);
        } else if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_UNKNOWN
                && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            // Otherwise, reject the connection if connectionPolicy is not valid.
            Log.w(TAG, "okToConnect: return false, connectionPolicy=" + connectionPolicy);
            return false;
        }
        return true;
@@ -592,20 +591,46 @@ public class A2dpService extends ProfileService {
        }
    }

    public boolean setPriority(BluetoothDevice device, int priority) {
    /**
     * Set connection policy of the profile
     *
     * <p> The device should already be paired.
     * Connection policy can be one of:
     * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED},
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN},
     * {@link BluetoothProfile#CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy is the connection policy to set to for this profile
     * @return true if connectionPolicy is set, false on error
     * @hide
     */
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "Saved priority " + device + " = " + priority);
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        mAdapterService.getDatabase()
                .setProfilePriority(device, BluetoothProfile.A2DP, priority);
                .setProfileConnectionPolicy(device, BluetoothProfile.A2DP, connectionPolicy);
        return true;
    }

    public int getPriority(BluetoothDevice device) {
    /**
     * Get the connection policy of the profile.
     *
     * <p> The connection policy can be any of:
     * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED},
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN},
     * {@link BluetoothProfile#CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Bluetooth device
     * @return connection policy of the device
     * @hide
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        return mAdapterService.getDatabase()
                .getProfilePriority(device, BluetoothProfile.A2DP);
                .getProfileConnectionPolicy(device, BluetoothProfile.A2DP);
    }

    public boolean isAvrcpAbsoluteVolumeSupported() {
@@ -1189,21 +1214,21 @@ public class A2dpService extends ProfileService {
        }

        @Override
        public boolean setPriority(BluetoothDevice device, int priority) {
        public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
            A2dpService service = getService();
            if (service == null) {
                return false;
            }
            return service.setPriority(device, priority);
            return service.setConnectionPolicy(device, connectionPolicy);
        }

        @Override
        public int getPriority(BluetoothDevice device) {
        public int getConnectionPolicy(BluetoothDevice device) {
            A2dpService service = getService();
            if (service == null) {
                return BluetoothProfile.PRIORITY_UNDEFINED;
                return BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
            }
            return service.getPriority(device);
            return service.getConnectionPolicy(device);
        }

        @Override
+17 −16
Original line number Diff line number Diff line
@@ -171,21 +171,21 @@ public class A2dpSinkService extends ProfileService {
        }

        @Override
        public boolean setPriority(BluetoothDevice device, int priority) {
        public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
            A2dpSinkService service = getService();
            if (service == null) {
                return false;
            }
            return service.setPriority(device, priority);
            return service.setConnectionPolicy(device, connectionPolicy);
        }

        @Override
        public int getPriority(BluetoothDevice device) {
        public int getConnectionPolicy(BluetoothDevice device) {
            A2dpSinkService service = getService();
            if (service == null) {
                return BluetoothProfile.PRIORITY_UNDEFINED;
                return BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
            }
            return service.getPriority(device);
            return service.getConnectionPolicy(device);
        }

        @Override
@@ -224,8 +224,9 @@ public class A2dpSinkService extends ProfileService {
            Log.d(TAG, " connect device: " + device
                    + ", InstanceMap start state: " + sb.toString());
        }
        if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) {
            Log.w(TAG, "Connection not allowed: <" + device.getAddress() + "> is PRIORITY_OFF");
        if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            Log.w(TAG, "Connection not allowed: <" + device.getAddress()
                    + "> is CONNECTION_POLICY_FORBIDDEN");
            return false;
        }
        A2dpSinkStateMachine stateMachine = getOrCreateStateMachine(device);
@@ -312,32 +313,32 @@ public class A2dpSinkService extends ProfileService {
    }

    /**
     * Set the priority of the  profile.
     * Set the connectionPolicy of the  profile.
     *
     * @param device   the remote device
     * @param priority the priority of the profile
     * @param connectionPolicy the connectionPolicy of the profile
     * @return true on success, otherwise false
     */
    public boolean setPriority(BluetoothDevice device, int priority) {
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "Saved priority " + device + " = " + priority);
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        AdapterService.getAdapterService().getDatabase()
                .setProfilePriority(device, BluetoothProfile.A2DP_SINK, priority);
                .setProfileConnectionPolicy(device, BluetoothProfile.A2DP_SINK, connectionPolicy);
        return true;
    }

    /**
     * Get the priority of the profile.
     * Get the connection policy of the profile.
     *
     * @param device the remote device
     * @return priority of the specified device
     * @return connection policy of the specified device
     */
    public int getPriority(BluetoothDevice device) {
    public int getConnectionPolicy(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        return AdapterService.getAdapterService().getDatabase()
                .getProfilePriority(device, BluetoothProfile.A2DP_SINK);
                .getProfileConnectionPolicy(device, BluetoothProfile.A2DP_SINK);
    }


+2 −3
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.bluetooth.a2dpsink;

import static android.bluetooth.BluetoothProfile.PRIORITY_OFF;

import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAudioConfig;
import android.bluetooth.BluetoothDevice;
@@ -171,7 +169,8 @@ public class A2dpSinkStateMachine extends StateMachine {
                case StackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED:
                    switch (event.mState) {
                        case StackEvent.CONNECTION_STATE_CONNECTING:
                            if (mService.getPriority(mDevice) == PRIORITY_OFF) {
                            if (mService.getConnectionPolicy(mDevice)
                                    == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
                                Log.w(TAG, "Ignore incoming connection, profile is"
                                        + " turned off for " + mDevice);
                                mService.disconnectA2dpNative(mDeviceAddress);
+82 −60

File changed.

Preview size limit exceeded, changes collapsed.

+8 −6
Original line number Diff line number Diff line
@@ -538,22 +538,24 @@ final class BondStateMachine extends StateMachine {
        PbapClientService pbapClientService = PbapClientService.getPbapClientService();

        if (hidService != null) {
            hidService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            hidService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
        if (a2dpService != null) {
            a2dpService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            a2dpService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
        if (headsetService != null) {
            headsetService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            headsetService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
        if (headsetClientService != null) {
            headsetClientService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            headsetClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
        if (a2dpSinkService != null) {
            a2dpSinkService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            a2dpSinkService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
        if (pbapClientService != null) {
            pbapClientService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
            pbapClientService.setConnectionPolicy(device,
                    BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
        }
    }

Loading