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 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 19 | import com.android.internal.R; |
| 20 | import com.android.internal.util.ArrayUtils; |
| 21 | import com.android.internal.util.XmlUtils; |
| 22 | |
| 23 | import org.xmlpull.v1.XmlPullParser; |
| 24 | import org.xmlpull.v1.XmlPullParserException; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 25 | |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.ComponentName; |
| 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
| 30 | import android.content.res.AssetManager; |
| 31 | import android.content.res.Configuration; |
| 32 | import android.content.res.Resources; |
| 33 | import android.content.res.TypedArray; |
| 34 | import android.content.res.XmlResourceParser; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 35 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Bundle; |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 37 | import android.os.FileUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.PatternMatcher; |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 39 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 42 | import android.util.ArrayMap; |
| 43 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.util.AttributeSet; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 45 | import android.util.Base64; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.util.DisplayMetrics; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 47 | import android.util.Log; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 48 | import android.util.Pair; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 49 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.util.TypedValue; |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 51 | import android.util.apk.ApkSignatureSchemeV2Verifier; |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 52 | import android.util.jar.StrictJarFile; |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 53 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| 55 | import java.io.File; |
| 56 | import java.io.IOException; |
| 57 | import java.io.InputStream; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 58 | import java.io.PrintWriter; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 59 | import java.security.GeneralSecurityException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 60 | import java.security.KeyFactory; |
| 61 | import java.security.NoSuchAlgorithmException; |
| 62 | import java.security.PublicKey; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import java.security.cert.Certificate; |
| 64 | import java.security.cert.CertificateEncodingException; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 65 | import java.security.spec.EncodedKeySpec; |
| 66 | import java.security.spec.InvalidKeySpecException; |
| 67 | import java.security.spec.X509EncodedKeySpec; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import java.util.ArrayList; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 69 | import java.util.Arrays; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 70 | import java.util.Collections; |
| 71 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import java.util.Iterator; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 73 | import java.util.List; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 74 | import java.util.Set; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 75 | import java.util.concurrent.atomic.AtomicReference; |
Kenny Root | 6c918ce | 2013-04-02 14:04:24 -0700 | [diff] [blame] | 76 | import java.util.zip.ZipEntry; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 78 | import libcore.io.IoUtils; |
| 79 | |
| 80 | import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; |
| 81 | import static android.content.pm.ActivityInfo.FLAG_IMMERSIVE; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 82 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 83 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
| 84 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
| 85 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 86 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 87 | import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED; |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 88 | import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 89 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST; |
| 90 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 91 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; |
| 92 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 93 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 94 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
| 95 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 96 | import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
| 97 | import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; |
| 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 100 | * Parser for package files (APKs) on disk. This supports apps packaged either |
| 101 | * as a single "monolithic" APK, or apps packaged as a "cluster" of multiple |
| 102 | * APKs in a single directory. |
| 103 | * <p> |
| 104 | * Apps packaged as multiple APKs always consist of a single "base" APK (with a |
| 105 | * {@code null} split name) and zero or more "split" APKs (with unique split |
| 106 | * names). Any subset of those split APKs are a valid install, as long as the |
| 107 | * following constraints are met: |
| 108 | * <ul> |
| 109 | * <li>All APKs must have the exact same package name, version code, and signing |
| 110 | * certificates. |
| 111 | * <li>All APKs must have unique split names. |
| 112 | * <li>All installations must contain a single base APK. |
| 113 | * </ul> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | * |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 115 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | */ |
| 117 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 118 | private static final boolean DEBUG_JAR = false; |
| 119 | private static final boolean DEBUG_PARSER = false; |
| 120 | private static final boolean DEBUG_BACKUP = false; |
| 121 | |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame^] | 122 | private static final boolean MULTI_PACKAGE_APK_ENABLED = false; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 123 | private static final int MAX_PACKAGES_PER_APK = 5; |
| 124 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 125 | public static final int APK_SIGNING_UNKNOWN = 0; |
| 126 | public static final int APK_SIGNING_V1 = 1; |
| 127 | public static final int APK_SIGNING_V2 = 2; |
| 128 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 129 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 130 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 131 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 132 | /** File name in an APK for the Android manifest. */ |
| 133 | private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
| 134 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 135 | /** Path prefix for apps on expanded storage */ |
| 136 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 137 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 138 | private static final String TAG_MANIFEST = "manifest"; |
| 139 | private static final String TAG_APPLICATION = "application"; |
| 140 | private static final String TAG_OVERLAY = "overlay"; |
| 141 | private static final String TAG_KEY_SETS = "key-sets"; |
| 142 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 143 | private static final String TAG_PERMISSION = "permission"; |
| 144 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 145 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 146 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 147 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 148 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 149 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 150 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 151 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 152 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 153 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 154 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 155 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 156 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 157 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 158 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 159 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 160 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 161 | private static final String TAG_PACKAGE = "package"; |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 162 | private static final String TAG_RESTRICT_UPDATE = "restrict-update"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 163 | |
| 164 | // These are the tags supported by child packages |
| 165 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 166 | static { |
| 167 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 168 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 169 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 170 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 171 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 172 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 173 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 174 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 175 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 176 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 177 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 178 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 179 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 180 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 181 | } |
| 182 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 183 | /** @hide */ |
| 184 | public static class NewPermissionInfo { |
| 185 | public final String name; |
| 186 | public final int sdkVersion; |
| 187 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 188 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 189 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 190 | this.name = name; |
| 191 | this.sdkVersion = sdkVersion; |
| 192 | this.fileVersion = fileVersion; |
| 193 | } |
| 194 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 195 | |
| 196 | /** @hide */ |
| 197 | public static class SplitPermissionInfo { |
| 198 | public final String rootPerm; |
| 199 | public final String[] newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 200 | public final int targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 201 | |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 202 | public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) { |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 203 | this.rootPerm = rootPerm; |
| 204 | this.newPerms = newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 205 | this.targetSdk = targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 209 | /** |
| 210 | * List of new permissions that have been added since 1.0. |
| 211 | * NOTE: These must be declared in SDK version order, with permissions |
| 212 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 213 | * If sdkVersion is 0, then this is not a permission that we want to |
| 214 | * automatically add to older apps, but we do want to allow it to be |
| 215 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 216 | * @hide |
| 217 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 218 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 219 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 220 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 221 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 222 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 223 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 224 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 226 | /** |
| 227 | * List of permissions that have been split into more granular or dependent |
| 228 | * permissions. |
| 229 | * @hide |
| 230 | */ |
| 231 | public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] = |
| 232 | new PackageParser.SplitPermissionInfo[] { |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 233 | // READ_EXTERNAL_STORAGE is always required when an app requests |
| 234 | // WRITE_EXTERNAL_STORAGE, because we can't have an app that has |
| 235 | // write access without read access. The hack here with the target |
| 236 | // target SDK version ensures that this grant is always done. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 237 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 238 | new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 239 | android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1), |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 240 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS, |
| 241 | new String[] { android.Manifest.permission.READ_CALL_LOG }, |
| 242 | android.os.Build.VERSION_CODES.JELLY_BEAN), |
| 243 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS, |
| 244 | new String[] { android.Manifest.permission.WRITE_CALL_LOG }, |
| 245 | android.os.Build.VERSION_CODES.JELLY_BEAN) |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 248 | /** |
| 249 | * @deprecated callers should move to explicitly passing around source path. |
| 250 | */ |
| 251 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 255 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 256 | private DisplayMetrics mMetrics; |
| 257 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 258 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 259 | 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] | 260 | |
| 261 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 262 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 263 | private static boolean sCompatibilityModeEnabled = true; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 264 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 265 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 266 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 267 | static class ParsePackageItemArgs { |
| 268 | final Package owner; |
| 269 | final String[] outError; |
| 270 | final int nameRes; |
| 271 | final int labelRes; |
| 272 | final int iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 273 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 274 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 275 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 276 | String tag; |
| 277 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 278 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 279 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 280 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 281 | owner = _owner; |
| 282 | outError = _outError; |
| 283 | nameRes = _nameRes; |
| 284 | labelRes = _labelRes; |
| 285 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 286 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 287 | bannerRes = _bannerRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 290 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 291 | static class ParseComponentArgs extends ParsePackageItemArgs { |
| 292 | final String[] sepProcesses; |
| 293 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 294 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 295 | final int enabledRes; |
| 296 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 297 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 298 | ParseComponentArgs(Package _owner, String[] _outError, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 299 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 300 | String[] _sepProcesses, int _processRes, |
| 301 | int _descriptionRes, int _enabledRes) { |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 302 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes, _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 303 | sepProcesses = _sepProcesses; |
| 304 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 305 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 306 | enabledRes = _enabledRes; |
| 307 | } |
| 308 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 309 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 310 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 311 | * Lightweight parsed details about a single package. |
| 312 | */ |
| 313 | public static class PackageLite { |
| 314 | public final String packageName; |
| 315 | public final int versionCode; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 316 | public final int installLocation; |
| 317 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 318 | |
| 319 | /** Names of any split APKs, ordered by parsed splitName */ |
| 320 | public final String[] splitNames; |
| 321 | |
| 322 | /** |
| 323 | * Path where this package was found on disk. For monolithic packages |
| 324 | * this is path to single base APK file; for cluster packages this is |
| 325 | * path to the cluster directory. |
| 326 | */ |
| 327 | public final String codePath; |
| 328 | |
| 329 | /** Path of base APK */ |
| 330 | public final String baseCodePath; |
| 331 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 332 | public final String[] splitCodePaths; |
| 333 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 334 | /** Revision code of base APK */ |
| 335 | public final int baseRevisionCode; |
| 336 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 337 | public final int[] splitRevisionCodes; |
| 338 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 339 | public final boolean coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 340 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 341 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 342 | public final boolean extractNativeLibs; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 343 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 344 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 345 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 346 | this.packageName = baseApk.packageName; |
| 347 | this.versionCode = baseApk.versionCode; |
| 348 | this.installLocation = baseApk.installLocation; |
| 349 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 350 | this.splitNames = splitNames; |
| 351 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 352 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 353 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 354 | this.baseRevisionCode = baseApk.revisionCode; |
| 355 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 356 | this.coreApp = baseApk.coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 357 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 358 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 359 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | public List<String> getAllCodePaths() { |
| 363 | ArrayList<String> paths = new ArrayList<>(); |
| 364 | paths.add(baseCodePath); |
| 365 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 366 | Collections.addAll(paths, splitCodePaths); |
| 367 | } |
| 368 | return paths; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 373 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 374 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 375 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 376 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 377 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 378 | public final String splitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 379 | public final int versionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 380 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 381 | public final int installLocation; |
| 382 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 383 | public final Signature[] signatures; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 384 | public final Certificate[][] certificates; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 385 | public final boolean coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 386 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 387 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 388 | public final boolean extractNativeLibs; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 389 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 390 | public ApkLite(String codePath, String packageName, String splitName, int versionCode, |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 391 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 392 | Signature[] signatures, Certificate[][] certificates, boolean coreApp, |
| 393 | boolean multiArch, boolean use32bitAbi, boolean extractNativeLibs) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 394 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 395 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 396 | this.splitName = splitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 397 | this.versionCode = versionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 398 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 399 | this.installLocation = installLocation; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 400 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 401 | this.signatures = signatures; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 402 | this.certificates = certificates; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 403 | this.coreApp = coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 404 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 405 | this.use32bitAbi = use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 406 | this.extractNativeLibs = extractNativeLibs; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 410 | private ParsePackageItemArgs mParseInstrumentationArgs; |
| 411 | private ParseComponentArgs mParseActivityArgs; |
| 412 | private ParseComponentArgs mParseActivityAliasArgs; |
| 413 | private ParseComponentArgs mParseServiceArgs; |
| 414 | private ParseComponentArgs mParseProviderArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | /** If set to true, we will only allow package files that exactly match |
| 417 | * the DTD. Otherwise, we try to get as much from the package as we |
| 418 | * can without failing. This should normally be set to false, to |
| 419 | * support extensions to the DTD in future versions. */ |
| 420 | private static final boolean RIGID_PARSER = false; |
| 421 | |
| 422 | private static final String TAG = "PackageParser"; |
| 423 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 424 | public PackageParser() { |
| 425 | mMetrics = new DisplayMetrics(); |
| 426 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 427 | } |
| 428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | public void setSeparateProcesses(String[] procs) { |
| 430 | mSeparateProcesses = procs; |
| 431 | } |
| 432 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Flag indicating this parser should only consider apps with |
| 435 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 436 | * creating a minimalist boot environment. |
| 437 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 438 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 439 | mOnlyCoreApps = onlyCoreApps; |
| 440 | } |
| 441 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 442 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 443 | mMetrics = metrics; |
| 444 | } |
| 445 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 446 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 447 | return isApkPath(file.getName()); |
| 448 | } |
| 449 | |
| 450 | private static boolean isApkPath(String path) { |
| 451 | return path.endsWith(".apk"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 456 | * |
| 457 | * @param p the parsed package. |
| 458 | * @param flags indicating which optional information is included. |
| 459 | */ |
| 460 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 461 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 462 | Set<String> grantedPermissions, PackageUserState state) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 464 | return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 465 | grantedPermissions, state, UserHandle.getCallingUserId()); |
| 466 | } |
| 467 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 468 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 469 | * Returns true if the package is installed and not hidden, or if the caller |
| 470 | * explicitly wanted all uninstalled and hidden packages as well. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 471 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 472 | private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state) { |
| 473 | return (state.installed && !state.hidden) |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 474 | || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 477 | public static boolean isAvailable(PackageUserState state) { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 478 | return checkUseInstalledOrHidden(0, state); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 479 | } |
| 480 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 481 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 482 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 483 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 484 | if (!checkUseInstalledOrHidden(flags, state) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 485 | return null; |
| 486 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | PackageInfo pi = new PackageInfo(); |
| 488 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 489 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | pi.versionCode = p.mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 491 | pi.baseRevisionCode = p.baseRevisionCode; |
| 492 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | pi.versionName = p.mVersionName; |
| 494 | pi.sharedUserId = p.mSharedUserId; |
| 495 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 496 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 497 | pi.installLocation = p.installLocation; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 498 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 499 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 500 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 501 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 502 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 503 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 504 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 505 | pi.overlayTarget = p.mOverlayTarget; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 506 | pi.firstInstallTime = firstInstallTime; |
| 507 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 509 | pi.gids = gids; |
| 510 | } |
| 511 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 512 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | if (N > 0) { |
| 514 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 515 | p.configPreferences.toArray(pi.configPreferences); |
| 516 | } |
| 517 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 518 | if (N > 0) { |
| 519 | pi.reqFeatures = new FeatureInfo[N]; |
| 520 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 522 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 523 | if (N > 0) { |
| 524 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 525 | p.featureGroups.toArray(pi.featureGroups); |
| 526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 528 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 529 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 531 | int num = 0; |
| 532 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 533 | for (int i = 0; i < N; i++) { |
| 534 | final Activity a = p.activities.get(i); |
| 535 | if (state.isMatch(a.info, flags)) { |
| 536 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 539 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | } |
| 541 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 542 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 543 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 545 | int num = 0; |
| 546 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 547 | for (int i = 0; i < N; i++) { |
| 548 | final Activity a = p.receivers.get(i); |
| 549 | if (state.isMatch(a.info, flags)) { |
| 550 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | } |
| 552 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 553 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | } |
| 555 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 556 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 557 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 559 | int num = 0; |
| 560 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 561 | for (int i = 0; i < N; i++) { |
| 562 | final Service s = p.services.get(i); |
| 563 | if (state.isMatch(s.info, flags)) { |
| 564 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 567 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | } |
| 569 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 570 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 571 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 573 | int num = 0; |
| 574 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 575 | for (int i = 0; i < N; i++) { |
| 576 | final Provider pr = p.providers.get(i); |
| 577 | if (state.isMatch(pr.info, flags)) { |
| 578 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 581 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 585 | int N = p.instrumentation.size(); |
| 586 | if (N > 0) { |
| 587 | pi.instrumentation = new InstrumentationInfo[N]; |
| 588 | for (int i=0; i<N; i++) { |
| 589 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 590 | p.instrumentation.get(i), flags); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 595 | int N = p.permissions.size(); |
| 596 | if (N > 0) { |
| 597 | pi.permissions = new PermissionInfo[N]; |
| 598 | for (int i=0; i<N; i++) { |
| 599 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 600 | } |
| 601 | } |
| 602 | N = p.requestedPermissions.size(); |
| 603 | if (N > 0) { |
| 604 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 605 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 607 | final String perm = p.requestedPermissions.get(i); |
| 608 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 609 | // The notion of required permissions is deprecated but for compatibility. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 610 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 611 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
| 612 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
| 613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | } |
| 617 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 618 | int N = (p.mSignatures != null) ? p.mSignatures.length : 0; |
| 619 | if (N > 0) { |
| 620 | pi.signatures = new Signature[N]; |
| 621 | System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | return pi; |
| 625 | } |
| 626 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 627 | private static Certificate[][] loadCertificates(StrictJarFile jarFile, ZipEntry entry) |
| 628 | throws PackageParserException { |
| 629 | InputStream is = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | try { |
| 631 | // We must read the stream for the JarEntry to retrieve |
| 632 | // its certificates. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 633 | is = jarFile.getInputStream(entry); |
| 634 | readFullyIgnoringContents(is); |
| 635 | return jarFile.getCertificateChains(entry); |
| 636 | } catch (IOException | RuntimeException e) { |
| 637 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 638 | "Failed reading " + entry.getName() + " in " + jarFile, e); |
| 639 | } finally { |
| 640 | IoUtils.closeQuietly(is); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 644 | public final static int PARSE_IS_SYSTEM = 1<<0; |
| 645 | public final static int PARSE_CHATTY = 1<<1; |
| 646 | public final static int PARSE_MUST_BE_APK = 1<<2; |
| 647 | public final static int PARSE_IGNORE_PROCESSES = 1<<3; |
| 648 | public final static int PARSE_FORWARD_LOCK = 1<<4; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 649 | public final static int PARSE_EXTERNAL_STORAGE = 1<<5; |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 650 | public final static int PARSE_IS_SYSTEM_DIR = 1<<6; |
Christopher Tate | ccbf84f | 2013-05-08 15:25:41 -0700 | [diff] [blame] | 651 | public final static int PARSE_IS_PRIVILEGED = 1<<7; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 652 | public final static int PARSE_COLLECT_CERTIFICATES = 1<<8; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 653 | public final static int PARSE_TRUSTED_OVERLAY = 1<<9; |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 654 | public final static int PARSE_ENFORCE_CODE = 1<<10; |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 655 | public final static int PARSE_IS_EPHEMERAL = 1<<11; |
Todd Kennedy | b107271 | 2016-04-26 15:41:20 -0700 | [diff] [blame] | 656 | public final static int PARSE_FORCE_SDK = 1<<12; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 657 | |
| 658 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 660 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 661 | * Used to sort a set of APKs based on their split names, always placing the |
| 662 | * base APK (with {@code null} split name) first. |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 663 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 664 | private static class SplitNameComparator implements Comparator<String> { |
| 665 | @Override |
| 666 | public int compare(String lhs, String rhs) { |
| 667 | if (lhs == null) { |
| 668 | return -1; |
| 669 | } else if (rhs == null) { |
| 670 | return 1; |
| 671 | } else { |
| 672 | return lhs.compareTo(rhs); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 677 | /** |
| 678 | * Parse only lightweight details about the package at the given location. |
| 679 | * Automatically detects if the package is a monolithic style (single APK |
| 680 | * file) or cluster style (directory of APKs). |
| 681 | * <p> |
| 682 | * This performs sanity checking on cluster style packages, such as |
| 683 | * requiring identical package name and version codes, a single base APK, |
| 684 | * and unique split names. |
| 685 | * |
| 686 | * @see PackageParser#parsePackage(File, int) |
| 687 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 688 | public static PackageLite parsePackageLite(File packageFile, int flags) |
| 689 | throws PackageParserException { |
| 690 | if (packageFile.isDirectory()) { |
| 691 | return parseClusterPackageLite(packageFile, flags); |
| 692 | } else { |
| 693 | return parseMonolithicPackageLite(packageFile, flags); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | private static PackageLite parseMonolithicPackageLite(File packageFile, int flags) |
| 698 | throws PackageParserException { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 699 | final ApkLite baseApk = parseApkLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 700 | final String packagePath = packageFile.getAbsolutePath(); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 701 | return new PackageLite(packagePath, baseApk, null, null, null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | private static PackageLite parseClusterPackageLite(File packageDir, int flags) |
| 705 | throws PackageParserException { |
| 706 | final File[] files = packageDir.listFiles(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 707 | if (ArrayUtils.isEmpty(files)) { |
| 708 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 709 | "No packages found in split"); |
| 710 | } |
| 711 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 712 | String packageName = null; |
| 713 | int versionCode = 0; |
| 714 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 715 | final ArrayMap<String, ApkLite> apks = new ArrayMap<>(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 716 | for (File file : files) { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 717 | if (isApkFile(file)) { |
| 718 | final ApkLite lite = parseApkLite(file, flags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 719 | |
| 720 | // Assert that all package names and version codes are |
| 721 | // consistent with the first one we encounter. |
| 722 | if (packageName == null) { |
| 723 | packageName = lite.packageName; |
| 724 | versionCode = lite.versionCode; |
| 725 | } else { |
| 726 | if (!packageName.equals(lite.packageName)) { |
| 727 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 728 | "Inconsistent package " + lite.packageName + " in " + file |
| 729 | + "; expected " + packageName); |
| 730 | } |
| 731 | if (versionCode != lite.versionCode) { |
| 732 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 733 | "Inconsistent version " + lite.versionCode + " in " + file |
| 734 | + "; expected " + versionCode); |
| 735 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 738 | // Assert that each split is defined only once |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 739 | if (apks.put(lite.splitName, lite) != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 740 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 741 | "Split name " + lite.splitName |
| 742 | + " defined more than once; most recent was " + file); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 747 | final ApkLite baseApk = apks.remove(null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 748 | if (baseApk == null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 749 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 750 | "Missing base APK in " + packageDir); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 753 | // Always apply deterministic ordering based on splitName |
| 754 | final int size = apks.size(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 755 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 756 | String[] splitNames = null; |
| 757 | String[] splitCodePaths = null; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 758 | int[] splitRevisionCodes = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 759 | if (size > 0) { |
| 760 | splitNames = new String[size]; |
| 761 | splitCodePaths = new String[size]; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 762 | splitRevisionCodes = new int[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 763 | |
| 764 | splitNames = apks.keySet().toArray(splitNames); |
| 765 | Arrays.sort(splitNames, sSplitNameComparator); |
| 766 | |
| 767 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 768 | splitCodePaths[i] = apks.get(splitNames[i]).codePath; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 769 | splitRevisionCodes[i] = apks.get(splitNames[i]).revisionCode; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 770 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 773 | final String codePath = packageDir.getAbsolutePath(); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 774 | return new PackageLite(codePath, baseApk, splitNames, splitCodePaths, |
| 775 | splitRevisionCodes); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 778 | /** |
| 779 | * Parse the package at the given location. Automatically detects if the |
| 780 | * package is a monolithic style (single APK file) or cluster style |
| 781 | * (directory of APKs). |
| 782 | * <p> |
| 783 | * This performs sanity checking on cluster style packages, such as |
| 784 | * requiring identical package name and version codes, a single base APK, |
| 785 | * and unique split names. |
| 786 | * <p> |
| 787 | * Note that this <em>does not</em> perform signature verification; that |
| 788 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 789 | * |
| 790 | * @see #parsePackageLite(File, int) |
| 791 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 792 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 793 | if (packageFile.isDirectory()) { |
| 794 | return parseClusterPackage(packageFile, flags); |
| 795 | } else { |
| 796 | return parseMonolithicPackage(packageFile, flags); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Parse all APKs contained in the given directory, treating them as a |
| 802 | * single package. This also performs sanity checking, such as requiring |
| 803 | * identical package name and version codes, a single base APK, and unique |
| 804 | * split names. |
| 805 | * <p> |
| 806 | * Note that this <em>does not</em> perform signature verification; that |
| 807 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 808 | */ |
| 809 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
| 810 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
| 811 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 812 | if (mOnlyCoreApps && !lite.coreApp) { |
| 813 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 814 | "Not a coreApp: " + packageDir); |
| 815 | } |
| 816 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 817 | final AssetManager assets = new AssetManager(); |
| 818 | try { |
| 819 | // Load the base and all splits into the AssetManager |
| 820 | // so that resources can be overriden when parsing the manifests. |
| 821 | loadApkIntoAssetManager(assets, lite.baseCodePath, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 822 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 823 | if (!ArrayUtils.isEmpty(lite.splitCodePaths)) { |
| 824 | for (String path : lite.splitCodePaths) { |
| 825 | loadApkIntoAssetManager(assets, path, flags); |
| 826 | } |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 827 | } |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 828 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 829 | final File baseApk = new File(lite.baseCodePath); |
| 830 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 831 | if (pkg == null) { |
| 832 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 833 | "Failed to parse base APK: " + baseApk); |
| 834 | } |
| 835 | |
| 836 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 837 | final int num = lite.splitNames.length; |
| 838 | pkg.splitNames = lite.splitNames; |
| 839 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 840 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 841 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 842 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 843 | |
| 844 | for (int i = 0; i < num; i++) { |
| 845 | parseSplitApk(pkg, i, assets, flags); |
| 846 | } |
| 847 | } |
| 848 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 849 | pkg.setCodePath(packageDir.getAbsolutePath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 850 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 851 | return pkg; |
| 852 | } finally { |
| 853 | IoUtils.closeQuietly(assets); |
| 854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 857 | /** |
| 858 | * Parse the given APK file, treating it as as a single monolithic package. |
| 859 | * <p> |
| 860 | * Note that this <em>does not</em> perform signature verification; that |
| 861 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 862 | * |
| 863 | * @deprecated external callers should move to |
| 864 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 865 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 866 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 867 | @Deprecated |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 868 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 869 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 870 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 871 | if (!lite.coreApp) { |
| 872 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 873 | "Not a coreApp: " + apkFile); |
| 874 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 875 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 876 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 877 | final AssetManager assets = new AssetManager(); |
| 878 | try { |
| 879 | final Package pkg = parseBaseApk(apkFile, assets, flags); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 880 | pkg.setCodePath(apkFile.getAbsolutePath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 881 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 882 | return pkg; |
| 883 | } finally { |
| 884 | IoUtils.closeQuietly(assets); |
| 885 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 888 | private static int loadApkIntoAssetManager(AssetManager assets, String apkPath, int flags) |
| 889 | throws PackageParserException { |
| 890 | if ((flags & PARSE_MUST_BE_APK) != 0 && !isApkPath(apkPath)) { |
| 891 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 892 | "Invalid package file: " + apkPath); |
| 893 | } |
| 894 | |
| 895 | // The AssetManager guarantees uniqueness for asset paths, so if this asset path |
| 896 | // already exists in the AssetManager, addAssetPath will only return the cookie |
| 897 | // assigned to it. |
| 898 | int cookie = assets.addAssetPath(apkPath); |
| 899 | if (cookie == 0) { |
| 900 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 901 | "Failed adding asset path: " + apkPath); |
| 902 | } |
| 903 | return cookie; |
| 904 | } |
| 905 | |
| 906 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 907 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 908 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 909 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 910 | String volumeUuid = null; |
| 911 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 912 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 913 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 914 | } |
| 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 917 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 918 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 919 | 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] | 920 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 921 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 922 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 923 | Resources res = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 924 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 926 | res = new Resources(assets, mMetrics, null); |
| 927 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 928 | Build.VERSION.RESOURCES_SDK_INT); |
| 929 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
| 930 | |
| 931 | final String[] outError = new String[1]; |
| 932 | final Package pkg = parseBaseApk(res, parser, flags, outError); |
| 933 | if (pkg == null) { |
| 934 | throw new PackageParserException(mParseError, |
| 935 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 937 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 938 | pkg.setVolumeUuid(volumeUuid); |
| 939 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 940 | pkg.setBaseCodePath(apkPath); |
| 941 | pkg.setSignatures(null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 942 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 943 | return pkg; |
| 944 | |
| 945 | } catch (PackageParserException e) { |
| 946 | throw e; |
| 947 | } catch (Exception e) { |
| 948 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 949 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 950 | } finally { |
| 951 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } |
| 954 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 955 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 956 | throws PackageParserException { |
| 957 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 958 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 959 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 960 | mArchiveSourcePath = apkPath; |
| 961 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 962 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 963 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 964 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 965 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 966 | Resources res = null; |
| 967 | XmlResourceParser parser = null; |
| 968 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 969 | res = new Resources(assets, mMetrics, null); |
| 970 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 971 | Build.VERSION.RESOURCES_SDK_INT); |
| 972 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
| 973 | |
| 974 | final String[] outError = new String[1]; |
| 975 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 976 | if (pkg == null) { |
| 977 | throw new PackageParserException(mParseError, |
| 978 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 979 | } |
| 980 | |
| 981 | } catch (PackageParserException e) { |
| 982 | throw e; |
| 983 | } catch (Exception e) { |
| 984 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 985 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 986 | } finally { |
| 987 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Parse the manifest of a <em>split APK</em>. |
| 993 | * <p> |
| 994 | * Note that split APKs have many more restrictions on what they're capable |
| 995 | * of doing, so many valid features of a base APK have been carefully |
| 996 | * omitted here. |
| 997 | */ |
| 998 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 999 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1000 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1001 | AttributeSet attrs = parser; |
| 1002 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1003 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1004 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1005 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1006 | mParseInstrumentationArgs = null; |
| 1007 | mParseActivityArgs = null; |
| 1008 | mParseServiceArgs = null; |
| 1009 | mParseProviderArgs = null; |
| 1010 | |
| 1011 | int type; |
| 1012 | |
| 1013 | boolean foundApp = false; |
| 1014 | |
| 1015 | int outerDepth = parser.getDepth(); |
| 1016 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1017 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1018 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1019 | continue; |
| 1020 | } |
| 1021 | |
| 1022 | String tagName = parser.getName(); |
| 1023 | if (tagName.equals("application")) { |
| 1024 | if (foundApp) { |
| 1025 | if (RIGID_PARSER) { |
| 1026 | outError[0] = "<manifest> has more than one <application>"; |
| 1027 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1028 | return null; |
| 1029 | } else { |
| 1030 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1031 | XmlUtils.skipCurrentTag(parser); |
| 1032 | continue; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1037 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1038 | return null; |
| 1039 | } |
| 1040 | |
| 1041 | } else if (RIGID_PARSER) { |
| 1042 | outError[0] = "Bad element under <manifest>: " |
| 1043 | + parser.getName(); |
| 1044 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1045 | return null; |
| 1046 | |
| 1047 | } else { |
| 1048 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1049 | + " at " + mArchiveSourcePath + " " |
| 1050 | + parser.getPositionDescription()); |
| 1051 | XmlUtils.skipCurrentTag(parser); |
| 1052 | continue; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | if (!foundApp) { |
| 1057 | outError[0] = "<manifest> does not contain an <application>"; |
| 1058 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1059 | } |
| 1060 | |
| 1061 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1064 | public static int getApkSigningVersion(Package pkg) { |
| 1065 | try { |
| 1066 | if (ApkSignatureSchemeV2Verifier.hasSignature(pkg.baseCodePath)) { |
| 1067 | return APK_SIGNING_V2; |
| 1068 | } |
| 1069 | return APK_SIGNING_V1; |
| 1070 | } catch (IOException e) { |
| 1071 | } |
| 1072 | return APK_SIGNING_UNKNOWN; |
| 1073 | } |
| 1074 | |
Kenny Root | 6c918ce | 2013-04-02 14:04:24 -0700 | [diff] [blame] | 1075 | /** |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1076 | * Populates the correct packages fields with the given certificates. |
| 1077 | * <p> |
| 1078 | * This is useful when we've already processed the certificates [such as during package |
| 1079 | * installation through an installer session]. We don't re-process the archive and |
| 1080 | * simply populate the correct fields. |
| 1081 | */ |
| 1082 | public static void populateCertificates(Package pkg, Certificate[][] certificates) |
| 1083 | throws PackageParserException { |
| 1084 | pkg.mCertificates = null; |
| 1085 | pkg.mSignatures = null; |
| 1086 | pkg.mSigningKeys = null; |
| 1087 | |
| 1088 | pkg.mCertificates = certificates; |
| 1089 | try { |
| 1090 | pkg.mSignatures = convertToSignatures(certificates); |
| 1091 | } catch (CertificateEncodingException e) { |
| 1092 | // certificates weren't encoded properly; something went wrong |
| 1093 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1094 | "Failed to collect certificates from " + pkg.baseCodePath, e); |
| 1095 | } |
| 1096 | pkg.mSigningKeys = new ArraySet<>(certificates.length); |
| 1097 | for (int i = 0; i < certificates.length; i++) { |
| 1098 | Certificate[] signerCerts = certificates[i]; |
| 1099 | Certificate signerCert = signerCerts[0]; |
| 1100 | pkg.mSigningKeys.add(signerCert.getPublicKey()); |
| 1101 | } |
| 1102 | // add signatures to child packages |
| 1103 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1104 | for (int i = 0; i < childCount; i++) { |
| 1105 | Package childPkg = pkg.childPackages.get(i); |
| 1106 | childPkg.mCertificates = pkg.mCertificates; |
| 1107 | childPkg.mSignatures = pkg.mSignatures; |
| 1108 | childPkg.mSigningKeys = pkg.mSigningKeys; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1113 | * Collect certificates from all the APKs described in the given package, |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 1114 | * populating {@link Package#mSignatures}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1115 | * contents are signed correctly and consistently. |
| 1116 | */ |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1117 | public static void collectCertificates(Package pkg, int parseFlags) |
| 1118 | throws PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1119 | collectCertificatesInternal(pkg, parseFlags); |
| 1120 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1121 | for (int i = 0; i < childCount; i++) { |
| 1122 | Package childPkg = pkg.childPackages.get(i); |
| 1123 | childPkg.mCertificates = pkg.mCertificates; |
| 1124 | childPkg.mSignatures = pkg.mSignatures; |
| 1125 | childPkg.mSigningKeys = pkg.mSigningKeys; |
| 1126 | } |
| 1127 | } |
| 1128 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1129 | private static void collectCertificatesInternal(Package pkg, int parseFlags) |
| 1130 | throws PackageParserException { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1131 | pkg.mCertificates = null; |
| 1132 | pkg.mSignatures = null; |
| 1133 | pkg.mSigningKeys = null; |
| 1134 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1135 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1136 | try { |
Todd Kennedy | f720a9d | 2016-04-15 09:44:36 -0700 | [diff] [blame] | 1137 | collectCertificates(pkg, new File(pkg.baseCodePath), parseFlags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1138 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1139 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
| 1140 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
Todd Kennedy | f720a9d | 2016-04-15 09:44:36 -0700 | [diff] [blame] | 1141 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), parseFlags); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1142 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1143 | } |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1144 | } finally { |
| 1145 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | |
Todd Kennedy | f720a9d | 2016-04-15 09:44:36 -0700 | [diff] [blame] | 1149 | private static void collectCertificates(Package pkg, File apkFile, int parseFlags) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1150 | throws PackageParserException { |
| 1151 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1153 | // Try to verify the APK using APK Signature Scheme v2. |
| 1154 | boolean verified = false; |
| 1155 | { |
| 1156 | Certificate[][] allSignersCerts = null; |
| 1157 | Signature[] signatures = null; |
| 1158 | try { |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1159 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "verifyV2"); |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1160 | allSignersCerts = ApkSignatureSchemeV2Verifier.verify(apkPath); |
| 1161 | signatures = convertToSignatures(allSignersCerts); |
| 1162 | // APK verified using APK Signature Scheme v2. |
| 1163 | verified = true; |
| 1164 | } catch (ApkSignatureSchemeV2Verifier.SignatureNotFoundException e) { |
| 1165 | // No APK Signature Scheme v2 signature found |
| 1166 | } catch (Exception e) { |
| 1167 | // APK Signature Scheme v2 signature was found but did not verify |
| 1168 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1169 | "Failed to collect certificates from " + apkPath |
| 1170 | + " using APK Signature Scheme v2", |
| 1171 | e); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1172 | } finally { |
| 1173 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | if (verified) { |
| 1177 | if (pkg.mCertificates == null) { |
| 1178 | pkg.mCertificates = allSignersCerts; |
| 1179 | pkg.mSignatures = signatures; |
| 1180 | pkg.mSigningKeys = new ArraySet<>(allSignersCerts.length); |
| 1181 | for (int i = 0; i < allSignersCerts.length; i++) { |
| 1182 | Certificate[] signerCerts = allSignersCerts[i]; |
| 1183 | Certificate signerCert = signerCerts[0]; |
| 1184 | pkg.mSigningKeys.add(signerCert.getPublicKey()); |
| 1185 | } |
| 1186 | } else { |
| 1187 | if (!Signature.areExactMatch(pkg.mSignatures, signatures)) { |
| 1188 | throw new PackageParserException( |
| 1189 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1190 | apkPath + " has mismatched certificates"); |
| 1191 | } |
| 1192 | } |
| 1193 | // Not yet done, because we need to confirm that AndroidManifest.xml exists and, |
| 1194 | // if requested, that classes.dex exists. |
| 1195 | } |
| 1196 | } |
| 1197 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1198 | StrictJarFile jarFile = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | try { |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1200 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "strictJarFileCtor"); |
Alex Klyubin | 9b59bc4 | 2016-03-24 12:02:20 -0700 | [diff] [blame] | 1201 | // Ignore signature stripping protections when verifying APKs from system partition. |
| 1202 | // For those APKs we only care about extracting signer certificates, and don't care |
| 1203 | // about verifying integrity. |
| 1204 | boolean signatureSchemeRollbackProtectionsEnforced = |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 1205 | (parseFlags & PARSE_IS_SYSTEM_DIR) == 0; |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1206 | jarFile = new StrictJarFile( |
| 1207 | apkPath, |
Alex Klyubin | 9b59bc4 | 2016-03-24 12:02:20 -0700 | [diff] [blame] | 1208 | !verified, // whether to verify JAR signature |
| 1209 | signatureSchemeRollbackProtectionsEnforced); |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1210 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1212 | // Always verify manifest, regardless of source |
| 1213 | final ZipEntry manifestEntry = jarFile.findEntry(ANDROID_MANIFEST_FILENAME); |
| 1214 | if (manifestEntry == null) { |
| 1215 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1216 | "Package " + apkPath + " has no manifest"); |
| 1217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1219 | // Optimization: early termination when APK already verified |
| 1220 | if (verified) { |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | // APK's integrity needs to be verified using JAR signature scheme. |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1225 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "verifyV1"); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1226 | final List<ZipEntry> toVerify = new ArrayList<>(); |
| 1227 | toVerify.add(manifestEntry); |
| 1228 | |
| 1229 | // If we're parsing an untrusted package, verify all contents |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 1230 | if ((parseFlags & PARSE_IS_SYSTEM_DIR) == 0) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1231 | final Iterator<ZipEntry> i = jarFile.iterator(); |
| 1232 | while (i.hasNext()) { |
| 1233 | final ZipEntry entry = i.next(); |
| 1234 | |
| 1235 | if (entry.isDirectory()) continue; |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 1236 | |
| 1237 | final String entryName = entry.getName(); |
| 1238 | if (entryName.startsWith("META-INF/")) continue; |
| 1239 | if (entryName.equals(ANDROID_MANIFEST_FILENAME)) continue; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1240 | |
| 1241 | toVerify.add(entry); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | // Verify that entries are signed consistently with the first entry |
| 1246 | // we encountered. Note that for splits, certificates may have |
| 1247 | // already been populated during an earlier parse of a base APK. |
| 1248 | for (ZipEntry entry : toVerify) { |
| 1249 | final Certificate[][] entryCerts = loadCertificates(jarFile, entry); |
| 1250 | if (ArrayUtils.isEmpty(entryCerts)) { |
| 1251 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1252 | "Package " + apkPath + " has no certificates at entry " |
| 1253 | + entry.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | } |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1255 | final Signature[] entrySignatures = convertToSignatures(entryCerts); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1256 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1257 | if (pkg.mCertificates == null) { |
| 1258 | pkg.mCertificates = entryCerts; |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1259 | pkg.mSignatures = entrySignatures; |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 1260 | pkg.mSigningKeys = new ArraySet<PublicKey>(); |
| 1261 | for (int i=0; i < entryCerts.length; i++) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1262 | pkg.mSigningKeys.add(entryCerts[i][0].getPublicKey()); |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 1263 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1264 | } else { |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1265 | if (!Signature.areExactMatch(pkg.mSignatures, entrySignatures)) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1266 | throw new PackageParserException( |
| 1267 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, "Package " + apkPath |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | + " has mismatched certificates at entry " |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1269 | + entry.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | } |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1273 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | bc09755 | 2014-09-09 14:57:26 -0700 | [diff] [blame] | 1274 | } catch (GeneralSecurityException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1275 | throw new PackageParserException(INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING, |
| 1276 | "Failed to collect certificates from " + apkPath, e); |
Jeff Sharkey | bc09755 | 2014-09-09 14:57:26 -0700 | [diff] [blame] | 1277 | } catch (IOException | RuntimeException e) { |
| 1278 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1279 | "Failed to collect certificates from " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1280 | } finally { |
| 1281 | closeQuietly(jarFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | } |
| 1284 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1285 | private static Signature[] convertToSignatures(Certificate[][] certs) |
| 1286 | throws CertificateEncodingException { |
| 1287 | final Signature[] res = new Signature[certs.length]; |
| 1288 | for (int i = 0; i < certs.length; i++) { |
| 1289 | res[i] = new Signature(certs[i]); |
| 1290 | } |
| 1291 | return res; |
| 1292 | } |
| 1293 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1294 | /** |
| 1295 | * Utility method that retrieves lightweight details about a single APK |
| 1296 | * file, including package name, split name, and install location. |
| 1297 | * |
| 1298 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1299 | * @param flags optional parse flags, such as |
| 1300 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1301 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1302 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1303 | throws PackageParserException { |
| 1304 | final String apkPath = apkFile.getAbsolutePath(); |
| 1305 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1306 | AssetManager assets = null; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1307 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1309 | assets = new AssetManager(); |
| 1310 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1311 | Build.VERSION.RESOURCES_SDK_INT); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1312 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1313 | int cookie = assets.addAssetPath(apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1314 | if (cookie == 0) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1315 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1316 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1319 | final DisplayMetrics metrics = new DisplayMetrics(); |
| 1320 | metrics.setToDefaults(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1321 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1322 | final Resources res = new Resources(assets, metrics, null); |
| 1323 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1324 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1325 | final Signature[] signatures; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1326 | final Certificate[][] certificates; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1327 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1328 | // TODO: factor signature related items out of Package object |
| 1329 | final Package tempPkg = new Package(null); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1330 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates"); |
| 1331 | try { |
Todd Kennedy | f720a9d | 2016-04-15 09:44:36 -0700 | [diff] [blame] | 1332 | collectCertificates(tempPkg, apkFile, 0 /*parseFlags*/); |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 1333 | } finally { |
| 1334 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1335 | } |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1336 | signatures = tempPkg.mSignatures; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1337 | certificates = tempPkg.mCertificates; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1338 | } else { |
| 1339 | signatures = null; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1340 | certificates = null; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1341 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1342 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1343 | final AttributeSet attrs = parser; |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1344 | return parseApkLite(apkPath, res, parser, attrs, flags, signatures, certificates); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1345 | |
| 1346 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
| 1347 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1348 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1350 | IoUtils.closeQuietly(parser); |
| 1351 | IoUtils.closeQuietly(assets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1355 | private static String validateName(String name, boolean requireSeparator, |
| 1356 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | final int N = name.length(); |
| 1358 | boolean hasSep = false; |
| 1359 | boolean front = true; |
| 1360 | for (int i=0; i<N; i++) { |
| 1361 | final char c = name.charAt(i); |
| 1362 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1363 | front = false; |
| 1364 | continue; |
| 1365 | } |
| 1366 | if (!front) { |
| 1367 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1368 | continue; |
| 1369 | } |
| 1370 | } |
| 1371 | if (c == '.') { |
| 1372 | hasSep = true; |
| 1373 | front = true; |
| 1374 | continue; |
| 1375 | } |
| 1376 | return "bad character '" + c + "'"; |
| 1377 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1378 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1379 | return "Invalid filename"; |
| 1380 | } |
| 1381 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | ? null : "must have at least one '.' separator"; |
| 1383 | } |
| 1384 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1385 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1386 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1387 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | |
| 1389 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1390 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1391 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1394 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1395 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1396 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1398 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1399 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1400 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1403 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1404 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1405 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1406 | if (error != null) { |
| 1407 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1408 | "Invalid manifest package: " + error); |
| 1409 | } |
| 1410 | } |
| 1411 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1412 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1413 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1414 | if (splitName.length() == 0) { |
| 1415 | splitName = null; |
| 1416 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1417 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1418 | if (error != null) { |
| 1419 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1420 | "Invalid manifest split: " + error); |
| 1421 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | return Pair.create(packageName.intern(), |
| 1426 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 1429 | private static ApkLite parseApkLite(String codePath, Resources res, XmlPullParser parser, |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1430 | AttributeSet attrs, int flags, Signature[] signatures, Certificate[][] certificates) |
| 1431 | throws IOException, XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1432 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1433 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1434 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1435 | int versionCode = 0; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1436 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1437 | boolean coreApp = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1438 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1439 | boolean use32bitAbi = false; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1440 | boolean extractNativeLibs = true; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1441 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1442 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1443 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1444 | if (attr.equals("installLocation")) { |
| 1445 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1446 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1447 | } else if (attr.equals("versionCode")) { |
| 1448 | versionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1449 | } else if (attr.equals("revisionCode")) { |
| 1450 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1451 | } else if (attr.equals("coreApp")) { |
| 1452 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1453 | } |
| 1454 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1455 | |
| 1456 | // Only search the tree when the tag is directly below <manifest> |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1457 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1458 | final int searchDepth = parser.getDepth() + 1; |
| 1459 | |
| 1460 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1461 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1462 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1463 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1464 | continue; |
| 1465 | } |
| 1466 | |
| 1467 | if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1468 | final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1469 | if (verifier != null) { |
| 1470 | verifiers.add(verifier); |
| 1471 | } |
| 1472 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1473 | |
| 1474 | if (parser.getDepth() == searchDepth && "application".equals(parser.getName())) { |
| 1475 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1476 | final String attr = attrs.getAttributeName(i); |
| 1477 | if ("multiArch".equals(attr)) { |
| 1478 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1479 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1480 | if ("use32bitAbi".equals(attr)) { |
| 1481 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1482 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1483 | if ("extractNativeLibs".equals(attr)) { |
| 1484 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 1490 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, versionCode, |
Todd Kennedy | d9d438a | 2016-04-06 14:08:14 -0700 | [diff] [blame] | 1491 | revisionCode, installLocation, verifiers, signatures, certificates, coreApp, |
| 1492 | multiArch, use32bitAbi, extractNativeLibs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1493 | } |
| 1494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | /** |
| 1496 | * Temporary. |
| 1497 | */ |
| 1498 | static public Signature stringToSignature(String str) { |
| 1499 | final int N = str.length(); |
| 1500 | byte[] sig = new byte[N]; |
| 1501 | for (int i=0; i<N; i++) { |
| 1502 | sig[i] = (byte)str.charAt(i); |
| 1503 | } |
| 1504 | return new Signature(sig); |
| 1505 | } |
| 1506 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1507 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1508 | * Parses a child package and adds it to the parent if successful. If you add |
| 1509 | * new tags that need to be supported by child packages make sure to add them |
| 1510 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1511 | * |
| 1512 | * @param parentPkg The parent that contains the child |
| 1513 | * @param res Resources against which to resolve values |
| 1514 | * @param parser Parser of the manifest |
| 1515 | * @param flags Flags about how to parse |
| 1516 | * @param outError Human readable error if parsing fails |
| 1517 | * @return True of parsing succeeded. |
| 1518 | * |
| 1519 | * @throws XmlPullParserException |
| 1520 | * @throws IOException |
| 1521 | */ |
| 1522 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1523 | int flags, String[] outError) throws XmlPullParserException, IOException { |
| 1524 | // Let ppl not abuse this mechanism by limiting the packages per APK |
| 1525 | if (parentPkg.childPackages != null && parentPkg.childPackages.size() + 2 |
| 1526 | > MAX_PACKAGES_PER_APK) { |
| 1527 | outError[0] = "Maximum number of packages per APK is: " + MAX_PACKAGES_PER_APK; |
| 1528 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
| 1532 | // Make sure we have a valid child package name |
| 1533 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1534 | if (validateName(childPackageName, true, false) != null) { |
| 1535 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | // Child packages must be unique |
| 1540 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1541 | String message = "Child package name cannot be equal to parent package name: " |
| 1542 | + parentPkg.packageName; |
| 1543 | Slog.w(TAG, message); |
| 1544 | outError[0] = message; |
| 1545 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1546 | return false; |
| 1547 | } |
| 1548 | |
| 1549 | // Child packages must be unique |
| 1550 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1551 | String message = "Duplicate child package:" + childPackageName; |
| 1552 | Slog.w(TAG, message); |
| 1553 | outError[0] = message; |
| 1554 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
| 1558 | // Go ahead and parse the child |
| 1559 | Package childPkg = new Package(childPackageName); |
| 1560 | |
| 1561 | // Child package inherits parent version code/name/target SDK |
| 1562 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1563 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1564 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1565 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1566 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1567 | |
| 1568 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1569 | if (childPkg == null) { |
| 1570 | // If we got null then error was set during child parsing |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
| 1574 | // Set the parent-child relation |
| 1575 | if (parentPkg.childPackages == null) { |
| 1576 | parentPkg.childPackages = new ArrayList<>(); |
| 1577 | } |
| 1578 | parentPkg.childPackages.add(childPkg); |
| 1579 | childPkg.parentPackage = parentPkg; |
| 1580 | |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1586 | * need to consider whether they should be supported by split APKs and child |
| 1587 | * packages. |
| 1588 | * |
| 1589 | * @param res The resources from which to resolve values |
| 1590 | * @param parser The manifest parser |
| 1591 | * @param flags Flags how to parse |
| 1592 | * @param outError Human readable error message |
| 1593 | * @return Parsed package or null on error. |
| 1594 | * |
| 1595 | * @throws XmlPullParserException |
| 1596 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1597 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1598 | private Package parseBaseApk(Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1599 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1600 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1601 | final String pkgName; |
| 1602 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1603 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1604 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1605 | pkgName = packageSplit.first; |
| 1606 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1607 | |
| 1608 | if (!TextUtils.isEmpty(splitName)) { |
| 1609 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1610 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1611 | return null; |
| 1612 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1613 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1615 | return null; |
| 1616 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1617 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1618 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1619 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1620 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1622 | |
Dianne Hackborn | 8472e61 | 2014-01-23 17:57:20 -0800 | [diff] [blame] | 1623 | pkg.mVersionCode = pkg.applicationInfo.versionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1625 | pkg.baseRevisionCode = sa.getInteger( |
| 1626 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1627 | pkg.mVersionName = sa.getNonConfigurationString( |
| 1628 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | if (pkg.mVersionName != null) { |
| 1630 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 1631 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1632 | |
| 1633 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 1634 | |
| 1635 | sa.recycle(); |
| 1636 | |
| 1637 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * This is the common parsing routing for handling parent and child |
| 1642 | * packages in a base APK. The difference between parent and child |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1643 | * parsing is that some tags are not supported by child packages as |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1644 | * well as some manifest attributes are ignored. The implementation |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 1645 | * assumes the calling code has already handled the manifest tag if needed |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1646 | * (this applies to the parent only). |
| 1647 | * |
| 1648 | * @param pkg The package which to populate |
| 1649 | * @param acceptedTags Which tags to handle, null to handle all |
| 1650 | * @param res Resources against which to resolve values |
| 1651 | * @param parser Parser of the manifest |
| 1652 | * @param flags Flags about how to parse |
| 1653 | * @param outError Human readable error if parsing fails |
| 1654 | * @return The package if parsing succeeded or null. |
| 1655 | * |
| 1656 | * @throws XmlPullParserException |
| 1657 | * @throws IOException |
| 1658 | */ |
| 1659 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 1660 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 1661 | IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1662 | mParseInstrumentationArgs = null; |
| 1663 | mParseActivityArgs = null; |
| 1664 | mParseServiceArgs = null; |
| 1665 | mParseProviderArgs = null; |
| 1666 | |
| 1667 | int type; |
| 1668 | boolean foundApp = false; |
| 1669 | |
| 1670 | TypedArray sa = res.obtainAttributes(parser, |
| 1671 | com.android.internal.R.styleable.AndroidManifest); |
| 1672 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1673 | String str = sa.getNonConfigurationString( |
| 1674 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 1675 | if (str != null && str.length() > 0) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1676 | String nameError = validateName(str, true, false); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1677 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 1679 | + str + "\": " + nameError; |
| 1680 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 1681 | return null; |
| 1682 | } |
| 1683 | pkg.mSharedUserId = str.intern(); |
| 1684 | pkg.mSharedUserLabel = sa.getResourceId( |
| 1685 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 1686 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 1687 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 1688 | pkg.installLocation = sa.getInteger( |
| 1689 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1690 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1691 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1692 | |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 1693 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1694 | /* Set the global "forward lock" flag */ |
| 1695 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1696 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1700 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1701 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 1702 | } |
| 1703 | |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 1704 | if ((flags & PARSE_IS_EPHEMERAL) != 0) { |
| 1705 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_EPHEMERAL; |
| 1706 | } |
| 1707 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1708 | // Resource boolean are -1, so 1 means we don't know the value. |
| 1709 | int supportsSmallScreens = 1; |
| 1710 | int supportsNormalScreens = 1; |
| 1711 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1712 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1713 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1714 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1717 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1718 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1719 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | continue; |
| 1721 | } |
| 1722 | |
| 1723 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1724 | |
| 1725 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 1726 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 1727 | + tagName + " at " + mArchiveSourcePath + " " |
| 1728 | + parser.getPositionDescription()); |
| 1729 | XmlUtils.skipCurrentTag(parser); |
| 1730 | continue; |
| 1731 | } |
| 1732 | |
| 1733 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | if (foundApp) { |
| 1735 | if (RIGID_PARSER) { |
| 1736 | outError[0] = "<manifest> has more than one <application>"; |
| 1737 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1738 | return null; |
| 1739 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1740 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | XmlUtils.skipCurrentTag(parser); |
| 1742 | continue; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1747 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1748 | return null; |
| 1749 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1750 | } else if (tagName.equals(TAG_OVERLAY)) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1751 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1752 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 1753 | pkg.mOverlayTarget = sa.getString( |
| 1754 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
| 1755 | pkg.mOverlayPriority = sa.getInt( |
| 1756 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 1757 | -1); |
| 1758 | sa.recycle(); |
| 1759 | |
| 1760 | if (pkg.mOverlayTarget == null) { |
| 1761 | outError[0] = "<overlay> does not specify a target package"; |
| 1762 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1763 | return null; |
| 1764 | } |
| 1765 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 1766 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 1767 | mParseError = |
| 1768 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1769 | return null; |
| 1770 | } |
| 1771 | XmlUtils.skipCurrentTag(parser); |
| 1772 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1773 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 1774 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 1775 | return null; |
| 1776 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1777 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
| 1778 | if (parsePermissionGroup(pkg, flags, res, parser, outError) == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1779 | return null; |
| 1780 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1781 | } else if (tagName.equals(TAG_PERMISSION)) { |
| 1782 | if (parsePermission(pkg, res, parser, outError) == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | return null; |
| 1784 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1785 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
| 1786 | if (parsePermissionTree(pkg, res, parser, outError) == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | return null; |
| 1788 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1789 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
| 1790 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 1791 | return null; |
| 1792 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1793 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 1794 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
| 1795 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 1796 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1798 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1800 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 1802 | cPref.reqTouchScreen = sa.getInt( |
| 1803 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 1804 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 1805 | cPref.reqKeyboardType = sa.getInt( |
| 1806 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 1807 | Configuration.KEYBOARD_UNDEFINED); |
| 1808 | if (sa.getBoolean( |
| 1809 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 1810 | false)) { |
| 1811 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 1812 | } |
| 1813 | cPref.reqNavigation = sa.getInt( |
| 1814 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 1815 | Configuration.NAVIGATION_UNDEFINED); |
| 1816 | if (sa.getBoolean( |
| 1817 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 1818 | false)) { |
| 1819 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 1820 | } |
| 1821 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1822 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | |
| 1824 | XmlUtils.skipCurrentTag(parser); |
| 1825 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1826 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 1827 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1828 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 1829 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1830 | if (fi.name == null) { |
| 1831 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 1832 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1833 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1834 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 1835 | |
| 1836 | XmlUtils.skipCurrentTag(parser); |
| 1837 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1838 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1839 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 1840 | ArrayList<FeatureInfo> features = null; |
| 1841 | final int innerDepth = parser.getDepth(); |
| 1842 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1843 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 1844 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1845 | continue; |
| 1846 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 1847 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1848 | final String innerTagName = parser.getName(); |
| 1849 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1850 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1851 | // FeatureGroups are stricter and mandate that |
| 1852 | // any <uses-feature> declared are mandatory. |
| 1853 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 1854 | features = ArrayUtils.add(features, featureInfo); |
| 1855 | } else { |
| 1856 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 1857 | " at " + mArchiveSourcePath + " " + |
| 1858 | parser.getPositionDescription()); |
| 1859 | } |
| 1860 | XmlUtils.skipCurrentTag(parser); |
| 1861 | } |
| 1862 | |
| 1863 | if (features != null) { |
| 1864 | group.features = new FeatureInfo[features.size()]; |
| 1865 | group.features = features.toArray(group.features); |
| 1866 | } |
| 1867 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 1868 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1869 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1870 | if (SDK_VERSION > 0) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1871 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 1873 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1874 | int minVers = 0; |
| 1875 | String minCode = null; |
| 1876 | int targetVers = 0; |
| 1877 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1878 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1879 | TypedValue val = sa.peekValue( |
| 1880 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 1881 | if (val != null) { |
| 1882 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 1883 | targetCode = minCode = val.string.toString(); |
| 1884 | } else { |
| 1885 | // If it's not a string, it's an integer. |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1886 | targetVers = minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1887 | } |
| 1888 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1889 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1890 | val = sa.peekValue( |
| 1891 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 1892 | if (val != null) { |
| 1893 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1894 | targetCode = val.string.toString(); |
| 1895 | if (minCode == null) { |
| 1896 | minCode = targetCode; |
| 1897 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1898 | } else { |
| 1899 | // If it's not a string, it's an integer. |
| 1900 | targetVers = val.data; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1901 | if (minVers == 0) { |
| 1902 | minVers = targetVers; |
| 1903 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1904 | } |
| 1905 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | sa.recycle(); |
| 1908 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1909 | if (minCode != null) { |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1910 | boolean allowedCodename = false; |
| 1911 | for (String codename : SDK_CODENAMES) { |
| 1912 | if (minCode.equals(codename)) { |
| 1913 | allowedCodename = true; |
| 1914 | break; |
| 1915 | } |
| 1916 | } |
| 1917 | if (!allowedCodename) { |
| 1918 | if (SDK_CODENAMES.length > 0) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1919 | outError[0] = "Requires development platform " + minCode |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1920 | + " (current platform is any of " |
| 1921 | + Arrays.toString(SDK_CODENAMES) + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1922 | } else { |
| 1923 | outError[0] = "Requires development platform " + minCode |
| 1924 | + " but this is a release platform."; |
| 1925 | } |
| 1926 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1927 | return null; |
| 1928 | } |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1929 | pkg.applicationInfo.minSdkVersion = minCode; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1930 | } else if (minVers > SDK_VERSION) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1931 | outError[0] = "Requires newer sdk version #" + minVers |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1932 | + " (current version is #" + SDK_VERSION + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1933 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1934 | return null; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1935 | } else { |
| 1936 | pkg.applicationInfo.minSdkVersion = Integer.toString(minVers); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1937 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1938 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1939 | if (targetCode != null) { |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1940 | boolean allowedCodename = false; |
| 1941 | for (String codename : SDK_CODENAMES) { |
| 1942 | if (targetCode.equals(codename)) { |
| 1943 | allowedCodename = true; |
| 1944 | break; |
| 1945 | } |
| 1946 | } |
| 1947 | if (!allowedCodename) { |
| 1948 | if (SDK_CODENAMES.length > 0) { |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1949 | outError[0] = "Requires development platform " + targetCode |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1950 | + " (current platform is any of " |
| 1951 | + Arrays.toString(SDK_CODENAMES) + ")"; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1952 | } else { |
| 1953 | outError[0] = "Requires development platform " + targetCode |
| 1954 | + " but this is a release platform."; |
| 1955 | } |
| 1956 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1957 | return null; |
| 1958 | } |
| 1959 | // If the code matches, it definitely targets this SDK. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1960 | pkg.applicationInfo.targetSdkVersion |
| 1961 | = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 1962 | } else { |
| 1963 | pkg.applicationInfo.targetSdkVersion = targetVers; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | XmlUtils.skipCurrentTag(parser); |
| 1968 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1969 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 1970 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1971 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 1972 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1973 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 1974 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 1975 | 0); |
| 1976 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 1977 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 1978 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 1979 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 1980 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 1981 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1982 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1983 | // This is a trick to get a boolean and still able to detect |
| 1984 | // if a value was actually set. |
| 1985 | supportsSmallScreens = sa.getInteger( |
| 1986 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 1987 | supportsSmallScreens); |
| 1988 | supportsNormalScreens = sa.getInteger( |
| 1989 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 1990 | supportsNormalScreens); |
| 1991 | supportsLargeScreens = sa.getInteger( |
| 1992 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 1993 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1994 | supportsXLargeScreens = sa.getInteger( |
| 1995 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 1996 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1997 | resizeable = sa.getInteger( |
| 1998 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1999 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2000 | anyDensity = sa.getInteger( |
| 2001 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 2002 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2003 | |
| 2004 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2005 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2006 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2007 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2008 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 2009 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2010 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 2011 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2012 | // Note: don't allow this value to be a reference to a resource |
| 2013 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2014 | String name = sa.getNonResourceString( |
| 2015 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 2016 | |
| 2017 | sa.recycle(); |
| 2018 | |
| 2019 | if (name != null && (flags&PARSE_IS_SYSTEM) != 0) { |
| 2020 | if (pkg.protectedBroadcasts == null) { |
| 2021 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 2022 | } |
| 2023 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 2024 | pkg.protectedBroadcasts.add(name.intern()); |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2029 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2030 | } else if (tagName.equals(TAG_INSTRUMENTATION)) { |
| 2031 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2032 | return null; |
| 2033 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2034 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2035 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2036 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2037 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2038 | String orig =sa.getNonConfigurationString( |
| 2039 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2040 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2041 | if (pkg.mOriginalPackages == null) { |
| 2042 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2043 | pkg.mRealPackage = pkg.packageName; |
| 2044 | } |
| 2045 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2046 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2047 | |
| 2048 | sa.recycle(); |
| 2049 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2050 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2051 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2052 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2053 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2054 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2055 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2056 | String name = sa.getNonConfigurationString( |
| 2057 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2058 | |
| 2059 | sa.recycle(); |
| 2060 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2061 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2062 | if (pkg.mAdoptPermissions == null) { |
| 2063 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2064 | } |
| 2065 | pkg.mAdoptPermissions.add(name); |
| 2066 | } |
| 2067 | |
| 2068 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2069 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2070 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2071 | // Just skip this tag |
| 2072 | XmlUtils.skipCurrentTag(parser); |
| 2073 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2074 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2075 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2076 | // Just skip this tag |
| 2077 | XmlUtils.skipCurrentTag(parser); |
| 2078 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2079 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2080 | XmlUtils.skipCurrentTag(parser); |
| 2081 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2082 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2083 | } else if (tagName.equals(TAG_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2084 | // Just skip this tag |
| 2085 | XmlUtils.skipCurrentTag(parser); |
| 2086 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2087 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2088 | } else if (tagName.equals(TAG_PACKAGE)) { |
Svet Ganov | a7532cf | 2016-05-02 08:13:17 -0700 | [diff] [blame^] | 2089 | if (!MULTI_PACKAGE_APK_ENABLED) { |
| 2090 | XmlUtils.skipCurrentTag(parser); |
| 2091 | continue; |
| 2092 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2093 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2094 | // If parsing a child failed the error is already set |
| 2095 | return null; |
| 2096 | } |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 2097 | |
| 2098 | } else if (tagName.equals(TAG_RESTRICT_UPDATE)) { |
| 2099 | if ((flags & PARSE_IS_SYSTEM_DIR) != 0) { |
| 2100 | sa = res.obtainAttributes(parser, |
| 2101 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate); |
| 2102 | final String hash = sa.getNonConfigurationString( |
| 2103 | com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0); |
| 2104 | sa.recycle(); |
| 2105 | |
| 2106 | pkg.restrictUpdateHash = null; |
| 2107 | if (hash != null) { |
| 2108 | final int hashLength = hash.length(); |
| 2109 | final byte[] hashBytes = new byte[hashLength / 2]; |
| 2110 | for (int i = 0; i < hashLength; i += 2){ |
| 2111 | hashBytes[i/2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) |
| 2112 | + Character.digit(hash.charAt(i + 1), 16)); |
| 2113 | } |
| 2114 | pkg.restrictUpdateHash = hashBytes; |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | XmlUtils.skipCurrentTag(parser); |
| 2119 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2120 | } else if (RIGID_PARSER) { |
| 2121 | outError[0] = "Bad element under <manifest>: " |
| 2122 | + parser.getName(); |
| 2123 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2124 | return null; |
| 2125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2127 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2128 | + " at " + mArchiveSourcePath + " " |
| 2129 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2130 | XmlUtils.skipCurrentTag(parser); |
| 2131 | continue; |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2136 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2137 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2138 | } |
| 2139 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2140 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2141 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2142 | for (int ip=0; ip<NP; ip++) { |
| 2143 | final PackageParser.NewPermissionInfo npi |
| 2144 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2145 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2146 | break; |
| 2147 | } |
| 2148 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2149 | if (implicitPerms == null) { |
| 2150 | implicitPerms = new StringBuilder(128); |
| 2151 | implicitPerms.append(pkg.packageName); |
| 2152 | implicitPerms.append(": compat added "); |
| 2153 | } else { |
| 2154 | implicitPerms.append(' '); |
| 2155 | } |
| 2156 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2157 | pkg.requestedPermissions.add(npi.name); |
| 2158 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2159 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2160 | if (implicitPerms != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2161 | Slog.i(TAG, implicitPerms.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2162 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2163 | |
| 2164 | final int NS = PackageParser.SPLIT_PERMISSIONS.length; |
| 2165 | for (int is=0; is<NS; is++) { |
| 2166 | final PackageParser.SplitPermissionInfo spi |
| 2167 | = PackageParser.SPLIT_PERMISSIONS[is]; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 2168 | if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk |
| 2169 | || !pkg.requestedPermissions.contains(spi.rootPerm)) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2170 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2171 | } |
| 2172 | for (int in=0; in<spi.newPerms.length; in++) { |
| 2173 | final String perm = spi.newPerms[in]; |
| 2174 | if (!pkg.requestedPermissions.contains(perm)) { |
| 2175 | pkg.requestedPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2176 | } |
| 2177 | } |
| 2178 | } |
| 2179 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2180 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2181 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2182 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2183 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2184 | } |
| 2185 | if (supportsNormalScreens != 0) { |
| 2186 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2187 | } |
| 2188 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2189 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2190 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2191 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2192 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2193 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2194 | && pkg.applicationInfo.targetSdkVersion |
| 2195 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2196 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2197 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2198 | if (resizeable < 0 || (resizeable > 0 |
| 2199 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2200 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2201 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2202 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2203 | if (anyDensity < 0 || (anyDensity > 0 |
| 2204 | && pkg.applicationInfo.targetSdkVersion |
| 2205 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2206 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2207 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | return pkg; |
| 2210 | } |
| 2211 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2212 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2213 | FeatureInfo fi = new FeatureInfo(); |
| 2214 | TypedArray sa = res.obtainAttributes(attrs, |
| 2215 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2216 | // Note: don't allow this value to be a reference to a resource |
| 2217 | // that may change. |
| 2218 | fi.name = sa.getNonResourceString( |
| 2219 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2220 | fi.version = sa.getInt( |
| 2221 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2222 | if (fi.name == null) { |
| 2223 | fi.reqGlEsVersion = sa.getInt( |
| 2224 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2225 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2226 | } |
| 2227 | if (sa.getBoolean( |
| 2228 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2229 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2230 | } |
| 2231 | sa.recycle(); |
| 2232 | return fi; |
| 2233 | } |
| 2234 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2235 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2236 | throws XmlPullParserException, IOException { |
| 2237 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2238 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2239 | |
| 2240 | // Note: don't allow this value to be a reference to a resource |
| 2241 | // that may change. |
| 2242 | String name = sa.getNonResourceString( |
| 2243 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2244 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2245 | int maxSdkVersion = 0; |
| 2246 | TypedValue val = sa.peekValue( |
| 2247 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2248 | if (val != null) { |
| 2249 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2250 | maxSdkVersion = val.data; |
| 2251 | } |
| 2252 | } |
| 2253 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2254 | sa.recycle(); |
| 2255 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2256 | if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) { |
| 2257 | if (name != null) { |
| 2258 | int index = pkg.requestedPermissions.indexOf(name); |
| 2259 | if (index == -1) { |
| 2260 | pkg.requestedPermissions.add(name.intern()); |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2261 | } else { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2262 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2263 | + name + " in package: " + pkg.packageName + " at: " |
| 2264 | + parser.getPositionDescription()); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | XmlUtils.skipCurrentTag(parser); |
| 2270 | return true; |
| 2271 | } |
| 2272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2274 | String[] outError) { |
| 2275 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2276 | outError[0] = "Empty class name in package " + pkg; |
| 2277 | return null; |
| 2278 | } |
| 2279 | String cls = clsSeq.toString(); |
| 2280 | char c = cls.charAt(0); |
| 2281 | if (c == '.') { |
| 2282 | return (pkg + cls).intern(); |
| 2283 | } |
| 2284 | if (cls.indexOf('.') < 0) { |
| 2285 | StringBuilder b = new StringBuilder(pkg); |
| 2286 | b.append('.'); |
| 2287 | b.append(cls); |
| 2288 | return b.toString().intern(); |
| 2289 | } |
| 2290 | if (c >= 'a' && c <= 'z') { |
| 2291 | return cls.intern(); |
| 2292 | } |
| 2293 | outError[0] = "Bad class name " + cls + " in package " + pkg; |
| 2294 | return null; |
| 2295 | } |
| 2296 | |
| 2297 | private static String buildCompoundName(String pkg, |
| 2298 | CharSequence procSeq, String type, String[] outError) { |
| 2299 | String proc = procSeq.toString(); |
| 2300 | char c = proc.charAt(0); |
| 2301 | if (pkg != null && c == ':') { |
| 2302 | if (proc.length() < 2) { |
| 2303 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2304 | + ": must be at least two characters"; |
| 2305 | return null; |
| 2306 | } |
| 2307 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2308 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | if (nameError != null) { |
| 2310 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2311 | + pkg + ": " + nameError; |
| 2312 | return null; |
| 2313 | } |
| 2314 | return (pkg + proc).intern(); |
| 2315 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2316 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | if (nameError != null && !"system".equals(proc)) { |
| 2318 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2319 | + pkg + ": " + nameError; |
| 2320 | return null; |
| 2321 | } |
| 2322 | return proc.intern(); |
| 2323 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | private static String buildProcessName(String pkg, String defProc, |
| 2326 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 2327 | String[] outError) { |
| 2328 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 2329 | return defProc != null ? defProc : pkg; |
| 2330 | } |
| 2331 | if (separateProcesses != null) { |
| 2332 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 2333 | String sp = separateProcesses[i]; |
| 2334 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 2335 | return pkg; |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | if (procSeq == null || procSeq.length() <= 0) { |
| 2340 | return defProc; |
| 2341 | } |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2342 | return buildCompoundName(pkg, procSeq, "process", outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 2346 | CharSequence procSeq, String[] outError) { |
| 2347 | if (procSeq == null) { |
| 2348 | return defProc; |
| 2349 | } |
| 2350 | if (procSeq.length() <= 0) { |
| 2351 | return null; |
| 2352 | } |
| 2353 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 2354 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2355 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2356 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2357 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2358 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2359 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2360 | // all the keys and keysets that we want must be defined here |
| 2361 | // so we're going to iterate over the parser and pull out the things we want |
| 2362 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2363 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2364 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2365 | String currentKeySet = null; |
| 2366 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 2367 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 2368 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 2369 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2370 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2371 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2372 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2373 | if (parser.getDepth() == currentKeySetDepth) { |
| 2374 | currentKeySet = null; |
| 2375 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2376 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2377 | continue; |
| 2378 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2379 | String tagName = parser.getName(); |
| 2380 | if (tagName.equals("key-set")) { |
| 2381 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2382 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2383 | + parser.getPositionDescription(); |
| 2384 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2385 | return false; |
| 2386 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2387 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2388 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 2389 | final String keysetName = sa.getNonResourceString( |
| 2390 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 2391 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 2392 | currentKeySet = keysetName; |
| 2393 | currentKeySetDepth = parser.getDepth(); |
| 2394 | sa.recycle(); |
| 2395 | } else if (tagName.equals("public-key")) { |
| 2396 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2397 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2398 | + parser.getPositionDescription(); |
| 2399 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2400 | return false; |
| 2401 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2402 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2403 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 2404 | final String publicKeyName = sa.getNonResourceString( |
| 2405 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2406 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2407 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 2408 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2409 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 2410 | + " on first use at " + parser.getPositionDescription(); |
| 2411 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2412 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2413 | return false; |
| 2414 | } else if (encodedKey != null) { |
| 2415 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 2416 | if (currentKey == null) { |
| 2417 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 2418 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 2419 | + " will not be added to the package's defined key-sets."); |
| 2420 | sa.recycle(); |
| 2421 | improperKeySets.add(currentKeySet); |
| 2422 | XmlUtils.skipCurrentTag(parser); |
| 2423 | continue; |
| 2424 | } |
| 2425 | if (publicKeys.get(publicKeyName) == null |
| 2426 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 2427 | |
| 2428 | /* public-key first definition, or matches old definition */ |
| 2429 | publicKeys.put(publicKeyName, currentKey); |
| 2430 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2431 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2432 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2433 | + parser.getPositionDescription(); |
| 2434 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2435 | sa.recycle(); |
| 2436 | return false; |
| 2437 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2438 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2439 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2440 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2441 | XmlUtils.skipCurrentTag(parser); |
| 2442 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2443 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2444 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 2445 | String name = sa.getNonResourceString( |
| 2446 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 2447 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2448 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2449 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2450 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2451 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2452 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2453 | + parser.getPositionDescription(); |
| 2454 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2455 | return false; |
| 2456 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2457 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2458 | + " at " + mArchiveSourcePath + " " |
| 2459 | + parser.getPositionDescription()); |
| 2460 | XmlUtils.skipCurrentTag(parser); |
| 2461 | continue; |
| 2462 | } |
| 2463 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2464 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 2465 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2466 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 2467 | + "'key-set' and 'public-key' names must be distinct."; |
| 2468 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2469 | return false; |
| 2470 | } |
| 2471 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 2472 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 2473 | final String keySetName = e.getKey(); |
| 2474 | if (e.getValue().size() == 0) { |
| 2475 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 2476 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 2477 | + " Not including in package's defined key-sets."); |
| 2478 | continue; |
| 2479 | } else if (improperKeySets.contains(keySetName)) { |
| 2480 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 2481 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 2482 | + " tags. Not including in package's defined key-sets."); |
| 2483 | continue; |
| 2484 | } |
| 2485 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 2486 | for (String s : e.getValue()) { |
| 2487 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2488 | } |
| 2489 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2490 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 2491 | owner.mUpgradeKeySets = upgradeKeySets; |
| 2492 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2493 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 2494 | + "does not define all 'upgrade-key-set's ."; |
| 2495 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2496 | return false; |
| 2497 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2498 | return true; |
| 2499 | } |
| 2500 | |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2501 | private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2502 | XmlResourceParser parser, String[] outError) |
| 2503 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | PermissionGroup perm = new PermissionGroup(owner); |
| 2505 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2506 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
| 2508 | |
| 2509 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2510 | "<permission-group>", sa, |
| 2511 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 2512 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2513 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2514 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 2515 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | sa.recycle(); |
| 2517 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2518 | return null; |
| 2519 | } |
| 2520 | |
| 2521 | perm.info.descriptionRes = sa.getResourceId( |
| 2522 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 2523 | 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 2524 | perm.info.flags = sa.getInt( |
| 2525 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2526 | perm.info.priority = sa.getInt( |
| 2527 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
Dianne Hackborn | 99222d2 | 2012-05-06 16:30:15 -0700 | [diff] [blame] | 2528 | if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) { |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2529 | perm.info.priority = 0; |
| 2530 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | |
| 2532 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2533 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2534 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | outError)) { |
| 2536 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2537 | return null; |
| 2538 | } |
| 2539 | |
| 2540 | owner.permissionGroups.add(perm); |
| 2541 | |
| 2542 | return perm; |
| 2543 | } |
| 2544 | |
| 2545 | private Permission parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2546 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | throws XmlPullParserException, IOException { |
| 2548 | Permission perm = new Permission(owner); |
| 2549 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2550 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 2552 | |
| 2553 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2554 | "<permission>", sa, |
| 2555 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 2556 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2557 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2558 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 2559 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | sa.recycle(); |
| 2561 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2562 | return null; |
| 2563 | } |
| 2564 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2565 | // Note: don't allow this value to be a reference to a resource |
| 2566 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | perm.info.group = sa.getNonResourceString( |
| 2568 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 2569 | if (perm.info.group != null) { |
| 2570 | perm.info.group = perm.info.group.intern(); |
| 2571 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | perm.info.descriptionRes = sa.getResourceId( |
| 2574 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 2575 | 0); |
| 2576 | |
| 2577 | perm.info.protectionLevel = sa.getInt( |
| 2578 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 2579 | PermissionInfo.PROTECTION_NORMAL); |
| 2580 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 2581 | perm.info.flags = sa.getInt( |
| 2582 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 2583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 2585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | if (perm.info.protectionLevel == -1) { |
| 2587 | outError[0] = "<permission> does not specify protectionLevel"; |
| 2588 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2589 | return null; |
| 2590 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 2591 | |
| 2592 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 2593 | |
| 2594 | if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) { |
| 2595 | if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
| 2596 | PermissionInfo.PROTECTION_SIGNATURE) { |
| 2597 | outError[0] = "<permission> protectionLevel specifies a flag but is " |
| 2598 | + "not based on signature type"; |
| 2599 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2600 | return null; |
| 2601 | } |
| 2602 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2603 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2604 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2606 | return null; |
| 2607 | } |
| 2608 | |
| 2609 | owner.permissions.add(perm); |
| 2610 | |
| 2611 | return perm; |
| 2612 | } |
| 2613 | |
| 2614 | private Permission parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2615 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | throws XmlPullParserException, IOException { |
| 2617 | Permission perm = new Permission(owner); |
| 2618 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2619 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 2621 | |
| 2622 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2623 | "<permission-tree>", sa, |
| 2624 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 2625 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2626 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2627 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 2628 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | sa.recycle(); |
| 2630 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2631 | return null; |
| 2632 | } |
| 2633 | |
| 2634 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | int index = perm.info.name.indexOf('.'); |
| 2637 | if (index > 0) { |
| 2638 | index = perm.info.name.indexOf('.', index+1); |
| 2639 | } |
| 2640 | if (index < 0) { |
| 2641 | outError[0] = "<permission-tree> name has less than three segments: " |
| 2642 | + perm.info.name; |
| 2643 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2644 | return null; |
| 2645 | } |
| 2646 | |
| 2647 | perm.info.descriptionRes = 0; |
| 2648 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 2649 | perm.tree = true; |
| 2650 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2651 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | outError)) { |
| 2653 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2654 | return null; |
| 2655 | } |
| 2656 | |
| 2657 | owner.permissions.add(perm); |
| 2658 | |
| 2659 | return perm; |
| 2660 | } |
| 2661 | |
| 2662 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2663 | XmlResourceParser parser, String[] outError) |
| 2664 | throws XmlPullParserException, IOException { |
| 2665 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2666 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 2667 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2668 | if (mParseInstrumentationArgs == null) { |
| 2669 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 2670 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 2671 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2672 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2673 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 2674 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2675 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 2676 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2677 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2678 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2679 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2680 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 2681 | new InstrumentationInfo()); |
| 2682 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | sa.recycle(); |
| 2684 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2685 | return null; |
| 2686 | } |
| 2687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2689 | // Note: don't allow this value to be a reference to a resource |
| 2690 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | str = sa.getNonResourceString( |
| 2692 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 2693 | a.info.targetPackage = str != null ? str.intern() : null; |
| 2694 | |
| 2695 | a.info.handleProfiling = sa.getBoolean( |
| 2696 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 2697 | false); |
| 2698 | |
| 2699 | a.info.functionalTest = sa.getBoolean( |
| 2700 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 2701 | false); |
| 2702 | |
| 2703 | sa.recycle(); |
| 2704 | |
| 2705 | if (a.info.targetPackage == null) { |
| 2706 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 2707 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2708 | return null; |
| 2709 | } |
| 2710 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2711 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | outError)) { |
| 2713 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2714 | return null; |
| 2715 | } |
| 2716 | |
| 2717 | owner.instrumentation.add(a); |
| 2718 | |
| 2719 | return a; |
| 2720 | } |
| 2721 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2722 | /** |
| 2723 | * Parse the {@code application} XML tree at the current parse location in a |
| 2724 | * <em>base APK</em> manifest. |
| 2725 | * <p> |
| 2726 | * When adding new features, carefully consider if they should also be |
| 2727 | * supported by split APKs. |
| 2728 | */ |
| 2729 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2730 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | throws XmlPullParserException, IOException { |
| 2732 | final ApplicationInfo ai = owner.applicationInfo; |
| 2733 | final String pkgName = owner.applicationInfo.packageName; |
| 2734 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2735 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 2737 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2738 | String name = sa.getNonConfigurationString( |
| 2739 | com.android.internal.R.styleable.AndroidManifestApplication_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | if (name != null) { |
| 2741 | ai.className = buildClassName(pkgName, name, outError); |
| 2742 | if (ai.className == null) { |
| 2743 | sa.recycle(); |
| 2744 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2745 | return false; |
| 2746 | } |
| 2747 | } |
| 2748 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2749 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2750 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 2751 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | if (manageSpaceActivity != null) { |
| 2753 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 2754 | outError); |
| 2755 | } |
| 2756 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2757 | boolean allowBackup = sa.getBoolean( |
| 2758 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 2759 | if (allowBackup) { |
| 2760 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 2761 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 2762 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 2763 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 2764 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2765 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2766 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 2767 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2768 | if (backupAgent != null) { |
| 2769 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2770 | if (DEBUG_BACKUP) { |
| 2771 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2772 | + " from " + pkgName + "+" + backupAgent); |
| 2773 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 2774 | |
| 2775 | if (sa.getBoolean( |
| 2776 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 2777 | true)) { |
| 2778 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 2779 | } |
| 2780 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 2781 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 2782 | false)) { |
| 2783 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 2784 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 2785 | if (sa.getBoolean( |
| 2786 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 2787 | false)) { |
| 2788 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 2789 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 2790 | if (sa.getBoolean( |
| 2791 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 2792 | false)) { |
| 2793 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 2794 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2795 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 2796 | |
| 2797 | TypedValue v = sa.peekValue( |
| 2798 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 2799 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 2800 | if (DEBUG_BACKUP) { |
| 2801 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 2802 | (v.data == 0 ? "false" : "true")); |
| 2803 | } |
| 2804 | // "false" => -1, "true" => 0 |
| 2805 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 2806 | } |
| 2807 | if (DEBUG_BACKUP) { |
| 2808 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 2809 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2810 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | TypedValue v = sa.peekValue( |
| 2813 | com.android.internal.R.styleable.AndroidManifestApplication_label); |
| 2814 | if (v != null && (ai.labelRes=v.resourceId) == 0) { |
| 2815 | ai.nonLocalizedLabel = v.coerceToString(); |
| 2816 | } |
| 2817 | |
| 2818 | ai.icon = sa.getResourceId( |
| 2819 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2820 | ai.logo = sa.getResourceId( |
| 2821 | com.android.internal.R.styleable.AndroidManifestApplication_logo, 0); |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2822 | ai.banner = sa.getResourceId( |
| 2823 | com.android.internal.R.styleable.AndroidManifestApplication_banner, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 2825 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | ai.descriptionRes = sa.getResourceId( |
| 2827 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 2828 | |
| 2829 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 2830 | if (sa.getBoolean( |
| 2831 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 2832 | false)) { |
| 2833 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
| 2834 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | if (sa.getBoolean( |
| 2838 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 2839 | false)) { |
| 2840 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 2844 | .AndroidManifestApplication_restrictedAccountType); |
| 2845 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 2846 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | } |
| 2848 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 2849 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 2850 | .AndroidManifestApplication_requiredAccountType); |
| 2851 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 2852 | owner.mRequiredAccountType = requiredAccountType; |
| 2853 | } |
| 2854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | if (sa.getBoolean( |
| 2856 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 2857 | false)) { |
| 2858 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 2859 | } |
| 2860 | |
| 2861 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 2862 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 2863 | false)) { |
| 2864 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 2865 | } |
| 2866 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2867 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2868 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 2869 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 2870 | if (owner.baseHardwareAccelerated) { |
| 2871 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 2872 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2873 | |
| 2874 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 2876 | true)) { |
| 2877 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 2878 | } |
| 2879 | |
| 2880 | if (sa.getBoolean( |
| 2881 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 2882 | false)) { |
| 2883 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 2884 | } |
| 2885 | |
| 2886 | if (sa.getBoolean( |
| 2887 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 2888 | true)) { |
| 2889 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 2890 | } |
| 2891 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2892 | // The parent package controls installation, hence specify test only installs. |
| 2893 | if (owner.parentPackage == null) { |
| 2894 | if (sa.getBoolean( |
| 2895 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 2896 | false)) { |
| 2897 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 2898 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2901 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 2902 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2903 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 2904 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2905 | } |
| 2906 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 2907 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 2908 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
| 2909 | true)) { |
| 2910 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 2911 | } |
| 2912 | |
| 2913 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 2914 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 2915 | false /* default is no RTL support*/)) { |
| 2916 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 2917 | } |
| 2918 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 2919 | if (sa.getBoolean( |
| 2920 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 2921 | false)) { |
| 2922 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 2923 | } |
| 2924 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 2925 | if (sa.getBoolean( |
| 2926 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
| 2927 | true)) { |
| 2928 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 2929 | } |
| 2930 | |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 2931 | if (sa.getBoolean( |
| 2932 | R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 2933 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2934 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2935 | } |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 2936 | if (sa.getBoolean( |
| 2937 | R.styleable.AndroidManifestApplication_directBootAware, |
| 2938 | false)) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2939 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 2940 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2941 | |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 2942 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, |
| 2943 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N)) { |
| 2944 | ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES; |
| 2945 | } |
| 2946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2948 | str = sa.getNonConfigurationString( |
| 2949 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 2951 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2952 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 2953 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2954 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 2955 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2956 | } else { |
| 2957 | // Some older apps have been seen to use a resource reference |
| 2958 | // here that on older builds was ignored (with a warning). We |
| 2959 | // need to continue to do this for them so they don't break. |
| 2960 | str = sa.getNonResourceString( |
| 2961 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 2962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 2964 | str, outError); |
| 2965 | |
| 2966 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2967 | CharSequence pname; |
| 2968 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 2969 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2970 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 2971 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2972 | } else { |
| 2973 | // Some older apps have been seen to use a resource reference |
| 2974 | // here that on older builds was ignored (with a warning). We |
| 2975 | // need to continue to do this for them so they don't break. |
| 2976 | pname = sa.getNonResourceString( |
| 2977 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 2978 | } |
| 2979 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2981 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2982 | ai.enabled = sa.getBoolean( |
| 2983 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2984 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 2985 | if (sa.getBoolean( |
| 2986 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 2987 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 2988 | } |
| 2989 | |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 2990 | if (false) { |
| 2991 | if (sa.getBoolean( |
| 2992 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 2993 | false)) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2994 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 2995 | |
| 2996 | // A heavy-weight application can not be in a custom process. |
| 2997 | // We can do direct compare because we intern all strings. |
| 2998 | if (ai.processName != null && ai.processName != ai.packageName) { |
| 2999 | outError[0] = "cantSaveState applications can not use custom processes"; |
| 3000 | } |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3001 | } |
| 3002 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | } |
| 3004 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3005 | ai.uiOptions = sa.getInt( |
| 3006 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 3007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | sa.recycle(); |
| 3009 | |
| 3010 | if (outError[0] != null) { |
| 3011 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3012 | return false; |
| 3013 | } |
| 3014 | |
| 3015 | final int innerDepth = parser.getDepth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3017 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3018 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3019 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3020 | continue; |
| 3021 | } |
| 3022 | |
| 3023 | String tagName = parser.getName(); |
| 3024 | if (tagName.equals("activity")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3025 | Activity a = parseActivity(owner, res, parser, flags, outError, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3026 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | if (a == null) { |
| 3028 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3029 | return false; |
| 3030 | } |
| 3031 | |
| 3032 | owner.activities.add(a); |
| 3033 | |
| 3034 | } else if (tagName.equals("receiver")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3035 | Activity a = parseActivity(owner, res, parser, flags, outError, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | if (a == null) { |
| 3037 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3038 | return false; |
| 3039 | } |
| 3040 | |
| 3041 | owner.receivers.add(a); |
| 3042 | |
| 3043 | } else if (tagName.equals("service")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3044 | Service s = parseService(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | if (s == null) { |
| 3046 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3047 | return false; |
| 3048 | } |
| 3049 | |
| 3050 | owner.services.add(s); |
| 3051 | |
| 3052 | } else if (tagName.equals("provider")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3053 | Provider p = parseProvider(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | if (p == null) { |
| 3055 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3056 | return false; |
| 3057 | } |
| 3058 | |
| 3059 | owner.providers.add(p); |
| 3060 | |
| 3061 | } else if (tagName.equals("activity-alias")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3062 | Activity a = parseActivityAlias(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | if (a == null) { |
| 3064 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3065 | return false; |
| 3066 | } |
| 3067 | |
| 3068 | owner.activities.add(a); |
| 3069 | |
| 3070 | } else if (parser.getName().equals("meta-data")) { |
| 3071 | // note: application meta-data is stored off to the side, so it can |
| 3072 | // remain null in the primary copy (we like to avoid extra copies because |
| 3073 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3074 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | outError)) == null) { |
| 3076 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3077 | return false; |
| 3078 | } |
| 3079 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3080 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3081 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3082 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3083 | |
| 3084 | // Note: don't allow this value to be a reference to a resource |
| 3085 | // that may change. |
| 3086 | String lname = sa.getNonResourceString( |
| 3087 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3088 | |
| 3089 | sa.recycle(); |
| 3090 | |
| 3091 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3092 | lname = lname.intern(); |
| 3093 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
| 3094 | owner.libraryNames = ArrayUtils.add(owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | XmlUtils.skipCurrentTag(parser); |
| 3099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3101 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3102 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3103 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3104 | // Note: don't allow this value to be a reference to a resource |
| 3105 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | String lname = sa.getNonResourceString( |
| 3107 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3108 | boolean req = sa.getBoolean( |
| 3109 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3110 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | |
| 3112 | sa.recycle(); |
| 3113 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3114 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3115 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3116 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3117 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3118 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3119 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3120 | owner.usesOptionalLibraries, lname); |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | XmlUtils.skipCurrentTag(parser); |
| 3125 | |
| 3126 | } else if (tagName.equals("uses-package")) { |
| 3127 | // Dependencies for app installers; we don't currently try to |
| 3128 | // enforce this. |
| 3129 | XmlUtils.skipCurrentTag(parser); |
| 3130 | |
| 3131 | } else { |
| 3132 | if (!RIGID_PARSER) { |
| 3133 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 3134 | + " at " + mArchiveSourcePath + " " |
| 3135 | + parser.getPositionDescription()); |
| 3136 | XmlUtils.skipCurrentTag(parser); |
| 3137 | continue; |
| 3138 | } else { |
| 3139 | outError[0] = "Bad element under <application>: " + tagName; |
| 3140 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3141 | return false; |
| 3142 | } |
| 3143 | } |
| 3144 | } |
| 3145 | |
Narayan Kamath | b12dcfb | 2015-03-30 11:31:04 +0100 | [diff] [blame] | 3146 | modifySharedLibrariesForBackwardCompatibility(owner); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3147 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3148 | if (hasDomainURLs(owner)) { |
| 3149 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3150 | } else { |
| 3151 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3152 | } |
| 3153 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3154 | return true; |
| 3155 | } |
| 3156 | |
Narayan Kamath | b12dcfb | 2015-03-30 11:31:04 +0100 | [diff] [blame] | 3157 | private static void modifySharedLibrariesForBackwardCompatibility(Package owner) { |
| 3158 | // "org.apache.http.legacy" is now a part of the boot classpath so it doesn't need |
| 3159 | // to be an explicit dependency. |
| 3160 | // |
| 3161 | // A future change will remove this library from the boot classpath, at which point |
| 3162 | // all apps that target SDK 21 and earlier will have it automatically added to their |
| 3163 | // dependency lists. |
| 3164 | owner.usesLibraries = ArrayUtils.remove(owner.usesLibraries, "org.apache.http.legacy"); |
| 3165 | owner.usesOptionalLibraries = ArrayUtils.remove(owner.usesOptionalLibraries, |
| 3166 | "org.apache.http.legacy"); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3167 | } |
| 3168 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3169 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3170 | * 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] | 3171 | */ |
| 3172 | private static boolean hasDomainURLs(Package pkg) { |
| 3173 | if (pkg == null || pkg.activities == null) return false; |
| 3174 | final ArrayList<Activity> activities = pkg.activities; |
| 3175 | final int countActivities = activities.size(); |
| 3176 | for (int n=0; n<countActivities; n++) { |
| 3177 | Activity activity = activities.get(n); |
| 3178 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 3179 | if (filters == null) continue; |
| 3180 | final int countFilters = filters.size(); |
| 3181 | for (int m=0; m<countFilters; m++) { |
| 3182 | ActivityIntentInfo aii = filters.get(m); |
| 3183 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3184 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3185 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 3186 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 3187 | return true; |
| 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | return false; |
| 3192 | } |
| 3193 | |
| 3194 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3195 | * Parse the {@code application} XML tree at the current parse location in a |
| 3196 | * <em>split APK</em> manifest. |
| 3197 | * <p> |
| 3198 | * Note that split APKs have many more restrictions on what they're capable |
| 3199 | * of doing, so many valid features of a base APK have been carefully |
| 3200 | * omitted here. |
| 3201 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3202 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 3203 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3204 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3205 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3206 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3207 | |
| 3208 | if (sa.getBoolean( |
| 3209 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 3210 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 3211 | } |
| 3212 | |
| 3213 | final int innerDepth = parser.getDepth(); |
| 3214 | int type; |
| 3215 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3216 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3217 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3218 | continue; |
| 3219 | } |
| 3220 | |
| 3221 | String tagName = parser.getName(); |
| 3222 | if (tagName.equals("activity")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3223 | Activity a = parseActivity(owner, res, parser, flags, outError, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3224 | owner.baseHardwareAccelerated); |
| 3225 | if (a == null) { |
| 3226 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3227 | return false; |
| 3228 | } |
| 3229 | |
| 3230 | owner.activities.add(a); |
| 3231 | |
| 3232 | } else if (tagName.equals("receiver")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3233 | Activity a = parseActivity(owner, res, parser, flags, outError, true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3234 | if (a == null) { |
| 3235 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3236 | return false; |
| 3237 | } |
| 3238 | |
| 3239 | owner.receivers.add(a); |
| 3240 | |
| 3241 | } else if (tagName.equals("service")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3242 | Service s = parseService(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3243 | if (s == null) { |
| 3244 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3245 | return false; |
| 3246 | } |
| 3247 | |
| 3248 | owner.services.add(s); |
| 3249 | |
| 3250 | } else if (tagName.equals("provider")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3251 | Provider p = parseProvider(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3252 | if (p == null) { |
| 3253 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | owner.providers.add(p); |
| 3258 | |
| 3259 | } else if (tagName.equals("activity-alias")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3260 | Activity a = parseActivityAlias(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3261 | if (a == null) { |
| 3262 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3263 | return false; |
| 3264 | } |
| 3265 | |
| 3266 | owner.activities.add(a); |
| 3267 | |
| 3268 | } else if (parser.getName().equals("meta-data")) { |
| 3269 | // note: application meta-data is stored off to the side, so it can |
| 3270 | // remain null in the primary copy (we like to avoid extra copies because |
| 3271 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3272 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3273 | outError)) == null) { |
| 3274 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3275 | return false; |
| 3276 | } |
| 3277 | |
| 3278 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3279 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3280 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3281 | |
| 3282 | // Note: don't allow this value to be a reference to a resource |
| 3283 | // that may change. |
| 3284 | String lname = sa.getNonResourceString( |
| 3285 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 3286 | boolean req = sa.getBoolean( |
| 3287 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3288 | true); |
| 3289 | |
| 3290 | sa.recycle(); |
| 3291 | |
| 3292 | if (lname != null) { |
| 3293 | lname = lname.intern(); |
| 3294 | if (req) { |
| 3295 | // Upgrade to treat as stronger constraint |
| 3296 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 3297 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 3298 | owner.usesOptionalLibraries, lname); |
| 3299 | } else { |
| 3300 | // Ignore if someone already defined as required |
| 3301 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 3302 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3303 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3304 | } |
| 3305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | XmlUtils.skipCurrentTag(parser); |
| 3309 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3310 | } else if (tagName.equals("uses-package")) { |
| 3311 | // Dependencies for app installers; we don't currently try to |
| 3312 | // enforce this. |
| 3313 | XmlUtils.skipCurrentTag(parser); |
| 3314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | } else { |
| 3316 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3317 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3318 | + " at " + mArchiveSourcePath + " " |
| 3319 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | XmlUtils.skipCurrentTag(parser); |
| 3321 | continue; |
| 3322 | } else { |
| 3323 | outError[0] = "Bad element under <application>: " + tagName; |
| 3324 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3325 | return false; |
| 3326 | } |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | return true; |
| 3331 | } |
| 3332 | |
| 3333 | private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 3334 | String[] outError, String tag, TypedArray sa, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3335 | int nameRes, int labelRes, int iconRes, int logoRes, int bannerRes) { |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3336 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | if (name == null) { |
| 3338 | outError[0] = tag + " does not specify android:name"; |
| 3339 | return false; |
| 3340 | } |
| 3341 | |
| 3342 | outInfo.name |
| 3343 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 3344 | if (outInfo.name == null) { |
| 3345 | return false; |
| 3346 | } |
| 3347 | |
| 3348 | int iconVal = sa.getResourceId(iconRes, 0); |
| 3349 | if (iconVal != 0) { |
| 3350 | outInfo.icon = iconVal; |
| 3351 | outInfo.nonLocalizedLabel = null; |
| 3352 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3353 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3354 | int logoVal = sa.getResourceId(logoRes, 0); |
| 3355 | if (logoVal != 0) { |
| 3356 | outInfo.logo = logoVal; |
| 3357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3359 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 3360 | if (bannerVal != 0) { |
| 3361 | outInfo.banner = bannerVal; |
| 3362 | } |
| 3363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | TypedValue v = sa.peekValue(labelRes); |
| 3365 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 3366 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 3367 | } |
| 3368 | |
| 3369 | outInfo.packageName = owner.packageName; |
| 3370 | |
| 3371 | return true; |
| 3372 | } |
| 3373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | private Activity parseActivity(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3375 | XmlResourceParser parser, int flags, String[] outError, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 3376 | boolean receiver, boolean hardwareAccelerated) |
| 3377 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3378 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3380 | if (mParseActivityArgs == null) { |
| 3381 | mParseActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3382 | R.styleable.AndroidManifestActivity_name, |
| 3383 | R.styleable.AndroidManifestActivity_label, |
| 3384 | R.styleable.AndroidManifestActivity_icon, |
| 3385 | R.styleable.AndroidManifestActivity_logo, |
| 3386 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3387 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3388 | R.styleable.AndroidManifestActivity_process, |
| 3389 | R.styleable.AndroidManifestActivity_description, |
| 3390 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3391 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3392 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3393 | mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 3394 | mParseActivityArgs.sa = sa; |
| 3395 | mParseActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3396 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3397 | Activity a = new Activity(mParseActivityArgs, new ActivityInfo()); |
| 3398 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | sa.recycle(); |
| 3400 | return null; |
| 3401 | } |
| 3402 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3403 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3405 | 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] | 3406 | } |
| 3407 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3408 | 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] | 3409 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3410 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3411 | a.info.applicationInfo.uiOptions); |
| 3412 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3413 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3414 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3415 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3416 | if (parentName != null) { |
| 3417 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 3418 | if (outError[0] == null) { |
| 3419 | a.info.parentActivityName = parentClassName; |
| 3420 | } else { |
| 3421 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 3422 | parentName); |
| 3423 | outError[0] = null; |
| 3424 | } |
| 3425 | } |
| 3426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3427 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3428 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | if (str == null) { |
| 3430 | a.info.permission = owner.applicationInfo.permission; |
| 3431 | } else { |
| 3432 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 3433 | } |
| 3434 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3435 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3436 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3437 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 3439 | owner.applicationInfo.taskAffinity, str, outError); |
| 3440 | |
| 3441 | a.info.flags = 0; |
| 3442 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3443 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 3445 | } |
| 3446 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3447 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3448 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 3449 | } |
| 3450 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3451 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 3453 | } |
| 3454 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3455 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 3457 | } |
| 3458 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3459 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 3461 | } |
| 3462 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3463 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3464 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 3465 | } |
| 3466 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3467 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 3469 | } |
| 3470 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3471 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 3473 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3474 | } |
| 3475 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3476 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 3477 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 3478 | } |
| 3479 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 3480 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 3481 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 3482 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3485 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 3486 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 3487 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3488 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 3489 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 3490 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 3491 | } |
| 3492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3494 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 3495 | hardwareAccelerated)) { |
| 3496 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 3497 | } |
| 3498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3500 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3501 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3502 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3503 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 3504 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3505 | R.styleable.AndroidManifestActivity_maxRecents, |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 3506 | ActivityManager.getDefaultAppRecentsLimitStatic()); |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3507 | a.info.configChanges = sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3509 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3510 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 3511 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3512 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 3513 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3514 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3515 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3516 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 3517 | } |
| 3518 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3519 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3520 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 3521 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3522 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3523 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3524 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 3525 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3526 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3527 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3528 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 3529 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3530 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3531 | a.info.screenOrientation = sa.getInt( |
| 3532 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 3533 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 3534 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3535 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 163828d | 2016-02-01 11:48:19 -0800 | [diff] [blame] | 3536 | final boolean appDefault = (owner.applicationInfo.privateFlags |
| 3537 | & PRIVATE_FLAG_RESIZEABLE_ACTIVITIES) != 0; |
| 3538 | final boolean resizeable = sa.getBoolean( |
| 3539 | R.styleable.AndroidManifestActivity_resizeableActivity, appDefault); |
| 3540 | |
| 3541 | if (resizeable) { |
| 3542 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 3543 | false)) { |
| 3544 | a.info.resizeMode = RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
| 3545 | } else { |
| 3546 | a.info.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3547 | } |
Wale Ogunwale | 163828d | 2016-02-01 11:48:19 -0800 | [diff] [blame] | 3548 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
| 3549 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 508ff55 | 2016-02-15 19:31:50 -0800 | [diff] [blame] | 3550 | } else if (!a.info.isFixedOrientation() && (a.info.flags & FLAG_IMMERSIVE) == 0) { |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 3551 | a.info.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3555 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3556 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3557 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3558 | a.info.lockTaskLaunchMode = |
| 3559 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3560 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3561 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 3562 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3563 | false); |
Ruben Brunk | f56c9f4 | 2016-04-22 18:20:55 -0700 | [diff] [blame] | 3564 | |
| 3565 | a.info.requestedVrComponent = |
| 3566 | sa.getString(R.styleable.AndroidManifestActivity_enableVrMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3567 | } else { |
| 3568 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 3569 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3571 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 3572 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3573 | if (a.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3574 | Slog.w(TAG, "Activity exported request ignored due to singleUser: " |
| 3575 | + a.className + " at " + mArchiveSourcePath + " " |
| 3576 | + parser.getPositionDescription()); |
| 3577 | a.info.exported = false; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3578 | setExported = true; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3579 | } |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3580 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3581 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3582 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 3583 | R.styleable.AndroidManifestActivity_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3584 | false); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3587 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3588 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3589 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | sa.recycle(); |
| 3593 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3594 | if (receiver && (owner.applicationInfo.privateFlags |
| 3595 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3596 | // A heavy-weight application can not have receives in its main process |
| 3597 | // We can do direct compare because we intern all strings. |
| 3598 | if (a.info.processName == owner.packageName) { |
| 3599 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 3600 | } |
| 3601 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | if (outError[0] != null) { |
| 3604 | return null; |
| 3605 | } |
| 3606 | |
| 3607 | int outerDepth = parser.getDepth(); |
| 3608 | int type; |
| 3609 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 3610 | && (type != XmlPullParser.END_TAG |
| 3611 | || parser.getDepth() > outerDepth)) { |
| 3612 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3613 | continue; |
| 3614 | } |
| 3615 | |
| 3616 | if (parser.getName().equals("intent-filter")) { |
| 3617 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3618 | if (!parseIntent(res, parser, true, true, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | return null; |
| 3620 | } |
| 3621 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3622 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 3623 | + mArchiveSourcePath + " " |
| 3624 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | } else { |
| 3626 | a.intents.add(intent); |
| 3627 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3628 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 3629 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3630 | if (!parseIntent(res, parser, false, false, intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3631 | return null; |
| 3632 | } |
| 3633 | if (intent.countActions() == 0) { |
| 3634 | Slog.w(TAG, "No actions in preferred at " |
| 3635 | + mArchiveSourcePath + " " |
| 3636 | + parser.getPositionDescription()); |
| 3637 | } else { |
| 3638 | if (owner.preferredActivityFilters == null) { |
| 3639 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 3640 | } |
| 3641 | owner.preferredActivityFilters.add(intent); |
| 3642 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3644 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3645 | outError)) == null) { |
| 3646 | return null; |
| 3647 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3648 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3649 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | } else { |
| 3651 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3652 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3654 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3655 | + " at " + mArchiveSourcePath + " " |
| 3656 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3658 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3659 | + " at " + mArchiveSourcePath + " " |
| 3660 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
| 3662 | XmlUtils.skipCurrentTag(parser); |
| 3663 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3665 | if (receiver) { |
| 3666 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 3667 | } else { |
| 3668 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 3669 | } |
| 3670 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | if (!setExported) { |
| 3676 | a.info.exported = a.intents.size() > 0; |
| 3677 | } |
| 3678 | |
| 3679 | return a; |
| 3680 | } |
| 3681 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3682 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3683 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3684 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3685 | int width = -1; |
| 3686 | float widthFraction = -1f; |
| 3687 | int height = -1; |
| 3688 | float heightFraction = -1f; |
| 3689 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3690 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3691 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 3692 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3693 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3694 | 1, 1, -1); |
| 3695 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 3696 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3697 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3698 | -1); |
| 3699 | } |
| 3700 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3701 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3702 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 3703 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3704 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3705 | 1, 1, -1); |
| 3706 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 3707 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3708 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3709 | -1); |
| 3710 | } |
| 3711 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3712 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3713 | Gravity.CENTER); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 3714 | int minimalWidth = sw.getDimensionPixelSize( |
| 3715 | com.android.internal.R.styleable.AndroidManifestLayout_minimalWidth, |
| 3716 | -1); |
| 3717 | int minimalHeight = sw.getDimensionPixelSize( |
| 3718 | com.android.internal.R.styleable.AndroidManifestLayout_minimalHeight, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3719 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3720 | sw.recycle(); |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 3721 | a.info.windowLayout = new ActivityInfo.WindowLayout(width, widthFraction, |
| 3722 | height, heightFraction, gravity, minimalWidth, minimalHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | private Activity parseActivityAlias(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3726 | XmlResourceParser parser, int flags, String[] outError) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3727 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3728 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 3730 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3731 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3732 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 3733 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | if (targetActivity == null) { |
| 3735 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 3736 | sa.recycle(); |
| 3737 | return null; |
| 3738 | } |
| 3739 | |
| 3740 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 3741 | targetActivity, outError); |
| 3742 | if (targetActivity == null) { |
| 3743 | sa.recycle(); |
| 3744 | return null; |
| 3745 | } |
| 3746 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3747 | if (mParseActivityAliasArgs == null) { |
| 3748 | mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, |
| 3749 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 3750 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 3751 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3752 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3753 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3754 | mSeparateProcesses, |
| 3755 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3756 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3757 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
| 3758 | mParseActivityAliasArgs.tag = "<activity-alias>"; |
| 3759 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3760 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3761 | mParseActivityAliasArgs.sa = sa; |
| 3762 | mParseActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | Activity target = null; |
| 3765 | |
| 3766 | final int NA = owner.activities.size(); |
| 3767 | for (int i=0; i<NA; i++) { |
| 3768 | Activity t = owner.activities.get(i); |
| 3769 | if (targetActivity.equals(t.info.name)) { |
| 3770 | target = t; |
| 3771 | break; |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | if (target == null) { |
| 3776 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 3777 | + " not found in manifest"; |
| 3778 | sa.recycle(); |
| 3779 | return null; |
| 3780 | } |
| 3781 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3782 | ActivityInfo info = new ActivityInfo(); |
| 3783 | info.targetActivity = targetActivity; |
| 3784 | info.configChanges = target.info.configChanges; |
| 3785 | info.flags = target.info.flags; |
| 3786 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3787 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3788 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3789 | info.labelRes = target.info.labelRes; |
| 3790 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 3791 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 3792 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3793 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3794 | if (info.descriptionRes == 0) { |
| 3795 | info.descriptionRes = target.info.descriptionRes; |
| 3796 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3797 | info.screenOrientation = target.info.screenOrientation; |
| 3798 | info.taskAffinity = target.info.taskAffinity; |
| 3799 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 3800 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3801 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3802 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 3803 | info.maxRecents = target.info.maxRecents; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 3804 | info.windowLayout = target.info.windowLayout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3805 | info.resizeMode = target.info.resizeMode; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3806 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 3807 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3808 | Activity a = new Activity(mParseActivityAliasArgs, info); |
| 3809 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | sa.recycle(); |
| 3811 | return null; |
| 3812 | } |
| 3813 | |
| 3814 | final boolean setExported = sa.hasValue( |
| 3815 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 3816 | if (setExported) { |
| 3817 | a.info.exported = sa.getBoolean( |
| 3818 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 3819 | } |
| 3820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3822 | str = sa.getNonConfigurationString( |
| 3823 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | if (str != null) { |
| 3825 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 3826 | } |
| 3827 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3828 | String parentName = sa.getNonConfigurationString( |
| 3829 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3830 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3831 | if (parentName != null) { |
| 3832 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 3833 | if (outError[0] == null) { |
| 3834 | a.info.parentActivityName = parentClassName; |
| 3835 | } else { |
| 3836 | Log.e(TAG, "Activity alias " + a.info.name + |
| 3837 | " specified invalid parentActivityName " + parentName); |
| 3838 | outError[0] = null; |
| 3839 | } |
| 3840 | } |
| 3841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | sa.recycle(); |
| 3843 | |
| 3844 | if (outError[0] != null) { |
| 3845 | return null; |
| 3846 | } |
| 3847 | |
| 3848 | int outerDepth = parser.getDepth(); |
| 3849 | int type; |
| 3850 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 3851 | && (type != XmlPullParser.END_TAG |
| 3852 | || parser.getDepth() > outerDepth)) { |
| 3853 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3854 | continue; |
| 3855 | } |
| 3856 | |
| 3857 | if (parser.getName().equals("intent-filter")) { |
| 3858 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3859 | if (!parseIntent(res, parser, true, true, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3860 | return null; |
| 3861 | } |
| 3862 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3863 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 3864 | + mArchiveSourcePath + " " |
| 3865 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | } else { |
| 3867 | a.intents.add(intent); |
| 3868 | } |
| 3869 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3870 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | outError)) == null) { |
| 3872 | return null; |
| 3873 | } |
| 3874 | } else { |
| 3875 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3876 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3877 | + " at " + mArchiveSourcePath + " " |
| 3878 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | XmlUtils.skipCurrentTag(parser); |
| 3880 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3881 | } else { |
| 3882 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 3883 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | if (!setExported) { |
| 3889 | a.info.exported = a.intents.size() > 0; |
| 3890 | } |
| 3891 | |
| 3892 | return a; |
| 3893 | } |
| 3894 | |
| 3895 | private Provider parseProvider(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3896 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3898 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 3900 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3901 | if (mParseProviderArgs == null) { |
| 3902 | mParseProviderArgs = new ParseComponentArgs(owner, outError, |
| 3903 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 3904 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 3905 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3906 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3907 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3908 | mSeparateProcesses, |
| 3909 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3910 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3911 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
| 3912 | mParseProviderArgs.tag = "<provider>"; |
| 3913 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3914 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3915 | mParseProviderArgs.sa = sa; |
| 3916 | mParseProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3917 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3918 | Provider p = new Provider(mParseProviderArgs, new ProviderInfo()); |
| 3919 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | sa.recycle(); |
| 3921 | return null; |
| 3922 | } |
| 3923 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 3924 | boolean providerExportedDefault = false; |
| 3925 | |
| 3926 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 3927 | // For compatibility, applications targeting API level 16 or lower |
| 3928 | // should have their content providers exported by default, unless they |
| 3929 | // specify otherwise. |
| 3930 | providerExportedDefault = true; |
| 3931 | } |
| 3932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 3934 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 3935 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3937 | String cpname = sa.getNonConfigurationString( |
| 3938 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | |
| 3940 | p.info.isSyncable = sa.getBoolean( |
| 3941 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 3942 | false); |
| 3943 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3944 | String permission = sa.getNonConfigurationString( |
| 3945 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 3946 | String str = sa.getNonConfigurationString( |
| 3947 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | if (str == null) { |
| 3949 | str = permission; |
| 3950 | } |
| 3951 | if (str == null) { |
| 3952 | p.info.readPermission = owner.applicationInfo.permission; |
| 3953 | } else { |
| 3954 | p.info.readPermission = |
| 3955 | str.length() > 0 ? str.toString().intern() : null; |
| 3956 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3957 | str = sa.getNonConfigurationString( |
| 3958 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | if (str == null) { |
| 3960 | str = permission; |
| 3961 | } |
| 3962 | if (str == null) { |
| 3963 | p.info.writePermission = owner.applicationInfo.permission; |
| 3964 | } else { |
| 3965 | p.info.writePermission = |
| 3966 | str.length() > 0 ? str.toString().intern() : null; |
| 3967 | } |
| 3968 | |
| 3969 | p.info.grantUriPermissions = sa.getBoolean( |
| 3970 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 3971 | false); |
| 3972 | |
| 3973 | p.info.multiprocess = sa.getBoolean( |
| 3974 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 3975 | false); |
| 3976 | |
| 3977 | p.info.initOrder = sa.getInt( |
| 3978 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 3979 | 0); |
| 3980 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3981 | p.info.flags = 0; |
| 3982 | |
| 3983 | if (sa.getBoolean( |
| 3984 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 3985 | false)) { |
| 3986 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3987 | if (p.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3988 | Slog.w(TAG, "Provider exported request ignored due to singleUser: " |
| 3989 | + p.className + " at " + mArchiveSourcePath + " " |
| 3990 | + parser.getPositionDescription()); |
| 3991 | p.info.exported = false; |
| 3992 | } |
| 3993 | } |
| 3994 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3995 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 3996 | R.styleable.AndroidManifestProvider_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 3997 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3998 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3999 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4000 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4001 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | sa.recycle(); |
| 4004 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4005 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 4006 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4007 | // A heavy-weight application can not have providers in its main process |
| 4008 | // We can do direct compare because we intern all strings. |
| 4009 | if (p.info.processName == owner.packageName) { |
| 4010 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 4011 | return null; |
| 4012 | } |
| 4013 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 4016 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | return null; |
| 4018 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 4019 | if (cpname.length() <= 0) { |
| 4020 | outError[0] = "<provider> has empty authorities attribute"; |
| 4021 | return null; |
| 4022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | p.info.authority = cpname.intern(); |
| 4024 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4025 | if (!parseProviderTags(res, parser, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | return null; |
| 4027 | } |
| 4028 | |
| 4029 | return p; |
| 4030 | } |
| 4031 | |
| 4032 | private boolean parseProviderTags(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4033 | XmlResourceParser parser, Provider outInfo, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | throws XmlPullParserException, IOException { |
| 4035 | int outerDepth = parser.getDepth(); |
| 4036 | int type; |
| 4037 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4038 | && (type != XmlPullParser.END_TAG |
| 4039 | || parser.getDepth() > outerDepth)) { |
| 4040 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4041 | continue; |
| 4042 | } |
| 4043 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4044 | if (parser.getName().equals("intent-filter")) { |
| 4045 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4046 | if (!parseIntent(res, parser, true, false, intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 4047 | return false; |
| 4048 | } |
| 4049 | outInfo.intents.add(intent); |
| 4050 | |
| 4051 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4052 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4053 | outInfo.metaData, outError)) == null) { |
| 4054 | return false; |
| 4055 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4058 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4059 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 4060 | |
| 4061 | PatternMatcher pa = null; |
| 4062 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4063 | String str = sa.getNonConfigurationString( |
| 4064 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | if (str != null) { |
| 4066 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 4067 | } |
| 4068 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4069 | str = sa.getNonConfigurationString( |
| 4070 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4071 | if (str != null) { |
| 4072 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 4073 | } |
| 4074 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4075 | str = sa.getNonConfigurationString( |
| 4076 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | if (str != null) { |
| 4078 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4079 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4081 | sa.recycle(); |
| 4082 | |
| 4083 | if (pa != null) { |
| 4084 | if (outInfo.info.uriPermissionPatterns == null) { |
| 4085 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 4086 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 4087 | } else { |
| 4088 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 4089 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 4090 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 4091 | newp[N] = pa; |
| 4092 | outInfo.info.uriPermissionPatterns = newp; |
| 4093 | } |
| 4094 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4095 | } else { |
| 4096 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4097 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4098 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4099 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4100 | XmlUtils.skipCurrentTag(parser); |
| 4101 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4102 | } else { |
| 4103 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 4104 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4105 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4106 | } |
| 4107 | XmlUtils.skipCurrentTag(parser); |
| 4108 | |
| 4109 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4110 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4111 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 4112 | |
| 4113 | PathPermission pa = null; |
| 4114 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4115 | String permission = sa.getNonConfigurationString( |
| 4116 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 4117 | String readPermission = sa.getNonConfigurationString( |
| 4118 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4119 | if (readPermission == null) { |
| 4120 | readPermission = permission; |
| 4121 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4122 | String writePermission = sa.getNonConfigurationString( |
| 4123 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4124 | if (writePermission == null) { |
| 4125 | writePermission = permission; |
| 4126 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4127 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4128 | boolean havePerm = false; |
| 4129 | if (readPermission != null) { |
| 4130 | readPermission = readPermission.intern(); |
| 4131 | havePerm = true; |
| 4132 | } |
| 4133 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 4134 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4135 | havePerm = true; |
| 4136 | } |
| 4137 | |
| 4138 | if (!havePerm) { |
| 4139 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4140 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4141 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4142 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4143 | XmlUtils.skipCurrentTag(parser); |
| 4144 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4145 | } else { |
| 4146 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 4147 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4148 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4149 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4150 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4151 | String path = sa.getNonConfigurationString( |
| 4152 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4153 | if (path != null) { |
| 4154 | pa = new PathPermission(path, |
| 4155 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 4156 | } |
| 4157 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4158 | path = sa.getNonConfigurationString( |
| 4159 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4160 | if (path != null) { |
| 4161 | pa = new PathPermission(path, |
| 4162 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 4163 | } |
| 4164 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4165 | path = sa.getNonConfigurationString( |
| 4166 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4167 | if (path != null) { |
| 4168 | pa = new PathPermission(path, |
| 4169 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 4170 | } |
| 4171 | |
| 4172 | sa.recycle(); |
| 4173 | |
| 4174 | if (pa != null) { |
| 4175 | if (outInfo.info.pathPermissions == null) { |
| 4176 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 4177 | outInfo.info.pathPermissions[0] = pa; |
| 4178 | } else { |
| 4179 | final int N = outInfo.info.pathPermissions.length; |
| 4180 | PathPermission[] newp = new PathPermission[N+1]; |
| 4181 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 4182 | newp[N] = pa; |
| 4183 | outInfo.info.pathPermissions = newp; |
| 4184 | } |
| 4185 | } else { |
| 4186 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4187 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4188 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4189 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4190 | XmlUtils.skipCurrentTag(parser); |
| 4191 | continue; |
| 4192 | } |
| 4193 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 4194 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | } |
| 4196 | XmlUtils.skipCurrentTag(parser); |
| 4197 | |
| 4198 | } else { |
| 4199 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4200 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4201 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4202 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | XmlUtils.skipCurrentTag(parser); |
| 4204 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4205 | } else { |
| 4206 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 4207 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | } |
| 4210 | } |
| 4211 | return true; |
| 4212 | } |
| 4213 | |
| 4214 | private Service parseService(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4215 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4217 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4218 | com.android.internal.R.styleable.AndroidManifestService); |
| 4219 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4220 | if (mParseServiceArgs == null) { |
| 4221 | mParseServiceArgs = new ParseComponentArgs(owner, outError, |
| 4222 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 4223 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 4224 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4225 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4226 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4227 | mSeparateProcesses, |
| 4228 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4229 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4230 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
| 4231 | mParseServiceArgs.tag = "<service>"; |
| 4232 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4233 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4234 | mParseServiceArgs.sa = sa; |
| 4235 | mParseServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4236 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4237 | Service s = new Service(mParseServiceArgs, new ServiceInfo()); |
| 4238 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | sa.recycle(); |
| 4240 | return null; |
| 4241 | } |
| 4242 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4243 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 4245 | if (setExported) { |
| 4246 | s.info.exported = sa.getBoolean( |
| 4247 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 4248 | } |
| 4249 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4250 | String str = sa.getNonConfigurationString( |
| 4251 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | if (str == null) { |
| 4253 | s.info.permission = owner.applicationInfo.permission; |
| 4254 | } else { |
| 4255 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4256 | } |
| 4257 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4258 | s.info.flags = 0; |
| 4259 | if (sa.getBoolean( |
| 4260 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 4261 | false)) { |
| 4262 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 4263 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4264 | if (sa.getBoolean( |
| 4265 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 4266 | false)) { |
| 4267 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 4268 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4269 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 4270 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 4271 | false)) { |
| 4272 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 4273 | } |
| 4274 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4275 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 4276 | false)) { |
| 4277 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 4278 | if (s.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4279 | Slog.w(TAG, "Service exported request ignored due to singleUser: " |
| 4280 | + s.className + " at " + mArchiveSourcePath + " " |
| 4281 | + parser.getPositionDescription()); |
| 4282 | s.info.exported = false; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 4283 | setExported = true; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4284 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4285 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4286 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4287 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 4288 | R.styleable.AndroidManifestService_directBootAware, |
Todd Kennedy | d022ac2 | 2016-04-13 10:49:29 -0700 | [diff] [blame] | 4289 | false); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4290 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4291 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4292 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4293 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | sa.recycle(); |
| 4296 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4297 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 4298 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4299 | // A heavy-weight application can not have services in its main process |
| 4300 | // We can do direct compare because we intern all strings. |
| 4301 | if (s.info.processName == owner.packageName) { |
| 4302 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 4303 | return null; |
| 4304 | } |
| 4305 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | int outerDepth = parser.getDepth(); |
| 4308 | int type; |
| 4309 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4310 | && (type != XmlPullParser.END_TAG |
| 4311 | || parser.getDepth() > outerDepth)) { |
| 4312 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4313 | continue; |
| 4314 | } |
| 4315 | |
| 4316 | if (parser.getName().equals("intent-filter")) { |
| 4317 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4318 | if (!parseIntent(res, parser, true, false, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | return null; |
| 4320 | } |
| 4321 | |
| 4322 | s.intents.add(intent); |
| 4323 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4324 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | outError)) == null) { |
| 4326 | return null; |
| 4327 | } |
| 4328 | } else { |
| 4329 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4330 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4331 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4332 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | XmlUtils.skipCurrentTag(parser); |
| 4334 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4335 | } else { |
| 4336 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 4337 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | if (!setExported) { |
| 4343 | s.info.exported = s.intents.size() > 0; |
| 4344 | } |
| 4345 | |
| 4346 | return s; |
| 4347 | } |
| 4348 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4349 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 4350 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | int outerDepth = parser.getDepth(); |
| 4352 | int type; |
| 4353 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4354 | && (type != XmlPullParser.END_TAG |
| 4355 | || parser.getDepth() > outerDepth)) { |
| 4356 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4357 | continue; |
| 4358 | } |
| 4359 | |
| 4360 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4361 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | outInfo.metaData, outError)) == null) { |
| 4363 | return false; |
| 4364 | } |
| 4365 | } else { |
| 4366 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4367 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4368 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4369 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | XmlUtils.skipCurrentTag(parser); |
| 4371 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4372 | } else { |
| 4373 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 4374 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | return true; |
| 4379 | } |
| 4380 | |
| 4381 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4382 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | throws XmlPullParserException, IOException { |
| 4384 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4385 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 4387 | |
| 4388 | if (data == null) { |
| 4389 | data = new Bundle(); |
| 4390 | } |
| 4391 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4392 | String name = sa.getNonConfigurationString( |
| 4393 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | if (name == null) { |
| 4395 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 4396 | sa.recycle(); |
| 4397 | return null; |
| 4398 | } |
| 4399 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4400 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4402 | TypedValue v = sa.peekValue( |
| 4403 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 4404 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4405 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | data.putInt(name, v.resourceId); |
| 4407 | } else { |
| 4408 | v = sa.peekValue( |
| 4409 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4410 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | if (v != null) { |
| 4412 | if (v.type == TypedValue.TYPE_STRING) { |
| 4413 | CharSequence cs = v.coerceToString(); |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4414 | data.putString(name, cs != null ? cs.toString().intern() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 4416 | data.putBoolean(name, v.data != 0); |
| 4417 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 4418 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 4419 | data.putInt(name, v.data); |
| 4420 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 4421 | data.putFloat(name, v.getFloat()); |
| 4422 | } else { |
| 4423 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4424 | 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] | 4425 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4426 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | } else { |
| 4428 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 4429 | data = null; |
| 4430 | } |
| 4431 | } |
| 4432 | } else { |
| 4433 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 4434 | data = null; |
| 4435 | } |
| 4436 | } |
| 4437 | |
| 4438 | sa.recycle(); |
| 4439 | |
| 4440 | XmlUtils.skipCurrentTag(parser); |
| 4441 | |
| 4442 | return data; |
| 4443 | } |
| 4444 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4445 | private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser, |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4446 | AttributeSet attrs, int flags) { |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4447 | final TypedArray sa = res.obtainAttributes(attrs, |
| 4448 | com.android.internal.R.styleable.AndroidManifestPackageVerifier); |
| 4449 | |
| 4450 | final String packageName = sa.getNonResourceString( |
| 4451 | com.android.internal.R.styleable.AndroidManifestPackageVerifier_name); |
| 4452 | |
| 4453 | final String encodedPublicKey = sa.getNonResourceString( |
| 4454 | com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey); |
| 4455 | |
| 4456 | sa.recycle(); |
| 4457 | |
| 4458 | if (packageName == null || packageName.length() == 0) { |
| 4459 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 4460 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4463 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 4464 | if (publicKey == null) { |
| 4465 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 4466 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4469 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4470 | } |
| 4471 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4472 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 4473 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4474 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4475 | return null; |
| 4476 | } |
| 4477 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4478 | EncodedKeySpec keySpec; |
| 4479 | try { |
| 4480 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 4481 | keySpec = new X509EncodedKeySpec(encoded); |
| 4482 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4483 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4484 | return null; |
| 4485 | } |
| 4486 | |
| 4487 | /* First try the key as an RSA key. */ |
| 4488 | try { |
| 4489 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4490 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4491 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4492 | 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] | 4493 | } catch (InvalidKeySpecException e) { |
| 4494 | // Not a RSA public key. |
| 4495 | } |
| 4496 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4497 | /* Now try it as a ECDSA key. */ |
| 4498 | try { |
| 4499 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 4500 | return keyFactory.generatePublic(keySpec); |
| 4501 | } catch (NoSuchAlgorithmException e) { |
| 4502 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 4503 | } catch (InvalidKeySpecException e) { |
| 4504 | // Not a ECDSA public key. |
| 4505 | } |
| 4506 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4507 | /* Now try it as a DSA key. */ |
| 4508 | try { |
| 4509 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4510 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4511 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4512 | 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] | 4513 | } catch (InvalidKeySpecException e) { |
| 4514 | // Not a DSA public key. |
| 4515 | } |
| 4516 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4517 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4518 | return null; |
| 4519 | } |
| 4520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | private static final String ANDROID_RESOURCES |
| 4522 | = "http://schemas.android.com/apk/res/android"; |
| 4523 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4524 | private boolean parseIntent(Resources res, XmlResourceParser parser, |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 4525 | boolean allowGlobs, boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | throws XmlPullParserException, IOException { |
| 4527 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4528 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 4530 | |
| 4531 | int priority = sa.getInt( |
| 4532 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 4534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | TypedValue v = sa.peekValue( |
| 4536 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 4537 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4538 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4539 | } |
| 4540 | |
| 4541 | outInfo.icon = sa.getResourceId( |
| 4542 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4543 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4544 | outInfo.logo = sa.getResourceId( |
| 4545 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4546 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4547 | outInfo.banner = sa.getResourceId( |
| 4548 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 4549 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 4550 | if (allowAutoVerify) { |
| 4551 | outInfo.setAutoVerify(sa.getBoolean( |
| 4552 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 4553 | false)); |
| 4554 | } |
| 4555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | sa.recycle(); |
| 4557 | |
| 4558 | int outerDepth = parser.getDepth(); |
| 4559 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4560 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4561 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4562 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4563 | continue; |
| 4564 | } |
| 4565 | |
| 4566 | String nodeName = parser.getName(); |
| 4567 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4568 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | ANDROID_RESOURCES, "name"); |
| 4570 | if (value == null || value == "") { |
| 4571 | outError[0] = "No value supplied for <android:name>"; |
| 4572 | return false; |
| 4573 | } |
| 4574 | XmlUtils.skipCurrentTag(parser); |
| 4575 | |
| 4576 | outInfo.addAction(value); |
| 4577 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4578 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | ANDROID_RESOURCES, "name"); |
| 4580 | if (value == null || value == "") { |
| 4581 | outError[0] = "No value supplied for <android:name>"; |
| 4582 | return false; |
| 4583 | } |
| 4584 | XmlUtils.skipCurrentTag(parser); |
| 4585 | |
| 4586 | outInfo.addCategory(value); |
| 4587 | |
| 4588 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4589 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | com.android.internal.R.styleable.AndroidManifestData); |
| 4591 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4592 | String str = sa.getNonConfigurationString( |
| 4593 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | if (str != null) { |
| 4595 | try { |
| 4596 | outInfo.addDataType(str); |
| 4597 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 4598 | outError[0] = e.toString(); |
| 4599 | sa.recycle(); |
| 4600 | return false; |
| 4601 | } |
| 4602 | } |
| 4603 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4604 | str = sa.getNonConfigurationString( |
| 4605 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4606 | if (str != null) { |
| 4607 | outInfo.addDataScheme(str); |
| 4608 | } |
| 4609 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 4610 | str = sa.getNonConfigurationString( |
| 4611 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 4612 | if (str != null) { |
| 4613 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 4614 | } |
| 4615 | |
| 4616 | str = sa.getNonConfigurationString( |
| 4617 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 4618 | if (str != null) { |
| 4619 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 4620 | } |
| 4621 | |
| 4622 | str = sa.getNonConfigurationString( |
| 4623 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 4624 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4625 | if (!allowGlobs) { |
| 4626 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 4627 | return false; |
| 4628 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 4629 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4630 | } |
| 4631 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4632 | String host = sa.getNonConfigurationString( |
| 4633 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 4634 | String port = sa.getNonConfigurationString( |
| 4635 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4636 | if (host != null) { |
| 4637 | outInfo.addDataAuthority(host, port); |
| 4638 | } |
| 4639 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4640 | str = sa.getNonConfigurationString( |
| 4641 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | if (str != null) { |
| 4643 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 4644 | } |
| 4645 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4646 | str = sa.getNonConfigurationString( |
| 4647 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | if (str != null) { |
| 4649 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 4650 | } |
| 4651 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4652 | str = sa.getNonConfigurationString( |
| 4653 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4655 | if (!allowGlobs) { |
| 4656 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 4657 | return false; |
| 4658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4660 | } |
| 4661 | |
| 4662 | sa.recycle(); |
| 4663 | XmlUtils.skipCurrentTag(parser); |
| 4664 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4665 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4666 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4667 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4668 | XmlUtils.skipCurrentTag(parser); |
| 4669 | } else { |
| 4670 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 4671 | return false; |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4676 | |
| 4677 | if (DEBUG_PARSER) { |
| 4678 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 4679 | cats.append(outInfo.hasDefault); |
| 4680 | cats.append(", cat="); |
| 4681 | |
| 4682 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 4683 | if (it != null) { |
| 4684 | while (it.hasNext()) { |
| 4685 | cats.append(' '); |
| 4686 | cats.append(it.next()); |
| 4687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4689 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | return true; |
| 4693 | } |
| 4694 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4695 | /** |
| 4696 | * Representation of a full package parsed from APK files on disk. A package |
| 4697 | * consists of a single base APK, and zero or more split APKs. |
| 4698 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | public final static class Package { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 4700 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4701 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4702 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4703 | /** Names of any split APKs, ordered by parsed splitName */ |
| 4704 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4705 | |
| 4706 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4707 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 4708 | public String volumeUuid; |
| 4709 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4710 | /** |
| 4711 | * Path where this package was found on disk. For monolithic packages |
| 4712 | * this is path to single base APK file; for cluster packages this is |
| 4713 | * path to the cluster directory. |
| 4714 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4715 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4716 | |
| 4717 | /** Path of base APK */ |
| 4718 | public String baseCodePath; |
| 4719 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4720 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4722 | /** Revision code of base APK */ |
| 4723 | public int baseRevisionCode; |
| 4724 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 4725 | public int[] splitRevisionCodes; |
| 4726 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4727 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 4728 | public int[] splitFlags; |
| 4729 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4730 | /** |
| 4731 | * Private flags of any split APKs; ordered by parsed splitName. |
| 4732 | * |
| 4733 | * {@hide} |
| 4734 | */ |
| 4735 | public int[] splitPrivateFlags; |
| 4736 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4737 | public boolean baseHardwareAccelerated; |
| 4738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | // For now we only support one application per package. |
| 4740 | public final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 4741 | |
| 4742 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 4743 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 4744 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 4745 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 4746 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 4747 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 4748 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 4749 | |
| 4750 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 4751 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4752 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4753 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4754 | public Package parentPackage; |
| 4755 | public ArrayList<Package> childPackages; |
| 4756 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4757 | public ArrayList<String> libraryNames = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4758 | public ArrayList<String> usesLibraries = null; |
| 4759 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4760 | public String[] usesLibraryFiles = null; |
| 4761 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4762 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 4763 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 4764 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4765 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 4766 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4768 | // We store the application meta-data independently to avoid multiple unwanted references |
| 4769 | public Bundle mAppMetaData = null; |
| 4770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4771 | // The version code declared for this package. |
| 4772 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | // The version name declared for this package. |
| 4775 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4777 | // The shared user id that this package wants to use. |
| 4778 | public String mSharedUserId; |
| 4779 | |
| 4780 | // The shared user label that this package wants to use. |
| 4781 | public int mSharedUserLabel; |
| 4782 | |
| 4783 | // Signatures that were read from the package. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4784 | public Signature[] mSignatures; |
| 4785 | public Certificate[][] mCertificates; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | |
| 4787 | // For use by package manager service for quick lookup of |
| 4788 | // preferred up order. |
| 4789 | public int mPreferredOrder = 0; |
| 4790 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 4791 | // 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] | 4792 | public long[] mLastPackageUsageTimeInMills = |
| 4793 | new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 4794 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4795 | // // User set enabled state. |
| 4796 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 4797 | // |
| 4798 | // // Whether the package has been stopped. |
| 4799 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 4800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | // Additional data supplied by callers. |
| 4802 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 4803 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4804 | // Applications hardware preferences |
| 4805 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4806 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4807 | // Applications requested features |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4808 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 4809 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 4810 | // Applications requested feature groups |
| 4811 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 4812 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 4813 | public int installLocation; |
| 4814 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 4815 | public boolean coreApp; |
| 4816 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4817 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 4818 | public boolean mRequiredForAllUsers; |
| 4819 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 4820 | /* The restricted account authenticator type that is used by this application */ |
| 4821 | public String mRestrictedAccountType; |
| 4822 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 4823 | /* The required account type without which this application will not function */ |
| 4824 | public String mRequiredAccountType; |
| 4825 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 4826 | public String mOverlayTarget; |
| 4827 | public int mOverlayPriority; |
| 4828 | public boolean mTrustedOverlay; |
| 4829 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4830 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 4831 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4832 | */ |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 4833 | public ArraySet<PublicKey> mSigningKeys; |
| 4834 | public ArraySet<String> mUpgradeKeySets; |
| 4835 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4836 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 4837 | /** |
| 4838 | * The install time abi override for this package, if any. |
| 4839 | * |
| 4840 | * TODO: This seems like a horrible place to put the abiOverride because |
| 4841 | * this isn't something the packageParser parsers. However, this fits in with |
| 4842 | * the rest of the PackageManager where package scanning randomly pushes |
| 4843 | * and prods fields out of {@code this.applicationInfo}. |
| 4844 | */ |
| 4845 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4846 | /** |
| 4847 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 4848 | * are present. This is only meaningfull for multiarch applications. |
| 4849 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 4850 | */ |
| 4851 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 4852 | |
Todd Kennedy | fdd241a | 2016-04-28 12:26:53 -0700 | [diff] [blame] | 4853 | public byte[] restrictUpdateHash; |
| 4854 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4855 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 4856 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 4857 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4858 | applicationInfo.uid = -1; |
| 4859 | } |
| 4860 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4861 | public void setApplicationVolumeUuid(String volumeUuid) { |
| 4862 | this.applicationInfo.volumeUuid = volumeUuid; |
| 4863 | if (childPackages != null) { |
| 4864 | final int packageCount = childPackages.size(); |
| 4865 | for (int i = 0; i < packageCount; i++) { |
| 4866 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
| 4867 | } |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | public void setApplicationInfoCodePath(String codePath) { |
| 4872 | this.applicationInfo.setCodePath(codePath); |
| 4873 | if (childPackages != null) { |
| 4874 | final int packageCount = childPackages.size(); |
| 4875 | for (int i = 0; i < packageCount; i++) { |
| 4876 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 4877 | } |
| 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 4882 | this.applicationInfo.setResourcePath(resourcePath); |
| 4883 | if (childPackages != null) { |
| 4884 | final int packageCount = childPackages.size(); |
| 4885 | for (int i = 0; i < packageCount; i++) { |
| 4886 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 4887 | } |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 4892 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 4893 | if (childPackages != null) { |
| 4894 | final int packageCount = childPackages.size(); |
| 4895 | for (int i = 0; i < packageCount; i++) { |
| 4896 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 4897 | } |
| 4898 | } |
| 4899 | } |
| 4900 | |
| 4901 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 4902 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 4903 | if (childPackages != null) { |
| 4904 | final int packageCount = childPackages.size(); |
| 4905 | for (int i = 0; i < packageCount; i++) { |
| 4906 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | public boolean hasChildPackage(String packageName) { |
| 4912 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 4913 | for (int i = 0; i < childCount; i++) { |
| 4914 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 4915 | return true; |
| 4916 | } |
| 4917 | } |
| 4918 | return false; |
| 4919 | } |
| 4920 | |
| 4921 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 4922 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 4923 | // Children have no splits |
| 4924 | } |
| 4925 | |
| 4926 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 4927 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 4928 | // Children have no splits |
| 4929 | } |
| 4930 | |
| 4931 | public void setSplitCodePaths(String[] codePaths) { |
| 4932 | this.splitCodePaths = codePaths; |
| 4933 | } |
| 4934 | |
| 4935 | public void setCodePath(String codePath) { |
| 4936 | this.codePath = codePath; |
| 4937 | if (childPackages != null) { |
| 4938 | final int packageCount = childPackages.size(); |
| 4939 | for (int i = 0; i < packageCount; i++) { |
| 4940 | childPackages.get(i).codePath = codePath; |
| 4941 | } |
| 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | public void setBaseCodePath(String baseCodePath) { |
| 4946 | this.baseCodePath = baseCodePath; |
| 4947 | if (childPackages != null) { |
| 4948 | final int packageCount = childPackages.size(); |
| 4949 | for (int i = 0; i < packageCount; i++) { |
| 4950 | childPackages.get(i).baseCodePath = baseCodePath; |
| 4951 | } |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | public void setSignatures(Signature[] signatures) { |
| 4956 | this.mSignatures = signatures; |
| 4957 | if (childPackages != null) { |
| 4958 | final int packageCount = childPackages.size(); |
| 4959 | for (int i = 0; i < packageCount; i++) { |
| 4960 | childPackages.get(i).mSignatures = signatures; |
| 4961 | } |
| 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | public void setVolumeUuid(String volumeUuid) { |
| 4966 | this.volumeUuid = volumeUuid; |
| 4967 | if (childPackages != null) { |
| 4968 | final int packageCount = childPackages.size(); |
| 4969 | for (int i = 0; i < packageCount; i++) { |
| 4970 | childPackages.get(i).volumeUuid = volumeUuid; |
| 4971 | } |
| 4972 | } |
| 4973 | } |
| 4974 | |
| 4975 | public void setApplicationInfoFlags(int mask, int flags) { |
| 4976 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 4977 | if (childPackages != null) { |
| 4978 | final int packageCount = childPackages.size(); |
| 4979 | for (int i = 0; i < packageCount; i++) { |
| 4980 | childPackages.get(i).applicationInfo.flags = |
| 4981 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 4982 | } |
| 4983 | } |
| 4984 | } |
| 4985 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 4986 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4987 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4988 | if (childPackages != null) { |
| 4989 | final int packageCount = childPackages.size(); |
| 4990 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4991 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4992 | } |
| 4993 | } |
| 4994 | } |
| 4995 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4996 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4997 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4998 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4999 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 5000 | Collections.addAll(paths, splitCodePaths); |
| 5001 | } |
| 5002 | return paths; |
| 5003 | } |
| 5004 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 5005 | /** |
| 5006 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 5007 | * resource-only APKs. |
| 5008 | */ |
| 5009 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 5010 | ArrayList<String> paths = new ArrayList<>(); |
| 5011 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5012 | paths.add(baseCodePath); |
| 5013 | } |
| 5014 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 5015 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 5016 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5017 | paths.add(splitCodePaths[i]); |
| 5018 | } |
| 5019 | } |
| 5020 | } |
| 5021 | return paths; |
| 5022 | } |
| 5023 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5024 | public void setPackageName(String newName) { |
| 5025 | packageName = newName; |
| 5026 | applicationInfo.packageName = newName; |
| 5027 | for (int i=permissions.size()-1; i>=0; i--) { |
| 5028 | permissions.get(i).setPackageName(newName); |
| 5029 | } |
| 5030 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 5031 | permissionGroups.get(i).setPackageName(newName); |
| 5032 | } |
| 5033 | for (int i=activities.size()-1; i>=0; i--) { |
| 5034 | activities.get(i).setPackageName(newName); |
| 5035 | } |
| 5036 | for (int i=receivers.size()-1; i>=0; i--) { |
| 5037 | receivers.get(i).setPackageName(newName); |
| 5038 | } |
| 5039 | for (int i=providers.size()-1; i>=0; i--) { |
| 5040 | providers.get(i).setPackageName(newName); |
| 5041 | } |
| 5042 | for (int i=services.size()-1; i>=0; i--) { |
| 5043 | services.get(i).setPackageName(newName); |
| 5044 | } |
| 5045 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 5046 | instrumentation.get(i).setPackageName(newName); |
| 5047 | } |
| 5048 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 5049 | |
| 5050 | public boolean hasComponentClassName(String name) { |
| 5051 | for (int i=activities.size()-1; i>=0; i--) { |
| 5052 | if (name.equals(activities.get(i).className)) { |
| 5053 | return true; |
| 5054 | } |
| 5055 | } |
| 5056 | for (int i=receivers.size()-1; i>=0; i--) { |
| 5057 | if (name.equals(receivers.get(i).className)) { |
| 5058 | return true; |
| 5059 | } |
| 5060 | } |
| 5061 | for (int i=providers.size()-1; i>=0; i--) { |
| 5062 | if (name.equals(providers.get(i).className)) { |
| 5063 | return true; |
| 5064 | } |
| 5065 | } |
| 5066 | for (int i=services.size()-1; i>=0; i--) { |
| 5067 | if (name.equals(services.get(i).className)) { |
| 5068 | return true; |
| 5069 | } |
| 5070 | } |
| 5071 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 5072 | if (name.equals(instrumentation.get(i).className)) { |
| 5073 | return true; |
| 5074 | } |
| 5075 | } |
| 5076 | return false; |
| 5077 | } |
| 5078 | |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 5079 | /** |
| 5080 | * @hide |
| 5081 | */ |
| 5082 | public boolean isForwardLocked() { |
| 5083 | return applicationInfo.isForwardLocked(); |
| 5084 | } |
| 5085 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 5086 | /** |
| 5087 | * @hide |
| 5088 | */ |
| 5089 | public boolean isSystemApp() { |
| 5090 | return applicationInfo.isSystemApp(); |
| 5091 | } |
| 5092 | |
| 5093 | /** |
| 5094 | * @hide |
| 5095 | */ |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5096 | public boolean isPrivilegedApp() { |
| 5097 | return applicationInfo.isPrivilegedApp(); |
| 5098 | } |
| 5099 | |
| 5100 | /** |
| 5101 | * @hide |
| 5102 | */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 5103 | public boolean isUpdatedSystemApp() { |
| 5104 | return applicationInfo.isUpdatedSystemApp(); |
| 5105 | } |
| 5106 | |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 5107 | /** |
| 5108 | * @hide |
| 5109 | */ |
| 5110 | public boolean canHaveOatDir() { |
| 5111 | // The following app types CANNOT have oat directory |
| 5112 | // - non-updated system apps |
| 5113 | // - forward-locked apps or apps installed in ASEC containers |
| 5114 | return (!isSystemApp() || isUpdatedSystemApp()) |
| 5115 | && !isForwardLocked() && !applicationInfo.isExternalAsec(); |
| 5116 | } |
| 5117 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 5118 | public boolean isMatch(int flags) { |
| 5119 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
| 5120 | return isSystemApp(); |
| 5121 | } |
| 5122 | return true; |
| 5123 | } |
| 5124 | |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 5125 | public long getLatestPackageUseTimeInMills() { |
| 5126 | long latestUse = 0L; |
| 5127 | for (long use : mLastPackageUsageTimeInMills) { |
| 5128 | latestUse = Math.max(latestUse, use); |
| 5129 | } |
| 5130 | return latestUse; |
| 5131 | } |
| 5132 | |
David Brazdil | 90e2699 | 2016-04-18 14:08:52 +0100 | [diff] [blame] | 5133 | public long getLatestForegroundPackageUseTimeInMills() { |
| 5134 | int[] foregroundReasons = { |
| 5135 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, |
| 5136 | PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE |
| 5137 | }; |
| 5138 | |
| 5139 | long latestUse = 0L; |
| 5140 | for (int reason : foregroundReasons) { |
| 5141 | latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); |
| 5142 | } |
| 5143 | return latestUse; |
| 5144 | } |
| 5145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | public String toString() { |
| 5147 | return "Package{" |
| 5148 | + Integer.toHexString(System.identityHashCode(this)) |
| 5149 | + " " + packageName + "}"; |
| 5150 | } |
| 5151 | } |
| 5152 | |
| 5153 | public static class Component<II extends IntentInfo> { |
| 5154 | public final Package owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5155 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5156 | public final String className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5157 | public Bundle metaData; |
| 5158 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5159 | ComponentName componentName; |
| 5160 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | public Component(Package _owner) { |
| 5163 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5164 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5165 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 5169 | owner = args.owner; |
| 5170 | intents = new ArrayList<II>(0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5171 | String name = args.sa.getNonConfigurationString(args.nameRes, 0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5172 | if (name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5173 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5174 | args.outError[0] = args.tag + " does not specify android:name"; |
| 5175 | return; |
| 5176 | } |
| 5177 | |
| 5178 | outInfo.name |
| 5179 | = buildClassName(owner.applicationInfo.packageName, name, args.outError); |
| 5180 | if (outInfo.name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5181 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5182 | args.outError[0] = args.tag + " does not have valid android:name"; |
| 5183 | return; |
| 5184 | } |
| 5185 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5186 | className = outInfo.name; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5187 | |
| 5188 | int iconVal = args.sa.getResourceId(args.iconRes, 0); |
| 5189 | if (iconVal != 0) { |
| 5190 | outInfo.icon = iconVal; |
| 5191 | outInfo.nonLocalizedLabel = null; |
| 5192 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5193 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5194 | int logoVal = args.sa.getResourceId(args.logoRes, 0); |
| 5195 | if (logoVal != 0) { |
| 5196 | outInfo.logo = logoVal; |
| 5197 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5198 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5199 | int bannerVal = args.sa.getResourceId(args.bannerRes, 0); |
| 5200 | if (bannerVal != 0) { |
| 5201 | outInfo.banner = bannerVal; |
| 5202 | } |
| 5203 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5204 | TypedValue v = args.sa.peekValue(args.labelRes); |
| 5205 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5206 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5207 | } |
| 5208 | |
| 5209 | outInfo.packageName = owner.packageName; |
| 5210 | } |
| 5211 | |
| 5212 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 5213 | this(args, (PackageItemInfo)outInfo); |
| 5214 | if (args.outError[0] != null) { |
| 5215 | return; |
| 5216 | } |
| 5217 | |
| 5218 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5219 | CharSequence pname; |
| 5220 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 5221 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 5222 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5223 | } else { |
| 5224 | // Some older apps have been seen to use a resource reference |
| 5225 | // here that on older builds was ignored (with a warning). We |
| 5226 | // need to continue to do this for them so they don't break. |
| 5227 | pname = args.sa.getNonResourceString(args.processRes); |
| 5228 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5229 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5230 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5231 | args.flags, args.sepProcesses, args.outError); |
| 5232 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5233 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5234 | if (args.descriptionRes != 0) { |
| 5235 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 5236 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5237 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5238 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | public Component(Component<II> clone) { |
| 5242 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5243 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5244 | className = clone.className; |
| 5245 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5246 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5247 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5248 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5249 | public ComponentName getComponentName() { |
| 5250 | if (componentName != null) { |
| 5251 | return componentName; |
| 5252 | } |
| 5253 | if (className != null) { |
| 5254 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 5255 | className); |
| 5256 | } |
| 5257 | return componentName; |
| 5258 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5259 | |
| 5260 | public void appendComponentShortName(StringBuilder sb) { |
| 5261 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5262 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5263 | |
| 5264 | public void printComponentShortName(PrintWriter pw) { |
| 5265 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 5266 | } |
| 5267 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5268 | public void setPackageName(String packageName) { |
| 5269 | componentName = null; |
| 5270 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | } |
| 5272 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | public final static class Permission extends Component<IntentInfo> { |
| 5275 | public final PermissionInfo info; |
| 5276 | public boolean tree; |
| 5277 | public PermissionGroup group; |
| 5278 | |
| 5279 | public Permission(Package _owner) { |
| 5280 | super(_owner); |
| 5281 | info = new PermissionInfo(); |
| 5282 | } |
| 5283 | |
| 5284 | public Permission(Package _owner, PermissionInfo _info) { |
| 5285 | super(_owner); |
| 5286 | info = _info; |
| 5287 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5288 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5289 | public void setPackageName(String packageName) { |
| 5290 | super.setPackageName(packageName); |
| 5291 | info.packageName = packageName; |
| 5292 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | |
| 5294 | public String toString() { |
| 5295 | return "Permission{" |
| 5296 | + Integer.toHexString(System.identityHashCode(this)) |
| 5297 | + " " + info.name + "}"; |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | public final static class PermissionGroup extends Component<IntentInfo> { |
| 5302 | public final PermissionGroupInfo info; |
| 5303 | |
| 5304 | public PermissionGroup(Package _owner) { |
| 5305 | super(_owner); |
| 5306 | info = new PermissionGroupInfo(); |
| 5307 | } |
| 5308 | |
| 5309 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 5310 | super(_owner); |
| 5311 | info = _info; |
| 5312 | } |
| 5313 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5314 | public void setPackageName(String packageName) { |
| 5315 | super.setPackageName(packageName); |
| 5316 | info.packageName = packageName; |
| 5317 | } |
| 5318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | public String toString() { |
| 5320 | return "PermissionGroup{" |
| 5321 | + Integer.toHexString(System.identityHashCode(this)) |
| 5322 | + " " + info.name + "}"; |
| 5323 | } |
| 5324 | } |
| 5325 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5326 | private static boolean copyNeeded(int flags, Package p, |
| 5327 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 5328 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5329 | // We always need to copy for other users, since we need |
| 5330 | // to fix up the uid. |
| 5331 | return true; |
| 5332 | } |
| 5333 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 5334 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 5335 | if (p.applicationInfo.enabled != enabled) { |
| 5336 | return true; |
| 5337 | } |
| 5338 | } |
Rubin Xu | bf67c9c | 2016-04-20 17:09:38 +0100 | [diff] [blame] | 5339 | boolean suspended = (p.applicationInfo.flags & FLAG_SUSPENDED) != 0; |
| 5340 | if (state.suspended != suspended) { |
| 5341 | return true; |
| 5342 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5343 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5344 | return true; |
| 5345 | } |
| 5346 | if (state.stopped) { |
| 5347 | return true; |
| 5348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 5350 | && (metaData != null || p.mAppMetaData != null)) { |
| 5351 | return true; |
| 5352 | } |
| 5353 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 5354 | && p.usesLibraryFiles != null) { |
| 5355 | return true; |
| 5356 | } |
| 5357 | return false; |
| 5358 | } |
| 5359 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5360 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 5361 | PackageUserState state) { |
| 5362 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5365 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 5366 | PackageUserState state) { |
| 5367 | // CompatibilityMode is global state. |
| 5368 | if (!sCompatibilityModeEnabled) { |
| 5369 | ai.disableCompatibilityMode(); |
| 5370 | } |
| 5371 | if (state.installed) { |
| 5372 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 5373 | } else { |
| 5374 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 5375 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5376 | if (state.suspended) { |
| 5377 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 5378 | } else { |
| 5379 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 5380 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5381 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5382 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 5383 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5384 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 5385 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5386 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 5387 | ai.enabled = true; |
| 5388 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 5389 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 5390 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 5391 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 5392 | ai.enabled = false; |
| 5393 | } |
| 5394 | ai.enabledSetting = state.enabled; |
| 5395 | } |
| 5396 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 5397 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5398 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5399 | if (p == null) return null; |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 5400 | if (!checkUseInstalledOrHidden(flags, state) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5401 | return null; |
| 5402 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5403 | if (!copyNeeded(flags, p, state, null, userId) |
| 5404 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 5405 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 5406 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 5407 | // - CompatibilityMode is global state, so will be the same for every call. |
| 5408 | // - We only come in to here if the app should reported as installed; this is the |
| 5409 | // default state, and we will do a copy otherwise. |
| 5410 | // - The enable state will always be reported the same for the application across |
| 5411 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 5412 | // be doing a copy. |
| 5413 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | return p.applicationInfo; |
| 5415 | } |
| 5416 | |
| 5417 | // Make shallow copy so we can store the metadata/libraries safely |
| 5418 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5419 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 5421 | ai.metaData = p.mAppMetaData; |
| 5422 | } |
| 5423 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 5424 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 5425 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5426 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 5427 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 5428 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 5429 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 5430 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5431 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | return ai; |
| 5433 | } |
| 5434 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5435 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 5436 | PackageUserState state, int userId) { |
| 5437 | if (ai == null) return null; |
| 5438 | if (!checkUseInstalledOrHidden(flags, state)) { |
| 5439 | return null; |
| 5440 | } |
| 5441 | // This is only used to return the ResolverActivity; we will just always |
| 5442 | // make a copy. |
| 5443 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5444 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5445 | if (state.stopped) { |
| 5446 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 5447 | } else { |
| 5448 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 5449 | } |
| 5450 | updateApplicationInfo(ai, flags, state); |
| 5451 | return ai; |
| 5452 | } |
| 5453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5454 | public static final PermissionInfo generatePermissionInfo( |
| 5455 | Permission p, int flags) { |
| 5456 | if (p == null) return null; |
| 5457 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5458 | return p.info; |
| 5459 | } |
| 5460 | PermissionInfo pi = new PermissionInfo(p.info); |
| 5461 | pi.metaData = p.metaData; |
| 5462 | return pi; |
| 5463 | } |
| 5464 | |
| 5465 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 5466 | PermissionGroup pg, int flags) { |
| 5467 | if (pg == null) return null; |
| 5468 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5469 | return pg.info; |
| 5470 | } |
| 5471 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 5472 | pgi.metaData = pg.metaData; |
| 5473 | return pgi; |
| 5474 | } |
| 5475 | |
| 5476 | public final static class Activity extends Component<ActivityIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5477 | public final ActivityInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5478 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5479 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 5480 | super(args, _info); |
| 5481 | info = _info; |
| 5482 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5483 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5484 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5485 | public void setPackageName(String packageName) { |
| 5486 | super.setPackageName(packageName); |
| 5487 | info.packageName = packageName; |
| 5488 | } |
| 5489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5491 | StringBuilder sb = new StringBuilder(128); |
| 5492 | sb.append("Activity{"); |
| 5493 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5494 | sb.append(' '); |
| 5495 | appendComponentShortName(sb); |
| 5496 | sb.append('}'); |
| 5497 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5498 | } |
| 5499 | } |
| 5500 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5501 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 5502 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | if (a == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5504 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5505 | return null; |
| 5506 | } |
| 5507 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | return a.info; |
| 5509 | } |
| 5510 | // Make shallow copies so we can store the metadata safely |
| 5511 | ActivityInfo ai = new ActivityInfo(a.info); |
| 5512 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5513 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | return ai; |
| 5515 | } |
| 5516 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5517 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 5518 | PackageUserState state, int userId) { |
| 5519 | if (ai == null) return null; |
| 5520 | if (!checkUseInstalledOrHidden(flags, state)) { |
| 5521 | return null; |
| 5522 | } |
| 5523 | // This is only used to return the ResolverActivity; we will just always |
| 5524 | // make a copy. |
| 5525 | ai = new ActivityInfo(ai); |
| 5526 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 5527 | return ai; |
| 5528 | } |
| 5529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5530 | public final static class Service extends Component<ServiceIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5531 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5533 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 5534 | super(args, _info); |
| 5535 | info = _info; |
| 5536 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5538 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5539 | public void setPackageName(String packageName) { |
| 5540 | super.setPackageName(packageName); |
| 5541 | info.packageName = packageName; |
| 5542 | } |
| 5543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5544 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5545 | StringBuilder sb = new StringBuilder(128); |
| 5546 | sb.append("Service{"); |
| 5547 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5548 | sb.append(' '); |
| 5549 | appendComponentShortName(sb); |
| 5550 | sb.append('}'); |
| 5551 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | } |
| 5553 | } |
| 5554 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5555 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 5556 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | if (s == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5558 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5559 | return null; |
| 5560 | } |
| 5561 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | return s.info; |
| 5563 | } |
| 5564 | // Make shallow copies so we can store the metadata safely |
| 5565 | ServiceInfo si = new ServiceInfo(s.info); |
| 5566 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5567 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | return si; |
| 5569 | } |
| 5570 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5571 | public final static class Provider extends Component<ProviderIntentInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | public final ProviderInfo info; |
| 5573 | public boolean syncable; |
| 5574 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5575 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 5576 | super(args, _info); |
| 5577 | info = _info; |
| 5578 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | syncable = false; |
| 5580 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | public Provider(Provider existingProvider) { |
| 5583 | super(existingProvider); |
| 5584 | this.info = existingProvider.info; |
| 5585 | this.syncable = existingProvider.syncable; |
| 5586 | } |
| 5587 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5588 | public void setPackageName(String packageName) { |
| 5589 | super.setPackageName(packageName); |
| 5590 | info.packageName = packageName; |
| 5591 | } |
| 5592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5593 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5594 | StringBuilder sb = new StringBuilder(128); |
| 5595 | sb.append("Provider{"); |
| 5596 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5597 | sb.append(' '); |
| 5598 | appendComponentShortName(sb); |
| 5599 | sb.append('}'); |
| 5600 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | } |
| 5602 | } |
| 5603 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5604 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 5605 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | if (p == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5607 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5608 | return null; |
| 5609 | } |
| 5610 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5612 | || p.info.uriPermissionPatterns == null)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | return p.info; |
| 5614 | } |
| 5615 | // Make shallow copies so we can store the metadata safely |
| 5616 | ProviderInfo pi = new ProviderInfo(p.info); |
| 5617 | pi.metaData = p.metaData; |
| 5618 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 5619 | pi.uriPermissionPatterns = null; |
| 5620 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5621 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | return pi; |
| 5623 | } |
| 5624 | |
Todd Kennedy | 0f4bc2b | 2016-04-06 07:46:13 -0700 | [diff] [blame] | 5625 | public final static class Instrumentation extends Component<IntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5626 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5628 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 5629 | super(args, _info); |
| 5630 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5632 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5633 | public void setPackageName(String packageName) { |
| 5634 | super.setPackageName(packageName); |
| 5635 | info.packageName = packageName; |
| 5636 | } |
| 5637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5638 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5639 | StringBuilder sb = new StringBuilder(128); |
| 5640 | sb.append("Instrumentation{"); |
| 5641 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5642 | sb.append(' '); |
| 5643 | appendComponentShortName(sb); |
| 5644 | sb.append('}'); |
| 5645 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 5650 | Instrumentation i, int flags) { |
| 5651 | if (i == null) return null; |
| 5652 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5653 | return i.info; |
| 5654 | } |
| 5655 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 5656 | ii.metaData = i.metaData; |
| 5657 | return ii; |
| 5658 | } |
| 5659 | |
| 5660 | public static class IntentInfo extends IntentFilter { |
| 5661 | public boolean hasDefault; |
| 5662 | public int labelRes; |
| 5663 | public CharSequence nonLocalizedLabel; |
| 5664 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5665 | public int logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5666 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5667 | public int preferred; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | public final static class ActivityIntentInfo extends IntentInfo { |
| 5671 | public final Activity activity; |
| 5672 | |
| 5673 | public ActivityIntentInfo(Activity _activity) { |
| 5674 | activity = _activity; |
| 5675 | } |
| 5676 | |
| 5677 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5678 | StringBuilder sb = new StringBuilder(128); |
| 5679 | sb.append("ActivityIntentInfo{"); |
| 5680 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5681 | sb.append(' '); |
| 5682 | activity.appendComponentShortName(sb); |
| 5683 | sb.append('}'); |
| 5684 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | public final static class ServiceIntentInfo extends IntentInfo { |
| 5689 | public final Service service; |
| 5690 | |
| 5691 | public ServiceIntentInfo(Service _service) { |
| 5692 | service = _service; |
| 5693 | } |
| 5694 | |
| 5695 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5696 | StringBuilder sb = new StringBuilder(128); |
| 5697 | sb.append("ServiceIntentInfo{"); |
| 5698 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5699 | sb.append(' '); |
| 5700 | service.appendComponentShortName(sb); |
| 5701 | sb.append('}'); |
| 5702 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | } |
| 5704 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 5705 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5706 | public static final class ProviderIntentInfo extends IntentInfo { |
| 5707 | public final Provider provider; |
| 5708 | |
| 5709 | public ProviderIntentInfo(Provider provider) { |
| 5710 | this.provider = provider; |
| 5711 | } |
| 5712 | |
| 5713 | public String toString() { |
| 5714 | StringBuilder sb = new StringBuilder(128); |
| 5715 | sb.append("ProviderIntentInfo{"); |
| 5716 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5717 | sb.append(' '); |
| 5718 | provider.appendComponentShortName(sb); |
| 5719 | sb.append('}'); |
| 5720 | return sb.toString(); |
| 5721 | } |
| 5722 | } |
| 5723 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 5724 | /** |
| 5725 | * @hide |
| 5726 | */ |
| 5727 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 5728 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 5729 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5730 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 5731 | private static AtomicReference<byte[]> sBuffer = new AtomicReference<byte[]>(); |
| 5732 | |
| 5733 | public static long readFullyIgnoringContents(InputStream in) throws IOException { |
| 5734 | byte[] buffer = sBuffer.getAndSet(null); |
| 5735 | if (buffer == null) { |
| 5736 | buffer = new byte[4096]; |
| 5737 | } |
| 5738 | |
| 5739 | int n = 0; |
| 5740 | int count = 0; |
| 5741 | while ((n = in.read(buffer, 0, buffer.length)) != -1) { |
| 5742 | count += n; |
| 5743 | } |
| 5744 | |
| 5745 | sBuffer.set(buffer); |
| 5746 | return count; |
| 5747 | } |
| 5748 | |
| 5749 | public static void closeQuietly(StrictJarFile jarFile) { |
| 5750 | if (jarFile != null) { |
| 5751 | try { |
| 5752 | jarFile.close(); |
| 5753 | } catch (Exception ignored) { |
| 5754 | } |
| 5755 | } |
| 5756 | } |
| 5757 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5758 | public static class PackageParserException extends Exception { |
| 5759 | public final int error; |
| 5760 | |
| 5761 | public PackageParserException(int error, String detailMessage) { |
| 5762 | super(detailMessage); |
| 5763 | this.error = error; |
| 5764 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 5765 | |
| 5766 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 5767 | super(detailMessage, throwable); |
| 5768 | this.error = error; |
| 5769 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | } |