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