blob: b71593b4103aac8ccc45a9d98516f80ce8827dee [file] [log] [blame]
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -07001/*
2 * Copyright (C) 2014 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
Sreeram Ramachandran4d4c8b72014-06-20 11:59:40 -070017#ifndef NETD_INCLUDE_PERMISSION_H
18#define NETD_INCLUDE_PERMISSION_H
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070019
Dan Albert648cf022017-10-11 11:42:52 -070020#include <string.h>
21
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070022// This enum represents the permissions we care about for networking. When applied to an app, it's
23// the permission the app (UID) has been granted. When applied to a network, it's the permission an
24// app must hold to be allowed to use the network. PERMISSION_NONE means "no special permission is
25// held by the app" or "no special permission is required to use the network".
26//
Sreeram Ramachandran379bd332014-04-10 19:58:06 -070027// Permissions are flags that can be OR'ed together to represent combinations of permissions.
28//
Sreeram Ramachandraned4bd1f2014-07-05 12:31:05 -070029// PERMISSION_NONE is used for regular networks and apps, such as those that hold the
30// android.permission.INTERNET framework permission.
31//
32// PERMISSION_NETWORK is used for privileged networks and apps that can manipulate or access them,
33// such as those that hold the android.permission.CHANGE_NETWORK_STATE framework permission.
34//
35// PERMISSION_SYSTEM is used for system apps, such as those that are installed on the system
36// partition, those that hold the android.permission.CONNECTIVITY_INTERNAL framework permission and
37// those whose UID is less than FIRST_APPLICATION_UID.
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070038enum Permission {
Sreeram Ramachandraned4bd1f2014-07-05 12:31:05 -070039 PERMISSION_NONE = 0x0,
40 PERMISSION_NETWORK = 0x1,
41 PERMISSION_SYSTEM = 0x3, // Includes PERMISSION_NETWORK.
Sreeram Ramachandran5c181bf2014-04-07 14:10:04 -070042};
43
Lorenzo Colitti1f28b642016-09-26 17:17:40 +090044inline const char *permissionToName(Permission permission) {
45 switch (permission) {
46 case PERMISSION_NONE: return "NONE";
47 case PERMISSION_NETWORK: return "NETWORK";
48 case PERMISSION_SYSTEM: return "SYSTEM";
49 // No default statement. We want to see errors of the form:
50 // "enumeration value 'PERMISSION_SYSTEM' not handled in switch [-Werror,-Wswitch]".
51 }
52}
53
Sreeram Ramachandran4d4c8b72014-06-20 11:59:40 -070054#endif // NETD_INCLUDE_PERMISSION_H