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