Home | History | Annotate | Download | only in binder
      1 /*
      2  * Copyright (C) 2018 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_PERMISSION_CONTROLLER_H
     18 #define ANDROID_PERMISSION_CONTROLLER_H
     19 
     20 #ifndef __ANDROID_VNDK__
     21 
     22 #include <binder/IPermissionController.h>
     23 
     24 #include <utils/threads.h>
     25 
     26 // ---------------------------------------------------------------------------
     27 namespace android {
     28 
     29 class PermissionController
     30 {
     31 public:
     32 
     33     enum {
     34         MATCH_SYSTEM_ONLY = 1<<16,
     35         MATCH_UNINSTALLED_PACKAGES = 1<<13,
     36         MATCH_FACTORY_ONLY = 1<<21,
     37         MATCH_INSTANT = 1<<23
     38     };
     39 
     40     enum {
     41         MODE_ALLOWED = 0,
     42         MODE_IGNORED = 1,
     43         MODE_ERRORED = 2,
     44         MODE_DEFAULT = 3,
     45     };
     46 
     47     PermissionController();
     48 
     49     bool checkPermission(const String16& permission, int32_t pid, int32_t uid);
     50     int32_t noteOp(const String16& op, int32_t uid, const String16& packageName);
     51     void getPackagesForUid(const uid_t uid, Vector<String16>& packages);
     52     bool isRuntimePermission(const String16& permission);
     53     int getPackageUid(const String16& package, int flags);
     54 
     55 private:
     56     Mutex mLock;
     57     sp<IPermissionController> mService;
     58 
     59     sp<IPermissionController> getService();
     60 };
     61 
     62 
     63 }; // namespace android
     64 // ---------------------------------------------------------------------------
     65 #else // __ANDROID_VNDK__
     66 #error "This header is not visible to vendors"
     67 #endif // __ANDROID_VNDK__
     68 
     69 #endif // ANDROID_PERMISSION_CONTROLLER_H
     70