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