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 
273     @VisibleForTesting
modifyUserState(int userId)274     PackageUserState modifyUserState(int userId) {
275         PackageUserState state = mUserState.get(userId);
276         if (state == null) {
277             state = new PackageUserState();
278             mUserState.put(userId, state);
279         }
280         return state;
281     }
282 
readUserState(int userId)283     public PackageUserState readUserState(int userId) {
284         PackageUserState state = mUserState.get(userId);
285         if (state == null) {
286             return DEFAULT_USER_STATE;
287         }
288         state.categoryHint = categoryHint;
289         return state;
290     }
291 
setEnabled(int state, int userId, String callingPackage)292     void setEnabled(int state, int userId, String callingPackage) {
293         PackageUserState st = modifyUserState(userId);
294         st.enabled = state;
295         st.lastDisableAppCaller = callingPackage;
296     }
297 
getEnabled(int userId)298     int getEnabled(int userId) {
299         return readUserState(userId).enabled;
300     }
301 
getLastDisabledAppCaller(int userId)302     String getLastDisabledAppCaller(int userId) {
303         return readUserState(userId).lastDisableAppCaller;
304     }
305 
setInstalled(boolean inst, int userId)306     void setInstalled(boolean inst, int userId) {
307         modifyUserState(userId).installed = inst;
308     }
309 
getInstalled(int userId)310     boolean getInstalled(int userId) {
311         return readUserState(userId).installed;
312     }
313 
getInstallReason(int userId)314     int getInstallReason(int userId) {
315         return readUserState(userId).installReason;
316     }
317 
setInstallReason(int installReason, int userId)318     void setInstallReason(int installReason, int userId) {
319         modifyUserState(userId).installReason = installReason;
320     }
321 
setOverlayPaths(List<String> overlayPaths, int userId)322     void setOverlayPaths(List<String> overlayPaths, int userId) {
323         modifyUserState(userId).overlayPaths = overlayPaths == null ? null :
324             overlayPaths.toArray(new String[overlayPaths.size()]);
325     }
326 
getOverlayPaths(int userId)327     String[] getOverlayPaths(int userId) {
328         return readUserState(userId).overlayPaths;
329     }
330 
331     /** Only use for testing. Do NOT use in production code. */
332     @VisibleForTesting
getUserState()333     SparseArray<PackageUserState> getUserState() {
334         return mUserState;
335     }
336 
isAnyInstalled(int[] users)337     boolean isAnyInstalled(int[] users) {
338         for (int user: users) {
339             if (readUserState(user).installed) {
340                 return true;
341             }
342         }
343         return false;
344     }
345 
queryInstalledUsers(int[] users, boolean installed)346     int[] queryInstalledUsers(int[] users, boolean installed) {
347         int num = 0;
348         for (int user : users) {
349             if (getInstalled(user) == installed) {
350                 num++;
351             }
352         }
353         int[] res = new int[num];
354         num = 0;
355         for (int user : users) {
356             if (getInstalled(user) == installed) {
357                 res[num] = user;
358                 num++;
359             }
360         }
361         return res;
362     }
363 
getCeDataInode(int userId)364     long getCeDataInode(int userId) {
365         return readUserState(userId).ceDataInode;
366     }
367 
setCeDataInode(long ceDataInode, int userId)368     void setCeDataInode(long ceDataInode, int userId) {
369         modifyUserState(userId).ceDataInode = ceDataInode;
370     }
371 
getStopped(int userId)372     boolean getStopped(int userId) {
373         return readUserState(userId).stopped;
374     }
375 
setStopped(boolean stop, int userId)376     void setStopped(boolean stop, int userId) {
377         modifyUserState(userId).stopped = stop;
378     }
379 
getNotLaunched(int userId)380     boolean getNotLaunched(int userId) {
381         return readUserState(userId).notLaunched;
382     }
383 
setNotLaunched(boolean stop, int userId)384     void setNotLaunched(boolean stop, int userId) {
385         modifyUserState(userId).notLaunched = stop;
386     }
387 
getHidden(int userId)388     boolean getHidden(int userId) {
389         return readUserState(userId).hidden;
390     }
391 
setHidden(boolean hidden, int userId)392     void setHidden(boolean hidden, int userId) {
393         modifyUserState(userId).hidden = hidden;
394     }
395 
getDistractionFlags(int userId)396     int getDistractionFlags(int userId) {
397         return readUserState(userId).distractionFlags;
398     }
399 
setDistractionFlags(int distractionFlags, int userId)400     void setDistractionFlags(int distractionFlags, int userId) {
401         modifyUserState(userId).distractionFlags = distractionFlags;
402     }
403 
getSuspended(int userId)404     boolean getSuspended(int userId) {
405         return readUserState(userId).suspended;
406     }
407 
setSuspended(boolean suspended, String suspendingPackage, SuspendDialogInfo dialogInfo, PersistableBundle appExtras, PersistableBundle launcherExtras, int userId)408     void setSuspended(boolean suspended, String suspendingPackage, SuspendDialogInfo dialogInfo,
409             PersistableBundle appExtras, PersistableBundle launcherExtras, int userId) {
410         final PackageUserState existingUserState = modifyUserState(userId);
411         existingUserState.suspended = suspended;
412         existingUserState.suspendingPackage = suspended ? suspendingPackage : null;
413         existingUserState.dialogInfo = suspended ? dialogInfo : null;
414         existingUserState.suspendedAppExtras = suspended ? appExtras : null;
415         existingUserState.suspendedLauncherExtras = suspended ? launcherExtras : null;
416     }
417 
getInstantApp(int userId)418     public boolean getInstantApp(int userId) {
419         return readUserState(userId).instantApp;
420     }
421 
setInstantApp(boolean instantApp, int userId)422     void setInstantApp(boolean instantApp, int userId) {
423         modifyUserState(userId).instantApp = instantApp;
424     }
425 
getVirtulalPreload(int userId)426     boolean getVirtulalPreload(int userId) {
427         return readUserState(userId).virtualPreload;
428     }
429 
setVirtualPreload(boolean virtualPreload, int userId)430     void setVirtualPreload(boolean virtualPreload, int userId) {
431         modifyUserState(userId).virtualPreload = virtualPreload;
432     }
433 
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)434     void setUserState(int userId, long ceDataInode, int enabled, boolean installed, boolean stopped,
435             boolean notLaunched, boolean hidden, int distractionFlags, boolean suspended,
436             String suspendingPackage,
437             SuspendDialogInfo dialogInfo, PersistableBundle suspendedAppExtras,
438             PersistableBundle suspendedLauncherExtras, boolean instantApp,
439             boolean virtualPreload, String lastDisableAppCaller,
440             ArraySet<String> enabledComponents, ArraySet<String> disabledComponents,
441             int domainVerifState, int linkGeneration, int installReason,
442             String harmfulAppWarning) {
443         PackageUserState state = modifyUserState(userId);
444         state.ceDataInode = ceDataInode;
445         state.enabled = enabled;
446         state.installed = installed;
447         state.stopped = stopped;
448         state.notLaunched = notLaunched;
449         state.hidden = hidden;
450         state.distractionFlags = distractionFlags;
451         state.suspended = suspended;
452         state.suspendingPackage = suspendingPackage;
453         state.dialogInfo = dialogInfo;
454         state.suspendedAppExtras = suspendedAppExtras;
455         state.suspendedLauncherExtras = suspendedLauncherExtras;
456         state.lastDisableAppCaller = lastDisableAppCaller;
457         state.enabledComponents = enabledComponents;
458         state.disabledComponents = disabledComponents;
459         state.domainVerificationStatus = domainVerifState;
460         state.appLinkGeneration = linkGeneration;
461         state.installReason = installReason;
462         state.instantApp = instantApp;
463         state.virtualPreload = virtualPreload;
464         state.harmfulAppWarning = harmfulAppWarning;
465     }
466 
setUserState(int userId, PackageUserState otherState)467     void setUserState(int userId, PackageUserState otherState) {
468         setUserState(userId, otherState.ceDataInode, otherState.enabled, otherState.installed,
469                 otherState.stopped, otherState.notLaunched, otherState.hidden,
470                 otherState.distractionFlags, otherState.suspended, otherState.suspendingPackage,
471                 otherState.dialogInfo, otherState.suspendedAppExtras,
472                 otherState.suspendedLauncherExtras, otherState.instantApp,
473                 otherState.virtualPreload, otherState.lastDisableAppCaller,
474                 otherState.enabledComponents, otherState.disabledComponents,
475                 otherState.domainVerificationStatus, otherState.appLinkGeneration,
476                 otherState.installReason, otherState.harmfulAppWarning);
477     }
478 
getEnabledComponents(int userId)479     ArraySet<String> getEnabledComponents(int userId) {
480         return readUserState(userId).enabledComponents;
481     }
482 
getDisabledComponents(int userId)483     ArraySet<String> getDisabledComponents(int userId) {
484         return readUserState(userId).disabledComponents;
485     }
486 
setEnabledComponents(ArraySet<String> components, int userId)487     void setEnabledComponents(ArraySet<String> components, int userId) {
488         modifyUserState(userId).enabledComponents = components;
489     }
490 
setDisabledComponents(ArraySet<String> components, int userId)491     void setDisabledComponents(ArraySet<String> components, int userId) {
492         modifyUserState(userId).disabledComponents = components;
493     }
494 
setEnabledComponentsCopy(ArraySet<String> components, int userId)495     void setEnabledComponentsCopy(ArraySet<String> components, int userId) {
496         modifyUserState(userId).enabledComponents = components != null
497                 ? new ArraySet<String>(components) : null;
498     }
499 
setDisabledComponentsCopy(ArraySet<String> components, int userId)500     void setDisabledComponentsCopy(ArraySet<String> components, int userId) {
501         modifyUserState(userId).disabledComponents = components != null
502                 ? new ArraySet<String>(components) : null;
503     }
504 
modifyUserStateComponents(int userId, boolean disabled, boolean enabled)505     PackageUserState modifyUserStateComponents(int userId, boolean disabled, boolean enabled) {
506         PackageUserState state = modifyUserState(userId);
507         if (disabled && state.disabledComponents == null) {
508             state.disabledComponents = new ArraySet<String>(1);
509         }
510         if (enabled && state.enabledComponents == null) {
511             state.enabledComponents = new ArraySet<String>(1);
512         }
513         return state;
514     }
515 
addDisabledComponent(String componentClassName, int userId)516     void addDisabledComponent(String componentClassName, int userId) {
517         modifyUserStateComponents(userId, true, false).disabledComponents.add(componentClassName);
518     }
519 
addEnabledComponent(String componentClassName, int userId)520     void addEnabledComponent(String componentClassName, int userId) {
521         modifyUserStateComponents(userId, false, true).enabledComponents.add(componentClassName);
522     }
523 
enableComponentLPw(String componentClassName, int userId)524     boolean enableComponentLPw(String componentClassName, int userId) {
525         PackageUserState state = modifyUserStateComponents(userId, false, true);
526         boolean changed = state.disabledComponents != null
527                 ? state.disabledComponents.remove(componentClassName) : false;
528         changed |= state.enabledComponents.add(componentClassName);
529         return changed;
530     }
531 
disableComponentLPw(String componentClassName, int userId)532     boolean disableComponentLPw(String componentClassName, int userId) {
533         PackageUserState state = modifyUserStateComponents(userId, true, false);
534         boolean changed = state.enabledComponents != null
535                 ? state.enabledComponents.remove(componentClassName) : false;
536         changed |= state.disabledComponents.add(componentClassName);
537         return changed;
538     }
539 
restoreComponentLPw(String componentClassName, int userId)540     boolean restoreComponentLPw(String componentClassName, int userId) {
541         PackageUserState state = modifyUserStateComponents(userId, true, true);
542         boolean changed = state.disabledComponents != null
543                 ? state.disabledComponents.remove(componentClassName) : false;
544         changed |= state.enabledComponents != null
545                 ? state.enabledComponents.remove(componentClassName) : false;
546         return changed;
547     }
548 
getCurrentEnabledStateLPr(String componentName, int userId)549     int getCurrentEnabledStateLPr(String componentName, int userId) {
550         PackageUserState state = readUserState(userId);
551         if (state.enabledComponents != null && state.enabledComponents.contains(componentName)) {
552             return COMPONENT_ENABLED_STATE_ENABLED;
553         } else if (state.disabledComponents != null
554                 && state.disabledComponents.contains(componentName)) {
555             return COMPONENT_ENABLED_STATE_DISABLED;
556         } else {
557             return COMPONENT_ENABLED_STATE_DEFAULT;
558         }
559     }
560 
removeUser(int userId)561     void removeUser(int userId) {
562         mUserState.delete(userId);
563     }
564 
getNotInstalledUserIds()565     public int[] getNotInstalledUserIds() {
566         int count = 0;
567         int userStateCount = mUserState.size();
568         for (int i = 0; i < userStateCount; i++) {
569             if (!mUserState.valueAt(i).installed) {
570                 count++;
571             }
572         }
573         if (count == 0) return EMPTY_INT_ARRAY;
574         int[] excludedUserIds = new int[count];
575         int idx = 0;
576         for (int i = 0; i < userStateCount; i++) {
577             if (!mUserState.valueAt(i).installed) {
578                 excludedUserIds[idx++] = mUserState.keyAt(i);
579             }
580         }
581         return excludedUserIds;
582     }
583 
getIntentFilterVerificationInfo()584     IntentFilterVerificationInfo getIntentFilterVerificationInfo() {
585         return verificationInfo;
586     }
587 
setIntentFilterVerificationInfo(IntentFilterVerificationInfo info)588     void setIntentFilterVerificationInfo(IntentFilterVerificationInfo info) {
589         verificationInfo = info;
590     }
591 
592     // Returns a packed value as a long:
593     //
594     // high 'int'-sized word: link status: undefined/ask/never/always.
595     // low 'int'-sized word: relative priority among 'always' results.
getDomainVerificationStatusForUser(int userId)596     long getDomainVerificationStatusForUser(int userId) {
597         PackageUserState state = readUserState(userId);
598         long result = (long) state.appLinkGeneration;
599         result |= ((long) state.domainVerificationStatus) << 32;
600         return result;
601     }
602 
setDomainVerificationStatusForUser(final int status, int generation, int userId)603     void setDomainVerificationStatusForUser(final int status, int generation, int userId) {
604         PackageUserState state = modifyUserState(userId);
605         state.domainVerificationStatus = status;
606         if (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) {
607             state.appLinkGeneration = generation;
608         }
609     }
610 
clearDomainVerificationStatusForUser(int userId)611     void clearDomainVerificationStatusForUser(int userId) {
612         modifyUserState(userId).domainVerificationStatus =
613                 PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
614     }
615 
writeUsersInfoToProto(ProtoOutputStream proto, long fieldId)616     protected void writeUsersInfoToProto(ProtoOutputStream proto, long fieldId) {
617         int count = mUserState.size();
618         for (int i = 0; i < count; i++) {
619             final long userToken = proto.start(fieldId);
620             final int userId = mUserState.keyAt(i);
621             final PackageUserState state = mUserState.valueAt(i);
622             proto.write(PackageProto.UserInfoProto.ID, userId);
623             final int installType;
624             if (state.instantApp) {
625                 installType = PackageProto.UserInfoProto.INSTANT_APP_INSTALL;
626             } else if (state.installed) {
627                 installType = PackageProto.UserInfoProto.FULL_APP_INSTALL;
628             } else {
629                 installType = PackageProto.UserInfoProto.NOT_INSTALLED_FOR_USER;
630             }
631             proto.write(PackageProto.UserInfoProto.INSTALL_TYPE, installType);
632             proto.write(PackageProto.UserInfoProto.IS_HIDDEN, state.hidden);
633             proto.write(PackageProto.UserInfoProto.DISTRACTION_FLAGS, state.distractionFlags);
634             proto.write(PackageProto.UserInfoProto.IS_SUSPENDED, state.suspended);
635             if (state.suspended) {
636                 proto.write(PackageProto.UserInfoProto.SUSPENDING_PACKAGE, state.suspendingPackage);
637             }
638             proto.write(PackageProto.UserInfoProto.IS_STOPPED, state.stopped);
639             proto.write(PackageProto.UserInfoProto.IS_LAUNCHED, !state.notLaunched);
640             proto.write(PackageProto.UserInfoProto.ENABLED_STATE, state.enabled);
641             proto.write(
642                     PackageProto.UserInfoProto.LAST_DISABLED_APP_CALLER,
643                     state.lastDisableAppCaller);
644             proto.end(userToken);
645         }
646     }
647 
setHarmfulAppWarning(int userId, String harmfulAppWarning)648     void setHarmfulAppWarning(int userId, String harmfulAppWarning) {
649         PackageUserState userState = modifyUserState(userId);
650         userState.harmfulAppWarning = harmfulAppWarning;
651     }
652 
getHarmfulAppWarning(int userId)653     String getHarmfulAppWarning(int userId) {
654         PackageUserState userState = readUserState(userId);
655         return userState.harmfulAppWarning;
656     }
657 
updateFrom(PackageSettingBase other)658     protected PackageSettingBase updateFrom(PackageSettingBase other) {
659         super.copyFrom(other);
660         this.parentPackageName = other.parentPackageName;
661         this.childPackageNames = other.childPackageNames;
662         this.codePath = other.codePath;
663         this.codePathString = other.codePathString;
664         this.resourcePath = other.resourcePath;
665         this.resourcePathString = other.resourcePathString;
666         this.usesStaticLibraries = other.usesStaticLibraries;
667         this.usesStaticLibrariesVersions = other.usesStaticLibrariesVersions;
668         this.legacyNativeLibraryPathString = other.legacyNativeLibraryPathString;
669         this.primaryCpuAbiString = other.primaryCpuAbiString;
670         this.secondaryCpuAbiString = other.secondaryCpuAbiString;
671         this.cpuAbiOverrideString = other.cpuAbiOverrideString;
672         this.timeStamp = other.timeStamp;
673         this.firstInstallTime = other.firstInstallTime;
674         this.lastUpdateTime = other.lastUpdateTime;
675         this.versionCode = other.versionCode;
676         this.uidError = other.uidError;
677         this.signatures = other.signatures;
678         this.installPermissionsFixed = other.installPermissionsFixed;
679         this.keySetData = other.keySetData;
680         this.installerPackageName = other.installerPackageName;
681         this.isOrphaned = other.isOrphaned;
682         this.volumeUuid = other.volumeUuid;
683         this.categoryHint = other.categoryHint;
684         this.updateAvailable = other.updateAvailable;
685         this.verificationInfo = other.verificationInfo;
686 
687         if (mOldCodePaths != null) {
688             if (other.mOldCodePaths != null) {
689                 mOldCodePaths.clear();
690                 mOldCodePaths.addAll(other.mOldCodePaths);
691             } else {
692                 mOldCodePaths = null;
693             }
694         }
695         mUserState.clear();
696         for (int i = 0; i < other.mUserState.size(); i++) {
697             mUserState.put(other.mUserState.keyAt(i), other.mUserState.valueAt(i));
698         }
699         return this;
700     }
701 }
702