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

Commit 34406555 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge changes Ib94827b0,Ic70c3260,I8c363a64,I9c5ec06d into main am: d6f23d8c am: 86bc3c16

parents ea0a843a 86bc3c16
Loading
Loading
Loading
Loading
+10 −66
Original line number Diff line number Diff line
@@ -824,7 +824,7 @@ public final class BluetoothAdapter {

    /** @hide */
    public static final String BLUETOOTH_MANAGER_SERVICE = "bluetooth_manager";
    private final IBinder mToken;
    private final IBinder mToken = new Binder(DESCRIPTOR);


    /**
@@ -873,7 +873,7 @@ public final class BluetoothAdapter {
    private static final Object sServiceLock = new Object();

    private final Object mLock = new Object();
    private final Map<LeScanCallback, ScanCallback> mLeScanClients;
    private final Map<LeScanCallback, ScanCallback> mLeScanClients = new HashMap<>();
    private final Map<BluetoothDevice, List<Pair<OnMetadataChangedListener, Executor>>>
                mMetadataListeners = new HashMap<>();
    private final Map<BluetoothConnectionCallback, Executor>
@@ -1066,8 +1066,6 @@ public final class BluetoothAdapter {
        } finally {
            mServiceLock.writeLock().unlock();
        }
        mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
        mToken = new Binder(DESCRIPTOR);
    }

    /**
@@ -3862,15 +3860,15 @@ public final class BluetoothAdapter {
                    mServiceLock.writeLock().lock();
                    try {
                        mService = null;
                        if (mLeScanClients != null) {
                        mLeScanClients.clear();
                        }
                        synchronized (mLock) {
                            if (mBluetoothLeAdvertiser != null) {
                                mBluetoothLeAdvertiser.cleanup();
                            }
                            if (mBluetoothLeScanner != null) {
                                mBluetoothLeScanner.cleanup();
                            }
                        }
                    } finally {
                        mServiceLock.writeLock().unlock();
                    }
@@ -4293,60 +4291,6 @@ public final class BluetoothAdapter {
        void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord);
    }

    /**
     * Register a callback to receive events whenever the bluetooth stack goes down and back up,
     * e.g. in the event the bluetooth is turned off/on via settings.
     *
     * If the bluetooth stack is currently up, there will not be an initial callback call.
     * You can use the return value as an indication of this being the case.
     *
     * Callbacks will be delivered on a binder thread.
     *
     * @return whether bluetooth is already up currently
     *
     * @hide
     */
    @RequiresNoPermission
    public boolean registerServiceLifecycleCallback(@NonNull ServiceLifecycleCallback callback) {
        return getBluetoothService(callback.mRemote) != null;
    }

    /**
     * Unregister a callback registered via {@link #registerServiceLifecycleCallback}
     *
     * @hide
     */
    @RequiresNoPermission
    public void unregisterServiceLifecycleCallback(@NonNull ServiceLifecycleCallback callback) {
        removeServiceStateCallback(callback.mRemote);
    }

    /**
     * A callback for {@link #registerServiceLifecycleCallback}
     *
     * @hide
     */
    public abstract static class ServiceLifecycleCallback {

        /** Called when the bluetooth stack is up */
        public abstract void onBluetoothServiceUp();

        /** Called when the bluetooth stack is down */
        public abstract void onBluetoothServiceDown();

        IBluetoothManagerCallback mRemote = new IBluetoothManagerCallback.Stub() {
            @Override
            public void onBluetoothServiceUp(IBluetooth bluetoothService) {
                ServiceLifecycleCallback.this.onBluetoothServiceUp();
            }

            @Override
            public void onBluetoothServiceDown() {
                ServiceLifecycleCallback.this.onBluetoothServiceDown();
            }
        };
    }

    /**
     * Starts a scan for Bluetooth LE devices.
     *
+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: