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