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; |
Anthony Hugh | 6f5eadc | 2019-08-22 15:35:48 -0700 | [diff] [blame] | 60 | import android.content.pm.permission.SplitPermissionInfoParcelable; |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 61 | import android.content.pm.split.DefaultSplitAssetLoader; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 62 | import android.content.pm.split.SplitAssetDependencyLoader; |
| 63 | import android.content.pm.split.SplitAssetLoader; |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 64 | import android.content.res.ApkAssets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.content.res.AssetManager; |
| 66 | import android.content.res.Configuration; |
| 67 | import android.content.res.Resources; |
| 68 | import android.content.res.TypedArray; |
| 69 | import android.content.res.XmlResourceParser; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 70 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Bundle; |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 72 | import android.os.FileUtils; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 73 | import android.os.Parcel; |
| 74 | import android.os.Parcelable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.PatternMatcher; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 76 | import android.os.RemoteException; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 77 | import android.os.SystemClock; |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 78 | import android.os.SystemProperties; |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 79 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 80 | import android.os.UserHandle; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 81 | import android.os.storage.StorageManager; |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 82 | import android.permission.PermissionManager; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 83 | import android.system.ErrnoException; |
| 84 | import android.system.OsConstants; |
| 85 | import android.system.StructStat; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 86 | import android.text.TextUtils; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 87 | import android.util.ArrayMap; |
| 88 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.util.AttributeSet; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 90 | import android.util.Base64; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.DisplayMetrics; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 92 | import android.util.Log; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 93 | import android.util.PackageUtils; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 94 | import android.util.Pair; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 95 | import android.util.Slog; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 96 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.TypedValue; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 98 | import android.util.apk.ApkSignatureVerifier; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 99 | import android.view.Display; |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 100 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 102 | import com.android.internal.R; |
| 103 | import com.android.internal.annotations.VisibleForTesting; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 104 | import com.android.internal.os.ClassLoaderFactory; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 105 | import com.android.internal.util.ArrayUtils; |
| 106 | import com.android.internal.util.XmlUtils; |
Anthony Hugh | 6f5eadc | 2019-08-22 15:35:48 -0700 | [diff] [blame] | 107 | import com.android.server.SystemConfig; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 108 | |
| 109 | import libcore.io.IoUtils; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 110 | import libcore.util.EmptyArray; |
Neil Fuller | 2c7cc6e | 2019-04-11 11:04:06 +0100 | [diff] [blame] | 111 | import libcore.util.HexEncoding; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 112 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 113 | import org.xmlpull.v1.XmlPullParser; |
| 114 | import org.xmlpull.v1.XmlPullParserException; |
| 115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import java.io.File; |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 117 | import java.io.FileDescriptor; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 118 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import java.io.IOException; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 120 | import java.io.PrintWriter; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 121 | import java.lang.annotation.Retention; |
| 122 | import java.lang.annotation.RetentionPolicy; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 123 | import java.lang.reflect.Constructor; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 124 | import java.security.KeyFactory; |
| 125 | import java.security.NoSuchAlgorithmException; |
| 126 | import java.security.PublicKey; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 127 | import java.security.cert.CertificateException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 128 | import java.security.spec.EncodedKeySpec; |
| 129 | import java.security.spec.InvalidKeySpecException; |
| 130 | import java.security.spec.X509EncodedKeySpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.util.ArrayList; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 132 | import java.util.Arrays; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 133 | import java.util.Collections; |
| 134 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.util.Iterator; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 136 | import java.util.List; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 137 | import java.util.Set; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 138 | import java.util.UUID; |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 139 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | |
| 141 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 142 | * Parser for package files (APKs) on disk. This supports apps packaged either |
| 143 | * as a single "monolithic" APK, or apps packaged as a "cluster" of multiple |
| 144 | * APKs in a single directory. |
| 145 | * <p> |
| 146 | * Apps packaged as multiple APKs always consist of a single "base" APK (with a |
| 147 | * {@code null} split name) and zero or more "split" APKs (with unique split |
| 148 | * names). Any subset of those split APKs are a valid install, as long as the |
| 149 | * following constraints are met: |
| 150 | * <ul> |
| 151 | * <li>All APKs must have the exact same package name, version code, and signing |
| 152 | * certificates. |
| 153 | * <li>All APKs must have unique split names. |
| 154 | * <li>All installations must contain a single base APK. |
| 155 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 157 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | */ |
| 159 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 160 | private static final boolean DEBUG_JAR = false; |
| 161 | private static final boolean DEBUG_PARSER = false; |
| 162 | private static final boolean DEBUG_BACKUP = false; |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 163 | private static final boolean LOG_PARSE_TIMINGS = Build.IS_DEBUGGABLE; |
| 164 | private static final int LOG_PARSE_TIMINGS_THRESHOLD_MS = 100; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 165 | |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 166 | private static final String PROPERTY_CHILD_PACKAGES_ENABLED = |
| 167 | "persist.sys.child_packages_enabled"; |
| 168 | |
Jeff Sharkey | 3f1790d | 2017-04-25 18:56:17 -0600 | [diff] [blame] | 169 | private static final boolean MULTI_PACKAGE_APK_ENABLED = Build.IS_DEBUGGABLE && |
Garrett Boyer | 1704153 | 2017-08-01 14:11:02 -0700 | [diff] [blame] | 170 | SystemProperties.getBoolean(PROPERTY_CHILD_PACKAGES_ENABLED, false); |
Svet Ganov | a3c4eb3 | 2017-04-19 23:51:33 -0700 | [diff] [blame] | 171 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 172 | private static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 173 | private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO = 1.333f; |
| 174 | private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO_WATCH = 1f; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 175 | |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 176 | private static final int DEFAULT_MIN_SDK_VERSION = 1; |
| 177 | private static final int DEFAULT_TARGET_SDK_VERSION = 0; |
| 178 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 179 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 180 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 181 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 182 | /** File name in an APK for the Android manifest. */ |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 183 | public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 184 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 185 | /** Path prefix for apps on expanded storage */ |
| 186 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 187 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 188 | private static final String TAG_MANIFEST = "manifest"; |
| 189 | private static final String TAG_APPLICATION = "application"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 190 | private static final String TAG_PACKAGE_VERIFIER = "package-verifier"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 191 | private static final String TAG_OVERLAY = "overlay"; |
| 192 | private static final String TAG_KEY_SETS = "key-sets"; |
| 193 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 194 | private static final String TAG_PERMISSION = "permission"; |
| 195 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 196 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 197 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 198 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 199 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 200 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 201 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 202 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 203 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 204 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 205 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 206 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 207 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 208 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 209 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 210 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 211 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 212 | private static final String TAG_PACKAGE = "package"; |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 213 | private static final String TAG_RESTRICT_UPDATE = "restrict-update"; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 214 | private static final String TAG_USES_SPLIT = "uses-split"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 215 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 216 | private static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect"; |
| 217 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 218 | /** |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 219 | * 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] | 220 | * @hide |
| 221 | */ |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 222 | private static final int RECREATE_ON_CONFIG_CHANGES_MASK = |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 223 | ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC; |
| 224 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 225 | // These are the tags supported by child packages |
| 226 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 227 | static { |
| 228 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 229 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 230 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 231 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 232 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 233 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 234 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 235 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 236 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 237 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 238 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 239 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 240 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 241 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 242 | } |
| 243 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 244 | private static final boolean LOG_UNSAFE_BROADCASTS = false; |
| 245 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 246 | /** |
| 247 | * Total number of packages that were read from the cache. We use it only for logging. |
| 248 | */ |
| 249 | public static final AtomicInteger sCachedPackageReadCount = new AtomicInteger(); |
| 250 | |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 251 | // Set of broadcast actions that are safe for manifest receivers |
| 252 | private static final Set<String> SAFE_BROADCASTS = new ArraySet<>(); |
| 253 | static { |
| 254 | SAFE_BROADCASTS.add(Intent.ACTION_BOOT_COMPLETED); |
| 255 | } |
| 256 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 257 | /** @hide */ |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 258 | public static final String APK_FILE_EXTENSION = ".apk"; |
Mohammad Samiul Islam | 73f1771 | 2019-07-05 14:47:17 +0100 | [diff] [blame] | 259 | /** @hide */ |
| 260 | public static final String APEX_FILE_EXTENSION = ".apex"; |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 261 | |
| 262 | /** @hide */ |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 263 | public static class NewPermissionInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 264 | @UnsupportedAppUsage |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 265 | public final String name; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 266 | @UnsupportedAppUsage |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 267 | public final int sdkVersion; |
| 268 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 269 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 270 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 271 | this.name = name; |
| 272 | this.sdkVersion = sdkVersion; |
| 273 | this.fileVersion = fileVersion; |
| 274 | } |
| 275 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 276 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 277 | /** |
| 278 | * List of new permissions that have been added since 1.0. |
| 279 | * NOTE: These must be declared in SDK version order, with permissions |
| 280 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 281 | * If sdkVersion is 0, then this is not a permission that we want to |
| 282 | * automatically add to older apps, but we do want to allow it to be |
| 283 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 284 | * @hide |
| 285 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 286 | @UnsupportedAppUsage |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 287 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 288 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 289 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 290 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 291 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 292 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 293 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 295 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 296 | * @deprecated callers should move to explicitly passing around source path. |
| 297 | */ |
| 298 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 302 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 303 | private DisplayMetrics mMetrics; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 304 | @UnsupportedAppUsage |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 305 | private Callback mCallback; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 306 | private File mCacheDir; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 307 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 308 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 309 | 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] | 310 | |
| 311 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 312 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 313 | private static boolean sCompatibilityModeEnabled = true; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 314 | private static boolean sUseRoundIcon = false; |
| 315 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 316 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 317 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 318 | private static final int PARSE_DEFAULT_TARGET_SANDBOX = 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 319 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 320 | static class ParsePackageItemArgs { |
| 321 | final Package owner; |
| 322 | final String[] outError; |
| 323 | final int nameRes; |
| 324 | final int labelRes; |
| 325 | final int iconRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 326 | final int roundIconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 327 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 328 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 329 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 330 | String tag; |
| 331 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 332 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 333 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 334 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 335 | int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 336 | owner = _owner; |
| 337 | outError = _outError; |
| 338 | nameRes = _nameRes; |
| 339 | labelRes = _labelRes; |
| 340 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 341 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 342 | bannerRes = _bannerRes; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 343 | roundIconRes = _roundIconRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 346 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 347 | /** @hide */ |
| 348 | @VisibleForTesting |
| 349 | public static class ParseComponentArgs extends ParsePackageItemArgs { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 350 | final String[] sepProcesses; |
| 351 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 352 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 353 | final int enabledRes; |
| 354 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 355 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 356 | public ParseComponentArgs(Package _owner, String[] _outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 357 | int _nameRes, int _labelRes, int _iconRes, int _roundIconRes, int _logoRes, |
| 358 | int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 359 | String[] _sepProcesses, int _processRes, |
| 360 | int _descriptionRes, int _enabledRes) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 361 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _roundIconRes, _logoRes, |
| 362 | _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 363 | sepProcesses = _sepProcesses; |
| 364 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 365 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 366 | enabledRes = _enabledRes; |
| 367 | } |
| 368 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 369 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 370 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 371 | * Lightweight parsed details about a single package. |
| 372 | */ |
| 373 | public static class PackageLite { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 374 | @UnsupportedAppUsage |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 375 | public final String packageName; |
| 376 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 377 | public final int versionCodeMajor; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 378 | @UnsupportedAppUsage |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 379 | public final int installLocation; |
| 380 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 381 | |
| 382 | /** Names of any split APKs, ordered by parsed splitName */ |
| 383 | public final String[] splitNames; |
| 384 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 385 | /** Names of any split APKs that are features. Ordered by splitName */ |
| 386 | public final boolean[] isFeatureSplits; |
| 387 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 388 | /** Dependencies of any split APKs, ordered by parsed splitName */ |
| 389 | public final String[] usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 390 | public final String[] configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 391 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 392 | /** |
| 393 | * Path where this package was found on disk. For monolithic packages |
| 394 | * this is path to single base APK file; for cluster packages this is |
| 395 | * path to the cluster directory. |
| 396 | */ |
| 397 | public final String codePath; |
| 398 | |
| 399 | /** Path of base APK */ |
| 400 | public final String baseCodePath; |
| 401 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 402 | public final String[] splitCodePaths; |
| 403 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 404 | /** Revision code of base APK */ |
| 405 | public final int baseRevisionCode; |
| 406 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 407 | public final int[] splitRevisionCodes; |
| 408 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 409 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 410 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 411 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 412 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 413 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 414 | public final boolean isolatedSplits; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 415 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 416 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 417 | boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 418 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 419 | this.packageName = baseApk.packageName; |
| 420 | this.versionCode = baseApk.versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 421 | this.versionCodeMajor = baseApk.versionCodeMajor; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 422 | this.installLocation = baseApk.installLocation; |
| 423 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 424 | this.splitNames = splitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 425 | this.isFeatureSplits = isFeatureSplits; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 426 | this.usesSplitNames = usesSplitNames; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 427 | this.configForSplit = configForSplit; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 428 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 429 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 430 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 431 | this.baseRevisionCode = baseApk.revisionCode; |
| 432 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 433 | this.coreApp = baseApk.coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 434 | this.debuggable = baseApk.debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 435 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 436 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 437 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 438 | this.isolatedSplits = baseApk.isolatedSplits; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | public List<String> getAllCodePaths() { |
| 442 | ArrayList<String> paths = new ArrayList<>(); |
| 443 | paths.add(baseCodePath); |
| 444 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 445 | Collections.addAll(paths, splitCodePaths); |
| 446 | } |
| 447 | return paths; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 452 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 453 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 454 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 455 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 456 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 457 | public final String splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 458 | public boolean isFeatureSplit; |
| 459 | public final String configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 460 | public final String usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 461 | public final int versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 462 | public final int versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 463 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 464 | public final int installLocation; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 465 | public final int minSdkVersion; |
| 466 | public final int targetSdkVersion; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 467 | public final VerifierInfo[] verifiers; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 468 | public final SigningDetails signingDetails; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 469 | public final boolean coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 470 | public final boolean debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 471 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 472 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 473 | public final boolean extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 474 | public final boolean isolatedSplits; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 475 | public final boolean isSplitRequired; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 476 | public final boolean useEmbeddedDex; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 477 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 478 | public ApkLite(String codePath, String packageName, String splitName, |
| 479 | boolean isFeatureSplit, |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 480 | String configForSplit, String usesSplitName, boolean isSplitRequired, |
| 481 | int versionCode, int versionCodeMajor, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 482 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 483 | SigningDetails signingDetails, boolean coreApp, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 484 | boolean debuggable, boolean multiArch, boolean use32bitAbi, |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 485 | boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits, |
| 486 | int minSdkVersion, int targetSdkVersion) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 487 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 488 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 489 | this.splitName = splitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 490 | this.isFeatureSplit = isFeatureSplit; |
| 491 | this.configForSplit = configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 492 | this.usesSplitName = usesSplitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 493 | this.versionCode = versionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 494 | this.versionCodeMajor = versionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 495 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 496 | this.installLocation = installLocation; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 497 | this.signingDetails = signingDetails; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 498 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 499 | this.coreApp = coreApp; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 500 | this.debuggable = debuggable; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 501 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 502 | this.use32bitAbi = use32bitAbi; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 503 | this.useEmbeddedDex = useEmbeddedDex; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 504 | this.extractNativeLibs = extractNativeLibs; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 505 | this.isolatedSplits = isolatedSplits; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 506 | this.isSplitRequired = isSplitRequired; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 507 | this.minSdkVersion = minSdkVersion; |
| 508 | this.targetSdkVersion = targetSdkVersion; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 509 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 510 | |
| 511 | public long getLongVersionCode() { |
| 512 | return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); |
| 513 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 516 | /** |
| 517 | * Cached parse state for new components. |
| 518 | * |
| 519 | * Allows reuse of the same parse argument records to avoid GC pressure. Lifetime is carefully |
| 520 | * scoped to the parsing of a single application element. |
| 521 | */ |
| 522 | private static class CachedComponentArgs { |
| 523 | ParseComponentArgs mActivityArgs; |
| 524 | ParseComponentArgs mActivityAliasArgs; |
| 525 | ParseComponentArgs mServiceArgs; |
| 526 | ParseComponentArgs mProviderArgs; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Cached state for parsing instrumentation to avoid GC pressure. |
| 531 | * |
| 532 | * Must be manually reset to null for each new manifest. |
| 533 | */ |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 534 | private ParsePackageItemArgs mParseInstrumentationArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | /** If set to true, we will only allow package files that exactly match |
| 537 | * the DTD. Otherwise, we try to get as much from the package as we |
| 538 | * can without failing. This should normally be set to false, to |
| 539 | * support extensions to the DTD in future versions. */ |
| 540 | private static final boolean RIGID_PARSER = false; |
| 541 | |
| 542 | private static final String TAG = "PackageParser"; |
| 543 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 544 | @UnsupportedAppUsage |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 545 | public PackageParser() { |
| 546 | mMetrics = new DisplayMetrics(); |
| 547 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 550 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | public void setSeparateProcesses(String[] procs) { |
| 552 | mSeparateProcesses = procs; |
| 553 | } |
| 554 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 555 | /** |
| 556 | * Flag indicating this parser should only consider apps with |
| 557 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 558 | * creating a minimalist boot environment. |
| 559 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 560 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 561 | mOnlyCoreApps = onlyCoreApps; |
| 562 | } |
| 563 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 564 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 565 | mMetrics = metrics; |
| 566 | } |
| 567 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 568 | /** |
| 569 | * Sets the cache directory for this package parser. |
| 570 | */ |
| 571 | public void setCacheDir(File cacheDir) { |
| 572 | mCacheDir = cacheDir; |
| 573 | } |
| 574 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 575 | /** |
| 576 | * Callback interface for retrieving information that may be needed while parsing |
| 577 | * a package. |
| 578 | */ |
| 579 | public interface Callback { |
| 580 | boolean hasFeature(String feature); |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 581 | String[] getOverlayPaths(String targetPackageName, String targetPath); |
| 582 | String[] getOverlayApks(String targetPackageName); |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Standard implementation of {@link Callback} on top of the public {@link PackageManager} |
| 587 | * class. |
| 588 | */ |
| 589 | public static final class CallbackImpl implements Callback { |
| 590 | private final PackageManager mPm; |
| 591 | |
| 592 | public CallbackImpl(PackageManager pm) { |
| 593 | mPm = pm; |
| 594 | } |
| 595 | |
| 596 | @Override public boolean hasFeature(String feature) { |
| 597 | return mPm.hasSystemFeature(feature); |
| 598 | } |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 599 | |
| 600 | @Override public String[] getOverlayPaths(String targetPackageName, String targetPath) { |
| 601 | return null; |
| 602 | } |
| 603 | |
| 604 | @Override public String[] getOverlayApks(String targetPackageName) { |
| 605 | return null; |
| 606 | } |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Set the {@link Callback} that can be used while parsing. |
| 611 | */ |
| 612 | public void setCallback(Callback cb) { |
| 613 | mCallback = cb; |
| 614 | } |
| 615 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 616 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 617 | return isApkPath(file.getName()); |
| 618 | } |
| 619 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 620 | public static boolean isApkPath(String path) { |
Calin Juravle | 3fc56c3 | 2017-12-11 18:26:13 -0800 | [diff] [blame] | 621 | return path.endsWith(APK_FILE_EXTENSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 625 | * Returns true if the package is installed and not hidden, or if the caller |
| 626 | * explicitly wanted all uninstalled and hidden packages as well. |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 627 | * @param appInfo The applicationInfo of the app being checked. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 628 | */ |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 629 | private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state, |
| 630 | ApplicationInfo appInfo) { |
Rhed Jao | cd47c26 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 631 | // Returns false if the package is hidden system app until installed. |
| 632 | if ((flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) == 0 |
| 633 | && !state.installed |
| 634 | && appInfo != null && appInfo.hiddenUntilInstalled) { |
| 635 | return false; |
| 636 | } |
| 637 | |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 638 | // If available for the target user, or trying to match uninstalled packages and it's |
| 639 | // a system app. |
| 640 | return state.isAvailable(flags) |
| 641 | || (appInfo != null && appInfo.isSystemApp() |
Rhed Jao | cd47c26 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 642 | && ((flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0 |
| 643 | || (flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) != 0)); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 646 | public static boolean isAvailable(PackageUserState state) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 647 | return checkUseInstalledOrHidden(0, state, null); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Oli Lan | 1138012 | 2019-07-31 15:27:22 +0100 | [diff] [blame] | 650 | /** |
| 651 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 652 | * |
| 653 | * @param p the parsed package. |
| 654 | * @param flags indicating which optional information is included. |
| 655 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 656 | @UnsupportedAppUsage |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 657 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Oli Lan | 1138012 | 2019-07-31 15:27:22 +0100 | [diff] [blame] | 658 | int[] gids, int flags, long firstInstallTime, long lastUpdateTime, |
| 659 | Set<String> grantedPermissions, PackageUserState state) { |
| 660 | |
| 661 | return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, |
| 662 | grantedPermissions, state, UserHandle.getCallingUserId()); |
| 663 | } |
| 664 | |
| 665 | @UnsupportedAppUsage |
| 666 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
| 667 | int[] gids, int flags, long firstInstallTime, long lastUpdateTime, |
| 668 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
| 669 | |
| 670 | return generatePackageInfo(p, null, gids, flags, firstInstallTime, lastUpdateTime, |
| 671 | grantedPermissions, state, userId); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * PackageInfo generator specifically for apex files. |
| 676 | * |
| 677 | * @param pkg Package to generate info from. Should be derived from an apex. |
| 678 | * @param apexInfo Apex info relating to the package. |
| 679 | * @return PackageInfo |
| 680 | * @throws PackageParserException |
| 681 | */ |
| 682 | public static PackageInfo generatePackageInfo( |
| 683 | PackageParser.Package pkg, ApexInfo apexInfo, int flags) { |
| 684 | return generatePackageInfo(pkg, apexInfo, EmptyArray.INT, flags, 0, 0, |
| 685 | Collections.emptySet(), new PackageUserState(), UserHandle.getCallingUserId()); |
| 686 | } |
| 687 | |
| 688 | private static PackageInfo generatePackageInfo(PackageParser.Package p, ApexInfo apexInfo, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 689 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 690 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 691 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 692 | return null; |
| 693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | PackageInfo pi = new PackageInfo(); |
| 695 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 696 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | pi.versionCode = p.mVersionCode; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 698 | pi.versionCodeMajor = p.mVersionCodeMajor; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 699 | pi.baseRevisionCode = p.baseRevisionCode; |
| 700 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | pi.versionName = p.mVersionName; |
| 702 | pi.sharedUserId = p.mSharedUserId; |
| 703 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 704 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 705 | pi.installLocation = p.installLocation; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 706 | pi.isStub = p.isStub; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 707 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 708 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 709 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 710 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 711 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 712 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 713 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 714 | pi.overlayTarget = p.mOverlayTarget; |
Ryan Mitchell | d57fb1f | 2019-03-20 17:18:58 -0700 | [diff] [blame] | 715 | pi.targetOverlayableName = p.mOverlayTargetName; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 716 | pi.overlayCategory = p.mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 717 | pi.overlayPriority = p.mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 718 | pi.mOverlayIsStatic = p.mOverlayIsStatic; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 719 | pi.compileSdkVersion = p.mCompileSdkVersion; |
| 720 | pi.compileSdkVersionCodename = p.mCompileSdkVersionCodename; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 721 | pi.firstInstallTime = firstInstallTime; |
| 722 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 724 | pi.gids = gids; |
| 725 | } |
| 726 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 727 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | if (N > 0) { |
| 729 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 730 | p.configPreferences.toArray(pi.configPreferences); |
| 731 | } |
| 732 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 733 | if (N > 0) { |
| 734 | pi.reqFeatures = new FeatureInfo[N]; |
| 735 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 737 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 738 | if (N > 0) { |
| 739 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 740 | p.featureGroups.toArray(pi.featureGroups); |
| 741 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 743 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 744 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 746 | int num = 0; |
| 747 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 748 | for (int i = 0; i < N; i++) { |
| 749 | final Activity a = p.activities.get(i); |
| 750 | if (state.isMatch(a.info, flags)) { |
Ricky Wai | 905908f | 2019-01-29 15:19:52 +0000 | [diff] [blame] | 751 | if (PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(a.className)) { |
| 752 | continue; |
| 753 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 754 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | } |
| 756 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 757 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } |
| 759 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 760 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 761 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 763 | int num = 0; |
| 764 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 765 | for (int i = 0; i < N; i++) { |
| 766 | final Activity a = p.receivers.get(i); |
| 767 | if (state.isMatch(a.info, flags)) { |
| 768 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | } |
| 770 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 771 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | } |
| 773 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 774 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 775 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 777 | int num = 0; |
| 778 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 779 | for (int i = 0; i < N; i++) { |
| 780 | final Service s = p.services.get(i); |
| 781 | if (state.isMatch(s.info, flags)) { |
| 782 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 785 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | } |
| 787 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 788 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 789 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 791 | int num = 0; |
| 792 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 793 | for (int i = 0; i < N; i++) { |
| 794 | final Provider pr = p.providers.get(i); |
| 795 | if (state.isMatch(pr.info, flags)) { |
| 796 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | } |
| 798 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 799 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 803 | int N = p.instrumentation.size(); |
| 804 | if (N > 0) { |
| 805 | pi.instrumentation = new InstrumentationInfo[N]; |
| 806 | for (int i=0; i<N; i++) { |
| 807 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 808 | p.instrumentation.get(i), flags); |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 813 | int N = p.permissions.size(); |
| 814 | if (N > 0) { |
| 815 | pi.permissions = new PermissionInfo[N]; |
| 816 | for (int i=0; i<N; i++) { |
| 817 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 818 | } |
| 819 | } |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 820 | N = p.requestedPermissions.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | if (N > 0) { |
| 822 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 823 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | for (int i=0; i<N; i++) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 825 | final String perm = p.requestedPermissions.get(i); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 826 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 827 | // The notion of required permissions is deprecated but for compatibility. |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 828 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 829 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 830 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 831 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | } |
Oli Lan | 1138012 | 2019-07-31 15:27:22 +0100 | [diff] [blame] | 835 | |
| 836 | if (apexInfo != null) { |
| 837 | File apexFile = new File(apexInfo.modulePath); |
| 838 | |
| 839 | pi.applicationInfo.sourceDir = apexFile.getPath(); |
| 840 | pi.applicationInfo.publicSourceDir = apexFile.getPath(); |
| 841 | if (apexInfo.isFactory) { |
| 842 | pi.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 843 | } else { |
| 844 | pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM; |
| 845 | } |
| 846 | if (apexInfo.isActive) { |
| 847 | pi.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 848 | } else { |
| 849 | pi.applicationInfo.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 850 | } |
| 851 | pi.isApex = true; |
| 852 | } |
| 853 | |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 854 | // deprecated method of getting signing certificates |
Oli Lan | 1138012 | 2019-07-31 15:27:22 +0100 | [diff] [blame] | 855 | if ((flags & PackageManager.GET_SIGNATURES) != 0) { |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 856 | if (p.mSigningDetails.hasPastSigningCertificates()) { |
| 857 | // Package has included signing certificate rotation information. Return the oldest |
| 858 | // cert so that programmatic checks keep working even if unaware of key rotation. |
| 859 | pi.signatures = new Signature[1]; |
| 860 | pi.signatures[0] = p.mSigningDetails.pastSigningCertificates[0]; |
| 861 | } else if (p.mSigningDetails.hasSignatures()) { |
| 862 | // otherwise keep old behavior |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 863 | int numberOfSigs = p.mSigningDetails.signatures.length; |
| 864 | pi.signatures = new Signature[numberOfSigs]; |
| 865 | 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] | 866 | } |
| 867 | } |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 868 | |
| 869 | // replacement for GET_SIGNATURES |
| 870 | if ((flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0) { |
Dan Cashman | 5c9f527e | 2018-04-03 16:42:23 -0700 | [diff] [blame] | 871 | if (p.mSigningDetails != SigningDetails.UNKNOWN) { |
| 872 | // only return a valid SigningInfo if there is signing information to report |
| 873 | pi.signingInfo = new SigningInfo(p.mSigningDetails); |
| 874 | } else { |
| 875 | pi.signingInfo = null; |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 876 | } |
| 877 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | return pi; |
| 879 | } |
| 880 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 881 | public static final int PARSE_MUST_BE_APK = 1 << 0; |
| 882 | public static final int PARSE_IGNORE_PROCESSES = 1 << 1; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 883 | public static final int PARSE_EXTERNAL_STORAGE = 1 << 3; |
| 884 | public static final int PARSE_IS_SYSTEM_DIR = 1 << 4; |
| 885 | public static final int PARSE_COLLECT_CERTIFICATES = 1 << 5; |
| 886 | public static final int PARSE_ENFORCE_CODE = 1 << 6; |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 887 | public static final int PARSE_CHATTY = 1 << 31; |
| 888 | |
| 889 | @IntDef(flag = true, prefix = { "PARSE_" }, value = { |
| 890 | PARSE_CHATTY, |
| 891 | PARSE_COLLECT_CERTIFICATES, |
| 892 | PARSE_ENFORCE_CODE, |
| 893 | PARSE_EXTERNAL_STORAGE, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 894 | PARSE_IGNORE_PROCESSES, |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 895 | PARSE_IS_SYSTEM_DIR, |
| 896 | PARSE_MUST_BE_APK, |
| 897 | }) |
| 898 | @Retention(RetentionPolicy.SOURCE) |
| 899 | public @interface ParseFlags {} |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 900 | |
| 901 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 903 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 904 | * Used to sort a set of APKs based on their split names, always placing the |
| 905 | * base APK (with {@code null} split name) first. |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 906 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 907 | private static class SplitNameComparator implements Comparator<String> { |
| 908 | @Override |
| 909 | public int compare(String lhs, String rhs) { |
| 910 | if (lhs == null) { |
| 911 | return -1; |
| 912 | } else if (rhs == null) { |
| 913 | return 1; |
| 914 | } else { |
| 915 | return lhs.compareTo(rhs); |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 920 | /** |
| 921 | * Parse only lightweight details about the package at the given location. |
| 922 | * Automatically detects if the package is a monolithic style (single APK |
| 923 | * file) or cluster style (directory of APKs). |
| 924 | * <p> |
| 925 | * This performs sanity checking on cluster style packages, such as |
| 926 | * requiring identical package name and version codes, a single base APK, |
| 927 | * and unique split names. |
| 928 | * |
| 929 | * @see PackageParser#parsePackage(File, int) |
| 930 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 931 | @UnsupportedAppUsage |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 932 | public static PackageLite parsePackageLite(File packageFile, int flags) |
| 933 | throws PackageParserException { |
| 934 | if (packageFile.isDirectory()) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 935 | return parseClusterPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 936 | } else { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 937 | return parseMonolithicPackageLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 941 | private static PackageLite parseMonolithicPackageLite(File packageFile, int flags) |
| 942 | throws PackageParserException { |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 943 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 944 | final ApkLite baseApk = parseApkLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 945 | final String packagePath = packageFile.getAbsolutePath(); |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 946 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 947 | return new PackageLite(packagePath, baseApk, null, null, null, null, null, null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 950 | static PackageLite parseClusterPackageLite(File packageDir, int flags) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 951 | throws PackageParserException { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 952 | final File[] files = packageDir.listFiles(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 953 | if (ArrayUtils.isEmpty(files)) { |
| 954 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 955 | "No packages found in split"); |
| 956 | } |
| 957 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 958 | String packageName = null; |
| 959 | int versionCode = 0; |
| 960 | |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 961 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite"); |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 962 | final ArrayMap<String, ApkLite> apks = new ArrayMap<>(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 963 | for (File file : files) { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 964 | if (isApkFile(file)) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 965 | final ApkLite lite = parseApkLite(file, flags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 966 | |
| 967 | // Assert that all package names and version codes are |
| 968 | // consistent with the first one we encounter. |
| 969 | if (packageName == null) { |
| 970 | packageName = lite.packageName; |
| 971 | versionCode = lite.versionCode; |
| 972 | } else { |
| 973 | if (!packageName.equals(lite.packageName)) { |
| 974 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 975 | "Inconsistent package " + lite.packageName + " in " + file |
| 976 | + "; expected " + packageName); |
| 977 | } |
| 978 | if (versionCode != lite.versionCode) { |
| 979 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 980 | "Inconsistent version " + lite.versionCode + " in " + file |
| 981 | + "; expected " + versionCode); |
| 982 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 985 | // Assert that each split is defined only once |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 986 | if (apks.put(lite.splitName, lite) != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 987 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 988 | "Split name " + lite.splitName |
| 989 | + " defined more than once; most recent was " + file); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
Todd Kennedy | cd029da | 2016-07-21 07:41:09 -0700 | [diff] [blame] | 993 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 994 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 995 | final ApkLite baseApk = apks.remove(null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 996 | if (baseApk == null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 997 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 998 | "Missing base APK in " + packageDir); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1001 | // Always apply deterministic ordering based on splitName |
| 1002 | final int size = apks.size(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1003 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1004 | String[] splitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1005 | boolean[] isFeatureSplits = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1006 | String[] usesSplitNames = null; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1007 | String[] configForSplits = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1008 | String[] splitCodePaths = null; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1009 | int[] splitRevisionCodes = null; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 1010 | String[] splitClassLoaderNames = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1011 | if (size > 0) { |
| 1012 | splitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1013 | isFeatureSplits = new boolean[size]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1014 | usesSplitNames = new String[size]; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1015 | configForSplits = new String[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1016 | splitCodePaths = new String[size]; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1017 | splitRevisionCodes = new int[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1018 | |
| 1019 | splitNames = apks.keySet().toArray(splitNames); |
| 1020 | Arrays.sort(splitNames, sSplitNameComparator); |
| 1021 | |
| 1022 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1023 | final ApkLite apk = apks.get(splitNames[i]); |
| 1024 | usesSplitNames[i] = apk.usesSplitName; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1025 | isFeatureSplits[i] = apk.isFeatureSplit; |
| 1026 | configForSplits[i] = apk.configForSplit; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1027 | splitCodePaths[i] = apk.codePath; |
| 1028 | splitRevisionCodes[i] = apk.revisionCode; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1029 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1032 | final String codePath = packageDir.getAbsolutePath(); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1033 | return new PackageLite(codePath, baseApk, splitNames, isFeatureSplits, usesSplitNames, |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 1034 | configForSplits, splitCodePaths, splitRevisionCodes); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1037 | /** |
| 1038 | * Parse the package at the given location. Automatically detects if the |
| 1039 | * package is a monolithic style (single APK file) or cluster style |
| 1040 | * (directory of APKs). |
| 1041 | * <p> |
| 1042 | * This performs sanity checking on cluster style packages, such as |
| 1043 | * requiring identical package name and version codes, a single base APK, |
| 1044 | * and unique split names. |
| 1045 | * <p> |
| 1046 | * Note that this <em>does not</em> perform signature verification; that |
| 1047 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1048 | * |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1049 | * If {@code useCaches} is true, the package parser might return a cached |
| 1050 | * result from a previous parse of the same {@code packageFile} with the same |
| 1051 | * {@code flags}. Note that this method does not check whether {@code packageFile} |
| 1052 | * has changed since the last parse, it's up to callers to do so. |
| 1053 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1054 | * @see #parsePackageLite(File, int) |
| 1055 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1056 | @UnsupportedAppUsage |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1057 | public Package parsePackage(File packageFile, int flags, boolean useCaches) |
| 1058 | throws PackageParserException { |
| 1059 | Package parsed = useCaches ? getCachedResult(packageFile, flags) : null; |
| 1060 | if (parsed != null) { |
| 1061 | return parsed; |
| 1062 | } |
| 1063 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1064 | long parseTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1065 | if (packageFile.isDirectory()) { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1066 | parsed = parseClusterPackage(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1067 | } else { |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1068 | parsed = parseMonolithicPackage(packageFile, flags); |
| 1069 | } |
| 1070 | |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1071 | long cacheTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1072 | cacheResult(packageFile, flags, parsed); |
Fyodor Kupolov | 28a988f | 2017-07-31 18:44:11 -0700 | [diff] [blame] | 1073 | if (LOG_PARSE_TIMINGS) { |
| 1074 | parseTime = cacheTime - parseTime; |
| 1075 | cacheTime = SystemClock.uptimeMillis() - cacheTime; |
| 1076 | if (parseTime + cacheTime > LOG_PARSE_TIMINGS_THRESHOLD_MS) { |
| 1077 | Slog.i(TAG, "Parse times for '" + packageFile + "': parse=" + parseTime |
| 1078 | + "ms, update_cache=" + cacheTime + " ms"); |
| 1079 | } |
| 1080 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1081 | return parsed; |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * Equivalent to {@link #parsePackage(File, int, boolean)} with {@code useCaches == false}. |
| 1086 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1087 | @UnsupportedAppUsage |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1088 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 1089 | return parsePackage(packageFile, flags, false /* useCaches */); |
| 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * Returns the cache key for a specificied {@code packageFile} and {@code flags}. |
| 1094 | */ |
| 1095 | private String getCacheKey(File packageFile, int flags) { |
| 1096 | StringBuilder sb = new StringBuilder(packageFile.getName()); |
| 1097 | sb.append('-'); |
| 1098 | sb.append(flags); |
| 1099 | |
| 1100 | return sb.toString(); |
| 1101 | } |
| 1102 | |
| 1103 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1104 | protected Package fromCacheEntry(byte[] bytes) { |
| 1105 | return fromCacheEntryStatic(bytes); |
| 1106 | } |
| 1107 | |
| 1108 | /** static version of {@link #fromCacheEntry} for unit tests. */ |
| 1109 | @VisibleForTesting |
| 1110 | public static Package fromCacheEntryStatic(byte[] bytes) { |
| 1111 | final Parcel p = Parcel.obtain(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1112 | p.unmarshall(bytes, 0, bytes.length); |
| 1113 | p.setDataPosition(0); |
| 1114 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1115 | final ReadHelper helper = new ReadHelper(p); |
| 1116 | helper.startAndInstall(); |
| 1117 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1118 | PackageParser.Package pkg = new PackageParser.Package(p); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1119 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1120 | p.recycle(); |
| 1121 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1122 | sCachedPackageReadCount.incrementAndGet(); |
| 1123 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1124 | return pkg; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | @VisibleForTesting |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1128 | protected byte[] toCacheEntry(Package pkg) { |
| 1129 | return toCacheEntryStatic(pkg); |
| 1130 | |
| 1131 | } |
| 1132 | |
| 1133 | /** static version of {@link #toCacheEntry} for unit tests. */ |
| 1134 | @VisibleForTesting |
| 1135 | public static byte[] toCacheEntryStatic(Package pkg) { |
| 1136 | final Parcel p = Parcel.obtain(); |
| 1137 | final WriteHelper helper = new WriteHelper(p); |
| 1138 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1139 | pkg.writeToParcel(p, 0 /* flags */); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1140 | |
| 1141 | helper.finishAndUninstall(); |
| 1142 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1143 | byte[] serialized = p.marshall(); |
| 1144 | p.recycle(); |
| 1145 | |
| 1146 | return serialized; |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Given a {@code packageFile} and a {@code cacheFile} returns whether the |
| 1151 | * cache file is up to date based on the mod-time of both files. |
| 1152 | */ |
| 1153 | private static boolean isCacheUpToDate(File packageFile, File cacheFile) { |
| 1154 | try { |
| 1155 | // NOTE: We don't use the File.lastModified API because it has the very |
| 1156 | // non-ideal failure mode of returning 0 with no excepions thrown. |
| 1157 | // The nio2 Files API is a little better but is considerably more expensive. |
| 1158 | final StructStat pkg = android.system.Os.stat(packageFile.getAbsolutePath()); |
| 1159 | final StructStat cache = android.system.Os.stat(cacheFile.getAbsolutePath()); |
| 1160 | return pkg.st_mtime < cache.st_mtime; |
| 1161 | } catch (ErrnoException ee) { |
| 1162 | // The most common reason why stat fails is that a given cache file doesn't |
| 1163 | // exist. We ignore that here. It's easy to reason that it's safe to say the |
| 1164 | // cache isn't up to date if we see any sort of exception here. |
| 1165 | // |
| 1166 | // (1) Exception while stating the package file : This should never happen, |
| 1167 | // and if it does, we do a full package parse (which is likely to throw the |
| 1168 | // same exception). |
| 1169 | // (2) Exception while stating the cache file : If the file doesn't exist, the |
| 1170 | // cache is obviously out of date. If the file *does* exist, we can't read it. |
| 1171 | // We will attempt to delete and recreate it after parsing the package. |
| 1172 | if (ee.errno != OsConstants.ENOENT) { |
| 1173 | Slog.w("Error while stating package cache : ", ee); |
| 1174 | } |
| 1175 | |
| 1176 | return false; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | /** |
| 1181 | * Returns the cached parse result for {@code packageFile} for parse flags {@code flags}, |
| 1182 | * or {@code null} if no cached result exists. |
| 1183 | */ |
| 1184 | private Package getCachedResult(File packageFile, int flags) { |
| 1185 | if (mCacheDir == null) { |
| 1186 | return null; |
| 1187 | } |
| 1188 | |
| 1189 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1190 | final File cacheFile = new File(mCacheDir, cacheKey); |
| 1191 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1192 | try { |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1193 | // If the cache is not up to date, return null. |
| 1194 | if (!isCacheUpToDate(packageFile, cacheFile)) { |
| 1195 | return null; |
| 1196 | } |
| 1197 | |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1198 | final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath()); |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1199 | Package p = fromCacheEntry(bytes); |
| 1200 | if (mCallback != null) { |
| 1201 | String[] overlayApks = mCallback.getOverlayApks(p.packageName); |
| 1202 | if (overlayApks != null && overlayApks.length > 0) { |
| 1203 | for (String overlayApk : overlayApks) { |
| 1204 | // If a static RRO is updated, return null. |
| 1205 | if (!isCacheUpToDate(new File(overlayApk), cacheFile)) { |
| 1206 | return null; |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | return p; |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1212 | } catch (Throwable e) { |
Narayan Kamath | 21a2838 | 2017-01-13 10:34:29 +0000 | [diff] [blame] | 1213 | Slog.w(TAG, "Error reading package cache: ", e); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1214 | |
| 1215 | // If something went wrong while reading the cache entry, delete the cache file |
| 1216 | // so that we regenerate it the next time. |
| 1217 | cacheFile.delete(); |
| 1218 | return null; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Caches the parse result for {@code packageFile} with flags {@code flags}. |
| 1224 | */ |
| 1225 | private void cacheResult(File packageFile, int flags, Package parsed) { |
| 1226 | if (mCacheDir == null) { |
| 1227 | return; |
| 1228 | } |
| 1229 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1230 | try { |
| 1231 | final String cacheKey = getCacheKey(packageFile, flags); |
| 1232 | final File cacheFile = new File(mCacheDir, cacheKey); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1233 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1234 | if (cacheFile.exists()) { |
| 1235 | if (!cacheFile.delete()) { |
| 1236 | Slog.e(TAG, "Unable to delete cache file: " + cacheFile); |
| 1237 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1238 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1239 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1240 | final byte[] cacheEntry = toCacheEntry(parsed); |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1241 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1242 | if (cacheEntry == null) { |
| 1243 | return; |
| 1244 | } |
Narayan Kamath | 988149c | 2016-12-01 13:32:59 +0000 | [diff] [blame] | 1245 | |
Makoto Onuki | 48e9316 | 2017-08-18 11:00:19 -0700 | [diff] [blame] | 1246 | try (FileOutputStream fos = new FileOutputStream(cacheFile)) { |
| 1247 | fos.write(cacheEntry); |
| 1248 | } catch (IOException ioe) { |
| 1249 | Slog.w(TAG, "Error writing cache entry.", ioe); |
| 1250 | cacheFile.delete(); |
| 1251 | } |
| 1252 | } catch (Throwable e) { |
| 1253 | Slog.w(TAG, "Error saving package cache.", e); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * Parse all APKs contained in the given directory, treating them as a |
| 1259 | * single package. This also performs sanity checking, such as requiring |
| 1260 | * identical package name and version codes, a single base APK, and unique |
| 1261 | * split names. |
| 1262 | * <p> |
| 1263 | * Note that this <em>does not</em> perform signature verification; that |
| 1264 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 1265 | */ |
| 1266 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1267 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1268 | if (mOnlyCoreApps && !lite.coreApp) { |
| 1269 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1270 | "Not a coreApp: " + packageDir); |
| 1271 | } |
| 1272 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1273 | // Build the split dependency tree. |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1274 | SparseArray<int[]> splitDependencies = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1275 | final SplitAssetLoader assetLoader; |
| 1276 | if (lite.isolatedSplits && !ArrayUtils.isEmpty(lite.splitNames)) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1277 | try { |
| 1278 | splitDependencies = SplitAssetDependencyLoader.createDependenciesFromPackage(lite); |
| 1279 | assetLoader = new SplitAssetDependencyLoader(lite, splitDependencies, flags); |
| 1280 | } catch (SplitAssetDependencyLoader.IllegalDependencyException e) { |
| 1281 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, e.getMessage()); |
| 1282 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1283 | } else { |
| 1284 | assetLoader = new DefaultSplitAssetLoader(lite, flags); |
| 1285 | } |
| 1286 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1287 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1288 | final AssetManager assets = assetLoader.getBaseAssetManager(); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1289 | final File baseApk = new File(lite.baseCodePath); |
| 1290 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 1291 | if (pkg == null) { |
| 1292 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1293 | "Failed to parse base APK: " + baseApk); |
| 1294 | } |
| 1295 | |
| 1296 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 1297 | final int num = lite.splitNames.length; |
| 1298 | pkg.splitNames = lite.splitNames; |
| 1299 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1300 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1301 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1302 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1303 | pkg.applicationInfo.splitNames = pkg.splitNames; |
| 1304 | pkg.applicationInfo.splitDependencies = splitDependencies; |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 1305 | pkg.applicationInfo.splitClassLoaderNames = new String[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1306 | |
| 1307 | for (int i = 0; i < num; i++) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1308 | final AssetManager splitAssets = assetLoader.getSplitAssetManager(i); |
| 1309 | parseSplitApk(pkg, i, splitAssets, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1313 | pkg.setCodePath(packageDir.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1314 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1315 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1316 | } catch (IOException e) { |
| 1317 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1318 | "Failed to get path: " + lite.baseCodePath, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1319 | } finally { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1320 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1321 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1324 | /** |
| 1325 | * Parse the given APK file, treating it as as a single monolithic package. |
| 1326 | * <p> |
| 1327 | * Note that this <em>does not</em> perform signature verification; that |
| 1328 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1329 | * |
| 1330 | * @deprecated external callers should move to |
| 1331 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 1332 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1333 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 1334 | @Deprecated |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1335 | @UnsupportedAppUsage |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1336 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1337 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1338 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1339 | if (!lite.coreApp) { |
| 1340 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1341 | "Not a coreApp: " + apkFile); |
| 1342 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1343 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 1344 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1345 | final SplitAssetLoader assetLoader = new DefaultSplitAssetLoader(lite, flags); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1346 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1347 | final Package pkg = parseBaseApk(apkFile, assetLoader.getBaseAssetManager(), flags); |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1348 | pkg.setCodePath(apkFile.getCanonicalPath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1349 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1350 | return pkg; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 1351 | } catch (IOException e) { |
| 1352 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1353 | "Failed to get path: " + apkFile, e); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1354 | } finally { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1355 | IoUtils.closeQuietly(assetLoader); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1356 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1359 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 1360 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1361 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1362 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1363 | String volumeUuid = null; |
| 1364 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 1365 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 1366 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 1367 | } |
| 1368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1370 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1371 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1372 | 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] | 1373 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1374 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 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 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1381 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1382 | final Resources res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1383 | |
| 1384 | final String[] outError = new String[1]; |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1385 | final Package pkg = parseBaseApk(apkPath, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1386 | if (pkg == null) { |
| 1387 | throw new PackageParserException(mParseError, |
| 1388 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1390 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1391 | pkg.setVolumeUuid(volumeUuid); |
| 1392 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 1393 | pkg.setBaseCodePath(apkPath); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1394 | pkg.setSigningDetails(SigningDetails.UNKNOWN); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1395 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1396 | return pkg; |
| 1397 | |
| 1398 | } catch (PackageParserException e) { |
| 1399 | throw e; |
| 1400 | } catch (Exception e) { |
| 1401 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1402 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1403 | } finally { |
| 1404 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 1408 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1409 | throws PackageParserException { |
| 1410 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1411 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1412 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 1413 | mArchiveSourcePath = apkPath; |
| 1414 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1415 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 1416 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1417 | final Resources res; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1418 | XmlResourceParser parser = null; |
| 1419 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1420 | // This must always succeed, as the path has been added to the AssetManager before. |
| 1421 | final int cookie = assets.findCookieForPath(apkPath); |
| 1422 | if (cookie == 0) { |
| 1423 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1424 | "Failed adding asset path: " + apkPath); |
| 1425 | } |
| 1426 | |
Adam Lesinski | 56c82be | 2018-02-09 11:02:04 -0800 | [diff] [blame] | 1427 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1428 | res = new Resources(assets, mMetrics, null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1429 | |
| 1430 | final String[] outError = new String[1]; |
| 1431 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 1432 | if (pkg == null) { |
| 1433 | throw new PackageParserException(mParseError, |
| 1434 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 1435 | } |
| 1436 | |
| 1437 | } catch (PackageParserException e) { |
| 1438 | throw e; |
| 1439 | } catch (Exception e) { |
| 1440 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1441 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1442 | } finally { |
| 1443 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * Parse the manifest of a <em>split APK</em>. |
| 1449 | * <p> |
| 1450 | * Note that split APKs have many more restrictions on what they're capable |
| 1451 | * of doing, so many valid features of a base APK have been carefully |
| 1452 | * omitted here. |
| 1453 | */ |
| 1454 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1455 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1456 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1457 | AttributeSet attrs = parser; |
| 1458 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1459 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1460 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1461 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1462 | mParseInstrumentationArgs = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1463 | |
| 1464 | int type; |
| 1465 | |
| 1466 | boolean foundApp = false; |
| 1467 | |
| 1468 | int outerDepth = parser.getDepth(); |
| 1469 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1470 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1471 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1472 | continue; |
| 1473 | } |
| 1474 | |
| 1475 | String tagName = parser.getName(); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1476 | if (tagName.equals(TAG_APPLICATION)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1477 | if (foundApp) { |
| 1478 | if (RIGID_PARSER) { |
| 1479 | outError[0] = "<manifest> has more than one <application>"; |
| 1480 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1481 | return null; |
| 1482 | } else { |
| 1483 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1484 | XmlUtils.skipCurrentTag(parser); |
| 1485 | continue; |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1490 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1491 | return null; |
| 1492 | } |
| 1493 | |
| 1494 | } else if (RIGID_PARSER) { |
| 1495 | outError[0] = "Bad element under <manifest>: " |
| 1496 | + parser.getName(); |
| 1497 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1498 | return null; |
| 1499 | |
| 1500 | } else { |
| 1501 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1502 | + " at " + mArchiveSourcePath + " " |
| 1503 | + parser.getPositionDescription()); |
| 1504 | XmlUtils.skipCurrentTag(parser); |
| 1505 | continue; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | if (!foundApp) { |
| 1510 | outError[0] = "<manifest> does not contain an <application>"; |
| 1511 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1512 | } |
| 1513 | |
| 1514 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1517 | /** Parses the public keys from the set of signatures. */ |
| 1518 | public static ArraySet<PublicKey> toSigningKeys(Signature[] signatures) |
| 1519 | throws CertificateException { |
| 1520 | ArraySet<PublicKey> keys = new ArraySet<>(signatures.length); |
| 1521 | for (int i = 0; i < signatures.length; i++) { |
| 1522 | keys.add(signatures[i].getPublicKey()); |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1523 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1524 | return keys; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1528 | * Collect certificates from all the APKs described in the given package, |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1529 | * populating {@link Package#mSigningDetails}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1530 | * contents are signed correctly and consistently. |
| 1531 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1532 | @UnsupportedAppUsage |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1533 | public static void collectCertificates(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1534 | throws PackageParserException { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1535 | collectCertificatesInternal(pkg, skipVerify); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1536 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1537 | for (int i = 0; i < childCount; i++) { |
| 1538 | Package childPkg = pkg.childPackages.get(i); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1539 | childPkg.mSigningDetails = pkg.mSigningDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1543 | private static void collectCertificatesInternal(Package pkg, boolean skipVerify) |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1544 | throws PackageParserException { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1545 | pkg.mSigningDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1546 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1547 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1548 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1549 | collectCertificates(pkg, new File(pkg.baseCodePath), skipVerify); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1550 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1551 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
| 1552 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1553 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1554 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1555 | } |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1556 | } finally { |
| 1557 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1561 | @UnsupportedAppUsage |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1562 | private static void collectCertificates(Package pkg, File apkFile, boolean skipVerify) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1563 | throws PackageParserException { |
| 1564 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1566 | int minSignatureScheme = SigningDetails.SignatureSchemeVersion.JAR; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1567 | if (pkg.applicationInfo.isStaticSharedLibrary()) { |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1568 | // must use v2 signing scheme |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1569 | minSignatureScheme = SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2; |
Dan Cashman | e92f842 | 2017-12-08 14:02:51 -0800 | [diff] [blame] | 1570 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1571 | SigningDetails verified; |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1572 | if (skipVerify) { |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1573 | // systemDir APKs are already trusted, save time by not verifying |
Gavin Corkery | ed521ab | 2019-01-31 16:59:41 +0000 | [diff] [blame] | 1574 | verified = ApkSignatureVerifier.unsafeGetCertsWithoutVerification( |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1575 | apkPath, minSignatureScheme); |
| 1576 | } else { |
| 1577 | verified = ApkSignatureVerifier.verify(apkPath, minSignatureScheme); |
| 1578 | } |
Dan Cashman | 636ea5e | 2017-12-18 10:38:20 -0800 | [diff] [blame] | 1579 | |
| 1580 | // Verify that entries are signed consistently with the first pkg |
| 1581 | // we encountered. Note that for splits, certificates may have |
| 1582 | // already been populated during an earlier parse of a base APK. |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1583 | if (pkg.mSigningDetails == SigningDetails.UNKNOWN) { |
| 1584 | pkg.mSigningDetails = verified; |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1585 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1586 | if (!Signature.areExactMatch(pkg.mSigningDetails.signatures, verified.signatures)) { |
Patrick Baumann | 9ff5574 | 2017-12-14 10:50:18 -0800 | [diff] [blame] | 1587 | throw new PackageParserException( |
| 1588 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1589 | apkPath + " has mismatched certificates"); |
| 1590 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | } |
| 1593 | |
Fyodor Kupolov | 965fa69 | 2016-10-28 18:20:25 -0700 | [diff] [blame] | 1594 | private static AssetManager newConfiguredAssetManager() { |
| 1595 | AssetManager assetManager = new AssetManager(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 1596 | 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] | 1597 | Build.VERSION.RESOURCES_SDK_INT); |
| 1598 | return assetManager; |
| 1599 | } |
| 1600 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1601 | /** |
| 1602 | * Utility method that retrieves lightweight details about a single APK |
| 1603 | * file, including package name, split name, and install location. |
| 1604 | * |
| 1605 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1606 | * @param flags optional parse flags, such as |
| 1607 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1608 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1609 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1610 | throws PackageParserException { |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 1611 | return parseApkLiteInner(apkFile, null, null, flags); |
| 1612 | } |
| 1613 | |
| 1614 | /** |
| 1615 | * Utility method that retrieves lightweight details about a single APK |
| 1616 | * file, including package name, split name, and install location. |
| 1617 | * |
| 1618 | * @param fd already open file descriptor of an apk file |
| 1619 | * @param debugPathName arbitrary text name for this file, for debug output |
| 1620 | * @param flags optional parse flags, such as |
| 1621 | * {@link #PARSE_COLLECT_CERTIFICATES} |
| 1622 | */ |
| 1623 | public static ApkLite parseApkLite(FileDescriptor fd, String debugPathName, int flags) |
| 1624 | throws PackageParserException { |
| 1625 | return parseApkLiteInner(null, fd, debugPathName, flags); |
| 1626 | } |
| 1627 | |
| 1628 | private static ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd, String debugPathName, |
| 1629 | int flags) throws PackageParserException { |
| 1630 | final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1631 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1632 | XmlResourceParser parser = null; |
Winson | 7a3d82a | 2019-03-07 12:54:24 -0800 | [diff] [blame] | 1633 | ApkAssets apkAssets = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | try { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1635 | try { |
| 1636 | apkAssets = fd != null |
| 1637 | ? ApkAssets.loadFromFd(fd, debugPathName, false, false) |
| 1638 | : ApkAssets.loadFromPath(apkPath); |
| 1639 | } catch (IOException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1640 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1641 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 1644 | parser = apkAssets.openXml(ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1645 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1646 | final SigningDetails signingDetails; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1647 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1648 | // TODO: factor signature related items out of Package object |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 1649 | final Package tempPkg = new Package((String) null); |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1650 | final boolean skipVerify = (flags & PARSE_IS_SYSTEM_DIR) != 0; |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1651 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1652 | try { |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 1653 | collectCertificates(tempPkg, apkFile, skipVerify); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1654 | } finally { |
| 1655 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1656 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1657 | signingDetails = tempPkg.mSigningDetails; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1658 | } else { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 1659 | signingDetails = SigningDetails.UNKNOWN; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1660 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1661 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1662 | final AttributeSet attrs = parser; |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1663 | return parseApkLite(apkPath, parser, attrs, signingDetails); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1664 | |
| 1665 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 1666 | Slog.w(TAG, "Failed to parse " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1667 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1668 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1670 | IoUtils.closeQuietly(parser); |
Winson | 7a3d82a | 2019-03-07 12:54:24 -0800 | [diff] [blame] | 1671 | if (apkAssets != null) { |
| 1672 | try { |
| 1673 | apkAssets.close(); |
| 1674 | } catch (Throwable ignored) { |
| 1675 | } |
| 1676 | } |
| 1677 | // TODO(b/72056911): Implement AutoCloseable on ApkAssets. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1681 | private static String validateName(String name, boolean requireSeparator, |
| 1682 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | final int N = name.length(); |
| 1684 | boolean hasSep = false; |
| 1685 | boolean front = true; |
| 1686 | for (int i=0; i<N; i++) { |
| 1687 | final char c = name.charAt(i); |
| 1688 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1689 | front = false; |
| 1690 | continue; |
| 1691 | } |
| 1692 | if (!front) { |
| 1693 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1694 | continue; |
| 1695 | } |
| 1696 | } |
| 1697 | if (c == '.') { |
| 1698 | hasSep = true; |
| 1699 | front = true; |
| 1700 | continue; |
| 1701 | } |
| 1702 | return "bad character '" + c + "'"; |
| 1703 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1704 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1705 | return "Invalid filename"; |
| 1706 | } |
| 1707 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | ? null : "must have at least one '.' separator"; |
| 1709 | } |
| 1710 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1711 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1712 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1713 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | |
| 1715 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1716 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1717 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1720 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1721 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1722 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1724 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1725 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1726 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1729 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1730 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1731 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1732 | if (error != null) { |
| 1733 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1734 | "Invalid manifest package: " + error); |
| 1735 | } |
| 1736 | } |
| 1737 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1738 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1739 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1740 | if (splitName.length() == 0) { |
| 1741 | splitName = null; |
| 1742 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1743 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1744 | if (error != null) { |
| 1745 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1746 | "Invalid manifest split: " + error); |
| 1747 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | return Pair.create(packageName.intern(), |
| 1752 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1755 | private static ApkLite parseApkLite(String codePath, XmlPullParser parser, AttributeSet attrs, |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1756 | SigningDetails signingDetails) |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1757 | throws IOException, XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1758 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1759 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1760 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1761 | int versionCode = 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1762 | int versionCodeMajor = 0; |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1763 | int targetSdkVersion = DEFAULT_TARGET_SDK_VERSION; |
| 1764 | int minSdkVersion = DEFAULT_MIN_SDK_VERSION; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1765 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1766 | boolean coreApp = false; |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1767 | boolean debuggable = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1768 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1769 | boolean use32bitAbi = false; |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1770 | boolean extractNativeLibs = true; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1771 | boolean isolatedSplits = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1772 | boolean isFeatureSplit = false; |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1773 | boolean isSplitRequired = false; |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 1774 | boolean useEmbeddedDex = false; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1775 | String configForSplit = null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1776 | String usesSplitName = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1777 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1778 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1779 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1780 | if (attr.equals("installLocation")) { |
| 1781 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1782 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1783 | } else if (attr.equals("versionCode")) { |
| 1784 | versionCode = attrs.getAttributeIntValue(i, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1785 | } else if (attr.equals("versionCodeMajor")) { |
| 1786 | versionCodeMajor = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1787 | } else if (attr.equals("revisionCode")) { |
| 1788 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1789 | } else if (attr.equals("coreApp")) { |
| 1790 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1791 | } else if (attr.equals("isolatedSplits")) { |
| 1792 | isolatedSplits = attrs.getAttributeBooleanValue(i, false); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1793 | } else if (attr.equals("configForSplit")) { |
| 1794 | configForSplit = attrs.getAttributeValue(i); |
| 1795 | } else if (attr.equals("isFeatureSplit")) { |
| 1796 | isFeatureSplit = attrs.getAttributeBooleanValue(i, false); |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1797 | } else if (attr.equals("isSplitRequired")) { |
| 1798 | isSplitRequired = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1799 | } |
| 1800 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1801 | |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1802 | // 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] | 1803 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1804 | final int searchDepth = parser.getDepth() + 1; |
| 1805 | |
| 1806 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1807 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1808 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1809 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1810 | continue; |
| 1811 | } |
| 1812 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1813 | if (parser.getDepth() != searchDepth) { |
| 1814 | continue; |
| 1815 | } |
| 1816 | |
| 1817 | if (TAG_PACKAGE_VERIFIER.equals(parser.getName())) { |
| 1818 | final VerifierInfo verifier = parseVerifier(attrs); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1819 | if (verifier != null) { |
| 1820 | verifiers.add(verifier); |
| 1821 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1822 | } else if (TAG_APPLICATION.equals(parser.getName())) { |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1823 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1824 | final String attr = attrs.getAttributeName(i); |
Tamas Berghammer | d6dd6b8 | 2016-10-07 19:12:51 +0100 | [diff] [blame] | 1825 | if ("debuggable".equals(attr)) { |
| 1826 | debuggable = attrs.getAttributeBooleanValue(i, false); |
| 1827 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1828 | if ("multiArch".equals(attr)) { |
| 1829 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1830 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1831 | if ("use32bitAbi".equals(attr)) { |
| 1832 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1833 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1834 | if ("extractNativeLibs".equals(attr)) { |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 1835 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1836 | } |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 1837 | if ("useEmbeddedDex".equals(attr)) { |
| 1838 | useEmbeddedDex = attrs.getAttributeBooleanValue(i, false); |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 1839 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1840 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1841 | } else if (TAG_USES_SPLIT.equals(parser.getName())) { |
| 1842 | if (usesSplitName != null) { |
| 1843 | Slog.w(TAG, "Only one <uses-split> permitted. Ignoring others."); |
| 1844 | continue; |
| 1845 | } |
| 1846 | |
| 1847 | usesSplitName = attrs.getAttributeValue(ANDROID_RESOURCES, "name"); |
| 1848 | if (usesSplitName == null) { |
| 1849 | throw new PackageParserException( |
| 1850 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1851 | "<uses-split> tag requires 'android:name' attribute"); |
| 1852 | } |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1853 | } else if (TAG_USES_SDK.equals(parser.getName())) { |
| 1854 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1855 | final String attr = attrs.getAttributeName(i); |
| 1856 | if ("targetSdkVersion".equals(attr)) { |
| 1857 | targetSdkVersion = attrs.getAttributeIntValue(i, |
| 1858 | DEFAULT_TARGET_SDK_VERSION); |
| 1859 | } |
| 1860 | if ("minSdkVersion".equals(attr)) { |
| 1861 | minSdkVersion = attrs.getAttributeIntValue(i, DEFAULT_MIN_SDK_VERSION); |
| 1862 | } |
| 1863 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1864 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1867 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, isFeatureSplit, |
Todd Kennedy | 29cfa27 | 2018-09-26 10:25:24 -0700 | [diff] [blame] | 1868 | configForSplit, usesSplitName, isSplitRequired, versionCode, versionCodeMajor, |
| 1869 | revisionCode, installLocation, verifiers, signingDetails, coreApp, debuggable, |
Mohammad Samiul Islam | 935a156 | 2019-03-12 16:52:56 +0000 | [diff] [blame] | 1870 | multiArch, use32bitAbi, useEmbeddedDex, extractNativeLibs, isolatedSplits, |
| 1871 | minSdkVersion, targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | } |
| 1873 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1874 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1875 | * Parses a child package and adds it to the parent if successful. If you add |
| 1876 | * new tags that need to be supported by child packages make sure to add them |
| 1877 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1878 | * |
| 1879 | * @param parentPkg The parent that contains the child |
| 1880 | * @param res Resources against which to resolve values |
| 1881 | * @param parser Parser of the manifest |
| 1882 | * @param flags Flags about how to parse |
| 1883 | * @param outError Human readable error if parsing fails |
| 1884 | * @return True of parsing succeeded. |
| 1885 | * |
| 1886 | * @throws XmlPullParserException |
| 1887 | * @throws IOException |
| 1888 | */ |
| 1889 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1890 | int flags, String[] outError) throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1891 | // Make sure we have a valid child package name |
| 1892 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1893 | if (validateName(childPackageName, true, false) != null) { |
| 1894 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1895 | return false; |
| 1896 | } |
| 1897 | |
| 1898 | // Child packages must be unique |
| 1899 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1900 | String message = "Child package name cannot be equal to parent package name: " |
| 1901 | + parentPkg.packageName; |
| 1902 | Slog.w(TAG, message); |
| 1903 | outError[0] = message; |
| 1904 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1905 | return false; |
| 1906 | } |
| 1907 | |
| 1908 | // Child packages must be unique |
| 1909 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1910 | String message = "Duplicate child package:" + childPackageName; |
| 1911 | Slog.w(TAG, message); |
| 1912 | outError[0] = message; |
| 1913 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1914 | return false; |
| 1915 | } |
| 1916 | |
| 1917 | // Go ahead and parse the child |
| 1918 | Package childPkg = new Package(childPackageName); |
| 1919 | |
| 1920 | // Child package inherits parent version code/name/target SDK |
| 1921 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1922 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1923 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1924 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1925 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1926 | |
| 1927 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1928 | if (childPkg == null) { |
| 1929 | // If we got null then error was set during child parsing |
| 1930 | return false; |
| 1931 | } |
| 1932 | |
| 1933 | // Set the parent-child relation |
| 1934 | if (parentPkg.childPackages == null) { |
| 1935 | parentPkg.childPackages = new ArrayList<>(); |
| 1936 | } |
| 1937 | parentPkg.childPackages.add(childPkg); |
| 1938 | childPkg.parentPackage = parentPkg; |
| 1939 | |
| 1940 | return true; |
| 1941 | } |
| 1942 | |
| 1943 | /** |
| 1944 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1945 | * need to consider whether they should be supported by split APKs and child |
| 1946 | * packages. |
| 1947 | * |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1948 | * @param apkPath The package apk file path |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1949 | * @param res The resources from which to resolve values |
| 1950 | * @param parser The manifest parser |
| 1951 | * @param flags Flags how to parse |
| 1952 | * @param outError Human readable error message |
| 1953 | * @return Parsed package or null on error. |
| 1954 | * |
| 1955 | * @throws XmlPullParserException |
| 1956 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1957 | */ |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1958 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1959 | private Package parseBaseApk(String apkPath, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1960 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1961 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1962 | final String pkgName; |
| 1963 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1964 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1965 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1966 | pkgName = packageSplit.first; |
| 1967 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1968 | |
| 1969 | if (!TextUtils.isEmpty(splitName)) { |
| 1970 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1971 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1972 | return null; |
| 1973 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1974 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1975 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1976 | return null; |
| 1977 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1978 | |
Jack He | 6103479 | 2019-04-10 23:01:45 +0000 | [diff] [blame] | 1979 | if (mCallback != null) { |
| 1980 | String[] overlayPaths = mCallback.getOverlayPaths(pkgName, apkPath); |
| 1981 | if (overlayPaths != null && overlayPaths.length > 0) { |
| 1982 | for (String overlayPath : overlayPaths) { |
| 1983 | res.getAssets().addOverlayPath(overlayPath); |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1988 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1989 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1990 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1991 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1992 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1993 | pkg.mVersionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 1995 | pkg.mVersionCodeMajor = sa.getInteger( |
| 1996 | com.android.internal.R.styleable.AndroidManifest_versionCodeMajor, 0); |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1997 | pkg.applicationInfo.setVersionCode(pkg.getLongVersionCode()); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1998 | pkg.baseRevisionCode = sa.getInteger( |
| 1999 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2000 | pkg.mVersionName = sa.getNonConfigurationString( |
| 2001 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | if (pkg.mVersionName != null) { |
| 2003 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 2004 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2005 | |
| 2006 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 2007 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 2008 | pkg.mCompileSdkVersion = sa.getInteger( |
| 2009 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersion, 0); |
| 2010 | pkg.applicationInfo.compileSdkVersion = pkg.mCompileSdkVersion; |
| 2011 | pkg.mCompileSdkVersionCodename = sa.getNonConfigurationString( |
| 2012 | com.android.internal.R.styleable.AndroidManifest_compileSdkVersionCodename, 0); |
| 2013 | if (pkg.mCompileSdkVersionCodename != null) { |
| 2014 | pkg.mCompileSdkVersionCodename = pkg.mCompileSdkVersionCodename.intern(); |
| 2015 | } |
| 2016 | pkg.applicationInfo.compileSdkVersionCodename = pkg.mCompileSdkVersionCodename; |
| 2017 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2018 | sa.recycle(); |
| 2019 | |
| 2020 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * This is the common parsing routing for handling parent and child |
| 2025 | * packages in a base APK. The difference between parent and child |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2026 | * parsing is that some tags are not supported by child packages as |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2027 | * well as some manifest attributes are ignored. The implementation |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2028 | * assumes the calling code has already handled the manifest tag if needed |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2029 | * (this applies to the parent only). |
| 2030 | * |
| 2031 | * @param pkg The package which to populate |
| 2032 | * @param acceptedTags Which tags to handle, null to handle all |
| 2033 | * @param res Resources against which to resolve values |
| 2034 | * @param parser Parser of the manifest |
| 2035 | * @param flags Flags about how to parse |
| 2036 | * @param outError Human readable error if parsing fails |
| 2037 | * @return The package if parsing succeeded or null. |
| 2038 | * |
| 2039 | * @throws XmlPullParserException |
| 2040 | * @throws IOException |
| 2041 | */ |
| 2042 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 2043 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 2044 | IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2045 | mParseInstrumentationArgs = null; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2046 | |
| 2047 | int type; |
| 2048 | boolean foundApp = false; |
| 2049 | |
| 2050 | TypedArray sa = res.obtainAttributes(parser, |
| 2051 | com.android.internal.R.styleable.AndroidManifest); |
| 2052 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2053 | String str = sa.getNonConfigurationString( |
| 2054 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 2055 | if (str != null && str.length() > 0) { |
Sudheer Shanka | 9c5079a | 2018-08-03 12:41:10 -0700 | [diff] [blame] | 2056 | String nameError = validateName(str, true, true); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2057 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 2059 | + str + "\": " + nameError; |
| 2060 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 2061 | return null; |
| 2062 | } |
| 2063 | pkg.mSharedUserId = str.intern(); |
| 2064 | pkg.mSharedUserLabel = sa.getResourceId( |
| 2065 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 2066 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 2067 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 2068 | pkg.installLocation = sa.getInteger( |
| 2069 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 2070 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2071 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2072 | |
Todd Kennedy | 11e4507 | 2017-01-25 13:24:21 -0800 | [diff] [blame] | 2073 | final int targetSandboxVersion = sa.getInteger( |
| 2074 | com.android.internal.R.styleable.AndroidManifest_targetSandboxVersion, |
| 2075 | PARSE_DEFAULT_TARGET_SANDBOX); |
| 2076 | pkg.applicationInfo.targetSandboxVersion = targetSandboxVersion; |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 2077 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2078 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2079 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 2080 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 2081 | } |
| 2082 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2083 | if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifest_isolatedSplits, false)) { |
| 2084 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING; |
| 2085 | } |
| 2086 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2087 | // Resource boolean are -1, so 1 means we don't know the value. |
| 2088 | int supportsSmallScreens = 1; |
| 2089 | int supportsNormalScreens = 1; |
| 2090 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2091 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2092 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2093 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2096 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2097 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2098 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | continue; |
| 2100 | } |
| 2101 | |
| 2102 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2103 | |
| 2104 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 2105 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 2106 | + tagName + " at " + mArchiveSourcePath + " " |
| 2107 | + parser.getPositionDescription()); |
| 2108 | XmlUtils.skipCurrentTag(parser); |
| 2109 | continue; |
| 2110 | } |
| 2111 | |
| 2112 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | if (foundApp) { |
| 2114 | if (RIGID_PARSER) { |
| 2115 | outError[0] = "<manifest> has more than one <application>"; |
| 2116 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2117 | return null; |
| 2118 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2119 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | XmlUtils.skipCurrentTag(parser); |
| 2121 | continue; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2126 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2127 | return null; |
| 2128 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2129 | } else if (tagName.equals(TAG_OVERLAY)) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2130 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2131 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 2132 | pkg.mOverlayTarget = sa.getString( |
| 2133 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 2134 | pkg.mOverlayTargetName = sa.getString( |
| 2135 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetName); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 2136 | pkg.mOverlayCategory = sa.getString( |
| 2137 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_category); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2138 | pkg.mOverlayPriority = sa.getInt( |
| 2139 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 2140 | 0); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 2141 | pkg.mOverlayIsStatic = sa.getBoolean( |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2142 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_isStatic, |
| 2143 | false); |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2144 | final String propName = sa.getString( |
| 2145 | com.android.internal.R.styleable |
| 2146 | .AndroidManifestResourceOverlay_requiredSystemPropertyName); |
| 2147 | final String propValue = sa.getString( |
| 2148 | com.android.internal.R.styleable |
| 2149 | .AndroidManifestResourceOverlay_requiredSystemPropertyValue); |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2150 | sa.recycle(); |
| 2151 | |
| 2152 | if (pkg.mOverlayTarget == null) { |
| 2153 | outError[0] = "<overlay> does not specify a target package"; |
| 2154 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2155 | return null; |
| 2156 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2157 | |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 2158 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 2159 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 2160 | mParseError = |
| 2161 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2162 | return null; |
| 2163 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2164 | |
| 2165 | // check to see if overlay should be excluded based on system property condition |
| 2166 | if (!checkOverlayRequiredSystemProperty(propName, propValue)) { |
| 2167 | Slog.i(TAG, "Skipping target and overlay pair " + pkg.mOverlayTarget + " and " |
| 2168 | + pkg.baseCodePath+ ": overlay ignored due to required system property: " |
| 2169 | + propName + " with value: " + propValue); |
| 2170 | return null; |
Jaekyun Seok | 0434289 | 2017-03-02 15:24:19 +0900 | [diff] [blame] | 2171 | } |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2172 | |
Zoran Jovanovic | 946e32f | 2019-02-17 22:02:40 +0100 | [diff] [blame] | 2173 | pkg.applicationInfo.privateFlags |= |
| 2174 | ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY; |
| 2175 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 2176 | XmlUtils.skipCurrentTag(parser); |
| 2177 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2178 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 2179 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2180 | return null; |
| 2181 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2182 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2183 | if (!parsePermissionGroup(pkg, flags, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | return null; |
| 2185 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2186 | } else if (tagName.equals(TAG_PERMISSION)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2187 | if (!parsePermission(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | return null; |
| 2189 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2190 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2191 | if (!parsePermissionTree(pkg, res, parser, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | return null; |
| 2193 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2194 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2195 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2196 | return null; |
| 2197 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2198 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 2199 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2200 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2201 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2203 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2205 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 2207 | cPref.reqTouchScreen = sa.getInt( |
| 2208 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 2209 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 2210 | cPref.reqKeyboardType = sa.getInt( |
| 2211 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 2212 | Configuration.KEYBOARD_UNDEFINED); |
| 2213 | if (sa.getBoolean( |
| 2214 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 2215 | false)) { |
| 2216 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 2217 | } |
| 2218 | cPref.reqNavigation = sa.getInt( |
| 2219 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 2220 | Configuration.NAVIGATION_UNDEFINED); |
| 2221 | if (sa.getBoolean( |
| 2222 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 2223 | false)) { |
| 2224 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 2225 | } |
| 2226 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2227 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | |
| 2229 | XmlUtils.skipCurrentTag(parser); |
| 2230 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2231 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 2232 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2233 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 2234 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2235 | if (fi.name == null) { |
| 2236 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 2237 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2238 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2239 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 2240 | |
| 2241 | XmlUtils.skipCurrentTag(parser); |
| 2242 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2243 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2244 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 2245 | ArrayList<FeatureInfo> features = null; |
| 2246 | final int innerDepth = parser.getDepth(); |
| 2247 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2248 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 2249 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2250 | continue; |
| 2251 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2252 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2253 | final String innerTagName = parser.getName(); |
| 2254 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2255 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2256 | // FeatureGroups are stricter and mandate that |
| 2257 | // any <uses-feature> declared are mandatory. |
| 2258 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2259 | features = ArrayUtils.add(features, featureInfo); |
| 2260 | } else { |
| 2261 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 2262 | " at " + mArchiveSourcePath + " " + |
| 2263 | parser.getPositionDescription()); |
| 2264 | } |
| 2265 | XmlUtils.skipCurrentTag(parser); |
| 2266 | } |
| 2267 | |
| 2268 | if (features != null) { |
| 2269 | group.features = new FeatureInfo[features.size()]; |
| 2270 | group.features = features.toArray(group.features); |
| 2271 | } |
| 2272 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 2273 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2274 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 2275 | if (SDK_VERSION > 0) { |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2276 | sa = res.obtainAttributes(parser, |
| 2277 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2279 | int minVers = 1; |
| 2280 | String minCode = null; |
| 2281 | int targetVers = 0; |
| 2282 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2283 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2284 | TypedValue val = sa.peekValue( |
| 2285 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 2286 | if (val != null) { |
| 2287 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 2288 | minCode = val.string.toString(); |
| 2289 | } else { |
| 2290 | // If it's not a string, it's an integer. |
| 2291 | minVers = val.data; |
| 2292 | } |
| 2293 | } |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2294 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2295 | val = sa.peekValue( |
| 2296 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 2297 | if (val != null) { |
| 2298 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 2299 | targetCode = val.string.toString(); |
| 2300 | if (minCode == null) { |
| 2301 | minCode = targetCode; |
| 2302 | } |
| 2303 | } else { |
| 2304 | // If it's not a string, it's an integer. |
| 2305 | targetVers = val.data; |
| 2306 | } |
| 2307 | } else { |
| 2308 | targetVers = minVers; |
| 2309 | targetCode = minCode; |
| 2310 | } |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2311 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2312 | sa.recycle(); |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2313 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2314 | final int minSdkVersion = PackageParser.computeMinSdkVersion(minVers, minCode, |
| 2315 | SDK_VERSION, SDK_CODENAMES, outError); |
| 2316 | if (minSdkVersion < 0) { |
Victor Hsieh | 4e54b52 | 2018-10-12 15:38:18 -0700 | [diff] [blame] | 2317 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2318 | return null; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2319 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2320 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2321 | final int targetSdkVersion = PackageParser.computeTargetSdkVersion(targetVers, |
| 2322 | targetCode, SDK_CODENAMES, outError); |
| 2323 | if (targetSdkVersion < 0) { |
| 2324 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 2325 | return null; |
| 2326 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2327 | |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2328 | pkg.applicationInfo.minSdkVersion = minSdkVersion; |
| 2329 | pkg.applicationInfo.targetSdkVersion = targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | } |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | XmlUtils.skipCurrentTag(parser); |
Victor Hsieh | 5430598 | 2019-03-12 10:09:39 -0700 | [diff] [blame] | 2333 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2334 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 2335 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2336 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 2337 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2338 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 2339 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 2340 | 0); |
| 2341 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 2342 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 2343 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 2344 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 2345 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 2346 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 2347 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2348 | // This is a trick to get a boolean and still able to detect |
| 2349 | // if a value was actually set. |
| 2350 | supportsSmallScreens = sa.getInteger( |
| 2351 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 2352 | supportsSmallScreens); |
| 2353 | supportsNormalScreens = sa.getInteger( |
| 2354 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 2355 | supportsNormalScreens); |
| 2356 | supportsLargeScreens = sa.getInteger( |
| 2357 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 2358 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2359 | supportsXLargeScreens = sa.getInteger( |
| 2360 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 2361 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2362 | resizeable = sa.getInteger( |
| 2363 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2364 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2365 | anyDensity = sa.getInteger( |
| 2366 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 2367 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2368 | |
| 2369 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2370 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2371 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2372 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2373 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 2374 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2375 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 2376 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2377 | // Note: don't allow this value to be a reference to a resource |
| 2378 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2379 | String name = sa.getNonResourceString( |
| 2380 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 2381 | |
| 2382 | sa.recycle(); |
| 2383 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 2384 | if (name != null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2385 | if (pkg.protectedBroadcasts == null) { |
| 2386 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 2387 | } |
| 2388 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 2389 | pkg.protectedBroadcasts.add(name.intern()); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | XmlUtils.skipCurrentTag(parser); |
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_INSTRUMENTATION)) { |
| 2396 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2397 | return null; |
| 2398 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2399 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2400 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2401 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2402 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2403 | String orig =sa.getNonConfigurationString( |
| 2404 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2405 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2406 | if (pkg.mOriginalPackages == null) { |
| 2407 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2408 | pkg.mRealPackage = pkg.packageName; |
| 2409 | } |
| 2410 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2411 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2412 | |
| 2413 | sa.recycle(); |
| 2414 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2415 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2416 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2417 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2418 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2419 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2420 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2421 | String name = sa.getNonConfigurationString( |
| 2422 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2423 | |
| 2424 | sa.recycle(); |
| 2425 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2426 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2427 | if (pkg.mAdoptPermissions == null) { |
| 2428 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2429 | } |
| 2430 | pkg.mAdoptPermissions.add(name); |
| 2431 | } |
| 2432 | |
| 2433 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2434 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2435 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2436 | // Just skip this tag |
| 2437 | XmlUtils.skipCurrentTag(parser); |
| 2438 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2439 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2440 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2441 | // Just skip this tag |
| 2442 | XmlUtils.skipCurrentTag(parser); |
| 2443 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2444 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2445 | XmlUtils.skipCurrentTag(parser); |
| 2446 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2447 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2448 | } else if (tagName.equals(TAG_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2449 | // Just skip this tag |
| 2450 | XmlUtils.skipCurrentTag(parser); |
| 2451 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2452 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2453 | } else if (tagName.equals(TAG_PACKAGE)) { |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame] | 2454 | if (!MULTI_PACKAGE_APK_ENABLED) { |
| 2455 | XmlUtils.skipCurrentTag(parser); |
| 2456 | continue; |
| 2457 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2458 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2459 | // If parsing a child failed the error is already set |
| 2460 | return null; |
| 2461 | } |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2462 | |
| 2463 | } else if (tagName.equals(TAG_RESTRICT_UPDATE)) { |
| 2464 | if ((flags & PARSE_IS_SYSTEM_DIR) != 0) { |
| 2465 | sa = res.obtainAttributes(parser, |
| 2466 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate); |
| 2467 | final String hash = sa.getNonConfigurationString( |
| 2468 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0); |
| 2469 | sa.recycle(); |
| 2470 | |
| 2471 | pkg.restrictUpdateHash = null; |
| 2472 | if (hash != null) { |
| 2473 | final int hashLength = hash.length(); |
| 2474 | final byte[] hashBytes = new byte[hashLength / 2]; |
| 2475 | for (int i = 0; i < hashLength; i += 2){ |
| 2476 | hashBytes[i/2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) |
| 2477 | + Character.digit(hash.charAt(i + 1), 16)); |
| 2478 | } |
| 2479 | pkg.restrictUpdateHash = hashBytes; |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | XmlUtils.skipCurrentTag(parser); |
| 2484 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2485 | } else if (RIGID_PARSER) { |
| 2486 | outError[0] = "Bad element under <manifest>: " |
| 2487 | + parser.getName(); |
| 2488 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2489 | return null; |
| 2490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2492 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2493 | + " at " + mArchiveSourcePath + " " |
| 2494 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | XmlUtils.skipCurrentTag(parser); |
| 2496 | continue; |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2501 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2502 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2503 | } |
| 2504 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2505 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2506 | StringBuilder newPermsMsg = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2507 | for (int ip=0; ip<NP; ip++) { |
| 2508 | final PackageParser.NewPermissionInfo npi |
| 2509 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2510 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2511 | break; |
| 2512 | } |
| 2513 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2514 | if (newPermsMsg == null) { |
| 2515 | newPermsMsg = new StringBuilder(128); |
| 2516 | newPermsMsg.append(pkg.packageName); |
| 2517 | newPermsMsg.append(": compat added "); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2518 | } else { |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2519 | newPermsMsg.append(' '); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2520 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2521 | newPermsMsg.append(npi.name); |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2522 | pkg.requestedPermissions.add(npi.name); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2523 | pkg.implicitPermissions.add(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2524 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2525 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2526 | if (newPermsMsg != null) { |
| 2527 | Slog.i(TAG, newPermsMsg.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2528 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2529 | |
Anthony Hugh | 6f5eadc | 2019-08-22 15:35:48 -0700 | [diff] [blame] | 2530 | List<SplitPermissionInfoParcelable> splitPermissions = getSplitPermissions(); |
| 2531 | final int listSize = splitPermissions.size(); |
| 2532 | for (int is = 0; is < listSize; is++) { |
| 2533 | final SplitPermissionInfoParcelable spi = splitPermissions.get(is); |
Philip P. Moltmann | 039678e | 2018-09-18 13:04:38 -0700 | [diff] [blame] | 2534 | if (pkg.applicationInfo.targetSdkVersion >= spi.getTargetSdk() |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2535 | || !pkg.requestedPermissions.contains(spi.getSplitPermission())) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2536 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2537 | } |
Philip P. Moltmann | a3ba4d9 | 2018-10-08 11:50:07 -0700 | [diff] [blame] | 2538 | final List<String> newPerms = spi.getNewPermissions(); |
| 2539 | for (int in = 0; in < newPerms.size(); in++) { |
| 2540 | final String perm = newPerms.get(in); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2541 | if (!pkg.requestedPermissions.contains(perm)) { |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2542 | pkg.requestedPermissions.add(perm); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 2543 | pkg.implicitPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | } |
| 2547 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2548 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2549 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2550 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2551 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2552 | } |
| 2553 | if (supportsNormalScreens != 0) { |
| 2554 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2555 | } |
| 2556 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2557 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2558 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2559 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2560 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2561 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2562 | && pkg.applicationInfo.targetSdkVersion |
| 2563 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2564 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2565 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2566 | if (resizeable < 0 || (resizeable > 0 |
| 2567 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2568 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2569 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2570 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2571 | if (anyDensity < 0 || (anyDensity > 0 |
| 2572 | && pkg.applicationInfo.targetSdkVersion |
| 2573 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2574 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2575 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2576 | |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2577 | // At this point we can check if an application is not supporting densities and hence |
| 2578 | // cannot be windowed / resized. Note that an SDK version of 0 is common for |
| 2579 | // pre-Doughnut applications. |
| 2580 | if (pkg.applicationInfo.usesCompatibilityMode()) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2581 | adjustPackageToBeUnresizeableAndUnpipable(pkg); |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2582 | } |
Jeff Sharkey | 4aacd8b | 2018-07-24 15:24:21 -0600 | [diff] [blame] | 2583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | return pkg; |
| 2585 | } |
| 2586 | |
Anthony Hugh | 6f5eadc | 2019-08-22 15:35:48 -0700 | [diff] [blame] | 2587 | private List<SplitPermissionInfoParcelable> getSplitPermissions() { |
| 2588 | // PackageManager runs this code during initialization prior to registering with |
| 2589 | // ServiceManager, so we can't use the PackageManager API. Instead, just read from |
| 2590 | // SystemConfig directly when in any SystemProcess and only use PackageManager when not in |
| 2591 | // one. |
| 2592 | if (ActivityThread.isSystem()) { |
| 2593 | return PermissionManager.splitPermissionInfoListToParcelableList( |
| 2594 | SystemConfig.getInstance().getSplitPermissions()); |
| 2595 | } else { |
| 2596 | try { |
| 2597 | return ActivityThread.getPackageManager().getSplitPermissions(); |
| 2598 | } catch (RemoteException e) { |
| 2599 | throw e.rethrowFromSystemServer(); |
| 2600 | } |
| 2601 | } |
| 2602 | } |
| 2603 | |
Todd Lee | ea2f3be | 2017-03-16 14:00:52 -0700 | [diff] [blame] | 2604 | private boolean checkOverlayRequiredSystemProperty(String propName, String propValue) { |
| 2605 | |
| 2606 | if (TextUtils.isEmpty(propName) || TextUtils.isEmpty(propValue)) { |
| 2607 | if (!TextUtils.isEmpty(propName) || !TextUtils.isEmpty(propValue)) { |
| 2608 | // malformed condition - incomplete |
| 2609 | Slog.w(TAG, "Disabling overlay - incomplete property :'" + propName |
| 2610 | + "=" + propValue + "' - require both requiredSystemPropertyName" |
| 2611 | + " AND requiredSystemPropertyValue to be specified."); |
| 2612 | return false; |
| 2613 | } |
| 2614 | // no valid condition set - so no exclusion criteria, overlay will be included. |
| 2615 | return true; |
| 2616 | } |
| 2617 | |
| 2618 | // check property value - make sure it is both set and equal to expected value |
| 2619 | final String currValue = SystemProperties.get(propName); |
| 2620 | return (currValue != null && currValue.equals(propValue)); |
| 2621 | } |
| 2622 | |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2623 | /** |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2624 | * This is a pre-density application which will get scaled - instead of being pixel perfect. |
| 2625 | * This type of application is not resizable. |
| 2626 | * |
| 2627 | * @param pkg The package which needs to be marked as unresizable. |
| 2628 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2629 | private void adjustPackageToBeUnresizeableAndUnpipable(Package pkg) { |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2630 | for (Activity a : pkg.activities) { |
| 2631 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2632 | a.info.flags &= ~FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
skuhne@google.com | 7e85eb0 | 2017-01-04 13:49:54 -0800 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /** |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 2637 | |
| 2638 | /** |
Narayan Kamath | 71fcc14 | 2019-01-15 18:20:39 +0000 | [diff] [blame] | 2639 | * Matches a given {@code targetCode} against a set of release codeNames. Target codes can |
| 2640 | * either be of the form {@code [codename]}" (e.g {@code "Q"}) or of the form |
| 2641 | * {@code [codename].[fingerprint]} (e.g {@code "Q.cafebc561"}). |
| 2642 | */ |
| 2643 | private static boolean matchTargetCode(@NonNull String[] codeNames, |
| 2644 | @NonNull String targetCode) { |
| 2645 | final String targetCodeName; |
| 2646 | final int targetCodeIdx = targetCode.indexOf('.'); |
| 2647 | if (targetCodeIdx == -1) { |
| 2648 | targetCodeName = targetCode; |
| 2649 | } else { |
| 2650 | targetCodeName = targetCode.substring(0, targetCodeIdx); |
| 2651 | } |
| 2652 | return ArrayUtils.contains(codeNames, targetCodeName); |
| 2653 | } |
| 2654 | |
| 2655 | /** |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2656 | * Computes the targetSdkVersion to use at runtime. If the package is not |
| 2657 | * compatible with this platform, populates {@code outError[0]} with an |
| 2658 | * error message. |
| 2659 | * <p> |
| 2660 | * If {@code targetCode} is not specified, e.g. the value is {@code null}, |
| 2661 | * then the {@code targetVers} will be returned unmodified. |
| 2662 | * <p> |
| 2663 | * Otherwise, the behavior varies based on whether the current platform |
| 2664 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2665 | * has length > 0: |
| 2666 | * <ul> |
| 2667 | * <li>If this is a pre-release platform and the value specified by |
| 2668 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2669 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2670 | * <li>If this is a released platform, this method will return -1 to |
| 2671 | * indicate that the package is not compatible with this platform. |
| 2672 | * </ul> |
| 2673 | * |
| 2674 | * @param targetVers targetSdkVersion number, if specified in the |
| 2675 | * application manifest, or 0 otherwise |
| 2676 | * @param targetCode targetSdkVersion code, if specified in the application |
| 2677 | * manifest, or {@code null} otherwise |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2678 | * @param platformSdkCodenames array of allowed pre-release SDK codenames |
| 2679 | * for this platform |
| 2680 | * @param outError output array to populate with error, if applicable |
| 2681 | * @return the targetSdkVersion to use at runtime, or -1 if the package is |
| 2682 | * not compatible with this platform |
| 2683 | * @hide Exposed for unit testing only. |
| 2684 | */ |
| 2685 | @TestApi |
| 2686 | public static int computeTargetSdkVersion(@IntRange(from = 0) int targetVers, |
Patrick Baumann | ccb20b8 | 2018-01-08 13:22:46 -0800 | [diff] [blame] | 2687 | @Nullable String targetCode, @NonNull String[] platformSdkCodenames, |
Nicholas Lativy | eb23e4d | 2019-02-01 13:39:28 +0000 | [diff] [blame] | 2688 | @NonNull String[] outError) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2689 | // If it's a release SDK, return the version number unmodified. |
| 2690 | if (targetCode == null) { |
| 2691 | return targetVers; |
| 2692 | } |
| 2693 | |
| 2694 | // If it's a pre-release SDK and the codename matches this platform, it |
| 2695 | // definitely targets this SDK. |
Nicholas Lativy | eb23e4d | 2019-02-01 13:39:28 +0000 | [diff] [blame] | 2696 | if (matchTargetCode(platformSdkCodenames, targetCode)) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2697 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2698 | } |
| 2699 | |
| 2700 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2701 | if (platformSdkCodenames.length > 0) { |
| 2702 | outError[0] = "Requires development platform " + targetCode |
| 2703 | + " (current platform is any of " |
| 2704 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2705 | } else { |
| 2706 | outError[0] = "Requires development platform " + targetCode |
| 2707 | + " but this is a release platform."; |
| 2708 | } |
| 2709 | return -1; |
| 2710 | } |
| 2711 | |
| 2712 | /** |
| 2713 | * Computes the minSdkVersion to use at runtime. If the package is not |
| 2714 | * compatible with this platform, populates {@code outError[0]} with an |
| 2715 | * error message. |
| 2716 | * <p> |
| 2717 | * If {@code minCode} is not specified, e.g. the value is {@code null}, |
| 2718 | * then behavior varies based on the {@code platformSdkVersion}: |
| 2719 | * <ul> |
| 2720 | * <li>If the platform SDK version is greater than or equal to the |
| 2721 | * {@code minVers}, returns the {@code mniVers} unmodified. |
| 2722 | * <li>Otherwise, returns -1 to indicate that the package is not |
| 2723 | * compatible with this platform. |
| 2724 | * </ul> |
| 2725 | * <p> |
| 2726 | * Otherwise, the behavior varies based on whether the current platform |
| 2727 | * is a pre-release version, e.g. the {@code platformSdkCodenames} array |
| 2728 | * has length > 0: |
| 2729 | * <ul> |
| 2730 | * <li>If this is a pre-release platform and the value specified by |
| 2731 | * {@code targetCode} is contained within the array of allowed pre-release |
| 2732 | * codenames, this method will return {@link Build.VERSION_CODES#CUR_DEVELOPMENT}. |
| 2733 | * <li>If this is a released platform, this method will return -1 to |
| 2734 | * indicate that the package is not compatible with this platform. |
| 2735 | * </ul> |
| 2736 | * |
| 2737 | * @param minVers minSdkVersion number, if specified in the application |
| 2738 | * manifest, or 1 otherwise |
| 2739 | * @param minCode minSdkVersion code, if specified in the application |
| 2740 | * manifest, or {@code null} otherwise |
| 2741 | * @param platformSdkVersion platform SDK version number, typically |
| 2742 | * Build.VERSION.SDK_INT |
| 2743 | * @param platformSdkCodenames array of allowed prerelease SDK codenames |
| 2744 | * for this platform |
| 2745 | * @param outError output array to populate with error, if applicable |
| 2746 | * @return the minSdkVersion to use at runtime, or -1 if the package is not |
| 2747 | * compatible with this platform |
| 2748 | * @hide Exposed for unit testing only. |
| 2749 | */ |
| 2750 | @TestApi |
| 2751 | public static int computeMinSdkVersion(@IntRange(from = 1) int minVers, |
| 2752 | @Nullable String minCode, @IntRange(from = 1) int platformSdkVersion, |
| 2753 | @NonNull String[] platformSdkCodenames, @NonNull String[] outError) { |
| 2754 | // If it's a release SDK, make sure we meet the minimum SDK requirement. |
| 2755 | if (minCode == null) { |
| 2756 | if (minVers <= platformSdkVersion) { |
| 2757 | return minVers; |
| 2758 | } |
| 2759 | |
| 2760 | // We don't meet the minimum SDK requirement. |
| 2761 | outError[0] = "Requires newer sdk version #" + minVers |
| 2762 | + " (current version is #" + platformSdkVersion + ")"; |
| 2763 | return -1; |
| 2764 | } |
| 2765 | |
| 2766 | // If it's a pre-release SDK and the codename matches this platform, we |
| 2767 | // definitely meet the minimum SDK requirement. |
Narayan Kamath | 71fcc14 | 2019-01-15 18:20:39 +0000 | [diff] [blame] | 2768 | if (matchTargetCode(platformSdkCodenames, minCode)) { |
Alan Viverette | 82f4b263a | 2016-12-19 15:40:05 -0500 | [diff] [blame] | 2769 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 2770 | } |
| 2771 | |
| 2772 | // Otherwise, we're looking at an incompatible pre-release SDK. |
| 2773 | if (platformSdkCodenames.length > 0) { |
| 2774 | outError[0] = "Requires development platform " + minCode |
| 2775 | + " (current platform is any of " |
| 2776 | + Arrays.toString(platformSdkCodenames) + ")"; |
| 2777 | } else { |
| 2778 | outError[0] = "Requires development platform " + minCode |
| 2779 | + " but this is a release platform."; |
| 2780 | } |
| 2781 | return -1; |
| 2782 | } |
| 2783 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2784 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2785 | FeatureInfo fi = new FeatureInfo(); |
| 2786 | TypedArray sa = res.obtainAttributes(attrs, |
| 2787 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2788 | // Note: don't allow this value to be a reference to a resource |
| 2789 | // that may change. |
| 2790 | fi.name = sa.getNonResourceString( |
| 2791 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2792 | fi.version = sa.getInt( |
| 2793 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2794 | if (fi.name == null) { |
| 2795 | fi.reqGlEsVersion = sa.getInt( |
| 2796 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2797 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2798 | } |
| 2799 | if (sa.getBoolean( |
| 2800 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2801 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2802 | } |
| 2803 | sa.recycle(); |
| 2804 | return fi; |
| 2805 | } |
| 2806 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2807 | private boolean parseUsesStaticLibrary(Package pkg, Resources res, XmlResourceParser parser, |
| 2808 | String[] outError) throws XmlPullParserException, IOException { |
| 2809 | TypedArray sa = res.obtainAttributes(parser, |
| 2810 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary); |
| 2811 | |
| 2812 | // Note: don't allow this value to be a reference to a resource that may change. |
| 2813 | String lname = sa.getNonResourceString( |
| 2814 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 2815 | final int version = sa.getInt( |
| 2816 | com.android.internal.R.styleable.AndroidManifestUsesStaticLibrary_version, -1); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2817 | String certSha256Digest = sa.getNonResourceString(com.android.internal.R.styleable |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2818 | .AndroidManifestUsesStaticLibrary_certDigest); |
| 2819 | sa.recycle(); |
| 2820 | |
| 2821 | // 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] | 2822 | if (lname == null || version < 0 || certSha256Digest == null) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2823 | outError[0] = "Bad uses-static-library declaration name: " + lname + " version: " |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2824 | + version + " certDigest" + certSha256Digest; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2825 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2826 | XmlUtils.skipCurrentTag(parser); |
| 2827 | return false; |
| 2828 | } |
| 2829 | |
| 2830 | // Can depend only on one version of the same library |
| 2831 | if (pkg.usesStaticLibraries != null && pkg.usesStaticLibraries.contains(lname)) { |
| 2832 | outError[0] = "Depending on multiple versions of static library " + lname; |
| 2833 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2834 | XmlUtils.skipCurrentTag(parser); |
| 2835 | return false; |
| 2836 | } |
| 2837 | |
| 2838 | lname = lname.intern(); |
| 2839 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2840 | // emitted by the certtool making it easy for developers to copy/paste. |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2841 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2842 | |
| 2843 | // Fot apps targeting O-MR1 we require explicit enumeration of all certs. |
| 2844 | String[] additionalCertSha256Digests = EmptyArray.STRING; |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 2845 | if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O_MR1) { |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2846 | additionalCertSha256Digests = parseAdditionalCertificates(res, parser, outError); |
| 2847 | if (additionalCertSha256Digests == null) { |
| 2848 | return false; |
| 2849 | } |
| 2850 | } else { |
| 2851 | XmlUtils.skipCurrentTag(parser); |
| 2852 | } |
| 2853 | |
| 2854 | final String[] certSha256Digests = new String[additionalCertSha256Digests.length + 1]; |
| 2855 | certSha256Digests[0] = certSha256Digest; |
| 2856 | System.arraycopy(additionalCertSha256Digests, 0, certSha256Digests, |
| 2857 | 1, additionalCertSha256Digests.length); |
| 2858 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2859 | pkg.usesStaticLibraries = ArrayUtils.add(pkg.usesStaticLibraries, lname); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2860 | pkg.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 8a10ef5 | 2017-02-16 20:58:09 -0800 | [diff] [blame] | 2861 | pkg.usesStaticLibrariesVersions, version, true); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2862 | pkg.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, |
| 2863 | pkg.usesStaticLibrariesCertDigests, certSha256Digests, true); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2864 | |
| 2865 | return true; |
| 2866 | } |
| 2867 | |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 2868 | private String[] parseAdditionalCertificates(Resources resources, XmlResourceParser parser, |
| 2869 | String[] outError) throws XmlPullParserException, IOException { |
| 2870 | String[] certSha256Digests = EmptyArray.STRING; |
| 2871 | |
| 2872 | int outerDepth = parser.getDepth(); |
| 2873 | int type; |
| 2874 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2875 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2876 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2877 | continue; |
| 2878 | } |
| 2879 | |
| 2880 | final String nodeName = parser.getName(); |
| 2881 | if (nodeName.equals("additional-certificate")) { |
| 2882 | final TypedArray sa = resources.obtainAttributes(parser, com.android.internal. |
| 2883 | R.styleable.AndroidManifestAdditionalCertificate); |
| 2884 | String certSha256Digest = sa.getNonResourceString(com.android.internal. |
| 2885 | R.styleable.AndroidManifestAdditionalCertificate_certDigest); |
| 2886 | sa.recycle(); |
| 2887 | |
| 2888 | if (TextUtils.isEmpty(certSha256Digest)) { |
| 2889 | outError[0] = "Bad additional-certificate declaration with empty" |
| 2890 | + " certDigest:" + certSha256Digest; |
| 2891 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2892 | XmlUtils.skipCurrentTag(parser); |
| 2893 | sa.recycle(); |
| 2894 | return null; |
| 2895 | } |
| 2896 | |
| 2897 | // We allow ":" delimiters in the SHA declaration as this is the format |
| 2898 | // emitted by the certtool making it easy for developers to copy/paste. |
| 2899 | certSha256Digest = certSha256Digest.replace(":", "").toLowerCase(); |
| 2900 | certSha256Digests = ArrayUtils.appendElement(String.class, |
| 2901 | certSha256Digests, certSha256Digest); |
| 2902 | } else { |
| 2903 | XmlUtils.skipCurrentTag(parser); |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | return certSha256Digests; |
| 2908 | } |
| 2909 | |
Chad Brubaker | e210731 | 2019-02-04 12:30:01 -0800 | [diff] [blame] | 2910 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2911 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2912 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2913 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2914 | |
| 2915 | // Note: don't allow this value to be a reference to a resource |
| 2916 | // that may change. |
| 2917 | String name = sa.getNonResourceString( |
| 2918 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2919 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2920 | int maxSdkVersion = 0; |
| 2921 | TypedValue val = sa.peekValue( |
| 2922 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2923 | if (val != null) { |
| 2924 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2925 | maxSdkVersion = val.data; |
| 2926 | } |
| 2927 | } |
| 2928 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2929 | final String requiredFeature = sa.getNonConfigurationString( |
| 2930 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredFeature, 0); |
| 2931 | |
| 2932 | final String requiredNotfeature = sa.getNonConfigurationString( |
| 2933 | com.android.internal.R.styleable.AndroidManifestUsesPermission_requiredNotFeature, 0); |
| 2934 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2935 | sa.recycle(); |
| 2936 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2937 | XmlUtils.skipCurrentTag(parser); |
| 2938 | |
| 2939 | if (name == null) { |
| 2940 | return true; |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 2943 | if ((maxSdkVersion != 0) && (maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT)) { |
| 2944 | return true; |
| 2945 | } |
| 2946 | |
| 2947 | // Only allow requesting this permission if the platform supports the given feature. |
| 2948 | if (requiredFeature != null && mCallback != null && !mCallback.hasFeature(requiredFeature)) { |
| 2949 | return true; |
| 2950 | } |
| 2951 | |
| 2952 | // Only allow requesting this permission if the platform doesn't support the given feature. |
| 2953 | if (requiredNotfeature != null && mCallback != null |
| 2954 | && mCallback.hasFeature(requiredNotfeature)) { |
| 2955 | return true; |
| 2956 | } |
| 2957 | |
| 2958 | int index = pkg.requestedPermissions.indexOf(name); |
| 2959 | if (index == -1) { |
| 2960 | pkg.requestedPermissions.add(name.intern()); |
| 2961 | } else { |
| 2962 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2963 | + name + " in package: " + pkg.packageName + " at: " |
| 2964 | + parser.getPositionDescription()); |
| 2965 | } |
| 2966 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2967 | return true; |
| 2968 | } |
| 2969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2971 | String[] outError) { |
| 2972 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2973 | outError[0] = "Empty class name in package " + pkg; |
| 2974 | return null; |
| 2975 | } |
| 2976 | String cls = clsSeq.toString(); |
| 2977 | char c = cls.charAt(0); |
| 2978 | if (c == '.') { |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2979 | return pkg + cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | } |
| 2981 | if (cls.indexOf('.') < 0) { |
| 2982 | StringBuilder b = new StringBuilder(pkg); |
| 2983 | b.append('.'); |
| 2984 | b.append(cls); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2985 | return b.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 2987 | return cls; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | private static String buildCompoundName(String pkg, |
| 2991 | CharSequence procSeq, String type, String[] outError) { |
| 2992 | String proc = procSeq.toString(); |
| 2993 | char c = proc.charAt(0); |
| 2994 | if (pkg != null && c == ':') { |
| 2995 | if (proc.length() < 2) { |
| 2996 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2997 | + ": must be at least two characters"; |
| 2998 | return null; |
| 2999 | } |
| 3000 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 3001 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | if (nameError != null) { |
| 3003 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 3004 | + pkg + ": " + nameError; |
| 3005 | return null; |
| 3006 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 3007 | return pkg + proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 3009 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | if (nameError != null && !"system".equals(proc)) { |
| 3011 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 3012 | + pkg + ": " + nameError; |
| 3013 | return null; |
| 3014 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 3015 | return proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | private static String buildProcessName(String pkg, String defProc, |
| 3019 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 3020 | String[] outError) { |
| 3021 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 3022 | return defProc != null ? defProc : pkg; |
| 3023 | } |
| 3024 | if (separateProcesses != null) { |
| 3025 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 3026 | String sp = separateProcesses[i]; |
| 3027 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 3028 | return pkg; |
| 3029 | } |
| 3030 | } |
| 3031 | } |
| 3032 | if (procSeq == null || procSeq.length() <= 0) { |
| 3033 | return defProc; |
| 3034 | } |
Makoto Onuki | 812d188a | 2017-08-07 09:58:23 -0700 | [diff] [blame] | 3035 | return TextUtils.safeIntern(buildCompoundName(pkg, procSeq, "process", outError)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 3039 | CharSequence procSeq, String[] outError) { |
| 3040 | if (procSeq == null) { |
| 3041 | return defProc; |
| 3042 | } |
| 3043 | if (procSeq.length() <= 0) { |
| 3044 | return null; |
| 3045 | } |
| 3046 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 3047 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3048 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3049 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3050 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3051 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3052 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3053 | // all the keys and keysets that we want must be defined here |
| 3054 | // so we're going to iterate over the parser and pull out the things we want |
| 3055 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3056 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3057 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3058 | String currentKeySet = null; |
| 3059 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 3060 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 3061 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 3062 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3063 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3064 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3065 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3066 | if (parser.getDepth() == currentKeySetDepth) { |
| 3067 | currentKeySet = null; |
| 3068 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3069 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3070 | continue; |
| 3071 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3072 | String tagName = parser.getName(); |
| 3073 | if (tagName.equals("key-set")) { |
| 3074 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3075 | outError[0] = "Improperly nested 'key-set' tag at " |
| 3076 | + parser.getPositionDescription(); |
| 3077 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3078 | return false; |
| 3079 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3080 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3081 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 3082 | final String keysetName = sa.getNonResourceString( |
| 3083 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 3084 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 3085 | currentKeySet = keysetName; |
| 3086 | currentKeySetDepth = parser.getDepth(); |
| 3087 | sa.recycle(); |
| 3088 | } else if (tagName.equals("public-key")) { |
| 3089 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3090 | outError[0] = "Improperly nested 'key-set' tag at " |
| 3091 | + parser.getPositionDescription(); |
| 3092 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3093 | return false; |
| 3094 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3095 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3096 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 3097 | final String publicKeyName = sa.getNonResourceString( |
| 3098 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3099 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3100 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 3101 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3102 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 3103 | + " on first use at " + parser.getPositionDescription(); |
| 3104 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3105 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3106 | return false; |
| 3107 | } else if (encodedKey != null) { |
| 3108 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 3109 | if (currentKey == null) { |
| 3110 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 3111 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 3112 | + " will not be added to the package's defined key-sets."); |
| 3113 | sa.recycle(); |
| 3114 | improperKeySets.add(currentKeySet); |
| 3115 | XmlUtils.skipCurrentTag(parser); |
| 3116 | continue; |
| 3117 | } |
| 3118 | if (publicKeys.get(publicKeyName) == null |
| 3119 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 3120 | |
| 3121 | /* public-key first definition, or matches old definition */ |
| 3122 | publicKeys.put(publicKeyName, currentKey); |
| 3123 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3124 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3125 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3126 | + parser.getPositionDescription(); |
| 3127 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3128 | sa.recycle(); |
| 3129 | return false; |
| 3130 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 3131 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3132 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3133 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3134 | XmlUtils.skipCurrentTag(parser); |
| 3135 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3136 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3137 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 3138 | String name = sa.getNonResourceString( |
| 3139 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 3140 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3141 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3142 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3143 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3144 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3145 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3146 | + parser.getPositionDescription(); |
| 3147 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3148 | return false; |
| 3149 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3150 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3151 | + " at " + mArchiveSourcePath + " " |
| 3152 | + parser.getPositionDescription()); |
| 3153 | XmlUtils.skipCurrentTag(parser); |
| 3154 | continue; |
| 3155 | } |
| 3156 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3157 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 3158 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3159 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 3160 | + "'key-set' and 'public-key' names must be distinct."; |
| 3161 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3162 | return false; |
| 3163 | } |
| 3164 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 3165 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 3166 | final String keySetName = e.getKey(); |
| 3167 | if (e.getValue().size() == 0) { |
| 3168 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3169 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 3170 | + " Not including in package's defined key-sets."); |
| 3171 | continue; |
| 3172 | } else if (improperKeySets.contains(keySetName)) { |
| 3173 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 3174 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 3175 | + " tags. Not including in package's defined key-sets."); |
| 3176 | continue; |
| 3177 | } |
| 3178 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 3179 | for (String s : e.getValue()) { |
| 3180 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3181 | } |
| 3182 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3183 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 3184 | owner.mUpgradeKeySets = upgradeKeySets; |
| 3185 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 3186 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 3187 | + "does not define all 'upgrade-key-set's ."; |
| 3188 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 3189 | return false; |
| 3190 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3191 | return true; |
| 3192 | } |
| 3193 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3194 | private boolean parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3195 | XmlResourceParser parser, String[] outError) |
| 3196 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3197 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 3199 | |
| 3200 | int requestDetailResourceId = sa.getResourceId( |
| 3201 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_requestDetail, 0); |
| 3202 | int backgroundRequestResourceId = sa.getResourceId( |
| 3203 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_backgroundRequest, |
| 3204 | 0); |
| 3205 | int backgroundRequestDetailResourceId = sa.getResourceId( |
| 3206 | com.android.internal.R.styleable |
| 3207 | .AndroidManifestPermissionGroup_backgroundRequestDetail, 0); |
| 3208 | |
| 3209 | PermissionGroup perm = new PermissionGroup(owner, requestDetailResourceId, |
| 3210 | backgroundRequestResourceId, backgroundRequestDetailResourceId); |
| 3211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3213 | "<permission-group>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 3215 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3216 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3217 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3218 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 3219 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | sa.recycle(); |
| 3221 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3222 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | perm.info.descriptionRes = sa.getResourceId( |
| 3226 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 3227 | 0); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3228 | perm.info.requestRes = sa.getResourceId( |
| 3229 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 3230 | perm.info.flags = sa.getInt( |
| 3231 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 3232 | perm.info.priority = sa.getInt( |
| 3233 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | |
| 3235 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3236 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3237 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | outError)) { |
| 3239 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3240 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | owner.permissionGroups.add(perm); |
| 3244 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3245 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3248 | private boolean parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3249 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3252 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 3254 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 3255 | String backgroundPermission = null; |
| 3256 | if (sa.hasValue( |
| 3257 | com.android.internal.R.styleable.AndroidManifestPermission_backgroundPermission)) { |
| 3258 | if ("android".equals(owner.packageName)) { |
| 3259 | backgroundPermission = sa.getNonResourceString( |
| 3260 | com.android.internal.R.styleable |
| 3261 | .AndroidManifestPermission_backgroundPermission); |
| 3262 | } else { |
| 3263 | Slog.w(TAG, owner.packageName + " defines a background permission. Only the " |
| 3264 | + "'android' package can do that."); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | Permission perm = new Permission(owner, backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3270 | "<permission>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3271 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 3272 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3273 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3274 | com.android.internal.R.styleable.AndroidManifestPermission_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3275 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 3276 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | sa.recycle(); |
| 3278 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3279 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | } |
| 3281 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3282 | // Note: don't allow this value to be a reference to a resource |
| 3283 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | perm.info.group = sa.getNonResourceString( |
| 3285 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 3286 | if (perm.info.group != null) { |
| 3287 | perm.info.group = perm.info.group.intern(); |
| 3288 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | perm.info.descriptionRes = sa.getResourceId( |
| 3291 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 3292 | 0); |
| 3293 | |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3294 | perm.info.requestRes = sa.getResourceId( |
| 3295 | com.android.internal.R.styleable.AndroidManifestPermission_request, 0); |
| 3296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | perm.info.protectionLevel = sa.getInt( |
| 3298 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 3299 | PermissionInfo.PROTECTION_NORMAL); |
| 3300 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 3301 | perm.info.flags = sa.getInt( |
| 3302 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 3303 | |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 3304 | // For now only platform runtime permissions can be restricted |
| 3305 | if (!perm.info.isRuntime() || !"android".equals(perm.info.packageName)) { |
| 3306 | perm.info.flags &= ~PermissionInfo.FLAG_HARD_RESTRICTED; |
| 3307 | perm.info.flags &= ~PermissionInfo.FLAG_SOFT_RESTRICTED; |
| 3308 | } else { |
| 3309 | // The platform does not get to specify conflicting permissions |
| 3310 | if ((perm.info.flags & PermissionInfo.FLAG_HARD_RESTRICTED) != 0 |
| 3311 | && (perm.info.flags & PermissionInfo.FLAG_SOFT_RESTRICTED) != 0) { |
| 3312 | throw new IllegalStateException("Permission cannot be both soft and hard" |
| 3313 | + " restricted: " + perm.info.name); |
| 3314 | } |
| 3315 | } |
| 3316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | if (perm.info.protectionLevel == -1) { |
| 3320 | outError[0] = "<permission> does not specify protectionLevel"; |
| 3321 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3322 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3324 | |
| 3325 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 3326 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 3327 | if (perm.info.getProtectionFlags() != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 3328 | if ( (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_INSTANT) == 0 |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 3329 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) == 0 |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 3330 | && (perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3331 | PermissionInfo.PROTECTION_SIGNATURE) { |
Joe Maples | 39bb9e8 | 2018-01-11 11:09:46 -0500 | [diff] [blame] | 3332 | outError[0] = "<permission> protectionLevel specifies a non-instant flag but is " |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3333 | + "not based on signature type"; |
| 3334 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3335 | return false; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 3336 | } |
| 3337 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3338 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3339 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3341 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | owner.permissions.add(perm); |
| 3345 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3346 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3349 | private boolean parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3350 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | throws XmlPullParserException, IOException { |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 3352 | Permission perm = new Permission(owner, (String) null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3354 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3355 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 3356 | |
| 3357 | if (!parsePackageItemInfo(owner, perm.info, outError, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3358 | "<permission-tree>", sa, true /*nameRequired*/, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 3360 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3361 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3362 | com.android.internal.R.styleable.AndroidManifestPermissionTree_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3363 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 3364 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | sa.recycle(); |
| 3366 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3367 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | int index = perm.info.name.indexOf('.'); |
| 3373 | if (index > 0) { |
| 3374 | index = perm.info.name.indexOf('.', index+1); |
| 3375 | } |
| 3376 | if (index < 0) { |
| 3377 | outError[0] = "<permission-tree> name has less than three segments: " |
| 3378 | + perm.info.name; |
| 3379 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3380 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | perm.info.descriptionRes = 0; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 3384 | perm.info.requestRes = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 3386 | perm.tree = true; |
| 3387 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3388 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | outError)) { |
| 3390 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3391 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | owner.permissions.add(perm); |
| 3395 | |
Dianne Hackborn | cd154e9 | 2017-02-28 17:37:35 -0800 | [diff] [blame] | 3396 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3400 | XmlResourceParser parser, String[] outError) |
| 3401 | throws XmlPullParserException, IOException { |
| 3402 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 3404 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3405 | if (mParseInstrumentationArgs == null) { |
| 3406 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 3407 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 3408 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3409 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3410 | com.android.internal.R.styleable.AndroidManifestInstrumentation_roundIcon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3411 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 3412 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3413 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 3414 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3415 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3416 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3417 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3418 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 3419 | new InstrumentationInfo()); |
| 3420 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | sa.recycle(); |
| 3422 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3423 | return null; |
| 3424 | } |
| 3425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3427 | // Note: don't allow this value to be a reference to a resource |
| 3428 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | str = sa.getNonResourceString( |
| 3430 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 3431 | a.info.targetPackage = str != null ? str.intern() : null; |
| 3432 | |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3433 | str = sa.getNonResourceString( |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 3434 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetProcesses); |
| 3435 | a.info.targetProcesses = str != null ? str.intern() : null; |
Dianne Hackborn | 3404173 | 2017-01-31 15:27:13 -0800 | [diff] [blame] | 3436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | a.info.handleProfiling = sa.getBoolean( |
| 3438 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 3439 | false); |
| 3440 | |
| 3441 | a.info.functionalTest = sa.getBoolean( |
| 3442 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 3443 | false); |
| 3444 | |
| 3445 | sa.recycle(); |
| 3446 | |
| 3447 | if (a.info.targetPackage == null) { |
| 3448 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 3449 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3450 | return null; |
| 3451 | } |
| 3452 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3453 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | outError)) { |
| 3455 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3456 | return null; |
| 3457 | } |
| 3458 | |
| 3459 | owner.instrumentation.add(a); |
| 3460 | |
| 3461 | return a; |
| 3462 | } |
| 3463 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3464 | /** |
| 3465 | * Parse the {@code application} XML tree at the current parse location in a |
| 3466 | * <em>base APK</em> manifest. |
| 3467 | * <p> |
| 3468 | * When adding new features, carefully consider if they should also be |
| 3469 | * supported by split APKs. |
| 3470 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3471 | @UnsupportedAppUsage |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3472 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3473 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | throws XmlPullParserException, IOException { |
| 3475 | final ApplicationInfo ai = owner.applicationInfo; |
| 3476 | final String pkgName = owner.applicationInfo.packageName; |
| 3477 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3478 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3479 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3480 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 3481 | ai.iconRes = sa.getResourceId( |
| 3482 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
| 3483 | ai.roundIconRes = sa.getResourceId( |
| 3484 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, 0); |
| 3485 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 3486 | if (!parsePackageItemInfo(owner, ai, outError, |
| 3487 | "<application>", sa, false /*nameRequired*/, |
| 3488 | com.android.internal.R.styleable.AndroidManifestApplication_name, |
| 3489 | com.android.internal.R.styleable.AndroidManifestApplication_label, |
| 3490 | com.android.internal.R.styleable.AndroidManifestApplication_icon, |
| 3491 | com.android.internal.R.styleable.AndroidManifestApplication_roundIcon, |
| 3492 | com.android.internal.R.styleable.AndroidManifestApplication_logo, |
| 3493 | com.android.internal.R.styleable.AndroidManifestApplication_banner)) { |
| 3494 | sa.recycle(); |
| 3495 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3496 | return false; |
| 3497 | } |
| 3498 | |
| 3499 | if (ai.name != null) { |
Todd Kennedy | afb5269 | 2016-08-22 15:44:00 -0700 | [diff] [blame] | 3500 | ai.className = ai.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | } |
| 3502 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3503 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3504 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 3505 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | if (manageSpaceActivity != null) { |
| 3507 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 3508 | outError); |
| 3509 | } |
| 3510 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3511 | boolean allowBackup = sa.getBoolean( |
| 3512 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 3513 | if (allowBackup) { |
| 3514 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3515 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3516 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 3517 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 3518 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3519 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3520 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 3521 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3522 | if (backupAgent != null) { |
| 3523 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3524 | if (DEBUG_BACKUP) { |
| 3525 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3526 | + " from " + pkgName + "+" + backupAgent); |
| 3527 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 3528 | |
| 3529 | if (sa.getBoolean( |
| 3530 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 3531 | true)) { |
| 3532 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 3533 | } |
| 3534 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 3535 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 3536 | false)) { |
| 3537 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 3538 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 3539 | if (sa.getBoolean( |
| 3540 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 3541 | false)) { |
| 3542 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 3543 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 3544 | if (sa.getBoolean( |
| 3545 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 3546 | false)) { |
| 3547 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 3548 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3549 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 3550 | |
| 3551 | TypedValue v = sa.peekValue( |
| 3552 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 3553 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 3554 | if (DEBUG_BACKUP) { |
| 3555 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 3556 | (v.data == 0 ? "false" : "true")); |
| 3557 | } |
| 3558 | // "false" => -1, "true" => 0 |
| 3559 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 3560 | } |
| 3561 | if (DEBUG_BACKUP) { |
| 3562 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 3563 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3564 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 3567 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | ai.descriptionRes = sa.getResourceId( |
| 3569 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 3570 | |
Todd Kennedy | 232d29e | 2017-11-06 14:45:53 -0800 | [diff] [blame] | 3571 | if (sa.getBoolean( |
| 3572 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 3573 | false)) { |
| 3574 | // Check if persistence is based on a feature being present |
| 3575 | final String requiredFeature = sa.getNonResourceString(com.android.internal.R.styleable |
| 3576 | .AndroidManifestApplication_persistentWhenFeatureAvailable); |
| 3577 | if (requiredFeature == null || mCallback.hasFeature(requiredFeature)) { |
| 3578 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3579 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | if (sa.getBoolean( |
| 3583 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 3584 | false)) { |
| 3585 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 3589 | .AndroidManifestApplication_restrictedAccountType); |
| 3590 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 3591 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | } |
| 3593 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 3594 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 3595 | .AndroidManifestApplication_requiredAccountType); |
| 3596 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 3597 | owner.mRequiredAccountType = requiredAccountType; |
| 3598 | } |
| 3599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | if (sa.getBoolean( |
| 3601 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 3602 | false)) { |
| 3603 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 3604 | // Debuggable implies profileable |
| 3605 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 3609 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 3610 | false)) { |
| 3611 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 3612 | } |
| 3613 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3614 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3615 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 3616 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 3617 | if (owner.baseHardwareAccelerated) { |
| 3618 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 3619 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3620 | |
| 3621 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 3623 | true)) { |
| 3624 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 3625 | } |
| 3626 | |
| 3627 | if (sa.getBoolean( |
| 3628 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 3629 | false)) { |
| 3630 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3631 | } |
| 3632 | |
| 3633 | if (sa.getBoolean( |
| 3634 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 3635 | true)) { |
| 3636 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 3637 | } |
| 3638 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3639 | // The parent package controls installation, hence specify test only installs. |
| 3640 | if (owner.parentPackage == null) { |
| 3641 | if (sa.getBoolean( |
| 3642 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 3643 | false)) { |
| 3644 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 3645 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3648 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3649 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3650 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 3651 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 3652 | } |
| 3653 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3654 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3655 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
Chad Brubaker | 0d285d5 | 2018-03-14 09:00:04 -0700 | [diff] [blame] | 3656 | owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.P)) { |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 3657 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 3658 | } |
| 3659 | |
| 3660 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 3661 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 3662 | false /* default is no RTL support*/)) { |
| 3663 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 3664 | } |
| 3665 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 3666 | if (sa.getBoolean( |
| 3667 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 3668 | false)) { |
| 3669 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 3670 | } |
| 3671 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3672 | if (sa.getBoolean( |
| 3673 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
Victor Hsieh | 0faa801 | 2019-03-11 10:00:54 -0700 | [diff] [blame] | 3674 | true)) { |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 3675 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 3676 | } |
| 3677 | |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3678 | if (sa.getBoolean( |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 3679 | R.styleable.AndroidManifestApplication_useEmbeddedDex, |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 3680 | false)) { |
Victor Hsieh | fa9df0b | 2019-01-29 12:48:36 -0800 | [diff] [blame] | 3681 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX; |
Victor Hsieh | e7b5a8d | 2018-11-16 10:27:06 -0800 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | if (sa.getBoolean( |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3685 | R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 3686 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3687 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3688 | } |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3689 | if (sa.getBoolean( |
| 3690 | R.styleable.AndroidManifestApplication_directBootAware, |
| 3691 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3692 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 3693 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3694 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3695 | if (sa.hasValueOrEmpty(R.styleable.AndroidManifestApplication_resizeableActivity)) { |
| 3696 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, true)) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3697 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; |
| 3698 | } else { |
| 3699 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 3700 | } |
| 3701 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 3702 | ai.privateFlags |= PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Ruslan Tkhakokhov | 7567485 | 2019-01-22 13:35:00 +0000 | [diff] [blame] | 3705 | if (sa.getBoolean( |
| 3706 | com.android.internal.R.styleable |
| 3707 | .AndroidManifestApplication_allowClearUserDataOnFailedRestore, |
| 3708 | true)) { |
| 3709 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE; |
| 3710 | } |
| 3711 | |
Kevin Rocard | f91d50b | 2019-02-21 14:32:46 -0800 | [diff] [blame] | 3712 | if (sa.getBoolean( |
| 3713 | R.styleable.AndroidManifestApplication_allowAudioPlaybackCapture, |
| 3714 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q)) { |
| 3715 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE; |
| 3716 | } |
| 3717 | |
Jeff Sharkey | bcff13c | 2019-03-28 14:29:35 -0600 | [diff] [blame] | 3718 | if (sa.getBoolean( |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 3719 | R.styleable.AndroidManifestApplication_requestLegacyExternalStorage, |
| 3720 | owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.Q)) { |
| 3721 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE; |
Jeff Sharkey | bcff13c | 2019-03-28 14:29:35 -0600 | [diff] [blame] | 3722 | } |
| 3723 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3724 | ai.maxAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_maxAspectRatio, 0); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 3725 | ai.minAspectRatio = sa.getFloat(R.styleable.AndroidManifestApplication_minAspectRatio, 0); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3726 | |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3727 | ai.networkSecurityConfigRes = sa.getResourceId( |
| 3728 | com.android.internal.R.styleable.AndroidManifestApplication_networkSecurityConfig, |
| 3729 | 0); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3730 | ai.category = sa.getInt( |
| 3731 | com.android.internal.R.styleable.AndroidManifestApplication_appCategory, |
| 3732 | ApplicationInfo.CATEGORY_UNDEFINED); |
Chad Brubaker | c845b2a | 2016-05-13 14:09:27 -0700 | [diff] [blame] | 3733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3735 | str = sa.getNonConfigurationString( |
| 3736 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 3738 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3739 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3740 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3741 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 3742 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3743 | } else { |
| 3744 | // Some older apps have been seen to use a resource reference |
| 3745 | // here that on older builds was ignored (with a warning). We |
| 3746 | // need to continue to do this for them so they don't break. |
| 3747 | str = sa.getNonResourceString( |
| 3748 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 3749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 3751 | str, outError); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3752 | String factory = sa.getNonResourceString( |
| 3753 | com.android.internal.R.styleable.AndroidManifestApplication_appComponentFactory); |
| 3754 | if (factory != null) { |
| 3755 | ai.appComponentFactory = buildClassName(ai.packageName, factory, outError); |
| 3756 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | |
David Brazdil | a5b4df2 | 2018-09-06 09:49:14 +0100 | [diff] [blame] | 3758 | if (sa.getBoolean( |
| 3759 | com.android.internal.R.styleable.AndroidManifestApplication_usesNonSdkApi, false)) { |
| 3760 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API; |
| 3761 | } |
David Brazdil | 787b6f22a | 2018-08-28 12:55:56 +0100 | [diff] [blame] | 3762 | |
Philip P. Moltmann | ae4a4b9 | 2018-12-12 11:28:57 -0800 | [diff] [blame] | 3763 | if (sa.getBoolean( |
| 3764 | com.android.internal.R.styleable.AndroidManifestApplication_hasFragileUserData, |
| 3765 | false)) { |
| 3766 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA; |
| 3767 | } |
| 3768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3770 | CharSequence pname; |
| 3771 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3772 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3773 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 3774 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3775 | } else { |
| 3776 | // Some older apps have been seen to use a resource reference |
| 3777 | // here that on older builds was ignored (with a warning). We |
| 3778 | // need to continue to do this for them so they don't break. |
| 3779 | pname = sa.getNonResourceString( |
| 3780 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 3781 | } |
| 3782 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3784 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3785 | ai.enabled = sa.getBoolean( |
| 3786 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3787 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 3788 | if (sa.getBoolean( |
| 3789 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 3790 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 3791 | } |
| 3792 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3793 | if (sa.getBoolean( |
| 3794 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 3795 | false)) { |
| 3796 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 3797 | |
Dianne Hackborn | 70c95c5 | 2017-10-06 16:30:59 -0700 | [diff] [blame] | 3798 | // A heavy-weight application can not be in a custom process. |
| 3799 | // We can do direct compare because we intern all strings. |
| 3800 | if (ai.processName != null && !ai.processName.equals(ai.packageName)) { |
| 3801 | outError[0] = "cantSaveState applications can not use custom processes"; |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3802 | } |
| 3803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | } |
| 3805 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3806 | ai.uiOptions = sa.getInt( |
| 3807 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 3808 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 3809 | ai.classLoaderName = sa.getString( |
| 3810 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 3811 | if (ai.classLoaderName != null |
| 3812 | && !ClassLoaderFactory.isValidClassLoaderName(ai.classLoaderName)) { |
| 3813 | outError[0] = "Invalid class loader name: " + ai.classLoaderName; |
| 3814 | } |
| 3815 | |
Martijn Coenen | fb7caa9 | 2019-01-29 11:45:56 +0100 | [diff] [blame] | 3816 | ai.zygotePreloadName = sa.getString( |
| 3817 | com.android.internal.R.styleable.AndroidManifestApplication_zygotePreloadName); |
| 3818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | sa.recycle(); |
| 3820 | |
| 3821 | if (outError[0] != null) { |
| 3822 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3823 | return false; |
| 3824 | } |
| 3825 | |
| 3826 | final int innerDepth = parser.getDepth(); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3827 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 3828 | // getting added to the wrong package. |
| 3829 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | int type; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3831 | boolean hasActivityOrder = false; |
| 3832 | boolean hasReceiverOrder = false; |
| 3833 | boolean hasServiceOrder = false; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3834 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3835 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3836 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | continue; |
| 3838 | } |
| 3839 | |
| 3840 | String tagName = parser.getName(); |
| 3841 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3842 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3843 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | if (a == null) { |
| 3845 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3846 | return false; |
| 3847 | } |
| 3848 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3849 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | owner.activities.add(a); |
| 3851 | |
| 3852 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3853 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 3854 | true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | if (a == null) { |
| 3856 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3857 | return false; |
| 3858 | } |
| 3859 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3860 | hasReceiverOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | owner.receivers.add(a); |
| 3862 | |
| 3863 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3864 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | if (s == null) { |
| 3866 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3867 | return false; |
| 3868 | } |
| 3869 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3870 | hasServiceOrder |= (s.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | owner.services.add(s); |
| 3872 | |
| 3873 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3874 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | if (p == null) { |
| 3876 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3877 | return false; |
| 3878 | } |
| 3879 | |
| 3880 | owner.providers.add(p); |
| 3881 | |
| 3882 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 3883 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | if (a == null) { |
| 3885 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3886 | return false; |
| 3887 | } |
| 3888 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 3889 | hasActivityOrder |= (a.order != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | owner.activities.add(a); |
| 3891 | |
| 3892 | } else if (parser.getName().equals("meta-data")) { |
| 3893 | // note: application meta-data is stored off to the side, so it can |
| 3894 | // remain null in the primary copy (we like to avoid extra copies because |
| 3895 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3896 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | outError)) == null) { |
| 3898 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3899 | return false; |
| 3900 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3901 | } else if (tagName.equals("static-library")) { |
| 3902 | sa = res.obtainAttributes(parser, |
| 3903 | com.android.internal.R.styleable.AndroidManifestStaticLibrary); |
| 3904 | |
| 3905 | // Note: don't allow this value to be a reference to a resource |
| 3906 | // that may change. |
| 3907 | final String lname = sa.getNonResourceString( |
| 3908 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_name); |
| 3909 | final int version = sa.getInt( |
| 3910 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_version, -1); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3911 | final int versionMajor = sa.getInt( |
| 3912 | com.android.internal.R.styleable.AndroidManifestStaticLibrary_versionMajor, |
| 3913 | 0); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3914 | |
| 3915 | sa.recycle(); |
| 3916 | |
| 3917 | // Since the app canot run without a static lib - fail if malformed |
| 3918 | if (lname == null || version < 0) { |
| 3919 | outError[0] = "Bad static-library declaration name: " + lname |
| 3920 | + " version: " + version; |
| 3921 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3922 | XmlUtils.skipCurrentTag(parser); |
| 3923 | return false; |
| 3924 | } |
| 3925 | |
| 3926 | if (owner.mSharedUserId != null) { |
| 3927 | outError[0] = "sharedUserId not allowed in static shared library"; |
| 3928 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 3929 | XmlUtils.skipCurrentTag(parser); |
| 3930 | return false; |
| 3931 | } |
| 3932 | |
| 3933 | if (owner.staticSharedLibName != null) { |
| 3934 | outError[0] = "Multiple static-shared libs for package " + pkgName; |
| 3935 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3936 | XmlUtils.skipCurrentTag(parser); |
| 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | owner.staticSharedLibName = lname.intern(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3941 | if (version >= 0) { |
| 3942 | owner.staticSharedLibVersion = |
| 3943 | PackageInfo.composeLongVersionCode(versionMajor, version); |
| 3944 | } else { |
| 3945 | owner.staticSharedLibVersion = version; |
| 3946 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3947 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY; |
| 3948 | |
| 3949 | XmlUtils.skipCurrentTag(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3951 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3952 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3953 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3954 | |
| 3955 | // Note: don't allow this value to be a reference to a resource |
| 3956 | // that may change. |
| 3957 | String lname = sa.getNonResourceString( |
| 3958 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3959 | |
| 3960 | sa.recycle(); |
| 3961 | |
| 3962 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3963 | lname = lname.intern(); |
| 3964 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3965 | owner.libraryNames = ArrayUtils.add( |
| 3966 | owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | XmlUtils.skipCurrentTag(parser); |
| 3971 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3972 | } else if (tagName.equals("uses-static-library")) { |
| 3973 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 3974 | return false; |
| 3975 | } |
| 3976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3978 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3980 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3981 | // Note: don't allow this value to be a reference to a resource |
| 3982 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | String lname = sa.getNonResourceString( |
| 3984 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3985 | boolean req = sa.getBoolean( |
| 3986 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3987 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | |
| 3989 | sa.recycle(); |
| 3990 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3991 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3992 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3993 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3994 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3995 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3996 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3997 | owner.usesOptionalLibraries, lname); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | XmlUtils.skipCurrentTag(parser); |
| 4002 | |
| 4003 | } else if (tagName.equals("uses-package")) { |
| 4004 | // Dependencies for app installers; we don't currently try to |
| 4005 | // enforce this. |
| 4006 | XmlUtils.skipCurrentTag(parser); |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 4007 | } else if (tagName.equals("profileable")) { |
| 4008 | sa = res.obtainAttributes(parser, |
| 4009 | com.android.internal.R.styleable.AndroidManifestProfileable); |
| 4010 | if (sa.getBoolean( |
| 4011 | com.android.internal.R.styleable.AndroidManifestProfileable_shell, false)) { |
| 4012 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL; |
| 4013 | } |
| 4014 | XmlUtils.skipCurrentTag(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4015 | |
| 4016 | } else { |
| 4017 | if (!RIGID_PARSER) { |
| 4018 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 4019 | + " at " + mArchiveSourcePath + " " |
| 4020 | + parser.getPositionDescription()); |
| 4021 | XmlUtils.skipCurrentTag(parser); |
| 4022 | continue; |
| 4023 | } else { |
| 4024 | outError[0] = "Bad element under <application>: " + tagName; |
| 4025 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4026 | return false; |
| 4027 | } |
| 4028 | } |
| 4029 | } |
| 4030 | |
Patrick Baumann | 1f9b885 | 2018-10-30 12:34:46 -0700 | [diff] [blame] | 4031 | if (TextUtils.isEmpty(owner.staticSharedLibName)) { |
| 4032 | // Add a hidden app detail activity to normal apps which forwards user to App Details |
| 4033 | // page. |
| 4034 | Activity a = generateAppDetailsHiddenActivity(owner, flags, outError, |
| 4035 | owner.baseHardwareAccelerated); |
| 4036 | owner.activities.add(a); |
| 4037 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4038 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4039 | if (hasActivityOrder) { |
| 4040 | Collections.sort(owner.activities, (a1, a2) -> Integer.compare(a2.order, a1.order)); |
| 4041 | } |
| 4042 | if (hasReceiverOrder) { |
| 4043 | Collections.sort(owner.receivers, (r1, r2) -> Integer.compare(r2.order, r1.order)); |
| 4044 | } |
| 4045 | if (hasServiceOrder) { |
| 4046 | Collections.sort(owner.services, (s1, s2) -> Integer.compare(s2.order, s1.order)); |
| 4047 | } |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4048 | // Must be ran after the entire {@link ApplicationInfo} has been fully processed and after |
| 4049 | // every activity info has had a chance to set it from its attributes. |
| 4050 | setMaxAspectRatio(owner); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4051 | setMinAspectRatio(owner); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4052 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 4053 | if (hasDomainURLs(owner)) { |
| 4054 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 4055 | } else { |
| 4056 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 4057 | } |
| 4058 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4059 | return true; |
| 4060 | } |
| 4061 | |
| 4062 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 4063 | * 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] | 4064 | */ |
| 4065 | private static boolean hasDomainURLs(Package pkg) { |
| 4066 | if (pkg == null || pkg.activities == null) return false; |
| 4067 | final ArrayList<Activity> activities = pkg.activities; |
| 4068 | final int countActivities = activities.size(); |
| 4069 | for (int n=0; n<countActivities; n++) { |
| 4070 | Activity activity = activities.get(n); |
| 4071 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 4072 | if (filters == null) continue; |
| 4073 | final int countFilters = filters.size(); |
| 4074 | for (int m=0; m<countFilters; m++) { |
| 4075 | ActivityIntentInfo aii = filters.get(m); |
| 4076 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 4077 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 4078 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 4079 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 4080 | return true; |
| 4081 | } |
| 4082 | } |
| 4083 | } |
| 4084 | return false; |
| 4085 | } |
| 4086 | |
| 4087 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4088 | * Parse the {@code application} XML tree at the current parse location in a |
| 4089 | * <em>split APK</em> manifest. |
| 4090 | * <p> |
| 4091 | * Note that split APKs have many more restrictions on what they're capable |
| 4092 | * of doing, so many valid features of a base APK have been carefully |
| 4093 | * omitted here. |
| 4094 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4095 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 4096 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4097 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4098 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4099 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 4100 | |
| 4101 | if (sa.getBoolean( |
| 4102 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 4103 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 4104 | } |
| 4105 | |
Narayan Kamath | 96c11c5 | 2017-08-09 13:07:21 +0100 | [diff] [blame] | 4106 | final String classLoaderName = sa.getString( |
| 4107 | com.android.internal.R.styleable.AndroidManifestApplication_classLoader); |
| 4108 | if (classLoaderName == null || ClassLoaderFactory.isValidClassLoaderName(classLoaderName)) { |
| 4109 | owner.applicationInfo.splitClassLoaderNames[splitIndex] = classLoaderName; |
| 4110 | } else { |
| 4111 | outError[0] = "Invalid class loader name: " + classLoaderName; |
| 4112 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4113 | return false; |
| 4114 | } |
| 4115 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4116 | final int innerDepth = parser.getDepth(); |
| 4117 | int type; |
| 4118 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4119 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 4120 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4121 | continue; |
| 4122 | } |
| 4123 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4124 | ComponentInfo parsedComponent = null; |
| 4125 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4126 | // IMPORTANT: These must only be cached for a single <application> to avoid components |
| 4127 | // getting added to the wrong package. |
| 4128 | final CachedComponentArgs cachedArgs = new CachedComponentArgs(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4129 | String tagName = parser.getName(); |
| 4130 | if (tagName.equals("activity")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4131 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4132 | owner.baseHardwareAccelerated); |
| 4133 | if (a == null) { |
| 4134 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4135 | return false; |
| 4136 | } |
| 4137 | |
| 4138 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4139 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4140 | |
| 4141 | } else if (tagName.equals("receiver")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4142 | Activity a = parseActivity(owner, res, parser, flags, outError, cachedArgs, |
| 4143 | true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4144 | if (a == null) { |
| 4145 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4146 | return false; |
| 4147 | } |
| 4148 | |
| 4149 | owner.receivers.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4150 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4151 | |
| 4152 | } else if (tagName.equals("service")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4153 | Service s = parseService(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4154 | if (s == null) { |
| 4155 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4156 | return false; |
| 4157 | } |
| 4158 | |
| 4159 | owner.services.add(s); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4160 | parsedComponent = s.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4161 | |
| 4162 | } else if (tagName.equals("provider")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4163 | Provider p = parseProvider(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4164 | if (p == null) { |
| 4165 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4166 | return false; |
| 4167 | } |
| 4168 | |
| 4169 | owner.providers.add(p); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4170 | parsedComponent = p.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4171 | |
| 4172 | } else if (tagName.equals("activity-alias")) { |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4173 | Activity a = parseActivityAlias(owner, res, parser, flags, outError, cachedArgs); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4174 | if (a == null) { |
| 4175 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4176 | return false; |
| 4177 | } |
| 4178 | |
| 4179 | owner.activities.add(a); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4180 | parsedComponent = a.info; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4181 | |
| 4182 | } else if (parser.getName().equals("meta-data")) { |
| 4183 | // note: application meta-data is stored off to the side, so it can |
| 4184 | // remain null in the primary copy (we like to avoid extra copies because |
| 4185 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4186 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4187 | outError)) == null) { |
| 4188 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4189 | return false; |
| 4190 | } |
| 4191 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4192 | } else if (tagName.equals("uses-static-library")) { |
| 4193 | if (!parseUsesStaticLibrary(owner, res, parser, outError)) { |
| 4194 | return false; |
| 4195 | } |
| 4196 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4197 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4198 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4199 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 4200 | |
| 4201 | // Note: don't allow this value to be a reference to a resource |
| 4202 | // that may change. |
| 4203 | String lname = sa.getNonResourceString( |
| 4204 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 4205 | boolean req = sa.getBoolean( |
| 4206 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 4207 | true); |
| 4208 | |
| 4209 | sa.recycle(); |
| 4210 | |
| 4211 | if (lname != null) { |
| 4212 | lname = lname.intern(); |
| 4213 | if (req) { |
| 4214 | // Upgrade to treat as stronger constraint |
| 4215 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 4216 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 4217 | owner.usesOptionalLibraries, lname); |
| 4218 | } else { |
| 4219 | // Ignore if someone already defined as required |
| 4220 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 4221 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 4222 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4223 | } |
| 4224 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | XmlUtils.skipCurrentTag(parser); |
| 4228 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 4229 | } else if (tagName.equals("uses-package")) { |
| 4230 | // Dependencies for app installers; we don't currently try to |
| 4231 | // enforce this. |
| 4232 | XmlUtils.skipCurrentTag(parser); |
| 4233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | } else { |
| 4235 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4236 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4237 | + " at " + mArchiveSourcePath + " " |
| 4238 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | XmlUtils.skipCurrentTag(parser); |
| 4240 | continue; |
| 4241 | } else { |
| 4242 | outError[0] = "Bad element under <application>: " + tagName; |
| 4243 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 4244 | return false; |
| 4245 | } |
| 4246 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 4247 | |
| 4248 | if (parsedComponent != null && parsedComponent.splitName == null) { |
| 4249 | // If the loaded component did not specify a split, inherit the split name |
| 4250 | // based on the split it is defined in. |
| 4251 | // This is used to later load the correct split when starting this |
| 4252 | // component. |
| 4253 | parsedComponent.splitName = owner.splitNames[splitIndex]; |
| 4254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | return true; |
| 4258 | } |
| 4259 | |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4260 | private static boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 4261 | String[] outError, String tag, TypedArray sa, boolean nameRequired, |
| 4262 | int nameRes, int labelRes, int iconRes, int roundIconRes, int logoRes, int bannerRes) { |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 4263 | // This case can only happen in unit tests where we sometimes need to create fakes |
| 4264 | // of various package parser data structures. |
| 4265 | if (sa == null) { |
| 4266 | outError[0] = tag + " does not contain any attributes"; |
| 4267 | return false; |
| 4268 | } |
| 4269 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4270 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | if (name == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4272 | if (nameRequired) { |
| 4273 | outError[0] = tag + " does not specify android:name"; |
| 4274 | return false; |
| 4275 | } |
| 4276 | } else { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4277 | String outInfoName |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4278 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4279 | if (PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(outInfoName)) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4280 | outError[0] = tag + " invalid android:name"; |
| 4281 | return false; |
| 4282 | } |
| 4283 | outInfo.name = outInfoName; |
| 4284 | if (outInfoName == null) { |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4285 | return false; |
| 4286 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | } |
| 4288 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 4289 | int roundIconVal = sUseRoundIcon ? sa.getResourceId(roundIconRes, 0) : 0; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4290 | if (roundIconVal != 0) { |
| 4291 | outInfo.icon = roundIconVal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | outInfo.nonLocalizedLabel = null; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4293 | } else { |
| 4294 | int iconVal = sa.getResourceId(iconRes, 0); |
| 4295 | if (iconVal != 0) { |
| 4296 | outInfo.icon = iconVal; |
| 4297 | outInfo.nonLocalizedLabel = null; |
| 4298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4300 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4301 | int logoVal = sa.getResourceId(logoRes, 0); |
| 4302 | if (logoVal != 0) { |
| 4303 | outInfo.logo = logoVal; |
| 4304 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4306 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 4307 | if (bannerVal != 0) { |
| 4308 | outInfo.banner = bannerVal; |
| 4309 | } |
| 4310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | TypedValue v = sa.peekValue(labelRes); |
| 4312 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4313 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4314 | } |
| 4315 | |
| 4316 | outInfo.packageName = owner.packageName; |
| 4317 | |
| 4318 | return true; |
| 4319 | } |
| 4320 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4321 | /** |
| 4322 | * Generate activity object that forwards user to App Details page automatically. |
| 4323 | * This activity should be invisible to user and user should not know or see it. |
| 4324 | */ |
| 4325 | private @NonNull PackageParser.Activity generateAppDetailsHiddenActivity( |
| 4326 | PackageParser.Package owner, int flags, String[] outError, |
| 4327 | boolean hardwareAccelerated) { |
| 4328 | |
| 4329 | // Build custom App Details activity info instead of parsing it from xml |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4330 | Activity a = new Activity(owner, PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME, |
| 4331 | new ActivityInfo()); |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4332 | a.owner = owner; |
| 4333 | a.setPackageName(owner.packageName); |
| 4334 | |
Ricky Wai | 62292507 | 2019-01-29 16:40:59 +0000 | [diff] [blame] | 4335 | a.info.theme = android.R.style.Theme_NoDisplay; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4336 | a.info.exported = true; |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 4337 | a.info.name = PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 4338 | a.info.processName = owner.applicationInfo.processName; |
| 4339 | a.info.uiOptions = a.info.applicationInfo.uiOptions; |
| 4340 | a.info.taskAffinity = buildTaskAffinityName(owner.packageName, owner.packageName, |
| 4341 | ":app_details", outError); |
| 4342 | a.info.enabled = true; |
| 4343 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4344 | a.info.documentLaunchMode = ActivityInfo.DOCUMENT_LAUNCH_NONE; |
| 4345 | a.info.maxRecents = ActivityTaskManager.getDefaultAppRecentsLimitStatic(); |
| 4346 | a.info.configChanges = getActivityConfigChanges(0, 0); |
| 4347 | a.info.softInputMode = 0; |
| 4348 | a.info.persistableMode = ActivityInfo.PERSIST_NEVER; |
| 4349 | a.info.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 4350 | a.info.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4351 | a.info.lockTaskLaunchMode = 0; |
| 4352 | a.info.encryptionAware = a.info.directBootAware = false; |
| 4353 | a.info.rotationAnimation = ROTATION_ANIMATION_UNSPECIFIED; |
| 4354 | a.info.colorMode = ActivityInfo.COLOR_MODE_DEFAULT; |
| 4355 | if (hardwareAccelerated) { |
| 4356 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4357 | } |
| 4358 | return a; |
| 4359 | } |
| 4360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | private Activity parseActivity(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4362 | XmlResourceParser parser, int flags, String[] outError, CachedComponentArgs cachedArgs, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4363 | boolean receiver, boolean hardwareAccelerated) |
| 4364 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4365 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4367 | if (cachedArgs.mActivityArgs == null) { |
| 4368 | cachedArgs.mActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4369 | R.styleable.AndroidManifestActivity_name, |
| 4370 | R.styleable.AndroidManifestActivity_label, |
| 4371 | R.styleable.AndroidManifestActivity_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4372 | R.styleable.AndroidManifestActivity_roundIcon, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4373 | R.styleable.AndroidManifestActivity_logo, |
| 4374 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4375 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4376 | R.styleable.AndroidManifestActivity_process, |
| 4377 | R.styleable.AndroidManifestActivity_description, |
| 4378 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4379 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4380 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4381 | cachedArgs.mActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 4382 | cachedArgs.mActivityArgs.sa = sa; |
| 4383 | cachedArgs.mActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4384 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4385 | Activity a = new Activity(cachedArgs.mActivityArgs, new ActivityInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4386 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | sa.recycle(); |
| 4388 | return null; |
| 4389 | } |
| 4390 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4391 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4393 | 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] | 4394 | } |
| 4395 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4396 | 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] | 4397 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4398 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4399 | a.info.applicationInfo.uiOptions); |
| 4400 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4401 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4402 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4403 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4404 | if (parentName != null) { |
| 4405 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 4406 | if (outError[0] == null) { |
| 4407 | a.info.parentActivityName = parentClassName; |
| 4408 | } else { |
| 4409 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 4410 | parentName); |
| 4411 | outError[0] = null; |
| 4412 | } |
| 4413 | } |
| 4414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4416 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | if (str == null) { |
| 4418 | a.info.permission = owner.applicationInfo.permission; |
| 4419 | } else { |
| 4420 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4421 | } |
| 4422 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4423 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4424 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4425 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4426 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 4427 | owner.applicationInfo.taskAffinity, str, outError); |
| 4428 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 4429 | a.info.splitName = |
| 4430 | sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_splitName, 0); |
| 4431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | a.info.flags = 0; |
| 4433 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4434 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 4436 | } |
| 4437 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4438 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 4440 | } |
| 4441 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4442 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 4444 | } |
| 4445 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4446 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 4448 | } |
| 4449 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4450 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 4452 | } |
| 4453 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4454 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 4456 | } |
| 4457 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4458 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 4460 | } |
| 4461 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4462 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 4464 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 4465 | } |
| 4466 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4467 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4468 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 4469 | } |
| 4470 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 4471 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 4472 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 4473 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4476 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 4477 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 4478 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 4479 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 4480 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 4481 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 4482 | } |
| 4483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4485 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 4486 | hardwareAccelerated)) { |
| 4487 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 4488 | } |
| 4489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4491 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4492 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4493 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4494 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 4495 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4496 | R.styleable.AndroidManifestActivity_maxRecents, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 4497 | ActivityTaskManager.getDefaultAppRecentsLimitStatic()); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4498 | a.info.configChanges = getActivityConfigChanges( |
| 4499 | sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0), |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4500 | sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4502 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4503 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4504 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4505 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 4506 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4507 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4508 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4509 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 4510 | } |
| 4511 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4512 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 4513 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 4514 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4515 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4516 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 4517 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 4518 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4519 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4520 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4521 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 4522 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4523 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4524 | a.info.screenOrientation = sa.getInt( |
| 4525 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 4526 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 4527 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4528 | setActivityResizeMode(a.info, sa, owner); |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4529 | |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4530 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 4531 | false)) { |
| 4532 | a.info.flags |= FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 4533 | } |
| 4534 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4535 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4536 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 4537 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 4538 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4539 | if (sa.hasValue(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4540 | && sa.getType(R.styleable.AndroidManifestActivity_maxAspectRatio) |
| 4541 | == TypedValue.TYPE_FLOAT) { |
| 4542 | a.setMaxAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_maxAspectRatio, |
| 4543 | 0 /*default*/)); |
| 4544 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4545 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4546 | if (sa.hasValue(R.styleable.AndroidManifestActivity_minAspectRatio) |
| 4547 | && sa.getType(R.styleable.AndroidManifestActivity_minAspectRatio) |
| 4548 | == TypedValue.TYPE_FLOAT) { |
| 4549 | a.setMinAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_minAspectRatio, |
| 4550 | 0 /*default*/)); |
| 4551 | } |
| 4552 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4553 | a.info.lockTaskLaunchMode = |
| 4554 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4555 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4556 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4557 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4558 | false); |
Ruben Brunk | f56c9f4 | 2016-04-22 18:20:55 -0700 | [diff] [blame] | 4559 | |
| 4560 | a.info.requestedVrComponent = |
| 4561 | sa.getString(R.styleable.AndroidManifestActivity_enableVrMode); |
Robert Carr | 0f5d753 | 2016-10-17 16:39:17 -0700 | [diff] [blame] | 4562 | |
| 4563 | a.info.rotationAnimation = |
Robert Carr | 427ba4f | 2017-07-17 18:37:06 -0700 | [diff] [blame] | 4564 | sa.getInt(R.styleable.AndroidManifestActivity_rotationAnimation, ROTATION_ANIMATION_UNSPECIFIED); |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 4565 | |
| 4566 | a.info.colorMode = sa.getInt(R.styleable.AndroidManifestActivity_colorMode, |
| 4567 | ActivityInfo.COLOR_MODE_DEFAULT); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4568 | |
| 4569 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showWhenLocked, false)) { |
| 4570 | a.info.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED; |
| 4571 | } |
| 4572 | |
| 4573 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_turnScreenOn, false)) { |
| 4574 | a.info.flags |= ActivityInfo.FLAG_TURN_SCREEN_ON; |
| 4575 | } |
| 4576 | |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4577 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_inheritShowWhenLocked, false)) { |
| 4578 | a.info.privateFlags |= ActivityInfo.FLAG_INHERIT_SHOW_WHEN_LOCKED; |
| 4579 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | } else { |
| 4581 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 4582 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4583 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4584 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 4585 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4586 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4587 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4588 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 4589 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4590 | false); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4593 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4594 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4595 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4596 | } |
| 4597 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 4598 | // can't make this final; we may set it later via meta-data |
| 4599 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4600 | sa.getBoolean(R.styleable.AndroidManifestActivity_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4601 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4602 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 4603 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4604 | } |
| 4605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4606 | sa.recycle(); |
| 4607 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4608 | if (receiver && (owner.applicationInfo.privateFlags |
| 4609 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4610 | // A heavy-weight application can not have receives in its main process |
| 4611 | // We can do direct compare because we intern all strings. |
| 4612 | if (a.info.processName == owner.packageName) { |
| 4613 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 4614 | } |
| 4615 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | if (outError[0] != null) { |
| 4618 | return null; |
| 4619 | } |
| 4620 | |
| 4621 | int outerDepth = parser.getDepth(); |
| 4622 | int type; |
| 4623 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4624 | && (type != XmlPullParser.END_TAG |
| 4625 | || parser.getDepth() > outerDepth)) { |
| 4626 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4627 | continue; |
| 4628 | } |
| 4629 | |
| 4630 | if (parser.getName().equals("intent-filter")) { |
| 4631 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4632 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 4633 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | return null; |
| 4635 | } |
| 4636 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4637 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 4638 | + mArchiveSourcePath + " " |
| 4639 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 4641 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | a.intents.add(intent); |
| 4643 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4644 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4645 | final int visibility = visibleToEphemeral |
| 4646 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4647 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4648 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4649 | : IntentFilter.VISIBILITY_NONE; |
| 4650 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4651 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4652 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4653 | } |
| 4654 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4655 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4656 | } |
Jeff Sharkey | 32ee8ee | 2017-03-08 20:17:51 -0700 | [diff] [blame] | 4657 | if (LOG_UNSAFE_BROADCASTS && receiver |
| 4658 | && (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O)) { |
| 4659 | for (int i = 0; i < intent.countActions(); i++) { |
| 4660 | final String action = intent.getAction(i); |
| 4661 | if (action == null || !action.startsWith("android.")) continue; |
| 4662 | if (!SAFE_BROADCASTS.contains(action)) { |
| 4663 | Slog.w(TAG, "Broadcast " + action + " may never be delivered to " |
| 4664 | + owner.packageName + " as requested at: " |
| 4665 | + parser.getPositionDescription()); |
| 4666 | } |
| 4667 | } |
| 4668 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4669 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 4670 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 4671 | if (!parseIntent(res, parser, false /*allowGlobs*/, false /*allowAutoVerify*/, |
| 4672 | intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4673 | return null; |
| 4674 | } |
| 4675 | if (intent.countActions() == 0) { |
| 4676 | Slog.w(TAG, "No actions in preferred at " |
| 4677 | + mArchiveSourcePath + " " |
| 4678 | + parser.getPositionDescription()); |
| 4679 | } else { |
| 4680 | if (owner.preferredActivityFilters == null) { |
| 4681 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 4682 | } |
| 4683 | owner.preferredActivityFilters.add(intent); |
| 4684 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4685 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4686 | final int visibility = visibleToEphemeral |
| 4687 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 4688 | : !receiver && isImplicitlyExposedIntent(intent) |
| 4689 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 4690 | : IntentFilter.VISIBILITY_NONE; |
| 4691 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4692 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 4693 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 4694 | } |
| 4695 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 4696 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 4697 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4698 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4699 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | outError)) == null) { |
| 4701 | return null; |
| 4702 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4703 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4704 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | } else { |
| 4706 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4707 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4708 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4709 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4710 | + " at " + mArchiveSourcePath + " " |
| 4711 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4712 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4713 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4714 | + " at " + mArchiveSourcePath + " " |
| 4715 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4716 | } |
| 4717 | XmlUtils.skipCurrentTag(parser); |
| 4718 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4719 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4720 | if (receiver) { |
| 4721 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 4722 | } else { |
| 4723 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 4724 | } |
| 4725 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4726 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | if (!setExported) { |
| 4731 | a.info.exported = a.intents.size() > 0; |
| 4732 | } |
| 4733 | |
| 4734 | return a; |
| 4735 | } |
| 4736 | |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4737 | private void setActivityResizeMode(ActivityInfo aInfo, TypedArray sa, Package owner) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4738 | final boolean appExplicitDefault = (owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4739 | & (PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE |
| 4740 | | PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE)) != 0; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4741 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4742 | if (sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity) |
| 4743 | || appExplicitDefault) { |
| 4744 | // Activity or app explicitly set if it is resizeable or not; |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4745 | final boolean appResizeable = (owner.applicationInfo.privateFlags |
| 4746 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE) != 0; |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4747 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity, |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4748 | appResizeable)) { |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4749 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4750 | } else { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4751 | aInfo.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4752 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4753 | return; |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4754 | } |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4755 | |
| 4756 | if ((owner.applicationInfo.privateFlags |
Wale Ogunwale | e633eb0 | 2017-03-30 12:57:29 -0700 | [diff] [blame] | 4757 | & PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) != 0) { |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4758 | // The activity or app didn't explicitly set the resizing option, however we want to |
| 4759 | // make it resize due to the sdk version it is targeting. |
| 4760 | aInfo.resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; |
| 4761 | return; |
| 4762 | } |
| 4763 | |
| 4764 | // resize preference isn't set and target sdk version doesn't support resizing apps by |
| 4765 | // 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] | 4766 | if (aInfo.isFixedOrientationPortrait()) { |
| 4767 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY; |
| 4768 | } else if (aInfo.isFixedOrientationLandscape()) { |
| 4769 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY; |
| 4770 | } else if (aInfo.isFixedOrientation()) { |
| 4771 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION; |
| 4772 | } else { |
| 4773 | aInfo.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
| 4774 | } |
Wale Ogunwale | 3eadad7 | 2016-10-13 09:16:59 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4777 | /** |
| 4778 | * Sets every the max aspect ratio of every child activity that doesn't already have an aspect |
| 4779 | * ratio set. |
| 4780 | */ |
| 4781 | private void setMaxAspectRatio(Package owner) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4782 | // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater. |
| 4783 | // 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] | 4784 | float maxAspectRatio = owner.applicationInfo.targetSdkVersion < O |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4785 | ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4786 | |
| 4787 | if (owner.applicationInfo.maxAspectRatio != 0) { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4788 | // Use the application max aspect ration as default if set. |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4789 | maxAspectRatio = owner.applicationInfo.maxAspectRatio; |
| 4790 | } else if (owner.mAppMetaData != null |
| 4791 | && owner.mAppMetaData.containsKey(METADATA_MAX_ASPECT_RATIO)) { |
| 4792 | maxAspectRatio = owner.mAppMetaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4793 | } |
| 4794 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4795 | for (Activity activity : owner.activities) { |
| 4796 | // If the max aspect ratio for the activity has already been set, skip. |
| 4797 | if (activity.hasMaxAspectRatio()) { |
| 4798 | continue; |
| 4799 | } |
| 4800 | |
| 4801 | // By default we prefer to use a values defined on the activity directly than values |
| 4802 | // defined on the application. We do not check the styled attributes on the activity |
| 4803 | // as it would have already been set when we processed the activity. We wait to process |
| 4804 | // the meta data here since this method is called at the end of processing the |
| 4805 | // application and all meta data is guaranteed. |
| 4806 | final float activityAspectRatio = activity.metaData != null |
| 4807 | ? activity.metaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio) |
| 4808 | : maxAspectRatio; |
| 4809 | |
| 4810 | activity.setMaxAspectRatio(activityAspectRatio); |
Wale Ogunwale | 0cb70ac | 2017-03-27 09:16:38 -0700 | [diff] [blame] | 4811 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4814 | /** |
Tiger Huang | 3d2b898 | 2019-01-29 22:56:48 +0800 | [diff] [blame] | 4815 | * 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] | 4816 | * ratio set. |
| 4817 | */ |
| 4818 | private void setMinAspectRatio(Package owner) { |
| 4819 | final float minAspectRatio; |
| 4820 | if (owner.applicationInfo.minAspectRatio != 0) { |
| 4821 | // Use the application max aspect ration as default if set. |
| 4822 | minAspectRatio = owner.applicationInfo.minAspectRatio; |
| 4823 | } else { |
| 4824 | // Default to (1.33) 4:3 aspect ratio for pre-Q apps and unset for Q and greater. |
| 4825 | // NOTE: 4:3 was the min aspect ratio Android devices can support pre-Q per the CDD, |
| 4826 | // except for watches which always supported 1:1. |
| 4827 | minAspectRatio = owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q |
| 4828 | ? 0 |
Mohammad Samiul Islam | 7aa7d2e | 2019-03-27 12:23:47 +0000 | [diff] [blame] | 4829 | : (mCallback != null && mCallback.hasFeature(FEATURE_WATCH)) |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4830 | ? DEFAULT_PRE_Q_MIN_ASPECT_RATIO_WATCH |
| 4831 | : DEFAULT_PRE_Q_MIN_ASPECT_RATIO; |
| 4832 | } |
| 4833 | |
| 4834 | for (Activity activity : owner.activities) { |
| 4835 | if (activity.hasMinAspectRatio()) { |
| 4836 | continue; |
| 4837 | } |
| 4838 | activity.setMinAspectRatio(minAspectRatio); |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | /** |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4843 | * @param configChanges The bit mask of configChanges fetched from AndroidManifest.xml. |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4844 | * @param recreateOnConfigChanges The bit mask recreateOnConfigChanges fetched from |
| 4845 | * AndroidManifest.xml. |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4846 | * @hide Exposed for unit testing only. |
| 4847 | */ |
| 4848 | @TestApi |
Holly Jiuyu Sun | c93c3b9 | 2017-04-28 15:34:44 -0700 | [diff] [blame] | 4849 | public static int getActivityConfigChanges(int configChanges, int recreateOnConfigChanges) { |
| 4850 | return configChanges | ((~recreateOnConfigChanges) & RECREATE_ON_CONFIG_CHANGES_MASK); |
Holly Jiuyu Sun | b6d7695 | 2017-01-11 17:34:03 -0800 | [diff] [blame] | 4851 | } |
| 4852 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4853 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4854 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4855 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4856 | int width = -1; |
| 4857 | float widthFraction = -1f; |
| 4858 | int height = -1; |
| 4859 | float heightFraction = -1f; |
| 4860 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4861 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4862 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 4863 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4864 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4865 | 1, 1, -1); |
| 4866 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 4867 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4868 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4869 | -1); |
| 4870 | } |
| 4871 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4872 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4873 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 4874 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4875 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4876 | 1, 1, -1); |
| 4877 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 4878 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 4879 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4880 | -1); |
| 4881 | } |
| 4882 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4883 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4884 | Gravity.CENTER); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4885 | int minWidth = sw.getDimensionPixelSize( |
| 4886 | com.android.internal.R.styleable.AndroidManifestLayout_minWidth, |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4887 | -1); |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4888 | int minHeight = sw.getDimensionPixelSize( |
| 4889 | com.android.internal.R.styleable.AndroidManifestLayout_minHeight, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4890 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4891 | sw.recycle(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4892 | a.info.windowLayout = new ActivityInfo.WindowLayout(width, widthFraction, |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4893 | height, heightFraction, gravity, minWidth, minHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4896 | private Activity parseActivityAlias(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4897 | XmlResourceParser parser, int flags, String[] outError, |
| 4898 | CachedComponentArgs cachedArgs) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4899 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4900 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4901 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 4902 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4903 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 4904 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 4905 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4906 | if (targetActivity == null) { |
| 4907 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 4908 | sa.recycle(); |
| 4909 | return null; |
| 4910 | } |
| 4911 | |
| 4912 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 4913 | targetActivity, outError); |
| 4914 | if (targetActivity == null) { |
| 4915 | sa.recycle(); |
| 4916 | return null; |
| 4917 | } |
| 4918 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4919 | if (cachedArgs.mActivityAliasArgs == null) { |
| 4920 | cachedArgs.mActivityAliasArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4921 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 4922 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 4923 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 4924 | com.android.internal.R.styleable.AndroidManifestActivityAlias_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4925 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4926 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4927 | mSeparateProcesses, |
| 4928 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4929 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4930 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4931 | cachedArgs.mActivityAliasArgs.tag = "<activity-alias>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4932 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4933 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4934 | cachedArgs.mActivityAliasArgs.sa = sa; |
| 4935 | cachedArgs.mActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4937 | Activity target = null; |
| 4938 | |
| 4939 | final int NA = owner.activities.size(); |
| 4940 | for (int i=0; i<NA; i++) { |
| 4941 | Activity t = owner.activities.get(i); |
| 4942 | if (targetActivity.equals(t.info.name)) { |
| 4943 | target = t; |
| 4944 | break; |
| 4945 | } |
| 4946 | } |
| 4947 | |
| 4948 | if (target == null) { |
| 4949 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 4950 | + " not found in manifest"; |
| 4951 | sa.recycle(); |
| 4952 | return null; |
| 4953 | } |
| 4954 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4955 | ActivityInfo info = new ActivityInfo(); |
| 4956 | info.targetActivity = targetActivity; |
| 4957 | info.configChanges = target.info.configChanges; |
| 4958 | info.flags = target.info.flags; |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4959 | info.privateFlags = target.info.privateFlags; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4960 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4961 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4962 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4963 | info.labelRes = target.info.labelRes; |
| 4964 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 4965 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 4966 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4967 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4968 | if (info.descriptionRes == 0) { |
| 4969 | info.descriptionRes = target.info.descriptionRes; |
| 4970 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4971 | info.screenOrientation = target.info.screenOrientation; |
| 4972 | info.taskAffinity = target.info.taskAffinity; |
| 4973 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 4974 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 4975 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 4976 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4977 | info.maxRecents = target.info.maxRecents; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 4978 | info.windowLayout = target.info.windowLayout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 4979 | info.resizeMode = target.info.resizeMode; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 4980 | info.maxAspectRatio = target.info.maxAspectRatio; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 4981 | info.minAspectRatio = target.info.minAspectRatio; |
rongliu | c12ede4 | 2018-02-23 17:58:38 -0800 | [diff] [blame] | 4982 | info.requestedVrComponent = target.info.requestedVrComponent; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 4983 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4984 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 4985 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 4986 | Activity a = new Activity(cachedArgs.mActivityAliasArgs, info); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4987 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | sa.recycle(); |
| 4989 | return null; |
| 4990 | } |
| 4991 | |
| 4992 | final boolean setExported = sa.hasValue( |
| 4993 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 4994 | if (setExported) { |
| 4995 | a.info.exported = sa.getBoolean( |
| 4996 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 4997 | } |
| 4998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4999 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5000 | str = sa.getNonConfigurationString( |
| 5001 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | if (str != null) { |
| 5003 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 5004 | } |
| 5005 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5006 | String parentName = sa.getNonConfigurationString( |
| 5007 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 5008 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 5009 | if (parentName != null) { |
| 5010 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 5011 | if (outError[0] == null) { |
| 5012 | a.info.parentActivityName = parentClassName; |
| 5013 | } else { |
| 5014 | Log.e(TAG, "Activity alias " + a.info.name + |
| 5015 | " specified invalid parentActivityName " + parentName); |
| 5016 | outError[0] = null; |
| 5017 | } |
| 5018 | } |
| 5019 | |
Chad Brubaker | 699c771 | 2017-01-20 13:53:42 -0800 | [diff] [blame] | 5020 | // TODO add visibleToInstantApps attribute to activity alias |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5021 | final boolean visibleToEphemeral = |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5022 | ((a.info.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | sa.recycle(); |
| 5025 | |
| 5026 | if (outError[0] != null) { |
| 5027 | return null; |
| 5028 | } |
| 5029 | |
| 5030 | int outerDepth = parser.getDepth(); |
| 5031 | int type; |
| 5032 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5033 | && (type != XmlPullParser.END_TAG |
| 5034 | || parser.getDepth() > outerDepth)) { |
| 5035 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5036 | continue; |
| 5037 | } |
| 5038 | |
| 5039 | if (parser.getName().equals("intent-filter")) { |
| 5040 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5041 | if (!parseIntent(res, parser, true /*allowGlobs*/, true /*allowAutoVerify*/, |
| 5042 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | return null; |
| 5044 | } |
| 5045 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5046 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 5047 | + mArchiveSourcePath + " " |
| 5048 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5049 | } else { |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5050 | a.order = Math.max(intent.getOrder(), a.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5051 | a.intents.add(intent); |
| 5052 | } |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5053 | // adjust activity flags when we implicitly expose it via a browsable filter |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5054 | final int visibility = visibleToEphemeral |
| 5055 | ? IntentFilter.VISIBILITY_EXPLICIT |
| 5056 | : isImplicitlyExposedIntent(intent) |
| 5057 | ? IntentFilter.VISIBILITY_IMPLICIT |
| 5058 | : IntentFilter.VISIBILITY_NONE; |
| 5059 | intent.setVisibilityToInstantApp(visibility); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5060 | if (intent.isVisibleToInstantApp()) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5061 | a.info.flags |= ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
| 5062 | } |
| 5063 | if (intent.isImplicitlyVisibleToInstantApp()) { |
| 5064 | a.info.flags |= ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5065 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5066 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5067 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5068 | outError)) == null) { |
| 5069 | return null; |
| 5070 | } |
| 5071 | } else { |
| 5072 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5073 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5074 | + " at " + mArchiveSourcePath + " " |
| 5075 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5076 | XmlUtils.skipCurrentTag(parser); |
| 5077 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5078 | } else { |
| 5079 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 5080 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | if (!setExported) { |
| 5086 | a.info.exported = a.intents.size() > 0; |
| 5087 | } |
| 5088 | |
| 5089 | return a; |
| 5090 | } |
| 5091 | |
| 5092 | private Provider parseProvider(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5093 | XmlResourceParser parser, int flags, String[] outError, |
| 5094 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5095 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5096 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 5098 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5099 | if (cachedArgs.mProviderArgs == null) { |
| 5100 | cachedArgs.mProviderArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5101 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 5102 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 5103 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5104 | com.android.internal.R.styleable.AndroidManifestProvider_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5105 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5106 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5107 | mSeparateProcesses, |
| 5108 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5109 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5110 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5111 | cachedArgs.mProviderArgs.tag = "<provider>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5112 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5113 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5114 | cachedArgs.mProviderArgs.sa = sa; |
| 5115 | cachedArgs.mProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5116 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5117 | Provider p = new Provider(cachedArgs.mProviderArgs, new ProviderInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5118 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5119 | sa.recycle(); |
| 5120 | return null; |
| 5121 | } |
| 5122 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5123 | boolean providerExportedDefault = false; |
| 5124 | |
| 5125 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 5126 | // For compatibility, applications targeting API level 16 or lower |
| 5127 | // should have their content providers exported by default, unless they |
| 5128 | // specify otherwise. |
| 5129 | providerExportedDefault = true; |
| 5130 | } |
| 5131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5132 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5133 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 5134 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5136 | String cpname = sa.getNonConfigurationString( |
| 5137 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5138 | |
| 5139 | p.info.isSyncable = sa.getBoolean( |
| 5140 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 5141 | false); |
| 5142 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5143 | String permission = sa.getNonConfigurationString( |
| 5144 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 5145 | String str = sa.getNonConfigurationString( |
| 5146 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5147 | if (str == null) { |
| 5148 | str = permission; |
| 5149 | } |
| 5150 | if (str == null) { |
| 5151 | p.info.readPermission = owner.applicationInfo.permission; |
| 5152 | } else { |
| 5153 | p.info.readPermission = |
| 5154 | str.length() > 0 ? str.toString().intern() : null; |
| 5155 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5156 | str = sa.getNonConfigurationString( |
| 5157 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5158 | if (str == null) { |
| 5159 | str = permission; |
| 5160 | } |
| 5161 | if (str == null) { |
| 5162 | p.info.writePermission = owner.applicationInfo.permission; |
| 5163 | } else { |
| 5164 | p.info.writePermission = |
| 5165 | str.length() > 0 ? str.toString().intern() : null; |
| 5166 | } |
| 5167 | |
| 5168 | p.info.grantUriPermissions = sa.getBoolean( |
| 5169 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 5170 | false); |
| 5171 | |
Dianne Hackborn | 52e42a4 | 2019-02-05 16:10:50 -0800 | [diff] [blame] | 5172 | p.info.forceUriPermissions = sa.getBoolean( |
| 5173 | com.android.internal.R.styleable.AndroidManifestProvider_forceUriPermissions, |
| 5174 | false); |
| 5175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | p.info.multiprocess = sa.getBoolean( |
| 5177 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 5178 | false); |
| 5179 | |
| 5180 | p.info.initOrder = sa.getInt( |
| 5181 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 5182 | 0); |
| 5183 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5184 | p.info.splitName = |
| 5185 | sa.getNonConfigurationString(R.styleable.AndroidManifestProvider_splitName, 0); |
| 5186 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 5187 | p.info.flags = 0; |
| 5188 | |
| 5189 | if (sa.getBoolean( |
| 5190 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 5191 | false)) { |
| 5192 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 5193 | } |
| 5194 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5195 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 5196 | R.styleable.AndroidManifestProvider_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5197 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5198 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5199 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5200 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5201 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5202 | |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5203 | final boolean visibleToEphemeral = |
| 5204 | sa.getBoolean(R.styleable.AndroidManifestProvider_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5205 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5206 | p.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5207 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5208 | } |
| 5209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | sa.recycle(); |
| 5211 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5212 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5213 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5214 | // A heavy-weight application can not have providers in its main process |
| 5215 | // We can do direct compare because we intern all strings. |
| 5216 | if (p.info.processName == owner.packageName) { |
| 5217 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 5218 | return null; |
| 5219 | } |
| 5220 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 5223 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | return null; |
| 5225 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 5226 | if (cpname.length() <= 0) { |
| 5227 | outError[0] = "<provider> has empty authorities attribute"; |
| 5228 | return null; |
| 5229 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | p.info.authority = cpname.intern(); |
| 5231 | |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5232 | if (!parseProviderTags( |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 5233 | res, parser, visibleToEphemeral, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5234 | return null; |
| 5235 | } |
| 5236 | |
| 5237 | return p; |
| 5238 | } |
| 5239 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5240 | private boolean parseProviderTags(Resources res, XmlResourceParser parser, |
Patrick Baumann | a290039 | 2018-02-05 15:30:43 -0800 | [diff] [blame] | 5241 | boolean visibleToEphemeral, Provider outInfo, String[] outError) |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5242 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | int outerDepth = parser.getDepth(); |
| 5244 | int type; |
| 5245 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5246 | && (type != XmlPullParser.END_TAG |
| 5247 | || parser.getDepth() > outerDepth)) { |
| 5248 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5249 | continue; |
| 5250 | } |
| 5251 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5252 | if (parser.getName().equals("intent-filter")) { |
| 5253 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5254 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5255 | intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5256 | return false; |
| 5257 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5258 | if (visibleToEphemeral) { |
| 5259 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5260 | outInfo.info.flags |= ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5261 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5262 | outInfo.order = Math.max(intent.getOrder(), outInfo.order); |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5263 | outInfo.intents.add(intent); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5264 | |
| 5265 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5266 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5267 | outInfo.metaData, outError)) == null) { |
| 5268 | return false; |
| 5269 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5272 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5273 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 5274 | |
| 5275 | PatternMatcher pa = null; |
| 5276 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5277 | String str = sa.getNonConfigurationString( |
| 5278 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | if (str != null) { |
| 5280 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 5281 | } |
| 5282 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5283 | str = sa.getNonConfigurationString( |
| 5284 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5285 | if (str != null) { |
| 5286 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 5287 | } |
| 5288 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5289 | str = sa.getNonConfigurationString( |
| 5290 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5291 | if (str != null) { |
| 5292 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5293 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5295 | sa.recycle(); |
| 5296 | |
| 5297 | if (pa != null) { |
| 5298 | if (outInfo.info.uriPermissionPatterns == null) { |
| 5299 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 5300 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 5301 | } else { |
| 5302 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 5303 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 5304 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 5305 | newp[N] = pa; |
| 5306 | outInfo.info.uriPermissionPatterns = newp; |
| 5307 | } |
| 5308 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5309 | } else { |
| 5310 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5311 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5312 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5313 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5314 | XmlUtils.skipCurrentTag(parser); |
| 5315 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5316 | } else { |
| 5317 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5318 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5319 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5320 | } |
| 5321 | XmlUtils.skipCurrentTag(parser); |
| 5322 | |
| 5323 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5324 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5325 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 5326 | |
| 5327 | PathPermission pa = null; |
| 5328 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5329 | String permission = sa.getNonConfigurationString( |
| 5330 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 5331 | String readPermission = sa.getNonConfigurationString( |
| 5332 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5333 | if (readPermission == null) { |
| 5334 | readPermission = permission; |
| 5335 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5336 | String writePermission = sa.getNonConfigurationString( |
| 5337 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5338 | if (writePermission == null) { |
| 5339 | writePermission = permission; |
| 5340 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5341 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5342 | boolean havePerm = false; |
| 5343 | if (readPermission != null) { |
| 5344 | readPermission = readPermission.intern(); |
| 5345 | havePerm = true; |
| 5346 | } |
| 5347 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 5348 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5349 | havePerm = true; |
| 5350 | } |
| 5351 | |
| 5352 | if (!havePerm) { |
| 5353 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5354 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5355 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5356 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5357 | XmlUtils.skipCurrentTag(parser); |
| 5358 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5359 | } else { |
| 5360 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 5361 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5362 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5363 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5364 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5365 | String path = sa.getNonConfigurationString( |
| 5366 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5367 | if (path != null) { |
| 5368 | pa = new PathPermission(path, |
| 5369 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 5370 | } |
| 5371 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5372 | path = sa.getNonConfigurationString( |
| 5373 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5374 | if (path != null) { |
| 5375 | pa = new PathPermission(path, |
| 5376 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 5377 | } |
| 5378 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5379 | path = sa.getNonConfigurationString( |
| 5380 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5381 | if (path != null) { |
| 5382 | pa = new PathPermission(path, |
| 5383 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 5384 | } |
| 5385 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5386 | path = sa.getNonConfigurationString( |
| 5387 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathAdvancedPattern, 0); |
| 5388 | if (path != null) { |
| 5389 | pa = new PathPermission(path, |
| 5390 | PatternMatcher.PATTERN_ADVANCED_GLOB, readPermission, writePermission); |
| 5391 | } |
| 5392 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5393 | sa.recycle(); |
| 5394 | |
| 5395 | if (pa != null) { |
| 5396 | if (outInfo.info.pathPermissions == null) { |
| 5397 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 5398 | outInfo.info.pathPermissions[0] = pa; |
| 5399 | } else { |
| 5400 | final int N = outInfo.info.pathPermissions.length; |
| 5401 | PathPermission[] newp = new PathPermission[N+1]; |
| 5402 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 5403 | newp[N] = pa; |
| 5404 | outInfo.info.pathPermissions = newp; |
| 5405 | } |
| 5406 | } else { |
| 5407 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5408 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5409 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5410 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 5411 | XmlUtils.skipCurrentTag(parser); |
| 5412 | continue; |
| 5413 | } |
| 5414 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 5415 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | } |
| 5417 | XmlUtils.skipCurrentTag(parser); |
| 5418 | |
| 5419 | } else { |
| 5420 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5421 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5422 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5423 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5424 | XmlUtils.skipCurrentTag(parser); |
| 5425 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5426 | } else { |
| 5427 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 5428 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | return true; |
| 5433 | } |
| 5434 | |
| 5435 | private Service parseService(Package owner, Resources res, |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5436 | XmlResourceParser parser, int flags, String[] outError, |
| 5437 | CachedComponentArgs cachedArgs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5439 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | com.android.internal.R.styleable.AndroidManifestService); |
| 5441 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5442 | if (cachedArgs.mServiceArgs == null) { |
| 5443 | cachedArgs.mServiceArgs = new ParseComponentArgs(owner, outError, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5444 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 5445 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 5446 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5447 | com.android.internal.R.styleable.AndroidManifestService_roundIcon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5448 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5449 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5450 | mSeparateProcesses, |
| 5451 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5452 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5453 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5454 | cachedArgs.mServiceArgs.tag = "<service>"; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5455 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5456 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5457 | cachedArgs.mServiceArgs.sa = sa; |
| 5458 | cachedArgs.mServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5459 | |
Garrett Boyer | 5213666 | 2017-05-23 13:47:58 -0700 | [diff] [blame] | 5460 | Service s = new Service(cachedArgs.mServiceArgs, new ServiceInfo()); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5461 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | sa.recycle(); |
| 5463 | return null; |
| 5464 | } |
| 5465 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5466 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5467 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 5468 | if (setExported) { |
| 5469 | s.info.exported = sa.getBoolean( |
| 5470 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 5471 | } |
| 5472 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5473 | String str = sa.getNonConfigurationString( |
| 5474 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | if (str == null) { |
| 5476 | s.info.permission = owner.applicationInfo.permission; |
| 5477 | } else { |
| 5478 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 5479 | } |
| 5480 | |
Todd Kennedy | e9d0d27 | 2017-01-23 06:49:29 -0800 | [diff] [blame] | 5481 | s.info.splitName = |
| 5482 | sa.getNonConfigurationString(R.styleable.AndroidManifestService_splitName, 0); |
| 5483 | |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 5484 | s.info.mForegroundServiceType = sa.getInt( |
| 5485 | com.android.internal.R.styleable.AndroidManifestService_foregroundServiceType, |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 5486 | ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE); |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 5487 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5488 | s.info.flags = 0; |
| 5489 | if (sa.getBoolean( |
| 5490 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 5491 | false)) { |
| 5492 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 5493 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5494 | if (sa.getBoolean( |
| 5495 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 5496 | false)) { |
| 5497 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 5498 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5499 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 5500 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 5501 | false)) { |
| 5502 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 5503 | } |
| 5504 | if (sa.getBoolean( |
Martijn Coenen | e066c5c | 2018-10-31 16:50:30 +0100 | [diff] [blame] | 5505 | com.android.internal.R.styleable.AndroidManifestService_useAppZygote, |
| 5506 | false)) { |
| 5507 | s.info.flags |= ServiceInfo.FLAG_USE_APP_ZYGOTE; |
| 5508 | } |
| 5509 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5510 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 5511 | false)) { |
| 5512 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 5513 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 5514 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5515 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 5516 | R.styleable.AndroidManifestService_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 5517 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5518 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5519 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5520 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 5521 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 5522 | |
Todd Kennedy | 752fb70 | 2017-03-21 16:28:10 -0700 | [diff] [blame] | 5523 | boolean visibleToEphemeral = |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 5524 | sa.getBoolean(R.styleable.AndroidManifestService_visibleToInstantApps, false); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5525 | if (visibleToEphemeral) { |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5526 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 5527 | owner.visibleToInstantApps = true; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5528 | } |
| 5529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5530 | sa.recycle(); |
| 5531 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5532 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 5533 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 5534 | // A heavy-weight application can not have services in its main process |
| 5535 | // We can do direct compare because we intern all strings. |
| 5536 | if (s.info.processName == owner.packageName) { |
| 5537 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 5538 | return null; |
| 5539 | } |
| 5540 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | int outerDepth = parser.getDepth(); |
| 5543 | int type; |
| 5544 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5545 | && (type != XmlPullParser.END_TAG |
| 5546 | || parser.getDepth() > outerDepth)) { |
| 5547 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5548 | continue; |
| 5549 | } |
| 5550 | |
| 5551 | if (parser.getName().equals("intent-filter")) { |
| 5552 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5553 | if (!parseIntent(res, parser, true /*allowGlobs*/, false /*allowAutoVerify*/, |
| 5554 | intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | return null; |
| 5556 | } |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 5557 | if (visibleToEphemeral) { |
| 5558 | intent.setVisibilityToInstantApp(IntentFilter.VISIBILITY_EXPLICIT); |
| 5559 | s.info.flags |= ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP; |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5560 | } |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5561 | s.order = Math.max(intent.getOrder(), s.order); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | s.intents.add(intent); |
| 5563 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5564 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5565 | outError)) == null) { |
| 5566 | return null; |
| 5567 | } |
| 5568 | } else { |
| 5569 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5570 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5571 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5572 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | XmlUtils.skipCurrentTag(parser); |
| 5574 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5575 | } else { |
| 5576 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 5577 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5578 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | if (!setExported) { |
| 5583 | s.info.exported = s.intents.size() > 0; |
| 5584 | } |
| 5585 | |
| 5586 | return s; |
| 5587 | } |
| 5588 | |
Chad Brubaker | 4941483 | 2017-04-13 16:13:23 -0700 | [diff] [blame] | 5589 | private boolean isImplicitlyExposedIntent(IntentInfo intent) { |
| 5590 | return intent.hasCategory(Intent.CATEGORY_BROWSABLE) |
| 5591 | || intent.hasAction(Intent.ACTION_SEND) |
| 5592 | || intent.hasAction(Intent.ACTION_SENDTO) |
| 5593 | || intent.hasAction(Intent.ACTION_SEND_MULTIPLE); |
Todd Kennedy | 388eb8c | 2016-12-16 14:40:25 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5596 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 5597 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | int outerDepth = parser.getDepth(); |
| 5599 | int type; |
| 5600 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 5601 | && (type != XmlPullParser.END_TAG |
| 5602 | || parser.getDepth() > outerDepth)) { |
| 5603 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5604 | continue; |
| 5605 | } |
| 5606 | |
| 5607 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5608 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | outInfo.metaData, outError)) == null) { |
| 5610 | return false; |
| 5611 | } |
| 5612 | } else { |
| 5613 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5614 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5615 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5616 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | XmlUtils.skipCurrentTag(parser); |
| 5618 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5619 | } else { |
| 5620 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 5621 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | } |
| 5624 | } |
| 5625 | return true; |
| 5626 | } |
| 5627 | |
| 5628 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5629 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | throws XmlPullParserException, IOException { |
| 5631 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5632 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 5634 | |
| 5635 | if (data == null) { |
| 5636 | data = new Bundle(); |
| 5637 | } |
| 5638 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5639 | String name = sa.getNonConfigurationString( |
| 5640 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | if (name == null) { |
| 5642 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 5643 | sa.recycle(); |
| 5644 | return null; |
| 5645 | } |
| 5646 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 5647 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | TypedValue v = sa.peekValue( |
| 5650 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 5651 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5652 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | data.putInt(name, v.resourceId); |
| 5654 | } else { |
| 5655 | v = sa.peekValue( |
| 5656 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5657 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | if (v != null) { |
| 5659 | if (v.type == TypedValue.TYPE_STRING) { |
| 5660 | CharSequence cs = v.coerceToString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 5661 | data.putString(name, cs != null ? cs.toString() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5662 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 5663 | data.putBoolean(name, v.data != 0); |
| 5664 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 5665 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 5666 | data.putInt(name, v.data); |
| 5667 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 5668 | data.putFloat(name, v.getFloat()); |
| 5669 | } else { |
| 5670 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5671 | 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] | 5672 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5673 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5674 | } else { |
| 5675 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 5676 | data = null; |
| 5677 | } |
| 5678 | } |
| 5679 | } else { |
| 5680 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 5681 | data = null; |
| 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | sa.recycle(); |
| 5686 | |
| 5687 | XmlUtils.skipCurrentTag(parser); |
| 5688 | |
| 5689 | return data; |
| 5690 | } |
| 5691 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5692 | private static VerifierInfo parseVerifier(AttributeSet attrs) { |
| 5693 | String packageName = null; |
| 5694 | String encodedPublicKey = null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5695 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5696 | final int attrCount = attrs.getAttributeCount(); |
| 5697 | for (int i = 0; i < attrCount; i++) { |
| 5698 | final int attrResId = attrs.getAttributeNameResource(i); |
| 5699 | switch (attrResId) { |
| 5700 | case com.android.internal.R.attr.name: |
| 5701 | packageName = attrs.getAttributeValue(i); |
| 5702 | break; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5703 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 5704 | case com.android.internal.R.attr.publicKey: |
| 5705 | encodedPublicKey = attrs.getAttributeValue(i); |
| 5706 | break; |
| 5707 | } |
| 5708 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5709 | |
| 5710 | if (packageName == null || packageName.length() == 0) { |
| 5711 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 5712 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5715 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 5716 | if (publicKey == null) { |
| 5717 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 5718 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5719 | } |
| 5720 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5721 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5724 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 5725 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5726 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 5727 | return null; |
| 5728 | } |
| 5729 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5730 | EncodedKeySpec keySpec; |
| 5731 | try { |
| 5732 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 5733 | keySpec = new X509EncodedKeySpec(encoded); |
| 5734 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5735 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5736 | return null; |
| 5737 | } |
| 5738 | |
| 5739 | /* First try the key as an RSA key. */ |
| 5740 | try { |
| 5741 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5742 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5743 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5744 | 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] | 5745 | } catch (InvalidKeySpecException e) { |
| 5746 | // Not a RSA public key. |
| 5747 | } |
| 5748 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5749 | /* Now try it as a ECDSA key. */ |
| 5750 | try { |
| 5751 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 5752 | return keyFactory.generatePublic(keySpec); |
| 5753 | } catch (NoSuchAlgorithmException e) { |
| 5754 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 5755 | } catch (InvalidKeySpecException e) { |
| 5756 | // Not a ECDSA public key. |
| 5757 | } |
| 5758 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5759 | /* Now try it as a DSA key. */ |
| 5760 | try { |
| 5761 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 5762 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5763 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5764 | 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] | 5765 | } catch (InvalidKeySpecException e) { |
| 5766 | // Not a DSA public key. |
| 5767 | } |
| 5768 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 5769 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 5770 | return null; |
| 5771 | } |
| 5772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | private static final String ANDROID_RESOURCES |
| 5774 | = "http://schemas.android.com/apk/res/android"; |
| 5775 | |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 5776 | private boolean parseIntent(Resources res, XmlResourceParser parser, boolean allowGlobs, |
| 5777 | boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
| 5778 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5779 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5780 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5781 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 5782 | |
| 5783 | int priority = sa.getInt( |
| 5784 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5785 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 5786 | |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 5787 | int order = sa.getInt( |
| 5788 | com.android.internal.R.styleable.AndroidManifestIntentFilter_order, 0); |
| 5789 | outInfo.setOrder(order); |
| 5790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | TypedValue v = sa.peekValue( |
| 5792 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 5793 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5794 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5795 | } |
| 5796 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 5797 | int roundIconVal = sUseRoundIcon ? sa.getResourceId( |
Todd Kennedy | a83bfca | 2016-06-03 07:52:17 -0700 | [diff] [blame] | 5798 | com.android.internal.R.styleable.AndroidManifestIntentFilter_roundIcon, 0) : 0; |
| 5799 | if (roundIconVal != 0) { |
| 5800 | outInfo.icon = roundIconVal; |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 5801 | } else { |
| 5802 | outInfo.icon = sa.getResourceId( |
| 5803 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
| 5804 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5805 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5806 | outInfo.logo = sa.getResourceId( |
| 5807 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5809 | outInfo.banner = sa.getResourceId( |
| 5810 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 5811 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 5812 | if (allowAutoVerify) { |
| 5813 | outInfo.setAutoVerify(sa.getBoolean( |
| 5814 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 5815 | false)); |
| 5816 | } |
| 5817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | sa.recycle(); |
| 5819 | |
| 5820 | int outerDepth = parser.getDepth(); |
| 5821 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5822 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5823 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5824 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | continue; |
| 5826 | } |
| 5827 | |
| 5828 | String nodeName = parser.getName(); |
| 5829 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5830 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | ANDROID_RESOURCES, "name"); |
| 5832 | if (value == null || value == "") { |
| 5833 | outError[0] = "No value supplied for <android:name>"; |
| 5834 | return false; |
| 5835 | } |
| 5836 | XmlUtils.skipCurrentTag(parser); |
| 5837 | |
| 5838 | outInfo.addAction(value); |
| 5839 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5840 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5841 | ANDROID_RESOURCES, "name"); |
| 5842 | if (value == null || value == "") { |
| 5843 | outError[0] = "No value supplied for <android:name>"; |
| 5844 | return false; |
| 5845 | } |
| 5846 | XmlUtils.skipCurrentTag(parser); |
| 5847 | |
| 5848 | outInfo.addCategory(value); |
| 5849 | |
| 5850 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 5851 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | com.android.internal.R.styleable.AndroidManifestData); |
| 5853 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5854 | String str = sa.getNonConfigurationString( |
| 5855 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | if (str != null) { |
| 5857 | try { |
| 5858 | outInfo.addDataType(str); |
| 5859 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 5860 | outError[0] = e.toString(); |
| 5861 | sa.recycle(); |
| 5862 | return false; |
| 5863 | } |
| 5864 | } |
| 5865 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5866 | str = sa.getNonConfigurationString( |
| 5867 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5868 | if (str != null) { |
| 5869 | outInfo.addDataScheme(str); |
| 5870 | } |
| 5871 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5872 | str = sa.getNonConfigurationString( |
| 5873 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 5874 | if (str != null) { |
| 5875 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 5876 | } |
| 5877 | |
| 5878 | str = sa.getNonConfigurationString( |
| 5879 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 5880 | if (str != null) { |
| 5881 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 5882 | } |
| 5883 | |
| 5884 | str = sa.getNonConfigurationString( |
| 5885 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 5886 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5887 | if (!allowGlobs) { |
| 5888 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 5889 | return false; |
| 5890 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 5891 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5892 | } |
| 5893 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5894 | String host = sa.getNonConfigurationString( |
| 5895 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 5896 | String port = sa.getNonConfigurationString( |
| 5897 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | if (host != null) { |
| 5899 | outInfo.addDataAuthority(host, port); |
| 5900 | } |
| 5901 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5902 | str = sa.getNonConfigurationString( |
| 5903 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5904 | if (str != null) { |
| 5905 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 5906 | } |
| 5907 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5908 | str = sa.getNonConfigurationString( |
| 5909 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | if (str != null) { |
| 5911 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 5912 | } |
| 5913 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5914 | str = sa.getNonConfigurationString( |
| 5915 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5916 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5917 | if (!allowGlobs) { |
| 5918 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 5919 | return false; |
| 5920 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 5922 | } |
| 5923 | |
Todd Kennedy | 9c9fdf2 | 2017-03-06 10:58:27 -0800 | [diff] [blame] | 5924 | str = sa.getNonConfigurationString( |
| 5925 | com.android.internal.R.styleable.AndroidManifestData_pathAdvancedPattern, 0); |
| 5926 | if (str != null) { |
| 5927 | if (!allowGlobs) { |
| 5928 | outError[0] = "pathAdvancedPattern not allowed here; path must be literal"; |
| 5929 | return false; |
| 5930 | } |
| 5931 | outInfo.addDataPath(str, PatternMatcher.PATTERN_ADVANCED_GLOB); |
| 5932 | } |
| 5933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | sa.recycle(); |
| 5935 | XmlUtils.skipCurrentTag(parser); |
| 5936 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5937 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 5938 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 5939 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | XmlUtils.skipCurrentTag(parser); |
| 5941 | } else { |
| 5942 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 5943 | return false; |
| 5944 | } |
| 5945 | } |
| 5946 | |
| 5947 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5948 | |
| 5949 | if (DEBUG_PARSER) { |
| 5950 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 5951 | cats.append(outInfo.hasDefault); |
| 5952 | cats.append(", cat="); |
| 5953 | |
| 5954 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 5955 | if (it != null) { |
| 5956 | while (it.hasNext()) { |
| 5957 | cats.append(' '); |
| 5958 | cats.append(it.next()); |
| 5959 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5960 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 5961 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | return true; |
| 5965 | } |
| 5966 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5967 | /** |
| 5968 | * A container for signing-related data of an application package. |
| 5969 | * @hide |
| 5970 | */ |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5971 | public static final class SigningDetails implements Parcelable { |
| 5972 | |
| 5973 | @IntDef({SigningDetails.SignatureSchemeVersion.UNKNOWN, |
| 5974 | SigningDetails.SignatureSchemeVersion.JAR, |
| 5975 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V2, |
| 5976 | SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V3}) |
| 5977 | public @interface SignatureSchemeVersion { |
| 5978 | int UNKNOWN = 0; |
| 5979 | int JAR = 1; |
| 5980 | int SIGNING_BLOCK_V2 = 2; |
| 5981 | int SIGNING_BLOCK_V3 = 3; |
| 5982 | } |
| 5983 | |
| 5984 | @Nullable |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 5985 | @UnsupportedAppUsage |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 5986 | public final Signature[] signatures; |
| 5987 | @SignatureSchemeVersion |
| 5988 | public final int signatureSchemeVersion; |
| 5989 | @Nullable |
| 5990 | public final ArraySet<PublicKey> publicKeys; |
| 5991 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 5992 | /** |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 5993 | * APK Signature Scheme v3 includes support for adding a proof-of-rotation record that |
| 5994 | * contains two pieces of information: |
| 5995 | * 1) the past signing certificates |
| 5996 | * 2) the flags that APK wants to assign to each of the past signing certificates. |
| 5997 | * |
| 5998 | * This collection of {@code Signature} objects, each of which is formed from a former |
| 5999 | * signing certificate of this APK before it was changed by signing certificate rotation, |
| 6000 | * represents the first piece of information. It is the APK saying to the rest of the |
| 6001 | * world: "hey if you trust the old cert, you can trust me!" This is useful, if for |
| 6002 | * instance, the platform would like to determine whether or not to allow this APK to do |
| 6003 | * 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] | 6004 | */ |
| 6005 | @Nullable |
| 6006 | public final Signature[] pastSigningCertificates; |
| 6007 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6008 | /** special value used to see if cert is in package - not exposed to callers */ |
| 6009 | private static final int PAST_CERT_EXISTS = 0; |
| 6010 | |
| 6011 | @IntDef( |
| 6012 | flag = true, |
| 6013 | value = {CertCapabilities.INSTALLED_DATA, |
| 6014 | CertCapabilities.SHARED_USER_ID, |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 6015 | CertCapabilities.PERMISSION, |
| 6016 | CertCapabilities.ROLLBACK}) |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6017 | public @interface CertCapabilities { |
| 6018 | |
| 6019 | /** accept data from already installed pkg with this cert */ |
| 6020 | int INSTALLED_DATA = 1; |
| 6021 | |
| 6022 | /** accept sharedUserId with pkg with this cert */ |
| 6023 | int SHARED_USER_ID = 2; |
| 6024 | |
| 6025 | /** grant SIGNATURE permissions to pkgs with this cert */ |
| 6026 | int PERMISSION = 4; |
Daniel Cashman | 629a5f9 | 2018-03-30 18:54:14 -0700 | [diff] [blame] | 6027 | |
| 6028 | /** allow pkg to update to one signed by this certificate */ |
| 6029 | int ROLLBACK = 8; |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 6030 | |
| 6031 | /** allow pkg to continue to have auth access gated by this cert */ |
| 6032 | int AUTH = 16; |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6033 | } |
| 6034 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6035 | /** A representation of unknown signing details. Use instead of null. */ |
| 6036 | public static final SigningDetails UNKNOWN = |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6037 | new SigningDetails(null, SignatureSchemeVersion.UNKNOWN, null, null); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6038 | |
| 6039 | @VisibleForTesting |
| 6040 | public SigningDetails(Signature[] signatures, |
| 6041 | @SignatureSchemeVersion int signatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6042 | ArraySet<PublicKey> keys, Signature[] pastSigningCertificates) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6043 | this.signatures = signatures; |
| 6044 | this.signatureSchemeVersion = signatureSchemeVersion; |
| 6045 | this.publicKeys = keys; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6046 | this.pastSigningCertificates = pastSigningCertificates; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | public SigningDetails(Signature[] signatures, |
| 6050 | @SignatureSchemeVersion int signatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6051 | Signature[] pastSigningCertificates) |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6052 | throws CertificateException { |
| 6053 | this(signatures, signatureSchemeVersion, toSigningKeys(signatures), |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6054 | pastSigningCertificates); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | public SigningDetails(Signature[] signatures, |
| 6058 | @SignatureSchemeVersion int signatureSchemeVersion) |
| 6059 | throws CertificateException { |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6060 | this(signatures, signatureSchemeVersion, null); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | public SigningDetails(SigningDetails orig) { |
| 6064 | if (orig != null) { |
| 6065 | if (orig.signatures != null) { |
| 6066 | this.signatures = orig.signatures.clone(); |
| 6067 | } else { |
| 6068 | this.signatures = null; |
| 6069 | } |
| 6070 | this.signatureSchemeVersion = orig.signatureSchemeVersion; |
| 6071 | this.publicKeys = new ArraySet<>(orig.publicKeys); |
| 6072 | if (orig.pastSigningCertificates != null) { |
| 6073 | this.pastSigningCertificates = orig.pastSigningCertificates.clone(); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6074 | } else { |
| 6075 | this.pastSigningCertificates = null; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6076 | } |
| 6077 | } else { |
| 6078 | this.signatures = null; |
| 6079 | this.signatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 6080 | this.publicKeys = null; |
| 6081 | this.pastSigningCertificates = null; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6082 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | /** Returns true if the signing details have one or more signatures. */ |
| 6086 | public boolean hasSignatures() { |
| 6087 | return signatures != null && signatures.length > 0; |
| 6088 | } |
| 6089 | |
Daniel Cashman | 5cdda34 | 2018-01-19 07:22:52 -0800 | [diff] [blame] | 6090 | /** Returns true if the signing details have past signing certificates. */ |
| 6091 | public boolean hasPastSigningCertificates() { |
| 6092 | return pastSigningCertificates != null && pastSigningCertificates.length > 0; |
| 6093 | } |
| 6094 | |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6095 | /** |
| 6096 | * Determines if the provided {@code oldDetails} is an ancestor of or the same as this one. |
| 6097 | * If the {@code oldDetails} signing certificate appears in our pastSigningCertificates, |
| 6098 | * then that means it has authorized a signing certificate rotation, which eventually leads |
| 6099 | * to our certificate, and thus can be trusted. If this method evaluates to true, this |
| 6100 | * SigningDetails object should be trusted if the previous one is. |
| 6101 | */ |
| 6102 | public boolean hasAncestorOrSelf(SigningDetails oldDetails) { |
| 6103 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6104 | return false; |
| 6105 | } |
| 6106 | if (oldDetails.signatures.length > 1) { |
| 6107 | |
| 6108 | // multiple-signer packages cannot rotate signing certs, so we just compare current |
| 6109 | // signers for an exact match |
| 6110 | return signaturesMatchExactly(oldDetails); |
| 6111 | } else { |
| 6112 | |
| 6113 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 6114 | // was one of our old signing certificates |
| 6115 | return hasCertificate(oldDetails.signatures[0]); |
| 6116 | } |
| 6117 | } |
| 6118 | |
| 6119 | /** |
| 6120 | * Similar to {@code hasAncestorOrSelf}. Returns true only if this {@code SigningDetails} |
| 6121 | * is a descendant of {@code oldDetails}, not if they're the same. This is used to |
| 6122 | * determine if this object is newer than the provided one. |
| 6123 | */ |
| 6124 | public boolean hasAncestor(SigningDetails oldDetails) { |
| 6125 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6126 | return false; |
| 6127 | } |
| 6128 | if (this.hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 6129 | |
| 6130 | // the last entry in pastSigningCertificates is the current signer, ignore it |
| 6131 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6132 | if (pastSigningCertificates[i].equals(oldDetails.signatures[i])) { |
| 6133 | return true; |
| 6134 | } |
| 6135 | } |
| 6136 | } |
| 6137 | return false; |
| 6138 | } |
| 6139 | |
| 6140 | /** |
| 6141 | * Determines if the provided {@code oldDetails} is an ancestor of this one, and whether or |
| 6142 | * not this one grants it the provided capability, represented by the {@code flags} |
| 6143 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 6144 | * with entities signed by its old signing certificate and not want to break previously |
| 6145 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 6146 | * signed by the newer signing certificate would like to continue to give to its previous |
| 6147 | * signing certificate(s). |
| 6148 | */ |
| 6149 | public boolean checkCapability(SigningDetails oldDetails, @CertCapabilities int flags) { |
| 6150 | if (this == UNKNOWN || oldDetails == UNKNOWN) { |
| 6151 | return false; |
| 6152 | } |
| 6153 | if (oldDetails.signatures.length > 1) { |
| 6154 | |
| 6155 | // multiple-signer packages cannot rotate signing certs, so we must have an exact |
| 6156 | // match, which also means all capabilities are granted |
| 6157 | return signaturesMatchExactly(oldDetails); |
| 6158 | } else { |
| 6159 | |
| 6160 | // we may have signing certificate rotation history, check to see if the oldDetails |
| 6161 | // was one of our old signing certificates, and if we grant it the capability it's |
| 6162 | // requesting |
| 6163 | return hasCertificate(oldDetails.signatures[0], flags); |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | /** |
| 6168 | * A special case of {@code checkCapability} which re-encodes both sets of signing |
| 6169 | * certificates to counteract a previous re-encoding. |
| 6170 | */ |
| 6171 | public boolean checkCapabilityRecover(SigningDetails oldDetails, |
| 6172 | @CertCapabilities int flags) throws CertificateException { |
| 6173 | if (oldDetails == UNKNOWN || this == UNKNOWN) { |
| 6174 | return false; |
| 6175 | } |
| 6176 | if (hasPastSigningCertificates() && oldDetails.signatures.length == 1) { |
| 6177 | |
| 6178 | // signing certificates may have rotated, check entire history for effective match |
| 6179 | for (int i = 0; i < pastSigningCertificates.length; i++) { |
| 6180 | if (Signature.areEffectiveMatch( |
| 6181 | oldDetails.signatures[0], |
| 6182 | pastSigningCertificates[i]) |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6183 | && pastSigningCertificates[i].getFlags() == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6184 | return true; |
| 6185 | } |
| 6186 | } |
| 6187 | } else { |
| 6188 | return Signature.areEffectiveMatch(oldDetails.signatures, signatures); |
| 6189 | } |
| 6190 | return false; |
| 6191 | } |
| 6192 | |
| 6193 | /** |
| 6194 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 6195 | * including the current signer. Automatically returns false if this object has multiple |
| 6196 | * signing certificates, since rotation is only supported for single-signers; this is |
| 6197 | * enforced by {@code hasCertificateInternal}. |
| 6198 | */ |
| 6199 | public boolean hasCertificate(Signature signature) { |
| 6200 | return hasCertificateInternal(signature, PAST_CERT_EXISTS); |
| 6201 | } |
| 6202 | |
| 6203 | /** |
| 6204 | * Determine if {@code signature} is in this SigningDetails' signing certificate history, |
| 6205 | * including the current signer, and whether or not it has the given permission. |
| 6206 | * Certificates which match our current signer automatically get all capabilities. |
| 6207 | * Automatically returns false if this object has multiple signing certificates, since |
| 6208 | * rotation is only supported for single-signers. |
| 6209 | */ |
| 6210 | public boolean hasCertificate(Signature signature, @CertCapabilities int flags) { |
| 6211 | return hasCertificateInternal(signature, flags); |
| 6212 | } |
| 6213 | |
| 6214 | /** Convenient wrapper for calling {@code hasCertificate} with certificate's raw bytes. */ |
| 6215 | public boolean hasCertificate(byte[] certificate) { |
| 6216 | Signature signature = new Signature(certificate); |
| 6217 | return hasCertificate(signature); |
| 6218 | } |
| 6219 | |
| 6220 | private boolean hasCertificateInternal(Signature signature, int flags) { |
| 6221 | if (this == UNKNOWN) { |
| 6222 | return false; |
| 6223 | } |
| 6224 | |
| 6225 | // only single-signed apps can have pastSigningCertificates |
| 6226 | if (hasPastSigningCertificates()) { |
| 6227 | |
| 6228 | // check all past certs, except for the current one, which automatically gets all |
| 6229 | // capabilities, since it is the same as the current signature |
| 6230 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6231 | if (pastSigningCertificates[i].equals(signature)) { |
| 6232 | if (flags == PAST_CERT_EXISTS |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6233 | || (flags & pastSigningCertificates[i].getFlags()) == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6234 | return true; |
| 6235 | } |
| 6236 | } |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | // not in previous certs signing history, just check the current signer and make sure |
| 6241 | // we are singly-signed |
| 6242 | return signatures.length == 1 && signatures[0].equals(signature); |
| 6243 | } |
| 6244 | |
| 6245 | /** |
| 6246 | * Determines if the provided {@code sha256String} is an ancestor of this one, and whether |
| 6247 | * or not this one grants it the provided capability, represented by the {@code flags} |
| 6248 | * parameter. In the event of signing certificate rotation, a package may still interact |
| 6249 | * with entities signed by its old signing certificate and not want to break previously |
| 6250 | * functioning behavior. The {@code flags} value determines which capabilities the app |
| 6251 | * signed by the newer signing certificate would like to continue to give to its previous |
| 6252 | * signing certificate(s). |
| 6253 | * |
| 6254 | * @param sha256String A hex-encoded representation of a sha256 digest. In the case of an |
| 6255 | * app with multiple signers, this represents the hex-encoded sha256 |
| 6256 | * digest of the combined hex-encoded sha256 digests of each individual |
| 6257 | * signing certificate according to {@link |
| 6258 | * PackageUtils#computeSignaturesSha256Digest(Signature[])} |
| 6259 | */ |
| 6260 | public boolean checkCapability(String sha256String, @CertCapabilities int flags) { |
| 6261 | if (this == UNKNOWN) { |
| 6262 | return false; |
| 6263 | } |
| 6264 | |
| 6265 | // 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] | 6266 | byte[] sha256Bytes = sha256String == null |
| 6267 | ? null : HexEncoding.decode(sha256String, false /* allowSingleChar */); |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6268 | if (hasSha256Certificate(sha256Bytes, flags)) { |
| 6269 | return true; |
| 6270 | } |
| 6271 | |
| 6272 | // Not in signing history, either represents multiple signatures or not a match. |
| 6273 | // Multiple signers can't rotate, so no need to check flags, just see if the SHAs match. |
| 6274 | // We already check the single-signer case above as part of hasSha256Certificate, so no |
| 6275 | // need to verify we have multiple signers, just run the old check |
| 6276 | // just consider current signing certs |
| 6277 | final String[] mSignaturesSha256Digests = |
| 6278 | PackageUtils.computeSignaturesSha256Digests(signatures); |
| 6279 | final String mSignaturesSha256Digest = |
| 6280 | PackageUtils.computeSignaturesSha256Digest(mSignaturesSha256Digests); |
| 6281 | return mSignaturesSha256Digest.equals(sha256String); |
| 6282 | } |
| 6283 | |
| 6284 | /** |
| 6285 | * Determine if the {@code sha256Certificate} is in this SigningDetails' signing certificate |
| 6286 | * history, including the current signer. Automatically returns false if this object has |
| 6287 | * multiple signing certificates, since rotation is only supported for single-signers. |
| 6288 | */ |
| 6289 | public boolean hasSha256Certificate(byte[] sha256Certificate) { |
| 6290 | return hasSha256CertificateInternal(sha256Certificate, PAST_CERT_EXISTS); |
| 6291 | } |
| 6292 | |
| 6293 | /** |
| 6294 | * Determine if the {@code sha256Certificate} certificate hash corresponds to a signing |
| 6295 | * certificate in this SigningDetails' signing certificate history, including the current |
| 6296 | * signer, and whether or not it has the given permission. Certificates which match our |
| 6297 | * current signer automatically get all capabilities. Automatically returns false if this |
| 6298 | * object has multiple signing certificates, since rotation is only supported for |
| 6299 | * single-signers. |
| 6300 | */ |
| 6301 | public boolean hasSha256Certificate(byte[] sha256Certificate, @CertCapabilities int flags) { |
| 6302 | return hasSha256CertificateInternal(sha256Certificate, flags); |
| 6303 | } |
| 6304 | |
| 6305 | private boolean hasSha256CertificateInternal(byte[] sha256Certificate, int flags) { |
| 6306 | if (this == UNKNOWN) { |
| 6307 | return false; |
| 6308 | } |
| 6309 | if (hasPastSigningCertificates()) { |
| 6310 | |
| 6311 | // check all past certs, except for the last one, which automatically gets all |
| 6312 | // capabilities, since it is the same as the current signature, and is checked below |
| 6313 | for (int i = 0; i < pastSigningCertificates.length - 1; i++) { |
| 6314 | byte[] digest = PackageUtils.computeSha256DigestBytes( |
| 6315 | pastSigningCertificates[i].toByteArray()); |
| 6316 | if (Arrays.equals(sha256Certificate, digest)) { |
| 6317 | if (flags == PAST_CERT_EXISTS |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6318 | || (flags & pastSigningCertificates[i].getFlags()) == flags) { |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame] | 6319 | return true; |
| 6320 | } |
| 6321 | } |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | // not in previous certs signing history, just check the current signer |
| 6326 | if (signatures.length == 1) { |
| 6327 | byte[] digest = |
| 6328 | PackageUtils.computeSha256DigestBytes(signatures[0].toByteArray()); |
| 6329 | return Arrays.equals(sha256Certificate, digest); |
| 6330 | } |
| 6331 | return false; |
| 6332 | } |
| 6333 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6334 | /** Returns true if the signatures in this and other match exactly. */ |
| 6335 | public boolean signaturesMatchExactly(SigningDetails other) { |
| 6336 | return Signature.areExactMatch(this.signatures, other.signatures); |
| 6337 | } |
| 6338 | |
| 6339 | @Override |
| 6340 | public int describeContents() { |
| 6341 | return 0; |
| 6342 | } |
| 6343 | |
| 6344 | @Override |
| 6345 | public void writeToParcel(Parcel dest, int flags) { |
| 6346 | boolean isUnknown = UNKNOWN == this; |
| 6347 | dest.writeBoolean(isUnknown); |
| 6348 | if (isUnknown) { |
| 6349 | return; |
| 6350 | } |
| 6351 | dest.writeTypedArray(this.signatures, flags); |
| 6352 | dest.writeInt(this.signatureSchemeVersion); |
| 6353 | dest.writeArraySet(this.publicKeys); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6354 | dest.writeTypedArray(this.pastSigningCertificates, flags); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | protected SigningDetails(Parcel in) { |
| 6358 | final ClassLoader boot = Object.class.getClassLoader(); |
| 6359 | this.signatures = in.createTypedArray(Signature.CREATOR); |
| 6360 | this.signatureSchemeVersion = in.readInt(); |
| 6361 | this.publicKeys = (ArraySet<PublicKey>) in.readArraySet(boot); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6362 | this.pastSigningCertificates = in.createTypedArray(Signature.CREATOR); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 6365 | public static final @android.annotation.NonNull Creator<SigningDetails> CREATOR = new Creator<SigningDetails>() { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6366 | @Override |
| 6367 | public SigningDetails createFromParcel(Parcel source) { |
| 6368 | if (source.readBoolean()) { |
| 6369 | return UNKNOWN; |
| 6370 | } |
| 6371 | return new SigningDetails(source); |
| 6372 | } |
| 6373 | |
| 6374 | @Override |
| 6375 | public SigningDetails[] newArray(int size) { |
| 6376 | return new SigningDetails[size]; |
| 6377 | } |
| 6378 | }; |
| 6379 | |
| 6380 | @Override |
| 6381 | public boolean equals(Object o) { |
| 6382 | if (this == o) return true; |
| 6383 | if (!(o instanceof SigningDetails)) return false; |
| 6384 | |
| 6385 | SigningDetails that = (SigningDetails) o; |
| 6386 | |
| 6387 | if (signatureSchemeVersion != that.signatureSchemeVersion) return false; |
| 6388 | if (!Signature.areExactMatch(signatures, that.signatures)) return false; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6389 | if (publicKeys != null) { |
| 6390 | if (!publicKeys.equals((that.publicKeys))) { |
| 6391 | return false; |
| 6392 | } |
| 6393 | } else if (that.publicKeys != null) { |
| 6394 | return false; |
| 6395 | } |
| 6396 | |
| 6397 | // can't use Signature.areExactMatch() because order matters with the past signing certs |
| 6398 | if (!Arrays.equals(pastSigningCertificates, that.pastSigningCertificates)) { |
| 6399 | return false; |
| 6400 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6401 | |
| 6402 | return true; |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | @Override |
| 6406 | public int hashCode() { |
| 6407 | int result = +Arrays.hashCode(signatures); |
| 6408 | result = 31 * result + signatureSchemeVersion; |
| 6409 | result = 31 * result + (publicKeys != null ? publicKeys.hashCode() : 0); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6410 | result = 31 * result + Arrays.hashCode(pastSigningCertificates); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6411 | return result; |
| 6412 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6413 | |
| 6414 | /** |
| 6415 | * Builder of {@code SigningDetails} instances. |
| 6416 | */ |
| 6417 | public static class Builder { |
| 6418 | private Signature[] mSignatures; |
| 6419 | private int mSignatureSchemeVersion = SignatureSchemeVersion.UNKNOWN; |
| 6420 | private Signature[] mPastSigningCertificates; |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6421 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6422 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6423 | public Builder() { |
| 6424 | } |
| 6425 | |
| 6426 | /** get signing certificates used to sign the current APK */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6427 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6428 | public Builder setSignatures(Signature[] signatures) { |
| 6429 | mSignatures = signatures; |
| 6430 | return this; |
| 6431 | } |
| 6432 | |
| 6433 | /** set the signature scheme version used to sign the APK */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6434 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6435 | public Builder setSignatureSchemeVersion(int signatureSchemeVersion) { |
| 6436 | mSignatureSchemeVersion = signatureSchemeVersion; |
| 6437 | return this; |
| 6438 | } |
| 6439 | |
| 6440 | /** 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] | 6441 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6442 | public Builder setPastSigningCertificates(Signature[] pastSigningCertificates) { |
| 6443 | mPastSigningCertificates = pastSigningCertificates; |
| 6444 | return this; |
| 6445 | } |
| 6446 | |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6447 | private void checkInvariants() { |
| 6448 | // must have signatures and scheme version set |
| 6449 | if (mSignatures == null) { |
| 6450 | throw new IllegalStateException("SigningDetails requires the current signing" |
| 6451 | + " certificates."); |
| 6452 | } |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6453 | } |
| 6454 | /** build a {@code SigningDetails} object */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6455 | @UnsupportedAppUsage |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6456 | public SigningDetails build() |
| 6457 | throws CertificateException { |
| 6458 | checkInvariants(); |
| 6459 | return new SigningDetails(mSignatures, mSignatureSchemeVersion, |
Michael Groover | a117b0d | 2018-07-23 12:55:54 -0700 | [diff] [blame] | 6460 | mPastSigningCertificates); |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 6461 | } |
| 6462 | } |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6463 | } |
| 6464 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6465 | /** |
| 6466 | * Representation of a full package parsed from APK files on disk. A package |
| 6467 | * consists of a single base APK, and zero or more split APKs. |
| 6468 | */ |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6469 | public final static class Package implements Parcelable { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6470 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6471 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6472 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6473 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6474 | // The package name declared in the manifest as the package can be |
| 6475 | // renamed, for example static shared libs use synthetic package names. |
| 6476 | public String manifestPackageName; |
| 6477 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6478 | /** Names of any split APKs, ordered by parsed splitName */ |
| 6479 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6480 | |
| 6481 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6482 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 6483 | public String volumeUuid; |
| 6484 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6485 | /** |
| 6486 | * Path where this package was found on disk. For monolithic packages |
| 6487 | * this is path to single base APK file; for cluster packages this is |
| 6488 | * path to the cluster directory. |
| 6489 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6490 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6491 | |
| 6492 | /** Path of base APK */ |
| 6493 | public String baseCodePath; |
| 6494 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6495 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6497 | /** Revision code of base APK */ |
| 6498 | public int baseRevisionCode; |
| 6499 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 6500 | public int[] splitRevisionCodes; |
| 6501 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6502 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 6503 | public int[] splitFlags; |
| 6504 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 6505 | /** |
| 6506 | * Private flags of any split APKs; ordered by parsed splitName. |
| 6507 | * |
| 6508 | * {@hide} |
| 6509 | */ |
| 6510 | public int[] splitPrivateFlags; |
| 6511 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6512 | public boolean baseHardwareAccelerated; |
| 6513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6514 | // For now we only support one application per package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6515 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 6516 | public ApplicationInfo applicationInfo = new ApplicationInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6518 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6520 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6522 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6524 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6526 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6528 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6530 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 6532 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6533 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6534 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 6535 | |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 6536 | /** Permissions requested but not in the manifest. */ |
| 6537 | public final ArrayList<String> implicitPermissions = new ArrayList<>(); |
| 6538 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6539 | @UnsupportedAppUsage |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 6540 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6541 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6542 | public Package parentPackage; |
| 6543 | public ArrayList<Package> childPackages; |
| 6544 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6545 | public String staticSharedLibName = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6546 | public long staticSharedLibVersion = 0; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 6547 | public ArrayList<String> libraryNames = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6548 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6549 | public ArrayList<String> usesLibraries = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6550 | public ArrayList<String> usesStaticLibraries = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6551 | public long[] usesStaticLibrariesVersions = null; |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 6552 | public String[][] usesStaticLibrariesCertDigests = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6553 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6554 | public ArrayList<String> usesOptionalLibraries = null; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6555 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6556 | public String[] usesLibraryFiles = null; |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 6557 | public ArrayList<SharedLibraryInfo> usesLibraryInfos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 6559 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 6560 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 6561 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6562 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 6563 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6565 | // We store the application meta-data independently to avoid multiple unwanted references |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6566 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6567 | public Bundle mAppMetaData = null; |
| 6568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6569 | // The version code declared for this package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6570 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6571 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 6572 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 6573 | // The major version code declared for this package. |
| 6574 | public int mVersionCodeMajor; |
| 6575 | |
| 6576 | // Return long containing mVersionCode and mVersionCodeMajor. |
| 6577 | public long getLongVersionCode() { |
| 6578 | return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); |
| 6579 | } |
| 6580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6581 | // The version name declared for this package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6582 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6583 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 6584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | // The shared user id that this package wants to use. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6586 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6587 | public String mSharedUserId; |
| 6588 | |
| 6589 | // The shared user label that this package wants to use. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6590 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | public int mSharedUserLabel; |
| 6592 | |
| 6593 | // Signatures that were read from the package. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6594 | @UnsupportedAppUsage |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6595 | @NonNull public SigningDetails mSigningDetails = SigningDetails.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6596 | |
| 6597 | // For use by package manager service for quick lookup of |
| 6598 | // preferred up order. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6599 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | public int mPreferredOrder = 0; |
| 6601 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6602 | // 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] | 6603 | public long[] mLastPackageUsageTimeInMills = |
| 6604 | new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 6605 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 6606 | // // User set enabled state. |
| 6607 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 6608 | // |
| 6609 | // // Whether the package has been stopped. |
| 6610 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 6611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | // Additional data supplied by callers. |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6613 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 6615 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6616 | // Applications hardware preferences |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6617 | @UnsupportedAppUsage |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6618 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6620 | // Applications requested features |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6621 | @UnsupportedAppUsage |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 6622 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 6623 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 6624 | // Applications requested feature groups |
| 6625 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 6626 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6627 | @UnsupportedAppUsage |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 6628 | public int installLocation; |
| 6629 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 6630 | public boolean coreApp; |
| 6631 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 6632 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 6633 | public boolean mRequiredForAllUsers; |
| 6634 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 6635 | /* The restricted account authenticator type that is used by this application */ |
| 6636 | public String mRestrictedAccountType; |
| 6637 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 6638 | /* The required account type without which this application will not function */ |
| 6639 | public String mRequiredAccountType; |
| 6640 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6641 | public String mOverlayTarget; |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 6642 | public String mOverlayTargetName; |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 6643 | public String mOverlayCategory; |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 6644 | public int mOverlayPriority; |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 6645 | public boolean mOverlayIsStatic; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 6646 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 6647 | public int mCompileSdkVersion; |
| 6648 | public String mCompileSdkVersionCodename; |
| 6649 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6650 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6651 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6652 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6653 | @UnsupportedAppUsage |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6654 | public ArraySet<String> mUpgradeKeySets; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6655 | @UnsupportedAppUsage |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 6656 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 6657 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6658 | /** |
| 6659 | * The install time abi override for this package, if any. |
| 6660 | * |
| 6661 | * TODO: This seems like a horrible place to put the abiOverride because |
| 6662 | * this isn't something the packageParser parsers. However, this fits in with |
| 6663 | * the rest of the PackageManager where package scanning randomly pushes |
| 6664 | * and prods fields out of {@code this.applicationInfo}. |
| 6665 | */ |
| 6666 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6667 | /** |
| 6668 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 6669 | * are present. This is only meaningfull for multiarch applications. |
| 6670 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 6671 | */ |
| 6672 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 6673 | |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 6674 | public byte[] restrictUpdateHash; |
| 6675 | |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6676 | /** 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] | 6677 | public boolean visibleToInstantApps; |
Todd Kennedy | 7c8addf | 2017-06-27 14:13:55 -0700 | [diff] [blame] | 6678 | /** Whether or not the package is a stub and must be replaced by the full version. */ |
| 6679 | public boolean isStub; |
Chad Brubaker | 06ca1e0 | 2017-03-16 17:56:25 -0700 | [diff] [blame] | 6680 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6681 | @UnsupportedAppUsage |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 6682 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6683 | this.packageName = packageName; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 6684 | this.manifestPackageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 6685 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | applicationInfo.uid = -1; |
| 6687 | } |
| 6688 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6689 | public void setApplicationVolumeUuid(String volumeUuid) { |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6690 | final UUID storageUuid = StorageManager.convert(volumeUuid); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6691 | this.applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6692 | this.applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6693 | if (childPackages != null) { |
| 6694 | final int packageCount = childPackages.size(); |
| 6695 | for (int i = 0; i < packageCount; i++) { |
| 6696 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 6697 | childPackages.get(i).applicationInfo.storageUuid = storageUuid; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6698 | } |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | public void setApplicationInfoCodePath(String codePath) { |
| 6703 | this.applicationInfo.setCodePath(codePath); |
| 6704 | if (childPackages != null) { |
| 6705 | final int packageCount = childPackages.size(); |
| 6706 | for (int i = 0; i < packageCount; i++) { |
| 6707 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 6708 | } |
| 6709 | } |
| 6710 | } |
| 6711 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6712 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6713 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6714 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 6715 | this.applicationInfo.setResourcePath(resourcePath); |
| 6716 | if (childPackages != null) { |
| 6717 | final int packageCount = childPackages.size(); |
| 6718 | for (int i = 0; i < packageCount; i++) { |
| 6719 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 6720 | } |
| 6721 | } |
| 6722 | } |
| 6723 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6724 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6725 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6726 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 6727 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 6728 | if (childPackages != null) { |
| 6729 | final int packageCount = childPackages.size(); |
| 6730 | for (int i = 0; i < packageCount; i++) { |
| 6731 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 6732 | } |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 6737 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 6738 | if (childPackages != null) { |
| 6739 | final int packageCount = childPackages.size(); |
| 6740 | for (int i = 0; i < packageCount; i++) { |
| 6741 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 6742 | } |
| 6743 | } |
| 6744 | } |
| 6745 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 6746 | public List<String> getChildPackageNames() { |
| 6747 | if (childPackages == null) { |
| 6748 | return null; |
| 6749 | } |
| 6750 | final int childCount = childPackages.size(); |
| 6751 | final List<String> childPackageNames = new ArrayList<>(childCount); |
| 6752 | for (int i = 0; i < childCount; i++) { |
| 6753 | String childPackageName = childPackages.get(i).packageName; |
| 6754 | childPackageNames.add(childPackageName); |
| 6755 | } |
| 6756 | return childPackageNames; |
| 6757 | } |
| 6758 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6759 | public boolean hasChildPackage(String packageName) { |
| 6760 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 6761 | for (int i = 0; i < childCount; i++) { |
| 6762 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 6763 | return true; |
| 6764 | } |
| 6765 | } |
| 6766 | return false; |
| 6767 | } |
| 6768 | |
| 6769 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 6770 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 6771 | // Children have no splits |
| 6772 | } |
| 6773 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 6774 | /** @deprecated Forward locked apps no longer supported. Resource path not needed. */ |
| 6775 | @Deprecated |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6776 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 6777 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 6778 | // Children have no splits |
| 6779 | } |
| 6780 | |
| 6781 | public void setSplitCodePaths(String[] codePaths) { |
| 6782 | this.splitCodePaths = codePaths; |
| 6783 | } |
| 6784 | |
| 6785 | public void setCodePath(String codePath) { |
| 6786 | this.codePath = codePath; |
| 6787 | if (childPackages != null) { |
| 6788 | final int packageCount = childPackages.size(); |
| 6789 | for (int i = 0; i < packageCount; i++) { |
| 6790 | childPackages.get(i).codePath = codePath; |
| 6791 | } |
| 6792 | } |
| 6793 | } |
| 6794 | |
| 6795 | public void setBaseCodePath(String baseCodePath) { |
| 6796 | this.baseCodePath = baseCodePath; |
| 6797 | if (childPackages != null) { |
| 6798 | final int packageCount = childPackages.size(); |
| 6799 | for (int i = 0; i < packageCount; i++) { |
| 6800 | childPackages.get(i).baseCodePath = baseCodePath; |
| 6801 | } |
| 6802 | } |
| 6803 | } |
| 6804 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6805 | /** Sets signing details on the package and any of its children. */ |
| 6806 | public void setSigningDetails(@NonNull SigningDetails signingDetails) { |
| 6807 | mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6808 | if (childPackages != null) { |
| 6809 | final int packageCount = childPackages.size(); |
| 6810 | for (int i = 0; i < packageCount; i++) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 6811 | childPackages.get(i).mSigningDetails = signingDetails; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6812 | } |
| 6813 | } |
| 6814 | } |
| 6815 | |
| 6816 | public void setVolumeUuid(String volumeUuid) { |
| 6817 | this.volumeUuid = volumeUuid; |
| 6818 | if (childPackages != null) { |
| 6819 | final int packageCount = childPackages.size(); |
| 6820 | for (int i = 0; i < packageCount; i++) { |
| 6821 | childPackages.get(i).volumeUuid = volumeUuid; |
| 6822 | } |
| 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | public void setApplicationInfoFlags(int mask, int flags) { |
| 6827 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 6828 | if (childPackages != null) { |
| 6829 | final int packageCount = childPackages.size(); |
| 6830 | for (int i = 0; i < packageCount; i++) { |
| 6831 | childPackages.get(i).applicationInfo.flags = |
| 6832 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 6833 | } |
| 6834 | } |
| 6835 | } |
| 6836 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 6837 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6838 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6839 | if (childPackages != null) { |
| 6840 | final int packageCount = childPackages.size(); |
| 6841 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 6842 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 6843 | } |
| 6844 | } |
| 6845 | } |
| 6846 | |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 6847 | public boolean isLibrary() { |
| 6848 | return staticSharedLibName != null || !ArrayUtils.isEmpty(libraryNames); |
| 6849 | } |
| 6850 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6851 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6852 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 6853 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 6854 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6855 | Collections.addAll(paths, splitCodePaths); |
| 6856 | } |
| 6857 | return paths; |
| 6858 | } |
| 6859 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 6860 | /** |
| 6861 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 6862 | * resource-only APKs. |
| 6863 | */ |
| 6864 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 6865 | ArrayList<String> paths = new ArrayList<>(); |
| 6866 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6867 | paths.add(baseCodePath); |
| 6868 | } |
| 6869 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 6870 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 6871 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 6872 | paths.add(splitCodePaths[i]); |
| 6873 | } |
| 6874 | } |
| 6875 | } |
| 6876 | return paths; |
| 6877 | } |
| 6878 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 6879 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6880 | public void setPackageName(String newName) { |
| 6881 | packageName = newName; |
| 6882 | applicationInfo.packageName = newName; |
| 6883 | for (int i=permissions.size()-1; i>=0; i--) { |
| 6884 | permissions.get(i).setPackageName(newName); |
| 6885 | } |
| 6886 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 6887 | permissionGroups.get(i).setPackageName(newName); |
| 6888 | } |
| 6889 | for (int i=activities.size()-1; i>=0; i--) { |
| 6890 | activities.get(i).setPackageName(newName); |
| 6891 | } |
| 6892 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6893 | receivers.get(i).setPackageName(newName); |
| 6894 | } |
| 6895 | for (int i=providers.size()-1; i>=0; i--) { |
| 6896 | providers.get(i).setPackageName(newName); |
| 6897 | } |
| 6898 | for (int i=services.size()-1; i>=0; i--) { |
| 6899 | services.get(i).setPackageName(newName); |
| 6900 | } |
| 6901 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6902 | instrumentation.get(i).setPackageName(newName); |
| 6903 | } |
| 6904 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 6905 | |
| 6906 | public boolean hasComponentClassName(String name) { |
| 6907 | for (int i=activities.size()-1; i>=0; i--) { |
| 6908 | if (name.equals(activities.get(i).className)) { |
| 6909 | return true; |
| 6910 | } |
| 6911 | } |
| 6912 | for (int i=receivers.size()-1; i>=0; i--) { |
| 6913 | if (name.equals(receivers.get(i).className)) { |
| 6914 | return true; |
| 6915 | } |
| 6916 | } |
| 6917 | for (int i=providers.size()-1; i>=0; i--) { |
| 6918 | if (name.equals(providers.get(i).className)) { |
| 6919 | return true; |
| 6920 | } |
| 6921 | } |
| 6922 | for (int i=services.size()-1; i>=0; i--) { |
| 6923 | if (name.equals(services.get(i).className)) { |
| 6924 | return true; |
| 6925 | } |
| 6926 | } |
| 6927 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 6928 | if (name.equals(instrumentation.get(i).className)) { |
| 6929 | return true; |
| 6930 | } |
| 6931 | } |
| 6932 | return false; |
| 6933 | } |
| 6934 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6935 | /** @hide */ |
| 6936 | public boolean isExternal() { |
| 6937 | return applicationInfo.isExternal(); |
| 6938 | } |
| 6939 | |
| 6940 | /** @hide */ |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6941 | public boolean isForwardLocked() { |
Patrick Baumann | fc2851e | 2018-11-13 15:23:22 -0800 | [diff] [blame] | 6942 | return false; |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 6943 | } |
| 6944 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6945 | /** @hide */ |
| 6946 | public boolean isOem() { |
| 6947 | return applicationInfo.isOem(); |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6948 | } |
| 6949 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6950 | /** @hide */ |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 6951 | public boolean isVendor() { |
| 6952 | return applicationInfo.isVendor(); |
| 6953 | } |
| 6954 | |
| 6955 | /** @hide */ |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 6956 | public boolean isProduct() { |
| 6957 | return applicationInfo.isProduct(); |
| 6958 | } |
| 6959 | |
| 6960 | /** @hide */ |
Jeongik Cha | f662983 | 2019-07-04 21:12:06 +0900 | [diff] [blame] | 6961 | public boolean isSystemExt() { |
| 6962 | return applicationInfo.isSystemExt(); |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | /** @hide */ |
MÃ¥rten Kongstad | 48c24cf | 2019-02-25 10:54:09 +0100 | [diff] [blame] | 6966 | public boolean isOdm() { |
| 6967 | return applicationInfo.isOdm(); |
| 6968 | } |
| 6969 | |
| 6970 | /** @hide */ |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6971 | public boolean isPrivileged() { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 6972 | return applicationInfo.isPrivilegedApp(); |
| 6973 | } |
| 6974 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6975 | /** @hide */ |
| 6976 | public boolean isSystem() { |
| 6977 | return applicationInfo.isSystemApp(); |
| 6978 | } |
| 6979 | |
| 6980 | /** @hide */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 6981 | public boolean isUpdatedSystemApp() { |
| 6982 | return applicationInfo.isUpdatedSystemApp(); |
| 6983 | } |
| 6984 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6985 | /** @hide */ |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6986 | public boolean canHaveOatDir() { |
| 6987 | // The following app types CANNOT have oat directory |
| 6988 | // - non-updated system apps |
Patrick Baumann | fc2851e | 2018-11-13 15:23:22 -0800 | [diff] [blame] | 6989 | return !isSystem() || isUpdatedSystemApp(); |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6992 | public boolean isMatch(int flags) { |
| 6993 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 6994 | return isSystem(); |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 6995 | } |
| 6996 | return true; |
| 6997 | } |
| 6998 | |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 6999 | public long getLatestPackageUseTimeInMills() { |
| 7000 | long latestUse = 0L; |
| 7001 | for (long use : mLastPackageUsageTimeInMills) { |
| 7002 | latestUse = Math.max(latestUse, use); |
| 7003 | } |
| 7004 | return latestUse; |
| 7005 | } |
| 7006 | |
David Brazdil | 90e2699 | 2016-04-18 14:08:52 +0100 | [diff] [blame] | 7007 | public long getLatestForegroundPackageUseTimeInMills() { |
| 7008 | int[] foregroundReasons = { |
| 7009 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, |
| 7010 | PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE |
| 7011 | }; |
| 7012 | |
| 7013 | long latestUse = 0L; |
| 7014 | for (int reason : foregroundReasons) { |
| 7015 | latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); |
| 7016 | } |
| 7017 | return latestUse; |
| 7018 | } |
| 7019 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | public String toString() { |
| 7021 | return "Package{" |
| 7022 | + Integer.toHexString(System.identityHashCode(this)) |
| 7023 | + " " + packageName + "}"; |
| 7024 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7025 | |
| 7026 | @Override |
| 7027 | public int describeContents() { |
| 7028 | return 0; |
| 7029 | } |
| 7030 | |
| 7031 | public Package(Parcel dest) { |
| 7032 | // We use the boot classloader for all classes that we load. |
| 7033 | final ClassLoader boot = Object.class.getClassLoader(); |
| 7034 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7035 | packageName = dest.readString().intern(); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7036 | manifestPackageName = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7037 | splitNames = dest.readStringArray(); |
| 7038 | volumeUuid = dest.readString(); |
| 7039 | codePath = dest.readString(); |
| 7040 | baseCodePath = dest.readString(); |
| 7041 | splitCodePaths = dest.readStringArray(); |
| 7042 | baseRevisionCode = dest.readInt(); |
| 7043 | splitRevisionCodes = dest.createIntArray(); |
| 7044 | splitFlags = dest.createIntArray(); |
| 7045 | splitPrivateFlags = dest.createIntArray(); |
| 7046 | baseHardwareAccelerated = (dest.readInt() == 1); |
| 7047 | applicationInfo = dest.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7048 | if (applicationInfo.permission != null) { |
| 7049 | applicationInfo.permission = applicationInfo.permission.intern(); |
| 7050 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7051 | |
| 7052 | // We don't serialize the "owner" package and the application info object for each of |
| 7053 | // these components, in order to save space and to avoid circular dependencies while |
| 7054 | // serialization. We need to fix them all up here. |
| 7055 | dest.readParcelableList(permissions, boot); |
| 7056 | fixupOwner(permissions); |
| 7057 | dest.readParcelableList(permissionGroups, boot); |
| 7058 | fixupOwner(permissionGroups); |
| 7059 | dest.readParcelableList(activities, boot); |
| 7060 | fixupOwner(activities); |
| 7061 | dest.readParcelableList(receivers, boot); |
| 7062 | fixupOwner(receivers); |
| 7063 | dest.readParcelableList(providers, boot); |
| 7064 | fixupOwner(providers); |
| 7065 | dest.readParcelableList(services, boot); |
| 7066 | fixupOwner(services); |
| 7067 | dest.readParcelableList(instrumentation, boot); |
| 7068 | fixupOwner(instrumentation); |
| 7069 | |
| 7070 | dest.readStringList(requestedPermissions); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7071 | internStringArrayList(requestedPermissions); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 7072 | dest.readStringList(implicitPermissions); |
| 7073 | internStringArrayList(implicitPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7074 | protectedBroadcasts = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7075 | internStringArrayList(protectedBroadcasts); |
| 7076 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7077 | parentPackage = dest.readParcelable(boot); |
| 7078 | |
| 7079 | childPackages = new ArrayList<>(); |
| 7080 | dest.readParcelableList(childPackages, boot); |
| 7081 | if (childPackages.size() == 0) { |
| 7082 | childPackages = null; |
| 7083 | } |
| 7084 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7085 | staticSharedLibName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7086 | if (staticSharedLibName != null) { |
| 7087 | staticSharedLibName = staticSharedLibName.intern(); |
| 7088 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7089 | staticSharedLibVersion = dest.readLong(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7090 | libraryNames = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7091 | internStringArrayList(libraryNames); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7092 | usesLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7093 | internStringArrayList(usesLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7094 | usesOptionalLibraries = dest.createStringArrayList(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7095 | internStringArrayList(usesOptionalLibraries); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7096 | usesLibraryFiles = dest.readStringArray(); |
| 7097 | |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7098 | usesLibraryInfos = dest.createTypedArrayList(SharedLibraryInfo.CREATOR); |
| 7099 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7100 | final int libCount = dest.readInt(); |
| 7101 | if (libCount > 0) { |
| 7102 | usesStaticLibraries = new ArrayList<>(libCount); |
| 7103 | dest.readStringList(usesStaticLibraries); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7104 | internStringArrayList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7105 | usesStaticLibrariesVersions = new long[libCount]; |
| 7106 | dest.readLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 7107 | usesStaticLibrariesCertDigests = new String[libCount][]; |
| 7108 | for (int i = 0; i < libCount; i++) { |
| 7109 | usesStaticLibrariesCertDigests[i] = dest.createStringArray(); |
| 7110 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7111 | } |
| 7112 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7113 | preferredActivityFilters = new ArrayList<>(); |
| 7114 | dest.readParcelableList(preferredActivityFilters, boot); |
| 7115 | if (preferredActivityFilters.size() == 0) { |
| 7116 | preferredActivityFilters = null; |
| 7117 | } |
| 7118 | |
| 7119 | mOriginalPackages = dest.createStringArrayList(); |
| 7120 | mRealPackage = dest.readString(); |
| 7121 | mAdoptPermissions = dest.createStringArrayList(); |
| 7122 | mAppMetaData = dest.readBundle(); |
| 7123 | mVersionCode = dest.readInt(); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 7124 | mVersionCodeMajor = dest.readInt(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7125 | mVersionName = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7126 | if (mVersionName != null) { |
| 7127 | mVersionName = mVersionName.intern(); |
| 7128 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7129 | mSharedUserId = dest.readString(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7130 | if (mSharedUserId != null) { |
| 7131 | mSharedUserId = mSharedUserId.intern(); |
| 7132 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7133 | mSharedUserLabel = dest.readInt(); |
| 7134 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 7135 | mSigningDetails = dest.readParcelable(boot); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7136 | |
| 7137 | mPreferredOrder = dest.readInt(); |
| 7138 | |
| 7139 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 7140 | // is parsed from the APK. |
| 7141 | |
| 7142 | // Object mExtras is not persisted because it is not information that is read from |
| 7143 | // the APK, rather, it is supplied by callers. |
| 7144 | |
| 7145 | |
| 7146 | configPreferences = new ArrayList<>(); |
| 7147 | dest.readParcelableList(configPreferences, boot); |
| 7148 | if (configPreferences.size() == 0) { |
| 7149 | configPreferences = null; |
| 7150 | } |
| 7151 | |
| 7152 | reqFeatures = new ArrayList<>(); |
| 7153 | dest.readParcelableList(reqFeatures, boot); |
| 7154 | if (reqFeatures.size() == 0) { |
| 7155 | reqFeatures = null; |
| 7156 | } |
| 7157 | |
| 7158 | featureGroups = new ArrayList<>(); |
| 7159 | dest.readParcelableList(featureGroups, boot); |
| 7160 | if (featureGroups.size() == 0) { |
| 7161 | featureGroups = null; |
| 7162 | } |
| 7163 | |
| 7164 | installLocation = dest.readInt(); |
| 7165 | coreApp = (dest.readInt() == 1); |
| 7166 | mRequiredForAllUsers = (dest.readInt() == 1); |
| 7167 | mRestrictedAccountType = dest.readString(); |
| 7168 | mRequiredAccountType = dest.readString(); |
| 7169 | mOverlayTarget = dest.readString(); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 7170 | mOverlayTargetName = dest.readString(); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 7171 | mOverlayCategory = dest.readString(); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 7172 | mOverlayPriority = dest.readInt(); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 7173 | mOverlayIsStatic = (dest.readInt() == 1); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 7174 | mCompileSdkVersion = dest.readInt(); |
| 7175 | mCompileSdkVersionCodename = dest.readString(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7176 | mUpgradeKeySets = (ArraySet<String>) dest.readArraySet(boot); |
| 7177 | |
| 7178 | mKeySetMapping = readKeySetMapping(dest); |
| 7179 | |
| 7180 | cpuAbiOverride = dest.readString(); |
| 7181 | use32bitAbi = (dest.readInt() == 1); |
| 7182 | restrictUpdateHash = dest.createByteArray(); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 7183 | visibleToInstantApps = dest.readInt() == 1; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7186 | private static void internStringArrayList(List<String> list) { |
| 7187 | if (list != null) { |
| 7188 | final int N = list.size(); |
| 7189 | for (int i = 0; i < N; ++i) { |
| 7190 | list.set(i, list.get(i).intern()); |
| 7191 | } |
| 7192 | } |
| 7193 | } |
| 7194 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7195 | /** |
| 7196 | * Sets the package owner and the the {@code applicationInfo} for every component |
| 7197 | * owner by this package. |
| 7198 | */ |
| 7199 | private void fixupOwner(List<? extends Component<?>> list) { |
| 7200 | if (list != null) { |
| 7201 | for (Component<?> c : list) { |
| 7202 | c.owner = this; |
| 7203 | if (c instanceof Activity) { |
| 7204 | ((Activity) c).info.applicationInfo = this.applicationInfo; |
| 7205 | } else if (c instanceof Service) { |
| 7206 | ((Service) c).info.applicationInfo = this.applicationInfo; |
| 7207 | } else if (c instanceof Provider) { |
| 7208 | ((Provider) c).info.applicationInfo = this.applicationInfo; |
| 7209 | } |
| 7210 | } |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | @Override |
| 7215 | public void writeToParcel(Parcel dest, int flags) { |
| 7216 | dest.writeString(packageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7217 | dest.writeString(manifestPackageName); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7218 | dest.writeStringArray(splitNames); |
| 7219 | dest.writeString(volumeUuid); |
| 7220 | dest.writeString(codePath); |
| 7221 | dest.writeString(baseCodePath); |
| 7222 | dest.writeStringArray(splitCodePaths); |
| 7223 | dest.writeInt(baseRevisionCode); |
| 7224 | dest.writeIntArray(splitRevisionCodes); |
| 7225 | dest.writeIntArray(splitFlags); |
| 7226 | dest.writeIntArray(splitPrivateFlags); |
| 7227 | dest.writeInt(baseHardwareAccelerated ? 1 : 0); |
| 7228 | dest.writeParcelable(applicationInfo, flags); |
| 7229 | |
| 7230 | dest.writeParcelableList(permissions, flags); |
| 7231 | dest.writeParcelableList(permissionGroups, flags); |
| 7232 | dest.writeParcelableList(activities, flags); |
| 7233 | dest.writeParcelableList(receivers, flags); |
| 7234 | dest.writeParcelableList(providers, flags); |
| 7235 | dest.writeParcelableList(services, flags); |
| 7236 | dest.writeParcelableList(instrumentation, flags); |
| 7237 | |
| 7238 | dest.writeStringList(requestedPermissions); |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 7239 | dest.writeStringList(implicitPermissions); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7240 | dest.writeStringList(protectedBroadcasts); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 7241 | |
| 7242 | // TODO: This doesn't work: b/64295061 |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7243 | dest.writeParcelable(parentPackage, flags); |
| 7244 | dest.writeParcelableList(childPackages, flags); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 7245 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7246 | dest.writeString(staticSharedLibName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7247 | dest.writeLong(staticSharedLibVersion); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7248 | dest.writeStringList(libraryNames); |
| 7249 | dest.writeStringList(usesLibraries); |
| 7250 | dest.writeStringList(usesOptionalLibraries); |
| 7251 | dest.writeStringArray(usesLibraryFiles); |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7252 | dest.writeTypedList(usesLibraryInfos); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7253 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7254 | if (ArrayUtils.isEmpty(usesStaticLibraries)) { |
| 7255 | dest.writeInt(-1); |
| 7256 | } else { |
| 7257 | dest.writeInt(usesStaticLibraries.size()); |
| 7258 | dest.writeStringList(usesStaticLibraries); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 7259 | dest.writeLongArray(usesStaticLibrariesVersions); |
Svetoslav Ganov | cdd685c | 2017-08-22 14:35:04 -0700 | [diff] [blame] | 7260 | for (String[] usesStaticLibrariesCertDigest : usesStaticLibrariesCertDigests) { |
| 7261 | dest.writeStringArray(usesStaticLibrariesCertDigest); |
| 7262 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7263 | } |
| 7264 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7265 | dest.writeParcelableList(preferredActivityFilters, flags); |
| 7266 | |
| 7267 | dest.writeStringList(mOriginalPackages); |
| 7268 | dest.writeString(mRealPackage); |
| 7269 | dest.writeStringList(mAdoptPermissions); |
| 7270 | dest.writeBundle(mAppMetaData); |
| 7271 | dest.writeInt(mVersionCode); |
Todd Kennedy | 5b1df2f | 2017-12-11 13:26:14 -0800 | [diff] [blame] | 7272 | dest.writeInt(mVersionCodeMajor); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7273 | dest.writeString(mVersionName); |
| 7274 | dest.writeString(mSharedUserId); |
| 7275 | dest.writeInt(mSharedUserLabel); |
| 7276 | |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 7277 | dest.writeParcelable(mSigningDetails, flags); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7278 | |
| 7279 | dest.writeInt(mPreferredOrder); |
| 7280 | |
| 7281 | // long[] packageUsageTimeMillis is not persisted because it isn't information that |
| 7282 | // is parsed from the APK. |
| 7283 | |
| 7284 | // Object mExtras is not persisted because it is not information that is read from |
| 7285 | // the APK, rather, it is supplied by callers. |
| 7286 | |
| 7287 | dest.writeParcelableList(configPreferences, flags); |
| 7288 | dest.writeParcelableList(reqFeatures, flags); |
| 7289 | dest.writeParcelableList(featureGroups, flags); |
| 7290 | |
| 7291 | dest.writeInt(installLocation); |
| 7292 | dest.writeInt(coreApp ? 1 : 0); |
| 7293 | dest.writeInt(mRequiredForAllUsers ? 1 : 0); |
| 7294 | dest.writeString(mRestrictedAccountType); |
| 7295 | dest.writeString(mRequiredAccountType); |
| 7296 | dest.writeString(mOverlayTarget); |
Ryan Mitchell | a362846 | 2019-01-14 12:19:40 -0800 | [diff] [blame] | 7297 | dest.writeString(mOverlayTargetName); |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 7298 | dest.writeString(mOverlayCategory); |
Jaekyun Seok | 42d53f6 | 2017-04-10 13:48:58 +0900 | [diff] [blame] | 7299 | dest.writeInt(mOverlayPriority); |
Adam Lesinski | e733497 | 2018-01-17 16:13:52 -0800 | [diff] [blame] | 7300 | dest.writeInt(mOverlayIsStatic ? 1 : 0); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 7301 | dest.writeInt(mCompileSdkVersion); |
| 7302 | dest.writeString(mCompileSdkVersionCodename); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7303 | dest.writeArraySet(mUpgradeKeySets); |
| 7304 | writeKeySetMapping(dest, mKeySetMapping); |
| 7305 | dest.writeString(cpuAbiOverride); |
| 7306 | dest.writeInt(use32bitAbi ? 1 : 0); |
| 7307 | dest.writeByteArray(restrictUpdateHash); |
Chad Brubaker | 49f24c6 | 2017-04-05 13:08:21 -0700 | [diff] [blame] | 7308 | dest.writeInt(visibleToInstantApps ? 1 : 0); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7309 | } |
| 7310 | |
| 7311 | |
| 7312 | /** |
| 7313 | * Writes the keyset mapping to the provided package. {@code null} mappings are permitted. |
| 7314 | */ |
| 7315 | private static void writeKeySetMapping( |
| 7316 | Parcel dest, ArrayMap<String, ArraySet<PublicKey>> keySetMapping) { |
| 7317 | if (keySetMapping == null) { |
| 7318 | dest.writeInt(-1); |
| 7319 | return; |
| 7320 | } |
| 7321 | |
| 7322 | final int N = keySetMapping.size(); |
| 7323 | dest.writeInt(N); |
| 7324 | |
| 7325 | for (int i = 0; i < N; i++) { |
| 7326 | dest.writeString(keySetMapping.keyAt(i)); |
| 7327 | ArraySet<PublicKey> keys = keySetMapping.valueAt(i); |
| 7328 | if (keys == null) { |
| 7329 | dest.writeInt(-1); |
| 7330 | continue; |
| 7331 | } |
| 7332 | |
| 7333 | final int M = keys.size(); |
| 7334 | dest.writeInt(M); |
| 7335 | for (int j = 0; j < M; j++) { |
| 7336 | dest.writeSerializable(keys.valueAt(j)); |
| 7337 | } |
| 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | /** |
| 7342 | * Reads a keyset mapping from the given parcel at the given data position. May return |
| 7343 | * {@code null} if the serialized mapping was {@code null}. |
| 7344 | */ |
| 7345 | private static ArrayMap<String, ArraySet<PublicKey>> readKeySetMapping(Parcel in) { |
| 7346 | final int N = in.readInt(); |
| 7347 | if (N == -1) { |
| 7348 | return null; |
| 7349 | } |
| 7350 | |
| 7351 | ArrayMap<String, ArraySet<PublicKey>> keySetMapping = new ArrayMap<>(); |
| 7352 | for (int i = 0; i < N; ++i) { |
| 7353 | String key = in.readString(); |
| 7354 | final int M = in.readInt(); |
| 7355 | if (M == -1) { |
| 7356 | keySetMapping.put(key, null); |
| 7357 | continue; |
| 7358 | } |
| 7359 | |
| 7360 | ArraySet<PublicKey> keys = new ArraySet<>(M); |
| 7361 | for (int j = 0; j < M; ++j) { |
| 7362 | PublicKey pk = (PublicKey) in.readSerializable(); |
| 7363 | keys.add(pk); |
| 7364 | } |
| 7365 | |
| 7366 | keySetMapping.put(key, keys); |
| 7367 | } |
| 7368 | |
| 7369 | return keySetMapping; |
| 7370 | } |
| 7371 | |
| 7372 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Package>() { |
| 7373 | public Package createFromParcel(Parcel in) { |
| 7374 | return new Package(in); |
| 7375 | } |
| 7376 | |
| 7377 | public Package[] newArray(int size) { |
| 7378 | return new Package[size]; |
| 7379 | } |
| 7380 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | } |
| 7382 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7383 | public static abstract class Component<II extends IntentInfo> { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7384 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7385 | public final ArrayList<II> intents; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7386 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7387 | public final String className; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7388 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7389 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7390 | public Bundle metaData; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7391 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7392 | public Package owner; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7393 | /** The order of this component in relation to its peers */ |
| 7394 | public int order; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7395 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7396 | ComponentName componentName; |
| 7397 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7398 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 7399 | public Component(Package owner, ArrayList<II> intents, String className) { |
| 7400 | this.owner = owner; |
| 7401 | this.intents = intents; |
| 7402 | this.className = className; |
| 7403 | } |
| 7404 | |
| 7405 | public Component(Package owner) { |
| 7406 | this.owner = owner; |
| 7407 | this.intents = null; |
| 7408 | this.className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 7412 | owner = args.owner; |
| 7413 | intents = new ArrayList<II>(0); |
Todd Kennedy | bb8a42d | 2016-06-02 14:13:56 -0700 | [diff] [blame] | 7414 | if (parsePackageItemInfo(args.owner, outInfo, args.outError, args.tag, args.sa, |
| 7415 | true /*nameRequired*/, args.nameRes, args.labelRes, args.iconRes, |
| 7416 | args.roundIconRes, args.logoRes, args.bannerRes)) { |
| 7417 | className = outInfo.name; |
| 7418 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7419 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7420 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 7424 | this(args, (PackageItemInfo)outInfo); |
| 7425 | if (args.outError[0] != null) { |
| 7426 | return; |
| 7427 | } |
| 7428 | |
| 7429 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7430 | CharSequence pname; |
| 7431 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 7432 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 7433 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7434 | } else { |
| 7435 | // Some older apps have been seen to use a resource reference |
| 7436 | // here that on older builds was ignored (with a warning). We |
| 7437 | // need to continue to do this for them so they don't break. |
| 7438 | pname = args.sa.getNonResourceString(args.processRes); |
| 7439 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7440 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 7441 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7442 | args.flags, args.sepProcesses, args.outError); |
| 7443 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7444 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 7445 | if (args.descriptionRes != 0) { |
| 7446 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 7447 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7448 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7449 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | public Component(Component<II> clone) { |
| 7453 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7454 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7455 | className = clone.className; |
| 7456 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7457 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7458 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7459 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7460 | @UnsupportedAppUsage |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7461 | public ComponentName getComponentName() { |
| 7462 | if (componentName != null) { |
| 7463 | return componentName; |
| 7464 | } |
| 7465 | if (className != null) { |
| 7466 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 7467 | className); |
| 7468 | } |
| 7469 | return componentName; |
| 7470 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7471 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7472 | protected Component(Parcel in) { |
| 7473 | className = in.readString(); |
| 7474 | metaData = in.readBundle(); |
| 7475 | intents = createIntentsList(in); |
| 7476 | |
| 7477 | owner = null; |
| 7478 | } |
| 7479 | |
| 7480 | protected void writeToParcel(Parcel dest, int flags) { |
| 7481 | dest.writeString(className); |
| 7482 | dest.writeBundle(metaData); |
| 7483 | |
| 7484 | writeIntentsList(intents, dest, flags); |
| 7485 | } |
| 7486 | |
| 7487 | /** |
| 7488 | * <p> |
| 7489 | * Implementation note: The serialized form for the intent list also contains the name |
| 7490 | * of the concrete class that's stored in the list, and assumes that every element of the |
| 7491 | * list is of the same type. This is very similar to the original parcelable mechanism. |
| 7492 | * We cannot use that directly because IntentInfo extends IntentFilter, which is parcelable |
| 7493 | * and is public API. It also declares Parcelable related methods as final which means |
| 7494 | * we can't extend them. The approach of using composition instead of inheritance leads to |
| 7495 | * a large set of cascading changes in the PackageManagerService, which seem undesirable. |
| 7496 | * |
| 7497 | * <p> |
| 7498 | * <b>WARNING: </b> The list of objects returned by this function might need to be fixed up |
| 7499 | * to make sure their owner fields are consistent. See {@code fixupOwner}. |
| 7500 | */ |
| 7501 | private static void writeIntentsList(ArrayList<? extends IntentInfo> list, Parcel out, |
| 7502 | int flags) { |
| 7503 | if (list == null) { |
| 7504 | out.writeInt(-1); |
| 7505 | return; |
| 7506 | } |
| 7507 | |
| 7508 | final int N = list.size(); |
| 7509 | out.writeInt(N); |
| 7510 | |
| 7511 | // Don't bother writing the component name if the list is empty. |
| 7512 | if (N > 0) { |
| 7513 | IntentInfo info = list.get(0); |
| 7514 | out.writeString(info.getClass().getName()); |
| 7515 | |
| 7516 | for (int i = 0; i < N;i++) { |
| 7517 | list.get(i).writeIntentInfoToParcel(out, flags); |
| 7518 | } |
| 7519 | } |
| 7520 | } |
| 7521 | |
| 7522 | private static <T extends IntentInfo> ArrayList<T> createIntentsList(Parcel in) { |
| 7523 | int N = in.readInt(); |
| 7524 | if (N == -1) { |
| 7525 | return null; |
| 7526 | } |
| 7527 | |
| 7528 | if (N == 0) { |
| 7529 | return new ArrayList<>(0); |
| 7530 | } |
| 7531 | |
| 7532 | String componentName = in.readString(); |
| 7533 | final ArrayList<T> intentsList; |
| 7534 | try { |
| 7535 | final Class<T> cls = (Class<T>) Class.forName(componentName); |
| 7536 | final Constructor<T> cons = cls.getConstructor(Parcel.class); |
| 7537 | |
| 7538 | intentsList = new ArrayList<>(N); |
| 7539 | for (int i = 0; i < N; ++i) { |
| 7540 | intentsList.add(cons.newInstance(in)); |
| 7541 | } |
| 7542 | } catch (ReflectiveOperationException ree) { |
| 7543 | throw new AssertionError("Unable to construct intent list for: " + componentName); |
| 7544 | } |
| 7545 | |
| 7546 | return intentsList; |
| 7547 | } |
| 7548 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7549 | public void appendComponentShortName(StringBuilder sb) { |
| 7550 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7551 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7552 | |
| 7553 | public void printComponentShortName(PrintWriter pw) { |
| 7554 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 7555 | } |
| 7556 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7557 | public void setPackageName(String packageName) { |
| 7558 | componentName = null; |
| 7559 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | } |
| 7561 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7562 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7563 | public final static class Permission extends Component<IntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7564 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | public final PermissionInfo info; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7566 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | public boolean tree; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7568 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | public PermissionGroup group; |
| 7570 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 7571 | /** |
| 7572 | * @hide |
| 7573 | */ |
| 7574 | public Permission(Package owner, @Nullable String backgroundPermission) { |
| 7575 | super(owner); |
| 7576 | info = new PermissionInfo(backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7577 | } |
| 7578 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7579 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | public Permission(Package _owner, PermissionInfo _info) { |
| 7581 | super(_owner); |
| 7582 | info = _info; |
| 7583 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7584 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7585 | public void setPackageName(String packageName) { |
| 7586 | super.setPackageName(packageName); |
| 7587 | info.packageName = packageName; |
| 7588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | |
| 7590 | public String toString() { |
| 7591 | return "Permission{" |
| 7592 | + Integer.toHexString(System.identityHashCode(this)) |
| 7593 | + " " + info.name + "}"; |
| 7594 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7595 | |
| 7596 | @Override |
| 7597 | public int describeContents() { |
| 7598 | return 0; |
| 7599 | } |
| 7600 | |
| 7601 | @Override |
| 7602 | public void writeToParcel(Parcel dest, int flags) { |
| 7603 | super.writeToParcel(dest, flags); |
| 7604 | dest.writeParcelable(info, flags); |
| 7605 | dest.writeInt(tree ? 1 : 0); |
| 7606 | dest.writeParcelable(group, flags); |
| 7607 | } |
| 7608 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 7609 | /** @hide */ |
| 7610 | public boolean isAppOp() { |
| 7611 | return info.isAppOp(); |
| 7612 | } |
| 7613 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7614 | private Permission(Parcel in) { |
| 7615 | super(in); |
| 7616 | final ClassLoader boot = Object.class.getClassLoader(); |
| 7617 | info = in.readParcelable(boot); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7618 | if (info.group != null) { |
| 7619 | info.group = info.group.intern(); |
| 7620 | } |
| 7621 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7622 | tree = (in.readInt() == 1); |
| 7623 | group = in.readParcelable(boot); |
| 7624 | } |
| 7625 | |
| 7626 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Permission>() { |
| 7627 | public Permission createFromParcel(Parcel in) { |
| 7628 | return new Permission(in); |
| 7629 | } |
| 7630 | |
| 7631 | public Permission[] newArray(int size) { |
| 7632 | return new Permission[size]; |
| 7633 | } |
| 7634 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7635 | } |
| 7636 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7637 | public final static class PermissionGroup extends Component<IntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7638 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | public final PermissionGroupInfo info; |
| 7640 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 7641 | public PermissionGroup(Package owner, @StringRes int requestDetailResourceId, |
| 7642 | @StringRes int backgroundRequestResourceId, |
| 7643 | @StringRes int backgroundRequestDetailResourceId) { |
| 7644 | super(owner); |
| 7645 | info = new PermissionGroupInfo(requestDetailResourceId, backgroundRequestResourceId, |
| 7646 | backgroundRequestDetailResourceId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7647 | } |
| 7648 | |
| 7649 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 7650 | super(_owner); |
| 7651 | info = _info; |
| 7652 | } |
| 7653 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7654 | public void setPackageName(String packageName) { |
| 7655 | super.setPackageName(packageName); |
| 7656 | info.packageName = packageName; |
| 7657 | } |
| 7658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7659 | public String toString() { |
| 7660 | return "PermissionGroup{" |
| 7661 | + Integer.toHexString(System.identityHashCode(this)) |
| 7662 | + " " + info.name + "}"; |
| 7663 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7664 | |
| 7665 | @Override |
| 7666 | public int describeContents() { |
| 7667 | return 0; |
| 7668 | } |
| 7669 | |
| 7670 | @Override |
| 7671 | public void writeToParcel(Parcel dest, int flags) { |
| 7672 | super.writeToParcel(dest, flags); |
| 7673 | dest.writeParcelable(info, flags); |
| 7674 | } |
| 7675 | |
| 7676 | private PermissionGroup(Parcel in) { |
| 7677 | super(in); |
| 7678 | info = in.readParcelable(Object.class.getClassLoader()); |
| 7679 | } |
| 7680 | |
| 7681 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<PermissionGroup>() { |
| 7682 | public PermissionGroup createFromParcel(Parcel in) { |
| 7683 | return new PermissionGroup(in); |
| 7684 | } |
| 7685 | |
| 7686 | public PermissionGroup[] newArray(int size) { |
| 7687 | return new PermissionGroup[size]; |
| 7688 | } |
| 7689 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | } |
| 7691 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7692 | private static boolean copyNeeded(int flags, Package p, |
| 7693 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 7694 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7695 | // We always need to copy for other users, since we need |
| 7696 | // to fix up the uid. |
| 7697 | return true; |
| 7698 | } |
| 7699 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 7700 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 7701 | if (p.applicationInfo.enabled != enabled) { |
| 7702 | return true; |
| 7703 | } |
| 7704 | } |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 7705 | boolean suspended = (p.applicationInfo.flags & FLAG_SUSPENDED) != 0; |
| 7706 | if (state.suspended != suspended) { |
| 7707 | return true; |
| 7708 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7709 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7710 | return true; |
| 7711 | } |
| 7712 | if (state.stopped) { |
| 7713 | return true; |
| 7714 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7715 | if (state.instantApp != p.applicationInfo.isInstantApp()) { |
| 7716 | return true; |
| 7717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 7719 | && (metaData != null || p.mAppMetaData != null)) { |
| 7720 | return true; |
| 7721 | } |
| 7722 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7723 | && p.usesLibraryFiles != null) { |
| 7724 | return true; |
| 7725 | } |
Nicolas Geoffray | abcd58e | 2018-10-22 10:23:50 +0100 | [diff] [blame] | 7726 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 7727 | && p.usesLibraryInfos != null) { |
| 7728 | return true; |
| 7729 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 7730 | if (p.staticSharedLibName != null) { |
| 7731 | return true; |
| 7732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | return false; |
| 7734 | } |
| 7735 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7736 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7737 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 7738 | PackageUserState state) { |
| 7739 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 7740 | } |
| 7741 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7742 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 7743 | PackageUserState state) { |
| 7744 | // CompatibilityMode is global state. |
| 7745 | if (!sCompatibilityModeEnabled) { |
| 7746 | ai.disableCompatibilityMode(); |
| 7747 | } |
| 7748 | if (state.installed) { |
| 7749 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 7750 | } else { |
| 7751 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 7752 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 7753 | if (state.suspended) { |
| 7754 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 7755 | } else { |
| 7756 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 7757 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7758 | if (state.instantApp) { |
| 7759 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7760 | } else { |
| 7761 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_INSTANT; |
| 7762 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 7763 | if (state.virtualPreload) { |
| 7764 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7765 | } else { |
| 7766 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD; |
| 7767 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 7768 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7769 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7770 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 7771 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 7772 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7773 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 7774 | ai.enabled = true; |
| 7775 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 7776 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 7777 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 7778 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 7779 | ai.enabled = false; |
| 7780 | } |
| 7781 | ai.enabledSetting = state.enabled; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 7782 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7783 | ai.category = state.categoryHint; |
| 7784 | } |
Jeff Sharkey | 0078e1b | 2017-01-11 16:05:27 -0700 | [diff] [blame] | 7785 | if (ai.category == ApplicationInfo.CATEGORY_UNDEFINED) { |
| 7786 | ai.category = FallbackCategoryProvider.getFallbackCategory(ai.packageName); |
| 7787 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 7788 | ai.seInfoUser = SELinuxUtil.assignSeinfoUser(state); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7789 | ai.resourceDirs = state.overlayPaths; |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 7790 | ai.icon = (sUseRoundIcon && ai.roundIconRes != 0) ? ai.roundIconRes : ai.iconRes; |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7791 | } |
| 7792 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7793 | @UnsupportedAppUsage |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 7794 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7795 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7797 | if (!checkUseInstalledOrHidden(flags, state, p.applicationInfo) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7798 | return null; |
| 7799 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7800 | if (!copyNeeded(flags, p, state, null, userId) |
| 7801 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 7802 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 7803 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 7804 | // - CompatibilityMode is global state, so will be the same for every call. |
| 7805 | // - We only come in to here if the app should reported as installed; this is the |
| 7806 | // default state, and we will do a copy otherwise. |
| 7807 | // - The enable state will always be reported the same for the application across |
| 7808 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 7809 | // be doing a copy. |
| 7810 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | return p.applicationInfo; |
| 7812 | } |
| 7813 | |
| 7814 | // Make shallow copy so we can store the metadata/libraries safely |
| 7815 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7816 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 7818 | ai.metaData = p.mAppMetaData; |
| 7819 | } |
| 7820 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 7821 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
Nicolas Geoffray | 8d144eb | 2018-11-15 12:59:52 +0000 | [diff] [blame] | 7822 | ai.sharedLibraryInfos = p.usesLibraryInfos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7823 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7824 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7825 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7826 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 7827 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 7828 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 7829 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | return ai; |
| 7831 | } |
| 7832 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7833 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 7834 | PackageUserState state, int userId) { |
| 7835 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7836 | if (!checkUseInstalledOrHidden(flags, state, ai)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7837 | return null; |
| 7838 | } |
| 7839 | // This is only used to return the ResolverActivity; we will just always |
| 7840 | // make a copy. |
| 7841 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 7842 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 7843 | if (state.stopped) { |
| 7844 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 7845 | } else { |
| 7846 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 7847 | } |
| 7848 | updateApplicationInfo(ai, flags, state); |
| 7849 | return ai; |
| 7850 | } |
| 7851 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7852 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | public static final PermissionInfo generatePermissionInfo( |
| 7854 | Permission p, int flags) { |
| 7855 | if (p == null) return null; |
| 7856 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7857 | return p.info; |
| 7858 | } |
| 7859 | PermissionInfo pi = new PermissionInfo(p.info); |
| 7860 | pi.metaData = p.metaData; |
| 7861 | return pi; |
| 7862 | } |
| 7863 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7864 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 7866 | PermissionGroup pg, int flags) { |
| 7867 | if (pg == null) return null; |
| 7868 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 7869 | return pg.info; |
| 7870 | } |
| 7871 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 7872 | pgi.metaData = pg.metaData; |
| 7873 | return pgi; |
| 7874 | } |
| 7875 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7876 | public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7877 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7878 | public final ActivityInfo info; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7879 | private boolean mHasMaxAspectRatio; |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7880 | private boolean mHasMinAspectRatio; |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7881 | |
| 7882 | private boolean hasMaxAspectRatio() { |
| 7883 | return mHasMaxAspectRatio; |
| 7884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7886 | private boolean hasMinAspectRatio() { |
| 7887 | return mHasMinAspectRatio; |
| 7888 | } |
| 7889 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 7890 | // To construct custom activity which does not exist in manifest |
| 7891 | Activity(final Package owner, final String className, final ActivityInfo info) { |
| 7892 | super(owner, new ArrayList<>(0), className); |
| 7893 | this.info = info; |
| 7894 | this.info.applicationInfo = owner.applicationInfo; |
| 7895 | } |
| 7896 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7897 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 7898 | super(args, _info); |
| 7899 | info = _info; |
| 7900 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 7902 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7903 | public void setPackageName(String packageName) { |
| 7904 | super.setPackageName(packageName); |
| 7905 | info.packageName = packageName; |
| 7906 | } |
| 7907 | |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7908 | |
| 7909 | private void setMaxAspectRatio(float maxAspectRatio) { |
| 7910 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7911 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7912 | // Resizeable activities can be put in any aspect ratio. |
| 7913 | return; |
| 7914 | } |
| 7915 | |
| 7916 | if (maxAspectRatio < 1.0f && maxAspectRatio != 0) { |
| 7917 | // Ignore any value lesser than 1.0. |
| 7918 | return; |
| 7919 | } |
| 7920 | |
| 7921 | info.maxAspectRatio = maxAspectRatio; |
| 7922 | mHasMaxAspectRatio = true; |
| 7923 | } |
| 7924 | |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7925 | private void setMinAspectRatio(float minAspectRatio) { |
| 7926 | if (info.resizeMode == RESIZE_MODE_RESIZEABLE |
| 7927 | || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) { |
| 7928 | // Resizeable activities can be put in any aspect ratio. |
| 7929 | return; |
| 7930 | } |
| 7931 | |
| 7932 | if (minAspectRatio < 1.0f && minAspectRatio != 0) { |
| 7933 | // Ignore any value lesser than 1.0. |
| 7934 | return; |
| 7935 | } |
| 7936 | |
| 7937 | info.minAspectRatio = minAspectRatio; |
| 7938 | mHasMinAspectRatio = true; |
| 7939 | } |
| 7940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7941 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 7942 | StringBuilder sb = new StringBuilder(128); |
| 7943 | sb.append("Activity{"); |
| 7944 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7945 | sb.append(' '); |
| 7946 | appendComponentShortName(sb); |
| 7947 | sb.append('}'); |
| 7948 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7950 | |
| 7951 | @Override |
| 7952 | public int describeContents() { |
| 7953 | return 0; |
| 7954 | } |
| 7955 | |
| 7956 | @Override |
| 7957 | public void writeToParcel(Parcel dest, int flags) { |
| 7958 | super.writeToParcel(dest, flags); |
| 7959 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7960 | dest.writeBoolean(mHasMaxAspectRatio); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7961 | dest.writeBoolean(mHasMinAspectRatio); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7962 | } |
| 7963 | |
| 7964 | private Activity(Parcel in) { |
| 7965 | super(in); |
| 7966 | info = in.readParcelable(Object.class.getClassLoader()); |
Bryce Lee | 22571db | 2017-07-07 15:54:18 -0700 | [diff] [blame] | 7967 | mHasMaxAspectRatio = in.readBoolean(); |
Adrian Roos | 917791e | 2018-11-28 16:30:44 +0100 | [diff] [blame] | 7968 | mHasMinAspectRatio = in.readBoolean(); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7969 | |
| 7970 | for (ActivityIntentInfo aii : intents) { |
| 7971 | aii.activity = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 7972 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7973 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 7974 | |
| 7975 | if (info.permission != null) { |
| 7976 | info.permission = info.permission.intern(); |
| 7977 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 7978 | } |
| 7979 | |
| 7980 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Activity>() { |
| 7981 | public Activity createFromParcel(Parcel in) { |
| 7982 | return new Activity(in); |
| 7983 | } |
| 7984 | |
| 7985 | public Activity[] newArray(int size) { |
| 7986 | return new Activity[size]; |
| 7987 | } |
| 7988 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | } |
| 7990 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 7991 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7992 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 7993 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7994 | if (a == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 7995 | if (!checkUseInstalledOrHidden(flags, state, a.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 7996 | return null; |
| 7997 | } |
| 7998 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 7999 | updateApplicationInfo(a.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | return a.info; |
| 8001 | } |
| 8002 | // Make shallow copies so we can store the metadata safely |
| 8003 | ActivityInfo ai = new ActivityInfo(a.info); |
| 8004 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8005 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8006 | return ai; |
| 8007 | } |
| 8008 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 8009 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 8010 | PackageUserState state, int userId) { |
| 8011 | if (ai == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 8012 | if (!checkUseInstalledOrHidden(flags, state, ai.applicationInfo)) { |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 8013 | return null; |
| 8014 | } |
| 8015 | // This is only used to return the ResolverActivity; we will just always |
| 8016 | // make a copy. |
| 8017 | ai = new ActivityInfo(ai); |
| 8018 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 8019 | return ai; |
| 8020 | } |
| 8021 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8022 | public final static class Service extends Component<ServiceIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8023 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8024 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8026 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 8027 | super(args, _info); |
| 8028 | info = _info; |
| 8029 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 8031 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8032 | public void setPackageName(String packageName) { |
| 8033 | super.setPackageName(packageName); |
| 8034 | info.packageName = packageName; |
| 8035 | } |
| 8036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8037 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8038 | StringBuilder sb = new StringBuilder(128); |
| 8039 | sb.append("Service{"); |
| 8040 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8041 | sb.append(' '); |
| 8042 | appendComponentShortName(sb); |
| 8043 | sb.append('}'); |
| 8044 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8046 | |
| 8047 | @Override |
| 8048 | public int describeContents() { |
| 8049 | return 0; |
| 8050 | } |
| 8051 | |
| 8052 | @Override |
| 8053 | public void writeToParcel(Parcel dest, int flags) { |
| 8054 | super.writeToParcel(dest, flags); |
| 8055 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 8056 | } |
| 8057 | |
| 8058 | private Service(Parcel in) { |
| 8059 | super(in); |
| 8060 | info = in.readParcelable(Object.class.getClassLoader()); |
| 8061 | |
| 8062 | for (ServiceIntentInfo aii : intents) { |
| 8063 | aii.service = this; |
Todd Kennedy | 6d418b6 | 2018-02-22 14:15:18 -0800 | [diff] [blame] | 8064 | order = Math.max(aii.getOrder(), order); |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8065 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8066 | |
| 8067 | if (info.permission != null) { |
| 8068 | info.permission = info.permission.intern(); |
| 8069 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8070 | } |
| 8071 | |
| 8072 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Service>() { |
| 8073 | public Service createFromParcel(Parcel in) { |
| 8074 | return new Service(in); |
| 8075 | } |
| 8076 | |
| 8077 | public Service[] newArray(int size) { |
| 8078 | return new Service[size]; |
| 8079 | } |
| 8080 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8081 | } |
| 8082 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8083 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8084 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 8085 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | if (s == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 8087 | if (!checkUseInstalledOrHidden(flags, state, s.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8088 | return null; |
| 8089 | } |
| 8090 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 8091 | updateApplicationInfo(s.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8092 | return s.info; |
| 8093 | } |
| 8094 | // Make shallow copies so we can store the metadata safely |
| 8095 | ServiceInfo si = new ServiceInfo(s.info); |
| 8096 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8097 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | return si; |
| 8099 | } |
| 8100 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8101 | public final static class Provider extends Component<ProviderIntentInfo> implements Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8102 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8103 | public final ProviderInfo info; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8104 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8105 | public boolean syncable; |
| 8106 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8107 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 8108 | super(args, _info); |
| 8109 | info = _info; |
| 8110 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8111 | syncable = false; |
| 8112 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 8113 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8114 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8115 | public Provider(Provider existingProvider) { |
| 8116 | super(existingProvider); |
| 8117 | this.info = existingProvider.info; |
| 8118 | this.syncable = existingProvider.syncable; |
| 8119 | } |
| 8120 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8121 | public void setPackageName(String packageName) { |
| 8122 | super.setPackageName(packageName); |
| 8123 | info.packageName = packageName; |
| 8124 | } |
| 8125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8126 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8127 | StringBuilder sb = new StringBuilder(128); |
| 8128 | sb.append("Provider{"); |
| 8129 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8130 | sb.append(' '); |
| 8131 | appendComponentShortName(sb); |
| 8132 | sb.append('}'); |
| 8133 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8135 | |
| 8136 | @Override |
| 8137 | public int describeContents() { |
| 8138 | return 0; |
| 8139 | } |
| 8140 | |
| 8141 | @Override |
| 8142 | public void writeToParcel(Parcel dest, int flags) { |
| 8143 | super.writeToParcel(dest, flags); |
| 8144 | dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); |
| 8145 | dest.writeInt((syncable) ? 1 : 0); |
| 8146 | } |
| 8147 | |
| 8148 | private Provider(Parcel in) { |
| 8149 | super(in); |
| 8150 | info = in.readParcelable(Object.class.getClassLoader()); |
| 8151 | syncable = (in.readInt() == 1); |
| 8152 | |
| 8153 | for (ProviderIntentInfo aii : intents) { |
| 8154 | aii.provider = this; |
| 8155 | } |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8156 | |
| 8157 | if (info.readPermission != null) { |
| 8158 | info.readPermission = info.readPermission.intern(); |
| 8159 | } |
| 8160 | |
| 8161 | if (info.writePermission != null) { |
| 8162 | info.writePermission = info.writePermission.intern(); |
| 8163 | } |
| 8164 | |
| 8165 | if (info.authority != null) { |
| 8166 | info.authority = info.authority.intern(); |
| 8167 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8168 | } |
| 8169 | |
| 8170 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Provider>() { |
| 8171 | public Provider createFromParcel(Parcel in) { |
| 8172 | return new Provider(in); |
| 8173 | } |
| 8174 | |
| 8175 | public Provider[] newArray(int size) { |
| 8176 | return new Provider[size]; |
| 8177 | } |
| 8178 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8179 | } |
| 8180 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8181 | @UnsupportedAppUsage |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8182 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 8183 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | if (p == null) return null; |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 8185 | if (!checkUseInstalledOrHidden(flags, state, p.owner.applicationInfo)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8186 | return null; |
| 8187 | } |
| 8188 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8189 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8190 | || p.info.uriPermissionPatterns == null)) { |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 8191 | updateApplicationInfo(p.info.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | return p.info; |
| 8193 | } |
| 8194 | // Make shallow copies so we can store the metadata safely |
| 8195 | ProviderInfo pi = new ProviderInfo(p.info); |
| 8196 | pi.metaData = p.metaData; |
| 8197 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 8198 | pi.uriPermissionPatterns = null; |
| 8199 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 8200 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | return pi; |
| 8202 | } |
| 8203 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8204 | public final static class Instrumentation extends Component<IntentInfo> implements |
| 8205 | Parcelable { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8206 | @UnsupportedAppUsage |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8207 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8208 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8209 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 8210 | super(args, _info); |
| 8211 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8212 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 8213 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8214 | public void setPackageName(String packageName) { |
| 8215 | super.setPackageName(packageName); |
| 8216 | info.packageName = packageName; |
| 8217 | } |
| 8218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8219 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8220 | StringBuilder sb = new StringBuilder(128); |
| 8221 | sb.append("Instrumentation{"); |
| 8222 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8223 | sb.append(' '); |
| 8224 | appendComponentShortName(sb); |
| 8225 | sb.append('}'); |
| 8226 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8227 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8228 | |
| 8229 | @Override |
| 8230 | public int describeContents() { |
| 8231 | return 0; |
| 8232 | } |
| 8233 | |
| 8234 | @Override |
| 8235 | public void writeToParcel(Parcel dest, int flags) { |
| 8236 | super.writeToParcel(dest, flags); |
| 8237 | dest.writeParcelable(info, flags); |
| 8238 | } |
| 8239 | |
| 8240 | private Instrumentation(Parcel in) { |
| 8241 | super(in); |
| 8242 | info = in.readParcelable(Object.class.getClassLoader()); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8243 | |
| 8244 | if (info.targetPackage != null) { |
| 8245 | info.targetPackage = info.targetPackage.intern(); |
| 8246 | } |
| 8247 | |
Dianne Hackborn | 1be5354 | 2017-04-28 13:36:00 -0700 | [diff] [blame] | 8248 | if (info.targetProcesses != null) { |
| 8249 | info.targetProcesses = info.targetProcesses.intern(); |
Narayan Kamath | 07ac144 | 2017-02-10 15:08:07 +0000 | [diff] [blame] | 8250 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator<Instrumentation>() { |
| 8254 | public Instrumentation createFromParcel(Parcel in) { |
| 8255 | return new Instrumentation(in); |
| 8256 | } |
| 8257 | |
| 8258 | public Instrumentation[] newArray(int size) { |
| 8259 | return new Instrumentation[size]; |
| 8260 | } |
| 8261 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8264 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 8266 | Instrumentation i, int flags) { |
| 8267 | if (i == null) return null; |
| 8268 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 8269 | return i.info; |
| 8270 | } |
| 8271 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 8272 | ii.metaData = i.metaData; |
| 8273 | return ii; |
| 8274 | } |
| 8275 | |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8276 | public static abstract class IntentInfo extends IntentFilter { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8277 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | public boolean hasDefault; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8279 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8280 | public int labelRes; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8281 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8282 | public CharSequence nonLocalizedLabel; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8283 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8284 | public int icon; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8285 | @UnsupportedAppUsage |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 8286 | public int logo; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8287 | @UnsupportedAppUsage |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 8288 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 8289 | public int preferred; |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8290 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8291 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8292 | protected IntentInfo() { |
| 8293 | } |
| 8294 | |
| 8295 | protected IntentInfo(Parcel dest) { |
| 8296 | super(dest); |
| 8297 | hasDefault = (dest.readInt() == 1); |
| 8298 | labelRes = dest.readInt(); |
| 8299 | nonLocalizedLabel = dest.readCharSequence(); |
| 8300 | icon = dest.readInt(); |
| 8301 | logo = dest.readInt(); |
| 8302 | banner = dest.readInt(); |
| 8303 | preferred = dest.readInt(); |
| 8304 | } |
| 8305 | |
| 8306 | |
| 8307 | public void writeIntentInfoToParcel(Parcel dest, int flags) { |
| 8308 | super.writeToParcel(dest, flags); |
| 8309 | dest.writeInt(hasDefault ? 1 : 0); |
| 8310 | dest.writeInt(labelRes); |
| 8311 | dest.writeCharSequence(nonLocalizedLabel); |
| 8312 | dest.writeInt(icon); |
| 8313 | dest.writeInt(logo); |
| 8314 | dest.writeInt(banner); |
| 8315 | dest.writeInt(preferred); |
| 8316 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8317 | } |
| 8318 | |
| 8319 | public final static class ActivityIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8320 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8321 | public Activity activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8322 | |
| 8323 | public ActivityIntentInfo(Activity _activity) { |
| 8324 | activity = _activity; |
| 8325 | } |
| 8326 | |
| 8327 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8328 | StringBuilder sb = new StringBuilder(128); |
| 8329 | sb.append("ActivityIntentInfo{"); |
| 8330 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8331 | sb.append(' '); |
| 8332 | activity.appendComponentShortName(sb); |
| 8333 | sb.append('}'); |
| 8334 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8335 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8336 | |
| 8337 | public ActivityIntentInfo(Parcel in) { |
| 8338 | super(in); |
| 8339 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | public final static class ServiceIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8343 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8344 | public Service service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8345 | |
| 8346 | public ServiceIntentInfo(Service _service) { |
| 8347 | service = _service; |
| 8348 | } |
| 8349 | |
| 8350 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 8351 | StringBuilder sb = new StringBuilder(128); |
| 8352 | sb.append("ServiceIntentInfo{"); |
| 8353 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8354 | sb.append(' '); |
| 8355 | service.appendComponentShortName(sb); |
| 8356 | sb.append('}'); |
| 8357 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8358 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8359 | |
| 8360 | public ServiceIntentInfo(Parcel in) { |
| 8361 | super(in); |
| 8362 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8363 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8364 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8365 | public static final class ProviderIntentInfo extends IntentInfo { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8366 | @UnsupportedAppUsage |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8367 | public Provider provider; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8368 | |
| 8369 | public ProviderIntentInfo(Provider provider) { |
| 8370 | this.provider = provider; |
| 8371 | } |
| 8372 | |
| 8373 | public String toString() { |
| 8374 | StringBuilder sb = new StringBuilder(128); |
| 8375 | sb.append("ProviderIntentInfo{"); |
| 8376 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8377 | sb.append(' '); |
| 8378 | provider.appendComponentShortName(sb); |
| 8379 | sb.append('}'); |
| 8380 | return sb.toString(); |
| 8381 | } |
Narayan Kamath | fb2afbf | 2016-11-24 13:22:40 +0000 | [diff] [blame] | 8382 | |
| 8383 | public ProviderIntentInfo(Parcel in) { |
| 8384 | super(in); |
| 8385 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 8386 | } |
| 8387 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8388 | /** |
| 8389 | * @hide |
| 8390 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 8391 | @UnsupportedAppUsage |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 8392 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 8393 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 8394 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8395 | |
Hyunyoung Song | 929de7a | 2019-03-21 23:51:27 -0700 | [diff] [blame] | 8396 | /** |
| 8397 | * @hide |
| 8398 | */ |
| 8399 | public static void readConfigUseRoundIcon(Resources r) { |
| 8400 | if (r != null) { |
| 8401 | sUseRoundIcon = r.getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 8402 | return; |
| 8403 | } |
| 8404 | |
| 8405 | ApplicationInfo androidAppInfo; |
| 8406 | try { |
| 8407 | androidAppInfo = ActivityThread.getPackageManager().getApplicationInfo( |
| 8408 | "android", 0 /* flags */, |
| 8409 | UserHandle.myUserId()); |
| 8410 | } catch (RemoteException e) { |
| 8411 | throw e.rethrowFromSystemServer(); |
| 8412 | } |
| 8413 | Resources systemResources = Resources.getSystem(); |
| 8414 | |
| 8415 | // Create in-flight as this overlayable resource is only used when config changes |
| 8416 | Resources overlayableRes = ResourcesManager.getInstance().getResources(null, |
| 8417 | null, |
| 8418 | null, |
| 8419 | androidAppInfo.resourceDirs, |
| 8420 | androidAppInfo.sharedLibraryFiles, |
| 8421 | Display.DEFAULT_DISPLAY, |
| 8422 | null, |
| 8423 | systemResources.getCompatibilityInfo(), |
| 8424 | systemResources.getClassLoader()); |
| 8425 | |
| 8426 | sUseRoundIcon = overlayableRes.getBoolean(com.android.internal.R.bool.config_useRoundIcon); |
| 8427 | } |
| 8428 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8429 | public static class PackageParserException extends Exception { |
| 8430 | public final int error; |
| 8431 | |
| 8432 | public PackageParserException(int error, String detailMessage) { |
| 8433 | super(detailMessage); |
| 8434 | this.error = error; |
| 8435 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 8436 | |
| 8437 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 8438 | super(detailMessage, throwable); |
| 8439 | this.error = error; |
| 8440 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 8441 | } |
Jiyong Park | 5b1b734 | 2019-01-18 09:45:17 +0900 | [diff] [blame] | 8442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | } |