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

Commit f64f6908 authored by timhypeng's avatar timhypeng Committed by hughchen
Browse files

remove LocalBluetoothAdapter usage

- replace LocalBluetoothAdapter with BluetoothAdapter.getDefaultAdapter() to call functions
- remove LocalBluetoothAdapter from each Bluetooth profile constructor
- no more pass LocalBluetoothAdapter to CachedBluetoothDeviceManager::addDevice()

Bug: 111815935
Test: make -j50 RunSettingsLibRoboTests
Change-Id: I2d2178c6e83034b08690d459973868a9ba583429
parent 0a83cf2c
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
    private BluetoothA2dp mService;
    private boolean mIsProfileReady;

    private final LocalBluetoothAdapter mLocalAdapter;
    private final CachedBluetoothDeviceManager mDeviceManager;

    static final ParcelUuid[] SINK_UUIDS = {
@@ -71,7 +70,7 @@ public class A2dpProfile implements LocalBluetoothProfile {
                // we may add a new device here, but generally this should not happen
                if (device == null) {
                    Log.w(TAG, "A2dpProfile found new device: " + nextDevice);
                    device = mDeviceManager.addDevice(mLocalAdapter, nextDevice);
                    device = mDeviceManager.addDevice(nextDevice);
                }
                device.onProfileStateChanged(A2dpProfile.this, BluetoothProfile.STATE_CONNECTED);
                device.refresh();
@@ -94,14 +93,12 @@ public class A2dpProfile implements LocalBluetoothProfile {
        return BluetoothProfile.A2DP;
    }

    A2dpProfile(Context context, LocalBluetoothAdapter adapter,
            CachedBluetoothDeviceManager deviceManager,
    A2dpProfile(Context context, CachedBluetoothDeviceManager deviceManager,
            LocalBluetoothProfileManager profileManager) {
        mContext = context;
        mLocalAdapter = adapter;
        mDeviceManager = deviceManager;
        mProfileManager = profileManager;
        mLocalAdapter.getProfileProxy(context, new A2dpServiceListener(),
        BluetoothAdapter.getDefaultAdapter().getProfileProxy(context, new A2dpServiceListener(),
                BluetoothProfile.A2DP);
    }

+3 −6
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ final class A2dpSinkProfile implements LocalBluetoothProfile {
    private BluetoothA2dpSink mService;
    private boolean mIsProfileReady;

    private final LocalBluetoothAdapter mLocalAdapter;
    private final CachedBluetoothDeviceManager mDeviceManager;

    static final ParcelUuid[] SRC_UUIDS = {
@@ -67,7 +66,7 @@ final class A2dpSinkProfile implements LocalBluetoothProfile {
                // we may add a new device here, but generally this should not happen
                if (device == null) {
                    Log.w(TAG, "A2dpSinkProfile found new device: " + nextDevice);
                    device = mDeviceManager.addDevice(mLocalAdapter, nextDevice);
                    device = mDeviceManager.addDevice(nextDevice);
                }
                device.onProfileStateChanged(A2dpSinkProfile.this, BluetoothProfile.STATE_CONNECTED);
                device.refresh();
@@ -90,13 +89,11 @@ final class A2dpSinkProfile implements LocalBluetoothProfile {
        return BluetoothProfile.A2DP_SINK;
    }

    A2dpSinkProfile(Context context, LocalBluetoothAdapter adapter,
            CachedBluetoothDeviceManager deviceManager,
    A2dpSinkProfile(Context context, CachedBluetoothDeviceManager deviceManager,
            LocalBluetoothProfileManager profileManager) {
        mLocalAdapter = adapter;
        mDeviceManager = deviceManager;
        mProfileManager = profileManager;
        mLocalAdapter.getProfileProxy(context, new A2dpSinkServiceListener(),
        BluetoothAdapter.getDefaultAdapter().getProfileProxy(context, new A2dpSinkServiceListener(),
                BluetoothProfile.A2DP_SINK);
    }

+3 −4
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ public class BluetoothEventManager {
        for (BluetoothDevice device : bondedDevices) {
            CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
            if (cachedDevice == null) {
                cachedDevice = mDeviceManager.addDevice(mLocalAdapter, device);
                cachedDevice = mDeviceManager.addDevice(device);
                dispatchDeviceAdded(cachedDevice);
                deviceAdded = true;
            }
@@ -282,7 +282,7 @@ public class BluetoothEventManager {
            // Skip for now, there's a bluez problem and we are not getting uuids even for 2.1.
            CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
            if (cachedDevice == null) {
                cachedDevice = mDeviceManager.addDevice(mLocalAdapter, device);
                cachedDevice = mDeviceManager.addDevice(device);
                Log.d(TAG, "DeviceFoundHandler created new CachedBluetoothDevice: "
                        + cachedDevice);
            }
@@ -348,8 +348,7 @@ public class BluetoothEventManager {
                if (cachedDevice == null) {
                    Log.w(TAG, "Got bonding state changed for " + device +
                            ", but we have no record of that device.");

                    cachedDevice = mDeviceManager.addDevice(mLocalAdapter, device);
                    cachedDevice = mDeviceManager.addDevice(device);
                    dispatchDeviceAdded(cachedDevice);
                }
            }
+3 −4
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    private static final String TAG = "CachedBluetoothDevice";

    private final Context mContext;
    private final LocalBluetoothAdapter mLocalAdapter;
    private final BluetoothAdapter mLocalAdapter;
    private final LocalBluetoothProfileManager mProfileManager;
    private final BluetoothDevice mDevice;
    //TODO: consider remove, BluetoothDevice.getName() is already cached
@@ -143,7 +143,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            Log.d(TAG, "onProfileStateChanged: profile " + profile +
                    " newProfileState " + newProfileState);
        }
        if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF)
        if (mLocalAdapter.getState() == BluetoothAdapter.STATE_TURNING_OFF)
        {
            if (BluetoothUtils.D) {
                Log.d(TAG, " BT Turninig Off...Profile conn state change ignored...");
@@ -179,11 +179,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    }

    CachedBluetoothDevice(Context context,
                          LocalBluetoothAdapter adapter,
                          LocalBluetoothProfileManager profileManager,
                          BluetoothDevice device) {
        mContext = context;
        mLocalAdapter = adapter;
        mLocalAdapter = BluetoothAdapter.getDefaultAdapter();
        mProfileManager = profileManager;
        mDevice = device;
        mProfileConnectionState = new HashMap<LocalBluetoothProfile, Integer>();
+3 −3
Original line number Diff line number Diff line
@@ -107,10 +107,10 @@ public class CachedBluetoothDeviceManager {
     * @param device the address of the new Bluetooth device
     * @return the newly created CachedBluetoothDevice object
     */
    public CachedBluetoothDevice addDevice(LocalBluetoothAdapter adapter, BluetoothDevice device) {
    public CachedBluetoothDevice addDevice(BluetoothDevice device) {
        LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
        CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, adapter,
            profileManager, device);
        CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, profileManager,
                device);
        if (profileManager.getHearingAidProfile() != null
            && profileManager.getHearingAidProfile().getHiSyncId(newDevice.getDevice())
                != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
Loading