blob: 07c9dec7b3532cd0a0718a7d200b47b4adbb5995 [file] [log] [blame]
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001/*
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
17package com.android.server.pm;
18
19import android.content.pm.PackageParser;
20import android.content.pm.PermissionInfo;
Jeff Sharkey00f39042015-03-23 16:51:22 -070021import android.os.UserHandle;
22
Kenny Rootcf0b38c2011-03-22 14:17:59 -070023final 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 Sharkey00f39042015-03-23 16:51:22 -070044 /** UID that owns the definition of this permission */
Kenny Rootcf0b38c2011-03-22 14:17:59 -070045 int uid;
46
Jeff Sharkey00f39042015-03-23 16:51:22 -070047 /** 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 Rootcf0b38c2011-03-22 14:17:59 -070055
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 Sharkey00f39042015-03-23 16:51:22 -070064 @Override
Kenny Rootcf0b38c2011-03-22 14:17:59 -070065 public String toString() {
66 return "BasePermission{" + Integer.toHexString(System.identityHashCode(this)) + " " + name
67 + "}";
68 }
Svetoslavc6d1c342015-02-26 14:44:43 -080069
Jeff Sharkey00f39042015-03-23 16:51:22 -070070 public void setGids(int[] gids, boolean perUser) {
71 this.gids = gids;
72 this.perUser = perUser;
73 }
74
Jeff Sharkey00f39042015-03-23 16:51:22 -070075 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
Svetoslavc6d1c342015-02-26 14:44:43 -080087 public boolean isRuntime() {
88 return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
89 == PermissionInfo.PROTECTION_DANGEROUS;
90 }
Dianne Hackborn9f5b0a22015-08-13 18:25:20 -070091
92 public boolean isDevelopment() {
93 return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
94 == PermissionInfo.PROTECTION_SIGNATURE
95 && (protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
96 }
Chad Brubakerc19706a2016-10-13 15:44:59 -070097
Svetoslav Ganov096d3042017-01-30 16:34:13 -080098 public boolean isInstant() {
Chad Brubakerc19706a2016-10-13 15:44:59 -070099 return (protectionLevel & PermissionInfo.PROTECTION_FLAG_EPHEMERAL) != 0;
100 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700101}