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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.content.ComponentName; |
| 20 | import android.content.Intent; |
| 21 | import android.content.IntentFilter; |
| 22 | import android.content.res.AssetManager; |
| 23 | import android.content.res.Configuration; |
| 24 | import android.content.res.Resources; |
| 25 | import android.content.res.TypedArray; |
| 26 | import android.content.res.XmlResourceParser; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 27 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.os.Bundle; |
| 29 | import android.os.PatternMatcher; |
| 30 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.DisplayMetrics; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 32 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.util.TypedValue; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 34 | import com.android.internal.util.XmlUtils; |
| 35 | import org.xmlpull.v1.XmlPullParser; |
| 36 | import org.xmlpull.v1.XmlPullParserException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Kenny Root | d63f7db | 2010-09-27 08:07:48 -0700 | [diff] [blame] | 38 | import java.io.BufferedInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import java.io.File; |
| 40 | import java.io.IOException; |
| 41 | import java.io.InputStream; |
| 42 | import java.lang.ref.WeakReference; |
| 43 | import java.security.cert.Certificate; |
| 44 | import java.security.cert.CertificateEncodingException; |
| 45 | import java.util.ArrayList; |
| 46 | import java.util.Enumeration; |
| 47 | import java.util.Iterator; |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 48 | import java.util.jar.Attributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import java.util.jar.JarEntry; |
| 50 | import java.util.jar.JarFile; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 51 | import java.util.jar.Manifest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Package archive parsing |
| 55 | * |
| 56 | * {@hide} |
| 57 | */ |
| 58 | public class PackageParser { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 59 | private static final boolean DEBUG_JAR = false; |
| 60 | private static final boolean DEBUG_PARSER = false; |
| 61 | private static final boolean DEBUG_BACKUP = false; |
| 62 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 63 | /** File name in an APK for the Android manifest. */ |
| 64 | private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; |
| 65 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 66 | /** @hide */ |
| 67 | public static class NewPermissionInfo { |
| 68 | public final String name; |
| 69 | public final int sdkVersion; |
| 70 | public final int fileVersion; |
| 71 | |
| 72 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 73 | this.name = name; |
| 74 | this.sdkVersion = sdkVersion; |
| 75 | this.fileVersion = fileVersion; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * List of new permissions that have been added since 1.0. |
| 81 | * NOTE: These must be declared in SDK version order, with permissions |
| 82 | * added to older SDKs appearing before those added to newer SDKs. |
| 83 | * @hide |
| 84 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 85 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 86 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 87 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 88 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 89 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 90 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 91 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | private String mArchiveSourcePath; |
| 94 | private String[] mSeparateProcesses; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 95 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
| 96 | private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME) |
| 97 | ? null : Build.VERSION.CODENAME; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | |
| 99 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 100 | |
| 101 | private static final Object mSync = new Object(); |
| 102 | private static WeakReference<byte[]> mReadBuffer; |
| 103 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 104 | private static boolean sCompatibilityModeEnabled = true; |
| 105 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 106 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 107 | static class ParsePackageItemArgs { |
| 108 | final Package owner; |
| 109 | final String[] outError; |
| 110 | final int nameRes; |
| 111 | final int labelRes; |
| 112 | final int iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 113 | final int logoRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 114 | |
| 115 | String tag; |
| 116 | TypedArray sa; |
| 117 | |
| 118 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 119 | int _nameRes, int _labelRes, int _iconRes, int _logoRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 120 | owner = _owner; |
| 121 | outError = _outError; |
| 122 | nameRes = _nameRes; |
| 123 | labelRes = _labelRes; |
| 124 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 125 | logoRes = _logoRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | static class ParseComponentArgs extends ParsePackageItemArgs { |
| 130 | final String[] sepProcesses; |
| 131 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 132 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 133 | final int enabledRes; |
| 134 | int flags; |
| 135 | |
| 136 | ParseComponentArgs(Package _owner, String[] _outError, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 137 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 138 | String[] _sepProcesses, int _processRes, |
| 139 | int _descriptionRes, int _enabledRes) { |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 140 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 141 | sepProcesses = _sepProcesses; |
| 142 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 143 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 144 | enabledRes = _enabledRes; |
| 145 | } |
| 146 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 147 | |
| 148 | /* Light weight package info. |
| 149 | * @hide |
| 150 | */ |
| 151 | public static class PackageLite { |
| 152 | public String packageName; |
| 153 | public int installLocation; |
| 154 | public String mScanPath; |
| 155 | public PackageLite(String packageName, int installLocation) { |
| 156 | this.packageName = packageName; |
| 157 | this.installLocation = installLocation; |
| 158 | } |
| 159 | } |
| 160 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 161 | private ParsePackageItemArgs mParseInstrumentationArgs; |
| 162 | private ParseComponentArgs mParseActivityArgs; |
| 163 | private ParseComponentArgs mParseActivityAliasArgs; |
| 164 | private ParseComponentArgs mParseServiceArgs; |
| 165 | private ParseComponentArgs mParseProviderArgs; |
| 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | /** If set to true, we will only allow package files that exactly match |
| 168 | * the DTD. Otherwise, we try to get as much from the package as we |
| 169 | * can without failing. This should normally be set to false, to |
| 170 | * support extensions to the DTD in future versions. */ |
| 171 | private static final boolean RIGID_PARSER = false; |
| 172 | |
| 173 | private static final String TAG = "PackageParser"; |
| 174 | |
| 175 | public PackageParser(String archiveSourcePath) { |
| 176 | mArchiveSourcePath = archiveSourcePath; |
| 177 | } |
| 178 | |
| 179 | public void setSeparateProcesses(String[] procs) { |
| 180 | mSeparateProcesses = procs; |
| 181 | } |
| 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | private static final boolean isPackageFilename(String name) { |
| 184 | return name.endsWith(".apk"); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 189 | * |
| 190 | * @param p the parsed package. |
| 191 | * @param flags indicating which optional information is included. |
| 192 | */ |
| 193 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | 78d6883 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 194 | int gids[], int flags, long firstInstallTime, long lastUpdateTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | |
| 196 | PackageInfo pi = new PackageInfo(); |
| 197 | pi.packageName = p.packageName; |
| 198 | pi.versionCode = p.mVersionCode; |
| 199 | pi.versionName = p.mVersionName; |
| 200 | pi.sharedUserId = p.mSharedUserId; |
| 201 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 202 | pi.applicationInfo = generateApplicationInfo(p, flags); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 203 | pi.installLocation = p.installLocation; |
Dianne Hackborn | 78d6883 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 204 | pi.firstInstallTime = firstInstallTime; |
| 205 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 207 | pi.gids = gids; |
| 208 | } |
| 209 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
| 210 | int N = p.configPreferences.size(); |
| 211 | if (N > 0) { |
| 212 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 213 | p.configPreferences.toArray(pi.configPreferences); |
| 214 | } |
| 215 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 216 | if (N > 0) { |
| 217 | pi.reqFeatures = new FeatureInfo[N]; |
| 218 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | if ((flags&PackageManager.GET_ACTIVITIES) != 0) { |
| 222 | int N = p.activities.size(); |
| 223 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 224 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 225 | pi.activities = new ActivityInfo[N]; |
| 226 | } else { |
| 227 | int num = 0; |
| 228 | for (int i=0; i<N; i++) { |
| 229 | if (p.activities.get(i).info.enabled) num++; |
| 230 | } |
| 231 | pi.activities = new ActivityInfo[num]; |
| 232 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 233 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | final Activity activity = p.activities.get(i); |
| 235 | if (activity.info.enabled |
| 236 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 237 | pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | if ((flags&PackageManager.GET_RECEIVERS) != 0) { |
| 243 | int N = p.receivers.size(); |
| 244 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 245 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 246 | pi.receivers = new ActivityInfo[N]; |
| 247 | } else { |
| 248 | int num = 0; |
| 249 | for (int i=0; i<N; i++) { |
| 250 | if (p.receivers.get(i).info.enabled) num++; |
| 251 | } |
| 252 | pi.receivers = new ActivityInfo[num]; |
| 253 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 254 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | final Activity activity = p.receivers.get(i); |
| 256 | if (activity.info.enabled |
| 257 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 258 | pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | if ((flags&PackageManager.GET_SERVICES) != 0) { |
| 264 | int N = p.services.size(); |
| 265 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 266 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 267 | pi.services = new ServiceInfo[N]; |
| 268 | } else { |
| 269 | int num = 0; |
| 270 | for (int i=0; i<N; i++) { |
| 271 | if (p.services.get(i).info.enabled) num++; |
| 272 | } |
| 273 | pi.services = new ServiceInfo[num]; |
| 274 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 275 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | final Service service = p.services.get(i); |
| 277 | if (service.info.enabled |
| 278 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 279 | pi.services[j++] = generateServiceInfo(p.services.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | if ((flags&PackageManager.GET_PROVIDERS) != 0) { |
| 285 | int N = p.providers.size(); |
| 286 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 287 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 288 | pi.providers = new ProviderInfo[N]; |
| 289 | } else { |
| 290 | int num = 0; |
| 291 | for (int i=0; i<N; i++) { |
| 292 | if (p.providers.get(i).info.enabled) num++; |
| 293 | } |
| 294 | pi.providers = new ProviderInfo[num]; |
| 295 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 296 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | final Provider provider = p.providers.get(i); |
| 298 | if (provider.info.enabled |
| 299 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 300 | pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 306 | int N = p.instrumentation.size(); |
| 307 | if (N > 0) { |
| 308 | pi.instrumentation = new InstrumentationInfo[N]; |
| 309 | for (int i=0; i<N; i++) { |
| 310 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 311 | p.instrumentation.get(i), flags); |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 316 | int N = p.permissions.size(); |
| 317 | if (N > 0) { |
| 318 | pi.permissions = new PermissionInfo[N]; |
| 319 | for (int i=0; i<N; i++) { |
| 320 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 321 | } |
| 322 | } |
| 323 | N = p.requestedPermissions.size(); |
| 324 | if (N > 0) { |
| 325 | pi.requestedPermissions = new String[N]; |
| 326 | for (int i=0; i<N; i++) { |
| 327 | pi.requestedPermissions[i] = p.requestedPermissions.get(i); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 332 | int N = (p.mSignatures != null) ? p.mSignatures.length : 0; |
| 333 | if (N > 0) { |
| 334 | pi.signatures = new Signature[N]; |
| 335 | System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | return pi; |
| 339 | } |
| 340 | |
| 341 | private Certificate[] loadCertificates(JarFile jarFile, JarEntry je, |
| 342 | byte[] readBuffer) { |
| 343 | try { |
| 344 | // We must read the stream for the JarEntry to retrieve |
| 345 | // its certificates. |
Kenny Root | d63f7db | 2010-09-27 08:07:48 -0700 | [diff] [blame] | 346 | InputStream is = new BufferedInputStream(jarFile.getInputStream(je)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | while (is.read(readBuffer, 0, readBuffer.length) != -1) { |
| 348 | // not using |
| 349 | } |
| 350 | is.close(); |
| 351 | return je != null ? je.getCertificates() : null; |
| 352 | } catch (IOException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 353 | Slog.w(TAG, "Exception reading " + je.getName() + " in " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | + jarFile.getName(), e); |
Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 355 | } catch (RuntimeException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 356 | Slog.w(TAG, "Exception reading " + je.getName() + " in " |
Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 357 | + jarFile.getName(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } |
| 359 | return null; |
| 360 | } |
| 361 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 362 | public final static int PARSE_IS_SYSTEM = 1<<0; |
| 363 | public final static int PARSE_CHATTY = 1<<1; |
| 364 | public final static int PARSE_MUST_BE_APK = 1<<2; |
| 365 | public final static int PARSE_IGNORE_PROCESSES = 1<<3; |
| 366 | public final static int PARSE_FORWARD_LOCK = 1<<4; |
| 367 | public final static int PARSE_ON_SDCARD = 1<<5; |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 368 | public final static int PARSE_IS_SYSTEM_DIR = 1<<6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | |
| 370 | public int getParseError() { |
| 371 | return mParseError; |
| 372 | } |
| 373 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 374 | public Package parsePackage(File sourceFile, String destCodePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | DisplayMetrics metrics, int flags) { |
| 376 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 377 | |
| 378 | mArchiveSourcePath = sourceFile.getPath(); |
| 379 | if (!sourceFile.isFile()) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 380 | Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
| 382 | return null; |
| 383 | } |
| 384 | if (!isPackageFilename(sourceFile.getName()) |
| 385 | && (flags&PARSE_MUST_BE_APK) != 0) { |
| 386 | if ((flags&PARSE_IS_SYSTEM) == 0) { |
| 387 | // We expect to have non-.apk files in the system dir, |
| 388 | // so don't warn about them. |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 389 | Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | } |
| 391 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
| 392 | return null; |
| 393 | } |
| 394 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 395 | if (DEBUG_JAR) |
| 396 | Slog.d(TAG, "Scanning package: " + mArchiveSourcePath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
| 398 | XmlResourceParser parser = null; |
| 399 | AssetManager assmgr = null; |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 400 | Resources res = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | boolean assetError = true; |
| 402 | try { |
| 403 | assmgr = new AssetManager(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 404 | int cookie = assmgr.addAssetPath(mArchiveSourcePath); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 405 | if (cookie != 0) { |
| 406 | res = new Resources(assmgr, metrics, null); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 407 | assmgr.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] | 408 | Build.VERSION.RESOURCES_SDK_INT); |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 409 | parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | assetError = false; |
| 411 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 412 | Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | } |
| 414 | } catch (Exception e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 415 | Slog.w(TAG, "Unable to read AndroidManifest.xml of " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | + mArchiveSourcePath, e); |
| 417 | } |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 418 | if (assetError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | if (assmgr != null) assmgr.close(); |
| 420 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST; |
| 421 | return null; |
| 422 | } |
| 423 | String[] errorText = new String[1]; |
| 424 | Package pkg = null; |
| 425 | Exception errorException = null; |
| 426 | try { |
| 427 | // XXXX todo: need to figure out correct configuration. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | pkg = parsePackage(res, parser, flags, errorText); |
| 429 | } catch (Exception e) { |
| 430 | errorException = e; |
| 431 | mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | if (pkg == null) { |
| 436 | if (errorException != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 437 | Slog.w(TAG, mArchiveSourcePath, errorException); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 439 | Slog.w(TAG, mArchiveSourcePath + " (at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | + parser.getPositionDescription() |
| 441 | + "): " + errorText[0]); |
| 442 | } |
| 443 | parser.close(); |
| 444 | assmgr.close(); |
| 445 | if (mParseError == PackageManager.INSTALL_SUCCEEDED) { |
| 446 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 447 | } |
| 448 | return null; |
| 449 | } |
| 450 | |
| 451 | parser.close(); |
| 452 | assmgr.close(); |
| 453 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 454 | // Set code and resource paths |
| 455 | pkg.mPath = destCodePath; |
| 456 | pkg.mScanPath = mArchiveSourcePath; |
| 457 | //pkg.applicationInfo.sourceDir = destCodePath; |
| 458 | //pkg.applicationInfo.publicSourceDir = destRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | pkg.mSignatures = null; |
| 460 | |
| 461 | return pkg; |
| 462 | } |
| 463 | |
| 464 | public boolean collectCertificates(Package pkg, int flags) { |
| 465 | pkg.mSignatures = null; |
| 466 | |
| 467 | WeakReference<byte[]> readBufferRef; |
| 468 | byte[] readBuffer = null; |
| 469 | synchronized (mSync) { |
| 470 | readBufferRef = mReadBuffer; |
| 471 | if (readBufferRef != null) { |
| 472 | mReadBuffer = null; |
| 473 | readBuffer = readBufferRef.get(); |
| 474 | } |
| 475 | if (readBuffer == null) { |
| 476 | readBuffer = new byte[8192]; |
| 477 | readBufferRef = new WeakReference<byte[]>(readBuffer); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | try { |
| 482 | JarFile jarFile = new JarFile(mArchiveSourcePath); |
| 483 | |
| 484 | Certificate[] certs = null; |
| 485 | |
| 486 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 487 | // If this package comes from the system image, then we |
| 488 | // can trust it... we'll just use the AndroidManifest.xml |
| 489 | // to retrieve its signatures, not validating all of the |
| 490 | // files. |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 491 | JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | certs = loadCertificates(jarFile, jarEntry, readBuffer); |
| 493 | if (certs == null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 494 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | + " has no certificates at entry " |
| 496 | + jarEntry.getName() + "; ignoring!"); |
| 497 | jarFile.close(); |
| 498 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 499 | return false; |
| 500 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 501 | if (DEBUG_JAR) { |
| 502 | Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | + " certs=" + (certs != null ? certs.length : 0)); |
| 504 | if (certs != null) { |
| 505 | final int N = certs.length; |
| 506 | for (int i=0; i<N; i++) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 507 | Slog.i(TAG, " Public key: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | + certs[i].getPublicKey().getEncoded() |
| 509 | + " " + certs[i].getPublicKey()); |
| 510 | } |
| 511 | } |
| 512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 514 | Enumeration<JarEntry> entries = jarFile.entries(); |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 515 | final Manifest manifest = jarFile.getManifest(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | while (entries.hasMoreElements()) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 517 | final JarEntry je = entries.nextElement(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | if (je.isDirectory()) continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 519 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 520 | final String name = je.getName(); |
| 521 | |
| 522 | if (name.startsWith("META-INF/")) |
| 523 | continue; |
| 524 | |
| 525 | if (ANDROID_MANIFEST_FILENAME.equals(name)) { |
| 526 | final Attributes attributes = manifest.getAttributes(name); |
| 527 | pkg.manifestDigest = ManifestDigest.fromAttributes(attributes); |
| 528 | } |
| 529 | |
| 530 | final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 531 | if (DEBUG_JAR) { |
| 532 | Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | + ": certs=" + certs + " (" |
| 534 | + (certs != null ? certs.length : 0) + ")"); |
| 535 | } |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | if (localCerts == null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 538 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | + " has no certificates at entry " |
| 540 | + je.getName() + "; ignoring!"); |
| 541 | jarFile.close(); |
| 542 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 543 | return false; |
| 544 | } else if (certs == null) { |
| 545 | certs = localCerts; |
| 546 | } else { |
| 547 | // Ensure all certificates match. |
| 548 | for (int i=0; i<certs.length; i++) { |
| 549 | boolean found = false; |
| 550 | for (int j=0; j<localCerts.length; j++) { |
| 551 | if (certs[i] != null && |
| 552 | certs[i].equals(localCerts[j])) { |
| 553 | found = true; |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | if (!found || certs.length != localCerts.length) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 558 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | + " has mismatched certificates at entry " |
| 560 | + je.getName() + "; ignoring!"); |
| 561 | jarFile.close(); |
| 562 | mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 563 | return false; |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | jarFile.close(); |
| 570 | |
| 571 | synchronized (mSync) { |
| 572 | mReadBuffer = readBufferRef; |
| 573 | } |
| 574 | |
| 575 | if (certs != null && certs.length > 0) { |
| 576 | final int N = certs.length; |
| 577 | pkg.mSignatures = new Signature[certs.length]; |
| 578 | for (int i=0; i<N; i++) { |
| 579 | pkg.mSignatures[i] = new Signature( |
| 580 | certs[i].getEncoded()); |
| 581 | } |
| 582 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 583 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | + " has no certificates; ignoring!"); |
| 585 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 586 | return false; |
| 587 | } |
| 588 | } catch (CertificateEncodingException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 589 | Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; |
| 591 | return false; |
| 592 | } catch (IOException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 593 | Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; |
| 595 | return false; |
| 596 | } catch (RuntimeException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 597 | Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 605 | /* |
| 606 | * Utility method that retrieves just the package name and install |
| 607 | * location from the apk location at the given file path. |
| 608 | * @param packageFilePath file location of the apk |
| 609 | * @param flags Special parse flags |
Kenny Root | 930d3af | 2010-07-30 16:52:29 -0700 | [diff] [blame] | 610 | * @return PackageLite object with package information or null on failure. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 611 | */ |
| 612 | public static PackageLite parsePackageLite(String packageFilePath, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | XmlResourceParser parser = null; |
| 614 | AssetManager assmgr = null; |
| 615 | try { |
| 616 | assmgr = new AssetManager(); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 617 | assmgr.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] | 618 | Build.VERSION.RESOURCES_SDK_INT); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | int cookie = assmgr.addAssetPath(packageFilePath); |
Kenny Root | 1ebd74a | 2011-08-03 15:09:44 -0700 | [diff] [blame] | 621 | if (cookie == 0) { |
| 622 | return null; |
| 623 | } |
| 624 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 625 | parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | } catch (Exception e) { |
| 627 | if (assmgr != null) assmgr.close(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 628 | Slog.w(TAG, "Unable to read AndroidManifest.xml of " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | + packageFilePath, e); |
| 630 | return null; |
| 631 | } |
| 632 | AttributeSet attrs = parser; |
| 633 | String errors[] = new String[1]; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 634 | PackageLite packageLite = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | try { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 636 | packageLite = parsePackageLite(parser, attrs, flags, errors); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | } catch (IOException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 638 | Slog.w(TAG, packageFilePath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | } catch (XmlPullParserException e) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 640 | Slog.w(TAG, packageFilePath, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | } finally { |
| 642 | if (parser != null) parser.close(); |
| 643 | if (assmgr != null) assmgr.close(); |
| 644 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 645 | if (packageLite == null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 646 | Slog.e(TAG, "parsePackageLite error: " + errors[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | return null; |
| 648 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 649 | return packageLite; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | private static String validateName(String name, boolean requiresSeparator) { |
| 653 | final int N = name.length(); |
| 654 | boolean hasSep = false; |
| 655 | boolean front = true; |
| 656 | for (int i=0; i<N; i++) { |
| 657 | final char c = name.charAt(i); |
| 658 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 659 | front = false; |
| 660 | continue; |
| 661 | } |
| 662 | if (!front) { |
| 663 | if ((c >= '0' && c <= '9') || c == '_') { |
| 664 | continue; |
| 665 | } |
| 666 | } |
| 667 | if (c == '.') { |
| 668 | hasSep = true; |
| 669 | front = true; |
| 670 | continue; |
| 671 | } |
| 672 | return "bad character '" + c + "'"; |
| 673 | } |
| 674 | return hasSep || !requiresSeparator |
| 675 | ? null : "must have at least one '.' separator"; |
| 676 | } |
| 677 | |
| 678 | private static String parsePackageName(XmlPullParser parser, |
| 679 | AttributeSet attrs, int flags, String[] outError) |
| 680 | throws IOException, XmlPullParserException { |
| 681 | |
| 682 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 683 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 684 | && type != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | ; |
| 686 | } |
| 687 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 688 | if (type != XmlPullParser.START_TAG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | outError[0] = "No start tag found"; |
| 690 | return null; |
| 691 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 692 | if (DEBUG_PARSER) |
| 693 | Slog.v(TAG, "Root element name: '" + parser.getName() + "'"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | if (!parser.getName().equals("manifest")) { |
| 695 | outError[0] = "No <manifest> tag"; |
| 696 | return null; |
| 697 | } |
| 698 | String pkgName = attrs.getAttributeValue(null, "package"); |
| 699 | if (pkgName == null || pkgName.length() == 0) { |
| 700 | outError[0] = "<manifest> does not specify package"; |
| 701 | return null; |
| 702 | } |
| 703 | String nameError = validateName(pkgName, true); |
| 704 | if (nameError != null && !"android".equals(pkgName)) { |
| 705 | outError[0] = "<manifest> specifies bad package name \"" |
| 706 | + pkgName + "\": " + nameError; |
| 707 | return null; |
| 708 | } |
| 709 | |
| 710 | return pkgName.intern(); |
| 711 | } |
| 712 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 713 | private static PackageLite parsePackageLite(XmlPullParser parser, |
| 714 | AttributeSet attrs, int flags, String[] outError) |
| 715 | throws IOException, XmlPullParserException { |
| 716 | |
| 717 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 718 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 719 | && type != XmlPullParser.END_DOCUMENT) { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 720 | ; |
| 721 | } |
| 722 | |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 723 | if (type != XmlPullParser.START_TAG) { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 724 | outError[0] = "No start tag found"; |
| 725 | return null; |
| 726 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 727 | if (DEBUG_PARSER) |
| 728 | Slog.v(TAG, "Root element name: '" + parser.getName() + "'"); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 729 | if (!parser.getName().equals("manifest")) { |
| 730 | outError[0] = "No <manifest> tag"; |
| 731 | return null; |
| 732 | } |
| 733 | String pkgName = attrs.getAttributeValue(null, "package"); |
| 734 | if (pkgName == null || pkgName.length() == 0) { |
| 735 | outError[0] = "<manifest> does not specify package"; |
| 736 | return null; |
| 737 | } |
| 738 | String nameError = validateName(pkgName, true); |
| 739 | if (nameError != null && !"android".equals(pkgName)) { |
| 740 | outError[0] = "<manifest> specifies bad package name \"" |
| 741 | + pkgName + "\": " + nameError; |
| 742 | return null; |
| 743 | } |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 744 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 745 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
| 746 | String attr = attrs.getAttributeName(i); |
| 747 | if (attr.equals("installLocation")) { |
| 748 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 749 | PARSE_DEFAULT_INSTALL_LOCATION); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 750 | break; |
| 751 | } |
| 752 | } |
| 753 | return new PackageLite(pkgName.intern(), installLocation); |
| 754 | } |
| 755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | /** |
| 757 | * Temporary. |
| 758 | */ |
| 759 | static public Signature stringToSignature(String str) { |
| 760 | final int N = str.length(); |
| 761 | byte[] sig = new byte[N]; |
| 762 | for (int i=0; i<N; i++) { |
| 763 | sig[i] = (byte)str.charAt(i); |
| 764 | } |
| 765 | return new Signature(sig); |
| 766 | } |
| 767 | |
| 768 | private Package parsePackage( |
| 769 | Resources res, XmlResourceParser parser, int flags, String[] outError) |
| 770 | throws XmlPullParserException, IOException { |
| 771 | AttributeSet attrs = parser; |
| 772 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 773 | mParseInstrumentationArgs = null; |
| 774 | mParseActivityArgs = null; |
| 775 | mParseServiceArgs = null; |
| 776 | mParseProviderArgs = null; |
| 777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | String pkgName = parsePackageName(parser, attrs, flags, outError); |
| 779 | if (pkgName == null) { |
| 780 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 781 | return null; |
| 782 | } |
| 783 | int type; |
| 784 | |
| 785 | final Package pkg = new Package(pkgName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | boolean foundApp = false; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | TypedArray sa = res.obtainAttributes(attrs, |
| 789 | com.android.internal.R.styleable.AndroidManifest); |
| 790 | pkg.mVersionCode = sa.getInteger( |
| 791 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 792 | pkg.mVersionName = sa.getNonConfigurationString( |
| 793 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | if (pkg.mVersionName != null) { |
| 795 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 796 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 797 | String str = sa.getNonConfigurationString( |
| 798 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 799 | if (str != null && str.length() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | String nameError = validateName(str, true); |
| 801 | if (nameError != null && !"android".equals(pkgName)) { |
| 802 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 803 | + str + "\": " + nameError; |
| 804 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 805 | return null; |
| 806 | } |
| 807 | pkg.mSharedUserId = str.intern(); |
| 808 | pkg.mSharedUserLabel = sa.getResourceId( |
| 809 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 810 | } |
| 811 | sa.recycle(); |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 812 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 813 | pkg.installLocation = sa.getInteger( |
| 814 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 815 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 816 | pkg.applicationInfo.installLocation = pkg.installLocation; |
| 817 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 818 | // Resource boolean are -1, so 1 means we don't know the value. |
| 819 | int supportsSmallScreens = 1; |
| 820 | int supportsNormalScreens = 1; |
| 821 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 822 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 823 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 824 | int anyDensity = 1; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | int outerDepth = parser.getDepth(); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 827 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 828 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 829 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | continue; |
| 831 | } |
| 832 | |
| 833 | String tagName = parser.getName(); |
| 834 | if (tagName.equals("application")) { |
| 835 | if (foundApp) { |
| 836 | if (RIGID_PARSER) { |
| 837 | outError[0] = "<manifest> has more than one <application>"; |
| 838 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 839 | return null; |
| 840 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 841 | Slog.w(TAG, "<manifest> has more than one <application>"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | XmlUtils.skipCurrentTag(parser); |
| 843 | continue; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | foundApp = true; |
| 848 | if (!parseApplication(pkg, res, parser, attrs, flags, outError)) { |
| 849 | return null; |
| 850 | } |
| 851 | } else if (tagName.equals("permission-group")) { |
| 852 | if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) { |
| 853 | return null; |
| 854 | } |
| 855 | } else if (tagName.equals("permission")) { |
| 856 | if (parsePermission(pkg, res, parser, attrs, outError) == null) { |
| 857 | return null; |
| 858 | } |
| 859 | } else if (tagName.equals("permission-tree")) { |
| 860 | if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) { |
| 861 | return null; |
| 862 | } |
| 863 | } else if (tagName.equals("uses-permission")) { |
| 864 | sa = res.obtainAttributes(attrs, |
| 865 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 866 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 867 | // Note: don't allow this value to be a reference to a resource |
| 868 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | String name = sa.getNonResourceString( |
| 870 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
| 871 | |
| 872 | sa.recycle(); |
| 873 | |
| 874 | if (name != null && !pkg.requestedPermissions.contains(name)) { |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 875 | pkg.requestedPermissions.add(name.intern()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | XmlUtils.skipCurrentTag(parser); |
| 879 | |
| 880 | } else if (tagName.equals("uses-configuration")) { |
| 881 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 882 | sa = res.obtainAttributes(attrs, |
| 883 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 884 | cPref.reqTouchScreen = sa.getInt( |
| 885 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 886 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 887 | cPref.reqKeyboardType = sa.getInt( |
| 888 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 889 | Configuration.KEYBOARD_UNDEFINED); |
| 890 | if (sa.getBoolean( |
| 891 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 892 | false)) { |
| 893 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 894 | } |
| 895 | cPref.reqNavigation = sa.getInt( |
| 896 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 897 | Configuration.NAVIGATION_UNDEFINED); |
| 898 | if (sa.getBoolean( |
| 899 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 900 | false)) { |
| 901 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 902 | } |
| 903 | sa.recycle(); |
| 904 | pkg.configPreferences.add(cPref); |
| 905 | |
| 906 | XmlUtils.skipCurrentTag(parser); |
| 907 | |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 908 | } else if (tagName.equals("uses-feature")) { |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 909 | FeatureInfo fi = new FeatureInfo(); |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 910 | sa = res.obtainAttributes(attrs, |
| 911 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 912 | // Note: don't allow this value to be a reference to a resource |
| 913 | // that may change. |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 914 | fi.name = sa.getNonResourceString( |
| 915 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
| 916 | if (fi.name == null) { |
| 917 | fi.reqGlEsVersion = sa.getInt( |
| 918 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 919 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 920 | } |
| 921 | if (sa.getBoolean( |
| 922 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, |
| 923 | true)) { |
| 924 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 925 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 926 | sa.recycle(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 927 | if (pkg.reqFeatures == null) { |
| 928 | pkg.reqFeatures = new ArrayList<FeatureInfo>(); |
| 929 | } |
| 930 | pkg.reqFeatures.add(fi); |
| 931 | |
| 932 | if (fi.name == null) { |
| 933 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 934 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
| 935 | pkg.configPreferences.add(cPref); |
| 936 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 937 | |
| 938 | XmlUtils.skipCurrentTag(parser); |
| 939 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 940 | } else if (tagName.equals("uses-sdk")) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 941 | if (SDK_VERSION > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | sa = res.obtainAttributes(attrs, |
| 943 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 944 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 945 | int minVers = 0; |
| 946 | String minCode = null; |
| 947 | int targetVers = 0; |
| 948 | String targetCode = null; |
| 949 | |
| 950 | TypedValue val = sa.peekValue( |
| 951 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 952 | if (val != null) { |
| 953 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 954 | targetCode = minCode = val.string.toString(); |
| 955 | } else { |
| 956 | // If it's not a string, it's an integer. |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 957 | targetVers = minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | val = sa.peekValue( |
| 962 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 963 | if (val != null) { |
| 964 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 965 | targetCode = minCode = val.string.toString(); |
| 966 | } else { |
| 967 | // If it's not a string, it's an integer. |
| 968 | targetVers = val.data; |
| 969 | } |
| 970 | } |
| 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | sa.recycle(); |
| 973 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 974 | if (minCode != null) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 975 | if (!minCode.equals(SDK_CODENAME)) { |
| 976 | if (SDK_CODENAME != null) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 977 | outError[0] = "Requires development platform " + minCode |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 978 | + " (current platform is " + SDK_CODENAME + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 979 | } else { |
| 980 | outError[0] = "Requires development platform " + minCode |
| 981 | + " but this is a release platform."; |
| 982 | } |
| 983 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 984 | return null; |
| 985 | } |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 986 | } else if (minVers > SDK_VERSION) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 987 | outError[0] = "Requires newer sdk version #" + minVers |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 988 | + " (current version is #" + SDK_VERSION + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 989 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 990 | return null; |
| 991 | } |
| 992 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 993 | if (targetCode != null) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 994 | if (!targetCode.equals(SDK_CODENAME)) { |
| 995 | if (SDK_CODENAME != null) { |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 996 | outError[0] = "Requires development platform " + targetCode |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 997 | + " (current platform is " + SDK_CODENAME + ")"; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 998 | } else { |
| 999 | outError[0] = "Requires development platform " + targetCode |
| 1000 | + " but this is a release platform."; |
| 1001 | } |
| 1002 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 1003 | return null; |
| 1004 | } |
| 1005 | // If the code matches, it definitely targets this SDK. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1006 | pkg.applicationInfo.targetSdkVersion |
| 1007 | = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 1008 | } else { |
| 1009 | pkg.applicationInfo.targetSdkVersion = targetVers; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | XmlUtils.skipCurrentTag(parser); |
| 1014 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1015 | } else if (tagName.equals("supports-screens")) { |
| 1016 | sa = res.obtainAttributes(attrs, |
| 1017 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 1018 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1019 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 1020 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 1021 | 0); |
| 1022 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 1023 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 1024 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 1025 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 1026 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 1027 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1028 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1029 | // This is a trick to get a boolean and still able to detect |
| 1030 | // if a value was actually set. |
| 1031 | supportsSmallScreens = sa.getInteger( |
| 1032 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 1033 | supportsSmallScreens); |
| 1034 | supportsNormalScreens = sa.getInteger( |
| 1035 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 1036 | supportsNormalScreens); |
| 1037 | supportsLargeScreens = sa.getInteger( |
| 1038 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 1039 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1040 | supportsXLargeScreens = sa.getInteger( |
| 1041 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 1042 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1043 | resizeable = sa.getInteger( |
| 1044 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1045 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1046 | anyDensity = sa.getInteger( |
| 1047 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 1048 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1049 | |
| 1050 | sa.recycle(); |
| 1051 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 1052 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1053 | |
| 1054 | } else if (tagName.equals("protected-broadcast")) { |
| 1055 | sa = res.obtainAttributes(attrs, |
| 1056 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 1057 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1058 | // Note: don't allow this value to be a reference to a resource |
| 1059 | // that may change. |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1060 | String name = sa.getNonResourceString( |
| 1061 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 1062 | |
| 1063 | sa.recycle(); |
| 1064 | |
| 1065 | if (name != null && (flags&PARSE_IS_SYSTEM) != 0) { |
| 1066 | if (pkg.protectedBroadcasts == null) { |
| 1067 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 1068 | } |
| 1069 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 1070 | pkg.protectedBroadcasts.add(name.intern()); |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | XmlUtils.skipCurrentTag(parser); |
| 1075 | |
| 1076 | } else if (tagName.equals("instrumentation")) { |
| 1077 | if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) { |
| 1078 | return null; |
| 1079 | } |
| 1080 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1081 | } else if (tagName.equals("original-package")) { |
| 1082 | sa = res.obtainAttributes(attrs, |
| 1083 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 1084 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1085 | String orig =sa.getNonConfigurationString( |
| 1086 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1087 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 1088 | if (pkg.mOriginalPackages == null) { |
| 1089 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 1090 | pkg.mRealPackage = pkg.packageName; |
| 1091 | } |
| 1092 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1093 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1094 | |
| 1095 | sa.recycle(); |
| 1096 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1097 | XmlUtils.skipCurrentTag(parser); |
| 1098 | |
| 1099 | } else if (tagName.equals("adopt-permissions")) { |
| 1100 | sa = res.obtainAttributes(attrs, |
| 1101 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 1102 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1103 | String name = sa.getNonConfigurationString( |
| 1104 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1105 | |
| 1106 | sa.recycle(); |
| 1107 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1108 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1109 | if (pkg.mAdoptPermissions == null) { |
| 1110 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 1111 | } |
| 1112 | pkg.mAdoptPermissions.add(name); |
| 1113 | } |
| 1114 | |
| 1115 | XmlUtils.skipCurrentTag(parser); |
| 1116 | |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1117 | } else if (tagName.equals("uses-gl-texture")) { |
| 1118 | // Just skip this tag |
| 1119 | XmlUtils.skipCurrentTag(parser); |
| 1120 | continue; |
| 1121 | |
| 1122 | } else if (tagName.equals("compatible-screens")) { |
| 1123 | // Just skip this tag |
| 1124 | XmlUtils.skipCurrentTag(parser); |
| 1125 | continue; |
| 1126 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1127 | } else if (tagName.equals("eat-comment")) { |
| 1128 | // Just skip this tag |
| 1129 | XmlUtils.skipCurrentTag(parser); |
| 1130 | continue; |
| 1131 | |
| 1132 | } else if (RIGID_PARSER) { |
| 1133 | outError[0] = "Bad element under <manifest>: " |
| 1134 | + parser.getName(); |
| 1135 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1136 | return null; |
| 1137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1139 | Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1140 | + " at " + mArchiveSourcePath + " " |
| 1141 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | XmlUtils.skipCurrentTag(parser); |
| 1143 | continue; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 1148 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 1149 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1150 | } |
| 1151 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1152 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1153 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1154 | for (int ip=0; ip<NP; ip++) { |
| 1155 | final PackageParser.NewPermissionInfo npi |
| 1156 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 1157 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 1158 | break; |
| 1159 | } |
| 1160 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1161 | if (implicitPerms == null) { |
| 1162 | implicitPerms = new StringBuilder(128); |
| 1163 | implicitPerms.append(pkg.packageName); |
| 1164 | implicitPerms.append(": compat added "); |
| 1165 | } else { |
| 1166 | implicitPerms.append(' '); |
| 1167 | } |
| 1168 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1169 | pkg.requestedPermissions.add(npi.name); |
| 1170 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1171 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1172 | if (implicitPerms != null) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1173 | Slog.i(TAG, implicitPerms.toString()); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1174 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1175 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1176 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 1177 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1178 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1179 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 1180 | } |
| 1181 | if (supportsNormalScreens != 0) { |
| 1182 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 1183 | } |
| 1184 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 1185 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1186 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1187 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 1188 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1189 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 1190 | && pkg.applicationInfo.targetSdkVersion |
| 1191 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 1192 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 1193 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1194 | if (resizeable < 0 || (resizeable > 0 |
| 1195 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1196 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1197 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 1198 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1199 | if (anyDensity < 0 || (anyDensity > 0 |
| 1200 | && pkg.applicationInfo.targetSdkVersion |
| 1201 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 1202 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 1203 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 1204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | return pkg; |
| 1206 | } |
| 1207 | |
| 1208 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 1209 | String[] outError) { |
| 1210 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 1211 | outError[0] = "Empty class name in package " + pkg; |
| 1212 | return null; |
| 1213 | } |
| 1214 | String cls = clsSeq.toString(); |
| 1215 | char c = cls.charAt(0); |
| 1216 | if (c == '.') { |
| 1217 | return (pkg + cls).intern(); |
| 1218 | } |
| 1219 | if (cls.indexOf('.') < 0) { |
| 1220 | StringBuilder b = new StringBuilder(pkg); |
| 1221 | b.append('.'); |
| 1222 | b.append(cls); |
| 1223 | return b.toString().intern(); |
| 1224 | } |
| 1225 | if (c >= 'a' && c <= 'z') { |
| 1226 | return cls.intern(); |
| 1227 | } |
| 1228 | outError[0] = "Bad class name " + cls + " in package " + pkg; |
| 1229 | return null; |
| 1230 | } |
| 1231 | |
| 1232 | private static String buildCompoundName(String pkg, |
| 1233 | CharSequence procSeq, String type, String[] outError) { |
| 1234 | String proc = procSeq.toString(); |
| 1235 | char c = proc.charAt(0); |
| 1236 | if (pkg != null && c == ':') { |
| 1237 | if (proc.length() < 2) { |
| 1238 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 1239 | + ": must be at least two characters"; |
| 1240 | return null; |
| 1241 | } |
| 1242 | String subName = proc.substring(1); |
| 1243 | String nameError = validateName(subName, false); |
| 1244 | if (nameError != null) { |
| 1245 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 1246 | + pkg + ": " + nameError; |
| 1247 | return null; |
| 1248 | } |
| 1249 | return (pkg + proc).intern(); |
| 1250 | } |
| 1251 | String nameError = validateName(proc, true); |
| 1252 | if (nameError != null && !"system".equals(proc)) { |
| 1253 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 1254 | + pkg + ": " + nameError; |
| 1255 | return null; |
| 1256 | } |
| 1257 | return proc.intern(); |
| 1258 | } |
| 1259 | |
| 1260 | private static String buildProcessName(String pkg, String defProc, |
| 1261 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 1262 | String[] outError) { |
| 1263 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 1264 | return defProc != null ? defProc : pkg; |
| 1265 | } |
| 1266 | if (separateProcesses != null) { |
| 1267 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 1268 | String sp = separateProcesses[i]; |
| 1269 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 1270 | return pkg; |
| 1271 | } |
| 1272 | } |
| 1273 | } |
| 1274 | if (procSeq == null || procSeq.length() <= 0) { |
| 1275 | return defProc; |
| 1276 | } |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1277 | return buildCompoundName(pkg, procSeq, "process", outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 1281 | CharSequence procSeq, String[] outError) { |
| 1282 | if (procSeq == null) { |
| 1283 | return defProc; |
| 1284 | } |
| 1285 | if (procSeq.length() <= 0) { |
| 1286 | return null; |
| 1287 | } |
| 1288 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 1289 | } |
| 1290 | |
| 1291 | private PermissionGroup parsePermissionGroup(Package owner, Resources res, |
| 1292 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1293 | throws XmlPullParserException, IOException { |
| 1294 | PermissionGroup perm = new PermissionGroup(owner); |
| 1295 | |
| 1296 | TypedArray sa = res.obtainAttributes(attrs, |
| 1297 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
| 1298 | |
| 1299 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1300 | "<permission-group>", sa, |
| 1301 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 1302 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1303 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
| 1304 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | sa.recycle(); |
| 1306 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1307 | return null; |
| 1308 | } |
| 1309 | |
| 1310 | perm.info.descriptionRes = sa.getResourceId( |
| 1311 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 1312 | 0); |
| 1313 | |
| 1314 | sa.recycle(); |
| 1315 | |
| 1316 | if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm, |
| 1317 | outError)) { |
| 1318 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1319 | return null; |
| 1320 | } |
| 1321 | |
| 1322 | owner.permissionGroups.add(perm); |
| 1323 | |
| 1324 | return perm; |
| 1325 | } |
| 1326 | |
| 1327 | private Permission parsePermission(Package owner, Resources res, |
| 1328 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1329 | throws XmlPullParserException, IOException { |
| 1330 | Permission perm = new Permission(owner); |
| 1331 | |
| 1332 | TypedArray sa = res.obtainAttributes(attrs, |
| 1333 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 1334 | |
| 1335 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1336 | "<permission>", sa, |
| 1337 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 1338 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1339 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
| 1340 | com.android.internal.R.styleable.AndroidManifestPermission_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | sa.recycle(); |
| 1342 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1343 | return null; |
| 1344 | } |
| 1345 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1346 | // Note: don't allow this value to be a reference to a resource |
| 1347 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | perm.info.group = sa.getNonResourceString( |
| 1349 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 1350 | if (perm.info.group != null) { |
| 1351 | perm.info.group = perm.info.group.intern(); |
| 1352 | } |
| 1353 | |
| 1354 | perm.info.descriptionRes = sa.getResourceId( |
| 1355 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 1356 | 0); |
| 1357 | |
| 1358 | perm.info.protectionLevel = sa.getInt( |
| 1359 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 1360 | PermissionInfo.PROTECTION_NORMAL); |
| 1361 | |
| 1362 | sa.recycle(); |
| 1363 | |
| 1364 | if (perm.info.protectionLevel == -1) { |
| 1365 | outError[0] = "<permission> does not specify protectionLevel"; |
| 1366 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1367 | return null; |
| 1368 | } |
| 1369 | |
| 1370 | if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, |
| 1371 | outError)) { |
| 1372 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1373 | return null; |
| 1374 | } |
| 1375 | |
| 1376 | owner.permissions.add(perm); |
| 1377 | |
| 1378 | return perm; |
| 1379 | } |
| 1380 | |
| 1381 | private Permission parsePermissionTree(Package owner, Resources res, |
| 1382 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1383 | throws XmlPullParserException, IOException { |
| 1384 | Permission perm = new Permission(owner); |
| 1385 | |
| 1386 | TypedArray sa = res.obtainAttributes(attrs, |
| 1387 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 1388 | |
| 1389 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1390 | "<permission-tree>", sa, |
| 1391 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 1392 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1393 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
| 1394 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | sa.recycle(); |
| 1396 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1397 | return null; |
| 1398 | } |
| 1399 | |
| 1400 | sa.recycle(); |
| 1401 | |
| 1402 | int index = perm.info.name.indexOf('.'); |
| 1403 | if (index > 0) { |
| 1404 | index = perm.info.name.indexOf('.', index+1); |
| 1405 | } |
| 1406 | if (index < 0) { |
| 1407 | outError[0] = "<permission-tree> name has less than three segments: " |
| 1408 | + perm.info.name; |
| 1409 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1410 | return null; |
| 1411 | } |
| 1412 | |
| 1413 | perm.info.descriptionRes = 0; |
| 1414 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 1415 | perm.tree = true; |
| 1416 | |
| 1417 | if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm, |
| 1418 | outError)) { |
| 1419 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1420 | return null; |
| 1421 | } |
| 1422 | |
| 1423 | owner.permissions.add(perm); |
| 1424 | |
| 1425 | return perm; |
| 1426 | } |
| 1427 | |
| 1428 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
| 1429 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1430 | throws XmlPullParserException, IOException { |
| 1431 | TypedArray sa = res.obtainAttributes(attrs, |
| 1432 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 1433 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1434 | if (mParseInstrumentationArgs == null) { |
| 1435 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 1436 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 1437 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1438 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
| 1439 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1440 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 1441 | } |
| 1442 | |
| 1443 | mParseInstrumentationArgs.sa = sa; |
| 1444 | |
| 1445 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 1446 | new InstrumentationInfo()); |
| 1447 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | sa.recycle(); |
| 1449 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1450 | return null; |
| 1451 | } |
| 1452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1454 | // Note: don't allow this value to be a reference to a resource |
| 1455 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | str = sa.getNonResourceString( |
| 1457 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 1458 | a.info.targetPackage = str != null ? str.intern() : null; |
| 1459 | |
| 1460 | a.info.handleProfiling = sa.getBoolean( |
| 1461 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 1462 | false); |
| 1463 | |
| 1464 | a.info.functionalTest = sa.getBoolean( |
| 1465 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 1466 | false); |
| 1467 | |
| 1468 | sa.recycle(); |
| 1469 | |
| 1470 | if (a.info.targetPackage == null) { |
| 1471 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 1472 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1473 | return null; |
| 1474 | } |
| 1475 | |
| 1476 | if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a, |
| 1477 | outError)) { |
| 1478 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1479 | return null; |
| 1480 | } |
| 1481 | |
| 1482 | owner.instrumentation.add(a); |
| 1483 | |
| 1484 | return a; |
| 1485 | } |
| 1486 | |
| 1487 | private boolean parseApplication(Package owner, Resources res, |
| 1488 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 1489 | throws XmlPullParserException, IOException { |
| 1490 | final ApplicationInfo ai = owner.applicationInfo; |
| 1491 | final String pkgName = owner.applicationInfo.packageName; |
| 1492 | |
| 1493 | TypedArray sa = res.obtainAttributes(attrs, |
| 1494 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 1495 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1496 | String name = sa.getNonConfigurationString( |
| 1497 | com.android.internal.R.styleable.AndroidManifestApplication_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | if (name != null) { |
| 1499 | ai.className = buildClassName(pkgName, name, outError); |
| 1500 | if (ai.className == null) { |
| 1501 | sa.recycle(); |
| 1502 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1503 | return false; |
| 1504 | } |
| 1505 | } |
| 1506 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1507 | String manageSpaceActivity = sa.getNonConfigurationString( |
| 1508 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | if (manageSpaceActivity != null) { |
| 1510 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 1511 | outError); |
| 1512 | } |
| 1513 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1514 | boolean allowBackup = sa.getBoolean( |
| 1515 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 1516 | if (allowBackup) { |
| 1517 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1518 | |
Christopher Tate | 3de55bc | 2010-03-12 17:28:08 -0800 | [diff] [blame] | 1519 | // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant |
| 1520 | // if backup is possible for the given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1521 | String backupAgent = sa.getNonConfigurationString( |
| 1522 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1523 | if (backupAgent != null) { |
| 1524 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1525 | if (DEBUG_BACKUP) { |
| 1526 | Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1527 | + " from " + pkgName + "+" + backupAgent); |
| 1528 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (sa.getBoolean( |
| 1531 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 1532 | true)) { |
| 1533 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 1534 | } |
| 1535 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 1536 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 1537 | false)) { |
| 1538 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 1539 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1540 | } |
| 1541 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | TypedValue v = sa.peekValue( |
| 1544 | com.android.internal.R.styleable.AndroidManifestApplication_label); |
| 1545 | if (v != null && (ai.labelRes=v.resourceId) == 0) { |
| 1546 | ai.nonLocalizedLabel = v.coerceToString(); |
| 1547 | } |
| 1548 | |
| 1549 | ai.icon = sa.getResourceId( |
| 1550 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1551 | ai.logo = sa.getResourceId( |
| 1552 | com.android.internal.R.styleable.AndroidManifestApplication_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 1554 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | ai.descriptionRes = sa.getResourceId( |
| 1556 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 1557 | |
| 1558 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 1559 | if (sa.getBoolean( |
| 1560 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 1561 | false)) { |
| 1562 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
| 1563 | } |
| 1564 | } |
| 1565 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 1566 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
| 1567 | ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK; |
| 1568 | } |
| 1569 | |
| 1570 | if ((flags & PARSE_ON_SDCARD) != 0) { |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 1571 | ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 1572 | } |
| 1573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | if (sa.getBoolean( |
| 1575 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 1576 | false)) { |
| 1577 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 1578 | } |
| 1579 | |
| 1580 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 1581 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 1582 | false)) { |
| 1583 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 1584 | } |
| 1585 | |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1586 | boolean hardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1587 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame] | 1588 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1589 | |
| 1590 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 1592 | true)) { |
| 1593 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 1594 | } |
| 1595 | |
| 1596 | if (sa.getBoolean( |
| 1597 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 1598 | false)) { |
| 1599 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 1600 | } |
| 1601 | |
| 1602 | if (sa.getBoolean( |
| 1603 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 1604 | true)) { |
| 1605 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 1606 | } |
| 1607 | |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 1608 | if (sa.getBoolean( |
| 1609 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
Dianne Hackborn | e7fe35b | 2009-05-13 10:53:41 -0700 | [diff] [blame] | 1610 | false)) { |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 1611 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 1612 | } |
| 1613 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1614 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1615 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1616 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1617 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1618 | } |
| 1619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1621 | str = sa.getNonConfigurationString( |
| 1622 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 1624 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1625 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 1626 | str = sa.getNonConfigurationString( |
| 1627 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0); |
| 1628 | } else { |
| 1629 | // Some older apps have been seen to use a resource reference |
| 1630 | // here that on older builds was ignored (with a warning). We |
| 1631 | // need to continue to do this for them so they don't break. |
| 1632 | str = sa.getNonResourceString( |
| 1633 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 1634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 1636 | str, outError); |
| 1637 | |
| 1638 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1639 | CharSequence pname; |
| 1640 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 1641 | pname = sa.getNonConfigurationString( |
| 1642 | com.android.internal.R.styleable.AndroidManifestApplication_process, 0); |
| 1643 | } else { |
| 1644 | // Some older apps have been seen to use a resource reference |
| 1645 | // here that on older builds was ignored (with a warning). We |
| 1646 | // need to continue to do this for them so they don't break. |
| 1647 | pname = sa.getNonResourceString( |
| 1648 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 1649 | } |
| 1650 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | flags, mSeparateProcesses, outError); |
| 1652 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1653 | ai.enabled = sa.getBoolean( |
| 1654 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1655 | |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 1656 | if (false) { |
| 1657 | if (sa.getBoolean( |
| 1658 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 1659 | false)) { |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1660 | ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 1661 | |
| 1662 | // A heavy-weight application can not be in a custom process. |
| 1663 | // We can do direct compare because we intern all strings. |
| 1664 | if (ai.processName != null && ai.processName != ai.packageName) { |
| 1665 | outError[0] = "cantSaveState applications can not use custom processes"; |
| 1666 | } |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | } |
| 1670 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 1671 | ai.uiOptions = sa.getInt( |
| 1672 | com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0); |
| 1673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | sa.recycle(); |
| 1675 | |
| 1676 | if (outError[0] != null) { |
| 1677 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1678 | return false; |
| 1679 | } |
| 1680 | |
| 1681 | final int innerDepth = parser.getDepth(); |
| 1682 | |
| 1683 | int type; |
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() > innerDepth)) { |
| 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(); |
| 1691 | if (tagName.equals("activity")) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1692 | Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false, |
| 1693 | hardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | if (a == null) { |
| 1695 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
| 1699 | owner.activities.add(a); |
| 1700 | |
| 1701 | } else if (tagName.equals("receiver")) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1702 | Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | if (a == null) { |
| 1704 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | owner.receivers.add(a); |
| 1709 | |
| 1710 | } else if (tagName.equals("service")) { |
| 1711 | Service s = parseService(owner, res, parser, attrs, flags, outError); |
| 1712 | if (s == null) { |
| 1713 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1714 | return false; |
| 1715 | } |
| 1716 | |
| 1717 | owner.services.add(s); |
| 1718 | |
| 1719 | } else if (tagName.equals("provider")) { |
| 1720 | Provider p = parseProvider(owner, res, parser, attrs, flags, outError); |
| 1721 | if (p == null) { |
| 1722 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1723 | return false; |
| 1724 | } |
| 1725 | |
| 1726 | owner.providers.add(p); |
| 1727 | |
| 1728 | } else if (tagName.equals("activity-alias")) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1729 | Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | if (a == null) { |
| 1731 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1732 | return false; |
| 1733 | } |
| 1734 | |
| 1735 | owner.activities.add(a); |
| 1736 | |
| 1737 | } else if (parser.getName().equals("meta-data")) { |
| 1738 | // note: application meta-data is stored off to the side, so it can |
| 1739 | // remain null in the primary copy (we like to avoid extra copies because |
| 1740 | // it can be large) |
| 1741 | if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData, |
| 1742 | outError)) == null) { |
| 1743 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1744 | return false; |
| 1745 | } |
| 1746 | |
| 1747 | } else if (tagName.equals("uses-library")) { |
| 1748 | sa = res.obtainAttributes(attrs, |
| 1749 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 1750 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1751 | // Note: don't allow this value to be a reference to a resource |
| 1752 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | String lname = sa.getNonResourceString( |
| 1754 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1755 | boolean req = sa.getBoolean( |
| 1756 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 1757 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | |
| 1759 | sa.recycle(); |
| 1760 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1761 | if (lname != null) { |
| 1762 | if (req) { |
| 1763 | if (owner.usesLibraries == null) { |
| 1764 | owner.usesLibraries = new ArrayList<String>(); |
| 1765 | } |
| 1766 | if (!owner.usesLibraries.contains(lname)) { |
| 1767 | owner.usesLibraries.add(lname.intern()); |
| 1768 | } |
| 1769 | } else { |
| 1770 | if (owner.usesOptionalLibraries == null) { |
| 1771 | owner.usesOptionalLibraries = new ArrayList<String>(); |
| 1772 | } |
| 1773 | if (!owner.usesOptionalLibraries.contains(lname)) { |
| 1774 | owner.usesOptionalLibraries.add(lname.intern()); |
| 1775 | } |
| 1776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | XmlUtils.skipCurrentTag(parser); |
| 1780 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1781 | } else if (tagName.equals("uses-package")) { |
| 1782 | // Dependencies for app installers; we don't currently try to |
| 1783 | // enforce this. |
| 1784 | XmlUtils.skipCurrentTag(parser); |
| 1785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | } else { |
| 1787 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 1788 | Slog.w(TAG, "Unknown element under <application>: " + tagName |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1789 | + " at " + mArchiveSourcePath + " " |
| 1790 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | XmlUtils.skipCurrentTag(parser); |
| 1792 | continue; |
| 1793 | } else { |
| 1794 | outError[0] = "Bad element under <application>: " + tagName; |
| 1795 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1796 | return false; |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | return true; |
| 1802 | } |
| 1803 | |
| 1804 | private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 1805 | String[] outError, String tag, TypedArray sa, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1806 | int nameRes, int labelRes, int iconRes, int logoRes) { |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1807 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | if (name == null) { |
| 1809 | outError[0] = tag + " does not specify android:name"; |
| 1810 | return false; |
| 1811 | } |
| 1812 | |
| 1813 | outInfo.name |
| 1814 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 1815 | if (outInfo.name == null) { |
| 1816 | return false; |
| 1817 | } |
| 1818 | |
| 1819 | int iconVal = sa.getResourceId(iconRes, 0); |
| 1820 | if (iconVal != 0) { |
| 1821 | outInfo.icon = iconVal; |
| 1822 | outInfo.nonLocalizedLabel = null; |
| 1823 | } |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1824 | |
| 1825 | int logoVal = sa.getResourceId(logoRes, 0); |
| 1826 | if (logoVal != 0) { |
| 1827 | outInfo.logo = logoVal; |
| 1828 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | |
| 1830 | TypedValue v = sa.peekValue(labelRes); |
| 1831 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 1832 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 1833 | } |
| 1834 | |
| 1835 | outInfo.packageName = owner.packageName; |
| 1836 | |
| 1837 | return true; |
| 1838 | } |
| 1839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | private Activity parseActivity(Package owner, Resources res, |
| 1841 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1842 | boolean receiver, boolean hardwareAccelerated) |
| 1843 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | TypedArray sa = res.obtainAttributes(attrs, |
| 1845 | com.android.internal.R.styleable.AndroidManifestActivity); |
| 1846 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1847 | if (mParseActivityArgs == null) { |
| 1848 | mParseActivityArgs = new ParseComponentArgs(owner, outError, |
| 1849 | com.android.internal.R.styleable.AndroidManifestActivity_name, |
| 1850 | com.android.internal.R.styleable.AndroidManifestActivity_label, |
| 1851 | com.android.internal.R.styleable.AndroidManifestActivity_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1852 | com.android.internal.R.styleable.AndroidManifestActivity_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1853 | mSeparateProcesses, |
| 1854 | com.android.internal.R.styleable.AndroidManifestActivity_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1855 | com.android.internal.R.styleable.AndroidManifestActivity_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1856 | com.android.internal.R.styleable.AndroidManifestActivity_enabled); |
| 1857 | } |
| 1858 | |
| 1859 | mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 1860 | mParseActivityArgs.sa = sa; |
| 1861 | mParseActivityArgs.flags = flags; |
| 1862 | |
| 1863 | Activity a = new Activity(mParseActivityArgs, new ActivityInfo()); |
| 1864 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | sa.recycle(); |
| 1866 | return null; |
| 1867 | } |
| 1868 | |
| 1869 | final boolean setExported = sa.hasValue( |
| 1870 | com.android.internal.R.styleable.AndroidManifestActivity_exported); |
| 1871 | if (setExported) { |
| 1872 | a.info.exported = sa.getBoolean( |
| 1873 | com.android.internal.R.styleable.AndroidManifestActivity_exported, false); |
| 1874 | } |
| 1875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | a.info.theme = sa.getResourceId( |
| 1877 | com.android.internal.R.styleable.AndroidManifestActivity_theme, 0); |
| 1878 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 1879 | a.info.uiOptions = sa.getInt( |
| 1880 | com.android.internal.R.styleable.AndroidManifestActivity_uiOptions, |
| 1881 | a.info.applicationInfo.uiOptions); |
| 1882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1884 | str = sa.getNonConfigurationString( |
| 1885 | com.android.internal.R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1886 | if (str == null) { |
| 1887 | a.info.permission = owner.applicationInfo.permission; |
| 1888 | } else { |
| 1889 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 1890 | } |
| 1891 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1892 | str = sa.getNonConfigurationString( |
| 1893 | com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 1895 | owner.applicationInfo.taskAffinity, str, outError); |
| 1896 | |
| 1897 | a.info.flags = 0; |
| 1898 | if (sa.getBoolean( |
| 1899 | com.android.internal.R.styleable.AndroidManifestActivity_multiprocess, |
| 1900 | false)) { |
| 1901 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 1902 | } |
| 1903 | |
| 1904 | if (sa.getBoolean( |
| 1905 | com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch, |
| 1906 | false)) { |
| 1907 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 1908 | } |
| 1909 | |
| 1910 | if (sa.getBoolean( |
| 1911 | com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch, |
| 1912 | false)) { |
| 1913 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 1914 | } |
| 1915 | |
| 1916 | if (sa.getBoolean( |
| 1917 | com.android.internal.R.styleable.AndroidManifestActivity_noHistory, |
| 1918 | false)) { |
| 1919 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 1920 | } |
| 1921 | |
| 1922 | if (sa.getBoolean( |
| 1923 | com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState, |
| 1924 | false)) { |
| 1925 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 1926 | } |
| 1927 | |
| 1928 | if (sa.getBoolean( |
| 1929 | com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded, |
| 1930 | false)) { |
| 1931 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 1932 | } |
| 1933 | |
| 1934 | if (sa.getBoolean( |
| 1935 | com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents, |
| 1936 | false)) { |
| 1937 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 1938 | } |
| 1939 | |
| 1940 | if (sa.getBoolean( |
| 1941 | com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting, |
| 1942 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 1943 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 1944 | } |
| 1945 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 1946 | if (sa.getBoolean( |
| 1947 | com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, |
| 1948 | false)) { |
| 1949 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 1950 | } |
| 1951 | |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 1952 | if (sa.getBoolean( |
| 1953 | com.android.internal.R.styleable.AndroidManifestActivity_immersive, |
| 1954 | false)) { |
| 1955 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 1956 | } |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | if (!receiver) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1959 | if (sa.getBoolean( |
| 1960 | com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated, |
| 1961 | hardwareAccelerated)) { |
| 1962 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 1963 | } |
| 1964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | a.info.launchMode = sa.getInt( |
| 1966 | com.android.internal.R.styleable.AndroidManifestActivity_launchMode, |
| 1967 | ActivityInfo.LAUNCH_MULTIPLE); |
| 1968 | a.info.screenOrientation = sa.getInt( |
| 1969 | com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation, |
| 1970 | ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 1971 | a.info.configChanges = sa.getInt( |
| 1972 | com.android.internal.R.styleable.AndroidManifestActivity_configChanges, |
| 1973 | 0); |
| 1974 | a.info.softInputMode = sa.getInt( |
| 1975 | com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode, |
| 1976 | 0); |
| 1977 | } else { |
| 1978 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 1979 | a.info.configChanges = 0; |
| 1980 | } |
| 1981 | |
| 1982 | sa.recycle(); |
| 1983 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1984 | if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1985 | // A heavy-weight application can not have receives in its main process |
| 1986 | // We can do direct compare because we intern all strings. |
| 1987 | if (a.info.processName == owner.packageName) { |
| 1988 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 1989 | } |
| 1990 | } |
| 1991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | if (outError[0] != null) { |
| 1993 | return null; |
| 1994 | } |
| 1995 | |
| 1996 | int outerDepth = parser.getDepth(); |
| 1997 | int type; |
| 1998 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1999 | && (type != XmlPullParser.END_TAG |
| 2000 | || parser.getDepth() > outerDepth)) { |
| 2001 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2002 | continue; |
| 2003 | } |
| 2004 | |
| 2005 | if (parser.getName().equals("intent-filter")) { |
| 2006 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
| 2007 | if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) { |
| 2008 | return null; |
| 2009 | } |
| 2010 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2011 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2012 | + mArchiveSourcePath + " " |
| 2013 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | } else { |
| 2015 | a.intents.add(intent); |
| 2016 | } |
| 2017 | } else if (parser.getName().equals("meta-data")) { |
| 2018 | if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, |
| 2019 | outError)) == null) { |
| 2020 | return null; |
| 2021 | } |
| 2022 | } else { |
| 2023 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2024 | Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | if (receiver) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2026 | Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2027 | + " at " + mArchiveSourcePath + " " |
| 2028 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2030 | Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2031 | + " at " + mArchiveSourcePath + " " |
| 2032 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2033 | } |
| 2034 | XmlUtils.skipCurrentTag(parser); |
| 2035 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | } else { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2037 | if (receiver) { |
| 2038 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 2039 | } else { |
| 2040 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 2041 | } |
| 2042 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | if (!setExported) { |
| 2048 | a.info.exported = a.intents.size() > 0; |
| 2049 | } |
| 2050 | |
| 2051 | return a; |
| 2052 | } |
| 2053 | |
| 2054 | private Activity parseActivityAlias(Package owner, Resources res, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2055 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2056 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | TypedArray sa = res.obtainAttributes(attrs, |
| 2058 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 2059 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2060 | String targetActivity = sa.getNonConfigurationString( |
| 2061 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | if (targetActivity == null) { |
| 2063 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 2064 | sa.recycle(); |
| 2065 | return null; |
| 2066 | } |
| 2067 | |
| 2068 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 2069 | targetActivity, outError); |
| 2070 | if (targetActivity == null) { |
| 2071 | sa.recycle(); |
| 2072 | return null; |
| 2073 | } |
| 2074 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2075 | if (mParseActivityAliasArgs == null) { |
| 2076 | mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, |
| 2077 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 2078 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 2079 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2080 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2081 | mSeparateProcesses, |
| 2082 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2083 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2084 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
| 2085 | mParseActivityAliasArgs.tag = "<activity-alias>"; |
| 2086 | } |
| 2087 | |
| 2088 | mParseActivityAliasArgs.sa = sa; |
| 2089 | mParseActivityAliasArgs.flags = flags; |
| 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | Activity target = null; |
| 2092 | |
| 2093 | final int NA = owner.activities.size(); |
| 2094 | for (int i=0; i<NA; i++) { |
| 2095 | Activity t = owner.activities.get(i); |
| 2096 | if (targetActivity.equals(t.info.name)) { |
| 2097 | target = t; |
| 2098 | break; |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | if (target == null) { |
| 2103 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 2104 | + " not found in manifest"; |
| 2105 | sa.recycle(); |
| 2106 | return null; |
| 2107 | } |
| 2108 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2109 | ActivityInfo info = new ActivityInfo(); |
| 2110 | info.targetActivity = targetActivity; |
| 2111 | info.configChanges = target.info.configChanges; |
| 2112 | info.flags = target.info.flags; |
| 2113 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2114 | info.logo = target.info.logo; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2115 | info.labelRes = target.info.labelRes; |
| 2116 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 2117 | info.launchMode = target.info.launchMode; |
| 2118 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2119 | if (info.descriptionRes == 0) { |
| 2120 | info.descriptionRes = target.info.descriptionRes; |
| 2121 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2122 | info.screenOrientation = target.info.screenOrientation; |
| 2123 | info.taskAffinity = target.info.taskAffinity; |
| 2124 | info.theme = target.info.theme; |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 2125 | info.uiOptions = target.info.uiOptions; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2126 | |
| 2127 | Activity a = new Activity(mParseActivityAliasArgs, info); |
| 2128 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | sa.recycle(); |
| 2130 | return null; |
| 2131 | } |
| 2132 | |
| 2133 | final boolean setExported = sa.hasValue( |
| 2134 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 2135 | if (setExported) { |
| 2136 | a.info.exported = sa.getBoolean( |
| 2137 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 2138 | } |
| 2139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2141 | str = sa.getNonConfigurationString( |
| 2142 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | if (str != null) { |
| 2144 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 2145 | } |
| 2146 | |
| 2147 | sa.recycle(); |
| 2148 | |
| 2149 | if (outError[0] != null) { |
| 2150 | return null; |
| 2151 | } |
| 2152 | |
| 2153 | int outerDepth = parser.getDepth(); |
| 2154 | int type; |
| 2155 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2156 | && (type != XmlPullParser.END_TAG |
| 2157 | || parser.getDepth() > outerDepth)) { |
| 2158 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2159 | continue; |
| 2160 | } |
| 2161 | |
| 2162 | if (parser.getName().equals("intent-filter")) { |
| 2163 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
| 2164 | if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) { |
| 2165 | return null; |
| 2166 | } |
| 2167 | if (intent.countActions() == 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2168 | Slog.w(TAG, "No actions in intent filter at " |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2169 | + mArchiveSourcePath + " " |
| 2170 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | } else { |
| 2172 | a.intents.add(intent); |
| 2173 | } |
| 2174 | } else if (parser.getName().equals("meta-data")) { |
| 2175 | if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, |
| 2176 | outError)) == null) { |
| 2177 | return null; |
| 2178 | } |
| 2179 | } else { |
| 2180 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2181 | Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2182 | + " at " + mArchiveSourcePath + " " |
| 2183 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | XmlUtils.skipCurrentTag(parser); |
| 2185 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2186 | } else { |
| 2187 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 2188 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | if (!setExported) { |
| 2194 | a.info.exported = a.intents.size() > 0; |
| 2195 | } |
| 2196 | |
| 2197 | return a; |
| 2198 | } |
| 2199 | |
| 2200 | private Provider parseProvider(Package owner, Resources res, |
| 2201 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2202 | throws XmlPullParserException, IOException { |
| 2203 | TypedArray sa = res.obtainAttributes(attrs, |
| 2204 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 2205 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2206 | if (mParseProviderArgs == null) { |
| 2207 | mParseProviderArgs = new ParseComponentArgs(owner, outError, |
| 2208 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 2209 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 2210 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2211 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2212 | mSeparateProcesses, |
| 2213 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2214 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2215 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
| 2216 | mParseProviderArgs.tag = "<provider>"; |
| 2217 | } |
| 2218 | |
| 2219 | mParseProviderArgs.sa = sa; |
| 2220 | mParseProviderArgs.flags = flags; |
| 2221 | |
| 2222 | Provider p = new Provider(mParseProviderArgs, new ProviderInfo()); |
| 2223 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2224 | sa.recycle(); |
| 2225 | return null; |
| 2226 | } |
| 2227 | |
| 2228 | p.info.exported = sa.getBoolean( |
| 2229 | com.android.internal.R.styleable.AndroidManifestProvider_exported, true); |
| 2230 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2231 | String cpname = sa.getNonConfigurationString( |
| 2232 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | |
| 2234 | p.info.isSyncable = sa.getBoolean( |
| 2235 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 2236 | false); |
| 2237 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2238 | String permission = sa.getNonConfigurationString( |
| 2239 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 2240 | String str = sa.getNonConfigurationString( |
| 2241 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | if (str == null) { |
| 2243 | str = permission; |
| 2244 | } |
| 2245 | if (str == null) { |
| 2246 | p.info.readPermission = owner.applicationInfo.permission; |
| 2247 | } else { |
| 2248 | p.info.readPermission = |
| 2249 | str.length() > 0 ? str.toString().intern() : null; |
| 2250 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2251 | str = sa.getNonConfigurationString( |
| 2252 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | if (str == null) { |
| 2254 | str = permission; |
| 2255 | } |
| 2256 | if (str == null) { |
| 2257 | p.info.writePermission = owner.applicationInfo.permission; |
| 2258 | } else { |
| 2259 | p.info.writePermission = |
| 2260 | str.length() > 0 ? str.toString().intern() : null; |
| 2261 | } |
| 2262 | |
| 2263 | p.info.grantUriPermissions = sa.getBoolean( |
| 2264 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 2265 | false); |
| 2266 | |
| 2267 | p.info.multiprocess = sa.getBoolean( |
| 2268 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 2269 | false); |
| 2270 | |
| 2271 | p.info.initOrder = sa.getInt( |
| 2272 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 2273 | 0); |
| 2274 | |
| 2275 | sa.recycle(); |
| 2276 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2277 | if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2278 | // A heavy-weight application can not have providers in its main process |
| 2279 | // We can do direct compare because we intern all strings. |
| 2280 | if (p.info.processName == owner.packageName) { |
| 2281 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 2282 | return null; |
| 2283 | } |
| 2284 | } |
| 2285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | if (cpname == null) { |
| 2287 | outError[0] = "<provider> does not incude authorities attribute"; |
| 2288 | return null; |
| 2289 | } |
| 2290 | p.info.authority = cpname.intern(); |
| 2291 | |
| 2292 | if (!parseProviderTags(res, parser, attrs, p, outError)) { |
| 2293 | return null; |
| 2294 | } |
| 2295 | |
| 2296 | return p; |
| 2297 | } |
| 2298 | |
| 2299 | private boolean parseProviderTags(Resources res, |
| 2300 | XmlPullParser parser, AttributeSet attrs, |
| 2301 | Provider outInfo, String[] outError) |
| 2302 | throws XmlPullParserException, IOException { |
| 2303 | int outerDepth = parser.getDepth(); |
| 2304 | int type; |
| 2305 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2306 | && (type != XmlPullParser.END_TAG |
| 2307 | || parser.getDepth() > outerDepth)) { |
| 2308 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2309 | continue; |
| 2310 | } |
| 2311 | |
| 2312 | if (parser.getName().equals("meta-data")) { |
| 2313 | if ((outInfo.metaData=parseMetaData(res, parser, attrs, |
| 2314 | outInfo.metaData, outError)) == null) { |
| 2315 | return false; |
| 2316 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | } else if (parser.getName().equals("grant-uri-permission")) { |
| 2319 | TypedArray sa = res.obtainAttributes(attrs, |
| 2320 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 2321 | |
| 2322 | PatternMatcher pa = null; |
| 2323 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2324 | String str = sa.getNonConfigurationString( |
| 2325 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | if (str != null) { |
| 2327 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 2328 | } |
| 2329 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2330 | str = sa.getNonConfigurationString( |
| 2331 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | if (str != null) { |
| 2333 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 2334 | } |
| 2335 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2336 | str = sa.getNonConfigurationString( |
| 2337 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | if (str != null) { |
| 2339 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 2340 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | sa.recycle(); |
| 2343 | |
| 2344 | if (pa != null) { |
| 2345 | if (outInfo.info.uriPermissionPatterns == null) { |
| 2346 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 2347 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 2348 | } else { |
| 2349 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 2350 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 2351 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 2352 | newp[N] = pa; |
| 2353 | outInfo.info.uriPermissionPatterns = newp; |
| 2354 | } |
| 2355 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2356 | } else { |
| 2357 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2358 | Slog.w(TAG, "Unknown element under <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2359 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2360 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2361 | XmlUtils.skipCurrentTag(parser); |
| 2362 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2363 | } else { |
| 2364 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 2365 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2366 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2367 | } |
| 2368 | XmlUtils.skipCurrentTag(parser); |
| 2369 | |
| 2370 | } else if (parser.getName().equals("path-permission")) { |
| 2371 | TypedArray sa = res.obtainAttributes(attrs, |
| 2372 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 2373 | |
| 2374 | PathPermission pa = null; |
| 2375 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2376 | String permission = sa.getNonConfigurationString( |
| 2377 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 2378 | String readPermission = sa.getNonConfigurationString( |
| 2379 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2380 | if (readPermission == null) { |
| 2381 | readPermission = permission; |
| 2382 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2383 | String writePermission = sa.getNonConfigurationString( |
| 2384 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2385 | if (writePermission == null) { |
| 2386 | writePermission = permission; |
| 2387 | } |
| 2388 | |
| 2389 | boolean havePerm = false; |
| 2390 | if (readPermission != null) { |
| 2391 | readPermission = readPermission.intern(); |
| 2392 | havePerm = true; |
| 2393 | } |
| 2394 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 2395 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2396 | havePerm = true; |
| 2397 | } |
| 2398 | |
| 2399 | if (!havePerm) { |
| 2400 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2401 | Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2402 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2403 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2404 | XmlUtils.skipCurrentTag(parser); |
| 2405 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2406 | } else { |
| 2407 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 2408 | return false; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2409 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2412 | String path = sa.getNonConfigurationString( |
| 2413 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2414 | if (path != null) { |
| 2415 | pa = new PathPermission(path, |
| 2416 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 2417 | } |
| 2418 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2419 | path = sa.getNonConfigurationString( |
| 2420 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2421 | if (path != null) { |
| 2422 | pa = new PathPermission(path, |
| 2423 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 2424 | } |
| 2425 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2426 | path = sa.getNonConfigurationString( |
| 2427 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2428 | if (path != null) { |
| 2429 | pa = new PathPermission(path, |
| 2430 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 2431 | } |
| 2432 | |
| 2433 | sa.recycle(); |
| 2434 | |
| 2435 | if (pa != null) { |
| 2436 | if (outInfo.info.pathPermissions == null) { |
| 2437 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 2438 | outInfo.info.pathPermissions[0] = pa; |
| 2439 | } else { |
| 2440 | final int N = outInfo.info.pathPermissions.length; |
| 2441 | PathPermission[] newp = new PathPermission[N+1]; |
| 2442 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 2443 | newp[N] = pa; |
| 2444 | outInfo.info.pathPermissions = newp; |
| 2445 | } |
| 2446 | } else { |
| 2447 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2448 | Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2449 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2450 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2451 | XmlUtils.skipCurrentTag(parser); |
| 2452 | continue; |
| 2453 | } |
| 2454 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 2455 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | } |
| 2457 | XmlUtils.skipCurrentTag(parser); |
| 2458 | |
| 2459 | } else { |
| 2460 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2461 | Slog.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2462 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2463 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | XmlUtils.skipCurrentTag(parser); |
| 2465 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2466 | } else { |
| 2467 | outError[0] = "Bad element under <provider>: " + parser.getName(); |
| 2468 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | return true; |
| 2473 | } |
| 2474 | |
| 2475 | private Service parseService(Package owner, Resources res, |
| 2476 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2477 | throws XmlPullParserException, IOException { |
| 2478 | TypedArray sa = res.obtainAttributes(attrs, |
| 2479 | com.android.internal.R.styleable.AndroidManifestService); |
| 2480 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2481 | if (mParseServiceArgs == null) { |
| 2482 | mParseServiceArgs = new ParseComponentArgs(owner, outError, |
| 2483 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 2484 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 2485 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2486 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2487 | mSeparateProcesses, |
| 2488 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2489 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2490 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
| 2491 | mParseServiceArgs.tag = "<service>"; |
| 2492 | } |
| 2493 | |
| 2494 | mParseServiceArgs.sa = sa; |
| 2495 | mParseServiceArgs.flags = flags; |
| 2496 | |
| 2497 | Service s = new Service(mParseServiceArgs, new ServiceInfo()); |
| 2498 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | sa.recycle(); |
| 2500 | return null; |
| 2501 | } |
| 2502 | |
| 2503 | final boolean setExported = sa.hasValue( |
| 2504 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 2505 | if (setExported) { |
| 2506 | s.info.exported = sa.getBoolean( |
| 2507 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 2508 | } |
| 2509 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2510 | String str = sa.getNonConfigurationString( |
| 2511 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | if (str == null) { |
| 2513 | s.info.permission = owner.applicationInfo.permission; |
| 2514 | } else { |
| 2515 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 2516 | } |
| 2517 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2518 | s.info.flags = 0; |
| 2519 | if (sa.getBoolean( |
| 2520 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 2521 | false)) { |
| 2522 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 2523 | } |
| 2524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | sa.recycle(); |
| 2526 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2527 | if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2528 | // A heavy-weight application can not have services in its main process |
| 2529 | // We can do direct compare because we intern all strings. |
| 2530 | if (s.info.processName == owner.packageName) { |
| 2531 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 2532 | return null; |
| 2533 | } |
| 2534 | } |
| 2535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | int outerDepth = parser.getDepth(); |
| 2537 | int type; |
| 2538 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2539 | && (type != XmlPullParser.END_TAG |
| 2540 | || parser.getDepth() > outerDepth)) { |
| 2541 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2542 | continue; |
| 2543 | } |
| 2544 | |
| 2545 | if (parser.getName().equals("intent-filter")) { |
| 2546 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
| 2547 | if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) { |
| 2548 | return null; |
| 2549 | } |
| 2550 | |
| 2551 | s.intents.add(intent); |
| 2552 | } else if (parser.getName().equals("meta-data")) { |
| 2553 | if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData, |
| 2554 | outError)) == null) { |
| 2555 | return null; |
| 2556 | } |
| 2557 | } else { |
| 2558 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2559 | Slog.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2560 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2561 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | XmlUtils.skipCurrentTag(parser); |
| 2563 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2564 | } else { |
| 2565 | outError[0] = "Bad element under <service>: " + parser.getName(); |
| 2566 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | if (!setExported) { |
| 2572 | s.info.exported = s.intents.size() > 0; |
| 2573 | } |
| 2574 | |
| 2575 | return s; |
| 2576 | } |
| 2577 | |
| 2578 | private boolean parseAllMetaData(Resources res, |
| 2579 | XmlPullParser parser, AttributeSet attrs, String tag, |
| 2580 | Component outInfo, String[] outError) |
| 2581 | throws XmlPullParserException, IOException { |
| 2582 | int outerDepth = parser.getDepth(); |
| 2583 | int type; |
| 2584 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2585 | && (type != XmlPullParser.END_TAG |
| 2586 | || parser.getDepth() > outerDepth)) { |
| 2587 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2588 | continue; |
| 2589 | } |
| 2590 | |
| 2591 | if (parser.getName().equals("meta-data")) { |
| 2592 | if ((outInfo.metaData=parseMetaData(res, parser, attrs, |
| 2593 | outInfo.metaData, outError)) == null) { |
| 2594 | return false; |
| 2595 | } |
| 2596 | } else { |
| 2597 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2598 | Slog.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2599 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2600 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | XmlUtils.skipCurrentTag(parser); |
| 2602 | continue; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2603 | } else { |
| 2604 | outError[0] = "Bad element under " + tag + ": " + parser.getName(); |
| 2605 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | } |
| 2608 | } |
| 2609 | return true; |
| 2610 | } |
| 2611 | |
| 2612 | private Bundle parseMetaData(Resources res, |
| 2613 | XmlPullParser parser, AttributeSet attrs, |
| 2614 | Bundle data, String[] outError) |
| 2615 | throws XmlPullParserException, IOException { |
| 2616 | |
| 2617 | TypedArray sa = res.obtainAttributes(attrs, |
| 2618 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 2619 | |
| 2620 | if (data == null) { |
| 2621 | data = new Bundle(); |
| 2622 | } |
| 2623 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2624 | String name = sa.getNonConfigurationString( |
| 2625 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | if (name == null) { |
| 2627 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 2628 | sa.recycle(); |
| 2629 | return null; |
| 2630 | } |
| 2631 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2632 | name = name.intern(); |
| 2633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | TypedValue v = sa.peekValue( |
| 2635 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 2636 | if (v != null && v.resourceId != 0) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2637 | //Slog.i(TAG, "Meta data ref " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | data.putInt(name, v.resourceId); |
| 2639 | } else { |
| 2640 | v = sa.peekValue( |
| 2641 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2642 | //Slog.i(TAG, "Meta data " + name + ": " + v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | if (v != null) { |
| 2644 | if (v.type == TypedValue.TYPE_STRING) { |
| 2645 | CharSequence cs = v.coerceToString(); |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2646 | data.putString(name, cs != null ? cs.toString().intern() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 2648 | data.putBoolean(name, v.data != 0); |
| 2649 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 2650 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 2651 | data.putInt(name, v.data); |
| 2652 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 2653 | data.putFloat(name, v.getFloat()); |
| 2654 | } else { |
| 2655 | if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2656 | 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] | 2657 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2658 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | } else { |
| 2660 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 2661 | data = null; |
| 2662 | } |
| 2663 | } |
| 2664 | } else { |
| 2665 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 2666 | data = null; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | sa.recycle(); |
| 2671 | |
| 2672 | XmlUtils.skipCurrentTag(parser); |
| 2673 | |
| 2674 | return data; |
| 2675 | } |
| 2676 | |
| 2677 | private static final String ANDROID_RESOURCES |
| 2678 | = "http://schemas.android.com/apk/res/android"; |
| 2679 | |
| 2680 | private boolean parseIntent(Resources res, |
| 2681 | XmlPullParser parser, AttributeSet attrs, int flags, |
| 2682 | IntentInfo outInfo, String[] outError, boolean isActivity) |
| 2683 | throws XmlPullParserException, IOException { |
| 2684 | |
| 2685 | TypedArray sa = res.obtainAttributes(attrs, |
| 2686 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 2687 | |
| 2688 | int priority = sa.getInt( |
| 2689 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 2691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | TypedValue v = sa.peekValue( |
| 2693 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 2694 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 2695 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 2696 | } |
| 2697 | |
| 2698 | outInfo.icon = sa.getResourceId( |
| 2699 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2700 | |
| 2701 | outInfo.logo = sa.getResourceId( |
| 2702 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | |
| 2704 | sa.recycle(); |
| 2705 | |
| 2706 | int outerDepth = parser.getDepth(); |
| 2707 | int type; |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2708 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2709 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2710 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | continue; |
| 2712 | } |
| 2713 | |
| 2714 | String nodeName = parser.getName(); |
| 2715 | if (nodeName.equals("action")) { |
| 2716 | String value = attrs.getAttributeValue( |
| 2717 | ANDROID_RESOURCES, "name"); |
| 2718 | if (value == null || value == "") { |
| 2719 | outError[0] = "No value supplied for <android:name>"; |
| 2720 | return false; |
| 2721 | } |
| 2722 | XmlUtils.skipCurrentTag(parser); |
| 2723 | |
| 2724 | outInfo.addAction(value); |
| 2725 | } else if (nodeName.equals("category")) { |
| 2726 | String value = attrs.getAttributeValue( |
| 2727 | ANDROID_RESOURCES, "name"); |
| 2728 | if (value == null || value == "") { |
| 2729 | outError[0] = "No value supplied for <android:name>"; |
| 2730 | return false; |
| 2731 | } |
| 2732 | XmlUtils.skipCurrentTag(parser); |
| 2733 | |
| 2734 | outInfo.addCategory(value); |
| 2735 | |
| 2736 | } else if (nodeName.equals("data")) { |
| 2737 | sa = res.obtainAttributes(attrs, |
| 2738 | com.android.internal.R.styleable.AndroidManifestData); |
| 2739 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2740 | String str = sa.getNonConfigurationString( |
| 2741 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | if (str != null) { |
| 2743 | try { |
| 2744 | outInfo.addDataType(str); |
| 2745 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 2746 | outError[0] = e.toString(); |
| 2747 | sa.recycle(); |
| 2748 | return false; |
| 2749 | } |
| 2750 | } |
| 2751 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2752 | str = sa.getNonConfigurationString( |
| 2753 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | if (str != null) { |
| 2755 | outInfo.addDataScheme(str); |
| 2756 | } |
| 2757 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2758 | String host = sa.getNonConfigurationString( |
| 2759 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 2760 | String port = sa.getNonConfigurationString( |
| 2761 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | if (host != null) { |
| 2763 | outInfo.addDataAuthority(host, port); |
| 2764 | } |
| 2765 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2766 | str = sa.getNonConfigurationString( |
| 2767 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | if (str != null) { |
| 2769 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 2770 | } |
| 2771 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2772 | str = sa.getNonConfigurationString( |
| 2773 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | if (str != null) { |
| 2775 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 2776 | } |
| 2777 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2778 | str = sa.getNonConfigurationString( |
| 2779 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2780 | if (str != null) { |
| 2781 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 2782 | } |
| 2783 | |
| 2784 | sa.recycle(); |
| 2785 | XmlUtils.skipCurrentTag(parser); |
| 2786 | } else if (!RIGID_PARSER) { |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2787 | Slog.w(TAG, "Unknown element under <intent-filter>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2788 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2789 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | XmlUtils.skipCurrentTag(parser); |
| 2791 | } else { |
| 2792 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 2793 | return false; |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2798 | |
| 2799 | if (DEBUG_PARSER) { |
| 2800 | final StringBuilder cats = new StringBuilder("Intent d="); |
| 2801 | cats.append(outInfo.hasDefault); |
| 2802 | cats.append(", cat="); |
| 2803 | |
| 2804 | final Iterator<String> it = outInfo.categoriesIterator(); |
| 2805 | if (it != null) { |
| 2806 | while (it.hasNext()) { |
| 2807 | cats.append(' '); |
| 2808 | cats.append(it.next()); |
| 2809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | } |
Kenny Root | d2d2925 | 2011-08-08 11:27:57 -0700 | [diff] [blame] | 2811 | Slog.d(TAG, cats.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | return true; |
| 2815 | } |
| 2816 | |
| 2817 | public final static class Package { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2818 | public String packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | |
| 2820 | // For now we only support one application per package. |
| 2821 | public final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 2822 | |
| 2823 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 2824 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 2825 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 2826 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 2827 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 2828 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 2829 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 2830 | |
| 2831 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 2832 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2833 | public ArrayList<String> protectedBroadcasts; |
| 2834 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2835 | public ArrayList<String> usesLibraries = null; |
| 2836 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | public String[] usesLibraryFiles = null; |
| 2838 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2839 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2840 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2841 | public ArrayList<String> mAdoptPermissions = null; |
| 2842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | // We store the application meta-data independently to avoid multiple unwanted references |
| 2844 | public Bundle mAppMetaData = null; |
| 2845 | |
| 2846 | // If this is a 3rd party app, this is the path of the zip file. |
| 2847 | public String mPath; |
| 2848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2849 | // The version code declared for this package. |
| 2850 | public int mVersionCode; |
| 2851 | |
| 2852 | // The version name declared for this package. |
| 2853 | public String mVersionName; |
| 2854 | |
| 2855 | // The shared user id that this package wants to use. |
| 2856 | public String mSharedUserId; |
| 2857 | |
| 2858 | // The shared user label that this package wants to use. |
| 2859 | public int mSharedUserLabel; |
| 2860 | |
| 2861 | // Signatures that were read from the package. |
| 2862 | public Signature mSignatures[]; |
| 2863 | |
| 2864 | // For use by package manager service for quick lookup of |
| 2865 | // preferred up order. |
| 2866 | public int mPreferredOrder = 0; |
| 2867 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2868 | // For use by the package manager to keep track of the path to the |
| 2869 | // file an app came from. |
| 2870 | public String mScanPath; |
| 2871 | |
| 2872 | // For use by package manager to keep track of where it has done dexopt. |
| 2873 | public boolean mDidDexOpt; |
| 2874 | |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 2875 | // User set enabled state. |
| 2876 | public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 2877 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2878 | // Whether the package has been stopped. |
| 2879 | public boolean mSetStopped = false; |
| 2880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | // Additional data supplied by callers. |
| 2882 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 2883 | |
| 2884 | // Whether an operation is currently pending on this package |
| 2885 | public boolean mOperationPending; |
| 2886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | /* |
| 2888 | * Applications hardware preferences |
| 2889 | */ |
| 2890 | public final ArrayList<ConfigurationInfo> configPreferences = |
| 2891 | new ArrayList<ConfigurationInfo>(); |
| 2892 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2893 | /* |
| 2894 | * Applications requested features |
| 2895 | */ |
| 2896 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 2897 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 2898 | public int installLocation; |
| 2899 | |
Kenny Root | bcc954d | 2011-08-08 16:19:08 -0700 | [diff] [blame^] | 2900 | /** |
| 2901 | * Digest suitable for comparing whether this package's manifest is the |
| 2902 | * same as another. |
| 2903 | */ |
| 2904 | public ManifestDigest manifestDigest; |
| 2905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | public Package(String _name) { |
| 2907 | packageName = _name; |
| 2908 | applicationInfo.packageName = _name; |
| 2909 | applicationInfo.uid = -1; |
| 2910 | } |
| 2911 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2912 | public void setPackageName(String newName) { |
| 2913 | packageName = newName; |
| 2914 | applicationInfo.packageName = newName; |
| 2915 | for (int i=permissions.size()-1; i>=0; i--) { |
| 2916 | permissions.get(i).setPackageName(newName); |
| 2917 | } |
| 2918 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 2919 | permissionGroups.get(i).setPackageName(newName); |
| 2920 | } |
| 2921 | for (int i=activities.size()-1; i>=0; i--) { |
| 2922 | activities.get(i).setPackageName(newName); |
| 2923 | } |
| 2924 | for (int i=receivers.size()-1; i>=0; i--) { |
| 2925 | receivers.get(i).setPackageName(newName); |
| 2926 | } |
| 2927 | for (int i=providers.size()-1; i>=0; i--) { |
| 2928 | providers.get(i).setPackageName(newName); |
| 2929 | } |
| 2930 | for (int i=services.size()-1; i>=0; i--) { |
| 2931 | services.get(i).setPackageName(newName); |
| 2932 | } |
| 2933 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 2934 | instrumentation.get(i).setPackageName(newName); |
| 2935 | } |
| 2936 | } |
| 2937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | public String toString() { |
| 2939 | return "Package{" |
| 2940 | + Integer.toHexString(System.identityHashCode(this)) |
| 2941 | + " " + packageName + "}"; |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | public static class Component<II extends IntentInfo> { |
| 2946 | public final Package owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2947 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2948 | public final String className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | public Bundle metaData; |
| 2950 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2951 | ComponentName componentName; |
| 2952 | String componentShortName; |
| 2953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | public Component(Package _owner) { |
| 2955 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2956 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2957 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 2961 | owner = args.owner; |
| 2962 | intents = new ArrayList<II>(0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2963 | String name = args.sa.getNonConfigurationString(args.nameRes, 0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2964 | if (name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2965 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2966 | args.outError[0] = args.tag + " does not specify android:name"; |
| 2967 | return; |
| 2968 | } |
| 2969 | |
| 2970 | outInfo.name |
| 2971 | = buildClassName(owner.applicationInfo.packageName, name, args.outError); |
| 2972 | if (outInfo.name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2973 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2974 | args.outError[0] = args.tag + " does not have valid android:name"; |
| 2975 | return; |
| 2976 | } |
| 2977 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2978 | className = outInfo.name; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2979 | |
| 2980 | int iconVal = args.sa.getResourceId(args.iconRes, 0); |
| 2981 | if (iconVal != 0) { |
| 2982 | outInfo.icon = iconVal; |
| 2983 | outInfo.nonLocalizedLabel = null; |
| 2984 | } |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2985 | |
| 2986 | int logoVal = args.sa.getResourceId(args.logoRes, 0); |
| 2987 | if (logoVal != 0) { |
| 2988 | outInfo.logo = logoVal; |
| 2989 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2990 | |
| 2991 | TypedValue v = args.sa.peekValue(args.labelRes); |
| 2992 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 2993 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 2994 | } |
| 2995 | |
| 2996 | outInfo.packageName = owner.packageName; |
| 2997 | } |
| 2998 | |
| 2999 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 3000 | this(args, (PackageItemInfo)outInfo); |
| 3001 | if (args.outError[0] != null) { |
| 3002 | return; |
| 3003 | } |
| 3004 | |
| 3005 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3006 | CharSequence pname; |
| 3007 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 3008 | pname = args.sa.getNonConfigurationString(args.processRes, 0); |
| 3009 | } else { |
| 3010 | // Some older apps have been seen to use a resource reference |
| 3011 | // here that on older builds was ignored (with a warning). We |
| 3012 | // need to continue to do this for them so they don't break. |
| 3013 | pname = args.sa.getNonResourceString(args.processRes); |
| 3014 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3015 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 3016 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3017 | args.flags, args.sepProcesses, args.outError); |
| 3018 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 3019 | |
| 3020 | if (args.descriptionRes != 0) { |
| 3021 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 3022 | } |
| 3023 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3024 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | public Component(Component<II> clone) { |
| 3028 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3029 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3030 | className = clone.className; |
| 3031 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3032 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | public ComponentName getComponentName() { |
| 3036 | if (componentName != null) { |
| 3037 | return componentName; |
| 3038 | } |
| 3039 | if (className != null) { |
| 3040 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 3041 | className); |
| 3042 | } |
| 3043 | return componentName; |
| 3044 | } |
| 3045 | |
| 3046 | public String getComponentShortName() { |
| 3047 | if (componentShortName != null) { |
| 3048 | return componentShortName; |
| 3049 | } |
| 3050 | ComponentName component = getComponentName(); |
| 3051 | if (component != null) { |
| 3052 | componentShortName = component.flattenToShortString(); |
| 3053 | } |
| 3054 | return componentShortName; |
| 3055 | } |
| 3056 | |
| 3057 | public void setPackageName(String packageName) { |
| 3058 | componentName = null; |
| 3059 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | public final static class Permission extends Component<IntentInfo> { |
| 3064 | public final PermissionInfo info; |
| 3065 | public boolean tree; |
| 3066 | public PermissionGroup group; |
| 3067 | |
| 3068 | public Permission(Package _owner) { |
| 3069 | super(_owner); |
| 3070 | info = new PermissionInfo(); |
| 3071 | } |
| 3072 | |
| 3073 | public Permission(Package _owner, PermissionInfo _info) { |
| 3074 | super(_owner); |
| 3075 | info = _info; |
| 3076 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3077 | |
| 3078 | public void setPackageName(String packageName) { |
| 3079 | super.setPackageName(packageName); |
| 3080 | info.packageName = packageName; |
| 3081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | |
| 3083 | public String toString() { |
| 3084 | return "Permission{" |
| 3085 | + Integer.toHexString(System.identityHashCode(this)) |
| 3086 | + " " + info.name + "}"; |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | public final static class PermissionGroup extends Component<IntentInfo> { |
| 3091 | public final PermissionGroupInfo info; |
| 3092 | |
| 3093 | public PermissionGroup(Package _owner) { |
| 3094 | super(_owner); |
| 3095 | info = new PermissionGroupInfo(); |
| 3096 | } |
| 3097 | |
| 3098 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 3099 | super(_owner); |
| 3100 | info = _info; |
| 3101 | } |
| 3102 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3103 | public void setPackageName(String packageName) { |
| 3104 | super.setPackageName(packageName); |
| 3105 | info.packageName = packageName; |
| 3106 | } |
| 3107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | public String toString() { |
| 3109 | return "PermissionGroup{" |
| 3110 | + Integer.toHexString(System.identityHashCode(this)) |
| 3111 | + " " + info.name + "}"; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | private static boolean copyNeeded(int flags, Package p, Bundle metaData) { |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 3116 | if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 3117 | boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 3118 | if (p.applicationInfo.enabled != enabled) { |
| 3119 | return true; |
| 3120 | } |
| 3121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 3123 | && (metaData != null || p.mAppMetaData != null)) { |
| 3124 | return true; |
| 3125 | } |
| 3126 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 3127 | && p.usesLibraryFiles != null) { |
| 3128 | return true; |
| 3129 | } |
| 3130 | return false; |
| 3131 | } |
| 3132 | |
| 3133 | public static ApplicationInfo generateApplicationInfo(Package p, int flags) { |
| 3134 | if (p == null) return null; |
| 3135 | if (!copyNeeded(flags, p, null)) { |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3136 | // CompatibilityMode is global state. It's safe to modify the instance |
| 3137 | // of the package. |
| 3138 | if (!sCompatibilityModeEnabled) { |
| 3139 | p.applicationInfo.disableCompatibilityMode(); |
| 3140 | } |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 3141 | if (p.mSetStopped) { |
| 3142 | p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED; |
| 3143 | } else { |
| 3144 | p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 3145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | return p.applicationInfo; |
| 3147 | } |
| 3148 | |
| 3149 | // Make shallow copy so we can store the metadata/libraries safely |
| 3150 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
| 3151 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 3152 | ai.metaData = p.mAppMetaData; |
| 3153 | } |
| 3154 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 3155 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 3156 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3157 | if (!sCompatibilityModeEnabled) { |
| 3158 | ai.disableCompatibilityMode(); |
| 3159 | } |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 3160 | if (p.mSetStopped) { |
| 3161 | p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED; |
| 3162 | } else { |
| 3163 | p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 3164 | } |
John Reck | 4b7b7cc | 2011-02-02 11:57:44 -0800 | [diff] [blame] | 3165 | if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 3166 | ai.enabled = true; |
Dianne Hackborn | 0ac3031 | 2011-06-17 14:49:23 -0700 | [diff] [blame] | 3167 | } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 3168 | || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
John Reck | 4b7b7cc | 2011-02-02 11:57:44 -0800 | [diff] [blame] | 3169 | ai.enabled = false; |
| 3170 | } |
Dianne Hackborn | 0ac3031 | 2011-06-17 14:49:23 -0700 | [diff] [blame] | 3171 | ai.enabledSetting = p.mSetEnabled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | return ai; |
| 3173 | } |
| 3174 | |
| 3175 | public static final PermissionInfo generatePermissionInfo( |
| 3176 | Permission p, int flags) { |
| 3177 | if (p == null) return null; |
| 3178 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3179 | return p.info; |
| 3180 | } |
| 3181 | PermissionInfo pi = new PermissionInfo(p.info); |
| 3182 | pi.metaData = p.metaData; |
| 3183 | return pi; |
| 3184 | } |
| 3185 | |
| 3186 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 3187 | PermissionGroup pg, int flags) { |
| 3188 | if (pg == null) return null; |
| 3189 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3190 | return pg.info; |
| 3191 | } |
| 3192 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 3193 | pgi.metaData = pg.metaData; |
| 3194 | return pgi; |
| 3195 | } |
| 3196 | |
| 3197 | public final static class Activity extends Component<ActivityIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3198 | public final ActivityInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3200 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 3201 | super(args, _info); |
| 3202 | info = _info; |
| 3203 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3205 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3206 | public void setPackageName(String packageName) { |
| 3207 | super.setPackageName(packageName); |
| 3208 | info.packageName = packageName; |
| 3209 | } |
| 3210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | public String toString() { |
| 3212 | return "Activity{" |
| 3213 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3214 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | public static final ActivityInfo generateActivityInfo(Activity a, |
| 3219 | int flags) { |
| 3220 | if (a == null) return null; |
| 3221 | if (!copyNeeded(flags, a.owner, a.metaData)) { |
| 3222 | return a.info; |
| 3223 | } |
| 3224 | // Make shallow copies so we can store the metadata safely |
| 3225 | ActivityInfo ai = new ActivityInfo(a.info); |
| 3226 | ai.metaData = a.metaData; |
| 3227 | ai.applicationInfo = generateApplicationInfo(a.owner, flags); |
| 3228 | return ai; |
| 3229 | } |
| 3230 | |
| 3231 | public final static class Service extends Component<ServiceIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3232 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3234 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 3235 | super(args, _info); |
| 3236 | info = _info; |
| 3237 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3239 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3240 | public void setPackageName(String packageName) { |
| 3241 | super.setPackageName(packageName); |
| 3242 | info.packageName = packageName; |
| 3243 | } |
| 3244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | public String toString() { |
| 3246 | return "Service{" |
| 3247 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3248 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | public static final ServiceInfo generateServiceInfo(Service s, int flags) { |
| 3253 | if (s == null) return null; |
| 3254 | if (!copyNeeded(flags, s.owner, s.metaData)) { |
| 3255 | return s.info; |
| 3256 | } |
| 3257 | // Make shallow copies so we can store the metadata safely |
| 3258 | ServiceInfo si = new ServiceInfo(s.info); |
| 3259 | si.metaData = s.metaData; |
| 3260 | si.applicationInfo = generateApplicationInfo(s.owner, flags); |
| 3261 | return si; |
| 3262 | } |
| 3263 | |
| 3264 | public final static class Provider extends Component { |
| 3265 | public final ProviderInfo info; |
| 3266 | public boolean syncable; |
| 3267 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3268 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 3269 | super(args, _info); |
| 3270 | info = _info; |
| 3271 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | syncable = false; |
| 3273 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | public Provider(Provider existingProvider) { |
| 3276 | super(existingProvider); |
| 3277 | this.info = existingProvider.info; |
| 3278 | this.syncable = existingProvider.syncable; |
| 3279 | } |
| 3280 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3281 | public void setPackageName(String packageName) { |
| 3282 | super.setPackageName(packageName); |
| 3283 | info.packageName = packageName; |
| 3284 | } |
| 3285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | public String toString() { |
| 3287 | return "Provider{" |
| 3288 | + Integer.toHexString(System.identityHashCode(this)) |
| 3289 | + " " + info.name + "}"; |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | public static final ProviderInfo generateProviderInfo(Provider p, |
| 3294 | int flags) { |
| 3295 | if (p == null) return null; |
| 3296 | if (!copyNeeded(flags, p.owner, p.metaData) |
| 3297 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
| 3298 | || p.info.uriPermissionPatterns == null)) { |
| 3299 | return p.info; |
| 3300 | } |
| 3301 | // Make shallow copies so we can store the metadata safely |
| 3302 | ProviderInfo pi = new ProviderInfo(p.info); |
| 3303 | pi.metaData = p.metaData; |
| 3304 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 3305 | pi.uriPermissionPatterns = null; |
| 3306 | } |
| 3307 | pi.applicationInfo = generateApplicationInfo(p.owner, flags); |
| 3308 | return pi; |
| 3309 | } |
| 3310 | |
| 3311 | public final static class Instrumentation extends Component { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3312 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3314 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 3315 | super(args, _info); |
| 3316 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3318 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3319 | public void setPackageName(String packageName) { |
| 3320 | super.setPackageName(packageName); |
| 3321 | info.packageName = packageName; |
| 3322 | } |
| 3323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | public String toString() { |
| 3325 | return "Instrumentation{" |
| 3326 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3327 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 3332 | Instrumentation i, int flags) { |
| 3333 | if (i == null) return null; |
| 3334 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3335 | return i.info; |
| 3336 | } |
| 3337 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 3338 | ii.metaData = i.metaData; |
| 3339 | return ii; |
| 3340 | } |
| 3341 | |
| 3342 | public static class IntentInfo extends IntentFilter { |
| 3343 | public boolean hasDefault; |
| 3344 | public int labelRes; |
| 3345 | public CharSequence nonLocalizedLabel; |
| 3346 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3347 | public int logo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | public final static class ActivityIntentInfo extends IntentInfo { |
| 3351 | public final Activity activity; |
| 3352 | |
| 3353 | public ActivityIntentInfo(Activity _activity) { |
| 3354 | activity = _activity; |
| 3355 | } |
| 3356 | |
| 3357 | public String toString() { |
| 3358 | return "ActivityIntentInfo{" |
| 3359 | + Integer.toHexString(System.identityHashCode(this)) |
| 3360 | + " " + activity.info.name + "}"; |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | public final static class ServiceIntentInfo extends IntentInfo { |
| 3365 | public final Service service; |
| 3366 | |
| 3367 | public ServiceIntentInfo(Service _service) { |
| 3368 | service = _service; |
| 3369 | } |
| 3370 | |
| 3371 | public String toString() { |
| 3372 | return "ServiceIntentInfo{" |
| 3373 | + Integer.toHexString(System.identityHashCode(this)) |
| 3374 | + " " + service.info.name + "}"; |
| 3375 | } |
| 3376 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3377 | |
| 3378 | /** |
| 3379 | * @hide |
| 3380 | */ |
| 3381 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 3382 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 3383 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | } |