Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +8 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ public class BluetoothUtils { private static final String TEMP_BOND_TYPE = "TEMP_BOND_TYPE"; private static final String TEMP_BOND_DEVICE_METADATA_VALUE = "le_audio_sharing"; private static final String BLUETOOTH_DIAGNOSIS_KEY = "cs_bt_diagnostics_enabled"; private static ErrorListener sErrorListener; Loading Loading @@ -1411,4 +1412,11 @@ public class BluetoothUtils { return !assistantProfile.getAllConnectedDevices().isEmpty(); } /** Checks if Bluetooth Diagnosis is available by reading from Settings Secure. */ public static boolean isBluetoothDiagnosisAvailable(@NonNull Context context) { return Flags.enableBluetoothDiagnosis() && Settings.Secure.getInt(context.getContentResolver(), BLUETOOTH_DIAGNOSIS_KEY, -1) > 0; } } packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +15 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> */ private long mConnectAttempted = -1; private long mBondFailureTimeMillis = -1; private long mConnectionFailureTimeMillis = -1; private boolean mIsAclConnectedBrEdr = false; private boolean mIsAclConnectedLe = false; Loading Loading @@ -364,6 +365,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> HearingAidStatsLogUtils.updateHistoryIfNeeded(mContext, this, profile, newProfileState); } if (Flags.enableBluetoothDiagnosis() && !isBusy()) { if (isProfileConnectedFail()) { mConnectionFailureTimeMillis = SystemClock.elapsedRealtime(); dispatchAttributesChanged(); } else if (mConnectionFailureTimeMillis > -1) { mConnectionFailureTimeMillis = -1; dispatchAttributesChanged(); } } fetchActiveDevices(); } Loading Loading @@ -1211,6 +1222,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> return mBondFailureTimeMillis; } public long getConnectionFailureTimeMillis() { return mConnectionFailureTimeMillis; } public BluetoothClass getBtClass() { return mDevice.getBluetoothClass(); } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settingslib.bluetooth; import static com.android.settingslib.bluetooth.BluetoothUtils.getInputDevice; import static com.android.settingslib.bluetooth.BluetoothUtils.getSelectedChannelIndex; import static com.android.settingslib.bluetooth.BluetoothUtils.isAvailableAudioSharingMediaBluetoothDevice; import static com.android.settingslib.bluetooth.BluetoothUtils.isBluetoothDiagnosisAvailable; import static com.android.settingslib.bluetooth.BluetoothUtils.isDeviceStylus; import static com.android.settingslib.bluetooth.BluetoothUtils.modifySelectedChannelIndex; import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.UNKNOWN_VALUE_PLACEHOLDER; Loading Loading @@ -139,6 +140,9 @@ public class BluetoothUtilsTest { private static final String TEST_EXCLUSIVE_MANAGER_PACKAGE = "com.test.manager"; private static final String TEST_EXCLUSIVE_MANAGER_COMPONENT = "com.test.manager/.component"; private static final String TEST_ADDRESS = "11:22:33:44:55:66"; private static final String BLUETOOTH_DIAGNOSIS_KEY = "cs_bt_diagnostics_enabled"; private static final int TEST_BROADCAST_ID = 25; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); Loading Loading @@ -1767,6 +1771,20 @@ public class BluetoothUtilsTest { assertThat(isAssistantConnected).isTrue(); } @Test @EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void isBluetoothDiagnosisAvailable_featureIsEnabled_returnTrue() { Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_DIAGNOSIS_KEY, 1); assertThat(isBluetoothDiagnosisAvailable(mContext)).isTrue(); } @Test @EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void isBluetoothDiagnosisAvailable_featureIsNotEnabled_returnFalse() { assertThat(isBluetoothDiagnosisAvailable(mContext)).isFalse(); } private BluetoothLeBroadcastMetadata createMetadataWithChannels( BluetoothLeBroadcastChannel... channels) { BluetoothLeBroadcastMetadata mockMetadata = mock(BluetoothLeBroadcastMetadata.class); Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,53 @@ public class CachedBluetoothDeviceTest { BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_specialProfileFailure_setConnectionFailureTime() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mA2dpProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mA2dpProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isGreaterThan(-1); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_normalProfileConnectionFailure_doNotSetConnectionFailureTime() { when(mPanProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mPanProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mPanProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isEqualTo(-1); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_profileConnectionSuccess_resetConnectionFailureTime() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mA2dpProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mA2dpProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isGreaterThan(-1); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isEqualTo(-1); } @Test public void getConnectionSummary_testProfilesInactive_returnPairing() { // Arrange: Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +8 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ public class BluetoothUtils { private static final String TEMP_BOND_TYPE = "TEMP_BOND_TYPE"; private static final String TEMP_BOND_DEVICE_METADATA_VALUE = "le_audio_sharing"; private static final String BLUETOOTH_DIAGNOSIS_KEY = "cs_bt_diagnostics_enabled"; private static ErrorListener sErrorListener; Loading Loading @@ -1411,4 +1412,11 @@ public class BluetoothUtils { return !assistantProfile.getAllConnectedDevices().isEmpty(); } /** Checks if Bluetooth Diagnosis is available by reading from Settings Secure. */ public static boolean isBluetoothDiagnosisAvailable(@NonNull Context context) { return Flags.enableBluetoothDiagnosis() && Settings.Secure.getInt(context.getContentResolver(), BLUETOOTH_DIAGNOSIS_KEY, -1) > 0; } }
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +15 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> */ private long mConnectAttempted = -1; private long mBondFailureTimeMillis = -1; private long mConnectionFailureTimeMillis = -1; private boolean mIsAclConnectedBrEdr = false; private boolean mIsAclConnectedLe = false; Loading Loading @@ -364,6 +365,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> HearingAidStatsLogUtils.updateHistoryIfNeeded(mContext, this, profile, newProfileState); } if (Flags.enableBluetoothDiagnosis() && !isBusy()) { if (isProfileConnectedFail()) { mConnectionFailureTimeMillis = SystemClock.elapsedRealtime(); dispatchAttributesChanged(); } else if (mConnectionFailureTimeMillis > -1) { mConnectionFailureTimeMillis = -1; dispatchAttributesChanged(); } } fetchActiveDevices(); } Loading Loading @@ -1211,6 +1222,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> return mBondFailureTimeMillis; } public long getConnectionFailureTimeMillis() { return mConnectionFailureTimeMillis; } public BluetoothClass getBtClass() { return mDevice.getBluetoothClass(); } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settingslib.bluetooth; import static com.android.settingslib.bluetooth.BluetoothUtils.getInputDevice; import static com.android.settingslib.bluetooth.BluetoothUtils.getSelectedChannelIndex; import static com.android.settingslib.bluetooth.BluetoothUtils.isAvailableAudioSharingMediaBluetoothDevice; import static com.android.settingslib.bluetooth.BluetoothUtils.isBluetoothDiagnosisAvailable; import static com.android.settingslib.bluetooth.BluetoothUtils.isDeviceStylus; import static com.android.settingslib.bluetooth.BluetoothUtils.modifySelectedChannelIndex; import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.UNKNOWN_VALUE_PLACEHOLDER; Loading Loading @@ -139,6 +140,9 @@ public class BluetoothUtilsTest { private static final String TEST_EXCLUSIVE_MANAGER_PACKAGE = "com.test.manager"; private static final String TEST_EXCLUSIVE_MANAGER_COMPONENT = "com.test.manager/.component"; private static final String TEST_ADDRESS = "11:22:33:44:55:66"; private static final String BLUETOOTH_DIAGNOSIS_KEY = "cs_bt_diagnostics_enabled"; private static final int TEST_BROADCAST_ID = 25; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); Loading Loading @@ -1767,6 +1771,20 @@ public class BluetoothUtilsTest { assertThat(isAssistantConnected).isTrue(); } @Test @EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void isBluetoothDiagnosisAvailable_featureIsEnabled_returnTrue() { Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_DIAGNOSIS_KEY, 1); assertThat(isBluetoothDiagnosisAvailable(mContext)).isTrue(); } @Test @EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void isBluetoothDiagnosisAvailable_featureIsNotEnabled_returnFalse() { assertThat(isBluetoothDiagnosisAvailable(mContext)).isFalse(); } private BluetoothLeBroadcastMetadata createMetadataWithChannels( BluetoothLeBroadcastChannel... channels) { BluetoothLeBroadcastMetadata mockMetadata = mock(BluetoothLeBroadcastMetadata.class); Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,53 @@ public class CachedBluetoothDeviceTest { BluetoothProfile.CONNECTION_POLICY_UNKNOWN, null); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_specialProfileFailure_setConnectionFailureTime() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mA2dpProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mA2dpProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isGreaterThan(-1); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_normalProfileConnectionFailure_doNotSetConnectionFailureTime() { when(mPanProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mPanProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mPanProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isEqualTo(-1); } @Test @EnableFlags(FLAG_ENABLE_BLUETOOTH_DIAGNOSIS) public void onProfileStateChanged_profileConnectionSuccess_resetConnectionFailureTime() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mA2dpProfile.getConnectionPolicy(mDevice)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mA2dpProfile.isEnabled(mDevice)).thenReturn(true); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isGreaterThan(-1); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.getConnectionFailureTimeMillis()).isEqualTo(-1); } @Test public void getConnectionSummary_testProfilesInactive_returnPairing() { // Arrange: Loading