OSDN Git Service

ext4_utils: Yet another MMC discard pain in the ass
[android-x86/system-extras.git] / su / binder / appops-wrapper.cpp
1 #define LOG_TAG "su"
2
3 #include <binder/AppOpsManager.h>
4 #include <utils/Log.h>
5
6 using namespace android;
7
8 extern "C" {
9
10 int appops_start_op_su(int uid, const char *pkgName) {
11     ALOGD("Checking whether app [uid:%d, pkgName: %s] is allowed to be root", uid, pkgName);
12     AppOpsManager *ops = new AppOpsManager();
13
14     int mode = ops->startOp(AppOpsManager::OP_SU, uid, String16(pkgName));
15
16     switch (mode) {
17         case AppOpsManager::MODE_ALLOWED:
18           ALOGD("Privilege elevation allowed by appops");
19           return 0;
20         default:
21           ALOGD("Privilege elevation denied by appops");
22           return 1;
23     }
24
25     delete ops;
26 }
27
28 void appops_finish_op_su(int uid, const char *pkgName) {
29     ALOGD("Finishing su operation for app [uid:%d, pkgName: %s]", uid, pkgName);
30     AppOpsManager *ops = new AppOpsManager();
31     ops->finishOp(AppOpsManager::OP_SU, uid, String16(pkgName));
32     delete ops;
33 }
34
35 }