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

Commit 84706aba authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8847022 from f5610efd to tm-qpr1-release

Change-Id: Id8a8d548b2e82b4a3de081b4607cb227ecb30f1d
parents 20fd7714 f5610efd
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.util.Log;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;

@@ -62,6 +63,7 @@ public class BatteryService extends ProfileService {
    private static BatteryService sBatteryService;

    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private final Map<BluetoothDevice, BatteryStateMachine> mStateMachines = new HashMap<>();

@@ -94,6 +96,8 @@ public class BatteryService extends ProfileService {

        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when BatteryService starts");
        mDatabaseManager = Objects.requireNonNull(mAdapterService.getDatabase(),
                "DatabaseManager cannot be null when BatteryService starts");

        mStateMachines.clear();
        mStateMachinesThread = new HandlerThread("BatteryService.StateMachines");
@@ -395,8 +399,7 @@ public class BatteryService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        mAdapterService.getDatabase()
                .setProfileConnectionPolicy(device, BluetoothProfile.BATTERY,
        mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.BATTERY,
                        connectionPolicy);
        if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            connect(device);
@@ -413,8 +416,7 @@ public class BatteryService extends ProfileService {
    public int getConnectionPolicy(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        return mAdapterService.getDatabase()
                .getProfileConnectionPolicy(device, BluetoothProfile.BATTERY);
        return mDatabaseManager.getProfileConnectionPolicy(device, BluetoothProfile.BATTERY);
    }
    /**
     * Called when the battery level of the device is notified.
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.bass_client;

import static android.Manifest.permission.BLUETOOTH_CONNECT;

import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.bluetooth.BluetoothAdapter;
@@ -47,6 +48,7 @@ import android.util.Log;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.internal.annotations.VisibleForTesting;

import java.nio.ByteBuffer;
@@ -74,6 +76,7 @@ public class BassClientService extends ProfileService {
    private HandlerThread mStateMachinesThread;
    private HandlerThread mCallbackHandlerThread;
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private BluetoothAdapter mBluetoothAdapter = null;
    private BassUtils mBassUtils = null;
    private Map<BluetoothDevice, BluetoothDevice> mActiveSourceMap;
@@ -218,6 +221,8 @@ public class BassClientService extends ProfileService {
        }
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when BassClientService starts");
        mDatabaseManager = Objects.requireNonNull(mAdapterService.getDatabase(),
                "DatabaseManager cannot be null when BassClientService starts");
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mStateMachines.clear();
        mStateMachinesThread = new HandlerThread("BassClientService.StateMachines");
@@ -545,7 +550,7 @@ public class BassClientService extends ProfileService {
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        boolean setSuccessfully =
                mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                mDatabaseManager.setProfileConnectionPolicy(device,
                        BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT, connectionPolicy);
        if (setSuccessfully && connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            connect(device);
@@ -568,8 +573,7 @@ public class BassClientService extends ProfileService {
     * @return connection policy of the device
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        return mAdapterService
                .getDatabase()
        return mDatabaseManager
                .getProfileConnectionPolicy(device, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT);
    }

+54 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.Parcelable;
import android.os.SystemProperties;
import android.util.Log;

import com.android.bluetooth.R;
@@ -95,6 +96,9 @@ class PhonePolicy {
    private static final int MESSAGE_PROFILE_ACTIVE_DEVICE_CHANGED = 5;
    private static final int MESSAGE_DEVICE_CONNECTED = 6;

    private static final String PREFER_LE_AUDIO_ONLY_MODE =
            "persist.bluetooth.prefer_le_audio_only_mode";

    // Timeouts
    @VisibleForTesting static int sConnectOtherProfilesTimeoutMillis = 6000; // 6s

@@ -106,6 +110,8 @@ class PhonePolicy {
    private final HashSet<BluetoothDevice> mA2dpRetrySet = new HashSet<>();
    private final HashSet<BluetoothDevice> mConnectOtherProfilesDeviceSet = new HashSet<>();

    private Boolean mPreferLeAudioOnlyMode = false;

    // Broadcast receiver for all changes to states of various profiles
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
@@ -284,6 +290,7 @@ class PhonePolicy {
                "DatabaseManager cannot be null when PhonePolicy starts");
        mFactory = factory;
        mHandler = new PhonePolicyHandler(service.getMainLooper());
        mPreferLeAudioOnlyMode = SystemProperties.getBoolean(PREFER_LE_AUDIO_ONLY_MODE, true);
    }

    // Policy implementation, all functions MUST be private
@@ -354,6 +361,24 @@ class PhonePolicy {
            debugLog("setting le audio profile priority for device " + device);
            mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                    BluetoothProfile.LE_AUDIO, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
            if (mPreferLeAudioOnlyMode) {
                if (mAdapterService.getDatabase()
                        .getProfileConnectionPolicy(device, BluetoothProfile.A2DP)
                        >  BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
                    debugLog("clear a2dp profile priority for the le audio dual mode device "
                            + device);
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                            BluetoothProfile.A2DP, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                }
                if (mAdapterService.getDatabase()
                        .getProfileConnectionPolicy(device, BluetoothProfile.HEADSET)
                        >  BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
                    debugLog("clear hfp profile priority for the le audio dual mode device "
                            + device);
                    mAdapterService.getDatabase().setProfileConnectionPolicy(device,
                            BluetoothProfile.HEADSET, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                }
            }
        }

        if ((hearingAidService != null) && Utils.arrayContains(uuids,
@@ -430,15 +455,42 @@ class PhonePolicy {

    /**
     * Updates the last connection date in the connection order database for the newly active device
     * if connected to a2dp profile
     * if connected to a2dp profile. If the device is LE audio dual mode device, and
     * mPreferLeAudioOnlyMode be true, A2DP/HFP will be disconnected as LE audio become active one
     * after pairing.
     *
     * @param device is the device we just made the active device
     */
    private void processActiveDeviceChanged(BluetoothDevice device, int profileId) {
        debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId);
        debugLog("processActiveDeviceChanged, device=" + device + ", profile=" + profileId
                + " mPreferLeAudioOnlyMode: " + mPreferLeAudioOnlyMode);

        if (device != null) {
            mDatabaseManager.setConnection(device, profileId == BluetoothProfile.A2DP);

            if (!mPreferLeAudioOnlyMode) return;
            if (profileId == BluetoothProfile.LE_AUDIO) {
                HeadsetService hsService = mFactory.getHeadsetService();
                if (hsService != null) {
                    if ((hsService.getConnectionPolicy(device)
                            != BluetoothProfile.CONNECTION_POLICY_ALLOWED)
                            && (hsService.getConnectionState(device)
                            == BluetoothProfile.STATE_CONNECTED)) {
                        debugLog("Disconnect HFP for the LE audio dual mode device " + device);
                        hsService.disconnect(device);
                    }
                }
                A2dpService a2dpService = mFactory.getA2dpService();
                if (a2dpService != null) {
                    if ((a2dpService.getConnectionPolicy(device)
                            != BluetoothProfile.CONNECTION_POLICY_ALLOWED)
                            && (a2dpService.getConnectionState(device)
                            == BluetoothProfile.STATE_CONNECTED)) {
                        debugLog("Disconnect A2DP for the LE audio dual mode device " + device);
                        a2dpService.disconnect(device);
                    }
                }
            }
        }
    }

+7 −3
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.util.Pair;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;

@@ -76,6 +77,7 @@ public class CsipSetCoordinatorService extends ProfileService {
    private static CsipSetCoordinatorService sCsipSetCoordinatorService;

    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private BluetoothDevice mPreviousAudioDevice;

@@ -121,10 +123,12 @@ public class CsipSetCoordinatorService extends ProfileService {
            throw new IllegalStateException("start() called twice");
        }

        // Get AdapterService, CsipSetCoordinatorNativeInterface.
        // Get AdapterService, DatabaseManager, CsipSetCoordinatorNativeInterface.
        // None of them can be null.
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when CsipSetCoordinatorService starts");
        mDatabaseManager = Objects.requireNonNull(mAdapterService.getDatabase(),
                "DatabaseManager cannot be null when CsipSetCoordinatorService starts");
        mCsipSetCoordinatorNativeInterface = Objects.requireNonNull(
                CsipSetCoordinatorNativeInterface.getInstance(),
                "CsipSetCoordinatorNativeInterface cannot be null when"
@@ -461,7 +465,7 @@ public class CsipSetCoordinatorService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        mAdapterService.getDatabase().setProfileConnectionPolicy(
        mDatabaseManager.setProfileConnectionPolicy(
                device, BluetoothProfile.CSIP_SET_COORDINATOR, connectionPolicy);
        if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            connect(device);
@@ -479,7 +483,7 @@ public class CsipSetCoordinatorService extends ProfileService {
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission");
        return mAdapterService.getDatabase().getProfileConnectionPolicy(
        return mDatabaseManager.getProfileConnectionPolicy(
                device, BluetoothProfile.CSIP_SET_COORDINATOR);
    }

+7 −5
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;
@@ -79,6 +80,7 @@ public class HapClientService extends ProfileService {
    @VisibleForTesting
    HapClientNativeInterface mHapClientNativeInterface;
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mConnectionStateChangedReceiver;
@@ -151,10 +153,12 @@ public class HapClientService extends ProfileService {
            throw new IllegalStateException("start() called twice");
        }

        // Get AdapterService, HapClientNativeInterface, AudioManager.
        // Get AdapterService, HapClientNativeInterface, DatabaseManager, AudioManager.
        // None of them can be null.
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when HapClientService starts");
        mDatabaseManager = Objects.requireNonNull(mAdapterService.getDatabase(),
                "DatabaseManager cannot be null when HapClientService starts");
        mHapClientNativeInterface = Objects.requireNonNull(
                HapClientNativeInterface.getInstance(),
                "HapClientNativeInterface cannot be null when HapClientService starts");
@@ -368,8 +372,7 @@ public class HapClientService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        mAdapterService.getDatabase()
                .setProfileConnectionPolicy(device, BluetoothProfile.HAP_CLIENT,
        mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.HAP_CLIENT,
                        connectionPolicy);
        if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            connect(device);
@@ -392,8 +395,7 @@ public class HapClientService extends ProfileService {
     * @hide
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        return mAdapterService.getDatabase()
                .getProfileConnectionPolicy(device, BluetoothProfile.HAP_CLIENT);
        return mDatabaseManager.getProfileConnectionPolicy(device, BluetoothProfile.HAP_CLIENT);
    }

    /**
Loading