• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #include <android/permission_manager.h>
18 #include <binder/ActivityManager.h>
19 
20 namespace android {
21 namespace permissionmananger {
22 
23 // Global instance of ActivityManager, service is obtained only on first use.
24 static ActivityManager gAm;
25 
26 } // permissionmanager
27 } // android
28 
29 using namespace android;
30 using namespace permissionmananger;
31 
APermissionManager_checkPermission(const char * permission,pid_t pid,uid_t uid,int32_t * outResult)32 int32_t APermissionManager_checkPermission(const char* permission,
33                                            pid_t pid,
34                                            uid_t uid,
35                                            int32_t* outResult) {
36     status_t result = gAm.checkPermission(String16(permission), pid, uid, outResult);
37     if (result == DEAD_OBJECT) {
38         return PERMISSION_MANAGER_STATUS_SERVICE_UNAVAILABLE;
39     } else if (result != NO_ERROR) {
40         return PERMISSION_MANAGER_STATUS_ERROR_UNKNOWN;
41     }
42     return PERMISSION_MANAGER_STATUS_OK;
43 }
44