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

Commit 4f4c8b95 authored by William Escande's avatar William Escande
Browse files

Bluetooth boot: call doBind only if stack is ready

Calling doBind when the stack is not yet ready is producing very verbose
logging during bluetooth startup.
To avoid that, the registerStateChangeCallback will now always call its
callback when it unregister, and it will also always call it when you
register and the bluetooth is already one.

This is a no-op change from an outsider point of view

Test: Any presubmit run will show profile
Test: atest ServiceBluetoothTests
Bug: 291815510
Change-Id: I9c5ec06da794e1444a38bcb3009456adbe50b34f
parent 5907b0ad
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -183,7 +183,6 @@ public abstract class BluetoothProfileConnector<T> {
                logError("Failed to register state change callback. " + re);
            }
        }
        doBind();
    }

    void disconnect() {
@@ -200,7 +199,6 @@ public abstract class BluetoothProfileConnector<T> {
                logError("Failed to unregister state change callback" + re);
            }
        }
        doUnbind();
    }

    T getService() {
+21 −2
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF;
import static android.bluetooth.BluetoothAdapter.STATE_TURNING_ON;
import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED;

import static com.android.server.bluetooth.BluetoothAirplaneModeListener.APM_ENHANCEMENT;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
@@ -2022,11 +2024,28 @@ class BluetoothManagerService {
                    break;

                case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
                    mStateChangeCallbacks.register((IBluetoothStateChangeCallback) msg.obj);
                    IBluetoothStateChangeCallback regCallback =
                            (IBluetoothStateChangeCallback)msg.obj;
                    if (mState.oneOf(STATE_ON)) {
                        try {
                            regCallback.onBluetoothStateChange(true);
                        } catch (RemoteException e) {
                            Log.e(TAG, "REGISTER_STATE_CHANGE_CALLBACK: callback failed", e);
                            break;
                        }
                    }
                    mStateChangeCallbacks.register(regCallback);
                    break;

                case MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK:
                    mStateChangeCallbacks.unregister((IBluetoothStateChangeCallback) msg.obj);
                    IBluetoothStateChangeCallback unregCallback =
                            (IBluetoothStateChangeCallback)msg.obj;
                    try {
                        unregCallback.onBluetoothStateChange(false);
                    } catch (RemoteException e) {
                        Log.e(TAG, "UNREGISTER_STATE_CHANGE_CALLBACK: callback failed", e);
                    }
                    mStateChangeCallbacks.unregister(unregCallback);
                    break;

                case MESSAGE_ADD_PROXY_DELAYED: