PackageParser.java revision 615e2fa1755ea3b6b8196f783842cd394ad3beb2
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("eat-comment")) { 1080 // Just skip this tag 1081 XmlUtils.skipCurrentTag(parser); 1082 continue; 1083 1084 } else if (RIGID_PARSER) { 1085 outError[0] = "Bad element under <manifest>: " 1086 + parser.getName(); 1087 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1088 return null; 1089 1090 } else { 1091 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName() 1092 + " at " + mArchiveSourcePath + " " 1093 + parser.getPositionDescription()); 1094 XmlUtils.skipCurrentTag(parser); 1095 continue; 1096 } 1097 } 1098 1099 if (!foundApp && pkg.instrumentation.size() == 0) { 1100 outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; 1101 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; 1102 } 1103 1104 final int NP = PackageParser.NEW_PERMISSIONS.length; 1105 StringBuilder implicitPerms = null; 1106 for (int ip=0; ip<NP; ip++) { 1107 final PackageParser.NewPermissionInfo npi 1108 = PackageParser.NEW_PERMISSIONS[ip]; 1109 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { 1110 break; 1111 } 1112 if (!pkg.requestedPermissions.contains(npi.name)) { 1113 if (implicitPerms == null) { 1114 implicitPerms = new StringBuilder(128); 1115 implicitPerms.append(pkg.packageName); 1116 implicitPerms.append(": compat added "); 1117 } else { 1118 implicitPerms.append(' '); 1119 } 1120 implicitPerms.append(npi.name); 1121 pkg.requestedPermissions.add(npi.name); 1122 } 1123 } 1124 if (implicitPerms != null) { 1125 Log.i(TAG, implicitPerms.toString()); 1126 } 1127 1128 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 1129 && pkg.applicationInfo.targetSdkVersion 1130 >= android.os.Build.VERSION_CODES.DONUT)) { 1131 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; 1132 } 1133 if (supportsNormalScreens != 0) { 1134 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; 1135 } 1136 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 1137 && pkg.applicationInfo.targetSdkVersion 1138 >= android.os.Build.VERSION_CODES.DONUT)) { 1139 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; 1140 } 1141 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 1142 && pkg.applicationInfo.targetSdkVersion 1143 >= android.os.Build.VERSION_CODES.GINGERBREAD)) { 1144 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; 1145 } 1146 if (resizeable < 0 || (resizeable > 0 1147 && pkg.applicationInfo.targetSdkVersion 1148 >= android.os.Build.VERSION_CODES.DONUT)) { 1149 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; 1150 } 1151 if (anyDensity < 0 || (anyDensity > 0 1152 && pkg.applicationInfo.targetSdkVersion 1153 >= android.os.Build.VERSION_CODES.DONUT)) { 1154 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; 1155 } 1156 1157 return pkg; 1158 } 1159 1160 private static String buildClassName(String pkg, CharSequence clsSeq, 1161 String[] outError) { 1162 if (clsSeq == null || clsSeq.length() <= 0) { 1163 outError[0] = "Empty class name in package " + pkg; 1164 return null; 1165 } 1166 String cls = clsSeq.toString(); 1167 char c = cls.charAt(0); 1168 if (c == '.') { 1169 return (pkg + cls).intern(); 1170 } 1171 if (cls.indexOf('.') < 0) { 1172 StringBuilder b = new StringBuilder(pkg); 1173 b.append('.'); 1174 b.append(cls); 1175 return b.toString().intern(); 1176 } 1177 if (c >= 'a' && c <= 'z') { 1178 return cls.intern(); 1179 } 1180 outError[0] = "Bad class name " + cls + " in package " + pkg; 1181 return null; 1182 } 1183 1184 private static String buildCompoundName(String pkg, 1185 CharSequence procSeq, String type, String[] outError) { 1186 String proc = procSeq.toString(); 1187 char c = proc.charAt(0); 1188 if (pkg != null && c == ':') { 1189 if (proc.length() < 2) { 1190 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg 1191 + ": must be at least two characters"; 1192 return null; 1193 } 1194 String subName = proc.substring(1); 1195 String nameError = validateName(subName, false); 1196 if (nameError != null) { 1197 outError[0] = "Invalid " + type + " name " + proc + " in package " 1198 + pkg + ": " + nameError; 1199 return null; 1200 } 1201 return (pkg + proc).intern(); 1202 } 1203 String nameError = validateName(proc, true); 1204 if (nameError != null && !"system".equals(proc)) { 1205 outError[0] = "Invalid " + type + " name " + proc + " in package " 1206 + pkg + ": " + nameError; 1207 return null; 1208 } 1209 return proc.intern(); 1210 } 1211 1212 private static String buildProcessName(String pkg, String defProc, 1213 CharSequence procSeq, int flags, String[] separateProcesses, 1214 String[] outError) { 1215 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { 1216 return defProc != null ? defProc : pkg; 1217 } 1218 if (separateProcesses != null) { 1219 for (int i=separateProcesses.length-1; i>=0; i--) { 1220 String sp = separateProcesses[i]; 1221 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { 1222 return pkg; 1223 } 1224 } 1225 } 1226 if (procSeq == null || procSeq.length() <= 0) { 1227 return defProc; 1228 } 1229 return buildCompoundName(pkg, procSeq, "process", outError); 1230 } 1231 1232 private static String buildTaskAffinityName(String pkg, String defProc, 1233 CharSequence procSeq, String[] outError) { 1234 if (procSeq == null) { 1235 return defProc; 1236 } 1237 if (procSeq.length() <= 0) { 1238 return null; 1239 } 1240 return buildCompoundName(pkg, procSeq, "taskAffinity", outError); 1241 } 1242 1243 private PermissionGroup parsePermissionGroup(Package owner, Resources res, 1244 XmlPullParser parser, AttributeSet attrs, String[] outError) 1245 throws XmlPullParserException, IOException { 1246 PermissionGroup perm = new PermissionGroup(owner); 1247 1248 TypedArray sa = res.obtainAttributes(attrs, 1249 com.android.internal.R.styleable.AndroidManifestPermissionGroup); 1250 1251 if (!parsePackageItemInfo(owner, perm.info, outError, 1252 "<permission-group>", sa, 1253 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, 1254 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, 1255 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, 1256 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) { 1257 sa.recycle(); 1258 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1259 return null; 1260 } 1261 1262 perm.info.descriptionRes = sa.getResourceId( 1263 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, 1264 0); 1265 1266 sa.recycle(); 1267 1268 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm, 1269 outError)) { 1270 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1271 return null; 1272 } 1273 1274 owner.permissionGroups.add(perm); 1275 1276 return perm; 1277 } 1278 1279 private Permission parsePermission(Package owner, Resources res, 1280 XmlPullParser parser, AttributeSet attrs, String[] outError) 1281 throws XmlPullParserException, IOException { 1282 Permission perm = new Permission(owner); 1283 1284 TypedArray sa = res.obtainAttributes(attrs, 1285 com.android.internal.R.styleable.AndroidManifestPermission); 1286 1287 if (!parsePackageItemInfo(owner, perm.info, outError, 1288 "<permission>", sa, 1289 com.android.internal.R.styleable.AndroidManifestPermission_name, 1290 com.android.internal.R.styleable.AndroidManifestPermission_label, 1291 com.android.internal.R.styleable.AndroidManifestPermission_icon, 1292 com.android.internal.R.styleable.AndroidManifestPermission_logo)) { 1293 sa.recycle(); 1294 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1295 return null; 1296 } 1297 1298 // Note: don't allow this value to be a reference to a resource 1299 // that may change. 1300 perm.info.group = sa.getNonResourceString( 1301 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); 1302 if (perm.info.group != null) { 1303 perm.info.group = perm.info.group.intern(); 1304 } 1305 1306 perm.info.descriptionRes = sa.getResourceId( 1307 com.android.internal.R.styleable.AndroidManifestPermission_description, 1308 0); 1309 1310 perm.info.protectionLevel = sa.getInt( 1311 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, 1312 PermissionInfo.PROTECTION_NORMAL); 1313 1314 sa.recycle(); 1315 1316 if (perm.info.protectionLevel == -1) { 1317 outError[0] = "<permission> does not specify protectionLevel"; 1318 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1319 return null; 1320 } 1321 1322 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, 1323 outError)) { 1324 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1325 return null; 1326 } 1327 1328 owner.permissions.add(perm); 1329 1330 return perm; 1331 } 1332 1333 private Permission parsePermissionTree(Package owner, Resources res, 1334 XmlPullParser parser, AttributeSet attrs, String[] outError) 1335 throws XmlPullParserException, IOException { 1336 Permission perm = new Permission(owner); 1337 1338 TypedArray sa = res.obtainAttributes(attrs, 1339 com.android.internal.R.styleable.AndroidManifestPermissionTree); 1340 1341 if (!parsePackageItemInfo(owner, perm.info, outError, 1342 "<permission-tree>", sa, 1343 com.android.internal.R.styleable.AndroidManifestPermissionTree_name, 1344 com.android.internal.R.styleable.AndroidManifestPermissionTree_label, 1345 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, 1346 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) { 1347 sa.recycle(); 1348 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1349 return null; 1350 } 1351 1352 sa.recycle(); 1353 1354 int index = perm.info.name.indexOf('.'); 1355 if (index > 0) { 1356 index = perm.info.name.indexOf('.', index+1); 1357 } 1358 if (index < 0) { 1359 outError[0] = "<permission-tree> name has less than three segments: " 1360 + perm.info.name; 1361 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1362 return null; 1363 } 1364 1365 perm.info.descriptionRes = 0; 1366 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; 1367 perm.tree = true; 1368 1369 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm, 1370 outError)) { 1371 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1372 return null; 1373 } 1374 1375 owner.permissions.add(perm); 1376 1377 return perm; 1378 } 1379 1380 private Instrumentation parseInstrumentation(Package owner, Resources res, 1381 XmlPullParser parser, AttributeSet attrs, String[] outError) 1382 throws XmlPullParserException, IOException { 1383 TypedArray sa = res.obtainAttributes(attrs, 1384 com.android.internal.R.styleable.AndroidManifestInstrumentation); 1385 1386 if (mParseInstrumentationArgs == null) { 1387 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, 1388 com.android.internal.R.styleable.AndroidManifestInstrumentation_name, 1389 com.android.internal.R.styleable.AndroidManifestInstrumentation_label, 1390 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, 1391 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo); 1392 mParseInstrumentationArgs.tag = "<instrumentation>"; 1393 } 1394 1395 mParseInstrumentationArgs.sa = sa; 1396 1397 Instrumentation a = new Instrumentation(mParseInstrumentationArgs, 1398 new InstrumentationInfo()); 1399 if (outError[0] != null) { 1400 sa.recycle(); 1401 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1402 return null; 1403 } 1404 1405 String str; 1406 // Note: don't allow this value to be a reference to a resource 1407 // that may change. 1408 str = sa.getNonResourceString( 1409 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); 1410 a.info.targetPackage = str != null ? str.intern() : null; 1411 1412 a.info.handleProfiling = sa.getBoolean( 1413 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, 1414 false); 1415 1416 a.info.functionalTest = sa.getBoolean( 1417 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, 1418 false); 1419 1420 sa.recycle(); 1421 1422 if (a.info.targetPackage == null) { 1423 outError[0] = "<instrumentation> does not specify targetPackage"; 1424 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1425 return null; 1426 } 1427 1428 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a, 1429 outError)) { 1430 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1431 return null; 1432 } 1433 1434 owner.instrumentation.add(a); 1435 1436 return a; 1437 } 1438 1439 private boolean parseApplication(Package owner, Resources res, 1440 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) 1441 throws XmlPullParserException, IOException { 1442 final ApplicationInfo ai = owner.applicationInfo; 1443 final String pkgName = owner.applicationInfo.packageName; 1444 1445 TypedArray sa = res.obtainAttributes(attrs, 1446 com.android.internal.R.styleable.AndroidManifestApplication); 1447 1448 String name = sa.getNonConfigurationString( 1449 com.android.internal.R.styleable.AndroidManifestApplication_name, 0); 1450 if (name != null) { 1451 ai.className = buildClassName(pkgName, name, outError); 1452 if (ai.className == null) { 1453 sa.recycle(); 1454 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1455 return false; 1456 } 1457 } 1458 1459 String manageSpaceActivity = sa.getNonConfigurationString( 1460 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0); 1461 if (manageSpaceActivity != null) { 1462 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, 1463 outError); 1464 } 1465 1466 boolean allowBackup = sa.getBoolean( 1467 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); 1468 if (allowBackup) { 1469 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; 1470 1471 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant 1472 // if backup is possible for the given application. 1473 String backupAgent = sa.getNonConfigurationString( 1474 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0); 1475 if (backupAgent != null) { 1476 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); 1477 if (false) { 1478 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName 1479 + " from " + pkgName + "+" + backupAgent); 1480 } 1481 1482 if (sa.getBoolean( 1483 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, 1484 true)) { 1485 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; 1486 } 1487 if (sa.getBoolean( 1488 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, 1489 false)) { 1490 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; 1491 } 1492 } 1493 } 1494 1495 TypedValue v = sa.peekValue( 1496 com.android.internal.R.styleable.AndroidManifestApplication_label); 1497 if (v != null && (ai.labelRes=v.resourceId) == 0) { 1498 ai.nonLocalizedLabel = v.coerceToString(); 1499 } 1500 1501 int defaultTheme = 0; 1502 if (owner.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { 1503 // As of honeycomb, the default application theme is holographic. 1504 defaultTheme = android.R.style.Theme_Holo; 1505 } 1506 1507 ai.icon = sa.getResourceId( 1508 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); 1509 ai.logo = sa.getResourceId( 1510 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0); 1511 ai.theme = sa.getResourceId( 1512 com.android.internal.R.styleable.AndroidManifestApplication_theme, defaultTheme); 1513 ai.descriptionRes = sa.getResourceId( 1514 com.android.internal.R.styleable.AndroidManifestApplication_description, 0); 1515 1516 if ((flags&PARSE_IS_SYSTEM) != 0) { 1517 if (sa.getBoolean( 1518 com.android.internal.R.styleable.AndroidManifestApplication_persistent, 1519 false)) { 1520 ai.flags |= ApplicationInfo.FLAG_PERSISTENT; 1521 } 1522 } 1523 1524 if ((flags & PARSE_FORWARD_LOCK) != 0) { 1525 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK; 1526 } 1527 1528 if ((flags & PARSE_ON_SDCARD) != 0) { 1529 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; 1530 } 1531 1532 if (sa.getBoolean( 1533 com.android.internal.R.styleable.AndroidManifestApplication_debuggable, 1534 false)) { 1535 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; 1536 } 1537 1538 if (sa.getBoolean( 1539 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, 1540 false)) { 1541 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; 1542 } 1543 1544 boolean hardwareAccelerated = sa.getBoolean( 1545 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, 1546 false); 1547 1548 if (sa.getBoolean( 1549 com.android.internal.R.styleable.AndroidManifestApplication_hasCode, 1550 true)) { 1551 ai.flags |= ApplicationInfo.FLAG_HAS_CODE; 1552 } 1553 1554 if (sa.getBoolean( 1555 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, 1556 false)) { 1557 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; 1558 } 1559 1560 if (sa.getBoolean( 1561 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, 1562 true)) { 1563 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; 1564 } 1565 1566 if (sa.getBoolean( 1567 com.android.internal.R.styleable.AndroidManifestApplication_testOnly, 1568 false)) { 1569 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; 1570 } 1571 1572 if (sa.getBoolean( 1573 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt, 1574 false)) { 1575 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT; 1576 } 1577 1578 String str; 1579 str = sa.getNonConfigurationString( 1580 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); 1581 ai.permission = (str != null && str.length() > 0) ? str.intern() : null; 1582 1583 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { 1584 str = sa.getNonConfigurationString( 1585 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0); 1586 } else { 1587 // Some older apps have been seen to use a resource reference 1588 // here that on older builds was ignored (with a warning). We 1589 // need to continue to do this for them so they don't break. 1590 str = sa.getNonResourceString( 1591 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); 1592 } 1593 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, 1594 str, outError); 1595 1596 if (outError[0] == null) { 1597 CharSequence pname; 1598 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { 1599 pname = sa.getNonConfigurationString( 1600 com.android.internal.R.styleable.AndroidManifestApplication_process, 0); 1601 } else { 1602 // Some older apps have been seen to use a resource reference 1603 // here that on older builds was ignored (with a warning). We 1604 // need to continue to do this for them so they don't break. 1605 pname = sa.getNonResourceString( 1606 com.android.internal.R.styleable.AndroidManifestApplication_process); 1607 } 1608 ai.processName = buildProcessName(ai.packageName, null, pname, 1609 flags, mSeparateProcesses, outError); 1610 1611 ai.enabled = sa.getBoolean( 1612 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); 1613 1614 if (false) { 1615 if (sa.getBoolean( 1616 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, 1617 false)) { 1618 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE; 1619 1620 // A heavy-weight application can not be in a custom process. 1621 // We can do direct compare because we intern all strings. 1622 if (ai.processName != null && ai.processName != ai.packageName) { 1623 outError[0] = "cantSaveState applications can not use custom processes"; 1624 } 1625 } 1626 } 1627 } 1628 1629 sa.recycle(); 1630 1631 if (outError[0] != null) { 1632 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1633 return false; 1634 } 1635 1636 final int innerDepth = parser.getDepth(); 1637 1638 int type; 1639 while ((type=parser.next()) != parser.END_DOCUMENT 1640 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) { 1641 if (type == parser.END_TAG || type == parser.TEXT) { 1642 continue; 1643 } 1644 1645 String tagName = parser.getName(); 1646 if (tagName.equals("activity")) { 1647 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false, 1648 hardwareAccelerated); 1649 if (a == null) { 1650 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1651 return false; 1652 } 1653 1654 owner.activities.add(a); 1655 1656 } else if (tagName.equals("receiver")) { 1657 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false); 1658 if (a == null) { 1659 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1660 return false; 1661 } 1662 1663 owner.receivers.add(a); 1664 1665 } else if (tagName.equals("service")) { 1666 Service s = parseService(owner, res, parser, attrs, flags, outError); 1667 if (s == null) { 1668 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1669 return false; 1670 } 1671 1672 owner.services.add(s); 1673 1674 } else if (tagName.equals("provider")) { 1675 Provider p = parseProvider(owner, res, parser, attrs, flags, outError); 1676 if (p == null) { 1677 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1678 return false; 1679 } 1680 1681 owner.providers.add(p); 1682 1683 } else if (tagName.equals("activity-alias")) { 1684 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError); 1685 if (a == null) { 1686 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1687 return false; 1688 } 1689 1690 owner.activities.add(a); 1691 1692 } else if (parser.getName().equals("meta-data")) { 1693 // note: application meta-data is stored off to the side, so it can 1694 // remain null in the primary copy (we like to avoid extra copies because 1695 // it can be large) 1696 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData, 1697 outError)) == null) { 1698 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1699 return false; 1700 } 1701 1702 } else if (tagName.equals("uses-library")) { 1703 sa = res.obtainAttributes(attrs, 1704 com.android.internal.R.styleable.AndroidManifestUsesLibrary); 1705 1706 // Note: don't allow this value to be a reference to a resource 1707 // that may change. 1708 String lname = sa.getNonResourceString( 1709 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); 1710 boolean req = sa.getBoolean( 1711 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, 1712 true); 1713 1714 sa.recycle(); 1715 1716 if (lname != null) { 1717 if (req) { 1718 if (owner.usesLibraries == null) { 1719 owner.usesLibraries = new ArrayList<String>(); 1720 } 1721 if (!owner.usesLibraries.contains(lname)) { 1722 owner.usesLibraries.add(lname.intern()); 1723 } 1724 } else { 1725 if (owner.usesOptionalLibraries == null) { 1726 owner.usesOptionalLibraries = new ArrayList<String>(); 1727 } 1728 if (!owner.usesOptionalLibraries.contains(lname)) { 1729 owner.usesOptionalLibraries.add(lname.intern()); 1730 } 1731 } 1732 } 1733 1734 XmlUtils.skipCurrentTag(parser); 1735 1736 } else if (tagName.equals("uses-package")) { 1737 // Dependencies for app installers; we don't currently try to 1738 // enforce this. 1739 XmlUtils.skipCurrentTag(parser); 1740 1741 } else { 1742 if (!RIGID_PARSER) { 1743 Log.w(TAG, "Unknown element under <application>: " + tagName 1744 + " at " + mArchiveSourcePath + " " 1745 + parser.getPositionDescription()); 1746 XmlUtils.skipCurrentTag(parser); 1747 continue; 1748 } else { 1749 outError[0] = "Bad element under <application>: " + tagName; 1750 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; 1751 return false; 1752 } 1753 } 1754 } 1755 1756 return true; 1757 } 1758 1759 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, 1760 String[] outError, String tag, TypedArray sa, 1761 int nameRes, int labelRes, int iconRes, int logoRes) { 1762 String name = sa.getNonConfigurationString(nameRes, 0); 1763 if (name == null) { 1764 outError[0] = tag + " does not specify android:name"; 1765 return false; 1766 } 1767 1768 outInfo.name 1769 = buildClassName(owner.applicationInfo.packageName, name, outError); 1770 if (outInfo.name == null) { 1771 return false; 1772 } 1773 1774 int iconVal = sa.getResourceId(iconRes, 0); 1775 if (iconVal != 0) { 1776 outInfo.icon = iconVal; 1777 outInfo.nonLocalizedLabel = null; 1778 } 1779 1780 int logoVal = sa.getResourceId(logoRes, 0); 1781 if (logoVal != 0) { 1782 outInfo.logo = logoVal; 1783 } 1784 1785 TypedValue v = sa.peekValue(labelRes); 1786 if (v != null && (outInfo.labelRes=v.resourceId) == 0) { 1787 outInfo.nonLocalizedLabel = v.coerceToString(); 1788 } 1789 1790 outInfo.packageName = owner.packageName; 1791 1792 return true; 1793 } 1794 1795 private Activity parseActivity(Package owner, Resources res, 1796 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError, 1797 boolean receiver, boolean hardwareAccelerated) 1798 throws XmlPullParserException, IOException { 1799 TypedArray sa = res.obtainAttributes(attrs, 1800 com.android.internal.R.styleable.AndroidManifestActivity); 1801 1802 if (mParseActivityArgs == null) { 1803 mParseActivityArgs = new ParseComponentArgs(owner, outError, 1804 com.android.internal.R.styleable.AndroidManifestActivity_name, 1805 com.android.internal.R.styleable.AndroidManifestActivity_label, 1806 com.android.internal.R.styleable.AndroidManifestActivity_icon, 1807 com.android.internal.R.styleable.AndroidManifestActivity_logo, 1808 mSeparateProcesses, 1809 com.android.internal.R.styleable.AndroidManifestActivity_process, 1810 com.android.internal.R.styleable.AndroidManifestActivity_description, 1811 com.android.internal.R.styleable.AndroidManifestActivity_enabled); 1812 } 1813 1814 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; 1815 mParseActivityArgs.sa = sa; 1816 mParseActivityArgs.flags = flags; 1817 1818 Activity a = new Activity(mParseActivityArgs, new ActivityInfo()); 1819 if (outError[0] != null) { 1820 sa.recycle(); 1821 return null; 1822 } 1823 1824 final boolean setExported = sa.hasValue( 1825 com.android.internal.R.styleable.AndroidManifestActivity_exported); 1826 if (setExported) { 1827 a.info.exported = sa.getBoolean( 1828 com.android.internal.R.styleable.AndroidManifestActivity_exported, false); 1829 } 1830 1831 a.info.theme = sa.getResourceId( 1832 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0); 1833 1834 String str; 1835 str = sa.getNonConfigurationString( 1836 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0); 1837 if (str == null) { 1838 a.info.permission = owner.applicationInfo.permission; 1839 } else { 1840 a.info.permission = str.length() > 0 ? str.toString().intern() : null; 1841 } 1842 1843 str = sa.getNonConfigurationString( 1844 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0); 1845 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, 1846 owner.applicationInfo.taskAffinity, str, outError); 1847 1848 a.info.flags = 0; 1849 if (sa.getBoolean( 1850 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess, 1851 false)) { 1852 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; 1853 } 1854 1855 if (sa.getBoolean( 1856 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch, 1857 false)) { 1858 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; 1859 } 1860 1861 if (sa.getBoolean( 1862 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch, 1863 false)) { 1864 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; 1865 } 1866 1867 if (sa.getBoolean( 1868 com.android.internal.R.styleable.AndroidManifestActivity_noHistory, 1869 false)) { 1870 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; 1871 } 1872 1873 if (sa.getBoolean( 1874 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState, 1875 false)) { 1876 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; 1877 } 1878 1879 if (sa.getBoolean( 1880 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded, 1881 false)) { 1882 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; 1883 } 1884 1885 if (sa.getBoolean( 1886 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents, 1887 false)) { 1888 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; 1889 } 1890 1891 if (sa.getBoolean( 1892 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting, 1893 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { 1894 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; 1895 } 1896 1897 if (sa.getBoolean( 1898 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, 1899 false)) { 1900 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; 1901 } 1902 1903 if (sa.getBoolean( 1904 com.android.internal.R.styleable.AndroidManifestActivity_immersive, 1905 false)) { 1906 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; 1907 } 1908 1909 if (!receiver) { 1910 if (sa.getBoolean( 1911 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated, 1912 hardwareAccelerated)) { 1913 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; 1914 } 1915 1916 a.info.launchMode = sa.getInt( 1917 com.android.internal.R.styleable.AndroidManifestActivity_launchMode, 1918 ActivityInfo.LAUNCH_MULTIPLE); 1919 a.info.screenOrientation = sa.getInt( 1920 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation, 1921 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 1922 a.info.configChanges = sa.getInt( 1923 com.android.internal.R.styleable.AndroidManifestActivity_configChanges, 1924 0); 1925 a.info.softInputMode = sa.getInt( 1926 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode, 1927 0); 1928 } else { 1929 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; 1930 a.info.configChanges = 0; 1931 } 1932 1933 sa.recycle(); 1934 1935 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { 1936 // A heavy-weight application can not have receives in its main process 1937 // We can do direct compare because we intern all strings. 1938 if (a.info.processName == owner.packageName) { 1939 outError[0] = "Heavy-weight applications can not have receivers in main process"; 1940 } 1941 } 1942 1943 if (outError[0] != null) { 1944 return null; 1945 } 1946 1947 int outerDepth = parser.getDepth(); 1948 int type; 1949 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 1950 && (type != XmlPullParser.END_TAG 1951 || parser.getDepth() > outerDepth)) { 1952 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 1953 continue; 1954 } 1955 1956 if (parser.getName().equals("intent-filter")) { 1957 ActivityIntentInfo intent = new ActivityIntentInfo(a); 1958 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) { 1959 return null; 1960 } 1961 if (intent.countActions() == 0) { 1962 Log.w(TAG, "No actions in intent filter at " 1963 + mArchiveSourcePath + " " 1964 + parser.getPositionDescription()); 1965 } else { 1966 a.intents.add(intent); 1967 } 1968 } else if (parser.getName().equals("meta-data")) { 1969 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, 1970 outError)) == null) { 1971 return null; 1972 } 1973 } else { 1974 if (!RIGID_PARSER) { 1975 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); 1976 if (receiver) { 1977 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName() 1978 + " at " + mArchiveSourcePath + " " 1979 + parser.getPositionDescription()); 1980 } else { 1981 Log.w(TAG, "Unknown element under <activity>: " + parser.getName() 1982 + " at " + mArchiveSourcePath + " " 1983 + parser.getPositionDescription()); 1984 } 1985 XmlUtils.skipCurrentTag(parser); 1986 continue; 1987 } 1988 if (receiver) { 1989 outError[0] = "Bad element under <receiver>: " + parser.getName(); 1990 } else { 1991 outError[0] = "Bad element under <activity>: " + parser.getName(); 1992 } 1993 return null; 1994 } 1995 } 1996 1997 if (!setExported) { 1998 a.info.exported = a.intents.size() > 0; 1999 } 2000 2001 return a; 2002 } 2003 2004 private Activity parseActivityAlias(Package owner, Resources res, 2005 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) 2006 throws XmlPullParserException, IOException { 2007 TypedArray sa = res.obtainAttributes(attrs, 2008 com.android.internal.R.styleable.AndroidManifestActivityAlias); 2009 2010 String targetActivity = sa.getNonConfigurationString( 2011 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0); 2012 if (targetActivity == null) { 2013 outError[0] = "<activity-alias> does not specify android:targetActivity"; 2014 sa.recycle(); 2015 return null; 2016 } 2017 2018 targetActivity = buildClassName(owner.applicationInfo.packageName, 2019 targetActivity, outError); 2020 if (targetActivity == null) { 2021 sa.recycle(); 2022 return null; 2023 } 2024 2025 if (mParseActivityAliasArgs == null) { 2026 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, 2027 com.android.internal.R.styleable.AndroidManifestActivityAlias_name, 2028 com.android.internal.R.styleable.AndroidManifestActivityAlias_label, 2029 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, 2030 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, 2031 mSeparateProcesses, 2032 0, 2033 com.android.internal.R.styleable.AndroidManifestActivityAlias_description, 2034 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); 2035 mParseActivityAliasArgs.tag = "<activity-alias>"; 2036 } 2037 2038 mParseActivityAliasArgs.sa = sa; 2039 mParseActivityAliasArgs.flags = flags; 2040 2041 Activity target = null; 2042 2043 final int NA = owner.activities.size(); 2044 for (int i=0; i<NA; i++) { 2045 Activity t = owner.activities.get(i); 2046 if (targetActivity.equals(t.info.name)) { 2047 target = t; 2048 break; 2049 } 2050 } 2051 2052 if (target == null) { 2053 outError[0] = "<activity-alias> target activity " + targetActivity 2054 + " not found in manifest"; 2055 sa.recycle(); 2056 return null; 2057 } 2058 2059 ActivityInfo info = new ActivityInfo(); 2060 info.targetActivity = targetActivity; 2061 info.configChanges = target.info.configChanges; 2062 info.flags = target.info.flags; 2063 info.icon = target.info.icon; 2064 info.logo = target.info.logo; 2065 info.labelRes = target.info.labelRes; 2066 info.nonLocalizedLabel = target.info.nonLocalizedLabel; 2067 info.launchMode = target.info.launchMode; 2068 info.processName = target.info.processName; 2069 if (info.descriptionRes == 0) { 2070 info.descriptionRes = target.info.descriptionRes; 2071 } 2072 info.screenOrientation = target.info.screenOrientation; 2073 info.taskAffinity = target.info.taskAffinity; 2074 info.theme = target.info.theme; 2075 2076 Activity a = new Activity(mParseActivityAliasArgs, info); 2077 if (outError[0] != null) { 2078 sa.recycle(); 2079 return null; 2080 } 2081 2082 final boolean setExported = sa.hasValue( 2083 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); 2084 if (setExported) { 2085 a.info.exported = sa.getBoolean( 2086 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); 2087 } 2088 2089 String str; 2090 str = sa.getNonConfigurationString( 2091 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); 2092 if (str != null) { 2093 a.info.permission = str.length() > 0 ? str.toString().intern() : null; 2094 } 2095 2096 sa.recycle(); 2097 2098 if (outError[0] != null) { 2099 return null; 2100 } 2101 2102 int outerDepth = parser.getDepth(); 2103 int type; 2104 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 2105 && (type != XmlPullParser.END_TAG 2106 || parser.getDepth() > outerDepth)) { 2107 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 2108 continue; 2109 } 2110 2111 if (parser.getName().equals("intent-filter")) { 2112 ActivityIntentInfo intent = new ActivityIntentInfo(a); 2113 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) { 2114 return null; 2115 } 2116 if (intent.countActions() == 0) { 2117 Log.w(TAG, "No actions in intent filter at " 2118 + mArchiveSourcePath + " " 2119 + parser.getPositionDescription()); 2120 } else { 2121 a.intents.add(intent); 2122 } 2123 } else if (parser.getName().equals("meta-data")) { 2124 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, 2125 outError)) == null) { 2126 return null; 2127 } 2128 } else { 2129 if (!RIGID_PARSER) { 2130 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() 2131 + " at " + mArchiveSourcePath + " " 2132 + parser.getPositionDescription()); 2133 XmlUtils.skipCurrentTag(parser); 2134 continue; 2135 } 2136 outError[0] = "Bad element under <activity-alias>: " + parser.getName(); 2137 return null; 2138 } 2139 } 2140 2141 if (!setExported) { 2142 a.info.exported = a.intents.size() > 0; 2143 } 2144 2145 return a; 2146 } 2147 2148 private Provider parseProvider(Package owner, Resources res, 2149 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) 2150 throws XmlPullParserException, IOException { 2151 TypedArray sa = res.obtainAttributes(attrs, 2152 com.android.internal.R.styleable.AndroidManifestProvider); 2153 2154 if (mParseProviderArgs == null) { 2155 mParseProviderArgs = new ParseComponentArgs(owner, outError, 2156 com.android.internal.R.styleable.AndroidManifestProvider_name, 2157 com.android.internal.R.styleable.AndroidManifestProvider_label, 2158 com.android.internal.R.styleable.AndroidManifestProvider_icon, 2159 com.android.internal.R.styleable.AndroidManifestProvider_logo, 2160 mSeparateProcesses, 2161 com.android.internal.R.styleable.AndroidManifestProvider_process, 2162 com.android.internal.R.styleable.AndroidManifestProvider_description, 2163 com.android.internal.R.styleable.AndroidManifestProvider_enabled); 2164 mParseProviderArgs.tag = "<provider>"; 2165 } 2166 2167 mParseProviderArgs.sa = sa; 2168 mParseProviderArgs.flags = flags; 2169 2170 Provider p = new Provider(mParseProviderArgs, new ProviderInfo()); 2171 if (outError[0] != null) { 2172 sa.recycle(); 2173 return null; 2174 } 2175 2176 p.info.exported = sa.getBoolean( 2177 com.android.internal.R.styleable.AndroidManifestProvider_exported, true); 2178 2179 String cpname = sa.getNonConfigurationString( 2180 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); 2181 2182 p.info.isSyncable = sa.getBoolean( 2183 com.android.internal.R.styleable.AndroidManifestProvider_syncable, 2184 false); 2185 2186 String permission = sa.getNonConfigurationString( 2187 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); 2188 String str = sa.getNonConfigurationString( 2189 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); 2190 if (str == null) { 2191 str = permission; 2192 } 2193 if (str == null) { 2194 p.info.readPermission = owner.applicationInfo.permission; 2195 } else { 2196 p.info.readPermission = 2197 str.length() > 0 ? str.toString().intern() : null; 2198 } 2199 str = sa.getNonConfigurationString( 2200 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); 2201 if (str == null) { 2202 str = permission; 2203 } 2204 if (str == null) { 2205 p.info.writePermission = owner.applicationInfo.permission; 2206 } else { 2207 p.info.writePermission = 2208 str.length() > 0 ? str.toString().intern() : null; 2209 } 2210 2211 p.info.grantUriPermissions = sa.getBoolean( 2212 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, 2213 false); 2214 2215 p.info.multiprocess = sa.getBoolean( 2216 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, 2217 false); 2218 2219 p.info.initOrder = sa.getInt( 2220 com.android.internal.R.styleable.AndroidManifestProvider_initOrder, 2221 0); 2222 2223 sa.recycle(); 2224 2225 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { 2226 // A heavy-weight application can not have providers in its main process 2227 // We can do direct compare because we intern all strings. 2228 if (p.info.processName == owner.packageName) { 2229 outError[0] = "Heavy-weight applications can not have providers in main process"; 2230 return null; 2231 } 2232 } 2233 2234 if (cpname == null) { 2235 outError[0] = "<provider> does not incude authorities attribute"; 2236 return null; 2237 } 2238 p.info.authority = cpname.intern(); 2239 2240 if (!parseProviderTags(res, parser, attrs, p, outError)) { 2241 return null; 2242 } 2243 2244 return p; 2245 } 2246 2247 private boolean parseProviderTags(Resources res, 2248 XmlPullParser parser, AttributeSet attrs, 2249 Provider outInfo, String[] outError) 2250 throws XmlPullParserException, IOException { 2251 int outerDepth = parser.getDepth(); 2252 int type; 2253 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 2254 && (type != XmlPullParser.END_TAG 2255 || parser.getDepth() > outerDepth)) { 2256 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 2257 continue; 2258 } 2259 2260 if (parser.getName().equals("meta-data")) { 2261 if ((outInfo.metaData=parseMetaData(res, parser, attrs, 2262 outInfo.metaData, outError)) == null) { 2263 return false; 2264 } 2265 2266 } else if (parser.getName().equals("grant-uri-permission")) { 2267 TypedArray sa = res.obtainAttributes(attrs, 2268 com.android.internal.R.styleable.AndroidManifestGrantUriPermission); 2269 2270 PatternMatcher pa = null; 2271 2272 String str = sa.getNonConfigurationString( 2273 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); 2274 if (str != null) { 2275 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); 2276 } 2277 2278 str = sa.getNonConfigurationString( 2279 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); 2280 if (str != null) { 2281 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); 2282 } 2283 2284 str = sa.getNonConfigurationString( 2285 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); 2286 if (str != null) { 2287 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); 2288 } 2289 2290 sa.recycle(); 2291 2292 if (pa != null) { 2293 if (outInfo.info.uriPermissionPatterns == null) { 2294 outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; 2295 outInfo.info.uriPermissionPatterns[0] = pa; 2296 } else { 2297 final int N = outInfo.info.uriPermissionPatterns.length; 2298 PatternMatcher[] newp = new PatternMatcher[N+1]; 2299 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); 2300 newp[N] = pa; 2301 outInfo.info.uriPermissionPatterns = newp; 2302 } 2303 outInfo.info.grantUriPermissions = true; 2304 } else { 2305 if (!RIGID_PARSER) { 2306 Log.w(TAG, "Unknown element under <path-permission>: " 2307 + parser.getName() + " at " + mArchiveSourcePath + " " 2308 + parser.getPositionDescription()); 2309 XmlUtils.skipCurrentTag(parser); 2310 continue; 2311 } 2312 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; 2313 return false; 2314 } 2315 XmlUtils.skipCurrentTag(parser); 2316 2317 } else if (parser.getName().equals("path-permission")) { 2318 TypedArray sa = res.obtainAttributes(attrs, 2319 com.android.internal.R.styleable.AndroidManifestPathPermission); 2320 2321 PathPermission pa = null; 2322 2323 String permission = sa.getNonConfigurationString( 2324 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); 2325 String readPermission = sa.getNonConfigurationString( 2326 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); 2327 if (readPermission == null) { 2328 readPermission = permission; 2329 } 2330 String writePermission = sa.getNonConfigurationString( 2331 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); 2332 if (writePermission == null) { 2333 writePermission = permission; 2334 } 2335 2336 boolean havePerm = false; 2337 if (readPermission != null) { 2338 readPermission = readPermission.intern(); 2339 havePerm = true; 2340 } 2341 if (writePermission != null) { 2342 writePermission = writePermission.intern(); 2343 havePerm = true; 2344 } 2345 2346 if (!havePerm) { 2347 if (!RIGID_PARSER) { 2348 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: " 2349 + parser.getName() + " at " + mArchiveSourcePath + " " 2350 + parser.getPositionDescription()); 2351 XmlUtils.skipCurrentTag(parser); 2352 continue; 2353 } 2354 outError[0] = "No readPermission or writePermssion for <path-permission>"; 2355 return false; 2356 } 2357 2358 String path = sa.getNonConfigurationString( 2359 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); 2360 if (path != null) { 2361 pa = new PathPermission(path, 2362 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); 2363 } 2364 2365 path = sa.getNonConfigurationString( 2366 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); 2367 if (path != null) { 2368 pa = new PathPermission(path, 2369 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); 2370 } 2371 2372 path = sa.getNonConfigurationString( 2373 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); 2374 if (path != null) { 2375 pa = new PathPermission(path, 2376 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); 2377 } 2378 2379 sa.recycle(); 2380 2381 if (pa != null) { 2382 if (outInfo.info.pathPermissions == null) { 2383 outInfo.info.pathPermissions = new PathPermission[1]; 2384 outInfo.info.pathPermissions[0] = pa; 2385 } else { 2386 final int N = outInfo.info.pathPermissions.length; 2387 PathPermission[] newp = new PathPermission[N+1]; 2388 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); 2389 newp[N] = pa; 2390 outInfo.info.pathPermissions = newp; 2391 } 2392 } else { 2393 if (!RIGID_PARSER) { 2394 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " 2395 + parser.getName() + " at " + mArchiveSourcePath + " " 2396 + parser.getPositionDescription()); 2397 XmlUtils.skipCurrentTag(parser); 2398 continue; 2399 } 2400 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; 2401 return false; 2402 } 2403 XmlUtils.skipCurrentTag(parser); 2404 2405 } else { 2406 if (!RIGID_PARSER) { 2407 Log.w(TAG, "Unknown element under <provider>: " 2408 + parser.getName() + " at " + mArchiveSourcePath + " " 2409 + parser.getPositionDescription()); 2410 XmlUtils.skipCurrentTag(parser); 2411 continue; 2412 } 2413 outError[0] = "Bad element under <provider>: " 2414 + parser.getName(); 2415 return false; 2416 } 2417 } 2418 return true; 2419 } 2420 2421 private Service parseService(Package owner, Resources res, 2422 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) 2423 throws XmlPullParserException, IOException { 2424 TypedArray sa = res.obtainAttributes(attrs, 2425 com.android.internal.R.styleable.AndroidManifestService); 2426 2427 if (mParseServiceArgs == null) { 2428 mParseServiceArgs = new ParseComponentArgs(owner, outError, 2429 com.android.internal.R.styleable.AndroidManifestService_name, 2430 com.android.internal.R.styleable.AndroidManifestService_label, 2431 com.android.internal.R.styleable.AndroidManifestService_icon, 2432 com.android.internal.R.styleable.AndroidManifestService_logo, 2433 mSeparateProcesses, 2434 com.android.internal.R.styleable.AndroidManifestService_process, 2435 com.android.internal.R.styleable.AndroidManifestService_description, 2436 com.android.internal.R.styleable.AndroidManifestService_enabled); 2437 mParseServiceArgs.tag = "<service>"; 2438 } 2439 2440 mParseServiceArgs.sa = sa; 2441 mParseServiceArgs.flags = flags; 2442 2443 Service s = new Service(mParseServiceArgs, new ServiceInfo()); 2444 if (outError[0] != null) { 2445 sa.recycle(); 2446 return null; 2447 } 2448 2449 final boolean setExported = sa.hasValue( 2450 com.android.internal.R.styleable.AndroidManifestService_exported); 2451 if (setExported) { 2452 s.info.exported = sa.getBoolean( 2453 com.android.internal.R.styleable.AndroidManifestService_exported, false); 2454 } 2455 2456 String str = sa.getNonConfigurationString( 2457 com.android.internal.R.styleable.AndroidManifestService_permission, 0); 2458 if (str == null) { 2459 s.info.permission = owner.applicationInfo.permission; 2460 } else { 2461 s.info.permission = str.length() > 0 ? str.toString().intern() : null; 2462 } 2463 2464 sa.recycle(); 2465 2466 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { 2467 // A heavy-weight application can not have services in its main process 2468 // We can do direct compare because we intern all strings. 2469 if (s.info.processName == owner.packageName) { 2470 outError[0] = "Heavy-weight applications can not have services in main process"; 2471 return null; 2472 } 2473 } 2474 2475 int outerDepth = parser.getDepth(); 2476 int type; 2477 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 2478 && (type != XmlPullParser.END_TAG 2479 || parser.getDepth() > outerDepth)) { 2480 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 2481 continue; 2482 } 2483 2484 if (parser.getName().equals("intent-filter")) { 2485 ServiceIntentInfo intent = new ServiceIntentInfo(s); 2486 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) { 2487 return null; 2488 } 2489 2490 s.intents.add(intent); 2491 } else if (parser.getName().equals("meta-data")) { 2492 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData, 2493 outError)) == null) { 2494 return null; 2495 } 2496 } else { 2497 if (!RIGID_PARSER) { 2498 Log.w(TAG, "Unknown element under <service>: " 2499 + parser.getName() + " at " + mArchiveSourcePath + " " 2500 + parser.getPositionDescription()); 2501 XmlUtils.skipCurrentTag(parser); 2502 continue; 2503 } 2504 outError[0] = "Bad element under <service>: " 2505 + parser.getName(); 2506 return null; 2507 } 2508 } 2509 2510 if (!setExported) { 2511 s.info.exported = s.intents.size() > 0; 2512 } 2513 2514 return s; 2515 } 2516 2517 private boolean parseAllMetaData(Resources res, 2518 XmlPullParser parser, AttributeSet attrs, String tag, 2519 Component outInfo, String[] outError) 2520 throws XmlPullParserException, IOException { 2521 int outerDepth = parser.getDepth(); 2522 int type; 2523 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 2524 && (type != XmlPullParser.END_TAG 2525 || parser.getDepth() > outerDepth)) { 2526 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 2527 continue; 2528 } 2529 2530 if (parser.getName().equals("meta-data")) { 2531 if ((outInfo.metaData=parseMetaData(res, parser, attrs, 2532 outInfo.metaData, outError)) == null) { 2533 return false; 2534 } 2535 } else { 2536 if (!RIGID_PARSER) { 2537 Log.w(TAG, "Unknown element under " + tag + ": " 2538 + parser.getName() + " at " + mArchiveSourcePath + " " 2539 + parser.getPositionDescription()); 2540 XmlUtils.skipCurrentTag(parser); 2541 continue; 2542 } 2543 outError[0] = "Bad element under " + tag + ": " 2544 + parser.getName(); 2545 return false; 2546 } 2547 } 2548 return true; 2549 } 2550 2551 private Bundle parseMetaData(Resources res, 2552 XmlPullParser parser, AttributeSet attrs, 2553 Bundle data, String[] outError) 2554 throws XmlPullParserException, IOException { 2555 2556 TypedArray sa = res.obtainAttributes(attrs, 2557 com.android.internal.R.styleable.AndroidManifestMetaData); 2558 2559 if (data == null) { 2560 data = new Bundle(); 2561 } 2562 2563 String name = sa.getNonConfigurationString( 2564 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); 2565 if (name == null) { 2566 outError[0] = "<meta-data> requires an android:name attribute"; 2567 sa.recycle(); 2568 return null; 2569 } 2570 2571 name = name.intern(); 2572 2573 TypedValue v = sa.peekValue( 2574 com.android.internal.R.styleable.AndroidManifestMetaData_resource); 2575 if (v != null && v.resourceId != 0) { 2576 //Log.i(TAG, "Meta data ref " + name + ": " + v); 2577 data.putInt(name, v.resourceId); 2578 } else { 2579 v = sa.peekValue( 2580 com.android.internal.R.styleable.AndroidManifestMetaData_value); 2581 //Log.i(TAG, "Meta data " + name + ": " + v); 2582 if (v != null) { 2583 if (v.type == TypedValue.TYPE_STRING) { 2584 CharSequence cs = v.coerceToString(); 2585 data.putString(name, cs != null ? cs.toString().intern() : null); 2586 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { 2587 data.putBoolean(name, v.data != 0); 2588 } else if (v.type >= TypedValue.TYPE_FIRST_INT 2589 && v.type <= TypedValue.TYPE_LAST_INT) { 2590 data.putInt(name, v.data); 2591 } else if (v.type == TypedValue.TYPE_FLOAT) { 2592 data.putFloat(name, v.getFloat()); 2593 } else { 2594 if (!RIGID_PARSER) { 2595 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " 2596 + parser.getName() + " at " + mArchiveSourcePath + " " 2597 + parser.getPositionDescription()); 2598 } else { 2599 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; 2600 data = null; 2601 } 2602 } 2603 } else { 2604 outError[0] = "<meta-data> requires an android:value or android:resource attribute"; 2605 data = null; 2606 } 2607 } 2608 2609 sa.recycle(); 2610 2611 XmlUtils.skipCurrentTag(parser); 2612 2613 return data; 2614 } 2615 2616 private static final String ANDROID_RESOURCES 2617 = "http://schemas.android.com/apk/res/android"; 2618 2619 private boolean parseIntent(Resources res, 2620 XmlPullParser parser, AttributeSet attrs, int flags, 2621 IntentInfo outInfo, String[] outError, boolean isActivity) 2622 throws XmlPullParserException, IOException { 2623 2624 TypedArray sa = res.obtainAttributes(attrs, 2625 com.android.internal.R.styleable.AndroidManifestIntentFilter); 2626 2627 int priority = sa.getInt( 2628 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); 2629 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) { 2630 Log.w(TAG, "Activity with priority > 0, forcing to 0 at " 2631 + mArchiveSourcePath + " " 2632 + parser.getPositionDescription()); 2633 priority = 0; 2634 } 2635 outInfo.setPriority(priority); 2636 2637 TypedValue v = sa.peekValue( 2638 com.android.internal.R.styleable.AndroidManifestIntentFilter_label); 2639 if (v != null && (outInfo.labelRes=v.resourceId) == 0) { 2640 outInfo.nonLocalizedLabel = v.coerceToString(); 2641 } 2642 2643 outInfo.icon = sa.getResourceId( 2644 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); 2645 2646 outInfo.logo = sa.getResourceId( 2647 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); 2648 2649 sa.recycle(); 2650 2651 int outerDepth = parser.getDepth(); 2652 int type; 2653 while ((type=parser.next()) != parser.END_DOCUMENT 2654 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) { 2655 if (type == parser.END_TAG || type == parser.TEXT) { 2656 continue; 2657 } 2658 2659 String nodeName = parser.getName(); 2660 if (nodeName.equals("action")) { 2661 String value = attrs.getAttributeValue( 2662 ANDROID_RESOURCES, "name"); 2663 if (value == null || value == "") { 2664 outError[0] = "No value supplied for <android:name>"; 2665 return false; 2666 } 2667 XmlUtils.skipCurrentTag(parser); 2668 2669 outInfo.addAction(value); 2670 } else if (nodeName.equals("category")) { 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.addCategory(value); 2680 2681 } else if (nodeName.equals("data")) { 2682 sa = res.obtainAttributes(attrs, 2683 com.android.internal.R.styleable.AndroidManifestData); 2684 2685 String str = sa.getNonConfigurationString( 2686 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); 2687 if (str != null) { 2688 try { 2689 outInfo.addDataType(str); 2690 } catch (IntentFilter.MalformedMimeTypeException e) { 2691 outError[0] = e.toString(); 2692 sa.recycle(); 2693 return false; 2694 } 2695 } 2696 2697 str = sa.getNonConfigurationString( 2698 com.android.internal.R.styleable.AndroidManifestData_scheme, 0); 2699 if (str != null) { 2700 outInfo.addDataScheme(str); 2701 } 2702 2703 String host = sa.getNonConfigurationString( 2704 com.android.internal.R.styleable.AndroidManifestData_host, 0); 2705 String port = sa.getNonConfigurationString( 2706 com.android.internal.R.styleable.AndroidManifestData_port, 0); 2707 if (host != null) { 2708 outInfo.addDataAuthority(host, port); 2709 } 2710 2711 str = sa.getNonConfigurationString( 2712 com.android.internal.R.styleable.AndroidManifestData_path, 0); 2713 if (str != null) { 2714 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); 2715 } 2716 2717 str = sa.getNonConfigurationString( 2718 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); 2719 if (str != null) { 2720 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); 2721 } 2722 2723 str = sa.getNonConfigurationString( 2724 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); 2725 if (str != null) { 2726 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); 2727 } 2728 2729 sa.recycle(); 2730 XmlUtils.skipCurrentTag(parser); 2731 } else if (!RIGID_PARSER) { 2732 Log.w(TAG, "Unknown element under <intent-filter>: " 2733 + parser.getName() + " at " + mArchiveSourcePath + " " 2734 + parser.getPositionDescription()); 2735 XmlUtils.skipCurrentTag(parser); 2736 } else { 2737 outError[0] = "Bad element under <intent-filter>: " + parser.getName(); 2738 return false; 2739 } 2740 } 2741 2742 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); 2743 if (false) { 2744 String cats = ""; 2745 Iterator<String> it = outInfo.categoriesIterator(); 2746 while (it != null && it.hasNext()) { 2747 cats += " " + it.next(); 2748 } 2749 System.out.println("Intent d=" + 2750 outInfo.hasDefault + ", cat=" + cats); 2751 } 2752 2753 return true; 2754 } 2755 2756 public final static class Package { 2757 public String packageName; 2758 2759 // For now we only support one application per package. 2760 public final ApplicationInfo applicationInfo = new ApplicationInfo(); 2761 2762 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); 2763 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); 2764 public final ArrayList<Activity> activities = new ArrayList<Activity>(0); 2765 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); 2766 public final ArrayList<Provider> providers = new ArrayList<Provider>(0); 2767 public final ArrayList<Service> services = new ArrayList<Service>(0); 2768 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); 2769 2770 public final ArrayList<String> requestedPermissions = new ArrayList<String>(); 2771 2772 public ArrayList<String> protectedBroadcasts; 2773 2774 public ArrayList<String> usesLibraries = null; 2775 public ArrayList<String> usesOptionalLibraries = null; 2776 public String[] usesLibraryFiles = null; 2777 2778 public ArrayList<String> mOriginalPackages = null; 2779 public String mRealPackage = null; 2780 public ArrayList<String> mAdoptPermissions = null; 2781 2782 // We store the application meta-data independently to avoid multiple unwanted references 2783 public Bundle mAppMetaData = null; 2784 2785 // If this is a 3rd party app, this is the path of the zip file. 2786 public String mPath; 2787 2788 // The version code declared for this package. 2789 public int mVersionCode; 2790 2791 // The version name declared for this package. 2792 public String mVersionName; 2793 2794 // The shared user id that this package wants to use. 2795 public String mSharedUserId; 2796 2797 // The shared user label that this package wants to use. 2798 public int mSharedUserLabel; 2799 2800 // Signatures that were read from the package. 2801 public Signature mSignatures[]; 2802 2803 // For use by package manager service for quick lookup of 2804 // preferred up order. 2805 public int mPreferredOrder = 0; 2806 2807 // For use by the package manager to keep track of the path to the 2808 // file an app came from. 2809 public String mScanPath; 2810 2811 // For use by package manager to keep track of where it has done dexopt. 2812 public boolean mDidDexOpt; 2813 2814 // User set enabled state. 2815 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; 2816 2817 // Additional data supplied by callers. 2818 public Object mExtras; 2819 2820 // Whether an operation is currently pending on this package 2821 public boolean mOperationPending; 2822 2823 /* 2824 * Applications hardware preferences 2825 */ 2826 public final ArrayList<ConfigurationInfo> configPreferences = 2827 new ArrayList<ConfigurationInfo>(); 2828 2829 /* 2830 * Applications requested features 2831 */ 2832 public ArrayList<FeatureInfo> reqFeatures = null; 2833 2834 public int installLocation; 2835 2836 public Package(String _name) { 2837 packageName = _name; 2838 applicationInfo.packageName = _name; 2839 applicationInfo.uid = -1; 2840 } 2841 2842 public void setPackageName(String newName) { 2843 packageName = newName; 2844 applicationInfo.packageName = newName; 2845 for (int i=permissions.size()-1; i>=0; i--) { 2846 permissions.get(i).setPackageName(newName); 2847 } 2848 for (int i=permissionGroups.size()-1; i>=0; i--) { 2849 permissionGroups.get(i).setPackageName(newName); 2850 } 2851 for (int i=activities.size()-1; i>=0; i--) { 2852 activities.get(i).setPackageName(newName); 2853 } 2854 for (int i=receivers.size()-1; i>=0; i--) { 2855 receivers.get(i).setPackageName(newName); 2856 } 2857 for (int i=providers.size()-1; i>=0; i--) { 2858 providers.get(i).setPackageName(newName); 2859 } 2860 for (int i=services.size()-1; i>=0; i--) { 2861 services.get(i).setPackageName(newName); 2862 } 2863 for (int i=instrumentation.size()-1; i>=0; i--) { 2864 instrumentation.get(i).setPackageName(newName); 2865 } 2866 } 2867 2868 public String toString() { 2869 return "Package{" 2870 + Integer.toHexString(System.identityHashCode(this)) 2871 + " " + packageName + "}"; 2872 } 2873 } 2874 2875 public static class Component<II extends IntentInfo> { 2876 public final Package owner; 2877 public final ArrayList<II> intents; 2878 public final String className; 2879 public Bundle metaData; 2880 2881 ComponentName componentName; 2882 String componentShortName; 2883 2884 public Component(Package _owner) { 2885 owner = _owner; 2886 intents = null; 2887 className = null; 2888 } 2889 2890 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { 2891 owner = args.owner; 2892 intents = new ArrayList<II>(0); 2893 String name = args.sa.getNonConfigurationString(args.nameRes, 0); 2894 if (name == null) { 2895 className = null; 2896 args.outError[0] = args.tag + " does not specify android:name"; 2897 return; 2898 } 2899 2900 outInfo.name 2901 = buildClassName(owner.applicationInfo.packageName, name, args.outError); 2902 if (outInfo.name == null) { 2903 className = null; 2904 args.outError[0] = args.tag + " does not have valid android:name"; 2905 return; 2906 } 2907 2908 className = outInfo.name; 2909 2910 int iconVal = args.sa.getResourceId(args.iconRes, 0); 2911 if (iconVal != 0) { 2912 outInfo.icon = iconVal; 2913 outInfo.nonLocalizedLabel = null; 2914 } 2915 2916 int logoVal = args.sa.getResourceId(args.logoRes, 0); 2917 if (logoVal != 0) { 2918 outInfo.logo = logoVal; 2919 } 2920 2921 TypedValue v = args.sa.peekValue(args.labelRes); 2922 if (v != null && (outInfo.labelRes=v.resourceId) == 0) { 2923 outInfo.nonLocalizedLabel = v.coerceToString(); 2924 } 2925 2926 outInfo.packageName = owner.packageName; 2927 } 2928 2929 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { 2930 this(args, (PackageItemInfo)outInfo); 2931 if (args.outError[0] != null) { 2932 return; 2933 } 2934 2935 if (args.processRes != 0) { 2936 CharSequence pname; 2937 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { 2938 pname = args.sa.getNonConfigurationString(args.processRes, 0); 2939 } else { 2940 // Some older apps have been seen to use a resource reference 2941 // here that on older builds was ignored (with a warning). We 2942 // need to continue to do this for them so they don't break. 2943 pname = args.sa.getNonResourceString(args.processRes); 2944 } 2945 outInfo.processName = buildProcessName(owner.applicationInfo.packageName, 2946 owner.applicationInfo.processName, pname, 2947 args.flags, args.sepProcesses, args.outError); 2948 } 2949 2950 if (args.descriptionRes != 0) { 2951 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); 2952 } 2953 2954 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); 2955 } 2956 2957 public Component(Component<II> clone) { 2958 owner = clone.owner; 2959 intents = clone.intents; 2960 className = clone.className; 2961 componentName = clone.componentName; 2962 componentShortName = clone.componentShortName; 2963 } 2964 2965 public ComponentName getComponentName() { 2966 if (componentName != null) { 2967 return componentName; 2968 } 2969 if (className != null) { 2970 componentName = new ComponentName(owner.applicationInfo.packageName, 2971 className); 2972 } 2973 return componentName; 2974 } 2975 2976 public String getComponentShortName() { 2977 if (componentShortName != null) { 2978 return componentShortName; 2979 } 2980 ComponentName component = getComponentName(); 2981 if (component != null) { 2982 componentShortName = component.flattenToShortString(); 2983 } 2984 return componentShortName; 2985 } 2986 2987 public void setPackageName(String packageName) { 2988 componentName = null; 2989 componentShortName = null; 2990 } 2991 } 2992 2993 public final static class Permission extends Component<IntentInfo> { 2994 public final PermissionInfo info; 2995 public boolean tree; 2996 public PermissionGroup group; 2997 2998 public Permission(Package _owner) { 2999 super(_owner); 3000 info = new PermissionInfo(); 3001 } 3002 3003 public Permission(Package _owner, PermissionInfo _info) { 3004 super(_owner); 3005 info = _info; 3006 } 3007 3008 public void setPackageName(String packageName) { 3009 super.setPackageName(packageName); 3010 info.packageName = packageName; 3011 } 3012 3013 public String toString() { 3014 return "Permission{" 3015 + Integer.toHexString(System.identityHashCode(this)) 3016 + " " + info.name + "}"; 3017 } 3018 } 3019 3020 public final static class PermissionGroup extends Component<IntentInfo> { 3021 public final PermissionGroupInfo info; 3022 3023 public PermissionGroup(Package _owner) { 3024 super(_owner); 3025 info = new PermissionGroupInfo(); 3026 } 3027 3028 public PermissionGroup(Package _owner, PermissionGroupInfo _info) { 3029 super(_owner); 3030 info = _info; 3031 } 3032 3033 public void setPackageName(String packageName) { 3034 super.setPackageName(packageName); 3035 info.packageName = packageName; 3036 } 3037 3038 public String toString() { 3039 return "PermissionGroup{" 3040 + Integer.toHexString(System.identityHashCode(this)) 3041 + " " + info.name + "}"; 3042 } 3043 } 3044 3045 private static boolean copyNeeded(int flags, Package p, Bundle metaData) { 3046 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { 3047 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; 3048 if (p.applicationInfo.enabled != enabled) { 3049 return true; 3050 } 3051 } 3052 if ((flags & PackageManager.GET_META_DATA) != 0 3053 && (metaData != null || p.mAppMetaData != null)) { 3054 return true; 3055 } 3056 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 3057 && p.usesLibraryFiles != null) { 3058 return true; 3059 } 3060 return false; 3061 } 3062 3063 public static ApplicationInfo generateApplicationInfo(Package p, int flags) { 3064 if (p == null) return null; 3065 if (!copyNeeded(flags, p, null)) { 3066 // CompatibilityMode is global state. It's safe to modify the instance 3067 // of the package. 3068 if (!sCompatibilityModeEnabled) { 3069 p.applicationInfo.disableCompatibilityMode(); 3070 } 3071 return p.applicationInfo; 3072 } 3073 3074 // Make shallow copy so we can store the metadata/libraries safely 3075 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); 3076 if ((flags & PackageManager.GET_META_DATA) != 0) { 3077 ai.metaData = p.mAppMetaData; 3078 } 3079 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { 3080 ai.sharedLibraryFiles = p.usesLibraryFiles; 3081 } 3082 if (!sCompatibilityModeEnabled) { 3083 ai.disableCompatibilityMode(); 3084 } 3085 ai.enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; 3086 return ai; 3087 } 3088 3089 public static final PermissionInfo generatePermissionInfo( 3090 Permission p, int flags) { 3091 if (p == null) return null; 3092 if ((flags&PackageManager.GET_META_DATA) == 0) { 3093 return p.info; 3094 } 3095 PermissionInfo pi = new PermissionInfo(p.info); 3096 pi.metaData = p.metaData; 3097 return pi; 3098 } 3099 3100 public static final PermissionGroupInfo generatePermissionGroupInfo( 3101 PermissionGroup pg, int flags) { 3102 if (pg == null) return null; 3103 if ((flags&PackageManager.GET_META_DATA) == 0) { 3104 return pg.info; 3105 } 3106 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); 3107 pgi.metaData = pg.metaData; 3108 return pgi; 3109 } 3110 3111 public final static class Activity extends Component<ActivityIntentInfo> { 3112 public final ActivityInfo info; 3113 3114 public Activity(final ParseComponentArgs args, final ActivityInfo _info) { 3115 super(args, _info); 3116 info = _info; 3117 info.applicationInfo = args.owner.applicationInfo; 3118 } 3119 3120 public void setPackageName(String packageName) { 3121 super.setPackageName(packageName); 3122 info.packageName = packageName; 3123 } 3124 3125 public String toString() { 3126 return "Activity{" 3127 + Integer.toHexString(System.identityHashCode(this)) 3128 + " " + getComponentShortName() + "}"; 3129 } 3130 } 3131 3132 public static final ActivityInfo generateActivityInfo(Activity a, 3133 int flags) { 3134 if (a == null) return null; 3135 if (!copyNeeded(flags, a.owner, a.metaData)) { 3136 return a.info; 3137 } 3138 // Make shallow copies so we can store the metadata safely 3139 ActivityInfo ai = new ActivityInfo(a.info); 3140 ai.metaData = a.metaData; 3141 ai.applicationInfo = generateApplicationInfo(a.owner, flags); 3142 return ai; 3143 } 3144 3145 public final static class Service extends Component<ServiceIntentInfo> { 3146 public final ServiceInfo info; 3147 3148 public Service(final ParseComponentArgs args, final ServiceInfo _info) { 3149 super(args, _info); 3150 info = _info; 3151 info.applicationInfo = args.owner.applicationInfo; 3152 } 3153 3154 public void setPackageName(String packageName) { 3155 super.setPackageName(packageName); 3156 info.packageName = packageName; 3157 } 3158 3159 public String toString() { 3160 return "Service{" 3161 + Integer.toHexString(System.identityHashCode(this)) 3162 + " " + getComponentShortName() + "}"; 3163 } 3164 } 3165 3166 public static final ServiceInfo generateServiceInfo(Service s, int flags) { 3167 if (s == null) return null; 3168 if (!copyNeeded(flags, s.owner, s.metaData)) { 3169 return s.info; 3170 } 3171 // Make shallow copies so we can store the metadata safely 3172 ServiceInfo si = new ServiceInfo(s.info); 3173 si.metaData = s.metaData; 3174 si.applicationInfo = generateApplicationInfo(s.owner, flags); 3175 return si; 3176 } 3177 3178 public final static class Provider extends Component { 3179 public final ProviderInfo info; 3180 public boolean syncable; 3181 3182 public Provider(final ParseComponentArgs args, final ProviderInfo _info) { 3183 super(args, _info); 3184 info = _info; 3185 info.applicationInfo = args.owner.applicationInfo; 3186 syncable = false; 3187 } 3188 3189 public Provider(Provider existingProvider) { 3190 super(existingProvider); 3191 this.info = existingProvider.info; 3192 this.syncable = existingProvider.syncable; 3193 } 3194 3195 public void setPackageName(String packageName) { 3196 super.setPackageName(packageName); 3197 info.packageName = packageName; 3198 } 3199 3200 public String toString() { 3201 return "Provider{" 3202 + Integer.toHexString(System.identityHashCode(this)) 3203 + " " + info.name + "}"; 3204 } 3205 } 3206 3207 public static final ProviderInfo generateProviderInfo(Provider p, 3208 int flags) { 3209 if (p == null) return null; 3210 if (!copyNeeded(flags, p.owner, p.metaData) 3211 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 3212 || p.info.uriPermissionPatterns == null)) { 3213 return p.info; 3214 } 3215 // Make shallow copies so we can store the metadata safely 3216 ProviderInfo pi = new ProviderInfo(p.info); 3217 pi.metaData = p.metaData; 3218 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { 3219 pi.uriPermissionPatterns = null; 3220 } 3221 pi.applicationInfo = generateApplicationInfo(p.owner, flags); 3222 return pi; 3223 } 3224 3225 public final static class Instrumentation extends Component { 3226 public final InstrumentationInfo info; 3227 3228 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { 3229 super(args, _info); 3230 info = _info; 3231 } 3232 3233 public void setPackageName(String packageName) { 3234 super.setPackageName(packageName); 3235 info.packageName = packageName; 3236 } 3237 3238 public String toString() { 3239 return "Instrumentation{" 3240 + Integer.toHexString(System.identityHashCode(this)) 3241 + " " + getComponentShortName() + "}"; 3242 } 3243 } 3244 3245 public static final InstrumentationInfo generateInstrumentationInfo( 3246 Instrumentation i, int flags) { 3247 if (i == null) return null; 3248 if ((flags&PackageManager.GET_META_DATA) == 0) { 3249 return i.info; 3250 } 3251 InstrumentationInfo ii = new InstrumentationInfo(i.info); 3252 ii.metaData = i.metaData; 3253 return ii; 3254 } 3255 3256 public static class IntentInfo extends IntentFilter { 3257 public boolean hasDefault; 3258 public int labelRes; 3259 public CharSequence nonLocalizedLabel; 3260 public int icon; 3261 public int logo; 3262 } 3263 3264 public final static class ActivityIntentInfo extends IntentInfo { 3265 public final Activity activity; 3266 3267 public ActivityIntentInfo(Activity _activity) { 3268 activity = _activity; 3269 } 3270 3271 public String toString() { 3272 return "ActivityIntentInfo{" 3273 + Integer.toHexString(System.identityHashCode(this)) 3274 + " " + activity.info.name + "}"; 3275 } 3276 } 3277 3278 public final static class ServiceIntentInfo extends IntentInfo { 3279 public final Service service; 3280 3281 public ServiceIntentInfo(Service _service) { 3282 service = _service; 3283 } 3284 3285 public String toString() { 3286 return "ServiceIntentInfo{" 3287 + Integer.toHexString(System.identityHashCode(this)) 3288 + " " + service.info.name + "}"; 3289 } 3290 } 3291 3292 /** 3293 * @hide 3294 */ 3295 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { 3296 sCompatibilityModeEnabled = compatibilityModeEnabled; 3297 } 3298} 3299