The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 android.content.pm; |
| 18 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 20 | import static android.content.pm.ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 21 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 22 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 23 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
| 24 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
| 25 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 27 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 28 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 29 | import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED; |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 30 | import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; |
| 31 | import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 32 | import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 33 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST; |
| 34 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 35 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 36 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 37 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 38 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 39 | import static android.os.Build.VERSION_CODES.O; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 40 | import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 42 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 43 | import android.annotation.IntDef; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 44 | import android.annotation.IntRange; |
| 45 | import android.annotation.NonNull; |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 46 | import android.annotation.Nullable; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 47 | import android.annotation.TestApi; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 48 | import android.app.ActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.ComponentName; |
| 50 | import android.content.Intent; |
| 51 | import android.content.IntentFilter; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 52 | import android.content.pm.PackageParserCacheHelper.ReadHelper; |
| 53 | import android.content.pm.PackageParserCacheHelper.WriteHelper; |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 54 | import android.content.pm.split.DefaultSplitAssetLoader; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 55 | import android.content.pm.split.SplitAssetDependencyLoader; |
| 56 | import android.content.pm.split.SplitAssetLoader; |
Adam Lesinski | dcb3c65 | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 57 | import android.content.res.ApkAssets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.res.AssetManager; |
| 59 | import android.content.res.Configuration; |
| 60 | import android.content.res.Resources; |
| 61 | import android.content.res.TypedArray; |
| 62 | import android.content.res.XmlResourceParser; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 63 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.os.Bundle; |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 65 | import android.os.FileUtils; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 66 | import android.os.Parcel; |
| 67 | import android.os.Parcelable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.os.PatternMatcher; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 69 | import android.os.SystemClock; |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 70 | import android.os.SystemProperties; |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 71 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 72 | import android.os.UserHandle; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 73 | import android.os.storage.StorageManager; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 74 | import android.system.ErrnoException; |
| 75 | import android.system.OsConstants; |
| 76 | import android.system.StructStat; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 77 | import android.text.TextUtils; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 78 | import android.util.ArrayMap; |
| 79 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.util.AttributeSet; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 81 | import android.util.Base64; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.util.DisplayMetrics; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 83 | import android.util.Log; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 84 | import android.util.Pair; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 85 | import android.util.Slog; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 86 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.util.TypedValue; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 88 | import android.util.apk.ApkSignatureVerifier; |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 89 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 91 | import com.android.internal.R; |
| 92 | import com.android.internal.annotations.VisibleForTesting; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 93 | import com.android.internal.os.ClassLoaderFactory; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 94 | import com.android.internal.util.ArrayUtils; |
| 95 | import com.android.internal.util.XmlUtils; |
| 96 | |
| 97 | import libcore.io.IoUtils; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 98 | import libcore.util.EmptyArray; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 99 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 100 | import org.xmlpull.v1.XmlPullParser; |
| 101 | import org.xmlpull.v1.XmlPullParserException; |
| 102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import java.io.File; |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 104 | import java.io.FileDescriptor; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 105 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import java.io.IOException; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 107 | import java.io.PrintWriter; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 108 | import java.lang.annotation.Retention; |
| 109 | import java.lang.annotation.RetentionPolicy; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 110 | import java.lang.reflect.Constructor; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 111 | import java.security.KeyFactory; |
| 112 | import java.security.NoSuchAlgorithmException; |
| 113 | import java.security.PublicKey; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 114 | import java.security.cert.CertificateException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 115 | import java.security.spec.EncodedKeySpec; |
| 116 | import java.security.spec.InvalidKeySpecException; |
| 117 | import java.security.spec.X509EncodedKeySpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import java.util.ArrayList; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 119 | import java.util.Arrays; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 120 | import java.util.Collections; |
| 121 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | import java.util.Iterator; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 123 | import java.util.List; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 124 | import java.util.Set; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 125 | import java.util.UUID; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 126 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
| 128 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 129 | * Parser for package files (APKs) on disk. This supports apps packaged either |
| 130 | * as a single "monolithic" APK, or apps packaged as a "cluster" of multiple |
| 131 | * APKs in a single directory. |
| 132 | * <p> |
| 133 | * Apps packaged as multiple APKs always consist of a single "base" APK (with a |
| 134 | * {@code null} split name) and zero or more "split" APKs (with unique split |
| 135 | * names). Any subset of those split APKs are a valid install, as long as the |
| 136 | * following constraints are met: |
| 137 | * <ul> |
| 138 | * <li>All APKs must have the exact same package name, version code, and signing |
| 139 | * certificates. |
| 140 | * <li>All APKs must have unique split names. |
| 141 | * <li>All installations must contain a single base APK. |
| 142 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 144 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | */ |
| 146 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 147 | private static final boolean DEBUG_JAR = false; |
| 148 | private static final boolean DEBUG_PARSER = false; |
| 149 | private static final boolean DEBUG_BACKUP = false; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 150 | private static final boolean LOG_PARSE_TIMINGS = Build.IS_DEBUGGABLE; |
| 151 | private static final int LOG_PARSE_TIMINGS_THRESHOLD_MS = 100; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 152 | |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 153 | private static final String PROPERTY_CHILD_PACKAGES_ENABLED = |
| 154 | "persist.sys.child_packages_enabled"; |
| 155 | |
Jeff Sharkey | 3f1790d | 2017-04-25 18:56:17 -0600 | [diff] [blame] | 156 | private static final boolean MULTI_PACKAGE_APK_ENABLED = Build.IS_DEBUGGABLE && |
Garrett Boyer | 1704153 | 2017-08-01 14:11:02 -0700 | [diff] [blame] | 157 | SystemProperties.getBoolean(PROPERTY_CHILD_PACKAGES_ENABLED, false); |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 158 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 159 | private static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f; |
| 160 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 161 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 162 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 163 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 164 | /** File name in an APK for the Android manifest. */ |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 165 | public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 166 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 167 | /** Path prefix for apps on expanded storage */ |
| 168 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 169 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 170 | private static final String TAG_MANIFEST = "manifest"; |
| 171 | private static final String TAG_APPLICATION = "application"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 172 | private static final String TAG_PACKAGE_VERIFIER = "package-verifier"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 173 | private static final String TAG_OVERLAY = "overlay"; |
| 174 | private static final String TAG_KEY_SETS = "key-sets"; |
| 175 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 176 | private static final String TAG_PERMISSION = "permission"; |
| 177 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 178 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 179 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 180 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 181 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 182 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 183 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 184 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 185 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 186 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 187 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 188 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 189 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 190 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 191 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 192 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 193 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 194 | private static final String TAG_PACKAGE = "package"; |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 195 | private static final String TAG_RESTRICT_UPDATE = "restrict-update"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 196 | private static final String TAG_USES_SPLIT = "uses-split"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 197 | |
Todd Kennedy | fe7f38c3 | 2017-03-23 09:51:21 -0700 | [diff] [blame] | 198 | // [b/36551762] STOPSHIP remove the ability to expose components via meta-data |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 199 | // Temporary workaround; allow meta-data to expose components to instant apps |
| 200 | private static final String META_DATA_INSTANT_APPS = "instantapps.clients.allowed"; |
| 201 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 202 | private static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect"; |
| 203 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 204 | /** |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 205 | * Bit mask of all the valid bits that can be set in recreateOnConfigChanges. |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 206 | * @hide |
| 207 | */ |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 208 | private static final int RECREATE_ON_CONFIG_CHANGES_MASK = |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 209 | ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC; |
| 210 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 211 | // These are the tags supported by child packages |
| 212 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 213 | static { |
| 214 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 215 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 216 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 217 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 218 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 219 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 220 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 221 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 222 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 223 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 224 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 225 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 226 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 227 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 228 | } |
| 229 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 230 | private static final boolean LOG_UNSAFE_BROADCASTS = false; |
| 231 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Total number of packages that were read from the cache. We use it only for logging. |
| 234 | */ |
| 235 | public static final AtomicInteger sCachedPackageReadCount = new AtomicInteger(); |
| 236 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 237 | // Set of broadcast actions that are safe for manifest receivers |
| 238 | private static final Set<String> SAFE_BROADCASTS = new ArraySet<>(); |
| 239 | static { |
| 240 | SAFE_BROADCASTS.add(Intent.ACTION_BOOT_COMPLETED); |
| 241 | } |
| 242 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 243 | /** @hide */ |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 244 | public static final String APK_FILE_EXTENSION = ".apk"; |
| 245 | |
| 246 | /** @hide */ |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 247 | public static class NewPermissionInfo { |
| 248 | public final String name; |
| 249 | public final int sdkVersion; |
| 250 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 251 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 252 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 253 | this.name = name; |
| 254 | this.sdkVersion = sdkVersion; |
| 255 | this.fileVersion = fileVersion; |
| 256 | } |
| 257 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 258 | |
| 259 | /** @hide */ |
| 260 | public static class SplitPermissionInfo { |
| 261 | public final String rootPerm; |
| 262 | public final String[] newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 263 | public final int targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 264 | |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 265 | public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) { |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 266 | this.rootPerm = rootPerm; |
| 267 | this.newPerms = newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 268 | this.targetSdk = targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 272 | /** |
| 273 | * List of new permissions that have been added since 1.0. |
| 274 | * NOTE: These must be declared in SDK version order, with permissions |
| 275 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 276 | * If sdkVersion is 0, then this is not a permission that we want to |
| 277 | * automatically add to older apps, but we do want to allow it to be |
| 278 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 279 | * @hide |
| 280 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 281 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 282 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 283 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 284 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 285 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 286 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 287 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 289 | /** |
| 290 | * List of permissions that have been split into more granular or dependent |
| 291 | * permissions. |
| 292 | * @hide |
| 293 | */ |
| 294 | public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] = |
| 295 | new PackageParser.SplitPermissionInfo[] { |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 296 | // READ_EXTERNAL_STORAGE is always required when an app requests |
| 297 | // WRITE_EXTERNAL_STORAGE, because we can't have an app that has |
| 298 | // write access without read access. The hack here with the target |
| 299 | // target SDK version ensures that this grant is always done. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 300 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 301 | new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 302 | android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1), |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 303 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS, |
| 304 | new String[] { android.Manifest.permission.READ_CALL_LOG }, |
| 305 | android.os.Build.VERSION_CODES.JELLY_BEAN), |
| 306 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS, |
| 307 | new String[] { android.Manifest.permission.WRITE_CALL_LOG }, |
| 308 | android.os.Build.VERSION_CODES.JELLY_BEAN) |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 309 | }; |
| 310 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 311 | /** |
| 312 | * @deprecated callers should move to explicitly passing around source path. |
| 313 | */ |
| 314 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 318 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 319 | private DisplayMetrics mMetrics; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 320 | private Callback mCallback; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 321 | private File mCacheDir; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 322 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 323 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 324 | private static final String[] SDK_CODENAMES = Build.VERSION.ACTIVE_CODENAMES; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | |
| 326 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 327 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 328 | private static boolean sCompatibilityModeEnabled = true; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 329 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 330 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 331 | private static final int PARSE_DEFAULT_TARGET_SANDBOX = 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 332 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 333 | static class ParsePackageItemArgs { |
| 334 | final Package owner; |
| 335 | final String[] outError; |
| 336 | final int nameRes; |
| 337 | final int labelRes; |
| 338 | final int iconRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 339 | final int roundIconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 340 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 341 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 343 | String tag; |
| 344 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 345 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 346 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 347 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 348 | int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 349 | owner = _owner; |
| 350 | outError = _outError; |
| 351 | nameRes = _nameRes; |
| 352 | labelRes = _labelRes; |
| 353 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 354 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 355 | bannerRes = _bannerRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 356 | roundIconRes = _roundIconRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 359 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 360 | /** @hide */ |
| 361 | @VisibleForTesting |
| 362 | public static class ParseComponentArgs extends ParsePackageItemArgs { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 363 | final String[] sepProcesses; |
| 364 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 365 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 366 | final int enabledRes; |
| 367 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 368 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 369 | public ParseComponentArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 370 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 371 | int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 372 | String[] _sepProcesses, int _processRes, |
| 373 | int _descriptionRes, int _enabledRes) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 374 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _roundIconRes, _logoRes, |
| 375 | _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 376 | sepProcesses = _sepProcesses; |
| 377 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 378 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 379 | enabledRes = _enabledRes; |
| 380 | } |
| 381 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 382 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 383 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 384 | * Lightweight parsed details about a single package. |
| 385 | */ |
| 386 | public static class PackageLite { |
| 387 | public final String packageName; |
| 388 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 389 | public final int versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 390 | public final int installLocation; |
| 391 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 392 | |
| 393 | /** Names of any split APKs, ordered by parsed splitName */ |
| 394 | public final String[] splitNames; |
| 395 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 396 | /** Names of any split APKs that are features. Ordered by splitName */ |
| 397 | public final boolean[] isFeatureSplits; |
| 398 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 399 | /** Dependencies of any split APKs, ordered by parsed splitName */ |
| 400 | public final String[] usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 401 | public final String[] configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 402 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 403 | /** |
| 404 | * Path where this package was found on disk. For monolithic packages |
| 405 | * this is path to single base APK file; for cluster packages this is |
| 406 | * path to the cluster directory. |
| 407 | */ |
| 408 | public final String codePath; |
| 409 | |
| 410 | /** Path of base APK */ |
| 411 | public final String baseCodePath; |
| 412 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 413 | public final String[] splitCodePaths; |
| 414 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 415 | /** Revision code of base APK */ |
| 416 | public final int baseRevisionCode; |
| 417 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 418 | public final int[] splitRevisionCodes; |
| 419 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 420 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 421 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 422 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 423 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 424 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 425 | public final boolean isolatedSplits; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 426 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 427 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 428 | boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 429 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 430 | this.packageName = baseApk.packageName; |
| 431 | this.versionCode = baseApk.versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 432 | this.versionCodeMajor = baseApk.versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 433 | this.installLocation = baseApk.installLocation; |
| 434 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 435 | this.splitNames = splitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 436 | this.isFeatureSplits = isFeatureSplits; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 437 | this.usesSplitNames = usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 438 | this.configForSplit = configForSplit; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 439 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 440 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 441 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 442 | this.baseRevisionCode = baseApk.revisionCode; |
| 443 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 444 | this.coreApp = baseApk.coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 445 | this.debuggable = baseApk.debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 446 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 447 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 448 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 449 | this.isolatedSplits = baseApk.isolatedSplits; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | public List<String> getAllCodePaths() { |
| 453 | ArrayList<String> paths = new ArrayList<>(); |
| 454 | paths.add(baseCodePath); |
| 455 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 456 | Collections.addAll(paths, splitCodePaths); |
| 457 | } |
| 458 | return paths; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 463 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 464 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 465 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 466 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 467 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 468 | public final String splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 469 | public boolean isFeatureSplit; |
| 470 | public final String configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 471 | public final String usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 472 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 473 | public final int versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 474 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 475 | public final int installLocation; |
| 476 | public final VerifierInfo[] verifiers; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 477 | public final SigningDetails signingDetails; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 478 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 479 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 480 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 481 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 482 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 483 | public final boolean isolatedSplits; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 484 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 485 | public ApkLite(String codePath, String packageName, String splitName, |
| 486 | boolean isFeatureSplit, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 487 | String configForSplit, String usesSplitName, int versionCode, int versionCodeMajor, |
| 488 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 489 | SigningDetails signingDetails, boolean coreApp, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 490 | boolean debuggable, boolean multiArch, boolean use32bitAbi, |
| 491 | boolean extractNativeLibs, boolean isolatedSplits) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 492 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 493 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 494 | this.splitName = splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 495 | this.isFeatureSplit = isFeatureSplit; |
| 496 | this.configForSplit = configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 497 | this.usesSplitName = usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 498 | this.versionCode = versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 499 | this.versionCodeMajor = versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 500 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 501 | this.installLocation = installLocation; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 502 | this.signingDetails = signingDetails; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 503 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 504 | this.coreApp = coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 505 | this.debuggable = debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 506 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 507 | this.use32bitAbi = use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 508 | this.extractNativeLibs = extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 509 | this.isolatedSplits = isolatedSplits; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 510 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 511 | |
| 512 | public long getLongVersionCode() { |
| 513 | return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); |
| 514 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 517 | /** |
| 518 | * Cached parse state for new components. |
| 519 | * |
| 520 | * Allows reuse of the same parse argument records to avoid GC pressure. Lifetime is carefully |
| 521 | * scoped to the parsing of a single application element. |
| 522 | */ |
| 523 | private static class CachedComponentArgs { |
| 524 | ParseComponentArgs mActivityArgs; |
| 525 | ParseComponentArgs mActivityAliasArgs; |
| 526 | ParseComponentArgs mServiceArgs; |
| 527 | ParseComponentArgs mProviderArgs; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Cached state for parsing instrumentation to avoid GC pressure. |
| 532 | * |
| 533 | * Must be manually reset to null for each new manifest. |
| 534 | */ |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 535 | private ParsePackageItemArgs mParseInstrumentationArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | /** If set to true, we will only allow package files that exactly match |
| 538 | * the DTD. Otherwise, we try to get as much from the package as we |
| 539 | * can without failing. This should normally be set to false, to |
| 540 | * support extensions to the DTD in future versions. */ |
| 541 | private static final boolean RIGID_PARSER = false; |
| 542 | |
| 543 | private static final String TAG = "PackageParser"; |
| 544 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 545 | public PackageParser() { |
| 546 | mMetrics = new DisplayMetrics(); |
| 547 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 548 | } |
| 549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | public void setSeparateProcesses(String[] procs) { |
| 551 | mSeparateProcesses = procs; |
| 552 | } |
| 553 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 554 | /** |
| 555 | * Flag indicating this parser should only consider apps with |
| 556 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 557 | * creating a minimalist boot environment. |
| 558 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 559 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 560 | mOnlyCoreApps = onlyCoreApps; |
| 561 | } |
| 562 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 563 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 564 | mMetrics = metrics; |
| 565 | } |
| 566 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 567 | /** |
| 568 | * Sets the cache directory for this package parser. |
| 569 | */ |
| 570 | public void setCacheDir(File cacheDir) { |
| 571 | mCacheDir = cacheDir; |
| 572 | } |
| 573 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 574 | /** |
| 575 | * Callback interface for retrieving information that may be needed while parsing |
| 576 | * a package. |
| 577 | */ |
| 578 | public interface Callback { |
| 579 | boolean hasFeature(String feature); |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 580 | String[] getOverlayPaths(String targetPackageName, String targetPath); |
| 581 | String[] getOverlayApks(String targetPackageName); |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Standard implementation of {@link Callback} on top of the public {@link PackageManager} |
| 586 | * class. |
| 587 | */ |
| 588 | public static final class CallbackImpl implements Callback { |
| 589 | private final PackageManager mPm; |
| 590 | |
| 591 | public CallbackImpl(PackageManager pm) { |
| 592 | mPm = pm; |
| 593 | } |
| 594 | |
| 595 | @Override public boolean hasFeature(String feature) { |
| 596 | return mPm.hasSystemFeature(feature); |
| 597 | } |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 598 | |
| 599 | @Override public String[] getOverlayPaths(String targetPackageName, String targetPath) { |
| 600 | return null; |
| 601 | } |
| 602 | |
| 603 | @Override public String[] getOverlayApks(String targetPackageName) { |
| 604 | return null; |
| 605 | } |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Set the {@link Callback} that can be used while parsing. |
| 610 | */ |
| 611 | public void setCallback(Callback cb) { |
| 612 | mCallback = cb; |
| 613 | } |
| 614 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 615 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 616 | return isApkPath(file.getName()); |
| 617 | } |
| 618 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 619 | public static boolean isApkPath(String path) { |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 620 | return path.endsWith(APK_FILE_EXTENSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 625 | * |
| 626 | * @param p the parsed package. |
| 627 | * @param flags indicating which optional information is included. |
| 628 | */ |
| 629 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 630 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 631 | Set<String> grantedPermissions, PackageUserState state) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 633 | return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 634 | grantedPermissions, state, UserHandle.getCallingUserId()); |
| 635 | } |
| 636 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 637 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 638 | * Returns true if the package is installed and not hidden, or if the caller |
| 639 | * explicitly wanted all uninstalled and hidden packages as well. |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 640 | * @param appInfo The applicationInfo of the app being checked. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 641 | */ |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 642 | private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state, |
| 643 | ApplicationInfo appInfo) { |
| 644 | // If available for the target user, or trying to match uninstalled packages and it's |
| 645 | // a system app. |
| 646 | return state.isAvailable(flags) |
| 647 | || (appInfo != null && appInfo.isSystemApp() |
| 648 | && (flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 651 | public static boolean isAvailable(PackageUserState state) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 652 | return checkUseInstalledOrHidden(0, state, null); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 653 | } |
| 654 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 655 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 656 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 657 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 658 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 659 | return null; |
| 660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | PackageInfo pi = new PackageInfo(); |
| 662 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 663 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | pi.versionCode = p.mVersionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 665 | pi.versionCodeMajor = p.mVersionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 666 | pi.baseRevisionCode = p.baseRevisionCode; |
| 667 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | pi.versionName = p.mVersionName; |
| 669 | pi.sharedUserId = p.mSharedUserId; |
| 670 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 671 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 672 | pi.installLocation = p.installLocation; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 673 | pi.isStub = p.isStub; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 674 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 675 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 676 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 677 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 678 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 679 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 680 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 681 | pi.overlayTarget = p.mOverlayTarget; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 682 | pi.overlayPriority = p.mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 683 | pi.mOverlayIsStatic = p.mOverlayIsStatic; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 684 | pi.compileSdkVersion = p.mCompileSdkVersion; |
| 685 | pi.compileSdkVersionCodename = p.mCompileSdkVersionCodename; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 686 | pi.firstInstallTime = firstInstallTime; |
| 687 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 689 | pi.gids = gids; |
| 690 | } |
| 691 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 692 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | if (N > 0) { |
| 694 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 695 | p.configPreferences.toArray(pi.configPreferences); |
| 696 | } |
| 697 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 698 | if (N > 0) { |
| 699 | pi.reqFeatures = new FeatureInfo[N]; |
| 700 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 702 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 703 | if (N > 0) { |
| 704 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 705 | p.featureGroups.toArray(pi.featureGroups); |
| 706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 708 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 709 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 711 | int num = 0; |
| 712 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 713 | for (int i = 0; i < N; i++) { |
| 714 | final Activity a = p.activities.get(i); |
| 715 | if (state.isMatch(a.info, flags)) { |
| 716 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | } |
| 718 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 719 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | } |
| 721 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 722 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 723 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 725 | int num = 0; |
| 726 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 727 | for (int i = 0; i < N; i++) { |
| 728 | final Activity a = p.receivers.get(i); |
| 729 | if (state.isMatch(a.info, flags)) { |
| 730 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | } |
| 732 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 733 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | } |
| 735 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 736 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 737 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 739 | int num = 0; |
| 740 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 741 | for (int i = 0; i < N; i++) { |
| 742 | final Service s = p.services.get(i); |
| 743 | if (state.isMatch(s.info, flags)) { |
| 744 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 747 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | } |
| 749 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 750 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 751 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 753 | int num = 0; |
| 754 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 755 | for (int i = 0; i < N; i++) { |
| 756 | final Provider pr = p.providers.get(i); |
| 757 | if (state.isMatch(pr.info, flags)) { |
| 758 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | } |
| 760 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 761 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 765 | int N = p.instrumentation.size(); |
| 766 | if (N > 0) { |
| 767 | pi.instrumentation = new InstrumentationInfo[N]; |
| 768 | for (int i=0; i<N; i++) { |
| 769 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 770 | p.instrumentation.get(i), flags); |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 775 | int N = p.permissions.size(); |
| 776 | if (N > 0) { |
| 777 | pi.permissions = new PermissionInfo[N]; |
| 778 | for (int i=0; i<N; i++) { |
| 779 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 780 | } |
| 781 | } |
| 782 | N = p.requestedPermissions.size(); |
| 783 | if (N > 0) { |
| 784 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 785 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 787 | final String perm = p.requestedPermissions.get(i); |
| 788 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 789 | // The notion of required permissions is deprecated but for compatibility. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 790 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 791 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
| 792 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
| 793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 797 | // deprecated method of getting signing certificates |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 799 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 800 | // Package has included signing certificate rotation information. Return the oldest |
| 801 | // cert so that programmatic checks keep working even if unaware of key rotation. |
| 802 | pi.signatures = new Signature[1]; |
| 803 | pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0]; |
| 804 | } else if (p.mSigningDetails.hasSignatures()) { |
| 805 | // otherwise keep old behavior |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 806 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 807 | pi.signatures = new Signature[numberOfSigs]; |
| 808 | System.arraycopy(p.mSigningDetails.signatures, 0, pi.signatures, 0, numberOfSigs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | } |
| 810 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 811 | |
| 812 | // replacement for GET_SIGNATURES |
| 813 | if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) { |
| 814 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 815 | // Package has included signing certificate rotation information. Convert each |
| 816 | // entry to an array |
| 817 | int numberOfSigs = p.mSigningDetails.pastSigningCertificates.length; |
| 818 | pi.signingCertificateHistory = new Signature[numberOfSigs][]; |
| 819 | for (int i = 0; i < numberOfSigs; i++) { |
| 820 | pi.signingCertificateHistory[i] = |
| 821 | new Signature[] { p.mSigningDetails.pastSigningCertificates[i] }; |
| 822 | } |
| 823 | } else if (p.mSigningDetails.hasSignatures()) { |
| 824 | // otherwise keep old behavior |
| 825 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 826 | pi.signingCertificateHistory = new Signature[1][numberOfSigs]; |
| 827 | System.arraycopy(p.mSigningDetails.signatures, 0, |
| 828 | pi.signingCertificateHistory[0], 0, numberOfSigs); |
| 829 | } |
| 830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | return pi; |
| 832 | } |
| 833 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 834 | public static final int PARSE_MUST_BE_APK = 1 << 0; |
| 835 | public static final int PARSE_IGNORE_PROCESSES = 1 << 1; |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 836 | /** @deprecated forward lock no longer functional. remove. */ |
| 837 | @Deprecated |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 838 | public static final int PARSE_FORWARD_LOCK = 1 << 2; |
| 839 | public static final int PARSE_EXTERNAL_STORAGE = 1 << 3; |
| 840 | public static final int PARSE_IS_SYSTEM_DIR = 1 << 4; |
| 841 | public static final int PARSE_COLLECT_CERTIFICATES = 1 << 5; |
| 842 | public static final int PARSE_ENFORCE_CODE = 1 << 6; |
| 843 | public static final int PARSE_FORCE_SDK = 1 << 7; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 844 | public static final int PARSE_CHATTY = 1 << 31; |
| 845 | |
| 846 | @IntDef(flag = true, prefix = { "PARSE_" }, value = { |
| 847 | PARSE_CHATTY, |
| 848 | PARSE_COLLECT_CERTIFICATES, |
| 849 | PARSE_ENFORCE_CODE, |
| 850 | PARSE_EXTERNAL_STORAGE, |
| 851 | PARSE_FORCE_SDK, |
| 852 | PARSE_FORWARD_LOCK, |
| 853 | PARSE_IGNORE_PROCESSES, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 854 | PARSE_IS_SYSTEM_DIR, |
| 855 | PARSE_MUST_BE_APK, |
| 856 | }) |
| 857 | @Retention(RetentionPolicy.SOURCE) |
| 858 | public @interface ParseFlags {} |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 859 | |
| 860 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 862 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 863 | * Used to sort a set of APKs based on their split names, always placing the |
| 864 | * base APK (with {@code null} split name) first. |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 865 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 866 | private static class SplitNameComparator implements Comparator<String> { |
| 867 | @Override |
| 868 | public int compare(String lhs, String rhs) { |
| 869 | if (lhs == null) { |
| 870 | return -1; |
| 871 | } else if (rhs == null) { |
| 872 | return 1; |
| 873 | } else { |
| 874 | return lhs.compareTo(rhs); |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 879 | /** |
| 880 | * Parse only lightweight details about the package at the given location. |
| 881 | * Automatically detects if the package is a monolithic style (single APK |
| 882 | * file) or cluster style (directory of APKs). |
| 883 | * <p> |
| 884 | * This performs sanity checking on cluster style packages, such as |
| 885 | * requiring identical package name and version codes, a single base APK, |
| 886 | * and unique split names. |
| 887 | * |
| 888 | * @see PackageParser#parsePackage(File, int) |
| 889 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 890 | public static PackageLite parsePackageLite(File packageFile, int flags) |
| 891 | throws PackageParserException { |
| 892 | if (packageFile.isDirectory()) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 893 | return parseClusterPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 894 | } else { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 895 | return parseMonolithicPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 899 | private static PackageLite parseMonolithicPackageLite(File packageFile, int flags) |
| 900 | throws PackageParserException { |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 901 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 902 | final ApkLite baseApk = parseApkLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 903 | final String packagePath = packageFile.getAbsolutePath(); |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 904 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 905 | return new PackageLite(packagePath, baseApk, null, null, null, null, null, null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 908 | static PackageLite parseClusterPackageLite(File packageDir, int flags) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 909 | throws PackageParserException { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 910 | final File[] files = packageDir.listFiles(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 911 | if (ArrayUtils.isEmpty(files)) { |
| 912 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 913 | "No packages found in split"); |
| 914 | } |
| 915 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 916 | String packageName = null; |
| 917 | int versionCode = 0; |
| 918 | |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 919 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 920 | final ArrayMap<String, ApkLite> apks = new ArrayMap<>(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 921 | for (File file : files) { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 922 | if (isApkFile(file)) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 923 | final ApkLite lite = parseApkLite(file, flags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 924 | |
| 925 | // Assert that all package names and version codes are |
| 926 | // consistent with the first one we encounter. |
| 927 | if (packageName == null) { |
| 928 | packageName = lite.packageName; |
| 929 | versionCode = lite.versionCode; |
| 930 | } else { |
| 931 | if (!packageName.equals(lite.packageName)) { |
| 932 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 933 | "Inconsistent package " + lite.packageName + " in " + file |
| 934 | + "; expected " + packageName); |
| 935 | } |
| 936 | if (versionCode != lite.versionCode) { |
| 937 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 938 | "Inconsistent version " + lite.versionCode + " in " + file |
| 939 | + "; expected " + versionCode); |
| 940 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 943 | // Assert that each split is defined only once |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 944 | if (apks.put(lite.splitName, lite) != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 945 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 946 | "Split name " + lite.splitName |
| 947 | + " defined more than once; most recent was " + file); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 951 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 952 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 953 | final ApkLite baseApk = apks.remove(null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 954 | if (baseApk == null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 955 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 956 | "Missing base APK in " + packageDir); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 959 | // Always apply deterministic ordering based on splitName |
| 960 | final int size = apks.size(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 961 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 962 | String[] splitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 963 | boolean[] isFeatureSplits = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 964 | String[] usesSplitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 965 | String[] configForSplits = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 966 | String[] splitCodePaths = null; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 967 | int[] splitRevisionCodes = null; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 968 | String[] splitClassLoaderNames = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 969 | if (size > 0) { |
| 970 | splitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 971 | isFeatureSplits = new boolean[size]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 972 | usesSplitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 973 | configForSplits = new String[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 974 | splitCodePaths = new String[size]; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 975 | splitRevisionCodes = new int[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 976 | |
| 977 | splitNames = apks.keySet().toArray(splitNames); |
| 978 | Arrays.sort(splitNames, sSplitNameComparator); |
| 979 | |
| 980 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 981 | final ApkLite apk = apks.get(splitNames[i]); |
| 982 | usesSplitNames[i] = apk.usesSplitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 983 | isFeatureSplits[i] = apk.isFeatureSplit; |
| 984 | configForSplits[i] = apk.configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 985 | splitCodePaths[i] = apk.codePath; |
| 986 | splitRevisionCodes[i] = apk.revisionCode; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 987 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 990 | final String codePath = packageDir.getAbsolutePath(); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 991 | return new PackageLite(codePath, baseApk, splitNames, isFeatureSplits, usesSplitNames, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 992 | configForSplits, splitCodePaths, splitRevisionCodes); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 995 | /** |
| 996 | * Parse the package at the given location. Automatically detects if the |
| 997 | * package is a monolithic style (single APK file) or cluster style |
| 998 | * (directory of APKs). |
| 999 | * <p> |
| 1000 | * This performs sanity checking on cluster style packages, such as |
| 1001 | * requiring identical package name and version codes, a single base APK, |
| 1002 | * and unique split names. |
| 1003 | * <p> |
| 1004 | * Note that this <em>does not</em> perform signature verification; that |
| 1005 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1006 | * |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1007 | * If {@code useCaches} is true, the package parser might return a cached |
| 1008 | * result from a previous parse of the same {@code packageFile} with the same |
| 1009 | * {@code flags}. Note that this method does not check whether {@code packageFile} |
| 1010 | * has changed since the last parse, it's up to callers to do so. |
| 1011 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1012 | * @see #parsePackageLite(File, int) |
| 1013 | */ |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1014 | public Package parsePackage(File packageFile, int flags, boolean useCaches) |
| 1015 | throws PackageParserException { |
| 1016 | Package parsed = useCaches ? getCachedResult(packageFile, flags) : null; |
| 1017 | if (parsed != null) { |
| 1018 | return parsed; |
| 1019 | } |
| 1020 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1021 | long parseTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1022 | if (packageFile.isDirectory()) { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1023 | parsed = parseClusterPackage(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1024 | } else { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1025 | parsed = parseMonolithicPackage(packageFile, flags); |
| 1026 | } |
| 1027 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1028 | long cacheTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1029 | cacheResult(packageFile, flags, parsed); |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1030 | if (LOG_PARSE_TIMINGS) { |
| 1031 | parseTime = cacheTime - parseTime; |
| 1032 | cacheTime = SystemClock.uptimeMillis() - cacheTime; |
| 1033 | if (parseTime + cacheTime > LOG_PARSE_TIMINGS_THRESHOLD_MS) { |
| 1034 | Slog.i(TAG, "Parse times for '" + packageFile + "': parse=" + parseTime |
| 1035 | + "ms, update_cache=" + cacheTime + " ms"); |
| 1036 | } |
| 1037 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1038 | return parsed; |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * Equivalent to {@link #parsePackage(File, int, boolean)} with {@code useCaches == false}. |
| 1043 | */ |
| 1044 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 1045 | return parsePackage(packageFile, flags, false /* useCaches */); |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Returns the cache key for a specificied {@code packageFile} and {@code flags}. |
| 1050 | */ |
| 1051 | private String getCacheKey(File packageFile, int flags) { |
| 1052 | StringBuilder sb = new StringBuilder(packageFile.getName()); |
| 1053 | sb.append('-'); |
| 1054 | sb.append(flags); |
| 1055 | |
| 1056 | return sb.toString(); |
| 1057 | } |
| 1058 | |
| 1059 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1060 | protected Package fromCacheEntry(byte[] bytes) { |
| 1061 | return fromCacheEntryStatic(bytes); |
| 1062 | } |
| 1063 | |
| 1064 | /** static version of {@link #fromCacheEntry} for unit tests. */ |
| 1065 | @VisibleForTesting |
| 1066 | public static Package fromCacheEntryStatic(byte[] bytes) { |
| 1067 | final Parcel p = Parcel.obtain(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1068 | p.unmarshall(bytes, 0, bytes.length); |
| 1069 | p.setDataPosition(0); |
| 1070 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1071 | final ReadHelper helper = new ReadHelper(p); |
| 1072 | helper.startAndInstall(); |
| 1073 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1074 | PackageParser.Package pkg = new PackageParser.Package(p); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1075 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1076 | p.recycle(); |
| 1077 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1078 | sCachedPackageReadCount.incrementAndGet(); |
| 1079 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1080 | return pkg; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1084 | protected byte[] toCacheEntry(Package pkg) { |
| 1085 | return toCacheEntryStatic(pkg); |
| 1086 | |
| 1087 | } |
| 1088 | |
| 1089 | /** static version of {@link #toCacheEntry} for unit tests. */ |
| 1090 | @VisibleForTesting |
| 1091 | public static byte[] toCacheEntryStatic(Package pkg) { |
| 1092 | final Parcel p = Parcel.obtain(); |
| 1093 | final WriteHelper helper = new WriteHelper(p); |
| 1094 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1095 | pkg.writeToParcel(p, 0 /* flags */); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1096 | |
| 1097 | helper.finishAndUninstall(); |
| 1098 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1099 | byte[] serialized = p.marshall(); |
| 1100 | p.recycle(); |
| 1101 | |
| 1102 | return serialized; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | /** |
| 1106 | * Given a {@code packageFile} and a {@code cacheFile} returns whether the |
| 1107 | * cache file is up to date based on the mod-time of both files. |
| 1108 | */ |
| 1109 | private static boolean isCacheUpToDate(File packageFile, File cacheFile) { |
| 1110 | try { |
| 1111 | // NOTE: We don't use the File.lastModified API because it has the very |
| 1112 | // non-ideal failure mode of returning 0 with no excepions thrown. |
| 1113 | // The nio2 Files API is a little better but is considerably more expensive. |
| 1114 | final StructStat pkg = android.system.Os.stat(packageFile.getAbsolutePath()); |
| 1115 | final StructStat cache = android.system.Os.stat(cacheFile.getAbsolutePath()); |
| 1116 | return pkg.st_mtime < cache.st_mtime; |
| 1117 | } catch (ErrnoException ee) { |
| 1118 | // The most common reason why stat fails is that a given cache file doesn't |
| 1119 | // exist. We ignore that here. It's easy to reason that it's safe to say the |
| 1120 | // cache isn't up to date if we see any sort of exception here. |
| 1121 | // |
| 1122 | // (1) Exception while stating the package file : This should never happen, |
| 1123 | // and if it does, we do a full package parse (which is likely to throw the |
| 1124 | // same exception). |
| 1125 | // (2) Exception while stating the cache file : If the file doesn't exist, the |
| 1126 | // cache is obviously out of date. If the file *does* exist, we can't read it. |
| 1127 | // We will attempt to delete and recreate it after parsing the package. |
| 1128 | if (ee.errno != OsConstants.ENOENT) { |
| 1129 | Slog.w("Error while stating package cache : ", ee); |
| 1130 | } |
| 1131 | |
| 1132 | return false; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Returns the cached parse result for {@code packageFile} for parse flags {@code flags}, |
| 1138 | * or {@code null} if no cached result exists. |
| 1139 | */ |
| 1140 | private Package getCachedResult(File packageFile, int flags) { |
| 1141 | if (mCacheDir == null) { |
| 1142 | return null; |
| 1143 | } |
| 1144 | |
| 1145 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1146 | final File cacheFile = new File(mCacheDir, cacheKey); |
| 1147 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1148 | try { |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1149 | // If the cache is not up to date, return null. |
| 1150 | if (!isCacheUpToDate(packageFile, cacheFile)) { |
| 1151 | return null; |
| 1152 | } |
| 1153 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1154 | final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath()); |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1155 | Package p = fromCacheEntry(bytes); |
| 1156 | if (mCallback != null) { |
| 1157 | String[] overlayApks = mCallback.getOverlayApks(p.packageName); |
| 1158 | if (overlayApks != null && overlayApks.length > 0) { |
| 1159 | for (String overlayApk : overlayApks) { |
| 1160 | // If a static RRO is updated, return null. |
| 1161 | if (!isCacheUpToDate(new File(overlayApk), cacheFile)) { |
| 1162 | return null; |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | return p; |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1168 | } catch (Throwable e) { |
Narayan Kamath | 21a2838 | 2017-01-13 10:34:29 +0000 | [diff] [blame] | 1169 | Slog.w(TAG, "Error reading package cache: ", e); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1170 | |
| 1171 | // If something went wrong while reading the cache entry, delete the cache file |
| 1172 | // so that we regenerate it the next time. |
| 1173 | cacheFile.delete(); |
| 1174 | return null; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Caches the parse result for {@code packageFile} with flags {@code flags}. |
| 1180 | */ |
| 1181 | private void cacheResult(File packageFile, int flags, Package parsed) { |
| 1182 | if (mCacheDir == null) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1186 | try { |
| 1187 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1188 | final File cacheFile = new File(mCacheDir, cacheKey); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1189 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1190 | if (cacheFile.exists()) { |
| 1191 | if (!cacheFile.delete()) { |
| 1192 | Slog.e(TAG, "Unable to delete cache file: " + cacheFile); |
| 1193 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1194 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1195 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1196 | final byte[] cacheEntry = toCacheEntry(parsed); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1197 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1198 | if (cacheEntry == null) { |
| 1199 | return; |
| 1200 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1201 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1202 | try (FileOutputStream fos = new FileOutputStream(cacheFile)) { |
| 1203 | fos.write(cacheEntry); |
| 1204 | } catch (IOException ioe) { |
| 1205 | Slog.w(TAG, "Error writing cache entry.", ioe); |
| 1206 | cacheFile.delete(); |
| 1207 | } |
| 1208 | } catch (Throwable e) { |
| 1209 | Slog.w(TAG, "Error saving package cache.", e); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * Parse all APKs contained in the given directory, treating them as a |
| 1215 | * single package. This also performs sanity checking, such as requiring |
| 1216 | * identical package name and version codes, a single base APK, and unique |
| 1217 | * split names. |
| 1218 | * <p> |
| 1219 | * Note that this <em>does not</em> perform signature verification; that |
| 1220 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1221 | */ |
| 1222 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1223 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1224 | if (mOnlyCoreApps && !lite.coreApp) { |
| 1225 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1226 | "Not a coreApp: " + packageDir); |
| 1227 | } |
| 1228 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1229 | // Build the split dependency tree. |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1230 | SparseArray<int[]> splitDependencies = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1231 | final SplitAssetLoader assetLoader; |
| 1232 | if (lite.isolatedSplits && !ArrayUtils.isEmpty(lite.splitNames)) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1233 | try { |
| 1234 | splitDependencies = SplitAssetDependencyLoader.createDependenciesFromPackage(lite); |
| 1235 | assetLoader = new SplitAssetDependencyLoader(lite, splitDependencies, flags); |
| 1236 | } catch (SplitAssetDependencyLoader.IllegalDependencyException e) { |
| 1237 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, e.getMessage()); |
| 1238 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1239 | } else { |
| 1240 | assetLoader = new DefaultSplitAssetLoader(lite, flags); |
| 1241 | } |
| 1242 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1243 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1244 | final AssetManager assets = assetLoader.getBaseAssetManager(); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1245 | final File baseApk = new File(lite.baseCodePath); |
| 1246 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 1247 | if (pkg == null) { |
| 1248 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1249 | "Failed to parse base APK: " + baseApk); |
| 1250 | } |
| 1251 | |
| 1252 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 1253 | final int num = lite.splitNames.length; |
| 1254 | pkg.splitNames = lite.splitNames; |
| 1255 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1256 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1257 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1258 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1259 | pkg.applicationInfo.splitNames = pkg.splitNames; |
| 1260 | pkg.applicationInfo.splitDependencies = splitDependencies; |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 1261 | pkg.applicationInfo.splitClassLoaderNames = new String[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1262 | |
| 1263 | for (int i = 0; i < num; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1264 | final AssetManager splitAssets = assetLoader.getSplitAssetManager(i); |
| 1265 | parseSplitApk(pkg, i, splitAssets, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1269 | pkg.setCodePath(packageDir.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1270 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1271 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1272 | } catch (IOException e) { |
| 1273 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1274 | "Failed to get path: " + lite.baseCodePath, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1275 | } finally { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1276 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1280 | /** |
| 1281 | * Parse the given APK file, treating it as as a single monolithic package. |
| 1282 | * <p> |
| 1283 | * Note that this <em>does not</em> perform signature verification; that |
| 1284 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1285 | * |
| 1286 | * @deprecated external callers should move to |
| 1287 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 1288 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1289 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1290 | @Deprecated |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1291 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1292 | final AssetManager assets = newConfiguredAssetManager(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1293 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1294 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1295 | if (!lite.coreApp) { |
| 1296 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1297 | "Not a coreApp: " + apkFile); |
| 1298 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1299 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1300 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1301 | try { |
| 1302 | final Package pkg = parseBaseApk(apkFile, assets, flags); |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1303 | pkg.setCodePath(apkFile.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1304 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1305 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1306 | } catch (IOException e) { |
| 1307 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1308 | "Failed to get path: " + apkFile, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1309 | } finally { |
| 1310 | IoUtils.closeQuietly(assets); |
| 1311 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1314 | private static int loadApkIntoAssetManager(AssetManager assets, String apkPath, int flags) |
| 1315 | throws PackageParserException { |
| 1316 | if ((flags & PARSE_MUST_BE_APK) != 0 && !isApkPath(apkPath)) { |
| 1317 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1318 | "Invalid package file: " + apkPath); |
| 1319 | } |
| 1320 | |
| 1321 | // The AssetManager guarantees uniqueness for asset paths, so if this asset path |
| 1322 | // already exists in the AssetManager, addAssetPath will only return the cookie |
| 1323 | // assigned to it. |
| 1324 | int cookie = assets.addAssetPath(apkPath); |
| 1325 | if (cookie == 0) { |
| 1326 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1327 | "Failed adding asset path: " + apkPath); |
| 1328 | } |
| 1329 | return cookie; |
| 1330 | } |
| 1331 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1332 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 1333 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1334 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1335 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1336 | String volumeUuid = null; |
| 1337 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 1338 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 1339 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 1340 | } |
| 1341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1343 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1344 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1345 | if (DEBUG_JAR) Slog.d(TAG, "Scanning base APK: " + apkPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1347 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 1348 | |
| 1349 | Resources res = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1350 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | try { |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1352 | res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1353 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
| 1354 | |
| 1355 | final String[] outError = new String[1]; |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1356 | final Package pkg = parseBaseApk(apkPath, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1357 | if (pkg == null) { |
| 1358 | throw new PackageParserException(mParseError, |
| 1359 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1361 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1362 | pkg.setVolumeUuid(volumeUuid); |
| 1363 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 1364 | pkg.setBaseCodePath(apkPath); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1365 | pkg.setSigningDetails(SigningDetails.UNKNOWN); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1366 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1367 | return pkg; |
| 1368 | |
| 1369 | } catch (PackageParserException e) { |
| 1370 | throw e; |
| 1371 | } catch (Exception e) { |
| 1372 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1373 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1374 | } finally { |
| 1375 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1379 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1380 | throws PackageParserException { |
| 1381 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1382 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1383 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 1384 | mArchiveSourcePath = apkPath; |
| 1385 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1386 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 1387 | |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1388 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 1389 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1390 | final Resources res; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1391 | XmlResourceParser parser = null; |
| 1392 | try { |
Adam Lesinski | e70b57a | 2017-12-01 18:22:37 -0800 | [diff] [blame] | 1393 | res = new Resources(assets, mMetrics, null); |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1394 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1395 | Build.VERSION.RESOURCES_SDK_INT); |
| 1396 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1397 | |
| 1398 | final String[] outError = new String[1]; |
| 1399 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 1400 | if (pkg == null) { |
| 1401 | throw new PackageParserException(mParseError, |
| 1402 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 1403 | } |
| 1404 | |
| 1405 | } catch (PackageParserException e) { |
| 1406 | throw e; |
| 1407 | } catch (Exception e) { |
| 1408 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1409 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1410 | } finally { |
| 1411 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * Parse the manifest of a <em>split APK</em>. |
| 1417 | * <p> |
| 1418 | * Note that split APKs have many more restrictions on what they're capable |
| 1419 | * of doing, so many valid features of a base APK have been carefully |
| 1420 | * omitted here. |
| 1421 | */ |
| 1422 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1423 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1424 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1425 | AttributeSet attrs = parser; |
| 1426 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1427 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1428 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1429 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1430 | mParseInstrumentationArgs = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1431 | |
| 1432 | int type; |
| 1433 | |
| 1434 | boolean foundApp = false; |
| 1435 | |
| 1436 | int outerDepth = parser.getDepth(); |
| 1437 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1438 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1439 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1440 | continue; |
| 1441 | } |
| 1442 | |
| 1443 | String tagName = parser.getName(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1444 | if (tagName.equals(TAG_APPLICATION)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1445 | if (foundApp) { |
| 1446 | if (RIGID_PARSER) { |
| 1447 | outError[0] = "<manifest> has more than one <application>"; |
| 1448 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1449 | return null; |
| 1450 | } else { |
| 1451 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1452 | XmlUtils.skipCurrentTag(parser); |
| 1453 | continue; |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1458 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1459 | return null; |
| 1460 | } |
| 1461 | |
| 1462 | } else if (RIGID_PARSER) { |
| 1463 | outError[0] = "Bad element under <manifest>: " |
| 1464 | + parser.getName(); |
| 1465 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1466 | return null; |
| 1467 | |
| 1468 | } else { |
| 1469 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1470 | + " at " + mArchiveSourcePath + " " |
| 1471 | + parser.getPositionDescription()); |
| 1472 | XmlUtils.skipCurrentTag(parser); |
| 1473 | continue; |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | if (!foundApp) { |
| 1478 | outError[0] = "<manifest> does not contain an <application>"; |
| 1479 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1480 | } |
| 1481 | |
| 1482 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1485 | /** Parses the public keys from the set of signatures. */ |
| 1486 | public static ArraySet<PublicKey> toSigningKeys(Signature[] signatures) |
| 1487 | throws CertificateException { |
| 1488 | ArraySet<PublicKey> keys = new ArraySet<>(signatures.length); |
| 1489 | for (int i = 0; i < signatures.length; i++) { |
| 1490 | keys.add(signatures[i].getPublicKey()); |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1491 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1492 | return keys; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1496 | * Collect certificates from all the APKs described in the given package, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1497 | * populating {@link Package#mSigningDetails}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1498 | * contents are signed correctly and consistently. |
| 1499 | */ |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1500 | public static void collectCertificates(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1501 | throws PackageParserException { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1502 | collectCertificatesInternal(pkg, skipVerify); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1503 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1504 | for (int i = 0; i < childCount; i++) { |
| 1505 | Package childPkg = pkg.childPackages.get(i); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1506 | childPkg.mSigningDetails = pkg.mSigningDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1510 | private static void collectCertificatesInternal(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1511 | throws PackageParserException { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1512 | pkg.mSigningDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1513 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1514 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1515 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1516 | collectCertificates(pkg, new File(pkg.baseCodePath), skipVerify); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1517 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1518 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
| 1519 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1520 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1521 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1522 | } |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1523 | } finally { |
| 1524 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1528 | private static void collectCertificates(Package pkg, File apkFile, boolean skipVerify) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1529 | throws PackageParserException { |
| 1530 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1532 | int minSignatureScheme = SigningDetails.SignatureSchemeVersion.JAR; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1533 | if (pkg.applicationInfo.isStaticSharedLibrary()) { |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1534 | // must use v2 signing scheme |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1535 | minSignatureScheme = SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1536 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1537 | SigningDetails verified; |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1538 | if (skipVerify) { |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1539 | // systemDir APKs are already trusted, save time by not verifying |
| 1540 | verified = ApkSignatureVerifier.plsCertsNoVerifyOnlyCerts( |
| 1541 | apkPath, minSignatureScheme); |
| 1542 | } else { |
| 1543 | verified = ApkSignatureVerifier.verify(apkPath, minSignatureScheme); |
| 1544 | } |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1545 | |
| 1546 | // Verify that entries are signed consistently with the first pkg |
| 1547 | // we encountered. Note that for splits, certificates may have |
| 1548 | // already been populated during an earlier parse of a base APK. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1549 | if (pkg.mSigningDetails == SigningDetails.UNKNOWN) { |
| 1550 | pkg.mSigningDetails = verified; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1551 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1552 | if (!Signature.areExactMatch(pkg.mSigningDetails.signatures, verified.signatures)) { |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1553 | throw new PackageParserException( |
| 1554 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1555 | apkPath + " has mismatched certificates"); |
| 1556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | } |
| 1559 | |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1560 | private static AssetManager newConfiguredAssetManager() { |
| 1561 | AssetManager assetManager = new AssetManager(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 1562 | assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1563 | Build.VERSION.RESOURCES_SDK_INT); |
| 1564 | return assetManager; |
| 1565 | } |
| 1566 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1567 | /** |
| 1568 | * Utility method that retrieves lightweight details about a single APK |
| 1569 | * file, including package name, split name, and install location. |
| 1570 | * |
| 1571 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1572 | * @param flags optional parse flags, such as |
| 1573 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1574 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1575 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1576 | throws PackageParserException { |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 1577 | return parseApkLiteInner(apkFile, null, null, flags); |
| 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * Utility method that retrieves lightweight details about a single APK |
| 1582 | * file, including package name, split name, and install location. |
| 1583 | * |
| 1584 | * @param fd already open file descriptor of an apk file |
| 1585 | * @param debugPathName arbitrary text name for this file, for debug output |
| 1586 | * @param flags optional parse flags, such as |
| 1587 | * {@link #PARSE_COLLECT_CERTIFICATES} |
| 1588 | */ |
| 1589 | public static ApkLite parseApkLite(FileDescriptor fd, String debugPathName, int flags) |
| 1590 | throws PackageParserException { |
| 1591 | return parseApkLiteInner(null, fd, debugPathName, flags); |
| 1592 | } |
| 1593 | |
| 1594 | private static ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd, String debugPathName, |
| 1595 | int flags) throws PackageParserException { |
| 1596 | final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1597 | |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1598 | ApkAssets apkAssets = null; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1599 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | try { |
Adam Lesinski | dcb3c65 | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 1601 | try { |
| 1602 | apkAssets = fd != null |
| 1603 | ? ApkAssets.loadFromFd(fd, debugPathName, false, false) |
| 1604 | : ApkAssets.loadFromPath(apkPath); |
| 1605 | } catch (IOException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1606 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1607 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Adam Lesinski | dcb3c65 | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 1610 | parser = apkAssets.openXml(ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1611 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1612 | final SigningDetails signingDetails; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1613 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1614 | // TODO: factor signature related items out of Package object |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1615 | final Package tempPkg = new Package((String) null); |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1616 | final boolean skipVerify = (flags & PARSE_IS_SYSTEM_DIR) != 0; |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1617 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1618 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1619 | collectCertificates(tempPkg, apkFile, skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1620 | } finally { |
| 1621 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1622 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1623 | signingDetails = tempPkg.mSigningDetails; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1624 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1625 | signingDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1626 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1627 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1628 | final AttributeSet attrs = parser; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1629 | return parseApkLite(apkPath, parser, attrs, signingDetails); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1630 | |
| 1631 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 1632 | Slog.w(TAG, "Failed to parse " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1633 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1634 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1636 | IoUtils.closeQuietly(parser); |
Artem Iglikov | 16b3dff | 2018-01-25 13:59:13 +0000 | [diff] [blame] | 1637 | IoUtils.closeQuietly(apkAssets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1641 | private static String validateName(String name, boolean requireSeparator, |
| 1642 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | final int N = name.length(); |
| 1644 | boolean hasSep = false; |
| 1645 | boolean front = true; |
| 1646 | for (int i=0; i<N; i++) { |
| 1647 | final char c = name.charAt(i); |
| 1648 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1649 | front = false; |
| 1650 | continue; |
| 1651 | } |
| 1652 | if (!front) { |
| 1653 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1654 | continue; |
| 1655 | } |
| 1656 | } |
| 1657 | if (c == '.') { |
| 1658 | hasSep = true; |
| 1659 | front = true; |
| 1660 | continue; |
| 1661 | } |
| 1662 | return "bad character '" + c + "'"; |
| 1663 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1664 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1665 | return "Invalid filename"; |
| 1666 | } |
| 1667 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | ? null : "must have at least one '.' separator"; |
| 1669 | } |
| 1670 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1671 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1672 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1673 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | |
| 1675 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1676 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1677 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | } |
| 1679 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1680 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1681 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1682 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1684 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1685 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1686 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | } |
| 1688 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1689 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1690 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1691 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1692 | if (error != null) { |
| 1693 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1694 | "Invalid manifest package: " + error); |
| 1695 | } |
| 1696 | } |
| 1697 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1698 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1699 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1700 | if (splitName.length() == 0) { |
| 1701 | splitName = null; |
| 1702 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1703 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1704 | if (error != null) { |
| 1705 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1706 | "Invalid manifest split: " + error); |
| 1707 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | return Pair.create(packageName.intern(), |
| 1712 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1715 | private static ApkLite parseApkLite(String codePath, XmlPullParser parser, AttributeSet attrs, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1716 | SigningDetails signingDetails) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1717 | throws IOException, XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1718 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1719 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1720 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1721 | int versionCode = 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1722 | int versionCodeMajor = 0; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1723 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1724 | boolean coreApp = false; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1725 | boolean debuggable = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1726 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1727 | boolean use32bitAbi = false; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1728 | boolean extractNativeLibs = true; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1729 | boolean isolatedSplits = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1730 | boolean isFeatureSplit = false; |
| 1731 | String configForSplit = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1732 | String usesSplitName = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1733 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1734 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1735 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1736 | if (attr.equals("installLocation")) { |
| 1737 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1738 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1739 | } else if (attr.equals("versionCode")) { |
| 1740 | versionCode = attrs.getAttributeIntValue(i, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1741 | } else if (attr.equals("versionCodeMajor")) { |
| 1742 | versionCodeMajor = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1743 | } else if (attr.equals("revisionCode")) { |
| 1744 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1745 | } else if (attr.equals("coreApp")) { |
| 1746 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1747 | } else if (attr.equals("isolatedSplits")) { |
| 1748 | isolatedSplits = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1749 | } else if (attr.equals("configForSplit")) { |
| 1750 | configForSplit = attrs.getAttributeValue(i); |
| 1751 | } else if (attr.equals("isFeatureSplit")) { |
| 1752 | isFeatureSplit = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1753 | } |
| 1754 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1755 | |
| 1756 | // Only search the tree when the tag is directly below <manifest> |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1757 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1758 | final int searchDepth = parser.getDepth() + 1; |
| 1759 | |
| 1760 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1761 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1762 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1763 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1764 | continue; |
| 1765 | } |
| 1766 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1767 | if (parser.getDepth() != searchDepth) { |
| 1768 | continue; |
| 1769 | } |
| 1770 | |
| 1771 | if (TAG_PACKAGE_VERIFIER.equals(parser.getName())) { |
| 1772 | final VerifierInfo verifier = parseVerifier(attrs); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1773 | if (verifier != null) { |
| 1774 | verifiers.add(verifier); |
| 1775 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1776 | } else if (TAG_APPLICATION.equals(parser.getName())) { |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1777 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1778 | final String attr = attrs.getAttributeName(i); |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1779 | if ("debuggable".equals(attr)) { |
| 1780 | debuggable = attrs.getAttributeBooleanValue(i, false); |
| 1781 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1782 | if ("multiArch".equals(attr)) { |
| 1783 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1784 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1785 | if ("use32bitAbi".equals(attr)) { |
| 1786 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1787 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1788 | if ("extractNativeLibs".equals(attr)) { |
| 1789 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1790 | } |
| 1791 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1792 | } else if (TAG_USES_SPLIT.equals(parser.getName())) { |
| 1793 | if (usesSplitName != null) { |
| 1794 | Slog.w(TAG, "Only one <uses-split> permitted. Ignoring others."); |
| 1795 | continue; |
| 1796 | } |
| 1797 | |
| 1798 | usesSplitName = attrs.getAttributeValue(ANDROID_RESOURCES, "name"); |
| 1799 | if (usesSplitName == null) { |
| 1800 | throw new PackageParserException( |
| 1801 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1802 | "<uses-split> tag requires 'android:name' attribute"); |
| 1803 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1804 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1807 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, isFeatureSplit, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1808 | configForSplit, usesSplitName, versionCode, versionCodeMajor, revisionCode, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1809 | installLocation, verifiers, signingDetails, coreApp, debuggable, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1810 | multiArch, use32bitAbi, extractNativeLibs, isolatedSplits); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1813 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1814 | * Parses a child package and adds it to the parent if successful. If you add |
| 1815 | * new tags that need to be supported by child packages make sure to add them |
| 1816 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1817 | * |
| 1818 | * @param parentPkg The parent that contains the child |
| 1819 | * @param res Resources against which to resolve values |
| 1820 | * @param parser Parser of the manifest |
| 1821 | * @param flags Flags about how to parse |
| 1822 | * @param outError Human readable error if parsing fails |
| 1823 | * @return True of parsing succeeded. |
| 1824 | * |
| 1825 | * @throws XmlPullParserException |
| 1826 | * @throws IOException |
| 1827 | */ |
| 1828 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1829 | int flags, String[] outError) throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1830 | // Make sure we have a valid child package name |
| 1831 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1832 | if (validateName(childPackageName, true, false) != null) { |
| 1833 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1834 | return false; |
| 1835 | } |
| 1836 | |
| 1837 | // Child packages must be unique |
| 1838 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1839 | String message = "Child package name cannot be equal to parent package name: " |
| 1840 | + parentPkg.packageName; |
| 1841 | Slog.w(TAG, message); |
| 1842 | outError[0] = message; |
| 1843 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | // Child packages must be unique |
| 1848 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1849 | String message = "Duplicate child package:" + childPackageName; |
| 1850 | Slog.w(TAG, message); |
| 1851 | outError[0] = message; |
| 1852 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | // Go ahead and parse the child |
| 1857 | Package childPkg = new Package(childPackageName); |
| 1858 | |
| 1859 | // Child package inherits parent version code/name/target SDK |
| 1860 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1861 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1862 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1863 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1864 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1865 | |
| 1866 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1867 | if (childPkg == null) { |
| 1868 | // If we got null then error was set during child parsing |
| 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | // Set the parent-child relation |
| 1873 | if (parentPkg.childPackages == null) { |
| 1874 | parentPkg.childPackages = new ArrayList<>(); |
| 1875 | } |
| 1876 | parentPkg.childPackages.add(childPkg); |
| 1877 | childPkg.parentPackage = parentPkg; |
| 1878 | |
| 1879 | return true; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1884 | * need to consider whether they should be supported by split APKs and child |
| 1885 | * packages. |
| 1886 | * |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1887 | * @param apkPath The package apk file path |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1888 | * @param res The resources from which to resolve values |
| 1889 | * @param parser The manifest parser |
| 1890 | * @param flags Flags how to parse |
| 1891 | * @param outError Human readable error message |
| 1892 | * @return Parsed package or null on error. |
| 1893 | * |
| 1894 | * @throws XmlPullParserException |
| 1895 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1896 | */ |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1897 | private Package parseBaseApk(String apkPath, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1898 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1899 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1900 | final String pkgName; |
| 1901 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1902 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1903 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1904 | pkgName = packageSplit.first; |
| 1905 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1906 | |
| 1907 | if (!TextUtils.isEmpty(splitName)) { |
| 1908 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1909 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1910 | return null; |
| 1911 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1912 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1914 | return null; |
| 1915 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1916 | |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1917 | if (mCallback != null) { |
| 1918 | String[] overlayPaths = mCallback.getOverlayPaths(pkgName, apkPath); |
| 1919 | if (overlayPaths != null && overlayPaths.length > 0) { |
| 1920 | for (String overlayPath : overlayPaths) { |
| 1921 | res.getAssets().addOverlayPath(overlayPath); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1926 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1927 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1928 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1930 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1931 | pkg.mVersionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1933 | pkg.mVersionCodeMajor = sa.getInteger( |
| 1934 | com.android.internal.R.styleable.AndroidManifest_versionCodeMajor, 0); |
| 1935 | pkg.applicationInfo.versionCode = pkg.getLongVersionCode(); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1936 | pkg.baseRevisionCode = sa.getInteger( |
| 1937 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1938 | pkg.mVersionName = sa.getNonConfigurationString( |
| 1939 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | if (pkg.mVersionName != null) { |
| 1941 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 1942 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1943 | |
| 1944 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 1945 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1946 | pkg.mCompileSdkVersion = sa.getInteger( |
| 1947 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersion, 0); |
| 1948 | pkg.applicationInfo.compileSdkVersion = pkg.mCompileSdkVersion; |
| 1949 | pkg.mCompileSdkVersionCodename = sa.getNonConfigurationString( |
| 1950 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersionCodename, 0); |
| 1951 | if (pkg.mCompileSdkVersionCodename != null) { |
| 1952 | pkg.mCompileSdkVersionCodename = pkg.mCompileSdkVersionCodename.intern(); |
| 1953 | } |
| 1954 | pkg.applicationInfo.compileSdkVersionCodename = pkg.mCompileSdkVersionCodename; |
| 1955 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1956 | sa.recycle(); |
| 1957 | |
| 1958 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * This is the common parsing routing for handling parent and child |
| 1963 | * packages in a base APK. The difference between parent and child |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1964 | * parsing is that some tags are not supported by child packages as |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1965 | * well as some manifest attributes are ignored. The implementation |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1966 | * assumes the calling code has already handled the manifest tag if needed |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1967 | * (this applies to the parent only). |
| 1968 | * |
| 1969 | * @param pkg The package which to populate |
| 1970 | * @param acceptedTags Which tags to handle, null to handle all |
| 1971 | * @param res Resources against which to resolve values |
| 1972 | * @param parser Parser of the manifest |
| 1973 | * @param flags Flags about how to parse |
| 1974 | * @param outError Human readable error if parsing fails |
| 1975 | * @return The package if parsing succeeded or null. |
| 1976 | * |
| 1977 | * @throws XmlPullParserException |
| 1978 | * @throws IOException |
| 1979 | */ |
| 1980 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 1981 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 1982 | IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1983 | mParseInstrumentationArgs = null; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1984 | |
| 1985 | int type; |
| 1986 | boolean foundApp = false; |
| 1987 | |
| 1988 | TypedArray sa = res.obtainAttributes(parser, |
| 1989 | com.android.internal.R.styleable.AndroidManifest); |
| 1990 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1991 | String str = sa.getNonConfigurationString( |
| 1992 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 1993 | if (str != null && str.length() > 0) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1994 | String nameError = validateName(str, true, false); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1995 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 1997 | + str + "\": " + nameError; |
| 1998 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 1999 | return null; |
| 2000 | } |
| 2001 | pkg.mSharedUserId = str.intern(); |
| 2002 | pkg.mSharedUserLabel = sa.getResourceId( |
| 2003 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 2004 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 2005 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 2006 | pkg.installLocation = sa.getInteger( |
| 2007 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 2008 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2009 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2010 | |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 2011 | final int targetSandboxVersion = sa.getInteger( |
| 2012 | com.android.internal.R.styleable.AndroidManifest_targetSandboxVersion, |
| 2013 | PARSE_DEFAULT_TARGET_SANDBOX); |
| 2014 | pkg.applicationInfo.targetSandboxVersion = targetSandboxVersion; |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 2015 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2016 | /* Set the global "forward lock" flag */ |
| 2017 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2018 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2022 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2023 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 2024 | } |
| 2025 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2026 | if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifest_isolatedSplits, false)) { |
| 2027 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING; |
| 2028 | } |
| 2029 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2030 | // Resource boolean are -1, so 1 means we don't know the value. |
| 2031 | int supportsSmallScreens = 1; |
| 2032 | int supportsNormalScreens = 1; |
| 2033 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2034 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2035 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2036 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2039 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2040 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2041 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | continue; |
| 2043 | } |
| 2044 | |
| 2045 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2046 | |
| 2047 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 2048 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 2049 | + tagName + " at " + mArchiveSourcePath + " " |
| 2050 | + parser.getPositionDescription()); |
| 2051 | XmlUtils.skipCurrentTag(parser); |
| 2052 | continue; |
| 2053 | } |
| 2054 | |
| 2055 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | if (foundApp) { |
| 2057 | if (RIGID_PARSER) { |
| 2058 | outError[0] = "<manifest> has more than one <application>"; |
| 2059 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2060 | return null; |
| 2061 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2062 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | XmlUtils.skipCurrentTag(parser); |
| 2064 | continue; |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2069 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | return null; |
| 2071 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2072 | } else if (tagName.equals(TAG_OVERLAY)) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2073 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2074 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 2075 | pkg.mOverlayTarget = sa.getString( |
| 2076 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2077 | pkg.mOverlayPriority = sa.getInt( |
| 2078 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 2079 | 0); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 2080 | pkg.mOverlayIsStatic = sa.getBoolean( |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2081 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_isStatic, |
| 2082 | false); |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2083 | final String propName = sa.getString( |
| 2084 | com.android.internal.R.styleable |
| 2085 | .AndroidManifestResourceOverlay_requiredSystemPropertyName); |
| 2086 | final String propValue = sa.getString( |
| 2087 | com.android.internal.R.styleable |
| 2088 | .AndroidManifestResourceOverlay_requiredSystemPropertyValue); |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2089 | sa.recycle(); |
| 2090 | |
| 2091 | if (pkg.mOverlayTarget == null) { |
| 2092 | outError[0] = "<overlay> does not specify a target package"; |
| 2093 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2094 | return null; |
| 2095 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2096 | |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2097 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 2098 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 2099 | mParseError = |
| 2100 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2101 | return null; |
| 2102 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2103 | |
| 2104 | // check to see if overlay should be excluded based on system property condition |
| 2105 | if (!checkOverlayRequiredSystemProperty(propName, propValue)) { |
| 2106 | Slog.i(TAG, "Skipping target and overlay pair " + pkg.mOverlayTarget + " and " |
| 2107 | + pkg.baseCodePath+ ": overlay ignored due to required system property: " |
| 2108 | + propName + " with value: " + propValue); |
| 2109 | return null; |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2110 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2111 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2112 | XmlUtils.skipCurrentTag(parser); |
| 2113 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2114 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 2115 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2116 | return null; |
| 2117 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2118 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2119 | if (!parsePermissionGroup(pkg, flags, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | return null; |
| 2121 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2122 | } else if (tagName.equals(TAG_PERMISSION)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2123 | if (!parsePermission(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | return null; |
| 2125 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2126 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2127 | if (!parsePermissionTree(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | return null; |
| 2129 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2130 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
| 2131 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2132 | return null; |
| 2133 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2134 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 2135 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
| 2136 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2137 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2139 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2141 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 2143 | cPref.reqTouchScreen = sa.getInt( |
| 2144 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 2145 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 2146 | cPref.reqKeyboardType = sa.getInt( |
| 2147 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 2148 | Configuration.KEYBOARD_UNDEFINED); |
| 2149 | if (sa.getBoolean( |
| 2150 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 2151 | false)) { |
| 2152 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 2153 | } |
| 2154 | cPref.reqNavigation = sa.getInt( |
| 2155 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 2156 | Configuration.NAVIGATION_UNDEFINED); |
| 2157 | if (sa.getBoolean( |
| 2158 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 2159 | false)) { |
| 2160 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 2161 | } |
| 2162 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2163 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | |
| 2165 | XmlUtils.skipCurrentTag(parser); |
| 2166 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2167 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 2168 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2169 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 2170 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2171 | if (fi.name == null) { |
| 2172 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 2173 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2174 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2175 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 2176 | |
| 2177 | XmlUtils.skipCurrentTag(parser); |
| 2178 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2179 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2180 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 2181 | ArrayList<FeatureInfo> features = null; |
| 2182 | final int innerDepth = parser.getDepth(); |
| 2183 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2184 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 2185 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2186 | continue; |
| 2187 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2188 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2189 | final String innerTagName = parser.getName(); |
| 2190 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2191 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2192 | // FeatureGroups are stricter and mandate that |
| 2193 | // any <uses-feature> declared are mandatory. |
| 2194 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2195 | features = ArrayUtils.add(features, featureInfo); |
| 2196 | } else { |
| 2197 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 2198 | " at " + mArchiveSourcePath + " " + |
| 2199 | parser.getPositionDescription()); |
| 2200 | } |
| 2201 | XmlUtils.skipCurrentTag(parser); |
| 2202 | } |
| 2203 | |
| 2204 | if (features != null) { |
| 2205 | group.features = new FeatureInfo[features.size()]; |
| 2206 | group.features = features.toArray(group.features); |
| 2207 | } |
| 2208 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2209 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2210 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 2211 | if (SDK_VERSION > 0) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2212 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 2214 | |
Todd Kennedy | 4f65708 | 2016-06-28 10:31:05 -0700 | [diff] [blame] | 2215 | int minVers = 1; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2216 | String minCode = null; |
| 2217 | int targetVers = 0; |
| 2218 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2219 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2220 | TypedValue val = sa.peekValue( |
| 2221 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 2222 | if (val != null) { |
| 2223 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 2224 | targetCode = minCode = val.string.toString(); |
| 2225 | } else { |
| 2226 | // If it's not a string, it's an integer. |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2227 | targetVers = minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2228 | } |
| 2229 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2230 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2231 | val = sa.peekValue( |
| 2232 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 2233 | if (val != null) { |
| 2234 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 2235 | targetCode = val.string.toString(); |
| 2236 | if (minCode == null) { |
| 2237 | minCode = targetCode; |
| 2238 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2239 | } else { |
| 2240 | // If it's not a string, it's an integer. |
| 2241 | targetVers = val.data; |
| 2242 | } |
| 2243 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | sa.recycle(); |
| 2246 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2247 | final int minSdkVersion = PackageParser.computeMinSdkVersion(minVers, minCode, |
| 2248 | SDK_VERSION, SDK_CODENAMES, outError); |
| 2249 | if (minSdkVersion < 0) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2250 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2251 | return null; |
| 2252 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2253 | |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2254 | boolean defaultToCurrentDevBranch = (flags & PARSE_FORCE_SDK) != 0; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2255 | final int targetSdkVersion = PackageParser.computeTargetSdkVersion(targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2256 | targetCode, SDK_CODENAMES, outError, defaultToCurrentDevBranch); |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2257 | if (targetSdkVersion < 0) { |
| 2258 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2259 | return null; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2260 | } |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2261 | |
| 2262 | pkg.applicationInfo.minSdkVersion = minSdkVersion; |
| 2263 | pkg.applicationInfo.targetSdkVersion = targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | XmlUtils.skipCurrentTag(parser); |
| 2267 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2268 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 2269 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2270 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 2271 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2272 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 2273 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 2274 | 0); |
| 2275 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 2276 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 2277 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 2278 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 2279 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 2280 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2281 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2282 | // This is a trick to get a boolean and still able to detect |
| 2283 | // if a value was actually set. |
| 2284 | supportsSmallScreens = sa.getInteger( |
| 2285 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 2286 | supportsSmallScreens); |
| 2287 | supportsNormalScreens = sa.getInteger( |
| 2288 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 2289 | supportsNormalScreens); |
| 2290 | supportsLargeScreens = sa.getInteger( |
| 2291 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 2292 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2293 | supportsXLargeScreens = sa.getInteger( |
| 2294 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 2295 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2296 | resizeable = sa.getInteger( |
| 2297 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2298 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2299 | anyDensity = sa.getInteger( |
| 2300 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 2301 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2302 | |
| 2303 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2304 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2305 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2306 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2307 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 2308 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2309 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 2310 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2311 | // Note: don't allow this value to be a reference to a resource |
| 2312 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2313 | String name = sa.getNonResourceString( |
| 2314 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 2315 | |
| 2316 | sa.recycle(); |
| 2317 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 2318 | if (name != null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2319 | if (pkg.protectedBroadcasts == null) { |
| 2320 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 2321 | } |
| 2322 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 2323 | pkg.protectedBroadcasts.add(name.intern()); |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2328 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2329 | } else if (tagName.equals(TAG_INSTRUMENTATION)) { |
| 2330 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2331 | return null; |
| 2332 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2333 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2334 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2335 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2336 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2337 | String orig =sa.getNonConfigurationString( |
| 2338 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2339 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2340 | if (pkg.mOriginalPackages == null) { |
| 2341 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2342 | pkg.mRealPackage = pkg.packageName; |
| 2343 | } |
| 2344 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2345 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2346 | |
| 2347 | sa.recycle(); |
| 2348 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2349 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2350 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2351 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2352 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2353 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2354 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2355 | String name = sa.getNonConfigurationString( |
| 2356 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2357 | |
| 2358 | sa.recycle(); |
| 2359 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2360 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2361 | if (pkg.mAdoptPermissions == null) { |
| 2362 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2363 | } |
| 2364 | pkg.mAdoptPermissions.add(name); |
| 2365 | } |
| 2366 | |
| 2367 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2368 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2369 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2370 | // Just skip this tag |
| 2371 | XmlUtils.skipCurrentTag(parser); |
| 2372 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2373 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2374 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2375 | // Just skip this tag |
| 2376 | XmlUtils.skipCurrentTag(parser); |
| 2377 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2378 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2379 | XmlUtils.skipCurrentTag(parser); |
| 2380 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2381 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2382 | } else if (tagName.equals(TAG_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2383 | // Just skip this tag |
| 2384 | XmlUtils.skipCurrentTag(parser); |
| 2385 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2386 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2387 | } else if (tagName.equals(TAG_PACKAGE)) { |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame] | 2388 | if (!MULTI_PACKAGE_APK_ENABLED) { |
| 2389 | XmlUtils.skipCurrentTag(parser); |
| 2390 | continue; |
| 2391 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2392 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2393 | // If parsing a child failed the error is already set |
| 2394 | return null; |
| 2395 | } |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2396 | |
| 2397 | } else if (tagName.equals(TAG_RESTRICT_UPDATE)) { |
| 2398 | if ((flags & PARSE_IS_SYSTEM_DIR) != 0) { |
| 2399 | sa = res.obtainAttributes(parser, |
| 2400 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate); |
| 2401 | final String hash = sa.getNonConfigurationString( |
| 2402 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0); |
| 2403 | sa.recycle(); |
| 2404 | |
| 2405 | pkg.restrictUpdateHash = null; |
| 2406 | if (hash != null) { |
| 2407 | final int hashLength = hash.length(); |
| 2408 | final byte[] hashBytes = new byte[hashLength / 2]; |
| 2409 | for (int i = 0; i < hashLength; i += 2){ |
| 2410 | hashBytes[i/2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) |
| 2411 | + Character.digit(hash.charAt(i + 1), 16)); |
| 2412 | } |
| 2413 | pkg.restrictUpdateHash = hashBytes; |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | XmlUtils.skipCurrentTag(parser); |
| 2418 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2419 | } else if (RIGID_PARSER) { |
| 2420 | outError[0] = "Bad element under <manifest>: " |
| 2421 | + parser.getName(); |
| 2422 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2423 | return null; |
| 2424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2426 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2427 | + " at " + mArchiveSourcePath + " " |
| 2428 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2429 | XmlUtils.skipCurrentTag(parser); |
| 2430 | continue; |
| 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2435 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2436 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2437 | } |
| 2438 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2439 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2440 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2441 | for (int ip=0; ip<NP; ip++) { |
| 2442 | final PackageParser.NewPermissionInfo npi |
| 2443 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2444 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2445 | break; |
| 2446 | } |
| 2447 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2448 | if (implicitPerms == null) { |
| 2449 | implicitPerms = new StringBuilder(128); |
| 2450 | implicitPerms.append(pkg.packageName); |
| 2451 | implicitPerms.append(": compat added "); |
| 2452 | } else { |
| 2453 | implicitPerms.append(' '); |
| 2454 | } |
| 2455 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2456 | pkg.requestedPermissions.add(npi.name); |
| 2457 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2458 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2459 | if (implicitPerms != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2460 | Slog.i(TAG, implicitPerms.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2461 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2462 | |
| 2463 | final int NS = PackageParser.SPLIT_PERMISSIONS.length; |
| 2464 | for (int is=0; is<NS; is++) { |
| 2465 | final PackageParser.SplitPermissionInfo spi |
| 2466 | = PackageParser.SPLIT_PERMISSIONS[is]; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 2467 | if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk |
| 2468 | || !pkg.requestedPermissions.contains(spi.rootPerm)) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2469 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2470 | } |
| 2471 | for (int in=0; in<spi.newPerms.length; in++) { |
| 2472 | final String perm = spi.newPerms[in]; |
| 2473 | if (!pkg.requestedPermissions.contains(perm)) { |
| 2474 | pkg.requestedPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2479 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2480 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2481 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2482 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2483 | } |
| 2484 | if (supportsNormalScreens != 0) { |
| 2485 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2486 | } |
| 2487 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2488 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2489 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2490 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2491 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2492 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2493 | && pkg.applicationInfo.targetSdkVersion |
| 2494 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2495 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2496 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2497 | if (resizeable < 0 || (resizeable > 0 |
| 2498 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2499 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2500 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2501 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2502 | if (anyDensity < 0 || (anyDensity > 0 |
| 2503 | && pkg.applicationInfo.targetSdkVersion |
| 2504 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2505 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2506 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2507 | |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2508 | // At this point we can check if an application is not supporting densities and hence |
| 2509 | // cannot be windowed / resized. Note that an SDK version of 0 is common for |
| 2510 | // pre-Doughnut applications. |
| 2511 | if (pkg.applicationInfo.usesCompatibilityMode()) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2512 | adjustPackageToBeUnresizeableAndUnpipable(pkg); |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | return pkg; |
| 2515 | } |
| 2516 | |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2517 | private boolean checkOverlayRequiredSystemProperty(String propName, String propValue) { |
| 2518 | |
| 2519 | if (TextUtils.isEmpty(propName) || TextUtils.isEmpty(propValue)) { |
| 2520 | if (!TextUtils.isEmpty(propName) || !TextUtils.isEmpty(propValue)) { |
| 2521 | // malformed condition - incomplete |
| 2522 | Slog.w(TAG, "Disabling overlay - incomplete property :'" + propName |
| 2523 | + "=" + propValue + "' - require both requiredSystemPropertyName" |
| 2524 | + " AND requiredSystemPropertyValue to be specified."); |
| 2525 | return false; |
| 2526 | } |
| 2527 | // no valid condition set - so no exclusion criteria, overlay will be included. |
| 2528 | return true; |
| 2529 | } |
| 2530 | |
| 2531 | // check property value - make sure it is both set and equal to expected value |
| 2532 | final String currValue = SystemProperties.get(propName); |
| 2533 | return (currValue != null && currValue.equals(propValue)); |
| 2534 | } |
| 2535 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2536 | /** |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2537 | * This is a pre-density application which will get scaled - instead of being pixel perfect. |
| 2538 | * This type of application is not resizable. |
| 2539 | * |
| 2540 | * @param pkg The package which needs to be marked as unresizable. |
| 2541 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2542 | private void adjustPackageToBeUnresizeableAndUnpipable(Package pkg) { |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2543 | for (Activity a : pkg.activities) { |
| 2544 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2545 | a.info.flags &= ~FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | /** |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2550 | * Computes the targetSdkVersion to use at runtime. If the package is not |
| 2551 | * compatible with this platform, populates {@code outError[0]} with an |
| 2552 | * error message. |
| 2553 | * <p> |
| 2554 | * If {@code targetCode} is not specified, e.g. the value is {@code null}, |
| 2555 | * then the {@code targetVers} will be returned unmodified. |
| 2556 | * <p> |
| 2557 | * Otherwise, the behavior varies based on whether the current platform |
| 2558 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2559 | * has length > 0: |
| 2560 | * <ul> |
| 2561 | * <li>If this is a pre-release platform and the value specified by |
| 2562 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2563 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2564 | * <li>If this is a released platform, this method will return -1 to |
| 2565 | * indicate that the package is not compatible with this platform. |
| 2566 | * </ul> |
| 2567 | * |
| 2568 | * @param targetVers targetSdkVersion number, if specified in the |
| 2569 | * application manifest, or 0 otherwise |
| 2570 | * @param targetCode targetSdkVersion code, if specified in the application |
| 2571 | * manifest, or {@code null} otherwise |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2572 | * @param platformSdkCodenames array of allowed pre-release SDK codenames |
| 2573 | * for this platform |
| 2574 | * @param outError output array to populate with error, if applicable |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2575 | * @param forceCurrentDev if development target code is not available, use the current |
| 2576 | * development version by default. |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2577 | * @return the targetSdkVersion to use at runtime, or -1 if the package is |
| 2578 | * not compatible with this platform |
| 2579 | * @hide Exposed for unit testing only. |
| 2580 | */ |
| 2581 | @TestApi |
| 2582 | public static int computeTargetSdkVersion(@IntRange(from = 0) int targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2583 | @Nullable String targetCode, @NonNull String[] platformSdkCodenames, |
| 2584 | @NonNull String[] outError, boolean forceCurrentDev) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2585 | // If it's a release SDK, return the version number unmodified. |
| 2586 | if (targetCode == null) { |
| 2587 | return targetVers; |
| 2588 | } |
| 2589 | |
| 2590 | // If it's a pre-release SDK and the codename matches this platform, it |
| 2591 | // definitely targets this SDK. |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2592 | if (ArrayUtils.contains(platformSdkCodenames, targetCode) || forceCurrentDev) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2593 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2594 | } |
| 2595 | |
| 2596 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2597 | if (platformSdkCodenames.length > 0) { |
| 2598 | outError[0] = "Requires development platform " + targetCode |
| 2599 | + " (current platform is any of " |
| 2600 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2601 | } else { |
| 2602 | outError[0] = "Requires development platform " + targetCode |
| 2603 | + " but this is a release platform."; |
| 2604 | } |
| 2605 | return -1; |
| 2606 | } |
| 2607 | |
| 2608 | /** |
| 2609 | * Computes the minSdkVersion to use at runtime. If the package is not |
| 2610 | * compatible with this platform, populates {@code outError[0]} with an |
| 2611 | * error message. |
| 2612 | * <p> |
| 2613 | * If {@code minCode} is not specified, e.g. the value is {@code null}, |
| 2614 | * then behavior varies based on the {@code platformSdkVersion}: |
| 2615 | * <ul> |
| 2616 | * <li>If the platform SDK version is greater than or equal to the |
| 2617 | * {@code minVers}, returns the {@code mniVers} unmodified. |
| 2618 | * <li>Otherwise, returns -1 to indicate that the package is not |
| 2619 | * compatible with this platform. |
| 2620 | * </ul> |
| 2621 | * <p> |
| 2622 | * Otherwise, the behavior varies based on whether the current platform |
| 2623 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2624 | * has length > 0: |
| 2625 | * <ul> |
| 2626 | * <li>If this is a pre-release platform and the value specified by |
| 2627 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2628 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2629 | * <li>If this is a released platform, this method will return -1 to |
| 2630 | * indicate that the package is not compatible with this platform. |
| 2631 | * </ul> |
| 2632 | * |
| 2633 | * @param minVers minSdkVersion number, if specified in the application |
| 2634 | * manifest, or 1 otherwise |
| 2635 | * @param minCode minSdkVersion code, if specified in the application |
| 2636 | * manifest, or {@code null} otherwise |
| 2637 | * @param platformSdkVersion platform SDK version number, typically |
| 2638 | * Build.VERSION.SDK_INT |
| 2639 | * @param platformSdkCodenames array of allowed prerelease SDK codenames |
| 2640 | * for this platform |
| 2641 | * @param outError output array to populate with error, if applicable |
| 2642 | * @return the minSdkVersion to use at runtime, or -1 if the package is not |
| 2643 | * compatible with this platform |
| 2644 | * @hide Exposed for unit testing only. |
| 2645 | */ |
| 2646 | @TestApi |
| 2647 | public static int computeMinSdkVersion(@IntRange(from = 1) int minVers, |
| 2648 | @Nullable String minCode, @IntRange(from = 1) int platformSdkVersion, |
| 2649 | @NonNull String[] platformSdkCodenames, @NonNull String[] outError) { |
| 2650 | // If it's a release SDK, make sure we meet the minimum SDK requirement. |
| 2651 | if (minCode == null) { |
| 2652 | if (minVers <= platformSdkVersion) { |
| 2653 | return minVers; |
| 2654 | } |
| 2655 | |
| 2656 | // We don't meet the minimum SDK requirement. |
| 2657 | outError[0] = "Requires newer sdk version #" + minVers |
| 2658 | + " (current version is #" + platformSdkVersion + ")"; |
| 2659 | return -1; |
| 2660 | } |
| 2661 | |
| 2662 | // If it's a pre-release SDK and the codename matches this platform, we |
| 2663 | // definitely meet the minimum SDK requirement. |
| 2664 | if (ArrayUtils.contains(platformSdkCodenames, minCode)) { |
| 2665 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2666 | } |
| 2667 | |
| 2668 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2669 | if (platformSdkCodenames.length > 0) { |
| 2670 | outError[0] = "Requires development platform " + minCode |
| 2671 | + " (current platform is any of " |
| 2672 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2673 | } else { |
| 2674 | outError[0] = "Requires development platform " + minCode |
| 2675 | + " but this is a release platform."; |
| 2676 | } |
| 2677 | return -1; |
| 2678 | } |
| 2679 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2680 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2681 | FeatureInfo fi = new FeatureInfo(); |
| 2682 | TypedArray sa = res.obtainAttributes(attrs, |
| 2683 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2684 | // Note: don't allow this value to be a reference to a resource |
| 2685 | // that may change. |
| 2686 | fi.name = sa.getNonResourceString( |
| 2687 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2688 | fi.version = sa.getInt( |
| 2689 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2690 | if (fi.name == null) { |
| 2691 | fi.reqGlEsVersion = sa.getInt( |
| 2692 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2693 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2694 | } |
| 2695 | if (sa.getBoolean( |
| 2696 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2697 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2698 | } |
| 2699 | sa.recycle(); |
| 2700 | return fi; |
| 2701 | } |
| 2702 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2703 | private boolean parseUsesStaticLibrary(Package pkg, Resources res, XmlResourceParser parser, |
| 2704 | String[] outError) throws XmlPullParserException, IOException { |
| 2705 | TypedArray sa = res.obtainAttributes(parser, |
| 2706 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary); |
| 2707 | |
| 2708 | // Note: don't allow this value to be a reference to a resource that may change. |
| 2709 | String lname = sa.getNonResourceString( |
| 2710 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 2711 | final int version = sa.getInt( |
| 2712 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary_version, -1); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2713 | String certSha256Digest = sa.getNonResourceString(com.android.internal.R.styleable |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2714 | .AndroidManifestUsesStaticLibrary_certDigest); |
| 2715 | sa.recycle(); |
| 2716 | |
| 2717 | // Since an APK providing a static shared lib can only provide the lib - fail if malformed |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2718 | if (lname == null || version < 0 || certSha256Digest == null) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2719 | outError[0] = "Bad uses-static-library declaration name: " + lname + " version: " |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2720 | + version + " certDigest" + certSha256Digest; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2721 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2722 | XmlUtils.skipCurrentTag(parser); |
| 2723 | return false; |
| 2724 | } |
| 2725 | |
| 2726 | // Can depend only on one version of the same library |
| 2727 | if (pkg.usesStaticLibraries != null && pkg.usesStaticLibraries.contains(lname)) { |
| 2728 | outError[0] = "Depending on multiple versions of static library " + lname; |
| 2729 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2730 | XmlUtils.skipCurrentTag(parser); |
| 2731 | return false; |
| 2732 | } |
| 2733 | |
| 2734 | lname = lname.intern(); |
| 2735 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2736 | // emitted by the certtool making it easy for developers to copy/paste. |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2737 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2738 | |
| 2739 | // Fot apps targeting O-MR1 we require explicit enumeration of all certs. |
| 2740 | String[] additionalCertSha256Digests = EmptyArray.STRING; |
| 2741 | if (pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.O) { |
| 2742 | additionalCertSha256Digests = parseAdditionalCertificates(res, parser, outError); |
| 2743 | if (additionalCertSha256Digests == null) { |
| 2744 | return false; |
| 2745 | } |
| 2746 | } else { |
| 2747 | XmlUtils.skipCurrentTag(parser); |
| 2748 | } |
| 2749 | |
| 2750 | final String[] certSha256Digests = new String[additionalCertSha256Digests.length + 1]; |
| 2751 | certSha256Digests[0] = certSha256Digest; |
| 2752 | System.arraycopy(additionalCertSha256Digests, 0, certSha256Digests, |
| 2753 | 1, additionalCertSha256Digests.length); |
| 2754 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2755 | pkg.usesStaticLibraries = ArrayUtils.add(pkg.usesStaticLibraries, lname); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2756 | pkg.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 8a10ef5 | 2017-02-16 20:58:09 -0800 | [diff] [blame] | 2757 | pkg.usesStaticLibrariesVersions, version, true); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2758 | pkg.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, |
| 2759 | pkg.usesStaticLibrariesCertDigests, certSha256Digests, true); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2760 | |
| 2761 | return true; |
| 2762 | } |
| 2763 | |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2764 | private String[] parseAdditionalCertificates(Resources resources, XmlResourceParser parser, |
| 2765 | String[] outError) throws XmlPullParserException, IOException { |
| 2766 | String[] certSha256Digests = EmptyArray.STRING; |
| 2767 | |
| 2768 | int outerDepth = parser.getDepth(); |
| 2769 | int type; |
| 2770 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2771 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2772 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2773 | continue; |
| 2774 | } |
| 2775 | |
| 2776 | final String nodeName = parser.getName(); |
| 2777 | if (nodeName.equals("additional-certificate")) { |
| 2778 | final TypedArray sa = resources.obtainAttributes(parser, com.android.internal. |
| 2779 | R.styleable.AndroidManifestAdditionalCertificate); |
| 2780 | String certSha256Digest = sa.getNonResourceString(com.android.internal. |
| 2781 | R.styleable.AndroidManifestAdditionalCertificate_certDigest); |
| 2782 | sa.recycle(); |
| 2783 | |
| 2784 | if (TextUtils.isEmpty(certSha256Digest)) { |
| 2785 | outError[0] = "Bad additional-certificate declaration with empty" |
| 2786 | + " certDigest:" + certSha256Digest; |
| 2787 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2788 | XmlUtils.skipCurrentTag(parser); |
| 2789 | sa.recycle(); |
| 2790 | return null; |
| 2791 | } |
| 2792 | |
| 2793 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2794 | // emitted by the certtool making it easy for developers to copy/paste. |
| 2795 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2796 | certSha256Digests = ArrayUtils.appendElement(String.class, |
| 2797 | certSha256Digests, certSha256Digest); |
| 2798 | } else { |
| 2799 | XmlUtils.skipCurrentTag(parser); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | return certSha256Digests; |
| 2804 | } |
| 2805 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2806 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2807 | throws XmlPullParserException, IOException { |
| 2808 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2809 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2810 | |
| 2811 | // Note: don't allow this value to be a reference to a resource |
| 2812 | // that may change. |
| 2813 | String name = sa.getNonResourceString( |
| 2814 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2815 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2816 | int maxSdkVersion = 0; |
| 2817 | TypedValue val = sa.peekValue( |
| 2818 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2819 | if (val != null) { |
| 2820 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2821 | maxSdkVersion = val.data; |
| 2822 | } |
| 2823 | } |
| 2824 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2825 | final String requiredFeature = sa.getNonConfigurationString( |
| 2826 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredFeature, 0); |
| 2827 | |
| 2828 | final String requiredNotfeature = sa.getNonConfigurationString( |
| 2829 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredNotFeature, 0); |
| 2830 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2831 | sa.recycle(); |
| 2832 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2833 | XmlUtils.skipCurrentTag(parser); |
| 2834 | |
| 2835 | if (name == null) { |
| 2836 | return true; |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2839 | if ((maxSdkVersion != 0) && (maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT)) { |
| 2840 | return true; |
| 2841 | } |
| 2842 | |
| 2843 | // Only allow requesting this permission if the platform supports the given feature. |
| 2844 | if (requiredFeature != null && mCallback != null && !mCallback.hasFeature(requiredFeature)) { |
| 2845 | return true; |
| 2846 | } |
| 2847 | |
| 2848 | // Only allow requesting this permission if the platform doesn't support the given feature. |
| 2849 | if (requiredNotfeature != null && mCallback != null |
| 2850 | && mCallback.hasFeature(requiredNotfeature)) { |
| 2851 | return true; |
| 2852 | } |
| 2853 | |
| 2854 | int index = pkg.requestedPermissions.indexOf(name); |
| 2855 | if (index == -1) { |
| 2856 | pkg.requestedPermissions.add(name.intern()); |
| 2857 | } else { |
| 2858 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2859 | + name + " in package: " + pkg.packageName + " at: " |
| 2860 | + parser.getPositionDescription()); |
| 2861 | } |
| 2862 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2863 | return true; |
| 2864 | } |
| 2865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2867 | String[] outError) { |
| 2868 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2869 | outError[0] = "Empty class name in package " + pkg; |
| 2870 | return null; |
| 2871 | } |
| 2872 | String cls = clsSeq.toString(); |
| 2873 | char c = cls.charAt(0); |
| 2874 | if (c == '.') { |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2875 | return pkg + cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | } |
| 2877 | if (cls.indexOf('.') < 0) { |
| 2878 | StringBuilder b = new StringBuilder(pkg); |
| 2879 | b.append('.'); |
| 2880 | b.append(cls); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2881 | return b.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2883 | return cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | private static String buildCompoundName(String pkg, |
| 2887 | CharSequence procSeq, String type, String[] outError) { |
| 2888 | String proc = procSeq.toString(); |
| 2889 | char c = proc.charAt(0); |
| 2890 | if (pkg != null && c == ':') { |
| 2891 | if (proc.length() < 2) { |
| 2892 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2893 | + ": must be at least two characters"; |
| 2894 | return null; |
| 2895 | } |
| 2896 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2897 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2898 | if (nameError != null) { |
| 2899 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2900 | + pkg + ": " + nameError; |
| 2901 | return null; |
| 2902 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2903 | return pkg + proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2905 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | if (nameError != null && !"system".equals(proc)) { |
| 2907 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2908 | + pkg + ": " + nameError; |
| 2909 | return null; |
| 2910 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2911 | return proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | private static String buildProcessName(String pkg, String defProc, |
| 2915 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 2916 | String[] outError) { |
| 2917 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 2918 | return defProc != null ? defProc : pkg; |
| 2919 | } |
| 2920 | if (separateProcesses != null) { |
| 2921 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 2922 | String sp = separateProcesses[i]; |
| 2923 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 2924 | return pkg; |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | if (procSeq == null || procSeq.length() <= 0) { |
| 2929 | return defProc; |
| 2930 | } |
Makoto Onuki | 812d188a | 2017-08-07 09:58:23 -0700 | [diff] [blame] | 2931 | return TextUtils.safeIntern(buildCompoundName(pkg, procSeq, "process", outError)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 2935 | CharSequence procSeq, String[] outError) { |
| 2936 | if (procSeq == null) { |
| 2937 | return defProc; |
| 2938 | } |
| 2939 | if (procSeq.length() <= 0) { |
| 2940 | return null; |
| 2941 | } |
| 2942 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 2943 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2944 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2945 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2946 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2947 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2948 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2949 | // all the keys and keysets that we want must be defined here |
| 2950 | // so we're going to iterate over the parser and pull out the things we want |
| 2951 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2952 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2953 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2954 | String currentKeySet = null; |
| 2955 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 2956 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 2957 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 2958 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2959 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2960 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2961 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2962 | if (parser.getDepth() == currentKeySetDepth) { |
| 2963 | currentKeySet = null; |
| 2964 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2965 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2966 | continue; |
| 2967 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2968 | String tagName = parser.getName(); |
| 2969 | if (tagName.equals("key-set")) { |
| 2970 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2971 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2972 | + parser.getPositionDescription(); |
| 2973 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2976 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2977 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 2978 | final String keysetName = sa.getNonResourceString( |
| 2979 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 2980 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 2981 | currentKeySet = keysetName; |
| 2982 | currentKeySetDepth = parser.getDepth(); |
| 2983 | sa.recycle(); |
| 2984 | } else if (tagName.equals("public-key")) { |
| 2985 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2986 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2987 | + parser.getPositionDescription(); |
| 2988 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2989 | return false; |
| 2990 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2991 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2992 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 2993 | final String publicKeyName = sa.getNonResourceString( |
| 2994 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2995 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2996 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 2997 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2998 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 2999 | + " on first use at " + parser.getPositionDescription(); |
| 3000 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3001 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3002 | return false; |
| 3003 | } else if (encodedKey != null) { |
| 3004 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 3005 | if (currentKey == null) { |
| 3006 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 3007 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 3008 | + " will not be added to the package's defined key-sets."); |
| 3009 | sa.recycle(); |
| 3010 | improperKeySets.add(currentKeySet); |
| 3011 | XmlUtils.skipCurrentTag(parser); |
| 3012 | continue; |
| 3013 | } |
| 3014 | if (publicKeys.get(publicKeyName) == null |
| 3015 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 3016 | |
| 3017 | /* public-key first definition, or matches old definition */ |
| 3018 | publicKeys.put(publicKeyName, currentKey); |
| 3019 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3020 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3021 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3022 | + parser.getPositionDescription(); |
| 3023 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3024 | sa.recycle(); |
| 3025 | return false; |
| 3026 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3027 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3028 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3029 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3030 | XmlUtils.skipCurrentTag(parser); |
| 3031 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3032 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3033 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 3034 | String name = sa.getNonResourceString( |
| 3035 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 3036 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3037 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3038 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3039 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3040 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3041 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3042 | + parser.getPositionDescription(); |
| 3043 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3044 | return false; |
| 3045 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3046 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3047 | + " at " + mArchiveSourcePath + " " |
| 3048 | + parser.getPositionDescription()); |
| 3049 | XmlUtils.skipCurrentTag(parser); |
| 3050 | continue; |
| 3051 | } |
| 3052 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3053 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 3054 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3055 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 3056 | + "'key-set' and 'public-key' names must be distinct."; |
| 3057 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3058 | return false; |
| 3059 | } |
| 3060 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 3061 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 3062 | final String keySetName = e.getKey(); |
| 3063 | if (e.getValue().size() == 0) { |
| 3064 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3065 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 3066 | + " Not including in package's defined key-sets."); |
| 3067 | continue; |
| 3068 | } else if (improperKeySets.contains(keySetName)) { |
| 3069 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3070 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 3071 | + " tags. Not including in package's defined key-sets."); |
| 3072 | continue; |
| 3073 | } |
| 3074 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 3075 | for (String s : e.getValue()) { |
| 3076 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3077 | } |
| 3078 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3079 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 3080 | owner.mUpgradeKeySets = upgradeKeySets; |
| 3081 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3082 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 3083 | + "does not define all 'upgrade-key-set's ."; |
| 3084 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3085 | return false; |
| 3086 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3087 | return true; |
| 3088 | } |
| 3089 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3090 | private boolean parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3091 | XmlResourceParser parser, String[] outError) |
| 3092 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | PermissionGroup perm = new PermissionGroup(owner); |
| 3094 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3095 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3096 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3098 | "<permission-group>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 3100 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3101 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3102 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3103 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 3104 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | sa.recycle(); |
| 3106 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3107 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | perm.info.descriptionRes = sa.getResourceId( |
| 3111 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 3112 | 0); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3113 | perm.info.requestRes = sa.getResourceId( |
| 3114 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 3115 | perm.info.flags = sa.getInt( |
| 3116 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 3117 | perm.info.priority = sa.getInt( |
| 3118 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | |
| 3120 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3121 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3122 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | outError)) { |
| 3124 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3125 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | owner.permissionGroups.add(perm); |
| 3129 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3130 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3133 | private boolean parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3134 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3137 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 3139 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3140 | Permission perm = new Permission(owner); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3142 | "<permission>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 3144 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3145 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3146 | com.android.internal.R.styleable.AndroidManifestPermission_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3147 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 3148 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | sa.recycle(); |
| 3150 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3151 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | } |
| 3153 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3154 | // Note: don't allow this value to be a reference to a resource |
| 3155 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | perm.info.group = sa.getNonResourceString( |
| 3157 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 3158 | if (perm.info.group != null) { |
| 3159 | perm.info.group = perm.info.group.intern(); |
| 3160 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | perm.info.descriptionRes = sa.getResourceId( |
| 3163 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 3164 | 0); |
| 3165 | |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3166 | perm.info.requestRes = sa.getResourceId( |
| 3167 | com.android.internal.R.styleable.AndroidManifestPermission_request, 0); |
| 3168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | perm.info.protectionLevel = sa.getInt( |
| 3170 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 3171 | PermissionInfo.PROTECTION_NORMAL); |
| 3172 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 3173 | perm.info.flags = sa.getInt( |
| 3174 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 3175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | if (perm.info.protectionLevel == -1) { |
| 3179 | outError[0] = "<permission> does not specify protectionLevel"; |
| 3180 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3181 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3183 | |
| 3184 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 3185 | |
| 3186 | if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 3187 | if ( (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_INSTANT) == 0 |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 3188 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) == 0 |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 3189 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3190 | PermissionInfo.PROTECTION_SIGNATURE) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 3191 | outError[0] = "<permission> protectionLevel specifies a non-instnat flag but is " |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3192 | + "not based on signature type"; |
| 3193 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3194 | return false; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3195 | } |
| 3196 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3197 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3198 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3200 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | owner.permissions.add(perm); |
| 3204 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3205 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | } |
| 3207 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3208 | private boolean parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3209 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | throws XmlPullParserException, IOException { |
| 3211 | Permission perm = new Permission(owner); |
| 3212 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3213 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 3215 | |
| 3216 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3217 | "<permission-tree>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 3219 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3220 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3221 | com.android.internal.R.styleable.AndroidManifestPermissionTree_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3222 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 3223 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | sa.recycle(); |
| 3225 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3226 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | int index = perm.info.name.indexOf('.'); |
| 3232 | if (index > 0) { |
| 3233 | index = perm.info.name.indexOf('.', index+1); |
| 3234 | } |
| 3235 | if (index < 0) { |
| 3236 | outError[0] = "<permission-tree> name has less than three segments: " |
| 3237 | + perm.info.name; |
| 3238 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3239 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | perm.info.descriptionRes = 0; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3243 | perm.info.requestRes = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 3245 | perm.tree = true; |
| 3246 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3247 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | outError)) { |
| 3249 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3250 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | owner.permissions.add(perm); |
| 3254 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3255 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3259 | XmlResourceParser parser, String[] outError) |
| 3260 | throws XmlPullParserException, IOException { |
| 3261 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 3263 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3264 | if (mParseInstrumentationArgs == null) { |
| 3265 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 3266 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 3267 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3268 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3269 | com.android.internal.R.styleable.AndroidManifestInstrumentation_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3270 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 3271 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3272 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 3273 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3274 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3275 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3276 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3277 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 3278 | new InstrumentationInfo()); |
| 3279 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | sa.recycle(); |
| 3281 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3282 | return null; |
| 3283 | } |
| 3284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3286 | // Note: don't allow this value to be a reference to a resource |
| 3287 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | str = sa.getNonResourceString( |
| 3289 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 3290 | a.info.targetPackage = str != null ? str.intern() : null; |
| 3291 | |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3292 | str = sa.getNonResourceString( |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 3293 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetProcesses); |
| 3294 | a.info.targetProcesses = str != null ? str.intern() : null; |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | a.info.handleProfiling = sa.getBoolean( |
| 3297 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 3298 | false); |
| 3299 | |
| 3300 | a.info.functionalTest = sa.getBoolean( |
| 3301 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 3302 | false); |
| 3303 | |
| 3304 | sa.recycle(); |
| 3305 | |
| 3306 | if (a.info.targetPackage == null) { |
| 3307 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 3308 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3309 | return null; |
| 3310 | } |
| 3311 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3312 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | outError)) { |
| 3314 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3315 | return null; |
| 3316 | } |
| 3317 | |
| 3318 | owner.instrumentation.add(a); |
| 3319 | |
| 3320 | return a; |
| 3321 | } |
| 3322 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3323 | /** |
| 3324 | * Parse the {@code application} XML tree at the current parse location in a |
| 3325 | * <em>base APK</em> manifest. |
| 3326 | * <p> |
| 3327 | * When adding new features, carefully consider if they should also be |
| 3328 | * supported by split APKs. |
| 3329 | */ |
| 3330 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3331 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | throws XmlPullParserException, IOException { |
| 3333 | final ApplicationInfo ai = owner.applicationInfo; |
| 3334 | final String pkgName = owner.applicationInfo.packageName; |
| 3335 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3336 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3338 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3339 | if (!parsePackageItemInfo(owner, ai, outError, |
| 3340 | "<application>", sa, false /*nameRequired*/, |
| 3341 | com.android.internal.R.styleable.AndroidManifestApplication_name, |
| 3342 | com.android.internal.R.styleable.AndroidManifestApplication_label, |
| 3343 | com.android.internal.R.styleable.AndroidManifestApplication_icon, |
| 3344 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, |
| 3345 | com.android.internal.R.styleable.AndroidManifestApplication_logo, |
| 3346 | com.android.internal.R.styleable.AndroidManifestApplication_banner)) { |
| 3347 | sa.recycle(); |
| 3348 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3349 | return false; |
| 3350 | } |
| 3351 | |
| 3352 | if (ai.name != null) { |
Todd Kennedy | afb5269 | 2016-08-22 15:44:00 -0700 | [diff] [blame] | 3353 | ai.className = ai.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | } |
| 3355 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3356 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3357 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 3358 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | if (manageSpaceActivity != null) { |
| 3360 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 3361 | outError); |
| 3362 | } |
| 3363 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3364 | boolean allowBackup = sa.getBoolean( |
| 3365 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 3366 | if (allowBackup) { |
| 3367 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3368 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3369 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 3370 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 3371 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3372 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3373 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 3374 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3375 | if (backupAgent != null) { |
| 3376 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3377 | if (DEBUG_BACKUP) { |
| 3378 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3379 | + " from " + pkgName + "+" + backupAgent); |
| 3380 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3381 | |
| 3382 | if (sa.getBoolean( |
| 3383 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 3384 | true)) { |
| 3385 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 3386 | } |
| 3387 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 3388 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 3389 | false)) { |
| 3390 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 3391 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 3392 | if (sa.getBoolean( |
| 3393 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 3394 | false)) { |
| 3395 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 3396 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3397 | if (sa.getBoolean( |
| 3398 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 3399 | false)) { |
| 3400 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 3401 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3402 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 3403 | |
| 3404 | TypedValue v = sa.peekValue( |
| 3405 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 3406 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 3407 | if (DEBUG_BACKUP) { |
| 3408 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 3409 | (v.data == 0 ? "false" : "true")); |
| 3410 | } |
| 3411 | // "false" => -1, "true" => 0 |
| 3412 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 3413 | } |
| 3414 | if (DEBUG_BACKUP) { |
| 3415 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 3416 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3417 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 3420 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | ai.descriptionRes = sa.getResourceId( |
| 3422 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 3423 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 3424 | if (sa.getBoolean( |
| 3425 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 3426 | false)) { |
| 3427 | // Check if persistence is based on a feature being present |
| 3428 | final String requiredFeature = sa.getNonResourceString(com.android.internal.R.styleable |
| 3429 | .AndroidManifestApplication_persistentWhenFeatureAvailable); |
| 3430 | if (requiredFeature == null || mCallback.hasFeature(requiredFeature)) { |
| 3431 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3432 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | if (sa.getBoolean( |
| 3436 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 3437 | false)) { |
| 3438 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 3442 | .AndroidManifestApplication_restrictedAccountType); |
| 3443 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 3444 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | } |
| 3446 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 3447 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 3448 | .AndroidManifestApplication_requiredAccountType); |
| 3449 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 3450 | owner.mRequiredAccountType = requiredAccountType; |
| 3451 | } |
| 3452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | if (sa.getBoolean( |
| 3454 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 3455 | false)) { |
| 3456 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 3457 | } |
| 3458 | |
| 3459 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 3460 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 3461 | false)) { |
| 3462 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 3463 | } |
| 3464 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3465 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3466 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 3467 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 3468 | if (owner.baseHardwareAccelerated) { |
| 3469 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 3470 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3471 | |
| 3472 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 3474 | true)) { |
| 3475 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 3476 | } |
| 3477 | |
| 3478 | if (sa.getBoolean( |
| 3479 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 3480 | false)) { |
| 3481 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3482 | } |
| 3483 | |
| 3484 | if (sa.getBoolean( |
| 3485 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 3486 | true)) { |
| 3487 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 3488 | } |
| 3489 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3490 | // The parent package controls installation, hence specify test only installs. |
| 3491 | if (owner.parentPackage == null) { |
| 3492 | if (sa.getBoolean( |
| 3493 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 3494 | false)) { |
| 3495 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 3496 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3499 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3500 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3501 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3502 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3503 | } |
| 3504 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3505 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3506 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
| 3507 | true)) { |
| 3508 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 3509 | } |
| 3510 | |
| 3511 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3512 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 3513 | false /* default is no RTL support*/)) { |
| 3514 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 3515 | } |
| 3516 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 3517 | if (sa.getBoolean( |
| 3518 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 3519 | false)) { |
| 3520 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 3521 | } |
| 3522 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3523 | if (sa.getBoolean( |
| 3524 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
| 3525 | true)) { |
| 3526 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 3527 | } |
| 3528 | |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3529 | if (sa.getBoolean( |
| 3530 | R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 3531 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3532 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3533 | } |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3534 | if (sa.getBoolean( |
| 3535 | R.styleable.AndroidManifestApplication_directBootAware, |
| 3536 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3537 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 3538 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3539 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3540 | if (sa.hasValueOrEmpty(R.styleable.AndroidManifestApplication_resizeableActivity)) { |
| 3541 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, true)) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3542 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; |
| 3543 | } else { |
| 3544 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3545 | } |
| 3546 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3547 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 3548 | } |
| 3549 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3550 | ai.maxAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_maxAspectRatio, 0); |
| 3551 | |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3552 | ai.networkSecurityConfigRes = sa.getResourceId( |
| 3553 | com.android.internal.R.styleable.AndroidManifestApplication_networkSecurityConfig, |
| 3554 | 0); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3555 | ai.category = sa.getInt( |
| 3556 | com.android.internal.R.styleable.AndroidManifestApplication_appCategory, |
| 3557 | ApplicationInfo.CATEGORY_UNDEFINED); |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3560 | str = sa.getNonConfigurationString( |
| 3561 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 3563 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3564 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3565 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3566 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 3567 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3568 | } else { |
| 3569 | // Some older apps have been seen to use a resource reference |
| 3570 | // here that on older builds was ignored (with a warning). We |
| 3571 | // need to continue to do this for them so they don't break. |
| 3572 | str = sa.getNonResourceString( |
| 3573 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 3574 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 3576 | str, outError); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3577 | String factory = sa.getNonResourceString( |
| 3578 | com.android.internal.R.styleable.AndroidManifestApplication_appComponentFactory); |
| 3579 | if (factory != null) { |
| 3580 | ai.appComponentFactory = buildClassName(ai.packageName, factory, outError); |
| 3581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | |
| 3583 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3584 | CharSequence pname; |
| 3585 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3586 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3587 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 3588 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3589 | } else { |
| 3590 | // Some older apps have been seen to use a resource reference |
| 3591 | // here that on older builds was ignored (with a warning). We |
| 3592 | // need to continue to do this for them so they don't break. |
| 3593 | pname = sa.getNonResourceString( |
| 3594 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 3595 | } |
| 3596 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3598 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3599 | ai.enabled = sa.getBoolean( |
| 3600 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3601 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 3602 | if (sa.getBoolean( |
| 3603 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 3604 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 3605 | } |
| 3606 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3607 | if (sa.getBoolean( |
| 3608 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 3609 | false)) { |
| 3610 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 3611 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3612 | // A heavy-weight application can not be in a custom process. |
| 3613 | // We can do direct compare because we intern all strings. |
| 3614 | if (ai.processName != null && !ai.processName.equals(ai.packageName)) { |
| 3615 | outError[0] = "cantSaveState applications can not use custom processes"; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3616 | } |
| 3617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
| 3619 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3620 | ai.uiOptions = sa.getInt( |
| 3621 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 3622 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3623 | ai.classLoaderName = sa.getString( |
| 3624 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3625 | if (ai.classLoaderName != null |
| 3626 | && !ClassLoaderFactory.isValidClassLoaderName(ai.classLoaderName)) { |
| 3627 | outError[0] = "Invalid class loader name: " + ai.classLoaderName; |
| 3628 | } |
| 3629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | sa.recycle(); |
| 3631 | |
| 3632 | if (outError[0] != null) { |
| 3633 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3634 | return false; |
| 3635 | } |
| 3636 | |
| 3637 | final int innerDepth = parser.getDepth(); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3638 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3639 | // getting added to the wrong package. |
| 3640 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | int type; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 3642 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3643 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3644 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3645 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | continue; |
| 3647 | } |
| 3648 | |
| 3649 | String tagName = parser.getName(); |
| 3650 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3651 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3652 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | if (a == null) { |
| 3654 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3655 | return false; |
| 3656 | } |
| 3657 | |
| 3658 | owner.activities.add(a); |
| 3659 | |
| 3660 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3661 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3662 | true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | if (a == null) { |
| 3664 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3665 | return false; |
| 3666 | } |
| 3667 | |
| 3668 | owner.receivers.add(a); |
| 3669 | |
| 3670 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3671 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | if (s == null) { |
| 3673 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3674 | return false; |
| 3675 | } |
| 3676 | |
| 3677 | owner.services.add(s); |
| 3678 | |
| 3679 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3680 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | if (p == null) { |
| 3682 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3683 | return false; |
| 3684 | } |
| 3685 | |
| 3686 | owner.providers.add(p); |
| 3687 | |
| 3688 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3689 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | if (a == null) { |
| 3691 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3692 | return false; |
| 3693 | } |
| 3694 | |
| 3695 | owner.activities.add(a); |
| 3696 | |
| 3697 | } else if (parser.getName().equals("meta-data")) { |
| 3698 | // note: application meta-data is stored off to the side, so it can |
| 3699 | // remain null in the primary copy (we like to avoid extra copies because |
| 3700 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3701 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | outError)) == null) { |
| 3703 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3704 | return false; |
| 3705 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3706 | } else if (tagName.equals("static-library")) { |
| 3707 | sa = res.obtainAttributes(parser, |
| 3708 | com.android.internal.R.styleable.AndroidManifestStaticLibrary); |
| 3709 | |
| 3710 | // Note: don't allow this value to be a reference to a resource |
| 3711 | // that may change. |
| 3712 | final String lname = sa.getNonResourceString( |
| 3713 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_name); |
| 3714 | final int version = sa.getInt( |
| 3715 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_version, -1); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3716 | final int versionMajor = sa.getInt( |
| 3717 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_versionMajor, |
| 3718 | 0); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3719 | |
| 3720 | sa.recycle(); |
| 3721 | |
| 3722 | // Since the app canot run without a static lib - fail if malformed |
| 3723 | if (lname == null || version < 0) { |
| 3724 | outError[0] = "Bad static-library declaration name: " + lname |
| 3725 | + " version: " + version; |
| 3726 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3727 | XmlUtils.skipCurrentTag(parser); |
| 3728 | return false; |
| 3729 | } |
| 3730 | |
| 3731 | if (owner.mSharedUserId != null) { |
| 3732 | outError[0] = "sharedUserId not allowed in static shared library"; |
| 3733 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 3734 | XmlUtils.skipCurrentTag(parser); |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
| 3738 | if (owner.staticSharedLibName != null) { |
| 3739 | outError[0] = "Multiple static-shared libs for package " + pkgName; |
| 3740 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3741 | XmlUtils.skipCurrentTag(parser); |
| 3742 | return false; |
| 3743 | } |
| 3744 | |
| 3745 | owner.staticSharedLibName = lname.intern(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3746 | if (version >= 0) { |
| 3747 | owner.staticSharedLibVersion = |
| 3748 | PackageInfo.composeLongVersionCode(versionMajor, version); |
| 3749 | } else { |
| 3750 | owner.staticSharedLibVersion = version; |
| 3751 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3752 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY; |
| 3753 | |
| 3754 | XmlUtils.skipCurrentTag(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3756 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3757 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3758 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3759 | |
| 3760 | // Note: don't allow this value to be a reference to a resource |
| 3761 | // that may change. |
| 3762 | String lname = sa.getNonResourceString( |
| 3763 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3764 | |
| 3765 | sa.recycle(); |
| 3766 | |
| 3767 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3768 | lname = lname.intern(); |
| 3769 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3770 | owner.libraryNames = ArrayUtils.add( |
| 3771 | owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | XmlUtils.skipCurrentTag(parser); |
| 3776 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3777 | } else if (tagName.equals("uses-static-library")) { |
| 3778 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3779 | return false; |
| 3780 | } |
| 3781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3783 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3785 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3786 | // Note: don't allow this value to be a reference to a resource |
| 3787 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3788 | String lname = sa.getNonResourceString( |
| 3789 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3790 | boolean req = sa.getBoolean( |
| 3791 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3792 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | |
| 3794 | sa.recycle(); |
| 3795 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3796 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3797 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3798 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3799 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3800 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3801 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3802 | owner.usesOptionalLibraries, lname); |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | XmlUtils.skipCurrentTag(parser); |
| 3807 | |
| 3808 | } else if (tagName.equals("uses-package")) { |
| 3809 | // Dependencies for app installers; we don't currently try to |
| 3810 | // enforce this. |
| 3811 | XmlUtils.skipCurrentTag(parser); |
| 3812 | |
| 3813 | } else { |
| 3814 | if (!RIGID_PARSER) { |
| 3815 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 3816 | + " at " + mArchiveSourcePath + " " |
| 3817 | + parser.getPositionDescription()); |
| 3818 | XmlUtils.skipCurrentTag(parser); |
| 3819 | continue; |
| 3820 | } else { |
| 3821 | outError[0] = "Bad element under <application>: " + tagName; |
| 3822 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3823 | return false; |
| 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 3828 | // Must be ran after the entire {@link ApplicationInfo} has been fully processed and after |
| 3829 | // every activity info has had a chance to set it from its attributes. |
| 3830 | setMaxAspectRatio(owner); |
| 3831 | |
Paul Duffin | 855d702 | 2017-07-10 15:16:07 +0100 | [diff] [blame] | 3832 | PackageBackwardCompatibility.modifySharedLibraries(owner); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3833 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3834 | if (hasDomainURLs(owner)) { |
| 3835 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3836 | } else { |
| 3837 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3838 | } |
| 3839 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3840 | return true; |
| 3841 | } |
| 3842 | |
| 3843 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3844 | * Check if one of the IntentFilter as both actions DEFAULT / VIEW and a HTTP/HTTPS data URI |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3845 | */ |
| 3846 | private static boolean hasDomainURLs(Package pkg) { |
| 3847 | if (pkg == null || pkg.activities == null) return false; |
| 3848 | final ArrayList<Activity> activities = pkg.activities; |
| 3849 | final int countActivities = activities.size(); |
| 3850 | for (int n=0; n<countActivities; n++) { |
| 3851 | Activity activity = activities.get(n); |
| 3852 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 3853 | if (filters == null) continue; |
| 3854 | final int countFilters = filters.size(); |
| 3855 | for (int m=0; m<countFilters; m++) { |
| 3856 | ActivityIntentInfo aii = filters.get(m); |
| 3857 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3858 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3859 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 3860 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 3861 | return true; |
| 3862 | } |
| 3863 | } |
| 3864 | } |
| 3865 | return false; |
| 3866 | } |
| 3867 | |
| 3868 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3869 | * Parse the {@code application} XML tree at the current parse location in a |
| 3870 | * <em>split APK</em> manifest. |
| 3871 | * <p> |
| 3872 | * Note that split APKs have many more restrictions on what they're capable |
| 3873 | * of doing, so many valid features of a base APK have been carefully |
| 3874 | * omitted here. |
| 3875 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3876 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 3877 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3878 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3879 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3880 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3881 | |
| 3882 | if (sa.getBoolean( |
| 3883 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 3884 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 3885 | } |
| 3886 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3887 | final String classLoaderName = sa.getString( |
| 3888 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3889 | if (classLoaderName == null || ClassLoaderFactory.isValidClassLoaderName(classLoaderName)) { |
| 3890 | owner.applicationInfo.splitClassLoaderNames[splitIndex] = classLoaderName; |
| 3891 | } else { |
| 3892 | outError[0] = "Invalid class loader name: " + classLoaderName; |
| 3893 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3894 | return false; |
| 3895 | } |
| 3896 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3897 | final int innerDepth = parser.getDepth(); |
| 3898 | int type; |
| 3899 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3900 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3901 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3902 | continue; |
| 3903 | } |
| 3904 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3905 | ComponentInfo parsedComponent = null; |
| 3906 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3907 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3908 | // getting added to the wrong package. |
| 3909 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3910 | String tagName = parser.getName(); |
| 3911 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3912 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3913 | owner.baseHardwareAccelerated); |
| 3914 | if (a == null) { |
| 3915 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3916 | return false; |
| 3917 | } |
| 3918 | |
| 3919 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3920 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3921 | |
| 3922 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3923 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3924 | true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3925 | if (a == null) { |
| 3926 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3927 | return false; |
| 3928 | } |
| 3929 | |
| 3930 | owner.receivers.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3931 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3932 | |
| 3933 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3934 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3935 | if (s == null) { |
| 3936 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | owner.services.add(s); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3941 | parsedComponent = s.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3942 | |
| 3943 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3944 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3945 | if (p == null) { |
| 3946 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3947 | return false; |
| 3948 | } |
| 3949 | |
| 3950 | owner.providers.add(p); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3951 | parsedComponent = p.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3952 | |
| 3953 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3954 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3955 | if (a == null) { |
| 3956 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3957 | return false; |
| 3958 | } |
| 3959 | |
| 3960 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3961 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3962 | |
| 3963 | } else if (parser.getName().equals("meta-data")) { |
| 3964 | // note: application meta-data is stored off to the side, so it can |
| 3965 | // remain null in the primary copy (we like to avoid extra copies because |
| 3966 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3967 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3968 | outError)) == null) { |
| 3969 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3970 | return false; |
| 3971 | } |
| 3972 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3973 | } else if (tagName.equals("uses-static-library")) { |
| 3974 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3975 | return false; |
| 3976 | } |
| 3977 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3978 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3979 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3980 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3981 | |
| 3982 | // Note: don't allow this value to be a reference to a resource |
| 3983 | // that may change. |
| 3984 | String lname = sa.getNonResourceString( |
| 3985 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 3986 | boolean req = sa.getBoolean( |
| 3987 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3988 | true); |
| 3989 | |
| 3990 | sa.recycle(); |
| 3991 | |
| 3992 | if (lname != null) { |
| 3993 | lname = lname.intern(); |
| 3994 | if (req) { |
| 3995 | // Upgrade to treat as stronger constraint |
| 3996 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 3997 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 3998 | owner.usesOptionalLibraries, lname); |
| 3999 | } else { |
| 4000 | // Ignore if someone already defined as required |
| 4001 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 4002 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 4003 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4004 | } |
| 4005 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | XmlUtils.skipCurrentTag(parser); |
| 4009 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 4010 | } else if (tagName.equals("uses-package")) { |
| 4011 | // Dependencies for app installers; we don't currently try to |
| 4012 | // enforce this. |
| 4013 | XmlUtils.skipCurrentTag(parser); |
| 4014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | } else { |
| 4016 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4017 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4018 | + " at " + mArchiveSourcePath + " " |
| 4019 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | XmlUtils.skipCurrentTag(parser); |
| 4021 | continue; |
| 4022 | } else { |
| 4023 | outError[0] = "Bad element under <application>: " + tagName; |
| 4024 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4025 | return false; |
| 4026 | } |
| 4027 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4028 | |
| 4029 | if (parsedComponent != null && parsedComponent.splitName == null) { |
| 4030 | // If the loaded component did not specify a split, inherit the split name |
| 4031 | // based on the split it is defined in. |
| 4032 | // This is used to later load the correct split when starting this |
| 4033 | // component. |
| 4034 | parsedComponent.splitName = owner.splitNames[splitIndex]; |
| 4035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | return true; |
| 4039 | } |
| 4040 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4041 | private static boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 4042 | String[] outError, String tag, TypedArray sa, boolean nameRequired, |
| 4043 | int nameRes, int labelRes, int iconRes, int roundIconRes, int logoRes, int bannerRes) { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 4044 | // This case can only happen in unit tests where we sometimes need to create fakes |
| 4045 | // of various package parser data structures. |
| 4046 | if (sa == null) { |
| 4047 | outError[0] = tag + " does not contain any attributes"; |
| 4048 | return false; |
| 4049 | } |
| 4050 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4051 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4052 | if (name == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4053 | if (nameRequired) { |
| 4054 | outError[0] = tag + " does not specify android:name"; |
| 4055 | return false; |
| 4056 | } |
| 4057 | } else { |
| 4058 | outInfo.name |
| 4059 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 4060 | if (outInfo.name == null) { |
| 4061 | return false; |
| 4062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 4065 | final boolean useRoundIcon = |
| 4066 | Resources.getSystem().getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 4067 | int roundIconVal = useRoundIcon ? sa.getResourceId(roundIconRes, 0) : 0; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4068 | if (roundIconVal != 0) { |
| 4069 | outInfo.icon = roundIconVal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | outInfo.nonLocalizedLabel = null; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4071 | } else { |
| 4072 | int iconVal = sa.getResourceId(iconRes, 0); |
| 4073 | if (iconVal != 0) { |
| 4074 | outInfo.icon = iconVal; |
| 4075 | outInfo.nonLocalizedLabel = null; |
| 4076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4078 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4079 | int logoVal = sa.getResourceId(logoRes, 0); |
| 4080 | if (logoVal != 0) { |
| 4081 | outInfo.logo = logoVal; |
| 4082 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4084 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 4085 | if (bannerVal != 0) { |
| 4086 | outInfo.banner = bannerVal; |
| 4087 | } |
| 4088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | TypedValue v = sa.peekValue(labelRes); |
| 4090 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4091 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4092 | } |
| 4093 | |
| 4094 | outInfo.packageName = owner.packageName; |
| 4095 | |
| 4096 | return true; |
| 4097 | } |
| 4098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | private Activity parseActivity(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4100 | XmlResourceParser parser, int flags, String[] outError, CachedComponentArgs cachedArgs, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4101 | boolean receiver, boolean hardwareAccelerated) |
| 4102 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4103 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4105 | if (cachedArgs.mActivityArgs == null) { |
| 4106 | cachedArgs.mActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4107 | R.styleable.AndroidManifestActivity_name, |
| 4108 | R.styleable.AndroidManifestActivity_label, |
| 4109 | R.styleable.AndroidManifestActivity_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4110 | R.styleable.AndroidManifestActivity_roundIcon, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4111 | R.styleable.AndroidManifestActivity_logo, |
| 4112 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4113 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4114 | R.styleable.AndroidManifestActivity_process, |
| 4115 | R.styleable.AndroidManifestActivity_description, |
| 4116 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4117 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4118 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4119 | cachedArgs.mActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 4120 | cachedArgs.mActivityArgs.sa = sa; |
| 4121 | cachedArgs.mActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4122 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4123 | Activity a = new Activity(cachedArgs.mActivityArgs, new ActivityInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4124 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | sa.recycle(); |
| 4126 | return null; |
| 4127 | } |
| 4128 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4129 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4131 | a.info.exported = sa.getBoolean(R.styleable.AndroidManifestActivity_exported, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | } |
| 4133 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4134 | a.info.theme = sa.getResourceId(R.styleable.AndroidManifestActivity_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4136 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4137 | a.info.applicationInfo.uiOptions); |
| 4138 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4139 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4140 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4141 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4142 | if (parentName != null) { |
| 4143 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4144 | if (outError[0] == null) { |
| 4145 | a.info.parentActivityName = parentClassName; |
| 4146 | } else { |
| 4147 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 4148 | parentName); |
| 4149 | outError[0] = null; |
| 4150 | } |
| 4151 | } |
| 4152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4154 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | if (str == null) { |
| 4156 | a.info.permission = owner.applicationInfo.permission; |
| 4157 | } else { |
| 4158 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4159 | } |
| 4160 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4161 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4162 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4163 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 4165 | owner.applicationInfo.taskAffinity, str, outError); |
| 4166 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4167 | a.info.splitName = |
| 4168 | sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_splitName, 0); |
| 4169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | a.info.flags = 0; |
| 4171 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4172 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 4174 | } |
| 4175 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4176 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 4178 | } |
| 4179 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4180 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 4182 | } |
| 4183 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4184 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 4186 | } |
| 4187 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4188 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 4190 | } |
| 4191 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4192 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 4194 | } |
| 4195 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4196 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 4198 | } |
| 4199 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4200 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 4202 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 4203 | } |
| 4204 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4205 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4206 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 4207 | } |
| 4208 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 4209 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 4210 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 4211 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4214 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 4215 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 4216 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4217 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 4218 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 4219 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4223 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4224 | hardwareAccelerated)) { |
| 4225 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4226 | } |
| 4227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4229 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4230 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4231 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4232 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 4233 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4234 | R.styleable.AndroidManifestActivity_maxRecents, |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 4235 | ActivityManager.getDefaultAppRecentsLimitStatic()); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4236 | a.info.configChanges = getActivityConfigChanges( |
| 4237 | sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0), |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4238 | sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4240 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4241 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4242 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4243 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4244 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4245 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4246 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4247 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 4248 | } |
| 4249 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4250 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4251 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 4252 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4253 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4254 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4255 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 4256 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4257 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4258 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4259 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 4260 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4261 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4262 | a.info.screenOrientation = sa.getInt( |
| 4263 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 4264 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 4265 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4266 | setActivityResizeMode(a.info, sa, owner); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4267 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4268 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 4269 | false)) { |
| 4270 | a.info.flags |= FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 4271 | } |
| 4272 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4273 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4274 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4275 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 4276 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4277 | if (sa.hasValue(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4278 | && sa.getType(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4279 | == TypedValue.TYPE_FLOAT) { |
| 4280 | a.setMaxAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_maxAspectRatio, |
| 4281 | 0 /*default*/)); |
| 4282 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4283 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4284 | a.info.lockTaskLaunchMode = |
| 4285 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4286 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4287 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4288 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4289 | false); |
Ruben Brunk | f56c9f4 | 2016-04-22 18:20:55 -0700 | [diff] [blame] | 4290 | |
| 4291 | a.info.requestedVrComponent = |
| 4292 | sa.getString(R.styleable.AndroidManifestActivity_enableVrMode); |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 4293 | |
| 4294 | a.info.rotationAnimation = |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 4295 | sa.getInt(R.styleable.AndroidManifestActivity_rotationAnimation, ROTATION_ANIMATION_UNSPECIFIED); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 4296 | |
| 4297 | a.info.colorMode = sa.getInt(R.styleable.AndroidManifestActivity_colorMode, |
| 4298 | ActivityInfo.COLOR_MODE_DEFAULT); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4299 | |
| 4300 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showWhenLocked, false)) { |
| 4301 | a.info.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
| 4302 | } |
| 4303 | |
| 4304 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_turnScreenOn, false)) { |
| 4305 | a.info.flags |= ActivityInfo.FLAG_TURN_SCREEN_ON; |
| 4306 | } |
| 4307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } else { |
| 4309 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4310 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4312 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 4313 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4314 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4315 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4316 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4317 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4318 | false); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4321 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4322 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4323 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4326 | // can't make this final; we may set it later via meta-data |
| 4327 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4328 | sa.getBoolean(R.styleable.AndroidManifestActivity_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4329 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4330 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4331 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4332 | } |
| 4333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | sa.recycle(); |
| 4335 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4336 | if (receiver && (owner.applicationInfo.privateFlags |
| 4337 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4338 | // A heavy-weight application can not have receives in its main process |
| 4339 | // We can do direct compare because we intern all strings. |
| 4340 | if (a.info.processName == owner.packageName) { |
| 4341 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 4342 | } |
| 4343 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | if (outError[0] != null) { |
| 4346 | return null; |
| 4347 | } |
| 4348 | |
| 4349 | int outerDepth = parser.getDepth(); |
| 4350 | int type; |
| 4351 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4352 | && (type != XmlPullParser.END_TAG |
| 4353 | || parser.getDepth() > outerDepth)) { |
| 4354 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4355 | continue; |
| 4356 | } |
| 4357 | |
| 4358 | if (parser.getName().equals("intent-filter")) { |
| 4359 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4360 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4361 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | return null; |
| 4363 | } |
| 4364 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4365 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4366 | + mArchiveSourcePath + " " |
| 4367 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | } else { |
| 4369 | a.intents.add(intent); |
| 4370 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4371 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4372 | final int visibility = visibleToEphemeral |
| 4373 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4374 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4375 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4376 | : IntentFilter.VISIBILITY_NONE; |
| 4377 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4378 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4379 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4380 | } |
| 4381 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4382 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4383 | } |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 4384 | if (LOG_UNSAFE_BROADCASTS && receiver |
| 4385 | && (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O)) { |
| 4386 | for (int i = 0; i < intent.countActions(); i++) { |
| 4387 | final String action = intent.getAction(i); |
| 4388 | if (action == null || !action.startsWith("android.")) continue; |
| 4389 | if (!SAFE_BROADCASTS.contains(action)) { |
| 4390 | Slog.w(TAG, "Broadcast " + action + " may never be delivered to " |
| 4391 | + owner.packageName + " as requested at: " |
| 4392 | + parser.getPositionDescription()); |
| 4393 | } |
| 4394 | } |
| 4395 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4396 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 4397 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4398 | if (!parseIntent(res, parser, false /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4399 | intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4400 | return null; |
| 4401 | } |
| 4402 | if (intent.countActions() == 0) { |
| 4403 | Slog.w(TAG, "No actions in preferred at " |
| 4404 | + mArchiveSourcePath + " " |
| 4405 | + parser.getPositionDescription()); |
| 4406 | } else { |
| 4407 | if (owner.preferredActivityFilters == null) { |
| 4408 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 4409 | } |
| 4410 | owner.preferredActivityFilters.add(intent); |
| 4411 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4412 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4413 | final int visibility = visibleToEphemeral |
| 4414 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4415 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4416 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4417 | : IntentFilter.VISIBILITY_NONE; |
| 4418 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4419 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4420 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4421 | } |
| 4422 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4423 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4426 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | outError)) == null) { |
| 4428 | return null; |
| 4429 | } |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4430 | // we don't have an attribute [or it's false], but, we have meta-data |
| 4431 | if (!visibleToEphemeral && a.metaData.getBoolean(META_DATA_INSTANT_APPS)) { |
| 4432 | visibleToEphemeral = true; // set in case there are more intent filters |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4433 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4434 | a.info.flags &= ~ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4435 | owner.visibleToInstantApps = true; |
| 4436 | // cycle through any filters already seen |
| 4437 | for (int i = a.intents.size() - 1; i >= 0; --i) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4438 | a.intents.get(i) |
| 4439 | .setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4440 | } |
| 4441 | if (owner.preferredActivityFilters != null) { |
| 4442 | for (int i = owner.preferredActivityFilters.size() - 1; i >= 0; --i) { |
| 4443 | owner.preferredActivityFilters.get(i) |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4444 | .setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4445 | } |
| 4446 | } |
| 4447 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4448 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4449 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | } else { |
| 4451 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4452 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4454 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4455 | + " at " + mArchiveSourcePath + " " |
| 4456 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4458 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4459 | + " at " + mArchiveSourcePath + " " |
| 4460 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | } |
| 4462 | XmlUtils.skipCurrentTag(parser); |
| 4463 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4465 | if (receiver) { |
| 4466 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 4467 | } else { |
| 4468 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 4469 | } |
| 4470 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | } |
| 4473 | } |
| 4474 | |
| 4475 | if (!setExported) { |
| 4476 | a.info.exported = a.intents.size() > 0; |
| 4477 | } |
| 4478 | |
| 4479 | return a; |
| 4480 | } |
| 4481 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4482 | private void setActivityResizeMode(ActivityInfo aInfo, TypedArray sa, Package owner) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4483 | final boolean appExplicitDefault = (owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4484 | & (PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE |
| 4485 | | PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE)) != 0; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4486 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4487 | if (sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity) |
| 4488 | || appExplicitDefault) { |
| 4489 | // Activity or app explicitly set if it is resizeable or not; |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4490 | final boolean appResizeable = (owner.applicationInfo.privateFlags |
| 4491 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE) != 0; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4492 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity, |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4493 | appResizeable)) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4494 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4495 | } else { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4496 | aInfo.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4497 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4498 | return; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4499 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4500 | |
| 4501 | if ((owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4502 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) != 0) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4503 | // The activity or app didn't explicitly set the resizing option, however we want to |
| 4504 | // make it resize due to the sdk version it is targeting. |
| 4505 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 4506 | return; |
| 4507 | } |
| 4508 | |
| 4509 | // resize preference isn't set and target sdk version doesn't support resizing apps by |
| 4510 | // default. For the app to be resizeable if it isn't fixed orientation or immersive. |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 4511 | if (aInfo.isFixedOrientationPortrait()) { |
| 4512 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 4513 | } else if (aInfo.isFixedOrientationLandscape()) { |
| 4514 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 4515 | } else if (aInfo.isFixedOrientation()) { |
| 4516 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
| 4517 | } else { |
| 4518 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4519 | } |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4522 | /** |
| 4523 | * Sets every the max aspect ratio of every child activity that doesn't already have an aspect |
| 4524 | * ratio set. |
| 4525 | */ |
| 4526 | private void setMaxAspectRatio(Package owner) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4527 | // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater. |
| 4528 | // NOTE: 16.7:9 was the max aspect ratio Android devices can support pre-O per the CDD. |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4529 | float maxAspectRatio = owner.applicationInfo.targetSdkVersion < O |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4530 | ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4531 | |
| 4532 | if (owner.applicationInfo.maxAspectRatio != 0) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4533 | // Use the application max aspect ration as default if set. |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4534 | maxAspectRatio = owner.applicationInfo.maxAspectRatio; |
| 4535 | } else if (owner.mAppMetaData != null |
| 4536 | && owner.mAppMetaData.containsKey(METADATA_MAX_ASPECT_RATIO)) { |
| 4537 | maxAspectRatio = owner.mAppMetaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4540 | for (Activity activity : owner.activities) { |
| 4541 | // If the max aspect ratio for the activity has already been set, skip. |
| 4542 | if (activity.hasMaxAspectRatio()) { |
| 4543 | continue; |
| 4544 | } |
| 4545 | |
| 4546 | // By default we prefer to use a values defined on the activity directly than values |
| 4547 | // defined on the application. We do not check the styled attributes on the activity |
| 4548 | // as it would have already been set when we processed the activity. We wait to process |
| 4549 | // the meta data here since this method is called at the end of processing the |
| 4550 | // application and all meta data is guaranteed. |
| 4551 | final float activityAspectRatio = activity.metaData != null |
| 4552 | ? activity.metaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio) |
| 4553 | : maxAspectRatio; |
| 4554 | |
| 4555 | activity.setMaxAspectRatio(activityAspectRatio); |
Wale Ogunwale | 0cb70ac | 2017-03-27 09:16:38 -0700 | [diff] [blame] | 4556 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4557 | } |
| 4558 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4559 | /** |
| 4560 | * @param configChanges The bit mask of configChanges fetched from AndroidManifest.xml. |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4561 | * @param recreateOnConfigChanges The bit mask recreateOnConfigChanges fetched from |
| 4562 | * AndroidManifest.xml. |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4563 | * @hide Exposed for unit testing only. |
| 4564 | */ |
| 4565 | @TestApi |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4566 | public static int getActivityConfigChanges(int configChanges, int recreateOnConfigChanges) { |
| 4567 | return configChanges | ((~recreateOnConfigChanges) & RECREATE_ON_CONFIG_CHANGES_MASK); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4568 | } |
| 4569 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4570 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4571 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4572 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4573 | int width = -1; |
| 4574 | float widthFraction = -1f; |
| 4575 | int height = -1; |
| 4576 | float heightFraction = -1f; |
| 4577 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4578 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4579 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 4580 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4581 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4582 | 1, 1, -1); |
| 4583 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 4584 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4585 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4586 | -1); |
| 4587 | } |
| 4588 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4589 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4590 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 4591 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4592 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4593 | 1, 1, -1); |
| 4594 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 4595 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4596 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4597 | -1); |
| 4598 | } |
| 4599 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4600 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4601 | Gravity.CENTER); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4602 | int minWidth = sw.getDimensionPixelSize( |
| 4603 | com.android.internal.R.styleable.AndroidManifestLayout_minWidth, |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4604 | -1); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4605 | int minHeight = sw.getDimensionPixelSize( |
| 4606 | com.android.internal.R.styleable.AndroidManifestLayout_minHeight, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4607 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4608 | sw.recycle(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4609 | a.info.windowLayout = new ActivityInfo.WindowLayout(width, widthFraction, |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4610 | height, heightFraction, gravity, minWidth, minHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | private Activity parseActivityAlias(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4614 | XmlResourceParser parser, int flags, String[] outError, |
| 4615 | CachedComponentArgs cachedArgs) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4616 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4617 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4618 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 4619 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4620 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4621 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 4622 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | if (targetActivity == null) { |
| 4624 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 4625 | sa.recycle(); |
| 4626 | return null; |
| 4627 | } |
| 4628 | |
| 4629 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 4630 | targetActivity, outError); |
| 4631 | if (targetActivity == null) { |
| 4632 | sa.recycle(); |
| 4633 | return null; |
| 4634 | } |
| 4635 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4636 | if (cachedArgs.mActivityAliasArgs == null) { |
| 4637 | cachedArgs.mActivityAliasArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4638 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 4639 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 4640 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4641 | com.android.internal.R.styleable.AndroidManifestActivityAlias_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4642 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4643 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4644 | mSeparateProcesses, |
| 4645 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4646 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4647 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4648 | cachedArgs.mActivityAliasArgs.tag = "<activity-alias>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4649 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4650 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4651 | cachedArgs.mActivityAliasArgs.sa = sa; |
| 4652 | cachedArgs.mActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | Activity target = null; |
| 4655 | |
| 4656 | final int NA = owner.activities.size(); |
| 4657 | for (int i=0; i<NA; i++) { |
| 4658 | Activity t = owner.activities.get(i); |
| 4659 | if (targetActivity.equals(t.info.name)) { |
| 4660 | target = t; |
| 4661 | break; |
| 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | if (target == null) { |
| 4666 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 4667 | + " not found in manifest"; |
| 4668 | sa.recycle(); |
| 4669 | return null; |
| 4670 | } |
| 4671 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4672 | ActivityInfo info = new ActivityInfo(); |
| 4673 | info.targetActivity = targetActivity; |
| 4674 | info.configChanges = target.info.configChanges; |
| 4675 | info.flags = target.info.flags; |
| 4676 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4677 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4678 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4679 | info.labelRes = target.info.labelRes; |
| 4680 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 4681 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 4682 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4683 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4684 | if (info.descriptionRes == 0) { |
| 4685 | info.descriptionRes = target.info.descriptionRes; |
| 4686 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4687 | info.screenOrientation = target.info.screenOrientation; |
| 4688 | info.taskAffinity = target.info.taskAffinity; |
| 4689 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 4690 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4691 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4692 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4693 | info.maxRecents = target.info.maxRecents; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4694 | info.windowLayout = target.info.windowLayout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4695 | info.resizeMode = target.info.resizeMode; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4696 | info.maxAspectRatio = target.info.maxAspectRatio; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4697 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4698 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4699 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4700 | Activity a = new Activity(cachedArgs.mActivityAliasArgs, info); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4701 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | sa.recycle(); |
| 4703 | return null; |
| 4704 | } |
| 4705 | |
| 4706 | final boolean setExported = sa.hasValue( |
| 4707 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 4708 | if (setExported) { |
| 4709 | a.info.exported = sa.getBoolean( |
| 4710 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 4711 | } |
| 4712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4714 | str = sa.getNonConfigurationString( |
| 4715 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4716 | if (str != null) { |
| 4717 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4718 | } |
| 4719 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4720 | String parentName = sa.getNonConfigurationString( |
| 4721 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4722 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4723 | if (parentName != null) { |
| 4724 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4725 | if (outError[0] == null) { |
| 4726 | a.info.parentActivityName = parentClassName; |
| 4727 | } else { |
| 4728 | Log.e(TAG, "Activity alias " + a.info.name + |
| 4729 | " specified invalid parentActivityName " + parentName); |
| 4730 | outError[0] = null; |
| 4731 | } |
| 4732 | } |
| 4733 | |
Chad Brubaker | 699c771 | 2017-01-20 13:53:42 -0800 | [diff] [blame] | 4734 | // TODO add visibleToInstantApps attribute to activity alias |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4735 | final boolean visibleToEphemeral = |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4736 | ((a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | sa.recycle(); |
| 4739 | |
| 4740 | if (outError[0] != null) { |
| 4741 | return null; |
| 4742 | } |
| 4743 | |
| 4744 | int outerDepth = parser.getDepth(); |
| 4745 | int type; |
| 4746 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4747 | && (type != XmlPullParser.END_TAG |
| 4748 | || parser.getDepth() > outerDepth)) { |
| 4749 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4750 | continue; |
| 4751 | } |
| 4752 | |
| 4753 | if (parser.getName().equals("intent-filter")) { |
| 4754 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4755 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4756 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | return null; |
| 4758 | } |
| 4759 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4760 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4761 | + mArchiveSourcePath + " " |
| 4762 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | } else { |
| 4764 | a.intents.add(intent); |
| 4765 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4766 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4767 | final int visibility = visibleToEphemeral |
| 4768 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4769 | : isImplicitlyExposedIntent(intent) |
| 4770 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4771 | : IntentFilter.VISIBILITY_NONE; |
| 4772 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4773 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4774 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4775 | } |
| 4776 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4777 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4778 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4780 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | outError)) == null) { |
| 4782 | return null; |
| 4783 | } |
| 4784 | } else { |
| 4785 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4786 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4787 | + " at " + mArchiveSourcePath + " " |
| 4788 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | XmlUtils.skipCurrentTag(parser); |
| 4790 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4791 | } else { |
| 4792 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 4793 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | if (!setExported) { |
| 4799 | a.info.exported = a.intents.size() > 0; |
| 4800 | } |
| 4801 | |
| 4802 | return a; |
| 4803 | } |
| 4804 | |
| 4805 | private Provider parseProvider(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4806 | XmlResourceParser parser, int flags, String[] outError, |
| 4807 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4809 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 4811 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4812 | if (cachedArgs.mProviderArgs == null) { |
| 4813 | cachedArgs.mProviderArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4814 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 4815 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 4816 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4817 | com.android.internal.R.styleable.AndroidManifestProvider_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4818 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4819 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4820 | mSeparateProcesses, |
| 4821 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4822 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4823 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4824 | cachedArgs.mProviderArgs.tag = "<provider>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4825 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4826 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4827 | cachedArgs.mProviderArgs.sa = sa; |
| 4828 | cachedArgs.mProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4829 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4830 | Provider p = new Provider(cachedArgs.mProviderArgs, new ProviderInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4831 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4832 | sa.recycle(); |
| 4833 | return null; |
| 4834 | } |
| 4835 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4836 | boolean providerExportedDefault = false; |
| 4837 | |
| 4838 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 4839 | // For compatibility, applications targeting API level 16 or lower |
| 4840 | // should have their content providers exported by default, unless they |
| 4841 | // specify otherwise. |
| 4842 | providerExportedDefault = true; |
| 4843 | } |
| 4844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4846 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 4847 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4849 | String cpname = sa.getNonConfigurationString( |
| 4850 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | |
| 4852 | p.info.isSyncable = sa.getBoolean( |
| 4853 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 4854 | false); |
| 4855 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4856 | String permission = sa.getNonConfigurationString( |
| 4857 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 4858 | String str = sa.getNonConfigurationString( |
| 4859 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | if (str == null) { |
| 4861 | str = permission; |
| 4862 | } |
| 4863 | if (str == null) { |
| 4864 | p.info.readPermission = owner.applicationInfo.permission; |
| 4865 | } else { |
| 4866 | p.info.readPermission = |
| 4867 | str.length() > 0 ? str.toString().intern() : null; |
| 4868 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4869 | str = sa.getNonConfigurationString( |
| 4870 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | if (str == null) { |
| 4872 | str = permission; |
| 4873 | } |
| 4874 | if (str == null) { |
| 4875 | p.info.writePermission = owner.applicationInfo.permission; |
| 4876 | } else { |
| 4877 | p.info.writePermission = |
| 4878 | str.length() > 0 ? str.toString().intern() : null; |
| 4879 | } |
| 4880 | |
| 4881 | p.info.grantUriPermissions = sa.getBoolean( |
| 4882 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 4883 | false); |
| 4884 | |
| 4885 | p.info.multiprocess = sa.getBoolean( |
| 4886 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 4887 | false); |
| 4888 | |
| 4889 | p.info.initOrder = sa.getInt( |
| 4890 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 4891 | 0); |
| 4892 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4893 | p.info.splitName = |
| 4894 | sa.getNonConfigurationString(R.styleable.AndroidManifestProvider_splitName, 0); |
| 4895 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4896 | p.info.flags = 0; |
| 4897 | |
| 4898 | if (sa.getBoolean( |
| 4899 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 4900 | false)) { |
| 4901 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4904 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 4905 | R.styleable.AndroidManifestProvider_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4906 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4907 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4908 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4909 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4910 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4911 | |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4912 | final boolean visibleToEphemeral = |
| 4913 | sa.getBoolean(R.styleable.AndroidManifestProvider_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4914 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4915 | p.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4916 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4917 | } |
| 4918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | sa.recycle(); |
| 4920 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4921 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 4922 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4923 | // A heavy-weight application can not have providers in its main process |
| 4924 | // We can do direct compare because we intern all strings. |
| 4925 | if (p.info.processName == owner.packageName) { |
| 4926 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 4927 | return null; |
| 4928 | } |
| 4929 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4932 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4933 | return null; |
| 4934 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 4935 | if (cpname.length() <= 0) { |
| 4936 | outError[0] = "<provider> has empty authorities attribute"; |
| 4937 | return null; |
| 4938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4939 | p.info.authority = cpname.intern(); |
| 4940 | |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4941 | if (!parseProviderTags( |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4942 | res, parser, visibleToEphemeral, owner, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | return null; |
| 4944 | } |
| 4945 | |
| 4946 | return p; |
| 4947 | } |
| 4948 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4949 | private boolean parseProviderTags(Resources res, XmlResourceParser parser, |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4950 | boolean visibleToEphemeral, Package owner, Provider outInfo, String[] outError) |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4951 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | int outerDepth = parser.getDepth(); |
| 4953 | int type; |
| 4954 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4955 | && (type != XmlPullParser.END_TAG |
| 4956 | || parser.getDepth() > outerDepth)) { |
| 4957 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4958 | continue; |
| 4959 | } |
| 4960 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4961 | if (parser.getName().equals("intent-filter")) { |
| 4962 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4963 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4964 | intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4965 | return false; |
| 4966 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4967 | if (visibleToEphemeral) { |
| 4968 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 4969 | outInfo.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4970 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4971 | outInfo.intents.add(intent); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4972 | |
| 4973 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4974 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4975 | outInfo.metaData, outError)) == null) { |
| 4976 | return false; |
| 4977 | } |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4978 | // we don't have an attribute [or it's false], but, we have meta-data |
| 4979 | if (!visibleToEphemeral && outInfo.metaData.getBoolean(META_DATA_INSTANT_APPS)) { |
| 4980 | visibleToEphemeral = true; // set in case there are more intent filters |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4981 | outInfo.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4982 | owner.visibleToInstantApps = true; |
| 4983 | // cycle through any filters already seen |
| 4984 | for (int i = outInfo.intents.size() - 1; i >= 0; --i) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4985 | outInfo.intents.get(i) |
| 4986 | .setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4987 | } |
| 4988 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4990 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4991 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4992 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 4993 | |
| 4994 | PatternMatcher pa = null; |
| 4995 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4996 | String str = sa.getNonConfigurationString( |
| 4997 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4998 | if (str != null) { |
| 4999 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 5000 | } |
| 5001 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5002 | str = sa.getNonConfigurationString( |
| 5003 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5004 | if (str != null) { |
| 5005 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 5006 | } |
| 5007 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5008 | str = sa.getNonConfigurationString( |
| 5009 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | if (str != null) { |
| 5011 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5012 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | sa.recycle(); |
| 5015 | |
| 5016 | if (pa != null) { |
| 5017 | if (outInfo.info.uriPermissionPatterns == null) { |
| 5018 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 5019 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 5020 | } else { |
| 5021 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 5022 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 5023 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 5024 | newp[N] = pa; |
| 5025 | outInfo.info.uriPermissionPatterns = newp; |
| 5026 | } |
| 5027 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5028 | } else { |
| 5029 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5030 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5031 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5032 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5033 | XmlUtils.skipCurrentTag(parser); |
| 5034 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5035 | } else { |
| 5036 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5037 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5038 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5039 | } |
| 5040 | XmlUtils.skipCurrentTag(parser); |
| 5041 | |
| 5042 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5043 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5044 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 5045 | |
| 5046 | PathPermission pa = null; |
| 5047 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5048 | String permission = sa.getNonConfigurationString( |
| 5049 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 5050 | String readPermission = sa.getNonConfigurationString( |
| 5051 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5052 | if (readPermission == null) { |
| 5053 | readPermission = permission; |
| 5054 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5055 | String writePermission = sa.getNonConfigurationString( |
| 5056 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5057 | if (writePermission == null) { |
| 5058 | writePermission = permission; |
| 5059 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5060 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5061 | boolean havePerm = false; |
| 5062 | if (readPermission != null) { |
| 5063 | readPermission = readPermission.intern(); |
| 5064 | havePerm = true; |
| 5065 | } |
| 5066 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 5067 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5068 | havePerm = true; |
| 5069 | } |
| 5070 | |
| 5071 | if (!havePerm) { |
| 5072 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5073 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5074 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5075 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5076 | XmlUtils.skipCurrentTag(parser); |
| 5077 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5078 | } else { |
| 5079 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 5080 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5081 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5082 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5083 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5084 | String path = sa.getNonConfigurationString( |
| 5085 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5086 | if (path != null) { |
| 5087 | pa = new PathPermission(path, |
| 5088 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 5089 | } |
| 5090 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5091 | path = sa.getNonConfigurationString( |
| 5092 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5093 | if (path != null) { |
| 5094 | pa = new PathPermission(path, |
| 5095 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 5096 | } |
| 5097 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5098 | path = sa.getNonConfigurationString( |
| 5099 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5100 | if (path != null) { |
| 5101 | pa = new PathPermission(path, |
| 5102 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 5103 | } |
| 5104 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5105 | path = sa.getNonConfigurationString( |
| 5106 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathAdvancedPattern, 0); |
| 5107 | if (path != null) { |
| 5108 | pa = new PathPermission(path, |
| 5109 | PatternMatcher.PATTERN_ADVANCED_GLOB, readPermission, writePermission); |
| 5110 | } |
| 5111 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5112 | sa.recycle(); |
| 5113 | |
| 5114 | if (pa != null) { |
| 5115 | if (outInfo.info.pathPermissions == null) { |
| 5116 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 5117 | outInfo.info.pathPermissions[0] = pa; |
| 5118 | } else { |
| 5119 | final int N = outInfo.info.pathPermissions.length; |
| 5120 | PathPermission[] newp = new PathPermission[N+1]; |
| 5121 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 5122 | newp[N] = pa; |
| 5123 | outInfo.info.pathPermissions = newp; |
| 5124 | } |
| 5125 | } else { |
| 5126 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5127 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5128 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5129 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5130 | XmlUtils.skipCurrentTag(parser); |
| 5131 | continue; |
| 5132 | } |
| 5133 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5134 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | } |
| 5136 | XmlUtils.skipCurrentTag(parser); |
| 5137 | |
| 5138 | } else { |
| 5139 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5140 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5141 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5142 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5143 | XmlUtils.skipCurrentTag(parser); |
| 5144 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5145 | } else { |
| 5146 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 5147 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5148 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | } |
| 5150 | } |
| 5151 | return true; |
| 5152 | } |
| 5153 | |
| 5154 | private Service parseService(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5155 | XmlResourceParser parser, int flags, String[] outError, |
| 5156 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5157 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5158 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | com.android.internal.R.styleable.AndroidManifestService); |
| 5160 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5161 | if (cachedArgs.mServiceArgs == null) { |
| 5162 | cachedArgs.mServiceArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5163 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 5164 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 5165 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5166 | com.android.internal.R.styleable.AndroidManifestService_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5167 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5168 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5169 | mSeparateProcesses, |
| 5170 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5171 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5172 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5173 | cachedArgs.mServiceArgs.tag = "<service>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5174 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5175 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5176 | cachedArgs.mServiceArgs.sa = sa; |
| 5177 | cachedArgs.mServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5178 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5179 | Service s = new Service(cachedArgs.mServiceArgs, new ServiceInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5180 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5181 | sa.recycle(); |
| 5182 | return null; |
| 5183 | } |
| 5184 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5185 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5186 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 5187 | if (setExported) { |
| 5188 | s.info.exported = sa.getBoolean( |
| 5189 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 5190 | } |
| 5191 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5192 | String str = sa.getNonConfigurationString( |
| 5193 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | if (str == null) { |
| 5195 | s.info.permission = owner.applicationInfo.permission; |
| 5196 | } else { |
| 5197 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 5198 | } |
| 5199 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5200 | s.info.splitName = |
| 5201 | sa.getNonConfigurationString(R.styleable.AndroidManifestService_splitName, 0); |
| 5202 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5203 | s.info.flags = 0; |
| 5204 | if (sa.getBoolean( |
| 5205 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 5206 | false)) { |
| 5207 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 5208 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5209 | if (sa.getBoolean( |
| 5210 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 5211 | false)) { |
| 5212 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 5213 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5214 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 5215 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 5216 | false)) { |
| 5217 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 5218 | } |
| 5219 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5220 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 5221 | false)) { |
| 5222 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5223 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5224 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5225 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 5226 | R.styleable.AndroidManifestService_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5227 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5228 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5229 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5230 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5231 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5232 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5233 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5234 | sa.getBoolean(R.styleable.AndroidManifestService_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5235 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5236 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5237 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5238 | } |
| 5239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | sa.recycle(); |
| 5241 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5242 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5243 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5244 | // A heavy-weight application can not have services in its main process |
| 5245 | // We can do direct compare because we intern all strings. |
| 5246 | if (s.info.processName == owner.packageName) { |
| 5247 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 5248 | return null; |
| 5249 | } |
| 5250 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5252 | int outerDepth = parser.getDepth(); |
| 5253 | int type; |
| 5254 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5255 | && (type != XmlPullParser.END_TAG |
| 5256 | || parser.getDepth() > outerDepth)) { |
| 5257 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5258 | continue; |
| 5259 | } |
| 5260 | |
| 5261 | if (parser.getName().equals("intent-filter")) { |
| 5262 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5263 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5264 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5265 | return null; |
| 5266 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5267 | if (visibleToEphemeral) { |
| 5268 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5269 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5270 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | s.intents.add(intent); |
| 5272 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5273 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | outError)) == null) { |
| 5275 | return null; |
| 5276 | } |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5277 | // we don't have an attribute [or it's false], but, we have meta-data |
| 5278 | if (!visibleToEphemeral && s.metaData.getBoolean(META_DATA_INSTANT_APPS)) { |
| 5279 | visibleToEphemeral = true; // set in case there are more intent filters |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5280 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5281 | owner.visibleToInstantApps = true; |
| 5282 | // cycle through any filters already seen |
| 5283 | for (int i = s.intents.size() - 1; i >= 0; --i) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5284 | s.intents.get(i) |
| 5285 | .setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5286 | } |
| 5287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | } else { |
| 5289 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5290 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5291 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5292 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | XmlUtils.skipCurrentTag(parser); |
| 5294 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5295 | } else { |
| 5296 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 5297 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | if (!setExported) { |
| 5303 | s.info.exported = s.intents.size() > 0; |
| 5304 | } |
| 5305 | |
| 5306 | return s; |
| 5307 | } |
| 5308 | |
Chad Brubaker | 4941483 | 2017-04-13 16:13:23 -0700 | [diff] [blame] | 5309 | private boolean isImplicitlyExposedIntent(IntentInfo intent) { |
| 5310 | return intent.hasCategory(Intent.CATEGORY_BROWSABLE) |
| 5311 | || intent.hasAction(Intent.ACTION_SEND) |
| 5312 | || intent.hasAction(Intent.ACTION_SENDTO) |
| 5313 | || intent.hasAction(Intent.ACTION_SEND_MULTIPLE); |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5314 | } |
| 5315 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5316 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 5317 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | int outerDepth = parser.getDepth(); |
| 5319 | int type; |
| 5320 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5321 | && (type != XmlPullParser.END_TAG |
| 5322 | || parser.getDepth() > outerDepth)) { |
| 5323 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5324 | continue; |
| 5325 | } |
| 5326 | |
| 5327 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5328 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | outInfo.metaData, outError)) == null) { |
| 5330 | return false; |
| 5331 | } |
| 5332 | } else { |
| 5333 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5334 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5335 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5336 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5337 | XmlUtils.skipCurrentTag(parser); |
| 5338 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5339 | } else { |
| 5340 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 5341 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5343 | } |
| 5344 | } |
| 5345 | return true; |
| 5346 | } |
| 5347 | |
| 5348 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5349 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | throws XmlPullParserException, IOException { |
| 5351 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5352 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 5354 | |
| 5355 | if (data == null) { |
| 5356 | data = new Bundle(); |
| 5357 | } |
| 5358 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5359 | String name = sa.getNonConfigurationString( |
| 5360 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5361 | if (name == null) { |
| 5362 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 5363 | sa.recycle(); |
| 5364 | return null; |
| 5365 | } |
| 5366 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 5367 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | TypedValue v = sa.peekValue( |
| 5370 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 5371 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5372 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | data.putInt(name, v.resourceId); |
| 5374 | } else { |
| 5375 | v = sa.peekValue( |
| 5376 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5377 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | if (v != null) { |
| 5379 | if (v.type == TypedValue.TYPE_STRING) { |
| 5380 | CharSequence cs = v.coerceToString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 5381 | data.putString(name, cs != null ? cs.toString() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 5383 | data.putBoolean(name, v.data != 0); |
| 5384 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 5385 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 5386 | data.putInt(name, v.data); |
| 5387 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 5388 | data.putFloat(name, v.getFloat()); |
| 5389 | } else { |
| 5390 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5391 | Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5392 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5393 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | } else { |
| 5395 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 5396 | data = null; |
| 5397 | } |
| 5398 | } |
| 5399 | } else { |
| 5400 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 5401 | data = null; |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | sa.recycle(); |
| 5406 | |
| 5407 | XmlUtils.skipCurrentTag(parser); |
| 5408 | |
| 5409 | return data; |
| 5410 | } |
| 5411 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5412 | private static VerifierInfo parseVerifier(AttributeSet attrs) { |
| 5413 | String packageName = null; |
| 5414 | String encodedPublicKey = null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5415 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5416 | final int attrCount = attrs.getAttributeCount(); |
| 5417 | for (int i = 0; i < attrCount; i++) { |
| 5418 | final int attrResId = attrs.getAttributeNameResource(i); |
| 5419 | switch (attrResId) { |
| 5420 | case com.android.internal.R.attr.name: |
| 5421 | packageName = attrs.getAttributeValue(i); |
| 5422 | break; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5423 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5424 | case com.android.internal.R.attr.publicKey: |
| 5425 | encodedPublicKey = attrs.getAttributeValue(i); |
| 5426 | break; |
| 5427 | } |
| 5428 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5429 | |
| 5430 | if (packageName == null || packageName.length() == 0) { |
| 5431 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 5432 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5433 | } |
| 5434 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5435 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 5436 | if (publicKey == null) { |
| 5437 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 5438 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5439 | } |
| 5440 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5441 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5444 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 5445 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5446 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5447 | return null; |
| 5448 | } |
| 5449 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5450 | EncodedKeySpec keySpec; |
| 5451 | try { |
| 5452 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 5453 | keySpec = new X509EncodedKeySpec(encoded); |
| 5454 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5455 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5456 | return null; |
| 5457 | } |
| 5458 | |
| 5459 | /* First try the key as an RSA key. */ |
| 5460 | try { |
| 5461 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5462 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5463 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5464 | Slog.wtf(TAG, "Could not parse public key: RSA KeyFactory not included in build"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5465 | } catch (InvalidKeySpecException e) { |
| 5466 | // Not a RSA public key. |
| 5467 | } |
| 5468 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5469 | /* Now try it as a ECDSA key. */ |
| 5470 | try { |
| 5471 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 5472 | return keyFactory.generatePublic(keySpec); |
| 5473 | } catch (NoSuchAlgorithmException e) { |
| 5474 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 5475 | } catch (InvalidKeySpecException e) { |
| 5476 | // Not a ECDSA public key. |
| 5477 | } |
| 5478 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5479 | /* Now try it as a DSA key. */ |
| 5480 | try { |
| 5481 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5482 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5483 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5484 | Slog.wtf(TAG, "Could not parse public key: DSA KeyFactory not included in build"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5485 | } catch (InvalidKeySpecException e) { |
| 5486 | // Not a DSA public key. |
| 5487 | } |
| 5488 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5489 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5490 | return null; |
| 5491 | } |
| 5492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | private static final String ANDROID_RESOURCES |
| 5494 | = "http://schemas.android.com/apk/res/android"; |
| 5495 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5496 | private boolean parseIntent(Resources res, XmlResourceParser parser, boolean allowGlobs, |
| 5497 | boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
| 5498 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5500 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 5502 | |
| 5503 | int priority = sa.getInt( |
| 5504 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 5506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | TypedValue v = sa.peekValue( |
| 5508 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 5509 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5510 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5511 | } |
| 5512 | |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 5513 | final boolean useRoundIcon = |
| 5514 | Resources.getSystem().getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 5515 | int roundIconVal = useRoundIcon ? sa.getResourceId( |
| 5516 | com.android.internal.R.styleable.AndroidManifestIntentFilter_roundIcon, 0) : 0; |
| 5517 | if (roundIconVal != 0) { |
| 5518 | outInfo.icon = roundIconVal; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5519 | } else { |
| 5520 | outInfo.icon = sa.getResourceId( |
| 5521 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
| 5522 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5523 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5524 | outInfo.logo = sa.getResourceId( |
| 5525 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5527 | outInfo.banner = sa.getResourceId( |
| 5528 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 5529 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 5530 | if (allowAutoVerify) { |
| 5531 | outInfo.setAutoVerify(sa.getBoolean( |
| 5532 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 5533 | false)); |
| 5534 | } |
| 5535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5536 | sa.recycle(); |
| 5537 | |
| 5538 | int outerDepth = parser.getDepth(); |
| 5539 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5540 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5541 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5542 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | continue; |
| 5544 | } |
| 5545 | |
| 5546 | String nodeName = parser.getName(); |
| 5547 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5548 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | ANDROID_RESOURCES, "name"); |
| 5550 | if (value == null || value == "") { |
| 5551 | outError[0] = "No value supplied for <android:name>"; |
| 5552 | return false; |
| 5553 | } |
| 5554 | XmlUtils.skipCurrentTag(parser); |
| 5555 | |
| 5556 | outInfo.addAction(value); |
| 5557 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5558 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | ANDROID_RESOURCES, "name"); |
| 5560 | if (value == null || value == "") { |
| 5561 | outError[0] = "No value supplied for <android:name>"; |
| 5562 | return false; |
| 5563 | } |
| 5564 | XmlUtils.skipCurrentTag(parser); |
| 5565 | |
| 5566 | outInfo.addCategory(value); |
| 5567 | |
| 5568 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5569 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | com.android.internal.R.styleable.AndroidManifestData); |
| 5571 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5572 | String str = sa.getNonConfigurationString( |
| 5573 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | if (str != null) { |
| 5575 | try { |
| 5576 | outInfo.addDataType(str); |
| 5577 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 5578 | outError[0] = e.toString(); |
| 5579 | sa.recycle(); |
| 5580 | return false; |
| 5581 | } |
| 5582 | } |
| 5583 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5584 | str = sa.getNonConfigurationString( |
| 5585 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5586 | if (str != null) { |
| 5587 | outInfo.addDataScheme(str); |
| 5588 | } |
| 5589 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5590 | str = sa.getNonConfigurationString( |
| 5591 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 5592 | if (str != null) { |
| 5593 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 5594 | } |
| 5595 | |
| 5596 | str = sa.getNonConfigurationString( |
| 5597 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 5598 | if (str != null) { |
| 5599 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 5600 | } |
| 5601 | |
| 5602 | str = sa.getNonConfigurationString( |
| 5603 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 5604 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5605 | if (!allowGlobs) { |
| 5606 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 5607 | return false; |
| 5608 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5609 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5610 | } |
| 5611 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5612 | String host = sa.getNonConfigurationString( |
| 5613 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 5614 | String port = sa.getNonConfigurationString( |
| 5615 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | if (host != null) { |
| 5617 | outInfo.addDataAuthority(host, port); |
| 5618 | } |
| 5619 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5620 | str = sa.getNonConfigurationString( |
| 5621 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | if (str != null) { |
| 5623 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 5624 | } |
| 5625 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5626 | str = sa.getNonConfigurationString( |
| 5627 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5628 | if (str != null) { |
| 5629 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 5630 | } |
| 5631 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5632 | str = sa.getNonConfigurationString( |
| 5633 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5635 | if (!allowGlobs) { |
| 5636 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 5637 | return false; |
| 5638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5640 | } |
| 5641 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5642 | str = sa.getNonConfigurationString( |
| 5643 | com.android.internal.R.styleable.AndroidManifestData_pathAdvancedPattern, 0); |
| 5644 | if (str != null) { |
| 5645 | if (!allowGlobs) { |
| 5646 | outError[0] = "pathAdvancedPattern not allowed here; path must be literal"; |
| 5647 | return false; |
| 5648 | } |
| 5649 | outInfo.addDataPath(str, PatternMatcher.PATTERN_ADVANCED_GLOB); |
| 5650 | } |
| 5651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5652 | sa.recycle(); |
| 5653 | XmlUtils.skipCurrentTag(parser); |
| 5654 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5655 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5656 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5657 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | XmlUtils.skipCurrentTag(parser); |
| 5659 | } else { |
| 5660 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 5661 | return false; |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5666 | |
| 5667 | if (DEBUG_PARSER) { |
| 5668 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 5669 | cats.append(outInfo.hasDefault); |
| 5670 | cats.append(", cat="); |
| 5671 | |
| 5672 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 5673 | if (it != null) { |
| 5674 | while (it.hasNext()) { |
| 5675 | cats.append(' '); |
| 5676 | cats.append(it.next()); |
| 5677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5678 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5679 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | return true; |
| 5683 | } |
| 5684 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5685 | /** A container for signing-related data of an application package. */ |
| 5686 | public static final class SigningDetails implements Parcelable { |
| 5687 | |
| 5688 | @IntDef({SigningDetails.SignatureSchemeVersion.UNKNOWN, |
| 5689 | SigningDetails.SignatureSchemeVersion.JAR, |
| 5690 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2, |
| 5691 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V3}) |
| 5692 | public @interface SignatureSchemeVersion { |
| 5693 | int UNKNOWN = 0; |
| 5694 | int JAR = 1; |
| 5695 | int SIGNING_BLOCK_V2 = 2; |
| 5696 | int SIGNING_BLOCK_V3 = 3; |
| 5697 | } |
| 5698 | |
| 5699 | @Nullable |
| 5700 | public final Signature[] signatures; |
| 5701 | @SignatureSchemeVersion |
| 5702 | public final int signatureSchemeVersion; |
| 5703 | @Nullable |
| 5704 | public final ArraySet<PublicKey> publicKeys; |
| 5705 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5706 | /** |
| 5707 | * Collection of {@code Signature} objects, each of which is formed from a former signing |
| 5708 | * certificate of this APK before it was changed by signing certificate rotation. |
| 5709 | */ |
| 5710 | @Nullable |
| 5711 | public final Signature[] pastSigningCertificates; |
| 5712 | |
| 5713 | /** |
| 5714 | * Flags for the {@code pastSigningCertificates} collection, which indicate the capabilities |
| 5715 | * the including APK wishes to grant to its past signing certificates. |
| 5716 | */ |
| 5717 | @Nullable |
| 5718 | public final int[] pastSigningCertificatesFlags; |
| 5719 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5720 | /** A representation of unknown signing details. Use instead of null. */ |
| 5721 | public static final SigningDetails UNKNOWN = |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5722 | new SigningDetails(null, SignatureSchemeVersion.UNKNOWN, null, null, null); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5723 | |
| 5724 | @VisibleForTesting |
| 5725 | public SigningDetails(Signature[] signatures, |
| 5726 | @SignatureSchemeVersion int signatureSchemeVersion, |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5727 | ArraySet<PublicKey> keys, Signature[] pastSigningCertificates, |
| 5728 | int[] pastSigningCertificatesFlags) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5729 | this.signatures = signatures; |
| 5730 | this.signatureSchemeVersion = signatureSchemeVersion; |
| 5731 | this.publicKeys = keys; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5732 | this.pastSigningCertificates = pastSigningCertificates; |
| 5733 | this.pastSigningCertificatesFlags = pastSigningCertificatesFlags; |
| 5734 | } |
| 5735 | |
| 5736 | public SigningDetails(Signature[] signatures, |
| 5737 | @SignatureSchemeVersion int signatureSchemeVersion, |
| 5738 | Signature[] pastSigningCertificates, int[] pastSigningCertificatesFlags) |
| 5739 | throws CertificateException { |
| 5740 | this(signatures, signatureSchemeVersion, toSigningKeys(signatures), |
| 5741 | pastSigningCertificates, pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | public SigningDetails(Signature[] signatures, |
| 5745 | @SignatureSchemeVersion int signatureSchemeVersion) |
| 5746 | throws CertificateException { |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5747 | this(signatures, signatureSchemeVersion, |
| 5748 | null, null); |
| 5749 | } |
| 5750 | |
| 5751 | public SigningDetails(SigningDetails orig) { |
| 5752 | if (orig != null) { |
| 5753 | if (orig.signatures != null) { |
| 5754 | this.signatures = orig.signatures.clone(); |
| 5755 | } else { |
| 5756 | this.signatures = null; |
| 5757 | } |
| 5758 | this.signatureSchemeVersion = orig.signatureSchemeVersion; |
| 5759 | this.publicKeys = new ArraySet<>(orig.publicKeys); |
| 5760 | if (orig.pastSigningCertificates != null) { |
| 5761 | this.pastSigningCertificates = orig.pastSigningCertificates.clone(); |
| 5762 | this.pastSigningCertificatesFlags = orig.pastSigningCertificatesFlags.clone(); |
| 5763 | } else { |
| 5764 | this.pastSigningCertificates = null; |
| 5765 | this.pastSigningCertificatesFlags = null; |
| 5766 | } |
| 5767 | } else { |
| 5768 | this.signatures = null; |
| 5769 | this.signatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 5770 | this.publicKeys = null; |
| 5771 | this.pastSigningCertificates = null; |
| 5772 | this.pastSigningCertificatesFlags = null; |
| 5773 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | /** Returns true if the signing details have one or more signatures. */ |
| 5777 | public boolean hasSignatures() { |
| 5778 | return signatures != null && signatures.length > 0; |
| 5779 | } |
| 5780 | |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 5781 | /** Returns true if the signing details have past signing certificates. */ |
| 5782 | public boolean hasPastSigningCertificates() { |
| 5783 | return pastSigningCertificates != null && pastSigningCertificates.length > 0; |
| 5784 | } |
| 5785 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5786 | /** Returns true if the signatures in this and other match exactly. */ |
| 5787 | public boolean signaturesMatchExactly(SigningDetails other) { |
| 5788 | return Signature.areExactMatch(this.signatures, other.signatures); |
| 5789 | } |
| 5790 | |
| 5791 | @Override |
| 5792 | public int describeContents() { |
| 5793 | return 0; |
| 5794 | } |
| 5795 | |
| 5796 | @Override |
| 5797 | public void writeToParcel(Parcel dest, int flags) { |
| 5798 | boolean isUnknown = UNKNOWN == this; |
| 5799 | dest.writeBoolean(isUnknown); |
| 5800 | if (isUnknown) { |
| 5801 | return; |
| 5802 | } |
| 5803 | dest.writeTypedArray(this.signatures, flags); |
| 5804 | dest.writeInt(this.signatureSchemeVersion); |
| 5805 | dest.writeArraySet(this.publicKeys); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5806 | dest.writeTypedArray(this.pastSigningCertificates, flags); |
| 5807 | dest.writeIntArray(this.pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | protected SigningDetails(Parcel in) { |
| 5811 | final ClassLoader boot = Object.class.getClassLoader(); |
| 5812 | this.signatures = in.createTypedArray(Signature.CREATOR); |
| 5813 | this.signatureSchemeVersion = in.readInt(); |
| 5814 | this.publicKeys = (ArraySet<PublicKey>) in.readArraySet(boot); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5815 | this.pastSigningCertificates = in.createTypedArray(Signature.CREATOR); |
| 5816 | this.pastSigningCertificatesFlags = in.createIntArray(); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | public static final Creator<SigningDetails> CREATOR = new Creator<SigningDetails>() { |
| 5820 | @Override |
| 5821 | public SigningDetails createFromParcel(Parcel source) { |
| 5822 | if (source.readBoolean()) { |
| 5823 | return UNKNOWN; |
| 5824 | } |
| 5825 | return new SigningDetails(source); |
| 5826 | } |
| 5827 | |
| 5828 | @Override |
| 5829 | public SigningDetails[] newArray(int size) { |
| 5830 | return new SigningDetails[size]; |
| 5831 | } |
| 5832 | }; |
| 5833 | |
| 5834 | @Override |
| 5835 | public boolean equals(Object o) { |
| 5836 | if (this == o) return true; |
| 5837 | if (!(o instanceof SigningDetails)) return false; |
| 5838 | |
| 5839 | SigningDetails that = (SigningDetails) o; |
| 5840 | |
| 5841 | if (signatureSchemeVersion != that.signatureSchemeVersion) return false; |
| 5842 | if (!Signature.areExactMatch(signatures, that.signatures)) return false; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5843 | if (publicKeys != null) { |
| 5844 | if (!publicKeys.equals((that.publicKeys))) { |
| 5845 | return false; |
| 5846 | } |
| 5847 | } else if (that.publicKeys != null) { |
| 5848 | return false; |
| 5849 | } |
| 5850 | |
| 5851 | // can't use Signature.areExactMatch() because order matters with the past signing certs |
| 5852 | if (!Arrays.equals(pastSigningCertificates, that.pastSigningCertificates)) { |
| 5853 | return false; |
| 5854 | } |
| 5855 | if (!Arrays.equals(pastSigningCertificatesFlags, that.pastSigningCertificatesFlags)) { |
| 5856 | return false; |
| 5857 | } |
| 5858 | |
| 5859 | return true; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | @Override |
| 5863 | public int hashCode() { |
| 5864 | int result = +Arrays.hashCode(signatures); |
| 5865 | result = 31 * result + signatureSchemeVersion; |
| 5866 | result = 31 * result + (publicKeys != null ? publicKeys.hashCode() : 0); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5867 | result = 31 * result + Arrays.hashCode(pastSigningCertificates); |
| 5868 | result = 31 * result + Arrays.hashCode(pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5869 | return result; |
| 5870 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5871 | |
| 5872 | /** |
| 5873 | * Builder of {@code SigningDetails} instances. |
| 5874 | */ |
| 5875 | public static class Builder { |
| 5876 | private Signature[] mSignatures; |
| 5877 | private int mSignatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 5878 | private Signature[] mPastSigningCertificates; |
| 5879 | private int[] mPastSigningCertificatesFlags; |
| 5880 | |
| 5881 | public Builder() { |
| 5882 | } |
| 5883 | |
| 5884 | /** get signing certificates used to sign the current APK */ |
| 5885 | public Builder setSignatures(Signature[] signatures) { |
| 5886 | mSignatures = signatures; |
| 5887 | return this; |
| 5888 | } |
| 5889 | |
| 5890 | /** set the signature scheme version used to sign the APK */ |
| 5891 | public Builder setSignatureSchemeVersion(int signatureSchemeVersion) { |
| 5892 | mSignatureSchemeVersion = signatureSchemeVersion; |
| 5893 | return this; |
| 5894 | } |
| 5895 | |
| 5896 | /** set the signing certificates by which the APK proved it can be authenticated */ |
| 5897 | public Builder setPastSigningCertificates(Signature[] pastSigningCertificates) { |
| 5898 | mPastSigningCertificates = pastSigningCertificates; |
| 5899 | return this; |
| 5900 | } |
| 5901 | |
| 5902 | /** set the flags for the {@code pastSigningCertificates} */ |
| 5903 | public Builder setPastSigningCertificatesFlags(int[] pastSigningCertificatesFlags) { |
| 5904 | mPastSigningCertificatesFlags = pastSigningCertificatesFlags; |
| 5905 | return this; |
| 5906 | } |
| 5907 | |
| 5908 | private void checkInvariants() { |
| 5909 | // must have signatures and scheme version set |
| 5910 | if (mSignatures == null) { |
| 5911 | throw new IllegalStateException("SigningDetails requires the current signing" |
| 5912 | + " certificates."); |
| 5913 | } |
| 5914 | |
| 5915 | // pastSigningCerts and flags must match up |
| 5916 | boolean pastMismatch = false; |
| 5917 | if (mPastSigningCertificates != null && mPastSigningCertificatesFlags != null) { |
| 5918 | if (mPastSigningCertificates.length != mPastSigningCertificatesFlags.length) { |
| 5919 | pastMismatch = true; |
| 5920 | } |
| 5921 | } else if (!(mPastSigningCertificates == null |
| 5922 | && mPastSigningCertificatesFlags == null)) { |
| 5923 | pastMismatch = true; |
| 5924 | } |
| 5925 | if (pastMismatch) { |
| 5926 | throw new IllegalStateException("SigningDetails must have a one to one mapping " |
| 5927 | + "between pastSigningCertificates and pastSigningCertificatesFlags"); |
| 5928 | } |
| 5929 | } |
| 5930 | /** build a {@code SigningDetails} object */ |
| 5931 | public SigningDetails build() |
| 5932 | throws CertificateException { |
| 5933 | checkInvariants(); |
| 5934 | return new SigningDetails(mSignatures, mSignatureSchemeVersion, |
| 5935 | mPastSigningCertificates, mPastSigningCertificatesFlags); |
| 5936 | } |
| 5937 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5938 | } |
| 5939 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 5940 | /** |
| 5941 | * Representation of a full package parsed from APK files on disk. A package |
| 5942 | * consists of a single base APK, and zero or more split APKs. |
| 5943 | */ |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 5944 | public final static class Package implements Parcelable { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 5945 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5946 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 5947 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 5948 | // The package name declared in the manifest as the package can be |
| 5949 | // renamed, for example static shared libs use synthetic package names. |
| 5950 | public String manifestPackageName; |
| 5951 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 5952 | /** Names of any split APKs, ordered by parsed splitName */ |
| 5953 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 5954 | |
| 5955 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 5956 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 5957 | public String volumeUuid; |
| 5958 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 5959 | /** |
| 5960 | * Path where this package was found on disk. For monolithic packages |
| 5961 | * this is path to single base APK file; for cluster packages this is |
| 5962 | * path to the cluster directory. |
| 5963 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 5964 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 5965 | |
| 5966 | /** Path of base APK */ |
| 5967 | public String baseCodePath; |
| 5968 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 5969 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 5971 | /** Revision code of base APK */ |
| 5972 | public int baseRevisionCode; |
| 5973 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 5974 | public int[] splitRevisionCodes; |
| 5975 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 5976 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 5977 | public int[] splitFlags; |
| 5978 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5979 | /** |
| 5980 | * Private flags of any split APKs; ordered by parsed splitName. |
| 5981 | * |
| 5982 | * {@hide} |
| 5983 | */ |
| 5984 | public int[] splitPrivateFlags; |
| 5985 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 5986 | public boolean baseHardwareAccelerated; |
| 5987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5988 | // For now we only support one application per package. |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 5989 | public ApplicationInfo applicationInfo = new ApplicationInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | |
| 5991 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 5992 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 5993 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 5994 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 5995 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 5996 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 5997 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 5998 | |
| 5999 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 6000 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 6001 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6002 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6003 | public Package parentPackage; |
| 6004 | public ArrayList<Package> childPackages; |
| 6005 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6006 | public String staticSharedLibName = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6007 | public long staticSharedLibVersion = 0; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6008 | public ArrayList<String> libraryNames = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6009 | public ArrayList<String> usesLibraries = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6010 | public ArrayList<String> usesStaticLibraries = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6011 | public long[] usesStaticLibrariesVersions = null; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6012 | public String[][] usesStaticLibrariesCertDigests = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6013 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | public String[] usesLibraryFiles = null; |
| 6015 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 6016 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 6017 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 6018 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6019 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 6020 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | // We store the application meta-data independently to avoid multiple unwanted references |
| 6023 | public Bundle mAppMetaData = null; |
| 6024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | // The version code declared for this package. |
| 6026 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6027 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6028 | // The major version code declared for this package. |
| 6029 | public int mVersionCodeMajor; |
| 6030 | |
| 6031 | // Return long containing mVersionCode and mVersionCodeMajor. |
| 6032 | public long getLongVersionCode() { |
| 6033 | return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); |
| 6034 | } |
| 6035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | // The version name declared for this package. |
| 6037 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | // The shared user id that this package wants to use. |
| 6040 | public String mSharedUserId; |
| 6041 | |
| 6042 | // The shared user label that this package wants to use. |
| 6043 | public int mSharedUserLabel; |
| 6044 | |
| 6045 | // Signatures that were read from the package. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6046 | @NonNull public SigningDetails mSigningDetails = SigningDetails.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6047 | |
| 6048 | // For use by package manager service for quick lookup of |
| 6049 | // preferred up order. |
| 6050 | public int mPreferredOrder = 0; |
| 6051 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6052 | // For use by package manager to keep track of when a package was last used. |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 6053 | public long[] mLastPackageUsageTimeInMills = |
| 6054 | new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6055 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 6056 | // // User set enabled state. |
| 6057 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 6058 | // |
| 6059 | // // Whether the package has been stopped. |
| 6060 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 6061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6062 | // Additional data supplied by callers. |
| 6063 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 6064 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6065 | // Applications hardware preferences |
| 6066 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6068 | // Applications requested features |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6069 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 6070 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 6071 | // Applications requested feature groups |
| 6072 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 6073 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 6074 | public int installLocation; |
| 6075 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 6076 | public boolean coreApp; |
| 6077 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 6078 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 6079 | public boolean mRequiredForAllUsers; |
| 6080 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6081 | /* The restricted account authenticator type that is used by this application */ |
| 6082 | public String mRestrictedAccountType; |
| 6083 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 6084 | /* The required account type without which this application will not function */ |
| 6085 | public String mRequiredAccountType; |
| 6086 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6087 | public String mOverlayTarget; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6088 | public int mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6089 | public boolean mOverlayIsStatic; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6090 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6091 | public int mCompileSdkVersion; |
| 6092 | public String mCompileSdkVersionCodename; |
| 6093 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6094 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6095 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6096 | */ |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6097 | public ArraySet<String> mUpgradeKeySets; |
| 6098 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6099 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6100 | /** |
| 6101 | * The install time abi override for this package, if any. |
| 6102 | * |
| 6103 | * TODO: This seems like a horrible place to put the abiOverride because |
| 6104 | * this isn't something the packageParser parsers. However, this fits in with |
| 6105 | * the rest of the PackageManager where package scanning randomly pushes |
| 6106 | * and prods fields out of {@code this.applicationInfo}. |
| 6107 | */ |
| 6108 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6109 | /** |
| 6110 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 6111 | * are present. This is only meaningfull for multiarch applications. |
| 6112 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 6113 | */ |
| 6114 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6115 | |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 6116 | public byte[] restrictUpdateHash; |
| 6117 | |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6118 | /** Set if the app or any of its components are visible to instant applications. */ |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 6119 | public boolean visibleToInstantApps; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6120 | /** Whether or not the package is a stub and must be replaced by the full version. */ |
| 6121 | public boolean isStub; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 6122 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6123 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6124 | this.packageName = packageName; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6125 | this.manifestPackageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6126 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | applicationInfo.uid = -1; |
| 6128 | } |
| 6129 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6130 | public void setApplicationVolumeUuid(String volumeUuid) { |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6131 | final UUID storageUuid = StorageManager.convert(volumeUuid); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6132 | this.applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6133 | this.applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6134 | if (childPackages != null) { |
| 6135 | final int packageCount = childPackages.size(); |
| 6136 | for (int i = 0; i < packageCount; i++) { |
| 6137 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6138 | childPackages.get(i).applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | public void setApplicationInfoCodePath(String codePath) { |
| 6144 | this.applicationInfo.setCodePath(codePath); |
| 6145 | if (childPackages != null) { |
| 6146 | final int packageCount = childPackages.size(); |
| 6147 | for (int i = 0; i < packageCount; i++) { |
| 6148 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 6149 | } |
| 6150 | } |
| 6151 | } |
| 6152 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6153 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6154 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6155 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 6156 | this.applicationInfo.setResourcePath(resourcePath); |
| 6157 | if (childPackages != null) { |
| 6158 | final int packageCount = childPackages.size(); |
| 6159 | for (int i = 0; i < packageCount; i++) { |
| 6160 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 6161 | } |
| 6162 | } |
| 6163 | } |
| 6164 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6165 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6166 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6167 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 6168 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 6169 | if (childPackages != null) { |
| 6170 | final int packageCount = childPackages.size(); |
| 6171 | for (int i = 0; i < packageCount; i++) { |
| 6172 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 6173 | } |
| 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 6178 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 6179 | if (childPackages != null) { |
| 6180 | final int packageCount = childPackages.size(); |
| 6181 | for (int i = 0; i < packageCount; i++) { |
| 6182 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 6183 | } |
| 6184 | } |
| 6185 | } |
| 6186 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 6187 | public List<String> getChildPackageNames() { |
| 6188 | if (childPackages == null) { |
| 6189 | return null; |
| 6190 | } |
| 6191 | final int childCount = childPackages.size(); |
| 6192 | final List<String> childPackageNames = new ArrayList<>(childCount); |
| 6193 | for (int i = 0; i < childCount; i++) { |
| 6194 | String childPackageName = childPackages.get(i).packageName; |
| 6195 | childPackageNames.add(childPackageName); |
| 6196 | } |
| 6197 | return childPackageNames; |
| 6198 | } |
| 6199 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6200 | public boolean hasChildPackage(String packageName) { |
| 6201 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 6202 | for (int i = 0; i < childCount; i++) { |
| 6203 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 6204 | return true; |
| 6205 | } |
| 6206 | } |
| 6207 | return false; |
| 6208 | } |
| 6209 | |
| 6210 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 6211 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 6212 | // Children have no splits |
| 6213 | } |
| 6214 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6215 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6216 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6217 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 6218 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 6219 | // Children have no splits |
| 6220 | } |
| 6221 | |
| 6222 | public void setSplitCodePaths(String[] codePaths) { |
| 6223 | this.splitCodePaths = codePaths; |
| 6224 | } |
| 6225 | |
| 6226 | public void setCodePath(String codePath) { |
| 6227 | this.codePath = codePath; |
| 6228 | if (childPackages != null) { |
| 6229 | final int packageCount = childPackages.size(); |
| 6230 | for (int i = 0; i < packageCount; i++) { |
| 6231 | childPackages.get(i).codePath = codePath; |
| 6232 | } |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | public void setBaseCodePath(String baseCodePath) { |
| 6237 | this.baseCodePath = baseCodePath; |
| 6238 | if (childPackages != null) { |
| 6239 | final int packageCount = childPackages.size(); |
| 6240 | for (int i = 0; i < packageCount; i++) { |
| 6241 | childPackages.get(i).baseCodePath = baseCodePath; |
| 6242 | } |
| 6243 | } |
| 6244 | } |
| 6245 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6246 | /** Sets signing details on the package and any of its children. */ |
| 6247 | public void setSigningDetails(@NonNull SigningDetails signingDetails) { |
| 6248 | mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6249 | if (childPackages != null) { |
| 6250 | final int packageCount = childPackages.size(); |
| 6251 | for (int i = 0; i < packageCount; i++) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6252 | childPackages.get(i).mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | public void setVolumeUuid(String volumeUuid) { |
| 6258 | this.volumeUuid = volumeUuid; |
| 6259 | if (childPackages != null) { |
| 6260 | final int packageCount = childPackages.size(); |
| 6261 | for (int i = 0; i < packageCount; i++) { |
| 6262 | childPackages.get(i).volumeUuid = volumeUuid; |
| 6263 | } |
| 6264 | } |
| 6265 | } |
| 6266 | |
| 6267 | public void setApplicationInfoFlags(int mask, int flags) { |
| 6268 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 6269 | if (childPackages != null) { |
| 6270 | final int packageCount = childPackages.size(); |
| 6271 | for (int i = 0; i < packageCount; i++) { |
| 6272 | childPackages.get(i).applicationInfo.flags = |
| 6273 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 6274 | } |
| 6275 | } |
| 6276 | } |
| 6277 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 6278 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6279 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6280 | if (childPackages != null) { |
| 6281 | final int packageCount = childPackages.size(); |
| 6282 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6283 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6284 | } |
| 6285 | } |
| 6286 | } |
| 6287 | |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 6288 | public boolean isLibrary() { |
| 6289 | return staticSharedLibName != null || !ArrayUtils.isEmpty(libraryNames); |
| 6290 | } |
| 6291 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6292 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6293 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6294 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6295 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6296 | Collections.addAll(paths, splitCodePaths); |
| 6297 | } |
| 6298 | return paths; |
| 6299 | } |
| 6300 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6301 | /** |
| 6302 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 6303 | * resource-only APKs. |
| 6304 | */ |
| 6305 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 6306 | ArrayList<String> paths = new ArrayList<>(); |
| 6307 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6308 | paths.add(baseCodePath); |
| 6309 | } |
| 6310 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6311 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 6312 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6313 | paths.add(splitCodePaths[i]); |
| 6314 | } |
| 6315 | } |
| 6316 | } |
| 6317 | return paths; |
| 6318 | } |
| 6319 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6320 | public void setPackageName(String newName) { |
| 6321 | packageName = newName; |
| 6322 | applicationInfo.packageName = newName; |
| 6323 | for (int i=permissions.size()-1; i>=0; i--) { |
| 6324 | permissions.get(i).setPackageName(newName); |
| 6325 | } |
| 6326 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 6327 | permissionGroups.get(i).setPackageName(newName); |
| 6328 | } |
| 6329 | for (int i=activities.size()-1; i>=0; i--) { |
| 6330 | activities.get(i).setPackageName(newName); |
| 6331 | } |
| 6332 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6333 | receivers.get(i).setPackageName(newName); |
| 6334 | } |
| 6335 | for (int i=providers.size()-1; i>=0; i--) { |
| 6336 | providers.get(i).setPackageName(newName); |
| 6337 | } |
| 6338 | for (int i=services.size()-1; i>=0; i--) { |
| 6339 | services.get(i).setPackageName(newName); |
| 6340 | } |
| 6341 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6342 | instrumentation.get(i).setPackageName(newName); |
| 6343 | } |
| 6344 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 6345 | |
| 6346 | public boolean hasComponentClassName(String name) { |
| 6347 | for (int i=activities.size()-1; i>=0; i--) { |
| 6348 | if (name.equals(activities.get(i).className)) { |
| 6349 | return true; |
| 6350 | } |
| 6351 | } |
| 6352 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6353 | if (name.equals(receivers.get(i).className)) { |
| 6354 | return true; |
| 6355 | } |
| 6356 | } |
| 6357 | for (int i=providers.size()-1; i>=0; i--) { |
| 6358 | if (name.equals(providers.get(i).className)) { |
| 6359 | return true; |
| 6360 | } |
| 6361 | } |
| 6362 | for (int i=services.size()-1; i>=0; i--) { |
| 6363 | if (name.equals(services.get(i).className)) { |
| 6364 | return true; |
| 6365 | } |
| 6366 | } |
| 6367 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6368 | if (name.equals(instrumentation.get(i).className)) { |
| 6369 | return true; |
| 6370 | } |
| 6371 | } |
| 6372 | return false; |
| 6373 | } |
| 6374 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6375 | /** @hide */ |
| 6376 | public boolean isExternal() { |
| 6377 | return applicationInfo.isExternal(); |
| 6378 | } |
| 6379 | |
| 6380 | /** @hide */ |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6381 | public boolean isForwardLocked() { |
| 6382 | return applicationInfo.isForwardLocked(); |
| 6383 | } |
| 6384 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6385 | /** @hide */ |
| 6386 | public boolean isOem() { |
| 6387 | return applicationInfo.isOem(); |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6388 | } |
| 6389 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6390 | /** @hide */ |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 6391 | public boolean isVendor() { |
| 6392 | return applicationInfo.isVendor(); |
| 6393 | } |
| 6394 | |
| 6395 | /** @hide */ |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6396 | public boolean isPrivileged() { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 6397 | return applicationInfo.isPrivilegedApp(); |
| 6398 | } |
| 6399 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6400 | /** @hide */ |
| 6401 | public boolean isSystem() { |
| 6402 | return applicationInfo.isSystemApp(); |
| 6403 | } |
| 6404 | |
| 6405 | /** @hide */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6406 | public boolean isUpdatedSystemApp() { |
| 6407 | return applicationInfo.isUpdatedSystemApp(); |
| 6408 | } |
| 6409 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6410 | /** @hide */ |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6411 | public boolean canHaveOatDir() { |
| 6412 | // The following app types CANNOT have oat directory |
| 6413 | // - non-updated system apps |
| 6414 | // - forward-locked apps or apps installed in ASEC containers |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6415 | return (!isSystem() || isUpdatedSystemApp()) |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6416 | && !isForwardLocked() && !applicationInfo.isExternalAsec(); |
| 6417 | } |
| 6418 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6419 | public boolean isMatch(int flags) { |
| 6420 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6421 | return isSystem(); |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6422 | } |
| 6423 | return true; |
| 6424 | } |
| 6425 | |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 6426 | public long getLatestPackageUseTimeInMills() { |
| 6427 | long latestUse = 0L; |
| 6428 | for (long use : mLastPackageUsageTimeInMills) { |
| 6429 | latestUse = Math.max(latestUse, use); |
| 6430 | } |
| 6431 | return latestUse; |
| 6432 | } |
| 6433 | |
David Brazdil | 90e2699 | 2016-04-18 14:08:52 +0100 | [diff] [blame] | 6434 | public long getLatestForegroundPackageUseTimeInMills() { |
| 6435 | int[] foregroundReasons = { |
| 6436 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, |
| 6437 | PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE |
| 6438 | }; |
| 6439 | |
| 6440 | long latestUse = 0L; |
| 6441 | for (int reason : foregroundReasons) { |
| 6442 | latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); |
| 6443 | } |
| 6444 | return latestUse; |
| 6445 | } |
| 6446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | public String toString() { |
| 6448 | return "Package{" |
| 6449 | + Integer.toHexString(System.identityHashCode(this)) |
| 6450 | + " " + packageName + "}"; |
| 6451 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6452 | |
Todd Kennedy | f996b76 | 2018-01-12 15:03:29 -0800 | [diff] [blame] | 6453 | public String dumpState_temp() { |
| 6454 | String flags = ""; |
| 6455 | flags += ((applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 ? "U" : ""); |
| 6456 | flags += ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? "S" : ""); |
| 6457 | if ("".equals(flags)) { |
| 6458 | flags = "-"; |
| 6459 | } |
| 6460 | String privFlags = ""; |
| 6461 | privFlags += ((applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0 ? "P" : ""); |
| 6462 | privFlags += ((applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0 ? "O" : ""); |
| 6463 | privFlags += ((applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0 ? "V" : ""); |
| 6464 | if ("".equals(privFlags)) { |
| 6465 | privFlags = "-"; |
| 6466 | } |
| 6467 | return "Package{" |
| 6468 | + Integer.toHexString(System.identityHashCode(this)) |
| 6469 | + " " + packageName |
| 6470 | + ", ver:" + getLongVersionCode() |
| 6471 | + ", path: " + codePath |
| 6472 | + ", flags: " + flags |
| 6473 | + ", privFlags: " + privFlags |
| 6474 | + ", extra: " + (mExtras == null ? "<<NULL>>" : Integer.toHexString(System.identityHashCode(mExtras)) + "}") |
| 6475 | + "}"; |
| 6476 | } |
| 6477 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6478 | @Override |
| 6479 | public int describeContents() { |
| 6480 | return 0; |
| 6481 | } |
| 6482 | |
| 6483 | public Package(Parcel dest) { |
| 6484 | // We use the boot classloader for all classes that we load. |
| 6485 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6486 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6487 | packageName = dest.readString().intern(); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6488 | manifestPackageName = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6489 | splitNames = dest.readStringArray(); |
| 6490 | volumeUuid = dest.readString(); |
| 6491 | codePath = dest.readString(); |
| 6492 | baseCodePath = dest.readString(); |
| 6493 | splitCodePaths = dest.readStringArray(); |
| 6494 | baseRevisionCode = dest.readInt(); |
| 6495 | splitRevisionCodes = dest.createIntArray(); |
| 6496 | splitFlags = dest.createIntArray(); |
| 6497 | splitPrivateFlags = dest.createIntArray(); |
| 6498 | baseHardwareAccelerated = (dest.readInt() == 1); |
| 6499 | applicationInfo = dest.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6500 | if (applicationInfo.permission != null) { |
| 6501 | applicationInfo.permission = applicationInfo.permission.intern(); |
| 6502 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6503 | |
| 6504 | // We don't serialize the "owner" package and the application info object for each of |
| 6505 | // these components, in order to save space and to avoid circular dependencies while |
| 6506 | // serialization. We need to fix them all up here. |
| 6507 | dest.readParcelableList(permissions, boot); |
| 6508 | fixupOwner(permissions); |
| 6509 | dest.readParcelableList(permissionGroups, boot); |
| 6510 | fixupOwner(permissionGroups); |
| 6511 | dest.readParcelableList(activities, boot); |
| 6512 | fixupOwner(activities); |
| 6513 | dest.readParcelableList(receivers, boot); |
| 6514 | fixupOwner(receivers); |
| 6515 | dest.readParcelableList(providers, boot); |
| 6516 | fixupOwner(providers); |
| 6517 | dest.readParcelableList(services, boot); |
| 6518 | fixupOwner(services); |
| 6519 | dest.readParcelableList(instrumentation, boot); |
| 6520 | fixupOwner(instrumentation); |
| 6521 | |
| 6522 | dest.readStringList(requestedPermissions); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6523 | internStringArrayList(requestedPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6524 | protectedBroadcasts = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6525 | internStringArrayList(protectedBroadcasts); |
| 6526 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6527 | parentPackage = dest.readParcelable(boot); |
| 6528 | |
| 6529 | childPackages = new ArrayList<>(); |
| 6530 | dest.readParcelableList(childPackages, boot); |
| 6531 | if (childPackages.size() == 0) { |
| 6532 | childPackages = null; |
| 6533 | } |
| 6534 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6535 | staticSharedLibName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6536 | if (staticSharedLibName != null) { |
| 6537 | staticSharedLibName = staticSharedLibName.intern(); |
| 6538 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6539 | staticSharedLibVersion = dest.readLong(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6540 | libraryNames = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6541 | internStringArrayList(libraryNames); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6542 | usesLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6543 | internStringArrayList(usesLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6544 | usesOptionalLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6545 | internStringArrayList(usesOptionalLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6546 | usesLibraryFiles = dest.readStringArray(); |
| 6547 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6548 | final int libCount = dest.readInt(); |
| 6549 | if (libCount > 0) { |
| 6550 | usesStaticLibraries = new ArrayList<>(libCount); |
| 6551 | dest.readStringList(usesStaticLibraries); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6552 | internStringArrayList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6553 | usesStaticLibrariesVersions = new long[libCount]; |
| 6554 | dest.readLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6555 | usesStaticLibrariesCertDigests = new String[libCount][]; |
| 6556 | for (int i = 0; i < libCount; i++) { |
| 6557 | usesStaticLibrariesCertDigests[i] = dest.createStringArray(); |
| 6558 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6559 | } |
| 6560 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6561 | preferredActivityFilters = new ArrayList<>(); |
| 6562 | dest.readParcelableList(preferredActivityFilters, boot); |
| 6563 | if (preferredActivityFilters.size() == 0) { |
| 6564 | preferredActivityFilters = null; |
| 6565 | } |
| 6566 | |
| 6567 | mOriginalPackages = dest.createStringArrayList(); |
| 6568 | mRealPackage = dest.readString(); |
| 6569 | mAdoptPermissions = dest.createStringArrayList(); |
| 6570 | mAppMetaData = dest.readBundle(); |
| 6571 | mVersionCode = dest.readInt(); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 6572 | mVersionCodeMajor = dest.readInt(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6573 | mVersionName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6574 | if (mVersionName != null) { |
| 6575 | mVersionName = mVersionName.intern(); |
| 6576 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6577 | mSharedUserId = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6578 | if (mSharedUserId != null) { |
| 6579 | mSharedUserId = mSharedUserId.intern(); |
| 6580 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6581 | mSharedUserLabel = dest.readInt(); |
| 6582 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6583 | mSigningDetails = dest.readParcelable(boot); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6584 | |
| 6585 | mPreferredOrder = dest.readInt(); |
| 6586 | |
| 6587 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 6588 | // is parsed from the APK. |
| 6589 | |
| 6590 | // Object mExtras is not persisted because it is not information that is read from |
| 6591 | // the APK, rather, it is supplied by callers. |
| 6592 | |
| 6593 | |
| 6594 | configPreferences = new ArrayList<>(); |
| 6595 | dest.readParcelableList(configPreferences, boot); |
| 6596 | if (configPreferences.size() == 0) { |
| 6597 | configPreferences = null; |
| 6598 | } |
| 6599 | |
| 6600 | reqFeatures = new ArrayList<>(); |
| 6601 | dest.readParcelableList(reqFeatures, boot); |
| 6602 | if (reqFeatures.size() == 0) { |
| 6603 | reqFeatures = null; |
| 6604 | } |
| 6605 | |
| 6606 | featureGroups = new ArrayList<>(); |
| 6607 | dest.readParcelableList(featureGroups, boot); |
| 6608 | if (featureGroups.size() == 0) { |
| 6609 | featureGroups = null; |
| 6610 | } |
| 6611 | |
| 6612 | installLocation = dest.readInt(); |
| 6613 | coreApp = (dest.readInt() == 1); |
| 6614 | mRequiredForAllUsers = (dest.readInt() == 1); |
| 6615 | mRestrictedAccountType = dest.readString(); |
| 6616 | mRequiredAccountType = dest.readString(); |
| 6617 | mOverlayTarget = dest.readString(); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6618 | mOverlayPriority = dest.readInt(); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6619 | mOverlayIsStatic = (dest.readInt() == 1); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6620 | mCompileSdkVersion = dest.readInt(); |
| 6621 | mCompileSdkVersionCodename = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6622 | mUpgradeKeySets = (ArraySet<String>) dest.readArraySet(boot); |
| 6623 | |
| 6624 | mKeySetMapping = readKeySetMapping(dest); |
| 6625 | |
| 6626 | cpuAbiOverride = dest.readString(); |
| 6627 | use32bitAbi = (dest.readInt() == 1); |
| 6628 | restrictUpdateHash = dest.createByteArray(); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 6629 | visibleToInstantApps = dest.readInt() == 1; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6630 | } |
| 6631 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6632 | private static void internStringArrayList(List<String> list) { |
| 6633 | if (list != null) { |
| 6634 | final int N = list.size(); |
| 6635 | for (int i = 0; i < N; ++i) { |
| 6636 | list.set(i, list.get(i).intern()); |
| 6637 | } |
| 6638 | } |
| 6639 | } |
| 6640 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6641 | /** |
| 6642 | * Sets the package owner and the the {@code applicationInfo} for every component |
| 6643 | * owner by this package. |
| 6644 | */ |
| 6645 | private void fixupOwner(List<? extends Component<?>> list) { |
| 6646 | if (list != null) { |
| 6647 | for (Component<?> c : list) { |
| 6648 | c.owner = this; |
| 6649 | if (c instanceof Activity) { |
| 6650 | ((Activity) c).info.applicationInfo = this.applicationInfo; |
| 6651 | } else if (c instanceof Service) { |
| 6652 | ((Service) c).info.applicationInfo = this.applicationInfo; |
| 6653 | } else if (c instanceof Provider) { |
| 6654 | ((Provider) c).info.applicationInfo = this.applicationInfo; |
| 6655 | } |
| 6656 | } |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | @Override |
| 6661 | public void writeToParcel(Parcel dest, int flags) { |
| 6662 | dest.writeString(packageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6663 | dest.writeString(manifestPackageName); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6664 | dest.writeStringArray(splitNames); |
| 6665 | dest.writeString(volumeUuid); |
| 6666 | dest.writeString(codePath); |
| 6667 | dest.writeString(baseCodePath); |
| 6668 | dest.writeStringArray(splitCodePaths); |
| 6669 | dest.writeInt(baseRevisionCode); |
| 6670 | dest.writeIntArray(splitRevisionCodes); |
| 6671 | dest.writeIntArray(splitFlags); |
| 6672 | dest.writeIntArray(splitPrivateFlags); |
| 6673 | dest.writeInt(baseHardwareAccelerated ? 1 : 0); |
| 6674 | dest.writeParcelable(applicationInfo, flags); |
| 6675 | |
| 6676 | dest.writeParcelableList(permissions, flags); |
| 6677 | dest.writeParcelableList(permissionGroups, flags); |
| 6678 | dest.writeParcelableList(activities, flags); |
| 6679 | dest.writeParcelableList(receivers, flags); |
| 6680 | dest.writeParcelableList(providers, flags); |
| 6681 | dest.writeParcelableList(services, flags); |
| 6682 | dest.writeParcelableList(instrumentation, flags); |
| 6683 | |
| 6684 | dest.writeStringList(requestedPermissions); |
| 6685 | dest.writeStringList(protectedBroadcasts); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 6686 | |
| 6687 | // TODO: This doesn't work: b/64295061 |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6688 | dest.writeParcelable(parentPackage, flags); |
| 6689 | dest.writeParcelableList(childPackages, flags); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 6690 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6691 | dest.writeString(staticSharedLibName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6692 | dest.writeLong(staticSharedLibVersion); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6693 | dest.writeStringList(libraryNames); |
| 6694 | dest.writeStringList(usesLibraries); |
| 6695 | dest.writeStringList(usesOptionalLibraries); |
| 6696 | dest.writeStringArray(usesLibraryFiles); |
| 6697 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6698 | if (ArrayUtils.isEmpty(usesStaticLibraries)) { |
| 6699 | dest.writeInt(-1); |
| 6700 | } else { |
| 6701 | dest.writeInt(usesStaticLibraries.size()); |
| 6702 | dest.writeStringList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6703 | dest.writeLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6704 | for (String[] usesStaticLibrariesCertDigest : usesStaticLibrariesCertDigests) { |
| 6705 | dest.writeStringArray(usesStaticLibrariesCertDigest); |
| 6706 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6707 | } |
| 6708 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6709 | dest.writeParcelableList(preferredActivityFilters, flags); |
| 6710 | |
| 6711 | dest.writeStringList(mOriginalPackages); |
| 6712 | dest.writeString(mRealPackage); |
| 6713 | dest.writeStringList(mAdoptPermissions); |
| 6714 | dest.writeBundle(mAppMetaData); |
| 6715 | dest.writeInt(mVersionCode); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 6716 | dest.writeInt(mVersionCodeMajor); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6717 | dest.writeString(mVersionName); |
| 6718 | dest.writeString(mSharedUserId); |
| 6719 | dest.writeInt(mSharedUserLabel); |
| 6720 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6721 | dest.writeParcelable(mSigningDetails, flags); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6722 | |
| 6723 | dest.writeInt(mPreferredOrder); |
| 6724 | |
| 6725 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 6726 | // is parsed from the APK. |
| 6727 | |
| 6728 | // Object mExtras is not persisted because it is not information that is read from |
| 6729 | // the APK, rather, it is supplied by callers. |
| 6730 | |
| 6731 | dest.writeParcelableList(configPreferences, flags); |
| 6732 | dest.writeParcelableList(reqFeatures, flags); |
| 6733 | dest.writeParcelableList(featureGroups, flags); |
| 6734 | |
| 6735 | dest.writeInt(installLocation); |
| 6736 | dest.writeInt(coreApp ? 1 : 0); |
| 6737 | dest.writeInt(mRequiredForAllUsers ? 1 : 0); |
| 6738 | dest.writeString(mRestrictedAccountType); |
| 6739 | dest.writeString(mRequiredAccountType); |
| 6740 | dest.writeString(mOverlayTarget); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6741 | dest.writeInt(mOverlayPriority); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6742 | dest.writeInt(mOverlayIsStatic ? 1 : 0); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6743 | dest.writeInt(mCompileSdkVersion); |
| 6744 | dest.writeString(mCompileSdkVersionCodename); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6745 | dest.writeArraySet(mUpgradeKeySets); |
| 6746 | writeKeySetMapping(dest, mKeySetMapping); |
| 6747 | dest.writeString(cpuAbiOverride); |
| 6748 | dest.writeInt(use32bitAbi ? 1 : 0); |
| 6749 | dest.writeByteArray(restrictUpdateHash); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 6750 | dest.writeInt(visibleToInstantApps ? 1 : 0); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | |
| 6754 | /** |
| 6755 | * Writes the keyset mapping to the provided package. {@code null} mappings are permitted. |
| 6756 | */ |
| 6757 | private static void writeKeySetMapping( |
| 6758 | Parcel dest, ArrayMap<String, ArraySet<PublicKey>> keySetMapping) { |
| 6759 | if (keySetMapping == null) { |
| 6760 | dest.writeInt(-1); |
| 6761 | return; |
| 6762 | } |
| 6763 | |
| 6764 | final int N = keySetMapping.size(); |
| 6765 | dest.writeInt(N); |
| 6766 | |
| 6767 | for (int i = 0; i < N; i++) { |
| 6768 | dest.writeString(keySetMapping.keyAt(i)); |
| 6769 | ArraySet<PublicKey> keys = keySetMapping.valueAt(i); |
| 6770 | if (keys == null) { |
| 6771 | dest.writeInt(-1); |
| 6772 | continue; |
| 6773 | } |
| 6774 | |
| 6775 | final int M = keys.size(); |
| 6776 | dest.writeInt(M); |
| 6777 | for (int j = 0; j < M; j++) { |
| 6778 | dest.writeSerializable(keys.valueAt(j)); |
| 6779 | } |
| 6780 | } |
| 6781 | } |
| 6782 | |
| 6783 | /** |
| 6784 | * Reads a keyset mapping from the given parcel at the given data position. May return |
| 6785 | * {@code null} if the serialized mapping was {@code null}. |
| 6786 | */ |
| 6787 | private static ArrayMap<String, ArraySet<PublicKey>> readKeySetMapping(Parcel in) { |
| 6788 | final int N = in.readInt(); |
| 6789 | if (N == -1) { |
| 6790 | return null; |
| 6791 | } |
| 6792 | |
| 6793 | ArrayMap<String, ArraySet<PublicKey>> keySetMapping = new ArrayMap<>(); |
| 6794 | for (int i = 0; i < N; ++i) { |
| 6795 | String key = in.readString(); |
| 6796 | final int M = in.readInt(); |
| 6797 | if (M == -1) { |
| 6798 | keySetMapping.put(key, null); |
| 6799 | continue; |
| 6800 | } |
| 6801 | |
| 6802 | ArraySet<PublicKey> keys = new ArraySet<>(M); |
| 6803 | for (int j = 0; j < M; ++j) { |
| 6804 | PublicKey pk = (PublicKey) in.readSerializable(); |
| 6805 | keys.add(pk); |
| 6806 | } |
| 6807 | |
| 6808 | keySetMapping.put(key, keys); |
| 6809 | } |
| 6810 | |
| 6811 | return keySetMapping; |
| 6812 | } |
| 6813 | |
| 6814 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Package>() { |
| 6815 | public Package createFromParcel(Parcel in) { |
| 6816 | return new Package(in); |
| 6817 | } |
| 6818 | |
| 6819 | public Package[] newArray(int size) { |
| 6820 | return new Package[size]; |
| 6821 | } |
| 6822 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | } |
| 6824 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6825 | public static abstract class Component<II extends IntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6826 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6827 | public final String className; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6829 | public Bundle metaData; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6830 | public Package owner; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6832 | ComponentName componentName; |
| 6833 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | public Component(Package _owner) { |
| 6836 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6837 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6838 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 6842 | owner = args.owner; |
| 6843 | intents = new ArrayList<II>(0); |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 6844 | if (parsePackageItemInfo(args.owner, outInfo, args.outError, args.tag, args.sa, |
| 6845 | true /*nameRequired*/, args.nameRes, args.labelRes, args.iconRes, |
| 6846 | args.roundIconRes, args.logoRes, args.bannerRes)) { |
| 6847 | className = outInfo.name; |
| 6848 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6849 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6850 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 6854 | this(args, (PackageItemInfo)outInfo); |
| 6855 | if (args.outError[0] != null) { |
| 6856 | return; |
| 6857 | } |
| 6858 | |
| 6859 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 6860 | CharSequence pname; |
| 6861 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 6862 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 6863 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 6864 | } else { |
| 6865 | // Some older apps have been seen to use a resource reference |
| 6866 | // here that on older builds was ignored (with a warning). We |
| 6867 | // need to continue to do this for them so they don't break. |
| 6868 | pname = args.sa.getNonResourceString(args.processRes); |
| 6869 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6870 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 6871 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6872 | args.flags, args.sepProcesses, args.outError); |
| 6873 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6874 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 6875 | if (args.descriptionRes != 0) { |
| 6876 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 6877 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6878 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6879 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | public Component(Component<II> clone) { |
| 6883 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6884 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6885 | className = clone.className; |
| 6886 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6887 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6888 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6889 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6890 | public ComponentName getComponentName() { |
| 6891 | if (componentName != null) { |
| 6892 | return componentName; |
| 6893 | } |
| 6894 | if (className != null) { |
| 6895 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 6896 | className); |
| 6897 | } |
| 6898 | return componentName; |
| 6899 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 6900 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6901 | protected Component(Parcel in) { |
| 6902 | className = in.readString(); |
| 6903 | metaData = in.readBundle(); |
| 6904 | intents = createIntentsList(in); |
| 6905 | |
| 6906 | owner = null; |
| 6907 | } |
| 6908 | |
| 6909 | protected void writeToParcel(Parcel dest, int flags) { |
| 6910 | dest.writeString(className); |
| 6911 | dest.writeBundle(metaData); |
| 6912 | |
| 6913 | writeIntentsList(intents, dest, flags); |
| 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * <p> |
| 6918 | * Implementation note: The serialized form for the intent list also contains the name |
| 6919 | * of the concrete class that's stored in the list, and assumes that every element of the |
| 6920 | * list is of the same type. This is very similar to the original parcelable mechanism. |
| 6921 | * We cannot use that directly because IntentInfo extends IntentFilter, which is parcelable |
| 6922 | * and is public API. It also declares Parcelable related methods as final which means |
| 6923 | * we can't extend them. The approach of using composition instead of inheritance leads to |
| 6924 | * a large set of cascading changes in the PackageManagerService, which seem undesirable. |
| 6925 | * |
| 6926 | * <p> |
| 6927 | * <b>WARNING: </b> The list of objects returned by this function might need to be fixed up |
| 6928 | * to make sure their owner fields are consistent. See {@code fixupOwner}. |
| 6929 | */ |
| 6930 | private static void writeIntentsList(ArrayList<? extends IntentInfo> list, Parcel out, |
| 6931 | int flags) { |
| 6932 | if (list == null) { |
| 6933 | out.writeInt(-1); |
| 6934 | return; |
| 6935 | } |
| 6936 | |
| 6937 | final int N = list.size(); |
| 6938 | out.writeInt(N); |
| 6939 | |
| 6940 | // Don't bother writing the component name if the list is empty. |
| 6941 | if (N > 0) { |
| 6942 | IntentInfo info = list.get(0); |
| 6943 | out.writeString(info.getClass().getName()); |
| 6944 | |
| 6945 | for (int i = 0; i < N;i++) { |
| 6946 | list.get(i).writeIntentInfoToParcel(out, flags); |
| 6947 | } |
| 6948 | } |
| 6949 | } |
| 6950 | |
| 6951 | private static <T extends IntentInfo> ArrayList<T> createIntentsList(Parcel in) { |
| 6952 | int N = in.readInt(); |
| 6953 | if (N == -1) { |
| 6954 | return null; |
| 6955 | } |
| 6956 | |
| 6957 | if (N == 0) { |
| 6958 | return new ArrayList<>(0); |
| 6959 | } |
| 6960 | |
| 6961 | String componentName = in.readString(); |
| 6962 | final ArrayList<T> intentsList; |
| 6963 | try { |
| 6964 | final Class<T> cls = (Class<T>) Class.forName(componentName); |
| 6965 | final Constructor<T> cons = cls.getConstructor(Parcel.class); |
| 6966 | |
| 6967 | intentsList = new ArrayList<>(N); |
| 6968 | for (int i = 0; i < N; ++i) { |
| 6969 | intentsList.add(cons.newInstance(in)); |
| 6970 | } |
| 6971 | } catch (ReflectiveOperationException ree) { |
| 6972 | throw new AssertionError("Unable to construct intent list for: " + componentName); |
| 6973 | } |
| 6974 | |
| 6975 | return intentsList; |
| 6976 | } |
| 6977 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 6978 | public void appendComponentShortName(StringBuilder sb) { |
| 6979 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6980 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 6981 | |
| 6982 | public void printComponentShortName(PrintWriter pw) { |
| 6983 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 6984 | } |
| 6985 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6986 | public void setPackageName(String packageName) { |
| 6987 | componentName = null; |
| 6988 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6989 | } |
| 6990 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6991 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6992 | public final static class Permission extends Component<IntentInfo> implements Parcelable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | public final PermissionInfo info; |
| 6994 | public boolean tree; |
| 6995 | public PermissionGroup group; |
| 6996 | |
| 6997 | public Permission(Package _owner) { |
| 6998 | super(_owner); |
| 6999 | info = new PermissionInfo(); |
| 7000 | } |
| 7001 | |
| 7002 | public Permission(Package _owner, PermissionInfo _info) { |
| 7003 | super(_owner); |
| 7004 | info = _info; |
| 7005 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7006 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7007 | public void setPackageName(String packageName) { |
| 7008 | super.setPackageName(packageName); |
| 7009 | info.packageName = packageName; |
| 7010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | |
| 7012 | public String toString() { |
| 7013 | return "Permission{" |
| 7014 | + Integer.toHexString(System.identityHashCode(this)) |
| 7015 | + " " + info.name + "}"; |
| 7016 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7017 | |
| 7018 | @Override |
| 7019 | public int describeContents() { |
| 7020 | return 0; |
| 7021 | } |
| 7022 | |
| 7023 | @Override |
| 7024 | public void writeToParcel(Parcel dest, int flags) { |
| 7025 | super.writeToParcel(dest, flags); |
| 7026 | dest.writeParcelable(info, flags); |
| 7027 | dest.writeInt(tree ? 1 : 0); |
| 7028 | dest.writeParcelable(group, flags); |
| 7029 | } |
| 7030 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 7031 | /** @hide */ |
| 7032 | public boolean isAppOp() { |
| 7033 | return info.isAppOp(); |
| 7034 | } |
| 7035 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7036 | private Permission(Parcel in) { |
| 7037 | super(in); |
| 7038 | final ClassLoader boot = Object.class.getClassLoader(); |
| 7039 | info = in.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7040 | if (info.group != null) { |
| 7041 | info.group = info.group.intern(); |
| 7042 | } |
| 7043 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7044 | tree = (in.readInt() == 1); |
| 7045 | group = in.readParcelable(boot); |
| 7046 | } |
| 7047 | |
| 7048 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Permission>() { |
| 7049 | public Permission createFromParcel(Parcel in) { |
| 7050 | return new Permission(in); |
| 7051 | } |
| 7052 | |
| 7053 | public Permission[] newArray(int size) { |
| 7054 | return new Permission[size]; |
| 7055 | } |
| 7056 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | } |
| 7058 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7059 | public final static class PermissionGroup extends Component<IntentInfo> implements Parcelable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7060 | public final PermissionGroupInfo info; |
| 7061 | |
| 7062 | public PermissionGroup(Package _owner) { |
| 7063 | super(_owner); |
| 7064 | info = new PermissionGroupInfo(); |
| 7065 | } |
| 7066 | |
| 7067 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 7068 | super(_owner); |
| 7069 | info = _info; |
| 7070 | } |
| 7071 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7072 | public void setPackageName(String packageName) { |
| 7073 | super.setPackageName(packageName); |
| 7074 | info.packageName = packageName; |
| 7075 | } |
| 7076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7077 | public String toString() { |
| 7078 | return "PermissionGroup{" |
| 7079 | + Integer.toHexString(System.identityHashCode(this)) |
| 7080 | + " " + info.name + "}"; |
| 7081 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7082 | |
| 7083 | @Override |
| 7084 | public int describeContents() { |
| 7085 | return 0; |
| 7086 | } |
| 7087 | |
| 7088 | @Override |
| 7089 | public void writeToParcel(Parcel dest, int flags) { |
| 7090 | super.writeToParcel(dest, flags); |
| 7091 | dest.writeParcelable(info, flags); |
| 7092 | } |
| 7093 | |
| 7094 | private PermissionGroup(Parcel in) { |
| 7095 | super(in); |
| 7096 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7097 | } |
| 7098 | |
| 7099 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<PermissionGroup>() { |
| 7100 | public PermissionGroup createFromParcel(Parcel in) { |
| 7101 | return new PermissionGroup(in); |
| 7102 | } |
| 7103 | |
| 7104 | public PermissionGroup[] newArray(int size) { |
| 7105 | return new PermissionGroup[size]; |
| 7106 | } |
| 7107 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | } |
| 7109 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7110 | private static boolean copyNeeded(int flags, Package p, |
| 7111 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 7112 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7113 | // We always need to copy for other users, since we need |
| 7114 | // to fix up the uid. |
| 7115 | return true; |
| 7116 | } |
| 7117 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 7118 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 7119 | if (p.applicationInfo.enabled != enabled) { |
| 7120 | return true; |
| 7121 | } |
| 7122 | } |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 7123 | boolean suspended = (p.applicationInfo.flags & FLAG_SUSPENDED) != 0; |
| 7124 | if (state.suspended != suspended) { |
| 7125 | return true; |
| 7126 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7127 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7128 | return true; |
| 7129 | } |
| 7130 | if (state.stopped) { |
| 7131 | return true; |
| 7132 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7133 | if (state.instantApp != p.applicationInfo.isInstantApp()) { |
| 7134 | return true; |
| 7135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 7137 | && (metaData != null || p.mAppMetaData != null)) { |
| 7138 | return true; |
| 7139 | } |
| 7140 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7141 | && p.usesLibraryFiles != null) { |
| 7142 | return true; |
| 7143 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7144 | if (p.staticSharedLibName != null) { |
| 7145 | return true; |
| 7146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | return false; |
| 7148 | } |
| 7149 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7150 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 7151 | PackageUserState state) { |
| 7152 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 7153 | } |
| 7154 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7155 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 7156 | PackageUserState state) { |
| 7157 | // CompatibilityMode is global state. |
| 7158 | if (!sCompatibilityModeEnabled) { |
| 7159 | ai.disableCompatibilityMode(); |
| 7160 | } |
| 7161 | if (state.installed) { |
| 7162 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 7163 | } else { |
| 7164 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 7165 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 7166 | if (state.suspended) { |
| 7167 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 7168 | } else { |
| 7169 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 7170 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7171 | if (state.instantApp) { |
| 7172 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7173 | } else { |
| 7174 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7175 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 7176 | if (state.virtualPreload) { |
| 7177 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7178 | } else { |
| 7179 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7180 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7181 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7182 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7183 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7184 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7185 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7186 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 7187 | ai.enabled = true; |
| 7188 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 7189 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 7190 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 7191 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 7192 | ai.enabled = false; |
| 7193 | } |
| 7194 | ai.enabledSetting = state.enabled; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 7195 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7196 | ai.category = state.categoryHint; |
| 7197 | } |
Jeff Sharkey | 0078e1b | 2017-01-11 16:05:27 -0700 | [diff] [blame] | 7198 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7199 | ai.category = FallbackCategoryProvider.getFallbackCategory(ai.packageName); |
| 7200 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7201 | ai.seInfoUser = SELinuxUtil.assignSeinfoUser(state); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7202 | ai.resourceDirs = state.overlayPaths; |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7203 | } |
| 7204 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 7205 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7206 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7208 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7209 | return null; |
| 7210 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7211 | if (!copyNeeded(flags, p, state, null, userId) |
| 7212 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 7213 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 7214 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 7215 | // - CompatibilityMode is global state, so will be the same for every call. |
| 7216 | // - We only come in to here if the app should reported as installed; this is the |
| 7217 | // default state, and we will do a copy otherwise. |
| 7218 | // - The enable state will always be reported the same for the application across |
| 7219 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 7220 | // be doing a copy. |
| 7221 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | return p.applicationInfo; |
| 7223 | } |
| 7224 | |
| 7225 | // Make shallow copy so we can store the metadata/libraries safely |
| 7226 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7227 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 7229 | ai.metaData = p.mAppMetaData; |
| 7230 | } |
| 7231 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 7232 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 7233 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7234 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7235 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7236 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7237 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7238 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7239 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7240 | return ai; |
| 7241 | } |
| 7242 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7243 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 7244 | PackageUserState state, int userId) { |
| 7245 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7246 | if (!checkUseInstalledOrHidden(flags, state, ai)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7247 | return null; |
| 7248 | } |
| 7249 | // This is only used to return the ResolverActivity; we will just always |
| 7250 | // make a copy. |
| 7251 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7252 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7253 | if (state.stopped) { |
| 7254 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 7255 | } else { |
| 7256 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 7257 | } |
| 7258 | updateApplicationInfo(ai, flags, state); |
| 7259 | return ai; |
| 7260 | } |
| 7261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | public static final PermissionInfo generatePermissionInfo( |
| 7263 | Permission p, int flags) { |
| 7264 | if (p == null) return null; |
| 7265 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7266 | return p.info; |
| 7267 | } |
| 7268 | PermissionInfo pi = new PermissionInfo(p.info); |
| 7269 | pi.metaData = p.metaData; |
| 7270 | return pi; |
| 7271 | } |
| 7272 | |
| 7273 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 7274 | PermissionGroup pg, int flags) { |
| 7275 | if (pg == null) return null; |
| 7276 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7277 | return pg.info; |
| 7278 | } |
| 7279 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 7280 | pgi.metaData = pg.metaData; |
| 7281 | return pgi; |
| 7282 | } |
| 7283 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7284 | public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7285 | public final ActivityInfo info; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7286 | private boolean mHasMaxAspectRatio; |
| 7287 | |
| 7288 | private boolean hasMaxAspectRatio() { |
| 7289 | return mHasMaxAspectRatio; |
| 7290 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7292 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 7293 | super(args, _info); |
| 7294 | info = _info; |
| 7295 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7296 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7297 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7298 | public void setPackageName(String packageName) { |
| 7299 | super.setPackageName(packageName); |
| 7300 | info.packageName = packageName; |
| 7301 | } |
| 7302 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7303 | |
| 7304 | private void setMaxAspectRatio(float maxAspectRatio) { |
| 7305 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7306 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7307 | // Resizeable activities can be put in any aspect ratio. |
| 7308 | return; |
| 7309 | } |
| 7310 | |
| 7311 | if (maxAspectRatio < 1.0f && maxAspectRatio != 0) { |
| 7312 | // Ignore any value lesser than 1.0. |
| 7313 | return; |
| 7314 | } |
| 7315 | |
| 7316 | info.maxAspectRatio = maxAspectRatio; |
| 7317 | mHasMaxAspectRatio = true; |
| 7318 | } |
| 7319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7320 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7321 | StringBuilder sb = new StringBuilder(128); |
| 7322 | sb.append("Activity{"); |
| 7323 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7324 | sb.append(' '); |
| 7325 | appendComponentShortName(sb); |
| 7326 | sb.append('}'); |
| 7327 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7328 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7329 | |
| 7330 | @Override |
| 7331 | public int describeContents() { |
| 7332 | return 0; |
| 7333 | } |
| 7334 | |
| 7335 | @Override |
| 7336 | public void writeToParcel(Parcel dest, int flags) { |
| 7337 | super.writeToParcel(dest, flags); |
| 7338 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7339 | dest.writeBoolean(mHasMaxAspectRatio); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | private Activity(Parcel in) { |
| 7343 | super(in); |
| 7344 | info = in.readParcelable(Object.class.getClassLoader()); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7345 | mHasMaxAspectRatio = in.readBoolean(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7346 | |
| 7347 | for (ActivityIntentInfo aii : intents) { |
| 7348 | aii.activity = this; |
| 7349 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7350 | |
| 7351 | if (info.permission != null) { |
| 7352 | info.permission = info.permission.intern(); |
| 7353 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7354 | } |
| 7355 | |
| 7356 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Activity>() { |
| 7357 | public Activity createFromParcel(Parcel in) { |
| 7358 | return new Activity(in); |
| 7359 | } |
| 7360 | |
| 7361 | public Activity[] newArray(int size) { |
| 7362 | return new Activity[size]; |
| 7363 | } |
| 7364 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | } |
| 7366 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7367 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 7368 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7369 | if (a == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7370 | if (!checkUseInstalledOrHidden(flags, state, a.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7371 | return null; |
| 7372 | } |
| 7373 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7374 | updateApplicationInfo(a.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | return a.info; |
| 7376 | } |
| 7377 | // Make shallow copies so we can store the metadata safely |
| 7378 | ActivityInfo ai = new ActivityInfo(a.info); |
| 7379 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7380 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | return ai; |
| 7382 | } |
| 7383 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7384 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 7385 | PackageUserState state, int userId) { |
| 7386 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7387 | if (!checkUseInstalledOrHidden(flags, state, ai.applicationInfo)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7388 | return null; |
| 7389 | } |
| 7390 | // This is only used to return the ResolverActivity; we will just always |
| 7391 | // make a copy. |
| 7392 | ai = new ActivityInfo(ai); |
| 7393 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 7394 | return ai; |
| 7395 | } |
| 7396 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7397 | public final static class Service extends Component<ServiceIntentInfo> implements Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7398 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7400 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 7401 | super(args, _info); |
| 7402 | info = _info; |
| 7403 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7404 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7405 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7406 | public void setPackageName(String packageName) { |
| 7407 | super.setPackageName(packageName); |
| 7408 | info.packageName = packageName; |
| 7409 | } |
| 7410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7412 | StringBuilder sb = new StringBuilder(128); |
| 7413 | sb.append("Service{"); |
| 7414 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7415 | sb.append(' '); |
| 7416 | appendComponentShortName(sb); |
| 7417 | sb.append('}'); |
| 7418 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7420 | |
| 7421 | @Override |
| 7422 | public int describeContents() { |
| 7423 | return 0; |
| 7424 | } |
| 7425 | |
| 7426 | @Override |
| 7427 | public void writeToParcel(Parcel dest, int flags) { |
| 7428 | super.writeToParcel(dest, flags); |
| 7429 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 7430 | } |
| 7431 | |
| 7432 | private Service(Parcel in) { |
| 7433 | super(in); |
| 7434 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7435 | |
| 7436 | for (ServiceIntentInfo aii : intents) { |
| 7437 | aii.service = this; |
| 7438 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7439 | |
| 7440 | if (info.permission != null) { |
| 7441 | info.permission = info.permission.intern(); |
| 7442 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Service>() { |
| 7446 | public Service createFromParcel(Parcel in) { |
| 7447 | return new Service(in); |
| 7448 | } |
| 7449 | |
| 7450 | public Service[] newArray(int size) { |
| 7451 | return new Service[size]; |
| 7452 | } |
| 7453 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | } |
| 7455 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7456 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 7457 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | if (s == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7459 | if (!checkUseInstalledOrHidden(flags, state, s.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7460 | return null; |
| 7461 | } |
| 7462 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7463 | updateApplicationInfo(s.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | return s.info; |
| 7465 | } |
| 7466 | // Make shallow copies so we can store the metadata safely |
| 7467 | ServiceInfo si = new ServiceInfo(s.info); |
| 7468 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7469 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | return si; |
| 7471 | } |
| 7472 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7473 | public final static class Provider extends Component<ProviderIntentInfo> implements Parcelable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | public final ProviderInfo info; |
| 7475 | public boolean syncable; |
| 7476 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7477 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 7478 | super(args, _info); |
| 7479 | info = _info; |
| 7480 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | syncable = false; |
| 7482 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7484 | public Provider(Provider existingProvider) { |
| 7485 | super(existingProvider); |
| 7486 | this.info = existingProvider.info; |
| 7487 | this.syncable = existingProvider.syncable; |
| 7488 | } |
| 7489 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7490 | public void setPackageName(String packageName) { |
| 7491 | super.setPackageName(packageName); |
| 7492 | info.packageName = packageName; |
| 7493 | } |
| 7494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7496 | StringBuilder sb = new StringBuilder(128); |
| 7497 | sb.append("Provider{"); |
| 7498 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7499 | sb.append(' '); |
| 7500 | appendComponentShortName(sb); |
| 7501 | sb.append('}'); |
| 7502 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7504 | |
| 7505 | @Override |
| 7506 | public int describeContents() { |
| 7507 | return 0; |
| 7508 | } |
| 7509 | |
| 7510 | @Override |
| 7511 | public void writeToParcel(Parcel dest, int flags) { |
| 7512 | super.writeToParcel(dest, flags); |
| 7513 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 7514 | dest.writeInt((syncable) ? 1 : 0); |
| 7515 | } |
| 7516 | |
| 7517 | private Provider(Parcel in) { |
| 7518 | super(in); |
| 7519 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7520 | syncable = (in.readInt() == 1); |
| 7521 | |
| 7522 | for (ProviderIntentInfo aii : intents) { |
| 7523 | aii.provider = this; |
| 7524 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7525 | |
| 7526 | if (info.readPermission != null) { |
| 7527 | info.readPermission = info.readPermission.intern(); |
| 7528 | } |
| 7529 | |
| 7530 | if (info.writePermission != null) { |
| 7531 | info.writePermission = info.writePermission.intern(); |
| 7532 | } |
| 7533 | |
| 7534 | if (info.authority != null) { |
| 7535 | info.authority = info.authority.intern(); |
| 7536 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Provider>() { |
| 7540 | public Provider createFromParcel(Parcel in) { |
| 7541 | return new Provider(in); |
| 7542 | } |
| 7543 | |
| 7544 | public Provider[] newArray(int size) { |
| 7545 | return new Provider[size]; |
| 7546 | } |
| 7547 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | } |
| 7549 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7550 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 7551 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7553 | if (!checkUseInstalledOrHidden(flags, state, p.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7554 | return null; |
| 7555 | } |
| 7556 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7558 | || p.info.uriPermissionPatterns == null)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7559 | updateApplicationInfo(p.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | return p.info; |
| 7561 | } |
| 7562 | // Make shallow copies so we can store the metadata safely |
| 7563 | ProviderInfo pi = new ProviderInfo(p.info); |
| 7564 | pi.metaData = p.metaData; |
| 7565 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 7566 | pi.uriPermissionPatterns = null; |
| 7567 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7568 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | return pi; |
| 7570 | } |
| 7571 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7572 | public final static class Instrumentation extends Component<IntentInfo> implements |
| 7573 | Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7574 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7575 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7576 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 7577 | super(args, _info); |
| 7578 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7580 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7581 | public void setPackageName(String packageName) { |
| 7582 | super.setPackageName(packageName); |
| 7583 | info.packageName = packageName; |
| 7584 | } |
| 7585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7587 | StringBuilder sb = new StringBuilder(128); |
| 7588 | sb.append("Instrumentation{"); |
| 7589 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7590 | sb.append(' '); |
| 7591 | appendComponentShortName(sb); |
| 7592 | sb.append('}'); |
| 7593 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7594 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7595 | |
| 7596 | @Override |
| 7597 | public int describeContents() { |
| 7598 | return 0; |
| 7599 | } |
| 7600 | |
| 7601 | @Override |
| 7602 | public void writeToParcel(Parcel dest, int flags) { |
| 7603 | super.writeToParcel(dest, flags); |
| 7604 | dest.writeParcelable(info, flags); |
| 7605 | } |
| 7606 | |
| 7607 | private Instrumentation(Parcel in) { |
| 7608 | super(in); |
| 7609 | info = in.readParcelable(Object.class.getClassLoader()); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7610 | |
| 7611 | if (info.targetPackage != null) { |
| 7612 | info.targetPackage = info.targetPackage.intern(); |
| 7613 | } |
| 7614 | |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 7615 | if (info.targetProcesses != null) { |
| 7616 | info.targetProcesses = info.targetProcesses.intern(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7617 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Instrumentation>() { |
| 7621 | public Instrumentation createFromParcel(Parcel in) { |
| 7622 | return new Instrumentation(in); |
| 7623 | } |
| 7624 | |
| 7625 | public Instrumentation[] newArray(int size) { |
| 7626 | return new Instrumentation[size]; |
| 7627 | } |
| 7628 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 7632 | Instrumentation i, int flags) { |
| 7633 | if (i == null) return null; |
| 7634 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7635 | return i.info; |
| 7636 | } |
| 7637 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 7638 | ii.metaData = i.metaData; |
| 7639 | return ii; |
| 7640 | } |
| 7641 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7642 | public static abstract class IntentInfo extends IntentFilter { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7643 | public boolean hasDefault; |
| 7644 | public int labelRes; |
| 7645 | public CharSequence nonLocalizedLabel; |
| 7646 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 7647 | public int logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 7648 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 7649 | public int preferred; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7650 | |
| 7651 | protected IntentInfo() { |
| 7652 | } |
| 7653 | |
| 7654 | protected IntentInfo(Parcel dest) { |
| 7655 | super(dest); |
| 7656 | hasDefault = (dest.readInt() == 1); |
| 7657 | labelRes = dest.readInt(); |
| 7658 | nonLocalizedLabel = dest.readCharSequence(); |
| 7659 | icon = dest.readInt(); |
| 7660 | logo = dest.readInt(); |
| 7661 | banner = dest.readInt(); |
| 7662 | preferred = dest.readInt(); |
| 7663 | } |
| 7664 | |
| 7665 | |
| 7666 | public void writeIntentInfoToParcel(Parcel dest, int flags) { |
| 7667 | super.writeToParcel(dest, flags); |
| 7668 | dest.writeInt(hasDefault ? 1 : 0); |
| 7669 | dest.writeInt(labelRes); |
| 7670 | dest.writeCharSequence(nonLocalizedLabel); |
| 7671 | dest.writeInt(icon); |
| 7672 | dest.writeInt(logo); |
| 7673 | dest.writeInt(banner); |
| 7674 | dest.writeInt(preferred); |
| 7675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7676 | } |
| 7677 | |
| 7678 | public final static class ActivityIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7679 | public Activity activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | |
| 7681 | public ActivityIntentInfo(Activity _activity) { |
| 7682 | activity = _activity; |
| 7683 | } |
| 7684 | |
| 7685 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7686 | StringBuilder sb = new StringBuilder(128); |
| 7687 | sb.append("ActivityIntentInfo{"); |
| 7688 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7689 | sb.append(' '); |
| 7690 | activity.appendComponentShortName(sb); |
| 7691 | sb.append('}'); |
| 7692 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7693 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7694 | |
| 7695 | public ActivityIntentInfo(Parcel in) { |
| 7696 | super(in); |
| 7697 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | } |
| 7699 | |
| 7700 | public final static class ServiceIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7701 | public Service service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | |
| 7703 | public ServiceIntentInfo(Service _service) { |
| 7704 | service = _service; |
| 7705 | } |
| 7706 | |
| 7707 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7708 | StringBuilder sb = new StringBuilder(128); |
| 7709 | sb.append("ServiceIntentInfo{"); |
| 7710 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7711 | sb.append(' '); |
| 7712 | service.appendComponentShortName(sb); |
| 7713 | sb.append('}'); |
| 7714 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7716 | |
| 7717 | public ServiceIntentInfo(Parcel in) { |
| 7718 | super(in); |
| 7719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 7721 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7722 | public static final class ProviderIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7723 | public Provider provider; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7724 | |
| 7725 | public ProviderIntentInfo(Provider provider) { |
| 7726 | this.provider = provider; |
| 7727 | } |
| 7728 | |
| 7729 | public String toString() { |
| 7730 | StringBuilder sb = new StringBuilder(128); |
| 7731 | sb.append("ProviderIntentInfo{"); |
| 7732 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7733 | sb.append(' '); |
| 7734 | provider.appendComponentShortName(sb); |
| 7735 | sb.append('}'); |
| 7736 | return sb.toString(); |
| 7737 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7738 | |
| 7739 | public ProviderIntentInfo(Parcel in) { |
| 7740 | super(in); |
| 7741 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7742 | } |
| 7743 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 7744 | /** |
| 7745 | * @hide |
| 7746 | */ |
| 7747 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 7748 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 7749 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 7750 | |
| 7751 | public static class PackageParserException extends Exception { |
| 7752 | public final int error; |
| 7753 | |
| 7754 | public PackageParserException(int error, String detailMessage) { |
| 7755 | super(detailMessage); |
| 7756 | this.error = error; |
| 7757 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 7758 | |
| 7759 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 7760 | super(detailMessage, throwable); |
| 7761 | this.error = error; |
| 7762 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 7763 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7764 | } |