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

Commit 4d912eec authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "wear_bt_mig"

* changes:
  [framework] Migration of hidden APIs to System APIs
  [service] Migration of APIs permission changes
parents 107c6333 7901c005
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1752,11 +1752,14 @@ public class AdapterService extends Service {
        }

        @Override
        public long getSupportedProfiles() {
        public long getSupportedProfiles(AttributionSource source) {
            AdapterService service = getService();
            if (service == null) {
            if (service == null
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return 0;
            }
            enforceBluetoothPrivilegedPermission(service);

            return Config.getSupportedProfilesBitMask();
        }

+2 −0
Original line number Diff line number Diff line
@@ -744,6 +744,7 @@ public class HeadsetService extends ProfileService {
            try {
                HeadsetService service = getService(source);
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    service.setAudioRouteAllowed(allowed);
                }
                receiver.send(null);
@@ -759,6 +760,7 @@ public class HeadsetService extends ProfileService {
                HeadsetService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    defaultValue = service.getAudioRouteAllowed();
                }
                receiver.send(defaultValue);
+5 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void generateLocalOobData(int, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OobDataCallback);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getActiveDevices(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public long getDiscoveryEndMillis();
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<java.lang.Integer> getSupportedProfiles();
    method public boolean isBleScanAlwaysAvailable();
    method public boolean isLeEnabled();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean removeActiveDevice(int);
@@ -157,9 +158,11 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int connectAudio();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean disconnect(android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int disconnectAudio();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getAudioRouteAllowed();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getAudioState(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean isInbandRingingEnabled();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int setAudioRouteAllowed(boolean);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean startScoUsingVirtualVoiceCall();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean stopScoUsingVirtualVoiceCall();
@@ -265,6 +268,7 @@ package android.bluetooth {
  }

  public final class BluetoothStatusCodes {
    field public static final int ALLOWED = 400; // 0x190
    field public static final int ERROR_ANOTHER_ACTIVE_OOB_REQUEST = 1000; // 0x3e8
    field public static final int ERROR_AUDIO_DEVICE_ALREADY_CONNECTED = 1116; // 0x45c
    field public static final int ERROR_AUDIO_DEVICE_ALREADY_DISCONNECTED = 1117; // 0x45d
@@ -274,6 +278,7 @@ package android.bluetooth {
    field public static final int ERROR_NO_ACTIVE_DEVICES = 13; // 0xd
    field public static final int ERROR_PROFILE_NOT_CONNECTED = 14; // 0xe
    field public static final int ERROR_TIMEOUT = 15; // 0xf
    field public static final int NOT_ALLOWED = 401; // 0x191
  }

  public final class BluetoothUuid {
+9 −3
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import android.os.IBinder;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.sysprop.BluetoothProperties;
import android.util.Log;
import android.util.Pair;
@@ -2552,14 +2551,20 @@ public final class BluetoothAdapter {
     * BluetoothProfile}.
     * @hide
     */
    @RequiresNoPermission
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    public @NonNull List<Integer> getSupportedProfiles() {
        final ArrayList<Integer> supportedProfiles = new ArrayList<Integer>();

        try {
            synchronized (mManagerCallback) {
                if (mService != null) {
                    final long supportedProfilesBitMask = mService.getSupportedProfiles();
                    final long supportedProfilesBitMask =
                            mService.getSupportedProfiles(mAttributionSource);

                    for (int i = 0; i <= BluetoothProfile.MAX_PROFILE_ID; i++) {
                        if ((supportedProfilesBitMask & (1 << i)) != 0) {
@@ -2575,6 +2580,7 @@ public final class BluetoothAdapter {
            }
        } catch (RemoteException e) {
            Log.e(TAG, "getSupportedProfiles:", e);
            e.rethrowFromSystemServer();
        }
        return supportedProfiles;
    }
+69 −30
Original line number Diff line number Diff line
@@ -939,60 +939,99 @@ public final class BluetoothHeadset implements BluetoothProfile {
        return defaultValue;
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            BluetoothStatusCodes.SUCCESS,
            BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED,
            BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND,
            BluetoothStatusCodes.ERROR_TIMEOUT,
            BluetoothStatusCodes.ALLOWED,
            BluetoothStatusCodes.NOT_ALLOWED,
    })
    public @interface AudioRouteAllowedReturnValues {}

    /**
     * Sets whether audio routing is allowed. When set to {@code false}, the AG will not route any
     * audio to the HF unless explicitly told to.
     * This method should be used in cases where the SCO channel is shared between multiple profiles
     * and must be delegated by a source knowledgeable
     * Note: This is an internal function and shouldn't be exposed
     * Sets whether audio routing is allowed. When set to {@code false}, the AG
     * will not route any audio to the HF unless explicitly told to. This method
     * should be used in cases where the SCO channel is shared between multiple
     * profiles and must be delegated by a source knowledgeable.
     *
     * @param allowed {@code true} if the profile can reroute audio,
     * {@code false} otherwise.
     * @return {@link BluetoothStatusCodes#SUCCESS} upon successful setting,
     * otherwise an error code.
     *
     * @param allowed {@code true} if the profile can reroute audio, {@code false} otherwise.
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public void setAudioRouteAllowed(boolean allowed) {
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    public @AudioRouteAllowedReturnValues int setAudioRouteAllowed(boolean allowed) {
        if (VDBG) log("setAudioRouteAllowed");
        final IBluetoothHeadset service = mService;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND;
        } else if (!isEnabled()) {
            return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;
        }
        try {
            final SynchronousResultReceiver recv = new SynchronousResultReceiver();
            service.setAudioRouteAllowed(allowed, mAttributionSource, recv);
            recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (RemoteException | TimeoutException e) {
            return BluetoothStatusCodes.SUCCESS;
        } catch (TimeoutException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            return BluetoothStatusCodes.ERROR_TIMEOUT;
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            e.rethrowFromSystemServer();
        }
        }
        return BluetoothStatusCodes.ERROR_UNKNOWN;
    }

    /**
     * Returns whether audio routing is allowed. see {@link #setAudioRouteAllowed(boolean)}.
     * Note: This is an internal function and shouldn't be exposed
     * @return {@link BluetoothStatusCodes#ALLOWED} if audio routing is allowed,
     * {@link BluetoothStatusCodes#NOT_ALLOWED} if audio routing is not allowed, or
     * an error code if an error occurs.
     * see {@link #setAudioRouteAllowed(boolean)}.
     *
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public boolean getAudioRouteAllowed() {
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    public @AudioRouteAllowedReturnValues int getAudioRouteAllowed() {
        if (VDBG) log("getAudioRouteAllowed");
        final IBluetoothHeadset service = mService;
        final boolean defaultValue = false;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND;
        } else if (!isEnabled()) {
            return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;
        }
        try {
            final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            service.getAudioRouteAllowed(mAttributionSource, recv);
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
            } catch (RemoteException | TimeoutException e) {
            return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false)
                    ? BluetoothStatusCodes.ALLOWED : BluetoothStatusCodes.NOT_ALLOWED;
        } catch (TimeoutException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            return BluetoothStatusCodes.ERROR_TIMEOUT;
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            e.rethrowFromSystemServer();
        }
        }
        return defaultValue;
        return BluetoothStatusCodes.ERROR_UNKNOWN;
    }

    /**
Loading