Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Ramachandran | 4d4c8b7 | 2014-06-20 11:59:40 -0700 | [diff] [blame] | 17 | #ifndef NETD_INCLUDE_PERMISSION_H |
| 18 | #define NETD_INCLUDE_PERMISSION_H |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 19 | |
Dan Albert | 648cf02 | 2017-10-11 11:42:52 -0700 | [diff] [blame] | 20 | #include <string.h> |
| 21 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 22 | // 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 Ramachandran | 379bd33 | 2014-04-10 19:58:06 -0700 | [diff] [blame] | 27 | // Permissions are flags that can be OR'ed together to represent combinations of permissions. |
| 28 | // |
Sreeram Ramachandran | ed4bd1f | 2014-07-05 12:31:05 -0700 | [diff] [blame] | 29 | // 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 Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 38 | enum Permission { |
Sreeram Ramachandran | ed4bd1f | 2014-07-05 12:31:05 -0700 | [diff] [blame] | 39 | PERMISSION_NONE = 0x0, |
| 40 | PERMISSION_NETWORK = 0x1, |
| 41 | PERMISSION_SYSTEM = 0x3, // Includes PERMISSION_NETWORK. |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Lorenzo Colitti | 1f28b64 | 2016-09-26 17:17:40 +0900 | [diff] [blame] | 44 | inline 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 Ramachandran | 4d4c8b7 | 2014-06-20 11:59:40 -0700 | [diff] [blame] | 54 | #endif // NETD_INCLUDE_PERMISSION_H |