1 /*
2  * Copyright (C) 2020 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.om;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.om.OverlayableInfo;
22 import android.content.pm.PackageManager;
23 import android.content.pm.PackageManagerInternal;
24 import android.util.ArrayMap;
25 
26 import com.android.server.pm.PackageManagerServiceUtils;
27 import com.android.server.pm.pkg.PackageState;
28 
29 import java.io.IOException;
30 import java.util.Map;
31 
32 /**
33  * Delegate for {@link PackageManager} and {@link PackageManagerInternal} functionality,
34  * separated for easy testing.
35  *
36  * @hide
37  */
38 interface PackageManagerHelper {
39 
40     /**
41      * Initializes the helper for the user. This only needs to be invoked one time before
42      * packages of this user are queried.
43      * @param userId the user id to initialize
44      * @return a map of package name to all packages installed in the user
45      */
46     @NonNull
initializeForUser(final int userId)47     ArrayMap<String, PackageState> initializeForUser(final int userId);
48 
49     /**
50      * Retrieves the package information if it is installed for the user.
51      */
52     @Nullable
getPackageStateForUser(@onNull final String packageName, final int userId)53     PackageState getPackageStateForUser(@NonNull final String packageName, final int userId);
54 
55     /**
56      * Returns whether the package is an instant app.
57      */
isInstantApp(@onNull final String packageName, final int userId)58     boolean isInstantApp(@NonNull final String packageName, final int userId);
59 
60     /**
61      * @see PackageManager#getPackagesForUid(int)
62      */
63     @Nullable
getPackagesForUid(int uid)64     String[] getPackagesForUid(int uid);
65 
66     /**
67      * @return true if the target package has declared an overlayable
68      */
doesTargetDefineOverlayable(String targetPackageName, int userId)69     boolean doesTargetDefineOverlayable(String targetPackageName, int userId) throws IOException;
70 
71     /**
72      * @throws SecurityException containing message if the caller doesn't have the given
73      *                           permission
74      */
enforcePermission(String permission, String message)75     void enforcePermission(String permission, String message) throws SecurityException;
76 
77     /**
78      * Returns the package name of the reference package defined in 'overlay-config-signature' tag
79      * of SystemConfig. This package is vetted on scan by PackageManagerService that it's a system
80      * package and is used to check if overlay matches its signature in order to fulfill the
81      * config_signature policy.
82      */
83     @Nullable
getConfigSignaturePackage()84     String getConfigSignaturePackage();
85 
86     /**
87      * @return map of system pre-defined, uniquely named actors; keys are namespace,
88      * value maps actor name to package name
89      */
90     @NonNull
getNamedActors()91     Map<String, Map<String, String>> getNamedActors();
92 
93     /**
94      * Read from the APK and AndroidManifest of a package to return the overlayable defined for
95      * a given name.
96      *
97      * @throws IOException if the target can't be read
98      */
99     @Nullable
getOverlayableForTarget(@onNull String packageName, @NonNull String targetOverlayableName, int userId)100     OverlayableInfo getOverlayableForTarget(@NonNull String packageName,
101             @NonNull String targetOverlayableName, int userId)
102             throws IOException;
103 
104     /**
105      * @return true if {@link PackageManagerServiceUtils#compareSignatures} run on both packages
106      *     in the system returns {@link PackageManager#SIGNATURE_MATCH}
107      */
signaturesMatching(@onNull String pkgName1, @NonNull String pkgName2, int userId)108     boolean signaturesMatching(@NonNull String pkgName1, @NonNull String pkgName2, int userId);
109 }
110