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 | |
| 19 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 20 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 21 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 22 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 23 | import android.content.pm.IntentFilterVerificationInfo; |
| 24 | import android.content.pm.PackageManager; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageUserState; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 26 | import android.os.storage.VolumeInfo; |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 27 | import android.util.ArraySet; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 28 | import android.util.SparseArray; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 29 | |
| 30 | import java.io.File; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Settings base class for pending and resolved classes. |
| 34 | */ |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 35 | abstract class PackageSettingBase extends SettingBase { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Indicates the state of installation. Used by PackageManager to figure out |
| 38 | * incomplete installations. Say a package is being installed (the state is |
| 39 | * set to PKG_INSTALL_INCOMPLETE) and remains so till the package |
| 40 | * installation is successful or unsuccessful in which case the |
| 41 | * PackageManager will no longer maintain state information associated with |
| 42 | * the package. If some exception(like device freeze or battery being pulled |
| 43 | * out) occurs during installation of a package, the PackageManager needs |
| 44 | * this information to clean up the previously failed installation. |
| 45 | */ |
| 46 | static final int PKG_INSTALL_COMPLETE = 1; |
| 47 | static final int PKG_INSTALL_INCOMPLETE = 0; |
| 48 | |
| 49 | final String name; |
| 50 | final String realName; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Path where this package was found on disk. For monolithic packages |
| 54 | * this is path to single base APK file; for cluster packages this is |
| 55 | * path to the cluster directory. |
| 56 | */ |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 57 | File codePath; |
| 58 | String codePathString; |
| 59 | File resourcePath; |
| 60 | String resourcePathString; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 61 | |
| 62 | /** |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 63 | * The path under which native libraries have been unpacked. This path is |
| 64 | * always derived at runtime, and is only stored here for cleanup when a |
| 65 | * package is uninstalled. |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 66 | */ |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 67 | @Deprecated |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 68 | String legacyNativeLibraryPathString; |
| 69 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 70 | /** |
| 71 | * The primary CPU abi for this package. This value is regenerated at every |
| 72 | * boot scan. |
| 73 | */ |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 74 | String primaryCpuAbiString; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * The secondary CPU abi for this package. This value is regenerated at every |
| 78 | * boot scan. |
| 79 | */ |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 80 | String secondaryCpuAbiString; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * The install time CPU override, if any. This value is written at install time |
| 84 | * and doesn't change during the life of an install. If non-null, |
| 85 | * {@code primaryCpuAbiString} will contain the same value. |
| 86 | */ |
| 87 | String cpuAbiOverrideString; |
| 88 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 89 | long timeStamp; |
| 90 | long firstInstallTime; |
| 91 | long lastUpdateTime; |
| 92 | int versionCode; |
| 93 | |
| 94 | boolean uidError; |
| 95 | |
| 96 | PackageSignatures signatures = new PackageSignatures(); |
| 97 | |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 98 | boolean installPermissionsFixed; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 99 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 100 | PackageKeySetData keySetData = new PackageKeySetData(); |
| 101 | |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 102 | private static final PackageUserState DEFAULT_USER_STATE = new PackageUserState(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 103 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 104 | // Whether this package is currently stopped, thus can not be |
| 105 | // started until explicitly launched by the user. |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 106 | private final SparseArray<PackageUserState> userState = new SparseArray<PackageUserState>(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 107 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 108 | int installStatus = PKG_INSTALL_COMPLETE; |
| 109 | |
Jeff Sharkey | e31b820 | 2015-04-29 21:44:57 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Non-persisted value indicating this package has been temporarily frozen, |
| 112 | * usually during a critical section of the package update pipeline. The |
| 113 | * platform will refuse to launch packages in a frozen state. |
| 114 | */ |
| 115 | boolean frozen = false; |
| 116 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 117 | PackageSettingBase origPackage; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 118 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 119 | /** Package name of the app that installed this package */ |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 120 | String installerPackageName; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 121 | /** UUID of {@link VolumeInfo} hosting this app */ |
| 122 | String volumeUuid; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 123 | |
| 124 | IntentFilterVerificationInfo verificationInfo; |
| 125 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 126 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 127 | String legacyNativeLibraryPathString, String primaryCpuAbiString, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 128 | String secondaryCpuAbiString, String cpuAbiOverrideString, |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 129 | int pVersionCode, int pkgFlags, int pkgPrivateFlags) { |
| 130 | super(pkgFlags, pkgPrivateFlags); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 131 | this.name = name; |
| 132 | this.realName = realName; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 133 | init(codePath, resourcePath, legacyNativeLibraryPathString, primaryCpuAbiString, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 134 | secondaryCpuAbiString, cpuAbiOverrideString, pVersionCode); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
| 138 | * New instance of PackageSetting with one-level-deep cloning. |
| 139 | */ |
| 140 | @SuppressWarnings("unchecked") |
| 141 | PackageSettingBase(PackageSettingBase base) { |
| 142 | super(base); |
| 143 | |
| 144 | name = base.name; |
| 145 | realName = base.realName; |
| 146 | codePath = base.codePath; |
| 147 | codePathString = base.codePathString; |
| 148 | resourcePath = base.resourcePath; |
| 149 | resourcePathString = base.resourcePathString; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 150 | legacyNativeLibraryPathString = base.legacyNativeLibraryPathString; |
| 151 | primaryCpuAbiString = base.primaryCpuAbiString; |
| 152 | secondaryCpuAbiString = base.secondaryCpuAbiString; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 153 | cpuAbiOverrideString = base.cpuAbiOverrideString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 154 | timeStamp = base.timeStamp; |
| 155 | firstInstallTime = base.firstInstallTime; |
| 156 | lastUpdateTime = base.lastUpdateTime; |
| 157 | versionCode = base.versionCode; |
| 158 | |
| 159 | uidError = base.uidError; |
| 160 | |
| 161 | signatures = new PackageSignatures(base.signatures); |
| 162 | |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 163 | installPermissionsFixed = base.installPermissionsFixed; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 164 | userState.clear(); |
| 165 | for (int i=0; i<base.userState.size(); i++) { |
| 166 | userState.put(base.userState.keyAt(i), |
| 167 | new PackageUserState(base.userState.valueAt(i))); |
| 168 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 169 | installStatus = base.installStatus; |
| 170 | |
| 171 | origPackage = base.origPackage; |
| 172 | |
| 173 | installerPackageName = base.installerPackageName; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 174 | volumeUuid = base.volumeUuid; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 175 | |
| 176 | keySetData = new PackageKeySetData(base.keySetData); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 179 | void init(File codePath, File resourcePath, String legacyNativeLibraryPathString, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 180 | String primaryCpuAbiString, String secondaryCpuAbiString, |
| 181 | String cpuAbiOverrideString, int pVersionCode) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 182 | this.codePath = codePath; |
| 183 | this.codePathString = codePath.toString(); |
| 184 | this.resourcePath = resourcePath; |
| 185 | this.resourcePathString = resourcePath.toString(); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 186 | this.legacyNativeLibraryPathString = legacyNativeLibraryPathString; |
| 187 | this.primaryCpuAbiString = primaryCpuAbiString; |
| 188 | this.secondaryCpuAbiString = secondaryCpuAbiString; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 189 | this.cpuAbiOverrideString = cpuAbiOverrideString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 190 | this.versionCode = pVersionCode; |
| 191 | } |
| 192 | |
| 193 | public void setInstallerPackageName(String packageName) { |
| 194 | installerPackageName = packageName; |
| 195 | } |
| 196 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 197 | public String getInstallerPackageName() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 198 | return installerPackageName; |
| 199 | } |
| 200 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 201 | public void setVolumeUuid(String volumeUuid) { |
| 202 | this.volumeUuid = volumeUuid; |
| 203 | } |
| 204 | |
| 205 | public String getVolumeUuid() { |
| 206 | return volumeUuid; |
| 207 | } |
| 208 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 209 | public void setInstallStatus(int newStatus) { |
| 210 | installStatus = newStatus; |
| 211 | } |
| 212 | |
| 213 | public int getInstallStatus() { |
| 214 | return installStatus; |
| 215 | } |
| 216 | |
| 217 | public void setTimeStamp(long newStamp) { |
| 218 | timeStamp = newStamp; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Make a shallow copy of this package settings. |
| 223 | */ |
| 224 | public void copyFrom(PackageSettingBase base) { |
Svet Ganov | 37f0518 | 2015-03-31 16:52:11 -0700 | [diff] [blame] | 225 | mPermissionsState.copyFrom(base.mPermissionsState); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 226 | primaryCpuAbiString = base.primaryCpuAbiString; |
| 227 | secondaryCpuAbiString = base.secondaryCpuAbiString; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 228 | cpuAbiOverrideString = base.cpuAbiOverrideString; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 229 | timeStamp = base.timeStamp; |
| 230 | firstInstallTime = base.firstInstallTime; |
| 231 | lastUpdateTime = base.lastUpdateTime; |
| 232 | signatures = base.signatures; |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 233 | installPermissionsFixed = base.installPermissionsFixed; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 234 | userState.clear(); |
| 235 | for (int i=0; i<base.userState.size(); i++) { |
| 236 | userState.put(base.userState.keyAt(i), base.userState.valueAt(i)); |
| 237 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 238 | installStatus = base.installStatus; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 239 | keySetData = base.keySetData; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 240 | verificationInfo = base.verificationInfo; |
hyemin.hwang | b4faf98 | 2015-07-09 09:16:12 +0900 | [diff] [blame] | 241 | installerPackageName = base.installerPackageName; |
Jeff Sharkey | 3b1c6e0 | 2015-10-31 13:58:54 -0700 | [diff] [blame] | 242 | volumeUuid = base.volumeUuid; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 245 | private PackageUserState modifyUserState(int userId) { |
| 246 | PackageUserState state = userState.get(userId); |
| 247 | if (state == null) { |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 248 | state = new PackageUserState(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 249 | userState.put(userId, state); |
| 250 | } |
| 251 | return state; |
| 252 | } |
| 253 | |
| 254 | public PackageUserState readUserState(int userId) { |
| 255 | PackageUserState state = userState.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 256 | if (state != null) { |
| 257 | return state; |
| 258 | } |
Dianne Hackborn | 4a9f071 | 2012-10-02 15:29:06 -0700 | [diff] [blame] | 259 | return DEFAULT_USER_STATE; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 262 | void setEnabled(int state, int userId, String callingPackage) { |
| 263 | PackageUserState st = modifyUserState(userId); |
| 264 | st.enabled = state; |
| 265 | st.lastDisableAppCaller = callingPackage; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | int getEnabled(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 269 | return readUserState(userId).enabled; |
| 270 | } |
| 271 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 272 | String getLastDisabledAppCaller(int userId) { |
| 273 | return readUserState(userId).lastDisableAppCaller; |
| 274 | } |
| 275 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 276 | void setInstalled(boolean inst, int userId) { |
| 277 | modifyUserState(userId).installed = inst; |
| 278 | } |
| 279 | |
| 280 | boolean getInstalled(int userId) { |
| 281 | return readUserState(userId).installed; |
| 282 | } |
| 283 | |
| 284 | boolean isAnyInstalled(int[] users) { |
| 285 | for (int user: users) { |
| 286 | if (readUserState(user).installed) { |
| 287 | return true; |
| 288 | } |
| 289 | } |
| 290 | return false; |
| 291 | } |
| 292 | |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 293 | int[] queryInstalledUsers(int[] users, boolean installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 294 | int num = 0; |
| 295 | for (int user : users) { |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 296 | if (getInstalled(user) == installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 297 | num++; |
| 298 | } |
| 299 | } |
| 300 | int[] res = new int[num]; |
| 301 | num = 0; |
| 302 | for (int user : users) { |
Dianne Hackborn | 786b440 | 2012-08-27 15:14:02 -0700 | [diff] [blame] | 303 | if (getInstalled(user) == installed) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 304 | res[num] = user; |
| 305 | num++; |
| 306 | } |
| 307 | } |
| 308 | return res; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | boolean getStopped(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 312 | return readUserState(userId).stopped; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void setStopped(boolean stop, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 316 | modifyUserState(userId).stopped = stop; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | boolean getNotLaunched(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 320 | return readUserState(userId).notLaunched; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void setNotLaunched(boolean stop, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 324 | modifyUserState(userId).notLaunched = stop; |
| 325 | } |
| 326 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 327 | boolean getHidden(int userId) { |
| 328 | return readUserState(userId).hidden; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 331 | void setHidden(boolean hidden, int userId) { |
| 332 | modifyUserState(userId).hidden = hidden; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 335 | boolean getSuspended(int userId) { |
| 336 | return readUserState(userId).suspended; |
| 337 | } |
| 338 | |
| 339 | void setSuspended(boolean suspended, int userId) { |
| 340 | modifyUserState(userId).suspended = suspended; |
| 341 | } |
| 342 | |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 343 | boolean getBlockUninstall(int userId) { |
| 344 | return readUserState(userId).blockUninstall; |
| 345 | } |
| 346 | |
| 347 | void setBlockUninstall(boolean blockUninstall, int userId) { |
| 348 | modifyUserState(userId).blockUninstall = blockUninstall; |
| 349 | } |
| 350 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 351 | void setUserState(int userId, int enabled, boolean installed, boolean stopped, |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 352 | boolean notLaunched, boolean hidden, boolean suspended, |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 353 | String lastDisableAppCaller, ArraySet<String> enabledComponents, |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 354 | ArraySet<String> disabledComponents, boolean blockUninstall, int domainVerifState, |
| 355 | int linkGeneration) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 356 | PackageUserState state = modifyUserState(userId); |
| 357 | state.enabled = enabled; |
| 358 | state.installed = installed; |
| 359 | state.stopped = stopped; |
| 360 | state.notLaunched = notLaunched; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 361 | state.hidden = hidden; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 362 | state.suspended = suspended; |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 363 | state.lastDisableAppCaller = lastDisableAppCaller; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 364 | state.enabledComponents = enabledComponents; |
| 365 | state.disabledComponents = disabledComponents; |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 366 | state.blockUninstall = blockUninstall; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 367 | state.domainVerificationStatus = domainVerifState; |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 368 | state.appLinkGeneration = linkGeneration; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 371 | ArraySet<String> getEnabledComponents(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 372 | return readUserState(userId).enabledComponents; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 375 | ArraySet<String> getDisabledComponents(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 376 | return readUserState(userId).disabledComponents; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 379 | void setEnabledComponents(ArraySet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 380 | modifyUserState(userId).enabledComponents = components; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 383 | void setDisabledComponents(ArraySet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 384 | modifyUserState(userId).disabledComponents = components; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 387 | void setEnabledComponentsCopy(ArraySet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 388 | modifyUserState(userId).enabledComponents = components != null |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 389 | ? new ArraySet<String>(components) : null; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 392 | void setDisabledComponentsCopy(ArraySet<String> components, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 393 | modifyUserState(userId).disabledComponents = components != null |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 394 | ? new ArraySet<String>(components) : null; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | PackageUserState modifyUserStateComponents(int userId, boolean disabled, boolean enabled) { |
| 398 | PackageUserState state = modifyUserState(userId); |
| 399 | if (disabled && state.disabledComponents == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 400 | state.disabledComponents = new ArraySet<String>(1); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 401 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 402 | if (enabled && state.enabledComponents == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 403 | state.enabledComponents = new ArraySet<String>(1); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 404 | } |
| 405 | return state; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void addDisabledComponent(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 409 | modifyUserStateComponents(userId, true, false).disabledComponents.add(componentClassName); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | void addEnabledComponent(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 413 | modifyUserStateComponents(userId, false, true).enabledComponents.add(componentClassName); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | boolean enableComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 417 | PackageUserState state = modifyUserStateComponents(userId, false, true); |
| 418 | boolean changed = state.disabledComponents != null |
| 419 | ? state.disabledComponents.remove(componentClassName) : false; |
| 420 | changed |= state.enabledComponents.add(componentClassName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 421 | return changed; |
| 422 | } |
| 423 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 424 | boolean disableComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 425 | PackageUserState state = modifyUserStateComponents(userId, true, false); |
| 426 | boolean changed = state.enabledComponents != null |
| 427 | ? state.enabledComponents.remove(componentClassName) : false; |
| 428 | changed |= state.disabledComponents.add(componentClassName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 429 | return changed; |
| 430 | } |
| 431 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 432 | boolean restoreComponentLPw(String componentClassName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 433 | PackageUserState state = modifyUserStateComponents(userId, true, true); |
| 434 | boolean changed = state.disabledComponents != null |
| 435 | ? state.disabledComponents.remove(componentClassName) : false; |
| 436 | changed |= state.enabledComponents != null |
| 437 | ? state.enabledComponents.remove(componentClassName) : false; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 438 | return changed; |
| 439 | } |
| 440 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 441 | int getCurrentEnabledStateLPr(String componentName, int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 442 | PackageUserState state = readUserState(userId); |
| 443 | if (state.enabledComponents != null && state.enabledComponents.contains(componentName)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 444 | return COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 445 | } else if (state.disabledComponents != null |
| 446 | && state.disabledComponents.contains(componentName)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 447 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 448 | } else { |
| 449 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 450 | } |
| 451 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 452 | |
| 453 | void removeUser(int userId) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 454 | userState.delete(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 455 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 456 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 457 | IntentFilterVerificationInfo getIntentFilterVerificationInfo() { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 458 | return verificationInfo; |
| 459 | } |
| 460 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 461 | void setIntentFilterVerificationInfo(IntentFilterVerificationInfo info) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 462 | verificationInfo = info; |
| 463 | } |
| 464 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 465 | // Returns a packed value as a long: |
| 466 | // |
| 467 | // high 'int'-sized word: link status: undefined/ask/never/always. |
| 468 | // low 'int'-sized word: relative priority among 'always' results. |
| 469 | long getDomainVerificationStatusForUser(int userId) { |
| 470 | PackageUserState state = readUserState(userId); |
| 471 | long result = (long) state.appLinkGeneration; |
| 472 | result |= ((long) state.domainVerificationStatus) << 32; |
| 473 | return result; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 476 | void setDomainVerificationStatusForUser(final int status, int generation, int userId) { |
| 477 | PackageUserState state = modifyUserState(userId); |
| 478 | state.domainVerificationStatus = status; |
| 479 | if (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { |
| 480 | state.appLinkGeneration = generation; |
| 481 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 484 | void clearDomainVerificationStatusForUser(int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 485 | modifyUserState(userId).domainVerificationStatus = |
| 486 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
| 487 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 488 | } |