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