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

Commit 15cb44e1 authored by Kun Liang's avatar Kun Liang Committed by Steve Kondik
Browse files

AppOps: add permission check when enabing nfc

Add appops permission check for enable function.

Change-Id: Ie98be3e7b3cd9e72b0ad12cc1634d9cd1869a66c
parent 4bbb741c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +26,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.ActivityThread;
import android.app.AppOpsManager;
import android.app.OnActivityPausedListener;
import android.app.PendingIntent;
import android.content.Context;
@@ -313,6 +317,7 @@ public final class NfcAdapter {
    final Context mContext;
    final HashMap<NfcUnlockHandler, INfcUnlockHandler> mNfcUnlockHandlers;
    final Object mLock;
    private final AppOpsManager mAppOps;

    /**
     * A callback to be invoked when the system finds a tag while the foreground activity is
@@ -534,6 +539,7 @@ public final class NfcAdapter {
        mNfcActivityManager = new NfcActivityManager(this);
        mNfcUnlockHandlers = new HashMap<NfcUnlockHandler, INfcUnlockHandler>();
        mLock = new Object();
        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
    }

    /**
@@ -665,6 +671,9 @@ public final class NfcAdapter {
     */
    @SystemApi
    public boolean enable() {
        if (mAppOps.noteOp(AppOpsManager.OP_NFC_CHANGE) != AppOpsManager.MODE_ALLOWED){
            return false;
        }
        try {
            return sService.enable();
        } catch (RemoteException e) {