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; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 33 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 34 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST; |
| 35 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 36 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 37 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 38 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 39 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 40 | import static android.os.Build.VERSION_CODES.O; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 41 | import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 43 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 44 | import android.annotation.IntDef; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 45 | import android.annotation.IntRange; |
| 46 | import android.annotation.NonNull; |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 47 | import android.annotation.Nullable; |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 48 | import android.annotation.StringRes; |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 49 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 50 | import android.annotation.UnsupportedAppUsage; |
Gavin Corkery | ef44172 | 2019-05-09 17:02:10 +0100 | [diff] [blame] | 51 | import android.apex.ApexInfo; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 52 | import android.app.ActivityTaskManager; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 53 | import android.app.ActivityThread; |
| 54 | import android.app.ResourcesManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.ComponentName; |
| 56 | import android.content.Intent; |
| 57 | import android.content.IntentFilter; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 58 | import android.content.pm.PackageParserCacheHelper.ReadHelper; |
| 59 | import android.content.pm.PackageParserCacheHelper.WriteHelper; |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 60 | import android.content.pm.split.DefaultSplitAssetLoader; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 61 | import android.content.pm.split.SplitAssetDependencyLoader; |
| 62 | import android.content.pm.split.SplitAssetLoader; |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 63 | import android.content.res.ApkAssets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.content.res.AssetManager; |
| 65 | import android.content.res.Configuration; |
| 66 | import android.content.res.Resources; |
| 67 | import android.content.res.TypedArray; |
| 68 | import android.content.res.XmlResourceParser; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 69 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Bundle; |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 71 | import android.os.FileUtils; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 72 | import android.os.Parcel; |
| 73 | import android.os.Parcelable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.os.PatternMatcher; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 75 | import android.os.RemoteException; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 76 | import android.os.SystemClock; |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 77 | import android.os.SystemProperties; |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 78 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 80 | import android.os.storage.StorageManager; |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 81 | import android.permission.PermissionManager; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 82 | import android.system.ErrnoException; |
| 83 | import android.system.OsConstants; |
| 84 | import android.system.StructStat; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 85 | import android.text.TextUtils; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 86 | import android.util.ArrayMap; |
| 87 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.AttributeSet; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 89 | import android.util.Base64; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 91 | import android.util.Log; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 92 | import android.util.PackageUtils; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 93 | import android.util.Pair; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 94 | import android.util.Slog; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 95 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.util.TypedValue; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 97 | import android.util.apk.ApkSignatureVerifier; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 98 | import android.view.Display; |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 99 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 101 | import com.android.internal.R; |
| 102 | import com.android.internal.annotations.VisibleForTesting; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 103 | import com.android.internal.os.ClassLoaderFactory; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 104 | import com.android.internal.util.ArrayUtils; |
| 105 | import com.android.internal.util.XmlUtils; |
| 106 | |
| 107 | import libcore.io.IoUtils; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 108 | import libcore.util.EmptyArray; |
Neil Fuller | 2c7cc6e | 2019-04-11 11:04:06 +0100 | [diff] [blame] | 109 | import libcore.util.HexEncoding; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 111 | import org.xmlpull.v1.XmlPullParser; |
| 112 | import org.xmlpull.v1.XmlPullParserException; |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import java.io.File; |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 115 | import java.io.FileDescriptor; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 116 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import java.io.IOException; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 118 | import java.io.PrintWriter; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 119 | import java.lang.annotation.Retention; |
| 120 | import java.lang.annotation.RetentionPolicy; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 121 | import java.lang.reflect.Constructor; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 122 | import java.security.KeyFactory; |
| 123 | import java.security.NoSuchAlgorithmException; |
| 124 | import java.security.PublicKey; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 125 | import java.security.cert.CertificateException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 126 | import java.security.spec.EncodedKeySpec; |
| 127 | import java.security.spec.InvalidKeySpecException; |
| 128 | import java.security.spec.X509EncodedKeySpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | import java.util.ArrayList; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 130 | import java.util.Arrays; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 131 | import java.util.Collections; |
| 132 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | import java.util.Iterator; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 134 | import java.util.List; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 135 | import java.util.Set; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 136 | import java.util.UUID; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 137 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
| 139 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 140 | * Parser for package files (APKs) on disk. This supports apps packaged either |
| 141 | * as a single "monolithic" APK, or apps packaged as a "cluster" of multiple |
| 142 | * APKs in a single directory. |
| 143 | * <p> |
| 144 | * Apps packaged as multiple APKs always consist of a single "base" APK (with a |
| 145 | * {@code null} split name) and zero or more "split" APKs (with unique split |
| 146 | * names). Any subset of those split APKs are a valid install, as long as the |
| 147 | * following constraints are met: |
| 148 | * <ul> |
| 149 | * <li>All APKs must have the exact same package name, version code, and signing |
| 150 | * certificates. |
| 151 | * <li>All APKs must have unique split names. |
| 152 | * <li>All installations must contain a single base APK. |
| 153 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 155 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | */ |
| 157 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 158 | private static final boolean DEBUG_JAR = false; |
| 159 | private static final boolean DEBUG_PARSER = false; |
| 160 | private static final boolean DEBUG_BACKUP = false; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 161 | private static final boolean LOG_PARSE_TIMINGS = Build.IS_DEBUGGABLE; |
| 162 | private static final int LOG_PARSE_TIMINGS_THRESHOLD_MS = 100; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 163 | |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 164 | private static final String PROPERTY_CHILD_PACKAGES_ENABLED = |
| 165 | "persist.sys.child_packages_enabled"; |
| 166 | |
Jeff Sharkey | 3f1790d | 2017-04-25 18:56:17 -0600 | [diff] [blame] | 167 | private static final boolean MULTI_PACKAGE_APK_ENABLED = Build.IS_DEBUGGABLE && |
Garrett Boyer | 1704153 | 2017-08-01 14:11:02 -0700 | [diff] [blame] | 168 | SystemProperties.getBoolean(PROPERTY_CHILD_PACKAGES_ENABLED, false); |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 169 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 170 | private static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 171 | private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO = 1.333f; |
| 172 | private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO_WATCH = 1f; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 173 | |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 174 | private static final int DEFAULT_MIN_SDK_VERSION = 1; |
| 175 | private static final int DEFAULT_TARGET_SDK_VERSION = 0; |
| 176 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 177 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 178 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 179 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 180 | /** File name in an APK for the Android manifest. */ |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 181 | public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 182 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 183 | /** Path prefix for apps on expanded storage */ |
| 184 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 185 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 186 | private static final String TAG_MANIFEST = "manifest"; |
| 187 | private static final String TAG_APPLICATION = "application"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 188 | private static final String TAG_PACKAGE_VERIFIER = "package-verifier"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 189 | private static final String TAG_OVERLAY = "overlay"; |
| 190 | private static final String TAG_KEY_SETS = "key-sets"; |
| 191 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 192 | private static final String TAG_PERMISSION = "permission"; |
| 193 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 194 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 195 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 196 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 197 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 198 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 199 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 200 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 201 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 202 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 203 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 204 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 205 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 206 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 207 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 208 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 209 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 210 | private static final String TAG_PACKAGE = "package"; |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 211 | private static final String TAG_RESTRICT_UPDATE = "restrict-update"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 212 | private static final String TAG_USES_SPLIT = "uses-split"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 213 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 214 | private static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect"; |
| 215 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 216 | /** |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 217 | * 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] | 218 | * @hide |
| 219 | */ |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 220 | private static final int RECREATE_ON_CONFIG_CHANGES_MASK = |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 221 | ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC; |
| 222 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 223 | // These are the tags supported by child packages |
| 224 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 225 | static { |
| 226 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 227 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 228 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 229 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 230 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 231 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 232 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 233 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 234 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 235 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 236 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 237 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 238 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 239 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 240 | } |
| 241 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 242 | private static final boolean LOG_UNSAFE_BROADCASTS = false; |
| 243 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Total number of packages that were read from the cache. We use it only for logging. |
| 246 | */ |
| 247 | public static final AtomicInteger sCachedPackageReadCount = new AtomicInteger(); |
| 248 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 249 | // Set of broadcast actions that are safe for manifest receivers |
| 250 | private static final Set<String> SAFE_BROADCASTS = new ArraySet<>(); |
| 251 | static { |
| 252 | SAFE_BROADCASTS.add(Intent.ACTION_BOOT_COMPLETED); |
| 253 | } |
| 254 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 255 | /** @hide */ |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 256 | public static final String APK_FILE_EXTENSION = ".apk"; |
| 257 | |
| 258 | /** @hide */ |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 259 | public static class NewPermissionInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 260 | @UnsupportedAppUsage |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 261 | public final String name; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 262 | @UnsupportedAppUsage |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 263 | public final int sdkVersion; |
| 264 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 265 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 266 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 267 | this.name = name; |
| 268 | this.sdkVersion = sdkVersion; |
| 269 | this.fileVersion = fileVersion; |
| 270 | } |
| 271 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 272 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 273 | /** |
| 274 | * List of new permissions that have been added since 1.0. |
| 275 | * NOTE: These must be declared in SDK version order, with permissions |
| 276 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 277 | * If sdkVersion is 0, then this is not a permission that we want to |
| 278 | * automatically add to older apps, but we do want to allow it to be |
| 279 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 280 | * @hide |
| 281 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 282 | @UnsupportedAppUsage |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 283 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 284 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 285 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 286 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 287 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 288 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 289 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 291 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 292 | * @deprecated callers should move to explicitly passing around source path. |
| 293 | */ |
| 294 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 298 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 299 | private DisplayMetrics mMetrics; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 300 | @UnsupportedAppUsage |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 301 | private Callback mCallback; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 302 | private File mCacheDir; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 303 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 304 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 305 | 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] | 306 | |
| 307 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 308 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 309 | private static boolean sCompatibilityModeEnabled = true; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 310 | private static boolean sUseRoundIcon = false; |
| 311 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 312 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 313 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 314 | private static final int PARSE_DEFAULT_TARGET_SANDBOX = 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 315 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 316 | static class ParsePackageItemArgs { |
| 317 | final Package owner; |
| 318 | final String[] outError; |
| 319 | final int nameRes; |
| 320 | final int labelRes; |
| 321 | final int iconRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 322 | final int roundIconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 323 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 324 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 325 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 326 | String tag; |
| 327 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 328 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 329 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 330 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 331 | int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 332 | owner = _owner; |
| 333 | outError = _outError; |
| 334 | nameRes = _nameRes; |
| 335 | labelRes = _labelRes; |
| 336 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 337 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 338 | bannerRes = _bannerRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 339 | roundIconRes = _roundIconRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 342 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 343 | /** @hide */ |
| 344 | @VisibleForTesting |
| 345 | public static class ParseComponentArgs extends ParsePackageItemArgs { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 346 | final String[] sepProcesses; |
| 347 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 348 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 349 | final int enabledRes; |
| 350 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 351 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 352 | public ParseComponentArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 353 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 354 | int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 355 | String[] _sepProcesses, int _processRes, |
| 356 | int _descriptionRes, int _enabledRes) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 357 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _roundIconRes, _logoRes, |
| 358 | _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 359 | sepProcesses = _sepProcesses; |
| 360 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 361 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 362 | enabledRes = _enabledRes; |
| 363 | } |
| 364 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 365 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 366 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 367 | * Lightweight parsed details about a single package. |
| 368 | */ |
| 369 | public static class PackageLite { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 370 | @UnsupportedAppUsage |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 371 | public final String packageName; |
| 372 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 373 | public final int versionCodeMajor; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 374 | @UnsupportedAppUsage |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 375 | public final int installLocation; |
| 376 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 377 | |
| 378 | /** Names of any split APKs, ordered by parsed splitName */ |
| 379 | public final String[] splitNames; |
| 380 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 381 | /** Names of any split APKs that are features. Ordered by splitName */ |
| 382 | public final boolean[] isFeatureSplits; |
| 383 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 384 | /** Dependencies of any split APKs, ordered by parsed splitName */ |
| 385 | public final String[] usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 386 | public final String[] configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 387 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 388 | /** |
| 389 | * Path where this package was found on disk. For monolithic packages |
| 390 | * this is path to single base APK file; for cluster packages this is |
| 391 | * path to the cluster directory. |
| 392 | */ |
| 393 | public final String codePath; |
| 394 | |
| 395 | /** Path of base APK */ |
| 396 | public final String baseCodePath; |
| 397 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 398 | public final String[] splitCodePaths; |
| 399 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 400 | /** Revision code of base APK */ |
| 401 | public final int baseRevisionCode; |
| 402 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 403 | public final int[] splitRevisionCodes; |
| 404 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 405 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 406 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 407 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 408 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 409 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 410 | public final boolean isolatedSplits; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 411 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 412 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 413 | boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 414 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 415 | this.packageName = baseApk.packageName; |
| 416 | this.versionCode = baseApk.versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 417 | this.versionCodeMajor = baseApk.versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 418 | this.installLocation = baseApk.installLocation; |
| 419 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 420 | this.splitNames = splitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 421 | this.isFeatureSplits = isFeatureSplits; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 422 | this.usesSplitNames = usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 423 | this.configForSplit = configForSplit; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 424 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 425 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 426 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 427 | this.baseRevisionCode = baseApk.revisionCode; |
| 428 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 429 | this.coreApp = baseApk.coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 430 | this.debuggable = baseApk.debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 431 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 432 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 433 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 434 | this.isolatedSplits = baseApk.isolatedSplits; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | public List<String> getAllCodePaths() { |
| 438 | ArrayList<String> paths = new ArrayList<>(); |
| 439 | paths.add(baseCodePath); |
| 440 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 441 | Collections.addAll(paths, splitCodePaths); |
| 442 | } |
| 443 | return paths; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 448 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 449 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 450 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 451 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 452 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 453 | public final String splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 454 | public boolean isFeatureSplit; |
| 455 | public final String configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 456 | public final String usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 457 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 458 | public final int versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 459 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 460 | public final int installLocation; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 461 | public final int minSdkVersion; |
| 462 | public final int targetSdkVersion; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 463 | public final VerifierInfo[] verifiers; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 464 | public final SigningDetails signingDetails; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 465 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 466 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 467 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 468 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 469 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 470 | public final boolean isolatedSplits; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 471 | public final boolean isSplitRequired; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 472 | public final boolean useEmbeddedDex; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 473 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 474 | public ApkLite(String codePath, String packageName, String splitName, |
| 475 | boolean isFeatureSplit, |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 476 | String configForSplit, String usesSplitName, boolean isSplitRequired, |
| 477 | int versionCode, int versionCodeMajor, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 478 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 479 | SigningDetails signingDetails, boolean coreApp, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 480 | boolean debuggable, boolean multiArch, boolean use32bitAbi, |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 481 | boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits, |
| 482 | int minSdkVersion, int targetSdkVersion) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 483 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 484 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 485 | this.splitName = splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 486 | this.isFeatureSplit = isFeatureSplit; |
| 487 | this.configForSplit = configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 488 | this.usesSplitName = usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 489 | this.versionCode = versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 490 | this.versionCodeMajor = versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 491 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 492 | this.installLocation = installLocation; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 493 | this.signingDetails = signingDetails; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 494 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 495 | this.coreApp = coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 496 | this.debuggable = debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 497 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 498 | this.use32bitAbi = use32bitAbi; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 499 | this.useEmbeddedDex = useEmbeddedDex; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 500 | this.extractNativeLibs = extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 501 | this.isolatedSplits = isolatedSplits; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 502 | this.isSplitRequired = isSplitRequired; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 503 | this.minSdkVersion = minSdkVersion; |
| 504 | this.targetSdkVersion = targetSdkVersion; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 505 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 506 | |
| 507 | public long getLongVersionCode() { |
| 508 | return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); |
| 509 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 510 | } |
| 511 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 512 | /** |
| 513 | * Cached parse state for new components. |
| 514 | * |
| 515 | * Allows reuse of the same parse argument records to avoid GC pressure. Lifetime is carefully |
| 516 | * scoped to the parsing of a single application element. |
| 517 | */ |
| 518 | private static class CachedComponentArgs { |
| 519 | ParseComponentArgs mActivityArgs; |
| 520 | ParseComponentArgs mActivityAliasArgs; |
| 521 | ParseComponentArgs mServiceArgs; |
| 522 | ParseComponentArgs mProviderArgs; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Cached state for parsing instrumentation to avoid GC pressure. |
| 527 | * |
| 528 | * Must be manually reset to null for each new manifest. |
| 529 | */ |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 530 | private ParsePackageItemArgs mParseInstrumentationArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | /** If set to true, we will only allow package files that exactly match |
| 533 | * the DTD. Otherwise, we try to get as much from the package as we |
| 534 | * can without failing. This should normally be set to false, to |
| 535 | * support extensions to the DTD in future versions. */ |
| 536 | private static final boolean RIGID_PARSER = false; |
| 537 | |
| 538 | private static final String TAG = "PackageParser"; |
| 539 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 540 | @UnsupportedAppUsage |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 541 | public PackageParser() { |
| 542 | mMetrics = new DisplayMetrics(); |
| 543 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 546 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | public void setSeparateProcesses(String[] procs) { |
| 548 | mSeparateProcesses = procs; |
| 549 | } |
| 550 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 551 | /** |
| 552 | * Flag indicating this parser should only consider apps with |
| 553 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 554 | * creating a minimalist boot environment. |
| 555 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 556 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 557 | mOnlyCoreApps = onlyCoreApps; |
| 558 | } |
| 559 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 560 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 561 | mMetrics = metrics; |
| 562 | } |
| 563 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 564 | /** |
| 565 | * Sets the cache directory for this package parser. |
| 566 | */ |
| 567 | public void setCacheDir(File cacheDir) { |
| 568 | mCacheDir = cacheDir; |
| 569 | } |
| 570 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 571 | /** |
| 572 | * Callback interface for retrieving information that may be needed while parsing |
| 573 | * a package. |
| 574 | */ |
| 575 | public interface Callback { |
| 576 | boolean hasFeature(String feature); |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 577 | String[] getOverlayPaths(String targetPackageName, String targetPath); |
| 578 | String[] getOverlayApks(String targetPackageName); |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Standard implementation of {@link Callback} on top of the public {@link PackageManager} |
| 583 | * class. |
| 584 | */ |
| 585 | public static final class CallbackImpl implements Callback { |
| 586 | private final PackageManager mPm; |
| 587 | |
| 588 | public CallbackImpl(PackageManager pm) { |
| 589 | mPm = pm; |
| 590 | } |
| 591 | |
| 592 | @Override public boolean hasFeature(String feature) { |
| 593 | return mPm.hasSystemFeature(feature); |
| 594 | } |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 595 | |
| 596 | @Override public String[] getOverlayPaths(String targetPackageName, String targetPath) { |
| 597 | return null; |
| 598 | } |
| 599 | |
| 600 | @Override public String[] getOverlayApks(String targetPackageName) { |
| 601 | return null; |
| 602 | } |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Set the {@link Callback} that can be used while parsing. |
| 607 | */ |
| 608 | public void setCallback(Callback cb) { |
| 609 | mCallback = cb; |
| 610 | } |
| 611 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 612 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 613 | return isApkPath(file.getName()); |
| 614 | } |
| 615 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 616 | public static boolean isApkPath(String path) { |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 617 | return path.endsWith(APK_FILE_EXTENSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 622 | * |
| 623 | * @param p the parsed package. |
| 624 | * @param flags indicating which optional information is included. |
| 625 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 626 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | cd47c26 | 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 | cd47c26 | 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 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 661 | @UnsupportedAppUsage |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 662 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 663 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 664 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 665 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 666 | return null; |
| 667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | PackageInfo pi = new PackageInfo(); |
| 669 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 670 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | pi.versionCode = p.mVersionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 672 | pi.versionCodeMajor = p.mVersionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 673 | pi.baseRevisionCode = p.baseRevisionCode; |
| 674 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | pi.versionName = p.mVersionName; |
| 676 | pi.sharedUserId = p.mSharedUserId; |
| 677 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 678 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 679 | pi.installLocation = p.installLocation; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 680 | pi.isStub = p.isStub; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 681 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 682 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 683 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 684 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 685 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 686 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 687 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 688 | pi.overlayTarget = p.mOverlayTarget; |
Ryan Mitchell | d57fb1f | 2019-03-20 17:18:58 -0700 | [diff] [blame] | 689 | pi.targetOverlayableName = p.mOverlayTargetName; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 690 | pi.overlayCategory = p.mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 691 | pi.overlayPriority = p.mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 692 | pi.mOverlayIsStatic = p.mOverlayIsStatic; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 693 | pi.compileSdkVersion = p.mCompileSdkVersion; |
| 694 | pi.compileSdkVersionCodename = p.mCompileSdkVersionCodename; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 695 | pi.firstInstallTime = firstInstallTime; |
| 696 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 698 | pi.gids = gids; |
| 699 | } |
| 700 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 701 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | if (N > 0) { |
| 703 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 704 | p.configPreferences.toArray(pi.configPreferences); |
| 705 | } |
| 706 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 707 | if (N > 0) { |
| 708 | pi.reqFeatures = new FeatureInfo[N]; |
| 709 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 711 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 712 | if (N > 0) { |
| 713 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 714 | p.featureGroups.toArray(pi.featureGroups); |
| 715 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 717 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 718 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 720 | int num = 0; |
| 721 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 722 | for (int i = 0; i < N; i++) { |
| 723 | final Activity a = p.activities.get(i); |
| 724 | if (state.isMatch(a.info, flags)) { |
Ricky Wai | 905908f | 2019-01-29 15:19:52 +0000 | [diff] [blame] | 725 | if (PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(a.className)) { |
| 726 | continue; |
| 727 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 728 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | } |
| 730 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 731 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | } |
| 733 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 734 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 735 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 737 | int num = 0; |
| 738 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 739 | for (int i = 0; i < N; i++) { |
| 740 | final Activity a = p.receivers.get(i); |
| 741 | if (state.isMatch(a.info, flags)) { |
| 742 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 745 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | } |
| 747 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 748 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 749 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 751 | int num = 0; |
| 752 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 753 | for (int i = 0; i < N; i++) { |
| 754 | final Service s = p.services.get(i); |
| 755 | if (state.isMatch(s.info, flags)) { |
| 756 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | } |
| 758 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 759 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | } |
| 761 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 762 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 763 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 765 | int num = 0; |
| 766 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 767 | for (int i = 0; i < N; i++) { |
| 768 | final Provider pr = p.providers.get(i); |
| 769 | if (state.isMatch(pr.info, flags)) { |
| 770 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | } |
| 772 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 773 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 777 | int N = p.instrumentation.size(); |
| 778 | if (N > 0) { |
| 779 | pi.instrumentation = new InstrumentationInfo[N]; |
| 780 | for (int i=0; i<N; i++) { |
| 781 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 782 | p.instrumentation.get(i), flags); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 787 | int N = p.permissions.size(); |
| 788 | if (N > 0) { |
| 789 | pi.permissions = new PermissionInfo[N]; |
| 790 | for (int i=0; i<N; i++) { |
| 791 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 792 | } |
| 793 | } |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 794 | N = p.requestedPermissions.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | if (N > 0) { |
| 796 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 797 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | for (int i=0; i<N; i++) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 799 | final String perm = p.requestedPermissions.get(i); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 800 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 801 | // The notion of required permissions is deprecated but for compatibility. |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 802 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 803 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 804 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 805 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 809 | // deprecated method of getting signing certificates |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 811 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 812 | // Package has included signing certificate rotation information. Return the oldest |
| 813 | // cert so that programmatic checks keep working even if unaware of key rotation. |
| 814 | pi.signatures = new Signature[1]; |
| 815 | pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0]; |
| 816 | } else if (p.mSigningDetails.hasSignatures()) { |
| 817 | // otherwise keep old behavior |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 818 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 819 | pi.signatures = new Signature[numberOfSigs]; |
| 820 | 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] | 821 | } |
| 822 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 823 | |
| 824 | // replacement for GET_SIGNATURES |
| 825 | if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) { |
Dan Cashman | 5c9f527e | 2018-04-03 16:42:23 -0700 | [diff] [blame] | 826 | if (p.mSigningDetails != SigningDetails.UNKNOWN) { |
| 827 | // only return a valid SigningInfo if there is signing information to report |
| 828 | pi.signingInfo = new SigningInfo(p.mSigningDetails); |
| 829 | } else { |
| 830 | pi.signingInfo = null; |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 831 | } |
| 832 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | return pi; |
| 834 | } |
| 835 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 836 | public static final int PARSE_MUST_BE_APK = 1 << 0; |
| 837 | public static final int PARSE_IGNORE_PROCESSES = 1 << 1; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 838 | public static final int PARSE_EXTERNAL_STORAGE = 1 << 3; |
| 839 | public static final int PARSE_IS_SYSTEM_DIR = 1 << 4; |
| 840 | public static final int PARSE_COLLECT_CERTIFICATES = 1 << 5; |
| 841 | public static final int PARSE_ENFORCE_CODE = 1 << 6; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 842 | public static final int PARSE_CHATTY = 1 << 31; |
| 843 | |
| 844 | @IntDef(flag = true, prefix = { "PARSE_" }, value = { |
| 845 | PARSE_CHATTY, |
| 846 | PARSE_COLLECT_CERTIFICATES, |
| 847 | PARSE_ENFORCE_CODE, |
| 848 | PARSE_EXTERNAL_STORAGE, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 849 | PARSE_IGNORE_PROCESSES, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 850 | PARSE_IS_SYSTEM_DIR, |
| 851 | PARSE_MUST_BE_APK, |
| 852 | }) |
| 853 | @Retention(RetentionPolicy.SOURCE) |
| 854 | public @interface ParseFlags {} |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 855 | |
| 856 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 858 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 859 | * Used to sort a set of APKs based on their split names, always placing the |
| 860 | * base APK (with {@code null} split name) first. |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 861 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 862 | private static class SplitNameComparator implements Comparator<String> { |
| 863 | @Override |
| 864 | public int compare(String lhs, String rhs) { |
| 865 | if (lhs == null) { |
| 866 | return -1; |
| 867 | } else if (rhs == null) { |
| 868 | return 1; |
| 869 | } else { |
| 870 | return lhs.compareTo(rhs); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 875 | /** |
| 876 | * Parse only lightweight details about the package at the given location. |
| 877 | * Automatically detects if the package is a monolithic style (single APK |
| 878 | * file) or cluster style (directory of APKs). |
| 879 | * <p> |
| 880 | * This performs sanity checking on cluster style packages, such as |
| 881 | * requiring identical package name and version codes, a single base APK, |
| 882 | * and unique split names. |
| 883 | * |
| 884 | * @see PackageParser#parsePackage(File, int) |
| 885 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 886 | @UnsupportedAppUsage |
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 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1011 | @UnsupportedAppUsage |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1012 | public Package parsePackage(File packageFile, int flags, boolean useCaches) |
| 1013 | throws PackageParserException { |
| 1014 | Package parsed = useCaches ? getCachedResult(packageFile, flags) : null; |
| 1015 | if (parsed != null) { |
| 1016 | return parsed; |
| 1017 | } |
| 1018 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1019 | long parseTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1020 | if (packageFile.isDirectory()) { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1021 | parsed = parseClusterPackage(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1022 | } else { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1023 | parsed = parseMonolithicPackage(packageFile, flags); |
| 1024 | } |
| 1025 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1026 | long cacheTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1027 | cacheResult(packageFile, flags, parsed); |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1028 | if (LOG_PARSE_TIMINGS) { |
| 1029 | parseTime = cacheTime - parseTime; |
| 1030 | cacheTime = SystemClock.uptimeMillis() - cacheTime; |
| 1031 | if (parseTime + cacheTime > LOG_PARSE_TIMINGS_THRESHOLD_MS) { |
| 1032 | Slog.i(TAG, "Parse times for '" + packageFile + "': parse=" + parseTime |
| 1033 | + "ms, update_cache=" + cacheTime + " ms"); |
| 1034 | } |
| 1035 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1036 | return parsed; |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Equivalent to {@link #parsePackage(File, int, boolean)} with {@code useCaches == false}. |
| 1041 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1042 | @UnsupportedAppUsage |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1043 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 1044 | return parsePackage(packageFile, flags, false /* useCaches */); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Returns the cache key for a specificied {@code packageFile} and {@code flags}. |
| 1049 | */ |
| 1050 | private String getCacheKey(File packageFile, int flags) { |
| 1051 | StringBuilder sb = new StringBuilder(packageFile.getName()); |
| 1052 | sb.append('-'); |
| 1053 | sb.append(flags); |
| 1054 | |
| 1055 | return sb.toString(); |
| 1056 | } |
| 1057 | |
| 1058 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1059 | protected Package fromCacheEntry(byte[] bytes) { |
| 1060 | return fromCacheEntryStatic(bytes); |
| 1061 | } |
| 1062 | |
| 1063 | /** static version of {@link #fromCacheEntry} for unit tests. */ |
| 1064 | @VisibleForTesting |
| 1065 | public static Package fromCacheEntryStatic(byte[] bytes) { |
| 1066 | final Parcel p = Parcel.obtain(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1067 | p.unmarshall(bytes, 0, bytes.length); |
| 1068 | p.setDataPosition(0); |
| 1069 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1070 | final ReadHelper helper = new ReadHelper(p); |
| 1071 | helper.startAndInstall(); |
| 1072 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1073 | PackageParser.Package pkg = new PackageParser.Package(p); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1074 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1075 | p.recycle(); |
| 1076 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1077 | sCachedPackageReadCount.incrementAndGet(); |
| 1078 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1079 | return pkg; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1083 | protected byte[] toCacheEntry(Package pkg) { |
| 1084 | return toCacheEntryStatic(pkg); |
| 1085 | |
| 1086 | } |
| 1087 | |
| 1088 | /** static version of {@link #toCacheEntry} for unit tests. */ |
| 1089 | @VisibleForTesting |
| 1090 | public static byte[] toCacheEntryStatic(Package pkg) { |
| 1091 | final Parcel p = Parcel.obtain(); |
| 1092 | final WriteHelper helper = new WriteHelper(p); |
| 1093 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1094 | pkg.writeToParcel(p, 0 /* flags */); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1095 | |
| 1096 | helper.finishAndUninstall(); |
| 1097 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1098 | byte[] serialized = p.marshall(); |
| 1099 | p.recycle(); |
| 1100 | |
| 1101 | return serialized; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * Given a {@code packageFile} and a {@code cacheFile} returns whether the |
| 1106 | * cache file is up to date based on the mod-time of both files. |
| 1107 | */ |
| 1108 | private static boolean isCacheUpToDate(File packageFile, File cacheFile) { |
| 1109 | try { |
| 1110 | // NOTE: We don't use the File.lastModified API because it has the very |
| 1111 | // non-ideal failure mode of returning 0 with no excepions thrown. |
| 1112 | // The nio2 Files API is a little better but is considerably more expensive. |
| 1113 | final StructStat pkg = android.system.Os.stat(packageFile.getAbsolutePath()); |
| 1114 | final StructStat cache = android.system.Os.stat(cacheFile.getAbsolutePath()); |
| 1115 | return pkg.st_mtime < cache.st_mtime; |
| 1116 | } catch (ErrnoException ee) { |
| 1117 | // The most common reason why stat fails is that a given cache file doesn't |
| 1118 | // exist. We ignore that here. It's easy to reason that it's safe to say the |
| 1119 | // cache isn't up to date if we see any sort of exception here. |
| 1120 | // |
| 1121 | // (1) Exception while stating the package file : This should never happen, |
| 1122 | // and if it does, we do a full package parse (which is likely to throw the |
| 1123 | // same exception). |
| 1124 | // (2) Exception while stating the cache file : If the file doesn't exist, the |
| 1125 | // cache is obviously out of date. If the file *does* exist, we can't read it. |
| 1126 | // We will attempt to delete and recreate it after parsing the package. |
| 1127 | if (ee.errno != OsConstants.ENOENT) { |
| 1128 | Slog.w("Error while stating package cache : ", ee); |
| 1129 | } |
| 1130 | |
| 1131 | return false; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * Returns the cached parse result for {@code packageFile} for parse flags {@code flags}, |
| 1137 | * or {@code null} if no cached result exists. |
| 1138 | */ |
| 1139 | private Package getCachedResult(File packageFile, int flags) { |
| 1140 | if (mCacheDir == null) { |
| 1141 | return null; |
| 1142 | } |
| 1143 | |
| 1144 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1145 | final File cacheFile = new File(mCacheDir, cacheKey); |
| 1146 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1147 | try { |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1148 | // If the cache is not up to date, return null. |
| 1149 | if (!isCacheUpToDate(packageFile, cacheFile)) { |
| 1150 | return null; |
| 1151 | } |
| 1152 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1153 | final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath()); |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1154 | Package p = fromCacheEntry(bytes); |
| 1155 | if (mCallback != null) { |
| 1156 | String[] overlayApks = mCallback.getOverlayApks(p.packageName); |
| 1157 | if (overlayApks != null && overlayApks.length > 0) { |
| 1158 | for (String overlayApk : overlayApks) { |
| 1159 | // If a static RRO is updated, return null. |
| 1160 | if (!isCacheUpToDate(new File(overlayApk), cacheFile)) { |
| 1161 | return null; |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | return p; |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1167 | } catch (Throwable e) { |
Narayan Kamath | 21a2838 | 2017-01-13 10:34:29 +0000 | [diff] [blame] | 1168 | Slog.w(TAG, "Error reading package cache: ", e); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1169 | |
| 1170 | // If something went wrong while reading the cache entry, delete the cache file |
| 1171 | // so that we regenerate it the next time. |
| 1172 | cacheFile.delete(); |
| 1173 | return null; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * Caches the parse result for {@code packageFile} with flags {@code flags}. |
| 1179 | */ |
| 1180 | private void cacheResult(File packageFile, int flags, Package parsed) { |
| 1181 | if (mCacheDir == null) { |
| 1182 | return; |
| 1183 | } |
| 1184 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1185 | try { |
| 1186 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1187 | final File cacheFile = new File(mCacheDir, cacheKey); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1188 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1189 | if (cacheFile.exists()) { |
| 1190 | if (!cacheFile.delete()) { |
| 1191 | Slog.e(TAG, "Unable to delete cache file: " + cacheFile); |
| 1192 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1193 | } |
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 | final byte[] cacheEntry = toCacheEntry(parsed); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1196 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1197 | if (cacheEntry == null) { |
| 1198 | return; |
| 1199 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1200 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1201 | try (FileOutputStream fos = new FileOutputStream(cacheFile)) { |
| 1202 | fos.write(cacheEntry); |
| 1203 | } catch (IOException ioe) { |
| 1204 | Slog.w(TAG, "Error writing cache entry.", ioe); |
| 1205 | cacheFile.delete(); |
| 1206 | } |
| 1207 | } catch (Throwable e) { |
| 1208 | Slog.w(TAG, "Error saving package cache.", e); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Parse all APKs contained in the given directory, treating them as a |
| 1214 | * single package. This also performs sanity checking, such as requiring |
| 1215 | * identical package name and version codes, a single base APK, and unique |
| 1216 | * split names. |
| 1217 | * <p> |
| 1218 | * Note that this <em>does not</em> perform signature verification; that |
| 1219 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1220 | */ |
| 1221 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1222 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1223 | if (mOnlyCoreApps && !lite.coreApp) { |
| 1224 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1225 | "Not a coreApp: " + packageDir); |
| 1226 | } |
| 1227 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1228 | // Build the split dependency tree. |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1229 | SparseArray<int[]> splitDependencies = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1230 | final SplitAssetLoader assetLoader; |
| 1231 | if (lite.isolatedSplits && !ArrayUtils.isEmpty(lite.splitNames)) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1232 | try { |
| 1233 | splitDependencies = SplitAssetDependencyLoader.createDependenciesFromPackage(lite); |
| 1234 | assetLoader = new SplitAssetDependencyLoader(lite, splitDependencies, flags); |
| 1235 | } catch (SplitAssetDependencyLoader.IllegalDependencyException e) { |
| 1236 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, e.getMessage()); |
| 1237 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1238 | } else { |
| 1239 | assetLoader = new DefaultSplitAssetLoader(lite, flags); |
| 1240 | } |
| 1241 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1242 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1243 | final AssetManager assets = assetLoader.getBaseAssetManager(); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1244 | final File baseApk = new File(lite.baseCodePath); |
| 1245 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 1246 | if (pkg == null) { |
| 1247 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1248 | "Failed to parse base APK: " + baseApk); |
| 1249 | } |
| 1250 | |
| 1251 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 1252 | final int num = lite.splitNames.length; |
| 1253 | pkg.splitNames = lite.splitNames; |
| 1254 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1255 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1256 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1257 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1258 | pkg.applicationInfo.splitNames = pkg.splitNames; |
| 1259 | pkg.applicationInfo.splitDependencies = splitDependencies; |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 1260 | pkg.applicationInfo.splitClassLoaderNames = new String[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1261 | |
| 1262 | for (int i = 0; i < num; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1263 | final AssetManager splitAssets = assetLoader.getSplitAssetManager(i); |
| 1264 | parseSplitApk(pkg, i, splitAssets, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1268 | pkg.setCodePath(packageDir.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1269 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1270 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1271 | } catch (IOException e) { |
| 1272 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1273 | "Failed to get path: " + lite.baseCodePath, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1274 | } finally { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1275 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | } |
| 1278 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1279 | /** |
| 1280 | * Parse the given APK file, treating it as as a single monolithic package. |
| 1281 | * <p> |
| 1282 | * Note that this <em>does not</em> perform signature verification; that |
| 1283 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1284 | * |
| 1285 | * @deprecated external callers should move to |
| 1286 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 1287 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1288 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1289 | @Deprecated |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1290 | @UnsupportedAppUsage |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1291 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1292 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1293 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1294 | if (!lite.coreApp) { |
| 1295 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1296 | "Not a coreApp: " + apkFile); |
| 1297 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1298 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1299 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1300 | final SplitAssetLoader assetLoader = new DefaultSplitAssetLoader(lite, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1301 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1302 | final Package pkg = parseBaseApk(apkFile, assetLoader.getBaseAssetManager(), flags); |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1303 | pkg.setCodePath(apkFile.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1304 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1305 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1306 | } catch (IOException e) { |
| 1307 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1308 | "Failed to get path: " + apkFile, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1309 | } finally { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1310 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1311 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1314 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 1315 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1316 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1317 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1318 | String volumeUuid = null; |
| 1319 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 1320 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 1321 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 1322 | } |
| 1323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1325 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1326 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1327 | 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] | 1328 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1329 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1331 | final int cookie = assets.findCookieForPath(apkPath); |
| 1332 | if (cookie == 0) { |
| 1333 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1334 | "Failed adding asset path: " + apkPath); |
| 1335 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1336 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1337 | final Resources res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1338 | |
| 1339 | final String[] outError = new String[1]; |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1340 | final Package pkg = parseBaseApk(apkPath, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1341 | if (pkg == null) { |
| 1342 | throw new PackageParserException(mParseError, |
| 1343 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1345 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1346 | pkg.setVolumeUuid(volumeUuid); |
| 1347 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 1348 | pkg.setBaseCodePath(apkPath); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1349 | pkg.setSigningDetails(SigningDetails.UNKNOWN); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1350 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1351 | return pkg; |
| 1352 | |
| 1353 | } catch (PackageParserException e) { |
| 1354 | throw e; |
| 1355 | } catch (Exception e) { |
| 1356 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1357 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1358 | } finally { |
| 1359 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1363 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1364 | throws PackageParserException { |
| 1365 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1366 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1367 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 1368 | mArchiveSourcePath = apkPath; |
| 1369 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1370 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 1371 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1372 | final Resources res; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1373 | XmlResourceParser parser = null; |
| 1374 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1375 | // This must always succeed, as the path has been added to the AssetManager before. |
| 1376 | final int cookie = assets.findCookieForPath(apkPath); |
| 1377 | if (cookie == 0) { |
| 1378 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1379 | "Failed adding asset path: " + apkPath); |
| 1380 | } |
| 1381 | |
Adam Lesinski | 56c82be | 2018-02-09 11:02:04 -0800 | [diff] [blame] | 1382 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1383 | res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1384 | |
| 1385 | final String[] outError = new String[1]; |
| 1386 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 1387 | if (pkg == null) { |
| 1388 | throw new PackageParserException(mParseError, |
| 1389 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 1390 | } |
| 1391 | |
| 1392 | } catch (PackageParserException e) { |
| 1393 | throw e; |
| 1394 | } catch (Exception e) { |
| 1395 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1396 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1397 | } finally { |
| 1398 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | /** |
| 1403 | * Parse the manifest of a <em>split APK</em>. |
| 1404 | * <p> |
| 1405 | * Note that split APKs have many more restrictions on what they're capable |
| 1406 | * of doing, so many valid features of a base APK have been carefully |
| 1407 | * omitted here. |
| 1408 | */ |
| 1409 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1410 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1411 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1412 | AttributeSet attrs = parser; |
| 1413 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1414 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1415 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1416 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1417 | mParseInstrumentationArgs = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1418 | |
| 1419 | int type; |
| 1420 | |
| 1421 | boolean foundApp = false; |
| 1422 | |
| 1423 | int outerDepth = parser.getDepth(); |
| 1424 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1425 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1426 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1427 | continue; |
| 1428 | } |
| 1429 | |
| 1430 | String tagName = parser.getName(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1431 | if (tagName.equals(TAG_APPLICATION)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1432 | if (foundApp) { |
| 1433 | if (RIGID_PARSER) { |
| 1434 | outError[0] = "<manifest> has more than one <application>"; |
| 1435 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1436 | return null; |
| 1437 | } else { |
| 1438 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1439 | XmlUtils.skipCurrentTag(parser); |
| 1440 | continue; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1445 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1446 | return null; |
| 1447 | } |
| 1448 | |
| 1449 | } else if (RIGID_PARSER) { |
| 1450 | outError[0] = "Bad element under <manifest>: " |
| 1451 | + parser.getName(); |
| 1452 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1453 | return null; |
| 1454 | |
| 1455 | } else { |
| 1456 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1457 | + " at " + mArchiveSourcePath + " " |
| 1458 | + parser.getPositionDescription()); |
| 1459 | XmlUtils.skipCurrentTag(parser); |
| 1460 | continue; |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | if (!foundApp) { |
| 1465 | outError[0] = "<manifest> does not contain an <application>"; |
| 1466 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1467 | } |
| 1468 | |
| 1469 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1472 | /** Parses the public keys from the set of signatures. */ |
| 1473 | public static ArraySet<PublicKey> toSigningKeys(Signature[] signatures) |
| 1474 | throws CertificateException { |
| 1475 | ArraySet<PublicKey> keys = new ArraySet<>(signatures.length); |
| 1476 | for (int i = 0; i < signatures.length; i++) { |
| 1477 | keys.add(signatures[i].getPublicKey()); |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1478 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1479 | return keys; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1483 | * Collect certificates from all the APKs described in the given package, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1484 | * populating {@link Package#mSigningDetails}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1485 | * contents are signed correctly and consistently. |
| 1486 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1487 | @UnsupportedAppUsage |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1488 | public static void collectCertificates(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1489 | throws PackageParserException { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1490 | collectCertificatesInternal(pkg, skipVerify); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1491 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1492 | for (int i = 0; i < childCount; i++) { |
| 1493 | Package childPkg = pkg.childPackages.get(i); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1494 | childPkg.mSigningDetails = pkg.mSigningDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1498 | private static void collectCertificatesInternal(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1499 | throws PackageParserException { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1500 | pkg.mSigningDetails = SigningDetails.UNKNOWN; |
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 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1503 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1504 | collectCertificates(pkg, new File(pkg.baseCodePath), skipVerify); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1505 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1506 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
| 1507 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1508 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1509 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1510 | } |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1511 | } finally { |
| 1512 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1516 | @UnsupportedAppUsage |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1517 | private static void collectCertificates(Package pkg, File apkFile, boolean skipVerify) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1518 | throws PackageParserException { |
| 1519 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1521 | int minSignatureScheme = SigningDetails.SignatureSchemeVersion.JAR; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1522 | if (pkg.applicationInfo.isStaticSharedLibrary()) { |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1523 | // must use v2 signing scheme |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1524 | minSignatureScheme = SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1525 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1526 | SigningDetails verified; |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1527 | if (skipVerify) { |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1528 | // systemDir APKs are already trusted, save time by not verifying |
Gavin Corkery | ed521ab | 2019-01-31 16:59:41 +0000 | [diff] [blame] | 1529 | verified = ApkSignatureVerifier.unsafeGetCertsWithoutVerification( |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1530 | apkPath, minSignatureScheme); |
| 1531 | } else { |
| 1532 | verified = ApkSignatureVerifier.verify(apkPath, minSignatureScheme); |
| 1533 | } |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1534 | |
| 1535 | // Verify that entries are signed consistently with the first pkg |
| 1536 | // we encountered. Note that for splits, certificates may have |
| 1537 | // already been populated during an earlier parse of a base APK. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1538 | if (pkg.mSigningDetails == SigningDetails.UNKNOWN) { |
| 1539 | pkg.mSigningDetails = verified; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1540 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1541 | if (!Signature.areExactMatch(pkg.mSigningDetails.signatures, verified.signatures)) { |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1542 | throw new PackageParserException( |
| 1543 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1544 | apkPath + " has mismatched certificates"); |
| 1545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | } |
| 1548 | |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1549 | private static AssetManager newConfiguredAssetManager() { |
| 1550 | AssetManager assetManager = new AssetManager(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 1551 | 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] | 1552 | Build.VERSION.RESOURCES_SDK_INT); |
| 1553 | return assetManager; |
| 1554 | } |
| 1555 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1556 | /** |
| 1557 | * Utility method that retrieves lightweight details about a single APK |
| 1558 | * file, including package name, split name, and install location. |
| 1559 | * |
| 1560 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1561 | * @param flags optional parse flags, such as |
| 1562 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1563 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1564 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1565 | throws PackageParserException { |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 1566 | return parseApkLiteInner(apkFile, null, null, flags); |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Utility method that retrieves lightweight details about a single APK |
| 1571 | * file, including package name, split name, and install location. |
| 1572 | * |
| 1573 | * @param fd already open file descriptor of an apk file |
| 1574 | * @param debugPathName arbitrary text name for this file, for debug output |
| 1575 | * @param flags optional parse flags, such as |
| 1576 | * {@link #PARSE_COLLECT_CERTIFICATES} |
| 1577 | */ |
| 1578 | public static ApkLite parseApkLite(FileDescriptor fd, String debugPathName, int flags) |
| 1579 | throws PackageParserException { |
| 1580 | return parseApkLiteInner(null, fd, debugPathName, flags); |
| 1581 | } |
| 1582 | |
| 1583 | private static ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd, String debugPathName, |
| 1584 | int flags) throws PackageParserException { |
| 1585 | final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1586 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1587 | XmlResourceParser parser = null; |
Winson | 7a3d82a | 2019-03-07 12:54:24 -0800 | [diff] [blame] | 1588 | ApkAssets apkAssets = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1590 | try { |
| 1591 | apkAssets = fd != null |
| 1592 | ? ApkAssets.loadFromFd(fd, debugPathName, false, false) |
| 1593 | : ApkAssets.loadFromPath(apkPath); |
| 1594 | } catch (IOException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1595 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1596 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1599 | parser = apkAssets.openXml(ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1600 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1601 | final SigningDetails signingDetails; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1602 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1603 | // TODO: factor signature related items out of Package object |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1604 | final Package tempPkg = new Package((String) null); |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1605 | final boolean skipVerify = (flags & PARSE_IS_SYSTEM_DIR) != 0; |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1606 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1607 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1608 | collectCertificates(tempPkg, apkFile, skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1609 | } finally { |
| 1610 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1611 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1612 | signingDetails = tempPkg.mSigningDetails; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1613 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1614 | signingDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1615 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1616 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1617 | final AttributeSet attrs = parser; |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1618 | return parseApkLite(apkPath, parser, attrs, signingDetails); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1619 | |
| 1620 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 1621 | Slog.w(TAG, "Failed to parse " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1622 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1623 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1625 | IoUtils.closeQuietly(parser); |
Winson | 7a3d82a | 2019-03-07 12:54:24 -0800 | [diff] [blame] | 1626 | if (apkAssets != null) { |
| 1627 | try { |
| 1628 | apkAssets.close(); |
| 1629 | } catch (Throwable ignored) { |
| 1630 | } |
| 1631 | } |
| 1632 | // TODO(b/72056911): Implement AutoCloseable on ApkAssets. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | } |
| 1635 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1636 | private static String validateName(String name, boolean requireSeparator, |
| 1637 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | final int N = name.length(); |
| 1639 | boolean hasSep = false; |
| 1640 | boolean front = true; |
| 1641 | for (int i=0; i<N; i++) { |
| 1642 | final char c = name.charAt(i); |
| 1643 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1644 | front = false; |
| 1645 | continue; |
| 1646 | } |
| 1647 | if (!front) { |
| 1648 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1649 | continue; |
| 1650 | } |
| 1651 | } |
| 1652 | if (c == '.') { |
| 1653 | hasSep = true; |
| 1654 | front = true; |
| 1655 | continue; |
| 1656 | } |
| 1657 | return "bad character '" + c + "'"; |
| 1658 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1659 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1660 | return "Invalid filename"; |
| 1661 | } |
| 1662 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | ? null : "must have at least one '.' separator"; |
| 1664 | } |
| 1665 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1666 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1667 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1668 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | |
| 1670 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1671 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1672 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1675 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1676 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1677 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1679 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1680 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1681 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | } |
| 1683 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1684 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1685 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1686 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1687 | if (error != null) { |
| 1688 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1689 | "Invalid manifest package: " + error); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1693 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1694 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1695 | if (splitName.length() == 0) { |
| 1696 | splitName = null; |
| 1697 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1698 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1699 | if (error != null) { |
| 1700 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1701 | "Invalid manifest split: " + error); |
| 1702 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | return Pair.create(packageName.intern(), |
| 1707 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1710 | private static ApkLite parseApkLite(String codePath, XmlPullParser parser, AttributeSet attrs, |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1711 | SigningDetails signingDetails) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1712 | throws IOException, XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1713 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1714 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1715 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1716 | int versionCode = 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1717 | int versionCodeMajor = 0; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1718 | int targetSdkVersion = DEFAULT_TARGET_SDK_VERSION; |
| 1719 | int minSdkVersion = DEFAULT_MIN_SDK_VERSION; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1720 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1721 | boolean coreApp = false; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1722 | boolean debuggable = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1723 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1724 | boolean use32bitAbi = false; |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1725 | boolean extractNativeLibs = true; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1726 | boolean isolatedSplits = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1727 | boolean isFeatureSplit = false; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1728 | boolean isSplitRequired = false; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 1729 | boolean useEmbeddedDex = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1730 | String configForSplit = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1731 | String usesSplitName = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1732 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1733 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1734 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1735 | if (attr.equals("installLocation")) { |
| 1736 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1737 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1738 | } else if (attr.equals("versionCode")) { |
| 1739 | versionCode = attrs.getAttributeIntValue(i, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1740 | } else if (attr.equals("versionCodeMajor")) { |
| 1741 | versionCodeMajor = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1742 | } else if (attr.equals("revisionCode")) { |
| 1743 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1744 | } else if (attr.equals("coreApp")) { |
| 1745 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1746 | } else if (attr.equals("isolatedSplits")) { |
| 1747 | isolatedSplits = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1748 | } else if (attr.equals("configForSplit")) { |
| 1749 | configForSplit = attrs.getAttributeValue(i); |
| 1750 | } else if (attr.equals("isFeatureSplit")) { |
| 1751 | isFeatureSplit = attrs.getAttributeBooleanValue(i, false); |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1752 | } else if (attr.equals("isSplitRequired")) { |
| 1753 | isSplitRequired = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1754 | } |
| 1755 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1756 | |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1757 | // Only search the tree when the tag is the direct child of <manifest> tag |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1758 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1759 | final int searchDepth = parser.getDepth() + 1; |
| 1760 | |
| 1761 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1762 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1763 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1764 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1765 | continue; |
| 1766 | } |
| 1767 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1768 | if (parser.getDepth() != searchDepth) { |
| 1769 | continue; |
| 1770 | } |
| 1771 | |
| 1772 | if (TAG_PACKAGE_VERIFIER.equals(parser.getName())) { |
| 1773 | final VerifierInfo verifier = parseVerifier(attrs); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1774 | if (verifier != null) { |
| 1775 | verifiers.add(verifier); |
| 1776 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1777 | } else if (TAG_APPLICATION.equals(parser.getName())) { |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1778 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1779 | final String attr = attrs.getAttributeName(i); |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1780 | if ("debuggable".equals(attr)) { |
| 1781 | debuggable = attrs.getAttributeBooleanValue(i, false); |
| 1782 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1783 | if ("multiArch".equals(attr)) { |
| 1784 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1785 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1786 | if ("use32bitAbi".equals(attr)) { |
| 1787 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1788 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1789 | if ("extractNativeLibs".equals(attr)) { |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1790 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1791 | } |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 1792 | if ("useEmbeddedDex".equals(attr)) { |
| 1793 | useEmbeddedDex = attrs.getAttributeBooleanValue(i, false); |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 1794 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1795 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1796 | } else if (TAG_USES_SPLIT.equals(parser.getName())) { |
| 1797 | if (usesSplitName != null) { |
| 1798 | Slog.w(TAG, "Only one <uses-split> permitted. Ignoring others."); |
| 1799 | continue; |
| 1800 | } |
| 1801 | |
| 1802 | usesSplitName = attrs.getAttributeValue(ANDROID_RESOURCES, "name"); |
| 1803 | if (usesSplitName == null) { |
| 1804 | throw new PackageParserException( |
| 1805 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1806 | "<uses-split> tag requires 'android:name' attribute"); |
| 1807 | } |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1808 | } else if (TAG_USES_SDK.equals(parser.getName())) { |
| 1809 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1810 | final String attr = attrs.getAttributeName(i); |
| 1811 | if ("targetSdkVersion".equals(attr)) { |
| 1812 | targetSdkVersion = attrs.getAttributeIntValue(i, |
| 1813 | DEFAULT_TARGET_SDK_VERSION); |
| 1814 | } |
| 1815 | if ("minSdkVersion".equals(attr)) { |
| 1816 | minSdkVersion = attrs.getAttributeIntValue(i, DEFAULT_MIN_SDK_VERSION); |
| 1817 | } |
| 1818 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1819 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1822 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, isFeatureSplit, |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1823 | configForSplit, usesSplitName, isSplitRequired, versionCode, versionCodeMajor, |
| 1824 | revisionCode, installLocation, verifiers, signingDetails, coreApp, debuggable, |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1825 | multiArch, use32bitAbi, useEmbeddedDex, extractNativeLibs, isolatedSplits, |
| 1826 | minSdkVersion, targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1829 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1830 | * Parses a child package and adds it to the parent if successful. If you add |
| 1831 | * new tags that need to be supported by child packages make sure to add them |
| 1832 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1833 | * |
| 1834 | * @param parentPkg The parent that contains the child |
| 1835 | * @param res Resources against which to resolve values |
| 1836 | * @param parser Parser of the manifest |
| 1837 | * @param flags Flags about how to parse |
| 1838 | * @param outError Human readable error if parsing fails |
| 1839 | * @return True of parsing succeeded. |
| 1840 | * |
| 1841 | * @throws XmlPullParserException |
| 1842 | * @throws IOException |
| 1843 | */ |
| 1844 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1845 | int flags, String[] outError) throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1846 | // Make sure we have a valid child package name |
| 1847 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1848 | if (validateName(childPackageName, true, false) != null) { |
| 1849 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1850 | return false; |
| 1851 | } |
| 1852 | |
| 1853 | // Child packages must be unique |
| 1854 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1855 | String message = "Child package name cannot be equal to parent package name: " |
| 1856 | + parentPkg.packageName; |
| 1857 | Slog.w(TAG, message); |
| 1858 | outError[0] = message; |
| 1859 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1860 | return false; |
| 1861 | } |
| 1862 | |
| 1863 | // Child packages must be unique |
| 1864 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1865 | String message = "Duplicate child package:" + childPackageName; |
| 1866 | Slog.w(TAG, message); |
| 1867 | outError[0] = message; |
| 1868 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | // Go ahead and parse the child |
| 1873 | Package childPkg = new Package(childPackageName); |
| 1874 | |
| 1875 | // Child package inherits parent version code/name/target SDK |
| 1876 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1877 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1878 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1879 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1880 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1881 | |
| 1882 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1883 | if (childPkg == null) { |
| 1884 | // If we got null then error was set during child parsing |
| 1885 | return false; |
| 1886 | } |
| 1887 | |
| 1888 | // Set the parent-child relation |
| 1889 | if (parentPkg.childPackages == null) { |
| 1890 | parentPkg.childPackages = new ArrayList<>(); |
| 1891 | } |
| 1892 | parentPkg.childPackages.add(childPkg); |
| 1893 | childPkg.parentPackage = parentPkg; |
| 1894 | |
| 1895 | return true; |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1900 | * need to consider whether they should be supported by split APKs and child |
| 1901 | * packages. |
| 1902 | * |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1903 | * @param apkPath The package apk file path |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1904 | * @param res The resources from which to resolve values |
| 1905 | * @param parser The manifest parser |
| 1906 | * @param flags Flags how to parse |
| 1907 | * @param outError Human readable error message |
| 1908 | * @return Parsed package or null on error. |
| 1909 | * |
| 1910 | * @throws XmlPullParserException |
| 1911 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1912 | */ |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1913 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1914 | private Package parseBaseApk(String apkPath, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1915 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1916 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1917 | final String pkgName; |
| 1918 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1919 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1920 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1921 | pkgName = packageSplit.first; |
| 1922 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1923 | |
| 1924 | if (!TextUtils.isEmpty(splitName)) { |
| 1925 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1926 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1927 | return null; |
| 1928 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1929 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1931 | return null; |
| 1932 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1933 | |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1934 | if (mCallback != null) { |
| 1935 | String[] overlayPaths = mCallback.getOverlayPaths(pkgName, apkPath); |
| 1936 | if (overlayPaths != null && overlayPaths.length > 0) { |
| 1937 | for (String overlayPath : overlayPaths) { |
| 1938 | res.getAssets().addOverlayPath(overlayPath); |
| 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1943 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1944 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1945 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1947 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1948 | pkg.mVersionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1950 | pkg.mVersionCodeMajor = sa.getInteger( |
| 1951 | com.android.internal.R.styleable.AndroidManifest_versionCodeMajor, 0); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1952 | pkg.applicationInfo.setVersionCode(pkg.getLongVersionCode()); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1953 | pkg.baseRevisionCode = sa.getInteger( |
| 1954 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1955 | pkg.mVersionName = sa.getNonConfigurationString( |
| 1956 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | if (pkg.mVersionName != null) { |
| 1958 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 1959 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1960 | |
| 1961 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 1962 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1963 | pkg.mCompileSdkVersion = sa.getInteger( |
| 1964 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersion, 0); |
| 1965 | pkg.applicationInfo.compileSdkVersion = pkg.mCompileSdkVersion; |
| 1966 | pkg.mCompileSdkVersionCodename = sa.getNonConfigurationString( |
| 1967 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersionCodename, 0); |
| 1968 | if (pkg.mCompileSdkVersionCodename != null) { |
| 1969 | pkg.mCompileSdkVersionCodename = pkg.mCompileSdkVersionCodename.intern(); |
| 1970 | } |
| 1971 | pkg.applicationInfo.compileSdkVersionCodename = pkg.mCompileSdkVersionCodename; |
| 1972 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1973 | sa.recycle(); |
| 1974 | |
| 1975 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * This is the common parsing routing for handling parent and child |
| 1980 | * packages in a base APK. The difference between parent and child |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1981 | * parsing is that some tags are not supported by child packages as |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1982 | * well as some manifest attributes are ignored. The implementation |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1983 | * assumes the calling code has already handled the manifest tag if needed |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1984 | * (this applies to the parent only). |
| 1985 | * |
| 1986 | * @param pkg The package which to populate |
| 1987 | * @param acceptedTags Which tags to handle, null to handle all |
| 1988 | * @param res Resources against which to resolve values |
| 1989 | * @param parser Parser of the manifest |
| 1990 | * @param flags Flags about how to parse |
| 1991 | * @param outError Human readable error if parsing fails |
| 1992 | * @return The package if parsing succeeded or null. |
| 1993 | * |
| 1994 | * @throws XmlPullParserException |
| 1995 | * @throws IOException |
| 1996 | */ |
| 1997 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 1998 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 1999 | IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2000 | mParseInstrumentationArgs = null; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2001 | |
| 2002 | int type; |
| 2003 | boolean foundApp = false; |
| 2004 | |
| 2005 | TypedArray sa = res.obtainAttributes(parser, |
| 2006 | com.android.internal.R.styleable.AndroidManifest); |
| 2007 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2008 | String str = sa.getNonConfigurationString( |
| 2009 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 2010 | if (str != null && str.length() > 0) { |
Sudheer Shanka | 9c5079a | 2018-08-03 12:41:10 -0700 | [diff] [blame] | 2011 | String nameError = validateName(str, true, true); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2012 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 2014 | + str + "\": " + nameError; |
| 2015 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 2016 | return null; |
| 2017 | } |
| 2018 | pkg.mSharedUserId = str.intern(); |
| 2019 | pkg.mSharedUserLabel = sa.getResourceId( |
| 2020 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 2021 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 2022 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 2023 | pkg.installLocation = sa.getInteger( |
| 2024 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 2025 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2026 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2027 | |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 2028 | final int targetSandboxVersion = sa.getInteger( |
| 2029 | com.android.internal.R.styleable.AndroidManifest_targetSandboxVersion, |
| 2030 | PARSE_DEFAULT_TARGET_SANDBOX); |
| 2031 | pkg.applicationInfo.targetSandboxVersion = targetSandboxVersion; |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 2032 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2033 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2034 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2035 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 2036 | } |
| 2037 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2038 | if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifest_isolatedSplits, false)) { |
| 2039 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING; |
| 2040 | } |
| 2041 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2042 | // Resource boolean are -1, so 1 means we don't know the value. |
| 2043 | int supportsSmallScreens = 1; |
| 2044 | int supportsNormalScreens = 1; |
| 2045 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2046 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2047 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2048 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2051 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2052 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2053 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | continue; |
| 2055 | } |
| 2056 | |
| 2057 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2058 | |
| 2059 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 2060 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 2061 | + tagName + " at " + mArchiveSourcePath + " " |
| 2062 | + parser.getPositionDescription()); |
| 2063 | XmlUtils.skipCurrentTag(parser); |
| 2064 | continue; |
| 2065 | } |
| 2066 | |
| 2067 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | if (foundApp) { |
| 2069 | if (RIGID_PARSER) { |
| 2070 | outError[0] = "<manifest> has more than one <application>"; |
| 2071 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2072 | return null; |
| 2073 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2074 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | XmlUtils.skipCurrentTag(parser); |
| 2076 | continue; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2081 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | return null; |
| 2083 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2084 | } else if (tagName.equals(TAG_OVERLAY)) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2085 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2086 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 2087 | pkg.mOverlayTarget = sa.getString( |
| 2088 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 2089 | pkg.mOverlayTargetName = sa.getString( |
| 2090 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetName); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 2091 | pkg.mOverlayCategory = sa.getString( |
| 2092 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_category); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2093 | pkg.mOverlayPriority = sa.getInt( |
| 2094 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 2095 | 0); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 2096 | pkg.mOverlayIsStatic = sa.getBoolean( |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2097 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_isStatic, |
| 2098 | false); |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2099 | final String propName = sa.getString( |
| 2100 | com.android.internal.R.styleable |
| 2101 | .AndroidManifestResourceOverlay_requiredSystemPropertyName); |
| 2102 | final String propValue = sa.getString( |
| 2103 | com.android.internal.R.styleable |
| 2104 | .AndroidManifestResourceOverlay_requiredSystemPropertyValue); |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2105 | sa.recycle(); |
| 2106 | |
| 2107 | if (pkg.mOverlayTarget == null) { |
| 2108 | outError[0] = "<overlay> does not specify a target package"; |
| 2109 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2110 | return null; |
| 2111 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2112 | |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2113 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 2114 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 2115 | mParseError = |
| 2116 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2117 | return null; |
| 2118 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2119 | |
| 2120 | // check to see if overlay should be excluded based on system property condition |
| 2121 | if (!checkOverlayRequiredSystemProperty(propName, propValue)) { |
| 2122 | Slog.i(TAG, "Skipping target and overlay pair " + pkg.mOverlayTarget + " and " |
| 2123 | + pkg.baseCodePath+ ": overlay ignored due to required system property: " |
| 2124 | + propName + " with value: " + propValue); |
| 2125 | return null; |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2126 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2127 | |
Zoran Jovanovic | 946e32f | 2019-02-17 22:02:40 +0100 | [diff] [blame] | 2128 | pkg.applicationInfo.privateFlags |= |
| 2129 | ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY; |
| 2130 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2131 | XmlUtils.skipCurrentTag(parser); |
| 2132 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2133 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 2134 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2135 | return null; |
| 2136 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2137 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2138 | if (!parsePermissionGroup(pkg, flags, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | return null; |
| 2140 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2141 | } else if (tagName.equals(TAG_PERMISSION)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2142 | if (!parsePermission(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | return null; |
| 2144 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2145 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2146 | if (!parsePermissionTree(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | return null; |
| 2148 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2149 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2150 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2151 | return null; |
| 2152 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2153 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 2154 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2155 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2156 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2158 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2160 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2161 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 2162 | cPref.reqTouchScreen = sa.getInt( |
| 2163 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 2164 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 2165 | cPref.reqKeyboardType = sa.getInt( |
| 2166 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 2167 | Configuration.KEYBOARD_UNDEFINED); |
| 2168 | if (sa.getBoolean( |
| 2169 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 2170 | false)) { |
| 2171 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 2172 | } |
| 2173 | cPref.reqNavigation = sa.getInt( |
| 2174 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 2175 | Configuration.NAVIGATION_UNDEFINED); |
| 2176 | if (sa.getBoolean( |
| 2177 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 2178 | false)) { |
| 2179 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 2180 | } |
| 2181 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2182 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | |
| 2184 | XmlUtils.skipCurrentTag(parser); |
| 2185 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2186 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 2187 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2188 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 2189 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2190 | if (fi.name == null) { |
| 2191 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 2192 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2193 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2194 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 2195 | |
| 2196 | XmlUtils.skipCurrentTag(parser); |
| 2197 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2198 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2199 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 2200 | ArrayList<FeatureInfo> features = null; |
| 2201 | final int innerDepth = parser.getDepth(); |
| 2202 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2203 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 2204 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2205 | continue; |
| 2206 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2207 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2208 | final String innerTagName = parser.getName(); |
| 2209 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2210 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2211 | // FeatureGroups are stricter and mandate that |
| 2212 | // any <uses-feature> declared are mandatory. |
| 2213 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2214 | features = ArrayUtils.add(features, featureInfo); |
| 2215 | } else { |
| 2216 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 2217 | " at " + mArchiveSourcePath + " " + |
| 2218 | parser.getPositionDescription()); |
| 2219 | } |
| 2220 | XmlUtils.skipCurrentTag(parser); |
| 2221 | } |
| 2222 | |
| 2223 | if (features != null) { |
| 2224 | group.features = new FeatureInfo[features.size()]; |
| 2225 | group.features = features.toArray(group.features); |
| 2226 | } |
| 2227 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2228 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2229 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 2230 | if (SDK_VERSION > 0) { |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2231 | sa = res.obtainAttributes(parser, |
| 2232 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2234 | int minVers = 1; |
| 2235 | String minCode = null; |
| 2236 | int targetVers = 0; |
| 2237 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2238 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2239 | TypedValue val = sa.peekValue( |
| 2240 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 2241 | if (val != null) { |
| 2242 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 2243 | minCode = val.string.toString(); |
| 2244 | } else { |
| 2245 | // If it's not a string, it's an integer. |
| 2246 | minVers = val.data; |
| 2247 | } |
| 2248 | } |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2249 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2250 | val = sa.peekValue( |
| 2251 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 2252 | if (val != null) { |
| 2253 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 2254 | targetCode = val.string.toString(); |
| 2255 | if (minCode == null) { |
| 2256 | minCode = targetCode; |
| 2257 | } |
| 2258 | } else { |
| 2259 | // If it's not a string, it's an integer. |
| 2260 | targetVers = val.data; |
| 2261 | } |
| 2262 | } else { |
| 2263 | targetVers = minVers; |
| 2264 | targetCode = minCode; |
| 2265 | } |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2266 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2267 | sa.recycle(); |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2268 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2269 | final int minSdkVersion = PackageParser.computeMinSdkVersion(minVers, minCode, |
| 2270 | SDK_VERSION, SDK_CODENAMES, outError); |
| 2271 | if (minSdkVersion < 0) { |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2272 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2273 | return null; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2274 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2275 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2276 | final int targetSdkVersion = PackageParser.computeTargetSdkVersion(targetVers, |
| 2277 | targetCode, SDK_CODENAMES, outError); |
| 2278 | if (targetSdkVersion < 0) { |
| 2279 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2280 | return null; |
| 2281 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2282 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2283 | pkg.applicationInfo.minSdkVersion = minSdkVersion; |
| 2284 | pkg.applicationInfo.targetSdkVersion = targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | } |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | XmlUtils.skipCurrentTag(parser); |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2288 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2289 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 2290 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2291 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 2292 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2293 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 2294 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 2295 | 0); |
| 2296 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 2297 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 2298 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 2299 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 2300 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 2301 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2302 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2303 | // This is a trick to get a boolean and still able to detect |
| 2304 | // if a value was actually set. |
| 2305 | supportsSmallScreens = sa.getInteger( |
| 2306 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 2307 | supportsSmallScreens); |
| 2308 | supportsNormalScreens = sa.getInteger( |
| 2309 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 2310 | supportsNormalScreens); |
| 2311 | supportsLargeScreens = sa.getInteger( |
| 2312 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 2313 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2314 | supportsXLargeScreens = sa.getInteger( |
| 2315 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 2316 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2317 | resizeable = sa.getInteger( |
| 2318 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2319 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2320 | anyDensity = sa.getInteger( |
| 2321 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 2322 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2323 | |
| 2324 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2325 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2326 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2327 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2328 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 2329 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2330 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 2331 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2332 | // Note: don't allow this value to be a reference to a resource |
| 2333 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2334 | String name = sa.getNonResourceString( |
| 2335 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 2336 | |
| 2337 | sa.recycle(); |
| 2338 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 2339 | if (name != null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2340 | if (pkg.protectedBroadcasts == null) { |
| 2341 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 2342 | } |
| 2343 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 2344 | pkg.protectedBroadcasts.add(name.intern()); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2349 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2350 | } else if (tagName.equals(TAG_INSTRUMENTATION)) { |
| 2351 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2352 | return null; |
| 2353 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2354 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2355 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2356 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2357 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2358 | String orig =sa.getNonConfigurationString( |
| 2359 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2360 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2361 | if (pkg.mOriginalPackages == null) { |
| 2362 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2363 | pkg.mRealPackage = pkg.packageName; |
| 2364 | } |
| 2365 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2366 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2367 | |
| 2368 | sa.recycle(); |
| 2369 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2370 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2371 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2372 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2373 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2374 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2375 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2376 | String name = sa.getNonConfigurationString( |
| 2377 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2378 | |
| 2379 | sa.recycle(); |
| 2380 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2381 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2382 | if (pkg.mAdoptPermissions == null) { |
| 2383 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2384 | } |
| 2385 | pkg.mAdoptPermissions.add(name); |
| 2386 | } |
| 2387 | |
| 2388 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2389 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2390 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2391 | // Just skip this tag |
| 2392 | XmlUtils.skipCurrentTag(parser); |
| 2393 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2394 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2395 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2396 | // Just skip this tag |
| 2397 | XmlUtils.skipCurrentTag(parser); |
| 2398 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2399 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2400 | XmlUtils.skipCurrentTag(parser); |
| 2401 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2402 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2403 | } else if (tagName.equals(TAG_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2404 | // Just skip this tag |
| 2405 | XmlUtils.skipCurrentTag(parser); |
| 2406 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2407 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2408 | } else if (tagName.equals(TAG_PACKAGE)) { |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame] | 2409 | if (!MULTI_PACKAGE_APK_ENABLED) { |
| 2410 | XmlUtils.skipCurrentTag(parser); |
| 2411 | continue; |
| 2412 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2413 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2414 | // If parsing a child failed the error is already set |
| 2415 | return null; |
| 2416 | } |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2417 | |
| 2418 | } else if (tagName.equals(TAG_RESTRICT_UPDATE)) { |
| 2419 | if ((flags & PARSE_IS_SYSTEM_DIR) != 0) { |
| 2420 | sa = res.obtainAttributes(parser, |
| 2421 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate); |
| 2422 | final String hash = sa.getNonConfigurationString( |
| 2423 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0); |
| 2424 | sa.recycle(); |
| 2425 | |
| 2426 | pkg.restrictUpdateHash = null; |
| 2427 | if (hash != null) { |
| 2428 | final int hashLength = hash.length(); |
| 2429 | final byte[] hashBytes = new byte[hashLength / 2]; |
| 2430 | for (int i = 0; i < hashLength; i += 2){ |
| 2431 | hashBytes[i/2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) |
| 2432 | + Character.digit(hash.charAt(i + 1), 16)); |
| 2433 | } |
| 2434 | pkg.restrictUpdateHash = hashBytes; |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | XmlUtils.skipCurrentTag(parser); |
| 2439 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2440 | } else if (RIGID_PARSER) { |
| 2441 | outError[0] = "Bad element under <manifest>: " |
| 2442 | + parser.getName(); |
| 2443 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2444 | return null; |
| 2445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2447 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2448 | + " at " + mArchiveSourcePath + " " |
| 2449 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | XmlUtils.skipCurrentTag(parser); |
| 2451 | continue; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2456 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2457 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2458 | } |
| 2459 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2460 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2461 | StringBuilder newPermsMsg = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2462 | for (int ip=0; ip<NP; ip++) { |
| 2463 | final PackageParser.NewPermissionInfo npi |
| 2464 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2465 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2466 | break; |
| 2467 | } |
| 2468 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2469 | if (newPermsMsg == null) { |
| 2470 | newPermsMsg = new StringBuilder(128); |
| 2471 | newPermsMsg.append(pkg.packageName); |
| 2472 | newPermsMsg.append(": compat added "); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2473 | } else { |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2474 | newPermsMsg.append(' '); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2475 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2476 | newPermsMsg.append(npi.name); |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2477 | pkg.requestedPermissions.add(npi.name); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2478 | pkg.implicitPermissions.add(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2479 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2480 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2481 | if (newPermsMsg != null) { |
| 2482 | Slog.i(TAG, newPermsMsg.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2483 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2484 | |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 2485 | |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2486 | final int NS = PermissionManager.SPLIT_PERMISSIONS.size(); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2487 | for (int is=0; is<NS; is++) { |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 2488 | final PermissionManager.SplitPermissionInfo spi = |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2489 | PermissionManager.SPLIT_PERMISSIONS.get(is); |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 2490 | if (pkg.applicationInfo.targetSdkVersion >= spi.getTargetSdk() |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2491 | || !pkg.requestedPermissions.contains(spi.getSplitPermission())) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2492 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2493 | } |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2494 | final List<String> newPerms = spi.getNewPermissions(); |
| 2495 | for (int in = 0; in < newPerms.size(); in++) { |
| 2496 | final String perm = newPerms.get(in); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2497 | if (!pkg.requestedPermissions.contains(perm)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2498 | pkg.requestedPermissions.add(perm); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2499 | pkg.implicitPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | } |
| 2503 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2504 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2505 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2506 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2507 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2508 | } |
| 2509 | if (supportsNormalScreens != 0) { |
| 2510 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2511 | } |
| 2512 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2513 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2514 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2515 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2516 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2517 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2518 | && pkg.applicationInfo.targetSdkVersion |
| 2519 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2520 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2521 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2522 | if (resizeable < 0 || (resizeable > 0 |
| 2523 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2524 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2525 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2526 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2527 | if (anyDensity < 0 || (anyDensity > 0 |
| 2528 | && pkg.applicationInfo.targetSdkVersion |
| 2529 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2530 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2531 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2532 | |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2533 | // At this point we can check if an application is not supporting densities and hence |
| 2534 | // cannot be windowed / resized. Note that an SDK version of 0 is common for |
| 2535 | // pre-Doughnut applications. |
| 2536 | if (pkg.applicationInfo.usesCompatibilityMode()) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2537 | adjustPackageToBeUnresizeableAndUnpipable(pkg); |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2538 | } |
Jeff Sharkey | 4aacd8b | 2018-07-24 15:24:21 -0600 | [diff] [blame] | 2539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | return pkg; |
| 2541 | } |
| 2542 | |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2543 | private boolean checkOverlayRequiredSystemProperty(String propName, String propValue) { |
| 2544 | |
| 2545 | if (TextUtils.isEmpty(propName) || TextUtils.isEmpty(propValue)) { |
| 2546 | if (!TextUtils.isEmpty(propName) || !TextUtils.isEmpty(propValue)) { |
| 2547 | // malformed condition - incomplete |
| 2548 | Slog.w(TAG, "Disabling overlay - incomplete property :'" + propName |
| 2549 | + "=" + propValue + "' - require both requiredSystemPropertyName" |
| 2550 | + " AND requiredSystemPropertyValue to be specified."); |
| 2551 | return false; |
| 2552 | } |
| 2553 | // no valid condition set - so no exclusion criteria, overlay will be included. |
| 2554 | return true; |
| 2555 | } |
| 2556 | |
| 2557 | // check property value - make sure it is both set and equal to expected value |
| 2558 | final String currValue = SystemProperties.get(propName); |
| 2559 | return (currValue != null && currValue.equals(propValue)); |
| 2560 | } |
| 2561 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2562 | /** |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2563 | * This is a pre-density application which will get scaled - instead of being pixel perfect. |
| 2564 | * This type of application is not resizable. |
| 2565 | * |
| 2566 | * @param pkg The package which needs to be marked as unresizable. |
| 2567 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2568 | private void adjustPackageToBeUnresizeableAndUnpipable(Package pkg) { |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2569 | for (Activity a : pkg.activities) { |
| 2570 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2571 | a.info.flags &= ~FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | /** |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 2576 | |
| 2577 | /** |
Narayan Kamath | 71fcc14 | 2019-01-15 18:20:39 +0000 | [diff] [blame] | 2578 | * Matches a given {@code targetCode} against a set of release codeNames. Target codes can |
| 2579 | * either be of the form {@code [codename]}" (e.g {@code "Q"}) or of the form |
| 2580 | * {@code [codename].[fingerprint]} (e.g {@code "Q.cafebc561"}). |
| 2581 | */ |
| 2582 | private static boolean matchTargetCode(@NonNull String[] codeNames, |
| 2583 | @NonNull String targetCode) { |
| 2584 | final String targetCodeName; |
| 2585 | final int targetCodeIdx = targetCode.indexOf('.'); |
| 2586 | if (targetCodeIdx == -1) { |
| 2587 | targetCodeName = targetCode; |
| 2588 | } else { |
| 2589 | targetCodeName = targetCode.substring(0, targetCodeIdx); |
| 2590 | } |
| 2591 | return ArrayUtils.contains(codeNames, targetCodeName); |
| 2592 | } |
| 2593 | |
| 2594 | /** |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2595 | * Computes the targetSdkVersion to use at runtime. If the package is not |
| 2596 | * compatible with this platform, populates {@code outError[0]} with an |
| 2597 | * error message. |
| 2598 | * <p> |
| 2599 | * If {@code targetCode} is not specified, e.g. the value is {@code null}, |
| 2600 | * then the {@code targetVers} will be returned unmodified. |
| 2601 | * <p> |
| 2602 | * Otherwise, the behavior varies based on whether the current platform |
| 2603 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2604 | * has length > 0: |
| 2605 | * <ul> |
| 2606 | * <li>If this is a pre-release platform and the value specified by |
| 2607 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2608 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2609 | * <li>If this is a released platform, this method will return -1 to |
| 2610 | * indicate that the package is not compatible with this platform. |
| 2611 | * </ul> |
| 2612 | * |
| 2613 | * @param targetVers targetSdkVersion number, if specified in the |
| 2614 | * application manifest, or 0 otherwise |
| 2615 | * @param targetCode targetSdkVersion code, if specified in the application |
| 2616 | * manifest, or {@code null} otherwise |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2617 | * @param platformSdkCodenames array of allowed pre-release SDK codenames |
| 2618 | * for this platform |
| 2619 | * @param outError output array to populate with error, if applicable |
| 2620 | * @return the targetSdkVersion to use at runtime, or -1 if the package is |
| 2621 | * not compatible with this platform |
| 2622 | * @hide Exposed for unit testing only. |
| 2623 | */ |
| 2624 | @TestApi |
| 2625 | public static int computeTargetSdkVersion(@IntRange(from = 0) int targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2626 | @Nullable String targetCode, @NonNull String[] platformSdkCodenames, |
Nicholas Lativy | eb23e4d | 2019-02-01 13:39:28 +0000 | [diff] [blame] | 2627 | @NonNull String[] outError) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2628 | // If it's a release SDK, return the version number unmodified. |
| 2629 | if (targetCode == null) { |
| 2630 | return targetVers; |
| 2631 | } |
| 2632 | |
| 2633 | // If it's a pre-release SDK and the codename matches this platform, it |
| 2634 | // definitely targets this SDK. |
Nicholas Lativy | eb23e4d | 2019-02-01 13:39:28 +0000 | [diff] [blame] | 2635 | if (matchTargetCode(platformSdkCodenames, targetCode)) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2636 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2637 | } |
| 2638 | |
| 2639 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2640 | if (platformSdkCodenames.length > 0) { |
| 2641 | outError[0] = "Requires development platform " + targetCode |
| 2642 | + " (current platform is any of " |
| 2643 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2644 | } else { |
| 2645 | outError[0] = "Requires development platform " + targetCode |
| 2646 | + " but this is a release platform."; |
| 2647 | } |
| 2648 | return -1; |
| 2649 | } |
| 2650 | |
| 2651 | /** |
| 2652 | * Computes the minSdkVersion to use at runtime. If the package is not |
| 2653 | * compatible with this platform, populates {@code outError[0]} with an |
| 2654 | * error message. |
| 2655 | * <p> |
| 2656 | * If {@code minCode} is not specified, e.g. the value is {@code null}, |
| 2657 | * then behavior varies based on the {@code platformSdkVersion}: |
| 2658 | * <ul> |
| 2659 | * <li>If the platform SDK version is greater than or equal to the |
| 2660 | * {@code minVers}, returns the {@code mniVers} unmodified. |
| 2661 | * <li>Otherwise, returns -1 to indicate that the package is not |
| 2662 | * compatible with this platform. |
| 2663 | * </ul> |
| 2664 | * <p> |
| 2665 | * Otherwise, the behavior varies based on whether the current platform |
| 2666 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2667 | * has length > 0: |
| 2668 | * <ul> |
| 2669 | * <li>If this is a pre-release platform and the value specified by |
| 2670 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2671 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2672 | * <li>If this is a released platform, this method will return -1 to |
| 2673 | * indicate that the package is not compatible with this platform. |
| 2674 | * </ul> |
| 2675 | * |
| 2676 | * @param minVers minSdkVersion number, if specified in the application |
| 2677 | * manifest, or 1 otherwise |
| 2678 | * @param minCode minSdkVersion code, if specified in the application |
| 2679 | * manifest, or {@code null} otherwise |
| 2680 | * @param platformSdkVersion platform SDK version number, typically |
| 2681 | * Build.VERSION.SDK_INT |
| 2682 | * @param platformSdkCodenames array of allowed prerelease SDK codenames |
| 2683 | * for this platform |
| 2684 | * @param outError output array to populate with error, if applicable |
| 2685 | * @return the minSdkVersion to use at runtime, or -1 if the package is not |
| 2686 | * compatible with this platform |
| 2687 | * @hide Exposed for unit testing only. |
| 2688 | */ |
| 2689 | @TestApi |
| 2690 | public static int computeMinSdkVersion(@IntRange(from = 1) int minVers, |
| 2691 | @Nullable String minCode, @IntRange(from = 1) int platformSdkVersion, |
| 2692 | @NonNull String[] platformSdkCodenames, @NonNull String[] outError) { |
| 2693 | // If it's a release SDK, make sure we meet the minimum SDK requirement. |
| 2694 | if (minCode == null) { |
| 2695 | if (minVers <= platformSdkVersion) { |
| 2696 | return minVers; |
| 2697 | } |
| 2698 | |
| 2699 | // We don't meet the minimum SDK requirement. |
| 2700 | outError[0] = "Requires newer sdk version #" + minVers |
| 2701 | + " (current version is #" + platformSdkVersion + ")"; |
| 2702 | return -1; |
| 2703 | } |
| 2704 | |
| 2705 | // If it's a pre-release SDK and the codename matches this platform, we |
| 2706 | // definitely meet the minimum SDK requirement. |
Narayan Kamath | 71fcc14 | 2019-01-15 18:20:39 +0000 | [diff] [blame] | 2707 | if (matchTargetCode(platformSdkCodenames, minCode)) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2708 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2709 | } |
| 2710 | |
| 2711 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2712 | if (platformSdkCodenames.length > 0) { |
| 2713 | outError[0] = "Requires development platform " + minCode |
| 2714 | + " (current platform is any of " |
| 2715 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2716 | } else { |
| 2717 | outError[0] = "Requires development platform " + minCode |
| 2718 | + " but this is a release platform."; |
| 2719 | } |
| 2720 | return -1; |
| 2721 | } |
| 2722 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2723 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2724 | FeatureInfo fi = new FeatureInfo(); |
| 2725 | TypedArray sa = res.obtainAttributes(attrs, |
| 2726 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2727 | // Note: don't allow this value to be a reference to a resource |
| 2728 | // that may change. |
| 2729 | fi.name = sa.getNonResourceString( |
| 2730 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2731 | fi.version = sa.getInt( |
| 2732 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2733 | if (fi.name == null) { |
| 2734 | fi.reqGlEsVersion = sa.getInt( |
| 2735 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2736 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2737 | } |
| 2738 | if (sa.getBoolean( |
| 2739 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2740 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2741 | } |
| 2742 | sa.recycle(); |
| 2743 | return fi; |
| 2744 | } |
| 2745 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2746 | private boolean parseUsesStaticLibrary(Package pkg, Resources res, XmlResourceParser parser, |
| 2747 | String[] outError) throws XmlPullParserException, IOException { |
| 2748 | TypedArray sa = res.obtainAttributes(parser, |
| 2749 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary); |
| 2750 | |
| 2751 | // Note: don't allow this value to be a reference to a resource that may change. |
| 2752 | String lname = sa.getNonResourceString( |
| 2753 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 2754 | final int version = sa.getInt( |
| 2755 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary_version, -1); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2756 | String certSha256Digest = sa.getNonResourceString(com.android.internal.R.styleable |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2757 | .AndroidManifestUsesStaticLibrary_certDigest); |
| 2758 | sa.recycle(); |
| 2759 | |
| 2760 | // 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] | 2761 | if (lname == null || version < 0 || certSha256Digest == null) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2762 | outError[0] = "Bad uses-static-library declaration name: " + lname + " version: " |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2763 | + version + " certDigest" + certSha256Digest; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2764 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2765 | XmlUtils.skipCurrentTag(parser); |
| 2766 | return false; |
| 2767 | } |
| 2768 | |
| 2769 | // Can depend only on one version of the same library |
| 2770 | if (pkg.usesStaticLibraries != null && pkg.usesStaticLibraries.contains(lname)) { |
| 2771 | outError[0] = "Depending on multiple versions of static library " + lname; |
| 2772 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2773 | XmlUtils.skipCurrentTag(parser); |
| 2774 | return false; |
| 2775 | } |
| 2776 | |
| 2777 | lname = lname.intern(); |
| 2778 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2779 | // emitted by the certtool making it easy for developers to copy/paste. |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2780 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2781 | |
| 2782 | // Fot apps targeting O-MR1 we require explicit enumeration of all certs. |
| 2783 | String[] additionalCertSha256Digests = EmptyArray.STRING; |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 2784 | if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O_MR1) { |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2785 | additionalCertSha256Digests = parseAdditionalCertificates(res, parser, outError); |
| 2786 | if (additionalCertSha256Digests == null) { |
| 2787 | return false; |
| 2788 | } |
| 2789 | } else { |
| 2790 | XmlUtils.skipCurrentTag(parser); |
| 2791 | } |
| 2792 | |
| 2793 | final String[] certSha256Digests = new String[additionalCertSha256Digests.length + 1]; |
| 2794 | certSha256Digests[0] = certSha256Digest; |
| 2795 | System.arraycopy(additionalCertSha256Digests, 0, certSha256Digests, |
| 2796 | 1, additionalCertSha256Digests.length); |
| 2797 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2798 | pkg.usesStaticLibraries = ArrayUtils.add(pkg.usesStaticLibraries, lname); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2799 | pkg.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 8a10ef5 | 2017-02-16 20:58:09 -0800 | [diff] [blame] | 2800 | pkg.usesStaticLibrariesVersions, version, true); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2801 | pkg.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, |
| 2802 | pkg.usesStaticLibrariesCertDigests, certSha256Digests, true); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2803 | |
| 2804 | return true; |
| 2805 | } |
| 2806 | |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2807 | private String[] parseAdditionalCertificates(Resources resources, XmlResourceParser parser, |
| 2808 | String[] outError) throws XmlPullParserException, IOException { |
| 2809 | String[] certSha256Digests = EmptyArray.STRING; |
| 2810 | |
| 2811 | int outerDepth = parser.getDepth(); |
| 2812 | int type; |
| 2813 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2814 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2815 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2816 | continue; |
| 2817 | } |
| 2818 | |
| 2819 | final String nodeName = parser.getName(); |
| 2820 | if (nodeName.equals("additional-certificate")) { |
| 2821 | final TypedArray sa = resources.obtainAttributes(parser, com.android.internal. |
| 2822 | R.styleable.AndroidManifestAdditionalCertificate); |
| 2823 | String certSha256Digest = sa.getNonResourceString(com.android.internal. |
| 2824 | R.styleable.AndroidManifestAdditionalCertificate_certDigest); |
| 2825 | sa.recycle(); |
| 2826 | |
| 2827 | if (TextUtils.isEmpty(certSha256Digest)) { |
| 2828 | outError[0] = "Bad additional-certificate declaration with empty" |
| 2829 | + " certDigest:" + certSha256Digest; |
| 2830 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2831 | XmlUtils.skipCurrentTag(parser); |
| 2832 | sa.recycle(); |
| 2833 | return null; |
| 2834 | } |
| 2835 | |
| 2836 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2837 | // emitted by the certtool making it easy for developers to copy/paste. |
| 2838 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2839 | certSha256Digests = ArrayUtils.appendElement(String.class, |
| 2840 | certSha256Digests, certSha256Digest); |
| 2841 | } else { |
| 2842 | XmlUtils.skipCurrentTag(parser); |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | return certSha256Digests; |
| 2847 | } |
| 2848 | |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2849 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2850 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2851 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2852 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2853 | |
| 2854 | // Note: don't allow this value to be a reference to a resource |
| 2855 | // that may change. |
| 2856 | String name = sa.getNonResourceString( |
| 2857 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2858 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2859 | int maxSdkVersion = 0; |
| 2860 | TypedValue val = sa.peekValue( |
| 2861 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2862 | if (val != null) { |
| 2863 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2864 | maxSdkVersion = val.data; |
| 2865 | } |
| 2866 | } |
| 2867 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2868 | final String requiredFeature = sa.getNonConfigurationString( |
| 2869 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredFeature, 0); |
| 2870 | |
| 2871 | final String requiredNotfeature = sa.getNonConfigurationString( |
| 2872 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredNotFeature, 0); |
| 2873 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2874 | sa.recycle(); |
| 2875 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2876 | XmlUtils.skipCurrentTag(parser); |
| 2877 | |
| 2878 | if (name == null) { |
| 2879 | return true; |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2882 | if ((maxSdkVersion != 0) && (maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT)) { |
| 2883 | return true; |
| 2884 | } |
| 2885 | |
| 2886 | // Only allow requesting this permission if the platform supports the given feature. |
| 2887 | if (requiredFeature != null && mCallback != null && !mCallback.hasFeature(requiredFeature)) { |
| 2888 | return true; |
| 2889 | } |
| 2890 | |
| 2891 | // Only allow requesting this permission if the platform doesn't support the given feature. |
| 2892 | if (requiredNotfeature != null && mCallback != null |
| 2893 | && mCallback.hasFeature(requiredNotfeature)) { |
| 2894 | return true; |
| 2895 | } |
| 2896 | |
| 2897 | int index = pkg.requestedPermissions.indexOf(name); |
| 2898 | if (index == -1) { |
| 2899 | pkg.requestedPermissions.add(name.intern()); |
| 2900 | } else { |
| 2901 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2902 | + name + " in package: " + pkg.packageName + " at: " |
| 2903 | + parser.getPositionDescription()); |
| 2904 | } |
| 2905 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2906 | return true; |
| 2907 | } |
| 2908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2910 | String[] outError) { |
| 2911 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2912 | outError[0] = "Empty class name in package " + pkg; |
| 2913 | return null; |
| 2914 | } |
| 2915 | String cls = clsSeq.toString(); |
| 2916 | char c = cls.charAt(0); |
| 2917 | if (c == '.') { |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2918 | return pkg + cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2919 | } |
| 2920 | if (cls.indexOf('.') < 0) { |
| 2921 | StringBuilder b = new StringBuilder(pkg); |
| 2922 | b.append('.'); |
| 2923 | b.append(cls); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2924 | return b.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2926 | return cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | private static String buildCompoundName(String pkg, |
| 2930 | CharSequence procSeq, String type, String[] outError) { |
| 2931 | String proc = procSeq.toString(); |
| 2932 | char c = proc.charAt(0); |
| 2933 | if (pkg != null && c == ':') { |
| 2934 | if (proc.length() < 2) { |
| 2935 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2936 | + ": must be at least two characters"; |
| 2937 | return null; |
| 2938 | } |
| 2939 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2940 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2941 | if (nameError != null) { |
| 2942 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2943 | + pkg + ": " + nameError; |
| 2944 | return null; |
| 2945 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2946 | return pkg + proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2948 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | if (nameError != null && !"system".equals(proc)) { |
| 2950 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2951 | + pkg + ": " + nameError; |
| 2952 | return null; |
| 2953 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2954 | return proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | private static String buildProcessName(String pkg, String defProc, |
| 2958 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 2959 | String[] outError) { |
| 2960 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 2961 | return defProc != null ? defProc : pkg; |
| 2962 | } |
| 2963 | if (separateProcesses != null) { |
| 2964 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 2965 | String sp = separateProcesses[i]; |
| 2966 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 2967 | return pkg; |
| 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | if (procSeq == null || procSeq.length() <= 0) { |
| 2972 | return defProc; |
| 2973 | } |
Makoto Onuki | 812d188a | 2017-08-07 09:58:23 -0700 | [diff] [blame] | 2974 | return TextUtils.safeIntern(buildCompoundName(pkg, procSeq, "process", outError)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 2978 | CharSequence procSeq, String[] outError) { |
| 2979 | if (procSeq == null) { |
| 2980 | return defProc; |
| 2981 | } |
| 2982 | if (procSeq.length() <= 0) { |
| 2983 | return null; |
| 2984 | } |
| 2985 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 2986 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2987 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2988 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2989 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2990 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2991 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2992 | // all the keys and keysets that we want must be defined here |
| 2993 | // so we're going to iterate over the parser and pull out the things we want |
| 2994 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2995 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2996 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2997 | String currentKeySet = null; |
| 2998 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 2999 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 3000 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 3001 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3002 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3003 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3004 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3005 | if (parser.getDepth() == currentKeySetDepth) { |
| 3006 | currentKeySet = null; |
| 3007 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3008 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3009 | continue; |
| 3010 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3011 | String tagName = parser.getName(); |
| 3012 | if (tagName.equals("key-set")) { |
| 3013 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3014 | outError[0] = "Improperly nested 'key-set' tag at " |
| 3015 | + parser.getPositionDescription(); |
| 3016 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3017 | return false; |
| 3018 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3019 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3020 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 3021 | final String keysetName = sa.getNonResourceString( |
| 3022 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 3023 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 3024 | currentKeySet = keysetName; |
| 3025 | currentKeySetDepth = parser.getDepth(); |
| 3026 | sa.recycle(); |
| 3027 | } else if (tagName.equals("public-key")) { |
| 3028 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3029 | outError[0] = "Improperly nested 'key-set' tag at " |
| 3030 | + parser.getPositionDescription(); |
| 3031 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3032 | return false; |
| 3033 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3034 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3035 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 3036 | final String publicKeyName = sa.getNonResourceString( |
| 3037 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3038 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3039 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 3040 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3041 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 3042 | + " on first use at " + parser.getPositionDescription(); |
| 3043 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3044 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3045 | return false; |
| 3046 | } else if (encodedKey != null) { |
| 3047 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 3048 | if (currentKey == null) { |
| 3049 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 3050 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 3051 | + " will not be added to the package's defined key-sets."); |
| 3052 | sa.recycle(); |
| 3053 | improperKeySets.add(currentKeySet); |
| 3054 | XmlUtils.skipCurrentTag(parser); |
| 3055 | continue; |
| 3056 | } |
| 3057 | if (publicKeys.get(publicKeyName) == null |
| 3058 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 3059 | |
| 3060 | /* public-key first definition, or matches old definition */ |
| 3061 | publicKeys.put(publicKeyName, currentKey); |
| 3062 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3063 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3064 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3065 | + parser.getPositionDescription(); |
| 3066 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3067 | sa.recycle(); |
| 3068 | return false; |
| 3069 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3070 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3071 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3072 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3073 | XmlUtils.skipCurrentTag(parser); |
| 3074 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3075 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3076 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 3077 | String name = sa.getNonResourceString( |
| 3078 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 3079 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3080 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3081 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3082 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3083 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3084 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3085 | + parser.getPositionDescription(); |
| 3086 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3087 | return false; |
| 3088 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3089 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3090 | + " at " + mArchiveSourcePath + " " |
| 3091 | + parser.getPositionDescription()); |
| 3092 | XmlUtils.skipCurrentTag(parser); |
| 3093 | continue; |
| 3094 | } |
| 3095 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3096 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 3097 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3098 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 3099 | + "'key-set' and 'public-key' names must be distinct."; |
| 3100 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3101 | return false; |
| 3102 | } |
| 3103 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 3104 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 3105 | final String keySetName = e.getKey(); |
| 3106 | if (e.getValue().size() == 0) { |
| 3107 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3108 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 3109 | + " Not including in package's defined key-sets."); |
| 3110 | continue; |
| 3111 | } else if (improperKeySets.contains(keySetName)) { |
| 3112 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3113 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 3114 | + " tags. Not including in package's defined key-sets."); |
| 3115 | continue; |
| 3116 | } |
| 3117 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 3118 | for (String s : e.getValue()) { |
| 3119 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3120 | } |
| 3121 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3122 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 3123 | owner.mUpgradeKeySets = upgradeKeySets; |
| 3124 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3125 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 3126 | + "does not define all 'upgrade-key-set's ."; |
| 3127 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3128 | return false; |
| 3129 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3130 | return true; |
| 3131 | } |
| 3132 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3133 | private boolean parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3134 | XmlResourceParser parser, String[] outError) |
| 3135 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3136 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 3138 | |
| 3139 | int requestDetailResourceId = sa.getResourceId( |
| 3140 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_requestDetail, 0); |
| 3141 | int backgroundRequestResourceId = sa.getResourceId( |
| 3142 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_backgroundRequest, |
| 3143 | 0); |
| 3144 | int backgroundRequestDetailResourceId = sa.getResourceId( |
| 3145 | com.android.internal.R.styleable |
| 3146 | .AndroidManifestPermissionGroup_backgroundRequestDetail, 0); |
| 3147 | |
| 3148 | PermissionGroup perm = new PermissionGroup(owner, requestDetailResourceId, |
| 3149 | backgroundRequestResourceId, backgroundRequestDetailResourceId); |
| 3150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3152 | "<permission-group>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 3154 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3155 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3156 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3157 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 3158 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | sa.recycle(); |
| 3160 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3161 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | perm.info.descriptionRes = sa.getResourceId( |
| 3165 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 3166 | 0); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3167 | perm.info.requestRes = sa.getResourceId( |
| 3168 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 3169 | perm.info.flags = sa.getInt( |
| 3170 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 3171 | perm.info.priority = sa.getInt( |
| 3172 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3173 | |
| 3174 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3175 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3176 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3177 | outError)) { |
| 3178 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3179 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | owner.permissionGroups.add(perm); |
| 3183 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3184 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | } |
| 3186 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3187 | private boolean parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3188 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3191 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 3193 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 3194 | String backgroundPermission = null; |
| 3195 | if (sa.hasValue( |
| 3196 | com.android.internal.R.styleable.AndroidManifestPermission_backgroundPermission)) { |
| 3197 | if ("android".equals(owner.packageName)) { |
| 3198 | backgroundPermission = sa.getNonResourceString( |
| 3199 | com.android.internal.R.styleable |
| 3200 | .AndroidManifestPermission_backgroundPermission); |
| 3201 | } else { |
| 3202 | Slog.w(TAG, owner.packageName + " defines a background permission. Only the " |
| 3203 | + "'android' package can do that."); |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | Permission perm = new Permission(owner, backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3209 | "<permission>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 3211 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3212 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3213 | com.android.internal.R.styleable.AndroidManifestPermission_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3214 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 3215 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | sa.recycle(); |
| 3217 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3218 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | } |
| 3220 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3221 | // Note: don't allow this value to be a reference to a resource |
| 3222 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | perm.info.group = sa.getNonResourceString( |
| 3224 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 3225 | if (perm.info.group != null) { |
| 3226 | perm.info.group = perm.info.group.intern(); |
| 3227 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | perm.info.descriptionRes = sa.getResourceId( |
| 3230 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 3231 | 0); |
| 3232 | |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3233 | perm.info.requestRes = sa.getResourceId( |
| 3234 | com.android.internal.R.styleable.AndroidManifestPermission_request, 0); |
| 3235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | perm.info.protectionLevel = sa.getInt( |
| 3237 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 3238 | PermissionInfo.PROTECTION_NORMAL); |
| 3239 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 3240 | perm.info.flags = sa.getInt( |
| 3241 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 3242 | |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 3243 | // For now only platform runtime permissions can be restricted |
| 3244 | if (!perm.info.isRuntime() || !"android".equals(perm.info.packageName)) { |
| 3245 | perm.info.flags &= ~PermissionInfo.FLAG_HARD_RESTRICTED; |
| 3246 | perm.info.flags &= ~PermissionInfo.FLAG_SOFT_RESTRICTED; |
| 3247 | } else { |
| 3248 | // The platform does not get to specify conflicting permissions |
| 3249 | if ((perm.info.flags & PermissionInfo.FLAG_HARD_RESTRICTED) != 0 |
| 3250 | && (perm.info.flags & PermissionInfo.FLAG_SOFT_RESTRICTED) != 0) { |
| 3251 | throw new IllegalStateException("Permission cannot be both soft and hard" |
| 3252 | + " restricted: " + perm.info.name); |
| 3253 | } |
| 3254 | } |
| 3255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | if (perm.info.protectionLevel == -1) { |
| 3259 | outError[0] = "<permission> does not specify protectionLevel"; |
| 3260 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3261 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3263 | |
| 3264 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 3265 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 3266 | if (perm.info.getProtectionFlags() != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 3267 | if ( (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_INSTANT) == 0 |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 3268 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) == 0 |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 3269 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3270 | PermissionInfo.PROTECTION_SIGNATURE) { |
Joe Maples | 39bb9e8 | 2018-01-11 11:09:46 -0500 | [diff] [blame] | 3271 | outError[0] = "<permission> protectionLevel specifies a non-instant flag but is " |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3272 | + "not based on signature type"; |
| 3273 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3274 | return false; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3275 | } |
| 3276 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3277 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3278 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3280 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | owner.permissions.add(perm); |
| 3284 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3285 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | } |
| 3287 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3288 | private boolean parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3289 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | throws XmlPullParserException, IOException { |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 3291 | Permission perm = new Permission(owner, (String) null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3293 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 3295 | |
| 3296 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3297 | "<permission-tree>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 3299 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3300 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3301 | com.android.internal.R.styleable.AndroidManifestPermissionTree_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3302 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 3303 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | sa.recycle(); |
| 3305 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3306 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | int index = perm.info.name.indexOf('.'); |
| 3312 | if (index > 0) { |
| 3313 | index = perm.info.name.indexOf('.', index+1); |
| 3314 | } |
| 3315 | if (index < 0) { |
| 3316 | outError[0] = "<permission-tree> name has less than three segments: " |
| 3317 | + perm.info.name; |
| 3318 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3319 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | perm.info.descriptionRes = 0; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3323 | perm.info.requestRes = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 3325 | perm.tree = true; |
| 3326 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3327 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | outError)) { |
| 3329 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3330 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | owner.permissions.add(perm); |
| 3334 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3335 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3339 | XmlResourceParser parser, String[] outError) |
| 3340 | throws XmlPullParserException, IOException { |
| 3341 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 3343 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3344 | if (mParseInstrumentationArgs == null) { |
| 3345 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 3346 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 3347 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3348 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3349 | com.android.internal.R.styleable.AndroidManifestInstrumentation_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3350 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 3351 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3352 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 3353 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3354 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3355 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3356 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3357 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 3358 | new InstrumentationInfo()); |
| 3359 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | sa.recycle(); |
| 3361 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3362 | return null; |
| 3363 | } |
| 3364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3366 | // Note: don't allow this value to be a reference to a resource |
| 3367 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | str = sa.getNonResourceString( |
| 3369 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 3370 | a.info.targetPackage = str != null ? str.intern() : null; |
| 3371 | |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3372 | str = sa.getNonResourceString( |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 3373 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetProcesses); |
| 3374 | a.info.targetProcesses = str != null ? str.intern() : null; |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | a.info.handleProfiling = sa.getBoolean( |
| 3377 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 3378 | false); |
| 3379 | |
| 3380 | a.info.functionalTest = sa.getBoolean( |
| 3381 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 3382 | false); |
| 3383 | |
| 3384 | sa.recycle(); |
| 3385 | |
| 3386 | if (a.info.targetPackage == null) { |
| 3387 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 3388 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3389 | return null; |
| 3390 | } |
| 3391 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3392 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | outError)) { |
| 3394 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3395 | return null; |
| 3396 | } |
| 3397 | |
| 3398 | owner.instrumentation.add(a); |
| 3399 | |
| 3400 | return a; |
| 3401 | } |
| 3402 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3403 | /** |
| 3404 | * Parse the {@code application} XML tree at the current parse location in a |
| 3405 | * <em>base APK</em> manifest. |
| 3406 | * <p> |
| 3407 | * When adding new features, carefully consider if they should also be |
| 3408 | * supported by split APKs. |
| 3409 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3410 | @UnsupportedAppUsage |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3411 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3412 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | throws XmlPullParserException, IOException { |
| 3414 | final ApplicationInfo ai = owner.applicationInfo; |
| 3415 | final String pkgName = owner.applicationInfo.packageName; |
| 3416 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3417 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3419 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 3420 | ai.iconRes = sa.getResourceId( |
| 3421 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
| 3422 | ai.roundIconRes = sa.getResourceId( |
| 3423 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, 0); |
| 3424 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3425 | if (!parsePackageItemInfo(owner, ai, outError, |
| 3426 | "<application>", sa, false /*nameRequired*/, |
| 3427 | com.android.internal.R.styleable.AndroidManifestApplication_name, |
| 3428 | com.android.internal.R.styleable.AndroidManifestApplication_label, |
| 3429 | com.android.internal.R.styleable.AndroidManifestApplication_icon, |
| 3430 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, |
| 3431 | com.android.internal.R.styleable.AndroidManifestApplication_logo, |
| 3432 | com.android.internal.R.styleable.AndroidManifestApplication_banner)) { |
| 3433 | sa.recycle(); |
| 3434 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3435 | return false; |
| 3436 | } |
| 3437 | |
| 3438 | if (ai.name != null) { |
Todd Kennedy | afb5269 | 2016-08-22 15:44:00 -0700 | [diff] [blame] | 3439 | ai.className = ai.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | } |
| 3441 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3442 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3443 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 3444 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3445 | if (manageSpaceActivity != null) { |
| 3446 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 3447 | outError); |
| 3448 | } |
| 3449 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3450 | boolean allowBackup = sa.getBoolean( |
| 3451 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 3452 | if (allowBackup) { |
| 3453 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3454 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3455 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 3456 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 3457 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3458 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3459 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 3460 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3461 | if (backupAgent != null) { |
| 3462 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3463 | if (DEBUG_BACKUP) { |
| 3464 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3465 | + " from " + pkgName + "+" + backupAgent); |
| 3466 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3467 | |
| 3468 | if (sa.getBoolean( |
| 3469 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 3470 | true)) { |
| 3471 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 3472 | } |
| 3473 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 3474 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 3475 | false)) { |
| 3476 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 3477 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 3478 | if (sa.getBoolean( |
| 3479 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 3480 | false)) { |
| 3481 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 3482 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3483 | if (sa.getBoolean( |
| 3484 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 3485 | false)) { |
| 3486 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 3487 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3488 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 3489 | |
| 3490 | TypedValue v = sa.peekValue( |
| 3491 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 3492 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 3493 | if (DEBUG_BACKUP) { |
| 3494 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 3495 | (v.data == 0 ? "false" : "true")); |
| 3496 | } |
| 3497 | // "false" => -1, "true" => 0 |
| 3498 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 3499 | } |
| 3500 | if (DEBUG_BACKUP) { |
| 3501 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 3502 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3503 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 3506 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | ai.descriptionRes = sa.getResourceId( |
| 3508 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 3509 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 3510 | if (sa.getBoolean( |
| 3511 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 3512 | false)) { |
| 3513 | // Check if persistence is based on a feature being present |
| 3514 | final String requiredFeature = sa.getNonResourceString(com.android.internal.R.styleable |
| 3515 | .AndroidManifestApplication_persistentWhenFeatureAvailable); |
| 3516 | if (requiredFeature == null || mCallback.hasFeature(requiredFeature)) { |
| 3517 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | if (sa.getBoolean( |
| 3522 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 3523 | false)) { |
| 3524 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 3528 | .AndroidManifestApplication_restrictedAccountType); |
| 3529 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 3530 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | } |
| 3532 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 3533 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 3534 | .AndroidManifestApplication_requiredAccountType); |
| 3535 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 3536 | owner.mRequiredAccountType = requiredAccountType; |
| 3537 | } |
| 3538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | if (sa.getBoolean( |
| 3540 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 3541 | false)) { |
| 3542 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 3543 | // Debuggable implies profileable |
| 3544 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 3548 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 3549 | false)) { |
| 3550 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 3551 | } |
| 3552 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3553 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3554 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 3555 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 3556 | if (owner.baseHardwareAccelerated) { |
| 3557 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 3558 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3559 | |
| 3560 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 3562 | true)) { |
| 3563 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 3564 | } |
| 3565 | |
| 3566 | if (sa.getBoolean( |
| 3567 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 3568 | false)) { |
| 3569 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3570 | } |
| 3571 | |
| 3572 | if (sa.getBoolean( |
| 3573 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 3574 | true)) { |
| 3575 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 3576 | } |
| 3577 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3578 | // The parent package controls installation, hence specify test only installs. |
| 3579 | if (owner.parentPackage == null) { |
| 3580 | if (sa.getBoolean( |
| 3581 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 3582 | false)) { |
| 3583 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 3584 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3587 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3588 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3589 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3590 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3591 | } |
| 3592 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3593 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3594 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
Chad Brubaker | 0d285d5 | 2018-03-14 09:00:04 -0700 | [diff] [blame] | 3595 | owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.P)) { |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3596 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 3597 | } |
| 3598 | |
| 3599 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3600 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 3601 | false /* default is no RTL support*/)) { |
| 3602 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 3603 | } |
| 3604 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 3605 | if (sa.getBoolean( |
| 3606 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 3607 | false)) { |
| 3608 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 3609 | } |
| 3610 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3611 | if (sa.getBoolean( |
| 3612 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
Victor Hsieh | 0faa801 | 2019-03-11 10:00:54 -0700 | [diff] [blame] | 3613 | true)) { |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3614 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 3615 | } |
| 3616 | |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3617 | if (sa.getBoolean( |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 3618 | R.styleable.AndroidManifestApplication_useEmbeddedDex, |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 3619 | false)) { |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 3620 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX; |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | if (sa.getBoolean( |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3624 | R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 3625 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3626 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3627 | } |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3628 | if (sa.getBoolean( |
| 3629 | R.styleable.AndroidManifestApplication_directBootAware, |
| 3630 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3631 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 3632 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3633 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3634 | if (sa.hasValueOrEmpty(R.styleable.AndroidManifestApplication_resizeableActivity)) { |
| 3635 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, true)) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3636 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; |
| 3637 | } else { |
| 3638 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3639 | } |
| 3640 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3641 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 3642 | } |
| 3643 | |
Ruslan Tkhakokhov | 7567485 | 2019-01-22 13:35:00 +0000 | [diff] [blame] | 3644 | if (sa.getBoolean( |
| 3645 | com.android.internal.R.styleable |
| 3646 | .AndroidManifestApplication_allowClearUserDataOnFailedRestore, |
| 3647 | true)) { |
| 3648 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE; |
| 3649 | } |
| 3650 | |
Kevin Rocard | f91d50b | 2019-02-21 14:32:46 -0800 | [diff] [blame] | 3651 | if (sa.getBoolean( |
| 3652 | R.styleable.AndroidManifestApplication_allowAudioPlaybackCapture, |
| 3653 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q)) { |
| 3654 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE; |
| 3655 | } |
| 3656 | |
Jeff Sharkey | bcff13c | 2019-03-28 14:29:35 -0600 | [diff] [blame] | 3657 | if (sa.getBoolean( |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 3658 | R.styleable.AndroidManifestApplication_requestLegacyExternalStorage, |
| 3659 | owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.Q)) { |
| 3660 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE; |
Jeff Sharkey | bcff13c | 2019-03-28 14:29:35 -0600 | [diff] [blame] | 3661 | } |
| 3662 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3663 | ai.maxAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_maxAspectRatio, 0); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3664 | ai.minAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_minAspectRatio, 0); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3665 | |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3666 | ai.networkSecurityConfigRes = sa.getResourceId( |
| 3667 | com.android.internal.R.styleable.AndroidManifestApplication_networkSecurityConfig, |
| 3668 | 0); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3669 | ai.category = sa.getInt( |
| 3670 | com.android.internal.R.styleable.AndroidManifestApplication_appCategory, |
| 3671 | ApplicationInfo.CATEGORY_UNDEFINED); |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3674 | str = sa.getNonConfigurationString( |
| 3675 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 3677 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3678 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3679 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3680 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 3681 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3682 | } else { |
| 3683 | // Some older apps have been seen to use a resource reference |
| 3684 | // here that on older builds was ignored (with a warning). We |
| 3685 | // need to continue to do this for them so they don't break. |
| 3686 | str = sa.getNonResourceString( |
| 3687 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 3688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 3690 | str, outError); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3691 | String factory = sa.getNonResourceString( |
| 3692 | com.android.internal.R.styleable.AndroidManifestApplication_appComponentFactory); |
| 3693 | if (factory != null) { |
| 3694 | ai.appComponentFactory = buildClassName(ai.packageName, factory, outError); |
| 3695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | |
David Brazdil | a5b4df2 | 2018-09-06 09:49:14 +0100 | [diff] [blame] | 3697 | if (sa.getBoolean( |
| 3698 | com.android.internal.R.styleable.AndroidManifestApplication_usesNonSdkApi, false)) { |
| 3699 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API; |
| 3700 | } |
David Brazdil | 787b6f22a | 2018-08-28 12:55:56 +0100 | [diff] [blame] | 3701 | |
Philip P. Moltmann | ae4a4b9 | 2018-12-12 11:28:57 -0800 | [diff] [blame] | 3702 | if (sa.getBoolean( |
| 3703 | com.android.internal.R.styleable.AndroidManifestApplication_hasFragileUserData, |
| 3704 | false)) { |
| 3705 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA; |
| 3706 | } |
| 3707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3709 | CharSequence pname; |
| 3710 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3711 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3712 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 3713 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3714 | } else { |
| 3715 | // Some older apps have been seen to use a resource reference |
| 3716 | // here that on older builds was ignored (with a warning). We |
| 3717 | // need to continue to do this for them so they don't break. |
| 3718 | pname = sa.getNonResourceString( |
| 3719 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 3720 | } |
| 3721 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3723 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3724 | ai.enabled = sa.getBoolean( |
| 3725 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3726 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 3727 | if (sa.getBoolean( |
| 3728 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 3729 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 3730 | } |
| 3731 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3732 | if (sa.getBoolean( |
| 3733 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 3734 | false)) { |
| 3735 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 3736 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3737 | // A heavy-weight application can not be in a custom process. |
| 3738 | // We can do direct compare because we intern all strings. |
| 3739 | if (ai.processName != null && !ai.processName.equals(ai.packageName)) { |
| 3740 | outError[0] = "cantSaveState applications can not use custom processes"; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3741 | } |
| 3742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | } |
| 3744 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3745 | ai.uiOptions = sa.getInt( |
| 3746 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 3747 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3748 | ai.classLoaderName = sa.getString( |
| 3749 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3750 | if (ai.classLoaderName != null |
| 3751 | && !ClassLoaderFactory.isValidClassLoaderName(ai.classLoaderName)) { |
| 3752 | outError[0] = "Invalid class loader name: " + ai.classLoaderName; |
| 3753 | } |
| 3754 | |
Martijn Coenen | fb7caa9 | 2019-01-29 11:45:56 +0100 | [diff] [blame] | 3755 | ai.zygotePreloadName = sa.getString( |
| 3756 | com.android.internal.R.styleable.AndroidManifestApplication_zygotePreloadName); |
| 3757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | sa.recycle(); |
| 3759 | |
| 3760 | if (outError[0] != null) { |
| 3761 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3762 | return false; |
| 3763 | } |
| 3764 | |
| 3765 | final int innerDepth = parser.getDepth(); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3766 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3767 | // getting added to the wrong package. |
| 3768 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | int type; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3770 | boolean hasActivityOrder = false; |
| 3771 | boolean hasReceiverOrder = false; |
| 3772 | boolean hasServiceOrder = false; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3773 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3774 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3775 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | continue; |
| 3777 | } |
| 3778 | |
| 3779 | String tagName = parser.getName(); |
| 3780 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3781 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3782 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | if (a == null) { |
| 3784 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3785 | return false; |
| 3786 | } |
| 3787 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3788 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | owner.activities.add(a); |
| 3790 | |
| 3791 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3792 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3793 | true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | if (a == null) { |
| 3795 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3796 | return false; |
| 3797 | } |
| 3798 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3799 | hasReceiverOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | owner.receivers.add(a); |
| 3801 | |
| 3802 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3803 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | if (s == null) { |
| 3805 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3806 | return false; |
| 3807 | } |
| 3808 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3809 | hasServiceOrder |= (s.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | owner.services.add(s); |
| 3811 | |
| 3812 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3813 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | if (p == null) { |
| 3815 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3816 | return false; |
| 3817 | } |
| 3818 | |
| 3819 | owner.providers.add(p); |
| 3820 | |
| 3821 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3822 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | if (a == null) { |
| 3824 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3825 | return false; |
| 3826 | } |
| 3827 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3828 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3829 | owner.activities.add(a); |
| 3830 | |
| 3831 | } else if (parser.getName().equals("meta-data")) { |
| 3832 | // note: application meta-data is stored off to the side, so it can |
| 3833 | // remain null in the primary copy (we like to avoid extra copies because |
| 3834 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3835 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | outError)) == null) { |
| 3837 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3838 | return false; |
| 3839 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3840 | } else if (tagName.equals("static-library")) { |
| 3841 | sa = res.obtainAttributes(parser, |
| 3842 | com.android.internal.R.styleable.AndroidManifestStaticLibrary); |
| 3843 | |
| 3844 | // Note: don't allow this value to be a reference to a resource |
| 3845 | // that may change. |
| 3846 | final String lname = sa.getNonResourceString( |
| 3847 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_name); |
| 3848 | final int version = sa.getInt( |
| 3849 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_version, -1); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3850 | final int versionMajor = sa.getInt( |
| 3851 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_versionMajor, |
| 3852 | 0); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3853 | |
| 3854 | sa.recycle(); |
| 3855 | |
| 3856 | // Since the app canot run without a static lib - fail if malformed |
| 3857 | if (lname == null || version < 0) { |
| 3858 | outError[0] = "Bad static-library declaration name: " + lname |
| 3859 | + " version: " + version; |
| 3860 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3861 | XmlUtils.skipCurrentTag(parser); |
| 3862 | return false; |
| 3863 | } |
| 3864 | |
| 3865 | if (owner.mSharedUserId != null) { |
| 3866 | outError[0] = "sharedUserId not allowed in static shared library"; |
| 3867 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 3868 | XmlUtils.skipCurrentTag(parser); |
| 3869 | return false; |
| 3870 | } |
| 3871 | |
| 3872 | if (owner.staticSharedLibName != null) { |
| 3873 | outError[0] = "Multiple static-shared libs for package " + pkgName; |
| 3874 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3875 | XmlUtils.skipCurrentTag(parser); |
| 3876 | return false; |
| 3877 | } |
| 3878 | |
| 3879 | owner.staticSharedLibName = lname.intern(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3880 | if (version >= 0) { |
| 3881 | owner.staticSharedLibVersion = |
| 3882 | PackageInfo.composeLongVersionCode(versionMajor, version); |
| 3883 | } else { |
| 3884 | owner.staticSharedLibVersion = version; |
| 3885 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3886 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY; |
| 3887 | |
| 3888 | XmlUtils.skipCurrentTag(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3890 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3891 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3892 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3893 | |
| 3894 | // Note: don't allow this value to be a reference to a resource |
| 3895 | // that may change. |
| 3896 | String lname = sa.getNonResourceString( |
| 3897 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3898 | |
| 3899 | sa.recycle(); |
| 3900 | |
| 3901 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3902 | lname = lname.intern(); |
| 3903 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3904 | owner.libraryNames = ArrayUtils.add( |
| 3905 | owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | XmlUtils.skipCurrentTag(parser); |
| 3910 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3911 | } else if (tagName.equals("uses-static-library")) { |
| 3912 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3913 | return false; |
| 3914 | } |
| 3915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3917 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3919 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3920 | // Note: don't allow this value to be a reference to a resource |
| 3921 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | String lname = sa.getNonResourceString( |
| 3923 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3924 | boolean req = sa.getBoolean( |
| 3925 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3926 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | |
| 3928 | sa.recycle(); |
| 3929 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3930 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3931 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3932 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3933 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3934 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3935 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3936 | owner.usesOptionalLibraries, lname); |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | XmlUtils.skipCurrentTag(parser); |
| 3941 | |
| 3942 | } else if (tagName.equals("uses-package")) { |
| 3943 | // Dependencies for app installers; we don't currently try to |
| 3944 | // enforce this. |
| 3945 | XmlUtils.skipCurrentTag(parser); |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 3946 | } else if (tagName.equals("profileable")) { |
| 3947 | sa = res.obtainAttributes(parser, |
| 3948 | com.android.internal.R.styleable.AndroidManifestProfileable); |
| 3949 | if (sa.getBoolean( |
| 3950 | com.android.internal.R.styleable.AndroidManifestProfileable_shell, false)) { |
| 3951 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL; |
| 3952 | } |
| 3953 | XmlUtils.skipCurrentTag(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3954 | |
| 3955 | } else { |
| 3956 | if (!RIGID_PARSER) { |
| 3957 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 3958 | + " at " + mArchiveSourcePath + " " |
| 3959 | + parser.getPositionDescription()); |
| 3960 | XmlUtils.skipCurrentTag(parser); |
| 3961 | continue; |
| 3962 | } else { |
| 3963 | outError[0] = "Bad element under <application>: " + tagName; |
| 3964 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3965 | return false; |
| 3966 | } |
| 3967 | } |
| 3968 | } |
| 3969 | |
Patrick Baumann | 1f9b885 | 2018-10-30 12:34:46 -0700 | [diff] [blame] | 3970 | if (TextUtils.isEmpty(owner.staticSharedLibName)) { |
| 3971 | // Add a hidden app detail activity to normal apps which forwards user to App Details |
| 3972 | // page. |
| 3973 | Activity a = generateAppDetailsHiddenActivity(owner, flags, outError, |
| 3974 | owner.baseHardwareAccelerated); |
| 3975 | owner.activities.add(a); |
| 3976 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 3977 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3978 | if (hasActivityOrder) { |
| 3979 | Collections.sort(owner.activities, (a1, a2) -> Integer.compare(a2.order, a1.order)); |
| 3980 | } |
| 3981 | if (hasReceiverOrder) { |
| 3982 | Collections.sort(owner.receivers, (r1, r2) -> Integer.compare(r2.order, r1.order)); |
| 3983 | } |
| 3984 | if (hasServiceOrder) { |
| 3985 | Collections.sort(owner.services, (s1, s2) -> Integer.compare(s2.order, s1.order)); |
| 3986 | } |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 3987 | // Must be ran after the entire {@link ApplicationInfo} has been fully processed and after |
| 3988 | // every activity info has had a chance to set it from its attributes. |
| 3989 | setMaxAspectRatio(owner); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3990 | setMinAspectRatio(owner); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 3991 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3992 | if (hasDomainURLs(owner)) { |
| 3993 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3994 | } else { |
| 3995 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3996 | } |
| 3997 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3998 | return true; |
| 3999 | } |
| 4000 | |
| 4001 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 4002 | * 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] | 4003 | */ |
| 4004 | private static boolean hasDomainURLs(Package pkg) { |
| 4005 | if (pkg == null || pkg.activities == null) return false; |
| 4006 | final ArrayList<Activity> activities = pkg.activities; |
| 4007 | final int countActivities = activities.size(); |
| 4008 | for (int n=0; n<countActivities; n++) { |
| 4009 | Activity activity = activities.get(n); |
| 4010 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 4011 | if (filters == null) continue; |
| 4012 | final int countFilters = filters.size(); |
| 4013 | for (int m=0; m<countFilters; m++) { |
| 4014 | ActivityIntentInfo aii = filters.get(m); |
| 4015 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 4016 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 4017 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 4018 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 4019 | return true; |
| 4020 | } |
| 4021 | } |
| 4022 | } |
| 4023 | return false; |
| 4024 | } |
| 4025 | |
| 4026 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4027 | * Parse the {@code application} XML tree at the current parse location in a |
| 4028 | * <em>split APK</em> manifest. |
| 4029 | * <p> |
| 4030 | * Note that split APKs have many more restrictions on what they're capable |
| 4031 | * of doing, so many valid features of a base APK have been carefully |
| 4032 | * omitted here. |
| 4033 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4034 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 4035 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4036 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4037 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4038 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 4039 | |
| 4040 | if (sa.getBoolean( |
| 4041 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 4042 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 4043 | } |
| 4044 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 4045 | final String classLoaderName = sa.getString( |
| 4046 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 4047 | if (classLoaderName == null || ClassLoaderFactory.isValidClassLoaderName(classLoaderName)) { |
| 4048 | owner.applicationInfo.splitClassLoaderNames[splitIndex] = classLoaderName; |
| 4049 | } else { |
| 4050 | outError[0] = "Invalid class loader name: " + classLoaderName; |
| 4051 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4052 | return false; |
| 4053 | } |
| 4054 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4055 | final int innerDepth = parser.getDepth(); |
| 4056 | int type; |
| 4057 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4058 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 4059 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4060 | continue; |
| 4061 | } |
| 4062 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4063 | ComponentInfo parsedComponent = null; |
| 4064 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4065 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 4066 | // getting added to the wrong package. |
| 4067 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4068 | String tagName = parser.getName(); |
| 4069 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4070 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4071 | owner.baseHardwareAccelerated); |
| 4072 | if (a == null) { |
| 4073 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4074 | return false; |
| 4075 | } |
| 4076 | |
| 4077 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4078 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4079 | |
| 4080 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4081 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 4082 | true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4083 | if (a == null) { |
| 4084 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4085 | return false; |
| 4086 | } |
| 4087 | |
| 4088 | owner.receivers.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4089 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4090 | |
| 4091 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4092 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4093 | if (s == null) { |
| 4094 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4095 | return false; |
| 4096 | } |
| 4097 | |
| 4098 | owner.services.add(s); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4099 | parsedComponent = s.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4100 | |
| 4101 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4102 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4103 | if (p == null) { |
| 4104 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4105 | return false; |
| 4106 | } |
| 4107 | |
| 4108 | owner.providers.add(p); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4109 | parsedComponent = p.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4110 | |
| 4111 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4112 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4113 | if (a == null) { |
| 4114 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4115 | return false; |
| 4116 | } |
| 4117 | |
| 4118 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4119 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4120 | |
| 4121 | } else if (parser.getName().equals("meta-data")) { |
| 4122 | // note: application meta-data is stored off to the side, so it can |
| 4123 | // remain null in the primary copy (we like to avoid extra copies because |
| 4124 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4125 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4126 | outError)) == null) { |
| 4127 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4128 | return false; |
| 4129 | } |
| 4130 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4131 | } else if (tagName.equals("uses-static-library")) { |
| 4132 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 4133 | return false; |
| 4134 | } |
| 4135 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4136 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4137 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4138 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 4139 | |
| 4140 | // Note: don't allow this value to be a reference to a resource |
| 4141 | // that may change. |
| 4142 | String lname = sa.getNonResourceString( |
| 4143 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 4144 | boolean req = sa.getBoolean( |
| 4145 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 4146 | true); |
| 4147 | |
| 4148 | sa.recycle(); |
| 4149 | |
| 4150 | if (lname != null) { |
| 4151 | lname = lname.intern(); |
| 4152 | if (req) { |
| 4153 | // Upgrade to treat as stronger constraint |
| 4154 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 4155 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 4156 | owner.usesOptionalLibraries, lname); |
| 4157 | } else { |
| 4158 | // Ignore if someone already defined as required |
| 4159 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 4160 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 4161 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4162 | } |
| 4163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | XmlUtils.skipCurrentTag(parser); |
| 4167 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 4168 | } else if (tagName.equals("uses-package")) { |
| 4169 | // Dependencies for app installers; we don't currently try to |
| 4170 | // enforce this. |
| 4171 | XmlUtils.skipCurrentTag(parser); |
| 4172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | } else { |
| 4174 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4175 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4176 | + " at " + mArchiveSourcePath + " " |
| 4177 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | XmlUtils.skipCurrentTag(parser); |
| 4179 | continue; |
| 4180 | } else { |
| 4181 | outError[0] = "Bad element under <application>: " + tagName; |
| 4182 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4183 | return false; |
| 4184 | } |
| 4185 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4186 | |
| 4187 | if (parsedComponent != null && parsedComponent.splitName == null) { |
| 4188 | // If the loaded component did not specify a split, inherit the split name |
| 4189 | // based on the split it is defined in. |
| 4190 | // This is used to later load the correct split when starting this |
| 4191 | // component. |
| 4192 | parsedComponent.splitName = owner.splitNames[splitIndex]; |
| 4193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | return true; |
| 4197 | } |
| 4198 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4199 | private static boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 4200 | String[] outError, String tag, TypedArray sa, boolean nameRequired, |
| 4201 | int nameRes, int labelRes, int iconRes, int roundIconRes, int logoRes, int bannerRes) { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 4202 | // This case can only happen in unit tests where we sometimes need to create fakes |
| 4203 | // of various package parser data structures. |
| 4204 | if (sa == null) { |
| 4205 | outError[0] = tag + " does not contain any attributes"; |
| 4206 | return false; |
| 4207 | } |
| 4208 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4209 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | if (name == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4211 | if (nameRequired) { |
| 4212 | outError[0] = tag + " does not specify android:name"; |
| 4213 | return false; |
| 4214 | } |
| 4215 | } else { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4216 | String outInfoName |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4217 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4218 | if (PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(outInfoName)) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4219 | outError[0] = tag + " invalid android:name"; |
| 4220 | return false; |
| 4221 | } |
| 4222 | outInfo.name = outInfoName; |
| 4223 | if (outInfoName == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4224 | return false; |
| 4225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 4228 | int roundIconVal = sUseRoundIcon ? sa.getResourceId(roundIconRes, 0) : 0; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4229 | if (roundIconVal != 0) { |
| 4230 | outInfo.icon = roundIconVal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4231 | outInfo.nonLocalizedLabel = null; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4232 | } else { |
| 4233 | int iconVal = sa.getResourceId(iconRes, 0); |
| 4234 | if (iconVal != 0) { |
| 4235 | outInfo.icon = iconVal; |
| 4236 | outInfo.nonLocalizedLabel = null; |
| 4237 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4239 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4240 | int logoVal = sa.getResourceId(logoRes, 0); |
| 4241 | if (logoVal != 0) { |
| 4242 | outInfo.logo = logoVal; |
| 4243 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4245 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 4246 | if (bannerVal != 0) { |
| 4247 | outInfo.banner = bannerVal; |
| 4248 | } |
| 4249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | TypedValue v = sa.peekValue(labelRes); |
| 4251 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4252 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4253 | } |
| 4254 | |
| 4255 | outInfo.packageName = owner.packageName; |
| 4256 | |
| 4257 | return true; |
| 4258 | } |
| 4259 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4260 | /** |
| 4261 | * Generate activity object that forwards user to App Details page automatically. |
| 4262 | * This activity should be invisible to user and user should not know or see it. |
| 4263 | */ |
| 4264 | private @NonNull PackageParser.Activity generateAppDetailsHiddenActivity( |
| 4265 | PackageParser.Package owner, int flags, String[] outError, |
| 4266 | boolean hardwareAccelerated) { |
| 4267 | |
| 4268 | // Build custom App Details activity info instead of parsing it from xml |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4269 | Activity a = new Activity(owner, PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME, |
| 4270 | new ActivityInfo()); |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4271 | a.owner = owner; |
| 4272 | a.setPackageName(owner.packageName); |
| 4273 | |
Ricky Wai | 62292507 | 2019-01-29 16:40:59 +0000 | [diff] [blame] | 4274 | a.info.theme = android.R.style.Theme_NoDisplay; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4275 | a.info.exported = true; |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4276 | a.info.name = PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4277 | a.info.processName = owner.applicationInfo.processName; |
| 4278 | a.info.uiOptions = a.info.applicationInfo.uiOptions; |
| 4279 | a.info.taskAffinity = buildTaskAffinityName(owner.packageName, owner.packageName, |
| 4280 | ":app_details", outError); |
| 4281 | a.info.enabled = true; |
| 4282 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4283 | a.info.documentLaunchMode = ActivityInfo.DOCUMENT_LAUNCH_NONE; |
| 4284 | a.info.maxRecents = ActivityTaskManager.getDefaultAppRecentsLimitStatic(); |
| 4285 | a.info.configChanges = getActivityConfigChanges(0, 0); |
| 4286 | a.info.softInputMode = 0; |
| 4287 | a.info.persistableMode = ActivityInfo.PERSIST_NEVER; |
| 4288 | a.info.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 4289 | a.info.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4290 | a.info.lockTaskLaunchMode = 0; |
| 4291 | a.info.encryptionAware = a.info.directBootAware = false; |
| 4292 | a.info.rotationAnimation = ROTATION_ANIMATION_UNSPECIFIED; |
| 4293 | a.info.colorMode = ActivityInfo.COLOR_MODE_DEFAULT; |
| 4294 | if (hardwareAccelerated) { |
| 4295 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4296 | } |
| 4297 | return a; |
| 4298 | } |
| 4299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | private Activity parseActivity(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4301 | XmlResourceParser parser, int flags, String[] outError, CachedComponentArgs cachedArgs, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4302 | boolean receiver, boolean hardwareAccelerated) |
| 4303 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4304 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4306 | if (cachedArgs.mActivityArgs == null) { |
| 4307 | cachedArgs.mActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4308 | R.styleable.AndroidManifestActivity_name, |
| 4309 | R.styleable.AndroidManifestActivity_label, |
| 4310 | R.styleable.AndroidManifestActivity_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4311 | R.styleable.AndroidManifestActivity_roundIcon, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4312 | R.styleable.AndroidManifestActivity_logo, |
| 4313 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4314 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4315 | R.styleable.AndroidManifestActivity_process, |
| 4316 | R.styleable.AndroidManifestActivity_description, |
| 4317 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4318 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4319 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4320 | cachedArgs.mActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 4321 | cachedArgs.mActivityArgs.sa = sa; |
| 4322 | cachedArgs.mActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4323 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4324 | Activity a = new Activity(cachedArgs.mActivityArgs, new ActivityInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4325 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | sa.recycle(); |
| 4327 | return null; |
| 4328 | } |
| 4329 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4330 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4332 | 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] | 4333 | } |
| 4334 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4335 | 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] | 4336 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4337 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4338 | a.info.applicationInfo.uiOptions); |
| 4339 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4340 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4341 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4342 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4343 | if (parentName != null) { |
| 4344 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4345 | if (outError[0] == null) { |
| 4346 | a.info.parentActivityName = parentClassName; |
| 4347 | } else { |
| 4348 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 4349 | parentName); |
| 4350 | outError[0] = null; |
| 4351 | } |
| 4352 | } |
| 4353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4355 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | if (str == null) { |
| 4357 | a.info.permission = owner.applicationInfo.permission; |
| 4358 | } else { |
| 4359 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4360 | } |
| 4361 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4362 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4363 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4364 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 4366 | owner.applicationInfo.taskAffinity, str, outError); |
| 4367 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4368 | a.info.splitName = |
| 4369 | sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_splitName, 0); |
| 4370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | a.info.flags = 0; |
| 4372 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4373 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4374 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 4375 | } |
| 4376 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4377 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 4379 | } |
| 4380 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4381 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 4383 | } |
| 4384 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4385 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 4387 | } |
| 4388 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4389 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 4391 | } |
| 4392 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4393 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 4395 | } |
| 4396 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4397 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 4399 | } |
| 4400 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4401 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4402 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 4403 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 4404 | } |
| 4405 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4406 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4407 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 4408 | } |
| 4409 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 4410 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 4411 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 4412 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4413 | } |
| 4414 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4415 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 4416 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 4417 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4418 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 4419 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 4420 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 4421 | } |
| 4422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4424 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4425 | hardwareAccelerated)) { |
| 4426 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4427 | } |
| 4428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4430 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4431 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4432 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4433 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 4434 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4435 | R.styleable.AndroidManifestActivity_maxRecents, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 4436 | ActivityTaskManager.getDefaultAppRecentsLimitStatic()); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4437 | a.info.configChanges = getActivityConfigChanges( |
| 4438 | sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0), |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4439 | sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4441 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4442 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4443 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4444 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4445 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4446 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4447 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4448 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 4449 | } |
| 4450 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4451 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4452 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 4453 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4454 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4455 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4456 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 4457 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4458 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4459 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4460 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 4461 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4462 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4463 | a.info.screenOrientation = sa.getInt( |
| 4464 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 4465 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 4466 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4467 | setActivityResizeMode(a.info, sa, owner); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4468 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4469 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 4470 | false)) { |
| 4471 | a.info.flags |= FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 4472 | } |
| 4473 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4474 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4475 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4476 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 4477 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4478 | if (sa.hasValue(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4479 | && sa.getType(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4480 | == TypedValue.TYPE_FLOAT) { |
| 4481 | a.setMaxAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_maxAspectRatio, |
| 4482 | 0 /*default*/)); |
| 4483 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4484 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4485 | if (sa.hasValue(R.styleable.AndroidManifestActivity_minAspectRatio) |
| 4486 | && sa.getType(R.styleable.AndroidManifestActivity_minAspectRatio) |
| 4487 | == TypedValue.TYPE_FLOAT) { |
| 4488 | a.setMinAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_minAspectRatio, |
| 4489 | 0 /*default*/)); |
| 4490 | } |
| 4491 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4492 | a.info.lockTaskLaunchMode = |
| 4493 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4494 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4495 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4496 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4497 | false); |
Ruben Brunk | f56c9f4 | 2016-04-22 18:20:55 -0700 | [diff] [blame] | 4498 | |
| 4499 | a.info.requestedVrComponent = |
| 4500 | sa.getString(R.styleable.AndroidManifestActivity_enableVrMode); |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 4501 | |
| 4502 | a.info.rotationAnimation = |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 4503 | sa.getInt(R.styleable.AndroidManifestActivity_rotationAnimation, ROTATION_ANIMATION_UNSPECIFIED); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 4504 | |
| 4505 | a.info.colorMode = sa.getInt(R.styleable.AndroidManifestActivity_colorMode, |
| 4506 | ActivityInfo.COLOR_MODE_DEFAULT); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4507 | |
| 4508 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showWhenLocked, false)) { |
| 4509 | a.info.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
| 4510 | } |
| 4511 | |
| 4512 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_turnScreenOn, false)) { |
| 4513 | a.info.flags |= ActivityInfo.FLAG_TURN_SCREEN_ON; |
| 4514 | } |
| 4515 | |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4516 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_inheritShowWhenLocked, false)) { |
| 4517 | a.info.privateFlags |= ActivityInfo.FLAG_INHERIT_SHOW_WHEN_LOCKED; |
| 4518 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | } else { |
| 4520 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4521 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4523 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 4524 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4525 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4526 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4527 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4528 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4529 | false); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4532 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4533 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4534 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4537 | // can't make this final; we may set it later via meta-data |
| 4538 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4539 | sa.getBoolean(R.styleable.AndroidManifestActivity_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4540 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4541 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4542 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4543 | } |
| 4544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | sa.recycle(); |
| 4546 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4547 | if (receiver && (owner.applicationInfo.privateFlags |
| 4548 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4549 | // A heavy-weight application can not have receives in its main process |
| 4550 | // We can do direct compare because we intern all strings. |
| 4551 | if (a.info.processName == owner.packageName) { |
| 4552 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 4553 | } |
| 4554 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | if (outError[0] != null) { |
| 4557 | return null; |
| 4558 | } |
| 4559 | |
| 4560 | int outerDepth = parser.getDepth(); |
| 4561 | int type; |
| 4562 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4563 | && (type != XmlPullParser.END_TAG |
| 4564 | || parser.getDepth() > outerDepth)) { |
| 4565 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4566 | continue; |
| 4567 | } |
| 4568 | |
| 4569 | if (parser.getName().equals("intent-filter")) { |
| 4570 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4571 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4572 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4573 | return null; |
| 4574 | } |
| 4575 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4576 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4577 | + mArchiveSourcePath + " " |
| 4578 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4580 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | a.intents.add(intent); |
| 4582 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4583 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4584 | final int visibility = visibleToEphemeral |
| 4585 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4586 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4587 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4588 | : IntentFilter.VISIBILITY_NONE; |
| 4589 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4590 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4591 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4592 | } |
| 4593 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4594 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4595 | } |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 4596 | if (LOG_UNSAFE_BROADCASTS && receiver |
| 4597 | && (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O)) { |
| 4598 | for (int i = 0; i < intent.countActions(); i++) { |
| 4599 | final String action = intent.getAction(i); |
| 4600 | if (action == null || !action.startsWith("android.")) continue; |
| 4601 | if (!SAFE_BROADCASTS.contains(action)) { |
| 4602 | Slog.w(TAG, "Broadcast " + action + " may never be delivered to " |
| 4603 | + owner.packageName + " as requested at: " |
| 4604 | + parser.getPositionDescription()); |
| 4605 | } |
| 4606 | } |
| 4607 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4608 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 4609 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4610 | if (!parseIntent(res, parser, false /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4611 | intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4612 | return null; |
| 4613 | } |
| 4614 | if (intent.countActions() == 0) { |
| 4615 | Slog.w(TAG, "No actions in preferred at " |
| 4616 | + mArchiveSourcePath + " " |
| 4617 | + parser.getPositionDescription()); |
| 4618 | } else { |
| 4619 | if (owner.preferredActivityFilters == null) { |
| 4620 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 4621 | } |
| 4622 | owner.preferredActivityFilters.add(intent); |
| 4623 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4624 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4625 | final int visibility = visibleToEphemeral |
| 4626 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4627 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4628 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4629 | : IntentFilter.VISIBILITY_NONE; |
| 4630 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4631 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4632 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4633 | } |
| 4634 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4635 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4638 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4639 | outError)) == null) { |
| 4640 | return null; |
| 4641 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4642 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4643 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | } else { |
| 4645 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4646 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4648 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4649 | + " at " + mArchiveSourcePath + " " |
| 4650 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4652 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4653 | + " at " + mArchiveSourcePath + " " |
| 4654 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | } |
| 4656 | XmlUtils.skipCurrentTag(parser); |
| 4657 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4658 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4659 | if (receiver) { |
| 4660 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 4661 | } else { |
| 4662 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 4663 | } |
| 4664 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | if (!setExported) { |
| 4670 | a.info.exported = a.intents.size() > 0; |
| 4671 | } |
| 4672 | |
| 4673 | return a; |
| 4674 | } |
| 4675 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4676 | private void setActivityResizeMode(ActivityInfo aInfo, TypedArray sa, Package owner) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4677 | final boolean appExplicitDefault = (owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4678 | & (PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE |
| 4679 | | PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE)) != 0; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4680 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4681 | if (sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity) |
| 4682 | || appExplicitDefault) { |
| 4683 | // Activity or app explicitly set if it is resizeable or not; |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4684 | final boolean appResizeable = (owner.applicationInfo.privateFlags |
| 4685 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE) != 0; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4686 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity, |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4687 | appResizeable)) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4688 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4689 | } else { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4690 | aInfo.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4691 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4692 | return; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4693 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4694 | |
| 4695 | if ((owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4696 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) != 0) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4697 | // The activity or app didn't explicitly set the resizing option, however we want to |
| 4698 | // make it resize due to the sdk version it is targeting. |
| 4699 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 4700 | return; |
| 4701 | } |
| 4702 | |
| 4703 | // resize preference isn't set and target sdk version doesn't support resizing apps by |
| 4704 | // 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] | 4705 | if (aInfo.isFixedOrientationPortrait()) { |
| 4706 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 4707 | } else if (aInfo.isFixedOrientationLandscape()) { |
| 4708 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 4709 | } else if (aInfo.isFixedOrientation()) { |
| 4710 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
| 4711 | } else { |
| 4712 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4713 | } |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4716 | /** |
| 4717 | * Sets every the max aspect ratio of every child activity that doesn't already have an aspect |
| 4718 | * ratio set. |
| 4719 | */ |
| 4720 | private void setMaxAspectRatio(Package owner) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4721 | // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater. |
| 4722 | // 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] | 4723 | float maxAspectRatio = owner.applicationInfo.targetSdkVersion < O |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4724 | ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4725 | |
| 4726 | if (owner.applicationInfo.maxAspectRatio != 0) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4727 | // Use the application max aspect ration as default if set. |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4728 | maxAspectRatio = owner.applicationInfo.maxAspectRatio; |
| 4729 | } else if (owner.mAppMetaData != null |
| 4730 | && owner.mAppMetaData.containsKey(METADATA_MAX_ASPECT_RATIO)) { |
| 4731 | maxAspectRatio = owner.mAppMetaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4734 | for (Activity activity : owner.activities) { |
| 4735 | // If the max aspect ratio for the activity has already been set, skip. |
| 4736 | if (activity.hasMaxAspectRatio()) { |
| 4737 | continue; |
| 4738 | } |
| 4739 | |
| 4740 | // By default we prefer to use a values defined on the activity directly than values |
| 4741 | // defined on the application. We do not check the styled attributes on the activity |
| 4742 | // as it would have already been set when we processed the activity. We wait to process |
| 4743 | // the meta data here since this method is called at the end of processing the |
| 4744 | // application and all meta data is guaranteed. |
| 4745 | final float activityAspectRatio = activity.metaData != null |
| 4746 | ? activity.metaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio) |
| 4747 | : maxAspectRatio; |
| 4748 | |
| 4749 | activity.setMaxAspectRatio(activityAspectRatio); |
Wale Ogunwale | 0cb70ac | 2017-03-27 09:16:38 -0700 | [diff] [blame] | 4750 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4751 | } |
| 4752 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4753 | /** |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 4754 | * Sets every the min aspect ratio of every child activity that doesn't already have an aspect |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4755 | * ratio set. |
| 4756 | */ |
| 4757 | private void setMinAspectRatio(Package owner) { |
| 4758 | final float minAspectRatio; |
| 4759 | if (owner.applicationInfo.minAspectRatio != 0) { |
| 4760 | // Use the application max aspect ration as default if set. |
| 4761 | minAspectRatio = owner.applicationInfo.minAspectRatio; |
| 4762 | } else { |
| 4763 | // Default to (1.33) 4:3 aspect ratio for pre-Q apps and unset for Q and greater. |
| 4764 | // NOTE: 4:3 was the min aspect ratio Android devices can support pre-Q per the CDD, |
| 4765 | // except for watches which always supported 1:1. |
| 4766 | minAspectRatio = owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q |
| 4767 | ? 0 |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 4768 | : (mCallback != null && mCallback.hasFeature(FEATURE_WATCH)) |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4769 | ? DEFAULT_PRE_Q_MIN_ASPECT_RATIO_WATCH |
| 4770 | : DEFAULT_PRE_Q_MIN_ASPECT_RATIO; |
| 4771 | } |
| 4772 | |
| 4773 | for (Activity activity : owner.activities) { |
| 4774 | if (activity.hasMinAspectRatio()) { |
| 4775 | continue; |
| 4776 | } |
| 4777 | activity.setMinAspectRatio(minAspectRatio); |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | /** |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4782 | * @param configChanges The bit mask of configChanges fetched from AndroidManifest.xml. |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4783 | * @param recreateOnConfigChanges The bit mask recreateOnConfigChanges fetched from |
| 4784 | * AndroidManifest.xml. |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4785 | * @hide Exposed for unit testing only. |
| 4786 | */ |
| 4787 | @TestApi |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4788 | public static int getActivityConfigChanges(int configChanges, int recreateOnConfigChanges) { |
| 4789 | return configChanges | ((~recreateOnConfigChanges) & RECREATE_ON_CONFIG_CHANGES_MASK); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4790 | } |
| 4791 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4792 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4793 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4794 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4795 | int width = -1; |
| 4796 | float widthFraction = -1f; |
| 4797 | int height = -1; |
| 4798 | float heightFraction = -1f; |
| 4799 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4800 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4801 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 4802 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4803 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4804 | 1, 1, -1); |
| 4805 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 4806 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4807 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4808 | -1); |
| 4809 | } |
| 4810 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4811 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4812 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 4813 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4814 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4815 | 1, 1, -1); |
| 4816 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 4817 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4818 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4819 | -1); |
| 4820 | } |
| 4821 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4822 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4823 | Gravity.CENTER); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4824 | int minWidth = sw.getDimensionPixelSize( |
| 4825 | com.android.internal.R.styleable.AndroidManifestLayout_minWidth, |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4826 | -1); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4827 | int minHeight = sw.getDimensionPixelSize( |
| 4828 | com.android.internal.R.styleable.AndroidManifestLayout_minHeight, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4829 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4830 | sw.recycle(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4831 | a.info.windowLayout = new ActivityInfo.WindowLayout(width, widthFraction, |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4832 | height, heightFraction, gravity, minWidth, minHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4835 | private Activity parseActivityAlias(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4836 | XmlResourceParser parser, int flags, String[] outError, |
| 4837 | CachedComponentArgs cachedArgs) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4838 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4839 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 4841 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4842 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4843 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 4844 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | if (targetActivity == null) { |
| 4846 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 4847 | sa.recycle(); |
| 4848 | return null; |
| 4849 | } |
| 4850 | |
| 4851 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 4852 | targetActivity, outError); |
| 4853 | if (targetActivity == null) { |
| 4854 | sa.recycle(); |
| 4855 | return null; |
| 4856 | } |
| 4857 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4858 | if (cachedArgs.mActivityAliasArgs == null) { |
| 4859 | cachedArgs.mActivityAliasArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4860 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 4861 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 4862 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4863 | com.android.internal.R.styleable.AndroidManifestActivityAlias_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4864 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4865 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4866 | mSeparateProcesses, |
| 4867 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4868 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4869 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4870 | cachedArgs.mActivityAliasArgs.tag = "<activity-alias>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4871 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4872 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4873 | cachedArgs.mActivityAliasArgs.sa = sa; |
| 4874 | cachedArgs.mActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | Activity target = null; |
| 4877 | |
| 4878 | final int NA = owner.activities.size(); |
| 4879 | for (int i=0; i<NA; i++) { |
| 4880 | Activity t = owner.activities.get(i); |
| 4881 | if (targetActivity.equals(t.info.name)) { |
| 4882 | target = t; |
| 4883 | break; |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | if (target == null) { |
| 4888 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 4889 | + " not found in manifest"; |
| 4890 | sa.recycle(); |
| 4891 | return null; |
| 4892 | } |
| 4893 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4894 | ActivityInfo info = new ActivityInfo(); |
| 4895 | info.targetActivity = targetActivity; |
| 4896 | info.configChanges = target.info.configChanges; |
| 4897 | info.flags = target.info.flags; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4898 | info.privateFlags = target.info.privateFlags; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4899 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4900 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4901 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4902 | info.labelRes = target.info.labelRes; |
| 4903 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 4904 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 4905 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4906 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4907 | if (info.descriptionRes == 0) { |
| 4908 | info.descriptionRes = target.info.descriptionRes; |
| 4909 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4910 | info.screenOrientation = target.info.screenOrientation; |
| 4911 | info.taskAffinity = target.info.taskAffinity; |
| 4912 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 4913 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4914 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4915 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4916 | info.maxRecents = target.info.maxRecents; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4917 | info.windowLayout = target.info.windowLayout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4918 | info.resizeMode = target.info.resizeMode; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4919 | info.maxAspectRatio = target.info.maxAspectRatio; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4920 | info.minAspectRatio = target.info.minAspectRatio; |
rongliu | c12ede4 | 2018-02-23 17:58:38 -0800 | [diff] [blame] | 4921 | info.requestedVrComponent = target.info.requestedVrComponent; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4922 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4923 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4924 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4925 | Activity a = new Activity(cachedArgs.mActivityAliasArgs, info); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4926 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4927 | sa.recycle(); |
| 4928 | return null; |
| 4929 | } |
| 4930 | |
| 4931 | final boolean setExported = sa.hasValue( |
| 4932 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 4933 | if (setExported) { |
| 4934 | a.info.exported = sa.getBoolean( |
| 4935 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 4936 | } |
| 4937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4938 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4939 | str = sa.getNonConfigurationString( |
| 4940 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | if (str != null) { |
| 4942 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4943 | } |
| 4944 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4945 | String parentName = sa.getNonConfigurationString( |
| 4946 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4947 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4948 | if (parentName != null) { |
| 4949 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4950 | if (outError[0] == null) { |
| 4951 | a.info.parentActivityName = parentClassName; |
| 4952 | } else { |
| 4953 | Log.e(TAG, "Activity alias " + a.info.name + |
| 4954 | " specified invalid parentActivityName " + parentName); |
| 4955 | outError[0] = null; |
| 4956 | } |
| 4957 | } |
| 4958 | |
Chad Brubaker | 699c771 | 2017-01-20 13:53:42 -0800 | [diff] [blame] | 4959 | // TODO add visibleToInstantApps attribute to activity alias |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4960 | final boolean visibleToEphemeral = |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4961 | ((a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4963 | sa.recycle(); |
| 4964 | |
| 4965 | if (outError[0] != null) { |
| 4966 | return null; |
| 4967 | } |
| 4968 | |
| 4969 | int outerDepth = parser.getDepth(); |
| 4970 | int type; |
| 4971 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4972 | && (type != XmlPullParser.END_TAG |
| 4973 | || parser.getDepth() > outerDepth)) { |
| 4974 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4975 | continue; |
| 4976 | } |
| 4977 | |
| 4978 | if (parser.getName().equals("intent-filter")) { |
| 4979 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4980 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4981 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4982 | return null; |
| 4983 | } |
| 4984 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4985 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4986 | + mArchiveSourcePath + " " |
| 4987 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4989 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4990 | a.intents.add(intent); |
| 4991 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4992 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4993 | final int visibility = visibleToEphemeral |
| 4994 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4995 | : isImplicitlyExposedIntent(intent) |
| 4996 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4997 | : IntentFilter.VISIBILITY_NONE; |
| 4998 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4999 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5000 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 5001 | } |
| 5002 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 5003 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5004 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5006 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5007 | outError)) == null) { |
| 5008 | return null; |
| 5009 | } |
| 5010 | } else { |
| 5011 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5012 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5013 | + " at " + mArchiveSourcePath + " " |
| 5014 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | XmlUtils.skipCurrentTag(parser); |
| 5016 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5017 | } else { |
| 5018 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 5019 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | if (!setExported) { |
| 5025 | a.info.exported = a.intents.size() > 0; |
| 5026 | } |
| 5027 | |
| 5028 | return a; |
| 5029 | } |
| 5030 | |
| 5031 | private Provider parseProvider(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5032 | XmlResourceParser parser, int flags, String[] outError, |
| 5033 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5035 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5036 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 5037 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5038 | if (cachedArgs.mProviderArgs == null) { |
| 5039 | cachedArgs.mProviderArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5040 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 5041 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 5042 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5043 | com.android.internal.R.styleable.AndroidManifestProvider_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5044 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5045 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5046 | mSeparateProcesses, |
| 5047 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5048 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5049 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5050 | cachedArgs.mProviderArgs.tag = "<provider>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5051 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5052 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5053 | cachedArgs.mProviderArgs.sa = sa; |
| 5054 | cachedArgs.mProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5055 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5056 | Provider p = new Provider(cachedArgs.mProviderArgs, new ProviderInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5057 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | sa.recycle(); |
| 5059 | return null; |
| 5060 | } |
| 5061 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5062 | boolean providerExportedDefault = false; |
| 5063 | |
| 5064 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 5065 | // For compatibility, applications targeting API level 16 or lower |
| 5066 | // should have their content providers exported by default, unless they |
| 5067 | // specify otherwise. |
| 5068 | providerExportedDefault = true; |
| 5069 | } |
| 5070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5072 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 5073 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5075 | String cpname = sa.getNonConfigurationString( |
| 5076 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5077 | |
| 5078 | p.info.isSyncable = sa.getBoolean( |
| 5079 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 5080 | false); |
| 5081 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5082 | String permission = sa.getNonConfigurationString( |
| 5083 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 5084 | String str = sa.getNonConfigurationString( |
| 5085 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | if (str == null) { |
| 5087 | str = permission; |
| 5088 | } |
| 5089 | if (str == null) { |
| 5090 | p.info.readPermission = owner.applicationInfo.permission; |
| 5091 | } else { |
| 5092 | p.info.readPermission = |
| 5093 | str.length() > 0 ? str.toString().intern() : null; |
| 5094 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5095 | str = sa.getNonConfigurationString( |
| 5096 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | if (str == null) { |
| 5098 | str = permission; |
| 5099 | } |
| 5100 | if (str == null) { |
| 5101 | p.info.writePermission = owner.applicationInfo.permission; |
| 5102 | } else { |
| 5103 | p.info.writePermission = |
| 5104 | str.length() > 0 ? str.toString().intern() : null; |
| 5105 | } |
| 5106 | |
| 5107 | p.info.grantUriPermissions = sa.getBoolean( |
| 5108 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 5109 | false); |
| 5110 | |
Dianne Hackborn | 52e42a4 | 2019-02-05 16:10:50 -0800 | [diff] [blame] | 5111 | p.info.forceUriPermissions = sa.getBoolean( |
| 5112 | com.android.internal.R.styleable.AndroidManifestProvider_forceUriPermissions, |
| 5113 | false); |
| 5114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5115 | p.info.multiprocess = sa.getBoolean( |
| 5116 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 5117 | false); |
| 5118 | |
| 5119 | p.info.initOrder = sa.getInt( |
| 5120 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 5121 | 0); |
| 5122 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5123 | p.info.splitName = |
| 5124 | sa.getNonConfigurationString(R.styleable.AndroidManifestProvider_splitName, 0); |
| 5125 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 5126 | p.info.flags = 0; |
| 5127 | |
| 5128 | if (sa.getBoolean( |
| 5129 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 5130 | false)) { |
| 5131 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5134 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 5135 | R.styleable.AndroidManifestProvider_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5136 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5137 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5138 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5139 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5140 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5141 | |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5142 | final boolean visibleToEphemeral = |
| 5143 | sa.getBoolean(R.styleable.AndroidManifestProvider_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5144 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5145 | p.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5146 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5147 | } |
| 5148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | sa.recycle(); |
| 5150 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5151 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5152 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5153 | // A heavy-weight application can not have providers in its main process |
| 5154 | // We can do direct compare because we intern all strings. |
| 5155 | if (p.info.processName == owner.packageName) { |
| 5156 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 5157 | return null; |
| 5158 | } |
| 5159 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5161 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5162 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5163 | return null; |
| 5164 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 5165 | if (cpname.length() <= 0) { |
| 5166 | outError[0] = "<provider> has empty authorities attribute"; |
| 5167 | return null; |
| 5168 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5169 | p.info.authority = cpname.intern(); |
| 5170 | |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5171 | if (!parseProviderTags( |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 5172 | res, parser, visibleToEphemeral, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | return null; |
| 5174 | } |
| 5175 | |
| 5176 | return p; |
| 5177 | } |
| 5178 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5179 | private boolean parseProviderTags(Resources res, XmlResourceParser parser, |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 5180 | boolean visibleToEphemeral, Provider outInfo, String[] outError) |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5181 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5182 | int outerDepth = parser.getDepth(); |
| 5183 | int type; |
| 5184 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5185 | && (type != XmlPullParser.END_TAG |
| 5186 | || parser.getDepth() > outerDepth)) { |
| 5187 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5188 | continue; |
| 5189 | } |
| 5190 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5191 | if (parser.getName().equals("intent-filter")) { |
| 5192 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5193 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5194 | intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5195 | return false; |
| 5196 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5197 | if (visibleToEphemeral) { |
| 5198 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5199 | outInfo.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5200 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5201 | outInfo.order = Math.max(intent.getOrder(), outInfo.order); |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5202 | outInfo.intents.add(intent); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5203 | |
| 5204 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5205 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5206 | outInfo.metaData, outError)) == null) { |
| 5207 | return false; |
| 5208 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5211 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 5213 | |
| 5214 | PatternMatcher pa = null; |
| 5215 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5216 | String str = sa.getNonConfigurationString( |
| 5217 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | if (str != null) { |
| 5219 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 5220 | } |
| 5221 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5222 | str = sa.getNonConfigurationString( |
| 5223 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | if (str != null) { |
| 5225 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 5226 | } |
| 5227 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5228 | str = sa.getNonConfigurationString( |
| 5229 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | if (str != null) { |
| 5231 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5232 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5234 | sa.recycle(); |
| 5235 | |
| 5236 | if (pa != null) { |
| 5237 | if (outInfo.info.uriPermissionPatterns == null) { |
| 5238 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 5239 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 5240 | } else { |
| 5241 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 5242 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 5243 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 5244 | newp[N] = pa; |
| 5245 | outInfo.info.uriPermissionPatterns = newp; |
| 5246 | } |
| 5247 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5248 | } else { |
| 5249 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5250 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5251 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5252 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5253 | XmlUtils.skipCurrentTag(parser); |
| 5254 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5255 | } else { |
| 5256 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5257 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5258 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5259 | } |
| 5260 | XmlUtils.skipCurrentTag(parser); |
| 5261 | |
| 5262 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5263 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5264 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 5265 | |
| 5266 | PathPermission pa = null; |
| 5267 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5268 | String permission = sa.getNonConfigurationString( |
| 5269 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 5270 | String readPermission = sa.getNonConfigurationString( |
| 5271 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5272 | if (readPermission == null) { |
| 5273 | readPermission = permission; |
| 5274 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5275 | String writePermission = sa.getNonConfigurationString( |
| 5276 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5277 | if (writePermission == null) { |
| 5278 | writePermission = permission; |
| 5279 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5280 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5281 | boolean havePerm = false; |
| 5282 | if (readPermission != null) { |
| 5283 | readPermission = readPermission.intern(); |
| 5284 | havePerm = true; |
| 5285 | } |
| 5286 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 5287 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5288 | havePerm = true; |
| 5289 | } |
| 5290 | |
| 5291 | if (!havePerm) { |
| 5292 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5293 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5294 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5295 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5296 | XmlUtils.skipCurrentTag(parser); |
| 5297 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5298 | } else { |
| 5299 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 5300 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5301 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5302 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5303 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5304 | String path = sa.getNonConfigurationString( |
| 5305 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5306 | if (path != null) { |
| 5307 | pa = new PathPermission(path, |
| 5308 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 5309 | } |
| 5310 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5311 | path = sa.getNonConfigurationString( |
| 5312 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5313 | if (path != null) { |
| 5314 | pa = new PathPermission(path, |
| 5315 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 5316 | } |
| 5317 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5318 | path = sa.getNonConfigurationString( |
| 5319 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5320 | if (path != null) { |
| 5321 | pa = new PathPermission(path, |
| 5322 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 5323 | } |
| 5324 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5325 | path = sa.getNonConfigurationString( |
| 5326 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathAdvancedPattern, 0); |
| 5327 | if (path != null) { |
| 5328 | pa = new PathPermission(path, |
| 5329 | PatternMatcher.PATTERN_ADVANCED_GLOB, readPermission, writePermission); |
| 5330 | } |
| 5331 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5332 | sa.recycle(); |
| 5333 | |
| 5334 | if (pa != null) { |
| 5335 | if (outInfo.info.pathPermissions == null) { |
| 5336 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 5337 | outInfo.info.pathPermissions[0] = pa; |
| 5338 | } else { |
| 5339 | final int N = outInfo.info.pathPermissions.length; |
| 5340 | PathPermission[] newp = new PathPermission[N+1]; |
| 5341 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 5342 | newp[N] = pa; |
| 5343 | outInfo.info.pathPermissions = newp; |
| 5344 | } |
| 5345 | } else { |
| 5346 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5347 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5348 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5349 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5350 | XmlUtils.skipCurrentTag(parser); |
| 5351 | continue; |
| 5352 | } |
| 5353 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5354 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | } |
| 5356 | XmlUtils.skipCurrentTag(parser); |
| 5357 | |
| 5358 | } else { |
| 5359 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5360 | Slog.w(TAG, "Unknown element under <provider>: " |
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 | XmlUtils.skipCurrentTag(parser); |
| 5364 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5365 | } else { |
| 5366 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 5367 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | } |
| 5370 | } |
| 5371 | return true; |
| 5372 | } |
| 5373 | |
| 5374 | private Service parseService(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5375 | XmlResourceParser parser, int flags, String[] outError, |
| 5376 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5378 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5379 | com.android.internal.R.styleable.AndroidManifestService); |
| 5380 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5381 | if (cachedArgs.mServiceArgs == null) { |
| 5382 | cachedArgs.mServiceArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5383 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 5384 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 5385 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5386 | com.android.internal.R.styleable.AndroidManifestService_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5387 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5388 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5389 | mSeparateProcesses, |
| 5390 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5391 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5392 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5393 | cachedArgs.mServiceArgs.tag = "<service>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5394 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5395 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5396 | cachedArgs.mServiceArgs.sa = sa; |
| 5397 | cachedArgs.mServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5398 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5399 | Service s = new Service(cachedArgs.mServiceArgs, new ServiceInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5400 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | sa.recycle(); |
| 5402 | return null; |
| 5403 | } |
| 5404 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5405 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 5407 | if (setExported) { |
| 5408 | s.info.exported = sa.getBoolean( |
| 5409 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 5410 | } |
| 5411 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5412 | String str = sa.getNonConfigurationString( |
| 5413 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | if (str == null) { |
| 5415 | s.info.permission = owner.applicationInfo.permission; |
| 5416 | } else { |
| 5417 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 5418 | } |
| 5419 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5420 | s.info.splitName = |
| 5421 | sa.getNonConfigurationString(R.styleable.AndroidManifestService_splitName, 0); |
| 5422 | |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 5423 | s.info.mForegroundServiceType = sa.getInt( |
| 5424 | com.android.internal.R.styleable.AndroidManifestService_foregroundServiceType, |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 5425 | ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE); |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 5426 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5427 | s.info.flags = 0; |
| 5428 | if (sa.getBoolean( |
| 5429 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 5430 | false)) { |
| 5431 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 5432 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5433 | if (sa.getBoolean( |
| 5434 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 5435 | false)) { |
| 5436 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 5437 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5438 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 5439 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 5440 | false)) { |
| 5441 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 5442 | } |
| 5443 | if (sa.getBoolean( |
Martijn Coenen | e066c5c | 2018-10-31 16:50:30 +0100 | [diff] [blame] | 5444 | com.android.internal.R.styleable.AndroidManifestService_useAppZygote, |
| 5445 | false)) { |
| 5446 | s.info.flags |= ServiceInfo.FLAG_USE_APP_ZYGOTE; |
| 5447 | } |
| 5448 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5449 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 5450 | false)) { |
| 5451 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5452 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5453 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5454 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 5455 | R.styleable.AndroidManifestService_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5456 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5457 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5458 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5459 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5460 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5461 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5462 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5463 | sa.getBoolean(R.styleable.AndroidManifestService_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5464 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5465 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5466 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5467 | } |
| 5468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5469 | sa.recycle(); |
| 5470 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5471 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5472 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5473 | // A heavy-weight application can not have services in its main process |
| 5474 | // We can do direct compare because we intern all strings. |
| 5475 | if (s.info.processName == owner.packageName) { |
| 5476 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 5477 | return null; |
| 5478 | } |
| 5479 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | int outerDepth = parser.getDepth(); |
| 5482 | int type; |
| 5483 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5484 | && (type != XmlPullParser.END_TAG |
| 5485 | || parser.getDepth() > outerDepth)) { |
| 5486 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5487 | continue; |
| 5488 | } |
| 5489 | |
| 5490 | if (parser.getName().equals("intent-filter")) { |
| 5491 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5492 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5493 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | return null; |
| 5495 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5496 | if (visibleToEphemeral) { |
| 5497 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5498 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5499 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5500 | s.order = Math.max(intent.getOrder(), s.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | s.intents.add(intent); |
| 5502 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5503 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5504 | outError)) == null) { |
| 5505 | return null; |
| 5506 | } |
| 5507 | } else { |
| 5508 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5509 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5510 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5511 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5512 | XmlUtils.skipCurrentTag(parser); |
| 5513 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5514 | } else { |
| 5515 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 5516 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | if (!setExported) { |
| 5522 | s.info.exported = s.intents.size() > 0; |
| 5523 | } |
| 5524 | |
| 5525 | return s; |
| 5526 | } |
| 5527 | |
Chad Brubaker | 4941483 | 2017-04-13 16:13:23 -0700 | [diff] [blame] | 5528 | private boolean isImplicitlyExposedIntent(IntentInfo intent) { |
| 5529 | return intent.hasCategory(Intent.CATEGORY_BROWSABLE) |
| 5530 | || intent.hasAction(Intent.ACTION_SEND) |
| 5531 | || intent.hasAction(Intent.ACTION_SENDTO) |
| 5532 | || intent.hasAction(Intent.ACTION_SEND_MULTIPLE); |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5533 | } |
| 5534 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5535 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 5536 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | int outerDepth = parser.getDepth(); |
| 5538 | int type; |
| 5539 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5540 | && (type != XmlPullParser.END_TAG |
| 5541 | || parser.getDepth() > outerDepth)) { |
| 5542 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5543 | continue; |
| 5544 | } |
| 5545 | |
| 5546 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5547 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5548 | outInfo.metaData, outError)) == null) { |
| 5549 | return false; |
| 5550 | } |
| 5551 | } else { |
| 5552 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5553 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5554 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5555 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | XmlUtils.skipCurrentTag(parser); |
| 5557 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5558 | } else { |
| 5559 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 5560 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | } |
| 5563 | } |
| 5564 | return true; |
| 5565 | } |
| 5566 | |
| 5567 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5568 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5569 | throws XmlPullParserException, IOException { |
| 5570 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5571 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 5573 | |
| 5574 | if (data == null) { |
| 5575 | data = new Bundle(); |
| 5576 | } |
| 5577 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5578 | String name = sa.getNonConfigurationString( |
| 5579 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | if (name == null) { |
| 5581 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 5582 | sa.recycle(); |
| 5583 | return null; |
| 5584 | } |
| 5585 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 5586 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5588 | TypedValue v = sa.peekValue( |
| 5589 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 5590 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5591 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | data.putInt(name, v.resourceId); |
| 5593 | } else { |
| 5594 | v = sa.peekValue( |
| 5595 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5596 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5597 | if (v != null) { |
| 5598 | if (v.type == TypedValue.TYPE_STRING) { |
| 5599 | CharSequence cs = v.coerceToString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 5600 | data.putString(name, cs != null ? cs.toString() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 5602 | data.putBoolean(name, v.data != 0); |
| 5603 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 5604 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 5605 | data.putInt(name, v.data); |
| 5606 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 5607 | data.putFloat(name, v.getFloat()); |
| 5608 | } else { |
| 5609 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5610 | 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] | 5611 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5612 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | } else { |
| 5614 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 5615 | data = null; |
| 5616 | } |
| 5617 | } |
| 5618 | } else { |
| 5619 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 5620 | data = null; |
| 5621 | } |
| 5622 | } |
| 5623 | |
| 5624 | sa.recycle(); |
| 5625 | |
| 5626 | XmlUtils.skipCurrentTag(parser); |
| 5627 | |
| 5628 | return data; |
| 5629 | } |
| 5630 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5631 | private static VerifierInfo parseVerifier(AttributeSet attrs) { |
| 5632 | String packageName = null; |
| 5633 | String encodedPublicKey = null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5634 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5635 | final int attrCount = attrs.getAttributeCount(); |
| 5636 | for (int i = 0; i < attrCount; i++) { |
| 5637 | final int attrResId = attrs.getAttributeNameResource(i); |
| 5638 | switch (attrResId) { |
| 5639 | case com.android.internal.R.attr.name: |
| 5640 | packageName = attrs.getAttributeValue(i); |
| 5641 | break; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5642 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5643 | case com.android.internal.R.attr.publicKey: |
| 5644 | encodedPublicKey = attrs.getAttributeValue(i); |
| 5645 | break; |
| 5646 | } |
| 5647 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5648 | |
| 5649 | if (packageName == null || packageName.length() == 0) { |
| 5650 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 5651 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5652 | } |
| 5653 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5654 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 5655 | if (publicKey == null) { |
| 5656 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 5657 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5658 | } |
| 5659 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5660 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5661 | } |
| 5662 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5663 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 5664 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5665 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5666 | return null; |
| 5667 | } |
| 5668 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5669 | EncodedKeySpec keySpec; |
| 5670 | try { |
| 5671 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 5672 | keySpec = new X509EncodedKeySpec(encoded); |
| 5673 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5674 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5675 | return null; |
| 5676 | } |
| 5677 | |
| 5678 | /* First try the key as an RSA key. */ |
| 5679 | try { |
| 5680 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5681 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5682 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5683 | 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] | 5684 | } catch (InvalidKeySpecException e) { |
| 5685 | // Not a RSA public key. |
| 5686 | } |
| 5687 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5688 | /* Now try it as a ECDSA key. */ |
| 5689 | try { |
| 5690 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 5691 | return keyFactory.generatePublic(keySpec); |
| 5692 | } catch (NoSuchAlgorithmException e) { |
| 5693 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 5694 | } catch (InvalidKeySpecException e) { |
| 5695 | // Not a ECDSA public key. |
| 5696 | } |
| 5697 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5698 | /* Now try it as a DSA key. */ |
| 5699 | try { |
| 5700 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5701 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5702 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5703 | 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] | 5704 | } catch (InvalidKeySpecException e) { |
| 5705 | // Not a DSA public key. |
| 5706 | } |
| 5707 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5708 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5709 | return null; |
| 5710 | } |
| 5711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | private static final String ANDROID_RESOURCES |
| 5713 | = "http://schemas.android.com/apk/res/android"; |
| 5714 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5715 | private boolean parseIntent(Resources res, XmlResourceParser parser, boolean allowGlobs, |
| 5716 | boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
| 5717 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5718 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5719 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 5721 | |
| 5722 | int priority = sa.getInt( |
| 5723 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 5725 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5726 | int order = sa.getInt( |
| 5727 | com.android.internal.R.styleable.AndroidManifestIntentFilter_order, 0); |
| 5728 | outInfo.setOrder(order); |
| 5729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5730 | TypedValue v = sa.peekValue( |
| 5731 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 5732 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5733 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5734 | } |
| 5735 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 5736 | int roundIconVal = sUseRoundIcon ? sa.getResourceId( |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 5737 | com.android.internal.R.styleable.AndroidManifestIntentFilter_roundIcon, 0) : 0; |
| 5738 | if (roundIconVal != 0) { |
| 5739 | outInfo.icon = roundIconVal; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5740 | } else { |
| 5741 | outInfo.icon = sa.getResourceId( |
| 5742 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
| 5743 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5744 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5745 | outInfo.logo = sa.getResourceId( |
| 5746 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5747 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5748 | outInfo.banner = sa.getResourceId( |
| 5749 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 5750 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 5751 | if (allowAutoVerify) { |
| 5752 | outInfo.setAutoVerify(sa.getBoolean( |
| 5753 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 5754 | false)); |
| 5755 | } |
| 5756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5757 | sa.recycle(); |
| 5758 | |
| 5759 | int outerDepth = parser.getDepth(); |
| 5760 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5761 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5762 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5763 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | continue; |
| 5765 | } |
| 5766 | |
| 5767 | String nodeName = parser.getName(); |
| 5768 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5769 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5770 | ANDROID_RESOURCES, "name"); |
| 5771 | if (value == null || value == "") { |
| 5772 | outError[0] = "No value supplied for <android:name>"; |
| 5773 | return false; |
| 5774 | } |
| 5775 | XmlUtils.skipCurrentTag(parser); |
| 5776 | |
| 5777 | outInfo.addAction(value); |
| 5778 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5779 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | ANDROID_RESOURCES, "name"); |
| 5781 | if (value == null || value == "") { |
| 5782 | outError[0] = "No value supplied for <android:name>"; |
| 5783 | return false; |
| 5784 | } |
| 5785 | XmlUtils.skipCurrentTag(parser); |
| 5786 | |
| 5787 | outInfo.addCategory(value); |
| 5788 | |
| 5789 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5790 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | com.android.internal.R.styleable.AndroidManifestData); |
| 5792 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5793 | String str = sa.getNonConfigurationString( |
| 5794 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | if (str != null) { |
| 5796 | try { |
| 5797 | outInfo.addDataType(str); |
| 5798 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 5799 | outError[0] = e.toString(); |
| 5800 | sa.recycle(); |
| 5801 | return false; |
| 5802 | } |
| 5803 | } |
| 5804 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5805 | str = sa.getNonConfigurationString( |
| 5806 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5807 | if (str != null) { |
| 5808 | outInfo.addDataScheme(str); |
| 5809 | } |
| 5810 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5811 | str = sa.getNonConfigurationString( |
| 5812 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 5813 | if (str != null) { |
| 5814 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 5815 | } |
| 5816 | |
| 5817 | str = sa.getNonConfigurationString( |
| 5818 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 5819 | if (str != null) { |
| 5820 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 5821 | } |
| 5822 | |
| 5823 | str = sa.getNonConfigurationString( |
| 5824 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 5825 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5826 | if (!allowGlobs) { |
| 5827 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 5828 | return false; |
| 5829 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5830 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5831 | } |
| 5832 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5833 | String host = sa.getNonConfigurationString( |
| 5834 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 5835 | String port = sa.getNonConfigurationString( |
| 5836 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | if (host != null) { |
| 5838 | outInfo.addDataAuthority(host, port); |
| 5839 | } |
| 5840 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5841 | str = sa.getNonConfigurationString( |
| 5842 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | if (str != null) { |
| 5844 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 5845 | } |
| 5846 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5847 | str = sa.getNonConfigurationString( |
| 5848 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5849 | if (str != null) { |
| 5850 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 5851 | } |
| 5852 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5853 | str = sa.getNonConfigurationString( |
| 5854 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5856 | if (!allowGlobs) { |
| 5857 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 5858 | return false; |
| 5859 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5861 | } |
| 5862 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5863 | str = sa.getNonConfigurationString( |
| 5864 | com.android.internal.R.styleable.AndroidManifestData_pathAdvancedPattern, 0); |
| 5865 | if (str != null) { |
| 5866 | if (!allowGlobs) { |
| 5867 | outError[0] = "pathAdvancedPattern not allowed here; path must be literal"; |
| 5868 | return false; |
| 5869 | } |
| 5870 | outInfo.addDataPath(str, PatternMatcher.PATTERN_ADVANCED_GLOB); |
| 5871 | } |
| 5872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | sa.recycle(); |
| 5874 | XmlUtils.skipCurrentTag(parser); |
| 5875 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5876 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5877 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5878 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5879 | XmlUtils.skipCurrentTag(parser); |
| 5880 | } else { |
| 5881 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 5882 | return false; |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5887 | |
| 5888 | if (DEBUG_PARSER) { |
| 5889 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 5890 | cats.append(outInfo.hasDefault); |
| 5891 | cats.append(", cat="); |
| 5892 | |
| 5893 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 5894 | if (it != null) { |
| 5895 | while (it.hasNext()) { |
| 5896 | cats.append(' '); |
| 5897 | cats.append(it.next()); |
| 5898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5900 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | return true; |
| 5904 | } |
| 5905 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5906 | /** |
| 5907 | * A container for signing-related data of an application package. |
| 5908 | * @hide |
| 5909 | */ |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5910 | public static final class SigningDetails implements Parcelable { |
| 5911 | |
| 5912 | @IntDef({SigningDetails.SignatureSchemeVersion.UNKNOWN, |
| 5913 | SigningDetails.SignatureSchemeVersion.JAR, |
| 5914 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2, |
| 5915 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V3}) |
| 5916 | public @interface SignatureSchemeVersion { |
| 5917 | int UNKNOWN = 0; |
| 5918 | int JAR = 1; |
| 5919 | int SIGNING_BLOCK_V2 = 2; |
| 5920 | int SIGNING_BLOCK_V3 = 3; |
| 5921 | } |
| 5922 | |
| 5923 | @Nullable |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 5924 | @UnsupportedAppUsage |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5925 | public final Signature[] signatures; |
| 5926 | @SignatureSchemeVersion |
| 5927 | public final int signatureSchemeVersion; |
| 5928 | @Nullable |
| 5929 | public final ArraySet<PublicKey> publicKeys; |
| 5930 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5931 | /** |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5932 | * APK Signature Scheme v3 includes support for adding a proof-of-rotation record that |
| 5933 | * contains two pieces of information: |
| 5934 | * 1) the past signing certificates |
| 5935 | * 2) the flags that APK wants to assign to each of the past signing certificates. |
| 5936 | * |
| 5937 | * This collection of {@code Signature} objects, each of which is formed from a former |
| 5938 | * signing certificate of this APK before it was changed by signing certificate rotation, |
| 5939 | * represents the first piece of information. It is the APK saying to the rest of the |
| 5940 | * world: "hey if you trust the old cert, you can trust me!" This is useful, if for |
| 5941 | * instance, the platform would like to determine whether or not to allow this APK to do |
| 5942 | * 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] | 5943 | */ |
| 5944 | @Nullable |
| 5945 | public final Signature[] pastSigningCertificates; |
| 5946 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5947 | /** special value used to see if cert is in package - not exposed to callers */ |
| 5948 | private static final int PAST_CERT_EXISTS = 0; |
| 5949 | |
| 5950 | @IntDef( |
| 5951 | flag = true, |
| 5952 | value = {CertCapabilities.INSTALLED_DATA, |
| 5953 | CertCapabilities.SHARED_USER_ID, |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 5954 | CertCapabilities.PERMISSION, |
| 5955 | CertCapabilities.ROLLBACK}) |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5956 | public @interface CertCapabilities { |
| 5957 | |
| 5958 | /** accept data from already installed pkg with this cert */ |
| 5959 | int INSTALLED_DATA = 1; |
| 5960 | |
| 5961 | /** accept sharedUserId with pkg with this cert */ |
| 5962 | int SHARED_USER_ID = 2; |
| 5963 | |
| 5964 | /** grant SIGNATURE permissions to pkgs with this cert */ |
| 5965 | int PERMISSION = 4; |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 5966 | |
| 5967 | /** allow pkg to update to one signed by this certificate */ |
| 5968 | int ROLLBACK = 8; |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 5969 | |
| 5970 | /** allow pkg to continue to have auth access gated by this cert */ |
| 5971 | int AUTH = 16; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5972 | } |
| 5973 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5974 | /** A representation of unknown signing details. Use instead of null. */ |
| 5975 | public static final SigningDetails UNKNOWN = |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 5976 | new SigningDetails(null, SignatureSchemeVersion.UNKNOWN, null, null); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5977 | |
| 5978 | @VisibleForTesting |
| 5979 | public SigningDetails(Signature[] signatures, |
| 5980 | @SignatureSchemeVersion int signatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 5981 | ArraySet<PublicKey> keys, Signature[] pastSigningCertificates) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5982 | this.signatures = signatures; |
| 5983 | this.signatureSchemeVersion = signatureSchemeVersion; |
| 5984 | this.publicKeys = keys; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5985 | this.pastSigningCertificates = pastSigningCertificates; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | public SigningDetails(Signature[] signatures, |
| 5989 | @SignatureSchemeVersion int signatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 5990 | Signature[] pastSigningCertificates) |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5991 | throws CertificateException { |
| 5992 | this(signatures, signatureSchemeVersion, toSigningKeys(signatures), |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 5993 | pastSigningCertificates); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | public SigningDetails(Signature[] signatures, |
| 5997 | @SignatureSchemeVersion int signatureSchemeVersion) |
| 5998 | throws CertificateException { |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 5999 | this(signatures, signatureSchemeVersion, null); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | public SigningDetails(SigningDetails orig) { |
| 6003 | if (orig != null) { |
| 6004 | if (orig.signatures != null) { |
| 6005 | this.signatures = orig.signatures.clone(); |
| 6006 | } else { |
| 6007 | this.signatures = null; |
| 6008 | } |
| 6009 | this.signatureSchemeVersion = orig.signatureSchemeVersion; |
| 6010 | this.publicKeys = new ArraySet<>(orig.publicKeys); |
| 6011 | if (orig.pastSigningCertificates != null) { |
| 6012 | this.pastSigningCertificates = orig.pastSigningCertificates.clone(); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6013 | } else { |
| 6014 | this.pastSigningCertificates = null; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6015 | } |
| 6016 | } else { |
| 6017 | this.signatures = null; |
| 6018 | this.signatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 6019 | this.publicKeys = null; |
| 6020 | this.pastSigningCertificates = null; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6021 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | /** Returns true if the signing details have one or more signatures. */ |
| 6025 | public boolean hasSignatures() { |
| 6026 | return signatures != null && signatures.length > 0; |
| 6027 | } |
| 6028 | |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 6029 | /** Returns true if the signing details have past signing certificates. */ |
| 6030 | public boolean hasPastSigningCertificates() { |
| 6031 | return pastSigningCertificates != null && pastSigningCertificates.length > 0; |
| 6032 | } |
| 6033 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6034 | /** |
| 6035 | * Determines if the provided {@code oldDetails} is an ancestor of or the same as this one. |
| 6036 | * If the {@code oldDetails} signing certificate appears in our pastSigningCertificates, |
| 6037 | * then that means it has authorized a signing certificate rotation, which eventually leads |
| 6038 | * to our certificate, and thus can be trusted. If this method evaluates to true, this |
| 6039 | * SigningDetails object should be trusted if the previous one is. |
| 6040 | */ |
| 6041 | public boolean hasAncestorOrSelf(SigningDetails oldDetails) { |
| 6042 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6043 | return false; |
| 6044 | } |
| 6045 | if (oldDetails.signatures.length > 1) { |
| 6046 | |
| 6047 | // multiple-signer packages cannot rotate signing certs, so we just compare current |
| 6048 | // signers for an exact match |
| 6049 | return signaturesMatchExactly(oldDetails); |
| 6050 | } else { |
| 6051 | |
| 6052 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 6053 | // was one of our old signing certificates |
| 6054 | return hasCertificate(oldDetails.signatures[0]); |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | /** |
| 6059 | * Similar to {@code hasAncestorOrSelf}. Returns true only if this {@code SigningDetails} |
| 6060 | * is a descendant of {@code oldDetails}, not if they're the same. This is used to |
| 6061 | * determine if this object is newer than the provided one. |
| 6062 | */ |
| 6063 | public boolean hasAncestor(SigningDetails oldDetails) { |
| 6064 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6065 | return false; |
| 6066 | } |
| 6067 | if (this.hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 6068 | |
| 6069 | // the last entry in pastSigningCertificates is the current signer, ignore it |
| 6070 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6071 | if (pastSigningCertificates[i].equals(oldDetails.signatures[i])) { |
| 6072 | return true; |
| 6073 | } |
| 6074 | } |
| 6075 | } |
| 6076 | return false; |
| 6077 | } |
| 6078 | |
| 6079 | /** |
| 6080 | * Determines if the provided {@code oldDetails} is an ancestor of this one, and whether or |
| 6081 | * not this one grants it the provided capability, represented by the {@code flags} |
| 6082 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 6083 | * with entities signed by its old signing certificate and not want to break previously |
| 6084 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 6085 | * signed by the newer signing certificate would like to continue to give to its previous |
| 6086 | * signing certificate(s). |
| 6087 | */ |
| 6088 | public boolean checkCapability(SigningDetails oldDetails, @CertCapabilities int flags) { |
| 6089 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6090 | return false; |
| 6091 | } |
| 6092 | if (oldDetails.signatures.length > 1) { |
| 6093 | |
| 6094 | // multiple-signer packages cannot rotate signing certs, so we must have an exact |
| 6095 | // match, which also means all capabilities are granted |
| 6096 | return signaturesMatchExactly(oldDetails); |
| 6097 | } else { |
| 6098 | |
| 6099 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 6100 | // was one of our old signing certificates, and if we grant it the capability it's |
| 6101 | // requesting |
| 6102 | return hasCertificate(oldDetails.signatures[0], flags); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
| 6107 | * A special case of {@code checkCapability} which re-encodes both sets of signing |
| 6108 | * certificates to counteract a previous re-encoding. |
| 6109 | */ |
| 6110 | public boolean checkCapabilityRecover(SigningDetails oldDetails, |
| 6111 | @CertCapabilities int flags) throws CertificateException { |
| 6112 | if (oldDetails == UNKNOWN || this == UNKNOWN) { |
| 6113 | return false; |
| 6114 | } |
| 6115 | if (hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 6116 | |
| 6117 | // signing certificates may have rotated, check entire history for effective match |
| 6118 | for (int i = 0; i < pastSigningCertificates.length; i++) { |
| 6119 | if (Signature.areEffectiveMatch( |
| 6120 | oldDetails.signatures[0], |
| 6121 | pastSigningCertificates[i]) |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6122 | && pastSigningCertificates[i].getFlags() == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6123 | return true; |
| 6124 | } |
| 6125 | } |
| 6126 | } else { |
| 6127 | return Signature.areEffectiveMatch(oldDetails.signatures, signatures); |
| 6128 | } |
| 6129 | return false; |
| 6130 | } |
| 6131 | |
| 6132 | /** |
| 6133 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 6134 | * including the current signer. Automatically returns false if this object has multiple |
| 6135 | * signing certificates, since rotation is only supported for single-signers; this is |
| 6136 | * enforced by {@code hasCertificateInternal}. |
| 6137 | */ |
| 6138 | public boolean hasCertificate(Signature signature) { |
| 6139 | return hasCertificateInternal(signature, PAST_CERT_EXISTS); |
| 6140 | } |
| 6141 | |
| 6142 | /** |
| 6143 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 6144 | * including the current signer, and whether or not it has the given permission. |
| 6145 | * Certificates which match our current signer automatically get all capabilities. |
| 6146 | * Automatically returns false if this object has multiple signing certificates, since |
| 6147 | * rotation is only supported for single-signers. |
| 6148 | */ |
| 6149 | public boolean hasCertificate(Signature signature, @CertCapabilities int flags) { |
| 6150 | return hasCertificateInternal(signature, flags); |
| 6151 | } |
| 6152 | |
| 6153 | /** Convenient wrapper for calling {@code hasCertificate} with certificate's raw bytes. */ |
| 6154 | public boolean hasCertificate(byte[] certificate) { |
| 6155 | Signature signature = new Signature(certificate); |
| 6156 | return hasCertificate(signature); |
| 6157 | } |
| 6158 | |
| 6159 | private boolean hasCertificateInternal(Signature signature, int flags) { |
| 6160 | if (this == UNKNOWN) { |
| 6161 | return false; |
| 6162 | } |
| 6163 | |
| 6164 | // only single-signed apps can have pastSigningCertificates |
| 6165 | if (hasPastSigningCertificates()) { |
| 6166 | |
| 6167 | // check all past certs, except for the current one, which automatically gets all |
| 6168 | // capabilities, since it is the same as the current signature |
| 6169 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6170 | if (pastSigningCertificates[i].equals(signature)) { |
| 6171 | if (flags == PAST_CERT_EXISTS |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6172 | || (flags & pastSigningCertificates[i].getFlags()) == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6173 | return true; |
| 6174 | } |
| 6175 | } |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | // not in previous certs signing history, just check the current signer and make sure |
| 6180 | // we are singly-signed |
| 6181 | return signatures.length == 1 && signatures[0].equals(signature); |
| 6182 | } |
| 6183 | |
| 6184 | /** |
| 6185 | * Determines if the provided {@code sha256String} is an ancestor of this one, and whether |
| 6186 | * or not this one grants it the provided capability, represented by the {@code flags} |
| 6187 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 6188 | * with entities signed by its old signing certificate and not want to break previously |
| 6189 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 6190 | * signed by the newer signing certificate would like to continue to give to its previous |
| 6191 | * signing certificate(s). |
| 6192 | * |
| 6193 | * @param sha256String A hex-encoded representation of a sha256 digest. In the case of an |
| 6194 | * app with multiple signers, this represents the hex-encoded sha256 |
| 6195 | * digest of the combined hex-encoded sha256 digests of each individual |
| 6196 | * signing certificate according to {@link |
| 6197 | * PackageUtils#computeSignaturesSha256Digest(Signature[])} |
| 6198 | */ |
| 6199 | public boolean checkCapability(String sha256String, @CertCapabilities int flags) { |
| 6200 | if (this == UNKNOWN) { |
| 6201 | return false; |
| 6202 | } |
| 6203 | |
| 6204 | // first see if the hash represents a single-signer in our signing history |
Neil Fuller | 2c7cc6e | 2019-04-11 11:04:06 +0100 | [diff] [blame] | 6205 | byte[] sha256Bytes = sha256String == null |
| 6206 | ? null : HexEncoding.decode(sha256String, false /* allowSingleChar */); |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6207 | if (hasSha256Certificate(sha256Bytes, flags)) { |
| 6208 | return true; |
| 6209 | } |
| 6210 | |
| 6211 | // Not in signing history, either represents multiple signatures or not a match. |
| 6212 | // Multiple signers can't rotate, so no need to check flags, just see if the SHAs match. |
| 6213 | // We already check the single-signer case above as part of hasSha256Certificate, so no |
| 6214 | // need to verify we have multiple signers, just run the old check |
| 6215 | // just consider current signing certs |
| 6216 | final String[] mSignaturesSha256Digests = |
| 6217 | PackageUtils.computeSignaturesSha256Digests(signatures); |
| 6218 | final String mSignaturesSha256Digest = |
| 6219 | PackageUtils.computeSignaturesSha256Digest(mSignaturesSha256Digests); |
| 6220 | return mSignaturesSha256Digest.equals(sha256String); |
| 6221 | } |
| 6222 | |
| 6223 | /** |
| 6224 | * Determine if the {@code sha256Certificate} is in this SigningDetails' signing certificate |
| 6225 | * history, including the current signer. Automatically returns false if this object has |
| 6226 | * multiple signing certificates, since rotation is only supported for single-signers. |
| 6227 | */ |
| 6228 | public boolean hasSha256Certificate(byte[] sha256Certificate) { |
| 6229 | return hasSha256CertificateInternal(sha256Certificate, PAST_CERT_EXISTS); |
| 6230 | } |
| 6231 | |
| 6232 | /** |
| 6233 | * Determine if the {@code sha256Certificate} certificate hash corresponds to a signing |
| 6234 | * certificate in this SigningDetails' signing certificate history, including the current |
| 6235 | * signer, and whether or not it has the given permission. Certificates which match our |
| 6236 | * current signer automatically get all capabilities. Automatically returns false if this |
| 6237 | * object has multiple signing certificates, since rotation is only supported for |
| 6238 | * single-signers. |
| 6239 | */ |
| 6240 | public boolean hasSha256Certificate(byte[] sha256Certificate, @CertCapabilities int flags) { |
| 6241 | return hasSha256CertificateInternal(sha256Certificate, flags); |
| 6242 | } |
| 6243 | |
| 6244 | private boolean hasSha256CertificateInternal(byte[] sha256Certificate, int flags) { |
| 6245 | if (this == UNKNOWN) { |
| 6246 | return false; |
| 6247 | } |
| 6248 | if (hasPastSigningCertificates()) { |
| 6249 | |
| 6250 | // check all past certs, except for the last one, which automatically gets all |
| 6251 | // capabilities, since it is the same as the current signature, and is checked below |
| 6252 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6253 | byte[] digest = PackageUtils.computeSha256DigestBytes( |
| 6254 | pastSigningCertificates[i].toByteArray()); |
| 6255 | if (Arrays.equals(sha256Certificate, digest)) { |
| 6256 | if (flags == PAST_CERT_EXISTS |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6257 | || (flags & pastSigningCertificates[i].getFlags()) == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6258 | return true; |
| 6259 | } |
| 6260 | } |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | // not in previous certs signing history, just check the current signer |
| 6265 | if (signatures.length == 1) { |
| 6266 | byte[] digest = |
| 6267 | PackageUtils.computeSha256DigestBytes(signatures[0].toByteArray()); |
| 6268 | return Arrays.equals(sha256Certificate, digest); |
| 6269 | } |
| 6270 | return false; |
| 6271 | } |
| 6272 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6273 | /** Returns true if the signatures in this and other match exactly. */ |
| 6274 | public boolean signaturesMatchExactly(SigningDetails other) { |
| 6275 | return Signature.areExactMatch(this.signatures, other.signatures); |
| 6276 | } |
| 6277 | |
| 6278 | @Override |
| 6279 | public int describeContents() { |
| 6280 | return 0; |
| 6281 | } |
| 6282 | |
| 6283 | @Override |
| 6284 | public void writeToParcel(Parcel dest, int flags) { |
| 6285 | boolean isUnknown = UNKNOWN == this; |
| 6286 | dest.writeBoolean(isUnknown); |
| 6287 | if (isUnknown) { |
| 6288 | return; |
| 6289 | } |
| 6290 | dest.writeTypedArray(this.signatures, flags); |
| 6291 | dest.writeInt(this.signatureSchemeVersion); |
| 6292 | dest.writeArraySet(this.publicKeys); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6293 | dest.writeTypedArray(this.pastSigningCertificates, flags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | protected SigningDetails(Parcel in) { |
| 6297 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6298 | this.signatures = in.createTypedArray(Signature.CREATOR); |
| 6299 | this.signatureSchemeVersion = in.readInt(); |
| 6300 | this.publicKeys = (ArraySet<PublicKey>) in.readArraySet(boot); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6301 | this.pastSigningCertificates = in.createTypedArray(Signature.CREATOR); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6302 | } |
| 6303 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 6304 | public static final @android.annotation.NonNull Creator<SigningDetails> CREATOR = new Creator<SigningDetails>() { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6305 | @Override |
| 6306 | public SigningDetails createFromParcel(Parcel source) { |
| 6307 | if (source.readBoolean()) { |
| 6308 | return UNKNOWN; |
| 6309 | } |
| 6310 | return new SigningDetails(source); |
| 6311 | } |
| 6312 | |
| 6313 | @Override |
| 6314 | public SigningDetails[] newArray(int size) { |
| 6315 | return new SigningDetails[size]; |
| 6316 | } |
| 6317 | }; |
| 6318 | |
| 6319 | @Override |
| 6320 | public boolean equals(Object o) { |
| 6321 | if (this == o) return true; |
| 6322 | if (!(o instanceof SigningDetails)) return false; |
| 6323 | |
| 6324 | SigningDetails that = (SigningDetails) o; |
| 6325 | |
| 6326 | if (signatureSchemeVersion != that.signatureSchemeVersion) return false; |
| 6327 | if (!Signature.areExactMatch(signatures, that.signatures)) return false; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6328 | if (publicKeys != null) { |
| 6329 | if (!publicKeys.equals((that.publicKeys))) { |
| 6330 | return false; |
| 6331 | } |
| 6332 | } else if (that.publicKeys != null) { |
| 6333 | return false; |
| 6334 | } |
| 6335 | |
| 6336 | // can't use Signature.areExactMatch() because order matters with the past signing certs |
| 6337 | if (!Arrays.equals(pastSigningCertificates, that.pastSigningCertificates)) { |
| 6338 | return false; |
| 6339 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6340 | |
| 6341 | return true; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | @Override |
| 6345 | public int hashCode() { |
| 6346 | int result = +Arrays.hashCode(signatures); |
| 6347 | result = 31 * result + signatureSchemeVersion; |
| 6348 | result = 31 * result + (publicKeys != null ? publicKeys.hashCode() : 0); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6349 | result = 31 * result + Arrays.hashCode(pastSigningCertificates); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6350 | return result; |
| 6351 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6352 | |
| 6353 | /** |
| 6354 | * Builder of {@code SigningDetails} instances. |
| 6355 | */ |
| 6356 | public static class Builder { |
| 6357 | private Signature[] mSignatures; |
| 6358 | private int mSignatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 6359 | private Signature[] mPastSigningCertificates; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6360 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6361 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6362 | public Builder() { |
| 6363 | } |
| 6364 | |
| 6365 | /** get signing certificates used to sign the current APK */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6366 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6367 | public Builder setSignatures(Signature[] signatures) { |
| 6368 | mSignatures = signatures; |
| 6369 | return this; |
| 6370 | } |
| 6371 | |
| 6372 | /** set the signature scheme version used to sign the APK */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6373 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6374 | public Builder setSignatureSchemeVersion(int signatureSchemeVersion) { |
| 6375 | mSignatureSchemeVersion = signatureSchemeVersion; |
| 6376 | return this; |
| 6377 | } |
| 6378 | |
| 6379 | /** set the signing certificates by which the APK proved it can be authenticated */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6380 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6381 | public Builder setPastSigningCertificates(Signature[] pastSigningCertificates) { |
| 6382 | mPastSigningCertificates = pastSigningCertificates; |
| 6383 | return this; |
| 6384 | } |
| 6385 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6386 | private void checkInvariants() { |
| 6387 | // must have signatures and scheme version set |
| 6388 | if (mSignatures == null) { |
| 6389 | throw new IllegalStateException("SigningDetails requires the current signing" |
| 6390 | + " certificates."); |
| 6391 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6392 | } |
| 6393 | /** build a {@code SigningDetails} object */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6394 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6395 | public SigningDetails build() |
| 6396 | throws CertificateException { |
| 6397 | checkInvariants(); |
| 6398 | return new SigningDetails(mSignatures, mSignatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6399 | mPastSigningCertificates); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6400 | } |
| 6401 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6402 | } |
| 6403 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6404 | /** |
| 6405 | * Representation of a full package parsed from APK files on disk. A package |
| 6406 | * consists of a single base APK, and zero or more split APKs. |
| 6407 | */ |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6408 | public final static class Package implements Parcelable { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6409 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6410 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6411 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6412 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6413 | // The package name declared in the manifest as the package can be |
| 6414 | // renamed, for example static shared libs use synthetic package names. |
| 6415 | public String manifestPackageName; |
| 6416 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6417 | /** Names of any split APKs, ordered by parsed splitName */ |
| 6418 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6419 | |
| 6420 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6421 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 6422 | public String volumeUuid; |
| 6423 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6424 | /** |
| 6425 | * Path where this package was found on disk. For monolithic packages |
| 6426 | * this is path to single base APK file; for cluster packages this is |
| 6427 | * path to the cluster directory. |
| 6428 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6429 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6430 | |
| 6431 | /** Path of base APK */ |
| 6432 | public String baseCodePath; |
| 6433 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6434 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6435 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6436 | /** Revision code of base APK */ |
| 6437 | public int baseRevisionCode; |
| 6438 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 6439 | public int[] splitRevisionCodes; |
| 6440 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6441 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 6442 | public int[] splitFlags; |
| 6443 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 6444 | /** |
| 6445 | * Private flags of any split APKs; ordered by parsed splitName. |
| 6446 | * |
| 6447 | * {@hide} |
| 6448 | */ |
| 6449 | public int[] splitPrivateFlags; |
| 6450 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6451 | public boolean baseHardwareAccelerated; |
| 6452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | // For now we only support one application per package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6454 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6455 | public ApplicationInfo applicationInfo = new ApplicationInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6457 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6459 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6461 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6463 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6465 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6467 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6468 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6469 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 6471 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6472 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 6474 | |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 6475 | /** Permissions requested but not in the manifest. */ |
| 6476 | public final ArrayList<String> implicitPermissions = new ArrayList<>(); |
| 6477 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6478 | @UnsupportedAppUsage |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 6479 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6480 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6481 | public Package parentPackage; |
| 6482 | public ArrayList<Package> childPackages; |
| 6483 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6484 | public String staticSharedLibName = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6485 | public long staticSharedLibVersion = 0; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6486 | public ArrayList<String> libraryNames = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6487 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6488 | public ArrayList<String> usesLibraries = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6489 | public ArrayList<String> usesStaticLibraries = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6490 | public long[] usesStaticLibrariesVersions = null; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6491 | public String[][] usesStaticLibrariesCertDigests = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6492 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6493 | public ArrayList<String> usesOptionalLibraries = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6494 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | public String[] usesLibraryFiles = null; |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 6496 | public ArrayList<SharedLibraryInfo> usesLibraryInfos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 6498 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 6499 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 6500 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6501 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 6502 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | // We store the application meta-data independently to avoid multiple unwanted references |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6505 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | public Bundle mAppMetaData = null; |
| 6507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | // The version code declared for this package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6509 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6511 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6512 | // The major version code declared for this package. |
| 6513 | public int mVersionCodeMajor; |
| 6514 | |
| 6515 | // Return long containing mVersionCode and mVersionCodeMajor. |
| 6516 | public long getLongVersionCode() { |
| 6517 | return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); |
| 6518 | } |
| 6519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | // The version name declared for this package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6521 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6522 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | // The shared user id that this package wants to use. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6525 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6526 | public String mSharedUserId; |
| 6527 | |
| 6528 | // The shared user label that this package wants to use. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6529 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | public int mSharedUserLabel; |
| 6531 | |
| 6532 | // Signatures that were read from the package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6533 | @UnsupportedAppUsage |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6534 | @NonNull public SigningDetails mSigningDetails = SigningDetails.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | |
| 6536 | // For use by package manager service for quick lookup of |
| 6537 | // preferred up order. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6538 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | public int mPreferredOrder = 0; |
| 6540 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6541 | // 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] | 6542 | public long[] mLastPackageUsageTimeInMills = |
| 6543 | new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6544 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 6545 | // // User set enabled state. |
| 6546 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 6547 | // |
| 6548 | // // Whether the package has been stopped. |
| 6549 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 6550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | // Additional data supplied by callers. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6552 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6553 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 6554 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6555 | // Applications hardware preferences |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6556 | @UnsupportedAppUsage |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6557 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6559 | // Applications requested features |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6560 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6561 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 6562 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 6563 | // Applications requested feature groups |
| 6564 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 6565 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6566 | @UnsupportedAppUsage |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 6567 | public int installLocation; |
| 6568 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 6569 | public boolean coreApp; |
| 6570 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 6571 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 6572 | public boolean mRequiredForAllUsers; |
| 6573 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6574 | /* The restricted account authenticator type that is used by this application */ |
| 6575 | public String mRestrictedAccountType; |
| 6576 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 6577 | /* The required account type without which this application will not function */ |
| 6578 | public String mRequiredAccountType; |
| 6579 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6580 | public String mOverlayTarget; |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 6581 | public String mOverlayTargetName; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 6582 | public String mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6583 | public int mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6584 | public boolean mOverlayIsStatic; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6585 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6586 | public int mCompileSdkVersion; |
| 6587 | public String mCompileSdkVersionCodename; |
| 6588 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6589 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6590 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6591 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6592 | @UnsupportedAppUsage |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6593 | public ArraySet<String> mUpgradeKeySets; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6594 | @UnsupportedAppUsage |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6595 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6596 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6597 | /** |
| 6598 | * The install time abi override for this package, if any. |
| 6599 | * |
| 6600 | * TODO: This seems like a horrible place to put the abiOverride because |
| 6601 | * this isn't something the packageParser parsers. However, this fits in with |
| 6602 | * the rest of the PackageManager where package scanning randomly pushes |
| 6603 | * and prods fields out of {@code this.applicationInfo}. |
| 6604 | */ |
| 6605 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6606 | /** |
| 6607 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 6608 | * are present. This is only meaningfull for multiarch applications. |
| 6609 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 6610 | */ |
| 6611 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6612 | |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 6613 | public byte[] restrictUpdateHash; |
| 6614 | |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6615 | /** 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] | 6616 | public boolean visibleToInstantApps; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6617 | /** Whether or not the package is a stub and must be replaced by the full version. */ |
| 6618 | public boolean isStub; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 6619 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6620 | @UnsupportedAppUsage |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6621 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6622 | this.packageName = packageName; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6623 | this.manifestPackageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6624 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | applicationInfo.uid = -1; |
| 6626 | } |
| 6627 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6628 | public void setApplicationVolumeUuid(String volumeUuid) { |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6629 | final UUID storageUuid = StorageManager.convert(volumeUuid); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6630 | this.applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6631 | this.applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6632 | if (childPackages != null) { |
| 6633 | final int packageCount = childPackages.size(); |
| 6634 | for (int i = 0; i < packageCount; i++) { |
| 6635 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6636 | childPackages.get(i).applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6637 | } |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | public void setApplicationInfoCodePath(String codePath) { |
| 6642 | this.applicationInfo.setCodePath(codePath); |
| 6643 | if (childPackages != null) { |
| 6644 | final int packageCount = childPackages.size(); |
| 6645 | for (int i = 0; i < packageCount; i++) { |
| 6646 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 6647 | } |
| 6648 | } |
| 6649 | } |
| 6650 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6651 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6652 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6653 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 6654 | this.applicationInfo.setResourcePath(resourcePath); |
| 6655 | if (childPackages != null) { |
| 6656 | final int packageCount = childPackages.size(); |
| 6657 | for (int i = 0; i < packageCount; i++) { |
| 6658 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 6659 | } |
| 6660 | } |
| 6661 | } |
| 6662 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6663 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6664 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6665 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 6666 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 6667 | if (childPackages != null) { |
| 6668 | final int packageCount = childPackages.size(); |
| 6669 | for (int i = 0; i < packageCount; i++) { |
| 6670 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 6671 | } |
| 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 6676 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 6677 | if (childPackages != null) { |
| 6678 | final int packageCount = childPackages.size(); |
| 6679 | for (int i = 0; i < packageCount; i++) { |
| 6680 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 6681 | } |
| 6682 | } |
| 6683 | } |
| 6684 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 6685 | public List<String> getChildPackageNames() { |
| 6686 | if (childPackages == null) { |
| 6687 | return null; |
| 6688 | } |
| 6689 | final int childCount = childPackages.size(); |
| 6690 | final List<String> childPackageNames = new ArrayList<>(childCount); |
| 6691 | for (int i = 0; i < childCount; i++) { |
| 6692 | String childPackageName = childPackages.get(i).packageName; |
| 6693 | childPackageNames.add(childPackageName); |
| 6694 | } |
| 6695 | return childPackageNames; |
| 6696 | } |
| 6697 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6698 | public boolean hasChildPackage(String packageName) { |
| 6699 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 6700 | for (int i = 0; i < childCount; i++) { |
| 6701 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 6702 | return true; |
| 6703 | } |
| 6704 | } |
| 6705 | return false; |
| 6706 | } |
| 6707 | |
| 6708 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 6709 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 6710 | // Children have no splits |
| 6711 | } |
| 6712 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6713 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6714 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6715 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 6716 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 6717 | // Children have no splits |
| 6718 | } |
| 6719 | |
| 6720 | public void setSplitCodePaths(String[] codePaths) { |
| 6721 | this.splitCodePaths = codePaths; |
| 6722 | } |
| 6723 | |
| 6724 | public void setCodePath(String codePath) { |
| 6725 | this.codePath = codePath; |
| 6726 | if (childPackages != null) { |
| 6727 | final int packageCount = childPackages.size(); |
| 6728 | for (int i = 0; i < packageCount; i++) { |
| 6729 | childPackages.get(i).codePath = codePath; |
| 6730 | } |
| 6731 | } |
| 6732 | } |
| 6733 | |
| 6734 | public void setBaseCodePath(String baseCodePath) { |
| 6735 | this.baseCodePath = baseCodePath; |
| 6736 | if (childPackages != null) { |
| 6737 | final int packageCount = childPackages.size(); |
| 6738 | for (int i = 0; i < packageCount; i++) { |
| 6739 | childPackages.get(i).baseCodePath = baseCodePath; |
| 6740 | } |
| 6741 | } |
| 6742 | } |
| 6743 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6744 | /** Sets signing details on the package and any of its children. */ |
| 6745 | public void setSigningDetails(@NonNull SigningDetails signingDetails) { |
| 6746 | mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6747 | if (childPackages != null) { |
| 6748 | final int packageCount = childPackages.size(); |
| 6749 | for (int i = 0; i < packageCount; i++) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6750 | childPackages.get(i).mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6751 | } |
| 6752 | } |
| 6753 | } |
| 6754 | |
| 6755 | public void setVolumeUuid(String volumeUuid) { |
| 6756 | this.volumeUuid = volumeUuid; |
| 6757 | if (childPackages != null) { |
| 6758 | final int packageCount = childPackages.size(); |
| 6759 | for (int i = 0; i < packageCount; i++) { |
| 6760 | childPackages.get(i).volumeUuid = volumeUuid; |
| 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | public void setApplicationInfoFlags(int mask, int flags) { |
| 6766 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 6767 | if (childPackages != null) { |
| 6768 | final int packageCount = childPackages.size(); |
| 6769 | for (int i = 0; i < packageCount; i++) { |
| 6770 | childPackages.get(i).applicationInfo.flags = |
| 6771 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 6772 | } |
| 6773 | } |
| 6774 | } |
| 6775 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 6776 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6777 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6778 | if (childPackages != null) { |
| 6779 | final int packageCount = childPackages.size(); |
| 6780 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6781 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6782 | } |
| 6783 | } |
| 6784 | } |
| 6785 | |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 6786 | public boolean isLibrary() { |
| 6787 | return staticSharedLibName != null || !ArrayUtils.isEmpty(libraryNames); |
| 6788 | } |
| 6789 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6790 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6791 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6792 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6793 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6794 | Collections.addAll(paths, splitCodePaths); |
| 6795 | } |
| 6796 | return paths; |
| 6797 | } |
| 6798 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6799 | /** |
| 6800 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 6801 | * resource-only APKs. |
| 6802 | */ |
| 6803 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 6804 | ArrayList<String> paths = new ArrayList<>(); |
| 6805 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6806 | paths.add(baseCodePath); |
| 6807 | } |
| 6808 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6809 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 6810 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6811 | paths.add(splitCodePaths[i]); |
| 6812 | } |
| 6813 | } |
| 6814 | } |
| 6815 | return paths; |
| 6816 | } |
| 6817 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6818 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6819 | public void setPackageName(String newName) { |
| 6820 | packageName = newName; |
| 6821 | applicationInfo.packageName = newName; |
| 6822 | for (int i=permissions.size()-1; i>=0; i--) { |
| 6823 | permissions.get(i).setPackageName(newName); |
| 6824 | } |
| 6825 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 6826 | permissionGroups.get(i).setPackageName(newName); |
| 6827 | } |
| 6828 | for (int i=activities.size()-1; i>=0; i--) { |
| 6829 | activities.get(i).setPackageName(newName); |
| 6830 | } |
| 6831 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6832 | receivers.get(i).setPackageName(newName); |
| 6833 | } |
| 6834 | for (int i=providers.size()-1; i>=0; i--) { |
| 6835 | providers.get(i).setPackageName(newName); |
| 6836 | } |
| 6837 | for (int i=services.size()-1; i>=0; i--) { |
| 6838 | services.get(i).setPackageName(newName); |
| 6839 | } |
| 6840 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6841 | instrumentation.get(i).setPackageName(newName); |
| 6842 | } |
| 6843 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 6844 | |
| 6845 | public boolean hasComponentClassName(String name) { |
| 6846 | for (int i=activities.size()-1; i>=0; i--) { |
| 6847 | if (name.equals(activities.get(i).className)) { |
| 6848 | return true; |
| 6849 | } |
| 6850 | } |
| 6851 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6852 | if (name.equals(receivers.get(i).className)) { |
| 6853 | return true; |
| 6854 | } |
| 6855 | } |
| 6856 | for (int i=providers.size()-1; i>=0; i--) { |
| 6857 | if (name.equals(providers.get(i).className)) { |
| 6858 | return true; |
| 6859 | } |
| 6860 | } |
| 6861 | for (int i=services.size()-1; i>=0; i--) { |
| 6862 | if (name.equals(services.get(i).className)) { |
| 6863 | return true; |
| 6864 | } |
| 6865 | } |
| 6866 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6867 | if (name.equals(instrumentation.get(i).className)) { |
| 6868 | return true; |
| 6869 | } |
| 6870 | } |
| 6871 | return false; |
| 6872 | } |
| 6873 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6874 | /** @hide */ |
| 6875 | public boolean isExternal() { |
| 6876 | return applicationInfo.isExternal(); |
| 6877 | } |
| 6878 | |
| 6879 | /** @hide */ |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6880 | public boolean isForwardLocked() { |
Patrick Baumann | fc2851e | 2018-11-13 15:23:22 -0800 | [diff] [blame] | 6881 | return false; |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6882 | } |
| 6883 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6884 | /** @hide */ |
| 6885 | public boolean isOem() { |
| 6886 | return applicationInfo.isOem(); |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6887 | } |
| 6888 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6889 | /** @hide */ |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 6890 | public boolean isVendor() { |
| 6891 | return applicationInfo.isVendor(); |
| 6892 | } |
| 6893 | |
| 6894 | /** @hide */ |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 6895 | public boolean isProduct() { |
| 6896 | return applicationInfo.isProduct(); |
| 6897 | } |
| 6898 | |
| 6899 | /** @hide */ |
Jeongik Cha | f662983 | 2019-07-04 21:12:06 +0900 | [diff] [blame] | 6900 | public boolean isSystemExt() { |
| 6901 | return applicationInfo.isSystemExt(); |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | /** @hide */ |
MÃ¥rten Kongstad | 48c24cf | 2019-02-25 10:54:09 +0100 | [diff] [blame] | 6905 | public boolean isOdm() { |
| 6906 | return applicationInfo.isOdm(); |
| 6907 | } |
| 6908 | |
| 6909 | /** @hide */ |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6910 | public boolean isPrivileged() { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 6911 | return applicationInfo.isPrivilegedApp(); |
| 6912 | } |
| 6913 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6914 | /** @hide */ |
| 6915 | public boolean isSystem() { |
| 6916 | return applicationInfo.isSystemApp(); |
| 6917 | } |
| 6918 | |
| 6919 | /** @hide */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6920 | public boolean isUpdatedSystemApp() { |
| 6921 | return applicationInfo.isUpdatedSystemApp(); |
| 6922 | } |
| 6923 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6924 | /** @hide */ |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6925 | public boolean canHaveOatDir() { |
| 6926 | // The following app types CANNOT have oat directory |
| 6927 | // - non-updated system apps |
Patrick Baumann | fc2851e | 2018-11-13 15:23:22 -0800 | [diff] [blame] | 6928 | return !isSystem() || isUpdatedSystemApp(); |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6929 | } |
| 6930 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6931 | public boolean isMatch(int flags) { |
| 6932 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6933 | return isSystem(); |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6934 | } |
| 6935 | return true; |
| 6936 | } |
| 6937 | |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 6938 | public long getLatestPackageUseTimeInMills() { |
| 6939 | long latestUse = 0L; |
| 6940 | for (long use : mLastPackageUsageTimeInMills) { |
| 6941 | latestUse = Math.max(latestUse, use); |
| 6942 | } |
| 6943 | return latestUse; |
| 6944 | } |
| 6945 | |
David Brazdil | 90e2699 | 2016-04-18 14:08:52 +0100 | [diff] [blame] | 6946 | public long getLatestForegroundPackageUseTimeInMills() { |
| 6947 | int[] foregroundReasons = { |
| 6948 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, |
| 6949 | PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE |
| 6950 | }; |
| 6951 | |
| 6952 | long latestUse = 0L; |
| 6953 | for (int reason : foregroundReasons) { |
| 6954 | latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); |
| 6955 | } |
| 6956 | return latestUse; |
| 6957 | } |
| 6958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | public String toString() { |
| 6960 | return "Package{" |
| 6961 | + Integer.toHexString(System.identityHashCode(this)) |
| 6962 | + " " + packageName + "}"; |
| 6963 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6964 | |
| 6965 | @Override |
| 6966 | public int describeContents() { |
| 6967 | return 0; |
| 6968 | } |
| 6969 | |
| 6970 | public Package(Parcel dest) { |
| 6971 | // We use the boot classloader for all classes that we load. |
| 6972 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6973 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6974 | packageName = dest.readString().intern(); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6975 | manifestPackageName = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6976 | splitNames = dest.readStringArray(); |
| 6977 | volumeUuid = dest.readString(); |
| 6978 | codePath = dest.readString(); |
| 6979 | baseCodePath = dest.readString(); |
| 6980 | splitCodePaths = dest.readStringArray(); |
| 6981 | baseRevisionCode = dest.readInt(); |
| 6982 | splitRevisionCodes = dest.createIntArray(); |
| 6983 | splitFlags = dest.createIntArray(); |
| 6984 | splitPrivateFlags = dest.createIntArray(); |
| 6985 | baseHardwareAccelerated = (dest.readInt() == 1); |
| 6986 | applicationInfo = dest.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 6987 | if (applicationInfo.permission != null) { |
| 6988 | applicationInfo.permission = applicationInfo.permission.intern(); |
| 6989 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6990 | |
| 6991 | // We don't serialize the "owner" package and the application info object for each of |
| 6992 | // these components, in order to save space and to avoid circular dependencies while |
| 6993 | // serialization. We need to fix them all up here. |
| 6994 | dest.readParcelableList(permissions, boot); |
| 6995 | fixupOwner(permissions); |
| 6996 | dest.readParcelableList(permissionGroups, boot); |
| 6997 | fixupOwner(permissionGroups); |
| 6998 | dest.readParcelableList(activities, boot); |
| 6999 | fixupOwner(activities); |
| 7000 | dest.readParcelableList(receivers, boot); |
| 7001 | fixupOwner(receivers); |
| 7002 | dest.readParcelableList(providers, boot); |
| 7003 | fixupOwner(providers); |
| 7004 | dest.readParcelableList(services, boot); |
| 7005 | fixupOwner(services); |
| 7006 | dest.readParcelableList(instrumentation, boot); |
| 7007 | fixupOwner(instrumentation); |
| 7008 | |
| 7009 | dest.readStringList(requestedPermissions); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7010 | internStringArrayList(requestedPermissions); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 7011 | dest.readStringList(implicitPermissions); |
| 7012 | internStringArrayList(implicitPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7013 | protectedBroadcasts = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7014 | internStringArrayList(protectedBroadcasts); |
| 7015 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7016 | parentPackage = dest.readParcelable(boot); |
| 7017 | |
| 7018 | childPackages = new ArrayList<>(); |
| 7019 | dest.readParcelableList(childPackages, boot); |
| 7020 | if (childPackages.size() == 0) { |
| 7021 | childPackages = null; |
| 7022 | } |
| 7023 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7024 | staticSharedLibName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7025 | if (staticSharedLibName != null) { |
| 7026 | staticSharedLibName = staticSharedLibName.intern(); |
| 7027 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7028 | staticSharedLibVersion = dest.readLong(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7029 | libraryNames = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7030 | internStringArrayList(libraryNames); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7031 | usesLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7032 | internStringArrayList(usesLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7033 | usesOptionalLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7034 | internStringArrayList(usesOptionalLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7035 | usesLibraryFiles = dest.readStringArray(); |
| 7036 | |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7037 | usesLibraryInfos = dest.createTypedArrayList(SharedLibraryInfo.CREATOR); |
| 7038 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7039 | final int libCount = dest.readInt(); |
| 7040 | if (libCount > 0) { |
| 7041 | usesStaticLibraries = new ArrayList<>(libCount); |
| 7042 | dest.readStringList(usesStaticLibraries); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7043 | internStringArrayList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7044 | usesStaticLibrariesVersions = new long[libCount]; |
| 7045 | dest.readLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 7046 | usesStaticLibrariesCertDigests = new String[libCount][]; |
| 7047 | for (int i = 0; i < libCount; i++) { |
| 7048 | usesStaticLibrariesCertDigests[i] = dest.createStringArray(); |
| 7049 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7050 | } |
| 7051 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7052 | preferredActivityFilters = new ArrayList<>(); |
| 7053 | dest.readParcelableList(preferredActivityFilters, boot); |
| 7054 | if (preferredActivityFilters.size() == 0) { |
| 7055 | preferredActivityFilters = null; |
| 7056 | } |
| 7057 | |
| 7058 | mOriginalPackages = dest.createStringArrayList(); |
| 7059 | mRealPackage = dest.readString(); |
| 7060 | mAdoptPermissions = dest.createStringArrayList(); |
| 7061 | mAppMetaData = dest.readBundle(); |
| 7062 | mVersionCode = dest.readInt(); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 7063 | mVersionCodeMajor = dest.readInt(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7064 | mVersionName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7065 | if (mVersionName != null) { |
| 7066 | mVersionName = mVersionName.intern(); |
| 7067 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7068 | mSharedUserId = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7069 | if (mSharedUserId != null) { |
| 7070 | mSharedUserId = mSharedUserId.intern(); |
| 7071 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7072 | mSharedUserLabel = dest.readInt(); |
| 7073 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 7074 | mSigningDetails = dest.readParcelable(boot); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7075 | |
| 7076 | mPreferredOrder = dest.readInt(); |
| 7077 | |
| 7078 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 7079 | // is parsed from the APK. |
| 7080 | |
| 7081 | // Object mExtras is not persisted because it is not information that is read from |
| 7082 | // the APK, rather, it is supplied by callers. |
| 7083 | |
| 7084 | |
| 7085 | configPreferences = new ArrayList<>(); |
| 7086 | dest.readParcelableList(configPreferences, boot); |
| 7087 | if (configPreferences.size() == 0) { |
| 7088 | configPreferences = null; |
| 7089 | } |
| 7090 | |
| 7091 | reqFeatures = new ArrayList<>(); |
| 7092 | dest.readParcelableList(reqFeatures, boot); |
| 7093 | if (reqFeatures.size() == 0) { |
| 7094 | reqFeatures = null; |
| 7095 | } |
| 7096 | |
| 7097 | featureGroups = new ArrayList<>(); |
| 7098 | dest.readParcelableList(featureGroups, boot); |
| 7099 | if (featureGroups.size() == 0) { |
| 7100 | featureGroups = null; |
| 7101 | } |
| 7102 | |
| 7103 | installLocation = dest.readInt(); |
| 7104 | coreApp = (dest.readInt() == 1); |
| 7105 | mRequiredForAllUsers = (dest.readInt() == 1); |
| 7106 | mRestrictedAccountType = dest.readString(); |
| 7107 | mRequiredAccountType = dest.readString(); |
| 7108 | mOverlayTarget = dest.readString(); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 7109 | mOverlayTargetName = dest.readString(); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 7110 | mOverlayCategory = dest.readString(); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 7111 | mOverlayPriority = dest.readInt(); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 7112 | mOverlayIsStatic = (dest.readInt() == 1); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 7113 | mCompileSdkVersion = dest.readInt(); |
| 7114 | mCompileSdkVersionCodename = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7115 | mUpgradeKeySets = (ArraySet<String>) dest.readArraySet(boot); |
| 7116 | |
| 7117 | mKeySetMapping = readKeySetMapping(dest); |
| 7118 | |
| 7119 | cpuAbiOverride = dest.readString(); |
| 7120 | use32bitAbi = (dest.readInt() == 1); |
| 7121 | restrictUpdateHash = dest.createByteArray(); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 7122 | visibleToInstantApps = dest.readInt() == 1; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7123 | } |
| 7124 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7125 | private static void internStringArrayList(List<String> list) { |
| 7126 | if (list != null) { |
| 7127 | final int N = list.size(); |
| 7128 | for (int i = 0; i < N; ++i) { |
| 7129 | list.set(i, list.get(i).intern()); |
| 7130 | } |
| 7131 | } |
| 7132 | } |
| 7133 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7134 | /** |
| 7135 | * Sets the package owner and the the {@code applicationInfo} for every component |
| 7136 | * owner by this package. |
| 7137 | */ |
| 7138 | private void fixupOwner(List<? extends Component<?>> list) { |
| 7139 | if (list != null) { |
| 7140 | for (Component<?> c : list) { |
| 7141 | c.owner = this; |
| 7142 | if (c instanceof Activity) { |
| 7143 | ((Activity) c).info.applicationInfo = this.applicationInfo; |
| 7144 | } else if (c instanceof Service) { |
| 7145 | ((Service) c).info.applicationInfo = this.applicationInfo; |
| 7146 | } else if (c instanceof Provider) { |
| 7147 | ((Provider) c).info.applicationInfo = this.applicationInfo; |
| 7148 | } |
| 7149 | } |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | @Override |
| 7154 | public void writeToParcel(Parcel dest, int flags) { |
| 7155 | dest.writeString(packageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7156 | dest.writeString(manifestPackageName); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7157 | dest.writeStringArray(splitNames); |
| 7158 | dest.writeString(volumeUuid); |
| 7159 | dest.writeString(codePath); |
| 7160 | dest.writeString(baseCodePath); |
| 7161 | dest.writeStringArray(splitCodePaths); |
| 7162 | dest.writeInt(baseRevisionCode); |
| 7163 | dest.writeIntArray(splitRevisionCodes); |
| 7164 | dest.writeIntArray(splitFlags); |
| 7165 | dest.writeIntArray(splitPrivateFlags); |
| 7166 | dest.writeInt(baseHardwareAccelerated ? 1 : 0); |
| 7167 | dest.writeParcelable(applicationInfo, flags); |
| 7168 | |
| 7169 | dest.writeParcelableList(permissions, flags); |
| 7170 | dest.writeParcelableList(permissionGroups, flags); |
| 7171 | dest.writeParcelableList(activities, flags); |
| 7172 | dest.writeParcelableList(receivers, flags); |
| 7173 | dest.writeParcelableList(providers, flags); |
| 7174 | dest.writeParcelableList(services, flags); |
| 7175 | dest.writeParcelableList(instrumentation, flags); |
| 7176 | |
| 7177 | dest.writeStringList(requestedPermissions); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 7178 | dest.writeStringList(implicitPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7179 | dest.writeStringList(protectedBroadcasts); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 7180 | |
| 7181 | // TODO: This doesn't work: b/64295061 |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7182 | dest.writeParcelable(parentPackage, flags); |
| 7183 | dest.writeParcelableList(childPackages, flags); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 7184 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7185 | dest.writeString(staticSharedLibName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7186 | dest.writeLong(staticSharedLibVersion); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7187 | dest.writeStringList(libraryNames); |
| 7188 | dest.writeStringList(usesLibraries); |
| 7189 | dest.writeStringList(usesOptionalLibraries); |
| 7190 | dest.writeStringArray(usesLibraryFiles); |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7191 | dest.writeTypedList(usesLibraryInfos); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7192 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7193 | if (ArrayUtils.isEmpty(usesStaticLibraries)) { |
| 7194 | dest.writeInt(-1); |
| 7195 | } else { |
| 7196 | dest.writeInt(usesStaticLibraries.size()); |
| 7197 | dest.writeStringList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7198 | dest.writeLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 7199 | for (String[] usesStaticLibrariesCertDigest : usesStaticLibrariesCertDigests) { |
| 7200 | dest.writeStringArray(usesStaticLibrariesCertDigest); |
| 7201 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7202 | } |
| 7203 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7204 | dest.writeParcelableList(preferredActivityFilters, flags); |
| 7205 | |
| 7206 | dest.writeStringList(mOriginalPackages); |
| 7207 | dest.writeString(mRealPackage); |
| 7208 | dest.writeStringList(mAdoptPermissions); |
| 7209 | dest.writeBundle(mAppMetaData); |
| 7210 | dest.writeInt(mVersionCode); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 7211 | dest.writeInt(mVersionCodeMajor); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7212 | dest.writeString(mVersionName); |
| 7213 | dest.writeString(mSharedUserId); |
| 7214 | dest.writeInt(mSharedUserLabel); |
| 7215 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 7216 | dest.writeParcelable(mSigningDetails, flags); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7217 | |
| 7218 | dest.writeInt(mPreferredOrder); |
| 7219 | |
| 7220 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 7221 | // is parsed from the APK. |
| 7222 | |
| 7223 | // Object mExtras is not persisted because it is not information that is read from |
| 7224 | // the APK, rather, it is supplied by callers. |
| 7225 | |
| 7226 | dest.writeParcelableList(configPreferences, flags); |
| 7227 | dest.writeParcelableList(reqFeatures, flags); |
| 7228 | dest.writeParcelableList(featureGroups, flags); |
| 7229 | |
| 7230 | dest.writeInt(installLocation); |
| 7231 | dest.writeInt(coreApp ? 1 : 0); |
| 7232 | dest.writeInt(mRequiredForAllUsers ? 1 : 0); |
| 7233 | dest.writeString(mRestrictedAccountType); |
| 7234 | dest.writeString(mRequiredAccountType); |
| 7235 | dest.writeString(mOverlayTarget); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 7236 | dest.writeString(mOverlayTargetName); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 7237 | dest.writeString(mOverlayCategory); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 7238 | dest.writeInt(mOverlayPriority); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 7239 | dest.writeInt(mOverlayIsStatic ? 1 : 0); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 7240 | dest.writeInt(mCompileSdkVersion); |
| 7241 | dest.writeString(mCompileSdkVersionCodename); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7242 | dest.writeArraySet(mUpgradeKeySets); |
| 7243 | writeKeySetMapping(dest, mKeySetMapping); |
| 7244 | dest.writeString(cpuAbiOverride); |
| 7245 | dest.writeInt(use32bitAbi ? 1 : 0); |
| 7246 | dest.writeByteArray(restrictUpdateHash); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 7247 | dest.writeInt(visibleToInstantApps ? 1 : 0); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7248 | } |
| 7249 | |
| 7250 | |
| 7251 | /** |
| 7252 | * Writes the keyset mapping to the provided package. {@code null} mappings are permitted. |
| 7253 | */ |
| 7254 | private static void writeKeySetMapping( |
| 7255 | Parcel dest, ArrayMap<String, ArraySet<PublicKey>> keySetMapping) { |
| 7256 | if (keySetMapping == null) { |
| 7257 | dest.writeInt(-1); |
| 7258 | return; |
| 7259 | } |
| 7260 | |
| 7261 | final int N = keySetMapping.size(); |
| 7262 | dest.writeInt(N); |
| 7263 | |
| 7264 | for (int i = 0; i < N; i++) { |
| 7265 | dest.writeString(keySetMapping.keyAt(i)); |
| 7266 | ArraySet<PublicKey> keys = keySetMapping.valueAt(i); |
| 7267 | if (keys == null) { |
| 7268 | dest.writeInt(-1); |
| 7269 | continue; |
| 7270 | } |
| 7271 | |
| 7272 | final int M = keys.size(); |
| 7273 | dest.writeInt(M); |
| 7274 | for (int j = 0; j < M; j++) { |
| 7275 | dest.writeSerializable(keys.valueAt(j)); |
| 7276 | } |
| 7277 | } |
| 7278 | } |
| 7279 | |
| 7280 | /** |
| 7281 | * Reads a keyset mapping from the given parcel at the given data position. May return |
| 7282 | * {@code null} if the serialized mapping was {@code null}. |
| 7283 | */ |
| 7284 | private static ArrayMap<String, ArraySet<PublicKey>> readKeySetMapping(Parcel in) { |
| 7285 | final int N = in.readInt(); |
| 7286 | if (N == -1) { |
| 7287 | return null; |
| 7288 | } |
| 7289 | |
| 7290 | ArrayMap<String, ArraySet<PublicKey>> keySetMapping = new ArrayMap<>(); |
| 7291 | for (int i = 0; i < N; ++i) { |
| 7292 | String key = in.readString(); |
| 7293 | final int M = in.readInt(); |
| 7294 | if (M == -1) { |
| 7295 | keySetMapping.put(key, null); |
| 7296 | continue; |
| 7297 | } |
| 7298 | |
| 7299 | ArraySet<PublicKey> keys = new ArraySet<>(M); |
| 7300 | for (int j = 0; j < M; ++j) { |
| 7301 | PublicKey pk = (PublicKey) in.readSerializable(); |
| 7302 | keys.add(pk); |
| 7303 | } |
| 7304 | |
| 7305 | keySetMapping.put(key, keys); |
| 7306 | } |
| 7307 | |
| 7308 | return keySetMapping; |
| 7309 | } |
| 7310 | |
| 7311 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Package>() { |
| 7312 | public Package createFromParcel(Parcel in) { |
| 7313 | return new Package(in); |
| 7314 | } |
| 7315 | |
| 7316 | public Package[] newArray(int size) { |
| 7317 | return new Package[size]; |
| 7318 | } |
| 7319 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7320 | } |
| 7321 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7322 | public static abstract class Component<II extends IntentInfo> { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7323 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7324 | public final ArrayList<II> intents; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7325 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7326 | public final String className; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7327 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7328 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | public Bundle metaData; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7330 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7331 | public Package owner; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7332 | /** The order of this component in relation to its peers */ |
| 7333 | public int order; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7335 | ComponentName componentName; |
| 7336 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7337 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 7338 | public Component(Package owner, ArrayList<II> intents, String className) { |
| 7339 | this.owner = owner; |
| 7340 | this.intents = intents; |
| 7341 | this.className = className; |
| 7342 | } |
| 7343 | |
| 7344 | public Component(Package owner) { |
| 7345 | this.owner = owner; |
| 7346 | this.intents = null; |
| 7347 | this.className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7348 | } |
| 7349 | |
| 7350 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 7351 | owner = args.owner; |
| 7352 | intents = new ArrayList<II>(0); |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 7353 | if (parsePackageItemInfo(args.owner, outInfo, args.outError, args.tag, args.sa, |
| 7354 | true /*nameRequired*/, args.nameRes, args.labelRes, args.iconRes, |
| 7355 | args.roundIconRes, args.logoRes, args.bannerRes)) { |
| 7356 | className = outInfo.name; |
| 7357 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7358 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7359 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 7363 | this(args, (PackageItemInfo)outInfo); |
| 7364 | if (args.outError[0] != null) { |
| 7365 | return; |
| 7366 | } |
| 7367 | |
| 7368 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7369 | CharSequence pname; |
| 7370 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 7371 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 7372 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7373 | } else { |
| 7374 | // Some older apps have been seen to use a resource reference |
| 7375 | // here that on older builds was ignored (with a warning). We |
| 7376 | // need to continue to do this for them so they don't break. |
| 7377 | pname = args.sa.getNonResourceString(args.processRes); |
| 7378 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7379 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7380 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7381 | args.flags, args.sepProcesses, args.outError); |
| 7382 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7383 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 7384 | if (args.descriptionRes != 0) { |
| 7385 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 7386 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7387 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7388 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7389 | } |
| 7390 | |
| 7391 | public Component(Component<II> clone) { |
| 7392 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7393 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7394 | className = clone.className; |
| 7395 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7396 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7397 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7398 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7399 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7400 | public ComponentName getComponentName() { |
| 7401 | if (componentName != null) { |
| 7402 | return componentName; |
| 7403 | } |
| 7404 | if (className != null) { |
| 7405 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 7406 | className); |
| 7407 | } |
| 7408 | return componentName; |
| 7409 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7410 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7411 | protected Component(Parcel in) { |
| 7412 | className = in.readString(); |
| 7413 | metaData = in.readBundle(); |
| 7414 | intents = createIntentsList(in); |
| 7415 | |
| 7416 | owner = null; |
| 7417 | } |
| 7418 | |
| 7419 | protected void writeToParcel(Parcel dest, int flags) { |
| 7420 | dest.writeString(className); |
| 7421 | dest.writeBundle(metaData); |
| 7422 | |
| 7423 | writeIntentsList(intents, dest, flags); |
| 7424 | } |
| 7425 | |
| 7426 | /** |
| 7427 | * <p> |
| 7428 | * Implementation note: The serialized form for the intent list also contains the name |
| 7429 | * of the concrete class that's stored in the list, and assumes that every element of the |
| 7430 | * list is of the same type. This is very similar to the original parcelable mechanism. |
| 7431 | * We cannot use that directly because IntentInfo extends IntentFilter, which is parcelable |
| 7432 | * and is public API. It also declares Parcelable related methods as final which means |
| 7433 | * we can't extend them. The approach of using composition instead of inheritance leads to |
| 7434 | * a large set of cascading changes in the PackageManagerService, which seem undesirable. |
| 7435 | * |
| 7436 | * <p> |
| 7437 | * <b>WARNING: </b> The list of objects returned by this function might need to be fixed up |
| 7438 | * to make sure their owner fields are consistent. See {@code fixupOwner}. |
| 7439 | */ |
| 7440 | private static void writeIntentsList(ArrayList<? extends IntentInfo> list, Parcel out, |
| 7441 | int flags) { |
| 7442 | if (list == null) { |
| 7443 | out.writeInt(-1); |
| 7444 | return; |
| 7445 | } |
| 7446 | |
| 7447 | final int N = list.size(); |
| 7448 | out.writeInt(N); |
| 7449 | |
| 7450 | // Don't bother writing the component name if the list is empty. |
| 7451 | if (N > 0) { |
| 7452 | IntentInfo info = list.get(0); |
| 7453 | out.writeString(info.getClass().getName()); |
| 7454 | |
| 7455 | for (int i = 0; i < N;i++) { |
| 7456 | list.get(i).writeIntentInfoToParcel(out, flags); |
| 7457 | } |
| 7458 | } |
| 7459 | } |
| 7460 | |
| 7461 | private static <T extends IntentInfo> ArrayList<T> createIntentsList(Parcel in) { |
| 7462 | int N = in.readInt(); |
| 7463 | if (N == -1) { |
| 7464 | return null; |
| 7465 | } |
| 7466 | |
| 7467 | if (N == 0) { |
| 7468 | return new ArrayList<>(0); |
| 7469 | } |
| 7470 | |
| 7471 | String componentName = in.readString(); |
| 7472 | final ArrayList<T> intentsList; |
| 7473 | try { |
| 7474 | final Class<T> cls = (Class<T>) Class.forName(componentName); |
| 7475 | final Constructor<T> cons = cls.getConstructor(Parcel.class); |
| 7476 | |
| 7477 | intentsList = new ArrayList<>(N); |
| 7478 | for (int i = 0; i < N; ++i) { |
| 7479 | intentsList.add(cons.newInstance(in)); |
| 7480 | } |
| 7481 | } catch (ReflectiveOperationException ree) { |
| 7482 | throw new AssertionError("Unable to construct intent list for: " + componentName); |
| 7483 | } |
| 7484 | |
| 7485 | return intentsList; |
| 7486 | } |
| 7487 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7488 | public void appendComponentShortName(StringBuilder sb) { |
| 7489 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7490 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7491 | |
| 7492 | public void printComponentShortName(PrintWriter pw) { |
| 7493 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 7494 | } |
| 7495 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7496 | public void setPackageName(String packageName) { |
| 7497 | componentName = null; |
| 7498 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | } |
| 7500 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7501 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7502 | public final static class Permission extends Component<IntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7503 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | public final PermissionInfo info; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7505 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7506 | public boolean tree; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7507 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | public PermissionGroup group; |
| 7509 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 7510 | /** |
| 7511 | * @hide |
| 7512 | */ |
| 7513 | public Permission(Package owner, @Nullable String backgroundPermission) { |
| 7514 | super(owner); |
| 7515 | info = new PermissionInfo(backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7516 | } |
| 7517 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7518 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | public Permission(Package _owner, PermissionInfo _info) { |
| 7520 | super(_owner); |
| 7521 | info = _info; |
| 7522 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7523 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7524 | public void setPackageName(String packageName) { |
| 7525 | super.setPackageName(packageName); |
| 7526 | info.packageName = packageName; |
| 7527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | |
| 7529 | public String toString() { |
| 7530 | return "Permission{" |
| 7531 | + Integer.toHexString(System.identityHashCode(this)) |
| 7532 | + " " + info.name + "}"; |
| 7533 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7534 | |
| 7535 | @Override |
| 7536 | public int describeContents() { |
| 7537 | return 0; |
| 7538 | } |
| 7539 | |
| 7540 | @Override |
| 7541 | public void writeToParcel(Parcel dest, int flags) { |
| 7542 | super.writeToParcel(dest, flags); |
| 7543 | dest.writeParcelable(info, flags); |
| 7544 | dest.writeInt(tree ? 1 : 0); |
| 7545 | dest.writeParcelable(group, flags); |
| 7546 | } |
| 7547 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 7548 | /** @hide */ |
| 7549 | public boolean isAppOp() { |
| 7550 | return info.isAppOp(); |
| 7551 | } |
| 7552 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7553 | private Permission(Parcel in) { |
| 7554 | super(in); |
| 7555 | final ClassLoader boot = Object.class.getClassLoader(); |
| 7556 | info = in.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7557 | if (info.group != null) { |
| 7558 | info.group = info.group.intern(); |
| 7559 | } |
| 7560 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7561 | tree = (in.readInt() == 1); |
| 7562 | group = in.readParcelable(boot); |
| 7563 | } |
| 7564 | |
| 7565 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Permission>() { |
| 7566 | public Permission createFromParcel(Parcel in) { |
| 7567 | return new Permission(in); |
| 7568 | } |
| 7569 | |
| 7570 | public Permission[] newArray(int size) { |
| 7571 | return new Permission[size]; |
| 7572 | } |
| 7573 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | } |
| 7575 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7576 | public final static class PermissionGroup extends Component<IntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7577 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | public final PermissionGroupInfo info; |
| 7579 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 7580 | public PermissionGroup(Package owner, @StringRes int requestDetailResourceId, |
| 7581 | @StringRes int backgroundRequestResourceId, |
| 7582 | @StringRes int backgroundRequestDetailResourceId) { |
| 7583 | super(owner); |
| 7584 | info = new PermissionGroupInfo(requestDetailResourceId, backgroundRequestResourceId, |
| 7585 | backgroundRequestDetailResourceId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 7589 | super(_owner); |
| 7590 | info = _info; |
| 7591 | } |
| 7592 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7593 | public void setPackageName(String packageName) { |
| 7594 | super.setPackageName(packageName); |
| 7595 | info.packageName = packageName; |
| 7596 | } |
| 7597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | public String toString() { |
| 7599 | return "PermissionGroup{" |
| 7600 | + Integer.toHexString(System.identityHashCode(this)) |
| 7601 | + " " + info.name + "}"; |
| 7602 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7603 | |
| 7604 | @Override |
| 7605 | public int describeContents() { |
| 7606 | return 0; |
| 7607 | } |
| 7608 | |
| 7609 | @Override |
| 7610 | public void writeToParcel(Parcel dest, int flags) { |
| 7611 | super.writeToParcel(dest, flags); |
| 7612 | dest.writeParcelable(info, flags); |
| 7613 | } |
| 7614 | |
| 7615 | private PermissionGroup(Parcel in) { |
| 7616 | super(in); |
| 7617 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7618 | } |
| 7619 | |
| 7620 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<PermissionGroup>() { |
| 7621 | public PermissionGroup createFromParcel(Parcel in) { |
| 7622 | return new PermissionGroup(in); |
| 7623 | } |
| 7624 | |
| 7625 | public PermissionGroup[] newArray(int size) { |
| 7626 | return new PermissionGroup[size]; |
| 7627 | } |
| 7628 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | } |
| 7630 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7631 | private static boolean copyNeeded(int flags, Package p, |
| 7632 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 7633 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7634 | // We always need to copy for other users, since we need |
| 7635 | // to fix up the uid. |
| 7636 | return true; |
| 7637 | } |
| 7638 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 7639 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 7640 | if (p.applicationInfo.enabled != enabled) { |
| 7641 | return true; |
| 7642 | } |
| 7643 | } |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 7644 | boolean suspended = (p.applicationInfo.flags & FLAG_SUSPENDED) != 0; |
| 7645 | if (state.suspended != suspended) { |
| 7646 | return true; |
| 7647 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7648 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7649 | return true; |
| 7650 | } |
| 7651 | if (state.stopped) { |
| 7652 | return true; |
| 7653 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7654 | if (state.instantApp != p.applicationInfo.isInstantApp()) { |
| 7655 | return true; |
| 7656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7657 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 7658 | && (metaData != null || p.mAppMetaData != null)) { |
| 7659 | return true; |
| 7660 | } |
| 7661 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7662 | && p.usesLibraryFiles != null) { |
| 7663 | return true; |
| 7664 | } |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7665 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7666 | && p.usesLibraryInfos != null) { |
| 7667 | return true; |
| 7668 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7669 | if (p.staticSharedLibName != null) { |
| 7670 | return true; |
| 7671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | return false; |
| 7673 | } |
| 7674 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7675 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7676 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 7677 | PackageUserState state) { |
| 7678 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 7679 | } |
| 7680 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7681 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 7682 | PackageUserState state) { |
| 7683 | // CompatibilityMode is global state. |
| 7684 | if (!sCompatibilityModeEnabled) { |
| 7685 | ai.disableCompatibilityMode(); |
| 7686 | } |
| 7687 | if (state.installed) { |
| 7688 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 7689 | } else { |
| 7690 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 7691 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 7692 | if (state.suspended) { |
| 7693 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 7694 | } else { |
| 7695 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 7696 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7697 | if (state.instantApp) { |
| 7698 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7699 | } else { |
| 7700 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7701 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 7702 | if (state.virtualPreload) { |
| 7703 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7704 | } else { |
| 7705 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7706 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7707 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7708 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7709 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7710 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7711 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7712 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 7713 | ai.enabled = true; |
| 7714 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 7715 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 7716 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 7717 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 7718 | ai.enabled = false; |
| 7719 | } |
| 7720 | ai.enabledSetting = state.enabled; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 7721 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7722 | ai.category = state.categoryHint; |
| 7723 | } |
Jeff Sharkey | 0078e1b | 2017-01-11 16:05:27 -0700 | [diff] [blame] | 7724 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7725 | ai.category = FallbackCategoryProvider.getFallbackCategory(ai.packageName); |
| 7726 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7727 | ai.seInfoUser = SELinuxUtil.assignSeinfoUser(state); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7728 | ai.resourceDirs = state.overlayPaths; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 7729 | ai.icon = (sUseRoundIcon && ai.roundIconRes != 0) ? ai.roundIconRes : ai.iconRes; |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7730 | } |
| 7731 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7732 | @UnsupportedAppUsage |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 7733 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7734 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7736 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7737 | return null; |
| 7738 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7739 | if (!copyNeeded(flags, p, state, null, userId) |
| 7740 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 7741 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 7742 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 7743 | // - CompatibilityMode is global state, so will be the same for every call. |
| 7744 | // - We only come in to here if the app should reported as installed; this is the |
| 7745 | // default state, and we will do a copy otherwise. |
| 7746 | // - The enable state will always be reported the same for the application across |
| 7747 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 7748 | // be doing a copy. |
| 7749 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | return p.applicationInfo; |
| 7751 | } |
| 7752 | |
| 7753 | // Make shallow copy so we can store the metadata/libraries safely |
| 7754 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7755 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 7757 | ai.metaData = p.mAppMetaData; |
| 7758 | } |
| 7759 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 7760 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
Nicolas Geoffray | 8d144eb | 2018-11-15 12:59:52 +0000 | [diff] [blame] | 7761 | ai.sharedLibraryInfos = p.usesLibraryInfos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7762 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7763 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7764 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7765 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7766 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7767 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7768 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7769 | return ai; |
| 7770 | } |
| 7771 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7772 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 7773 | PackageUserState state, int userId) { |
| 7774 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7775 | if (!checkUseInstalledOrHidden(flags, state, ai)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7776 | return null; |
| 7777 | } |
| 7778 | // This is only used to return the ResolverActivity; we will just always |
| 7779 | // make a copy. |
| 7780 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7781 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7782 | if (state.stopped) { |
| 7783 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 7784 | } else { |
| 7785 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 7786 | } |
| 7787 | updateApplicationInfo(ai, flags, state); |
| 7788 | return ai; |
| 7789 | } |
| 7790 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7791 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | public static final PermissionInfo generatePermissionInfo( |
| 7793 | Permission p, int flags) { |
| 7794 | if (p == null) return null; |
| 7795 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7796 | return p.info; |
| 7797 | } |
| 7798 | PermissionInfo pi = new PermissionInfo(p.info); |
| 7799 | pi.metaData = p.metaData; |
| 7800 | return pi; |
| 7801 | } |
| 7802 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7803 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 7805 | PermissionGroup pg, int flags) { |
| 7806 | if (pg == null) return null; |
| 7807 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7808 | return pg.info; |
| 7809 | } |
| 7810 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 7811 | pgi.metaData = pg.metaData; |
| 7812 | return pgi; |
| 7813 | } |
| 7814 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7815 | public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7816 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7817 | public final ActivityInfo info; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7818 | private boolean mHasMaxAspectRatio; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7819 | private boolean mHasMinAspectRatio; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7820 | |
| 7821 | private boolean hasMaxAspectRatio() { |
| 7822 | return mHasMaxAspectRatio; |
| 7823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7825 | private boolean hasMinAspectRatio() { |
| 7826 | return mHasMinAspectRatio; |
| 7827 | } |
| 7828 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 7829 | // To construct custom activity which does not exist in manifest |
| 7830 | Activity(final Package owner, final String className, final ActivityInfo info) { |
| 7831 | super(owner, new ArrayList<>(0), className); |
| 7832 | this.info = info; |
| 7833 | this.info.applicationInfo = owner.applicationInfo; |
| 7834 | } |
| 7835 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7836 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 7837 | super(args, _info); |
| 7838 | info = _info; |
| 7839 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7841 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7842 | public void setPackageName(String packageName) { |
| 7843 | super.setPackageName(packageName); |
| 7844 | info.packageName = packageName; |
| 7845 | } |
| 7846 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7847 | |
| 7848 | private void setMaxAspectRatio(float maxAspectRatio) { |
| 7849 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7850 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7851 | // Resizeable activities can be put in any aspect ratio. |
| 7852 | return; |
| 7853 | } |
| 7854 | |
| 7855 | if (maxAspectRatio < 1.0f && maxAspectRatio != 0) { |
| 7856 | // Ignore any value lesser than 1.0. |
| 7857 | return; |
| 7858 | } |
| 7859 | |
| 7860 | info.maxAspectRatio = maxAspectRatio; |
| 7861 | mHasMaxAspectRatio = true; |
| 7862 | } |
| 7863 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7864 | private void setMinAspectRatio(float minAspectRatio) { |
| 7865 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7866 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7867 | // Resizeable activities can be put in any aspect ratio. |
| 7868 | return; |
| 7869 | } |
| 7870 | |
| 7871 | if (minAspectRatio < 1.0f && minAspectRatio != 0) { |
| 7872 | // Ignore any value lesser than 1.0. |
| 7873 | return; |
| 7874 | } |
| 7875 | |
| 7876 | info.minAspectRatio = minAspectRatio; |
| 7877 | mHasMinAspectRatio = true; |
| 7878 | } |
| 7879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7881 | StringBuilder sb = new StringBuilder(128); |
| 7882 | sb.append("Activity{"); |
| 7883 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7884 | sb.append(' '); |
| 7885 | appendComponentShortName(sb); |
| 7886 | sb.append('}'); |
| 7887 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7888 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7889 | |
| 7890 | @Override |
| 7891 | public int describeContents() { |
| 7892 | return 0; |
| 7893 | } |
| 7894 | |
| 7895 | @Override |
| 7896 | public void writeToParcel(Parcel dest, int flags) { |
| 7897 | super.writeToParcel(dest, flags); |
| 7898 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7899 | dest.writeBoolean(mHasMaxAspectRatio); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7900 | dest.writeBoolean(mHasMinAspectRatio); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7901 | } |
| 7902 | |
| 7903 | private Activity(Parcel in) { |
| 7904 | super(in); |
| 7905 | info = in.readParcelable(Object.class.getClassLoader()); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7906 | mHasMaxAspectRatio = in.readBoolean(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7907 | mHasMinAspectRatio = in.readBoolean(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7908 | |
| 7909 | for (ActivityIntentInfo aii : intents) { |
| 7910 | aii.activity = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7911 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7912 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7913 | |
| 7914 | if (info.permission != null) { |
| 7915 | info.permission = info.permission.intern(); |
| 7916 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Activity>() { |
| 7920 | public Activity createFromParcel(Parcel in) { |
| 7921 | return new Activity(in); |
| 7922 | } |
| 7923 | |
| 7924 | public Activity[] newArray(int size) { |
| 7925 | return new Activity[size]; |
| 7926 | } |
| 7927 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7928 | } |
| 7929 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7930 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7931 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 7932 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7933 | if (a == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7934 | if (!checkUseInstalledOrHidden(flags, state, a.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7935 | return null; |
| 7936 | } |
| 7937 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7938 | updateApplicationInfo(a.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7939 | return a.info; |
| 7940 | } |
| 7941 | // Make shallow copies so we can store the metadata safely |
| 7942 | ActivityInfo ai = new ActivityInfo(a.info); |
| 7943 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7944 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | return ai; |
| 7946 | } |
| 7947 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7948 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 7949 | PackageUserState state, int userId) { |
| 7950 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7951 | if (!checkUseInstalledOrHidden(flags, state, ai.applicationInfo)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7952 | return null; |
| 7953 | } |
| 7954 | // This is only used to return the ResolverActivity; we will just always |
| 7955 | // make a copy. |
| 7956 | ai = new ActivityInfo(ai); |
| 7957 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 7958 | return ai; |
| 7959 | } |
| 7960 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7961 | public final static class Service extends Component<ServiceIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7962 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7963 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7965 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 7966 | super(args, _info); |
| 7967 | info = _info; |
| 7968 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7969 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7970 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7971 | public void setPackageName(String packageName) { |
| 7972 | super.setPackageName(packageName); |
| 7973 | info.packageName = packageName; |
| 7974 | } |
| 7975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7976 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7977 | StringBuilder sb = new StringBuilder(128); |
| 7978 | sb.append("Service{"); |
| 7979 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7980 | sb.append(' '); |
| 7981 | appendComponentShortName(sb); |
| 7982 | sb.append('}'); |
| 7983 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7985 | |
| 7986 | @Override |
| 7987 | public int describeContents() { |
| 7988 | return 0; |
| 7989 | } |
| 7990 | |
| 7991 | @Override |
| 7992 | public void writeToParcel(Parcel dest, int flags) { |
| 7993 | super.writeToParcel(dest, flags); |
| 7994 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 7995 | } |
| 7996 | |
| 7997 | private Service(Parcel in) { |
| 7998 | super(in); |
| 7999 | info = in.readParcelable(Object.class.getClassLoader()); |
| 8000 | |
| 8001 | for (ServiceIntentInfo aii : intents) { |
| 8002 | aii.service = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 8003 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8004 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8005 | |
| 8006 | if (info.permission != null) { |
| 8007 | info.permission = info.permission.intern(); |
| 8008 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8009 | } |
| 8010 | |
| 8011 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Service>() { |
| 8012 | public Service createFromParcel(Parcel in) { |
| 8013 | return new Service(in); |
| 8014 | } |
| 8015 | |
| 8016 | public Service[] newArray(int size) { |
| 8017 | return new Service[size]; |
| 8018 | } |
| 8019 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | } |
| 8021 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8022 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8023 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 8024 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | if (s == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 8026 | if (!checkUseInstalledOrHidden(flags, state, s.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8027 | return null; |
| 8028 | } |
| 8029 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 8030 | updateApplicationInfo(s.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | return s.info; |
| 8032 | } |
| 8033 | // Make shallow copies so we can store the metadata safely |
| 8034 | ServiceInfo si = new ServiceInfo(s.info); |
| 8035 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8036 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8037 | return si; |
| 8038 | } |
| 8039 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8040 | public final static class Provider extends Component<ProviderIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8041 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8042 | public final ProviderInfo info; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8043 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8044 | public boolean syncable; |
| 8045 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8046 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 8047 | super(args, _info); |
| 8048 | info = _info; |
| 8049 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | syncable = false; |
| 8051 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 8052 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8053 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8054 | public Provider(Provider existingProvider) { |
| 8055 | super(existingProvider); |
| 8056 | this.info = existingProvider.info; |
| 8057 | this.syncable = existingProvider.syncable; |
| 8058 | } |
| 8059 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8060 | public void setPackageName(String packageName) { |
| 8061 | super.setPackageName(packageName); |
| 8062 | info.packageName = packageName; |
| 8063 | } |
| 8064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8065 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8066 | StringBuilder sb = new StringBuilder(128); |
| 8067 | sb.append("Provider{"); |
| 8068 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8069 | sb.append(' '); |
| 8070 | appendComponentShortName(sb); |
| 8071 | sb.append('}'); |
| 8072 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8074 | |
| 8075 | @Override |
| 8076 | public int describeContents() { |
| 8077 | return 0; |
| 8078 | } |
| 8079 | |
| 8080 | @Override |
| 8081 | public void writeToParcel(Parcel dest, int flags) { |
| 8082 | super.writeToParcel(dest, flags); |
| 8083 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 8084 | dest.writeInt((syncable) ? 1 : 0); |
| 8085 | } |
| 8086 | |
| 8087 | private Provider(Parcel in) { |
| 8088 | super(in); |
| 8089 | info = in.readParcelable(Object.class.getClassLoader()); |
| 8090 | syncable = (in.readInt() == 1); |
| 8091 | |
| 8092 | for (ProviderIntentInfo aii : intents) { |
| 8093 | aii.provider = this; |
| 8094 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8095 | |
| 8096 | if (info.readPermission != null) { |
| 8097 | info.readPermission = info.readPermission.intern(); |
| 8098 | } |
| 8099 | |
| 8100 | if (info.writePermission != null) { |
| 8101 | info.writePermission = info.writePermission.intern(); |
| 8102 | } |
| 8103 | |
| 8104 | if (info.authority != null) { |
| 8105 | info.authority = info.authority.intern(); |
| 8106 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Provider>() { |
| 8110 | public Provider createFromParcel(Parcel in) { |
| 8111 | return new Provider(in); |
| 8112 | } |
| 8113 | |
| 8114 | public Provider[] newArray(int size) { |
| 8115 | return new Provider[size]; |
| 8116 | } |
| 8117 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | } |
| 8119 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8120 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8121 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 8122 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8123 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 8124 | if (!checkUseInstalledOrHidden(flags, state, p.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8125 | return null; |
| 8126 | } |
| 8127 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8129 | || p.info.uriPermissionPatterns == null)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 8130 | updateApplicationInfo(p.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8131 | return p.info; |
| 8132 | } |
| 8133 | // Make shallow copies so we can store the metadata safely |
| 8134 | ProviderInfo pi = new ProviderInfo(p.info); |
| 8135 | pi.metaData = p.metaData; |
| 8136 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 8137 | pi.uriPermissionPatterns = null; |
| 8138 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8139 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | return pi; |
| 8141 | } |
| 8142 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8143 | public final static class Instrumentation extends Component<IntentInfo> implements |
| 8144 | Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8145 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8146 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8148 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 8149 | super(args, _info); |
| 8150 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 8152 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8153 | public void setPackageName(String packageName) { |
| 8154 | super.setPackageName(packageName); |
| 8155 | info.packageName = packageName; |
| 8156 | } |
| 8157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8159 | StringBuilder sb = new StringBuilder(128); |
| 8160 | sb.append("Instrumentation{"); |
| 8161 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8162 | sb.append(' '); |
| 8163 | appendComponentShortName(sb); |
| 8164 | sb.append('}'); |
| 8165 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8167 | |
| 8168 | @Override |
| 8169 | public int describeContents() { |
| 8170 | return 0; |
| 8171 | } |
| 8172 | |
| 8173 | @Override |
| 8174 | public void writeToParcel(Parcel dest, int flags) { |
| 8175 | super.writeToParcel(dest, flags); |
| 8176 | dest.writeParcelable(info, flags); |
| 8177 | } |
| 8178 | |
| 8179 | private Instrumentation(Parcel in) { |
| 8180 | super(in); |
| 8181 | info = in.readParcelable(Object.class.getClassLoader()); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8182 | |
| 8183 | if (info.targetPackage != null) { |
| 8184 | info.targetPackage = info.targetPackage.intern(); |
| 8185 | } |
| 8186 | |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 8187 | if (info.targetProcesses != null) { |
| 8188 | info.targetProcesses = info.targetProcesses.intern(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8189 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8190 | } |
| 8191 | |
| 8192 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Instrumentation>() { |
| 8193 | public Instrumentation createFromParcel(Parcel in) { |
| 8194 | return new Instrumentation(in); |
| 8195 | } |
| 8196 | |
| 8197 | public Instrumentation[] newArray(int size) { |
| 8198 | return new Instrumentation[size]; |
| 8199 | } |
| 8200 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | } |
| 8202 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8203 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8204 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 8205 | Instrumentation i, int flags) { |
| 8206 | if (i == null) return null; |
| 8207 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 8208 | return i.info; |
| 8209 | } |
| 8210 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 8211 | ii.metaData = i.metaData; |
| 8212 | return ii; |
| 8213 | } |
| 8214 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8215 | public static abstract class IntentInfo extends IntentFilter { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8216 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8217 | public boolean hasDefault; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8218 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8219 | public int labelRes; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8220 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | public CharSequence nonLocalizedLabel; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8222 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8223 | public int icon; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8224 | @UnsupportedAppUsage |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 8225 | public int logo; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8226 | @UnsupportedAppUsage |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 8227 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 8228 | public int preferred; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8229 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8230 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8231 | protected IntentInfo() { |
| 8232 | } |
| 8233 | |
| 8234 | protected IntentInfo(Parcel dest) { |
| 8235 | super(dest); |
| 8236 | hasDefault = (dest.readInt() == 1); |
| 8237 | labelRes = dest.readInt(); |
| 8238 | nonLocalizedLabel = dest.readCharSequence(); |
| 8239 | icon = dest.readInt(); |
| 8240 | logo = dest.readInt(); |
| 8241 | banner = dest.readInt(); |
| 8242 | preferred = dest.readInt(); |
| 8243 | } |
| 8244 | |
| 8245 | |
| 8246 | public void writeIntentInfoToParcel(Parcel dest, int flags) { |
| 8247 | super.writeToParcel(dest, flags); |
| 8248 | dest.writeInt(hasDefault ? 1 : 0); |
| 8249 | dest.writeInt(labelRes); |
| 8250 | dest.writeCharSequence(nonLocalizedLabel); |
| 8251 | dest.writeInt(icon); |
| 8252 | dest.writeInt(logo); |
| 8253 | dest.writeInt(banner); |
| 8254 | dest.writeInt(preferred); |
| 8255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8256 | } |
| 8257 | |
| 8258 | public final static class ActivityIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8259 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8260 | public Activity activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8261 | |
| 8262 | public ActivityIntentInfo(Activity _activity) { |
| 8263 | activity = _activity; |
| 8264 | } |
| 8265 | |
| 8266 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8267 | StringBuilder sb = new StringBuilder(128); |
| 8268 | sb.append("ActivityIntentInfo{"); |
| 8269 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8270 | sb.append(' '); |
| 8271 | activity.appendComponentShortName(sb); |
| 8272 | sb.append('}'); |
| 8273 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8275 | |
| 8276 | public ActivityIntentInfo(Parcel in) { |
| 8277 | super(in); |
| 8278 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | public final static class ServiceIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8282 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8283 | public Service service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8284 | |
| 8285 | public ServiceIntentInfo(Service _service) { |
| 8286 | service = _service; |
| 8287 | } |
| 8288 | |
| 8289 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8290 | StringBuilder sb = new StringBuilder(128); |
| 8291 | sb.append("ServiceIntentInfo{"); |
| 8292 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8293 | sb.append(' '); |
| 8294 | service.appendComponentShortName(sb); |
| 8295 | sb.append('}'); |
| 8296 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8298 | |
| 8299 | public ServiceIntentInfo(Parcel in) { |
| 8300 | super(in); |
| 8301 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8302 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8303 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8304 | public static final class ProviderIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8305 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8306 | public Provider provider; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8307 | |
| 8308 | public ProviderIntentInfo(Provider provider) { |
| 8309 | this.provider = provider; |
| 8310 | } |
| 8311 | |
| 8312 | public String toString() { |
| 8313 | StringBuilder sb = new StringBuilder(128); |
| 8314 | sb.append("ProviderIntentInfo{"); |
| 8315 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8316 | sb.append(' '); |
| 8317 | provider.appendComponentShortName(sb); |
| 8318 | sb.append('}'); |
| 8319 | return sb.toString(); |
| 8320 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8321 | |
| 8322 | public ProviderIntentInfo(Parcel in) { |
| 8323 | super(in); |
| 8324 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8325 | } |
| 8326 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8327 | /** |
| 8328 | * @hide |
| 8329 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8330 | @UnsupportedAppUsage |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8331 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 8332 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 8333 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8334 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 8335 | /** |
| 8336 | * @hide |
| 8337 | */ |
| 8338 | public static void readConfigUseRoundIcon(Resources r) { |
| 8339 | if (r != null) { |
| 8340 | sUseRoundIcon = r.getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 8341 | return; |
| 8342 | } |
| 8343 | |
| 8344 | ApplicationInfo androidAppInfo; |
| 8345 | try { |
| 8346 | androidAppInfo = ActivityThread.getPackageManager().getApplicationInfo( |
| 8347 | "android", 0 /* flags */, |
| 8348 | UserHandle.myUserId()); |
| 8349 | } catch (RemoteException e) { |
| 8350 | throw e.rethrowFromSystemServer(); |
| 8351 | } |
| 8352 | Resources systemResources = Resources.getSystem(); |
| 8353 | |
| 8354 | // Create in-flight as this overlayable resource is only used when config changes |
| 8355 | Resources overlayableRes = ResourcesManager.getInstance().getResources(null, |
| 8356 | null, |
| 8357 | null, |
| 8358 | androidAppInfo.resourceDirs, |
| 8359 | androidAppInfo.sharedLibraryFiles, |
| 8360 | Display.DEFAULT_DISPLAY, |
| 8361 | null, |
| 8362 | systemResources.getCompatibilityInfo(), |
| 8363 | systemResources.getClassLoader()); |
| 8364 | |
| 8365 | sUseRoundIcon = overlayableRes.getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 8366 | } |
| 8367 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8368 | public static class PackageParserException extends Exception { |
| 8369 | public final int error; |
| 8370 | |
| 8371 | public PackageParserException(int error, String detailMessage) { |
| 8372 | super(detailMessage); |
| 8373 | this.error = error; |
| 8374 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 8375 | |
| 8376 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 8377 | super(detailMessage, throwable); |
| 8378 | this.error = error; |
| 8379 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8380 | } |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8381 | |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 8382 | // TODO(b/129261524): Clean up API |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8383 | /** |
| 8384 | * PackageInfo parser specifically for apex files. |
| 8385 | * NOTE: It will collect certificates |
| 8386 | * |
Gavin Corkery | ef44172 | 2019-05-09 17:02:10 +0100 | [diff] [blame] | 8387 | * @param apexInfo |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8388 | * @return PackageInfo |
| 8389 | * @throws PackageParserException |
| 8390 | */ |
Gavin Corkery | ef44172 | 2019-05-09 17:02:10 +0100 | [diff] [blame] | 8391 | public static PackageInfo generatePackageInfoFromApex(ApexInfo apexInfo, int flags) |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8392 | throws PackageParserException { |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8393 | PackageParser pp = new PackageParser(); |
Nikita Ioffe | b4eee2a | 2019-06-28 15:46:04 +0100 | [diff] [blame] | 8394 | File apexFile = new File(apexInfo.modulePath); |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8395 | final Package p = pp.parsePackage(apexFile, flags, false); |
| 8396 | PackageUserState state = new PackageUserState(); |
| 8397 | PackageInfo pi = generatePackageInfo(p, EmptyArray.INT, flags, 0, 0, |
| 8398 | Collections.emptySet(), state); |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8399 | pi.applicationInfo.sourceDir = apexFile.getPath(); |
Andrew Sapperstein | 93f5ed6 | 2019-06-20 15:25:19 -0700 | [diff] [blame] | 8400 | pi.applicationInfo.publicSourceDir = apexFile.getPath(); |
Gavin Corkery | ef44172 | 2019-05-09 17:02:10 +0100 | [diff] [blame] | 8401 | if (apexInfo.isFactory) { |
| 8402 | pi.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 8403 | } else { |
| 8404 | pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM; |
| 8405 | } |
| 8406 | if (apexInfo.isActive) { |
| 8407 | pi.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 8408 | } else { |
| 8409 | pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 8410 | } |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8411 | pi.isApex = true; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 8412 | |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8413 | // Collect certificates |
| 8414 | if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) { |
| 8415 | collectCertificates(p, apexFile, false); |
Todd Kennedy | 9c37cd2 | 2019-04-19 13:05:40 -0700 | [diff] [blame] | 8416 | // Keep legacy mechanism for handling signatures. While this is deprecated, it's |
| 8417 | // still part of the public API and needs to be maintained |
| 8418 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 8419 | // Package has included signing certificate rotation information. Return |
| 8420 | // the oldest cert so that programmatic checks keep working even if unaware |
| 8421 | // of key rotation. |
| 8422 | pi.signatures = new Signature[1]; |
| 8423 | pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0]; |
| 8424 | } else if (p.mSigningDetails.hasSignatures()) { |
| 8425 | // otherwise keep old behavior |
| 8426 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 8427 | pi.signatures = new Signature[numberOfSigs]; |
| 8428 | System.arraycopy(p.mSigningDetails.signatures, 0, pi.signatures, 0, numberOfSigs); |
| 8429 | } |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8430 | if (p.mSigningDetails != SigningDetails.UNKNOWN) { |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8431 | // only return a valid SigningInfo if there is signing information to report |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 8432 | pi.signingInfo = new SigningInfo(p.mSigningDetails); |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8433 | } else { |
| 8434 | pi.signingInfo = null; |
| 8435 | } |
| 8436 | } |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8437 | return pi; |
| 8438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8439 | } |