File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222import android .annotation .SdkConstant .SdkConstantType ;
2323import android .app .Activity ;
2424import android .app .ActivityThread ;
25+ import android .app .AppOpsManager ;
2526import android .app .OnActivityPausedListener ;
2627import android .app .PendingIntent ;
2728import 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 ) {
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments