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

Commit 2141fc7a authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

Merge "AppOps: Add Bluetooth enable control into AppOps" into cm-10.2

parents ef0ed7c2 f7676eb8
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ public class AppOpsManager {
    public static final int OP_WRITE_CLIPBOARD = 30;
    /** @hide */
    public static final int OP_WIFI_CHANGE = 31;
    public static final int _NUM_OP = 32;
    public static final int OP_BLUETOOTH_CHANGE = 32;
    public static final int _NUM_OP = 33;

    /**
     * Map to check if each operation is strict or not, to determine default
@@ -143,6 +144,7 @@ public class AppOpsManager {
        false,  //OP_READ_CLIPBOARD
        false,  //OP_WRITE_CLIPBOARD
        true,   //OP_WIFI_CHANGE
        true,   //OP_BLUETOOTH_CHANGE
    };

    /**
@@ -186,6 +188,7 @@ public class AppOpsManager {
            OP_READ_CLIPBOARD,
            OP_WRITE_CLIPBOARD,
            OP_WIFI_CHANGE,
            OP_BLUETOOTH_CHANGE,
    };

    /**
@@ -225,6 +228,7 @@ public class AppOpsManager {
            "READ_CLIPBOARD",
            "WRITE_CLIPBOARD",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
    };

    /**
@@ -264,6 +268,7 @@ public class AppOpsManager {
            null, // no permission for reading clipboard
            null, // no permission for writing clipboard
            android.Manifest.permission.CHANGE_WIFI_STATE,
            android.Manifest.permission.BLUETOOTH,
    };

    /**
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package android.bluetooth;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.ActivityThread;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -518,7 +519,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
@@ -33,7 +33,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
@@ -86,5 +86,6 @@
        <item>Trying to read clipboard</item>
        <item>Trying to modify clipboard</item>
        <item>Trying to turn on/off Wifi</item>
        <item>Trying to turn on/off bluetooth</item>
    </string-array>
</resources>
+11 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.app.AppOpsManager;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
@@ -392,7 +393,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");
@@ -406,6 +407,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;