blob: 166e00e8dbe27c1a62e4b8a557820b8a96ab4192 [file] [log] [blame]
Chong Zhang06dbe5b2020-11-02 16:02:07 -08001/*
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
20namespace android {
21namespace permissionmananger {
22
23// Global instance of ActivityManager, service is obtained only on first use.
24static ActivityManager gAm;
25
26} // permissionmanager
27} // android
28
29using namespace android;
30using namespace permissionmananger;
31
32int32_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}