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