xref: /aosp_15_r20/system/netd/include/Permission.h (revision 8542734a0dd1db395a4d42aae09c37f3c3c3e7a1)
1*8542734aSAndroid Build Coastguard Worker /*
2*8542734aSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*8542734aSAndroid Build Coastguard Worker  *
4*8542734aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8542734aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8542734aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8542734aSAndroid Build Coastguard Worker  *
8*8542734aSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*8542734aSAndroid Build Coastguard Worker  *
10*8542734aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8542734aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8542734aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8542734aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8542734aSAndroid Build Coastguard Worker  * limitations under the License.
15*8542734aSAndroid Build Coastguard Worker  */
16*8542734aSAndroid Build Coastguard Worker 
17*8542734aSAndroid Build Coastguard Worker #ifndef NETD_INCLUDE_PERMISSION_H
18*8542734aSAndroid Build Coastguard Worker #define NETD_INCLUDE_PERMISSION_H
19*8542734aSAndroid Build Coastguard Worker 
20*8542734aSAndroid Build Coastguard Worker #include <string.h>
21*8542734aSAndroid Build Coastguard Worker 
22*8542734aSAndroid Build Coastguard Worker // This enum represents the permissions we care about for networking. When applied to an app, it's
23*8542734aSAndroid Build Coastguard Worker // the permission the app (UID) has been granted. When applied to a network, it's the permission an
24*8542734aSAndroid Build Coastguard Worker // app must hold to be allowed to use the network. PERMISSION_NONE means "no special permission is
25*8542734aSAndroid Build Coastguard Worker // held by the app" or "no special permission is required to use the network".
26*8542734aSAndroid Build Coastguard Worker //
27*8542734aSAndroid Build Coastguard Worker // Permissions are flags that can be OR'ed together to represent combinations of permissions.
28*8542734aSAndroid Build Coastguard Worker //
29*8542734aSAndroid Build Coastguard Worker // PERMISSION_NONE is used for regular networks and apps, such as those that hold the
30*8542734aSAndroid Build Coastguard Worker // android.permission.INTERNET framework permission.
31*8542734aSAndroid Build Coastguard Worker //
32*8542734aSAndroid Build Coastguard Worker // PERMISSION_NETWORK is used for privileged networks and apps that can manipulate or access them,
33*8542734aSAndroid Build Coastguard Worker // such as those that hold the android.permission.CHANGE_NETWORK_STATE framework permission.
34*8542734aSAndroid Build Coastguard Worker //
35*8542734aSAndroid Build Coastguard Worker // PERMISSION_SYSTEM is used for system apps, such as those that are installed on the system
36*8542734aSAndroid Build Coastguard Worker // partition, those that hold the android.permission.CONNECTIVITY_INTERNAL framework permission and
37*8542734aSAndroid Build Coastguard Worker // those whose UID is less than FIRST_APPLICATION_UID.
38*8542734aSAndroid Build Coastguard Worker enum Permission {
39*8542734aSAndroid Build Coastguard Worker     PERMISSION_NONE    = 0x0,
40*8542734aSAndroid Build Coastguard Worker     PERMISSION_NETWORK = 0x1,
41*8542734aSAndroid Build Coastguard Worker     PERMISSION_SYSTEM  = 0x3,  // Includes PERMISSION_NETWORK.
42*8542734aSAndroid Build Coastguard Worker };
43*8542734aSAndroid Build Coastguard Worker 
permissionToName(Permission permission)44*8542734aSAndroid Build Coastguard Worker inline const char *permissionToName(Permission permission) {
45*8542734aSAndroid Build Coastguard Worker     switch (permission) {
46*8542734aSAndroid Build Coastguard Worker         case PERMISSION_NONE:    return "NONE";
47*8542734aSAndroid Build Coastguard Worker         case PERMISSION_NETWORK: return "NETWORK";
48*8542734aSAndroid Build Coastguard Worker         case PERMISSION_SYSTEM:  return "SYSTEM";
49*8542734aSAndroid Build Coastguard Worker         // No default statement. We want to see errors of the form:
50*8542734aSAndroid Build Coastguard Worker         // "enumeration value 'PERMISSION_SYSTEM' not handled in switch [-Werror,-Wswitch]".
51*8542734aSAndroid Build Coastguard Worker     }
52*8542734aSAndroid Build Coastguard Worker }
53*8542734aSAndroid Build Coastguard Worker 
54*8542734aSAndroid Build Coastguard Worker #endif  // NETD_INCLUDE_PERMISSION_H
55