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; |
| 82 | import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS; |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 83 | import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 84 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; |
| 85 | import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
| 86 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 87 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
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 | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 122 | private static final int MAX_PACKAGES_PER_APK = 5; |
| 123 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 124 | public static final int APK_SIGNING_UNKNOWN = 0; |
| 125 | public static final int APK_SIGNING_V1 = 1; |
| 126 | public static final int APK_SIGNING_V2 = 2; |
| 127 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 128 | // TODO: switch outError users to PackageParserException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 129 | // TODO: refactor "codePath" to "apkPath" |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 130 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 131 | /** File name in an APK for the Android manifest. */ |
| 132 | private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
| 133 | |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 134 | /** |
| 135 | * File name in an APK for bytecode. There may be additional bytecode files |
| 136 | * but this one is always required for an APK that has code. |
| 137 | */ |
| 138 | private static final String BYTECODE_FILENAME = "classes.dex"; |
| 139 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 140 | /** Path prefix for apps on expanded storage */ |
| 141 | private static final String MNT_EXPAND = "/mnt/expand/"; |
| 142 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 143 | private static final String TAG_MANIFEST = "manifest"; |
| 144 | private static final String TAG_APPLICATION = "application"; |
| 145 | private static final String TAG_OVERLAY = "overlay"; |
| 146 | private static final String TAG_KEY_SETS = "key-sets"; |
| 147 | private static final String TAG_PERMISSION_GROUP = "permission-group"; |
| 148 | private static final String TAG_PERMISSION = "permission"; |
| 149 | private static final String TAG_PERMISSION_TREE = "permission-tree"; |
| 150 | private static final String TAG_USES_PERMISSION = "uses-permission"; |
| 151 | private static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; |
| 152 | private static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; |
| 153 | private static final String TAG_USES_CONFIGURATION = "uses-configuration"; |
| 154 | private static final String TAG_USES_FEATURE = "uses-feature"; |
| 155 | private static final String TAG_FEATURE_GROUP = "feature-group"; |
| 156 | private static final String TAG_USES_SDK = "uses-sdk"; |
| 157 | private static final String TAG_SUPPORT_SCREENS = "supports-screens"; |
| 158 | private static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; |
| 159 | private static final String TAG_INSTRUMENTATION = "instrumentation"; |
| 160 | private static final String TAG_ORIGINAL_PACKAGE = "original-package"; |
| 161 | private static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; |
| 162 | private static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; |
| 163 | private static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; |
| 164 | private static final String TAG_SUPPORTS_INPUT = "supports-input"; |
| 165 | private static final String TAG_EAT_COMMENT = "eat-comment"; |
| 166 | private static final String TAG_PACKAGE = "package"; |
| 167 | |
| 168 | // These are the tags supported by child packages |
| 169 | private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>(); |
| 170 | static { |
| 171 | CHILD_PACKAGE_TAGS.add(TAG_APPLICATION); |
| 172 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION); |
| 173 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_M); |
| 174 | CHILD_PACKAGE_TAGS.add(TAG_USES_PERMISSION_SDK_23); |
| 175 | CHILD_PACKAGE_TAGS.add(TAG_USES_CONFIGURATION); |
| 176 | CHILD_PACKAGE_TAGS.add(TAG_USES_FEATURE); |
| 177 | CHILD_PACKAGE_TAGS.add(TAG_FEATURE_GROUP); |
| 178 | CHILD_PACKAGE_TAGS.add(TAG_USES_SDK); |
| 179 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORT_SCREENS); |
| 180 | CHILD_PACKAGE_TAGS.add(TAG_INSTRUMENTATION); |
| 181 | CHILD_PACKAGE_TAGS.add(TAG_USES_GL_TEXTURE); |
| 182 | CHILD_PACKAGE_TAGS.add(TAG_COMPATIBLE_SCREENS); |
| 183 | CHILD_PACKAGE_TAGS.add(TAG_SUPPORTS_INPUT); |
| 184 | CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); |
| 185 | } |
| 186 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 187 | /** @hide */ |
| 188 | public static class NewPermissionInfo { |
| 189 | public final String name; |
| 190 | public final int sdkVersion; |
| 191 | public final int fileVersion; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 192 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 193 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 194 | this.name = name; |
| 195 | this.sdkVersion = sdkVersion; |
| 196 | this.fileVersion = fileVersion; |
| 197 | } |
| 198 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 199 | |
| 200 | /** @hide */ |
| 201 | public static class SplitPermissionInfo { |
| 202 | public final String rootPerm; |
| 203 | public final String[] newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 204 | public final int targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 205 | |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 206 | public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) { |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 207 | this.rootPerm = rootPerm; |
| 208 | this.newPerms = newPerms; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 209 | this.targetSdk = targetSdk; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 213 | /** |
| 214 | * List of new permissions that have been added since 1.0. |
| 215 | * NOTE: These must be declared in SDK version order, with permissions |
| 216 | * added to older SDKs appearing before those added to newer SDKs. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 217 | * If sdkVersion is 0, then this is not a permission that we want to |
| 218 | * automatically add to older apps, but we do want to allow it to be |
| 219 | * granted during a platform update. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 220 | * @hide |
| 221 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 222 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 223 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 224 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 225 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 226 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 227 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 228 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 230 | /** |
| 231 | * List of permissions that have been split into more granular or dependent |
| 232 | * permissions. |
| 233 | * @hide |
| 234 | */ |
| 235 | public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] = |
| 236 | new PackageParser.SplitPermissionInfo[] { |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 237 | // READ_EXTERNAL_STORAGE is always required when an app requests |
| 238 | // WRITE_EXTERNAL_STORAGE, because we can't have an app that has |
| 239 | // write access without read access. The hack here with the target |
| 240 | // target SDK version ensures that this grant is always done. |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 241 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 242 | new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, |
Dianne Hackborn | 2bd8d04 | 2012-06-11 12:27:05 -0700 | [diff] [blame] | 243 | android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1), |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 244 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS, |
| 245 | new String[] { android.Manifest.permission.READ_CALL_LOG }, |
| 246 | android.os.Build.VERSION_CODES.JELLY_BEAN), |
| 247 | new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS, |
| 248 | new String[] { android.Manifest.permission.WRITE_CALL_LOG }, |
| 249 | android.os.Build.VERSION_CODES.JELLY_BEAN) |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 252 | /** |
| 253 | * @deprecated callers should move to explicitly passing around source path. |
| 254 | */ |
| 255 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | private String mArchiveSourcePath; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | private String[] mSeparateProcesses; |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 259 | private boolean mOnlyCoreApps; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 260 | private DisplayMetrics mMetrics; |
| 261 | |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 262 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 263 | 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] | 264 | |
| 265 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 266 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 267 | private static boolean sCompatibilityModeEnabled = true; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 268 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = |
| 269 | PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 270 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 271 | static class ParsePackageItemArgs { |
| 272 | final Package owner; |
| 273 | final String[] outError; |
| 274 | final int nameRes; |
| 275 | final int labelRes; |
| 276 | final int iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 277 | final int logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 278 | final int bannerRes; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 279 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 280 | String tag; |
| 281 | TypedArray sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 282 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 283 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 284 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 285 | owner = _owner; |
| 286 | outError = _outError; |
| 287 | nameRes = _nameRes; |
| 288 | labelRes = _labelRes; |
| 289 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 290 | logoRes = _logoRes; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 291 | bannerRes = _bannerRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 294 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 295 | static class ParseComponentArgs extends ParsePackageItemArgs { |
| 296 | final String[] sepProcesses; |
| 297 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 298 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 299 | final int enabledRes; |
| 300 | int flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 301 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 302 | ParseComponentArgs(Package _owner, String[] _outError, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 303 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 304 | String[] _sepProcesses, int _processRes, |
| 305 | int _descriptionRes, int _enabledRes) { |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 306 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes, _bannerRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 307 | sepProcesses = _sepProcesses; |
| 308 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 309 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 310 | enabledRes = _enabledRes; |
| 311 | } |
| 312 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 313 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 314 | /** |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 315 | * Lightweight parsed details about a single package. |
| 316 | */ |
| 317 | public static class PackageLite { |
| 318 | public final String packageName; |
| 319 | public final int versionCode; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 320 | public final int installLocation; |
| 321 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 322 | |
| 323 | /** Names of any split APKs, ordered by parsed splitName */ |
| 324 | public final String[] splitNames; |
| 325 | |
| 326 | /** |
| 327 | * Path where this package was found on disk. For monolithic packages |
| 328 | * this is path to single base APK file; for cluster packages this is |
| 329 | * path to the cluster directory. |
| 330 | */ |
| 331 | public final String codePath; |
| 332 | |
| 333 | /** Path of base APK */ |
| 334 | public final String baseCodePath; |
| 335 | /** Paths of any split APKs, ordered by parsed splitName */ |
| 336 | public final String[] splitCodePaths; |
| 337 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 338 | /** Revision code of base APK */ |
| 339 | public final int baseRevisionCode; |
| 340 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 341 | public final int[] splitRevisionCodes; |
| 342 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 343 | public final boolean coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 344 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 345 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 346 | public final boolean extractNativeLibs; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 347 | |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 348 | public PackageLite(String codePath, ApkLite baseApk, String[] splitNames, |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 349 | String[] splitCodePaths, int[] splitRevisionCodes) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 350 | this.packageName = baseApk.packageName; |
| 351 | this.versionCode = baseApk.versionCode; |
| 352 | this.installLocation = baseApk.installLocation; |
| 353 | this.verifiers = baseApk.verifiers; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 354 | this.splitNames = splitNames; |
| 355 | this.codePath = codePath; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 356 | this.baseCodePath = baseApk.codePath; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 357 | this.splitCodePaths = splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 358 | this.baseRevisionCode = baseApk.revisionCode; |
| 359 | this.splitRevisionCodes = splitRevisionCodes; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 360 | this.coreApp = baseApk.coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 361 | this.multiArch = baseApk.multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 362 | this.use32bitAbi = baseApk.use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 363 | this.extractNativeLibs = baseApk.extractNativeLibs; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | public List<String> getAllCodePaths() { |
| 367 | ArrayList<String> paths = new ArrayList<>(); |
| 368 | paths.add(baseCodePath); |
| 369 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 370 | Collections.addAll(paths, splitCodePaths); |
| 371 | } |
| 372 | return paths; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 377 | * Lightweight parsed details about a single APK file. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 378 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 379 | public static class ApkLite { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 380 | public final String codePath; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 381 | public final String packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 382 | public final String splitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 383 | public final int versionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 384 | public final int revisionCode; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 385 | public final int installLocation; |
| 386 | public final VerifierInfo[] verifiers; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 387 | public final Signature[] signatures; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 388 | public final boolean coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 389 | public final boolean multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 390 | public final boolean use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 391 | public final boolean extractNativeLibs; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 392 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 393 | public ApkLite(String codePath, String packageName, String splitName, int versionCode, |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 394 | int revisionCode, int installLocation, List<VerifierInfo> verifiers, |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 395 | Signature[] signatures, boolean coreApp, boolean multiArch, boolean use32bitAbi, |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 396 | boolean extractNativeLibs) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 397 | this.codePath = codePath; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 398 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 399 | this.splitName = splitName; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 400 | this.versionCode = versionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 401 | this.revisionCode = revisionCode; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 402 | this.installLocation = installLocation; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 403 | this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 404 | this.signatures = signatures; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 405 | this.coreApp = coreApp; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 406 | this.multiArch = multiArch; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 407 | this.use32bitAbi = use32bitAbi; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 408 | this.extractNativeLibs = extractNativeLibs; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 412 | private ParsePackageItemArgs mParseInstrumentationArgs; |
| 413 | private ParseComponentArgs mParseActivityArgs; |
| 414 | private ParseComponentArgs mParseActivityAliasArgs; |
| 415 | private ParseComponentArgs mParseServiceArgs; |
| 416 | private ParseComponentArgs mParseProviderArgs; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | /** If set to true, we will only allow package files that exactly match |
| 419 | * the DTD. Otherwise, we try to get as much from the package as we |
| 420 | * can without failing. This should normally be set to false, to |
| 421 | * support extensions to the DTD in future versions. */ |
| 422 | private static final boolean RIGID_PARSER = false; |
| 423 | |
| 424 | private static final String TAG = "PackageParser"; |
| 425 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 426 | public PackageParser() { |
| 427 | mMetrics = new DisplayMetrics(); |
| 428 | mMetrics.setToDefaults(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 429 | } |
| 430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | public void setSeparateProcesses(String[] procs) { |
| 432 | mSeparateProcesses = procs; |
| 433 | } |
| 434 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 435 | /** |
| 436 | * Flag indicating this parser should only consider apps with |
| 437 | * {@code coreApp} manifest attribute to be valid apps. This is useful when |
| 438 | * creating a minimalist boot environment. |
| 439 | */ |
Dianne Hackborn | d2509fd | 2011-09-12 12:29:43 -0700 | [diff] [blame] | 440 | public void setOnlyCoreApps(boolean onlyCoreApps) { |
| 441 | mOnlyCoreApps = onlyCoreApps; |
| 442 | } |
| 443 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 444 | public void setDisplayMetrics(DisplayMetrics metrics) { |
| 445 | mMetrics = metrics; |
| 446 | } |
| 447 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 448 | public static final boolean isApkFile(File file) { |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 449 | return isApkPath(file.getName()); |
| 450 | } |
| 451 | |
| 452 | private static boolean isApkPath(String path) { |
| 453 | return path.endsWith(".apk"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 458 | * |
| 459 | * @param p the parsed package. |
| 460 | * @param flags indicating which optional information is included. |
| 461 | */ |
| 462 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 463 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 464 | Set<String> grantedPermissions, PackageUserState state) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 466 | return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 467 | grantedPermissions, state, UserHandle.getCallingUserId()); |
| 468 | } |
| 469 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 470 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 471 | * Returns true if the package is installed and not hidden, or if the caller |
| 472 | * explicitly wanted all uninstalled and hidden packages as well. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 473 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 474 | private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state) { |
| 475 | return (state.installed && !state.hidden) |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 476 | || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 479 | public static boolean isAvailable(PackageUserState state) { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 480 | return checkUseInstalledOrHidden(0, state); |
Christopher Tate | ba629da | 2013-11-13 17:42:28 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 483 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 484 | int gids[], int flags, long firstInstallTime, long lastUpdateTime, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 485 | Set<String> grantedPermissions, PackageUserState state, int userId) { |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 486 | if (!checkUseInstalledOrHidden(flags, state) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 487 | return null; |
| 488 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | PackageInfo pi = new PackageInfo(); |
| 490 | pi.packageName = p.packageName; |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 491 | pi.splitNames = p.splitNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | pi.versionCode = p.mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 493 | pi.baseRevisionCode = p.baseRevisionCode; |
| 494 | pi.splitRevisionCodes = p.splitRevisionCodes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | pi.versionName = p.mVersionName; |
| 496 | pi.sharedUserId = p.mSharedUserId; |
| 497 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 498 | pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 499 | pi.installLocation = p.installLocation; |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 500 | pi.coreApp = p.coreApp; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 501 | if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| 502 | || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 503 | pi.requiredForAllUsers = p.mRequiredForAllUsers; |
| 504 | } |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 505 | pi.restrictedAccountType = p.mRestrictedAccountType; |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 506 | pi.requiredAccountType = p.mRequiredAccountType; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 507 | pi.overlayTarget = p.mOverlayTarget; |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 508 | pi.firstInstallTime = firstInstallTime; |
| 509 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 511 | pi.gids = gids; |
| 512 | } |
| 513 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 514 | int N = p.configPreferences != null ? p.configPreferences.size() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | if (N > 0) { |
| 516 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 517 | p.configPreferences.toArray(pi.configPreferences); |
| 518 | } |
| 519 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 520 | if (N > 0) { |
| 521 | pi.reqFeatures = new FeatureInfo[N]; |
| 522 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | } |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 524 | N = p.featureGroups != null ? p.featureGroups.size() : 0; |
| 525 | if (N > 0) { |
| 526 | pi.featureGroups = new FeatureGroupInfo[N]; |
| 527 | p.featureGroups.toArray(pi.featureGroups); |
| 528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 530 | if ((flags & PackageManager.GET_ACTIVITIES) != 0) { |
| 531 | final int N = p.activities.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 533 | int num = 0; |
| 534 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 535 | for (int i = 0; i < N; i++) { |
| 536 | final Activity a = p.activities.get(i); |
| 537 | if (state.isMatch(a.info, flags)) { |
| 538 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 541 | pi.activities = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | } |
| 543 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 544 | if ((flags & PackageManager.GET_RECEIVERS) != 0) { |
| 545 | final int N = p.receivers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 547 | int num = 0; |
| 548 | final ActivityInfo[] res = new ActivityInfo[N]; |
| 549 | for (int i = 0; i < N; i++) { |
| 550 | final Activity a = p.receivers.get(i); |
| 551 | if (state.isMatch(a.info, flags)) { |
| 552 | res[num++] = generateActivityInfo(a, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |
| 554 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 555 | pi.receivers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | } |
| 557 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 558 | if ((flags & PackageManager.GET_SERVICES) != 0) { |
| 559 | final int N = p.services.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 561 | int num = 0; |
| 562 | final ServiceInfo[] res = new ServiceInfo[N]; |
| 563 | for (int i = 0; i < N; i++) { |
| 564 | final Service s = p.services.get(i); |
| 565 | if (state.isMatch(s.info, flags)) { |
| 566 | res[num++] = generateServiceInfo(s, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | } |
| 568 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 569 | pi.services = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | } |
| 571 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 572 | if ((flags & PackageManager.GET_PROVIDERS) != 0) { |
| 573 | final int N = p.providers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | if (N > 0) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 575 | int num = 0; |
| 576 | final ProviderInfo[] res = new ProviderInfo[N]; |
| 577 | for (int i = 0; i < N; i++) { |
| 578 | final Provider pr = p.providers.get(i); |
| 579 | if (state.isMatch(pr.info, flags)) { |
| 580 | res[num++] = generateProviderInfo(pr, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } |
| 582 | } |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 583 | pi.providers = ArrayUtils.trimToSize(res, num); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 587 | int N = p.instrumentation.size(); |
| 588 | if (N > 0) { |
| 589 | pi.instrumentation = new InstrumentationInfo[N]; |
| 590 | for (int i=0; i<N; i++) { |
| 591 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 592 | p.instrumentation.get(i), flags); |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 597 | int N = p.permissions.size(); |
| 598 | if (N > 0) { |
| 599 | pi.permissions = new PermissionInfo[N]; |
| 600 | for (int i=0; i<N; i++) { |
| 601 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 602 | } |
| 603 | } |
| 604 | N = p.requestedPermissions.size(); |
| 605 | if (N > 0) { |
| 606 | pi.requestedPermissions = new String[N]; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 607 | pi.requestedPermissionsFlags = new int[N]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 609 | final String perm = p.requestedPermissions.get(i); |
| 610 | pi.requestedPermissions[i] = perm; |
Svet Ganov | 3695b8a | 2015-03-24 16:30:25 -0700 | [diff] [blame] | 611 | // The notion of required permissions is deprecated but for compatibility. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 612 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 613 | if (grantedPermissions != null && grantedPermissions.contains(perm)) { |
| 614 | pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; |
| 615 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | } |
| 619 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 620 | int N = (p.mSignatures != null) ? p.mSignatures.length : 0; |
| 621 | if (N > 0) { |
| 622 | pi.signatures = new Signature[N]; |
| 623 | System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | return pi; |
| 627 | } |
| 628 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 629 | private static Certificate[][] loadCertificates(StrictJarFile jarFile, ZipEntry entry) |
| 630 | throws PackageParserException { |
| 631 | InputStream is = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | try { |
| 633 | // We must read the stream for the JarEntry to retrieve |
| 634 | // its certificates. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 635 | is = jarFile.getInputStream(entry); |
| 636 | readFullyIgnoringContents(is); |
| 637 | return jarFile.getCertificateChains(entry); |
| 638 | } catch (IOException | RuntimeException e) { |
| 639 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 640 | "Failed reading " + entry.getName() + " in " + jarFile, e); |
| 641 | } finally { |
| 642 | IoUtils.closeQuietly(is); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 646 | public final static int PARSE_IS_SYSTEM = 1<<0; |
| 647 | public final static int PARSE_CHATTY = 1<<1; |
| 648 | public final static int PARSE_MUST_BE_APK = 1<<2; |
| 649 | public final static int PARSE_IGNORE_PROCESSES = 1<<3; |
| 650 | public final static int PARSE_FORWARD_LOCK = 1<<4; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 651 | public final static int PARSE_EXTERNAL_STORAGE = 1<<5; |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 652 | public final static int PARSE_IS_SYSTEM_DIR = 1<<6; |
Christopher Tate | ccbf84f | 2013-05-08 15:25:41 -0700 | [diff] [blame] | 653 | public final static int PARSE_IS_PRIVILEGED = 1<<7; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 654 | public final static int PARSE_COLLECT_CERTIFICATES = 1<<8; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 655 | public final static int PARSE_TRUSTED_OVERLAY = 1<<9; |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 656 | public final static int PARSE_ENFORCE_CODE = 1<<10; |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 657 | public final static int PARSE_IS_EPHEMERAL = 1<<11; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 658 | |
| 659 | private static final Comparator<String> sSplitNameComparator = new SplitNameComparator(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 661 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 662 | * Used to sort a set of APKs based on their split names, always placing the |
| 663 | * base APK (with {@code null} split name) first. |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 664 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 665 | private static class SplitNameComparator implements Comparator<String> { |
| 666 | @Override |
| 667 | public int compare(String lhs, String rhs) { |
| 668 | if (lhs == null) { |
| 669 | return -1; |
| 670 | } else if (rhs == null) { |
| 671 | return 1; |
| 672 | } else { |
| 673 | return lhs.compareTo(rhs); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 678 | /** |
| 679 | * Parse only lightweight details about the package at the given location. |
| 680 | * Automatically detects if the package is a monolithic style (single APK |
| 681 | * file) or cluster style (directory of APKs). |
| 682 | * <p> |
| 683 | * This performs sanity checking on cluster style packages, such as |
| 684 | * requiring identical package name and version codes, a single base APK, |
| 685 | * and unique split names. |
| 686 | * |
| 687 | * @see PackageParser#parsePackage(File, int) |
| 688 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 689 | public static PackageLite parsePackageLite(File packageFile, int flags) |
| 690 | throws PackageParserException { |
| 691 | if (packageFile.isDirectory()) { |
| 692 | return parseClusterPackageLite(packageFile, flags); |
| 693 | } else { |
| 694 | return parseMonolithicPackageLite(packageFile, flags); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | private static PackageLite parseMonolithicPackageLite(File packageFile, int flags) |
| 699 | throws PackageParserException { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 700 | final ApkLite baseApk = parseApkLite(packageFile, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 701 | final String packagePath = packageFile.getAbsolutePath(); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 702 | return new PackageLite(packagePath, baseApk, null, null, null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | private static PackageLite parseClusterPackageLite(File packageDir, int flags) |
| 706 | throws PackageParserException { |
| 707 | final File[] files = packageDir.listFiles(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 708 | if (ArrayUtils.isEmpty(files)) { |
| 709 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 710 | "No packages found in split"); |
| 711 | } |
| 712 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 713 | String packageName = null; |
| 714 | int versionCode = 0; |
| 715 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 716 | final ArrayMap<String, ApkLite> apks = new ArrayMap<>(); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 717 | for (File file : files) { |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 718 | if (isApkFile(file)) { |
| 719 | final ApkLite lite = parseApkLite(file, flags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 720 | |
| 721 | // Assert that all package names and version codes are |
| 722 | // consistent with the first one we encounter. |
| 723 | if (packageName == null) { |
| 724 | packageName = lite.packageName; |
| 725 | versionCode = lite.versionCode; |
| 726 | } else { |
| 727 | if (!packageName.equals(lite.packageName)) { |
| 728 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 729 | "Inconsistent package " + lite.packageName + " in " + file |
| 730 | + "; expected " + packageName); |
| 731 | } |
| 732 | if (versionCode != lite.versionCode) { |
| 733 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 734 | "Inconsistent version " + lite.versionCode + " in " + file |
| 735 | + "; expected " + versionCode); |
| 736 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 739 | // Assert that each split is defined only once |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 740 | if (apks.put(lite.splitName, lite) != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 741 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 742 | "Split name " + lite.splitName |
| 743 | + " defined more than once; most recent was " + file); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 748 | final ApkLite baseApk = apks.remove(null); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 749 | if (baseApk == null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 750 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 751 | "Missing base APK in " + packageDir); |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 754 | // Always apply deterministic ordering based on splitName |
| 755 | final int size = apks.size(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 756 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 757 | String[] splitNames = null; |
| 758 | String[] splitCodePaths = null; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 759 | int[] splitRevisionCodes = null; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 760 | if (size > 0) { |
| 761 | splitNames = new String[size]; |
| 762 | splitCodePaths = new String[size]; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 763 | splitRevisionCodes = new int[size]; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 764 | |
| 765 | splitNames = apks.keySet().toArray(splitNames); |
| 766 | Arrays.sort(splitNames, sSplitNameComparator); |
| 767 | |
| 768 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 769 | splitCodePaths[i] = apks.get(splitNames[i]).codePath; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 770 | splitRevisionCodes[i] = apks.get(splitNames[i]).revisionCode; |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 771 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 774 | final String codePath = packageDir.getAbsolutePath(); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 775 | return new PackageLite(codePath, baseApk, splitNames, splitCodePaths, |
| 776 | splitRevisionCodes); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 779 | /** |
| 780 | * Parse the package at the given location. Automatically detects if the |
| 781 | * package is a monolithic style (single APK file) or cluster style |
| 782 | * (directory of APKs). |
| 783 | * <p> |
| 784 | * This performs sanity checking on cluster style packages, such as |
| 785 | * requiring identical package name and version codes, a single base APK, |
| 786 | * and unique split names. |
| 787 | * <p> |
| 788 | * Note that this <em>does not</em> perform signature verification; that |
| 789 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 790 | * |
| 791 | * @see #parsePackageLite(File, int) |
| 792 | */ |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 793 | public Package parsePackage(File packageFile, int flags) throws PackageParserException { |
| 794 | if (packageFile.isDirectory()) { |
| 795 | return parseClusterPackage(packageFile, flags); |
| 796 | } else { |
| 797 | return parseMonolithicPackage(packageFile, flags); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * Parse all APKs contained in the given directory, treating them as a |
| 803 | * single package. This also performs sanity checking, such as requiring |
| 804 | * identical package name and version codes, a single base APK, and unique |
| 805 | * split names. |
| 806 | * <p> |
| 807 | * Note that this <em>does not</em> perform signature verification; that |
| 808 | * must be done separately in {@link #collectCertificates(Package, int)}. |
| 809 | */ |
| 810 | private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException { |
| 811 | final PackageLite lite = parseClusterPackageLite(packageDir, 0); |
| 812 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 813 | if (mOnlyCoreApps && !lite.coreApp) { |
| 814 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 815 | "Not a coreApp: " + packageDir); |
| 816 | } |
| 817 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 818 | final AssetManager assets = new AssetManager(); |
| 819 | try { |
| 820 | // Load the base and all splits into the AssetManager |
| 821 | // so that resources can be overriden when parsing the manifests. |
| 822 | loadApkIntoAssetManager(assets, lite.baseCodePath, flags); |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 823 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 824 | if (!ArrayUtils.isEmpty(lite.splitCodePaths)) { |
| 825 | for (String path : lite.splitCodePaths) { |
| 826 | loadApkIntoAssetManager(assets, path, flags); |
| 827 | } |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 828 | } |
Jeff Sharkey | 73767b9 | 2014-07-04 20:18:13 -0700 | [diff] [blame] | 829 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 830 | final File baseApk = new File(lite.baseCodePath); |
| 831 | final Package pkg = parseBaseApk(baseApk, assets, flags); |
| 832 | if (pkg == null) { |
| 833 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 834 | "Failed to parse base APK: " + baseApk); |
| 835 | } |
| 836 | |
| 837 | if (!ArrayUtils.isEmpty(lite.splitNames)) { |
| 838 | final int num = lite.splitNames.length; |
| 839 | pkg.splitNames = lite.splitNames; |
| 840 | pkg.splitCodePaths = lite.splitCodePaths; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 841 | pkg.splitRevisionCodes = lite.splitRevisionCodes; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 842 | pkg.splitFlags = new int[num]; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 843 | pkg.splitPrivateFlags = new int[num]; |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 844 | |
| 845 | for (int i = 0; i < num; i++) { |
| 846 | parseSplitApk(pkg, i, assets, flags); |
| 847 | } |
| 848 | } |
| 849 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 850 | pkg.setCodePath(packageDir.getAbsolutePath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 851 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 852 | return pkg; |
| 853 | } finally { |
| 854 | IoUtils.closeQuietly(assets); |
| 855 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 858 | /** |
| 859 | * Parse the given APK file, treating it as as a single monolithic package. |
| 860 | * <p> |
| 861 | * Note that this <em>does not</em> perform signature verification; that |
| 862 | * must be done separately in {@link #collectCertificates(Package, int)}. |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 863 | * |
| 864 | * @deprecated external callers should move to |
| 865 | * {@link #parsePackage(File, int)}. Eventually this method will |
| 866 | * be marked private. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 867 | */ |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 868 | @Deprecated |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 869 | public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException { |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 870 | final PackageLite lite = parseMonolithicPackageLite(apkFile, flags); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 871 | if (mOnlyCoreApps) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 872 | if (!lite.coreApp) { |
| 873 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 874 | "Not a coreApp: " + apkFile); |
| 875 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 876 | } |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 877 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 878 | final AssetManager assets = new AssetManager(); |
| 879 | try { |
| 880 | final Package pkg = parseBaseApk(apkFile, assets, flags); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 881 | pkg.setCodePath(apkFile.getAbsolutePath()); |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 882 | pkg.setUse32bitAbi(lite.use32bitAbi); |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 883 | return pkg; |
| 884 | } finally { |
| 885 | IoUtils.closeQuietly(assets); |
| 886 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 889 | private static int loadApkIntoAssetManager(AssetManager assets, String apkPath, int flags) |
| 890 | throws PackageParserException { |
| 891 | if ((flags & PARSE_MUST_BE_APK) != 0 && !isApkPath(apkPath)) { |
| 892 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 893 | "Invalid package file: " + apkPath); |
| 894 | } |
| 895 | |
| 896 | // The AssetManager guarantees uniqueness for asset paths, so if this asset path |
| 897 | // already exists in the AssetManager, addAssetPath will only return the cookie |
| 898 | // assigned to it. |
| 899 | int cookie = assets.addAssetPath(apkPath); |
| 900 | if (cookie == 0) { |
| 901 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 902 | "Failed adding asset path: " + apkPath); |
| 903 | } |
| 904 | return cookie; |
| 905 | } |
| 906 | |
| 907 | private Package parseBaseApk(File apkFile, AssetManager assets, int flags) |
| 908 | throws PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 909 | final String apkPath = apkFile.getAbsolutePath(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 910 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 911 | String volumeUuid = null; |
| 912 | if (apkPath.startsWith(MNT_EXPAND)) { |
| 913 | final int end = apkPath.indexOf('/', MNT_EXPAND.length()); |
| 914 | volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); |
| 915 | } |
| 916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 918 | mArchiveSourcePath = apkFile.getAbsolutePath(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 919 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 920 | 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] | 921 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 922 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 923 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 924 | Resources res = null; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 925 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 927 | res = new Resources(assets, mMetrics, null); |
| 928 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 929 | Build.VERSION.RESOURCES_SDK_INT); |
| 930 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
| 931 | |
| 932 | final String[] outError = new String[1]; |
| 933 | final Package pkg = parseBaseApk(res, parser, flags, outError); |
| 934 | if (pkg == null) { |
| 935 | throw new PackageParserException(mParseError, |
| 936 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | } |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 938 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 939 | pkg.setVolumeUuid(volumeUuid); |
| 940 | pkg.setApplicationVolumeUuid(volumeUuid); |
| 941 | pkg.setBaseCodePath(apkPath); |
| 942 | pkg.setSignatures(null); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 943 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 944 | return pkg; |
| 945 | |
| 946 | } catch (PackageParserException e) { |
| 947 | throw e; |
| 948 | } catch (Exception e) { |
| 949 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 950 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 951 | } finally { |
| 952 | IoUtils.closeQuietly(parser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 956 | private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 957 | throws PackageParserException { |
| 958 | final String apkPath = pkg.splitCodePaths[splitIndex]; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 959 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 960 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 961 | mArchiveSourcePath = apkPath; |
| 962 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 963 | if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); |
| 964 | |
Adam Lesinski | 3bcbd90 | 2014-08-22 17:01:04 -0700 | [diff] [blame] | 965 | final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); |
| 966 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 967 | Resources res = null; |
| 968 | XmlResourceParser parser = null; |
| 969 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 970 | res = new Resources(assets, mMetrics, null); |
| 971 | assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 972 | Build.VERSION.RESOURCES_SDK_INT); |
| 973 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
| 974 | |
| 975 | final String[] outError = new String[1]; |
| 976 | pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); |
| 977 | if (pkg == null) { |
| 978 | throw new PackageParserException(mParseError, |
| 979 | apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); |
| 980 | } |
| 981 | |
| 982 | } catch (PackageParserException e) { |
| 983 | throw e; |
| 984 | } catch (Exception e) { |
| 985 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 986 | "Failed to read manifest from " + apkPath, e); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 987 | } finally { |
| 988 | IoUtils.closeQuietly(parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Parse the manifest of a <em>split APK</em>. |
| 994 | * <p> |
| 995 | * Note that split APKs have many more restrictions on what they're capable |
| 996 | * of doing, so many valid features of a base APK have been carefully |
| 997 | * omitted here. |
| 998 | */ |
| 999 | private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1000 | int splitIndex, String[] outError) throws XmlPullParserException, IOException, |
| 1001 | PackageParserException { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1002 | AttributeSet attrs = parser; |
| 1003 | |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1004 | // We parsed manifest tag earlier; just skip past it |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1005 | parsePackageSplitNames(parser, attrs); |
Jeff Sharkey | 78a1301 | 2014-07-15 20:18:34 -0700 | [diff] [blame] | 1006 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1007 | mParseInstrumentationArgs = null; |
| 1008 | mParseActivityArgs = null; |
| 1009 | mParseServiceArgs = null; |
| 1010 | mParseProviderArgs = null; |
| 1011 | |
| 1012 | int type; |
| 1013 | |
| 1014 | boolean foundApp = false; |
| 1015 | |
| 1016 | int outerDepth = parser.getDepth(); |
| 1017 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1018 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1019 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1020 | continue; |
| 1021 | } |
| 1022 | |
| 1023 | String tagName = parser.getName(); |
| 1024 | if (tagName.equals("application")) { |
| 1025 | if (foundApp) { |
| 1026 | if (RIGID_PARSER) { |
| 1027 | outError[0] = "<manifest> has more than one <application>"; |
| 1028 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1029 | return null; |
| 1030 | } else { |
| 1031 | Slog.w(TAG, "<manifest> has more than one <application>"); |
| 1032 | XmlUtils.skipCurrentTag(parser); |
| 1033 | continue; |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1038 | if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1039 | return null; |
| 1040 | } |
| 1041 | |
| 1042 | } else if (RIGID_PARSER) { |
| 1043 | outError[0] = "Bad element under <manifest>: " |
| 1044 | + parser.getName(); |
| 1045 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1046 | return null; |
| 1047 | |
| 1048 | } else { |
| 1049 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1050 | + " at " + mArchiveSourcePath + " " |
| 1051 | + parser.getPositionDescription()); |
| 1052 | XmlUtils.skipCurrentTag(parser); |
| 1053 | continue; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | if (!foundApp) { |
| 1058 | outError[0] = "<manifest> does not contain an <application>"; |
| 1059 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1060 | } |
| 1061 | |
| 1062 | return pkg; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1065 | public static int getApkSigningVersion(Package pkg) { |
| 1066 | try { |
| 1067 | if (ApkSignatureSchemeV2Verifier.hasSignature(pkg.baseCodePath)) { |
| 1068 | return APK_SIGNING_V2; |
| 1069 | } |
| 1070 | return APK_SIGNING_V1; |
| 1071 | } catch (IOException e) { |
| 1072 | } |
| 1073 | return APK_SIGNING_UNKNOWN; |
| 1074 | } |
| 1075 | |
Kenny Root | 6c918ce | 2013-04-02 14:04:24 -0700 | [diff] [blame] | 1076 | /** |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1077 | * Collect certificates from all the APKs described in the given package, |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 1078 | * populating {@link Package#mSignatures}. Also asserts that all APK |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1079 | * contents are signed correctly and consistently. |
| 1080 | */ |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1081 | public static void collectCertificates(Package pkg, int parseFlags) |
| 1082 | throws PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1083 | collectCertificatesInternal(pkg, parseFlags); |
| 1084 | final int childCount = (pkg.childPackages != null) ? pkg.childPackages.size() : 0; |
| 1085 | for (int i = 0; i < childCount; i++) { |
| 1086 | Package childPkg = pkg.childPackages.get(i); |
| 1087 | childPkg.mCertificates = pkg.mCertificates; |
| 1088 | childPkg.mSignatures = pkg.mSignatures; |
| 1089 | childPkg.mSigningKeys = pkg.mSigningKeys; |
| 1090 | } |
| 1091 | } |
| 1092 | |
Todd Kennedy | 66c5553 | 2016-02-26 16:22:11 -0800 | [diff] [blame] | 1093 | private static void collectCertificatesInternal(Package pkg, int parseFlags) |
| 1094 | throws PackageParserException { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1095 | pkg.mCertificates = null; |
| 1096 | pkg.mSignatures = null; |
| 1097 | pkg.mSigningKeys = null; |
| 1098 | |
Todd Kennedy | 3398be8 | 2015-12-02 13:40:49 -0800 | [diff] [blame] | 1099 | collectCertificates(pkg, new File(pkg.baseCodePath), pkg.applicationInfo.flags, parseFlags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1100 | |
| 1101 | if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) { |
Todd Kennedy | 3398be8 | 2015-12-02 13:40:49 -0800 | [diff] [blame] | 1102 | for (int i = 0; i < pkg.splitCodePaths.length; i++) { |
| 1103 | collectCertificates(pkg, new File(pkg.splitCodePaths[i]), pkg.splitFlags[i], |
| 1104 | parseFlags); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1105 | } |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
Todd Kennedy | 3398be8 | 2015-12-02 13:40:49 -0800 | [diff] [blame] | 1109 | private static void collectCertificates(Package pkg, File apkFile, int apkFlags, int parseFlags) |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1110 | throws PackageParserException { |
Todd Kennedy | 3398be8 | 2015-12-02 13:40:49 -0800 | [diff] [blame] | 1111 | final boolean hasCode = (apkFlags & ApplicationInfo.FLAG_HAS_CODE) != 0; |
| 1112 | final boolean requireCode = ((parseFlags & PARSE_ENFORCE_CODE) != 0) && hasCode; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1113 | final String apkPath = apkFile.getAbsolutePath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1115 | // Try to verify the APK using APK Signature Scheme v2. |
| 1116 | boolean verified = false; |
| 1117 | { |
| 1118 | Certificate[][] allSignersCerts = null; |
| 1119 | Signature[] signatures = null; |
| 1120 | try { |
| 1121 | allSignersCerts = ApkSignatureSchemeV2Verifier.verify(apkPath); |
| 1122 | signatures = convertToSignatures(allSignersCerts); |
| 1123 | // APK verified using APK Signature Scheme v2. |
| 1124 | verified = true; |
| 1125 | } catch (ApkSignatureSchemeV2Verifier.SignatureNotFoundException e) { |
| 1126 | // No APK Signature Scheme v2 signature found |
| 1127 | } catch (Exception e) { |
| 1128 | // APK Signature Scheme v2 signature was found but did not verify |
| 1129 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1130 | "Failed to collect certificates from " + apkPath |
| 1131 | + " using APK Signature Scheme v2", |
| 1132 | e); |
| 1133 | } |
| 1134 | |
| 1135 | if (verified) { |
| 1136 | if (pkg.mCertificates == null) { |
| 1137 | pkg.mCertificates = allSignersCerts; |
| 1138 | pkg.mSignatures = signatures; |
| 1139 | pkg.mSigningKeys = new ArraySet<>(allSignersCerts.length); |
| 1140 | for (int i = 0; i < allSignersCerts.length; i++) { |
| 1141 | Certificate[] signerCerts = allSignersCerts[i]; |
| 1142 | Certificate signerCert = signerCerts[0]; |
| 1143 | pkg.mSigningKeys.add(signerCert.getPublicKey()); |
| 1144 | } |
| 1145 | } else { |
| 1146 | if (!Signature.areExactMatch(pkg.mSignatures, signatures)) { |
| 1147 | throw new PackageParserException( |
| 1148 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, |
| 1149 | apkPath + " has mismatched certificates"); |
| 1150 | } |
| 1151 | } |
| 1152 | // Not yet done, because we need to confirm that AndroidManifest.xml exists and, |
| 1153 | // if requested, that classes.dex exists. |
| 1154 | } |
| 1155 | } |
| 1156 | |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 1157 | boolean codeFound = false; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1158 | StrictJarFile jarFile = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | try { |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1160 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "strictJarFileCtor"); |
Alex Klyubin | 9b59bc4 | 2016-03-24 12:02:20 -0700 | [diff] [blame] | 1161 | // Ignore signature stripping protections when verifying APKs from system partition. |
| 1162 | // For those APKs we only care about extracting signer certificates, and don't care |
| 1163 | // about verifying integrity. |
| 1164 | boolean signatureSchemeRollbackProtectionsEnforced = |
| 1165 | (parseFlags & PARSE_IS_SYSTEM) == 0; |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1166 | jarFile = new StrictJarFile( |
| 1167 | apkPath, |
Alex Klyubin | 9b59bc4 | 2016-03-24 12:02:20 -0700 | [diff] [blame] | 1168 | !verified, // whether to verify JAR signature |
| 1169 | signatureSchemeRollbackProtectionsEnforced); |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1170 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1172 | // Always verify manifest, regardless of source |
| 1173 | final ZipEntry manifestEntry = jarFile.findEntry(ANDROID_MANIFEST_FILENAME); |
| 1174 | if (manifestEntry == null) { |
| 1175 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, |
| 1176 | "Package " + apkPath + " has no manifest"); |
| 1177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | |
Alex Klyubin | e415718 | 2016-01-05 13:27:05 -0800 | [diff] [blame] | 1179 | // Optimization: early termination when APK already verified |
| 1180 | if (verified) { |
| 1181 | if ((requireCode) && (jarFile.findEntry(BYTECODE_FILENAME) == null)) { |
| 1182 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1183 | "Package " + apkPath + " code is missing"); |
| 1184 | } |
| 1185 | return; |
| 1186 | } |
| 1187 | |
| 1188 | // APK's integrity needs to be verified using JAR signature scheme. |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1189 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "buildVerifyList"); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1190 | final List<ZipEntry> toVerify = new ArrayList<>(); |
| 1191 | toVerify.add(manifestEntry); |
| 1192 | |
| 1193 | // If we're parsing an untrusted package, verify all contents |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 1194 | if ((parseFlags & PARSE_IS_SYSTEM) == 0) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1195 | final Iterator<ZipEntry> i = jarFile.iterator(); |
| 1196 | while (i.hasNext()) { |
| 1197 | final ZipEntry entry = i.next(); |
| 1198 | |
| 1199 | if (entry.isDirectory()) continue; |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 1200 | |
| 1201 | final String entryName = entry.getName(); |
| 1202 | if (entryName.startsWith("META-INF/")) continue; |
| 1203 | if (entryName.equals(ANDROID_MANIFEST_FILENAME)) continue; |
| 1204 | if (entryName.equals(BYTECODE_FILENAME)) { |
| 1205 | codeFound = true; |
| 1206 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1207 | |
| 1208 | toVerify.add(entry); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1210 | } |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1211 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1212 | |
Christopher Tate | f3d939c | 2015-09-17 12:25:51 -0700 | [diff] [blame] | 1213 | if (!codeFound && requireCode) { |
| 1214 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1215 | "Package " + apkPath + " code is missing"); |
| 1216 | } |
| 1217 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1218 | // Verify that entries are signed consistently with the first entry |
| 1219 | // we encountered. Note that for splits, certificates may have |
| 1220 | // already been populated during an earlier parse of a base APK. |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1221 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "verifyEntries"); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1222 | for (ZipEntry entry : toVerify) { |
| 1223 | final Certificate[][] entryCerts = loadCertificates(jarFile, entry); |
| 1224 | if (ArrayUtils.isEmpty(entryCerts)) { |
| 1225 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1226 | "Package " + apkPath + " has no certificates at entry " |
| 1227 | + entry.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | } |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1229 | final Signature[] entrySignatures = convertToSignatures(entryCerts); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1230 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1231 | if (pkg.mCertificates == null) { |
| 1232 | pkg.mCertificates = entryCerts; |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1233 | pkg.mSignatures = entrySignatures; |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 1234 | pkg.mSigningKeys = new ArraySet<PublicKey>(); |
| 1235 | for (int i=0; i < entryCerts.length; i++) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1236 | pkg.mSigningKeys.add(entryCerts[i][0].getPublicKey()); |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame] | 1237 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1238 | } else { |
Jeff Sharkey | ec55ef0 | 2014-07-08 11:28:00 -0700 | [diff] [blame] | 1239 | if (!Signature.areExactMatch(pkg.mSignatures, entrySignatures)) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1240 | throw new PackageParserException( |
| 1241 | INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES, "Package " + apkPath |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | + " has mismatched certificates at entry " |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1243 | + entry.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | } |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 1247 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
Jeff Sharkey | bc09755 | 2014-09-09 14:57:26 -0700 | [diff] [blame] | 1248 | } catch (GeneralSecurityException e) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1249 | throw new PackageParserException(INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING, |
| 1250 | "Failed to collect certificates from " + apkPath, e); |
Jeff Sharkey | bc09755 | 2014-09-09 14:57:26 -0700 | [diff] [blame] | 1251 | } catch (IOException | RuntimeException e) { |
| 1252 | throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, |
| 1253 | "Failed to collect certificates from " + apkPath, e); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1254 | } finally { |
| 1255 | closeQuietly(jarFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1259 | private static Signature[] convertToSignatures(Certificate[][] certs) |
| 1260 | throws CertificateEncodingException { |
| 1261 | final Signature[] res = new Signature[certs.length]; |
| 1262 | for (int i = 0; i < certs.length; i++) { |
| 1263 | res[i] = new Signature(certs[i]); |
| 1264 | } |
| 1265 | return res; |
| 1266 | } |
| 1267 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1268 | /** |
| 1269 | * Utility method that retrieves lightweight details about a single APK |
| 1270 | * file, including package name, split name, and install location. |
| 1271 | * |
| 1272 | * @param apkFile path to a single APK |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1273 | * @param flags optional parse flags, such as |
| 1274 | * {@link #PARSE_COLLECT_CERTIFICATES} |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1275 | */ |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1276 | public static ApkLite parseApkLite(File apkFile, int flags) |
| 1277 | throws PackageParserException { |
| 1278 | final String apkPath = apkFile.getAbsolutePath(); |
| 1279 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1280 | AssetManager assets = null; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1281 | XmlResourceParser parser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | try { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1283 | assets = new AssetManager(); |
| 1284 | 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] | 1285 | Build.VERSION.RESOURCES_SDK_INT); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1286 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1287 | int cookie = assets.addAssetPath(apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1288 | if (cookie == 0) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1289 | throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, |
| 1290 | "Failed to parse " + apkPath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1293 | final DisplayMetrics metrics = new DisplayMetrics(); |
| 1294 | metrics.setToDefaults(); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1295 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1296 | final Resources res = new Resources(assets, metrics, null); |
| 1297 | parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1298 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1299 | final Signature[] signatures; |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1300 | if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { |
| 1301 | // TODO: factor signature related items out of Package object |
| 1302 | final Package tempPkg = new Package(null); |
Todd Kennedy | 373f0b4 | 2015-12-16 14:45:14 -0800 | [diff] [blame] | 1303 | collectCertificates(tempPkg, apkFile, 0 /*apkFlags*/, 0 /*flags*/); |
Jeff Sharkey | bb7b7be | 2014-08-19 16:18:28 -0700 | [diff] [blame] | 1304 | signatures = tempPkg.mSignatures; |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1305 | } else { |
| 1306 | signatures = null; |
| 1307 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1308 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1309 | final AttributeSet attrs = parser; |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 1310 | return parseApkLite(apkPath, res, parser, attrs, flags, signatures); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1311 | |
| 1312 | } catch (XmlPullParserException | IOException | RuntimeException e) { |
| 1313 | throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, |
| 1314 | "Failed to parse " + apkPath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | } finally { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1316 | IoUtils.closeQuietly(parser); |
| 1317 | IoUtils.closeQuietly(assets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1321 | private static String validateName(String name, boolean requireSeparator, |
| 1322 | boolean requireFilename) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | final int N = name.length(); |
| 1324 | boolean hasSep = false; |
| 1325 | boolean front = true; |
| 1326 | for (int i=0; i<N; i++) { |
| 1327 | final char c = name.charAt(i); |
| 1328 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 1329 | front = false; |
| 1330 | continue; |
| 1331 | } |
| 1332 | if (!front) { |
| 1333 | if ((c >= '0' && c <= '9') || c == '_') { |
| 1334 | continue; |
| 1335 | } |
| 1336 | } |
| 1337 | if (c == '.') { |
| 1338 | hasSep = true; |
| 1339 | front = true; |
| 1340 | continue; |
| 1341 | } |
| 1342 | return "bad character '" + c + "'"; |
| 1343 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1344 | if (requireFilename && !FileUtils.isValidExtFilename(name)) { |
| 1345 | return "Invalid filename"; |
| 1346 | } |
| 1347 | return hasSep || !requireSeparator |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | ? null : "must have at least one '.' separator"; |
| 1349 | } |
| 1350 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1351 | private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1352 | AttributeSet attrs) throws IOException, XmlPullParserException, |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1353 | PackageParserException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | |
| 1355 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1356 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1357 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1360 | if (type != XmlPullParser.START_TAG) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1361 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1362 | "No start tag found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1363 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1364 | if (!parser.getName().equals(TAG_MANIFEST)) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1365 | throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, |
| 1366 | "No <manifest> tag"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | } |
| 1368 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1369 | final String packageName = attrs.getAttributeValue(null, "package"); |
| 1370 | if (!"android".equals(packageName)) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1371 | final String error = validateName(packageName, true, true); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1372 | if (error != null) { |
| 1373 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1374 | "Invalid manifest package: " + error); |
| 1375 | } |
| 1376 | } |
| 1377 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1378 | String splitName = attrs.getAttributeValue(null, "split"); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1379 | if (splitName != null) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1380 | if (splitName.length() == 0) { |
| 1381 | splitName = null; |
| 1382 | } else { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1383 | final String error = validateName(splitName, false, false); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1384 | if (error != null) { |
| 1385 | throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, |
| 1386 | "Invalid manifest split: " + error); |
| 1387 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | return Pair.create(packageName.intern(), |
| 1392 | (splitName != null) ? splitName.intern() : splitName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 1395 | private static ApkLite parseApkLite(String codePath, Resources res, XmlPullParser parser, |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1396 | AttributeSet attrs, int flags, Signature[] signatures) throws IOException, |
| 1397 | XmlPullParserException, PackageParserException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1398 | final Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1399 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1400 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1401 | int versionCode = 0; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1402 | int revisionCode = 0; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1403 | boolean coreApp = false; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 1404 | boolean multiArch = false; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1405 | boolean use32bitAbi = false; |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1406 | boolean extractNativeLibs = true; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1407 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1408 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1409 | final String attr = attrs.getAttributeName(i); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1410 | if (attr.equals("installLocation")) { |
| 1411 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1412 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1413 | } else if (attr.equals("versionCode")) { |
| 1414 | versionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1415 | } else if (attr.equals("revisionCode")) { |
| 1416 | revisionCode = attrs.getAttributeIntValue(i, 0); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1417 | } else if (attr.equals("coreApp")) { |
| 1418 | coreApp = attrs.getAttributeBooleanValue(i, false); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1419 | } |
| 1420 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1421 | |
| 1422 | // Only search the tree when the tag is directly below <manifest> |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1423 | int type; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1424 | final int searchDepth = parser.getDepth() + 1; |
| 1425 | |
| 1426 | final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>(); |
| 1427 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1428 | && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) { |
| 1429 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1430 | continue; |
| 1431 | } |
| 1432 | |
| 1433 | if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 1434 | final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1435 | if (verifier != null) { |
| 1436 | verifiers.add(verifier); |
| 1437 | } |
| 1438 | } |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1439 | |
| 1440 | if (parser.getDepth() == searchDepth && "application".equals(parser.getName())) { |
| 1441 | for (int i = 0; i < attrs.getAttributeCount(); ++i) { |
| 1442 | final String attr = attrs.getAttributeName(i); |
| 1443 | if ("multiArch".equals(attr)) { |
| 1444 | multiArch = attrs.getAttributeBooleanValue(i, false); |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1445 | } |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1446 | if ("use32bitAbi".equals(attr)) { |
| 1447 | use32bitAbi = attrs.getAttributeBooleanValue(i, false); |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 1448 | } |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1449 | if ("extractNativeLibs".equals(attr)) { |
| 1450 | extractNativeLibs = attrs.getAttributeBooleanValue(i, true); |
Narayan Kamath | a8755a8 | 2014-07-15 12:26:35 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | } |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Jeff Sharkey | be520fb | 2014-07-04 18:23:17 -0700 | [diff] [blame] | 1456 | return new ApkLite(codePath, packageSplit.first, packageSplit.second, versionCode, |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 1457 | revisionCode, installLocation, verifiers, signatures, coreApp, multiArch, |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 1458 | use32bitAbi, extractNativeLibs); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | /** |
| 1462 | * Temporary. |
| 1463 | */ |
| 1464 | static public Signature stringToSignature(String str) { |
| 1465 | final int N = str.length(); |
| 1466 | byte[] sig = new byte[N]; |
| 1467 | for (int i=0; i<N; i++) { |
| 1468 | sig[i] = (byte)str.charAt(i); |
| 1469 | } |
| 1470 | return new Signature(sig); |
| 1471 | } |
| 1472 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1473 | /** |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1474 | * Parses a child package and adds it to the parent if successful. If you add |
| 1475 | * new tags that need to be supported by child packages make sure to add them |
| 1476 | * to {@link #CHILD_PACKAGE_TAGS}. |
| 1477 | * |
| 1478 | * @param parentPkg The parent that contains the child |
| 1479 | * @param res Resources against which to resolve values |
| 1480 | * @param parser Parser of the manifest |
| 1481 | * @param flags Flags about how to parse |
| 1482 | * @param outError Human readable error if parsing fails |
| 1483 | * @return True of parsing succeeded. |
| 1484 | * |
| 1485 | * @throws XmlPullParserException |
| 1486 | * @throws IOException |
| 1487 | */ |
| 1488 | private boolean parseBaseApkChild(Package parentPkg, Resources res, XmlResourceParser parser, |
| 1489 | int flags, String[] outError) throws XmlPullParserException, IOException { |
| 1490 | // Let ppl not abuse this mechanism by limiting the packages per APK |
| 1491 | if (parentPkg.childPackages != null && parentPkg.childPackages.size() + 2 |
| 1492 | > MAX_PACKAGES_PER_APK) { |
| 1493 | outError[0] = "Maximum number of packages per APK is: " + MAX_PACKAGES_PER_APK; |
| 1494 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1495 | return false; |
| 1496 | } |
| 1497 | |
| 1498 | // Make sure we have a valid child package name |
| 1499 | String childPackageName = parser.getAttributeValue(null, "package"); |
| 1500 | if (validateName(childPackageName, true, false) != null) { |
| 1501 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | // Child packages must be unique |
| 1506 | if (childPackageName.equals(parentPkg.packageName)) { |
| 1507 | String message = "Child package name cannot be equal to parent package name: " |
| 1508 | + parentPkg.packageName; |
| 1509 | Slog.w(TAG, message); |
| 1510 | outError[0] = message; |
| 1511 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1512 | return false; |
| 1513 | } |
| 1514 | |
| 1515 | // Child packages must be unique |
| 1516 | if (parentPkg.hasChildPackage(childPackageName)) { |
| 1517 | String message = "Duplicate child package:" + childPackageName; |
| 1518 | Slog.w(TAG, message); |
| 1519 | outError[0] = message; |
| 1520 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1521 | return false; |
| 1522 | } |
| 1523 | |
| 1524 | // Go ahead and parse the child |
| 1525 | Package childPkg = new Package(childPackageName); |
| 1526 | |
| 1527 | // Child package inherits parent version code/name/target SDK |
| 1528 | childPkg.mVersionCode = parentPkg.mVersionCode; |
| 1529 | childPkg.baseRevisionCode = parentPkg.baseRevisionCode; |
| 1530 | childPkg.mVersionName = parentPkg.mVersionName; |
| 1531 | childPkg.applicationInfo.targetSdkVersion = parentPkg.applicationInfo.targetSdkVersion; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1532 | childPkg.applicationInfo.minSdkVersion = parentPkg.applicationInfo.minSdkVersion; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1533 | |
| 1534 | childPkg = parseBaseApkCommon(childPkg, CHILD_PACKAGE_TAGS, res, parser, flags, outError); |
| 1535 | if (childPkg == null) { |
| 1536 | // If we got null then error was set during child parsing |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | // Set the parent-child relation |
| 1541 | if (parentPkg.childPackages == null) { |
| 1542 | parentPkg.childPackages = new ArrayList<>(); |
| 1543 | } |
| 1544 | parentPkg.childPackages.add(childPkg); |
| 1545 | childPkg.parentPackage = parentPkg; |
| 1546 | |
| 1547 | return true; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * Parse the manifest of a <em>base APK</em>. When adding new features you |
| 1552 | * need to consider whether they should be supported by split APKs and child |
| 1553 | * packages. |
| 1554 | * |
| 1555 | * @param res The resources from which to resolve values |
| 1556 | * @param parser The manifest parser |
| 1557 | * @param flags Flags how to parse |
| 1558 | * @param outError Human readable error message |
| 1559 | * @return Parsed package or null on error. |
| 1560 | * |
| 1561 | * @throws XmlPullParserException |
| 1562 | * @throws IOException |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1563 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1564 | private Package parseBaseApk(Resources res, XmlResourceParser parser, int flags, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1565 | String[] outError) throws XmlPullParserException, IOException { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1566 | final String splitName; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1567 | final String pkgName; |
| 1568 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1569 | try { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1570 | Pair<String, String> packageSplit = parsePackageSplitNames(parser, parser); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1571 | pkgName = packageSplit.first; |
| 1572 | splitName = packageSplit.second; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1573 | |
| 1574 | if (!TextUtils.isEmpty(splitName)) { |
| 1575 | outError[0] = "Expected base APK, but found split " + splitName; |
| 1576 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1577 | return null; |
| 1578 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1579 | } catch (PackageParserException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 1581 | return null; |
| 1582 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1583 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 1584 | final Package pkg = new Package(pkgName); |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1585 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1586 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | com.android.internal.R.styleable.AndroidManifest); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1588 | |
Dianne Hackborn | 8472e61 | 2014-01-23 17:57:20 -0800 | [diff] [blame] | 1589 | pkg.mVersionCode = pkg.applicationInfo.versionCode = sa.getInteger( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 1591 | pkg.baseRevisionCode = sa.getInteger( |
| 1592 | com.android.internal.R.styleable.AndroidManifest_revisionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1593 | pkg.mVersionName = sa.getNonConfigurationString( |
| 1594 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (pkg.mVersionName != null) { |
| 1596 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 1597 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1598 | |
| 1599 | pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false); |
| 1600 | |
| 1601 | sa.recycle(); |
| 1602 | |
| 1603 | return parseBaseApkCommon(pkg, null, res, parser, flags, outError); |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * This is the common parsing routing for handling parent and child |
| 1608 | * packages in a base APK. The difference between parent and child |
| 1609 | * parsing is that some targs are not supported by child packages as |
| 1610 | * well as some manifest attributes are ignored. The implementation |
| 1611 | * assumes the calling code already handled the manifest tag if needed |
| 1612 | * (this applies to the parent only). |
| 1613 | * |
| 1614 | * @param pkg The package which to populate |
| 1615 | * @param acceptedTags Which tags to handle, null to handle all |
| 1616 | * @param res Resources against which to resolve values |
| 1617 | * @param parser Parser of the manifest |
| 1618 | * @param flags Flags about how to parse |
| 1619 | * @param outError Human readable error if parsing fails |
| 1620 | * @return The package if parsing succeeded or null. |
| 1621 | * |
| 1622 | * @throws XmlPullParserException |
| 1623 | * @throws IOException |
| 1624 | */ |
| 1625 | private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, |
| 1626 | XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, |
| 1627 | IOException { |
| 1628 | final boolean trustedOverlay = (flags & PARSE_TRUSTED_OVERLAY) != 0; |
| 1629 | mParseInstrumentationArgs = null; |
| 1630 | mParseActivityArgs = null; |
| 1631 | mParseServiceArgs = null; |
| 1632 | mParseProviderArgs = null; |
| 1633 | |
| 1634 | int type; |
| 1635 | boolean foundApp = false; |
| 1636 | |
| 1637 | TypedArray sa = res.obtainAttributes(parser, |
| 1638 | com.android.internal.R.styleable.AndroidManifest); |
| 1639 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1640 | String str = sa.getNonConfigurationString( |
| 1641 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 1642 | if (str != null && str.length() > 0) { |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 1643 | String nameError = validateName(str, true, false); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1644 | if (nameError != null && !"android".equals(pkg.packageName)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 1646 | + str + "\": " + nameError; |
| 1647 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 1648 | return null; |
| 1649 | } |
| 1650 | pkg.mSharedUserId = str.intern(); |
| 1651 | pkg.mSharedUserLabel = sa.getResourceId( |
| 1652 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 1653 | } |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 1654 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 1655 | pkg.installLocation = sa.getInteger( |
| 1656 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 1657 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1658 | pkg.applicationInfo.installLocation = pkg.installLocation; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1659 | |
Alan Viverette | fd274a0 | 2014-03-27 15:39:15 -0700 | [diff] [blame] | 1660 | |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1661 | /* Set the global "forward lock" flag */ |
| 1662 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1663 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /* Set the global "on SD card" flag */ |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1667 | if ((flags & PARSE_EXTERNAL_STORAGE) != 0) { |
Kenny Root | 7cb9be2 | 2012-05-30 15:30:37 -0700 | [diff] [blame] | 1668 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 1669 | } |
| 1670 | |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 1671 | if ((flags & PARSE_IS_EPHEMERAL) != 0) { |
| 1672 | pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_EPHEMERAL; |
| 1673 | } |
| 1674 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1675 | // Resource boolean are -1, so 1 means we don't know the value. |
| 1676 | int supportsSmallScreens = 1; |
| 1677 | int supportsNormalScreens = 1; |
| 1678 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1679 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1680 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1681 | int anyDensity = 1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1684 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1685 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1686 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | continue; |
| 1688 | } |
| 1689 | |
| 1690 | String tagName = parser.getName(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1691 | |
| 1692 | if (acceptedTags != null && !acceptedTags.contains(tagName)) { |
| 1693 | Slog.w(TAG, "Skipping unsupported element under <manifest>: " |
| 1694 | + tagName + " at " + mArchiveSourcePath + " " |
| 1695 | + parser.getPositionDescription()); |
| 1696 | XmlUtils.skipCurrentTag(parser); |
| 1697 | continue; |
| 1698 | } |
| 1699 | |
| 1700 | if (tagName.equals(TAG_APPLICATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | if (foundApp) { |
| 1702 | if (RIGID_PARSER) { |
| 1703 | outError[0] = "<manifest> has more than one <application>"; |
| 1704 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1705 | return null; |
| 1706 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1707 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | XmlUtils.skipCurrentTag(parser); |
| 1709 | continue; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | foundApp = true; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1714 | if (!parseBaseApplication(pkg, res, parser, flags, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | return null; |
| 1716 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1717 | } else if (tagName.equals(TAG_OVERLAY)) { |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1718 | pkg.mTrustedOverlay = trustedOverlay; |
| 1719 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1720 | sa = res.obtainAttributes(parser, |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1721 | com.android.internal.R.styleable.AndroidManifestResourceOverlay); |
| 1722 | pkg.mOverlayTarget = sa.getString( |
| 1723 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage); |
| 1724 | pkg.mOverlayPriority = sa.getInt( |
| 1725 | com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, |
| 1726 | -1); |
| 1727 | sa.recycle(); |
| 1728 | |
| 1729 | if (pkg.mOverlayTarget == null) { |
| 1730 | outError[0] = "<overlay> does not specify a target package"; |
| 1731 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1732 | return null; |
| 1733 | } |
| 1734 | if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) { |
| 1735 | outError[0] = "<overlay> priority must be between 0 and 9999"; |
| 1736 | mParseError = |
| 1737 | PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1738 | return null; |
| 1739 | } |
| 1740 | XmlUtils.skipCurrentTag(parser); |
| 1741 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1742 | } else if (tagName.equals(TAG_KEY_SETS)) { |
| 1743 | if (!parseKeySets(pkg, res, parser, outError)) { |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 1744 | return null; |
| 1745 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1746 | } else if (tagName.equals(TAG_PERMISSION_GROUP)) { |
| 1747 | if (parsePermissionGroup(pkg, flags, res, parser, outError) == null) { |
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_PERMISSION)) { |
| 1751 | if (parsePermission(pkg, res, parser, outError) == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1752 | return null; |
| 1753 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1754 | } else if (tagName.equals(TAG_PERMISSION_TREE)) { |
| 1755 | if (parsePermissionTree(pkg, res, parser, outError) == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1756 | return null; |
| 1757 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1758 | } else if (tagName.equals(TAG_USES_PERMISSION)) { |
| 1759 | if (!parseUsesPermission(pkg, res, parser)) { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 1760 | return null; |
| 1761 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1762 | } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) |
| 1763 | || tagName.equals(TAG_USES_PERMISSION_SDK_23)) { |
| 1764 | if (!parseUsesPermission(pkg, res, parser)) { |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 1765 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1767 | } else if (tagName.equals(TAG_USES_CONFIGURATION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | ConfigurationInfo cPref = new ConfigurationInfo(); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1769 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 1771 | cPref.reqTouchScreen = sa.getInt( |
| 1772 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 1773 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 1774 | cPref.reqKeyboardType = sa.getInt( |
| 1775 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 1776 | Configuration.KEYBOARD_UNDEFINED); |
| 1777 | if (sa.getBoolean( |
| 1778 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 1779 | false)) { |
| 1780 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 1781 | } |
| 1782 | cPref.reqNavigation = sa.getInt( |
| 1783 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 1784 | Configuration.NAVIGATION_UNDEFINED); |
| 1785 | if (sa.getBoolean( |
| 1786 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 1787 | false)) { |
| 1788 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 1789 | } |
| 1790 | sa.recycle(); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1791 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | |
| 1793 | XmlUtils.skipCurrentTag(parser); |
| 1794 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1795 | } else if (tagName.equals(TAG_USES_FEATURE)) { |
| 1796 | FeatureInfo fi = parseUsesFeature(res, parser); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1797 | pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi); |
| 1798 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1799 | if (fi.name == null) { |
| 1800 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 1801 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 1802 | pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1803 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 1804 | |
| 1805 | XmlUtils.skipCurrentTag(parser); |
| 1806 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1807 | } else if (tagName.equals(TAG_FEATURE_GROUP)) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1808 | FeatureGroupInfo group = new FeatureGroupInfo(); |
| 1809 | ArrayList<FeatureInfo> features = null; |
| 1810 | final int innerDepth = parser.getDepth(); |
| 1811 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1812 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 1813 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1814 | continue; |
| 1815 | } |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 1816 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1817 | final String innerTagName = parser.getName(); |
| 1818 | if (innerTagName.equals("uses-feature")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1819 | FeatureInfo featureInfo = parseUsesFeature(res, parser); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 1820 | // FeatureGroups are stricter and mandate that |
| 1821 | // any <uses-feature> declared are mandatory. |
| 1822 | featureInfo.flags |= FeatureInfo.FLAG_REQUIRED; |
| 1823 | features = ArrayUtils.add(features, featureInfo); |
| 1824 | } else { |
| 1825 | Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + |
| 1826 | " at " + mArchiveSourcePath + " " + |
| 1827 | parser.getPositionDescription()); |
| 1828 | } |
| 1829 | XmlUtils.skipCurrentTag(parser); |
| 1830 | } |
| 1831 | |
| 1832 | if (features != null) { |
| 1833 | group.features = new FeatureInfo[features.size()]; |
| 1834 | group.features = features.toArray(group.features); |
| 1835 | } |
| 1836 | pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group); |
Adam Lesinski | 2c72b68 | 2014-06-24 09:56:01 -0700 | [diff] [blame] | 1837 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1838 | } else if (tagName.equals(TAG_USES_SDK)) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1839 | if (SDK_VERSION > 0) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1840 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 1842 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1843 | int minVers = 0; |
| 1844 | String minCode = null; |
| 1845 | int targetVers = 0; |
| 1846 | String targetCode = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1847 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1848 | TypedValue val = sa.peekValue( |
| 1849 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 1850 | if (val != null) { |
| 1851 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 1852 | targetCode = minCode = val.string.toString(); |
| 1853 | } else { |
| 1854 | // If it's not a string, it's an integer. |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1855 | targetVers = minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1856 | } |
| 1857 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1858 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1859 | val = sa.peekValue( |
| 1860 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 1861 | if (val != null) { |
| 1862 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1863 | targetCode = val.string.toString(); |
| 1864 | if (minCode == null) { |
| 1865 | minCode = targetCode; |
| 1866 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1867 | } else { |
| 1868 | // If it's not a string, it's an integer. |
| 1869 | targetVers = val.data; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1870 | if (minVers == 0) { |
| 1871 | minVers = targetVers; |
| 1872 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | sa.recycle(); |
| 1877 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1878 | if (minCode != null) { |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1879 | boolean allowedCodename = false; |
| 1880 | for (String codename : SDK_CODENAMES) { |
| 1881 | if (minCode.equals(codename)) { |
| 1882 | allowedCodename = true; |
| 1883 | break; |
| 1884 | } |
| 1885 | } |
| 1886 | if (!allowedCodename) { |
| 1887 | if (SDK_CODENAMES.length > 0) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1888 | outError[0] = "Requires development platform " + minCode |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1889 | + " (current platform is any of " |
| 1890 | + Arrays.toString(SDK_CODENAMES) + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1891 | } else { |
| 1892 | outError[0] = "Requires development platform " + minCode |
| 1893 | + " but this is a release platform."; |
| 1894 | } |
| 1895 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1896 | return null; |
| 1897 | } |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1898 | pkg.applicationInfo.minSdkVersion = minCode; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1899 | } else if (minVers > SDK_VERSION) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1900 | outError[0] = "Requires newer sdk version #" + minVers |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 1901 | + " (current version is #" + SDK_VERSION + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1902 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1903 | return null; |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 1904 | } else { |
| 1905 | pkg.applicationInfo.minSdkVersion = Integer.toString(minVers); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 1906 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1907 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1908 | if (targetCode != null) { |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1909 | boolean allowedCodename = false; |
| 1910 | for (String codename : SDK_CODENAMES) { |
| 1911 | if (targetCode.equals(codename)) { |
| 1912 | allowedCodename = true; |
| 1913 | break; |
| 1914 | } |
| 1915 | } |
| 1916 | if (!allowedCodename) { |
| 1917 | if (SDK_CODENAMES.length > 0) { |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1918 | outError[0] = "Requires development platform " + targetCode |
Dianne Hackborn | ffcda10 | 2014-04-24 13:06:27 -0700 | [diff] [blame] | 1919 | + " (current platform is any of " |
| 1920 | + Arrays.toString(SDK_CODENAMES) + ")"; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1921 | } else { |
| 1922 | outError[0] = "Requires development platform " + targetCode |
| 1923 | + " but this is a release platform."; |
| 1924 | } |
| 1925 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1926 | return null; |
| 1927 | } |
| 1928 | // If the code matches, it definitely targets this SDK. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1929 | pkg.applicationInfo.targetSdkVersion |
| 1930 | = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 1931 | } else { |
| 1932 | pkg.applicationInfo.targetSdkVersion = targetVers; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | XmlUtils.skipCurrentTag(parser); |
| 1937 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1938 | } else if (tagName.equals(TAG_SUPPORT_SCREENS)) { |
| 1939 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1940 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 1941 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1942 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 1943 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 1944 | 0); |
| 1945 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 1946 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 1947 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 1948 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 1949 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 1950 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1951 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1952 | // This is a trick to get a boolean and still able to detect |
| 1953 | // if a value was actually set. |
| 1954 | supportsSmallScreens = sa.getInteger( |
| 1955 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 1956 | supportsSmallScreens); |
| 1957 | supportsNormalScreens = sa.getInteger( |
| 1958 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 1959 | supportsNormalScreens); |
| 1960 | supportsLargeScreens = sa.getInteger( |
| 1961 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 1962 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1963 | supportsXLargeScreens = sa.getInteger( |
| 1964 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 1965 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1966 | resizeable = sa.getInteger( |
| 1967 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1968 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1969 | anyDensity = sa.getInteger( |
| 1970 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 1971 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1972 | |
| 1973 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1974 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 1975 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1976 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1977 | } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) { |
| 1978 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1979 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 1980 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1981 | // Note: don't allow this value to be a reference to a resource |
| 1982 | // that may change. |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1983 | String name = sa.getNonResourceString( |
| 1984 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 1985 | |
| 1986 | sa.recycle(); |
| 1987 | |
| 1988 | if (name != null && (flags&PARSE_IS_SYSTEM) != 0) { |
| 1989 | if (pkg.protectedBroadcasts == null) { |
| 1990 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 1991 | } |
| 1992 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 1993 | pkg.protectedBroadcasts.add(name.intern()); |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 1998 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 1999 | } else if (tagName.equals(TAG_INSTRUMENTATION)) { |
| 2000 | if (parseInstrumentation(pkg, res, parser, outError) == null) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2001 | return null; |
| 2002 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2003 | } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) { |
| 2004 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2005 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2006 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2007 | String orig =sa.getNonConfigurationString( |
| 2008 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2009 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2010 | if (pkg.mOriginalPackages == null) { |
| 2011 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 2012 | pkg.mRealPackage = pkg.packageName; |
| 2013 | } |
| 2014 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2015 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2016 | |
| 2017 | sa.recycle(); |
| 2018 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2019 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2020 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2021 | } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) { |
| 2022 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2023 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 2024 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2025 | String name = sa.getNonConfigurationString( |
| 2026 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2027 | |
| 2028 | sa.recycle(); |
| 2029 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2030 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2031 | if (pkg.mAdoptPermissions == null) { |
| 2032 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 2033 | } |
| 2034 | pkg.mAdoptPermissions.add(name); |
| 2035 | } |
| 2036 | |
| 2037 | XmlUtils.skipCurrentTag(parser); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2038 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2039 | } else if (tagName.equals(TAG_USES_GL_TEXTURE)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2040 | // Just skip this tag |
| 2041 | XmlUtils.skipCurrentTag(parser); |
| 2042 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2043 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2044 | } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) { |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 2045 | // Just skip this tag |
| 2046 | XmlUtils.skipCurrentTag(parser); |
| 2047 | continue; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2048 | } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {// |
Michael Wright | eaeb190 | 2013-09-05 18:15:57 -0700 | [diff] [blame] | 2049 | XmlUtils.skipCurrentTag(parser); |
| 2050 | continue; |
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_EAT_COMMENT)) { |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2053 | // Just skip this tag |
| 2054 | XmlUtils.skipCurrentTag(parser); |
| 2055 | continue; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2056 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2057 | } else if (tagName.equals(TAG_PACKAGE)) { |
| 2058 | if (!parseBaseApkChild(pkg, res, parser, flags, outError)) { |
| 2059 | // If parsing a child failed the error is already set |
| 2060 | return null; |
| 2061 | } |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2062 | } else if (RIGID_PARSER) { |
| 2063 | outError[0] = "Bad element under <manifest>: " |
| 2064 | + parser.getName(); |
| 2065 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2066 | return null; |
| 2067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2069 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2070 | + " at " + mArchiveSourcePath + " " |
| 2071 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | XmlUtils.skipCurrentTag(parser); |
| 2073 | continue; |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 2078 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 2079 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 2080 | } |
| 2081 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2082 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2083 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2084 | for (int ip=0; ip<NP; ip++) { |
| 2085 | final PackageParser.NewPermissionInfo npi |
| 2086 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 2087 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 2088 | break; |
| 2089 | } |
| 2090 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2091 | if (implicitPerms == null) { |
| 2092 | implicitPerms = new StringBuilder(128); |
| 2093 | implicitPerms.append(pkg.packageName); |
| 2094 | implicitPerms.append(": compat added "); |
| 2095 | } else { |
| 2096 | implicitPerms.append(' '); |
| 2097 | } |
| 2098 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 2099 | pkg.requestedPermissions.add(npi.name); |
| 2100 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 2101 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2102 | if (implicitPerms != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2103 | Slog.i(TAG, implicitPerms.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2104 | } |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2105 | |
| 2106 | final int NS = PackageParser.SPLIT_PERMISSIONS.length; |
| 2107 | for (int is=0; is<NS; is++) { |
| 2108 | final PackageParser.SplitPermissionInfo spi |
| 2109 | = PackageParser.SPLIT_PERMISSIONS[is]; |
Dianne Hackborn | 31b0e0e | 2012-04-05 19:33:30 -0700 | [diff] [blame] | 2110 | if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk |
| 2111 | || !pkg.requestedPermissions.contains(spi.rootPerm)) { |
Dianne Hackborn | 5e4705a | 2012-04-06 12:55:53 -0700 | [diff] [blame] | 2112 | continue; |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2113 | } |
| 2114 | for (int in=0; in<spi.newPerms.length; in++) { |
| 2115 | final String perm = spi.newPerms[in]; |
| 2116 | if (!pkg.requestedPermissions.contains(perm)) { |
| 2117 | pkg.requestedPermissions.add(perm); |
Dianne Hackborn | 7924512 | 2012-03-12 10:51:26 -0700 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2122 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 2123 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2124 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2125 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 2126 | } |
| 2127 | if (supportsNormalScreens != 0) { |
| 2128 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 2129 | } |
| 2130 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 2131 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2132 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 2133 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 2134 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 2135 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 2136 | && pkg.applicationInfo.targetSdkVersion |
| 2137 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 2138 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 2139 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2140 | if (resizeable < 0 || (resizeable > 0 |
| 2141 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2142 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 2143 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 2144 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 2145 | if (anyDensity < 0 || (anyDensity > 0 |
| 2146 | && pkg.applicationInfo.targetSdkVersion |
| 2147 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 2148 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 2149 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 2150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2151 | return pkg; |
| 2152 | } |
| 2153 | |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 2154 | private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs) { |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2155 | FeatureInfo fi = new FeatureInfo(); |
| 2156 | TypedArray sa = res.obtainAttributes(attrs, |
| 2157 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
| 2158 | // Note: don't allow this value to be a reference to a resource |
| 2159 | // that may change. |
| 2160 | fi.name = sa.getNonResourceString( |
| 2161 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 2162 | fi.version = sa.getInt( |
| 2163 | com.android.internal.R.styleable.AndroidManifestUsesFeature_version, 0); |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 2164 | if (fi.name == null) { |
| 2165 | fi.reqGlEsVersion = sa.getInt( |
| 2166 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 2167 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 2168 | } |
| 2169 | if (sa.getBoolean( |
| 2170 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, true)) { |
| 2171 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 2172 | } |
| 2173 | sa.recycle(); |
| 2174 | return fi; |
| 2175 | } |
| 2176 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2177 | private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser) |
| 2178 | throws XmlPullParserException, IOException { |
| 2179 | TypedArray sa = res.obtainAttributes(parser, |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2180 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 2181 | |
| 2182 | // Note: don't allow this value to be a reference to a resource |
| 2183 | // that may change. |
| 2184 | String name = sa.getNonResourceString( |
| 2185 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2186 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2187 | int maxSdkVersion = 0; |
| 2188 | TypedValue val = sa.peekValue( |
| 2189 | com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion); |
| 2190 | if (val != null) { |
| 2191 | if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) { |
| 2192 | maxSdkVersion = val.data; |
| 2193 | } |
| 2194 | } |
| 2195 | |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2196 | sa.recycle(); |
| 2197 | |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2198 | if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) { |
| 2199 | if (name != null) { |
| 2200 | int index = pkg.requestedPermissions.indexOf(name); |
| 2201 | if (index == -1) { |
| 2202 | pkg.requestedPermissions.add(name.intern()); |
Christopher Tate | fb0676a | 2013-09-16 16:34:52 -0700 | [diff] [blame] | 2203 | } else { |
Svetoslav | 96a7716 | 2015-04-03 13:58:33 -0700 | [diff] [blame] | 2204 | Slog.w(TAG, "Ignoring duplicate uses-permissions/uses-permissions-sdk-m: " |
| 2205 | + name + " in package: " + pkg.packageName + " at: " |
| 2206 | + parser.getPositionDescription()); |
Nick Kralevich | 73f2d3c | 2013-04-04 14:38:13 -0700 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | XmlUtils.skipCurrentTag(parser); |
| 2212 | return true; |
| 2213 | } |
| 2214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 2216 | String[] outError) { |
| 2217 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 2218 | outError[0] = "Empty class name in package " + pkg; |
| 2219 | return null; |
| 2220 | } |
| 2221 | String cls = clsSeq.toString(); |
| 2222 | char c = cls.charAt(0); |
| 2223 | if (c == '.') { |
| 2224 | return (pkg + cls).intern(); |
| 2225 | } |
| 2226 | if (cls.indexOf('.') < 0) { |
| 2227 | StringBuilder b = new StringBuilder(pkg); |
| 2228 | b.append('.'); |
| 2229 | b.append(cls); |
| 2230 | return b.toString().intern(); |
| 2231 | } |
| 2232 | if (c >= 'a' && c <= 'z') { |
| 2233 | return cls.intern(); |
| 2234 | } |
| 2235 | outError[0] = "Bad class name " + cls + " in package " + pkg; |
| 2236 | return null; |
| 2237 | } |
| 2238 | |
| 2239 | private static String buildCompoundName(String pkg, |
| 2240 | CharSequence procSeq, String type, String[] outError) { |
| 2241 | String proc = procSeq.toString(); |
| 2242 | char c = proc.charAt(0); |
| 2243 | if (pkg != null && c == ':') { |
| 2244 | if (proc.length() < 2) { |
| 2245 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 2246 | + ": must be at least two characters"; |
| 2247 | return null; |
| 2248 | } |
| 2249 | String subName = proc.substring(1); |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2250 | String nameError = validateName(subName, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | if (nameError != null) { |
| 2252 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2253 | + pkg + ": " + nameError; |
| 2254 | return null; |
| 2255 | } |
| 2256 | return (pkg + proc).intern(); |
| 2257 | } |
Jeff Sharkey | 4f5e8b3 | 2015-06-11 19:13:37 -0700 | [diff] [blame] | 2258 | String nameError = validateName(proc, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | if (nameError != null && !"system".equals(proc)) { |
| 2260 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 2261 | + pkg + ": " + nameError; |
| 2262 | return null; |
| 2263 | } |
| 2264 | return proc.intern(); |
| 2265 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | private static String buildProcessName(String pkg, String defProc, |
| 2268 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 2269 | String[] outError) { |
| 2270 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 2271 | return defProc != null ? defProc : pkg; |
| 2272 | } |
| 2273 | if (separateProcesses != null) { |
| 2274 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 2275 | String sp = separateProcesses[i]; |
| 2276 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 2277 | return pkg; |
| 2278 | } |
| 2279 | } |
| 2280 | } |
| 2281 | if (procSeq == null || procSeq.length() <= 0) { |
| 2282 | return defProc; |
| 2283 | } |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2284 | return buildCompoundName(pkg, procSeq, "process", outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 2288 | CharSequence procSeq, String[] outError) { |
| 2289 | if (procSeq == null) { |
| 2290 | return defProc; |
| 2291 | } |
| 2292 | if (procSeq.length() <= 0) { |
| 2293 | return null; |
| 2294 | } |
| 2295 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 2296 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2297 | |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2298 | private boolean parseKeySets(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2299 | XmlResourceParser parser, String[] outError) |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2300 | throws XmlPullParserException, IOException { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2301 | // we've encountered the 'key-sets' tag |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2302 | // all the keys and keysets that we want must be defined here |
| 2303 | // so we're going to iterate over the parser and pull out the things we want |
| 2304 | int outerDepth = parser.getDepth(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2305 | int currentKeySetDepth = -1; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2306 | int type; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2307 | String currentKeySet = null; |
| 2308 | ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); |
| 2309 | ArraySet<String> upgradeKeySets = new ArraySet<String>(); |
| 2310 | ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); |
| 2311 | ArraySet<String> improperKeySets = new ArraySet<String>(); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2312 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2313 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2314 | if (type == XmlPullParser.END_TAG) { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2315 | if (parser.getDepth() == currentKeySetDepth) { |
| 2316 | currentKeySet = null; |
| 2317 | currentKeySetDepth = -1; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2318 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2319 | continue; |
| 2320 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2321 | String tagName = parser.getName(); |
| 2322 | if (tagName.equals("key-set")) { |
| 2323 | if (currentKeySet != null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2324 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2325 | + parser.getPositionDescription(); |
| 2326 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2327 | return false; |
| 2328 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2329 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2330 | com.android.internal.R.styleable.AndroidManifestKeySet); |
| 2331 | final String keysetName = sa.getNonResourceString( |
| 2332 | com.android.internal.R.styleable.AndroidManifestKeySet_name); |
| 2333 | definedKeySets.put(keysetName, new ArraySet<String>()); |
| 2334 | currentKeySet = keysetName; |
| 2335 | currentKeySetDepth = parser.getDepth(); |
| 2336 | sa.recycle(); |
| 2337 | } else if (tagName.equals("public-key")) { |
| 2338 | if (currentKeySet == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2339 | outError[0] = "Improperly nested 'key-set' tag at " |
| 2340 | + parser.getPositionDescription(); |
| 2341 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2342 | return false; |
| 2343 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2344 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2345 | com.android.internal.R.styleable.AndroidManifestPublicKey); |
| 2346 | final String publicKeyName = sa.getNonResourceString( |
| 2347 | com.android.internal.R.styleable.AndroidManifestPublicKey_name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2348 | final String encodedKey = sa.getNonResourceString( |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2349 | com.android.internal.R.styleable.AndroidManifestPublicKey_value); |
| 2350 | if (encodedKey == null && publicKeys.get(publicKeyName) == null) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2351 | outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" |
| 2352 | + " on first use at " + parser.getPositionDescription(); |
| 2353 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2354 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2355 | return false; |
| 2356 | } else if (encodedKey != null) { |
| 2357 | PublicKey currentKey = parsePublicKey(encodedKey); |
| 2358 | if (currentKey == null) { |
| 2359 | Slog.w(TAG, "No recognized valid key in 'public-key' tag at " |
| 2360 | + parser.getPositionDescription() + " key-set " + currentKeySet |
| 2361 | + " will not be added to the package's defined key-sets."); |
| 2362 | sa.recycle(); |
| 2363 | improperKeySets.add(currentKeySet); |
| 2364 | XmlUtils.skipCurrentTag(parser); |
| 2365 | continue; |
| 2366 | } |
| 2367 | if (publicKeys.get(publicKeyName) == null |
| 2368 | || publicKeys.get(publicKeyName).equals(currentKey)) { |
| 2369 | |
| 2370 | /* public-key first definition, or matches old definition */ |
| 2371 | publicKeys.put(publicKeyName, currentKey); |
| 2372 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2373 | outError[0] = "Value of 'public-key' " + publicKeyName |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2374 | + " conflicts with previously defined value at " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2375 | + parser.getPositionDescription(); |
| 2376 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2377 | sa.recycle(); |
| 2378 | return false; |
| 2379 | } |
Kenny Root | 37dca15 | 2013-07-10 14:01:49 -0700 | [diff] [blame] | 2380 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2381 | definedKeySets.get(currentKeySet).add(publicKeyName); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2382 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2383 | XmlUtils.skipCurrentTag(parser); |
| 2384 | } else if (tagName.equals("upgrade-key-set")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2385 | final TypedArray sa = res.obtainAttributes(parser, |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2386 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); |
| 2387 | String name = sa.getNonResourceString( |
| 2388 | com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); |
| 2389 | upgradeKeySets.add(name); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2390 | sa.recycle(); |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2391 | XmlUtils.skipCurrentTag(parser); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2392 | } else if (RIGID_PARSER) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2393 | outError[0] = "Bad element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2394 | + " at " + mArchiveSourcePath + " " |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2395 | + parser.getPositionDescription(); |
| 2396 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2397 | return false; |
| 2398 | } else { |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2399 | Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2400 | + " at " + mArchiveSourcePath + " " |
| 2401 | + parser.getPositionDescription()); |
| 2402 | XmlUtils.skipCurrentTag(parser); |
| 2403 | continue; |
| 2404 | } |
| 2405 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2406 | Set<String> publicKeyNames = publicKeys.keySet(); |
| 2407 | if (publicKeyNames.removeAll(definedKeySets.keySet())) { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2408 | outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " |
| 2409 | + "'key-set' and 'public-key' names must be distinct."; |
| 2410 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2411 | return false; |
| 2412 | } |
| 2413 | owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); |
| 2414 | for (ArrayMap.Entry<String, ArraySet<String>> e: definedKeySets.entrySet()) { |
| 2415 | final String keySetName = e.getKey(); |
| 2416 | if (e.getValue().size() == 0) { |
| 2417 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 2418 | + "'key-set' " + keySetName + " has no valid associated 'public-key'." |
| 2419 | + " Not including in package's defined key-sets."); |
| 2420 | continue; |
| 2421 | } else if (improperKeySets.contains(keySetName)) { |
| 2422 | Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " |
| 2423 | + "'key-set' " + keySetName + " contained improper 'public-key'" |
| 2424 | + " tags. Not including in package's defined key-sets."); |
| 2425 | continue; |
| 2426 | } |
| 2427 | owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); |
| 2428 | for (String s : e.getValue()) { |
| 2429 | owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2430 | } |
| 2431 | } |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2432 | if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { |
| 2433 | owner.mUpgradeKeySets = upgradeKeySets; |
| 2434 | } else { |
dcashman | 5db0cd4 | 2015-05-22 15:24:40 -0700 | [diff] [blame] | 2435 | outError[0] ="Package" + owner.packageName + " AndroidManifext.xml " |
| 2436 | + "does not define all 'upgrade-key-set's ."; |
| 2437 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 2438 | return false; |
| 2439 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2440 | return true; |
| 2441 | } |
| 2442 | |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2443 | private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2444 | XmlResourceParser parser, String[] outError) |
| 2445 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | PermissionGroup perm = new PermissionGroup(owner); |
| 2447 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2448 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
| 2450 | |
| 2451 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2452 | "<permission-group>", sa, |
| 2453 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 2454 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2455 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2456 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, |
| 2457 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | sa.recycle(); |
| 2459 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2460 | return null; |
| 2461 | } |
| 2462 | |
| 2463 | perm.info.descriptionRes = sa.getResourceId( |
| 2464 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 2465 | 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 2466 | perm.info.flags = sa.getInt( |
| 2467 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2468 | perm.info.priority = sa.getInt( |
| 2469 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); |
Dianne Hackborn | 99222d2 | 2012-05-06 16:30:15 -0700 | [diff] [blame] | 2470 | if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) { |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 2471 | perm.info.priority = 0; |
| 2472 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | |
| 2474 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2475 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2476 | if (!parseAllMetaData(res, parser, "<permission-group>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2477 | outError)) { |
| 2478 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2479 | return null; |
| 2480 | } |
| 2481 | |
| 2482 | owner.permissionGroups.add(perm); |
| 2483 | |
| 2484 | return perm; |
| 2485 | } |
| 2486 | |
| 2487 | private Permission parsePermission(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2488 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | throws XmlPullParserException, IOException { |
| 2490 | Permission perm = new Permission(owner); |
| 2491 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2492 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 2494 | |
| 2495 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2496 | "<permission>", sa, |
| 2497 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 2498 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2499 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2500 | com.android.internal.R.styleable.AndroidManifestPermission_logo, |
| 2501 | com.android.internal.R.styleable.AndroidManifestPermission_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | sa.recycle(); |
| 2503 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2504 | return null; |
| 2505 | } |
| 2506 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2507 | // Note: don't allow this value to be a reference to a resource |
| 2508 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | perm.info.group = sa.getNonResourceString( |
| 2510 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 2511 | if (perm.info.group != null) { |
| 2512 | perm.info.group = perm.info.group.intern(); |
| 2513 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | perm.info.descriptionRes = sa.getResourceId( |
| 2516 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 2517 | 0); |
| 2518 | |
| 2519 | perm.info.protectionLevel = sa.getInt( |
| 2520 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 2521 | PermissionInfo.PROTECTION_NORMAL); |
| 2522 | |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 2523 | perm.info.flags = sa.getInt( |
| 2524 | com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); |
| 2525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | sa.recycle(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 2527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | if (perm.info.protectionLevel == -1) { |
| 2529 | outError[0] = "<permission> does not specify protectionLevel"; |
| 2530 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2531 | return null; |
| 2532 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 2533 | |
| 2534 | perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); |
| 2535 | |
| 2536 | if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) { |
| 2537 | if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) != |
| 2538 | PermissionInfo.PROTECTION_SIGNATURE) { |
| 2539 | outError[0] = "<permission> protectionLevel specifies a flag but is " |
| 2540 | + "not based on signature type"; |
| 2541 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2542 | return null; |
| 2543 | } |
| 2544 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2545 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2546 | if (!parseAllMetaData(res, parser, "<permission>", perm, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2548 | return null; |
| 2549 | } |
| 2550 | |
| 2551 | owner.permissions.add(perm); |
| 2552 | |
| 2553 | return perm; |
| 2554 | } |
| 2555 | |
| 2556 | private Permission parsePermissionTree(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2557 | XmlResourceParser parser, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | throws XmlPullParserException, IOException { |
| 2559 | Permission perm = new Permission(owner); |
| 2560 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2561 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 2563 | |
| 2564 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 2565 | "<permission-tree>", sa, |
| 2566 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 2567 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2568 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2569 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, |
| 2570 | com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | sa.recycle(); |
| 2572 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2573 | return null; |
| 2574 | } |
| 2575 | |
| 2576 | sa.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | int index = perm.info.name.indexOf('.'); |
| 2579 | if (index > 0) { |
| 2580 | index = perm.info.name.indexOf('.', index+1); |
| 2581 | } |
| 2582 | if (index < 0) { |
| 2583 | outError[0] = "<permission-tree> name has less than three segments: " |
| 2584 | + perm.info.name; |
| 2585 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2586 | return null; |
| 2587 | } |
| 2588 | |
| 2589 | perm.info.descriptionRes = 0; |
| 2590 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 2591 | perm.tree = true; |
| 2592 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2593 | if (!parseAllMetaData(res, parser, "<permission-tree>", perm, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | outError)) { |
| 2595 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2596 | return null; |
| 2597 | } |
| 2598 | |
| 2599 | owner.permissions.add(perm); |
| 2600 | |
| 2601 | return perm; |
| 2602 | } |
| 2603 | |
| 2604 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2605 | XmlResourceParser parser, String[] outError) |
| 2606 | throws XmlPullParserException, IOException { |
| 2607 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 2609 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2610 | if (mParseInstrumentationArgs == null) { |
| 2611 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 2612 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 2613 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2614 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2615 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo, |
| 2616 | com.android.internal.R.styleable.AndroidManifestInstrumentation_banner); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2617 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 2618 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2619 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2620 | mParseInstrumentationArgs.sa = sa; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2621 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2622 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 2623 | new InstrumentationInfo()); |
| 2624 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | sa.recycle(); |
| 2626 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2627 | return null; |
| 2628 | } |
| 2629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2631 | // Note: don't allow this value to be a reference to a resource |
| 2632 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2633 | str = sa.getNonResourceString( |
| 2634 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 2635 | a.info.targetPackage = str != null ? str.intern() : null; |
| 2636 | |
| 2637 | a.info.handleProfiling = sa.getBoolean( |
| 2638 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 2639 | false); |
| 2640 | |
| 2641 | a.info.functionalTest = sa.getBoolean( |
| 2642 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 2643 | false); |
| 2644 | |
| 2645 | sa.recycle(); |
| 2646 | |
| 2647 | if (a.info.targetPackage == null) { |
| 2648 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 2649 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2650 | return null; |
| 2651 | } |
| 2652 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2653 | if (!parseAllMetaData(res, parser, "<instrumentation>", a, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | outError)) { |
| 2655 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2656 | return null; |
| 2657 | } |
| 2658 | |
| 2659 | owner.instrumentation.add(a); |
| 2660 | |
| 2661 | return a; |
| 2662 | } |
| 2663 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2664 | /** |
| 2665 | * Parse the {@code application} XML tree at the current parse location in a |
| 2666 | * <em>base APK</em> manifest. |
| 2667 | * <p> |
| 2668 | * When adding new features, carefully consider if they should also be |
| 2669 | * supported by split APKs. |
| 2670 | */ |
| 2671 | private boolean parseBaseApplication(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2672 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | throws XmlPullParserException, IOException { |
| 2674 | final ApplicationInfo ai = owner.applicationInfo; |
| 2675 | final String pkgName = owner.applicationInfo.packageName; |
| 2676 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2677 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 2679 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2680 | String name = sa.getNonConfigurationString( |
| 2681 | com.android.internal.R.styleable.AndroidManifestApplication_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | if (name != null) { |
| 2683 | ai.className = buildClassName(pkgName, name, outError); |
| 2684 | if (ai.className == null) { |
| 2685 | sa.recycle(); |
| 2686 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2687 | return false; |
| 2688 | } |
| 2689 | } |
| 2690 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2691 | String manageSpaceActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2692 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, |
| 2693 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | if (manageSpaceActivity != null) { |
| 2695 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 2696 | outError); |
| 2697 | } |
| 2698 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2699 | boolean allowBackup = sa.getBoolean( |
| 2700 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 2701 | if (allowBackup) { |
| 2702 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 2703 | |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 2704 | // backupAgent, killAfterRestore, fullBackupContent, backupInForeground, |
| 2705 | // and restoreAnyVersion are only relevant if backup is possible for the |
| 2706 | // given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2707 | String backupAgent = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2708 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, |
| 2709 | Configuration.NATIVE_CONFIG_VERSION); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2710 | if (backupAgent != null) { |
| 2711 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2712 | if (DEBUG_BACKUP) { |
| 2713 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2714 | + " from " + pkgName + "+" + backupAgent); |
| 2715 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 2716 | |
| 2717 | if (sa.getBoolean( |
| 2718 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 2719 | true)) { |
| 2720 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 2721 | } |
| 2722 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 2723 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 2724 | false)) { |
| 2725 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 2726 | } |
Christopher Tate | d1de256 | 2014-06-17 17:12:35 -0700 | [diff] [blame] | 2727 | if (sa.getBoolean( |
| 2728 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly, |
| 2729 | false)) { |
| 2730 | ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY; |
| 2731 | } |
Christopher Tate | 43fbc5f | 2016-02-17 18:00:48 -0800 | [diff] [blame] | 2732 | if (sa.getBoolean( |
| 2733 | com.android.internal.R.styleable.AndroidManifestApplication_backupInForeground, |
| 2734 | false)) { |
| 2735 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; |
| 2736 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2737 | } |
Matthew Williams | 303650c | 2015-04-17 18:22:51 -0700 | [diff] [blame] | 2738 | |
| 2739 | TypedValue v = sa.peekValue( |
| 2740 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent); |
| 2741 | if (v != null && (ai.fullBackupContent = v.resourceId) == 0) { |
| 2742 | if (DEBUG_BACKUP) { |
| 2743 | Slog.v(TAG, "fullBackupContent specified as boolean=" + |
| 2744 | (v.data == 0 ? "false" : "true")); |
| 2745 | } |
| 2746 | // "false" => -1, "true" => 0 |
| 2747 | ai.fullBackupContent = (v.data == 0 ? -1 : 0); |
| 2748 | } |
| 2749 | if (DEBUG_BACKUP) { |
| 2750 | Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName); |
| 2751 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2752 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | TypedValue v = sa.peekValue( |
| 2755 | com.android.internal.R.styleable.AndroidManifestApplication_label); |
| 2756 | if (v != null && (ai.labelRes=v.resourceId) == 0) { |
| 2757 | ai.nonLocalizedLabel = v.coerceToString(); |
| 2758 | } |
| 2759 | |
| 2760 | ai.icon = sa.getResourceId( |
| 2761 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2762 | ai.logo = sa.getResourceId( |
| 2763 | com.android.internal.R.styleable.AndroidManifestApplication_logo, 0); |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 2764 | ai.banner = sa.getResourceId( |
| 2765 | com.android.internal.R.styleable.AndroidManifestApplication_banner, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2766 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 2767 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | ai.descriptionRes = sa.getResourceId( |
| 2769 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 2770 | |
| 2771 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 2772 | if (sa.getBoolean( |
| 2773 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 2774 | false)) { |
| 2775 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
| 2776 | } |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | if (sa.getBoolean( |
| 2780 | com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, |
| 2781 | false)) { |
| 2782 | owner.mRequiredForAllUsers = true; |
Amith Yamasani | e993ae1 | 2013-04-15 13:42:57 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | String restrictedAccountType = sa.getString(com.android.internal.R.styleable |
| 2786 | .AndroidManifestApplication_restrictedAccountType); |
| 2787 | if (restrictedAccountType != null && restrictedAccountType.length() > 0) { |
| 2788 | owner.mRestrictedAccountType = restrictedAccountType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | } |
| 2790 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 2791 | String requiredAccountType = sa.getString(com.android.internal.R.styleable |
| 2792 | .AndroidManifestApplication_requiredAccountType); |
| 2793 | if (requiredAccountType != null && requiredAccountType.length() > 0) { |
| 2794 | owner.mRequiredAccountType = requiredAccountType; |
| 2795 | } |
| 2796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | if (sa.getBoolean( |
| 2798 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 2799 | false)) { |
| 2800 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 2801 | } |
| 2802 | |
| 2803 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 2804 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 2805 | false)) { |
| 2806 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 2807 | } |
| 2808 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2809 | owner.baseHardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2810 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 2811 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Alan Viverette | d70b9e7 | 2015-05-27 14:29:20 -0700 | [diff] [blame] | 2812 | if (owner.baseHardwareAccelerated) { |
| 2813 | ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED; |
| 2814 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2815 | |
| 2816 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 2818 | true)) { |
| 2819 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 2820 | } |
| 2821 | |
| 2822 | if (sa.getBoolean( |
| 2823 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 2824 | false)) { |
| 2825 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 2826 | } |
| 2827 | |
| 2828 | if (sa.getBoolean( |
| 2829 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 2830 | true)) { |
| 2831 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 2832 | } |
| 2833 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2834 | // The parent package controls installation, hence specify test only installs. |
| 2835 | if (owner.parentPackage == null) { |
| 2836 | if (sa.getBoolean( |
| 2837 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
| 2838 | false)) { |
| 2839 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 2840 | } |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2843 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 2844 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2845 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 2846 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 2847 | } |
| 2848 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 2849 | if (sa.getBoolean( |
Alex Klyubin | 01a959d | 2015-03-18 10:05:45 -0700 | [diff] [blame] | 2850 | com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, |
| 2851 | true)) { |
| 2852 | ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; |
| 2853 | } |
| 2854 | |
| 2855 | if (sa.getBoolean( |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 2856 | com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, |
| 2857 | false /* default is no RTL support*/)) { |
| 2858 | ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL; |
| 2859 | } |
| 2860 | |
Narayan Kamath | 589a1bc | 2014-07-03 14:43:26 +0100 | [diff] [blame] | 2861 | if (sa.getBoolean( |
| 2862 | com.android.internal.R.styleable.AndroidManifestApplication_multiArch, |
| 2863 | false)) { |
| 2864 | ai.flags |= ApplicationInfo.FLAG_MULTIARCH; |
| 2865 | } |
| 2866 | |
Dmitriy Ivanov | ff193d6 | 2014-09-30 15:10:48 -0700 | [diff] [blame] | 2867 | if (sa.getBoolean( |
| 2868 | com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, |
| 2869 | true)) { |
| 2870 | ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; |
| 2871 | } |
| 2872 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2873 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_defaultToDeviceProtectedStorage, |
| 2874 | false) && (flags & PARSE_IS_SYSTEM) != 0) { |
| 2875 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2876 | } |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2877 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_directBootAware, false) |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 2878 | && (flags & PARSE_IS_SYSTEM) != 0) { |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 2879 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 2880 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2881 | |
Wale Ogunwale | 6afdf91 | 2016-01-30 13:01:33 -0800 | [diff] [blame] | 2882 | if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, |
| 2883 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N)) { |
| 2884 | ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES; |
| 2885 | } |
| 2886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2888 | str = sa.getNonConfigurationString( |
| 2889 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 2891 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2892 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 2893 | str = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2894 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, |
| 2895 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2896 | } else { |
| 2897 | // Some older apps have been seen to use a resource reference |
| 2898 | // here that on older builds was ignored (with a warning). We |
| 2899 | // need to continue to do this for them so they don't break. |
| 2900 | str = sa.getNonResourceString( |
| 2901 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 2902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 2904 | str, outError); |
| 2905 | |
| 2906 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2907 | CharSequence pname; |
| 2908 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 2909 | pname = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 2910 | com.android.internal.R.styleable.AndroidManifestApplication_process, |
| 2911 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2912 | } else { |
| 2913 | // Some older apps have been seen to use a resource reference |
| 2914 | // here that on older builds was ignored (with a warning). We |
| 2915 | // need to continue to do this for them so they don't break. |
| 2916 | pname = sa.getNonResourceString( |
| 2917 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 2918 | } |
| 2919 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | flags, mSeparateProcesses, outError); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2921 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2922 | ai.enabled = sa.getBoolean( |
| 2923 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 2924 | |
Jose Lima | 12d0b4c | 2014-03-14 16:55:12 -0700 | [diff] [blame] | 2925 | if (sa.getBoolean( |
| 2926 | com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) { |
| 2927 | ai.flags |= ApplicationInfo.FLAG_IS_GAME; |
| 2928 | } |
| 2929 | |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 2930 | if (false) { |
| 2931 | if (sa.getBoolean( |
| 2932 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 2933 | false)) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2934 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 2935 | |
| 2936 | // A heavy-weight application can not be in a custom process. |
| 2937 | // We can do direct compare because we intern all strings. |
| 2938 | if (ai.processName != null && ai.processName != ai.packageName) { |
| 2939 | outError[0] = "cantSaveState applications can not use custom processes"; |
| 2940 | } |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2941 | } |
| 2942 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | } |
| 2944 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 2945 | ai.uiOptions = sa.getInt( |
| 2946 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 2947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | sa.recycle(); |
| 2949 | |
| 2950 | if (outError[0] != null) { |
| 2951 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2952 | return false; |
| 2953 | } |
| 2954 | |
| 2955 | final int innerDepth = parser.getDepth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2957 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2958 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 2959 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | continue; |
| 2961 | } |
| 2962 | |
| 2963 | String tagName = parser.getName(); |
| 2964 | if (tagName.equals("activity")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2965 | Activity a = parseActivity(owner, res, parser, flags, outError, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 2966 | owner.baseHardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | if (a == null) { |
| 2968 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2969 | return false; |
| 2970 | } |
| 2971 | |
| 2972 | owner.activities.add(a); |
| 2973 | |
| 2974 | } else if (tagName.equals("receiver")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2975 | 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] | 2976 | if (a == null) { |
| 2977 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2978 | return false; |
| 2979 | } |
| 2980 | |
| 2981 | owner.receivers.add(a); |
| 2982 | |
| 2983 | } else if (tagName.equals("service")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2984 | Service s = parseService(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | if (s == null) { |
| 2986 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2987 | return false; |
| 2988 | } |
| 2989 | |
| 2990 | owner.services.add(s); |
| 2991 | |
| 2992 | } else if (tagName.equals("provider")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2993 | Provider p = parseProvider(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | if (p == null) { |
| 2995 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 2996 | return false; |
| 2997 | } |
| 2998 | |
| 2999 | owner.providers.add(p); |
| 3000 | |
| 3001 | } else if (tagName.equals("activity-alias")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3002 | Activity a = parseActivityAlias(owner, res, parser, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | if (a == null) { |
| 3004 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3005 | return false; |
| 3006 | } |
| 3007 | |
| 3008 | owner.activities.add(a); |
| 3009 | |
| 3010 | } else if (parser.getName().equals("meta-data")) { |
| 3011 | // note: application meta-data is stored off to the side, so it can |
| 3012 | // remain null in the primary copy (we like to avoid extra copies because |
| 3013 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3014 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | outError)) == null) { |
| 3016 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3017 | return false; |
| 3018 | } |
| 3019 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3020 | } else if (tagName.equals("library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3021 | sa = res.obtainAttributes(parser, |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3022 | com.android.internal.R.styleable.AndroidManifestLibrary); |
| 3023 | |
| 3024 | // Note: don't allow this value to be a reference to a resource |
| 3025 | // that may change. |
| 3026 | String lname = sa.getNonResourceString( |
| 3027 | com.android.internal.R.styleable.AndroidManifestLibrary_name); |
| 3028 | |
| 3029 | sa.recycle(); |
| 3030 | |
| 3031 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3032 | lname = lname.intern(); |
| 3033 | if (!ArrayUtils.contains(owner.libraryNames, lname)) { |
| 3034 | owner.libraryNames = ArrayUtils.add(owner.libraryNames, lname); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | XmlUtils.skipCurrentTag(parser); |
| 3039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3041 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3043 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3044 | // Note: don't allow this value to be a reference to a resource |
| 3045 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | String lname = sa.getNonResourceString( |
| 3047 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3048 | boolean req = sa.getBoolean( |
| 3049 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3050 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | |
| 3052 | sa.recycle(); |
| 3053 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3054 | if (lname != null) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3055 | lname = lname.intern(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3056 | if (req) { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3057 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3058 | } else { |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3059 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3060 | owner.usesOptionalLibraries, lname); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | XmlUtils.skipCurrentTag(parser); |
| 3065 | |
| 3066 | } else if (tagName.equals("uses-package")) { |
| 3067 | // Dependencies for app installers; we don't currently try to |
| 3068 | // enforce this. |
| 3069 | XmlUtils.skipCurrentTag(parser); |
| 3070 | |
| 3071 | } else { |
| 3072 | if (!RIGID_PARSER) { |
| 3073 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
| 3074 | + " at " + mArchiveSourcePath + " " |
| 3075 | + parser.getPositionDescription()); |
| 3076 | XmlUtils.skipCurrentTag(parser); |
| 3077 | continue; |
| 3078 | } else { |
| 3079 | outError[0] = "Bad element under <application>: " + tagName; |
| 3080 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3081 | return false; |
| 3082 | } |
| 3083 | } |
| 3084 | } |
| 3085 | |
Narayan Kamath | b12dcfb | 2015-03-30 11:31:04 +0100 | [diff] [blame] | 3086 | modifySharedLibrariesForBackwardCompatibility(owner); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3087 | |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3088 | if (hasDomainURLs(owner)) { |
| 3089 | owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3090 | } else { |
| 3091 | owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; |
| 3092 | } |
| 3093 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3094 | return true; |
| 3095 | } |
| 3096 | |
Narayan Kamath | b12dcfb | 2015-03-30 11:31:04 +0100 | [diff] [blame] | 3097 | private static void modifySharedLibrariesForBackwardCompatibility(Package owner) { |
| 3098 | // "org.apache.http.legacy" is now a part of the boot classpath so it doesn't need |
| 3099 | // to be an explicit dependency. |
| 3100 | // |
| 3101 | // A future change will remove this library from the boot classpath, at which point |
| 3102 | // all apps that target SDK 21 and earlier will have it automatically added to their |
| 3103 | // dependency lists. |
| 3104 | owner.usesLibraries = ArrayUtils.remove(owner.usesLibraries, "org.apache.http.legacy"); |
| 3105 | owner.usesOptionalLibraries = ArrayUtils.remove(owner.usesOptionalLibraries, |
| 3106 | "org.apache.http.legacy"); |
Narayan Kamath | e2d2ed4 | 2015-01-13 15:51:57 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3109 | /** |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3110 | * 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] | 3111 | */ |
| 3112 | private static boolean hasDomainURLs(Package pkg) { |
| 3113 | if (pkg == null || pkg.activities == null) return false; |
| 3114 | final ArrayList<Activity> activities = pkg.activities; |
| 3115 | final int countActivities = activities.size(); |
| 3116 | for (int n=0; n<countActivities; n++) { |
| 3117 | Activity activity = activities.get(n); |
| 3118 | ArrayList<ActivityIntentInfo> filters = activity.intents; |
| 3119 | if (filters == null) continue; |
| 3120 | final int countFilters = filters.size(); |
| 3121 | for (int m=0; m<countFilters; m++) { |
| 3122 | ActivityIntentInfo aii = filters.get(m); |
| 3123 | if (!aii.hasAction(Intent.ACTION_VIEW)) continue; |
Fabrice Di Meglio | e48c137 | 2015-04-09 15:55:42 -0700 | [diff] [blame] | 3124 | if (!aii.hasAction(Intent.ACTION_DEFAULT)) continue; |
Fabrice Di Meglio | d3d8a32 | 2015-04-01 15:58:47 -0700 | [diff] [blame] | 3125 | if (aii.hasDataScheme(IntentFilter.SCHEME_HTTP) || |
| 3126 | aii.hasDataScheme(IntentFilter.SCHEME_HTTPS)) { |
| 3127 | return true; |
| 3128 | } |
| 3129 | } |
| 3130 | } |
| 3131 | return false; |
| 3132 | } |
| 3133 | |
| 3134 | /** |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3135 | * Parse the {@code application} XML tree at the current parse location in a |
| 3136 | * <em>split APK</em> manifest. |
| 3137 | * <p> |
| 3138 | * Note that split APKs have many more restrictions on what they're capable |
| 3139 | * of doing, so many valid features of a base APK have been carefully |
| 3140 | * omitted here. |
| 3141 | */ |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3142 | private boolean parseSplitApplication(Package owner, Resources res, XmlResourceParser parser, |
| 3143 | int flags, int splitIndex, String[] outError) |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3144 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3145 | TypedArray sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3146 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 3147 | |
| 3148 | if (sa.getBoolean( |
| 3149 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) { |
| 3150 | owner.splitFlags[splitIndex] |= ApplicationInfo.FLAG_HAS_CODE; |
| 3151 | } |
| 3152 | |
| 3153 | final int innerDepth = parser.getDepth(); |
| 3154 | int type; |
| 3155 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3156 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 3157 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3158 | continue; |
| 3159 | } |
| 3160 | |
| 3161 | String tagName = parser.getName(); |
| 3162 | if (tagName.equals("activity")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3163 | Activity a = parseActivity(owner, res, parser, flags, outError, false, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3164 | owner.baseHardwareAccelerated); |
| 3165 | if (a == null) { |
| 3166 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3167 | return false; |
| 3168 | } |
| 3169 | |
| 3170 | owner.activities.add(a); |
| 3171 | |
| 3172 | } else if (tagName.equals("receiver")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3173 | Activity a = parseActivity(owner, res, parser, flags, outError, true, false); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3174 | if (a == null) { |
| 3175 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3176 | return false; |
| 3177 | } |
| 3178 | |
| 3179 | owner.receivers.add(a); |
| 3180 | |
| 3181 | } else if (tagName.equals("service")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3182 | Service s = parseService(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3183 | if (s == null) { |
| 3184 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3185 | return false; |
| 3186 | } |
| 3187 | |
| 3188 | owner.services.add(s); |
| 3189 | |
| 3190 | } else if (tagName.equals("provider")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3191 | Provider p = parseProvider(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3192 | if (p == null) { |
| 3193 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3194 | return false; |
| 3195 | } |
| 3196 | |
| 3197 | owner.providers.add(p); |
| 3198 | |
| 3199 | } else if (tagName.equals("activity-alias")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3200 | Activity a = parseActivityAlias(owner, res, parser, flags, outError); |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3201 | if (a == null) { |
| 3202 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3203 | return false; |
| 3204 | } |
| 3205 | |
| 3206 | owner.activities.add(a); |
| 3207 | |
| 3208 | } else if (parser.getName().equals("meta-data")) { |
| 3209 | // note: application meta-data is stored off to the side, so it can |
| 3210 | // remain null in the primary copy (we like to avoid extra copies because |
| 3211 | // it can be large) |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3212 | if ((owner.mAppMetaData = parseMetaData(res, parser, owner.mAppMetaData, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3213 | outError)) == null) { |
| 3214 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3215 | return false; |
| 3216 | } |
| 3217 | |
| 3218 | } else if (tagName.equals("uses-library")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3219 | sa = res.obtainAttributes(parser, |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 3220 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 3221 | |
| 3222 | // Note: don't allow this value to be a reference to a resource |
| 3223 | // that may change. |
| 3224 | String lname = sa.getNonResourceString( |
| 3225 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
| 3226 | boolean req = sa.getBoolean( |
| 3227 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 3228 | true); |
| 3229 | |
| 3230 | sa.recycle(); |
| 3231 | |
| 3232 | if (lname != null) { |
| 3233 | lname = lname.intern(); |
| 3234 | if (req) { |
| 3235 | // Upgrade to treat as stronger constraint |
| 3236 | owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname); |
| 3237 | owner.usesOptionalLibraries = ArrayUtils.remove( |
| 3238 | owner.usesOptionalLibraries, lname); |
| 3239 | } else { |
| 3240 | // Ignore if someone already defined as required |
| 3241 | if (!ArrayUtils.contains(owner.usesLibraries, lname)) { |
| 3242 | owner.usesOptionalLibraries = ArrayUtils.add( |
| 3243 | owner.usesOptionalLibraries, lname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 3244 | } |
| 3245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | XmlUtils.skipCurrentTag(parser); |
| 3249 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3250 | } else if (tagName.equals("uses-package")) { |
| 3251 | // Dependencies for app installers; we don't currently try to |
| 3252 | // enforce this. |
| 3253 | XmlUtils.skipCurrentTag(parser); |
| 3254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3255 | } else { |
| 3256 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3257 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3258 | + " at " + mArchiveSourcePath + " " |
| 3259 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | XmlUtils.skipCurrentTag(parser); |
| 3261 | continue; |
| 3262 | } else { |
| 3263 | outError[0] = "Bad element under <application>: " + tagName; |
| 3264 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 3265 | return false; |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | return true; |
| 3271 | } |
| 3272 | |
| 3273 | private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 3274 | String[] outError, String tag, TypedArray sa, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3275 | int nameRes, int labelRes, int iconRes, int logoRes, int bannerRes) { |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3276 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | if (name == null) { |
| 3278 | outError[0] = tag + " does not specify android:name"; |
| 3279 | return false; |
| 3280 | } |
| 3281 | |
| 3282 | outInfo.name |
| 3283 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 3284 | if (outInfo.name == null) { |
| 3285 | return false; |
| 3286 | } |
| 3287 | |
| 3288 | int iconVal = sa.getResourceId(iconRes, 0); |
| 3289 | if (iconVal != 0) { |
| 3290 | outInfo.icon = iconVal; |
| 3291 | outInfo.nonLocalizedLabel = null; |
| 3292 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3293 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3294 | int logoVal = sa.getResourceId(logoRes, 0); |
| 3295 | if (logoVal != 0) { |
| 3296 | outInfo.logo = logoVal; |
| 3297 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3299 | int bannerVal = sa.getResourceId(bannerRes, 0); |
| 3300 | if (bannerVal != 0) { |
| 3301 | outInfo.banner = bannerVal; |
| 3302 | } |
| 3303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | TypedValue v = sa.peekValue(labelRes); |
| 3305 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 3306 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 3307 | } |
| 3308 | |
| 3309 | outInfo.packageName = owner.packageName; |
| 3310 | |
| 3311 | return true; |
| 3312 | } |
| 3313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | private Activity parseActivity(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3315 | XmlResourceParser parser, int flags, String[] outError, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 3316 | boolean receiver, boolean hardwareAccelerated) |
| 3317 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3318 | TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3320 | if (mParseActivityArgs == null) { |
| 3321 | mParseActivityArgs = new ParseComponentArgs(owner, outError, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3322 | R.styleable.AndroidManifestActivity_name, |
| 3323 | R.styleable.AndroidManifestActivity_label, |
| 3324 | R.styleable.AndroidManifestActivity_icon, |
| 3325 | R.styleable.AndroidManifestActivity_logo, |
| 3326 | R.styleable.AndroidManifestActivity_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3327 | mSeparateProcesses, |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3328 | R.styleable.AndroidManifestActivity_process, |
| 3329 | R.styleable.AndroidManifestActivity_description, |
| 3330 | R.styleable.AndroidManifestActivity_enabled); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3331 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3332 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3333 | mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 3334 | mParseActivityArgs.sa = sa; |
| 3335 | mParseActivityArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3336 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3337 | Activity a = new Activity(mParseActivityArgs, new ActivityInfo()); |
| 3338 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | sa.recycle(); |
| 3340 | return null; |
| 3341 | } |
| 3342 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3343 | boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | if (setExported) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3345 | 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] | 3346 | } |
| 3347 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3348 | 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] | 3349 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3350 | a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions, |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3351 | a.info.applicationInfo.uiOptions); |
| 3352 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3353 | String parentName = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3354 | R.styleable.AndroidManifestActivity_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3355 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3356 | if (parentName != null) { |
| 3357 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 3358 | if (outError[0] == null) { |
| 3359 | a.info.parentActivityName = parentClassName; |
| 3360 | } else { |
| 3361 | Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + |
| 3362 | parentName); |
| 3363 | outError[0] = null; |
| 3364 | } |
| 3365 | } |
| 3366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | String str; |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3368 | str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | if (str == null) { |
| 3370 | a.info.permission = owner.applicationInfo.permission; |
| 3371 | } else { |
| 3372 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 3373 | } |
| 3374 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3375 | str = sa.getNonConfigurationString( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3376 | R.styleable.AndroidManifestActivity_taskAffinity, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3377 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 3379 | owner.applicationInfo.taskAffinity, str, outError); |
| 3380 | |
| 3381 | a.info.flags = 0; |
| 3382 | if (sa.getBoolean( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3383 | R.styleable.AndroidManifestActivity_multiprocess, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 3385 | } |
| 3386 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3387 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 3389 | } |
| 3390 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3391 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 3393 | } |
| 3394 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3395 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 3397 | } |
| 3398 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3399 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 3401 | } |
| 3402 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3403 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 3405 | } |
| 3406 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3407 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 3409 | } |
| 3410 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3411 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 3413 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 3414 | } |
| 3415 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3416 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 3417 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 3418 | } |
| 3419 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 3420 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false) |
| 3421 | || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) { |
| 3422 | a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3425 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) { |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 3426 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 3427 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3428 | |
Fyodor Kupolov | 4f5de34 | 2015-08-25 10:08:45 -0700 | [diff] [blame] | 3429 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_systemUserOnly, false)) { |
| 3430 | a.info.flags |= ActivityInfo.FLAG_SYSTEM_USER_ONLY; |
Fyodor Kupolov | 703d1c4 | 2015-01-27 11:59:00 -0800 | [diff] [blame] | 3431 | } |
| 3432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | if (!receiver) { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3434 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 3435 | hardwareAccelerated)) { |
| 3436 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 3437 | } |
| 3438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | a.info.launchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3440 | R.styleable.AndroidManifestActivity_launchMode, ActivityInfo.LAUNCH_MULTIPLE); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3441 | a.info.documentLaunchMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3442 | R.styleable.AndroidManifestActivity_documentLaunchMode, |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3443 | ActivityInfo.DOCUMENT_LAUNCH_NONE); |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 3444 | a.info.maxRecents = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3445 | R.styleable.AndroidManifestActivity_maxRecents, |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 3446 | ActivityManager.getDefaultAppRecentsLimitStatic()); |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3447 | 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] | 3448 | a.info.softInputMode = sa.getInt( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3449 | R.styleable.AndroidManifestActivity_windowSoftInputMode, 0); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3450 | |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 3451 | a.info.persistableMode = sa.getInteger( |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3452 | R.styleable.AndroidManifestActivity_persistableMode, |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 3453 | ActivityInfo.PERSIST_ROOT_ONLY); |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3454 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3455 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3456 | a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED; |
| 3457 | } |
| 3458 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3459 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) { |
Craig Mautner | 2dac056 | 2014-05-06 09:06:44 -0700 | [diff] [blame] | 3460 | a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS; |
| 3461 | } |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3462 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3463 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) { |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3464 | a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY; |
| 3465 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3466 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3467 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3468 | a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
| 3469 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3470 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3471 | a.info.screenOrientation = sa.getInt( |
| 3472 | R.styleable.AndroidManifestActivity_screenOrientation, |
| 3473 | SCREEN_ORIENTATION_UNSPECIFIED); |
Wale Ogunwale | 6a59136 | 2015-10-05 20:18:27 -0700 | [diff] [blame] | 3474 | |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3475 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 163828d | 2016-02-01 11:48:19 -0800 | [diff] [blame] | 3476 | final boolean appDefault = (owner.applicationInfo.privateFlags |
| 3477 | & PRIVATE_FLAG_RESIZEABLE_ACTIVITIES) != 0; |
| 3478 | final boolean resizeable = sa.getBoolean( |
| 3479 | R.styleable.AndroidManifestActivity_resizeableActivity, appDefault); |
| 3480 | |
| 3481 | if (resizeable) { |
| 3482 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, |
| 3483 | false)) { |
| 3484 | a.info.resizeMode = RESIZE_MODE_RESIZEABLE_AND_PIPABLE; |
| 3485 | } else { |
| 3486 | a.info.resizeMode = RESIZE_MODE_RESIZEABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3487 | } |
Wale Ogunwale | 163828d | 2016-02-01 11:48:19 -0800 | [diff] [blame] | 3488 | } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
| 3489 | a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | 508ff55 | 2016-02-15 19:31:50 -0800 | [diff] [blame] | 3490 | } else if (!a.info.isFixedOrientation() && (a.info.flags & FLAG_IMMERSIVE) == 0) { |
Wale Ogunwale | d829d36 | 2016-02-10 19:24:49 -0800 | [diff] [blame] | 3491 | a.info.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) { |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3495 | a.info.flags |= FLAG_ALWAYS_FOCUSABLE; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3496 | } |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3497 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3498 | a.info.lockTaskLaunchMode = |
| 3499 | sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3500 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3501 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 3502 | R.styleable.AndroidManifestActivity_directBootAware, |
| 3503 | owner.applicationInfo.isDirectBootAware()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3504 | } else { |
| 3505 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 3506 | a.info.configChanges = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 3508 | if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 3509 | a.info.flags |= ActivityInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3510 | if (a.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3511 | Slog.w(TAG, "Activity exported request ignored due to singleUser: " |
| 3512 | + a.className + " at " + mArchiveSourcePath + " " |
| 3513 | + parser.getPositionDescription()); |
| 3514 | a.info.exported = false; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3515 | setExported = true; |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3516 | } |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3517 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3518 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3519 | a.info.encryptionAware = a.info.directBootAware = sa.getBoolean( |
| 3520 | R.styleable.AndroidManifestActivity_directBootAware, |
| 3521 | owner.applicationInfo.isDirectBootAware()); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3524 | if (a.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3525 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3526 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | sa.recycle(); |
| 3530 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3531 | if (receiver && (owner.applicationInfo.privateFlags |
| 3532 | &ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3533 | // A heavy-weight application can not have receives in its main process |
| 3534 | // We can do direct compare because we intern all strings. |
| 3535 | if (a.info.processName == owner.packageName) { |
| 3536 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 3537 | } |
| 3538 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | if (outError[0] != null) { |
| 3541 | return null; |
| 3542 | } |
| 3543 | |
| 3544 | int outerDepth = parser.getDepth(); |
| 3545 | int type; |
| 3546 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 3547 | && (type != XmlPullParser.END_TAG |
| 3548 | || parser.getDepth() > outerDepth)) { |
| 3549 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3550 | continue; |
| 3551 | } |
| 3552 | |
| 3553 | if (parser.getName().equals("intent-filter")) { |
| 3554 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3555 | if (!parseIntent(res, parser, true, true, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | return null; |
| 3557 | } |
| 3558 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3559 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 3560 | + mArchiveSourcePath + " " |
| 3561 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | } else { |
| 3563 | a.intents.add(intent); |
| 3564 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3565 | } else if (!receiver && parser.getName().equals("preferred")) { |
| 3566 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3567 | if (!parseIntent(res, parser, false, false, intent, outError)) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3568 | return null; |
| 3569 | } |
| 3570 | if (intent.countActions() == 0) { |
| 3571 | Slog.w(TAG, "No actions in preferred at " |
| 3572 | + mArchiveSourcePath + " " |
| 3573 | + parser.getPositionDescription()); |
| 3574 | } else { |
| 3575 | if (owner.preferredActivityFilters == null) { |
| 3576 | owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>(); |
| 3577 | } |
| 3578 | owner.preferredActivityFilters.add(intent); |
| 3579 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3581 | if ((a.metaData = parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | outError)) == null) { |
| 3583 | return null; |
| 3584 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3585 | } else if (!receiver && parser.getName().equals("layout")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3586 | parseLayout(res, parser, a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } else { |
| 3588 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3589 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3590 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3591 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3592 | + " at " + mArchiveSourcePath + " " |
| 3593 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3594 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3595 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3596 | + " at " + mArchiveSourcePath + " " |
| 3597 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } |
| 3599 | XmlUtils.skipCurrentTag(parser); |
| 3600 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3602 | if (receiver) { |
| 3603 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 3604 | } else { |
| 3605 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 3606 | } |
| 3607 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | if (!setExported) { |
| 3613 | a.info.exported = a.intents.size() > 0; |
| 3614 | } |
| 3615 | |
| 3616 | return a; |
| 3617 | } |
| 3618 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3619 | private void parseLayout(Resources res, AttributeSet attrs, Activity a) { |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3620 | TypedArray sw = res.obtainAttributes(attrs, |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3621 | com.android.internal.R.styleable.AndroidManifestLayout); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3622 | int width = -1; |
| 3623 | float widthFraction = -1f; |
| 3624 | int height = -1; |
| 3625 | float heightFraction = -1f; |
| 3626 | final int widthType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3627 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3628 | if (widthType == TypedValue.TYPE_FRACTION) { |
| 3629 | widthFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3630 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3631 | 1, 1, -1); |
| 3632 | } else if (widthType == TypedValue.TYPE_DIMENSION) { |
| 3633 | width = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3634 | com.android.internal.R.styleable.AndroidManifestLayout_defaultWidth, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3635 | -1); |
| 3636 | } |
| 3637 | final int heightType = sw.getType( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3638 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3639 | if (heightType == TypedValue.TYPE_FRACTION) { |
| 3640 | heightFraction = sw.getFraction( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3641 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3642 | 1, 1, -1); |
| 3643 | } else if (heightType == TypedValue.TYPE_DIMENSION) { |
| 3644 | height = sw.getDimensionPixelSize( |
Wale Ogunwale | b12e109 | 2016-01-30 12:23:09 -0800 | [diff] [blame] | 3645 | com.android.internal.R.styleable.AndroidManifestLayout_defaultHeight, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3646 | -1); |
| 3647 | } |
| 3648 | int gravity = sw.getInt( |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3649 | com.android.internal.R.styleable.AndroidManifestLayout_gravity, |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3650 | Gravity.CENTER); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3651 | int minimalSize = sw.getDimensionPixelSize( |
| 3652 | com.android.internal.R.styleable.AndroidManifestLayout_minimalSize, |
| 3653 | -1); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3654 | sw.recycle(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3655 | a.info.layout = new ActivityInfo.Layout(width, widthFraction, |
| 3656 | height, heightFraction, gravity, minimalSize); |
Filip Gruszczynski | 848fe6b | 2015-08-19 13:32:41 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | private Activity parseActivityAlias(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3660 | XmlResourceParser parser, int flags, String[] outError) |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3661 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3662 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 3664 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3665 | String targetActivity = sa.getNonConfigurationString( |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3666 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, |
| 3667 | Configuration.NATIVE_CONFIG_VERSION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | if (targetActivity == null) { |
| 3669 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 3670 | sa.recycle(); |
| 3671 | return null; |
| 3672 | } |
| 3673 | |
| 3674 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 3675 | targetActivity, outError); |
| 3676 | if (targetActivity == null) { |
| 3677 | sa.recycle(); |
| 3678 | return null; |
| 3679 | } |
| 3680 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3681 | if (mParseActivityAliasArgs == null) { |
| 3682 | mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, |
| 3683 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 3684 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 3685 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3686 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3687 | com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3688 | mSeparateProcesses, |
| 3689 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3690 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3691 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
| 3692 | mParseActivityAliasArgs.tag = "<activity-alias>"; |
| 3693 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3694 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3695 | mParseActivityAliasArgs.sa = sa; |
| 3696 | mParseActivityAliasArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | Activity target = null; |
| 3699 | |
| 3700 | final int NA = owner.activities.size(); |
| 3701 | for (int i=0; i<NA; i++) { |
| 3702 | Activity t = owner.activities.get(i); |
| 3703 | if (targetActivity.equals(t.info.name)) { |
| 3704 | target = t; |
| 3705 | break; |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | if (target == null) { |
| 3710 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 3711 | + " not found in manifest"; |
| 3712 | sa.recycle(); |
| 3713 | return null; |
| 3714 | } |
| 3715 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3716 | ActivityInfo info = new ActivityInfo(); |
| 3717 | info.targetActivity = targetActivity; |
| 3718 | info.configChanges = target.info.configChanges; |
| 3719 | info.flags = target.info.flags; |
| 3720 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3721 | info.logo = target.info.logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3722 | info.banner = target.info.banner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3723 | info.labelRes = target.info.labelRes; |
| 3724 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 3725 | info.launchMode = target.info.launchMode; |
Yao Chen | 597ad3f | 2015-06-09 16:00:14 -0700 | [diff] [blame] | 3726 | info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3727 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3728 | if (info.descriptionRes == 0) { |
| 3729 | info.descriptionRes = target.info.descriptionRes; |
| 3730 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3731 | info.screenOrientation = target.info.screenOrientation; |
| 3732 | info.taskAffinity = target.info.taskAffinity; |
| 3733 | info.theme = target.info.theme; |
Dianne Hackborn | 0836c7c | 2011-10-20 18:40:23 -0700 | [diff] [blame] | 3734 | info.softInputMode = target.info.softInputMode; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 3735 | info.uiOptions = target.info.uiOptions; |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3736 | info.parentActivityName = target.info.parentActivityName; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 3737 | info.maxRecents = target.info.maxRecents; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3738 | info.layout = target.info.layout; |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 3739 | info.resizeMode = target.info.resizeMode; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3740 | info.encryptionAware = info.directBootAware = target.info.directBootAware; |
Craig Mautner | 8307ea7 | 2014-09-11 15:03:53 -0700 | [diff] [blame] | 3741 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3742 | Activity a = new Activity(mParseActivityAliasArgs, info); |
| 3743 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | sa.recycle(); |
| 3745 | return null; |
| 3746 | } |
| 3747 | |
| 3748 | final boolean setExported = sa.hasValue( |
| 3749 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 3750 | if (setExported) { |
| 3751 | a.info.exported = sa.getBoolean( |
| 3752 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 3753 | } |
| 3754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3756 | str = sa.getNonConfigurationString( |
| 3757 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | if (str != null) { |
| 3759 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 3760 | } |
| 3761 | |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3762 | String parentName = sa.getNonConfigurationString( |
| 3763 | com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 3764 | Configuration.NATIVE_CONFIG_VERSION); |
Adam Powell | dd8fab2 | 2012-03-22 17:47:27 -0700 | [diff] [blame] | 3765 | if (parentName != null) { |
| 3766 | String parentClassName = buildClassName(a.info.packageName, parentName, outError); |
| 3767 | if (outError[0] == null) { |
| 3768 | a.info.parentActivityName = parentClassName; |
| 3769 | } else { |
| 3770 | Log.e(TAG, "Activity alias " + a.info.name + |
| 3771 | " specified invalid parentActivityName " + parentName); |
| 3772 | outError[0] = null; |
| 3773 | } |
| 3774 | } |
| 3775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | sa.recycle(); |
| 3777 | |
| 3778 | if (outError[0] != null) { |
| 3779 | return null; |
| 3780 | } |
| 3781 | |
| 3782 | int outerDepth = parser.getDepth(); |
| 3783 | int type; |
| 3784 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 3785 | && (type != XmlPullParser.END_TAG |
| 3786 | || parser.getDepth() > outerDepth)) { |
| 3787 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3788 | continue; |
| 3789 | } |
| 3790 | |
| 3791 | if (parser.getName().equals("intent-filter")) { |
| 3792 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3793 | if (!parseIntent(res, parser, true, true, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | return null; |
| 3795 | } |
| 3796 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3797 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 3798 | + mArchiveSourcePath + " " |
| 3799 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | } else { |
| 3801 | a.intents.add(intent); |
| 3802 | } |
| 3803 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3804 | if ((a.metaData=parseMetaData(res, parser, a.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | outError)) == null) { |
| 3806 | return null; |
| 3807 | } |
| 3808 | } else { |
| 3809 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3810 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 3811 | + " at " + mArchiveSourcePath + " " |
| 3812 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | XmlUtils.skipCurrentTag(parser); |
| 3814 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 3815 | } else { |
| 3816 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 3817 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | if (!setExported) { |
| 3823 | a.info.exported = a.intents.size() > 0; |
| 3824 | } |
| 3825 | |
| 3826 | return a; |
| 3827 | } |
| 3828 | |
| 3829 | private Provider parseProvider(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3830 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3831 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3832 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 3834 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3835 | if (mParseProviderArgs == null) { |
| 3836 | mParseProviderArgs = new ParseComponentArgs(owner, outError, |
| 3837 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 3838 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 3839 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3840 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 3841 | com.android.internal.R.styleable.AndroidManifestProvider_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3842 | mSeparateProcesses, |
| 3843 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3844 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3845 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
| 3846 | mParseProviderArgs.tag = "<provider>"; |
| 3847 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3848 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3849 | mParseProviderArgs.sa = sa; |
| 3850 | mParseProviderArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3851 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3852 | Provider p = new Provider(mParseProviderArgs, new ProviderInfo()); |
| 3853 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3854 | sa.recycle(); |
| 3855 | return null; |
| 3856 | } |
| 3857 | |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 3858 | boolean providerExportedDefault = false; |
| 3859 | |
| 3860 | if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 3861 | // For compatibility, applications targeting API level 16 or lower |
| 3862 | // should have their content providers exported by default, unless they |
| 3863 | // specify otherwise. |
| 3864 | providerExportedDefault = true; |
| 3865 | } |
| 3866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | p.info.exported = sa.getBoolean( |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 3868 | com.android.internal.R.styleable.AndroidManifestProvider_exported, |
| 3869 | providerExportedDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3870 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3871 | String cpname = sa.getNonConfigurationString( |
| 3872 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | |
| 3874 | p.info.isSyncable = sa.getBoolean( |
| 3875 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 3876 | false); |
| 3877 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3878 | String permission = sa.getNonConfigurationString( |
| 3879 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 3880 | String str = sa.getNonConfigurationString( |
| 3881 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | if (str == null) { |
| 3883 | str = permission; |
| 3884 | } |
| 3885 | if (str == null) { |
| 3886 | p.info.readPermission = owner.applicationInfo.permission; |
| 3887 | } else { |
| 3888 | p.info.readPermission = |
| 3889 | str.length() > 0 ? str.toString().intern() : null; |
| 3890 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3891 | str = sa.getNonConfigurationString( |
| 3892 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | if (str == null) { |
| 3894 | str = permission; |
| 3895 | } |
| 3896 | if (str == null) { |
| 3897 | p.info.writePermission = owner.applicationInfo.permission; |
| 3898 | } else { |
| 3899 | p.info.writePermission = |
| 3900 | str.length() > 0 ? str.toString().intern() : null; |
| 3901 | } |
| 3902 | |
| 3903 | p.info.grantUriPermissions = sa.getBoolean( |
| 3904 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 3905 | false); |
| 3906 | |
| 3907 | p.info.multiprocess = sa.getBoolean( |
| 3908 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 3909 | false); |
| 3910 | |
| 3911 | p.info.initOrder = sa.getInt( |
| 3912 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 3913 | 0); |
| 3914 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3915 | p.info.flags = 0; |
| 3916 | |
| 3917 | if (sa.getBoolean( |
| 3918 | com.android.internal.R.styleable.AndroidManifestProvider_singleUser, |
| 3919 | false)) { |
| 3920 | p.info.flags |= ProviderInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 3921 | if (p.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3922 | Slog.w(TAG, "Provider exported request ignored due to singleUser: " |
| 3923 | + p.className + " at " + mArchiveSourcePath + " " |
| 3924 | + parser.getPositionDescription()); |
| 3925 | p.info.exported = false; |
| 3926 | } |
| 3927 | } |
| 3928 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3929 | p.info.encryptionAware = p.info.directBootAware = sa.getBoolean( |
| 3930 | R.styleable.AndroidManifestProvider_directBootAware, |
| 3931 | owner.applicationInfo.isDirectBootAware()); |
| 3932 | if (p.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3933 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3934 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 3935 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 3936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | sa.recycle(); |
| 3938 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3939 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 3940 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3941 | // A heavy-weight application can not have providers in its main process |
| 3942 | // We can do direct compare because we intern all strings. |
| 3943 | if (p.info.processName == owner.packageName) { |
| 3944 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 3945 | return null; |
| 3946 | } |
| 3947 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | if (cpname == null) { |
Nick Kralevich | f097b16 | 2012-07-28 12:43:48 -0700 | [diff] [blame] | 3950 | outError[0] = "<provider> does not include authorities attribute"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3951 | return null; |
| 3952 | } |
Dianne Hackborn | 1bc177c | 2014-12-03 10:20:30 -0800 | [diff] [blame] | 3953 | if (cpname.length() <= 0) { |
| 3954 | outError[0] = "<provider> has empty authorities attribute"; |
| 3955 | return null; |
| 3956 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | p.info.authority = cpname.intern(); |
| 3958 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3959 | if (!parseProviderTags(res, parser, p, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | return null; |
| 3961 | } |
| 3962 | |
| 3963 | return p; |
| 3964 | } |
| 3965 | |
| 3966 | private boolean parseProviderTags(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3967 | XmlResourceParser parser, Provider outInfo, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | throws XmlPullParserException, IOException { |
| 3969 | int outerDepth = parser.getDepth(); |
| 3970 | int type; |
| 3971 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 3972 | && (type != XmlPullParser.END_TAG |
| 3973 | || parser.getDepth() > outerDepth)) { |
| 3974 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3975 | continue; |
| 3976 | } |
| 3977 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 3978 | if (parser.getName().equals("intent-filter")) { |
| 3979 | ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3980 | if (!parseIntent(res, parser, true, false, intent, outError)) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 3981 | return false; |
| 3982 | } |
| 3983 | outInfo.intents.add(intent); |
| 3984 | |
| 3985 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3986 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | outInfo.metaData, outError)) == null) { |
| 3988 | return false; |
| 3989 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3991 | } else if (parser.getName().equals("grant-uri-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3992 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 3994 | |
| 3995 | PatternMatcher pa = null; |
| 3996 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 3997 | String str = sa.getNonConfigurationString( |
| 3998 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | if (str != null) { |
| 4000 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 4001 | } |
| 4002 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4003 | str = sa.getNonConfigurationString( |
| 4004 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | if (str != null) { |
| 4006 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 4007 | } |
| 4008 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4009 | str = sa.getNonConfigurationString( |
| 4010 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | if (str != null) { |
| 4012 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 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 | sa.recycle(); |
| 4016 | |
| 4017 | if (pa != null) { |
| 4018 | if (outInfo.info.uriPermissionPatterns == null) { |
| 4019 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 4020 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 4021 | } else { |
| 4022 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 4023 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 4024 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 4025 | newp[N] = pa; |
| 4026 | outInfo.info.uriPermissionPatterns = newp; |
| 4027 | } |
| 4028 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4029 | } else { |
| 4030 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4031 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4032 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4033 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4034 | XmlUtils.skipCurrentTag(parser); |
| 4035 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4036 | } else { |
| 4037 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 4038 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4039 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4040 | } |
| 4041 | XmlUtils.skipCurrentTag(parser); |
| 4042 | |
| 4043 | } else if (parser.getName().equals("path-permission")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4044 | TypedArray sa = res.obtainAttributes(parser, |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4045 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 4046 | |
| 4047 | PathPermission pa = null; |
| 4048 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4049 | String permission = sa.getNonConfigurationString( |
| 4050 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 4051 | String readPermission = sa.getNonConfigurationString( |
| 4052 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4053 | if (readPermission == null) { |
| 4054 | readPermission = permission; |
| 4055 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4056 | String writePermission = sa.getNonConfigurationString( |
| 4057 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4058 | if (writePermission == null) { |
| 4059 | writePermission = permission; |
| 4060 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4061 | |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4062 | boolean havePerm = false; |
| 4063 | if (readPermission != null) { |
| 4064 | readPermission = readPermission.intern(); |
| 4065 | havePerm = true; |
| 4066 | } |
| 4067 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 4068 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4069 | havePerm = true; |
| 4070 | } |
| 4071 | |
| 4072 | if (!havePerm) { |
| 4073 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4074 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4075 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4076 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4077 | XmlUtils.skipCurrentTag(parser); |
| 4078 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4079 | } else { |
| 4080 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 4081 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4082 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4083 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4084 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4085 | String path = sa.getNonConfigurationString( |
| 4086 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4087 | if (path != null) { |
| 4088 | pa = new PathPermission(path, |
| 4089 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 4090 | } |
| 4091 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4092 | path = sa.getNonConfigurationString( |
| 4093 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4094 | if (path != null) { |
| 4095 | pa = new PathPermission(path, |
| 4096 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 4097 | } |
| 4098 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4099 | path = sa.getNonConfigurationString( |
| 4100 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4101 | if (path != null) { |
| 4102 | pa = new PathPermission(path, |
| 4103 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 4104 | } |
| 4105 | |
| 4106 | sa.recycle(); |
| 4107 | |
| 4108 | if (pa != null) { |
| 4109 | if (outInfo.info.pathPermissions == null) { |
| 4110 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 4111 | outInfo.info.pathPermissions[0] = pa; |
| 4112 | } else { |
| 4113 | final int N = outInfo.info.pathPermissions.length; |
| 4114 | PathPermission[] newp = new PathPermission[N+1]; |
| 4115 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 4116 | newp[N] = pa; |
| 4117 | outInfo.info.pathPermissions = newp; |
| 4118 | } |
| 4119 | } else { |
| 4120 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4121 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4122 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4123 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 4124 | XmlUtils.skipCurrentTag(parser); |
| 4125 | continue; |
| 4126 | } |
| 4127 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 4128 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | } |
| 4130 | XmlUtils.skipCurrentTag(parser); |
| 4131 | |
| 4132 | } else { |
| 4133 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4134 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4135 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4136 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | XmlUtils.skipCurrentTag(parser); |
| 4138 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4139 | } else { |
| 4140 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 4141 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | } |
| 4144 | } |
| 4145 | return true; |
| 4146 | } |
| 4147 | |
| 4148 | private Service parseService(Package owner, Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4149 | XmlResourceParser parser, int flags, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | throws XmlPullParserException, IOException { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4151 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | com.android.internal.R.styleable.AndroidManifestService); |
| 4153 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4154 | if (mParseServiceArgs == null) { |
| 4155 | mParseServiceArgs = new ParseComponentArgs(owner, outError, |
| 4156 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 4157 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 4158 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4159 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4160 | com.android.internal.R.styleable.AndroidManifestService_banner, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4161 | mSeparateProcesses, |
| 4162 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 4163 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4164 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
| 4165 | mParseServiceArgs.tag = "<service>"; |
| 4166 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4167 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4168 | mParseServiceArgs.sa = sa; |
| 4169 | mParseServiceArgs.flags = flags; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4170 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4171 | Service s = new Service(mParseServiceArgs, new ServiceInfo()); |
| 4172 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | sa.recycle(); |
| 4174 | return null; |
| 4175 | } |
| 4176 | |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4177 | boolean setExported = sa.hasValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 4179 | if (setExported) { |
| 4180 | s.info.exported = sa.getBoolean( |
| 4181 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 4182 | } |
| 4183 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4184 | String str = sa.getNonConfigurationString( |
| 4185 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | if (str == null) { |
| 4187 | s.info.permission = owner.applicationInfo.permission; |
| 4188 | } else { |
| 4189 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 4190 | } |
| 4191 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4192 | s.info.flags = 0; |
| 4193 | if (sa.getBoolean( |
| 4194 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 4195 | false)) { |
| 4196 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 4197 | } |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4198 | if (sa.getBoolean( |
| 4199 | com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, |
| 4200 | false)) { |
| 4201 | s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS; |
| 4202 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4203 | if (sa.getBoolean( |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 4204 | com.android.internal.R.styleable.AndroidManifestService_externalService, |
| 4205 | false)) { |
| 4206 | s.info.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE; |
| 4207 | } |
| 4208 | if (sa.getBoolean( |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4209 | com.android.internal.R.styleable.AndroidManifestService_singleUser, |
| 4210 | false)) { |
| 4211 | s.info.flags |= ServiceInfo.FLAG_SINGLE_USER; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 4212 | if (s.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) { |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4213 | Slog.w(TAG, "Service exported request ignored due to singleUser: " |
| 4214 | + s.className + " at " + mArchiveSourcePath + " " |
| 4215 | + parser.getPositionDescription()); |
| 4216 | s.info.exported = false; |
Amith Yamasani | 4b9d79c | 2014-05-21 19:14:21 -0700 | [diff] [blame] | 4217 | setExported = true; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4218 | } |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 4219 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4220 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4221 | s.info.encryptionAware = s.info.directBootAware = sa.getBoolean( |
| 4222 | R.styleable.AndroidManifestService_directBootAware, |
| 4223 | owner.applicationInfo.isDirectBootAware()); |
| 4224 | if (s.info.directBootAware) { |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4225 | owner.applicationInfo.privateFlags |= |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 4226 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4227 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | sa.recycle(); |
| 4230 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4231 | if ((owner.applicationInfo.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) |
| 4232 | != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 4233 | // A heavy-weight application can not have services in its main process |
| 4234 | // We can do direct compare because we intern all strings. |
| 4235 | if (s.info.processName == owner.packageName) { |
| 4236 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 4237 | return null; |
| 4238 | } |
| 4239 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | int outerDepth = parser.getDepth(); |
| 4242 | int type; |
| 4243 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4244 | && (type != XmlPullParser.END_TAG |
| 4245 | || parser.getDepth() > outerDepth)) { |
| 4246 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4247 | continue; |
| 4248 | } |
| 4249 | |
| 4250 | if (parser.getName().equals("intent-filter")) { |
| 4251 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4252 | if (!parseIntent(res, parser, true, false, intent, outError)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | return null; |
| 4254 | } |
| 4255 | |
| 4256 | s.intents.add(intent); |
| 4257 | } else if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4258 | if ((s.metaData=parseMetaData(res, parser, s.metaData, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | outError)) == null) { |
| 4260 | return null; |
| 4261 | } |
| 4262 | } else { |
| 4263 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4264 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4265 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4266 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | XmlUtils.skipCurrentTag(parser); |
| 4268 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4269 | } else { |
| 4270 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 4271 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | if (!setExported) { |
| 4277 | s.info.exported = s.intents.size() > 0; |
| 4278 | } |
| 4279 | |
| 4280 | return s; |
| 4281 | } |
| 4282 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4283 | private boolean parseAllMetaData(Resources res, XmlResourceParser parser, String tag, |
| 4284 | Component<?> outInfo, String[] outError) throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | int outerDepth = parser.getDepth(); |
| 4286 | int type; |
| 4287 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 4288 | && (type != XmlPullParser.END_TAG |
| 4289 | || parser.getDepth() > outerDepth)) { |
| 4290 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4291 | continue; |
| 4292 | } |
| 4293 | |
| 4294 | if (parser.getName().equals("meta-data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4295 | if ((outInfo.metaData=parseMetaData(res, parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | outInfo.metaData, outError)) == null) { |
| 4297 | return false; |
| 4298 | } |
| 4299 | } else { |
| 4300 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4301 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4302 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4303 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | XmlUtils.skipCurrentTag(parser); |
| 4305 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4306 | } else { |
| 4307 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 4308 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | return true; |
| 4313 | } |
| 4314 | |
| 4315 | private Bundle parseMetaData(Resources res, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4316 | XmlResourceParser parser, Bundle data, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | throws XmlPullParserException, IOException { |
| 4318 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4319 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 4321 | |
| 4322 | if (data == null) { |
| 4323 | data = new Bundle(); |
| 4324 | } |
| 4325 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4326 | String name = sa.getNonConfigurationString( |
| 4327 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | if (name == null) { |
| 4329 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 4330 | sa.recycle(); |
| 4331 | return null; |
| 4332 | } |
| 4333 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4334 | name = name.intern(); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4336 | TypedValue v = sa.peekValue( |
| 4337 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 4338 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4339 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | data.putInt(name, v.resourceId); |
| 4341 | } else { |
| 4342 | v = sa.peekValue( |
| 4343 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4344 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | if (v != null) { |
| 4346 | if (v.type == TypedValue.TYPE_STRING) { |
| 4347 | CharSequence cs = v.coerceToString(); |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4348 | data.putString(name, cs != null ? cs.toString().intern() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 4350 | data.putBoolean(name, v.data != 0); |
| 4351 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 4352 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 4353 | data.putInt(name, v.data); |
| 4354 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 4355 | data.putFloat(name, v.getFloat()); |
| 4356 | } else { |
| 4357 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4358 | 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] | 4359 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4360 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | } else { |
| 4362 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 4363 | data = null; |
| 4364 | } |
| 4365 | } |
| 4366 | } else { |
| 4367 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 4368 | data = null; |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | sa.recycle(); |
| 4373 | |
| 4374 | XmlUtils.skipCurrentTag(parser); |
| 4375 | |
| 4376 | return data; |
| 4377 | } |
| 4378 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4379 | private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser, |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4380 | AttributeSet attrs, int flags) { |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4381 | final TypedArray sa = res.obtainAttributes(attrs, |
| 4382 | com.android.internal.R.styleable.AndroidManifestPackageVerifier); |
| 4383 | |
| 4384 | final String packageName = sa.getNonResourceString( |
| 4385 | com.android.internal.R.styleable.AndroidManifestPackageVerifier_name); |
| 4386 | |
| 4387 | final String encodedPublicKey = sa.getNonResourceString( |
| 4388 | com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey); |
| 4389 | |
| 4390 | sa.recycle(); |
| 4391 | |
| 4392 | if (packageName == null || packageName.length() == 0) { |
| 4393 | Slog.i(TAG, "verifier package name was null; skipping"); |
| 4394 | return null; |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4397 | final PublicKey publicKey = parsePublicKey(encodedPublicKey); |
| 4398 | if (publicKey == null) { |
| 4399 | Slog.i(TAG, "Unable to parse verifier public key for " + packageName); |
| 4400 | return null; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4401 | } |
| 4402 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4403 | return new VerifierInfo(packageName, publicKey); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4404 | } |
| 4405 | |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4406 | public static final PublicKey parsePublicKey(final String encodedPublicKey) { |
| 4407 | if (encodedPublicKey == null) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4408 | Slog.w(TAG, "Could not parse null public key"); |
Christopher Tate | 3014733 | 2014-04-15 12:57:47 -0700 | [diff] [blame] | 4409 | return null; |
| 4410 | } |
| 4411 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4412 | EncodedKeySpec keySpec; |
| 4413 | try { |
| 4414 | final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT); |
| 4415 | keySpec = new X509EncodedKeySpec(encoded); |
| 4416 | } catch (IllegalArgumentException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4417 | Slog.w(TAG, "Could not parse verifier public key; invalid Base64"); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4418 | return null; |
| 4419 | } |
| 4420 | |
| 4421 | /* First try the key as an RSA key. */ |
| 4422 | try { |
| 4423 | final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4424 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4425 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4426 | 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] | 4427 | } catch (InvalidKeySpecException e) { |
| 4428 | // Not a RSA public key. |
| 4429 | } |
| 4430 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4431 | /* Now try it as a ECDSA key. */ |
| 4432 | try { |
| 4433 | final KeyFactory keyFactory = KeyFactory.getInstance("EC"); |
| 4434 | return keyFactory.generatePublic(keySpec); |
| 4435 | } catch (NoSuchAlgorithmException e) { |
| 4436 | Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build"); |
| 4437 | } catch (InvalidKeySpecException e) { |
| 4438 | // Not a ECDSA public key. |
| 4439 | } |
| 4440 | |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4441 | /* Now try it as a DSA key. */ |
| 4442 | try { |
| 4443 | final KeyFactory keyFactory = KeyFactory.getInstance("DSA"); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4444 | return keyFactory.generatePublic(keySpec); |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4445 | } catch (NoSuchAlgorithmException e) { |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4446 | 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] | 4447 | } catch (InvalidKeySpecException e) { |
| 4448 | // Not a DSA public key. |
| 4449 | } |
| 4450 | |
dcashman | 1616f30 | 2015-05-29 14:47:23 -0700 | [diff] [blame] | 4451 | /* Not a supported key type */ |
Kenny Root | 05ca4c9 | 2011-09-15 10:36:25 -0700 | [diff] [blame] | 4452 | return null; |
| 4453 | } |
| 4454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | private static final String ANDROID_RESOURCES |
| 4456 | = "http://schemas.android.com/apk/res/android"; |
| 4457 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4458 | private boolean parseIntent(Resources res, XmlResourceParser parser, |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 4459 | boolean allowGlobs, boolean allowAutoVerify, IntentInfo outInfo, String[] outError) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | throws XmlPullParserException, IOException { |
| 4461 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4462 | TypedArray sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 4464 | |
| 4465 | int priority = sa.getInt( |
| 4466 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 4468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | TypedValue v = sa.peekValue( |
| 4470 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 4471 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 4472 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 4473 | } |
| 4474 | |
| 4475 | outInfo.icon = sa.getResourceId( |
| 4476 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4477 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 4478 | outInfo.logo = sa.getResourceId( |
| 4479 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 4481 | outInfo.banner = sa.getResourceId( |
| 4482 | com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0); |
| 4483 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 4484 | if (allowAutoVerify) { |
| 4485 | outInfo.setAutoVerify(sa.getBoolean( |
| 4486 | com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, |
| 4487 | false)); |
| 4488 | } |
| 4489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | sa.recycle(); |
| 4491 | |
| 4492 | int outerDepth = parser.getDepth(); |
| 4493 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4494 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4495 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4496 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | continue; |
| 4498 | } |
| 4499 | |
| 4500 | String nodeName = parser.getName(); |
| 4501 | if (nodeName.equals("action")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4502 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | ANDROID_RESOURCES, "name"); |
| 4504 | if (value == null || value == "") { |
| 4505 | outError[0] = "No value supplied for <android:name>"; |
| 4506 | return false; |
| 4507 | } |
| 4508 | XmlUtils.skipCurrentTag(parser); |
| 4509 | |
| 4510 | outInfo.addAction(value); |
| 4511 | } else if (nodeName.equals("category")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4512 | String value = parser.getAttributeValue( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | ANDROID_RESOURCES, "name"); |
| 4514 | if (value == null || value == "") { |
| 4515 | outError[0] = "No value supplied for <android:name>"; |
| 4516 | return false; |
| 4517 | } |
| 4518 | XmlUtils.skipCurrentTag(parser); |
| 4519 | |
| 4520 | outInfo.addCategory(value); |
| 4521 | |
| 4522 | } else if (nodeName.equals("data")) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4523 | sa = res.obtainAttributes(parser, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | com.android.internal.R.styleable.AndroidManifestData); |
| 4525 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4526 | String str = sa.getNonConfigurationString( |
| 4527 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | if (str != null) { |
| 4529 | try { |
| 4530 | outInfo.addDataType(str); |
| 4531 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 4532 | outError[0] = e.toString(); |
| 4533 | sa.recycle(); |
| 4534 | return false; |
| 4535 | } |
| 4536 | } |
| 4537 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4538 | str = sa.getNonConfigurationString( |
| 4539 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | if (str != null) { |
| 4541 | outInfo.addDataScheme(str); |
| 4542 | } |
| 4543 | |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 4544 | str = sa.getNonConfigurationString( |
| 4545 | com.android.internal.R.styleable.AndroidManifestData_ssp, 0); |
| 4546 | if (str != null) { |
| 4547 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL); |
| 4548 | } |
| 4549 | |
| 4550 | str = sa.getNonConfigurationString( |
| 4551 | com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0); |
| 4552 | if (str != null) { |
| 4553 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX); |
| 4554 | } |
| 4555 | |
| 4556 | str = sa.getNonConfigurationString( |
| 4557 | com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0); |
| 4558 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4559 | if (!allowGlobs) { |
| 4560 | outError[0] = "sspPattern not allowed here; ssp must be literal"; |
| 4561 | return false; |
| 4562 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 4563 | outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4564 | } |
| 4565 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4566 | String host = sa.getNonConfigurationString( |
| 4567 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 4568 | String port = sa.getNonConfigurationString( |
| 4569 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | if (host != null) { |
| 4571 | outInfo.addDataAuthority(host, port); |
| 4572 | } |
| 4573 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4574 | str = sa.getNonConfigurationString( |
| 4575 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4576 | if (str != null) { |
| 4577 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 4578 | } |
| 4579 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4580 | str = sa.getNonConfigurationString( |
| 4581 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | if (str != null) { |
| 4583 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 4584 | } |
| 4585 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 4586 | str = sa.getNonConfigurationString( |
| 4587 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | if (str != null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4589 | if (!allowGlobs) { |
| 4590 | outError[0] = "pathPattern not allowed here; path must be literal"; |
| 4591 | return false; |
| 4592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 4594 | } |
| 4595 | |
| 4596 | sa.recycle(); |
| 4597 | XmlUtils.skipCurrentTag(parser); |
| 4598 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4599 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 4600 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 4601 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | XmlUtils.skipCurrentTag(parser); |
| 4603 | } else { |
| 4604 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 4605 | return false; |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4610 | |
| 4611 | if (DEBUG_PARSER) { |
| 4612 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 4613 | cats.append(outInfo.hasDefault); |
| 4614 | cats.append(", cat="); |
| 4615 | |
| 4616 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 4617 | if (it != null) { |
| 4618 | while (it.hasNext()) { |
| 4619 | cats.append(' '); |
| 4620 | cats.append(it.next()); |
| 4621 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 4623 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | return true; |
| 4627 | } |
| 4628 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4629 | /** |
| 4630 | * Representation of a full package parsed from APK files on disk. A package |
| 4631 | * consists of a single base APK, and zero or more split APKs. |
| 4632 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | public final static class Package { |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 4634 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4635 | public String packageName; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4636 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4637 | /** Names of any split APKs, ordered by parsed splitName */ |
| 4638 | public String[] splitNames; |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4639 | |
| 4640 | // TODO: work towards making these paths invariant |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4641 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 4642 | public String volumeUuid; |
| 4643 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4644 | /** |
| 4645 | * Path where this package was found on disk. For monolithic packages |
| 4646 | * this is path to single base APK file; for cluster packages this is |
| 4647 | * path to the cluster directory. |
| 4648 | */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4649 | public String codePath; |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4650 | |
| 4651 | /** Path of base APK */ |
| 4652 | public String baseCodePath; |
| 4653 | /** Paths of any split APKs, ordered by parsed splitName */ |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4654 | public String[] splitCodePaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4656 | /** Revision code of base APK */ |
| 4657 | public int baseRevisionCode; |
| 4658 | /** Revision codes of any split APKs, ordered by parsed splitName */ |
| 4659 | public int[] splitRevisionCodes; |
| 4660 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4661 | /** Flags of any split APKs; ordered by parsed splitName */ |
| 4662 | public int[] splitFlags; |
| 4663 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4664 | /** |
| 4665 | * Private flags of any split APKs; ordered by parsed splitName. |
| 4666 | * |
| 4667 | * {@hide} |
| 4668 | */ |
| 4669 | public int[] splitPrivateFlags; |
| 4670 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4671 | public boolean baseHardwareAccelerated; |
| 4672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4673 | // For now we only support one application per package. |
| 4674 | public final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 4675 | |
| 4676 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 4677 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 4678 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 4679 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 4680 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 4681 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 4682 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 4683 | |
| 4684 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 4685 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 4686 | public ArrayList<String> protectedBroadcasts; |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4687 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4688 | public Package parentPackage; |
| 4689 | public ArrayList<Package> childPackages; |
| 4690 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4691 | public ArrayList<String> libraryNames = null; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4692 | public ArrayList<String> usesLibraries = null; |
| 4693 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | public String[] usesLibraryFiles = null; |
| 4695 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 4696 | public ArrayList<ActivityIntentInfo> preferredActivityFilters = null; |
| 4697 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 4698 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4699 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 4700 | public ArrayList<String> mAdoptPermissions = null; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | // We store the application meta-data independently to avoid multiple unwanted references |
| 4703 | public Bundle mAppMetaData = null; |
| 4704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | // The version code declared for this package. |
| 4706 | public int mVersionCode; |
Jeff Sharkey | 88d2a3c | 2014-11-22 16:49:34 -0800 | [diff] [blame] | 4707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4708 | // The version name declared for this package. |
| 4709 | public String mVersionName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | // The shared user id that this package wants to use. |
| 4712 | public String mSharedUserId; |
| 4713 | |
| 4714 | // The shared user label that this package wants to use. |
| 4715 | public int mSharedUserLabel; |
| 4716 | |
| 4717 | // Signatures that were read from the package. |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4718 | public Signature[] mSignatures; |
| 4719 | public Certificate[][] mCertificates; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | |
| 4721 | // For use by package manager service for quick lookup of |
| 4722 | // preferred up order. |
| 4723 | public int mPreferredOrder = 0; |
| 4724 | |
Brian Carlstrom | ff1ec4d | 2014-03-17 15:21:35 -0700 | [diff] [blame] | 4725 | // For use by package manager to keep track of when a package was last used. |
| 4726 | public long mLastPackageUsageTimeInMills; |
| 4727 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4728 | // // User set enabled state. |
| 4729 | // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 4730 | // |
| 4731 | // // Whether the package has been stopped. |
| 4732 | // public boolean mSetStopped = false; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 4733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | // Additional data supplied by callers. |
| 4735 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 4736 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4737 | // Applications hardware preferences |
| 4738 | public ArrayList<ConfigurationInfo> configPreferences = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4740 | // Applications requested features |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 4741 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 4742 | |
Adam Lesinski | d3edfde | 2014-08-08 17:32:44 -0700 | [diff] [blame] | 4743 | // Applications requested feature groups |
| 4744 | public ArrayList<FeatureGroupInfo> featureGroups = null; |
| 4745 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 4746 | public int installLocation; |
| 4747 | |
Jeff Hao | 272bf3a | 2014-10-08 13:34:43 -0700 | [diff] [blame] | 4748 | public boolean coreApp; |
| 4749 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 4750 | /* An app that's required for all users and cannot be uninstalled for a user */ |
| 4751 | public boolean mRequiredForAllUsers; |
| 4752 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame] | 4753 | /* The restricted account authenticator type that is used by this application */ |
| 4754 | public String mRestrictedAccountType; |
| 4755 | |
Amith Yamasani | ccbe389 | 2013-04-12 17:52:42 -0700 | [diff] [blame] | 4756 | /* The required account type without which this application will not function */ |
| 4757 | public String mRequiredAccountType; |
| 4758 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 4759 | public String mOverlayTarget; |
| 4760 | public int mOverlayPriority; |
| 4761 | public boolean mTrustedOverlay; |
| 4762 | |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4763 | /** |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 4764 | * Data used to feed the KeySetManagerService |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4765 | */ |
dcashman | 989eb371 | 2014-06-17 12:56:12 -0700 | [diff] [blame] | 4766 | public ArraySet<PublicKey> mSigningKeys; |
| 4767 | public ArraySet<String> mUpgradeKeySets; |
| 4768 | public ArrayMap<String, ArraySet<PublicKey>> mKeySetMapping; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 4769 | |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 4770 | /** |
| 4771 | * The install time abi override for this package, if any. |
| 4772 | * |
| 4773 | * TODO: This seems like a horrible place to put the abiOverride because |
| 4774 | * this isn't something the packageParser parsers. However, this fits in with |
| 4775 | * the rest of the PackageManager where package scanning randomly pushes |
| 4776 | * and prods fields out of {@code this.applicationInfo}. |
| 4777 | */ |
| 4778 | public String cpuAbiOverride; |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4779 | /** |
| 4780 | * The install time abi override to choose 32bit abi's when multiple abi's |
| 4781 | * are present. This is only meaningfull for multiarch applications. |
| 4782 | * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. |
| 4783 | */ |
| 4784 | public boolean use32bitAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 4785 | |
Jeff Sharkey | c4858a2 | 2014-06-16 10:51:20 -0700 | [diff] [blame] | 4786 | public Package(String packageName) { |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 4787 | this.packageName = packageName; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 4788 | applicationInfo.packageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | applicationInfo.uid = -1; |
| 4790 | } |
| 4791 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4792 | public void setApplicationVolumeUuid(String volumeUuid) { |
| 4793 | this.applicationInfo.volumeUuid = volumeUuid; |
| 4794 | if (childPackages != null) { |
| 4795 | final int packageCount = childPackages.size(); |
| 4796 | for (int i = 0; i < packageCount; i++) { |
| 4797 | childPackages.get(i).applicationInfo.volumeUuid = volumeUuid; |
| 4798 | } |
| 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | public void setApplicationInfoCodePath(String codePath) { |
| 4803 | this.applicationInfo.setCodePath(codePath); |
| 4804 | if (childPackages != null) { |
| 4805 | final int packageCount = childPackages.size(); |
| 4806 | for (int i = 0; i < packageCount; i++) { |
| 4807 | childPackages.get(i).applicationInfo.setCodePath(codePath); |
| 4808 | } |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | public void setApplicationInfoResourcePath(String resourcePath) { |
| 4813 | this.applicationInfo.setResourcePath(resourcePath); |
| 4814 | if (childPackages != null) { |
| 4815 | final int packageCount = childPackages.size(); |
| 4816 | for (int i = 0; i < packageCount; i++) { |
| 4817 | childPackages.get(i).applicationInfo.setResourcePath(resourcePath); |
| 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | public void setApplicationInfoBaseResourcePath(String resourcePath) { |
| 4823 | this.applicationInfo.setBaseResourcePath(resourcePath); |
| 4824 | if (childPackages != null) { |
| 4825 | final int packageCount = childPackages.size(); |
| 4826 | for (int i = 0; i < packageCount; i++) { |
| 4827 | childPackages.get(i).applicationInfo.setBaseResourcePath(resourcePath); |
| 4828 | } |
| 4829 | } |
| 4830 | } |
| 4831 | |
| 4832 | public void setApplicationInfoBaseCodePath(String baseCodePath) { |
| 4833 | this.applicationInfo.setBaseCodePath(baseCodePath); |
| 4834 | if (childPackages != null) { |
| 4835 | final int packageCount = childPackages.size(); |
| 4836 | for (int i = 0; i < packageCount; i++) { |
| 4837 | childPackages.get(i).applicationInfo.setBaseCodePath(baseCodePath); |
| 4838 | } |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | public boolean hasChildPackage(String packageName) { |
| 4843 | final int childCount = (childPackages != null) ? childPackages.size() : 0; |
| 4844 | for (int i = 0; i < childCount; i++) { |
| 4845 | if (childPackages.get(i).packageName.equals(packageName)) { |
| 4846 | return true; |
| 4847 | } |
| 4848 | } |
| 4849 | return false; |
| 4850 | } |
| 4851 | |
| 4852 | public void setApplicationInfoSplitCodePaths(String[] splitCodePaths) { |
| 4853 | this.applicationInfo.setSplitCodePaths(splitCodePaths); |
| 4854 | // Children have no splits |
| 4855 | } |
| 4856 | |
| 4857 | public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) { |
| 4858 | this.applicationInfo.setSplitResourcePaths(resroucePaths); |
| 4859 | // Children have no splits |
| 4860 | } |
| 4861 | |
| 4862 | public void setSplitCodePaths(String[] codePaths) { |
| 4863 | this.splitCodePaths = codePaths; |
| 4864 | } |
| 4865 | |
| 4866 | public void setCodePath(String codePath) { |
| 4867 | this.codePath = codePath; |
| 4868 | if (childPackages != null) { |
| 4869 | final int packageCount = childPackages.size(); |
| 4870 | for (int i = 0; i < packageCount; i++) { |
| 4871 | childPackages.get(i).codePath = codePath; |
| 4872 | } |
| 4873 | } |
| 4874 | } |
| 4875 | |
| 4876 | public void setBaseCodePath(String baseCodePath) { |
| 4877 | this.baseCodePath = baseCodePath; |
| 4878 | if (childPackages != null) { |
| 4879 | final int packageCount = childPackages.size(); |
| 4880 | for (int i = 0; i < packageCount; i++) { |
| 4881 | childPackages.get(i).baseCodePath = baseCodePath; |
| 4882 | } |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | public void setSignatures(Signature[] signatures) { |
| 4887 | this.mSignatures = signatures; |
| 4888 | if (childPackages != null) { |
| 4889 | final int packageCount = childPackages.size(); |
| 4890 | for (int i = 0; i < packageCount; i++) { |
| 4891 | childPackages.get(i).mSignatures = signatures; |
| 4892 | } |
| 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | public void setVolumeUuid(String volumeUuid) { |
| 4897 | this.volumeUuid = volumeUuid; |
| 4898 | if (childPackages != null) { |
| 4899 | final int packageCount = childPackages.size(); |
| 4900 | for (int i = 0; i < packageCount; i++) { |
| 4901 | childPackages.get(i).volumeUuid = volumeUuid; |
| 4902 | } |
| 4903 | } |
| 4904 | } |
| 4905 | |
| 4906 | public void setApplicationInfoFlags(int mask, int flags) { |
| 4907 | applicationInfo.flags = (applicationInfo.flags & ~mask) | (mask & flags); |
| 4908 | if (childPackages != null) { |
| 4909 | final int packageCount = childPackages.size(); |
| 4910 | for (int i = 0; i < packageCount; i++) { |
| 4911 | childPackages.get(i).applicationInfo.flags = |
| 4912 | (applicationInfo.flags & ~mask) | (mask & flags); |
| 4913 | } |
| 4914 | } |
| 4915 | } |
| 4916 | |
Selim Gurun | 75827b2 | 2016-02-09 10:55:33 -0800 | [diff] [blame] | 4917 | public void setUse32bitAbi(boolean use32bitAbi) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4918 | this.use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4919 | if (childPackages != null) { |
| 4920 | final int packageCount = childPackages.size(); |
| 4921 | for (int i = 0; i < packageCount; i++) { |
Selim Gurun | 2d291d8 | 2016-02-05 17:50:53 -0800 | [diff] [blame] | 4922 | childPackages.get(i).use32bitAbi = use32bitAbi; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4927 | public List<String> getAllCodePaths() { |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4928 | ArrayList<String> paths = new ArrayList<>(); |
Jeff Sharkey | 57dcf5b | 2014-06-18 17:46:05 -0700 | [diff] [blame] | 4929 | paths.add(baseCodePath); |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 4930 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 4931 | Collections.addAll(paths, splitCodePaths); |
| 4932 | } |
| 4933 | return paths; |
| 4934 | } |
| 4935 | |
Jeff Sharkey | da96e13 | 2014-07-15 14:54:09 -0700 | [diff] [blame] | 4936 | /** |
| 4937 | * Filtered set of {@link #getAllCodePaths()} that excludes |
| 4938 | * resource-only APKs. |
| 4939 | */ |
| 4940 | public List<String> getAllCodePathsExcludingResourceOnly() { |
| 4941 | ArrayList<String> paths = new ArrayList<>(); |
| 4942 | if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 4943 | paths.add(baseCodePath); |
| 4944 | } |
| 4945 | if (!ArrayUtils.isEmpty(splitCodePaths)) { |
| 4946 | for (int i = 0; i < splitCodePaths.length; i++) { |
| 4947 | if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 4948 | paths.add(splitCodePaths[i]); |
| 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | return paths; |
| 4953 | } |
| 4954 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4955 | public void setPackageName(String newName) { |
| 4956 | packageName = newName; |
| 4957 | applicationInfo.packageName = newName; |
| 4958 | for (int i=permissions.size()-1; i>=0; i--) { |
| 4959 | permissions.get(i).setPackageName(newName); |
| 4960 | } |
| 4961 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 4962 | permissionGroups.get(i).setPackageName(newName); |
| 4963 | } |
| 4964 | for (int i=activities.size()-1; i>=0; i--) { |
| 4965 | activities.get(i).setPackageName(newName); |
| 4966 | } |
| 4967 | for (int i=receivers.size()-1; i>=0; i--) { |
| 4968 | receivers.get(i).setPackageName(newName); |
| 4969 | } |
| 4970 | for (int i=providers.size()-1; i>=0; i--) { |
| 4971 | providers.get(i).setPackageName(newName); |
| 4972 | } |
| 4973 | for (int i=services.size()-1; i>=0; i--) { |
| 4974 | services.get(i).setPackageName(newName); |
| 4975 | } |
| 4976 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 4977 | instrumentation.get(i).setPackageName(newName); |
| 4978 | } |
| 4979 | } |
Dianne Hackborn | 6569625 | 2012-03-05 18:49:21 -0800 | [diff] [blame] | 4980 | |
| 4981 | public boolean hasComponentClassName(String name) { |
| 4982 | for (int i=activities.size()-1; i>=0; i--) { |
| 4983 | if (name.equals(activities.get(i).className)) { |
| 4984 | return true; |
| 4985 | } |
| 4986 | } |
| 4987 | for (int i=receivers.size()-1; i>=0; i--) { |
| 4988 | if (name.equals(receivers.get(i).className)) { |
| 4989 | return true; |
| 4990 | } |
| 4991 | } |
| 4992 | for (int i=providers.size()-1; i>=0; i--) { |
| 4993 | if (name.equals(providers.get(i).className)) { |
| 4994 | return true; |
| 4995 | } |
| 4996 | } |
| 4997 | for (int i=services.size()-1; i>=0; i--) { |
| 4998 | if (name.equals(services.get(i).className)) { |
| 4999 | return true; |
| 5000 | } |
| 5001 | } |
| 5002 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 5003 | if (name.equals(instrumentation.get(i).className)) { |
| 5004 | return true; |
| 5005 | } |
| 5006 | } |
| 5007 | return false; |
| 5008 | } |
| 5009 | |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 5010 | /** |
| 5011 | * @hide |
| 5012 | */ |
| 5013 | public boolean isForwardLocked() { |
| 5014 | return applicationInfo.isForwardLocked(); |
| 5015 | } |
| 5016 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 5017 | /** |
| 5018 | * @hide |
| 5019 | */ |
| 5020 | public boolean isSystemApp() { |
| 5021 | return applicationInfo.isSystemApp(); |
| 5022 | } |
| 5023 | |
| 5024 | /** |
| 5025 | * @hide |
| 5026 | */ |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5027 | public boolean isPrivilegedApp() { |
| 5028 | return applicationInfo.isPrivilegedApp(); |
| 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * @hide |
| 5033 | */ |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 5034 | public boolean isUpdatedSystemApp() { |
| 5035 | return applicationInfo.isUpdatedSystemApp(); |
| 5036 | } |
| 5037 | |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 5038 | /** |
| 5039 | * @hide |
| 5040 | */ |
| 5041 | public boolean canHaveOatDir() { |
| 5042 | // The following app types CANNOT have oat directory |
| 5043 | // - non-updated system apps |
| 5044 | // - forward-locked apps or apps installed in ASEC containers |
| 5045 | return (!isSystemApp() || isUpdatedSystemApp()) |
| 5046 | && !isForwardLocked() && !applicationInfo.isExternalAsec(); |
| 5047 | } |
| 5048 | |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 5049 | public boolean isMatch(int flags) { |
| 5050 | if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { |
| 5051 | return isSystemApp(); |
| 5052 | } |
| 5053 | return true; |
| 5054 | } |
| 5055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5056 | public String toString() { |
| 5057 | return "Package{" |
| 5058 | + Integer.toHexString(System.identityHashCode(this)) |
| 5059 | + " " + packageName + "}"; |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | public static class Component<II extends IntentInfo> { |
| 5064 | public final Package owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5065 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5066 | public final String className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5067 | public Bundle metaData; |
| 5068 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5069 | ComponentName componentName; |
| 5070 | String componentShortName; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5072 | public Component(Package _owner) { |
| 5073 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5074 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5075 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 5079 | owner = args.owner; |
| 5080 | intents = new ArrayList<II>(0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 5081 | String name = args.sa.getNonConfigurationString(args.nameRes, 0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5082 | if (name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5083 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5084 | args.outError[0] = args.tag + " does not specify android:name"; |
| 5085 | return; |
| 5086 | } |
| 5087 | |
| 5088 | outInfo.name |
| 5089 | = buildClassName(owner.applicationInfo.packageName, name, args.outError); |
| 5090 | if (outInfo.name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5091 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5092 | args.outError[0] = args.tag + " does not have valid android:name"; |
| 5093 | return; |
| 5094 | } |
| 5095 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5096 | className = outInfo.name; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5097 | |
| 5098 | int iconVal = args.sa.getResourceId(args.iconRes, 0); |
| 5099 | if (iconVal != 0) { |
| 5100 | outInfo.icon = iconVal; |
| 5101 | outInfo.nonLocalizedLabel = null; |
| 5102 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5103 | |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5104 | int logoVal = args.sa.getResourceId(args.logoRes, 0); |
| 5105 | if (logoVal != 0) { |
| 5106 | outInfo.logo = logoVal; |
| 5107 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5108 | |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5109 | int bannerVal = args.sa.getResourceId(args.bannerRes, 0); |
| 5110 | if (bannerVal != 0) { |
| 5111 | outInfo.banner = bannerVal; |
| 5112 | } |
| 5113 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5114 | TypedValue v = args.sa.peekValue(args.labelRes); |
| 5115 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 5116 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 5117 | } |
| 5118 | |
| 5119 | outInfo.packageName = owner.packageName; |
| 5120 | } |
| 5121 | |
| 5122 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 5123 | this(args, (PackageItemInfo)outInfo); |
| 5124 | if (args.outError[0] != null) { |
| 5125 | return; |
| 5126 | } |
| 5127 | |
| 5128 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5129 | CharSequence pname; |
| 5130 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
Dianne Hackborn | 1d0b177 | 2013-09-06 14:02:54 -0700 | [diff] [blame] | 5131 | pname = args.sa.getNonConfigurationString(args.processRes, |
| 5132 | Configuration.NATIVE_CONFIG_VERSION); |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5133 | } else { |
| 5134 | // Some older apps have been seen to use a resource reference |
| 5135 | // here that on older builds was ignored (with a warning). We |
| 5136 | // need to continue to do this for them so they don't break. |
| 5137 | pname = args.sa.getNonResourceString(args.processRes); |
| 5138 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5139 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 5140 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5141 | args.flags, args.sepProcesses, args.outError); |
| 5142 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5143 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 5144 | if (args.descriptionRes != 0) { |
| 5145 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 5146 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5147 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5148 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | public Component(Component<II> clone) { |
| 5152 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5153 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5154 | className = clone.className; |
| 5155 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5156 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5157 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5158 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5159 | public ComponentName getComponentName() { |
| 5160 | if (componentName != null) { |
| 5161 | return componentName; |
| 5162 | } |
| 5163 | if (className != null) { |
| 5164 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 5165 | className); |
| 5166 | } |
| 5167 | return componentName; |
| 5168 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5169 | |
| 5170 | public void appendComponentShortName(StringBuilder sb) { |
| 5171 | ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5172 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5173 | |
| 5174 | public void printComponentShortName(PrintWriter pw) { |
| 5175 | ComponentName.printShortString(pw, owner.applicationInfo.packageName, className); |
| 5176 | } |
| 5177 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5178 | public void setPackageName(String packageName) { |
| 5179 | componentName = null; |
| 5180 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5181 | } |
| 5182 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | public final static class Permission extends Component<IntentInfo> { |
| 5185 | public final PermissionInfo info; |
| 5186 | public boolean tree; |
| 5187 | public PermissionGroup group; |
| 5188 | |
| 5189 | public Permission(Package _owner) { |
| 5190 | super(_owner); |
| 5191 | info = new PermissionInfo(); |
| 5192 | } |
| 5193 | |
| 5194 | public Permission(Package _owner, PermissionInfo _info) { |
| 5195 | super(_owner); |
| 5196 | info = _info; |
| 5197 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5198 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5199 | public void setPackageName(String packageName) { |
| 5200 | super.setPackageName(packageName); |
| 5201 | info.packageName = packageName; |
| 5202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5203 | |
| 5204 | public String toString() { |
| 5205 | return "Permission{" |
| 5206 | + Integer.toHexString(System.identityHashCode(this)) |
| 5207 | + " " + info.name + "}"; |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | public final static class PermissionGroup extends Component<IntentInfo> { |
| 5212 | public final PermissionGroupInfo info; |
| 5213 | |
| 5214 | public PermissionGroup(Package _owner) { |
| 5215 | super(_owner); |
| 5216 | info = new PermissionGroupInfo(); |
| 5217 | } |
| 5218 | |
| 5219 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 5220 | super(_owner); |
| 5221 | info = _info; |
| 5222 | } |
| 5223 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5224 | public void setPackageName(String packageName) { |
| 5225 | super.setPackageName(packageName); |
| 5226 | info.packageName = packageName; |
| 5227 | } |
| 5228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | public String toString() { |
| 5230 | return "PermissionGroup{" |
| 5231 | + Integer.toHexString(System.identityHashCode(this)) |
| 5232 | + " " + info.name + "}"; |
| 5233 | } |
| 5234 | } |
| 5235 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5236 | private static boolean copyNeeded(int flags, Package p, |
| 5237 | PackageUserState state, Bundle metaData, int userId) { |
Xiaohui Chen | 98404fd | 2015-08-17 16:09:02 -0700 | [diff] [blame] | 5238 | if (userId != UserHandle.USER_SYSTEM) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5239 | // We always need to copy for other users, since we need |
| 5240 | // to fix up the uid. |
| 5241 | return true; |
| 5242 | } |
| 5243 | if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 5244 | boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 5245 | if (p.applicationInfo.enabled != enabled) { |
| 5246 | return true; |
| 5247 | } |
| 5248 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5249 | if (!state.installed || state.hidden) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5250 | return true; |
| 5251 | } |
| 5252 | if (state.stopped) { |
| 5253 | return true; |
| 5254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 5256 | && (metaData != null || p.mAppMetaData != null)) { |
| 5257 | return true; |
| 5258 | } |
| 5259 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 5260 | && p.usesLibraryFiles != null) { |
| 5261 | return true; |
| 5262 | } |
| 5263 | return false; |
| 5264 | } |
| 5265 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5266 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
| 5267 | PackageUserState state) { |
| 5268 | return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId()); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5271 | private static void updateApplicationInfo(ApplicationInfo ai, int flags, |
| 5272 | PackageUserState state) { |
| 5273 | // CompatibilityMode is global state. |
| 5274 | if (!sCompatibilityModeEnabled) { |
| 5275 | ai.disableCompatibilityMode(); |
| 5276 | } |
| 5277 | if (state.installed) { |
| 5278 | ai.flags |= ApplicationInfo.FLAG_INSTALLED; |
| 5279 | } else { |
| 5280 | ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; |
| 5281 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 5282 | if (state.suspended) { |
| 5283 | ai.flags |= ApplicationInfo.FLAG_SUSPENDED; |
| 5284 | } else { |
| 5285 | ai.flags &= ~ApplicationInfo.FLAG_SUSPENDED; |
| 5286 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5287 | if (state.hidden) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5288 | ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 5289 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 5290 | ai.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 5291 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5292 | if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 5293 | ai.enabled = true; |
| 5294 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 5295 | ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0; |
| 5296 | } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 5297 | || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
| 5298 | ai.enabled = false; |
| 5299 | } |
| 5300 | ai.enabledSetting = state.enabled; |
| 5301 | } |
| 5302 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 5303 | public static ApplicationInfo generateApplicationInfo(Package p, int flags, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5304 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5305 | if (p == null) return null; |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 5306 | if (!checkUseInstalledOrHidden(flags, state) || !p.isMatch(flags)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5307 | return null; |
| 5308 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5309 | if (!copyNeeded(flags, p, state, null, userId) |
| 5310 | && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 |
| 5311 | || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { |
| 5312 | // In this case it is safe to directly modify the internal ApplicationInfo state: |
| 5313 | // - CompatibilityMode is global state, so will be the same for every call. |
| 5314 | // - We only come in to here if the app should reported as installed; this is the |
| 5315 | // default state, and we will do a copy otherwise. |
| 5316 | // - The enable state will always be reported the same for the application across |
| 5317 | // calls; the only exception is for the UNTIL_USED mode, and in that case we will |
| 5318 | // be doing a copy. |
| 5319 | updateApplicationInfo(p.applicationInfo, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5320 | return p.applicationInfo; |
| 5321 | } |
| 5322 | |
| 5323 | // Make shallow copy so we can store the metadata/libraries safely |
| 5324 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5325 | ai.initForUser(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 5327 | ai.metaData = p.mAppMetaData; |
| 5328 | } |
| 5329 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 5330 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 5331 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5332 | if (state.stopped) { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 5333 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 5334 | } else { |
Amith Yamasani | a4a54e2 | 2012-04-16 15:44:19 -0700 | [diff] [blame] | 5335 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 5336 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 5337 | updateApplicationInfo(ai, flags, state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5338 | return ai; |
| 5339 | } |
| 5340 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5341 | public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, |
| 5342 | PackageUserState state, int userId) { |
| 5343 | if (ai == null) return null; |
| 5344 | if (!checkUseInstalledOrHidden(flags, state)) { |
| 5345 | return null; |
| 5346 | } |
| 5347 | // This is only used to return the ResolverActivity; we will just always |
| 5348 | // make a copy. |
| 5349 | ai = new ApplicationInfo(ai); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5350 | ai.initForUser(userId); |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5351 | if (state.stopped) { |
| 5352 | ai.flags |= ApplicationInfo.FLAG_STOPPED; |
| 5353 | } else { |
| 5354 | ai.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 5355 | } |
| 5356 | updateApplicationInfo(ai, flags, state); |
| 5357 | return ai; |
| 5358 | } |
| 5359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5360 | public static final PermissionInfo generatePermissionInfo( |
| 5361 | Permission p, int flags) { |
| 5362 | if (p == null) return null; |
| 5363 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5364 | return p.info; |
| 5365 | } |
| 5366 | PermissionInfo pi = new PermissionInfo(p.info); |
| 5367 | pi.metaData = p.metaData; |
| 5368 | return pi; |
| 5369 | } |
| 5370 | |
| 5371 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 5372 | PermissionGroup pg, int flags) { |
| 5373 | if (pg == null) return null; |
| 5374 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5375 | return pg.info; |
| 5376 | } |
| 5377 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 5378 | pgi.metaData = pg.metaData; |
| 5379 | return pgi; |
| 5380 | } |
| 5381 | |
| 5382 | public final static class Activity extends Component<ActivityIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5383 | public final ActivityInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5384 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5385 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 5386 | super(args, _info); |
| 5387 | info = _info; |
| 5388 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5390 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5391 | public void setPackageName(String packageName) { |
| 5392 | super.setPackageName(packageName); |
| 5393 | info.packageName = packageName; |
| 5394 | } |
| 5395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5397 | StringBuilder sb = new StringBuilder(128); |
| 5398 | sb.append("Activity{"); |
| 5399 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5400 | sb.append(' '); |
| 5401 | appendComponentShortName(sb); |
| 5402 | sb.append('}'); |
| 5403 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5404 | } |
| 5405 | } |
| 5406 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5407 | public static final ActivityInfo generateActivityInfo(Activity a, int flags, |
| 5408 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5409 | if (a == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5410 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5411 | return null; |
| 5412 | } |
| 5413 | if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | return a.info; |
| 5415 | } |
| 5416 | // Make shallow copies so we can store the metadata safely |
| 5417 | ActivityInfo ai = new ActivityInfo(a.info); |
| 5418 | ai.metaData = a.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5419 | ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | return ai; |
| 5421 | } |
| 5422 | |
Dianne Hackborn | ace2791 | 2014-09-18 18:38:30 -0700 | [diff] [blame] | 5423 | public static final ActivityInfo generateActivityInfo(ActivityInfo ai, int flags, |
| 5424 | PackageUserState state, int userId) { |
| 5425 | if (ai == null) return null; |
| 5426 | if (!checkUseInstalledOrHidden(flags, state)) { |
| 5427 | return null; |
| 5428 | } |
| 5429 | // This is only used to return the ResolverActivity; we will just always |
| 5430 | // make a copy. |
| 5431 | ai = new ActivityInfo(ai); |
| 5432 | ai.applicationInfo = generateApplicationInfo(ai.applicationInfo, flags, state, userId); |
| 5433 | return ai; |
| 5434 | } |
| 5435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5436 | public final static class Service extends Component<ServiceIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5437 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5439 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 5440 | super(args, _info); |
| 5441 | info = _info; |
| 5442 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5443 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5444 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5445 | public void setPackageName(String packageName) { |
| 5446 | super.setPackageName(packageName); |
| 5447 | info.packageName = packageName; |
| 5448 | } |
| 5449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5450 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5451 | StringBuilder sb = new StringBuilder(128); |
| 5452 | sb.append("Service{"); |
| 5453 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5454 | sb.append(' '); |
| 5455 | appendComponentShortName(sb); |
| 5456 | sb.append('}'); |
| 5457 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | } |
| 5459 | } |
| 5460 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5461 | public static final ServiceInfo generateServiceInfo(Service s, int flags, |
| 5462 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5463 | if (s == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5464 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5465 | return null; |
| 5466 | } |
| 5467 | if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | return s.info; |
| 5469 | } |
| 5470 | // Make shallow copies so we can store the metadata safely |
| 5471 | ServiceInfo si = new ServiceInfo(s.info); |
| 5472 | si.metaData = s.metaData; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5473 | si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5474 | return si; |
| 5475 | } |
| 5476 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5477 | public final static class Provider extends Component<ProviderIntentInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5478 | public final ProviderInfo info; |
| 5479 | public boolean syncable; |
| 5480 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5481 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 5482 | super(args, _info); |
| 5483 | info = _info; |
| 5484 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | syncable = false; |
| 5486 | } |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 5487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5488 | public Provider(Provider existingProvider) { |
| 5489 | super(existingProvider); |
| 5490 | this.info = existingProvider.info; |
| 5491 | this.syncable = existingProvider.syncable; |
| 5492 | } |
| 5493 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5494 | public void setPackageName(String packageName) { |
| 5495 | super.setPackageName(packageName); |
| 5496 | info.packageName = packageName; |
| 5497 | } |
| 5498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5500 | StringBuilder sb = new StringBuilder(128); |
| 5501 | sb.append("Provider{"); |
| 5502 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5503 | sb.append(' '); |
| 5504 | appendComponentShortName(sb); |
| 5505 | sb.append('}'); |
| 5506 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | } |
| 5508 | } |
| 5509 | |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5510 | public static final ProviderInfo generateProviderInfo(Provider p, int flags, |
| 5511 | PackageUserState state, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5512 | if (p == null) return null; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 5513 | if (!checkUseInstalledOrHidden(flags, state)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5514 | return null; |
| 5515 | } |
| 5516 | if (!copyNeeded(flags, p.owner, state, p.metaData, userId) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5517 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5518 | || p.info.uriPermissionPatterns == null)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5519 | return p.info; |
| 5520 | } |
| 5521 | // Make shallow copies so we can store the metadata safely |
| 5522 | ProviderInfo pi = new ProviderInfo(p.info); |
| 5523 | pi.metaData = p.metaData; |
| 5524 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 5525 | pi.uriPermissionPatterns = null; |
| 5526 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 5527 | pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5528 | return pi; |
| 5529 | } |
| 5530 | |
| 5531 | public final static class Instrumentation extends Component { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5532 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5533 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5534 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 5535 | super(args, _info); |
| 5536 | info = _info; |
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("Instrumentation{"); |
| 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 | |
| 5555 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 5556 | Instrumentation i, int flags) { |
| 5557 | if (i == null) return null; |
| 5558 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 5559 | return i.info; |
| 5560 | } |
| 5561 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 5562 | ii.metaData = i.metaData; |
| 5563 | return ii; |
| 5564 | } |
| 5565 | |
| 5566 | public static class IntentInfo extends IntentFilter { |
| 5567 | public boolean hasDefault; |
| 5568 | public int labelRes; |
| 5569 | public CharSequence nonLocalizedLabel; |
| 5570 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 5571 | public int logo; |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 5572 | public int banner; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 5573 | public int preferred; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | public final static class ActivityIntentInfo extends IntentInfo { |
| 5577 | public final Activity activity; |
| 5578 | |
| 5579 | public ActivityIntentInfo(Activity _activity) { |
| 5580 | activity = _activity; |
| 5581 | } |
| 5582 | |
| 5583 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5584 | StringBuilder sb = new StringBuilder(128); |
| 5585 | sb.append("ActivityIntentInfo{"); |
| 5586 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5587 | sb.append(' '); |
| 5588 | activity.appendComponentShortName(sb); |
| 5589 | sb.append('}'); |
| 5590 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | } |
| 5592 | } |
| 5593 | |
| 5594 | public final static class ServiceIntentInfo extends IntentInfo { |
| 5595 | public final Service service; |
| 5596 | |
| 5597 | public ServiceIntentInfo(Service _service) { |
| 5598 | service = _service; |
| 5599 | } |
| 5600 | |
| 5601 | public String toString() { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 5602 | StringBuilder sb = new StringBuilder(128); |
| 5603 | sb.append("ServiceIntentInfo{"); |
| 5604 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5605 | sb.append(' '); |
| 5606 | service.appendComponentShortName(sb); |
| 5607 | sb.append('}'); |
| 5608 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | } |
| 5610 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 5611 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 5612 | public static final class ProviderIntentInfo extends IntentInfo { |
| 5613 | public final Provider provider; |
| 5614 | |
| 5615 | public ProviderIntentInfo(Provider provider) { |
| 5616 | this.provider = provider; |
| 5617 | } |
| 5618 | |
| 5619 | public String toString() { |
| 5620 | StringBuilder sb = new StringBuilder(128); |
| 5621 | sb.append("ProviderIntentInfo{"); |
| 5622 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5623 | sb.append(' '); |
| 5624 | provider.appendComponentShortName(sb); |
| 5625 | sb.append('}'); |
| 5626 | return sb.toString(); |
| 5627 | } |
| 5628 | } |
| 5629 | |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 5630 | /** |
| 5631 | * @hide |
| 5632 | */ |
| 5633 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 5634 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 5635 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5636 | |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 5637 | private static AtomicReference<byte[]> sBuffer = new AtomicReference<byte[]>(); |
| 5638 | |
| 5639 | public static long readFullyIgnoringContents(InputStream in) throws IOException { |
| 5640 | byte[] buffer = sBuffer.getAndSet(null); |
| 5641 | if (buffer == null) { |
| 5642 | buffer = new byte[4096]; |
| 5643 | } |
| 5644 | |
| 5645 | int n = 0; |
| 5646 | int count = 0; |
| 5647 | while ((n = in.read(buffer, 0, buffer.length)) != -1) { |
| 5648 | count += n; |
| 5649 | } |
| 5650 | |
| 5651 | sBuffer.set(buffer); |
| 5652 | return count; |
| 5653 | } |
| 5654 | |
| 5655 | public static void closeQuietly(StrictJarFile jarFile) { |
| 5656 | if (jarFile != null) { |
| 5657 | try { |
| 5658 | jarFile.close(); |
| 5659 | } catch (Exception ignored) { |
| 5660 | } |
| 5661 | } |
| 5662 | } |
| 5663 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5664 | public static class PackageParserException extends Exception { |
| 5665 | public final int error; |
| 5666 | |
| 5667 | public PackageParserException(int error, String detailMessage) { |
| 5668 | super(detailMessage); |
| 5669 | this.error = error; |
| 5670 | } |
Jeff Sharkey | 275e085 | 2014-06-17 18:18:49 -0700 | [diff] [blame] | 5671 | |
| 5672 | public PackageParserException(int error, String detailMessage, Throwable throwable) { |
| 5673 | super(detailMessage, throwable); |
| 5674 | this.error = error; |
| 5675 | } |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 5676 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | } |