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 #include <binder/IAppOpsService.h>
21 
22 #include <utils/threads.h>
23 
24 #ifdef __ANDROID_VNDK__
25 #error "This header is not visible to vendors"
26 #endif
27 
28 // ---------------------------------------------------------------------------
29 namespace android {
30 
31 class AppOpsManager
32 {
33 public:
34     enum {
35         MODE_ALLOWED = IAppOpsService::MODE_ALLOWED,
36         MODE_IGNORED = IAppOpsService::MODE_IGNORED,
37         MODE_ERRORED = IAppOpsService::MODE_ERRORED
38     };
39 
40     enum {
41         OP_NONE = -1,
42         OP_COARSE_LOCATION = 0,
43         OP_FINE_LOCATION = 1,
44         OP_GPS = 2,
45         OP_VIBRATE = 3,
46         OP_READ_CONTACTS = 4,
47         OP_WRITE_CONTACTS = 5,
48         OP_READ_CALL_LOG = 6,
49         OP_WRITE_CALL_LOG = 7,
50         OP_READ_CALENDAR = 8,
51         OP_WRITE_CALENDAR = 9,
52         OP_WIFI_SCAN = 10,
53         OP_POST_NOTIFICATION = 11,
54         OP_NEIGHBORING_CELLS = 12,
55         OP_CALL_PHONE = 13,
56         OP_READ_SMS = 14,
57         OP_WRITE_SMS = 15,
58         OP_RECEIVE_SMS = 16,
59         OP_RECEIVE_EMERGECY_SMS = 17,
60         OP_RECEIVE_MMS = 18,
61         OP_RECEIVE_WAP_PUSH = 19,
62         OP_SEND_SMS = 20,
63         OP_READ_ICC_SMS = 21,
64         OP_WRITE_ICC_SMS = 22,
65         OP_WRITE_SETTINGS = 23,
66         OP_SYSTEM_ALERT_WINDOW = 24,
67         OP_ACCESS_NOTIFICATIONS = 25,
68         OP_CAMERA = 26,
69         OP_RECORD_AUDIO = 27,
70         OP_PLAY_AUDIO = 28,
71         OP_READ_CLIPBOARD = 29,
72         OP_WRITE_CLIPBOARD = 30,
73         OP_TAKE_MEDIA_BUTTONS = 31,
74         OP_TAKE_AUDIO_FOCUS = 32,
75         OP_AUDIO_MASTER_VOLUME = 33,
76         OP_AUDIO_VOICE_VOLUME = 34,
77         OP_AUDIO_RING_VOLUME = 35,
78         OP_AUDIO_MEDIA_VOLUME = 36,
79         OP_AUDIO_ALARM_VOLUME = 37,
80         OP_AUDIO_NOTIFICATION_VOLUME = 38,
81         OP_AUDIO_BLUETOOTH_VOLUME = 39,
82         OP_WAKE_LOCK = 40,
83         OP_MONITOR_LOCATION = 41,
84         OP_MONITOR_HIGH_POWER_LOCATION = 42,
85         OP_GET_USAGE_STATS = 43,
86         OP_MUTE_MICROPHONE = 44,
87         OP_TOAST_WINDOW = 45,
88         OP_PROJECT_MEDIA = 46,
89         OP_ACTIVATE_VPN = 47,
90         OP_WRITE_WALLPAPER = 48,
91         OP_ASSIST_STRUCTURE = 49,
92         OP_ASSIST_SCREENSHOT = 50,
93         OP_READ_PHONE_STATE = 51,
94         OP_ADD_VOICEMAIL = 52,
95         OP_USE_SIP = 53,
96         OP_PROCESS_OUTGOING_CALLS = 54,
97         OP_USE_FINGERPRINT = 55,
98         OP_BODY_SENSORS = 56,
99         OP_AUDIO_ACCESSIBILITY_VOLUME = 64,
100         OP_READ_PHONE_NUMBERS = 65,
101         OP_REQUEST_INSTALL_PACKAGES = 66,
102         OP_PICTURE_IN_PICTURE = 67,
103         OP_INSTANT_APP_START_FOREGROUND = 68,
104         OP_ANSWER_PHONE_CALLS = 69,
105         OP_RUN_ANY_IN_BACKGROUND = 70,
106         OP_CHANGE_WIFI_STATE = 71,
107         OP_REQUEST_DELETE_PACKAGES = 72,
108         OP_BIND_ACCESSIBILITY_SERVICE = 73,
109         OP_ACCEPT_HANDOVER = 74,
110         OP_MANAGE_IPSEC_TUNNELS = 75,
111         OP_START_FOREGROUND = 76,
112         OP_BLUETOOTH_SCAN = 77,
113         OP_USE_BIOMETRIC = 78,
114         OP_ACTIVITY_RECOGNITION = 79,
115         OP_SMS_FINANCIAL_TRANSACTIONS = 80,
116         OP_READ_MEDIA_AUDIO = 81,
117         OP_WRITE_MEDIA_AUDIO = 82,
118         OP_READ_MEDIA_VIDEO = 83,
119         OP_WRITE_MEDIA_VIDEO = 84,
120         OP_READ_MEDIA_IMAGES = 85,
121         OP_WRITE_MEDIA_IMAGES = 86,
122         OP_LEGACY_STORAGE = 87,
123         OP_ACCESS_ACCESSIBILITY = 88,
124         OP_READ_DEVICE_IDENTIFIERS = 89,
125         OP_ACCESS_MEDIA_LOCATION = 90,
126         OP_QUERY_ALL_PACKAGES = 91,
127         OP_MANAGE_EXTERNAL_STORAGE = 92,
128         OP_INTERACT_ACROSS_PROFILES = 93,
129         OP_ACTIVATE_PLATFORM_VPN = 94,
130         OP_LOADER_USAGE_STATS = 95,
131         OP_DEPRECATED_1 = 96,
132         OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = 97,
133         OP_AUTO_REVOKE_MANAGED_BY_INSTALLER = 98,
134         _NUM_OP = 99
135     };
136 
137     AppOpsManager();
138 
139     int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
140     int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid,
141             const String16& callingPackage);
142     // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&,
143     //              const String16&) instead
144     int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
145     int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage,
146             const std::unique_ptr<String16>& attributionTag, const String16& message);
147     // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&,
148     //              const String16&) instead
149     int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
150             bool startIfModeDefault);
151     int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
152             bool startIfModeDefault, const std::unique_ptr<String16>& attributionTag,
153             const String16& message);
154     // @Deprecated, use finishOp(int32_t, int32_t, const String16&, bool, const String16&) instead
155     void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
156     void finishOp(int32_t op, int32_t uid, const String16& callingPackage,
157             const std::unique_ptr<String16>& attributionTag);
158     void startWatchingMode(int32_t op, const String16& packageName,
159             const sp<IAppOpsCallback>& callback);
160     void stopWatchingMode(const sp<IAppOpsCallback>& callback);
161     int32_t permissionToOpCode(const String16& permission);
162     void setCameraAudioRestriction(int32_t mode);
163 
164 private:
165     Mutex mLock;
166     sp<IAppOpsService> mService;
167 
168     sp<IAppOpsService> getService();
169     bool shouldCollectNotes(int32_t opCode);
170 };
171 
172 
173 } // namespace android
174 
175 // ---------------------------------------------------------------------------
176 
177 #endif // ANDROID_APP_OPS_MANAGER_H
178