Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import android.content.pm.PackageParser; |
| 20 | import android.content.pm.PermissionInfo; |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 21 | import android.os.UserHandle; |
| 22 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 23 | final class BasePermission { |
| 24 | final static int TYPE_NORMAL = 0; |
| 25 | |
| 26 | final static int TYPE_BUILTIN = 1; |
| 27 | |
| 28 | final static int TYPE_DYNAMIC = 2; |
| 29 | |
| 30 | final String name; |
| 31 | |
| 32 | String sourcePackage; |
| 33 | |
| 34 | PackageSettingBase packageSetting; |
| 35 | |
| 36 | final int type; |
| 37 | |
| 38 | int protectionLevel; |
| 39 | |
| 40 | PackageParser.Permission perm; |
| 41 | |
| 42 | PermissionInfo pendingInfo; |
| 43 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 44 | /** UID that owns the definition of this permission */ |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 45 | int uid; |
| 46 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 47 | /** Additional GIDs given to apps granted this permission */ |
| 48 | private int[] gids; |
| 49 | |
| 50 | /** |
| 51 | * Flag indicating that {@link #gids} should be adjusted based on the |
| 52 | * {@link UserHandle} the granted app is running as. |
| 53 | */ |
| 54 | private boolean perUser; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 55 | |
| 56 | BasePermission(String _name, String _sourcePackage, int _type) { |
| 57 | name = _name; |
| 58 | sourcePackage = _sourcePackage; |
| 59 | type = _type; |
| 60 | // Default to most conservative protection level. |
| 61 | protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; |
| 62 | } |
| 63 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 64 | @Override |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 65 | public String toString() { |
| 66 | return "BasePermission{" + Integer.toHexString(System.identityHashCode(this)) + " " + name |
| 67 | + "}"; |
| 68 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 69 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 70 | public void setGids(int[] gids, boolean perUser) { |
| 71 | this.gids = gids; |
| 72 | this.perUser = perUser; |
| 73 | } |
| 74 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 75 | public int[] computeGids(int userId) { |
| 76 | if (perUser) { |
| 77 | final int[] userGids = new int[gids.length]; |
| 78 | for (int i = 0; i < gids.length; i++) { |
| 79 | userGids[i] = UserHandle.getUid(userId, gids[i]); |
| 80 | } |
| 81 | return userGids; |
| 82 | } else { |
| 83 | return gids; |
| 84 | } |
| 85 | } |
| 86 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 87 | public boolean isRuntime() { |
| 88 | return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE) |
| 89 | == PermissionInfo.PROTECTION_DANGEROUS; |
| 90 | } |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 91 | |
| 92 | public boolean isDevelopment() { |
| 93 | return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE) |
| 94 | == PermissionInfo.PROTECTION_SIGNATURE |
| 95 | && (protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0; |
| 96 | } |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 97 | |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 98 | public boolean isInstant() { |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 99 | return (protectionLevel & PermissionInfo.PROTECTION_FLAG_EPHEMERAL) != 0; |
| 100 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 101 | } |