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

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

Merge "[Bluetooth Diagnosis] Set special summary and icon for devices that...

Merge "[Bluetooth Diagnosis] Set special summary and icon for devices that have connection or pairing failure." into main
parents 17d66ea0 64d7c4c1
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2025 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24"
    android:viewportWidth="24">
    <group>
        <clip-path android:pathData="M12,0L12,0A12,12 0,0 1,24 12L24,12A12,12 0,0 1,12 24L12,24A12,12 0,0 1,0 12L0,12A12,12 0,0 1,12 0z" />
        <path
            android:fillColor="#FCBD00"
            android:pathData="M2.008,19.975L12,3.017L21.992,19.975H2.008ZM12,17.225C12.244,17.225 12.451,17.141 12.619,16.973C12.787,16.805 12.871,16.599 12.871,16.354C12.871,16.11 12.787,15.903 12.619,15.735C12.451,15.567 12.244,15.483 12,15.483C11.756,15.483 11.549,15.567 11.381,15.735C11.213,15.903 11.129,16.11 11.129,16.354C11.129,16.599 11.213,16.805 11.381,16.973C11.549,17.141 11.756,17.225 12,17.225ZM11.129,14.475H12.871V9.983H11.129V14.475Z" />
    </group>
</vector>
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -179,6 +179,10 @@
    <string name="bluetooth_connected">Connected<xliff:g id="active_device">%1$s</xliff:g></string>
    <!--Bluetooth settings screen, summary text under individual Bluetooth devices when pairing -->
    <string name="bluetooth_pairing">Pairing\u2026</string>
    <!-- Bluetooth settings. Message when the device having a pairing failure. [CHAR LIMIT=40] -->
    <string name="bluetooth_pairing_failure">Can\'t pair</string>
    <!-- Bluetooth settings. Message when the device having a connection failure. [CHAR LIMIT=40] -->
    <string name="bluetooth_connection_failure">Can\'t connect</string>

    <!-- Bluetooth settings.  Message when connected to a device, except for phone audio. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_headset">Connected (no phone)<xliff:g id="active_device">%1$s</xliff:g></string>
+18 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.SystemClock;
import android.provider.DeviceConfig;
import android.provider.MediaStore;
import android.provider.Settings;
@@ -94,6 +95,9 @@ public class BluetoothUtils {
    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 final int CAN_NOT_PAIR_TIME_OUT_MILLS = 60000;
    private static final int CAN_NOT_CONNECT_TIME_OUT_MILLS = 60000;

    private static ErrorListener sErrorListener;

    public static int getConnectionStateSummary(int connectionState) {
@@ -1419,4 +1423,18 @@ public class BluetoothUtils {
                && Settings.Secure.getInt(context.getContentResolver(), BLUETOOTH_DIAGNOSIS_KEY, -1)
                        > 0;
    }

    /** Checks if the device should show as pairing failure. */
    public static boolean showPairingFailure(@NonNull CachedBluetoothDevice device) {
        return device.getBondFailureTimeMillis() > 0
                && SystemClock.elapsedRealtime() - device.getBondFailureTimeMillis()
                        <= CAN_NOT_PAIR_TIME_OUT_MILLS;
    }

    /** Checks if the device should show as connection failure. */
    public static boolean showConnectionFailure(@NonNull CachedBluetoothDevice device) {
        return device.getConnectionFailureTimeMillis() > 0
                && SystemClock.elapsedRealtime() - device.getConnectionFailureTimeMillis()
                        <= CAN_NOT_CONNECT_TIME_OUT_MILLS;
    }
}
+51 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static com.android.settingslib.bluetooth.BluetoothUtils.isAvailableAudioS
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.BluetoothUtils.showConnectionFailure;
import static com.android.settingslib.bluetooth.BluetoothUtils.showPairingFailure;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.UNKNOWN_VALUE_PLACEHOLDER;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.UNKNOWN_CHANNEL;
import static com.android.settingslib.flags.Flags.FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA;
@@ -65,6 +67,7 @@ import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.SystemClock;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -1785,6 +1788,54 @@ public class BluetoothUtilsTest {
        assertThat(isBluetoothDiagnosisAvailable(mContext)).isFalse();
    }

    @Test
    public void showPairingFailure_failureWithinTimeout_returnTrue() {
        when(mCachedBluetoothDevice.getBondFailureTimeMillis()).thenReturn(10000L);
        SystemClock.setCurrentTimeMillis(20000L);

        assertThat(showPairingFailure(mCachedBluetoothDevice)).isTrue();
    }

    @Test
    public void showPairingFailure_noFailure_returnFalse() {
        when(mCachedBluetoothDevice.getBondFailureTimeMillis()).thenReturn(-1L);
        SystemClock.setCurrentTimeMillis(20000L);

        assertThat(showPairingFailure(mCachedBluetoothDevice)).isFalse();
    }

    @Test
    public void showPairingFailure_failureOutOfTimeout_returnFalse() {
        when(mCachedBluetoothDevice.getBondFailureTimeMillis()).thenReturn(10000L);
        SystemClock.setCurrentTimeMillis(80000L);

        assertThat(showPairingFailure(mCachedBluetoothDevice)).isFalse();
    }

    @Test
    public void showConnectionFailure_failureOutOfTimeout_returnFalse() {
        when(mCachedBluetoothDevice.getConnectionFailureTimeMillis()).thenReturn(10000L);
        SystemClock.setCurrentTimeMillis(80000L);

        assertThat(showConnectionFailure(mCachedBluetoothDevice)).isFalse();
    }

    @Test
    public void showConnectionFailure_failureWithinTimeout_returnTrue() {
        when(mCachedBluetoothDevice.getConnectionFailureTimeMillis()).thenReturn(10000L);
        SystemClock.setCurrentTimeMillis(20000L);

        assertThat(showConnectionFailure(mCachedBluetoothDevice)).isTrue();
    }

    @Test
    public void showConnectionFailure_noFailure_returnFalse() {
        when(mCachedBluetoothDevice.getConnectionFailureTimeMillis()).thenReturn(-1L);
        SystemClock.setCurrentTimeMillis(20000L);

        assertThat(showConnectionFailure(mCachedBluetoothDevice)).isFalse();
    }

    private BluetoothLeBroadcastMetadata createMetadataWithChannels(
            BluetoothLeBroadcastChannel... channels) {
        BluetoothLeBroadcastMetadata mockMetadata = mock(BluetoothLeBroadcastMetadata.class);