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

Commit bdfde4fc authored by Shashank Mittal's avatar Shashank Mittal Committed by Ricardo Cerqueira
Browse files

AppOps: Add Bluetooth enable control into AppOps

Check user permission before enabling bluetooth.

Change-Id: I9af341157df05104d3c5a52874538eefdbe14c4b
parent 5aaea028
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -221,7 +221,9 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_WIFI_CHANGE = 48;
    /** @hide */
    public static final int _NUM_OP = 49;
    public static final int OP_BLUETOOTH_CHANGE = 49;
    /** @hide */
    public static final int _NUM_OP = 50;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -328,6 +330,8 @@ public class AppOpsManager {
            "android:project_media";
    private static final String OPSTR_WIFI_CHANGE =
            "android:wifi_change";
    private static final String OPSTR_BLUETOOTH_CHANGE =
            "android:bluetooth_change";

    /**
     * This maps each operation to the operation that serves as the
@@ -387,6 +391,7 @@ public class AppOpsManager {
            OP_PROJECT_MEDIA,
            OP_ACTIVATE_VPN,
            OP_WIFI_CHANGE,
            OP_BLUETOOTH_CHANGE,
    };

    /**
@@ -435,6 +440,7 @@ public class AppOpsManager {
            null,
            null,
            null,
            null,
            OPSTR_MONITOR_LOCATION,
            OPSTR_MONITOR_HIGH_POWER_LOCATION,
            OPSTR_GET_USAGE_STATS,
@@ -499,6 +505,7 @@ public class AppOpsManager {
        OPSTR_PROJECT_MEDIA,
        OPSTR_ACTIVATE_VPN,
        OPSTR_WIFI_CHANGE,
        OPSTR_BLUETOOTH_CHANGE,
    };

    /**
@@ -555,6 +562,7 @@ public class AppOpsManager {
            "PROJECT_MEDIA",
            "ACTIVATE_VPN",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
    };

    /**
@@ -611,6 +619,7 @@ public class AppOpsManager {
            null, // no permission for projecting media
            null, // no permission for activating vpn
            android.Manifest.permission.CHANGE_WIFI_STATE,
            android.Manifest.permission.BLUETOOTH,
    };

    /**
@@ -668,6 +677,7 @@ public class AppOpsManager {
            null, //PROJECT_MEDIA
            UserManager.DISALLOW_CONFIG_VPN, // ACTIVATE_VPN
            null, //WIFI_CHANGE
            null, //BLUETOOTH_CHANGE
    };

    /**
@@ -724,6 +734,7 @@ public class AppOpsManager {
            false, //PROJECT_MEDIA
            false, //ACTIVATE_VPN
            false, // WIFI_CHANGE
            false, // BLUETOOTH_CHANGE
    };

    /**
@@ -779,6 +790,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -835,6 +847,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ASK,     // OP_WIFI_CHANGE
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
    };

    /**
@@ -890,6 +903,7 @@ public class AppOpsManager {
        false,    // OP_PROJECT_MEDIA
        false,    // OP_ACTIVATE_VPN
        true,     // OP_WIFI_CHANGE
        true,     // OP_BLUETOOTH_CHANGE
    };

    /**
@@ -949,6 +963,7 @@ public class AppOpsManager {
            false,
            false,
            false,     // OP_WIFI_CHANGE
            false,     // OP_BLUETOOTH_CHANGE
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+5 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2009-2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +21,7 @@ package android.bluetooth;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.ActivityThread;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
@@ -570,7 +574,7 @@ public final class BluetoothAdapter {
            return true;
        }
        try {
            return mManagerService.enable();
            return mManagerService.enable(ActivityThread.currentPackageName());
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
    }
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ interface IBluetoothManager
    void registerStateChangeCallback(in IBluetoothStateChangeCallback callback);
    void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
    boolean isEnabled();
    boolean enable();
    boolean enable(String callingPackage);
    boolean enableNoAutoConnect();
    boolean disable(boolean persist);
    IBluetoothGatt getBluetoothGatt();
+1 −0
Original line number Diff line number Diff line
@@ -1952,5 +1952,6 @@
        <item>Trying to project media</item>
        <item>Trying to activate vpn</item>
        <item>Trying to turn on/off Wifi</item>
        <item>Trying to trun on/off bluetooth</item>
    </string-array>
</resources>
+12 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +20,7 @@
package com.android.server;

import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.IBluetooth;
import android.bluetooth.IQBluetooth;
@@ -433,7 +437,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;

    }
    public boolean enable() {
    public boolean enable(String callingPackage) {
        if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
            (!checkIfCallerIsForegroundUser())) {
            Log.w(TAG,"enable(): not allowed for non-active and non system user");
@@ -447,6 +451,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) {
            mQuietEnableExternal = false;
            mEnableExternal = true;