Home | History | Annotate | Download | only in binder
      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         OP_READ_PHONE_NUMBERS = 65,
     99         OP_REQUEST_INSTALL_PACKAGES = 66,
    100         OP_PICTURE_IN_PICTURE = 67,
    101         OP_INSTANT_APP_START_FOREGROUND = 68,
    102         OP_ANSWER_PHONE_CALLS = 69,
    103         OP_RUN_ANY_IN_BACKGROUND = 70,
    104         OP_CHANGE_WIFI_STATE = 71,
    105         OP_REQUEST_DELETE_PACKAGES = 72,
    106         OP_BIND_ACCESSIBILITY_SERVICE = 73,
    107         OP_ACCEPT_HANDOVER = 74,
    108         OP_MANAGE_IPSEC_TUNNELS = 75,
    109         OP_START_FOREGROUND = 76,
    110         OP_BLUETOOTH_SCAN = 77,
    111         OP_USE_BIOMETRIC = 78,
    112     };
    113 
    114     AppOpsManager();
    115 
    116     int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
    117     int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid,
    118             const String16& callingPackage);
    119     int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
    120     int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
    121             bool startIfModeDefault);
    122     void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
    123     void startWatchingMode(int32_t op, const String16& packageName,
    124             const sp<IAppOpsCallback>& callback);
    125     void stopWatchingMode(const sp<IAppOpsCallback>& callback);
    126     int32_t permissionToOpCode(const String16& permission);
    127 
    128 private:
    129     Mutex mLock;
    130     sp<IAppOpsService> mService;
    131 
    132     sp<IAppOpsService> getService();
    133 };
    134 
    135 
    136 }; // namespace android
    137 // ---------------------------------------------------------------------------
    138 #else // __ANDROID_VNDK__
    139 #error "This header is not visible to vendors"
    140 #endif // __ANDROID_VNDK__
    141 
    142 #endif // ANDROID_APP_OPS_MANAGER_H
    143