Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 19 | import android.content.pm.ApplicationInfo; |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 20 | import android.content.pm.PackageManager; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageParser; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 22 | import android.content.pm.UserInfo; |
| 23 | import android.service.pm.PackageProto; |
| 24 | import android.util.proto.ProtoOutputStream; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 25 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 26 | import com.android.server.pm.permission.PermissionsState; |
| 27 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 28 | import java.io.File; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 29 | import java.util.List; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Settings data for a particular package we know about. |
| 33 | */ |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 34 | public final class PackageSetting extends PackageSettingBase { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 35 | int appId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 36 | PackageParser.Package pkg; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 37 | /** |
| 38 | * WARNING. The object reference is important. We perform integer equality and NOT |
| 39 | * object equality to check whether shared user settings are the same. |
| 40 | */ |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 41 | SharedUserSetting sharedUser; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Temporary holding space for the shared user ID. While parsing package settings, the |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 44 | * shared users tag may come after the packages. In this case, we must delay linking the |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 45 | * shared user setting with the package setting. The shared user ID lets us link the |
| 46 | * two objects. |
| 47 | */ |
| 48 | private int sharedUserId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 49 | |
| 50 | PackageSetting(String name, String realName, File codePath, File resourcePath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 51 | String legacyNativeLibraryPathString, String primaryCpuAbiString, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 52 | String secondaryCpuAbiString, String cpuAbiOverrideString, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 53 | long pVersionCode, int pkgFlags, int privateFlags, String parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 54 | List<String> childPackageNames, int sharedUserId, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 55 | long[] usesStaticLibrariesVersions) { |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 56 | super(name, realName, codePath, resourcePath, legacyNativeLibraryPathString, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 57 | primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 58 | pVersionCode, pkgFlags, privateFlags, parentPackageName, childPackageNames, |
| 59 | usesStaticLibraries, usesStaticLibrariesVersions); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 60 | this.sharedUserId = sharedUserId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
| 64 | * New instance of PackageSetting replicating the original settings. |
| 65 | * Note that it keeps the same PackageParser.Package instance. |
| 66 | */ |
| 67 | PackageSetting(PackageSetting orig) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 68 | super(orig, orig.realName); |
| 69 | doCopy(orig); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * New instance of PackageSetting replicating the original settings, but, allows specifying |
| 74 | * a real package name. |
| 75 | * Note that it keeps the same PackageParser.Package instance. |
| 76 | */ |
| 77 | PackageSetting(PackageSetting orig, String realPkgName) { |
| 78 | super(orig, realPkgName); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 79 | doCopy(orig); |
| 80 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 81 | |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 82 | public int getSharedUserId() { |
| 83 | if (sharedUser != null) { |
| 84 | return sharedUser.userId; |
| 85 | } |
| 86 | return sharedUserId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 89 | public SharedUserSetting getSharedUser() { |
| 90 | return sharedUser; |
| 91 | } |
| 92 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 93 | @Override |
| 94 | public String toString() { |
| 95 | return "PackageSetting{" |
| 96 | + Integer.toHexString(System.identityHashCode(this)) |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 97 | + " " + name + "/" + appId + "}"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 98 | } |
Jeff Sharkey | 02e4d16e | 2013-08-12 20:31:36 -0700 | [diff] [blame] | 99 | |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 100 | public void copyFrom(PackageSetting orig) { |
| 101 | super.copyFrom(orig); |
| 102 | doCopy(orig); |
| 103 | } |
| 104 | |
| 105 | private void doCopy(PackageSetting orig) { |
| 106 | appId = orig.appId; |
| 107 | pkg = orig.pkg; |
| 108 | sharedUser = orig.sharedUser; |
| 109 | sharedUserId = orig.sharedUserId; |
| 110 | } |
| 111 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 112 | @Override |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 113 | public PermissionsState getPermissionsState() { |
| 114 | return (sharedUser != null) |
| 115 | ? sharedUser.getPermissionsState() |
| 116 | : super.getPermissionsState(); |
Jeff Sharkey | 02e4d16e | 2013-08-12 20:31:36 -0700 | [diff] [blame] | 117 | } |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 118 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 119 | public PackageParser.Package getPackage() { |
| 120 | return pkg; |
| 121 | } |
| 122 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 123 | public int getAppId() { |
| 124 | return appId; |
| 125 | } |
| 126 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 127 | public void setInstallPermissionsFixed(boolean fixed) { |
| 128 | installPermissionsFixed = fixed; |
| 129 | } |
| 130 | |
| 131 | public boolean areInstallPermissionsFixed() { |
| 132 | return installPermissionsFixed; |
| 133 | } |
| 134 | |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 135 | public boolean isPrivileged() { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 136 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 137 | } |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 138 | |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 139 | public boolean isOem() { |
| 140 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0; |
| 141 | } |
| 142 | |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 143 | public boolean isVendor() { |
| 144 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0; |
| 145 | } |
| 146 | |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 147 | public boolean isProduct() { |
| 148 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT) != 0; |
| 149 | } |
| 150 | |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 151 | public boolean isProductServices() { |
| 152 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT_SERVICES) != 0; |
| 153 | } |
| 154 | |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 155 | public boolean isForwardLocked() { |
| 156 | return (pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0; |
| 157 | } |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 158 | |
| 159 | public boolean isSystem() { |
| 160 | return (pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 161 | } |
Svetoslav | d2cf3ae | 2015-04-02 16:51:55 -0700 | [diff] [blame] | 162 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 163 | public boolean isUpdatedSystem() { |
| 164 | return (pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; |
| 165 | } |
| 166 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 167 | @Override |
Svetoslav | d2cf3ae | 2015-04-02 16:51:55 -0700 | [diff] [blame] | 168 | public boolean isSharedUser() { |
| 169 | return sharedUser != null; |
| 170 | } |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 171 | |
| 172 | public boolean isMatch(int flags) { |
| 173 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
| 174 | return isSystem(); |
| 175 | } |
| 176 | return true; |
| 177 | } |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 178 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 179 | public boolean hasChildPackages() { |
| 180 | return childPackageNames != null && !childPackageNames.isEmpty(); |
| 181 | } |
| 182 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 183 | public void writeToProto(ProtoOutputStream proto, long fieldId, List<UserInfo> users) { |
| 184 | final long packageToken = proto.start(fieldId); |
| 185 | proto.write(PackageProto.NAME, (realName != null ? realName : name)); |
| 186 | proto.write(PackageProto.UID, appId); |
| 187 | proto.write(PackageProto.VERSION_CODE, versionCode); |
| 188 | proto.write(PackageProto.VERSION_STRING, pkg.mVersionName); |
| 189 | proto.write(PackageProto.INSTALL_TIME_MS, firstInstallTime); |
| 190 | proto.write(PackageProto.UPDATE_TIME_MS, lastUpdateTime); |
| 191 | proto.write(PackageProto.INSTALLER_NAME, installerPackageName); |
| 192 | |
| 193 | if (pkg != null) { |
| 194 | long splitToken = proto.start(PackageProto.SPLITS); |
| 195 | proto.write(PackageProto.SplitProto.NAME, "base"); |
| 196 | proto.write(PackageProto.SplitProto.REVISION_CODE, pkg.baseRevisionCode); |
| 197 | proto.end(splitToken); |
| 198 | if (pkg.splitNames != null) { |
| 199 | for (int i = 0; i < pkg.splitNames.length; i++) { |
| 200 | splitToken = proto.start(PackageProto.SPLITS); |
| 201 | proto.write(PackageProto.SplitProto.NAME, pkg.splitNames[i]); |
| 202 | proto.write(PackageProto.SplitProto.REVISION_CODE, pkg.splitRevisionCodes[i]); |
| 203 | proto.end(splitToken); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | writeUsersInfoToProto(proto, PackageProto.USERS); |
| 208 | proto.end(packageToken); |
| 209 | } |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 210 | |
| 211 | /** Updates all fields in the current setting from another. */ |
| 212 | public void updateFrom(PackageSetting other) { |
| 213 | super.updateFrom(other); |
| 214 | appId = other.appId; |
| 215 | pkg = other.pkg; |
| 216 | sharedUserId = other.sharedUserId; |
| 217 | sharedUser = other.sharedUser; |
| 218 | } |
Jeff Sharkey | 02e4d16e | 2013-08-12 20:31:36 -0700 | [diff] [blame] | 219 | } |