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

Commit 65b57ada authored by Eugene Susla's avatar Eugene Susla
Browse files

[DO NOT MERGE] Scan and notify apps when their companion devices are nearby

Test: manual
Bug: 168052577
Change-Id: Ib2187fb76e604878b1d4dd9c0cd6cea610b2a04d
(cherry picked from commit 017c2c41456e3938145cf33facea339f9918b20c)
parent 2abe8c6e
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -3197,6 +3197,61 @@ 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
     */
    public boolean registerServiceLifecycleCallback(ServiceLifecycleCallback callback) {
        return getBluetoothService(callback.mRemote) != null;
    }

    /**
     * Unregister a callback registered via {@link #registerServiceLifecycleCallback}
     *
     * @hide
     */
    public void unregisterServiceLifecycleCallback(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();
            }

            @Override
            public void onBrEdrDown() {}
        };
    }

    /**
     * Starts a scan for Bluetooth LE devices.
     *