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

Commit 1751eaa5 authored by jackqdyulei's avatar jackqdyulei
Browse files

Clean up CachedBluetoothDevice

1. Resort methods and fields a little bit
2. Remove unused code

Bug: 112517004
Test: Build
Change-Id: If0d581c6130c6b72d0940be95da9a8e06d7e9630
parent 4dc09a4b
Loading
Loading
Loading
Loading
+29 −37
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

import com.android.settingslib.R;

import java.util.ArrayList;
@@ -39,6 +37,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import androidx.annotation.VisibleForTesting;

/**
 * CachedBluetoothDevice represents a remote Bluetooth device. It contains
 * attributes of the device (such as the address, name, RSSI, etc.) and
@@ -48,6 +48,10 @@ import java.util.List;
public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
    private static final String TAG = "CachedBluetoothDevice";

    // See mConnectAttempted
    private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
    private static final long MAX_HOGP_DELAY_FOR_AUTO_CONNECT = 30000;

    private final Context mContext;
    private final BluetoothAdapter mLocalAdapter;
    private final LocalBluetoothProfileManager mProfileManager;
@@ -78,17 +82,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>

    private final static String MESSAGE_REJECTION_COUNT_PREFS_NAME = "bluetooth_message_reject";

    public long getHiSyncId() {
        return mHiSyncId;
    }

    public void setHiSyncId(long id) {
        if (BluetoothUtils.D) {
            Log.d(TAG, "setHiSyncId: mDevice " + mDevice + ", id " + id);
        }
        mHiSyncId = id;
    }

    /**
     * Last time a bt profile auto-connect was attempted.
     * If an ACTION_UUID intent comes in within
@@ -97,14 +90,22 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     */
    private long mConnectAttempted;

    // See mConnectAttempted
    private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
    private static final long MAX_HOGP_DELAY_FOR_AUTO_CONNECT = 30000;

    // Active device state
    private boolean mIsActiveDeviceA2dp = false;
    private boolean mIsActiveDeviceHeadset = false;
    private boolean mIsActiveDeviceHearingAid = false;

    CachedBluetoothDevice(Context context, LocalBluetoothProfileManager profileManager,
            BluetoothDevice device) {
        mContext = context;
        mLocalAdapter = BluetoothAdapter.getDefaultAdapter();
        mProfileManager = profileManager;
        mDevice = device;
        mProfileConnectionState = new HashMap<>();
        fillData();
        mHiSyncId = BluetoothHearingAid.HI_SYNC_ID_INVALID;
    }

    /**
     * Describes the current device and profile for logging.
     *
@@ -161,18 +162,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        fetchActiveDevices();
    }

    CachedBluetoothDevice(Context context,
                          LocalBluetoothProfileManager profileManager,
                          BluetoothDevice device) {
        mContext = context;
        mLocalAdapter = BluetoothAdapter.getDefaultAdapter();
        mProfileManager = profileManager;
        mDevice = device;
        mProfileConnectionState = new HashMap<LocalBluetoothProfile, Integer>();
        fillData();
        mHiSyncId = BluetoothHearingAid.HI_SYNC_ID_INVALID;
    }

    public void disconnect() {
        for (LocalBluetoothProfile profile : mProfiles) {
            disconnect(profile);
@@ -204,6 +193,17 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        connectWithoutResettingTimer(connectAllProfiles);
    }

    public long getHiSyncId() {
        return mHiSyncId;
    }

    public void setHiSyncId(long id) {
        if (BluetoothUtils.D) {
            Log.d(TAG, "setHiSyncId: mDevice " + mDevice + ", id " + id);
        }
        mHiSyncId = id;
    }

    void onBondingDockConnect() {
        // Attempt to connect if UUIDs are available. Otherwise,
        // we will connect when the ACTION_UUID intent arrives.
@@ -300,14 +300,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        return true;
    }

    /**
     * Return true if user initiated pairing on this device. The message text is
     * slightly different for local vs. remote initiated pairing dialogs.
     */
    boolean isUserInitiatedPairing() {
        return mDevice.isBondingInitiatedLocally();
    }

    public void unpair() {
        int state = getBondState();