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.pm.parsing.pkg; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Intent; 22 import android.content.pm.ApplicationInfo; 23 import android.content.pm.PackageInfo; 24 import android.content.pm.PackageParser; 25 import android.content.pm.PermissionGroupInfo; 26 import android.content.pm.parsing.ParsingPackageRead; 27 import android.content.pm.parsing.ParsingPackageUtils; 28 import android.content.pm.parsing.component.ParsedAttribution; 29 import android.content.pm.parsing.component.ParsedIntentInfo; 30 import android.content.pm.parsing.component.ParsedPermissionGroup; 31 import android.os.Bundle; 32 import android.os.Parcelable; 33 import android.util.ArraySet; 34 import android.util.Pair; 35 36 import com.android.internal.R; 37 38 import java.security.PublicKey; 39 import java.util.List; 40 import java.util.Map; 41 import java.util.Set; 42 import java.util.UUID; 43 44 /** 45 * The last state of a package during parsing/install before it is available in 46 * {@link com.android.server.pm.PackageManagerService#mPackages}. 47 * 48 * It is the responsibility of the caller to understand what data is available at what step of the 49 * parsing or install process. 50 * 51 * TODO(b/135203078): Nullability annotations 52 * TODO(b/135203078): Remove get/setAppInfo differences 53 * 54 * @hide 55 */ 56 public interface AndroidPackage extends PkgAppInfo, PkgPackageInfo, ParsingPackageRead, Parcelable { 57 58 /** 59 * The names of packages to adopt ownership of permissions from, parsed under 60 * {@link ParsingPackageUtils#TAG_ADOPT_PERMISSIONS}. 61 * @see R.styleable#AndroidManifestOriginalPackage_name 62 */ 63 @NonNull getAdoptPermissions()64 List<String> getAdoptPermissions(); 65 66 /** Path of base APK */ 67 @NonNull getBaseApkPath()68 String getBaseApkPath(); 69 70 /** Revision code of base APK */ getBaseRevisionCode()71 int getBaseRevisionCode(); 72 73 /** 74 * The path to the folder containing the base APK and any installed splits. 75 */ 76 @NonNull getPath()77 String getPath(); 78 79 /** 80 * Permissions requested but not in the manifest. These may have been split or migrated from 81 * previous versions/definitions. 82 */ 83 @NonNull getImplicitPermissions()84 List<String> getImplicitPermissions(); 85 86 /** 87 * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in 88 * {@link ParsingPackageUtils#TAG_KEY_SETS}. 89 * @see R.styleable#AndroidManifestKeySet 90 * @see R.styleable#AndroidManifestPublicKey 91 */ 92 @NonNull getKeySetMapping()93 Map<String, ArraySet<PublicKey>> getKeySetMapping(); 94 95 /** 96 * Library names this package is declared as, for use by other packages with "uses-library". 97 * @see R.styleable#AndroidManifestLibrary 98 */ 99 @NonNull getLibraryNames()100 List<String> getLibraryNames(); 101 102 /** 103 * The package name as declared in the manifest, since the package can be renamed. For example, 104 * static shared libs use synthetic package names. 105 */ 106 @NonNull getManifestPackageName()107 String getManifestPackageName(); 108 109 /** 110 * We store the application meta-data independently to avoid multiple unwanted references 111 * TODO(b/135203078): What does this comment mean? 112 * TODO(b/135203078): Make all the Bundles immutable (and non-null by shared empty reference?) 113 */ 114 @Nullable getMetaData()115 Bundle getMetaData(); 116 117 /** 118 * For system use to migrate from an old package name to a new one, moving over data 119 * if available. 120 * @see R.styleable#AndroidManifestOriginalPackage} 121 */ 122 @NonNull getOriginalPackages()123 List<String> getOriginalPackages(); 124 125 /** 126 * Map of overlayable name to actor name. 127 */ 128 @NonNull getOverlayables()129 Map<String, String> getOverlayables(); 130 131 /** 132 * The name of the package as used to identify it in the system. This may be adjusted by the 133 * system from the value declared in the manifest, and may not correspond to a Java code 134 * package. 135 * @see ApplicationInfo#packageName 136 * @see PackageInfo#packageName 137 */ 138 @NonNull getPackageName()139 String getPackageName(); 140 141 /** 142 * @see PermissionGroupInfo 143 */ 144 @NonNull getPermissionGroups()145 List<ParsedPermissionGroup> getPermissionGroups(); 146 147 @NonNull getAttributions()148 List<ParsedAttribution> getAttributions(); 149 150 /** 151 * Used to determine the default preferred handler of an {@link Intent}. 152 * 153 * Map of component className to intent info inside that component. 154 * TODO(b/135203078): Is this actually used/working? 155 */ 156 @NonNull getPreferredActivityFilters()157 List<Pair<String, ParsedIntentInfo>> getPreferredActivityFilters(); 158 159 /** 160 * System protected broadcasts. 161 * @see R.styleable#AndroidManifestProtectedBroadcast 162 */ 163 @NonNull getProtectedBroadcasts()164 List<String> getProtectedBroadcasts(); 165 166 /** 167 * Intents that this package may query or require and thus requires visibility into. 168 * @see R.styleable#AndroidManifestQueriesIntent 169 */ 170 @NonNull getQueriesIntents()171 List<Intent> getQueriesIntents(); 172 173 /** 174 * Other packages that this package may query or require and thus requires visibility into. 175 * @see R.styleable#AndroidManifestQueriesPackage 176 */ 177 @NonNull getQueriesPackages()178 List<String> getQueriesPackages(); 179 180 /** 181 * If a system app declares {@link #getOriginalPackages()}, and the app was previously installed 182 * under one of those original package names, the {@link #getPackageName()} system identifier 183 * will be changed to that previously installed name. This will then be non-null, set to the 184 * manifest package name, for tracking the package under its true name. 185 * 186 * TODO(b/135203078): Remove this in favor of checking originalPackages.isEmpty and 187 * getManifestPackageName 188 */ 189 @Nullable getRealPackage()190 String getRealPackage(); 191 192 /** 193 * SHA-512 hash of the only APK that can be used to update a system package. 194 * @see R.styleable#AndroidManifestRestrictUpdate 195 */ 196 @Nullable getRestrictUpdateHash()197 byte[] getRestrictUpdateHash(); 198 199 /** 200 * The signature data of all APKs in this package, which must be exactly the same across the 201 * base and splits. 202 */ getSigningDetails()203 PackageParser.SigningDetails getSigningDetails(); 204 205 /** 206 * TODO(b/135203078): Move split stuff to an inner data class 207 * @see ApplicationInfo#splitNames 208 * @see PackageInfo#splitNames 209 */ 210 @Nullable getSplitNames()211 String[] getSplitNames(); 212 213 /** Flags of any split APKs; ordered by parsed splitName */ 214 @Nullable getSplitFlags()215 int[] getSplitFlags(); 216 217 /** @see R.styleable#AndroidManifestStaticLibrary_name */ 218 @Nullable getStaticSharedLibName()219 String getStaticSharedLibName(); 220 221 /** @see R.styleable#AndroidManifestStaticLibrary_version */ getStaticSharedLibVersion()222 long getStaticSharedLibVersion(); 223 224 /** 225 * {@link android.os.storage.StorageManager#convert(String)} version of 226 * {@link #getVolumeUuid()}. 227 * TODO(b/135203078): All usages call toString() on this. Can the string be returned directly, 228 * or does the parsing logic in StorageManager have to run? 229 */ getStorageUuid()230 UUID getStorageUuid(); 231 232 /** 233 * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in 234 * {@link ParsingPackageUtils#TAG_KEY_SETS}. 235 * @see R.styleable#AndroidManifestUpgradeKeySet 236 */ 237 @NonNull getUpgradeKeySets()238 Set<String> getUpgradeKeySets(); 239 240 /** @see R.styleable#AndroidManifestUsesLibrary */ 241 @NonNull getUsesLibraries()242 List<String> getUsesLibraries(); 243 244 /** 245 * Like {@link #getUsesLibraries()}, but marked optional by setting 246 * {@link R.styleable#AndroidManifestUsesLibrary_required} to false . Application is expected 247 * to handle absence manually. 248 * @see R.styleable#AndroidManifestUsesLibrary 249 */ 250 @NonNull getUsesOptionalLibraries()251 List<String> getUsesOptionalLibraries(); 252 253 /** @see R.styleabele#AndroidManifestUsesNativeLibrary */ 254 @NonNull getUsesNativeLibraries()255 List<String> getUsesNativeLibraries(); 256 257 /** 258 * Like {@link #getUsesNativeLibraries()}, but marked optional by setting 259 * {@link R.styleable#AndroidManifestUsesNativeLibrary_required} to false . Application is 260 * expected to handle absence manually. 261 * @see R.styleable#AndroidManifestUsesNativeLibrary 262 */ 263 @NonNull getUsesOptionalNativeLibraries()264 List<String> getUsesOptionalNativeLibraries(); 265 266 /** 267 * TODO(b/135203078): Move static library stuff to an inner data class 268 * @see R.styleable#AndroidManifestUsesStaticLibrary 269 */ 270 @NonNull getUsesStaticLibraries()271 List<String> getUsesStaticLibraries(); 272 273 /** @see R.styleable#AndroidManifestUsesStaticLibrary_certDigest */ 274 @Nullable getUsesStaticLibrariesCertDigests()275 String[][] getUsesStaticLibrariesCertDigests(); 276 277 /** @see R.styleable#AndroidManifestUsesStaticLibrary_version */ 278 @Nullable getUsesStaticLibrariesVersions()279 long[] getUsesStaticLibrariesVersions(); 280 281 /** @see R.styleable#AndroidManifestApplication_forceQueryable */ isForceQueryable()282 boolean isForceQueryable(); 283 isCrossProfile()284 boolean isCrossProfile(); 285 286 /** 287 * The install time abi override to choose 32bit abi's when multiple abi's 288 * are present. This is only meaningfull for multiarch applications. 289 */ isUse32BitAbi()290 boolean isUse32BitAbi(); 291 292 /** 293 * Set if the any of components are visible to instant applications. 294 * @see R.styleable#AndroidManifestActivity_visibleToInstantApps 295 * @see R.styleable#AndroidManifestProvider_visibleToInstantApps 296 * @see R.styleable#AndroidManifestService_visibleToInstantApps 297 */ isVisibleToInstantApps()298 boolean isVisibleToInstantApps(); 299 300 /** 301 * Generates an {@link ApplicationInfo} object with only the data available in this object. 302 * 303 * TODO(b/135203078): Actually add this 304 * This does not contain any system or user state data, and should be avoided. Prefer 305 * com.android.server.pm.parsing.PackageInfoUtils#generateApplicationInfo( 306 * AndroidPackage, int, PackageUserState, int, com.android.server.pm.PackageSetting) 307 * 308 * @deprecated Access AndroidPackage fields directly. 309 */ 310 @Deprecated 311 @NonNull toAppInfoWithoutState()312 ApplicationInfo toAppInfoWithoutState(); 313 314 /** 315 * Same as toAppInfoWithoutState except it does not compute any flags. 316 */ 317 @NonNull toAppInfoWithoutStateWithoutFlags()318 ApplicationInfo toAppInfoWithoutStateWithoutFlags(); 319 320 /** 321 * TODO(b/135203078): Remove usages? 322 * @return a mock of what the previous package.applicationInfo would've returned for logging 323 * @deprecated don't use this in any new code, just print package name directly 324 */ 325 @Deprecated 326 @NonNull toAppInfoToString()327 String toAppInfoToString(); 328 } 329