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

Commit 2ece4008 authored by Kun Liang's avatar Kun Liang Committed by Ed Carrigan
Browse files

AppOps: add permission check when enabing nfc

Add appops permission check for enable function.

Change-Id: Ie98be3e7b3cd9e72b0ad12cc1634d9cd1869a66c
parent b351a48b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.Activity;
import android.app.ActivityThread;
import android.app.AppOpsManager;
import android.app.OnActivityPausedListener;
import android.app.PendingIntent;
import android.content.Context;
@@ -309,6 +310,7 @@ public final class NfcAdapter {

    final NfcActivityManager mNfcActivityManager;
    final Context mContext;
    private final AppOpsManager mAppOps;

    /**
     * A callback to be invoked when the system finds a tag while the foreground activity is
@@ -512,6 +514,7 @@ public final class NfcAdapter {
    NfcAdapter(Context context) {
        mContext = context;
        mNfcActivityManager = new NfcActivityManager(this);
        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
    }

    /**
@@ -642,6 +645,9 @@ public final class NfcAdapter {
     * @hide
     */
    public boolean enable() {
        if (mAppOps.noteOp(AppOpsManager.OP_NFC_CHANGE) != AppOpsManager.MODE_ALLOWED){
            return false;
        }
        try {
            return sService.enable();
        } catch (RemoteException e) {
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@
  <string name="app_ops_toggle_bluetooth">开启蓝牙</string>
  <string name="app_ops_toggle_mobile_data">开启移动数据</string>
  <string name="app_ops_toggle_wifi">开启 Wi-Fi</string>
  <string name="app_ops_toggle_nfc">试图开关NFC</string>
  <string name="app_ops_use_alarm_volume">控制闹铃音量</string>
  <string name="app_ops_use_audio_focus">控制音频焦点</string>
  <string name="app_ops_use_bluetooth_volume">控制蓝牙音量</string>
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@
        <item>@string/app_ops_read_mms</item>
        <item>@string/app_ops_write_mms</item>
        <item>@string/app_ops_start_at_bootup</item>
        <item>@string/app_ops_toggle_nfc</item>
    </string-array>

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@
    <string name="app_ops_toggle_bluetooth">toggle Bluetooth</string>
    <string name="app_ops_toggle_mobile_data">toggle mobile data</string>
    <string name="app_ops_toggle_wifi">toggle WiFi</string>
    <string name="app_ops_toggle_nfc">toggle NFC</string>
    <string name="app_ops_use_alarm_volume">control alarm volume</string>
    <string name="app_ops_use_audio_focus">control the audio focus</string>
    <string name="app_ops_use_bluetooth_volume">control the Bluetooth volume</string>