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