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 | bebfcc4 | 2018-02-12 14:27:46 -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; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 82 | import android.util.ByteStringUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.util.DisplayMetrics; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 84 | import android.util.Log; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 85 | import android.util.PackageUtils; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 86 | import android.util.Pair; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 87 | import android.util.Slog; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 88 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.util.TypedValue; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 90 | import android.util.apk.ApkSignatureVerifier; |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 91 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 93 | import com.android.internal.R; |
| 94 | import com.android.internal.annotations.VisibleForTesting; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 95 | import com.android.internal.os.ClassLoaderFactory; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 96 | import com.android.internal.util.ArrayUtils; |
| 97 | import com.android.internal.util.XmlUtils; |
| 98 | |
| 99 | import libcore.io.IoUtils; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 100 | import libcore.util.EmptyArray; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 101 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 102 | import org.xmlpull.v1.XmlPullParser; |
| 103 | import org.xmlpull.v1.XmlPullParserException; |
| 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import java.io.File; |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 106 | import java.io.FileDescriptor; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 107 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import java.io.IOException; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 109 | import java.io.PrintWriter; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 110 | import java.lang.annotation.Retention; |
| 111 | import java.lang.annotation.RetentionPolicy; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 112 | import java.lang.reflect.Constructor; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 113 | import java.security.KeyFactory; |
| 114 | import java.security.NoSuchAlgorithmException; |
| 115 | import java.security.PublicKey; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 116 | import java.security.cert.CertificateException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 117 | import java.security.spec.EncodedKeySpec; |
| 118 | import java.security.spec.InvalidKeySpecException; |
| 119 | import java.security.spec.X509EncodedKeySpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import java.util.ArrayList; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 121 | import java.util.Arrays; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 122 | import java.util.Collections; |
| 123 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import java.util.Iterator; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 125 | import java.util.List; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 126 | import java.util.Set; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 127 | import java.util.UUID; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 128 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | |
| 130 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 131 | * Parser for package files (APKs) on disk. This supports apps packaged either |
| 132 | * as a single "monolithic" APK, or apps packaged as a "cluster" of multiple |
| 133 | * APKs in a single directory. |
| 134 | * <p> |
| 135 | * Apps packaged as multiple APKs always consist of a single "base" APK (with a |
| 136 | * {@code null} split name) and zero or more "split" APKs (with unique split |
| 137 | * names). Any subset of those split APKs are a valid install, as long as the |
| 138 | * following constraints are met: |
| 139 | * <ul> |
| 140 | * <li>All APKs must have the exact same package name, version code, and signing |
| 141 | * certificates. |
| 142 | * <li>All APKs must have unique split names. |
| 143 | * <li>All installations must contain a single base APK. |
| 144 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 146 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | */ |
| 148 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 149 | private static final boolean DEBUG_JAR = false; |
| 150 | private static final boolean DEBUG_PARSER = false; |
| 151 | private static final boolean DEBUG_BACKUP = false; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 152 | private static final boolean LOG_PARSE_TIMINGS = Build.IS_DEBUGGABLE; |
| 153 | private static final int LOG_PARSE_TIMINGS_THRESHOLD_MS = 100; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 154 | |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 155 | private static final String PROPERTY_CHILD_PACKAGES_ENABLED = |
| 156 | "persist.sys.child_packages_enabled"; |
| 157 | |
Jeff Sharkey | 3f1790d | 2017-04-25 18:56:17 -0600 | [diff] [blame] | 158 | private static final boolean MULTI_PACKAGE_APK_ENABLED = Build.IS_DEBUGGABLE && |
Garrett Boyer | 1704153 | 2017-08-01 14:11:02 -0700 | [diff] [blame] | 159 | SystemProperties.getBoolean(PROPERTY_CHILD_PACKAGES_ENABLED, false); |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 160 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 161 | private static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f; |
| 162 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 163 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 164 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 165 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 166 | /** File name in an APK for the Android manifest. */ |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 167 | public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 168 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 169 | /** Path prefix for apps on expanded storage */ |
| 170 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 171 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 172 | private static final String TAG_MANIFEST = "manifest"; |
| 173 | private static final String TAG_APPLICATION = "application"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 174 | private static final String TAG_PACKAGE_VERIFIER = "package-verifier"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 175 | private static final String TAG_OVERLAY = "overlay"; |
| 176 | private static final String TAG_KEY_SETS = "key-sets"; |
| 177 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 178 | private static final String TAG_PERMISSION = "permission"; |
| 179 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 180 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 181 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 182 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 183 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 184 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 185 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 186 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 187 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 188 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 189 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 190 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 191 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 192 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 193 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 194 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 195 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 196 | private static final String TAG_PACKAGE = "package"; |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 197 | private static final String TAG_RESTRICT_UPDATE = "restrict-update"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 198 | private static final String TAG_USES_SPLIT = "uses-split"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 199 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 200 | private static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect"; |
| 201 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 202 | /** |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 203 | * 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] | 204 | * @hide |
| 205 | */ |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 206 | private static final int RECREATE_ON_CONFIG_CHANGES_MASK = |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 207 | ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC; |
| 208 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 209 | // These are the tags supported by child packages |
| 210 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 211 | static { |
| 212 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 213 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 214 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 215 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 216 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 217 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 218 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 219 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 220 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 221 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 222 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 223 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 224 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 225 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 226 | } |
| 227 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 228 | private static final boolean LOG_UNSAFE_BROADCASTS = false; |
| 229 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Total number of packages that were read from the cache. We use it only for logging. |
| 232 | */ |
| 233 | public static final AtomicInteger sCachedPackageReadCount = new AtomicInteger(); |
| 234 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 235 | // Set of broadcast actions that are safe for manifest receivers |
| 236 | private static final Set<String> SAFE_BROADCASTS = new ArraySet<>(); |
| 237 | static { |
| 238 | SAFE_BROADCASTS.add(Intent.ACTION_BOOT_COMPLETED); |
| 239 | } |
| 240 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 241 | /** @hide */ |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 242 | public static final String APK_FILE_EXTENSION = ".apk"; |
| 243 | |
| 244 | /** @hide */ |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 245 | public static class NewPermissionInfo { |
| 246 | public final String name; |
| 247 | public final int sdkVersion; |
| 248 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 249 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 250 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 251 | this.name = name; |
| 252 | this.sdkVersion = sdkVersion; |
| 253 | this.fileVersion = fileVersion; |
| 254 | } |
| 255 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 256 | |
| 257 | /** @hide */ |
| 258 | public static class SplitPermissionInfo { |
| 259 | public final String rootPerm; |
| 260 | public final String[] newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 261 | public final int targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 262 | |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 263 | public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) { |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 264 | this.rootPerm = rootPerm; |
| 265 | this.newPerms = newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 266 | this.targetSdk = targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 270 | /** |
| 271 | * List of new permissions that have been added since 1.0. |
| 272 | * NOTE: These must be declared in SDK version order, with permissions |
| 273 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 274 | * If sdkVersion is 0, then this is not a permission that we want to |
| 275 | * automatically add to older apps, but we do want to allow it to be |
| 276 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 277 | * @hide |
| 278 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 279 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 280 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 281 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 282 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 283 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 284 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 285 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 287 | /** |
| 288 | * List of permissions that have been split into more granular or dependent |
| 289 | * permissions. |
| 290 | * @hide |
| 291 | */ |
| 292 | public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] = |
| 293 | new PackageParser.SplitPermissionInfo[] { |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 294 | // READ_EXTERNAL_STORAGE is always required when an app requests |
| 295 | // WRITE_EXTERNAL_STORAGE, because we can't have an app that has |
| 296 | // write access without read access. The hack here with the target |
| 297 | // target SDK version ensures that this grant is always done. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 298 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 299 | new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 300 | android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1), |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 301 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS, |
| 302 | new String[] { android.Manifest.permission.READ_CALL_LOG }, |
| 303 | android.os.Build.VERSION_CODES.JELLY_BEAN), |
| 304 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS, |
| 305 | new String[] { android.Manifest.permission.WRITE_CALL_LOG }, |
| 306 | android.os.Build.VERSION_CODES.JELLY_BEAN) |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 307 | }; |
| 308 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 309 | /** |
| 310 | * @deprecated callers should move to explicitly passing around source path. |
| 311 | */ |
| 312 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 316 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 317 | private DisplayMetrics mMetrics; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 318 | private Callback mCallback; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 319 | private File mCacheDir; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 320 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 321 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 322 | 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] | 323 | |
| 324 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 325 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 326 | private static boolean sCompatibilityModeEnabled = true; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 327 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 328 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 329 | private static final int PARSE_DEFAULT_TARGET_SANDBOX = 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 330 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 331 | static class ParsePackageItemArgs { |
| 332 | final Package owner; |
| 333 | final String[] outError; |
| 334 | final int nameRes; |
| 335 | final int labelRes; |
| 336 | final int iconRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 337 | final int roundIconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 338 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 339 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 340 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 341 | String tag; |
| 342 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 343 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 344 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 345 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 346 | int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 347 | owner = _owner; |
| 348 | outError = _outError; |
| 349 | nameRes = _nameRes; |
| 350 | labelRes = _labelRes; |
| 351 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 352 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 353 | bannerRes = _bannerRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 354 | roundIconRes = _roundIconRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 357 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 358 | /** @hide */ |
| 359 | @VisibleForTesting |
| 360 | public static class ParseComponentArgs extends ParsePackageItemArgs { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 361 | final String[] sepProcesses; |
| 362 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 363 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 364 | final int enabledRes; |
| 365 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 366 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 367 | public ParseComponentArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 368 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 369 | int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 370 | String[] _sepProcesses, int _processRes, |
| 371 | int _descriptionRes, int _enabledRes) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 372 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _roundIconRes, _logoRes, |
| 373 | _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 374 | sepProcesses = _sepProcesses; |
| 375 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 376 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 377 | enabledRes = _enabledRes; |
| 378 | } |
| 379 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 380 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 381 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 382 | * Lightweight parsed details about a single package. |
| 383 | */ |
| 384 | public static class PackageLite { |
| 385 | public final String packageName; |
| 386 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 387 | public final int versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 388 | public final int installLocation; |
| 389 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 390 | |
| 391 | /** Names of any split APKs, ordered by parsed splitName */ |
| 392 | public final String[] splitNames; |
| 393 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 394 | /** Names of any split APKs that are features. Ordered by splitName */ |
| 395 | public final boolean[] isFeatureSplits; |
| 396 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 397 | /** Dependencies of any split APKs, ordered by parsed splitName */ |
| 398 | public final String[] usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 399 | public final String[] configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 400 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 401 | /** |
| 402 | * Path where this package was found on disk. For monolithic packages |
| 403 | * this is path to single base APK file; for cluster packages this is |
| 404 | * path to the cluster directory. |
| 405 | */ |
| 406 | public final String codePath; |
| 407 | |
| 408 | /** Path of base APK */ |
| 409 | public final String baseCodePath; |
| 410 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 411 | public final String[] splitCodePaths; |
| 412 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 413 | /** Revision code of base APK */ |
| 414 | public final int baseRevisionCode; |
| 415 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 416 | public final int[] splitRevisionCodes; |
| 417 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 418 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 419 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 420 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 421 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 422 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 423 | public final boolean isolatedSplits; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 424 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 425 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 426 | boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 427 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 428 | this.packageName = baseApk.packageName; |
| 429 | this.versionCode = baseApk.versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 430 | this.versionCodeMajor = baseApk.versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 431 | this.installLocation = baseApk.installLocation; |
| 432 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 433 | this.splitNames = splitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 434 | this.isFeatureSplits = isFeatureSplits; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 435 | this.usesSplitNames = usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 436 | this.configForSplit = configForSplit; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 437 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 438 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 439 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 440 | this.baseRevisionCode = baseApk.revisionCode; |
| 441 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 442 | this.coreApp = baseApk.coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 443 | this.debuggable = baseApk.debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 444 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 445 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 446 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 447 | this.isolatedSplits = baseApk.isolatedSplits; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | public List<String> getAllCodePaths() { |
| 451 | ArrayList<String> paths = new ArrayList<>(); |
| 452 | paths.add(baseCodePath); |
| 453 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 454 | Collections.addAll(paths, splitCodePaths); |
| 455 | } |
| 456 | return paths; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 461 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 462 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 463 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 464 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 465 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 466 | public final String splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 467 | public boolean isFeatureSplit; |
| 468 | public final String configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 469 | public final String usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 470 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 471 | public final int versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 472 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 473 | public final int installLocation; |
| 474 | public final VerifierInfo[] verifiers; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 475 | public final SigningDetails signingDetails; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 476 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 477 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 478 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 479 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 480 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 481 | public final boolean isolatedSplits; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 482 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 483 | public ApkLite(String codePath, String packageName, String splitName, |
| 484 | boolean isFeatureSplit, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 485 | String configForSplit, String usesSplitName, int versionCode, int versionCodeMajor, |
| 486 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 487 | SigningDetails signingDetails, boolean coreApp, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 488 | boolean debuggable, boolean multiArch, boolean use32bitAbi, |
| 489 | boolean extractNativeLibs, boolean isolatedSplits) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 490 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 491 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 492 | this.splitName = splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 493 | this.isFeatureSplit = isFeatureSplit; |
| 494 | this.configForSplit = configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 495 | this.usesSplitName = usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 496 | this.versionCode = versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 497 | this.versionCodeMajor = versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 498 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 499 | this.installLocation = installLocation; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 500 | this.signingDetails = signingDetails; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 501 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 502 | this.coreApp = coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 503 | this.debuggable = debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 504 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 505 | this.use32bitAbi = use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 506 | this.extractNativeLibs = extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 507 | this.isolatedSplits = isolatedSplits; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 508 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 509 | |
| 510 | public long getLongVersionCode() { |
| 511 | return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); |
| 512 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 515 | /** |
| 516 | * Cached parse state for new components. |
| 517 | * |
| 518 | * Allows reuse of the same parse argument records to avoid GC pressure. Lifetime is carefully |
| 519 | * scoped to the parsing of a single application element. |
| 520 | */ |
| 521 | private static class CachedComponentArgs { |
| 522 | ParseComponentArgs mActivityArgs; |
| 523 | ParseComponentArgs mActivityAliasArgs; |
| 524 | ParseComponentArgs mServiceArgs; |
| 525 | ParseComponentArgs mProviderArgs; |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * Cached state for parsing instrumentation to avoid GC pressure. |
| 530 | * |
| 531 | * Must be manually reset to null for each new manifest. |
| 532 | */ |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 533 | private ParsePackageItemArgs mParseInstrumentationArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | /** If set to true, we will only allow package files that exactly match |
| 536 | * the DTD. Otherwise, we try to get as much from the package as we |
| 537 | * can without failing. This should normally be set to false, to |
| 538 | * support extensions to the DTD in future versions. */ |
| 539 | private static final boolean RIGID_PARSER = false; |
| 540 | |
| 541 | private static final String TAG = "PackageParser"; |
| 542 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 543 | public PackageParser() { |
| 544 | mMetrics = new DisplayMetrics(); |
| 545 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 546 | } |
| 547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | public void setSeparateProcesses(String[] procs) { |
| 549 | mSeparateProcesses = procs; |
| 550 | } |
| 551 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 552 | /** |
| 553 | * Flag indicating this parser should only consider apps with |
| 554 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 555 | * creating a minimalist boot environment. |
| 556 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 557 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 558 | mOnlyCoreApps = onlyCoreApps; |
| 559 | } |
| 560 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 561 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 562 | mMetrics = metrics; |
| 563 | } |
| 564 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 565 | /** |
| 566 | * Sets the cache directory for this package parser. |
| 567 | */ |
| 568 | public void setCacheDir(File cacheDir) { |
| 569 | mCacheDir = cacheDir; |
| 570 | } |
| 571 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 572 | /** |
| 573 | * Callback interface for retrieving information that may be needed while parsing |
| 574 | * a package. |
| 575 | */ |
| 576 | public interface Callback { |
| 577 | boolean hasFeature(String feature); |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 578 | String[] getOverlayPaths(String targetPackageName, String targetPath); |
| 579 | String[] getOverlayApks(String targetPackageName); |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Standard implementation of {@link Callback} on top of the public {@link PackageManager} |
| 584 | * class. |
| 585 | */ |
| 586 | public static final class CallbackImpl implements Callback { |
| 587 | private final PackageManager mPm; |
| 588 | |
| 589 | public CallbackImpl(PackageManager pm) { |
| 590 | mPm = pm; |
| 591 | } |
| 592 | |
| 593 | @Override public boolean hasFeature(String feature) { |
| 594 | return mPm.hasSystemFeature(feature); |
| 595 | } |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 596 | |
| 597 | @Override public String[] getOverlayPaths(String targetPackageName, String targetPath) { |
| 598 | return null; |
| 599 | } |
| 600 | |
| 601 | @Override public String[] getOverlayApks(String targetPackageName) { |
| 602 | return null; |
| 603 | } |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Set the {@link Callback} that can be used while parsing. |
| 608 | */ |
| 609 | public void setCallback(Callback cb) { |
| 610 | mCallback = cb; |
| 611 | } |
| 612 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 613 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 614 | return isApkPath(file.getName()); |
| 615 | } |
| 616 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 617 | public static boolean isApkPath(String path) { |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 618 | return path.endsWith(APK_FILE_EXTENSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 623 | * |
| 624 | * @param p the parsed package. |
| 625 | * @param flags indicating which optional information is included. |
| 626 | */ |
| 627 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 628 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 629 | Set<String> grantedPermissions, PackageUserState state) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 631 | return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 632 | grantedPermissions, state, UserHandle.getCallingUserId()); |
| 633 | } |
| 634 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 635 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 636 | * Returns true if the package is installed and not hidden, or if the caller |
| 637 | * explicitly wanted all uninstalled and hidden packages as well. |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 638 | * @param appInfo The applicationInfo of the app being checked. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 639 | */ |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 640 | private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state, |
| 641 | ApplicationInfo appInfo) { |
Rhed Jao | c19da78 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 642 | // Returns false if the package is hidden system app until installed. |
| 643 | if ((flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) == 0 |
| 644 | && !state.installed |
| 645 | && appInfo != null && appInfo.hiddenUntilInstalled) { |
| 646 | return false; |
| 647 | } |
| 648 | |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 649 | // If available for the target user, or trying to match uninstalled packages and it's |
| 650 | // a system app. |
| 651 | return state.isAvailable(flags) |
| 652 | || (appInfo != null && appInfo.isSystemApp() |
Rhed Jao | c19da78 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 653 | && ((flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0 |
| 654 | || (flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) != 0)); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 657 | public static boolean isAvailable(PackageUserState state) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 658 | return checkUseInstalledOrHidden(0, state, null); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 661 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 662 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 663 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 664 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 665 | return null; |
| 666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | PackageInfo pi = new PackageInfo(); |
| 668 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 669 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | pi.versionCode = p.mVersionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 671 | pi.versionCodeMajor = p.mVersionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 672 | pi.baseRevisionCode = p.baseRevisionCode; |
| 673 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | pi.versionName = p.mVersionName; |
| 675 | pi.sharedUserId = p.mSharedUserId; |
| 676 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 677 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 678 | pi.installLocation = p.installLocation; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 679 | pi.isStub = p.isStub; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 680 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 681 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 682 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 683 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 684 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 685 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 686 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 687 | pi.overlayTarget = p.mOverlayTarget; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 688 | pi.overlayCategory = p.mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 689 | pi.overlayPriority = p.mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 690 | pi.mOverlayIsStatic = p.mOverlayIsStatic; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 691 | pi.compileSdkVersion = p.mCompileSdkVersion; |
| 692 | pi.compileSdkVersionCodename = p.mCompileSdkVersionCodename; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 693 | pi.firstInstallTime = firstInstallTime; |
| 694 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 696 | pi.gids = gids; |
| 697 | } |
| 698 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 699 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | if (N > 0) { |
| 701 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 702 | p.configPreferences.toArray(pi.configPreferences); |
| 703 | } |
| 704 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 705 | if (N > 0) { |
| 706 | pi.reqFeatures = new FeatureInfo[N]; |
| 707 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 709 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 710 | if (N > 0) { |
| 711 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 712 | p.featureGroups.toArray(pi.featureGroups); |
| 713 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 715 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 716 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 718 | int num = 0; |
| 719 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 720 | for (int i = 0; i < N; i++) { |
| 721 | final Activity a = p.activities.get(i); |
| 722 | if (state.isMatch(a.info, flags)) { |
| 723 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | } |
| 725 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 726 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | } |
| 728 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 729 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 730 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 732 | int num = 0; |
| 733 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 734 | for (int i = 0; i < N; i++) { |
| 735 | final Activity a = p.receivers.get(i); |
| 736 | if (state.isMatch(a.info, flags)) { |
| 737 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | } |
| 739 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 740 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 743 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 744 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 746 | int num = 0; |
| 747 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 748 | for (int i = 0; i < N; i++) { |
| 749 | final Service s = p.services.get(i); |
| 750 | if (state.isMatch(s.info, flags)) { |
| 751 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | } |
| 753 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 754 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | } |
| 756 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 757 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 758 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 760 | int num = 0; |
| 761 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 762 | for (int i = 0; i < N; i++) { |
| 763 | final Provider pr = p.providers.get(i); |
| 764 | if (state.isMatch(pr.info, flags)) { |
| 765 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | } |
| 767 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 768 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 772 | int N = p.instrumentation.size(); |
| 773 | if (N > 0) { |
| 774 | pi.instrumentation = new InstrumentationInfo[N]; |
| 775 | for (int i=0; i<N; i++) { |
| 776 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 777 | p.instrumentation.get(i), flags); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 782 | int N = p.permissions.size(); |
| 783 | if (N > 0) { |
| 784 | pi.permissions = new PermissionInfo[N]; |
| 785 | for (int i=0; i<N; i++) { |
| 786 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 787 | } |
| 788 | } |
| 789 | N = p.requestedPermissions.size(); |
| 790 | if (N > 0) { |
| 791 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 792 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 794 | final String perm = p.requestedPermissions.get(i); |
| 795 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 796 | // The notion of required permissions is deprecated but for compatibility. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 797 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 798 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
| 799 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
| 800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 804 | // deprecated method of getting signing certificates |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 806 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 807 | // Package has included signing certificate rotation information. Return the oldest |
| 808 | // cert so that programmatic checks keep working even if unaware of key rotation. |
| 809 | pi.signatures = new Signature[1]; |
| 810 | pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0]; |
| 811 | } else if (p.mSigningDetails.hasSignatures()) { |
| 812 | // otherwise keep old behavior |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 813 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 814 | pi.signatures = new Signature[numberOfSigs]; |
| 815 | 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] | 816 | } |
| 817 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 818 | |
| 819 | // replacement for GET_SIGNATURES |
| 820 | if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) { |
Dan Cashman | 5c9f527e | 2018-04-03 16:42:23 -0700 | [diff] [blame] | 821 | if (p.mSigningDetails != SigningDetails.UNKNOWN) { |
| 822 | // only return a valid SigningInfo if there is signing information to report |
| 823 | pi.signingInfo = new SigningInfo(p.mSigningDetails); |
| 824 | } else { |
| 825 | pi.signingInfo = null; |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 826 | } |
| 827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | return pi; |
| 829 | } |
| 830 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 831 | public static final int PARSE_MUST_BE_APK = 1 << 0; |
| 832 | public static final int PARSE_IGNORE_PROCESSES = 1 << 1; |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 833 | /** @deprecated forward lock no longer functional. remove. */ |
| 834 | @Deprecated |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 835 | public static final int PARSE_FORWARD_LOCK = 1 << 2; |
| 836 | public static final int PARSE_EXTERNAL_STORAGE = 1 << 3; |
| 837 | public static final int PARSE_IS_SYSTEM_DIR = 1 << 4; |
| 838 | public static final int PARSE_COLLECT_CERTIFICATES = 1 << 5; |
| 839 | public static final int PARSE_ENFORCE_CODE = 1 << 6; |
| 840 | public static final int PARSE_FORCE_SDK = 1 << 7; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 841 | public static final int PARSE_CHATTY = 1 << 31; |
| 842 | |
| 843 | @IntDef(flag = true, prefix = { "PARSE_" }, value = { |
| 844 | PARSE_CHATTY, |
| 845 | PARSE_COLLECT_CERTIFICATES, |
| 846 | PARSE_ENFORCE_CODE, |
| 847 | PARSE_EXTERNAL_STORAGE, |
| 848 | PARSE_FORCE_SDK, |
| 849 | PARSE_FORWARD_LOCK, |
| 850 | PARSE_IGNORE_PROCESSES, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 851 | PARSE_IS_SYSTEM_DIR, |
| 852 | PARSE_MUST_BE_APK, |
| 853 | }) |
| 854 | @Retention(RetentionPolicy.SOURCE) |
| 855 | public @interface ParseFlags {} |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 856 | |
| 857 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 859 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 860 | * Used to sort a set of APKs based on their split names, always placing the |
| 861 | * base APK (with {@code null} split name) first. |
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 | private static class SplitNameComparator implements Comparator<String> { |
| 864 | @Override |
| 865 | public int compare(String lhs, String rhs) { |
| 866 | if (lhs == null) { |
| 867 | return -1; |
| 868 | } else if (rhs == null) { |
| 869 | return 1; |
| 870 | } else { |
| 871 | return lhs.compareTo(rhs); |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 876 | /** |
| 877 | * Parse only lightweight details about the package at the given location. |
| 878 | * Automatically detects if the package is a monolithic style (single APK |
| 879 | * file) or cluster style (directory of APKs). |
| 880 | * <p> |
| 881 | * This performs sanity checking on cluster style packages, such as |
| 882 | * requiring identical package name and version codes, a single base APK, |
| 883 | * and unique split names. |
| 884 | * |
| 885 | * @see PackageParser#parsePackage(File, int) |
| 886 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 887 | public static PackageLite parsePackageLite(File packageFile, int flags) |
| 888 | throws PackageParserException { |
| 889 | if (packageFile.isDirectory()) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 890 | return parseClusterPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 891 | } else { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 892 | return parseMonolithicPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 896 | private static PackageLite parseMonolithicPackageLite(File packageFile, int flags) |
| 897 | throws PackageParserException { |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 898 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 899 | final ApkLite baseApk = parseApkLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 900 | final String packagePath = packageFile.getAbsolutePath(); |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 901 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 902 | return new PackageLite(packagePath, baseApk, null, null, null, null, null, null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 905 | static PackageLite parseClusterPackageLite(File packageDir, int flags) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 906 | throws PackageParserException { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 907 | final File[] files = packageDir.listFiles(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 908 | if (ArrayUtils.isEmpty(files)) { |
| 909 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 910 | "No packages found in split"); |
| 911 | } |
| 912 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 913 | String packageName = null; |
| 914 | int versionCode = 0; |
| 915 | |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 916 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 917 | final ArrayMap<String, ApkLite> apks = new ArrayMap<>(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 918 | for (File file : files) { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 919 | if (isApkFile(file)) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 920 | final ApkLite lite = parseApkLite(file, flags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 921 | |
| 922 | // Assert that all package names and version codes are |
| 923 | // consistent with the first one we encounter. |
| 924 | if (packageName == null) { |
| 925 | packageName = lite.packageName; |
| 926 | versionCode = lite.versionCode; |
| 927 | } else { |
| 928 | if (!packageName.equals(lite.packageName)) { |
| 929 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 930 | "Inconsistent package " + lite.packageName + " in " + file |
| 931 | + "; expected " + packageName); |
| 932 | } |
| 933 | if (versionCode != lite.versionCode) { |
| 934 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 935 | "Inconsistent version " + lite.versionCode + " in " + file |
| 936 | + "; expected " + versionCode); |
| 937 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 940 | // Assert that each split is defined only once |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 941 | if (apks.put(lite.splitName, lite) != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 942 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 943 | "Split name " + lite.splitName |
| 944 | + " defined more than once; most recent was " + file); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | } |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 948 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 949 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 950 | final ApkLite baseApk = apks.remove(null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 951 | if (baseApk == null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 952 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 953 | "Missing base APK in " + packageDir); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 956 | // Always apply deterministic ordering based on splitName |
| 957 | final int size = apks.size(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 958 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 959 | String[] splitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 960 | boolean[] isFeatureSplits = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 961 | String[] usesSplitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 962 | String[] configForSplits = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 963 | String[] splitCodePaths = null; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 964 | int[] splitRevisionCodes = null; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 965 | String[] splitClassLoaderNames = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 966 | if (size > 0) { |
| 967 | splitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 968 | isFeatureSplits = new boolean[size]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 969 | usesSplitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 970 | configForSplits = new String[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 971 | splitCodePaths = new String[size]; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 972 | splitRevisionCodes = new int[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 973 | |
| 974 | splitNames = apks.keySet().toArray(splitNames); |
| 975 | Arrays.sort(splitNames, sSplitNameComparator); |
| 976 | |
| 977 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 978 | final ApkLite apk = apks.get(splitNames[i]); |
| 979 | usesSplitNames[i] = apk.usesSplitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 980 | isFeatureSplits[i] = apk.isFeatureSplit; |
| 981 | configForSplits[i] = apk.configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 982 | splitCodePaths[i] = apk.codePath; |
| 983 | splitRevisionCodes[i] = apk.revisionCode; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 984 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 987 | final String codePath = packageDir.getAbsolutePath(); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 988 | return new PackageLite(codePath, baseApk, splitNames, isFeatureSplits, usesSplitNames, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 989 | configForSplits, splitCodePaths, splitRevisionCodes); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 992 | /** |
| 993 | * Parse the package at the given location. Automatically detects if the |
| 994 | * package is a monolithic style (single APK file) or cluster style |
| 995 | * (directory of APKs). |
| 996 | * <p> |
| 997 | * This performs sanity checking on cluster style packages, such as |
| 998 | * requiring identical package name and version codes, a single base APK, |
| 999 | * and unique split names. |
| 1000 | * <p> |
| 1001 | * Note that this <em>does not</em> perform signature verification; that |
| 1002 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1003 | * |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1004 | * If {@code useCaches} is true, the package parser might return a cached |
| 1005 | * result from a previous parse of the same {@code packageFile} with the same |
| 1006 | * {@code flags}. Note that this method does not check whether {@code packageFile} |
| 1007 | * has changed since the last parse, it's up to callers to do so. |
| 1008 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1009 | * @see #parsePackageLite(File, int) |
| 1010 | */ |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1011 | public Package parsePackage(File packageFile, int flags, boolean useCaches) |
| 1012 | throws PackageParserException { |
| 1013 | Package parsed = useCaches ? getCachedResult(packageFile, flags) : null; |
| 1014 | if (parsed != null) { |
| 1015 | return parsed; |
| 1016 | } |
| 1017 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1018 | long parseTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1019 | if (packageFile.isDirectory()) { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1020 | parsed = parseClusterPackage(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1021 | } else { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1022 | parsed = parseMonolithicPackage(packageFile, flags); |
| 1023 | } |
| 1024 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1025 | long cacheTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1026 | cacheResult(packageFile, flags, parsed); |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1027 | if (LOG_PARSE_TIMINGS) { |
| 1028 | parseTime = cacheTime - parseTime; |
| 1029 | cacheTime = SystemClock.uptimeMillis() - cacheTime; |
| 1030 | if (parseTime + cacheTime > LOG_PARSE_TIMINGS_THRESHOLD_MS) { |
| 1031 | Slog.i(TAG, "Parse times for '" + packageFile + "': parse=" + parseTime |
| 1032 | + "ms, update_cache=" + cacheTime + " ms"); |
| 1033 | } |
| 1034 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1035 | return parsed; |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Equivalent to {@link #parsePackage(File, int, boolean)} with {@code useCaches == false}. |
| 1040 | */ |
| 1041 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 1042 | return parsePackage(packageFile, flags, false /* useCaches */); |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Returns the cache key for a specificied {@code packageFile} and {@code flags}. |
| 1047 | */ |
| 1048 | private String getCacheKey(File packageFile, int flags) { |
| 1049 | StringBuilder sb = new StringBuilder(packageFile.getName()); |
| 1050 | sb.append('-'); |
| 1051 | sb.append(flags); |
| 1052 | |
| 1053 | return sb.toString(); |
| 1054 | } |
| 1055 | |
| 1056 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1057 | protected Package fromCacheEntry(byte[] bytes) { |
| 1058 | return fromCacheEntryStatic(bytes); |
| 1059 | } |
| 1060 | |
| 1061 | /** static version of {@link #fromCacheEntry} for unit tests. */ |
| 1062 | @VisibleForTesting |
| 1063 | public static Package fromCacheEntryStatic(byte[] bytes) { |
| 1064 | final Parcel p = Parcel.obtain(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1065 | p.unmarshall(bytes, 0, bytes.length); |
| 1066 | p.setDataPosition(0); |
| 1067 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1068 | final ReadHelper helper = new ReadHelper(p); |
| 1069 | helper.startAndInstall(); |
| 1070 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1071 | PackageParser.Package pkg = new PackageParser.Package(p); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1072 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1073 | p.recycle(); |
| 1074 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1075 | sCachedPackageReadCount.incrementAndGet(); |
| 1076 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1077 | return pkg; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1081 | protected byte[] toCacheEntry(Package pkg) { |
| 1082 | return toCacheEntryStatic(pkg); |
| 1083 | |
| 1084 | } |
| 1085 | |
| 1086 | /** static version of {@link #toCacheEntry} for unit tests. */ |
| 1087 | @VisibleForTesting |
| 1088 | public static byte[] toCacheEntryStatic(Package pkg) { |
| 1089 | final Parcel p = Parcel.obtain(); |
| 1090 | final WriteHelper helper = new WriteHelper(p); |
| 1091 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1092 | pkg.writeToParcel(p, 0 /* flags */); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1093 | |
| 1094 | helper.finishAndUninstall(); |
| 1095 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1096 | byte[] serialized = p.marshall(); |
| 1097 | p.recycle(); |
| 1098 | |
| 1099 | return serialized; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * Given a {@code packageFile} and a {@code cacheFile} returns whether the |
| 1104 | * cache file is up to date based on the mod-time of both files. |
| 1105 | */ |
| 1106 | private static boolean isCacheUpToDate(File packageFile, File cacheFile) { |
| 1107 | try { |
| 1108 | // NOTE: We don't use the File.lastModified API because it has the very |
| 1109 | // non-ideal failure mode of returning 0 with no excepions thrown. |
| 1110 | // The nio2 Files API is a little better but is considerably more expensive. |
| 1111 | final StructStat pkg = android.system.Os.stat(packageFile.getAbsolutePath()); |
| 1112 | final StructStat cache = android.system.Os.stat(cacheFile.getAbsolutePath()); |
| 1113 | return pkg.st_mtime < cache.st_mtime; |
| 1114 | } catch (ErrnoException ee) { |
| 1115 | // The most common reason why stat fails is that a given cache file doesn't |
| 1116 | // exist. We ignore that here. It's easy to reason that it's safe to say the |
| 1117 | // cache isn't up to date if we see any sort of exception here. |
| 1118 | // |
| 1119 | // (1) Exception while stating the package file : This should never happen, |
| 1120 | // and if it does, we do a full package parse (which is likely to throw the |
| 1121 | // same exception). |
| 1122 | // (2) Exception while stating the cache file : If the file doesn't exist, the |
| 1123 | // cache is obviously out of date. If the file *does* exist, we can't read it. |
| 1124 | // We will attempt to delete and recreate it after parsing the package. |
| 1125 | if (ee.errno != OsConstants.ENOENT) { |
| 1126 | Slog.w("Error while stating package cache : ", ee); |
| 1127 | } |
| 1128 | |
| 1129 | return false; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * Returns the cached parse result for {@code packageFile} for parse flags {@code flags}, |
| 1135 | * or {@code null} if no cached result exists. |
| 1136 | */ |
| 1137 | private Package getCachedResult(File packageFile, int flags) { |
| 1138 | if (mCacheDir == null) { |
| 1139 | return null; |
| 1140 | } |
| 1141 | |
| 1142 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1143 | final File cacheFile = new File(mCacheDir, cacheKey); |
| 1144 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1145 | try { |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1146 | // If the cache is not up to date, return null. |
| 1147 | if (!isCacheUpToDate(packageFile, cacheFile)) { |
| 1148 | return null; |
| 1149 | } |
| 1150 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1151 | final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath()); |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1152 | Package p = fromCacheEntry(bytes); |
| 1153 | if (mCallback != null) { |
| 1154 | String[] overlayApks = mCallback.getOverlayApks(p.packageName); |
| 1155 | if (overlayApks != null && overlayApks.length > 0) { |
| 1156 | for (String overlayApk : overlayApks) { |
| 1157 | // If a static RRO is updated, return null. |
| 1158 | if (!isCacheUpToDate(new File(overlayApk), cacheFile)) { |
| 1159 | return null; |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | return p; |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1165 | } catch (Throwable e) { |
Narayan Kamath | 21a2838 | 2017-01-13 10:34:29 +0000 | [diff] [blame] | 1166 | Slog.w(TAG, "Error reading package cache: ", e); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1167 | |
| 1168 | // If something went wrong while reading the cache entry, delete the cache file |
| 1169 | // so that we regenerate it the next time. |
| 1170 | cacheFile.delete(); |
| 1171 | return null; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Caches the parse result for {@code packageFile} with flags {@code flags}. |
| 1177 | */ |
| 1178 | private void cacheResult(File packageFile, int flags, Package parsed) { |
| 1179 | if (mCacheDir == null) { |
| 1180 | return; |
| 1181 | } |
| 1182 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1183 | try { |
| 1184 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1185 | final File cacheFile = new File(mCacheDir, cacheKey); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1186 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1187 | if (cacheFile.exists()) { |
| 1188 | if (!cacheFile.delete()) { |
| 1189 | Slog.e(TAG, "Unable to delete cache file: " + cacheFile); |
| 1190 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1191 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1192 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1193 | final byte[] cacheEntry = toCacheEntry(parsed); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1194 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1195 | if (cacheEntry == null) { |
| 1196 | return; |
| 1197 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1198 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1199 | try (FileOutputStream fos = new FileOutputStream(cacheFile)) { |
| 1200 | fos.write(cacheEntry); |
| 1201 | } catch (IOException ioe) { |
| 1202 | Slog.w(TAG, "Error writing cache entry.", ioe); |
| 1203 | cacheFile.delete(); |
| 1204 | } |
| 1205 | } catch (Throwable e) { |
| 1206 | Slog.w(TAG, "Error saving package cache.", e); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Parse all APKs contained in the given directory, treating them as a |
| 1212 | * single package. This also performs sanity checking, such as requiring |
| 1213 | * identical package name and version codes, a single base APK, and unique |
| 1214 | * split names. |
| 1215 | * <p> |
| 1216 | * Note that this <em>does not</em> perform signature verification; that |
| 1217 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1218 | */ |
| 1219 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1220 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1221 | if (mOnlyCoreApps && !lite.coreApp) { |
| 1222 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1223 | "Not a coreApp: " + packageDir); |
| 1224 | } |
| 1225 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1226 | // Build the split dependency tree. |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1227 | SparseArray<int[]> splitDependencies = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1228 | final SplitAssetLoader assetLoader; |
| 1229 | if (lite.isolatedSplits && !ArrayUtils.isEmpty(lite.splitNames)) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1230 | try { |
| 1231 | splitDependencies = SplitAssetDependencyLoader.createDependenciesFromPackage(lite); |
| 1232 | assetLoader = new SplitAssetDependencyLoader(lite, splitDependencies, flags); |
| 1233 | } catch (SplitAssetDependencyLoader.IllegalDependencyException e) { |
| 1234 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, e.getMessage()); |
| 1235 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1236 | } else { |
| 1237 | assetLoader = new DefaultSplitAssetLoader(lite, flags); |
| 1238 | } |
| 1239 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1240 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1241 | final AssetManager assets = assetLoader.getBaseAssetManager(); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1242 | final File baseApk = new File(lite.baseCodePath); |
| 1243 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 1244 | if (pkg == null) { |
| 1245 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1246 | "Failed to parse base APK: " + baseApk); |
| 1247 | } |
| 1248 | |
| 1249 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 1250 | final int num = lite.splitNames.length; |
| 1251 | pkg.splitNames = lite.splitNames; |
| 1252 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1253 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1254 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1255 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1256 | pkg.applicationInfo.splitNames = pkg.splitNames; |
| 1257 | pkg.applicationInfo.splitDependencies = splitDependencies; |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 1258 | pkg.applicationInfo.splitClassLoaderNames = new String[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1259 | |
| 1260 | for (int i = 0; i < num; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1261 | final AssetManager splitAssets = assetLoader.getSplitAssetManager(i); |
| 1262 | parseSplitApk(pkg, i, splitAssets, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1266 | pkg.setCodePath(packageDir.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1267 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1268 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1269 | } catch (IOException e) { |
| 1270 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1271 | "Failed to get path: " + lite.baseCodePath, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1272 | } finally { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1273 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1274 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1277 | /** |
| 1278 | * Parse the given APK file, treating it as as a single monolithic package. |
| 1279 | * <p> |
| 1280 | * Note that this <em>does not</em> perform signature verification; that |
| 1281 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1282 | * |
| 1283 | * @deprecated external callers should move to |
| 1284 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 1285 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1286 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1287 | @Deprecated |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1288 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1289 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1290 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1291 | if (!lite.coreApp) { |
| 1292 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1293 | "Not a coreApp: " + apkFile); |
| 1294 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1295 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1296 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1297 | final SplitAssetLoader assetLoader = new DefaultSplitAssetLoader(lite, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1298 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1299 | final Package pkg = parseBaseApk(apkFile, assetLoader.getBaseAssetManager(), flags); |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1300 | pkg.setCodePath(apkFile.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1301 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1302 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1303 | } catch (IOException e) { |
| 1304 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1305 | "Failed to get path: " + apkFile, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1306 | } finally { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1307 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1308 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1311 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 1312 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1313 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1314 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1315 | String volumeUuid = null; |
| 1316 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 1317 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 1318 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 1319 | } |
| 1320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1322 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1323 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1324 | 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] | 1325 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1326 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1328 | final int cookie = assets.findCookieForPath(apkPath); |
| 1329 | if (cookie == 0) { |
| 1330 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1331 | "Failed adding asset path: " + apkPath); |
| 1332 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1333 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1334 | final Resources res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1335 | |
| 1336 | final String[] outError = new String[1]; |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1337 | final Package pkg = parseBaseApk(apkPath, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1338 | if (pkg == null) { |
| 1339 | throw new PackageParserException(mParseError, |
| 1340 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1342 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1343 | pkg.setVolumeUuid(volumeUuid); |
| 1344 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 1345 | pkg.setBaseCodePath(apkPath); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1346 | pkg.setSigningDetails(SigningDetails.UNKNOWN); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1347 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1348 | return pkg; |
| 1349 | |
| 1350 | } catch (PackageParserException e) { |
| 1351 | throw e; |
| 1352 | } catch (Exception e) { |
| 1353 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1354 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1355 | } finally { |
| 1356 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1360 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1361 | throws PackageParserException { |
| 1362 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1363 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1364 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 1365 | mArchiveSourcePath = apkPath; |
| 1366 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1367 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 1368 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1369 | final Resources res; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1370 | XmlResourceParser parser = null; |
| 1371 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1372 | // This must always succeed, as the path has been added to the AssetManager before. |
| 1373 | final int cookie = assets.findCookieForPath(apkPath); |
| 1374 | if (cookie == 0) { |
| 1375 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1376 | "Failed adding asset path: " + apkPath); |
| 1377 | } |
| 1378 | |
Adam Lesinski | 56c82be | 2018-02-09 11:02:04 -0800 | [diff] [blame] | 1379 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1380 | res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1381 | |
| 1382 | final String[] outError = new String[1]; |
| 1383 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 1384 | if (pkg == null) { |
| 1385 | throw new PackageParserException(mParseError, |
| 1386 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 1387 | } |
| 1388 | |
| 1389 | } catch (PackageParserException e) { |
| 1390 | throw e; |
| 1391 | } catch (Exception e) { |
| 1392 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1393 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1394 | } finally { |
| 1395 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | /** |
| 1400 | * Parse the manifest of a <em>split APK</em>. |
| 1401 | * <p> |
| 1402 | * Note that split APKs have many more restrictions on what they're capable |
| 1403 | * of doing, so many valid features of a base APK have been carefully |
| 1404 | * omitted here. |
| 1405 | */ |
| 1406 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1407 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1408 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1409 | AttributeSet attrs = parser; |
| 1410 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1411 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1412 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1413 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1414 | mParseInstrumentationArgs = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1415 | |
| 1416 | int type; |
| 1417 | |
| 1418 | boolean foundApp = false; |
| 1419 | |
| 1420 | int outerDepth = parser.getDepth(); |
| 1421 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1422 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1423 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1424 | continue; |
| 1425 | } |
| 1426 | |
| 1427 | String tagName = parser.getName(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1428 | if (tagName.equals(TAG_APPLICATION)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1429 | if (foundApp) { |
| 1430 | if (RIGID_PARSER) { |
| 1431 | outError[0] = "<manifest> has more than one <application>"; |
| 1432 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1433 | return null; |
| 1434 | } else { |
| 1435 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1436 | XmlUtils.skipCurrentTag(parser); |
| 1437 | continue; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1442 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1443 | return null; |
| 1444 | } |
| 1445 | |
| 1446 | } else if (RIGID_PARSER) { |
| 1447 | outError[0] = "Bad element under <manifest>: " |
| 1448 | + parser.getName(); |
| 1449 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1450 | return null; |
| 1451 | |
| 1452 | } else { |
| 1453 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1454 | + " at " + mArchiveSourcePath + " " |
| 1455 | + parser.getPositionDescription()); |
| 1456 | XmlUtils.skipCurrentTag(parser); |
| 1457 | continue; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | if (!foundApp) { |
| 1462 | outError[0] = "<manifest> does not contain an <application>"; |
| 1463 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1464 | } |
| 1465 | |
| 1466 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1469 | /** Parses the public keys from the set of signatures. */ |
| 1470 | public static ArraySet<PublicKey> toSigningKeys(Signature[] signatures) |
| 1471 | throws CertificateException { |
| 1472 | ArraySet<PublicKey> keys = new ArraySet<>(signatures.length); |
| 1473 | for (int i = 0; i < signatures.length; i++) { |
| 1474 | keys.add(signatures[i].getPublicKey()); |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1475 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1476 | return keys; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1480 | * Collect certificates from all the APKs described in the given package, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1481 | * populating {@link Package#mSigningDetails}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1482 | * contents are signed correctly and consistently. |
| 1483 | */ |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1484 | public static void collectCertificates(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1485 | throws PackageParserException { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1486 | collectCertificatesInternal(pkg, skipVerify); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1487 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1488 | for (int i = 0; i < childCount; i++) { |
| 1489 | Package childPkg = pkg.childPackages.get(i); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1490 | childPkg.mSigningDetails = pkg.mSigningDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1494 | private static void collectCertificatesInternal(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1495 | throws PackageParserException { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1496 | pkg.mSigningDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1497 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1498 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1499 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1500 | collectCertificates(pkg, new File(pkg.baseCodePath), skipVerify); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1501 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1502 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
| 1503 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1504 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1505 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1506 | } |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1507 | } finally { |
| 1508 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1512 | private static void collectCertificates(Package pkg, File apkFile, boolean skipVerify) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1513 | throws PackageParserException { |
| 1514 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1516 | int minSignatureScheme = SigningDetails.SignatureSchemeVersion.JAR; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1517 | if (pkg.applicationInfo.isStaticSharedLibrary()) { |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1518 | // must use v2 signing scheme |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1519 | minSignatureScheme = SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1520 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1521 | SigningDetails verified; |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1522 | if (skipVerify) { |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1523 | // systemDir APKs are already trusted, save time by not verifying |
| 1524 | verified = ApkSignatureVerifier.plsCertsNoVerifyOnlyCerts( |
| 1525 | apkPath, minSignatureScheme); |
| 1526 | } else { |
| 1527 | verified = ApkSignatureVerifier.verify(apkPath, minSignatureScheme); |
| 1528 | } |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1529 | |
| 1530 | // Verify that entries are signed consistently with the first pkg |
| 1531 | // we encountered. Note that for splits, certificates may have |
| 1532 | // already been populated during an earlier parse of a base APK. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1533 | if (pkg.mSigningDetails == SigningDetails.UNKNOWN) { |
| 1534 | pkg.mSigningDetails = verified; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1535 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1536 | if (!Signature.areExactMatch(pkg.mSigningDetails.signatures, verified.signatures)) { |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1537 | throw new PackageParserException( |
| 1538 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1539 | apkPath + " has mismatched certificates"); |
| 1540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1544 | private static AssetManager newConfiguredAssetManager() { |
| 1545 | AssetManager assetManager = new AssetManager(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 1546 | 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] | 1547 | Build.VERSION.RESOURCES_SDK_INT); |
| 1548 | return assetManager; |
| 1549 | } |
| 1550 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1551 | /** |
| 1552 | * Utility method that retrieves lightweight details about a single APK |
| 1553 | * file, including package name, split name, and install location. |
| 1554 | * |
| 1555 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1556 | * @param flags optional parse flags, such as |
| 1557 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1558 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1559 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1560 | throws PackageParserException { |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 1561 | return parseApkLiteInner(apkFile, null, null, flags); |
| 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * Utility method that retrieves lightweight details about a single APK |
| 1566 | * file, including package name, split name, and install location. |
| 1567 | * |
| 1568 | * @param fd already open file descriptor of an apk file |
| 1569 | * @param debugPathName arbitrary text name for this file, for debug output |
| 1570 | * @param flags optional parse flags, such as |
| 1571 | * {@link #PARSE_COLLECT_CERTIFICATES} |
| 1572 | */ |
| 1573 | public static ApkLite parseApkLite(FileDescriptor fd, String debugPathName, int flags) |
| 1574 | throws PackageParserException { |
| 1575 | return parseApkLiteInner(null, fd, debugPathName, flags); |
| 1576 | } |
| 1577 | |
| 1578 | private static ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd, String debugPathName, |
| 1579 | int flags) throws PackageParserException { |
| 1580 | final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1581 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1582 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1584 | final ApkAssets apkAssets; |
| 1585 | try { |
| 1586 | apkAssets = fd != null |
| 1587 | ? ApkAssets.loadFromFd(fd, debugPathName, false, false) |
| 1588 | : ApkAssets.loadFromPath(apkPath); |
| 1589 | } catch (IOException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1590 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1591 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1594 | parser = apkAssets.openXml(ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1595 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1596 | final SigningDetails signingDetails; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1597 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1598 | // TODO: factor signature related items out of Package object |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1599 | final Package tempPkg = new Package((String) null); |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1600 | final boolean skipVerify = (flags & PARSE_IS_SYSTEM_DIR) != 0; |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1601 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1602 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1603 | collectCertificates(tempPkg, apkFile, skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1604 | } finally { |
| 1605 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1606 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1607 | signingDetails = tempPkg.mSigningDetails; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1608 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1609 | signingDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1610 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1611 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1612 | final AttributeSet attrs = parser; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1613 | return parseApkLite(apkPath, parser, attrs, signingDetails); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1614 | |
| 1615 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 1616 | Slog.w(TAG, "Failed to parse " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1617 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1618 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1620 | IoUtils.closeQuietly(parser); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1621 | // TODO(b/72056911): Implement and call close() on ApkAssets. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1625 | private static String validateName(String name, boolean requireSeparator, |
| 1626 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | final int N = name.length(); |
| 1628 | boolean hasSep = false; |
| 1629 | boolean front = true; |
| 1630 | for (int i=0; i<N; i++) { |
| 1631 | final char c = name.charAt(i); |
| 1632 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1633 | front = false; |
| 1634 | continue; |
| 1635 | } |
| 1636 | if (!front) { |
| 1637 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1638 | continue; |
| 1639 | } |
| 1640 | } |
| 1641 | if (c == '.') { |
| 1642 | hasSep = true; |
| 1643 | front = true; |
| 1644 | continue; |
| 1645 | } |
| 1646 | return "bad character '" + c + "'"; |
| 1647 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1648 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1649 | return "Invalid filename"; |
| 1650 | } |
| 1651 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | ? null : "must have at least one '.' separator"; |
| 1653 | } |
| 1654 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1655 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1656 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1657 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | |
| 1659 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1660 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1661 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | } |
| 1663 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1664 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1665 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1666 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1668 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1669 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1670 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | } |
| 1672 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1673 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1674 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1675 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1676 | if (error != null) { |
| 1677 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1678 | "Invalid manifest package: " + error); |
| 1679 | } |
| 1680 | } |
| 1681 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1682 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1683 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1684 | if (splitName.length() == 0) { |
| 1685 | splitName = null; |
| 1686 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1687 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1688 | if (error != null) { |
| 1689 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1690 | "Invalid manifest split: " + error); |
| 1691 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | return Pair.create(packageName.intern(), |
| 1696 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | } |
| 1698 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1699 | private static ApkLite parseApkLite(String codePath, XmlPullParser parser, AttributeSet attrs, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1700 | SigningDetails signingDetails) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1701 | throws IOException, XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1702 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1703 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1704 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1705 | int versionCode = 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1706 | int versionCodeMajor = 0; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1707 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1708 | boolean coreApp = false; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1709 | boolean debuggable = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1710 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1711 | boolean use32bitAbi = false; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1712 | boolean extractNativeLibs = true; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1713 | boolean isolatedSplits = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1714 | boolean isFeatureSplit = false; |
| 1715 | String configForSplit = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1716 | String usesSplitName = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1717 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1718 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1719 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1720 | if (attr.equals("installLocation")) { |
| 1721 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1722 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1723 | } else if (attr.equals("versionCode")) { |
| 1724 | versionCode = attrs.getAttributeIntValue(i, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1725 | } else if (attr.equals("versionCodeMajor")) { |
| 1726 | versionCodeMajor = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1727 | } else if (attr.equals("revisionCode")) { |
| 1728 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1729 | } else if (attr.equals("coreApp")) { |
| 1730 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1731 | } else if (attr.equals("isolatedSplits")) { |
| 1732 | isolatedSplits = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1733 | } else if (attr.equals("configForSplit")) { |
| 1734 | configForSplit = attrs.getAttributeValue(i); |
| 1735 | } else if (attr.equals("isFeatureSplit")) { |
| 1736 | isFeatureSplit = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1737 | } |
| 1738 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1739 | |
| 1740 | // Only search the tree when the tag is directly below <manifest> |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1741 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1742 | final int searchDepth = parser.getDepth() + 1; |
| 1743 | |
| 1744 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1745 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1746 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1747 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1748 | continue; |
| 1749 | } |
| 1750 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1751 | if (parser.getDepth() != searchDepth) { |
| 1752 | continue; |
| 1753 | } |
| 1754 | |
| 1755 | if (TAG_PACKAGE_VERIFIER.equals(parser.getName())) { |
| 1756 | final VerifierInfo verifier = parseVerifier(attrs); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1757 | if (verifier != null) { |
| 1758 | verifiers.add(verifier); |
| 1759 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1760 | } else if (TAG_APPLICATION.equals(parser.getName())) { |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1761 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1762 | final String attr = attrs.getAttributeName(i); |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1763 | if ("debuggable".equals(attr)) { |
| 1764 | debuggable = attrs.getAttributeBooleanValue(i, false); |
| 1765 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1766 | if ("multiArch".equals(attr)) { |
| 1767 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1768 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1769 | if ("use32bitAbi".equals(attr)) { |
| 1770 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1771 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1772 | if ("extractNativeLibs".equals(attr)) { |
| 1773 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1774 | } |
| 1775 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1776 | } else if (TAG_USES_SPLIT.equals(parser.getName())) { |
| 1777 | if (usesSplitName != null) { |
| 1778 | Slog.w(TAG, "Only one <uses-split> permitted. Ignoring others."); |
| 1779 | continue; |
| 1780 | } |
| 1781 | |
| 1782 | usesSplitName = attrs.getAttributeValue(ANDROID_RESOURCES, "name"); |
| 1783 | if (usesSplitName == null) { |
| 1784 | throw new PackageParserException( |
| 1785 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1786 | "<uses-split> tag requires 'android:name' attribute"); |
| 1787 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1788 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1791 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, isFeatureSplit, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1792 | configForSplit, usesSplitName, versionCode, versionCodeMajor, revisionCode, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1793 | installLocation, verifiers, signingDetails, coreApp, debuggable, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1794 | multiArch, use32bitAbi, extractNativeLibs, isolatedSplits); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1797 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1798 | * Parses a child package and adds it to the parent if successful. If you add |
| 1799 | * new tags that need to be supported by child packages make sure to add them |
| 1800 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1801 | * |
| 1802 | * @param parentPkg The parent that contains the child |
| 1803 | * @param res Resources against which to resolve values |
| 1804 | * @param parser Parser of the manifest |
| 1805 | * @param flags Flags about how to parse |
| 1806 | * @param outError Human readable error if parsing fails |
| 1807 | * @return True of parsing succeeded. |
| 1808 | * |
| 1809 | * @throws XmlPullParserException |
| 1810 | * @throws IOException |
| 1811 | */ |
| 1812 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1813 | int flags, String[] outError) throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1814 | // Make sure we have a valid child package name |
| 1815 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1816 | if (validateName(childPackageName, true, false) != null) { |
| 1817 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | // Child packages must be unique |
| 1822 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1823 | String message = "Child package name cannot be equal to parent package name: " |
| 1824 | + parentPkg.packageName; |
| 1825 | Slog.w(TAG, message); |
| 1826 | outError[0] = message; |
| 1827 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1828 | return false; |
| 1829 | } |
| 1830 | |
| 1831 | // Child packages must be unique |
| 1832 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1833 | String message = "Duplicate child package:" + childPackageName; |
| 1834 | Slog.w(TAG, message); |
| 1835 | outError[0] = message; |
| 1836 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1837 | return false; |
| 1838 | } |
| 1839 | |
| 1840 | // Go ahead and parse the child |
| 1841 | Package childPkg = new Package(childPackageName); |
| 1842 | |
| 1843 | // Child package inherits parent version code/name/target SDK |
| 1844 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1845 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1846 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1847 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1848 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1849 | |
| 1850 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1851 | if (childPkg == null) { |
| 1852 | // If we got null then error was set during child parsing |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | // Set the parent-child relation |
| 1857 | if (parentPkg.childPackages == null) { |
| 1858 | parentPkg.childPackages = new ArrayList<>(); |
| 1859 | } |
| 1860 | parentPkg.childPackages.add(childPkg); |
| 1861 | childPkg.parentPackage = parentPkg; |
| 1862 | |
| 1863 | return true; |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1868 | * need to consider whether they should be supported by split APKs and child |
| 1869 | * packages. |
| 1870 | * |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1871 | * @param apkPath The package apk file path |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1872 | * @param res The resources from which to resolve values |
| 1873 | * @param parser The manifest parser |
| 1874 | * @param flags Flags how to parse |
| 1875 | * @param outError Human readable error message |
| 1876 | * @return Parsed package or null on error. |
| 1877 | * |
| 1878 | * @throws XmlPullParserException |
| 1879 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1880 | */ |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1881 | private Package parseBaseApk(String apkPath, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1882 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1883 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1884 | final String pkgName; |
| 1885 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1886 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1887 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1888 | pkgName = packageSplit.first; |
| 1889 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1890 | |
| 1891 | if (!TextUtils.isEmpty(splitName)) { |
| 1892 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1893 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1894 | return null; |
| 1895 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1896 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1898 | return null; |
| 1899 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1900 | |
Jaekyun Seok | 30dc2a0 | 2017-04-11 09:41:11 +0900 | [diff] [blame] | 1901 | if (mCallback != null) { |
| 1902 | String[] overlayPaths = mCallback.getOverlayPaths(pkgName, apkPath); |
| 1903 | if (overlayPaths != null && overlayPaths.length > 0) { |
| 1904 | for (String overlayPath : overlayPaths) { |
| 1905 | res.getAssets().addOverlayPath(overlayPath); |
| 1906 | } |
| 1907 | } |
| 1908 | } |
| 1909 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1910 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1911 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1912 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1914 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1915 | pkg.mVersionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1917 | pkg.mVersionCodeMajor = sa.getInteger( |
| 1918 | com.android.internal.R.styleable.AndroidManifest_versionCodeMajor, 0); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1919 | pkg.applicationInfo.setVersionCode(pkg.getLongVersionCode()); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1920 | pkg.baseRevisionCode = sa.getInteger( |
| 1921 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1922 | pkg.mVersionName = sa.getNonConfigurationString( |
| 1923 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | if (pkg.mVersionName != null) { |
| 1925 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 1926 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1927 | |
| 1928 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 1929 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1930 | pkg.mCompileSdkVersion = sa.getInteger( |
| 1931 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersion, 0); |
| 1932 | pkg.applicationInfo.compileSdkVersion = pkg.mCompileSdkVersion; |
| 1933 | pkg.mCompileSdkVersionCodename = sa.getNonConfigurationString( |
| 1934 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersionCodename, 0); |
| 1935 | if (pkg.mCompileSdkVersionCodename != null) { |
| 1936 | pkg.mCompileSdkVersionCodename = pkg.mCompileSdkVersionCodename.intern(); |
| 1937 | } |
| 1938 | pkg.applicationInfo.compileSdkVersionCodename = pkg.mCompileSdkVersionCodename; |
| 1939 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1940 | sa.recycle(); |
| 1941 | |
| 1942 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * This is the common parsing routing for handling parent and child |
| 1947 | * packages in a base APK. The difference between parent and child |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1948 | * parsing is that some tags are not supported by child packages as |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1949 | * well as some manifest attributes are ignored. The implementation |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1950 | * assumes the calling code has already handled the manifest tag if needed |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1951 | * (this applies to the parent only). |
| 1952 | * |
| 1953 | * @param pkg The package which to populate |
| 1954 | * @param acceptedTags Which tags to handle, null to handle all |
| 1955 | * @param res Resources against which to resolve values |
| 1956 | * @param parser Parser of the manifest |
| 1957 | * @param flags Flags about how to parse |
| 1958 | * @param outError Human readable error if parsing fails |
| 1959 | * @return The package if parsing succeeded or null. |
| 1960 | * |
| 1961 | * @throws XmlPullParserException |
| 1962 | * @throws IOException |
| 1963 | */ |
| 1964 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 1965 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 1966 | IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1967 | mParseInstrumentationArgs = null; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1968 | |
| 1969 | int type; |
| 1970 | boolean foundApp = false; |
| 1971 | |
| 1972 | TypedArray sa = res.obtainAttributes(parser, |
| 1973 | com.android.internal.R.styleable.AndroidManifest); |
| 1974 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1975 | String str = sa.getNonConfigurationString( |
| 1976 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 1977 | if (str != null && str.length() > 0) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1978 | String nameError = validateName(str, true, false); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1979 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 1981 | + str + "\": " + nameError; |
| 1982 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 1983 | return null; |
| 1984 | } |
| 1985 | pkg.mSharedUserId = str.intern(); |
| 1986 | pkg.mSharedUserLabel = sa.getResourceId( |
| 1987 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 1988 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 1989 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 1990 | pkg.installLocation = sa.getInteger( |
| 1991 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1992 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1993 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1994 | |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 1995 | final int targetSandboxVersion = sa.getInteger( |
| 1996 | com.android.internal.R.styleable.AndroidManifest_targetSandboxVersion, |
| 1997 | PARSE_DEFAULT_TARGET_SANDBOX); |
| 1998 | pkg.applicationInfo.targetSandboxVersion = targetSandboxVersion; |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 1999 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2000 | /* Set the global "forward lock" flag */ |
| 2001 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2002 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2006 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2007 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 2008 | } |
| 2009 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2010 | if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifest_isolatedSplits, false)) { |
| 2011 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING; |
| 2012 | } |
| 2013 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2014 | // Resource boolean are -1, so 1 means we don't know the value. |
| 2015 | int supportsSmallScreens = 1; |
| 2016 | int supportsNormalScreens = 1; |
| 2017 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2018 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2019 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2020 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2023 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2024 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2025 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | continue; |
| 2027 | } |
| 2028 | |
| 2029 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2030 | |
| 2031 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 2032 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 2033 | + tagName + " at " + mArchiveSourcePath + " " |
| 2034 | + parser.getPositionDescription()); |
| 2035 | XmlUtils.skipCurrentTag(parser); |
| 2036 | continue; |
| 2037 | } |
| 2038 | |
| 2039 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | if (foundApp) { |
| 2041 | if (RIGID_PARSER) { |
| 2042 | outError[0] = "<manifest> has more than one <application>"; |
| 2043 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2044 | return null; |
| 2045 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2046 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | XmlUtils.skipCurrentTag(parser); |
| 2048 | continue; |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2053 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | return null; |
| 2055 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2056 | } else if (tagName.equals(TAG_OVERLAY)) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2057 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2058 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 2059 | pkg.mOverlayTarget = sa.getString( |
| 2060 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 2061 | pkg.mOverlayCategory = sa.getString( |
| 2062 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_category); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2063 | pkg.mOverlayPriority = sa.getInt( |
| 2064 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 2065 | 0); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 2066 | pkg.mOverlayIsStatic = sa.getBoolean( |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2067 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_isStatic, |
| 2068 | false); |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2069 | final String propName = sa.getString( |
| 2070 | com.android.internal.R.styleable |
| 2071 | .AndroidManifestResourceOverlay_requiredSystemPropertyName); |
| 2072 | final String propValue = sa.getString( |
| 2073 | com.android.internal.R.styleable |
| 2074 | .AndroidManifestResourceOverlay_requiredSystemPropertyValue); |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2075 | sa.recycle(); |
| 2076 | |
| 2077 | if (pkg.mOverlayTarget == null) { |
| 2078 | outError[0] = "<overlay> does not specify a target package"; |
| 2079 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2080 | return null; |
| 2081 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2082 | |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2083 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 2084 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 2085 | mParseError = |
| 2086 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2087 | return null; |
| 2088 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2089 | |
| 2090 | // check to see if overlay should be excluded based on system property condition |
| 2091 | if (!checkOverlayRequiredSystemProperty(propName, propValue)) { |
| 2092 | Slog.i(TAG, "Skipping target and overlay pair " + pkg.mOverlayTarget + " and " |
| 2093 | + pkg.baseCodePath+ ": overlay ignored due to required system property: " |
| 2094 | + propName + " with value: " + propValue); |
| 2095 | return null; |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2096 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2097 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2098 | XmlUtils.skipCurrentTag(parser); |
| 2099 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2100 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 2101 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2102 | return null; |
| 2103 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2104 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2105 | if (!parsePermissionGroup(pkg, flags, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2106 | return null; |
| 2107 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2108 | } else if (tagName.equals(TAG_PERMISSION)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2109 | if (!parsePermission(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | return null; |
| 2111 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2112 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2113 | if (!parsePermissionTree(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | return null; |
| 2115 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2116 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
| 2117 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2118 | return null; |
| 2119 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2120 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 2121 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
| 2122 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2123 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2125 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2127 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 2129 | cPref.reqTouchScreen = sa.getInt( |
| 2130 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 2131 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 2132 | cPref.reqKeyboardType = sa.getInt( |
| 2133 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 2134 | Configuration.KEYBOARD_UNDEFINED); |
| 2135 | if (sa.getBoolean( |
| 2136 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 2137 | false)) { |
| 2138 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 2139 | } |
| 2140 | cPref.reqNavigation = sa.getInt( |
| 2141 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 2142 | Configuration.NAVIGATION_UNDEFINED); |
| 2143 | if (sa.getBoolean( |
| 2144 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 2145 | false)) { |
| 2146 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 2147 | } |
| 2148 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2149 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | |
| 2151 | XmlUtils.skipCurrentTag(parser); |
| 2152 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2153 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 2154 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2155 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 2156 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2157 | if (fi.name == null) { |
| 2158 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 2159 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2160 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2161 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 2162 | |
| 2163 | XmlUtils.skipCurrentTag(parser); |
| 2164 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2165 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2166 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 2167 | ArrayList<FeatureInfo> features = null; |
| 2168 | final int innerDepth = parser.getDepth(); |
| 2169 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2170 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 2171 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2172 | continue; |
| 2173 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2174 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2175 | final String innerTagName = parser.getName(); |
| 2176 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2177 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2178 | // FeatureGroups are stricter and mandate that |
| 2179 | // any <uses-feature> declared are mandatory. |
| 2180 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2181 | features = ArrayUtils.add(features, featureInfo); |
| 2182 | } else { |
| 2183 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 2184 | " at " + mArchiveSourcePath + " " + |
| 2185 | parser.getPositionDescription()); |
| 2186 | } |
| 2187 | XmlUtils.skipCurrentTag(parser); |
| 2188 | } |
| 2189 | |
| 2190 | if (features != null) { |
| 2191 | group.features = new FeatureInfo[features.size()]; |
| 2192 | group.features = features.toArray(group.features); |
| 2193 | } |
| 2194 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2195 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2196 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 2197 | if (SDK_VERSION > 0) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2198 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 2200 | |
Todd Kennedy | 4f65708 | 2016-06-28 10:31:05 -0700 | [diff] [blame] | 2201 | int minVers = 1; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2202 | String minCode = null; |
| 2203 | int targetVers = 0; |
| 2204 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2205 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2206 | TypedValue val = sa.peekValue( |
| 2207 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 2208 | if (val != null) { |
| 2209 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
Colin Cross | f61f9e3 | 2018-06-18 11:47:45 -0700 | [diff] [blame] | 2210 | minCode = val.string.toString(); |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2211 | } else { |
| 2212 | // If it's not a string, it's an integer. |
Colin Cross | f61f9e3 | 2018-06-18 11:47:45 -0700 | [diff] [blame] | 2213 | minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2214 | } |
| 2215 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2216 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2217 | val = sa.peekValue( |
| 2218 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 2219 | if (val != null) { |
| 2220 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 2221 | targetCode = val.string.toString(); |
| 2222 | if (minCode == null) { |
| 2223 | minCode = targetCode; |
| 2224 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2225 | } else { |
| 2226 | // If it's not a string, it's an integer. |
| 2227 | targetVers = val.data; |
| 2228 | } |
Colin Cross | f61f9e3 | 2018-06-18 11:47:45 -0700 | [diff] [blame] | 2229 | } else { |
| 2230 | targetVers = minVers; |
| 2231 | targetCode = minCode; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2232 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | sa.recycle(); |
| 2235 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2236 | final int minSdkVersion = PackageParser.computeMinSdkVersion(minVers, minCode, |
| 2237 | SDK_VERSION, SDK_CODENAMES, outError); |
| 2238 | if (minSdkVersion < 0) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2239 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2240 | return null; |
| 2241 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2242 | |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2243 | boolean defaultToCurrentDevBranch = (flags & PARSE_FORCE_SDK) != 0; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2244 | final int targetSdkVersion = PackageParser.computeTargetSdkVersion(targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2245 | targetCode, SDK_CODENAMES, outError, defaultToCurrentDevBranch); |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2246 | if (targetSdkVersion < 0) { |
| 2247 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2248 | return null; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2249 | } |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2250 | |
| 2251 | pkg.applicationInfo.minSdkVersion = minSdkVersion; |
| 2252 | pkg.applicationInfo.targetSdkVersion = targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | XmlUtils.skipCurrentTag(parser); |
| 2256 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2257 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 2258 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2259 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 2260 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2261 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 2262 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 2263 | 0); |
| 2264 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 2265 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 2266 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 2267 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 2268 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 2269 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2270 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2271 | // This is a trick to get a boolean and still able to detect |
| 2272 | // if a value was actually set. |
| 2273 | supportsSmallScreens = sa.getInteger( |
| 2274 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 2275 | supportsSmallScreens); |
| 2276 | supportsNormalScreens = sa.getInteger( |
| 2277 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 2278 | supportsNormalScreens); |
| 2279 | supportsLargeScreens = sa.getInteger( |
| 2280 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 2281 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2282 | supportsXLargeScreens = sa.getInteger( |
| 2283 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 2284 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2285 | resizeable = sa.getInteger( |
| 2286 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2287 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2288 | anyDensity = sa.getInteger( |
| 2289 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 2290 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2291 | |
| 2292 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2293 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2294 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2295 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2296 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 2297 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2298 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 2299 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2300 | // Note: don't allow this value to be a reference to a resource |
| 2301 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2302 | String name = sa.getNonResourceString( |
| 2303 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 2304 | |
| 2305 | sa.recycle(); |
| 2306 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 2307 | if (name != null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2308 | if (pkg.protectedBroadcasts == null) { |
| 2309 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 2310 | } |
| 2311 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 2312 | pkg.protectedBroadcasts.add(name.intern()); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2317 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2318 | } else if (tagName.equals(TAG_INSTRUMENTATION)) { |
| 2319 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2320 | return null; |
| 2321 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2322 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2323 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2324 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2325 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2326 | String orig =sa.getNonConfigurationString( |
| 2327 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2328 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2329 | if (pkg.mOriginalPackages == null) { |
| 2330 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2331 | pkg.mRealPackage = pkg.packageName; |
| 2332 | } |
| 2333 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2334 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2335 | |
| 2336 | sa.recycle(); |
| 2337 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2338 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2339 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2340 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2341 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2342 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2343 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2344 | String name = sa.getNonConfigurationString( |
| 2345 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2346 | |
| 2347 | sa.recycle(); |
| 2348 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2349 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2350 | if (pkg.mAdoptPermissions == null) { |
| 2351 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2352 | } |
| 2353 | pkg.mAdoptPermissions.add(name); |
| 2354 | } |
| 2355 | |
| 2356 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2357 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2358 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2359 | // Just skip this tag |
| 2360 | XmlUtils.skipCurrentTag(parser); |
| 2361 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2362 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2363 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2364 | // Just skip this tag |
| 2365 | XmlUtils.skipCurrentTag(parser); |
| 2366 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2367 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2368 | XmlUtils.skipCurrentTag(parser); |
| 2369 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2370 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2371 | } else if (tagName.equals(TAG_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2372 | // Just skip this tag |
| 2373 | XmlUtils.skipCurrentTag(parser); |
| 2374 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2375 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2376 | } else if (tagName.equals(TAG_PACKAGE)) { |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame] | 2377 | if (!MULTI_PACKAGE_APK_ENABLED) { |
| 2378 | XmlUtils.skipCurrentTag(parser); |
| 2379 | continue; |
| 2380 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2381 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2382 | // If parsing a child failed the error is already set |
| 2383 | return null; |
| 2384 | } |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2385 | |
| 2386 | } else if (tagName.equals(TAG_RESTRICT_UPDATE)) { |
| 2387 | if ((flags & PARSE_IS_SYSTEM_DIR) != 0) { |
| 2388 | sa = res.obtainAttributes(parser, |
| 2389 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate); |
| 2390 | final String hash = sa.getNonConfigurationString( |
| 2391 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0); |
| 2392 | sa.recycle(); |
| 2393 | |
| 2394 | pkg.restrictUpdateHash = null; |
| 2395 | if (hash != null) { |
| 2396 | final int hashLength = hash.length(); |
| 2397 | final byte[] hashBytes = new byte[hashLength / 2]; |
| 2398 | for (int i = 0; i < hashLength; i += 2){ |
| 2399 | hashBytes[i/2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) |
| 2400 | + Character.digit(hash.charAt(i + 1), 16)); |
| 2401 | } |
| 2402 | pkg.restrictUpdateHash = hashBytes; |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | XmlUtils.skipCurrentTag(parser); |
| 2407 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2408 | } else if (RIGID_PARSER) { |
| 2409 | outError[0] = "Bad element under <manifest>: " |
| 2410 | + parser.getName(); |
| 2411 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2412 | return null; |
| 2413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2415 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2416 | + " at " + mArchiveSourcePath + " " |
| 2417 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | XmlUtils.skipCurrentTag(parser); |
| 2419 | continue; |
| 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2424 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2425 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2426 | } |
| 2427 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2428 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2429 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2430 | for (int ip=0; ip<NP; ip++) { |
| 2431 | final PackageParser.NewPermissionInfo npi |
| 2432 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2433 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2434 | break; |
| 2435 | } |
| 2436 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2437 | if (implicitPerms == null) { |
| 2438 | implicitPerms = new StringBuilder(128); |
| 2439 | implicitPerms.append(pkg.packageName); |
| 2440 | implicitPerms.append(": compat added "); |
| 2441 | } else { |
| 2442 | implicitPerms.append(' '); |
| 2443 | } |
| 2444 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2445 | pkg.requestedPermissions.add(npi.name); |
| 2446 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2447 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2448 | if (implicitPerms != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2449 | Slog.i(TAG, implicitPerms.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2450 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2451 | |
| 2452 | final int NS = PackageParser.SPLIT_PERMISSIONS.length; |
| 2453 | for (int is=0; is<NS; is++) { |
| 2454 | final PackageParser.SplitPermissionInfo spi |
| 2455 | = PackageParser.SPLIT_PERMISSIONS[is]; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 2456 | if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk |
| 2457 | || !pkg.requestedPermissions.contains(spi.rootPerm)) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2458 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2459 | } |
| 2460 | for (int in=0; in<spi.newPerms.length; in++) { |
| 2461 | final String perm = spi.newPerms[in]; |
| 2462 | if (!pkg.requestedPermissions.contains(perm)) { |
| 2463 | pkg.requestedPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2468 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2469 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2470 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2471 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2472 | } |
| 2473 | if (supportsNormalScreens != 0) { |
| 2474 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2475 | } |
| 2476 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2477 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2478 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2479 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2480 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2481 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2482 | && pkg.applicationInfo.targetSdkVersion |
| 2483 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2484 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2485 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2486 | if (resizeable < 0 || (resizeable > 0 |
| 2487 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2488 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2489 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2490 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2491 | if (anyDensity < 0 || (anyDensity > 0 |
| 2492 | && pkg.applicationInfo.targetSdkVersion |
| 2493 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2494 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2495 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2496 | |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2497 | // At this point we can check if an application is not supporting densities and hence |
| 2498 | // cannot be windowed / resized. Note that an SDK version of 0 is common for |
| 2499 | // pre-Doughnut applications. |
| 2500 | if (pkg.applicationInfo.usesCompatibilityMode()) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2501 | adjustPackageToBeUnresizeableAndUnpipable(pkg); |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | return pkg; |
| 2504 | } |
| 2505 | |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2506 | private boolean checkOverlayRequiredSystemProperty(String propName, String propValue) { |
| 2507 | |
| 2508 | if (TextUtils.isEmpty(propName) || TextUtils.isEmpty(propValue)) { |
| 2509 | if (!TextUtils.isEmpty(propName) || !TextUtils.isEmpty(propValue)) { |
| 2510 | // malformed condition - incomplete |
| 2511 | Slog.w(TAG, "Disabling overlay - incomplete property :'" + propName |
| 2512 | + "=" + propValue + "' - require both requiredSystemPropertyName" |
| 2513 | + " AND requiredSystemPropertyValue to be specified."); |
| 2514 | return false; |
| 2515 | } |
| 2516 | // no valid condition set - so no exclusion criteria, overlay will be included. |
| 2517 | return true; |
| 2518 | } |
| 2519 | |
| 2520 | // check property value - make sure it is both set and equal to expected value |
| 2521 | final String currValue = SystemProperties.get(propName); |
| 2522 | return (currValue != null && currValue.equals(propValue)); |
| 2523 | } |
| 2524 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2525 | /** |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2526 | * This is a pre-density application which will get scaled - instead of being pixel perfect. |
| 2527 | * This type of application is not resizable. |
| 2528 | * |
| 2529 | * @param pkg The package which needs to be marked as unresizable. |
| 2530 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2531 | private void adjustPackageToBeUnresizeableAndUnpipable(Package pkg) { |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2532 | for (Activity a : pkg.activities) { |
| 2533 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2534 | a.info.flags &= ~FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | /** |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2539 | * Computes the targetSdkVersion to use at runtime. If the package is not |
| 2540 | * compatible with this platform, populates {@code outError[0]} with an |
| 2541 | * error message. |
| 2542 | * <p> |
| 2543 | * If {@code targetCode} is not specified, e.g. the value is {@code null}, |
| 2544 | * then the {@code targetVers} will be returned unmodified. |
| 2545 | * <p> |
| 2546 | * Otherwise, the behavior varies based on whether the current platform |
| 2547 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2548 | * has length > 0: |
| 2549 | * <ul> |
| 2550 | * <li>If this is a pre-release platform and the value specified by |
| 2551 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2552 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2553 | * <li>If this is a released platform, this method will return -1 to |
| 2554 | * indicate that the package is not compatible with this platform. |
| 2555 | * </ul> |
| 2556 | * |
| 2557 | * @param targetVers targetSdkVersion number, if specified in the |
| 2558 | * application manifest, or 0 otherwise |
| 2559 | * @param targetCode targetSdkVersion code, if specified in the application |
| 2560 | * manifest, or {@code null} otherwise |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2561 | * @param platformSdkCodenames array of allowed pre-release SDK codenames |
| 2562 | * for this platform |
| 2563 | * @param outError output array to populate with error, if applicable |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2564 | * @param forceCurrentDev if development target code is not available, use the current |
| 2565 | * development version by default. |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2566 | * @return the targetSdkVersion to use at runtime, or -1 if the package is |
| 2567 | * not compatible with this platform |
| 2568 | * @hide Exposed for unit testing only. |
| 2569 | */ |
| 2570 | @TestApi |
| 2571 | public static int computeTargetSdkVersion(@IntRange(from = 0) int targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2572 | @Nullable String targetCode, @NonNull String[] platformSdkCodenames, |
| 2573 | @NonNull String[] outError, boolean forceCurrentDev) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2574 | // If it's a release SDK, return the version number unmodified. |
| 2575 | if (targetCode == null) { |
| 2576 | return targetVers; |
| 2577 | } |
| 2578 | |
| 2579 | // If it's a pre-release SDK and the codename matches this platform, it |
| 2580 | // definitely targets this SDK. |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2581 | if (ArrayUtils.contains(platformSdkCodenames, targetCode) || forceCurrentDev) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2582 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2583 | } |
| 2584 | |
| 2585 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2586 | if (platformSdkCodenames.length > 0) { |
| 2587 | outError[0] = "Requires development platform " + targetCode |
| 2588 | + " (current platform is any of " |
| 2589 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2590 | } else { |
| 2591 | outError[0] = "Requires development platform " + targetCode |
| 2592 | + " but this is a release platform."; |
| 2593 | } |
| 2594 | return -1; |
| 2595 | } |
| 2596 | |
| 2597 | /** |
| 2598 | * Computes the minSdkVersion to use at runtime. If the package is not |
| 2599 | * compatible with this platform, populates {@code outError[0]} with an |
| 2600 | * error message. |
| 2601 | * <p> |
| 2602 | * If {@code minCode} is not specified, e.g. the value is {@code null}, |
| 2603 | * then behavior varies based on the {@code platformSdkVersion}: |
| 2604 | * <ul> |
| 2605 | * <li>If the platform SDK version is greater than or equal to the |
| 2606 | * {@code minVers}, returns the {@code mniVers} unmodified. |
| 2607 | * <li>Otherwise, returns -1 to indicate that the package is not |
| 2608 | * compatible with this platform. |
| 2609 | * </ul> |
| 2610 | * <p> |
| 2611 | * Otherwise, the behavior varies based on whether the current platform |
| 2612 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2613 | * has length > 0: |
| 2614 | * <ul> |
| 2615 | * <li>If this is a pre-release platform and the value specified by |
| 2616 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2617 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2618 | * <li>If this is a released platform, this method will return -1 to |
| 2619 | * indicate that the package is not compatible with this platform. |
| 2620 | * </ul> |
| 2621 | * |
| 2622 | * @param minVers minSdkVersion number, if specified in the application |
| 2623 | * manifest, or 1 otherwise |
| 2624 | * @param minCode minSdkVersion code, if specified in the application |
| 2625 | * manifest, or {@code null} otherwise |
| 2626 | * @param platformSdkVersion platform SDK version number, typically |
| 2627 | * Build.VERSION.SDK_INT |
| 2628 | * @param platformSdkCodenames array of allowed prerelease SDK codenames |
| 2629 | * for this platform |
| 2630 | * @param outError output array to populate with error, if applicable |
| 2631 | * @return the minSdkVersion to use at runtime, or -1 if the package is not |
| 2632 | * compatible with this platform |
| 2633 | * @hide Exposed for unit testing only. |
| 2634 | */ |
| 2635 | @TestApi |
| 2636 | public static int computeMinSdkVersion(@IntRange(from = 1) int minVers, |
| 2637 | @Nullable String minCode, @IntRange(from = 1) int platformSdkVersion, |
| 2638 | @NonNull String[] platformSdkCodenames, @NonNull String[] outError) { |
| 2639 | // If it's a release SDK, make sure we meet the minimum SDK requirement. |
| 2640 | if (minCode == null) { |
| 2641 | if (minVers <= platformSdkVersion) { |
| 2642 | return minVers; |
| 2643 | } |
| 2644 | |
| 2645 | // We don't meet the minimum SDK requirement. |
| 2646 | outError[0] = "Requires newer sdk version #" + minVers |
| 2647 | + " (current version is #" + platformSdkVersion + ")"; |
| 2648 | return -1; |
| 2649 | } |
| 2650 | |
| 2651 | // If it's a pre-release SDK and the codename matches this platform, we |
| 2652 | // definitely meet the minimum SDK requirement. |
| 2653 | if (ArrayUtils.contains(platformSdkCodenames, minCode)) { |
| 2654 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2655 | } |
| 2656 | |
| 2657 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2658 | if (platformSdkCodenames.length > 0) { |
| 2659 | outError[0] = "Requires development platform " + minCode |
| 2660 | + " (current platform is any of " |
| 2661 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2662 | } else { |
| 2663 | outError[0] = "Requires development platform " + minCode |
| 2664 | + " but this is a release platform."; |
| 2665 | } |
| 2666 | return -1; |
| 2667 | } |
| 2668 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2669 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2670 | FeatureInfo fi = new FeatureInfo(); |
| 2671 | TypedArray sa = res.obtainAttributes(attrs, |
| 2672 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2673 | // Note: don't allow this value to be a reference to a resource |
| 2674 | // that may change. |
| 2675 | fi.name = sa.getNonResourceString( |
| 2676 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2677 | fi.version = sa.getInt( |
| 2678 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2679 | if (fi.name == null) { |
| 2680 | fi.reqGlEsVersion = sa.getInt( |
| 2681 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2682 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2683 | } |
| 2684 | if (sa.getBoolean( |
| 2685 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2686 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2687 | } |
| 2688 | sa.recycle(); |
| 2689 | return fi; |
| 2690 | } |
| 2691 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2692 | private boolean parseUsesStaticLibrary(Package pkg, Resources res, XmlResourceParser parser, |
| 2693 | String[] outError) throws XmlPullParserException, IOException { |
| 2694 | TypedArray sa = res.obtainAttributes(parser, |
| 2695 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary); |
| 2696 | |
| 2697 | // Note: don't allow this value to be a reference to a resource that may change. |
| 2698 | String lname = sa.getNonResourceString( |
| 2699 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 2700 | final int version = sa.getInt( |
| 2701 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary_version, -1); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2702 | String certSha256Digest = sa.getNonResourceString(com.android.internal.R.styleable |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2703 | .AndroidManifestUsesStaticLibrary_certDigest); |
| 2704 | sa.recycle(); |
| 2705 | |
| 2706 | // 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] | 2707 | if (lname == null || version < 0 || certSha256Digest == null) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2708 | outError[0] = "Bad uses-static-library declaration name: " + lname + " version: " |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2709 | + version + " certDigest" + certSha256Digest; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2710 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2711 | XmlUtils.skipCurrentTag(parser); |
| 2712 | return false; |
| 2713 | } |
| 2714 | |
| 2715 | // Can depend only on one version of the same library |
| 2716 | if (pkg.usesStaticLibraries != null && pkg.usesStaticLibraries.contains(lname)) { |
| 2717 | outError[0] = "Depending on multiple versions of static library " + lname; |
| 2718 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2719 | XmlUtils.skipCurrentTag(parser); |
| 2720 | return false; |
| 2721 | } |
| 2722 | |
| 2723 | lname = lname.intern(); |
| 2724 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2725 | // emitted by the certtool making it easy for developers to copy/paste. |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2726 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2727 | |
| 2728 | // Fot apps targeting O-MR1 we require explicit enumeration of all certs. |
| 2729 | String[] additionalCertSha256Digests = EmptyArray.STRING; |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 2730 | if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O_MR1) { |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2731 | additionalCertSha256Digests = parseAdditionalCertificates(res, parser, outError); |
| 2732 | if (additionalCertSha256Digests == null) { |
| 2733 | return false; |
| 2734 | } |
| 2735 | } else { |
| 2736 | XmlUtils.skipCurrentTag(parser); |
| 2737 | } |
| 2738 | |
| 2739 | final String[] certSha256Digests = new String[additionalCertSha256Digests.length + 1]; |
| 2740 | certSha256Digests[0] = certSha256Digest; |
| 2741 | System.arraycopy(additionalCertSha256Digests, 0, certSha256Digests, |
| 2742 | 1, additionalCertSha256Digests.length); |
| 2743 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2744 | pkg.usesStaticLibraries = ArrayUtils.add(pkg.usesStaticLibraries, lname); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2745 | pkg.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 8a10ef5 | 2017-02-16 20:58:09 -0800 | [diff] [blame] | 2746 | pkg.usesStaticLibrariesVersions, version, true); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2747 | pkg.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, |
| 2748 | pkg.usesStaticLibrariesCertDigests, certSha256Digests, true); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2749 | |
| 2750 | return true; |
| 2751 | } |
| 2752 | |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2753 | private String[] parseAdditionalCertificates(Resources resources, XmlResourceParser parser, |
| 2754 | String[] outError) throws XmlPullParserException, IOException { |
| 2755 | String[] certSha256Digests = EmptyArray.STRING; |
| 2756 | |
| 2757 | int outerDepth = parser.getDepth(); |
| 2758 | int type; |
| 2759 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2760 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2761 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2762 | continue; |
| 2763 | } |
| 2764 | |
| 2765 | final String nodeName = parser.getName(); |
| 2766 | if (nodeName.equals("additional-certificate")) { |
| 2767 | final TypedArray sa = resources.obtainAttributes(parser, com.android.internal. |
| 2768 | R.styleable.AndroidManifestAdditionalCertificate); |
| 2769 | String certSha256Digest = sa.getNonResourceString(com.android.internal. |
| 2770 | R.styleable.AndroidManifestAdditionalCertificate_certDigest); |
| 2771 | sa.recycle(); |
| 2772 | |
| 2773 | if (TextUtils.isEmpty(certSha256Digest)) { |
| 2774 | outError[0] = "Bad additional-certificate declaration with empty" |
| 2775 | + " certDigest:" + certSha256Digest; |
| 2776 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2777 | XmlUtils.skipCurrentTag(parser); |
| 2778 | sa.recycle(); |
| 2779 | return null; |
| 2780 | } |
| 2781 | |
| 2782 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2783 | // emitted by the certtool making it easy for developers to copy/paste. |
| 2784 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2785 | certSha256Digests = ArrayUtils.appendElement(String.class, |
| 2786 | certSha256Digests, certSha256Digest); |
| 2787 | } else { |
| 2788 | XmlUtils.skipCurrentTag(parser); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | return certSha256Digests; |
| 2793 | } |
| 2794 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2795 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2796 | throws XmlPullParserException, IOException { |
| 2797 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2798 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2799 | |
| 2800 | // Note: don't allow this value to be a reference to a resource |
| 2801 | // that may change. |
| 2802 | String name = sa.getNonResourceString( |
| 2803 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2804 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2805 | int maxSdkVersion = 0; |
| 2806 | TypedValue val = sa.peekValue( |
| 2807 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2808 | if (val != null) { |
| 2809 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2810 | maxSdkVersion = val.data; |
| 2811 | } |
| 2812 | } |
| 2813 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2814 | final String requiredFeature = sa.getNonConfigurationString( |
| 2815 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredFeature, 0); |
| 2816 | |
| 2817 | final String requiredNotfeature = sa.getNonConfigurationString( |
| 2818 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredNotFeature, 0); |
| 2819 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2820 | sa.recycle(); |
| 2821 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2822 | XmlUtils.skipCurrentTag(parser); |
| 2823 | |
| 2824 | if (name == null) { |
| 2825 | return true; |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2828 | if ((maxSdkVersion != 0) && (maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT)) { |
| 2829 | return true; |
| 2830 | } |
| 2831 | |
| 2832 | // Only allow requesting this permission if the platform supports the given feature. |
| 2833 | if (requiredFeature != null && mCallback != null && !mCallback.hasFeature(requiredFeature)) { |
| 2834 | return true; |
| 2835 | } |
| 2836 | |
| 2837 | // Only allow requesting this permission if the platform doesn't support the given feature. |
| 2838 | if (requiredNotfeature != null && mCallback != null |
| 2839 | && mCallback.hasFeature(requiredNotfeature)) { |
| 2840 | return true; |
| 2841 | } |
| 2842 | |
| 2843 | int index = pkg.requestedPermissions.indexOf(name); |
| 2844 | if (index == -1) { |
| 2845 | pkg.requestedPermissions.add(name.intern()); |
| 2846 | } else { |
| 2847 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2848 | + name + " in package: " + pkg.packageName + " at: " |
| 2849 | + parser.getPositionDescription()); |
| 2850 | } |
| 2851 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2852 | return true; |
| 2853 | } |
| 2854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2856 | String[] outError) { |
| 2857 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2858 | outError[0] = "Empty class name in package " + pkg; |
| 2859 | return null; |
| 2860 | } |
| 2861 | String cls = clsSeq.toString(); |
| 2862 | char c = cls.charAt(0); |
| 2863 | if (c == '.') { |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2864 | return pkg + cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | } |
| 2866 | if (cls.indexOf('.') < 0) { |
| 2867 | StringBuilder b = new StringBuilder(pkg); |
| 2868 | b.append('.'); |
| 2869 | b.append(cls); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2870 | return b.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2872 | return cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | private static String buildCompoundName(String pkg, |
| 2876 | CharSequence procSeq, String type, String[] outError) { |
| 2877 | String proc = procSeq.toString(); |
| 2878 | char c = proc.charAt(0); |
| 2879 | if (pkg != null && c == ':') { |
| 2880 | if (proc.length() < 2) { |
| 2881 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2882 | + ": must be at least two characters"; |
| 2883 | return null; |
| 2884 | } |
| 2885 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2886 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | if (nameError != null) { |
| 2888 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2889 | + pkg + ": " + nameError; |
| 2890 | return null; |
| 2891 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2892 | return pkg + proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2894 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | if (nameError != null && !"system".equals(proc)) { |
| 2896 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2897 | + pkg + ": " + nameError; |
| 2898 | return null; |
| 2899 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2900 | return proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | private static String buildProcessName(String pkg, String defProc, |
| 2904 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 2905 | String[] outError) { |
| 2906 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 2907 | return defProc != null ? defProc : pkg; |
| 2908 | } |
| 2909 | if (separateProcesses != null) { |
| 2910 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 2911 | String sp = separateProcesses[i]; |
| 2912 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 2913 | return pkg; |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | if (procSeq == null || procSeq.length() <= 0) { |
| 2918 | return defProc; |
| 2919 | } |
Makoto Onuki | 812d188a | 2017-08-07 09:58:23 -0700 | [diff] [blame] | 2920 | return TextUtils.safeIntern(buildCompoundName(pkg, procSeq, "process", outError)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 2924 | CharSequence procSeq, String[] outError) { |
| 2925 | if (procSeq == null) { |
| 2926 | return defProc; |
| 2927 | } |
| 2928 | if (procSeq.length() <= 0) { |
| 2929 | return null; |
| 2930 | } |
| 2931 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 2932 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2933 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2934 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2935 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2936 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2937 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2938 | // all the keys and keysets that we want must be defined here |
| 2939 | // so we're going to iterate over the parser and pull out the things we want |
| 2940 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2941 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2942 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2943 | String currentKeySet = null; |
| 2944 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 2945 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 2946 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 2947 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2948 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2949 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2950 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2951 | if (parser.getDepth() == currentKeySetDepth) { |
| 2952 | currentKeySet = null; |
| 2953 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2954 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2955 | continue; |
| 2956 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2957 | String tagName = parser.getName(); |
| 2958 | if (tagName.equals("key-set")) { |
| 2959 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2960 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2961 | + parser.getPositionDescription(); |
| 2962 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2963 | return false; |
| 2964 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2965 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2966 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 2967 | final String keysetName = sa.getNonResourceString( |
| 2968 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 2969 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 2970 | currentKeySet = keysetName; |
| 2971 | currentKeySetDepth = parser.getDepth(); |
| 2972 | sa.recycle(); |
| 2973 | } else if (tagName.equals("public-key")) { |
| 2974 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2975 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2976 | + parser.getPositionDescription(); |
| 2977 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2978 | return false; |
| 2979 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2980 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2981 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 2982 | final String publicKeyName = sa.getNonResourceString( |
| 2983 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2984 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2985 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 2986 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2987 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 2988 | + " on first use at " + parser.getPositionDescription(); |
| 2989 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2990 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2991 | return false; |
| 2992 | } else if (encodedKey != null) { |
| 2993 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 2994 | if (currentKey == null) { |
| 2995 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 2996 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 2997 | + " will not be added to the package's defined key-sets."); |
| 2998 | sa.recycle(); |
| 2999 | improperKeySets.add(currentKeySet); |
| 3000 | XmlUtils.skipCurrentTag(parser); |
| 3001 | continue; |
| 3002 | } |
| 3003 | if (publicKeys.get(publicKeyName) == null |
| 3004 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 3005 | |
| 3006 | /* public-key first definition, or matches old definition */ |
| 3007 | publicKeys.put(publicKeyName, currentKey); |
| 3008 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3009 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3010 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3011 | + parser.getPositionDescription(); |
| 3012 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3013 | sa.recycle(); |
| 3014 | return false; |
| 3015 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3016 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3017 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3018 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3019 | XmlUtils.skipCurrentTag(parser); |
| 3020 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3021 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3022 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 3023 | String name = sa.getNonResourceString( |
| 3024 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 3025 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3026 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3027 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3028 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3029 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3030 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3031 | + parser.getPositionDescription(); |
| 3032 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3033 | return false; |
| 3034 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3035 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3036 | + " at " + mArchiveSourcePath + " " |
| 3037 | + parser.getPositionDescription()); |
| 3038 | XmlUtils.skipCurrentTag(parser); |
| 3039 | continue; |
| 3040 | } |
| 3041 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3042 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 3043 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3044 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 3045 | + "'key-set' and 'public-key' names must be distinct."; |
| 3046 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3047 | return false; |
| 3048 | } |
| 3049 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 3050 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 3051 | final String keySetName = e.getKey(); |
| 3052 | if (e.getValue().size() == 0) { |
| 3053 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3054 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 3055 | + " Not including in package's defined key-sets."); |
| 3056 | continue; |
| 3057 | } else if (improperKeySets.contains(keySetName)) { |
| 3058 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3059 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 3060 | + " tags. Not including in package's defined key-sets."); |
| 3061 | continue; |
| 3062 | } |
| 3063 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 3064 | for (String s : e.getValue()) { |
| 3065 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3066 | } |
| 3067 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3068 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 3069 | owner.mUpgradeKeySets = upgradeKeySets; |
| 3070 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3071 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 3072 | + "does not define all 'upgrade-key-set's ."; |
| 3073 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3074 | return false; |
| 3075 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3076 | return true; |
| 3077 | } |
| 3078 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3079 | private boolean parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3080 | XmlResourceParser parser, String[] outError) |
| 3081 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | PermissionGroup perm = new PermissionGroup(owner); |
| 3083 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3084 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3087 | "<permission-group>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 3089 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3090 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3091 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3092 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 3093 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | sa.recycle(); |
| 3095 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3096 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | perm.info.descriptionRes = sa.getResourceId( |
| 3100 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 3101 | 0); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3102 | perm.info.requestRes = sa.getResourceId( |
| 3103 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 3104 | perm.info.flags = sa.getInt( |
| 3105 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 3106 | perm.info.priority = sa.getInt( |
| 3107 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | |
| 3109 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3110 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3111 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | outError)) { |
| 3113 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3114 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | owner.permissionGroups.add(perm); |
| 3118 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3119 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | } |
| 3121 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3122 | private boolean parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3123 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3125 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3126 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3127 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 3128 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3129 | Permission perm = new Permission(owner); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3131 | "<permission>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 3133 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3134 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3135 | com.android.internal.R.styleable.AndroidManifestPermission_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3136 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 3137 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | sa.recycle(); |
| 3139 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3140 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | } |
| 3142 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3143 | // Note: don't allow this value to be a reference to a resource |
| 3144 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | perm.info.group = sa.getNonResourceString( |
| 3146 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 3147 | if (perm.info.group != null) { |
| 3148 | perm.info.group = perm.info.group.intern(); |
| 3149 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | perm.info.descriptionRes = sa.getResourceId( |
| 3152 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 3153 | 0); |
| 3154 | |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3155 | perm.info.requestRes = sa.getResourceId( |
| 3156 | com.android.internal.R.styleable.AndroidManifestPermission_request, 0); |
| 3157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | perm.info.protectionLevel = sa.getInt( |
| 3159 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 3160 | PermissionInfo.PROTECTION_NORMAL); |
| 3161 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 3162 | perm.info.flags = sa.getInt( |
| 3163 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 3164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | if (perm.info.protectionLevel == -1) { |
| 3168 | outError[0] = "<permission> does not specify protectionLevel"; |
| 3169 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3170 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3172 | |
| 3173 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 3174 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 3175 | if (perm.info.getProtectionFlags() != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 3176 | if ( (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_INSTANT) == 0 |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 3177 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) == 0 |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 3178 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3179 | PermissionInfo.PROTECTION_SIGNATURE) { |
Joe Maples | 39bb9e8 | 2018-01-11 11:09:46 -0500 | [diff] [blame] | 3180 | outError[0] = "<permission> protectionLevel specifies a non-instant flag but is " |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3181 | + "not based on signature type"; |
| 3182 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3183 | return false; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3184 | } |
| 3185 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3186 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3187 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3189 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | owner.permissions.add(perm); |
| 3193 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3194 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3197 | private boolean parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3198 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | throws XmlPullParserException, IOException { |
| 3200 | Permission perm = new Permission(owner); |
| 3201 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3202 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 3204 | |
| 3205 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3206 | "<permission-tree>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 3208 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3209 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3210 | com.android.internal.R.styleable.AndroidManifestPermissionTree_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3211 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 3212 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | sa.recycle(); |
| 3214 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3215 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | int index = perm.info.name.indexOf('.'); |
| 3221 | if (index > 0) { |
| 3222 | index = perm.info.name.indexOf('.', index+1); |
| 3223 | } |
| 3224 | if (index < 0) { |
| 3225 | outError[0] = "<permission-tree> name has less than three segments: " |
| 3226 | + perm.info.name; |
| 3227 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3228 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | perm.info.descriptionRes = 0; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3232 | perm.info.requestRes = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 3234 | perm.tree = true; |
| 3235 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3236 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | outError)) { |
| 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 | owner.permissions.add(perm); |
| 3243 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3244 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3248 | XmlResourceParser parser, String[] outError) |
| 3249 | throws XmlPullParserException, IOException { |
| 3250 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 3252 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3253 | if (mParseInstrumentationArgs == null) { |
| 3254 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 3255 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 3256 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3257 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3258 | com.android.internal.R.styleable.AndroidManifestInstrumentation_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3259 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 3260 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3261 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 3262 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3263 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3264 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3265 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3266 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 3267 | new InstrumentationInfo()); |
| 3268 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | sa.recycle(); |
| 3270 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3271 | return null; |
| 3272 | } |
| 3273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3275 | // Note: don't allow this value to be a reference to a resource |
| 3276 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | str = sa.getNonResourceString( |
| 3278 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 3279 | a.info.targetPackage = str != null ? str.intern() : null; |
| 3280 | |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3281 | str = sa.getNonResourceString( |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 3282 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetProcesses); |
| 3283 | a.info.targetProcesses = str != null ? str.intern() : null; |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | a.info.handleProfiling = sa.getBoolean( |
| 3286 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 3287 | false); |
| 3288 | |
| 3289 | a.info.functionalTest = sa.getBoolean( |
| 3290 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 3291 | false); |
| 3292 | |
| 3293 | sa.recycle(); |
| 3294 | |
| 3295 | if (a.info.targetPackage == null) { |
| 3296 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 3297 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3298 | return null; |
| 3299 | } |
| 3300 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3301 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | outError)) { |
| 3303 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3304 | return null; |
| 3305 | } |
| 3306 | |
| 3307 | owner.instrumentation.add(a); |
| 3308 | |
| 3309 | return a; |
| 3310 | } |
| 3311 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3312 | /** |
| 3313 | * Parse the {@code application} XML tree at the current parse location in a |
| 3314 | * <em>base APK</em> manifest. |
| 3315 | * <p> |
| 3316 | * When adding new features, carefully consider if they should also be |
| 3317 | * supported by split APKs. |
| 3318 | */ |
| 3319 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3320 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | throws XmlPullParserException, IOException { |
| 3322 | final ApplicationInfo ai = owner.applicationInfo; |
| 3323 | final String pkgName = owner.applicationInfo.packageName; |
| 3324 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3325 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3327 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3328 | if (!parsePackageItemInfo(owner, ai, outError, |
| 3329 | "<application>", sa, false /*nameRequired*/, |
| 3330 | com.android.internal.R.styleable.AndroidManifestApplication_name, |
| 3331 | com.android.internal.R.styleable.AndroidManifestApplication_label, |
| 3332 | com.android.internal.R.styleable.AndroidManifestApplication_icon, |
| 3333 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, |
| 3334 | com.android.internal.R.styleable.AndroidManifestApplication_logo, |
| 3335 | com.android.internal.R.styleable.AndroidManifestApplication_banner)) { |
| 3336 | sa.recycle(); |
| 3337 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3338 | return false; |
| 3339 | } |
| 3340 | |
| 3341 | if (ai.name != null) { |
Todd Kennedy | afb5269 | 2016-08-22 15:44:00 -0700 | [diff] [blame] | 3342 | ai.className = ai.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
| 3344 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3345 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3346 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 3347 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | if (manageSpaceActivity != null) { |
| 3349 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 3350 | outError); |
| 3351 | } |
| 3352 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3353 | boolean allowBackup = sa.getBoolean( |
| 3354 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 3355 | if (allowBackup) { |
| 3356 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3357 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3358 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 3359 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 3360 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3361 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3362 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 3363 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3364 | if (backupAgent != null) { |
| 3365 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3366 | if (DEBUG_BACKUP) { |
| 3367 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3368 | + " from " + pkgName + "+" + backupAgent); |
| 3369 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3370 | |
| 3371 | if (sa.getBoolean( |
| 3372 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 3373 | true)) { |
| 3374 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 3375 | } |
| 3376 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 3377 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 3378 | false)) { |
| 3379 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 3380 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 3381 | if (sa.getBoolean( |
| 3382 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 3383 | false)) { |
| 3384 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 3385 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3386 | if (sa.getBoolean( |
| 3387 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 3388 | false)) { |
| 3389 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 3390 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3391 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 3392 | |
| 3393 | TypedValue v = sa.peekValue( |
| 3394 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 3395 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 3396 | if (DEBUG_BACKUP) { |
| 3397 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 3398 | (v.data == 0 ? "false" : "true")); |
| 3399 | } |
| 3400 | // "false" => -1, "true" => 0 |
| 3401 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 3402 | } |
| 3403 | if (DEBUG_BACKUP) { |
| 3404 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 3405 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3406 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 3409 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | ai.descriptionRes = sa.getResourceId( |
| 3411 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 3412 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 3413 | if (sa.getBoolean( |
| 3414 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 3415 | false)) { |
| 3416 | // Check if persistence is based on a feature being present |
| 3417 | final String requiredFeature = sa.getNonResourceString(com.android.internal.R.styleable |
| 3418 | .AndroidManifestApplication_persistentWhenFeatureAvailable); |
| 3419 | if (requiredFeature == null || mCallback.hasFeature(requiredFeature)) { |
| 3420 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | if (sa.getBoolean( |
| 3425 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 3426 | false)) { |
| 3427 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 3431 | .AndroidManifestApplication_restrictedAccountType); |
| 3432 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 3433 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3434 | } |
| 3435 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 3436 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 3437 | .AndroidManifestApplication_requiredAccountType); |
| 3438 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 3439 | owner.mRequiredAccountType = requiredAccountType; |
| 3440 | } |
| 3441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | if (sa.getBoolean( |
| 3443 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 3444 | false)) { |
| 3445 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 3446 | } |
| 3447 | |
| 3448 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 3449 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 3450 | false)) { |
| 3451 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 3452 | } |
| 3453 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3454 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3455 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 3456 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 3457 | if (owner.baseHardwareAccelerated) { |
| 3458 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 3459 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3460 | |
| 3461 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3462 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 3463 | true)) { |
| 3464 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 3465 | } |
| 3466 | |
| 3467 | if (sa.getBoolean( |
| 3468 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 3469 | false)) { |
| 3470 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3471 | } |
| 3472 | |
| 3473 | if (sa.getBoolean( |
| 3474 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 3475 | true)) { |
| 3476 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 3477 | } |
| 3478 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3479 | // The parent package controls installation, hence specify test only installs. |
| 3480 | if (owner.parentPackage == null) { |
| 3481 | if (sa.getBoolean( |
| 3482 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 3483 | false)) { |
| 3484 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 3485 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3488 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3489 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3490 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3491 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3492 | } |
| 3493 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3494 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3495 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
Chad Brubaker | 0d285d5 | 2018-03-14 09:00:04 -0700 | [diff] [blame] | 3496 | owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.P)) { |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3497 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 3498 | } |
| 3499 | |
| 3500 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3501 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 3502 | false /* default is no RTL support*/)) { |
| 3503 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 3504 | } |
| 3505 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 3506 | if (sa.getBoolean( |
| 3507 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 3508 | false)) { |
| 3509 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 3510 | } |
| 3511 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3512 | if (sa.getBoolean( |
| 3513 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
| 3514 | true)) { |
| 3515 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 3516 | } |
| 3517 | |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3518 | if (sa.getBoolean( |
| 3519 | R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 3520 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3521 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3522 | } |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3523 | if (sa.getBoolean( |
| 3524 | R.styleable.AndroidManifestApplication_directBootAware, |
| 3525 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3526 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 3527 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3528 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3529 | if (sa.hasValueOrEmpty(R.styleable.AndroidManifestApplication_resizeableActivity)) { |
| 3530 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, true)) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3531 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; |
| 3532 | } else { |
| 3533 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3534 | } |
| 3535 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3536 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 3537 | } |
| 3538 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3539 | ai.maxAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_maxAspectRatio, 0); |
| 3540 | |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3541 | ai.networkSecurityConfigRes = sa.getResourceId( |
| 3542 | com.android.internal.R.styleable.AndroidManifestApplication_networkSecurityConfig, |
| 3543 | 0); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3544 | ai.category = sa.getInt( |
| 3545 | com.android.internal.R.styleable.AndroidManifestApplication_appCategory, |
| 3546 | ApplicationInfo.CATEGORY_UNDEFINED); |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3549 | str = sa.getNonConfigurationString( |
| 3550 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 3552 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3553 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3554 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3555 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 3556 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3557 | } else { |
| 3558 | // Some older apps have been seen to use a resource reference |
| 3559 | // here that on older builds was ignored (with a warning). We |
| 3560 | // need to continue to do this for them so they don't break. |
| 3561 | str = sa.getNonResourceString( |
| 3562 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 3563 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3564 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 3565 | str, outError); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3566 | String factory = sa.getNonResourceString( |
| 3567 | com.android.internal.R.styleable.AndroidManifestApplication_appComponentFactory); |
| 3568 | if (factory != null) { |
| 3569 | ai.appComponentFactory = buildClassName(ai.packageName, factory, outError); |
| 3570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | |
| 3572 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3573 | CharSequence pname; |
| 3574 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3575 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3576 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 3577 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3578 | } else { |
| 3579 | // Some older apps have been seen to use a resource reference |
| 3580 | // here that on older builds was ignored (with a warning). We |
| 3581 | // need to continue to do this for them so they don't break. |
| 3582 | pname = sa.getNonResourceString( |
| 3583 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 3584 | } |
| 3585 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3587 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3588 | ai.enabled = sa.getBoolean( |
| 3589 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3590 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 3591 | if (sa.getBoolean( |
| 3592 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 3593 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 3594 | } |
| 3595 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3596 | if (sa.getBoolean( |
| 3597 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 3598 | false)) { |
| 3599 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 3600 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3601 | // A heavy-weight application can not be in a custom process. |
| 3602 | // We can do direct compare because we intern all strings. |
| 3603 | if (ai.processName != null && !ai.processName.equals(ai.packageName)) { |
| 3604 | outError[0] = "cantSaveState applications can not use custom processes"; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3605 | } |
| 3606 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | } |
| 3608 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3609 | ai.uiOptions = sa.getInt( |
| 3610 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 3611 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3612 | ai.classLoaderName = sa.getString( |
| 3613 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3614 | if (ai.classLoaderName != null |
| 3615 | && !ClassLoaderFactory.isValidClassLoaderName(ai.classLoaderName)) { |
| 3616 | outError[0] = "Invalid class loader name: " + ai.classLoaderName; |
| 3617 | } |
| 3618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | sa.recycle(); |
| 3620 | |
| 3621 | if (outError[0] != null) { |
| 3622 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3623 | return false; |
| 3624 | } |
| 3625 | |
| 3626 | final int innerDepth = parser.getDepth(); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3627 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3628 | // getting added to the wrong package. |
| 3629 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | int type; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3631 | boolean hasActivityOrder = false; |
| 3632 | boolean hasReceiverOrder = false; |
| 3633 | boolean hasServiceOrder = false; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3634 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3635 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3636 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | continue; |
| 3638 | } |
| 3639 | |
| 3640 | String tagName = parser.getName(); |
| 3641 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3642 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3643 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | if (a == null) { |
| 3645 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3646 | return false; |
| 3647 | } |
| 3648 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3649 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | owner.activities.add(a); |
| 3651 | |
| 3652 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3653 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3654 | true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3655 | if (a == null) { |
| 3656 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3657 | return false; |
| 3658 | } |
| 3659 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3660 | hasReceiverOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | owner.receivers.add(a); |
| 3662 | |
| 3663 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3664 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | if (s == null) { |
| 3666 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3667 | return false; |
| 3668 | } |
| 3669 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3670 | hasServiceOrder |= (s.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | owner.services.add(s); |
| 3672 | |
| 3673 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3674 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | if (p == null) { |
| 3676 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3677 | return false; |
| 3678 | } |
| 3679 | |
| 3680 | owner.providers.add(p); |
| 3681 | |
| 3682 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3683 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | if (a == null) { |
| 3685 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3686 | return false; |
| 3687 | } |
| 3688 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3689 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | owner.activities.add(a); |
| 3691 | |
| 3692 | } else if (parser.getName().equals("meta-data")) { |
| 3693 | // note: application meta-data is stored off to the side, so it can |
| 3694 | // remain null in the primary copy (we like to avoid extra copies because |
| 3695 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3696 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | outError)) == null) { |
| 3698 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3699 | return false; |
| 3700 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3701 | } else if (tagName.equals("static-library")) { |
| 3702 | sa = res.obtainAttributes(parser, |
| 3703 | com.android.internal.R.styleable.AndroidManifestStaticLibrary); |
| 3704 | |
| 3705 | // Note: don't allow this value to be a reference to a resource |
| 3706 | // that may change. |
| 3707 | final String lname = sa.getNonResourceString( |
| 3708 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_name); |
| 3709 | final int version = sa.getInt( |
| 3710 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_version, -1); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3711 | final int versionMajor = sa.getInt( |
| 3712 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_versionMajor, |
| 3713 | 0); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3714 | |
| 3715 | sa.recycle(); |
| 3716 | |
| 3717 | // Since the app canot run without a static lib - fail if malformed |
| 3718 | if (lname == null || version < 0) { |
| 3719 | outError[0] = "Bad static-library declaration name: " + lname |
| 3720 | + " version: " + version; |
| 3721 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3722 | XmlUtils.skipCurrentTag(parser); |
| 3723 | return false; |
| 3724 | } |
| 3725 | |
| 3726 | if (owner.mSharedUserId != null) { |
| 3727 | outError[0] = "sharedUserId not allowed in static shared library"; |
| 3728 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 3729 | XmlUtils.skipCurrentTag(parser); |
| 3730 | return false; |
| 3731 | } |
| 3732 | |
| 3733 | if (owner.staticSharedLibName != null) { |
| 3734 | outError[0] = "Multiple static-shared libs for package " + pkgName; |
| 3735 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3736 | XmlUtils.skipCurrentTag(parser); |
| 3737 | return false; |
| 3738 | } |
| 3739 | |
| 3740 | owner.staticSharedLibName = lname.intern(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3741 | if (version >= 0) { |
| 3742 | owner.staticSharedLibVersion = |
| 3743 | PackageInfo.composeLongVersionCode(versionMajor, version); |
| 3744 | } else { |
| 3745 | owner.staticSharedLibVersion = version; |
| 3746 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3747 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY; |
| 3748 | |
| 3749 | XmlUtils.skipCurrentTag(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3751 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3752 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3753 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3754 | |
| 3755 | // Note: don't allow this value to be a reference to a resource |
| 3756 | // that may change. |
| 3757 | String lname = sa.getNonResourceString( |
| 3758 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3759 | |
| 3760 | sa.recycle(); |
| 3761 | |
| 3762 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3763 | lname = lname.intern(); |
| 3764 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3765 | owner.libraryNames = ArrayUtils.add( |
| 3766 | owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3767 | } |
| 3768 | } |
| 3769 | |
| 3770 | XmlUtils.skipCurrentTag(parser); |
| 3771 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3772 | } else if (tagName.equals("uses-static-library")) { |
| 3773 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3774 | return false; |
| 3775 | } |
| 3776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3778 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3780 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3781 | // Note: don't allow this value to be a reference to a resource |
| 3782 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | String lname = sa.getNonResourceString( |
| 3784 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3785 | boolean req = sa.getBoolean( |
| 3786 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3787 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3788 | |
| 3789 | sa.recycle(); |
| 3790 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3791 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3792 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3793 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3794 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3795 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3796 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3797 | owner.usesOptionalLibraries, lname); |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | XmlUtils.skipCurrentTag(parser); |
| 3802 | |
| 3803 | } else if (tagName.equals("uses-package")) { |
| 3804 | // Dependencies for app installers; we don't currently try to |
| 3805 | // enforce this. |
| 3806 | XmlUtils.skipCurrentTag(parser); |
| 3807 | |
| 3808 | } else { |
| 3809 | if (!RIGID_PARSER) { |
| 3810 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 3811 | + " at " + mArchiveSourcePath + " " |
| 3812 | + parser.getPositionDescription()); |
| 3813 | XmlUtils.skipCurrentTag(parser); |
| 3814 | continue; |
| 3815 | } else { |
| 3816 | outError[0] = "Bad element under <application>: " + tagName; |
| 3817 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3818 | return false; |
| 3819 | } |
| 3820 | } |
| 3821 | } |
| 3822 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3823 | if (hasActivityOrder) { |
| 3824 | Collections.sort(owner.activities, (a1, a2) -> Integer.compare(a2.order, a1.order)); |
| 3825 | } |
| 3826 | if (hasReceiverOrder) { |
| 3827 | Collections.sort(owner.receivers, (r1, r2) -> Integer.compare(r2.order, r1.order)); |
| 3828 | } |
| 3829 | if (hasServiceOrder) { |
| 3830 | Collections.sort(owner.services, (s1, s2) -> Integer.compare(s2.order, s1.order)); |
| 3831 | } |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 3832 | // Must be ran after the entire {@link ApplicationInfo} has been fully processed and after |
| 3833 | // every activity info has had a chance to set it from its attributes. |
| 3834 | setMaxAspectRatio(owner); |
| 3835 | |
Paul Duffin | 855d702 | 2017-07-10 15:16:07 +0100 | [diff] [blame] | 3836 | PackageBackwardCompatibility.modifySharedLibraries(owner); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3837 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3838 | if (hasDomainURLs(owner)) { |
| 3839 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3840 | } else { |
| 3841 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3842 | } |
| 3843 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3844 | return true; |
| 3845 | } |
| 3846 | |
| 3847 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3848 | * 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] | 3849 | */ |
| 3850 | private static boolean hasDomainURLs(Package pkg) { |
| 3851 | if (pkg == null || pkg.activities == null) return false; |
| 3852 | final ArrayList<Activity> activities = pkg.activities; |
| 3853 | final int countActivities = activities.size(); |
| 3854 | for (int n=0; n<countActivities; n++) { |
| 3855 | Activity activity = activities.get(n); |
| 3856 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 3857 | if (filters == null) continue; |
| 3858 | final int countFilters = filters.size(); |
| 3859 | for (int m=0; m<countFilters; m++) { |
| 3860 | ActivityIntentInfo aii = filters.get(m); |
| 3861 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3862 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3863 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 3864 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 3865 | return true; |
| 3866 | } |
| 3867 | } |
| 3868 | } |
| 3869 | return false; |
| 3870 | } |
| 3871 | |
| 3872 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3873 | * Parse the {@code application} XML tree at the current parse location in a |
| 3874 | * <em>split APK</em> manifest. |
| 3875 | * <p> |
| 3876 | * Note that split APKs have many more restrictions on what they're capable |
| 3877 | * of doing, so many valid features of a base APK have been carefully |
| 3878 | * omitted here. |
| 3879 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3880 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 3881 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3882 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3883 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3884 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3885 | |
| 3886 | if (sa.getBoolean( |
| 3887 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 3888 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 3889 | } |
| 3890 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3891 | final String classLoaderName = sa.getString( |
| 3892 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3893 | if (classLoaderName == null || ClassLoaderFactory.isValidClassLoaderName(classLoaderName)) { |
| 3894 | owner.applicationInfo.splitClassLoaderNames[splitIndex] = classLoaderName; |
| 3895 | } else { |
| 3896 | outError[0] = "Invalid class loader name: " + classLoaderName; |
| 3897 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3898 | return false; |
| 3899 | } |
| 3900 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3901 | final int innerDepth = parser.getDepth(); |
| 3902 | int type; |
| 3903 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3904 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3905 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3906 | continue; |
| 3907 | } |
| 3908 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3909 | ComponentInfo parsedComponent = null; |
| 3910 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3911 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3912 | // getting added to the wrong package. |
| 3913 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3914 | String tagName = parser.getName(); |
| 3915 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3916 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3917 | owner.baseHardwareAccelerated); |
| 3918 | if (a == null) { |
| 3919 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3920 | return false; |
| 3921 | } |
| 3922 | |
| 3923 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3924 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3925 | |
| 3926 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3927 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3928 | true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3929 | if (a == null) { |
| 3930 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3931 | return false; |
| 3932 | } |
| 3933 | |
| 3934 | owner.receivers.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3935 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3936 | |
| 3937 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3938 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3939 | if (s == null) { |
| 3940 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3941 | return false; |
| 3942 | } |
| 3943 | |
| 3944 | owner.services.add(s); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3945 | parsedComponent = s.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3946 | |
| 3947 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3948 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3949 | if (p == null) { |
| 3950 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3951 | return false; |
| 3952 | } |
| 3953 | |
| 3954 | owner.providers.add(p); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3955 | parsedComponent = p.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3956 | |
| 3957 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3958 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3959 | if (a == null) { |
| 3960 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3961 | return false; |
| 3962 | } |
| 3963 | |
| 3964 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3965 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3966 | |
| 3967 | } else if (parser.getName().equals("meta-data")) { |
| 3968 | // note: application meta-data is stored off to the side, so it can |
| 3969 | // remain null in the primary copy (we like to avoid extra copies because |
| 3970 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3971 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3972 | outError)) == null) { |
| 3973 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3974 | return false; |
| 3975 | } |
| 3976 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3977 | } else if (tagName.equals("uses-static-library")) { |
| 3978 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3979 | return false; |
| 3980 | } |
| 3981 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3982 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3983 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3984 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3985 | |
| 3986 | // Note: don't allow this value to be a reference to a resource |
| 3987 | // that may change. |
| 3988 | String lname = sa.getNonResourceString( |
| 3989 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 3990 | boolean req = sa.getBoolean( |
| 3991 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3992 | true); |
| 3993 | |
| 3994 | sa.recycle(); |
| 3995 | |
| 3996 | if (lname != null) { |
| 3997 | lname = lname.intern(); |
| 3998 | if (req) { |
| 3999 | // Upgrade to treat as stronger constraint |
| 4000 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 4001 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 4002 | owner.usesOptionalLibraries, lname); |
| 4003 | } else { |
| 4004 | // Ignore if someone already defined as required |
| 4005 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 4006 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 4007 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4008 | } |
| 4009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | XmlUtils.skipCurrentTag(parser); |
| 4013 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 4014 | } else if (tagName.equals("uses-package")) { |
| 4015 | // Dependencies for app installers; we don't currently try to |
| 4016 | // enforce this. |
| 4017 | XmlUtils.skipCurrentTag(parser); |
| 4018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4019 | } else { |
| 4020 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4021 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4022 | + " at " + mArchiveSourcePath + " " |
| 4023 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | XmlUtils.skipCurrentTag(parser); |
| 4025 | continue; |
| 4026 | } else { |
| 4027 | outError[0] = "Bad element under <application>: " + tagName; |
| 4028 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4029 | return false; |
| 4030 | } |
| 4031 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4032 | |
| 4033 | if (parsedComponent != null && parsedComponent.splitName == null) { |
| 4034 | // If the loaded component did not specify a split, inherit the split name |
| 4035 | // based on the split it is defined in. |
| 4036 | // This is used to later load the correct split when starting this |
| 4037 | // component. |
| 4038 | parsedComponent.splitName = owner.splitNames[splitIndex]; |
| 4039 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | return true; |
| 4043 | } |
| 4044 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4045 | private static boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 4046 | String[] outError, String tag, TypedArray sa, boolean nameRequired, |
| 4047 | int nameRes, int labelRes, int iconRes, int roundIconRes, int logoRes, int bannerRes) { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 4048 | // This case can only happen in unit tests where we sometimes need to create fakes |
| 4049 | // of various package parser data structures. |
| 4050 | if (sa == null) { |
| 4051 | outError[0] = tag + " does not contain any attributes"; |
| 4052 | return false; |
| 4053 | } |
| 4054 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4055 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | if (name == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4057 | if (nameRequired) { |
| 4058 | outError[0] = tag + " does not specify android:name"; |
| 4059 | return false; |
| 4060 | } |
| 4061 | } else { |
| 4062 | outInfo.name |
| 4063 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 4064 | if (outInfo.name == null) { |
| 4065 | return false; |
| 4066 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 4069 | final boolean useRoundIcon = |
| 4070 | Resources.getSystem().getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 4071 | int roundIconVal = useRoundIcon ? sa.getResourceId(roundIconRes, 0) : 0; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4072 | if (roundIconVal != 0) { |
| 4073 | outInfo.icon = roundIconVal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | outInfo.nonLocalizedLabel = null; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4075 | } else { |
| 4076 | int iconVal = sa.getResourceId(iconRes, 0); |
| 4077 | if (iconVal != 0) { |
| 4078 | outInfo.icon = iconVal; |
| 4079 | outInfo.nonLocalizedLabel = null; |
| 4080 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4082 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4083 | int logoVal = sa.getResourceId(logoRes, 0); |
| 4084 | if (logoVal != 0) { |
| 4085 | outInfo.logo = logoVal; |
| 4086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4088 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 4089 | if (bannerVal != 0) { |
| 4090 | outInfo.banner = bannerVal; |
| 4091 | } |
| 4092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | TypedValue v = sa.peekValue(labelRes); |
| 4094 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4095 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4096 | } |
| 4097 | |
| 4098 | outInfo.packageName = owner.packageName; |
| 4099 | |
| 4100 | return true; |
| 4101 | } |
| 4102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | private Activity parseActivity(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4104 | XmlResourceParser parser, int flags, String[] outError, CachedComponentArgs cachedArgs, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4105 | boolean receiver, boolean hardwareAccelerated) |
| 4106 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4107 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4108 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4109 | if (cachedArgs.mActivityArgs == null) { |
| 4110 | cachedArgs.mActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4111 | R.styleable.AndroidManifestActivity_name, |
| 4112 | R.styleable.AndroidManifestActivity_label, |
| 4113 | R.styleable.AndroidManifestActivity_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4114 | R.styleable.AndroidManifestActivity_roundIcon, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4115 | R.styleable.AndroidManifestActivity_logo, |
| 4116 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4117 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4118 | R.styleable.AndroidManifestActivity_process, |
| 4119 | R.styleable.AndroidManifestActivity_description, |
| 4120 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4121 | } |
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 | cachedArgs.mActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 4124 | cachedArgs.mActivityArgs.sa = sa; |
| 4125 | cachedArgs.mActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4126 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4127 | Activity a = new Activity(cachedArgs.mActivityArgs, new ActivityInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4128 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | sa.recycle(); |
| 4130 | return null; |
| 4131 | } |
| 4132 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4133 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4135 | 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] | 4136 | } |
| 4137 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4138 | 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] | 4139 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4140 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4141 | a.info.applicationInfo.uiOptions); |
| 4142 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4143 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4144 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4145 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4146 | if (parentName != null) { |
| 4147 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4148 | if (outError[0] == null) { |
| 4149 | a.info.parentActivityName = parentClassName; |
| 4150 | } else { |
| 4151 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 4152 | parentName); |
| 4153 | outError[0] = null; |
| 4154 | } |
| 4155 | } |
| 4156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4158 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | if (str == null) { |
| 4160 | a.info.permission = owner.applicationInfo.permission; |
| 4161 | } else { |
| 4162 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4163 | } |
| 4164 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4165 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4166 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4167 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 4169 | owner.applicationInfo.taskAffinity, str, outError); |
| 4170 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4171 | a.info.splitName = |
| 4172 | sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_splitName, 0); |
| 4173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | a.info.flags = 0; |
| 4175 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4176 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 4178 | } |
| 4179 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4180 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 4182 | } |
| 4183 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4184 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 4186 | } |
| 4187 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4188 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 4190 | } |
| 4191 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4192 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 4194 | } |
| 4195 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4196 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 4198 | } |
| 4199 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4200 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 4202 | } |
| 4203 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4204 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 4206 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 4207 | } |
| 4208 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4209 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4210 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 4211 | } |
| 4212 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 4213 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 4214 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 4215 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4218 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 4219 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 4220 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4221 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 4222 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 4223 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 4224 | } |
| 4225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4227 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4228 | hardwareAccelerated)) { |
| 4229 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4230 | } |
| 4231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4232 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4233 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4234 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4235 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4236 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 4237 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4238 | R.styleable.AndroidManifestActivity_maxRecents, |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 4239 | ActivityManager.getDefaultAppRecentsLimitStatic()); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4240 | a.info.configChanges = getActivityConfigChanges( |
| 4241 | sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0), |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4242 | sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4244 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4245 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4246 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4247 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4248 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4249 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4250 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4251 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 4252 | } |
| 4253 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4254 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4255 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 4256 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4257 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4258 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4259 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 4260 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4261 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4262 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4263 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 4264 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4265 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4266 | a.info.screenOrientation = sa.getInt( |
| 4267 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 4268 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 4269 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4270 | setActivityResizeMode(a.info, sa, owner); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4271 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4272 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 4273 | false)) { |
| 4274 | a.info.flags |= FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 4275 | } |
| 4276 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4277 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4278 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4279 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 4280 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4281 | if (sa.hasValue(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4282 | && sa.getType(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4283 | == TypedValue.TYPE_FLOAT) { |
| 4284 | a.setMaxAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_maxAspectRatio, |
| 4285 | 0 /*default*/)); |
| 4286 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4287 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4288 | a.info.lockTaskLaunchMode = |
| 4289 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4290 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4291 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4292 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4293 | false); |
Ruben Brunk | f56c9f4 | 2016-04-22 18:20:55 -0700 | [diff] [blame] | 4294 | |
| 4295 | a.info.requestedVrComponent = |
| 4296 | sa.getString(R.styleable.AndroidManifestActivity_enableVrMode); |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 4297 | |
| 4298 | a.info.rotationAnimation = |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 4299 | sa.getInt(R.styleable.AndroidManifestActivity_rotationAnimation, ROTATION_ANIMATION_UNSPECIFIED); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 4300 | |
| 4301 | a.info.colorMode = sa.getInt(R.styleable.AndroidManifestActivity_colorMode, |
| 4302 | ActivityInfo.COLOR_MODE_DEFAULT); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4303 | |
| 4304 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showWhenLocked, false)) { |
| 4305 | a.info.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
| 4306 | } |
| 4307 | |
| 4308 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_turnScreenOn, false)) { |
| 4309 | a.info.flags |= ActivityInfo.FLAG_TURN_SCREEN_ON; |
| 4310 | } |
| 4311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | } else { |
| 4313 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4314 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4316 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 4317 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4318 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4319 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4320 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4321 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4322 | false); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4323 | } |
| 4324 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4325 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4326 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4327 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4330 | // can't make this final; we may set it later via meta-data |
| 4331 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4332 | sa.getBoolean(R.styleable.AndroidManifestActivity_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4333 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4334 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4335 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4336 | } |
| 4337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4338 | sa.recycle(); |
| 4339 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4340 | if (receiver && (owner.applicationInfo.privateFlags |
| 4341 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4342 | // A heavy-weight application can not have receives in its main process |
| 4343 | // We can do direct compare because we intern all strings. |
| 4344 | if (a.info.processName == owner.packageName) { |
| 4345 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 4346 | } |
| 4347 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | if (outError[0] != null) { |
| 4350 | return null; |
| 4351 | } |
| 4352 | |
| 4353 | int outerDepth = parser.getDepth(); |
| 4354 | int type; |
| 4355 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4356 | && (type != XmlPullParser.END_TAG |
| 4357 | || parser.getDepth() > outerDepth)) { |
| 4358 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4359 | continue; |
| 4360 | } |
| 4361 | |
| 4362 | if (parser.getName().equals("intent-filter")) { |
| 4363 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4364 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4365 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | return null; |
| 4367 | } |
| 4368 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4369 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4370 | + mArchiveSourcePath + " " |
| 4371 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4373 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4374 | a.intents.add(intent); |
| 4375 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4376 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4377 | final int visibility = visibleToEphemeral |
| 4378 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4379 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4380 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4381 | : IntentFilter.VISIBILITY_NONE; |
| 4382 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4383 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4384 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4385 | } |
| 4386 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4387 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4388 | } |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 4389 | if (LOG_UNSAFE_BROADCASTS && receiver |
| 4390 | && (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O)) { |
| 4391 | for (int i = 0; i < intent.countActions(); i++) { |
| 4392 | final String action = intent.getAction(i); |
| 4393 | if (action == null || !action.startsWith("android.")) continue; |
| 4394 | if (!SAFE_BROADCASTS.contains(action)) { |
| 4395 | Slog.w(TAG, "Broadcast " + action + " may never be delivered to " |
| 4396 | + owner.packageName + " as requested at: " |
| 4397 | + parser.getPositionDescription()); |
| 4398 | } |
| 4399 | } |
| 4400 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4401 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 4402 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4403 | if (!parseIntent(res, parser, false /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4404 | intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4405 | return null; |
| 4406 | } |
| 4407 | if (intent.countActions() == 0) { |
| 4408 | Slog.w(TAG, "No actions in preferred at " |
| 4409 | + mArchiveSourcePath + " " |
| 4410 | + parser.getPositionDescription()); |
| 4411 | } else { |
| 4412 | if (owner.preferredActivityFilters == null) { |
| 4413 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 4414 | } |
| 4415 | owner.preferredActivityFilters.add(intent); |
| 4416 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4417 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4418 | final int visibility = visibleToEphemeral |
| 4419 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4420 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4421 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4422 | : IntentFilter.VISIBILITY_NONE; |
| 4423 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4424 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4425 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4426 | } |
| 4427 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4428 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4431 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | outError)) == null) { |
| 4433 | return null; |
| 4434 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4435 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4436 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | } else { |
| 4438 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4439 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4441 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4442 | + " at " + mArchiveSourcePath + " " |
| 4443 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4445 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4446 | + " at " + mArchiveSourcePath + " " |
| 4447 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | } |
| 4449 | XmlUtils.skipCurrentTag(parser); |
| 4450 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4452 | if (receiver) { |
| 4453 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 4454 | } else { |
| 4455 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 4456 | } |
| 4457 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | if (!setExported) { |
| 4463 | a.info.exported = a.intents.size() > 0; |
| 4464 | } |
| 4465 | |
| 4466 | return a; |
| 4467 | } |
| 4468 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4469 | private void setActivityResizeMode(ActivityInfo aInfo, TypedArray sa, Package owner) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4470 | final boolean appExplicitDefault = (owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4471 | & (PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE |
| 4472 | | PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE)) != 0; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4473 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4474 | if (sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity) |
| 4475 | || appExplicitDefault) { |
| 4476 | // Activity or app explicitly set if it is resizeable or not; |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4477 | final boolean appResizeable = (owner.applicationInfo.privateFlags |
| 4478 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE) != 0; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4479 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity, |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4480 | appResizeable)) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4481 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4482 | } else { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4483 | aInfo.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4484 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4485 | return; |
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 | |
| 4488 | if ((owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4489 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) != 0) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4490 | // The activity or app didn't explicitly set the resizing option, however we want to |
| 4491 | // make it resize due to the sdk version it is targeting. |
| 4492 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 4493 | return; |
| 4494 | } |
| 4495 | |
| 4496 | // resize preference isn't set and target sdk version doesn't support resizing apps by |
| 4497 | // 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] | 4498 | if (aInfo.isFixedOrientationPortrait()) { |
| 4499 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 4500 | } else if (aInfo.isFixedOrientationLandscape()) { |
| 4501 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 4502 | } else if (aInfo.isFixedOrientation()) { |
| 4503 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
| 4504 | } else { |
| 4505 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4506 | } |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4509 | /** |
| 4510 | * Sets every the max aspect ratio of every child activity that doesn't already have an aspect |
| 4511 | * ratio set. |
| 4512 | */ |
| 4513 | private void setMaxAspectRatio(Package owner) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4514 | // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater. |
| 4515 | // 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] | 4516 | float maxAspectRatio = owner.applicationInfo.targetSdkVersion < O |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4517 | ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4518 | |
| 4519 | if (owner.applicationInfo.maxAspectRatio != 0) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4520 | // Use the application max aspect ration as default if set. |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4521 | maxAspectRatio = owner.applicationInfo.maxAspectRatio; |
| 4522 | } else if (owner.mAppMetaData != null |
| 4523 | && owner.mAppMetaData.containsKey(METADATA_MAX_ASPECT_RATIO)) { |
| 4524 | maxAspectRatio = owner.mAppMetaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4527 | for (Activity activity : owner.activities) { |
| 4528 | // If the max aspect ratio for the activity has already been set, skip. |
| 4529 | if (activity.hasMaxAspectRatio()) { |
| 4530 | continue; |
| 4531 | } |
| 4532 | |
| 4533 | // By default we prefer to use a values defined on the activity directly than values |
| 4534 | // defined on the application. We do not check the styled attributes on the activity |
| 4535 | // as it would have already been set when we processed the activity. We wait to process |
| 4536 | // the meta data here since this method is called at the end of processing the |
| 4537 | // application and all meta data is guaranteed. |
| 4538 | final float activityAspectRatio = activity.metaData != null |
| 4539 | ? activity.metaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio) |
| 4540 | : maxAspectRatio; |
| 4541 | |
| 4542 | activity.setMaxAspectRatio(activityAspectRatio); |
Wale Ogunwale | 0cb70ac | 2017-03-27 09:16:38 -0700 | [diff] [blame] | 4543 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4544 | } |
| 4545 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4546 | /** |
| 4547 | * @param configChanges The bit mask of configChanges fetched from AndroidManifest.xml. |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4548 | * @param recreateOnConfigChanges The bit mask recreateOnConfigChanges fetched from |
| 4549 | * AndroidManifest.xml. |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4550 | * @hide Exposed for unit testing only. |
| 4551 | */ |
| 4552 | @TestApi |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4553 | public static int getActivityConfigChanges(int configChanges, int recreateOnConfigChanges) { |
| 4554 | return configChanges | ((~recreateOnConfigChanges) & RECREATE_ON_CONFIG_CHANGES_MASK); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4555 | } |
| 4556 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4557 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4558 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4559 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4560 | int width = -1; |
| 4561 | float widthFraction = -1f; |
| 4562 | int height = -1; |
| 4563 | float heightFraction = -1f; |
| 4564 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4565 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4566 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 4567 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4568 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4569 | 1, 1, -1); |
| 4570 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 4571 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4572 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4573 | -1); |
| 4574 | } |
| 4575 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4576 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4577 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 4578 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4579 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4580 | 1, 1, -1); |
| 4581 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 4582 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4583 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4584 | -1); |
| 4585 | } |
| 4586 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4587 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4588 | Gravity.CENTER); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4589 | int minWidth = sw.getDimensionPixelSize( |
| 4590 | com.android.internal.R.styleable.AndroidManifestLayout_minWidth, |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4591 | -1); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4592 | int minHeight = sw.getDimensionPixelSize( |
| 4593 | com.android.internal.R.styleable.AndroidManifestLayout_minHeight, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4594 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4595 | sw.recycle(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4596 | a.info.windowLayout = new ActivityInfo.WindowLayout(width, widthFraction, |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4597 | height, heightFraction, gravity, minWidth, minHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | private Activity parseActivityAlias(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4601 | XmlResourceParser parser, int flags, String[] outError, |
| 4602 | CachedComponentArgs cachedArgs) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4603 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4604 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4605 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 4606 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4607 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4608 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 4609 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4610 | if (targetActivity == null) { |
| 4611 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 4612 | sa.recycle(); |
| 4613 | return null; |
| 4614 | } |
| 4615 | |
| 4616 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 4617 | targetActivity, outError); |
| 4618 | if (targetActivity == null) { |
| 4619 | sa.recycle(); |
| 4620 | return null; |
| 4621 | } |
| 4622 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4623 | if (cachedArgs.mActivityAliasArgs == null) { |
| 4624 | cachedArgs.mActivityAliasArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4625 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 4626 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 4627 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4628 | com.android.internal.R.styleable.AndroidManifestActivityAlias_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4629 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4630 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4631 | mSeparateProcesses, |
| 4632 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4633 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4634 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4635 | cachedArgs.mActivityAliasArgs.tag = "<activity-alias>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4636 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4637 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4638 | cachedArgs.mActivityAliasArgs.sa = sa; |
| 4639 | cachedArgs.mActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4641 | Activity target = null; |
| 4642 | |
| 4643 | final int NA = owner.activities.size(); |
| 4644 | for (int i=0; i<NA; i++) { |
| 4645 | Activity t = owner.activities.get(i); |
| 4646 | if (targetActivity.equals(t.info.name)) { |
| 4647 | target = t; |
| 4648 | break; |
| 4649 | } |
| 4650 | } |
| 4651 | |
| 4652 | if (target == null) { |
| 4653 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 4654 | + " not found in manifest"; |
| 4655 | sa.recycle(); |
| 4656 | return null; |
| 4657 | } |
| 4658 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4659 | ActivityInfo info = new ActivityInfo(); |
| 4660 | info.targetActivity = targetActivity; |
| 4661 | info.configChanges = target.info.configChanges; |
| 4662 | info.flags = target.info.flags; |
| 4663 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4664 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4665 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4666 | info.labelRes = target.info.labelRes; |
| 4667 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 4668 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 4669 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4670 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4671 | if (info.descriptionRes == 0) { |
| 4672 | info.descriptionRes = target.info.descriptionRes; |
| 4673 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4674 | info.screenOrientation = target.info.screenOrientation; |
| 4675 | info.taskAffinity = target.info.taskAffinity; |
| 4676 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 4677 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4678 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4679 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4680 | info.maxRecents = target.info.maxRecents; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4681 | info.windowLayout = target.info.windowLayout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4682 | info.resizeMode = target.info.resizeMode; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4683 | info.maxAspectRatio = target.info.maxAspectRatio; |
rongliu | c12ede4 | 2018-02-23 17:58:38 -0800 | [diff] [blame] | 4684 | info.requestedVrComponent = target.info.requestedVrComponent; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4685 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4686 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4687 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4688 | Activity a = new Activity(cachedArgs.mActivityAliasArgs, info); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4689 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | sa.recycle(); |
| 4691 | return null; |
| 4692 | } |
| 4693 | |
| 4694 | final boolean setExported = sa.hasValue( |
| 4695 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 4696 | if (setExported) { |
| 4697 | a.info.exported = sa.getBoolean( |
| 4698 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 4699 | } |
| 4700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4701 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4702 | str = sa.getNonConfigurationString( |
| 4703 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | if (str != null) { |
| 4705 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4706 | } |
| 4707 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4708 | String parentName = sa.getNonConfigurationString( |
| 4709 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4710 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4711 | if (parentName != null) { |
| 4712 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4713 | if (outError[0] == null) { |
| 4714 | a.info.parentActivityName = parentClassName; |
| 4715 | } else { |
| 4716 | Log.e(TAG, "Activity alias " + a.info.name + |
| 4717 | " specified invalid parentActivityName " + parentName); |
| 4718 | outError[0] = null; |
| 4719 | } |
| 4720 | } |
| 4721 | |
Chad Brubaker | 699c771 | 2017-01-20 13:53:42 -0800 | [diff] [blame] | 4722 | // TODO add visibleToInstantApps attribute to activity alias |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4723 | final boolean visibleToEphemeral = |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4724 | ((a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4726 | sa.recycle(); |
| 4727 | |
| 4728 | if (outError[0] != null) { |
| 4729 | return null; |
| 4730 | } |
| 4731 | |
| 4732 | int outerDepth = parser.getDepth(); |
| 4733 | int type; |
| 4734 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4735 | && (type != XmlPullParser.END_TAG |
| 4736 | || parser.getDepth() > outerDepth)) { |
| 4737 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4738 | continue; |
| 4739 | } |
| 4740 | |
| 4741 | if (parser.getName().equals("intent-filter")) { |
| 4742 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4743 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4744 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | return null; |
| 4746 | } |
| 4747 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4748 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4749 | + mArchiveSourcePath + " " |
| 4750 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4752 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | a.intents.add(intent); |
| 4754 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4755 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4756 | final int visibility = visibleToEphemeral |
| 4757 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4758 | : isImplicitlyExposedIntent(intent) |
| 4759 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4760 | : IntentFilter.VISIBILITY_NONE; |
| 4761 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4762 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4763 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4764 | } |
| 4765 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4766 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4767 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4768 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4769 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | outError)) == null) { |
| 4771 | return null; |
| 4772 | } |
| 4773 | } else { |
| 4774 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4775 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4776 | + " at " + mArchiveSourcePath + " " |
| 4777 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | XmlUtils.skipCurrentTag(parser); |
| 4779 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4780 | } else { |
| 4781 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 4782 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | } |
| 4785 | } |
| 4786 | |
| 4787 | if (!setExported) { |
| 4788 | a.info.exported = a.intents.size() > 0; |
| 4789 | } |
| 4790 | |
| 4791 | return a; |
| 4792 | } |
| 4793 | |
| 4794 | private Provider parseProvider(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4795 | XmlResourceParser parser, int flags, String[] outError, |
| 4796 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4798 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 4800 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4801 | if (cachedArgs.mProviderArgs == null) { |
| 4802 | cachedArgs.mProviderArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4803 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 4804 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 4805 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4806 | com.android.internal.R.styleable.AndroidManifestProvider_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4807 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4808 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4809 | mSeparateProcesses, |
| 4810 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4811 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4812 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4813 | cachedArgs.mProviderArgs.tag = "<provider>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4814 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4815 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4816 | cachedArgs.mProviderArgs.sa = sa; |
| 4817 | cachedArgs.mProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4818 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4819 | Provider p = new Provider(cachedArgs.mProviderArgs, new ProviderInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4820 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | sa.recycle(); |
| 4822 | return null; |
| 4823 | } |
| 4824 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4825 | boolean providerExportedDefault = false; |
| 4826 | |
| 4827 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 4828 | // For compatibility, applications targeting API level 16 or lower |
| 4829 | // should have their content providers exported by default, unless they |
| 4830 | // specify otherwise. |
| 4831 | providerExportedDefault = true; |
| 4832 | } |
| 4833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4835 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 4836 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4838 | String cpname = sa.getNonConfigurationString( |
| 4839 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | |
| 4841 | p.info.isSyncable = sa.getBoolean( |
| 4842 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 4843 | false); |
| 4844 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4845 | String permission = sa.getNonConfigurationString( |
| 4846 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 4847 | String str = sa.getNonConfigurationString( |
| 4848 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | if (str == null) { |
| 4850 | str = permission; |
| 4851 | } |
| 4852 | if (str == null) { |
| 4853 | p.info.readPermission = owner.applicationInfo.permission; |
| 4854 | } else { |
| 4855 | p.info.readPermission = |
| 4856 | str.length() > 0 ? str.toString().intern() : null; |
| 4857 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4858 | str = sa.getNonConfigurationString( |
| 4859 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 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.writePermission = owner.applicationInfo.permission; |
| 4865 | } else { |
| 4866 | p.info.writePermission = |
| 4867 | str.length() > 0 ? str.toString().intern() : null; |
| 4868 | } |
| 4869 | |
| 4870 | p.info.grantUriPermissions = sa.getBoolean( |
| 4871 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 4872 | false); |
| 4873 | |
| 4874 | p.info.multiprocess = sa.getBoolean( |
| 4875 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 4876 | false); |
| 4877 | |
| 4878 | p.info.initOrder = sa.getInt( |
| 4879 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 4880 | 0); |
| 4881 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4882 | p.info.splitName = |
| 4883 | sa.getNonConfigurationString(R.styleable.AndroidManifestProvider_splitName, 0); |
| 4884 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4885 | p.info.flags = 0; |
| 4886 | |
| 4887 | if (sa.getBoolean( |
| 4888 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 4889 | false)) { |
| 4890 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4893 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 4894 | R.styleable.AndroidManifestProvider_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4895 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4896 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4897 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4898 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4899 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4900 | |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4901 | final boolean visibleToEphemeral = |
| 4902 | sa.getBoolean(R.styleable.AndroidManifestProvider_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4903 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4904 | p.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4905 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4906 | } |
| 4907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | sa.recycle(); |
| 4909 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4910 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 4911 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4912 | // A heavy-weight application can not have providers in its main process |
| 4913 | // We can do direct compare because we intern all strings. |
| 4914 | if (p.info.processName == owner.packageName) { |
| 4915 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 4916 | return null; |
| 4917 | } |
| 4918 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4920 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4921 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | return null; |
| 4923 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 4924 | if (cpname.length() <= 0) { |
| 4925 | outError[0] = "<provider> has empty authorities attribute"; |
| 4926 | return null; |
| 4927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | p.info.authority = cpname.intern(); |
| 4929 | |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4930 | if (!parseProviderTags( |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 4931 | res, parser, visibleToEphemeral, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | return null; |
| 4933 | } |
| 4934 | |
| 4935 | return p; |
| 4936 | } |
| 4937 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4938 | private boolean parseProviderTags(Resources res, XmlResourceParser parser, |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 4939 | boolean visibleToEphemeral, Provider outInfo, String[] outError) |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4940 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | int outerDepth = parser.getDepth(); |
| 4942 | int type; |
| 4943 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4944 | && (type != XmlPullParser.END_TAG |
| 4945 | || parser.getDepth() > outerDepth)) { |
| 4946 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4947 | continue; |
| 4948 | } |
| 4949 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4950 | if (parser.getName().equals("intent-filter")) { |
| 4951 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4952 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4953 | intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4954 | return false; |
| 4955 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4956 | if (visibleToEphemeral) { |
| 4957 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 4958 | outInfo.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4959 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4960 | outInfo.order = Math.max(intent.getOrder(), outInfo.order); |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4961 | outInfo.intents.add(intent); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4962 | |
| 4963 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4964 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | outInfo.metaData, outError)) == null) { |
| 4966 | return false; |
| 4967 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4970 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 4972 | |
| 4973 | PatternMatcher pa = null; |
| 4974 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4975 | String str = sa.getNonConfigurationString( |
| 4976 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4977 | if (str != null) { |
| 4978 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 4979 | } |
| 4980 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4981 | str = sa.getNonConfigurationString( |
| 4982 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | if (str != null) { |
| 4984 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 4985 | } |
| 4986 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4987 | str = sa.getNonConfigurationString( |
| 4988 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4989 | if (str != null) { |
| 4990 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4991 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4993 | sa.recycle(); |
| 4994 | |
| 4995 | if (pa != null) { |
| 4996 | if (outInfo.info.uriPermissionPatterns == null) { |
| 4997 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 4998 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 4999 | } else { |
| 5000 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 5001 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 5002 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 5003 | newp[N] = pa; |
| 5004 | outInfo.info.uriPermissionPatterns = newp; |
| 5005 | } |
| 5006 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5007 | } else { |
| 5008 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5009 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5010 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5011 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5012 | XmlUtils.skipCurrentTag(parser); |
| 5013 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5014 | } else { |
| 5015 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5016 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5017 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5018 | } |
| 5019 | XmlUtils.skipCurrentTag(parser); |
| 5020 | |
| 5021 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5022 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5023 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 5024 | |
| 5025 | PathPermission pa = null; |
| 5026 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5027 | String permission = sa.getNonConfigurationString( |
| 5028 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 5029 | String readPermission = sa.getNonConfigurationString( |
| 5030 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5031 | if (readPermission == null) { |
| 5032 | readPermission = permission; |
| 5033 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5034 | String writePermission = sa.getNonConfigurationString( |
| 5035 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5036 | if (writePermission == null) { |
| 5037 | writePermission = permission; |
| 5038 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5039 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5040 | boolean havePerm = false; |
| 5041 | if (readPermission != null) { |
| 5042 | readPermission = readPermission.intern(); |
| 5043 | havePerm = true; |
| 5044 | } |
| 5045 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 5046 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5047 | havePerm = true; |
| 5048 | } |
| 5049 | |
| 5050 | if (!havePerm) { |
| 5051 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5052 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5053 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5054 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5055 | XmlUtils.skipCurrentTag(parser); |
| 5056 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5057 | } else { |
| 5058 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 5059 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5060 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5061 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5062 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5063 | String path = sa.getNonConfigurationString( |
| 5064 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5065 | if (path != null) { |
| 5066 | pa = new PathPermission(path, |
| 5067 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 5068 | } |
| 5069 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5070 | path = sa.getNonConfigurationString( |
| 5071 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5072 | if (path != null) { |
| 5073 | pa = new PathPermission(path, |
| 5074 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 5075 | } |
| 5076 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5077 | path = sa.getNonConfigurationString( |
| 5078 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5079 | if (path != null) { |
| 5080 | pa = new PathPermission(path, |
| 5081 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 5082 | } |
| 5083 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5084 | path = sa.getNonConfigurationString( |
| 5085 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathAdvancedPattern, 0); |
| 5086 | if (path != null) { |
| 5087 | pa = new PathPermission(path, |
| 5088 | PatternMatcher.PATTERN_ADVANCED_GLOB, readPermission, writePermission); |
| 5089 | } |
| 5090 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5091 | sa.recycle(); |
| 5092 | |
| 5093 | if (pa != null) { |
| 5094 | if (outInfo.info.pathPermissions == null) { |
| 5095 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 5096 | outInfo.info.pathPermissions[0] = pa; |
| 5097 | } else { |
| 5098 | final int N = outInfo.info.pathPermissions.length; |
| 5099 | PathPermission[] newp = new PathPermission[N+1]; |
| 5100 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 5101 | newp[N] = pa; |
| 5102 | outInfo.info.pathPermissions = newp; |
| 5103 | } |
| 5104 | } else { |
| 5105 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5106 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5107 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5108 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5109 | XmlUtils.skipCurrentTag(parser); |
| 5110 | continue; |
| 5111 | } |
| 5112 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5113 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | } |
| 5115 | XmlUtils.skipCurrentTag(parser); |
| 5116 | |
| 5117 | } else { |
| 5118 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5119 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5120 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5121 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | XmlUtils.skipCurrentTag(parser); |
| 5123 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5124 | } else { |
| 5125 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 5126 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | } |
| 5129 | } |
| 5130 | return true; |
| 5131 | } |
| 5132 | |
| 5133 | private Service parseService(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5134 | XmlResourceParser parser, int flags, String[] outError, |
| 5135 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5137 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5138 | com.android.internal.R.styleable.AndroidManifestService); |
| 5139 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5140 | if (cachedArgs.mServiceArgs == null) { |
| 5141 | cachedArgs.mServiceArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5142 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 5143 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 5144 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5145 | com.android.internal.R.styleable.AndroidManifestService_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5146 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5147 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5148 | mSeparateProcesses, |
| 5149 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5150 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5151 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5152 | cachedArgs.mServiceArgs.tag = "<service>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5153 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5154 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5155 | cachedArgs.mServiceArgs.sa = sa; |
| 5156 | cachedArgs.mServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5157 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5158 | Service s = new Service(cachedArgs.mServiceArgs, new ServiceInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5159 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | sa.recycle(); |
| 5161 | return null; |
| 5162 | } |
| 5163 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5164 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5165 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 5166 | if (setExported) { |
| 5167 | s.info.exported = sa.getBoolean( |
| 5168 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 5169 | } |
| 5170 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5171 | String str = sa.getNonConfigurationString( |
| 5172 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | if (str == null) { |
| 5174 | s.info.permission = owner.applicationInfo.permission; |
| 5175 | } else { |
| 5176 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 5177 | } |
| 5178 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5179 | s.info.splitName = |
| 5180 | sa.getNonConfigurationString(R.styleable.AndroidManifestService_splitName, 0); |
| 5181 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5182 | s.info.flags = 0; |
| 5183 | if (sa.getBoolean( |
| 5184 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 5185 | false)) { |
| 5186 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 5187 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5188 | if (sa.getBoolean( |
| 5189 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 5190 | false)) { |
| 5191 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 5192 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5193 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 5194 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 5195 | false)) { |
| 5196 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 5197 | } |
| 5198 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5199 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 5200 | false)) { |
| 5201 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5202 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5203 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5204 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 5205 | R.styleable.AndroidManifestService_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5206 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5207 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5208 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5209 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5210 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5211 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5212 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5213 | sa.getBoolean(R.styleable.AndroidManifestService_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5214 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5215 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5216 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5217 | } |
| 5218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5219 | sa.recycle(); |
| 5220 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5221 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5222 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5223 | // A heavy-weight application can not have services in its main process |
| 5224 | // We can do direct compare because we intern all strings. |
| 5225 | if (s.info.processName == owner.packageName) { |
| 5226 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 5227 | return null; |
| 5228 | } |
| 5229 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5231 | int outerDepth = parser.getDepth(); |
| 5232 | int type; |
| 5233 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5234 | && (type != XmlPullParser.END_TAG |
| 5235 | || parser.getDepth() > outerDepth)) { |
| 5236 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5237 | continue; |
| 5238 | } |
| 5239 | |
| 5240 | if (parser.getName().equals("intent-filter")) { |
| 5241 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5242 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5243 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5244 | return null; |
| 5245 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5246 | if (visibleToEphemeral) { |
| 5247 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5248 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5249 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5250 | s.order = Math.max(intent.getOrder(), s.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | s.intents.add(intent); |
| 5252 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5253 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5254 | outError)) == null) { |
| 5255 | return null; |
| 5256 | } |
| 5257 | } else { |
| 5258 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5259 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5260 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5261 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | XmlUtils.skipCurrentTag(parser); |
| 5263 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5264 | } else { |
| 5265 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 5266 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | if (!setExported) { |
| 5272 | s.info.exported = s.intents.size() > 0; |
| 5273 | } |
| 5274 | |
| 5275 | return s; |
| 5276 | } |
| 5277 | |
Chad Brubaker | 4941483 | 2017-04-13 16:13:23 -0700 | [diff] [blame] | 5278 | private boolean isImplicitlyExposedIntent(IntentInfo intent) { |
| 5279 | return intent.hasCategory(Intent.CATEGORY_BROWSABLE) |
| 5280 | || intent.hasAction(Intent.ACTION_SEND) |
| 5281 | || intent.hasAction(Intent.ACTION_SENDTO) |
| 5282 | || intent.hasAction(Intent.ACTION_SEND_MULTIPLE); |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5283 | } |
| 5284 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5285 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 5286 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | int outerDepth = parser.getDepth(); |
| 5288 | int type; |
| 5289 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5290 | && (type != XmlPullParser.END_TAG |
| 5291 | || parser.getDepth() > outerDepth)) { |
| 5292 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5293 | continue; |
| 5294 | } |
| 5295 | |
| 5296 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5297 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | outInfo.metaData, outError)) == null) { |
| 5299 | return false; |
| 5300 | } |
| 5301 | } else { |
| 5302 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5303 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5304 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5305 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | XmlUtils.skipCurrentTag(parser); |
| 5307 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5308 | } else { |
| 5309 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 5310 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | } |
| 5313 | } |
| 5314 | return true; |
| 5315 | } |
| 5316 | |
| 5317 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5318 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | throws XmlPullParserException, IOException { |
| 5320 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5321 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 5323 | |
| 5324 | if (data == null) { |
| 5325 | data = new Bundle(); |
| 5326 | } |
| 5327 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5328 | String name = sa.getNonConfigurationString( |
| 5329 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5330 | if (name == null) { |
| 5331 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 5332 | sa.recycle(); |
| 5333 | return null; |
| 5334 | } |
| 5335 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 5336 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5338 | TypedValue v = sa.peekValue( |
| 5339 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 5340 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5341 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | data.putInt(name, v.resourceId); |
| 5343 | } else { |
| 5344 | v = sa.peekValue( |
| 5345 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5346 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5347 | if (v != null) { |
| 5348 | if (v.type == TypedValue.TYPE_STRING) { |
| 5349 | CharSequence cs = v.coerceToString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 5350 | data.putString(name, cs != null ? cs.toString() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 5352 | data.putBoolean(name, v.data != 0); |
| 5353 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 5354 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 5355 | data.putInt(name, v.data); |
| 5356 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 5357 | data.putFloat(name, v.getFloat()); |
| 5358 | } else { |
| 5359 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5360 | 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] | 5361 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5362 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5363 | } else { |
| 5364 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 5365 | data = null; |
| 5366 | } |
| 5367 | } |
| 5368 | } else { |
| 5369 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 5370 | data = null; |
| 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | sa.recycle(); |
| 5375 | |
| 5376 | XmlUtils.skipCurrentTag(parser); |
| 5377 | |
| 5378 | return data; |
| 5379 | } |
| 5380 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5381 | private static VerifierInfo parseVerifier(AttributeSet attrs) { |
| 5382 | String packageName = null; |
| 5383 | String encodedPublicKey = null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5384 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5385 | final int attrCount = attrs.getAttributeCount(); |
| 5386 | for (int i = 0; i < attrCount; i++) { |
| 5387 | final int attrResId = attrs.getAttributeNameResource(i); |
| 5388 | switch (attrResId) { |
| 5389 | case com.android.internal.R.attr.name: |
| 5390 | packageName = attrs.getAttributeValue(i); |
| 5391 | break; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5392 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5393 | case com.android.internal.R.attr.publicKey: |
| 5394 | encodedPublicKey = attrs.getAttributeValue(i); |
| 5395 | break; |
| 5396 | } |
| 5397 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5398 | |
| 5399 | if (packageName == null || packageName.length() == 0) { |
| 5400 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 5401 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5404 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 5405 | if (publicKey == null) { |
| 5406 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 5407 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5408 | } |
| 5409 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5410 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5411 | } |
| 5412 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5413 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 5414 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5415 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5416 | return null; |
| 5417 | } |
| 5418 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5419 | EncodedKeySpec keySpec; |
| 5420 | try { |
| 5421 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 5422 | keySpec = new X509EncodedKeySpec(encoded); |
| 5423 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5424 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5425 | return null; |
| 5426 | } |
| 5427 | |
| 5428 | /* First try the key as an RSA key. */ |
| 5429 | try { |
| 5430 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5431 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5432 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5433 | 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] | 5434 | } catch (InvalidKeySpecException e) { |
| 5435 | // Not a RSA public key. |
| 5436 | } |
| 5437 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5438 | /* Now try it as a ECDSA key. */ |
| 5439 | try { |
| 5440 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 5441 | return keyFactory.generatePublic(keySpec); |
| 5442 | } catch (NoSuchAlgorithmException e) { |
| 5443 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 5444 | } catch (InvalidKeySpecException e) { |
| 5445 | // Not a ECDSA public key. |
| 5446 | } |
| 5447 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5448 | /* Now try it as a DSA key. */ |
| 5449 | try { |
| 5450 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5451 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5452 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5453 | 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] | 5454 | } catch (InvalidKeySpecException e) { |
| 5455 | // Not a DSA public key. |
| 5456 | } |
| 5457 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5458 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5459 | return null; |
| 5460 | } |
| 5461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | private static final String ANDROID_RESOURCES |
| 5463 | = "http://schemas.android.com/apk/res/android"; |
| 5464 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5465 | private boolean parseIntent(Resources res, XmlResourceParser parser, boolean allowGlobs, |
| 5466 | boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
| 5467 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5469 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5470 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 5471 | |
| 5472 | int priority = sa.getInt( |
| 5473 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5474 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 5475 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5476 | int order = sa.getInt( |
| 5477 | com.android.internal.R.styleable.AndroidManifestIntentFilter_order, 0); |
| 5478 | outInfo.setOrder(order); |
| 5479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5480 | TypedValue v = sa.peekValue( |
| 5481 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 5482 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5483 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5484 | } |
| 5485 | |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 5486 | final boolean useRoundIcon = |
| 5487 | Resources.getSystem().getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 5488 | int roundIconVal = useRoundIcon ? sa.getResourceId( |
| 5489 | com.android.internal.R.styleable.AndroidManifestIntentFilter_roundIcon, 0) : 0; |
| 5490 | if (roundIconVal != 0) { |
| 5491 | outInfo.icon = roundIconVal; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5492 | } else { |
| 5493 | outInfo.icon = sa.getResourceId( |
| 5494 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
| 5495 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5496 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5497 | outInfo.logo = sa.getResourceId( |
| 5498 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5500 | outInfo.banner = sa.getResourceId( |
| 5501 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 5502 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 5503 | if (allowAutoVerify) { |
| 5504 | outInfo.setAutoVerify(sa.getBoolean( |
| 5505 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 5506 | false)); |
| 5507 | } |
| 5508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | sa.recycle(); |
| 5510 | |
| 5511 | int outerDepth = parser.getDepth(); |
| 5512 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5513 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5514 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5515 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5516 | continue; |
| 5517 | } |
| 5518 | |
| 5519 | String nodeName = parser.getName(); |
| 5520 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5521 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | ANDROID_RESOURCES, "name"); |
| 5523 | if (value == null || value == "") { |
| 5524 | outError[0] = "No value supplied for <android:name>"; |
| 5525 | return false; |
| 5526 | } |
| 5527 | XmlUtils.skipCurrentTag(parser); |
| 5528 | |
| 5529 | outInfo.addAction(value); |
| 5530 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5531 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | ANDROID_RESOURCES, "name"); |
| 5533 | if (value == null || value == "") { |
| 5534 | outError[0] = "No value supplied for <android:name>"; |
| 5535 | return false; |
| 5536 | } |
| 5537 | XmlUtils.skipCurrentTag(parser); |
| 5538 | |
| 5539 | outInfo.addCategory(value); |
| 5540 | |
| 5541 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5542 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | com.android.internal.R.styleable.AndroidManifestData); |
| 5544 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5545 | String str = sa.getNonConfigurationString( |
| 5546 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5547 | if (str != null) { |
| 5548 | try { |
| 5549 | outInfo.addDataType(str); |
| 5550 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 5551 | outError[0] = e.toString(); |
| 5552 | sa.recycle(); |
| 5553 | return false; |
| 5554 | } |
| 5555 | } |
| 5556 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5557 | str = sa.getNonConfigurationString( |
| 5558 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | if (str != null) { |
| 5560 | outInfo.addDataScheme(str); |
| 5561 | } |
| 5562 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5563 | str = sa.getNonConfigurationString( |
| 5564 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 5565 | if (str != null) { |
| 5566 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 5567 | } |
| 5568 | |
| 5569 | str = sa.getNonConfigurationString( |
| 5570 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 5571 | if (str != null) { |
| 5572 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 5573 | } |
| 5574 | |
| 5575 | str = sa.getNonConfigurationString( |
| 5576 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 5577 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5578 | if (!allowGlobs) { |
| 5579 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 5580 | return false; |
| 5581 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5582 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5583 | } |
| 5584 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5585 | String host = sa.getNonConfigurationString( |
| 5586 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 5587 | String port = sa.getNonConfigurationString( |
| 5588 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5589 | if (host != null) { |
| 5590 | outInfo.addDataAuthority(host, port); |
| 5591 | } |
| 5592 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5593 | str = sa.getNonConfigurationString( |
| 5594 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | if (str != null) { |
| 5596 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 5597 | } |
| 5598 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5599 | str = sa.getNonConfigurationString( |
| 5600 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | if (str != null) { |
| 5602 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 5603 | } |
| 5604 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5605 | str = sa.getNonConfigurationString( |
| 5606 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5607 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5608 | if (!allowGlobs) { |
| 5609 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 5610 | return false; |
| 5611 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5613 | } |
| 5614 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5615 | str = sa.getNonConfigurationString( |
| 5616 | com.android.internal.R.styleable.AndroidManifestData_pathAdvancedPattern, 0); |
| 5617 | if (str != null) { |
| 5618 | if (!allowGlobs) { |
| 5619 | outError[0] = "pathAdvancedPattern not allowed here; path must be literal"; |
| 5620 | return false; |
| 5621 | } |
| 5622 | outInfo.addDataPath(str, PatternMatcher.PATTERN_ADVANCED_GLOB); |
| 5623 | } |
| 5624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | sa.recycle(); |
| 5626 | XmlUtils.skipCurrentTag(parser); |
| 5627 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5628 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5629 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5630 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | XmlUtils.skipCurrentTag(parser); |
| 5632 | } else { |
| 5633 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 5634 | return false; |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5639 | |
| 5640 | if (DEBUG_PARSER) { |
| 5641 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 5642 | cats.append(outInfo.hasDefault); |
| 5643 | cats.append(", cat="); |
| 5644 | |
| 5645 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 5646 | if (it != null) { |
| 5647 | while (it.hasNext()) { |
| 5648 | cats.append(' '); |
| 5649 | cats.append(it.next()); |
| 5650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5652 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | return true; |
| 5656 | } |
| 5657 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5658 | /** |
| 5659 | * A container for signing-related data of an application package. |
| 5660 | * @hide |
| 5661 | */ |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5662 | public static final class SigningDetails implements Parcelable { |
| 5663 | |
| 5664 | @IntDef({SigningDetails.SignatureSchemeVersion.UNKNOWN, |
| 5665 | SigningDetails.SignatureSchemeVersion.JAR, |
| 5666 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2, |
| 5667 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V3}) |
| 5668 | public @interface SignatureSchemeVersion { |
| 5669 | int UNKNOWN = 0; |
| 5670 | int JAR = 1; |
| 5671 | int SIGNING_BLOCK_V2 = 2; |
| 5672 | int SIGNING_BLOCK_V3 = 3; |
| 5673 | } |
| 5674 | |
| 5675 | @Nullable |
| 5676 | public final Signature[] signatures; |
| 5677 | @SignatureSchemeVersion |
| 5678 | public final int signatureSchemeVersion; |
| 5679 | @Nullable |
| 5680 | public final ArraySet<PublicKey> publicKeys; |
| 5681 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5682 | /** |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5683 | * APK Signature Scheme v3 includes support for adding a proof-of-rotation record that |
| 5684 | * contains two pieces of information: |
| 5685 | * 1) the past signing certificates |
| 5686 | * 2) the flags that APK wants to assign to each of the past signing certificates. |
| 5687 | * |
| 5688 | * This collection of {@code Signature} objects, each of which is formed from a former |
| 5689 | * signing certificate of this APK before it was changed by signing certificate rotation, |
| 5690 | * represents the first piece of information. It is the APK saying to the rest of the |
| 5691 | * world: "hey if you trust the old cert, you can trust me!" This is useful, if for |
| 5692 | * instance, the platform would like to determine whether or not to allow this APK to do |
| 5693 | * something it would've allowed it to do under the old cert (like upgrade). |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5694 | */ |
| 5695 | @Nullable |
| 5696 | public final Signature[] pastSigningCertificates; |
| 5697 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5698 | /** special value used to see if cert is in package - not exposed to callers */ |
| 5699 | private static final int PAST_CERT_EXISTS = 0; |
| 5700 | |
| 5701 | @IntDef( |
| 5702 | flag = true, |
| 5703 | value = {CertCapabilities.INSTALLED_DATA, |
| 5704 | CertCapabilities.SHARED_USER_ID, |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 5705 | CertCapabilities.PERMISSION, |
| 5706 | CertCapabilities.ROLLBACK}) |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5707 | public @interface CertCapabilities { |
| 5708 | |
| 5709 | /** accept data from already installed pkg with this cert */ |
| 5710 | int INSTALLED_DATA = 1; |
| 5711 | |
| 5712 | /** accept sharedUserId with pkg with this cert */ |
| 5713 | int SHARED_USER_ID = 2; |
| 5714 | |
| 5715 | /** grant SIGNATURE permissions to pkgs with this cert */ |
| 5716 | int PERMISSION = 4; |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 5717 | |
| 5718 | /** allow pkg to update to one signed by this certificate */ |
| 5719 | int ROLLBACK = 8; |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 5720 | |
| 5721 | /** allow pkg to continue to have auth access gated by this cert */ |
| 5722 | int AUTH = 16; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5723 | } |
| 5724 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5725 | /** |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5726 | * APK Signature Scheme v3 includes support for adding a proof-of-rotation record that |
| 5727 | * contains two pieces of information: |
| 5728 | * 1) the past signing certificates |
| 5729 | * 2) the flags that APK wants to assign to each of the past signing certificates. |
| 5730 | * |
| 5731 | * These flags, which have a one-to-one relationship for the {@code pastSigningCertificates} |
| 5732 | * collection, represent the second piece of information and are viewed as capabilities. |
| 5733 | * They are an APK's way of telling the platform: "this is how I want to trust my old certs, |
| 5734 | * please enforce that." This is useful for situation where this app itself is using its |
| 5735 | * signing certificate as an authorization mechanism, like whether or not to allow another |
| 5736 | * app to have its SIGNATURE permission. An app could specify whether to allow other apps |
| 5737 | * signed by its old cert 'X' to still get a signature permission it defines, for example. |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5738 | */ |
| 5739 | @Nullable |
| 5740 | public final int[] pastSigningCertificatesFlags; |
| 5741 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5742 | /** A representation of unknown signing details. Use instead of null. */ |
| 5743 | public static final SigningDetails UNKNOWN = |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5744 | new SigningDetails(null, SignatureSchemeVersion.UNKNOWN, null, null, null); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5745 | |
| 5746 | @VisibleForTesting |
| 5747 | public SigningDetails(Signature[] signatures, |
| 5748 | @SignatureSchemeVersion int signatureSchemeVersion, |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5749 | ArraySet<PublicKey> keys, Signature[] pastSigningCertificates, |
| 5750 | int[] pastSigningCertificatesFlags) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5751 | this.signatures = signatures; |
| 5752 | this.signatureSchemeVersion = signatureSchemeVersion; |
| 5753 | this.publicKeys = keys; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5754 | this.pastSigningCertificates = pastSigningCertificates; |
| 5755 | this.pastSigningCertificatesFlags = pastSigningCertificatesFlags; |
| 5756 | } |
| 5757 | |
| 5758 | public SigningDetails(Signature[] signatures, |
| 5759 | @SignatureSchemeVersion int signatureSchemeVersion, |
| 5760 | Signature[] pastSigningCertificates, int[] pastSigningCertificatesFlags) |
| 5761 | throws CertificateException { |
| 5762 | this(signatures, signatureSchemeVersion, toSigningKeys(signatures), |
| 5763 | pastSigningCertificates, pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | public SigningDetails(Signature[] signatures, |
| 5767 | @SignatureSchemeVersion int signatureSchemeVersion) |
| 5768 | throws CertificateException { |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5769 | this(signatures, signatureSchemeVersion, |
| 5770 | null, null); |
| 5771 | } |
| 5772 | |
| 5773 | public SigningDetails(SigningDetails orig) { |
| 5774 | if (orig != null) { |
| 5775 | if (orig.signatures != null) { |
| 5776 | this.signatures = orig.signatures.clone(); |
| 5777 | } else { |
| 5778 | this.signatures = null; |
| 5779 | } |
| 5780 | this.signatureSchemeVersion = orig.signatureSchemeVersion; |
| 5781 | this.publicKeys = new ArraySet<>(orig.publicKeys); |
| 5782 | if (orig.pastSigningCertificates != null) { |
| 5783 | this.pastSigningCertificates = orig.pastSigningCertificates.clone(); |
| 5784 | this.pastSigningCertificatesFlags = orig.pastSigningCertificatesFlags.clone(); |
| 5785 | } else { |
| 5786 | this.pastSigningCertificates = null; |
| 5787 | this.pastSigningCertificatesFlags = null; |
| 5788 | } |
| 5789 | } else { |
| 5790 | this.signatures = null; |
| 5791 | this.signatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 5792 | this.publicKeys = null; |
| 5793 | this.pastSigningCertificates = null; |
| 5794 | this.pastSigningCertificatesFlags = null; |
| 5795 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | /** Returns true if the signing details have one or more signatures. */ |
| 5799 | public boolean hasSignatures() { |
| 5800 | return signatures != null && signatures.length > 0; |
| 5801 | } |
| 5802 | |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 5803 | /** Returns true if the signing details have past signing certificates. */ |
| 5804 | public boolean hasPastSigningCertificates() { |
| 5805 | return pastSigningCertificates != null && pastSigningCertificates.length > 0; |
| 5806 | } |
| 5807 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5808 | /** |
| 5809 | * Determines if the provided {@code oldDetails} is an ancestor of or the same as this one. |
| 5810 | * If the {@code oldDetails} signing certificate appears in our pastSigningCertificates, |
| 5811 | * then that means it has authorized a signing certificate rotation, which eventually leads |
| 5812 | * to our certificate, and thus can be trusted. If this method evaluates to true, this |
| 5813 | * SigningDetails object should be trusted if the previous one is. |
| 5814 | */ |
| 5815 | public boolean hasAncestorOrSelf(SigningDetails oldDetails) { |
| 5816 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 5817 | return false; |
| 5818 | } |
| 5819 | if (oldDetails.signatures.length > 1) { |
| 5820 | |
| 5821 | // multiple-signer packages cannot rotate signing certs, so we just compare current |
| 5822 | // signers for an exact match |
| 5823 | return signaturesMatchExactly(oldDetails); |
| 5824 | } else { |
| 5825 | |
| 5826 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 5827 | // was one of our old signing certificates |
| 5828 | return hasCertificate(oldDetails.signatures[0]); |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | /** |
| 5833 | * Similar to {@code hasAncestorOrSelf}. Returns true only if this {@code SigningDetails} |
| 5834 | * is a descendant of {@code oldDetails}, not if they're the same. This is used to |
| 5835 | * determine if this object is newer than the provided one. |
| 5836 | */ |
| 5837 | public boolean hasAncestor(SigningDetails oldDetails) { |
| 5838 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 5839 | return false; |
| 5840 | } |
| 5841 | if (this.hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 5842 | |
| 5843 | // the last entry in pastSigningCertificates is the current signer, ignore it |
| 5844 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 5845 | if (pastSigningCertificates[i].equals(oldDetails.signatures[i])) { |
| 5846 | return true; |
| 5847 | } |
| 5848 | } |
| 5849 | } |
| 5850 | return false; |
| 5851 | } |
| 5852 | |
| 5853 | /** |
| 5854 | * Determines if the provided {@code oldDetails} is an ancestor of this one, and whether or |
| 5855 | * not this one grants it the provided capability, represented by the {@code flags} |
| 5856 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 5857 | * with entities signed by its old signing certificate and not want to break previously |
| 5858 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 5859 | * signed by the newer signing certificate would like to continue to give to its previous |
| 5860 | * signing certificate(s). |
| 5861 | */ |
| 5862 | public boolean checkCapability(SigningDetails oldDetails, @CertCapabilities int flags) { |
| 5863 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 5864 | return false; |
| 5865 | } |
| 5866 | if (oldDetails.signatures.length > 1) { |
| 5867 | |
| 5868 | // multiple-signer packages cannot rotate signing certs, so we must have an exact |
| 5869 | // match, which also means all capabilities are granted |
| 5870 | return signaturesMatchExactly(oldDetails); |
| 5871 | } else { |
| 5872 | |
| 5873 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 5874 | // was one of our old signing certificates, and if we grant it the capability it's |
| 5875 | // requesting |
| 5876 | return hasCertificate(oldDetails.signatures[0], flags); |
| 5877 | } |
| 5878 | } |
| 5879 | |
| 5880 | /** |
| 5881 | * A special case of {@code checkCapability} which re-encodes both sets of signing |
| 5882 | * certificates to counteract a previous re-encoding. |
| 5883 | */ |
| 5884 | public boolean checkCapabilityRecover(SigningDetails oldDetails, |
| 5885 | @CertCapabilities int flags) throws CertificateException { |
| 5886 | if (oldDetails == UNKNOWN || this == UNKNOWN) { |
| 5887 | return false; |
| 5888 | } |
| 5889 | if (hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 5890 | |
| 5891 | // signing certificates may have rotated, check entire history for effective match |
| 5892 | for (int i = 0; i < pastSigningCertificates.length; i++) { |
| 5893 | if (Signature.areEffectiveMatch( |
| 5894 | oldDetails.signatures[0], |
| 5895 | pastSigningCertificates[i]) |
| 5896 | && pastSigningCertificatesFlags[i] == flags) { |
| 5897 | return true; |
| 5898 | } |
| 5899 | } |
| 5900 | } else { |
| 5901 | return Signature.areEffectiveMatch(oldDetails.signatures, signatures); |
| 5902 | } |
| 5903 | return false; |
| 5904 | } |
| 5905 | |
| 5906 | /** |
| 5907 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 5908 | * including the current signer. Automatically returns false if this object has multiple |
| 5909 | * signing certificates, since rotation is only supported for single-signers; this is |
| 5910 | * enforced by {@code hasCertificateInternal}. |
| 5911 | */ |
| 5912 | public boolean hasCertificate(Signature signature) { |
| 5913 | return hasCertificateInternal(signature, PAST_CERT_EXISTS); |
| 5914 | } |
| 5915 | |
| 5916 | /** |
| 5917 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 5918 | * including the current signer, and whether or not it has the given permission. |
| 5919 | * Certificates which match our current signer automatically get all capabilities. |
| 5920 | * Automatically returns false if this object has multiple signing certificates, since |
| 5921 | * rotation is only supported for single-signers. |
| 5922 | */ |
| 5923 | public boolean hasCertificate(Signature signature, @CertCapabilities int flags) { |
| 5924 | return hasCertificateInternal(signature, flags); |
| 5925 | } |
| 5926 | |
| 5927 | /** Convenient wrapper for calling {@code hasCertificate} with certificate's raw bytes. */ |
| 5928 | public boolean hasCertificate(byte[] certificate) { |
| 5929 | Signature signature = new Signature(certificate); |
| 5930 | return hasCertificate(signature); |
| 5931 | } |
| 5932 | |
| 5933 | private boolean hasCertificateInternal(Signature signature, int flags) { |
| 5934 | if (this == UNKNOWN) { |
| 5935 | return false; |
| 5936 | } |
| 5937 | |
| 5938 | // only single-signed apps can have pastSigningCertificates |
| 5939 | if (hasPastSigningCertificates()) { |
| 5940 | |
| 5941 | // check all past certs, except for the current one, which automatically gets all |
| 5942 | // capabilities, since it is the same as the current signature |
| 5943 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 5944 | if (pastSigningCertificates[i].equals(signature)) { |
| 5945 | if (flags == PAST_CERT_EXISTS |
| 5946 | || (flags & pastSigningCertificatesFlags[i]) == flags) { |
| 5947 | return true; |
| 5948 | } |
| 5949 | } |
| 5950 | } |
| 5951 | } |
| 5952 | |
| 5953 | // not in previous certs signing history, just check the current signer and make sure |
| 5954 | // we are singly-signed |
| 5955 | return signatures.length == 1 && signatures[0].equals(signature); |
| 5956 | } |
| 5957 | |
| 5958 | /** |
| 5959 | * Determines if the provided {@code sha256String} is an ancestor of this one, and whether |
| 5960 | * or not this one grants it the provided capability, represented by the {@code flags} |
| 5961 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 5962 | * with entities signed by its old signing certificate and not want to break previously |
| 5963 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 5964 | * signed by the newer signing certificate would like to continue to give to its previous |
| 5965 | * signing certificate(s). |
| 5966 | * |
| 5967 | * @param sha256String A hex-encoded representation of a sha256 digest. In the case of an |
| 5968 | * app with multiple signers, this represents the hex-encoded sha256 |
| 5969 | * digest of the combined hex-encoded sha256 digests of each individual |
| 5970 | * signing certificate according to {@link |
| 5971 | * PackageUtils#computeSignaturesSha256Digest(Signature[])} |
| 5972 | */ |
| 5973 | public boolean checkCapability(String sha256String, @CertCapabilities int flags) { |
| 5974 | if (this == UNKNOWN) { |
| 5975 | return false; |
| 5976 | } |
| 5977 | |
| 5978 | // first see if the hash represents a single-signer in our signing history |
| 5979 | byte[] sha256Bytes = ByteStringUtils.fromHexToByteArray(sha256String); |
| 5980 | if (hasSha256Certificate(sha256Bytes, flags)) { |
| 5981 | return true; |
| 5982 | } |
| 5983 | |
| 5984 | // Not in signing history, either represents multiple signatures or not a match. |
| 5985 | // Multiple signers can't rotate, so no need to check flags, just see if the SHAs match. |
| 5986 | // We already check the single-signer case above as part of hasSha256Certificate, so no |
| 5987 | // need to verify we have multiple signers, just run the old check |
| 5988 | // just consider current signing certs |
| 5989 | final String[] mSignaturesSha256Digests = |
| 5990 | PackageUtils.computeSignaturesSha256Digests(signatures); |
| 5991 | final String mSignaturesSha256Digest = |
| 5992 | PackageUtils.computeSignaturesSha256Digest(mSignaturesSha256Digests); |
| 5993 | return mSignaturesSha256Digest.equals(sha256String); |
| 5994 | } |
| 5995 | |
| 5996 | /** |
| 5997 | * Determine if the {@code sha256Certificate} is in this SigningDetails' signing certificate |
| 5998 | * history, including the current signer. Automatically returns false if this object has |
| 5999 | * multiple signing certificates, since rotation is only supported for single-signers. |
| 6000 | */ |
| 6001 | public boolean hasSha256Certificate(byte[] sha256Certificate) { |
| 6002 | return hasSha256CertificateInternal(sha256Certificate, PAST_CERT_EXISTS); |
| 6003 | } |
| 6004 | |
| 6005 | /** |
| 6006 | * Determine if the {@code sha256Certificate} certificate hash corresponds to a signing |
| 6007 | * certificate in this SigningDetails' signing certificate history, including the current |
| 6008 | * signer, and whether or not it has the given permission. Certificates which match our |
| 6009 | * current signer automatically get all capabilities. Automatically returns false if this |
| 6010 | * object has multiple signing certificates, since rotation is only supported for |
| 6011 | * single-signers. |
| 6012 | */ |
| 6013 | public boolean hasSha256Certificate(byte[] sha256Certificate, @CertCapabilities int flags) { |
| 6014 | return hasSha256CertificateInternal(sha256Certificate, flags); |
| 6015 | } |
| 6016 | |
| 6017 | private boolean hasSha256CertificateInternal(byte[] sha256Certificate, int flags) { |
| 6018 | if (this == UNKNOWN) { |
| 6019 | return false; |
| 6020 | } |
| 6021 | if (hasPastSigningCertificates()) { |
| 6022 | |
| 6023 | // check all past certs, except for the last one, which automatically gets all |
| 6024 | // capabilities, since it is the same as the current signature, and is checked below |
| 6025 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6026 | byte[] digest = PackageUtils.computeSha256DigestBytes( |
| 6027 | pastSigningCertificates[i].toByteArray()); |
| 6028 | if (Arrays.equals(sha256Certificate, digest)) { |
| 6029 | if (flags == PAST_CERT_EXISTS |
| 6030 | || (flags & pastSigningCertificatesFlags[i]) == flags) { |
| 6031 | return true; |
| 6032 | } |
| 6033 | } |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | // not in previous certs signing history, just check the current signer |
| 6038 | if (signatures.length == 1) { |
| 6039 | byte[] digest = |
| 6040 | PackageUtils.computeSha256DigestBytes(signatures[0].toByteArray()); |
| 6041 | return Arrays.equals(sha256Certificate, digest); |
| 6042 | } |
| 6043 | return false; |
| 6044 | } |
| 6045 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6046 | /** Returns true if the signatures in this and other match exactly. */ |
| 6047 | public boolean signaturesMatchExactly(SigningDetails other) { |
| 6048 | return Signature.areExactMatch(this.signatures, other.signatures); |
| 6049 | } |
| 6050 | |
| 6051 | @Override |
| 6052 | public int describeContents() { |
| 6053 | return 0; |
| 6054 | } |
| 6055 | |
| 6056 | @Override |
| 6057 | public void writeToParcel(Parcel dest, int flags) { |
| 6058 | boolean isUnknown = UNKNOWN == this; |
| 6059 | dest.writeBoolean(isUnknown); |
| 6060 | if (isUnknown) { |
| 6061 | return; |
| 6062 | } |
| 6063 | dest.writeTypedArray(this.signatures, flags); |
| 6064 | dest.writeInt(this.signatureSchemeVersion); |
| 6065 | dest.writeArraySet(this.publicKeys); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6066 | dest.writeTypedArray(this.pastSigningCertificates, flags); |
| 6067 | dest.writeIntArray(this.pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | protected SigningDetails(Parcel in) { |
| 6071 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6072 | this.signatures = in.createTypedArray(Signature.CREATOR); |
| 6073 | this.signatureSchemeVersion = in.readInt(); |
| 6074 | this.publicKeys = (ArraySet<PublicKey>) in.readArraySet(boot); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6075 | this.pastSigningCertificates = in.createTypedArray(Signature.CREATOR); |
| 6076 | this.pastSigningCertificatesFlags = in.createIntArray(); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | public static final Creator<SigningDetails> CREATOR = new Creator<SigningDetails>() { |
| 6080 | @Override |
| 6081 | public SigningDetails createFromParcel(Parcel source) { |
| 6082 | if (source.readBoolean()) { |
| 6083 | return UNKNOWN; |
| 6084 | } |
| 6085 | return new SigningDetails(source); |
| 6086 | } |
| 6087 | |
| 6088 | @Override |
| 6089 | public SigningDetails[] newArray(int size) { |
| 6090 | return new SigningDetails[size]; |
| 6091 | } |
| 6092 | }; |
| 6093 | |
| 6094 | @Override |
| 6095 | public boolean equals(Object o) { |
| 6096 | if (this == o) return true; |
| 6097 | if (!(o instanceof SigningDetails)) return false; |
| 6098 | |
| 6099 | SigningDetails that = (SigningDetails) o; |
| 6100 | |
| 6101 | if (signatureSchemeVersion != that.signatureSchemeVersion) return false; |
| 6102 | if (!Signature.areExactMatch(signatures, that.signatures)) return false; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6103 | if (publicKeys != null) { |
| 6104 | if (!publicKeys.equals((that.publicKeys))) { |
| 6105 | return false; |
| 6106 | } |
| 6107 | } else if (that.publicKeys != null) { |
| 6108 | return false; |
| 6109 | } |
| 6110 | |
| 6111 | // can't use Signature.areExactMatch() because order matters with the past signing certs |
| 6112 | if (!Arrays.equals(pastSigningCertificates, that.pastSigningCertificates)) { |
| 6113 | return false; |
| 6114 | } |
| 6115 | if (!Arrays.equals(pastSigningCertificatesFlags, that.pastSigningCertificatesFlags)) { |
| 6116 | return false; |
| 6117 | } |
| 6118 | |
| 6119 | return true; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | @Override |
| 6123 | public int hashCode() { |
| 6124 | int result = +Arrays.hashCode(signatures); |
| 6125 | result = 31 * result + signatureSchemeVersion; |
| 6126 | result = 31 * result + (publicKeys != null ? publicKeys.hashCode() : 0); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6127 | result = 31 * result + Arrays.hashCode(pastSigningCertificates); |
| 6128 | result = 31 * result + Arrays.hashCode(pastSigningCertificatesFlags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6129 | return result; |
| 6130 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6131 | |
| 6132 | /** |
| 6133 | * Builder of {@code SigningDetails} instances. |
| 6134 | */ |
| 6135 | public static class Builder { |
| 6136 | private Signature[] mSignatures; |
| 6137 | private int mSignatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 6138 | private Signature[] mPastSigningCertificates; |
| 6139 | private int[] mPastSigningCertificatesFlags; |
| 6140 | |
| 6141 | public Builder() { |
| 6142 | } |
| 6143 | |
| 6144 | /** get signing certificates used to sign the current APK */ |
| 6145 | public Builder setSignatures(Signature[] signatures) { |
| 6146 | mSignatures = signatures; |
| 6147 | return this; |
| 6148 | } |
| 6149 | |
| 6150 | /** set the signature scheme version used to sign the APK */ |
| 6151 | public Builder setSignatureSchemeVersion(int signatureSchemeVersion) { |
| 6152 | mSignatureSchemeVersion = signatureSchemeVersion; |
| 6153 | return this; |
| 6154 | } |
| 6155 | |
| 6156 | /** set the signing certificates by which the APK proved it can be authenticated */ |
| 6157 | public Builder setPastSigningCertificates(Signature[] pastSigningCertificates) { |
| 6158 | mPastSigningCertificates = pastSigningCertificates; |
| 6159 | return this; |
| 6160 | } |
| 6161 | |
| 6162 | /** set the flags for the {@code pastSigningCertificates} */ |
| 6163 | public Builder setPastSigningCertificatesFlags(int[] pastSigningCertificatesFlags) { |
| 6164 | mPastSigningCertificatesFlags = pastSigningCertificatesFlags; |
| 6165 | return this; |
| 6166 | } |
| 6167 | |
| 6168 | private void checkInvariants() { |
| 6169 | // must have signatures and scheme version set |
| 6170 | if (mSignatures == null) { |
| 6171 | throw new IllegalStateException("SigningDetails requires the current signing" |
| 6172 | + " certificates."); |
| 6173 | } |
| 6174 | |
| 6175 | // pastSigningCerts and flags must match up |
| 6176 | boolean pastMismatch = false; |
| 6177 | if (mPastSigningCertificates != null && mPastSigningCertificatesFlags != null) { |
| 6178 | if (mPastSigningCertificates.length != mPastSigningCertificatesFlags.length) { |
| 6179 | pastMismatch = true; |
| 6180 | } |
| 6181 | } else if (!(mPastSigningCertificates == null |
| 6182 | && mPastSigningCertificatesFlags == null)) { |
| 6183 | pastMismatch = true; |
| 6184 | } |
| 6185 | if (pastMismatch) { |
| 6186 | throw new IllegalStateException("SigningDetails must have a one to one mapping " |
| 6187 | + "between pastSigningCertificates and pastSigningCertificatesFlags"); |
| 6188 | } |
| 6189 | } |
| 6190 | /** build a {@code SigningDetails} object */ |
| 6191 | public SigningDetails build() |
| 6192 | throws CertificateException { |
| 6193 | checkInvariants(); |
| 6194 | return new SigningDetails(mSignatures, mSignatureSchemeVersion, |
| 6195 | mPastSigningCertificates, mPastSigningCertificatesFlags); |
| 6196 | } |
| 6197 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6198 | } |
| 6199 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6200 | /** |
| 6201 | * Representation of a full package parsed from APK files on disk. A package |
| 6202 | * consists of a single base APK, and zero or more split APKs. |
| 6203 | */ |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6204 | public final static class Package implements Parcelable { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6205 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6206 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6207 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6208 | // The package name declared in the manifest as the package can be |
| 6209 | // renamed, for example static shared libs use synthetic package names. |
| 6210 | public String manifestPackageName; |
| 6211 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6212 | /** Names of any split APKs, ordered by parsed splitName */ |
| 6213 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6214 | |
| 6215 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6216 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 6217 | public String volumeUuid; |
| 6218 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6219 | /** |
| 6220 | * Path where this package was found on disk. For monolithic packages |
| 6221 | * this is path to single base APK file; for cluster packages this is |
| 6222 | * path to the cluster directory. |
| 6223 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6224 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6225 | |
| 6226 | /** Path of base APK */ |
| 6227 | public String baseCodePath; |
| 6228 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6229 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6230 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6231 | /** Revision code of base APK */ |
| 6232 | public int baseRevisionCode; |
| 6233 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 6234 | public int[] splitRevisionCodes; |
| 6235 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6236 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 6237 | public int[] splitFlags; |
| 6238 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 6239 | /** |
| 6240 | * Private flags of any split APKs; ordered by parsed splitName. |
| 6241 | * |
| 6242 | * {@hide} |
| 6243 | */ |
| 6244 | public int[] splitPrivateFlags; |
| 6245 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6246 | public boolean baseHardwareAccelerated; |
| 6247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | // For now we only support one application per package. |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6249 | public ApplicationInfo applicationInfo = new ApplicationInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | |
| 6251 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 6252 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 6253 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 6254 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 6255 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 6256 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 6257 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 6258 | |
| 6259 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 6260 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 6261 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6262 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6263 | public Package parentPackage; |
| 6264 | public ArrayList<Package> childPackages; |
| 6265 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6266 | public String staticSharedLibName = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6267 | public long staticSharedLibVersion = 0; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6268 | public ArrayList<String> libraryNames = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6269 | public ArrayList<String> usesLibraries = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6270 | public ArrayList<String> usesStaticLibraries = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6271 | public long[] usesStaticLibrariesVersions = null; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6272 | public String[][] usesStaticLibrariesCertDigests = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6273 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | public String[] usesLibraryFiles = null; |
| 6275 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 6276 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 6277 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 6278 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6279 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 6280 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | // We store the application meta-data independently to avoid multiple unwanted references |
| 6283 | public Bundle mAppMetaData = null; |
| 6284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | // The version code declared for this package. |
| 6286 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6287 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6288 | // The major version code declared for this package. |
| 6289 | public int mVersionCodeMajor; |
| 6290 | |
| 6291 | // Return long containing mVersionCode and mVersionCodeMajor. |
| 6292 | public long getLongVersionCode() { |
| 6293 | return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); |
| 6294 | } |
| 6295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6296 | // The version name declared for this package. |
| 6297 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6299 | // The shared user id that this package wants to use. |
| 6300 | public String mSharedUserId; |
| 6301 | |
| 6302 | // The shared user label that this package wants to use. |
| 6303 | public int mSharedUserLabel; |
| 6304 | |
| 6305 | // Signatures that were read from the package. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6306 | @NonNull public SigningDetails mSigningDetails = SigningDetails.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | |
| 6308 | // For use by package manager service for quick lookup of |
| 6309 | // preferred up order. |
| 6310 | public int mPreferredOrder = 0; |
| 6311 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6312 | // 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] | 6313 | public long[] mLastPackageUsageTimeInMills = |
| 6314 | new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6315 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 6316 | // // User set enabled state. |
| 6317 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 6318 | // |
| 6319 | // // Whether the package has been stopped. |
| 6320 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 6321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | // Additional data supplied by callers. |
| 6323 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 6324 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6325 | // Applications hardware preferences |
| 6326 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6328 | // Applications requested features |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6329 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 6330 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 6331 | // Applications requested feature groups |
| 6332 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 6333 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 6334 | public int installLocation; |
| 6335 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 6336 | public boolean coreApp; |
| 6337 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 6338 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 6339 | public boolean mRequiredForAllUsers; |
| 6340 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6341 | /* The restricted account authenticator type that is used by this application */ |
| 6342 | public String mRestrictedAccountType; |
| 6343 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 6344 | /* The required account type without which this application will not function */ |
| 6345 | public String mRequiredAccountType; |
| 6346 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6347 | public String mOverlayTarget; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 6348 | public String mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6349 | public int mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6350 | public boolean mOverlayIsStatic; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6351 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6352 | public int mCompileSdkVersion; |
| 6353 | public String mCompileSdkVersionCodename; |
| 6354 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6355 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6356 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6357 | */ |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6358 | public ArraySet<String> mUpgradeKeySets; |
| 6359 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6360 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6361 | /** |
| 6362 | * The install time abi override for this package, if any. |
| 6363 | * |
| 6364 | * TODO: This seems like a horrible place to put the abiOverride because |
| 6365 | * this isn't something the packageParser parsers. However, this fits in with |
| 6366 | * the rest of the PackageManager where package scanning randomly pushes |
| 6367 | * and prods fields out of {@code this.applicationInfo}. |
| 6368 | */ |
| 6369 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6370 | /** |
| 6371 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 6372 | * are present. This is only meaningfull for multiarch applications. |
| 6373 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 6374 | */ |
| 6375 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6376 | |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 6377 | public byte[] restrictUpdateHash; |
| 6378 | |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6379 | /** 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] | 6380 | public boolean visibleToInstantApps; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6381 | /** Whether or not the package is a stub and must be replaced by the full version. */ |
| 6382 | public boolean isStub; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 6383 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6384 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6385 | this.packageName = packageName; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6386 | this.manifestPackageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6387 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6388 | applicationInfo.uid = -1; |
| 6389 | } |
| 6390 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6391 | public void setApplicationVolumeUuid(String volumeUuid) { |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6392 | final UUID storageUuid = StorageManager.convert(volumeUuid); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6393 | this.applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6394 | this.applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6395 | if (childPackages != null) { |
| 6396 | final int packageCount = childPackages.size(); |
| 6397 | for (int i = 0; i < packageCount; i++) { |
| 6398 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6399 | childPackages.get(i).applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6400 | } |
| 6401 | } |
| 6402 | } |
| 6403 | |
| 6404 | public void setApplicationInfoCodePath(String codePath) { |
| 6405 | this.applicationInfo.setCodePath(codePath); |
| 6406 | if (childPackages != null) { |
| 6407 | final int packageCount = childPackages.size(); |
| 6408 | for (int i = 0; i < packageCount; i++) { |
| 6409 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 6410 | } |
| 6411 | } |
| 6412 | } |
| 6413 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6414 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6415 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6416 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 6417 | this.applicationInfo.setResourcePath(resourcePath); |
| 6418 | if (childPackages != null) { |
| 6419 | final int packageCount = childPackages.size(); |
| 6420 | for (int i = 0; i < packageCount; i++) { |
| 6421 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 6422 | } |
| 6423 | } |
| 6424 | } |
| 6425 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6426 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6427 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6428 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 6429 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 6430 | if (childPackages != null) { |
| 6431 | final int packageCount = childPackages.size(); |
| 6432 | for (int i = 0; i < packageCount; i++) { |
| 6433 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 6434 | } |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 6439 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 6440 | if (childPackages != null) { |
| 6441 | final int packageCount = childPackages.size(); |
| 6442 | for (int i = 0; i < packageCount; i++) { |
| 6443 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 6444 | } |
| 6445 | } |
| 6446 | } |
| 6447 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 6448 | public List<String> getChildPackageNames() { |
| 6449 | if (childPackages == null) { |
| 6450 | return null; |
| 6451 | } |
| 6452 | final int childCount = childPackages.size(); |
| 6453 | final List<String> childPackageNames = new ArrayList<>(childCount); |
| 6454 | for (int i = 0; i < childCount; i++) { |
| 6455 | String childPackageName = childPackages.get(i).packageName; |
| 6456 | childPackageNames.add(childPackageName); |
| 6457 | } |
| 6458 | return childPackageNames; |
| 6459 | } |
| 6460 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6461 | public boolean hasChildPackage(String packageName) { |
| 6462 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 6463 | for (int i = 0; i < childCount; i++) { |
| 6464 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 6465 | return true; |
| 6466 | } |
| 6467 | } |
| 6468 | return false; |
| 6469 | } |
| 6470 | |
| 6471 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 6472 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 6473 | // Children have no splits |
| 6474 | } |
| 6475 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6476 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6477 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6478 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 6479 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 6480 | // Children have no splits |
| 6481 | } |
| 6482 | |
| 6483 | public void setSplitCodePaths(String[] codePaths) { |
| 6484 | this.splitCodePaths = codePaths; |
| 6485 | } |
| 6486 | |
| 6487 | public void setCodePath(String codePath) { |
| 6488 | this.codePath = codePath; |
| 6489 | if (childPackages != null) { |
| 6490 | final int packageCount = childPackages.size(); |
| 6491 | for (int i = 0; i < packageCount; i++) { |
| 6492 | childPackages.get(i).codePath = codePath; |
| 6493 | } |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | public void setBaseCodePath(String baseCodePath) { |
| 6498 | this.baseCodePath = baseCodePath; |
| 6499 | if (childPackages != null) { |
| 6500 | final int packageCount = childPackages.size(); |
| 6501 | for (int i = 0; i < packageCount; i++) { |
| 6502 | childPackages.get(i).baseCodePath = baseCodePath; |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6507 | /** Sets signing details on the package and any of its children. */ |
| 6508 | public void setSigningDetails(@NonNull SigningDetails signingDetails) { |
| 6509 | mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6510 | if (childPackages != null) { |
| 6511 | final int packageCount = childPackages.size(); |
| 6512 | for (int i = 0; i < packageCount; i++) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6513 | childPackages.get(i).mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6514 | } |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | public void setVolumeUuid(String volumeUuid) { |
| 6519 | this.volumeUuid = volumeUuid; |
| 6520 | if (childPackages != null) { |
| 6521 | final int packageCount = childPackages.size(); |
| 6522 | for (int i = 0; i < packageCount; i++) { |
| 6523 | childPackages.get(i).volumeUuid = volumeUuid; |
| 6524 | } |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | public void setApplicationInfoFlags(int mask, int flags) { |
| 6529 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 6530 | if (childPackages != null) { |
| 6531 | final int packageCount = childPackages.size(); |
| 6532 | for (int i = 0; i < packageCount; i++) { |
| 6533 | childPackages.get(i).applicationInfo.flags = |
| 6534 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 6535 | } |
| 6536 | } |
| 6537 | } |
| 6538 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 6539 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6540 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6541 | if (childPackages != null) { |
| 6542 | final int packageCount = childPackages.size(); |
| 6543 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6544 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6545 | } |
| 6546 | } |
| 6547 | } |
| 6548 | |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 6549 | public boolean isLibrary() { |
| 6550 | return staticSharedLibName != null || !ArrayUtils.isEmpty(libraryNames); |
| 6551 | } |
| 6552 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6553 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6554 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6555 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6556 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6557 | Collections.addAll(paths, splitCodePaths); |
| 6558 | } |
| 6559 | return paths; |
| 6560 | } |
| 6561 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6562 | /** |
| 6563 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 6564 | * resource-only APKs. |
| 6565 | */ |
| 6566 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 6567 | ArrayList<String> paths = new ArrayList<>(); |
| 6568 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6569 | paths.add(baseCodePath); |
| 6570 | } |
| 6571 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6572 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 6573 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6574 | paths.add(splitCodePaths[i]); |
| 6575 | } |
| 6576 | } |
| 6577 | } |
| 6578 | return paths; |
| 6579 | } |
| 6580 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6581 | public void setPackageName(String newName) { |
| 6582 | packageName = newName; |
| 6583 | applicationInfo.packageName = newName; |
| 6584 | for (int i=permissions.size()-1; i>=0; i--) { |
| 6585 | permissions.get(i).setPackageName(newName); |
| 6586 | } |
| 6587 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 6588 | permissionGroups.get(i).setPackageName(newName); |
| 6589 | } |
| 6590 | for (int i=activities.size()-1; i>=0; i--) { |
| 6591 | activities.get(i).setPackageName(newName); |
| 6592 | } |
| 6593 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6594 | receivers.get(i).setPackageName(newName); |
| 6595 | } |
| 6596 | for (int i=providers.size()-1; i>=0; i--) { |
| 6597 | providers.get(i).setPackageName(newName); |
| 6598 | } |
| 6599 | for (int i=services.size()-1; i>=0; i--) { |
| 6600 | services.get(i).setPackageName(newName); |
| 6601 | } |
| 6602 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6603 | instrumentation.get(i).setPackageName(newName); |
| 6604 | } |
| 6605 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 6606 | |
| 6607 | public boolean hasComponentClassName(String name) { |
| 6608 | for (int i=activities.size()-1; i>=0; i--) { |
| 6609 | if (name.equals(activities.get(i).className)) { |
| 6610 | return true; |
| 6611 | } |
| 6612 | } |
| 6613 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6614 | if (name.equals(receivers.get(i).className)) { |
| 6615 | return true; |
| 6616 | } |
| 6617 | } |
| 6618 | for (int i=providers.size()-1; i>=0; i--) { |
| 6619 | if (name.equals(providers.get(i).className)) { |
| 6620 | return true; |
| 6621 | } |
| 6622 | } |
| 6623 | for (int i=services.size()-1; i>=0; i--) { |
| 6624 | if (name.equals(services.get(i).className)) { |
| 6625 | return true; |
| 6626 | } |
| 6627 | } |
| 6628 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6629 | if (name.equals(instrumentation.get(i).className)) { |
| 6630 | return true; |
| 6631 | } |
| 6632 | } |
| 6633 | return false; |
| 6634 | } |
| 6635 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6636 | /** @hide */ |
| 6637 | public boolean isExternal() { |
| 6638 | return applicationInfo.isExternal(); |
| 6639 | } |
| 6640 | |
| 6641 | /** @hide */ |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6642 | public boolean isForwardLocked() { |
| 6643 | return applicationInfo.isForwardLocked(); |
| 6644 | } |
| 6645 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6646 | /** @hide */ |
| 6647 | public boolean isOem() { |
| 6648 | return applicationInfo.isOem(); |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6649 | } |
| 6650 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6651 | /** @hide */ |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 6652 | public boolean isVendor() { |
| 6653 | return applicationInfo.isVendor(); |
| 6654 | } |
| 6655 | |
| 6656 | /** @hide */ |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 6657 | public boolean isProduct() { |
| 6658 | return applicationInfo.isProduct(); |
| 6659 | } |
| 6660 | |
| 6661 | /** @hide */ |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6662 | public boolean isPrivileged() { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 6663 | return applicationInfo.isPrivilegedApp(); |
| 6664 | } |
| 6665 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6666 | /** @hide */ |
| 6667 | public boolean isSystem() { |
| 6668 | return applicationInfo.isSystemApp(); |
| 6669 | } |
| 6670 | |
| 6671 | /** @hide */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6672 | public boolean isUpdatedSystemApp() { |
| 6673 | return applicationInfo.isUpdatedSystemApp(); |
| 6674 | } |
| 6675 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6676 | /** @hide */ |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6677 | public boolean canHaveOatDir() { |
| 6678 | // The following app types CANNOT have oat directory |
| 6679 | // - non-updated system apps |
| 6680 | // - forward-locked apps or apps installed in ASEC containers |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6681 | return (!isSystem() || isUpdatedSystemApp()) |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6682 | && !isForwardLocked() && !applicationInfo.isExternalAsec(); |
| 6683 | } |
| 6684 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6685 | public boolean isMatch(int flags) { |
| 6686 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6687 | return isSystem(); |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6688 | } |
| 6689 | return true; |
| 6690 | } |
| 6691 | |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 6692 | public long getLatestPackageUseTimeInMills() { |
| 6693 | long latestUse = 0L; |
| 6694 | for (long use : mLastPackageUsageTimeInMills) { |
| 6695 | latestUse = Math.max(latestUse, use); |
| 6696 | } |
| 6697 | return latestUse; |
| 6698 | } |
| 6699 | |
David Brazdil | 90e2699 | 2016-04-18 14:08:52 +0100 | [diff] [blame] | 6700 | public long getLatestForegroundPackageUseTimeInMills() { |
| 6701 | int[] foregroundReasons = { |
| 6702 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, |
| 6703 | PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE |
| 6704 | }; |
| 6705 | |
| 6706 | long latestUse = 0L; |
| 6707 | for (int reason : foregroundReasons) { |
| 6708 | latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); |
| 6709 | } |
| 6710 | return latestUse; |
| 6711 | } |
| 6712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6713 | public String toString() { |
| 6714 | return "Package{" |
| 6715 | + Integer.toHexString(System.identityHashCode(this)) |
| 6716 | + " " + packageName + "}"; |
| 6717 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6718 | |
| 6719 | @Override |
| 6720 | public int describeContents() { |
| 6721 | return 0; |
| 6722 | } |
| 6723 | |
| 6724 | public Package(Parcel dest) { |
| 6725 | // We use the boot classloader for all classes that we load. |
| 6726 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6727 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6728 | packageName = dest.readString().intern(); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6729 | manifestPackageName = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6730 | splitNames = dest.readStringArray(); |
| 6731 | volumeUuid = dest.readString(); |
| 6732 | codePath = dest.readString(); |
| 6733 | baseCodePath = dest.readString(); |
| 6734 | splitCodePaths = dest.readStringArray(); |
| 6735 | baseRevisionCode = dest.readInt(); |
| 6736 | splitRevisionCodes = dest.createIntArray(); |
| 6737 | splitFlags = dest.createIntArray(); |
| 6738 | splitPrivateFlags = dest.createIntArray(); |
| 6739 | baseHardwareAccelerated = (dest.readInt() == 1); |
| 6740 | applicationInfo = dest.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6741 | if (applicationInfo.permission != null) { |
| 6742 | applicationInfo.permission = applicationInfo.permission.intern(); |
| 6743 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6744 | |
| 6745 | // We don't serialize the "owner" package and the application info object for each of |
| 6746 | // these components, in order to save space and to avoid circular dependencies while |
| 6747 | // serialization. We need to fix them all up here. |
| 6748 | dest.readParcelableList(permissions, boot); |
| 6749 | fixupOwner(permissions); |
| 6750 | dest.readParcelableList(permissionGroups, boot); |
| 6751 | fixupOwner(permissionGroups); |
| 6752 | dest.readParcelableList(activities, boot); |
| 6753 | fixupOwner(activities); |
| 6754 | dest.readParcelableList(receivers, boot); |
| 6755 | fixupOwner(receivers); |
| 6756 | dest.readParcelableList(providers, boot); |
| 6757 | fixupOwner(providers); |
| 6758 | dest.readParcelableList(services, boot); |
| 6759 | fixupOwner(services); |
| 6760 | dest.readParcelableList(instrumentation, boot); |
| 6761 | fixupOwner(instrumentation); |
| 6762 | |
| 6763 | dest.readStringList(requestedPermissions); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6764 | internStringArrayList(requestedPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6765 | protectedBroadcasts = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6766 | internStringArrayList(protectedBroadcasts); |
| 6767 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6768 | parentPackage = dest.readParcelable(boot); |
| 6769 | |
| 6770 | childPackages = new ArrayList<>(); |
| 6771 | dest.readParcelableList(childPackages, boot); |
| 6772 | if (childPackages.size() == 0) { |
| 6773 | childPackages = null; |
| 6774 | } |
| 6775 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6776 | staticSharedLibName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6777 | if (staticSharedLibName != null) { |
| 6778 | staticSharedLibName = staticSharedLibName.intern(); |
| 6779 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6780 | staticSharedLibVersion = dest.readLong(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6781 | libraryNames = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6782 | internStringArrayList(libraryNames); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6783 | usesLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6784 | internStringArrayList(usesLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6785 | usesOptionalLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6786 | internStringArrayList(usesOptionalLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6787 | usesLibraryFiles = dest.readStringArray(); |
| 6788 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6789 | final int libCount = dest.readInt(); |
| 6790 | if (libCount > 0) { |
| 6791 | usesStaticLibraries = new ArrayList<>(libCount); |
| 6792 | dest.readStringList(usesStaticLibraries); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6793 | internStringArrayList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6794 | usesStaticLibrariesVersions = new long[libCount]; |
| 6795 | dest.readLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6796 | usesStaticLibrariesCertDigests = new String[libCount][]; |
| 6797 | for (int i = 0; i < libCount; i++) { |
| 6798 | usesStaticLibrariesCertDigests[i] = dest.createStringArray(); |
| 6799 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6800 | } |
| 6801 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6802 | preferredActivityFilters = new ArrayList<>(); |
| 6803 | dest.readParcelableList(preferredActivityFilters, boot); |
| 6804 | if (preferredActivityFilters.size() == 0) { |
| 6805 | preferredActivityFilters = null; |
| 6806 | } |
| 6807 | |
| 6808 | mOriginalPackages = dest.createStringArrayList(); |
| 6809 | mRealPackage = dest.readString(); |
| 6810 | mAdoptPermissions = dest.createStringArrayList(); |
| 6811 | mAppMetaData = dest.readBundle(); |
| 6812 | mVersionCode = dest.readInt(); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 6813 | mVersionCodeMajor = dest.readInt(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6814 | mVersionName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6815 | if (mVersionName != null) { |
| 6816 | mVersionName = mVersionName.intern(); |
| 6817 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6818 | mSharedUserId = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6819 | if (mSharedUserId != null) { |
| 6820 | mSharedUserId = mSharedUserId.intern(); |
| 6821 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6822 | mSharedUserLabel = dest.readInt(); |
| 6823 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6824 | mSigningDetails = dest.readParcelable(boot); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6825 | |
| 6826 | mPreferredOrder = dest.readInt(); |
| 6827 | |
| 6828 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 6829 | // is parsed from the APK. |
| 6830 | |
| 6831 | // Object mExtras is not persisted because it is not information that is read from |
| 6832 | // the APK, rather, it is supplied by callers. |
| 6833 | |
| 6834 | |
| 6835 | configPreferences = new ArrayList<>(); |
| 6836 | dest.readParcelableList(configPreferences, boot); |
| 6837 | if (configPreferences.size() == 0) { |
| 6838 | configPreferences = null; |
| 6839 | } |
| 6840 | |
| 6841 | reqFeatures = new ArrayList<>(); |
| 6842 | dest.readParcelableList(reqFeatures, boot); |
| 6843 | if (reqFeatures.size() == 0) { |
| 6844 | reqFeatures = null; |
| 6845 | } |
| 6846 | |
| 6847 | featureGroups = new ArrayList<>(); |
| 6848 | dest.readParcelableList(featureGroups, boot); |
| 6849 | if (featureGroups.size() == 0) { |
| 6850 | featureGroups = null; |
| 6851 | } |
| 6852 | |
| 6853 | installLocation = dest.readInt(); |
| 6854 | coreApp = (dest.readInt() == 1); |
| 6855 | mRequiredForAllUsers = (dest.readInt() == 1); |
| 6856 | mRestrictedAccountType = dest.readString(); |
| 6857 | mRequiredAccountType = dest.readString(); |
| 6858 | mOverlayTarget = dest.readString(); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 6859 | mOverlayCategory = dest.readString(); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6860 | mOverlayPriority = dest.readInt(); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6861 | mOverlayIsStatic = (dest.readInt() == 1); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6862 | mCompileSdkVersion = dest.readInt(); |
| 6863 | mCompileSdkVersionCodename = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6864 | mUpgradeKeySets = (ArraySet<String>) dest.readArraySet(boot); |
| 6865 | |
| 6866 | mKeySetMapping = readKeySetMapping(dest); |
| 6867 | |
| 6868 | cpuAbiOverride = dest.readString(); |
| 6869 | use32bitAbi = (dest.readInt() == 1); |
| 6870 | restrictUpdateHash = dest.createByteArray(); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 6871 | visibleToInstantApps = dest.readInt() == 1; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6872 | } |
| 6873 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6874 | private static void internStringArrayList(List<String> list) { |
| 6875 | if (list != null) { |
| 6876 | final int N = list.size(); |
| 6877 | for (int i = 0; i < N; ++i) { |
| 6878 | list.set(i, list.get(i).intern()); |
| 6879 | } |
| 6880 | } |
| 6881 | } |
| 6882 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6883 | /** |
| 6884 | * Sets the package owner and the the {@code applicationInfo} for every component |
| 6885 | * owner by this package. |
| 6886 | */ |
| 6887 | private void fixupOwner(List<? extends Component<?>> list) { |
| 6888 | if (list != null) { |
| 6889 | for (Component<?> c : list) { |
| 6890 | c.owner = this; |
| 6891 | if (c instanceof Activity) { |
| 6892 | ((Activity) c).info.applicationInfo = this.applicationInfo; |
| 6893 | } else if (c instanceof Service) { |
| 6894 | ((Service) c).info.applicationInfo = this.applicationInfo; |
| 6895 | } else if (c instanceof Provider) { |
| 6896 | ((Provider) c).info.applicationInfo = this.applicationInfo; |
| 6897 | } |
| 6898 | } |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | @Override |
| 6903 | public void writeToParcel(Parcel dest, int flags) { |
| 6904 | dest.writeString(packageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6905 | dest.writeString(manifestPackageName); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6906 | dest.writeStringArray(splitNames); |
| 6907 | dest.writeString(volumeUuid); |
| 6908 | dest.writeString(codePath); |
| 6909 | dest.writeString(baseCodePath); |
| 6910 | dest.writeStringArray(splitCodePaths); |
| 6911 | dest.writeInt(baseRevisionCode); |
| 6912 | dest.writeIntArray(splitRevisionCodes); |
| 6913 | dest.writeIntArray(splitFlags); |
| 6914 | dest.writeIntArray(splitPrivateFlags); |
| 6915 | dest.writeInt(baseHardwareAccelerated ? 1 : 0); |
| 6916 | dest.writeParcelable(applicationInfo, flags); |
| 6917 | |
| 6918 | dest.writeParcelableList(permissions, flags); |
| 6919 | dest.writeParcelableList(permissionGroups, flags); |
| 6920 | dest.writeParcelableList(activities, flags); |
| 6921 | dest.writeParcelableList(receivers, flags); |
| 6922 | dest.writeParcelableList(providers, flags); |
| 6923 | dest.writeParcelableList(services, flags); |
| 6924 | dest.writeParcelableList(instrumentation, flags); |
| 6925 | |
| 6926 | dest.writeStringList(requestedPermissions); |
| 6927 | dest.writeStringList(protectedBroadcasts); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 6928 | |
| 6929 | // TODO: This doesn't work: b/64295061 |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6930 | dest.writeParcelable(parentPackage, flags); |
| 6931 | dest.writeParcelableList(childPackages, flags); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 6932 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6933 | dest.writeString(staticSharedLibName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6934 | dest.writeLong(staticSharedLibVersion); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6935 | dest.writeStringList(libraryNames); |
| 6936 | dest.writeStringList(usesLibraries); |
| 6937 | dest.writeStringList(usesOptionalLibraries); |
| 6938 | dest.writeStringArray(usesLibraryFiles); |
| 6939 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6940 | if (ArrayUtils.isEmpty(usesStaticLibraries)) { |
| 6941 | dest.writeInt(-1); |
| 6942 | } else { |
| 6943 | dest.writeInt(usesStaticLibraries.size()); |
| 6944 | dest.writeStringList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6945 | dest.writeLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6946 | for (String[] usesStaticLibrariesCertDigest : usesStaticLibrariesCertDigests) { |
| 6947 | dest.writeStringArray(usesStaticLibrariesCertDigest); |
| 6948 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6949 | } |
| 6950 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6951 | dest.writeParcelableList(preferredActivityFilters, flags); |
| 6952 | |
| 6953 | dest.writeStringList(mOriginalPackages); |
| 6954 | dest.writeString(mRealPackage); |
| 6955 | dest.writeStringList(mAdoptPermissions); |
| 6956 | dest.writeBundle(mAppMetaData); |
| 6957 | dest.writeInt(mVersionCode); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 6958 | dest.writeInt(mVersionCodeMajor); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6959 | dest.writeString(mVersionName); |
| 6960 | dest.writeString(mSharedUserId); |
| 6961 | dest.writeInt(mSharedUserLabel); |
| 6962 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6963 | dest.writeParcelable(mSigningDetails, flags); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6964 | |
| 6965 | dest.writeInt(mPreferredOrder); |
| 6966 | |
| 6967 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 6968 | // is parsed from the APK. |
| 6969 | |
| 6970 | // Object mExtras is not persisted because it is not information that is read from |
| 6971 | // the APK, rather, it is supplied by callers. |
| 6972 | |
| 6973 | dest.writeParcelableList(configPreferences, flags); |
| 6974 | dest.writeParcelableList(reqFeatures, flags); |
| 6975 | dest.writeParcelableList(featureGroups, flags); |
| 6976 | |
| 6977 | dest.writeInt(installLocation); |
| 6978 | dest.writeInt(coreApp ? 1 : 0); |
| 6979 | dest.writeInt(mRequiredForAllUsers ? 1 : 0); |
| 6980 | dest.writeString(mRestrictedAccountType); |
| 6981 | dest.writeString(mRequiredAccountType); |
| 6982 | dest.writeString(mOverlayTarget); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 6983 | dest.writeString(mOverlayCategory); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6984 | dest.writeInt(mOverlayPriority); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6985 | dest.writeInt(mOverlayIsStatic ? 1 : 0); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6986 | dest.writeInt(mCompileSdkVersion); |
| 6987 | dest.writeString(mCompileSdkVersionCodename); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6988 | dest.writeArraySet(mUpgradeKeySets); |
| 6989 | writeKeySetMapping(dest, mKeySetMapping); |
| 6990 | dest.writeString(cpuAbiOverride); |
| 6991 | dest.writeInt(use32bitAbi ? 1 : 0); |
| 6992 | dest.writeByteArray(restrictUpdateHash); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 6993 | dest.writeInt(visibleToInstantApps ? 1 : 0); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6994 | } |
| 6995 | |
| 6996 | |
| 6997 | /** |
| 6998 | * Writes the keyset mapping to the provided package. {@code null} mappings are permitted. |
| 6999 | */ |
| 7000 | private static void writeKeySetMapping( |
| 7001 | Parcel dest, ArrayMap<String, ArraySet<PublicKey>> keySetMapping) { |
| 7002 | if (keySetMapping == null) { |
| 7003 | dest.writeInt(-1); |
| 7004 | return; |
| 7005 | } |
| 7006 | |
| 7007 | final int N = keySetMapping.size(); |
| 7008 | dest.writeInt(N); |
| 7009 | |
| 7010 | for (int i = 0; i < N; i++) { |
| 7011 | dest.writeString(keySetMapping.keyAt(i)); |
| 7012 | ArraySet<PublicKey> keys = keySetMapping.valueAt(i); |
| 7013 | if (keys == null) { |
| 7014 | dest.writeInt(-1); |
| 7015 | continue; |
| 7016 | } |
| 7017 | |
| 7018 | final int M = keys.size(); |
| 7019 | dest.writeInt(M); |
| 7020 | for (int j = 0; j < M; j++) { |
| 7021 | dest.writeSerializable(keys.valueAt(j)); |
| 7022 | } |
| 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | /** |
| 7027 | * Reads a keyset mapping from the given parcel at the given data position. May return |
| 7028 | * {@code null} if the serialized mapping was {@code null}. |
| 7029 | */ |
| 7030 | private static ArrayMap<String, ArraySet<PublicKey>> readKeySetMapping(Parcel in) { |
| 7031 | final int N = in.readInt(); |
| 7032 | if (N == -1) { |
| 7033 | return null; |
| 7034 | } |
| 7035 | |
| 7036 | ArrayMap<String, ArraySet<PublicKey>> keySetMapping = new ArrayMap<>(); |
| 7037 | for (int i = 0; i < N; ++i) { |
| 7038 | String key = in.readString(); |
| 7039 | final int M = in.readInt(); |
| 7040 | if (M == -1) { |
| 7041 | keySetMapping.put(key, null); |
| 7042 | continue; |
| 7043 | } |
| 7044 | |
| 7045 | ArraySet<PublicKey> keys = new ArraySet<>(M); |
| 7046 | for (int j = 0; j < M; ++j) { |
| 7047 | PublicKey pk = (PublicKey) in.readSerializable(); |
| 7048 | keys.add(pk); |
| 7049 | } |
| 7050 | |
| 7051 | keySetMapping.put(key, keys); |
| 7052 | } |
| 7053 | |
| 7054 | return keySetMapping; |
| 7055 | } |
| 7056 | |
| 7057 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Package>() { |
| 7058 | public Package createFromParcel(Parcel in) { |
| 7059 | return new Package(in); |
| 7060 | } |
| 7061 | |
| 7062 | public Package[] newArray(int size) { |
| 7063 | return new Package[size]; |
| 7064 | } |
| 7065 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7066 | } |
| 7067 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7068 | public static abstract class Component<II extends IntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7069 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7070 | public final String className; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | public Bundle metaData; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7073 | public Package owner; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7074 | /** The order of this component in relation to its peers */ |
| 7075 | public int order; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7076 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7077 | ComponentName componentName; |
| 7078 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7080 | public Component(Package _owner) { |
| 7081 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7082 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7083 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7084 | } |
| 7085 | |
| 7086 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 7087 | owner = args.owner; |
| 7088 | intents = new ArrayList<II>(0); |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 7089 | if (parsePackageItemInfo(args.owner, outInfo, args.outError, args.tag, args.sa, |
| 7090 | true /*nameRequired*/, args.nameRes, args.labelRes, args.iconRes, |
| 7091 | args.roundIconRes, args.logoRes, args.bannerRes)) { |
| 7092 | className = outInfo.name; |
| 7093 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7094 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7095 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 7099 | this(args, (PackageItemInfo)outInfo); |
| 7100 | if (args.outError[0] != null) { |
| 7101 | return; |
| 7102 | } |
| 7103 | |
| 7104 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7105 | CharSequence pname; |
| 7106 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 7107 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 7108 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7109 | } else { |
| 7110 | // Some older apps have been seen to use a resource reference |
| 7111 | // here that on older builds was ignored (with a warning). We |
| 7112 | // need to continue to do this for them so they don't break. |
| 7113 | pname = args.sa.getNonResourceString(args.processRes); |
| 7114 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7115 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7116 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7117 | args.flags, args.sepProcesses, args.outError); |
| 7118 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7119 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 7120 | if (args.descriptionRes != 0) { |
| 7121 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 7122 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7123 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7124 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | public Component(Component<II> clone) { |
| 7128 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7129 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7130 | className = clone.className; |
| 7131 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7132 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7133 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7134 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7135 | public ComponentName getComponentName() { |
| 7136 | if (componentName != null) { |
| 7137 | return componentName; |
| 7138 | } |
| 7139 | if (className != null) { |
| 7140 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 7141 | className); |
| 7142 | } |
| 7143 | return componentName; |
| 7144 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7145 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7146 | protected Component(Parcel in) { |
| 7147 | className = in.readString(); |
| 7148 | metaData = in.readBundle(); |
| 7149 | intents = createIntentsList(in); |
| 7150 | |
| 7151 | owner = null; |
| 7152 | } |
| 7153 | |
| 7154 | protected void writeToParcel(Parcel dest, int flags) { |
| 7155 | dest.writeString(className); |
| 7156 | dest.writeBundle(metaData); |
| 7157 | |
| 7158 | writeIntentsList(intents, dest, flags); |
| 7159 | } |
| 7160 | |
| 7161 | /** |
| 7162 | * <p> |
| 7163 | * Implementation note: The serialized form for the intent list also contains the name |
| 7164 | * of the concrete class that's stored in the list, and assumes that every element of the |
| 7165 | * list is of the same type. This is very similar to the original parcelable mechanism. |
| 7166 | * We cannot use that directly because IntentInfo extends IntentFilter, which is parcelable |
| 7167 | * and is public API. It also declares Parcelable related methods as final which means |
| 7168 | * we can't extend them. The approach of using composition instead of inheritance leads to |
| 7169 | * a large set of cascading changes in the PackageManagerService, which seem undesirable. |
| 7170 | * |
| 7171 | * <p> |
| 7172 | * <b>WARNING: </b> The list of objects returned by this function might need to be fixed up |
| 7173 | * to make sure their owner fields are consistent. See {@code fixupOwner}. |
| 7174 | */ |
| 7175 | private static void writeIntentsList(ArrayList<? extends IntentInfo> list, Parcel out, |
| 7176 | int flags) { |
| 7177 | if (list == null) { |
| 7178 | out.writeInt(-1); |
| 7179 | return; |
| 7180 | } |
| 7181 | |
| 7182 | final int N = list.size(); |
| 7183 | out.writeInt(N); |
| 7184 | |
| 7185 | // Don't bother writing the component name if the list is empty. |
| 7186 | if (N > 0) { |
| 7187 | IntentInfo info = list.get(0); |
| 7188 | out.writeString(info.getClass().getName()); |
| 7189 | |
| 7190 | for (int i = 0; i < N;i++) { |
| 7191 | list.get(i).writeIntentInfoToParcel(out, flags); |
| 7192 | } |
| 7193 | } |
| 7194 | } |
| 7195 | |
| 7196 | private static <T extends IntentInfo> ArrayList<T> createIntentsList(Parcel in) { |
| 7197 | int N = in.readInt(); |
| 7198 | if (N == -1) { |
| 7199 | return null; |
| 7200 | } |
| 7201 | |
| 7202 | if (N == 0) { |
| 7203 | return new ArrayList<>(0); |
| 7204 | } |
| 7205 | |
| 7206 | String componentName = in.readString(); |
| 7207 | final ArrayList<T> intentsList; |
| 7208 | try { |
| 7209 | final Class<T> cls = (Class<T>) Class.forName(componentName); |
| 7210 | final Constructor<T> cons = cls.getConstructor(Parcel.class); |
| 7211 | |
| 7212 | intentsList = new ArrayList<>(N); |
| 7213 | for (int i = 0; i < N; ++i) { |
| 7214 | intentsList.add(cons.newInstance(in)); |
| 7215 | } |
| 7216 | } catch (ReflectiveOperationException ree) { |
| 7217 | throw new AssertionError("Unable to construct intent list for: " + componentName); |
| 7218 | } |
| 7219 | |
| 7220 | return intentsList; |
| 7221 | } |
| 7222 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7223 | public void appendComponentShortName(StringBuilder sb) { |
| 7224 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7225 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7226 | |
| 7227 | public void printComponentShortName(PrintWriter pw) { |
| 7228 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 7229 | } |
| 7230 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7231 | public void setPackageName(String packageName) { |
| 7232 | componentName = null; |
| 7233 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | } |
| 7235 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7236 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7237 | 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] | 7238 | public final PermissionInfo info; |
| 7239 | public boolean tree; |
| 7240 | public PermissionGroup group; |
| 7241 | |
| 7242 | public Permission(Package _owner) { |
| 7243 | super(_owner); |
| 7244 | info = new PermissionInfo(); |
| 7245 | } |
| 7246 | |
| 7247 | public Permission(Package _owner, PermissionInfo _info) { |
| 7248 | super(_owner); |
| 7249 | info = _info; |
| 7250 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7251 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7252 | public void setPackageName(String packageName) { |
| 7253 | super.setPackageName(packageName); |
| 7254 | info.packageName = packageName; |
| 7255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7256 | |
| 7257 | public String toString() { |
| 7258 | return "Permission{" |
| 7259 | + Integer.toHexString(System.identityHashCode(this)) |
| 7260 | + " " + info.name + "}"; |
| 7261 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7262 | |
| 7263 | @Override |
| 7264 | public int describeContents() { |
| 7265 | return 0; |
| 7266 | } |
| 7267 | |
| 7268 | @Override |
| 7269 | public void writeToParcel(Parcel dest, int flags) { |
| 7270 | super.writeToParcel(dest, flags); |
| 7271 | dest.writeParcelable(info, flags); |
| 7272 | dest.writeInt(tree ? 1 : 0); |
| 7273 | dest.writeParcelable(group, flags); |
| 7274 | } |
| 7275 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 7276 | /** @hide */ |
| 7277 | public boolean isAppOp() { |
| 7278 | return info.isAppOp(); |
| 7279 | } |
| 7280 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7281 | private Permission(Parcel in) { |
| 7282 | super(in); |
| 7283 | final ClassLoader boot = Object.class.getClassLoader(); |
| 7284 | info = in.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7285 | if (info.group != null) { |
| 7286 | info.group = info.group.intern(); |
| 7287 | } |
| 7288 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7289 | tree = (in.readInt() == 1); |
| 7290 | group = in.readParcelable(boot); |
| 7291 | } |
| 7292 | |
| 7293 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Permission>() { |
| 7294 | public Permission createFromParcel(Parcel in) { |
| 7295 | return new Permission(in); |
| 7296 | } |
| 7297 | |
| 7298 | public Permission[] newArray(int size) { |
| 7299 | return new Permission[size]; |
| 7300 | } |
| 7301 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7302 | } |
| 7303 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7304 | 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] | 7305 | public final PermissionGroupInfo info; |
| 7306 | |
| 7307 | public PermissionGroup(Package _owner) { |
| 7308 | super(_owner); |
| 7309 | info = new PermissionGroupInfo(); |
| 7310 | } |
| 7311 | |
| 7312 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 7313 | super(_owner); |
| 7314 | info = _info; |
| 7315 | } |
| 7316 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7317 | public void setPackageName(String packageName) { |
| 7318 | super.setPackageName(packageName); |
| 7319 | info.packageName = packageName; |
| 7320 | } |
| 7321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | public String toString() { |
| 7323 | return "PermissionGroup{" |
| 7324 | + Integer.toHexString(System.identityHashCode(this)) |
| 7325 | + " " + info.name + "}"; |
| 7326 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7327 | |
| 7328 | @Override |
| 7329 | public int describeContents() { |
| 7330 | return 0; |
| 7331 | } |
| 7332 | |
| 7333 | @Override |
| 7334 | public void writeToParcel(Parcel dest, int flags) { |
| 7335 | super.writeToParcel(dest, flags); |
| 7336 | dest.writeParcelable(info, flags); |
| 7337 | } |
| 7338 | |
| 7339 | private PermissionGroup(Parcel in) { |
| 7340 | super(in); |
| 7341 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7342 | } |
| 7343 | |
| 7344 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<PermissionGroup>() { |
| 7345 | public PermissionGroup createFromParcel(Parcel in) { |
| 7346 | return new PermissionGroup(in); |
| 7347 | } |
| 7348 | |
| 7349 | public PermissionGroup[] newArray(int size) { |
| 7350 | return new PermissionGroup[size]; |
| 7351 | } |
| 7352 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7353 | } |
| 7354 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7355 | private static boolean copyNeeded(int flags, Package p, |
| 7356 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 7357 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7358 | // We always need to copy for other users, since we need |
| 7359 | // to fix up the uid. |
| 7360 | return true; |
| 7361 | } |
| 7362 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 7363 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 7364 | if (p.applicationInfo.enabled != enabled) { |
| 7365 | return true; |
| 7366 | } |
| 7367 | } |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 7368 | boolean suspended = (p.applicationInfo.flags & FLAG_SUSPENDED) != 0; |
| 7369 | if (state.suspended != suspended) { |
| 7370 | return true; |
| 7371 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7372 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7373 | return true; |
| 7374 | } |
| 7375 | if (state.stopped) { |
| 7376 | return true; |
| 7377 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7378 | if (state.instantApp != p.applicationInfo.isInstantApp()) { |
| 7379 | return true; |
| 7380 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 7382 | && (metaData != null || p.mAppMetaData != null)) { |
| 7383 | return true; |
| 7384 | } |
| 7385 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7386 | && p.usesLibraryFiles != null) { |
| 7387 | return true; |
| 7388 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7389 | if (p.staticSharedLibName != null) { |
| 7390 | return true; |
| 7391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | return false; |
| 7393 | } |
| 7394 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7395 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 7396 | PackageUserState state) { |
| 7397 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 7398 | } |
| 7399 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7400 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 7401 | PackageUserState state) { |
| 7402 | // CompatibilityMode is global state. |
| 7403 | if (!sCompatibilityModeEnabled) { |
| 7404 | ai.disableCompatibilityMode(); |
| 7405 | } |
| 7406 | if (state.installed) { |
| 7407 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 7408 | } else { |
| 7409 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 7410 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 7411 | if (state.suspended) { |
| 7412 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 7413 | } else { |
| 7414 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 7415 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7416 | if (state.instantApp) { |
| 7417 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7418 | } else { |
| 7419 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7420 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 7421 | if (state.virtualPreload) { |
| 7422 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7423 | } else { |
| 7424 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7425 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7426 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7427 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7428 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7429 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7430 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7431 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 7432 | ai.enabled = true; |
| 7433 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 7434 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 7435 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 7436 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 7437 | ai.enabled = false; |
| 7438 | } |
| 7439 | ai.enabledSetting = state.enabled; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 7440 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7441 | ai.category = state.categoryHint; |
| 7442 | } |
Jeff Sharkey | 0078e1b | 2017-01-11 16:05:27 -0700 | [diff] [blame] | 7443 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7444 | ai.category = FallbackCategoryProvider.getFallbackCategory(ai.packageName); |
| 7445 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7446 | ai.seInfoUser = SELinuxUtil.assignSeinfoUser(state); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7447 | ai.resourceDirs = state.overlayPaths; |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7448 | } |
| 7449 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 7450 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7451 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7453 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7454 | return null; |
| 7455 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7456 | if (!copyNeeded(flags, p, state, null, userId) |
| 7457 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 7458 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 7459 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 7460 | // - CompatibilityMode is global state, so will be the same for every call. |
| 7461 | // - We only come in to here if the app should reported as installed; this is the |
| 7462 | // default state, and we will do a copy otherwise. |
| 7463 | // - The enable state will always be reported the same for the application across |
| 7464 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 7465 | // be doing a copy. |
| 7466 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7467 | return p.applicationInfo; |
| 7468 | } |
| 7469 | |
| 7470 | // Make shallow copy so we can store the metadata/libraries safely |
| 7471 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7472 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 7474 | ai.metaData = p.mAppMetaData; |
| 7475 | } |
| 7476 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 7477 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 7478 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7479 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7480 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7481 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7482 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7483 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7484 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | return ai; |
| 7486 | } |
| 7487 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7488 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 7489 | PackageUserState state, int userId) { |
| 7490 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7491 | if (!checkUseInstalledOrHidden(flags, state, ai)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7492 | return null; |
| 7493 | } |
| 7494 | // This is only used to return the ResolverActivity; we will just always |
| 7495 | // make a copy. |
| 7496 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7497 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7498 | if (state.stopped) { |
| 7499 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 7500 | } else { |
| 7501 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 7502 | } |
| 7503 | updateApplicationInfo(ai, flags, state); |
| 7504 | return ai; |
| 7505 | } |
| 7506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | public static final PermissionInfo generatePermissionInfo( |
| 7508 | Permission p, int flags) { |
| 7509 | if (p == null) return null; |
| 7510 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7511 | return p.info; |
| 7512 | } |
| 7513 | PermissionInfo pi = new PermissionInfo(p.info); |
| 7514 | pi.metaData = p.metaData; |
| 7515 | return pi; |
| 7516 | } |
| 7517 | |
| 7518 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 7519 | PermissionGroup pg, int flags) { |
| 7520 | if (pg == null) return null; |
| 7521 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7522 | return pg.info; |
| 7523 | } |
| 7524 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 7525 | pgi.metaData = pg.metaData; |
| 7526 | return pgi; |
| 7527 | } |
| 7528 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7529 | public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7530 | public final ActivityInfo info; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7531 | private boolean mHasMaxAspectRatio; |
| 7532 | |
| 7533 | private boolean hasMaxAspectRatio() { |
| 7534 | return mHasMaxAspectRatio; |
| 7535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7536 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7537 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 7538 | super(args, _info); |
| 7539 | info = _info; |
| 7540 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7541 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7542 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7543 | public void setPackageName(String packageName) { |
| 7544 | super.setPackageName(packageName); |
| 7545 | info.packageName = packageName; |
| 7546 | } |
| 7547 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7548 | |
| 7549 | private void setMaxAspectRatio(float maxAspectRatio) { |
| 7550 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7551 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7552 | // Resizeable activities can be put in any aspect ratio. |
| 7553 | return; |
| 7554 | } |
| 7555 | |
| 7556 | if (maxAspectRatio < 1.0f && maxAspectRatio != 0) { |
| 7557 | // Ignore any value lesser than 1.0. |
| 7558 | return; |
| 7559 | } |
| 7560 | |
| 7561 | info.maxAspectRatio = maxAspectRatio; |
| 7562 | mHasMaxAspectRatio = true; |
| 7563 | } |
| 7564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7566 | StringBuilder sb = new StringBuilder(128); |
| 7567 | sb.append("Activity{"); |
| 7568 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7569 | sb.append(' '); |
| 7570 | appendComponentShortName(sb); |
| 7571 | sb.append('}'); |
| 7572 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7574 | |
| 7575 | @Override |
| 7576 | public int describeContents() { |
| 7577 | return 0; |
| 7578 | } |
| 7579 | |
| 7580 | @Override |
| 7581 | public void writeToParcel(Parcel dest, int flags) { |
| 7582 | super.writeToParcel(dest, flags); |
| 7583 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7584 | dest.writeBoolean(mHasMaxAspectRatio); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7585 | } |
| 7586 | |
| 7587 | private Activity(Parcel in) { |
| 7588 | super(in); |
| 7589 | info = in.readParcelable(Object.class.getClassLoader()); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7590 | mHasMaxAspectRatio = in.readBoolean(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7591 | |
| 7592 | for (ActivityIntentInfo aii : intents) { |
| 7593 | aii.activity = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7594 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7595 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7596 | |
| 7597 | if (info.permission != null) { |
| 7598 | info.permission = info.permission.intern(); |
| 7599 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7600 | } |
| 7601 | |
| 7602 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Activity>() { |
| 7603 | public Activity createFromParcel(Parcel in) { |
| 7604 | return new Activity(in); |
| 7605 | } |
| 7606 | |
| 7607 | public Activity[] newArray(int size) { |
| 7608 | return new Activity[size]; |
| 7609 | } |
| 7610 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7613 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 7614 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | if (a == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7616 | if (!checkUseInstalledOrHidden(flags, state, a.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7617 | return null; |
| 7618 | } |
| 7619 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7620 | updateApplicationInfo(a.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | return a.info; |
| 7622 | } |
| 7623 | // Make shallow copies so we can store the metadata safely |
| 7624 | ActivityInfo ai = new ActivityInfo(a.info); |
| 7625 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7626 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7627 | return ai; |
| 7628 | } |
| 7629 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7630 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 7631 | PackageUserState state, int userId) { |
| 7632 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7633 | if (!checkUseInstalledOrHidden(flags, state, ai.applicationInfo)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7634 | return null; |
| 7635 | } |
| 7636 | // This is only used to return the ResolverActivity; we will just always |
| 7637 | // make a copy. |
| 7638 | ai = new ActivityInfo(ai); |
| 7639 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 7640 | return ai; |
| 7641 | } |
| 7642 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7643 | public final static class Service extends Component<ServiceIntentInfo> implements Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7644 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7645 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7646 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 7647 | super(args, _info); |
| 7648 | info = _info; |
| 7649 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7650 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7651 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7652 | public void setPackageName(String packageName) { |
| 7653 | super.setPackageName(packageName); |
| 7654 | info.packageName = packageName; |
| 7655 | } |
| 7656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7657 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7658 | StringBuilder sb = new StringBuilder(128); |
| 7659 | sb.append("Service{"); |
| 7660 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7661 | sb.append(' '); |
| 7662 | appendComponentShortName(sb); |
| 7663 | sb.append('}'); |
| 7664 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7666 | |
| 7667 | @Override |
| 7668 | public int describeContents() { |
| 7669 | return 0; |
| 7670 | } |
| 7671 | |
| 7672 | @Override |
| 7673 | public void writeToParcel(Parcel dest, int flags) { |
| 7674 | super.writeToParcel(dest, flags); |
| 7675 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 7676 | } |
| 7677 | |
| 7678 | private Service(Parcel in) { |
| 7679 | super(in); |
| 7680 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7681 | |
| 7682 | for (ServiceIntentInfo aii : intents) { |
| 7683 | aii.service = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7684 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7685 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7686 | |
| 7687 | if (info.permission != null) { |
| 7688 | info.permission = info.permission.intern(); |
| 7689 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Service>() { |
| 7693 | public Service createFromParcel(Parcel in) { |
| 7694 | return new Service(in); |
| 7695 | } |
| 7696 | |
| 7697 | public Service[] newArray(int size) { |
| 7698 | return new Service[size]; |
| 7699 | } |
| 7700 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | } |
| 7702 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7703 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 7704 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | if (s == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7706 | if (!checkUseInstalledOrHidden(flags, state, s.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7707 | return null; |
| 7708 | } |
| 7709 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7710 | updateApplicationInfo(s.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | return s.info; |
| 7712 | } |
| 7713 | // Make shallow copies so we can store the metadata safely |
| 7714 | ServiceInfo si = new ServiceInfo(s.info); |
| 7715 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7716 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7717 | return si; |
| 7718 | } |
| 7719 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7720 | 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] | 7721 | public final ProviderInfo info; |
| 7722 | public boolean syncable; |
| 7723 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7724 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 7725 | super(args, _info); |
| 7726 | info = _info; |
| 7727 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | syncable = false; |
| 7729 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | public Provider(Provider existingProvider) { |
| 7732 | super(existingProvider); |
| 7733 | this.info = existingProvider.info; |
| 7734 | this.syncable = existingProvider.syncable; |
| 7735 | } |
| 7736 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7737 | public void setPackageName(String packageName) { |
| 7738 | super.setPackageName(packageName); |
| 7739 | info.packageName = packageName; |
| 7740 | } |
| 7741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7742 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7743 | StringBuilder sb = new StringBuilder(128); |
| 7744 | sb.append("Provider{"); |
| 7745 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7746 | sb.append(' '); |
| 7747 | appendComponentShortName(sb); |
| 7748 | sb.append('}'); |
| 7749 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7751 | |
| 7752 | @Override |
| 7753 | public int describeContents() { |
| 7754 | return 0; |
| 7755 | } |
| 7756 | |
| 7757 | @Override |
| 7758 | public void writeToParcel(Parcel dest, int flags) { |
| 7759 | super.writeToParcel(dest, flags); |
| 7760 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 7761 | dest.writeInt((syncable) ? 1 : 0); |
| 7762 | } |
| 7763 | |
| 7764 | private Provider(Parcel in) { |
| 7765 | super(in); |
| 7766 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7767 | syncable = (in.readInt() == 1); |
| 7768 | |
| 7769 | for (ProviderIntentInfo aii : intents) { |
| 7770 | aii.provider = this; |
| 7771 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7772 | |
| 7773 | if (info.readPermission != null) { |
| 7774 | info.readPermission = info.readPermission.intern(); |
| 7775 | } |
| 7776 | |
| 7777 | if (info.writePermission != null) { |
| 7778 | info.writePermission = info.writePermission.intern(); |
| 7779 | } |
| 7780 | |
| 7781 | if (info.authority != null) { |
| 7782 | info.authority = info.authority.intern(); |
| 7783 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7784 | } |
| 7785 | |
| 7786 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Provider>() { |
| 7787 | public Provider createFromParcel(Parcel in) { |
| 7788 | return new Provider(in); |
| 7789 | } |
| 7790 | |
| 7791 | public Provider[] newArray(int size) { |
| 7792 | return new Provider[size]; |
| 7793 | } |
| 7794 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | } |
| 7796 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7797 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 7798 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7799 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7800 | if (!checkUseInstalledOrHidden(flags, state, p.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7801 | return null; |
| 7802 | } |
| 7803 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7805 | || p.info.uriPermissionPatterns == null)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7806 | updateApplicationInfo(p.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | return p.info; |
| 7808 | } |
| 7809 | // Make shallow copies so we can store the metadata safely |
| 7810 | ProviderInfo pi = new ProviderInfo(p.info); |
| 7811 | pi.metaData = p.metaData; |
| 7812 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 7813 | pi.uriPermissionPatterns = null; |
| 7814 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7815 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | return pi; |
| 7817 | } |
| 7818 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7819 | public final static class Instrumentation extends Component<IntentInfo> implements |
| 7820 | Parcelable { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7821 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7822 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7823 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 7824 | super(args, _info); |
| 7825 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7827 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7828 | public void setPackageName(String packageName) { |
| 7829 | super.setPackageName(packageName); |
| 7830 | info.packageName = packageName; |
| 7831 | } |
| 7832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7834 | StringBuilder sb = new StringBuilder(128); |
| 7835 | sb.append("Instrumentation{"); |
| 7836 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7837 | sb.append(' '); |
| 7838 | appendComponentShortName(sb); |
| 7839 | sb.append('}'); |
| 7840 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7841 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7842 | |
| 7843 | @Override |
| 7844 | public int describeContents() { |
| 7845 | return 0; |
| 7846 | } |
| 7847 | |
| 7848 | @Override |
| 7849 | public void writeToParcel(Parcel dest, int flags) { |
| 7850 | super.writeToParcel(dest, flags); |
| 7851 | dest.writeParcelable(info, flags); |
| 7852 | } |
| 7853 | |
| 7854 | private Instrumentation(Parcel in) { |
| 7855 | super(in); |
| 7856 | info = in.readParcelable(Object.class.getClassLoader()); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7857 | |
| 7858 | if (info.targetPackage != null) { |
| 7859 | info.targetPackage = info.targetPackage.intern(); |
| 7860 | } |
| 7861 | |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 7862 | if (info.targetProcesses != null) { |
| 7863 | info.targetProcesses = info.targetProcesses.intern(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7864 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Instrumentation>() { |
| 7868 | public Instrumentation createFromParcel(Parcel in) { |
| 7869 | return new Instrumentation(in); |
| 7870 | } |
| 7871 | |
| 7872 | public Instrumentation[] newArray(int size) { |
| 7873 | return new Instrumentation[size]; |
| 7874 | } |
| 7875 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7876 | } |
| 7877 | |
| 7878 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 7879 | Instrumentation i, int flags) { |
| 7880 | if (i == null) return null; |
| 7881 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7882 | return i.info; |
| 7883 | } |
| 7884 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 7885 | ii.metaData = i.metaData; |
| 7886 | return ii; |
| 7887 | } |
| 7888 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7889 | public static abstract class IntentInfo extends IntentFilter { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | public boolean hasDefault; |
| 7891 | public int labelRes; |
| 7892 | public CharSequence nonLocalizedLabel; |
| 7893 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 7894 | public int logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 7895 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 7896 | public int preferred; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7897 | |
| 7898 | protected IntentInfo() { |
| 7899 | } |
| 7900 | |
| 7901 | protected IntentInfo(Parcel dest) { |
| 7902 | super(dest); |
| 7903 | hasDefault = (dest.readInt() == 1); |
| 7904 | labelRes = dest.readInt(); |
| 7905 | nonLocalizedLabel = dest.readCharSequence(); |
| 7906 | icon = dest.readInt(); |
| 7907 | logo = dest.readInt(); |
| 7908 | banner = dest.readInt(); |
| 7909 | preferred = dest.readInt(); |
| 7910 | } |
| 7911 | |
| 7912 | |
| 7913 | public void writeIntentInfoToParcel(Parcel dest, int flags) { |
| 7914 | super.writeToParcel(dest, flags); |
| 7915 | dest.writeInt(hasDefault ? 1 : 0); |
| 7916 | dest.writeInt(labelRes); |
| 7917 | dest.writeCharSequence(nonLocalizedLabel); |
| 7918 | dest.writeInt(icon); |
| 7919 | dest.writeInt(logo); |
| 7920 | dest.writeInt(banner); |
| 7921 | dest.writeInt(preferred); |
| 7922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | public final static class ActivityIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7926 | public Activity activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | |
| 7928 | public ActivityIntentInfo(Activity _activity) { |
| 7929 | activity = _activity; |
| 7930 | } |
| 7931 | |
| 7932 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7933 | StringBuilder sb = new StringBuilder(128); |
| 7934 | sb.append("ActivityIntentInfo{"); |
| 7935 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7936 | sb.append(' '); |
| 7937 | activity.appendComponentShortName(sb); |
| 7938 | sb.append('}'); |
| 7939 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7940 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7941 | |
| 7942 | public ActivityIntentInfo(Parcel in) { |
| 7943 | super(in); |
| 7944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | } |
| 7946 | |
| 7947 | public final static class ServiceIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7948 | public Service service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | |
| 7950 | public ServiceIntentInfo(Service _service) { |
| 7951 | service = _service; |
| 7952 | } |
| 7953 | |
| 7954 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7955 | StringBuilder sb = new StringBuilder(128); |
| 7956 | sb.append("ServiceIntentInfo{"); |
| 7957 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7958 | sb.append(' '); |
| 7959 | service.appendComponentShortName(sb); |
| 7960 | sb.append('}'); |
| 7961 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7962 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7963 | |
| 7964 | public ServiceIntentInfo(Parcel in) { |
| 7965 | super(in); |
| 7966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 7968 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7969 | public static final class ProviderIntentInfo extends IntentInfo { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7970 | public Provider provider; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7971 | |
| 7972 | public ProviderIntentInfo(Provider provider) { |
| 7973 | this.provider = provider; |
| 7974 | } |
| 7975 | |
| 7976 | public String toString() { |
| 7977 | StringBuilder sb = new StringBuilder(128); |
| 7978 | sb.append("ProviderIntentInfo{"); |
| 7979 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7980 | sb.append(' '); |
| 7981 | provider.appendComponentShortName(sb); |
| 7982 | sb.append('}'); |
| 7983 | return sb.toString(); |
| 7984 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7985 | |
| 7986 | public ProviderIntentInfo(Parcel in) { |
| 7987 | super(in); |
| 7988 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 7989 | } |
| 7990 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 7991 | /** |
| 7992 | * @hide |
| 7993 | */ |
| 7994 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 7995 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 7996 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 7997 | |
| 7998 | public static class PackageParserException extends Exception { |
| 7999 | public final int error; |
| 8000 | |
| 8001 | public PackageParserException(int error, String detailMessage) { |
| 8002 | super(detailMessage); |
| 8003 | this.error = error; |
| 8004 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 8005 | |
| 8006 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 8007 | super(detailMessage, throwable); |
| 8008 | this.error = error; |
| 8009 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8011 | } |