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

Commit 96b794c2 authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Automerger Merge Worker
Browse files

Merge changes from topic "api-review-result-receiver" am: 4016e3d9

parents d5c24b89 4016e3d9
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ package android.bluetooth {
    method public boolean registerServiceLifecycleCallback(@NonNull android.bluetooth.BluetoothAdapter.ServiceLifecycleCallback);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean removeActiveDevice(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void requestControllerActivityEnergyInfo(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnBluetoothActivityEnergyInfoListener);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void requestControllerActivityEnergyInfo(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnBluetoothActivityEnergyInfoCallback);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BluetoothSocket retrieveConnectedRfcommSocket(@NonNull java.util.UUID);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int startRfcommServer(@NonNull String, @NonNull java.util.UUID, @NonNull android.app.PendingIntent);
@@ -97,8 +97,9 @@ package android.bluetooth {
    method public void onDeviceDisconnected(@NonNull android.bluetooth.BluetoothDevice, int);
  }

  public static interface BluetoothAdapter.OnBluetoothActivityEnergyInfoListener {
    method public void onBluetoothActivityEnergyInfo(@Nullable android.bluetooth.BluetoothActivityEnergyInfo);
  public static interface BluetoothAdapter.OnBluetoothActivityEnergyInfoCallback {
    method public void onBluetoothActivityEnergyInfoAvailable(@NonNull android.bluetooth.BluetoothActivityEnergyInfo);
    method public default void onBluetoothActivityEnergyInfoError(int);
  }

  public static interface BluetoothAdapter.OnMetadataChangedListener {
+56 −23
Original line number Diff line number Diff line
@@ -818,52 +818,79 @@ public final class BluetoothAdapter {
        }
    };

    /** @hide */
    @IntDef(value = {
            BluetoothStatusCodes.ERROR_UNKNOWN,
            BluetoothStatusCodes.FEATURE_NOT_SUPPORTED,
            BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BluetoothActivityEnergyInfoCallbackError {}

    /**
     * Interface for Bluetooth activity energy info listener. Should be implemented by applications
     * and set when calling {@link BluetoothAdapter#requestControllerActivityEnergyInfo}.
     * Interface for Bluetooth activity energy info callback. Should be implemented by applications
     * and set when calling {@link #requestControllerActivityEnergyInfo}.
     *
     * @hide
     */
    @SystemApi
    public interface OnBluetoothActivityEnergyInfoListener {
    public interface OnBluetoothActivityEnergyInfoCallback {
        /**
         * Called when Bluetooth activity energy info is available.
         * Note: this listener is triggered at most once for each call to
         * Note: this callback is triggered at most once for each call to
         * {@link #requestControllerActivityEnergyInfo}.
         *
         * @param info the latest {@link BluetoothActivityEnergyInfo}, or null if unavailable.
         * @param info the latest {@link BluetoothActivityEnergyInfo}
         */
        void onBluetoothActivityEnergyInfo(@Nullable BluetoothActivityEnergyInfo info);
        void onBluetoothActivityEnergyInfoAvailable(
                @NonNull BluetoothActivityEnergyInfo info);

        /**
         * Called when the latest {@link BluetoothActivityEnergyInfo} can't be retrieved.
         * The reason of the failure is indicated by the {@link BluetoothStatusCodes}
         * passed as an argument to this method.
         * Note: this callback is triggered at most once for each call to
         * {@link #requestControllerActivityEnergyInfo}.
         *
         * @param error code indicating the reason for the failure
         */
        default void onBluetoothActivityEnergyInfoError(
                @BluetoothActivityEnergyInfoCallbackError int error) {}
    }

    private static class OnBluetoothActivityEnergyInfoProxy
            extends IBluetoothActivityEnergyInfoListener.Stub {
        private final Object mLock = new Object();
        @Nullable @GuardedBy("mLock") private Executor mExecutor;
        @Nullable @GuardedBy("mLock") private OnBluetoothActivityEnergyInfoListener mListener;
        @Nullable @GuardedBy("mLock") private OnBluetoothActivityEnergyInfoCallback mCallback;

        OnBluetoothActivityEnergyInfoProxy(Executor executor,
                OnBluetoothActivityEnergyInfoListener listener) {
                OnBluetoothActivityEnergyInfoCallback callback) {
            mExecutor = executor;
            mListener = listener;
            mCallback = callback;
        }

        @Override
        public void onBluetoothActivityEnergyInfoAvailable(BluetoothActivityEnergyInfo info) {
            Executor executor;
            OnBluetoothActivityEnergyInfoListener listener;
            OnBluetoothActivityEnergyInfoCallback callback;
            synchronized (mLock) {
                if (mExecutor == null || mListener == null) {
                if (mExecutor == null || mCallback == null) {
                    return;
                }
                executor = mExecutor;
                listener = mListener;
                // null out to allow garbage collection, prevent triggering listener more than once
                callback = mCallback;
                // null out to allow garbage collection, prevent triggering callback more than once
                mExecutor = null;
                mListener = null;
                mCallback = null;
            }
            Binder.clearCallingIdentity();
            executor.execute(() -> listener.onBluetoothActivityEnergyInfo(info));
            if (info == null) {
                executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                        BluetoothStatusCodes.FEATURE_NOT_SUPPORTED));
            } else {
                executor.execute(() -> callback.onBluetoothActivityEnergyInfoAvailable(info));
            }
        }
    }

@@ -2734,12 +2761,12 @@ public final class BluetoothAdapter {
     * has the activity and energy info. This can be used to ascertain what
     * the controller has been up to, since the last sample.
     *
     * A null value for the activity info object may be sent if the bluetooth service is
     * unreachable or the device does not support reporting such information.
     * The callback will be called only once, when the record is available.
     *
     * @param executor the executor that the listener will be invoked on
     * @param listener the listener that will receive the {@link BluetoothActivityEnergyInfo}
     *                 object when it becomes available
     * @param executor the executor that the callback will be invoked on
     * @param callback the callback that will be called with either the
     *                 {@link BluetoothActivityEnergyInfo} object, or the
     *                 error code if an error has occurred
     * @hide
     */
    @SystemApi
@@ -2750,18 +2777,24 @@ public final class BluetoothAdapter {
    })
    public void requestControllerActivityEnergyInfo(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull OnBluetoothActivityEnergyInfoListener listener) {
            @NonNull OnBluetoothActivityEnergyInfoCallback callback) {
        requireNonNull(executor, "executor cannot be null");
        requireNonNull(listener, "listener cannot be null");
        requireNonNull(callback, "callback cannot be null");
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                mService.requestActivityInfo(
                        new OnBluetoothActivityEnergyInfoProxy(executor, listener),
                        new OnBluetoothActivityEnergyInfoProxy(executor, callback),
                        mAttributionSource);
            } else {
                executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                        BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND));
            }
        } catch (RemoteException e) {
            Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
            Binder.clearCallingIdentity();
            executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                    BluetoothStatusCodes.ERROR_UNKNOWN));
        } finally {
            mServiceLock.readLock().unlock();
        }