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