1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_APP_OPS_MANAGER_H
18 #define ANDROID_APP_OPS_MANAGER_H
19 
20 #ifndef __ANDROID_VNDK__
21 
22 #include <binder/IAppOpsService.h>
23 
24 #include <utils/threads.h>
25 
26 // ---------------------------------------------------------------------------
27 namespace android {
28 
29 class AppOpsManager
30 {
31 public:
32     enum {
33         MODE_ALLOWED = IAppOpsService::MODE_ALLOWED,
34         MODE_IGNORED = IAppOpsService::MODE_IGNORED,
35         MODE_ERRORED = IAppOpsService::MODE_ERRORED
36     };
37 
38     enum {
39         OP_NONE = -1,
40         OP_COARSE_LOCATION = 0,
41         OP_FINE_LOCATION = 1,
42         OP_GPS = 2,
43         OP_VIBRATE = 3,
44         OP_READ_CONTACTS = 4,
45         OP_WRITE_CONTACTS = 5,
46         OP_READ_CALL_LOG = 6,
47         OP_WRITE_CALL_LOG = 7,
48         OP_READ_CALENDAR = 8,
49         OP_WRITE_CALENDAR = 9,
50         OP_WIFI_SCAN = 10,
51         OP_POST_NOTIFICATION = 11,
52         OP_NEIGHBORING_CELLS = 12,
53         OP_CALL_PHONE = 13,
54         OP_READ_SMS = 14,
55         OP_WRITE_SMS = 15,
56         OP_RECEIVE_SMS = 16,
57         OP_RECEIVE_EMERGECY_SMS = 17,
58         OP_RECEIVE_MMS = 18,
59         OP_RECEIVE_WAP_PUSH = 19,
60         OP_SEND_SMS = 20,
61         OP_READ_ICC_SMS = 21,
62         OP_WRITE_ICC_SMS = 22,
63         OP_WRITE_SETTINGS = 23,
64         OP_SYSTEM_ALERT_WINDOW = 24,
65         OP_ACCESS_NOTIFICATIONS = 25,
66         OP_CAMERA = 26,
67         OP_RECORD_AUDIO = 27,
68         OP_PLAY_AUDIO = 28,
69         OP_READ_CLIPBOARD = 29,
70         OP_WRITE_CLIPBOARD = 30,
71         OP_TAKE_MEDIA_BUTTONS = 31,
72         OP_TAKE_AUDIO_FOCUS = 32,
73         OP_AUDIO_MASTER_VOLUME = 33,
74         OP_AUDIO_VOICE_VOLUME = 34,
75         OP_AUDIO_RING_VOLUME = 35,
76         OP_AUDIO_MEDIA_VOLUME = 36,
77         OP_AUDIO_ALARM_VOLUME = 37,
78         OP_AUDIO_NOTIFICATION_VOLUME = 38,
79         OP_AUDIO_BLUETOOTH_VOLUME = 39,
80         OP_WAKE_LOCK = 40,
81         OP_MONITOR_LOCATION = 41,
82         OP_MONITOR_HIGH_POWER_LOCATION = 42,
83         OP_GET_USAGE_STATS = 43,
84         OP_MUTE_MICROPHONE = 44,
85         OP_TOAST_WINDOW = 45,
86         OP_PROJECT_MEDIA = 46,
87         OP_ACTIVATE_VPN = 47,
88         OP_WRITE_WALLPAPER = 48,
89         OP_ASSIST_STRUCTURE = 49,
90         OP_ASSIST_SCREENSHOT = 50,
91         OP_READ_PHONE_STATE = 51,
92         OP_ADD_VOICEMAIL = 52,
93         OP_USE_SIP = 53,
94         OP_PROCESS_OUTGOING_CALLS = 54,
95         OP_USE_FINGERPRINT = 55,
96         OP_BODY_SENSORS = 56,
97         OP_AUDIO_ACCESSIBILITY_VOLUME = 64,
98     };
99 
100     AppOpsManager();
101 
102     int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
103     int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
104     int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
105             bool startIfModeDefault);
106     void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
107     void startWatchingMode(int32_t op, const String16& packageName,
108             const sp<IAppOpsCallback>& callback);
109     void stopWatchingMode(const sp<IAppOpsCallback>& callback);
110     int32_t permissionToOpCode(const String16& permission);
111 
112 private:
113     Mutex mLock;
114     sp<IAppOpsService> mService;
115 
116     sp<IAppOpsService> getService();
117 };
118 
119 
120 }; // namespace android
121 // ---------------------------------------------------------------------------
122 #else // __ANDROID_VNDK__
123 #error "This header is not visible to vendors"
124 #endif // __ANDROID_VNDK__
125 
126 #endif // ANDROID_APP_OPS_MANAGER_H
127