blob: 7817126eec23301e949f6ba5ece9271ab67efd20 [file] [log] [blame]
Chong Zhangb632bd52020-11-02 11:01:48 -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#ifndef ANDROID_PERMISSION_MANAGER_H
18#define ANDROID_PERMISSION_MANAGER_H
19
20#include <sys/cdefs.h>
21#include <sys/types.h>
22
23__BEGIN_DECLS
24
25/**
26 * Permission check results.
27 *
28 * Introduced in API 31.
29 */
30enum {
31 /**
32 * This is returned by APermissionManager_checkPermission()
33 * if the permission has been granted to the given package.
34 */
35 PERMISSION_MANAGER_PERMISSION_GRANTED = 0,
36 /**
37 * This is returned by APermissionManager_checkPermission()
38 * if the permission has not been granted to the given package.
39 */
40 PERMISSION_MANAGER_PERMISSION_DENIED = -1,
41};
42
43/**
44 * Permission check return status values.
45 *
46 * Introduced in API 31.
47 */
48enum {
49 /**
50 * This is returned if the permission check completed without errors.
51 * The output result is valid and contains one of {PERMISSION_MANAGER_PERMISSION_GRANTED,
52 * PERMISSION_MANAGER_PERMISSION_DENIED}.
53 */
54 PERMISSION_MANAGER_STATUS_OK = 0,
55 /**
56 * This is returned if the permission check encountered an unspecified error.
57 * The output result is unmodified.
58 */
59 PERMISSION_MANAGER_STATUS_ERROR_UNKNOWN = -1,
60 /**
61 * This is returned if the permission check failed because the service is
62 * unavailable. The output result is unmodified.
63 */
64 PERMISSION_MANAGER_STATUS_SERVICE_UNAVAILABLE = -2,
65};
66
67#if __ANDROID_API__ >= 31
68
69/**
70 * Checks whether the package with the given pid/uid has been granted a permission.
71 *
72 * Note that the Java API of Context#checkPermission() is usually faster due to caching,
73 * thus is preferred over this API wherever possible.
74 *
75 * @param permission the permission to be checked.
76 * @param pid the process id of the package to be checked.
77 * @param uid the uid of the package to be checked.
78 * @param outResult output of the permission check result.
79 *
80 * @return error codes if any error happened during the check.
81 */
82int32_t APermissionManager_checkPermission(const char* permission,
83 pid_t pid,
84 uid_t uid,
85 int32_t* outResult) __INTRODUCED_IN(31);
86
87#endif // __ANDROID_API__ >= 31
88
89__END_DECLS
90
91#endif // ANDROID_PERMISSION_MANAGER_H