Skip to content

Commit 3df029d

Browse files
Kun Liangcodex-corp
authored andcommitted
AppOps: add permission check when enabing nfc
Add appops permission check for enable function. Change-Id: Ie98be3e7b3cd9e72b0ad12cc1634d9cd1869a66c
1 parent d510cb8 commit 3df029d

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

core/java/android/nfc/NfcAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.annotation.SdkConstant.SdkConstantType;
2323
import android.app.Activity;
2424
import android.app.ActivityThread;
25+
import android.app.AppOpsManager;
2526
import android.app.OnActivityPausedListener;
2627
import android.app.PendingIntent;
2728
import android.content.Context;
@@ -309,6 +310,7 @@ public final class NfcAdapter {
309310

310311
final NfcActivityManager mNfcActivityManager;
311312
final Context mContext;
313+
private final AppOpsManager mAppOps;
312314

313315
/**
314316
* A callback to be invoked when the system finds a tag while the foreground activity is
@@ -512,6 +514,7 @@ public static NfcAdapter getDefaultAdapter() {
512514
NfcAdapter(Context context) {
513515
mContext = context;
514516
mNfcActivityManager = new NfcActivityManager(this);
517+
mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
515518
}
516519

517520
/**
@@ -642,6 +645,9 @@ public int getAdapterState() {
642645
* @hide
643646
*/
644647
public boolean enable() {
648+
if (mAppOps.noteOp(AppOpsManager.OP_NFC_CHANGE) != AppOpsManager.MODE_ALLOWED){
649+
return false;
650+
}
645651
try {
646652
return sService.enable();
647653
} catch (RemoteException e) {

core/res/res/values-zh-rCN/cm_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<string name="app_ops_toggle_bluetooth">开启蓝牙</string>
114114
<string name="app_ops_toggle_mobile_data">开启移动数据</string>
115115
<string name="app_ops_toggle_wifi">开启 Wi-Fi</string>
116+
<string name="app_ops_toggle_nfc">试图开关NFC</string>
116117
<string name="app_ops_use_alarm_volume">控制闹铃音量</string>
117118
<string name="app_ops_use_audio_focus">控制音频焦点</string>
118119
<string name="app_ops_use_bluetooth_volume">控制蓝牙音量</string>

core/res/res/values/cm_arrays.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<item>@string/app_ops_read_mms</item>
105105
<item>@string/app_ops_write_mms</item>
106106
<item>@string/app_ops_start_at_bootup</item>
107+
<item>@string/app_ops_toggle_nfc</item>
107108
</string-array>
108109

109110
</resources>

core/res/res/values/cm_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<string name="app_ops_toggle_bluetooth">toggle Bluetooth</string>
200200
<string name="app_ops_toggle_mobile_data">toggle mobile data</string>
201201
<string name="app_ops_toggle_wifi">toggle WiFi</string>
202+
<string name="app_ops_toggle_nfc">toggle NFC</string>
202203
<string name="app_ops_use_alarm_volume">control alarm volume</string>
203204
<string name="app_ops_use_audio_focus">control the audio focus</string>
204205
<string name="app_ops_use_bluetooth_volume">control the Bluetooth volume</string>

0 commit comments

Comments
 (0)