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

Commit f035ecba authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

appops: enforce appop for bluetooth disabled action



Bluetooth disable action should be enforced in the same manner that the enable one.

Patchset 2: Fix derp
Patchset 3: Fix build
Patchset 4: Rebase. Fix comment style
Patchset 5: Rebase

Change-Id: Ie161ac0c038acbd4c1ce7f27ab4c5897813fd4cf
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 9b13e64d
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -712,10 +712,7 @@ public final class BluetoothAdapter {
     *         immediate error
     */
    public boolean disable() {
        try {
            return mManagerService.disable(true);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return disable(true);
    }

    /**
@@ -731,7 +728,7 @@ public final class BluetoothAdapter {
    public boolean disable(boolean persist) {

        try {
            return mManagerService.disable(persist);
            return mManagerService.disable(ActivityThread.currentPackageName(), persist);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
    }
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ interface IBluetoothManager
    boolean isEnabled();
    boolean enable(String callingPackage);
    boolean enableNoAutoConnect();
    boolean disable(boolean persist);
    boolean disable(String callingPackage, boolean persist);
    IBluetoothGatt getBluetoothGatt();
    IQBluetooth getQBluetooth();

+8 −1
Original line number Diff line number Diff line
@@ -449,7 +449,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
    }

    public boolean disable(boolean persist) {
    public boolean disable(String callingPackage, boolean persist) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                "Need BLUETOOTH ADMIN permissicacheNameAndAddresson");

@@ -470,6 +470,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                " mBinding = " + mBinding);
        }

        AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        int callingUid = Binder.getCallingUid();
        if (appOps.noteOp(AppOpsManager.OP_BLUETOOTH_CHANGE, callingUid, callingPackage) !=
                AppOpsManager.MODE_ALLOWED) {
            return false;
        }

        synchronized(mReceiver) {
            if (persist) {
                // waive WRITE_SECURE_SETTINGS permission check
+2 −1
Original line number Diff line number Diff line
@@ -468,7 +468,8 @@ public final class ShutdownThread extends Thread {
                    bluetoothOff = bluetooth == null || !bluetooth.isEnabled();
                    if (!bluetoothOff) {
                        Log.w(TAG, "Disabling Bluetooth...");
                        bluetooth.disable(false);  // disable but don't persist new state
                        // disable but don't persist new state
                        bluetooth.disable(mContext.getBasePackageName(), false);
                    }
                } catch (RemoteException ex) {
                    Log.e(TAG, "RemoteException during bluetooth shutdown", ex);