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

Commit dd2eed59 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

Avoid showing "Problem connecting" for Android Auto

Flag: com.android.settingslib.flags.ignore_a2dp_disconnection_for_android_auto
Bug: 381981752
Test: compile
Change-Id: Ia836d64c595e4f30e9c54f010093dd73189a16ea
parent afe6b0af
Loading
Loading
Loading
Loading
+35 −12
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settingslib.bluetooth;

import static com.android.settingslib.flags.Flags.enableSetPreferredTransportForLeAudioDevice;
import static com.android.settingslib.flags.Flags.ignoreA2dpDisconnectionForAndroidAuto;

import android.annotation.CallbackExecutor;
import android.annotation.StringRes;
@@ -82,6 +83,8 @@ import java.util.stream.Stream;
 */
public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
    private static final String TAG = "CachedBluetoothDevice";
    private static final ParcelUuid ANDROID_AUTO_UUID =
            ParcelUuid.fromString("4de17a00-52cb-11e6-bdf4-0800200c9a66");

    // See mConnectAttempted
    private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
@@ -261,6 +264,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                            mHandler.removeMessages(profile.getProfileId());
                            if (profile.getConnectionPolicy(mDevice) >
                                    BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
                                if (ignoreA2dpDisconnectionForAndroidAuto()
                                        && profile instanceof A2dpProfile && isAndroidAuto()) {
                                    Log.w(TAG,
                                            "onProfileStateChanged(): Skip setting A2DP "
                                                    + "connection fail for Android Auto");
                                } else {
                                    /*
                                     * If we received state DISCONNECTED and previous state was
                                     * CONNECTING and connection policy is FORBIDDEN or UNKNOWN
@@ -270,10 +279,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                                     * policy indicates that profile should be connected
                                     * but it got disconnected.
                                     */
                                Log.w(TAG, "onProfileStateChanged(): Failed to connect profile");
                                    Log.w(TAG,
                                            "onProfileStateChanged(): Failed to connect profile");
                                    setProfileConnectedStatus(profile.getProfileId(), true);
                                }
                            }
                        }
                        break;
                    default:
                        Log.w(TAG, "onProfileStateChanged(): unknown profile state : "
@@ -2031,4 +2042,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    void setLocalBluetoothManager(LocalBluetoothManager bluetoothManager) {
        mBluetoothManager = bluetoothManager;
    }

    private boolean isAndroidAuto() {
        try {
            ParcelUuid[] uuids = mDevice.getUuids();
            if (ArrayUtils.contains(uuids, ANDROID_AUTO_UUID)) {
                return true;
            }
        } catch (RuntimeException e) {
            Log.w(TAG, "Fail to check isAndroidAuto for " + this);
        }
        return false;
    }
}