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

Commit d1813713 authored by Surajit Chandra's avatar Surajit Chandra Committed by Gerrit Code Review
Browse files

Merge "Revert "Adapter: registerBluetoothConnection permissions"" into main

parents f0e726dd 6524ff8e
Loading
Loading
Loading
Loading
+5 −39
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
@@ -856,7 +855,6 @@ public final class BluetoothAdapter {

    private final IBluetoothManager mManagerService;
    private final AttributionSource mAttributionSource;
    private final Optional<Context> mContext;

    // Yeah, keeping both mService and sService isn't pretty, but it's too late
    // in the current release for a major refactoring, so we leave them both
@@ -1065,13 +1063,13 @@ public final class BluetoothAdapter {
    @RequiresNoPermission
    public static synchronized BluetoothAdapter getDefaultAdapter() {
        if (sAdapter == null) {
            sAdapter = createAdapter(null);
            sAdapter = createAdapter(AttributionSource.myAttributionSource());
        }
        return sAdapter;
    }

    /** @hide */
    public static BluetoothAdapter createAdapter(Context context) {
    public static BluetoothAdapter createAdapter(AttributionSource attributionSource) {
        BluetoothServiceManager manager =
                BluetoothFrameworkInitializer.getBluetoothServiceManager();
        if (manager == null) {
@@ -1082,7 +1080,7 @@ public final class BluetoothAdapter {
                IBluetoothManager.Stub.asInterface(
                        manager.getBluetoothManagerServiceRegisterer().get());
        if (service != null) {
            return new BluetoothAdapter(service, context);
            return new BluetoothAdapter(service, attributionSource);
        } else {
            Log.e(TAG, "Bluetooth service is null");
            return null;
@@ -1090,15 +1088,9 @@ public final class BluetoothAdapter {
    }

    /** Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance. */
    BluetoothAdapter(IBluetoothManager managerService, @Nullable Context context) {
        mContext = Optional.ofNullable(context);
    BluetoothAdapter(IBluetoothManager managerService, AttributionSource attributionSource) {
        mManagerService = requireNonNull(managerService);
        if (context != null) {
            mAttributionSource = requireNonNull(context.getAttributionSource());
        } else {
            mAttributionSource = requireNonNull(AttributionSource.myAttributionSource());
        }

        mAttributionSource = requireNonNull(attributionSource);
        mServiceLock.writeLock().lock();
        try {
            mService = getBluetoothService(mManagerCallback);
@@ -4675,19 +4667,6 @@ public final class BluetoothAdapter {
            return false;
        }

        // Enforcing permission in the framework is useless from security point of view.
        // This is being done to help normal app developer to catch the missing permission, since
        // the call to the service is oneway and the SecurityException will just be logged
        mContext.ifPresent(
                ctx -> {
                    final int pid = Process.myPid();
                    final int uid = Process.myUid();
                    ctx.enforcePermission(
                            android.Manifest.permission.BLUETOOTH_CONNECT, pid, uid, null);
                    ctx.enforcePermission(
                            android.Manifest.permission.BLUETOOTH_PRIVILEGED, pid, uid, null);
                });

        synchronized (mBluetoothConnectionCallbackExecutorMap) {
            if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
                throw new IllegalArgumentException("This callback has already been registered");
@@ -4748,19 +4727,6 @@ public final class BluetoothAdapter {
            return false;
        }

        // Enforcing permission in the framework is useless from security point of view.
        // This is being done to help normal app developer to catch the missing permission, since
        // the call to the service is oneway and the SecurityException will just be logged
        mContext.ifPresent(
                ctx -> {
                    final int pid = Process.myPid();
                    final int uid = Process.myUid();
                    ctx.enforcePermission(
                            android.Manifest.permission.BLUETOOTH_CONNECT, pid, uid, null);
                    ctx.enforcePermission(
                            android.Manifest.permission.BLUETOOTH_PRIVILEGED, pid, uid, null);
                });

        synchronized (mBluetoothConnectionCallbackExecutorMap) {
            if (!mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
                return true;
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public final class BluetoothManager {
    /** @hide */
    public BluetoothManager(Context context) {
        mAttributionSource = context.getAttributionSource();
        mAdapter = BluetoothAdapter.createAdapter(context);
        mAdapter = BluetoothAdapter.createAdapter(mAttributionSource);
    }

    /**
+2 −7
Original line number Diff line number Diff line
@@ -53,15 +53,10 @@ object Permissions {
        }
        newPermissions.forEach {
            val permissionsSet = newPermissions.toMutableSet()
            val removedPermission = it
            permissionsSet.remove(removedPermission)
            permissionsSet.remove(it)

            withPermissions(*arrayOf(*permissionsSet.toTypedArray())).use {
                assertThrows(
                    "SecurityException wasn't throw when checking for $removedPermission",
                    SecurityException::class.java,
                    { action() }
                )
                assertThrows(SecurityException::class.java, { action() })
            }
        }
    }