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 23 import android.content.pm.ApplicationInfo; 24 import android.content.pm.IntentFilterVerificationInfo; 25 import android.content.pm.PackageManager; 26 import android.content.pm.PackageParser; 27 import android.content.pm.PackageUserState; 28 import android.content.pm.Signature; 29 import android.content.pm.SuspendDialogInfo; 30 import android.os.PersistableBundle; 31 import android.service.pm.PackageProto; 32 import android.util.ArraySet; 33 import android.util.SparseArray; 34 import android.util.proto.ProtoOutputStream; 35 36 import com.android.internal.annotations.VisibleForTesting; 37 38 import java.io.File; 39 import java.util.ArrayList; 40 import java.util.Arrays; 41 import java.util.List; 42 import java.util.Set; 43 44 /** 45 * Settings base class for pending and resolved classes. 46 */ 47 public abstract class PackageSettingBase extends SettingBase { 48 49 private static final int[] EMPTY_INT_ARRAY = new int[0]; 50 51 public final String name; 52 final String realName; 53 54 String parentPackageName; 55 List<String> childPackageNames; 56 57 /** 58 * Path where this package was found on disk. For monolithic packages 59 * this is path to single base APK file; for cluster packages this is 60 * path to the cluster directory. 61 */ 62 File codePath; 63 String codePathString; 64 File resourcePath; 65 String resourcePathString; 66 67 String[] usesStaticLibraries; 68 long[] usesStaticLibrariesVersions; 69 70 /** 71 * The path under which native libraries have been unpacked. This path is 72 * always derived at runtime, and is only stored here for cleanup when a 73 * package is uninstalled. 74 */ 75 @Deprecated 76 String legacyNativeLibraryPathString; 77 78 /** 79 * The primary CPU abi for this package. 80 */ 81 String primaryCpuAbiString; 82 83 /** 84 * The secondary CPU abi for this package. 85 */ 86 String secondaryCpuAbiString; 87 88 /** 89 * The install time CPU override, if any. This value is written at install time 90 * and doesn't change during the life of an install. If non-null, 91 * {@code primaryCpuAbiString} will contain the same value. 92 */ 93 String cpuAbiOverrideString; 94 95 long timeStamp; 96 long firstInstallTime; 97 long lastUpdateTime; 98 long versionCode; 99 100 boolean uidError; 101 102 PackageSignatures signatures; 103 104 boolean installPermissionsFixed; 105 106 PackageKeySetData keySetData = new PackageKeySetData(); 107 108 static final PackageUserState DEFAULT_USER_STATE = new PackageUserState(); 109 110 // Whether this package is currently stopped, thus can not be 111 // started until explicitly launched by the user. 112 private final SparseArray<PackageUserState> mUserState = new SparseArray<>(); 113 114 /** 115 * Non-persisted value. During an "upgrade without restart", we need the set 116 * of all previous code paths so we can surgically add the new APKs to the 117 * active classloader. If at any point an application is upgraded with a 118 * restart, this field will be cleared since the classloader would be created 119 * using the full set of code paths when the package's process is started. 120 */ 121 Set<String> mOldCodePaths; 122 123 /** Package name of the app that installed this package */ 124 String installerPackageName; 125 /** Indicates if the package that installed this app has been uninstalled */ 126 boolean isOrphaned; 127 /** UUID of {@link VolumeInfo} hosting this app */ 128 String volumeUuid; 129 /** The category of this app, as hinted by the installer */ 130 int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED; 131 /** Whether or not an update is available. Ostensibly only for instant apps. */ 132 boolean updateAvailable; 133 134 IntentFilterVerificationInfo verificationInfo; 135 PackageSettingBase(String name, String realName, File codePath, File resourcePath, String legacyNativeLibraryPathString, String primaryCpuAbiString, String secondaryCpuAbiString, String cpuAbiOverrideString, long pVersionCode, int pkgFlags, int pkgPrivateFlags, String parentPackageName, List<String> childPackageNames, String[] usesStaticLibraries, long[] usesStaticLibrariesVersions)136 PackageSettingBase(String name, String realName, File codePath, File resourcePath, 137 String legacyNativeLibraryPathString, String primaryCpuAbiString, 138 String secondaryCpuAbiString, String cpuAbiOverrideString, 139 long pVersionCode, int pkgFlags, int pkgPrivateFlags, 140 String parentPackageName, List<String> childPackageNames, 141 String[] usesStaticLibraries, long[] usesStaticLibrariesVersions) { 142 super(pkgFlags, pkgPrivateFlags); 143 this.name = name; 144 this.realName = realName; 145 this.parentPackageName = parentPackageName; 146 this.childPackageNames = (childPackageNames != null) 147 ? new ArrayList<>(childPackageNames) : null; 148 this.usesStaticLibraries = usesStaticLibraries; 149 this.usesStaticLibrariesVersions = usesStaticLibrariesVersions; 150 init(codePath, resourcePath, legacyNativeLibraryPathString, primaryCpuAbiString, 151 secondaryCpuAbiString, cpuAbiOverrideString, pVersionCode); 152 } 153 154 /** 155 * New instance of PackageSetting with one-level-deep cloning. 156 * <p> 157 * IMPORTANT: With a shallow copy, we do NOT create new contained objects. 158 * This means, for example, changes to the user state of the original PackageSetting 159 * will also change the user state in its copy. 160 */ PackageSettingBase(PackageSettingBase base, String realName)161 PackageSettingBase(PackageSettingBase base, String realName) { 162 super(base); 163 name = base.name; 164 this.realName = realName; 165 doCopy(base); 166 } 167 init(File codePath, File resourcePath, String legacyNativeLibraryPathString, String primaryCpuAbiString, String secondaryCpuAbiString, String cpuAbiOverrideString, long pVersionCode)168 void init(File codePath, File resourcePath, String legacyNativeLibraryPathString, 169 String primaryCpuAbiString, String secondaryCpuAbiString, 170 String cpuAbiOverrideString, long pVersionCode) { 171 this.codePath = codePath; 172 this.codePathString = codePath.toString(); 173 this.resourcePath = resourcePath; 174 this.resourcePathString = resourcePath.toString(); 175 this.legacyNativeLibraryPathString = legacyNativeLibraryPathString; 176 this.primaryCpuAbiString = primaryCpuAbiString; 177 this.secondaryCpuAbiString = secondaryCpuAbiString; 178 this.cpuAbiOverrideString = cpuAbiOverrideString; 179 this.versionCode = pVersionCode; 180 this.signatures = new PackageSignatures(); 181 } 182 setInstallerPackageName(String packageName)183 public void setInstallerPackageName(String packageName) { 184 installerPackageName = packageName; 185 } 186 getInstallerPackageName()187 public String getInstallerPackageName() { 188 return installerPackageName; 189 } 190 setVolumeUuid(String volumeUuid)191 public void setVolumeUuid(String volumeUuid) { 192 this.volumeUuid = volumeUuid; 193 } 194 getVolumeUuid()195 public String getVolumeUuid() { 196 return volumeUuid; 197 } 198 setTimeStamp(long newStamp)199 public void setTimeStamp(long newStamp) { 200 timeStamp = newStamp; 201 } 202 setUpdateAvailable(boolean updateAvailable)203 public void setUpdateAvailable(boolean updateAvailable) { 204 this.updateAvailable = updateAvailable; 205 } 206 isUpdateAvailable()207 public boolean isUpdateAvailable() { 208 return updateAvailable; 209 } 210 isSharedUser()211 public boolean isSharedUser() { 212 return false; 213 } 214 getSignatures()215 public Signature[] getSignatures() { 216 return signatures.mSigningDetails.signatures; 217 } 218 getSigningDetails()219 public PackageParser.SigningDetails getSigningDetails() { 220 return signatures.mSigningDetails; 221 } 222 223 /** 224 * Makes a shallow copy of the given package settings. 225 * 226 * NOTE: For some fields [such as keySetData, signatures, mUserState, verificationInfo, etc...], 227 * the original object is copied and a new one is not created. 228 */ copyFrom(PackageSettingBase orig)229 public void copyFrom(PackageSettingBase orig) { 230 super.copyFrom(orig); 231 doCopy(orig); 232 } 233 doCopy(PackageSettingBase orig)234 private void doCopy(PackageSettingBase orig) { 235 childPackageNames = (orig.childPackageNames != null) 236 ? new ArrayList<>(orig.childPackageNames) : null; 237 codePath = orig.codePath; 238 codePathString = orig.codePathString; 239 cpuAbiOverrideString = orig.cpuAbiOverrideString; 240 firstInstallTime = orig.firstInstallTime; 241 installPermissionsFixed = orig.installPermissionsFixed; 242 installerPackageName = orig.installerPackageName; 243 isOrphaned = orig.isOrphaned; 244 keySetData = orig.keySetData; 245 lastUpdateTime = orig.lastUpdateTime; 246 legacyNativeLibraryPathString = orig.legacyNativeLibraryPathString; 247 // Intentionally skip mOldCodePaths; it's not relevant for copies 248 parentPackageName = orig.parentPackageName; 249 primaryCpuAbiString = orig.primaryCpuAbiString; 250 resourcePath = orig.resourcePath; 251 resourcePathString = orig.resourcePathString; 252 secondaryCpuAbiString = orig.secondaryCpuAbiString; 253 signatures = orig.signatures; 254 timeStamp = orig.timeStamp; 255 uidError = orig.uidError; 256 mUserState.clear(); 257 for (int i = 0; i < orig.mUserState.size(); i++) { 258 mUserState.put(orig.mUserState.keyAt(i), orig.mUserState.valueAt(i)); 259 } 260 verificationInfo = orig.verificationInfo; 261 versionCode = orig.versionCode; 262 volumeUuid = orig.volumeUuid; 263 categoryHint = orig.categoryHint; 264 usesStaticLibraries = orig.usesStaticLibraries != null 265 ? Arrays.copyOf(orig.usesStaticLibraries, 266 orig.usesStaticLibraries.length) : null; 267 usesStaticLibrariesVersions = orig.usesStaticLibrariesVersions != null 268 ? Arrays.copyOf(orig.usesStaticLibrariesVersions, 269 orig.usesStaticLibrariesVersions.length) : null; 270 updateAvailable = orig.updateAvailable; 271 } 272 modifyUserState(int userId)273 private PackageUserState modifyUserState(int userId) { 274 PackageUserState state = mUserState.get(userId); 275 if (state == null) { 276 state = new PackageUserState(); 277 mUserState.put(userId, state); 278 } 279 return state; 280 } 281 readUserState(int userId)282 public PackageUserState readUserState(int userId) { 283 PackageUserState state = mUserState.get(userId); 284 if (state == null) { 285 return DEFAULT_USER_STATE; 286 } 287 state.categoryHint = categoryHint; 288 return state; 289 } 290 setEnabled(int state, int userId, String callingPackage)291 void setEnabled(int state, int userId, String callingPackage) { 292 PackageUserState st = modifyUserState(userId); 293 st.enabled = state; 294 st.lastDisableAppCaller = callingPackage; 295 } 296 getEnabled(int userId)297 int getEnabled(int userId) { 298 return readUserState(userId).enabled; 299 } 300 getLastDisabledAppCaller(int userId)301 String getLastDisabledAppCaller(int userId) { 302 return readUserState(userId).lastDisableAppCaller; 303 } 304 setInstalled(boolean inst, int userId)305 void setInstalled(boolean inst, int userId) { 306 modifyUserState(userId).installed = inst; 307 } 308 getInstalled(int userId)309 boolean getInstalled(int userId) { 310 return readUserState(userId).installed; 311 } 312 getInstallReason(int userId)313 int getInstallReason(int userId) { 314 return readUserState(userId).installReason; 315 } 316 setInstallReason(int installReason, int userId)317 void setInstallReason(int installReason, int userId) { 318 modifyUserState(userId).installReason = installReason; 319 } 320 setOverlayPaths(List<String> overlayPaths, int userId)321 void setOverlayPaths(List<String> overlayPaths, int userId) { 322 modifyUserState(userId).overlayPaths = overlayPaths == null ? null : 323 overlayPaths.toArray(new String[overlayPaths.size()]); 324 } 325 getOverlayPaths(int userId)326 String[] getOverlayPaths(int userId) { 327 return readUserState(userId).overlayPaths; 328 } 329 330 /** Only use for testing. Do NOT use in production code. */ 331 @VisibleForTesting getUserState()332 SparseArray<PackageUserState> getUserState() { 333 return mUserState; 334 } 335 isAnyInstalled(int[] users)336 boolean isAnyInstalled(int[] users) { 337 for (int user: users) { 338 if (readUserState(user).installed) { 339 return true; 340 } 341 } 342 return false; 343 } 344 queryInstalledUsers(int[] users, boolean installed)345 int[] queryInstalledUsers(int[] users, boolean installed) { 346 int num = 0; 347 for (int user : users) { 348 if (getInstalled(user) == installed) { 349 num++; 350 } 351 } 352 int[] res = new int[num]; 353 num = 0; 354 for (int user : users) { 355 if (getInstalled(user) == installed) { 356 res[num] = user; 357 num++; 358 } 359 } 360 return res; 361 } 362 getCeDataInode(int userId)363 long getCeDataInode(int userId) { 364 return readUserState(userId).ceDataInode; 365 } 366 setCeDataInode(long ceDataInode, int userId)367 void setCeDataInode(long ceDataInode, int userId) { 368 modifyUserState(userId).ceDataInode = ceDataInode; 369 } 370 getStopped(int userId)371 boolean getStopped(int userId) { 372 return readUserState(userId).stopped; 373 } 374 setStopped(boolean stop, int userId)375 void setStopped(boolean stop, int userId) { 376 modifyUserState(userId).stopped = stop; 377 } 378 getNotLaunched(int userId)379 boolean getNotLaunched(int userId) { 380 return readUserState(userId).notLaunched; 381 } 382 setNotLaunched(boolean stop, int userId)383 void setNotLaunched(boolean stop, int userId) { 384 modifyUserState(userId).notLaunched = stop; 385 } 386 getHidden(int userId)387 boolean getHidden(int userId) { 388 return readUserState(userId).hidden; 389 } 390 setHidden(boolean hidden, int userId)391 void setHidden(boolean hidden, int userId) { 392 modifyUserState(userId).hidden = hidden; 393 } 394 getDistractionFlags(int userId)395 int getDistractionFlags(int userId) { 396 return readUserState(userId).distractionFlags; 397 } 398 setDistractionFlags(int distractionFlags, int userId)399 void setDistractionFlags(int distractionFlags, int userId) { 400 modifyUserState(userId).distractionFlags = distractionFlags; 401 } 402 getSuspended(int userId)403 boolean getSuspended(int userId) { 404 return readUserState(userId).suspended; 405 } 406 setSuspended(boolean suspended, String suspendingPackage, SuspendDialogInfo dialogInfo, PersistableBundle appExtras, PersistableBundle launcherExtras, int userId)407 void setSuspended(boolean suspended, String suspendingPackage, SuspendDialogInfo dialogInfo, 408 PersistableBundle appExtras, PersistableBundle launcherExtras, int userId) { 409 final PackageUserState existingUserState = modifyUserState(userId); 410 existingUserState.suspended = suspended; 411 existingUserState.suspendingPackage = suspended ? suspendingPackage : null; 412 existingUserState.dialogInfo = suspended ? dialogInfo : null; 413 existingUserState.suspendedAppExtras = suspended ? appExtras : null; 414 existingUserState.suspendedLauncherExtras = suspended ? launcherExtras : null; 415 } 416 getInstantApp(int userId)417 public boolean getInstantApp(int userId) { 418 return readUserState(userId).instantApp; 419 } 420 setInstantApp(boolean instantApp, int userId)421 void setInstantApp(boolean instantApp, int userId) { 422 modifyUserState(userId).instantApp = instantApp; 423 } 424 getVirtulalPreload(int userId)425 boolean getVirtulalPreload(int userId) { 426 return readUserState(userId).virtualPreload; 427 } 428 setVirtualPreload(boolean virtualPreload, int userId)429 void setVirtualPreload(boolean virtualPreload, int userId) { 430 modifyUserState(userId).virtualPreload = virtualPreload; 431 } 432 setUserState(int userId, long ceDataInode, int enabled, boolean installed, boolean stopped, boolean notLaunched, boolean hidden, int distractionFlags, boolean suspended, String suspendingPackage, SuspendDialogInfo dialogInfo, PersistableBundle suspendedAppExtras, PersistableBundle suspendedLauncherExtras, boolean instantApp, boolean virtualPreload, String lastDisableAppCaller, ArraySet<String> enabledComponents, ArraySet<String> disabledComponents, int domainVerifState, int linkGeneration, int installReason, String harmfulAppWarning)433 void setUserState(int userId, long ceDataInode, int enabled, boolean installed, boolean stopped, 434 boolean notLaunched, boolean hidden, int distractionFlags, boolean suspended, 435 String suspendingPackage, 436 SuspendDialogInfo dialogInfo, PersistableBundle suspendedAppExtras, 437 PersistableBundle suspendedLauncherExtras, boolean instantApp, 438 boolean virtualPreload, String lastDisableAppCaller, 439 ArraySet<String> enabledComponents, ArraySet<String> disabledComponents, 440 int domainVerifState, int linkGeneration, int installReason, 441 String harmfulAppWarning) { 442 PackageUserState state = modifyUserState(userId); 443 state.ceDataInode = ceDataInode; 444 state.enabled = enabled; 445 state.installed = installed; 446 state.stopped = stopped; 447 state.notLaunched = notLaunched; 448 state.hidden = hidden; 449 state.distractionFlags = distractionFlags; 450 state.suspended = suspended; 451 state.suspendingPackage = suspendingPackage; 452 state.dialogInfo = dialogInfo; 453 state.suspendedAppExtras = suspendedAppExtras; 454 state.suspendedLauncherExtras = suspendedLauncherExtras; 455 state.lastDisableAppCaller = lastDisableAppCaller; 456 state.enabledComponents = enabledComponents; 457 state.disabledComponents = disabledComponents; 458 state.domainVerificationStatus = domainVerifState; 459 state.appLinkGeneration = linkGeneration; 460 state.installReason = installReason; 461 state.instantApp = instantApp; 462 state.virtualPreload = virtualPreload; 463 state.harmfulAppWarning = harmfulAppWarning; 464 } 465 getEnabledComponents(int userId)466 ArraySet<String> getEnabledComponents(int userId) { 467 return readUserState(userId).enabledComponents; 468 } 469 getDisabledComponents(int userId)470 ArraySet<String> getDisabledComponents(int userId) { 471 return readUserState(userId).disabledComponents; 472 } 473 setEnabledComponents(ArraySet<String> components, int userId)474 void setEnabledComponents(ArraySet<String> components, int userId) { 475 modifyUserState(userId).enabledComponents = components; 476 } 477 setDisabledComponents(ArraySet<String> components, int userId)478 void setDisabledComponents(ArraySet<String> components, int userId) { 479 modifyUserState(userId).disabledComponents = components; 480 } 481 setEnabledComponentsCopy(ArraySet<String> components, int userId)482 void setEnabledComponentsCopy(ArraySet<String> components, int userId) { 483 modifyUserState(userId).enabledComponents = components != null 484 ? new ArraySet<String>(components) : null; 485 } 486 setDisabledComponentsCopy(ArraySet<String> components, int userId)487 void setDisabledComponentsCopy(ArraySet<String> components, int userId) { 488 modifyUserState(userId).disabledComponents = components != null 489 ? new ArraySet<String>(components) : null; 490 } 491 modifyUserStateComponents(int userId, boolean disabled, boolean enabled)492 PackageUserState modifyUserStateComponents(int userId, boolean disabled, boolean enabled) { 493 PackageUserState state = modifyUserState(userId); 494 if (disabled && state.disabledComponents == null) { 495 state.disabledComponents = new ArraySet<String>(1); 496 } 497 if (enabled && state.enabledComponents == null) { 498 state.enabledComponents = new ArraySet<String>(1); 499 } 500 return state; 501 } 502 addDisabledComponent(String componentClassName, int userId)503 void addDisabledComponent(String componentClassName, int userId) { 504 modifyUserStateComponents(userId, true, false).disabledComponents.add(componentClassName); 505 } 506 addEnabledComponent(String componentClassName, int userId)507 void addEnabledComponent(String componentClassName, int userId) { 508 modifyUserStateComponents(userId, false, true).enabledComponents.add(componentClassName); 509 } 510 enableComponentLPw(String componentClassName, int userId)511 boolean enableComponentLPw(String componentClassName, int userId) { 512 PackageUserState state = modifyUserStateComponents(userId, false, true); 513 boolean changed = state.disabledComponents != null 514 ? state.disabledComponents.remove(componentClassName) : false; 515 changed |= state.enabledComponents.add(componentClassName); 516 return changed; 517 } 518 disableComponentLPw(String componentClassName, int userId)519 boolean disableComponentLPw(String componentClassName, int userId) { 520 PackageUserState state = modifyUserStateComponents(userId, true, false); 521 boolean changed = state.enabledComponents != null 522 ? state.enabledComponents.remove(componentClassName) : false; 523 changed |= state.disabledComponents.add(componentClassName); 524 return changed; 525 } 526 restoreComponentLPw(String componentClassName, int userId)527 boolean restoreComponentLPw(String componentClassName, int userId) { 528 PackageUserState state = modifyUserStateComponents(userId, true, true); 529 boolean changed = state.disabledComponents != null 530 ? state.disabledComponents.remove(componentClassName) : false; 531 changed |= state.enabledComponents != null 532 ? state.enabledComponents.remove(componentClassName) : false; 533 return changed; 534 } 535 getCurrentEnabledStateLPr(String componentName, int userId)536 int getCurrentEnabledStateLPr(String componentName, int userId) { 537 PackageUserState state = readUserState(userId); 538 if (state.enabledComponents != null && state.enabledComponents.contains(componentName)) { 539 return COMPONENT_ENABLED_STATE_ENABLED; 540 } else if (state.disabledComponents != null 541 && state.disabledComponents.contains(componentName)) { 542 return COMPONENT_ENABLED_STATE_DISABLED; 543 } else { 544 return COMPONENT_ENABLED_STATE_DEFAULT; 545 } 546 } 547 removeUser(int userId)548 void removeUser(int userId) { 549 mUserState.delete(userId); 550 } 551 getNotInstalledUserIds()552 public int[] getNotInstalledUserIds() { 553 int count = 0; 554 int userStateCount = mUserState.size(); 555 for (int i = 0; i < userStateCount; i++) { 556 if (!mUserState.valueAt(i).installed) { 557 count++; 558 } 559 } 560 if (count == 0) return EMPTY_INT_ARRAY; 561 int[] excludedUserIds = new int[count]; 562 int idx = 0; 563 for (int i = 0; i < userStateCount; i++) { 564 if (!mUserState.valueAt(i).installed) { 565 excludedUserIds[idx++] = mUserState.keyAt(i); 566 } 567 } 568 return excludedUserIds; 569 } 570 getIntentFilterVerificationInfo()571 IntentFilterVerificationInfo getIntentFilterVerificationInfo() { 572 return verificationInfo; 573 } 574 setIntentFilterVerificationInfo(IntentFilterVerificationInfo info)575 void setIntentFilterVerificationInfo(IntentFilterVerificationInfo info) { 576 verificationInfo = info; 577 } 578 579 // Returns a packed value as a long: 580 // 581 // high 'int'-sized word: link status: undefined/ask/never/always. 582 // low 'int'-sized word: relative priority among 'always' results. getDomainVerificationStatusForUser(int userId)583 long getDomainVerificationStatusForUser(int userId) { 584 PackageUserState state = readUserState(userId); 585 long result = (long) state.appLinkGeneration; 586 result |= ((long) state.domainVerificationStatus) << 32; 587 return result; 588 } 589 setDomainVerificationStatusForUser(final int status, int generation, int userId)590 void setDomainVerificationStatusForUser(final int status, int generation, int userId) { 591 PackageUserState state = modifyUserState(userId); 592 state.domainVerificationStatus = status; 593 if (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { 594 state.appLinkGeneration = generation; 595 } 596 } 597 clearDomainVerificationStatusForUser(int userId)598 void clearDomainVerificationStatusForUser(int userId) { 599 modifyUserState(userId).domainVerificationStatus = 600 PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; 601 } 602 writeUsersInfoToProto(ProtoOutputStream proto, long fieldId)603 protected void writeUsersInfoToProto(ProtoOutputStream proto, long fieldId) { 604 int count = mUserState.size(); 605 for (int i = 0; i < count; i++) { 606 final long userToken = proto.start(fieldId); 607 final int userId = mUserState.keyAt(i); 608 final PackageUserState state = mUserState.valueAt(i); 609 proto.write(PackageProto.UserInfoProto.ID, userId); 610 final int installType; 611 if (state.instantApp) { 612 installType = PackageProto.UserInfoProto.INSTANT_APP_INSTALL; 613 } else if (state.installed) { 614 installType = PackageProto.UserInfoProto.FULL_APP_INSTALL; 615 } else { 616 installType = PackageProto.UserInfoProto.NOT_INSTALLED_FOR_USER; 617 } 618 proto.write(PackageProto.UserInfoProto.INSTALL_TYPE, installType); 619 proto.write(PackageProto.UserInfoProto.IS_HIDDEN, state.hidden); 620 proto.write(PackageProto.UserInfoProto.DISTRACTION_FLAGS, state.distractionFlags); 621 proto.write(PackageProto.UserInfoProto.IS_SUSPENDED, state.suspended); 622 if (state.suspended) { 623 proto.write(PackageProto.UserInfoProto.SUSPENDING_PACKAGE, state.suspendingPackage); 624 } 625 proto.write(PackageProto.UserInfoProto.IS_STOPPED, state.stopped); 626 proto.write(PackageProto.UserInfoProto.IS_LAUNCHED, !state.notLaunched); 627 proto.write(PackageProto.UserInfoProto.ENABLED_STATE, state.enabled); 628 proto.write( 629 PackageProto.UserInfoProto.LAST_DISABLED_APP_CALLER, 630 state.lastDisableAppCaller); 631 proto.end(userToken); 632 } 633 } 634 setHarmfulAppWarning(int userId, String harmfulAppWarning)635 void setHarmfulAppWarning(int userId, String harmfulAppWarning) { 636 PackageUserState userState = modifyUserState(userId); 637 userState.harmfulAppWarning = harmfulAppWarning; 638 } 639 getHarmfulAppWarning(int userId)640 String getHarmfulAppWarning(int userId) { 641 PackageUserState userState = readUserState(userId); 642 return userState.harmfulAppWarning; 643 } 644 updateFrom(PackageSettingBase other)645 protected PackageSettingBase updateFrom(PackageSettingBase other) { 646 super.copyFrom(other); 647 this.parentPackageName = other.parentPackageName; 648 this.childPackageNames = other.childPackageNames; 649 this.codePath = other.codePath; 650 this.codePathString = other.codePathString; 651 this.resourcePath = other.resourcePath; 652 this.resourcePathString = other.resourcePathString; 653 this.usesStaticLibraries = other.usesStaticLibraries; 654 this.usesStaticLibrariesVersions = other.usesStaticLibrariesVersions; 655 this.legacyNativeLibraryPathString = other.legacyNativeLibraryPathString; 656 this.primaryCpuAbiString = other.primaryCpuAbiString; 657 this.secondaryCpuAbiString = other.secondaryCpuAbiString; 658 this.cpuAbiOverrideString = other.cpuAbiOverrideString; 659 this.timeStamp = other.timeStamp; 660 this.firstInstallTime = other.firstInstallTime; 661 this.lastUpdateTime = other.lastUpdateTime; 662 this.versionCode = other.versionCode; 663 this.uidError = other.uidError; 664 this.signatures = other.signatures; 665 this.installPermissionsFixed = other.installPermissionsFixed; 666 this.keySetData = other.keySetData; 667 this.installerPackageName = other.installerPackageName; 668 this.isOrphaned = other.isOrphaned; 669 this.volumeUuid = other.volumeUuid; 670 this.categoryHint = other.categoryHint; 671 this.updateAvailable = other.updateAvailable; 672 this.verificationInfo = other.verificationInfo; 673 674 if (mOldCodePaths != null) { 675 if (other.mOldCodePaths != null) { 676 mOldCodePaths.clear(); 677 mOldCodePaths.addAll(other.mOldCodePaths); 678 } else { 679 mOldCodePaths = null; 680 } 681 } 682 mUserState.clear(); 683 for (int i = 0; i < other.mUserState.size(); i++) { 684 mUserState.put(other.mUserState.keyAt(i), other.mUserState.valueAt(i)); 685 } 686 return this; 687 } 688 } 689