summaryrefslogtreecommitdiff
path: root/include/android/permission_manager.h
blob: 753b6d16de1cb085c57d1715b1049d0fb9f96797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Structures and functions related to permission checks in native code.
 *
 * @addtogroup Permission
 * @{
 */

/**
 * @file permission_manager.h
 */

#ifndef ANDROID_PERMISSION_MANAGER_H
#define ANDROID_PERMISSION_MANAGER_H

#include <sys/cdefs.h>
#include <sys/types.h>

__BEGIN_DECLS

/**
 * Permission check results.
 *
 * Introduced in API 31.
 */
enum {
    /**
     * This is returned by APermissionManager_checkPermission()
     * if the permission has been granted to the given package.
     */
    PERMISSION_MANAGER_PERMISSION_GRANTED = 0,
    /**
     * This is returned by APermissionManager_checkPermission()
     * if the permission has not been granted to the given package.
     */
    PERMISSION_MANAGER_PERMISSION_DENIED = -1,
};

/**
 * Permission check return status values.
 *
 * Introduced in API 31.
 */
enum {
    /**
     * This is returned if the permission check completed without errors.
     * The output result is valid and contains one of {::PERMISSION_MANAGER_PERMISSION_GRANTED,
     * ::PERMISSION_MANAGER_PERMISSION_DENIED}.
     */
    PERMISSION_MANAGER_STATUS_OK = 0,
    /**
     * This is returned if the permission check encountered an unspecified error.
     * The output result is unmodified.
     */
    PERMISSION_MANAGER_STATUS_ERROR_UNKNOWN = -1,
    /**
     * This is returned if the permission check failed because the service is
     * unavailable. The output result is unmodified.
     */
    PERMISSION_MANAGER_STATUS_SERVICE_UNAVAILABLE = -2,
};

/**
 * Checks whether the package with the given pid/uid has been granted a permission.
 *
 * Note that the Java API of Context#checkPermission() is usually faster due to caching,
 * thus is preferred over this API wherever possible.
 *
 * @param permission the permission to be checked.
 * @param pid the process id of the package to be checked.
 * @param uid the uid of the package to be checked.
 * @param outResult output of the permission check result.
 *
 * @return error codes if any error happened during the check.
 */
int32_t APermissionManager_checkPermission(const char* permission,
                                           pid_t pid,
                                           uid_t uid,
                                           int32_t* outResult) __INTRODUCED_IN(31);

__END_DECLS

#endif  // ANDROID_PERMISSION_MANAGER_H

/** @} */