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

Commit 91640c0b authored by Ze Li's avatar Ze Li Committed by Android (Google) Code Review
Browse files

Merge "[Bluetooth Diagnosis] Mark the timestamp of pairing failure" into main

parents 433d2a92 113e106a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -424,7 +424,9 @@ public class BluetoothEventManager {
            for (BluetoothCallback callback : mCallbacks) {
                callback.onDeviceBondStateChanged(cachedDevice, bondState);
            }
            cachedDevice.onBondingStateChanged(bondState);
            int prevBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE,
                    BluetoothDevice.ERROR);
            cachedDevice.onBondingStateChanged(bondState, prevBondState);

            if (bondState == BluetoothDevice.BOND_NONE) {
                // Check if we need to remove other Coordinated set member devices / Hearing Aid
+23 −2
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     * The value is reset if a disconnection happens.
     */
    private long mConnectAttempted = -1;
    private long mBondFailureTimeMillis = -1;
    private boolean mIsAclConnectedBrEdr = false;
    private boolean mIsAclConnectedLe = false;

@@ -1105,7 +1106,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        dispatchAttributesChanged();
    }

    void onBondingStateChanged(int bondState) {
    void onBondingStateChanged(int bondState, int prevBondState) {
        if (bondState == BluetoothDevice.BOND_NONE) {
            synchronized (mProfileLock) {
                mProfiles.clear();
@@ -1115,9 +1116,17 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            mDevice.setSimAccessPermission(BluetoothDevice.ACCESS_UNKNOWN);

            mBondTimestamp = null;

            if (Flags.enableBluetoothDiagnosis()) {
                if (prevBondState == BluetoothDevice.BOND_BONDING) {
                    mBondFailureTimeMillis = SystemClock.elapsedRealtime();
                }
            }
        }

        if (!Flags.enableBluetoothDiagnosis()) {
            refresh();
        }

        if (bondState == BluetoothDevice.BOND_BONDED) {
            mBondTimestamp = new Timestamp(System.currentTimeMillis());
@@ -1129,6 +1138,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            // Saves this device as just bonded and checks if it's an hearing device after
            // profiles are connected. This is for judging whether to display the survey.
            HearingAidStatsLogUtils.addToJustBonded(getAddress());

            if (Flags.enableBluetoothDiagnosis()) {
                mBondFailureTimeMillis = -1;
            }
        }

        if (Flags.enableBluetoothDiagnosis()) {
            refresh();
        }
    }

@@ -1188,6 +1205,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        return mBondTimestamp;
    }

    public long getBondFailureTimeMillis() {
        return mBondFailureTimeMillis;
    }

    public BluetoothClass getBtClass() {
        return mDevice.getBluetoothClass();
    }
+26 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.settingslib.bluetooth;

import static com.android.settingslib.flags.Flags.FLAG_ENABLE_BLUETOOTH_DIAGNOSIS;
import static com.android.settingslib.flags.Flags.FLAG_ENABLE_LE_AUDIO_SHARING;
import static com.android.settingslib.flags.Flags.FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY;

@@ -2942,6 +2943,31 @@ public class CachedBluetoothDeviceTest {
        assertThat(summary).isNull();
    }

    @Test
    @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS)
    public void onBondingStateChanged_bondFailure_setFailureTime() {
        mCachedDevice.onBondingStateChanged(
                BluetoothDevice.BOND_NONE, BluetoothDevice.BOND_BONDING);

        assertThat(mCachedDevice.getBondFailureTimeMillis()).isNotEqualTo(-1);
    }

    @Test
    @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS)
    public void onBondingStateChanged_bondSuccess_resetFailureTime() {
        mCachedDevice.onBondingStateChanged(
                BluetoothDevice.BOND_NONE, BluetoothDevice.BOND_BONDING);

        assertThat(mCachedDevice.getBondFailureTimeMillis()).isNotEqualTo(-1);

        mCachedDevice.onBondingStateChanged(
                BluetoothDevice.BOND_BONDING, BluetoothDevice.BOND_NONE);
        mCachedDevice.onBondingStateChanged(
                BluetoothDevice.BOND_BONDED, BluetoothDevice.BOND_BONDING);

        assertThat(mCachedDevice.getBondFailureTimeMillis()).isEqualTo(-1);
    }

    private void updateProfileStatus(LocalBluetoothProfile profile, int status) {
        doReturn(status).when(profile).getConnectionStatus(mDevice);
        mCachedDevice.onProfileStateChanged(profile, status);