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