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

Commit 33ff7c32 authored by Hieu Dang's avatar Hieu Dang Committed by Gerrit Code Review
Browse files

Merge "Add BluetoothDevice#getCreateBondCaller API"

parents 8f8a30fd 631fcbe1
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static com.android.bluetooth.Utils.hasBluetoothPrivilegedPermission;
import static com.android.bluetooth.Utils.isPackageNameAccurate;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
@@ -2646,6 +2647,32 @@ public class AdapterService extends Service {
            return service.canBondWithoutDialog(device);
        }

        @Override
        public void getCreateBondCaller(BluetoothDevice device,
                SynchronousResultReceiver receiver) {
            try {
                receiver.send(getCreateBondCaller(device));
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @RequiresPermission(allOf = {
                android.Manifest.permission.BLUETOOTH_CONNECT,
                android.Manifest.permission.BLUETOOTH_PRIVILEGED,
        })
        private String getCreateBondCaller(BluetoothDevice device)  {
            AdapterService service = getService();

            if (service == null) {
                return null;
            }

            enforceBluetoothPrivilegedPermission(service);

            return service.getCreateBondCaller(device);
        }

        @Override
        public void removeActiveDevice(@ActiveDeviceUse int profiles,
                AttributionSource source, SynchronousResultReceiver receiver) {
@@ -4908,6 +4935,19 @@ public class AdapterService extends Service {
        return false;
    }

    /**
     * Returns the package name of the most recent caller that called
     * {@link BluetoothDevice#createBond} on the given device.
     */
    @Nullable
    public String getCreateBondCaller(BluetoothDevice device) {
        CallerInfo info = mBondAttemptCallerInfo.get(device.getAddress());
        if (info == null) {
            return null;
        }
        return info.callerPackageName;
    }

    /**
     * Sets device as the active devices for the profiles passed into the function
     *
+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getAudioPolicyRemoteSupported();
    method @IntRange(from=0xffffff9c, to=100) @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getBatteryLevel();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionHandle(int);
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public String getCreateBondCaller();
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public String getIdentityAddress();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getMessageAccessPermission();
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public byte[] getMetadata(int);
+33 −0
Original line number Diff line number Diff line
@@ -2087,6 +2087,39 @@ public final class BluetoothDevice implements Parcelable, Attributable {
        return defaultValue;
    }

    /**
     * Gets the package name of the application that initiate bonding with this device
     *
     * @return package name of the application, or null of no application initiate bonding with
     * this device
     *
     * @hide
     */
    @SystemApi
    @Nullable
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    public String getCreateBondCaller() {
        if (DBG) log("getCreateBondCaller()");
        final IBluetooth service = getService();
        final String defaultValue = null;
        if (service == null || !isBluetoothEnabled()) {
            Log.w(TAG, "BT not enabled, getCreateBondCaller failed");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else {
            try {
                final SynchronousResultReceiver<String> recv = SynchronousResultReceiver.get();
                service.getCreateBondCaller(this, recv);
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
        }
        return defaultValue;
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
+2 −0
Original line number Diff line number Diff line
@@ -258,6 +258,8 @@ interface IBluetooth
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void canBondWithoutDialog(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void getCreateBondCaller(in BluetoothDevice device, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void generateLocalOobData(in int transport, IBluetoothOobDataCallback callback, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")