blob: e2c0fe69f3452e05a12b22ef2e07c1c9bbb4f22e [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[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070079 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070080 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;
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700838
839
840 } else if (tagName.equals("supports-density")) {
841 sa = res.obtainAttributes(attrs,
842 com.android.internal.R.styleable.AndroidManifestSupportsDensity);
843
844 int density = sa.getInteger(
845 com.android.internal.R.styleable.AndroidManifestSupportsDensity_density, -1);
846
847 sa.recycle();
848
849 if (density != -1 && !pkg.supportsDensityList.contains(density)) {
850 pkg.supportsDensityList.add(density);
851 }
852
853 XmlUtils.skipCurrentTag(parser);
854
855 } else if (tagName.equals("expandable")) {
856 pkg.expandable = true;
857 XmlUtils.skipCurrentTag(parser);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 } else {
859 Log.w(TAG, "Bad element under <manifest>: "
860 + parser.getName());
861 XmlUtils.skipCurrentTag(parser);
862 continue;
863 }
864 }
865
866 if (!foundApp && pkg.instrumentation.size() == 0) {
867 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
868 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
869 }
870
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700871 final int NP = PackageParser.NEW_PERMISSIONS.length;
872 for (int ip=0; ip<NP; ip++) {
873 final PackageParser.NewPermissionInfo npi
874 = PackageParser.NEW_PERMISSIONS[ip];
875 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
876 break;
877 }
878 if (!pkg.requestedPermissions.contains(npi.name)) {
879 Log.i(TAG, "Impliciting adding " + npi.name + " to old pkg "
880 + pkg.packageName);
881 pkg.requestedPermissions.add(npi.name);
882 }
Dianne Hackborn851a5412009-05-08 12:06:44 -0700883 }
884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 if (pkg.usesLibraries.size() > 0) {
886 pkg.usesLibraryFiles = new String[pkg.usesLibraries.size()];
887 pkg.usesLibraries.toArray(pkg.usesLibraryFiles);
888 }
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700889 // TODO: enable all density & expandable if target sdk is higher than donut
890
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700891 int size = pkg.supportsDensityList.size();
892 if (size > 0) {
893 int densities[] = pkg.supportsDensities = new int[size];
894 List<Integer> densityList = pkg.supportsDensityList;
895 for (int i = 0; i < size; i++) {
896 densities[i] = densityList.get(i);
897 }
898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 return pkg;
900 }
901
902 private static String buildClassName(String pkg, CharSequence clsSeq,
903 String[] outError) {
904 if (clsSeq == null || clsSeq.length() <= 0) {
905 outError[0] = "Empty class name in package " + pkg;
906 return null;
907 }
908 String cls = clsSeq.toString();
909 char c = cls.charAt(0);
910 if (c == '.') {
911 return (pkg + cls).intern();
912 }
913 if (cls.indexOf('.') < 0) {
914 StringBuilder b = new StringBuilder(pkg);
915 b.append('.');
916 b.append(cls);
917 return b.toString().intern();
918 }
919 if (c >= 'a' && c <= 'z') {
920 return cls.intern();
921 }
922 outError[0] = "Bad class name " + cls + " in package " + pkg;
923 return null;
924 }
925
926 private static String buildCompoundName(String pkg,
927 CharSequence procSeq, String type, String[] outError) {
928 String proc = procSeq.toString();
929 char c = proc.charAt(0);
930 if (pkg != null && c == ':') {
931 if (proc.length() < 2) {
932 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
933 + ": must be at least two characters";
934 return null;
935 }
936 String subName = proc.substring(1);
937 String nameError = validateName(subName, false);
938 if (nameError != null) {
939 outError[0] = "Invalid " + type + " name " + proc + " in package "
940 + pkg + ": " + nameError;
941 return null;
942 }
943 return (pkg + proc).intern();
944 }
945 String nameError = validateName(proc, true);
946 if (nameError != null && !"system".equals(proc)) {
947 outError[0] = "Invalid " + type + " name " + proc + " in package "
948 + pkg + ": " + nameError;
949 return null;
950 }
951 return proc.intern();
952 }
953
954 private static String buildProcessName(String pkg, String defProc,
955 CharSequence procSeq, int flags, String[] separateProcesses,
956 String[] outError) {
957 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
958 return defProc != null ? defProc : pkg;
959 }
960 if (separateProcesses != null) {
961 for (int i=separateProcesses.length-1; i>=0; i--) {
962 String sp = separateProcesses[i];
963 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
964 return pkg;
965 }
966 }
967 }
968 if (procSeq == null || procSeq.length() <= 0) {
969 return defProc;
970 }
971 return buildCompoundName(pkg, procSeq, "package", outError);
972 }
973
974 private static String buildTaskAffinityName(String pkg, String defProc,
975 CharSequence procSeq, String[] outError) {
976 if (procSeq == null) {
977 return defProc;
978 }
979 if (procSeq.length() <= 0) {
980 return null;
981 }
982 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
983 }
984
985 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
986 XmlPullParser parser, AttributeSet attrs, String[] outError)
987 throws XmlPullParserException, IOException {
988 PermissionGroup perm = new PermissionGroup(owner);
989
990 TypedArray sa = res.obtainAttributes(attrs,
991 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
992
993 if (!parsePackageItemInfo(owner, perm.info, outError,
994 "<permission-group>", sa,
995 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
996 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
997 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon)) {
998 sa.recycle();
999 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1000 return null;
1001 }
1002
1003 perm.info.descriptionRes = sa.getResourceId(
1004 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1005 0);
1006
1007 sa.recycle();
1008
1009 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1010 outError)) {
1011 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1012 return null;
1013 }
1014
1015 owner.permissionGroups.add(perm);
1016
1017 return perm;
1018 }
1019
1020 private Permission parsePermission(Package owner, Resources res,
1021 XmlPullParser parser, AttributeSet attrs, String[] outError)
1022 throws XmlPullParserException, IOException {
1023 Permission perm = new Permission(owner);
1024
1025 TypedArray sa = res.obtainAttributes(attrs,
1026 com.android.internal.R.styleable.AndroidManifestPermission);
1027
1028 if (!parsePackageItemInfo(owner, perm.info, outError,
1029 "<permission>", sa,
1030 com.android.internal.R.styleable.AndroidManifestPermission_name,
1031 com.android.internal.R.styleable.AndroidManifestPermission_label,
1032 com.android.internal.R.styleable.AndroidManifestPermission_icon)) {
1033 sa.recycle();
1034 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1035 return null;
1036 }
1037
1038 perm.info.group = sa.getNonResourceString(
1039 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1040 if (perm.info.group != null) {
1041 perm.info.group = perm.info.group.intern();
1042 }
1043
1044 perm.info.descriptionRes = sa.getResourceId(
1045 com.android.internal.R.styleable.AndroidManifestPermission_description,
1046 0);
1047
1048 perm.info.protectionLevel = sa.getInt(
1049 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1050 PermissionInfo.PROTECTION_NORMAL);
1051
1052 sa.recycle();
1053
1054 if (perm.info.protectionLevel == -1) {
1055 outError[0] = "<permission> does not specify protectionLevel";
1056 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1057 return null;
1058 }
1059
1060 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1061 outError)) {
1062 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1063 return null;
1064 }
1065
1066 owner.permissions.add(perm);
1067
1068 return perm;
1069 }
1070
1071 private Permission parsePermissionTree(Package owner, Resources res,
1072 XmlPullParser parser, AttributeSet attrs, String[] outError)
1073 throws XmlPullParserException, IOException {
1074 Permission perm = new Permission(owner);
1075
1076 TypedArray sa = res.obtainAttributes(attrs,
1077 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1078
1079 if (!parsePackageItemInfo(owner, perm.info, outError,
1080 "<permission-tree>", sa,
1081 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1082 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
1083 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon)) {
1084 sa.recycle();
1085 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1086 return null;
1087 }
1088
1089 sa.recycle();
1090
1091 int index = perm.info.name.indexOf('.');
1092 if (index > 0) {
1093 index = perm.info.name.indexOf('.', index+1);
1094 }
1095 if (index < 0) {
1096 outError[0] = "<permission-tree> name has less than three segments: "
1097 + perm.info.name;
1098 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1099 return null;
1100 }
1101
1102 perm.info.descriptionRes = 0;
1103 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1104 perm.tree = true;
1105
1106 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1107 outError)) {
1108 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1109 return null;
1110 }
1111
1112 owner.permissions.add(perm);
1113
1114 return perm;
1115 }
1116
1117 private Instrumentation parseInstrumentation(Package owner, Resources res,
1118 XmlPullParser parser, AttributeSet attrs, String[] outError)
1119 throws XmlPullParserException, IOException {
1120 TypedArray sa = res.obtainAttributes(attrs,
1121 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1122
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001123 if (mParseInstrumentationArgs == null) {
1124 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1125 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1126 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
1127 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon);
1128 mParseInstrumentationArgs.tag = "<instrumentation>";
1129 }
1130
1131 mParseInstrumentationArgs.sa = sa;
1132
1133 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1134 new InstrumentationInfo());
1135 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 sa.recycle();
1137 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1138 return null;
1139 }
1140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 String str;
1142 str = sa.getNonResourceString(
1143 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1144 a.info.targetPackage = str != null ? str.intern() : null;
1145
1146 a.info.handleProfiling = sa.getBoolean(
1147 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1148 false);
1149
1150 a.info.functionalTest = sa.getBoolean(
1151 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1152 false);
1153
1154 sa.recycle();
1155
1156 if (a.info.targetPackage == null) {
1157 outError[0] = "<instrumentation> does not specify targetPackage";
1158 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1159 return null;
1160 }
1161
1162 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1163 outError)) {
1164 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1165 return null;
1166 }
1167
1168 owner.instrumentation.add(a);
1169
1170 return a;
1171 }
1172
1173 private boolean parseApplication(Package owner, Resources res,
1174 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1175 throws XmlPullParserException, IOException {
1176 final ApplicationInfo ai = owner.applicationInfo;
1177 final String pkgName = owner.applicationInfo.packageName;
1178
1179 TypedArray sa = res.obtainAttributes(attrs,
1180 com.android.internal.R.styleable.AndroidManifestApplication);
1181
1182 String name = sa.getNonResourceString(
1183 com.android.internal.R.styleable.AndroidManifestApplication_name);
1184 if (name != null) {
1185 ai.className = buildClassName(pkgName, name, outError);
1186 if (ai.className == null) {
1187 sa.recycle();
1188 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1189 return false;
1190 }
1191 }
1192
1193 String manageSpaceActivity = sa.getNonResourceString(
1194 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity);
1195 if (manageSpaceActivity != null) {
1196 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1197 outError);
1198 }
1199
Christopher Tate181fafa2009-05-14 11:12:14 -07001200 boolean allowBackup = sa.getBoolean(
1201 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1202 if (allowBackup) {
1203 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
1204 String backupAgent = sa.getNonResourceString(
1205 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent);
1206 if (backupAgent != null) {
1207 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
1208 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1209 + " from " + pkgName + "+" + backupAgent);
1210 }
1211 }
1212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 TypedValue v = sa.peekValue(
1214 com.android.internal.R.styleable.AndroidManifestApplication_label);
1215 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1216 ai.nonLocalizedLabel = v.coerceToString();
1217 }
1218
1219 ai.icon = sa.getResourceId(
1220 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1221 ai.theme = sa.getResourceId(
1222 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1223 ai.descriptionRes = sa.getResourceId(
1224 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1225
1226 if ((flags&PARSE_IS_SYSTEM) != 0) {
1227 if (sa.getBoolean(
1228 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1229 false)) {
1230 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1231 }
1232 }
1233
1234 if (sa.getBoolean(
1235 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1236 false)) {
1237 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1238 }
1239
1240 if (sa.getBoolean(
1241 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1242 true)) {
1243 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1244 }
1245
1246 if (sa.getBoolean(
1247 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1248 false)) {
1249 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1250 }
1251
1252 if (sa.getBoolean(
1253 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1254 true)) {
1255 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1256 }
1257
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001258 if (sa.getBoolean(
1259 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001260 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001261 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1262 }
1263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 String str;
1265 str = sa.getNonResourceString(
1266 com.android.internal.R.styleable.AndroidManifestApplication_permission);
1267 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1268
1269 str = sa.getNonResourceString(
1270 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1271 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1272 str, outError);
1273
1274 if (outError[0] == null) {
1275 ai.processName = buildProcessName(ai.packageName, null, sa.getNonResourceString(
1276 com.android.internal.R.styleable.AndroidManifestApplication_process),
1277 flags, mSeparateProcesses, outError);
1278
1279 ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
1280 }
1281
1282 sa.recycle();
1283
1284 if (outError[0] != null) {
1285 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1286 return false;
1287 }
1288
1289 final int innerDepth = parser.getDepth();
1290
1291 int type;
1292 while ((type=parser.next()) != parser.END_DOCUMENT
1293 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1294 if (type == parser.END_TAG || type == parser.TEXT) {
1295 continue;
1296 }
1297
1298 String tagName = parser.getName();
1299 if (tagName.equals("activity")) {
1300 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1301 if (a == null) {
1302 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1303 return false;
1304 }
1305
1306 owner.activities.add(a);
1307
1308 } else if (tagName.equals("receiver")) {
1309 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1310 if (a == null) {
1311 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1312 return false;
1313 }
1314
1315 owner.receivers.add(a);
1316
1317 } else if (tagName.equals("service")) {
1318 Service s = parseService(owner, res, parser, attrs, flags, outError);
1319 if (s == null) {
1320 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1321 return false;
1322 }
1323
1324 owner.services.add(s);
1325
1326 } else if (tagName.equals("provider")) {
1327 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1328 if (p == null) {
1329 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1330 return false;
1331 }
1332
1333 owner.providers.add(p);
1334
1335 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001336 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 if (a == null) {
1338 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1339 return false;
1340 }
1341
1342 owner.activities.add(a);
1343
1344 } else if (parser.getName().equals("meta-data")) {
1345 // note: application meta-data is stored off to the side, so it can
1346 // remain null in the primary copy (we like to avoid extra copies because
1347 // it can be large)
1348 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1349 outError)) == null) {
1350 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1351 return false;
1352 }
1353
1354 } else if (tagName.equals("uses-library")) {
1355 sa = res.obtainAttributes(attrs,
1356 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1357
1358 String lname = sa.getNonResourceString(
1359 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
1360
1361 sa.recycle();
1362
1363 if (lname != null && !owner.usesLibraries.contains(lname)) {
1364 owner.usesLibraries.add(lname);
1365 }
1366
1367 XmlUtils.skipCurrentTag(parser);
1368
1369 } else {
1370 if (!RIGID_PARSER) {
1371 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1372 Log.w(TAG, "Unknown element under <application>: " + tagName);
1373 XmlUtils.skipCurrentTag(parser);
1374 continue;
1375 } else {
1376 outError[0] = "Bad element under <application>: " + tagName;
1377 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1378 return false;
1379 }
1380 }
1381 }
1382
1383 return true;
1384 }
1385
1386 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1387 String[] outError, String tag, TypedArray sa,
1388 int nameRes, int labelRes, int iconRes) {
1389 String name = sa.getNonResourceString(nameRes);
1390 if (name == null) {
1391 outError[0] = tag + " does not specify android:name";
1392 return false;
1393 }
1394
1395 outInfo.name
1396 = buildClassName(owner.applicationInfo.packageName, name, outError);
1397 if (outInfo.name == null) {
1398 return false;
1399 }
1400
1401 int iconVal = sa.getResourceId(iconRes, 0);
1402 if (iconVal != 0) {
1403 outInfo.icon = iconVal;
1404 outInfo.nonLocalizedLabel = null;
1405 }
1406
1407 TypedValue v = sa.peekValue(labelRes);
1408 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1409 outInfo.nonLocalizedLabel = v.coerceToString();
1410 }
1411
1412 outInfo.packageName = owner.packageName;
1413
1414 return true;
1415 }
1416
1417 private boolean parseComponentInfo(Package owner, int flags,
1418 ComponentInfo outInfo, String[] outError, String tag, TypedArray sa,
1419 int nameRes, int labelRes, int iconRes, int processRes,
1420 int enabledRes) {
1421 if (!parsePackageItemInfo(owner, outInfo, outError, tag, sa,
1422 nameRes, labelRes, iconRes)) {
1423 return false;
1424 }
1425
1426 if (processRes != 0) {
1427 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
1428 owner.applicationInfo.processName, sa.getNonResourceString(processRes),
1429 flags, mSeparateProcesses, outError);
1430 }
1431 outInfo.enabled = sa.getBoolean(enabledRes, true);
1432
1433 return outError[0] == null;
1434 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 private Activity parseActivity(Package owner, Resources res,
1437 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1438 boolean receiver) throws XmlPullParserException, IOException {
1439 TypedArray sa = res.obtainAttributes(attrs,
1440 com.android.internal.R.styleable.AndroidManifestActivity);
1441
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001442 if (mParseActivityArgs == null) {
1443 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1444 com.android.internal.R.styleable.AndroidManifestActivity_name,
1445 com.android.internal.R.styleable.AndroidManifestActivity_label,
1446 com.android.internal.R.styleable.AndroidManifestActivity_icon,
1447 mSeparateProcesses,
1448 com.android.internal.R.styleable.AndroidManifestActivity_process,
1449 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1450 }
1451
1452 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1453 mParseActivityArgs.sa = sa;
1454 mParseActivityArgs.flags = flags;
1455
1456 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1457 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 sa.recycle();
1459 return null;
1460 }
1461
1462 final boolean setExported = sa.hasValue(
1463 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1464 if (setExported) {
1465 a.info.exported = sa.getBoolean(
1466 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1467 }
1468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 a.info.theme = sa.getResourceId(
1470 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1471
1472 String str;
1473 str = sa.getNonResourceString(
1474 com.android.internal.R.styleable.AndroidManifestActivity_permission);
1475 if (str == null) {
1476 a.info.permission = owner.applicationInfo.permission;
1477 } else {
1478 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1479 }
1480
1481 str = sa.getNonResourceString(
1482 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity);
1483 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1484 owner.applicationInfo.taskAffinity, str, outError);
1485
1486 a.info.flags = 0;
1487 if (sa.getBoolean(
1488 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1489 false)) {
1490 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1491 }
1492
1493 if (sa.getBoolean(
1494 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1495 false)) {
1496 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1497 }
1498
1499 if (sa.getBoolean(
1500 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1501 false)) {
1502 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1503 }
1504
1505 if (sa.getBoolean(
1506 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1507 false)) {
1508 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1509 }
1510
1511 if (sa.getBoolean(
1512 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1513 false)) {
1514 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1515 }
1516
1517 if (sa.getBoolean(
1518 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1519 false)) {
1520 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1521 }
1522
1523 if (sa.getBoolean(
1524 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1525 false)) {
1526 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1527 }
1528
1529 if (sa.getBoolean(
1530 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1531 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1532 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1533 }
1534
1535 if (!receiver) {
1536 a.info.launchMode = sa.getInt(
1537 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1538 ActivityInfo.LAUNCH_MULTIPLE);
1539 a.info.screenOrientation = sa.getInt(
1540 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1541 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1542 a.info.configChanges = sa.getInt(
1543 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1544 0);
1545 a.info.softInputMode = sa.getInt(
1546 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1547 0);
1548 } else {
1549 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1550 a.info.configChanges = 0;
1551 }
1552
1553 sa.recycle();
1554
1555 if (outError[0] != null) {
1556 return null;
1557 }
1558
1559 int outerDepth = parser.getDepth();
1560 int type;
1561 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1562 && (type != XmlPullParser.END_TAG
1563 || parser.getDepth() > outerDepth)) {
1564 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1565 continue;
1566 }
1567
1568 if (parser.getName().equals("intent-filter")) {
1569 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1570 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1571 return null;
1572 }
1573 if (intent.countActions() == 0) {
1574 Log.w(TAG, "Intent filter for activity " + intent
1575 + " defines no actions");
1576 } else {
1577 a.intents.add(intent);
1578 }
1579 } else if (parser.getName().equals("meta-data")) {
1580 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1581 outError)) == null) {
1582 return null;
1583 }
1584 } else {
1585 if (!RIGID_PARSER) {
1586 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1587 if (receiver) {
1588 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName());
1589 } else {
1590 Log.w(TAG, "Unknown element under <activity>: " + parser.getName());
1591 }
1592 XmlUtils.skipCurrentTag(parser);
1593 continue;
1594 }
1595 if (receiver) {
1596 outError[0] = "Bad element under <receiver>: " + parser.getName();
1597 } else {
1598 outError[0] = "Bad element under <activity>: " + parser.getName();
1599 }
1600 return null;
1601 }
1602 }
1603
1604 if (!setExported) {
1605 a.info.exported = a.intents.size() > 0;
1606 }
1607
1608 return a;
1609 }
1610
1611 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001612 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1613 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 TypedArray sa = res.obtainAttributes(attrs,
1615 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1616
1617 String targetActivity = sa.getNonResourceString(
1618 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity);
1619 if (targetActivity == null) {
1620 outError[0] = "<activity-alias> does not specify android:targetActivity";
1621 sa.recycle();
1622 return null;
1623 }
1624
1625 targetActivity = buildClassName(owner.applicationInfo.packageName,
1626 targetActivity, outError);
1627 if (targetActivity == null) {
1628 sa.recycle();
1629 return null;
1630 }
1631
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001632 if (mParseActivityAliasArgs == null) {
1633 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1634 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1635 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1636 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
1637 mSeparateProcesses,
1638 0,
1639 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1640 mParseActivityAliasArgs.tag = "<activity-alias>";
1641 }
1642
1643 mParseActivityAliasArgs.sa = sa;
1644 mParseActivityAliasArgs.flags = flags;
1645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 Activity target = null;
1647
1648 final int NA = owner.activities.size();
1649 for (int i=0; i<NA; i++) {
1650 Activity t = owner.activities.get(i);
1651 if (targetActivity.equals(t.info.name)) {
1652 target = t;
1653 break;
1654 }
1655 }
1656
1657 if (target == null) {
1658 outError[0] = "<activity-alias> target activity " + targetActivity
1659 + " not found in manifest";
1660 sa.recycle();
1661 return null;
1662 }
1663
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001664 ActivityInfo info = new ActivityInfo();
1665 info.targetActivity = targetActivity;
1666 info.configChanges = target.info.configChanges;
1667 info.flags = target.info.flags;
1668 info.icon = target.info.icon;
1669 info.labelRes = target.info.labelRes;
1670 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
1671 info.launchMode = target.info.launchMode;
1672 info.processName = target.info.processName;
1673 info.screenOrientation = target.info.screenOrientation;
1674 info.taskAffinity = target.info.taskAffinity;
1675 info.theme = target.info.theme;
1676
1677 Activity a = new Activity(mParseActivityAliasArgs, info);
1678 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 sa.recycle();
1680 return null;
1681 }
1682
1683 final boolean setExported = sa.hasValue(
1684 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
1685 if (setExported) {
1686 a.info.exported = sa.getBoolean(
1687 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
1688 }
1689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 String str;
1691 str = sa.getNonResourceString(
1692 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission);
1693 if (str != null) {
1694 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1695 }
1696
1697 sa.recycle();
1698
1699 if (outError[0] != null) {
1700 return null;
1701 }
1702
1703 int outerDepth = parser.getDepth();
1704 int type;
1705 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1706 && (type != XmlPullParser.END_TAG
1707 || parser.getDepth() > outerDepth)) {
1708 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1709 continue;
1710 }
1711
1712 if (parser.getName().equals("intent-filter")) {
1713 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1714 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
1715 return null;
1716 }
1717 if (intent.countActions() == 0) {
1718 Log.w(TAG, "Intent filter for activity alias " + intent
1719 + " defines no actions");
1720 } else {
1721 a.intents.add(intent);
1722 }
1723 } else if (parser.getName().equals("meta-data")) {
1724 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1725 outError)) == null) {
1726 return null;
1727 }
1728 } else {
1729 if (!RIGID_PARSER) {
1730 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1731 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName());
1732 XmlUtils.skipCurrentTag(parser);
1733 continue;
1734 }
1735 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
1736 return null;
1737 }
1738 }
1739
1740 if (!setExported) {
1741 a.info.exported = a.intents.size() > 0;
1742 }
1743
1744 return a;
1745 }
1746
1747 private Provider parseProvider(Package owner, Resources res,
1748 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1749 throws XmlPullParserException, IOException {
1750 TypedArray sa = res.obtainAttributes(attrs,
1751 com.android.internal.R.styleable.AndroidManifestProvider);
1752
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001753 if (mParseProviderArgs == null) {
1754 mParseProviderArgs = new ParseComponentArgs(owner, outError,
1755 com.android.internal.R.styleable.AndroidManifestProvider_name,
1756 com.android.internal.R.styleable.AndroidManifestProvider_label,
1757 com.android.internal.R.styleable.AndroidManifestProvider_icon,
1758 mSeparateProcesses,
1759 com.android.internal.R.styleable.AndroidManifestProvider_process,
1760 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
1761 mParseProviderArgs.tag = "<provider>";
1762 }
1763
1764 mParseProviderArgs.sa = sa;
1765 mParseProviderArgs.flags = flags;
1766
1767 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
1768 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 sa.recycle();
1770 return null;
1771 }
1772
1773 p.info.exported = sa.getBoolean(
1774 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
1775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 String cpname = sa.getNonResourceString(
1777 com.android.internal.R.styleable.AndroidManifestProvider_authorities);
1778
1779 p.info.isSyncable = sa.getBoolean(
1780 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
1781 false);
1782
1783 String permission = sa.getNonResourceString(
1784 com.android.internal.R.styleable.AndroidManifestProvider_permission);
1785 String str = sa.getNonResourceString(
1786 com.android.internal.R.styleable.AndroidManifestProvider_readPermission);
1787 if (str == null) {
1788 str = permission;
1789 }
1790 if (str == null) {
1791 p.info.readPermission = owner.applicationInfo.permission;
1792 } else {
1793 p.info.readPermission =
1794 str.length() > 0 ? str.toString().intern() : null;
1795 }
1796 str = sa.getNonResourceString(
1797 com.android.internal.R.styleable.AndroidManifestProvider_writePermission);
1798 if (str == null) {
1799 str = permission;
1800 }
1801 if (str == null) {
1802 p.info.writePermission = owner.applicationInfo.permission;
1803 } else {
1804 p.info.writePermission =
1805 str.length() > 0 ? str.toString().intern() : null;
1806 }
1807
1808 p.info.grantUriPermissions = sa.getBoolean(
1809 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
1810 false);
1811
1812 p.info.multiprocess = sa.getBoolean(
1813 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
1814 false);
1815
1816 p.info.initOrder = sa.getInt(
1817 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
1818 0);
1819
1820 sa.recycle();
1821
1822 if (cpname == null) {
1823 outError[0] = "<provider> does not incude authorities attribute";
1824 return null;
1825 }
1826 p.info.authority = cpname.intern();
1827
1828 if (!parseProviderTags(res, parser, attrs, p, outError)) {
1829 return null;
1830 }
1831
1832 return p;
1833 }
1834
1835 private boolean parseProviderTags(Resources res,
1836 XmlPullParser parser, AttributeSet attrs,
1837 Provider outInfo, String[] outError)
1838 throws XmlPullParserException, IOException {
1839 int outerDepth = parser.getDepth();
1840 int type;
1841 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1842 && (type != XmlPullParser.END_TAG
1843 || parser.getDepth() > outerDepth)) {
1844 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1845 continue;
1846 }
1847
1848 if (parser.getName().equals("meta-data")) {
1849 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
1850 outInfo.metaData, outError)) == null) {
1851 return false;
1852 }
1853 } else if (parser.getName().equals("grant-uri-permission")) {
1854 TypedArray sa = res.obtainAttributes(attrs,
1855 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
1856
1857 PatternMatcher pa = null;
1858
1859 String str = sa.getNonResourceString(
1860 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path);
1861 if (str != null) {
1862 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
1863 }
1864
1865 str = sa.getNonResourceString(
1866 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix);
1867 if (str != null) {
1868 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
1869 }
1870
1871 str = sa.getNonResourceString(
1872 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern);
1873 if (str != null) {
1874 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
1875 }
1876
1877 sa.recycle();
1878
1879 if (pa != null) {
1880 if (outInfo.info.uriPermissionPatterns == null) {
1881 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
1882 outInfo.info.uriPermissionPatterns[0] = pa;
1883 } else {
1884 final int N = outInfo.info.uriPermissionPatterns.length;
1885 PatternMatcher[] newp = new PatternMatcher[N+1];
1886 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
1887 newp[N] = pa;
1888 outInfo.info.uriPermissionPatterns = newp;
1889 }
1890 outInfo.info.grantUriPermissions = true;
1891 }
1892 XmlUtils.skipCurrentTag(parser);
1893
1894 } else {
1895 if (!RIGID_PARSER) {
1896 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1897 Log.w(TAG, "Unknown element under <provider>: "
1898 + parser.getName());
1899 XmlUtils.skipCurrentTag(parser);
1900 continue;
1901 }
1902 outError[0] = "Bad element under <provider>: "
1903 + parser.getName();
1904 return false;
1905 }
1906 }
1907 return true;
1908 }
1909
1910 private Service parseService(Package owner, Resources res,
1911 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1912 throws XmlPullParserException, IOException {
1913 TypedArray sa = res.obtainAttributes(attrs,
1914 com.android.internal.R.styleable.AndroidManifestService);
1915
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001916 if (mParseServiceArgs == null) {
1917 mParseServiceArgs = new ParseComponentArgs(owner, outError,
1918 com.android.internal.R.styleable.AndroidManifestService_name,
1919 com.android.internal.R.styleable.AndroidManifestService_label,
1920 com.android.internal.R.styleable.AndroidManifestService_icon,
1921 mSeparateProcesses,
1922 com.android.internal.R.styleable.AndroidManifestService_process,
1923 com.android.internal.R.styleable.AndroidManifestService_enabled);
1924 mParseServiceArgs.tag = "<service>";
1925 }
1926
1927 mParseServiceArgs.sa = sa;
1928 mParseServiceArgs.flags = flags;
1929
1930 Service s = new Service(mParseServiceArgs, new ServiceInfo());
1931 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 sa.recycle();
1933 return null;
1934 }
1935
1936 final boolean setExported = sa.hasValue(
1937 com.android.internal.R.styleable.AndroidManifestService_exported);
1938 if (setExported) {
1939 s.info.exported = sa.getBoolean(
1940 com.android.internal.R.styleable.AndroidManifestService_exported, false);
1941 }
1942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 String str = sa.getNonResourceString(
1944 com.android.internal.R.styleable.AndroidManifestService_permission);
1945 if (str == null) {
1946 s.info.permission = owner.applicationInfo.permission;
1947 } else {
1948 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
1949 }
1950
1951 sa.recycle();
1952
1953 int outerDepth = parser.getDepth();
1954 int type;
1955 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1956 && (type != XmlPullParser.END_TAG
1957 || parser.getDepth() > outerDepth)) {
1958 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1959 continue;
1960 }
1961
1962 if (parser.getName().equals("intent-filter")) {
1963 ServiceIntentInfo intent = new ServiceIntentInfo(s);
1964 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
1965 return null;
1966 }
1967
1968 s.intents.add(intent);
1969 } else if (parser.getName().equals("meta-data")) {
1970 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
1971 outError)) == null) {
1972 return null;
1973 }
1974 } else {
1975 if (!RIGID_PARSER) {
1976 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1977 Log.w(TAG, "Unknown element under <service>: "
1978 + parser.getName());
1979 XmlUtils.skipCurrentTag(parser);
1980 continue;
1981 }
1982 outError[0] = "Bad element under <service>: "
1983 + parser.getName();
1984 return null;
1985 }
1986 }
1987
1988 if (!setExported) {
1989 s.info.exported = s.intents.size() > 0;
1990 }
1991
1992 return s;
1993 }
1994
1995 private boolean parseAllMetaData(Resources res,
1996 XmlPullParser parser, AttributeSet attrs, String tag,
1997 Component outInfo, String[] outError)
1998 throws XmlPullParserException, IOException {
1999 int outerDepth = parser.getDepth();
2000 int type;
2001 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2002 && (type != XmlPullParser.END_TAG
2003 || parser.getDepth() > outerDepth)) {
2004 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2005 continue;
2006 }
2007
2008 if (parser.getName().equals("meta-data")) {
2009 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2010 outInfo.metaData, outError)) == null) {
2011 return false;
2012 }
2013 } else {
2014 if (!RIGID_PARSER) {
2015 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
2016 Log.w(TAG, "Unknown element under " + tag + ": "
2017 + parser.getName());
2018 XmlUtils.skipCurrentTag(parser);
2019 continue;
2020 }
2021 outError[0] = "Bad element under " + tag + ": "
2022 + parser.getName();
2023 return false;
2024 }
2025 }
2026 return true;
2027 }
2028
2029 private Bundle parseMetaData(Resources res,
2030 XmlPullParser parser, AttributeSet attrs,
2031 Bundle data, String[] outError)
2032 throws XmlPullParserException, IOException {
2033
2034 TypedArray sa = res.obtainAttributes(attrs,
2035 com.android.internal.R.styleable.AndroidManifestMetaData);
2036
2037 if (data == null) {
2038 data = new Bundle();
2039 }
2040
2041 String name = sa.getNonResourceString(
2042 com.android.internal.R.styleable.AndroidManifestMetaData_name);
2043 if (name == null) {
2044 outError[0] = "<meta-data> requires an android:name attribute";
2045 sa.recycle();
2046 return null;
2047 }
2048
2049 boolean success = true;
2050
2051 TypedValue v = sa.peekValue(
2052 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2053 if (v != null && v.resourceId != 0) {
2054 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2055 data.putInt(name, v.resourceId);
2056 } else {
2057 v = sa.peekValue(
2058 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2059 //Log.i(TAG, "Meta data " + name + ": " + v);
2060 if (v != null) {
2061 if (v.type == TypedValue.TYPE_STRING) {
2062 CharSequence cs = v.coerceToString();
2063 data.putString(name, cs != null ? cs.toString() : null);
2064 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2065 data.putBoolean(name, v.data != 0);
2066 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2067 && v.type <= TypedValue.TYPE_LAST_INT) {
2068 data.putInt(name, v.data);
2069 } else if (v.type == TypedValue.TYPE_FLOAT) {
2070 data.putFloat(name, v.getFloat());
2071 } else {
2072 if (!RIGID_PARSER) {
2073 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
2074 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types");
2075 } else {
2076 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2077 data = null;
2078 }
2079 }
2080 } else {
2081 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2082 data = null;
2083 }
2084 }
2085
2086 sa.recycle();
2087
2088 XmlUtils.skipCurrentTag(parser);
2089
2090 return data;
2091 }
2092
2093 private static final String ANDROID_RESOURCES
2094 = "http://schemas.android.com/apk/res/android";
2095
2096 private boolean parseIntent(Resources res,
2097 XmlPullParser parser, AttributeSet attrs, int flags,
2098 IntentInfo outInfo, String[] outError, boolean isActivity)
2099 throws XmlPullParserException, IOException {
2100
2101 TypedArray sa = res.obtainAttributes(attrs,
2102 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2103
2104 int priority = sa.getInt(
2105 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2106 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2107 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
2108 + parser.getPositionDescription());
2109 priority = 0;
2110 }
2111 outInfo.setPriority(priority);
2112
2113 TypedValue v = sa.peekValue(
2114 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2115 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2116 outInfo.nonLocalizedLabel = v.coerceToString();
2117 }
2118
2119 outInfo.icon = sa.getResourceId(
2120 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
2121
2122 sa.recycle();
2123
2124 int outerDepth = parser.getDepth();
2125 int type;
2126 while ((type=parser.next()) != parser.END_DOCUMENT
2127 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2128 if (type == parser.END_TAG || type == parser.TEXT) {
2129 continue;
2130 }
2131
2132 String nodeName = parser.getName();
2133 if (nodeName.equals("action")) {
2134 String value = attrs.getAttributeValue(
2135 ANDROID_RESOURCES, "name");
2136 if (value == null || value == "") {
2137 outError[0] = "No value supplied for <android:name>";
2138 return false;
2139 }
2140 XmlUtils.skipCurrentTag(parser);
2141
2142 outInfo.addAction(value);
2143 } else if (nodeName.equals("category")) {
2144 String value = attrs.getAttributeValue(
2145 ANDROID_RESOURCES, "name");
2146 if (value == null || value == "") {
2147 outError[0] = "No value supplied for <android:name>";
2148 return false;
2149 }
2150 XmlUtils.skipCurrentTag(parser);
2151
2152 outInfo.addCategory(value);
2153
2154 } else if (nodeName.equals("data")) {
2155 sa = res.obtainAttributes(attrs,
2156 com.android.internal.R.styleable.AndroidManifestData);
2157
2158 String str = sa.getNonResourceString(
2159 com.android.internal.R.styleable.AndroidManifestData_mimeType);
2160 if (str != null) {
2161 try {
2162 outInfo.addDataType(str);
2163 } catch (IntentFilter.MalformedMimeTypeException e) {
2164 outError[0] = e.toString();
2165 sa.recycle();
2166 return false;
2167 }
2168 }
2169
2170 str = sa.getNonResourceString(
2171 com.android.internal.R.styleable.AndroidManifestData_scheme);
2172 if (str != null) {
2173 outInfo.addDataScheme(str);
2174 }
2175
2176 String host = sa.getNonResourceString(
2177 com.android.internal.R.styleable.AndroidManifestData_host);
2178 String port = sa.getNonResourceString(
2179 com.android.internal.R.styleable.AndroidManifestData_port);
2180 if (host != null) {
2181 outInfo.addDataAuthority(host, port);
2182 }
2183
2184 str = sa.getNonResourceString(
2185 com.android.internal.R.styleable.AndroidManifestData_path);
2186 if (str != null) {
2187 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2188 }
2189
2190 str = sa.getNonResourceString(
2191 com.android.internal.R.styleable.AndroidManifestData_pathPrefix);
2192 if (str != null) {
2193 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2194 }
2195
2196 str = sa.getNonResourceString(
2197 com.android.internal.R.styleable.AndroidManifestData_pathPattern);
2198 if (str != null) {
2199 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2200 }
2201
2202 sa.recycle();
2203 XmlUtils.skipCurrentTag(parser);
2204 } else if (!RIGID_PARSER) {
2205 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
2206 Log.w(TAG, "Unknown element under <intent-filter>: " + parser.getName());
2207 XmlUtils.skipCurrentTag(parser);
2208 } else {
2209 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2210 return false;
2211 }
2212 }
2213
2214 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2215 if (false) {
2216 String cats = "";
2217 Iterator<String> it = outInfo.categoriesIterator();
2218 while (it != null && it.hasNext()) {
2219 cats += " " + it.next();
2220 }
2221 System.out.println("Intent d=" +
2222 outInfo.hasDefault + ", cat=" + cats);
2223 }
2224
2225 return true;
2226 }
2227
2228 public final static class Package {
2229 public final String packageName;
2230
2231 // For now we only support one application per package.
2232 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2233
2234 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2235 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2236 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2237 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2238 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2239 public final ArrayList<Service> services = new ArrayList<Service>(0);
2240 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2241
2242 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2243
2244 public final ArrayList<String> usesLibraries = new ArrayList<String>();
2245 public String[] usesLibraryFiles = null;
2246
2247 // We store the application meta-data independently to avoid multiple unwanted references
2248 public Bundle mAppMetaData = null;
2249
Mitsuru Oshima8d112672009-04-27 12:01:23 -07002250 public final ArrayList<Integer> supportsDensityList = new ArrayList<Integer>();
2251 public int[] supportsDensities = null;
2252
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07002253 // If the application's window is expandable.
2254 public boolean expandable;
2255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 // If this is a 3rd party app, this is the path of the zip file.
2257 public String mPath;
2258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 // The version code declared for this package.
2260 public int mVersionCode;
2261
2262 // The version name declared for this package.
2263 public String mVersionName;
2264
2265 // The shared user id that this package wants to use.
2266 public String mSharedUserId;
2267
2268 // The shared user label that this package wants to use.
2269 public int mSharedUserLabel;
2270
2271 // Signatures that were read from the package.
2272 public Signature mSignatures[];
2273
2274 // For use by package manager service for quick lookup of
2275 // preferred up order.
2276 public int mPreferredOrder = 0;
2277
2278 // Additional data supplied by callers.
2279 public Object mExtras;
2280
2281 /*
2282 * Applications hardware preferences
2283 */
2284 public final ArrayList<ConfigurationInfo> configPreferences =
2285 new ArrayList<ConfigurationInfo>();
2286
2287 public Package(String _name) {
2288 packageName = _name;
2289 applicationInfo.packageName = _name;
2290 applicationInfo.uid = -1;
2291 }
2292
2293 public String toString() {
2294 return "Package{"
2295 + Integer.toHexString(System.identityHashCode(this))
2296 + " " + packageName + "}";
2297 }
2298 }
2299
2300 public static class Component<II extends IntentInfo> {
2301 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002302 public final ArrayList<II> intents;
2303 public final ComponentName component;
2304 public final String componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 public Bundle metaData;
2306
2307 public Component(Package _owner) {
2308 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002309 intents = null;
2310 component = null;
2311 componentShortName = null;
2312 }
2313
2314 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2315 owner = args.owner;
2316 intents = new ArrayList<II>(0);
2317 String name = args.sa.getNonResourceString(args.nameRes);
2318 if (name == null) {
2319 component = null;
2320 componentShortName = null;
2321 args.outError[0] = args.tag + " does not specify android:name";
2322 return;
2323 }
2324
2325 outInfo.name
2326 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2327 if (outInfo.name == null) {
2328 component = null;
2329 componentShortName = null;
2330 args.outError[0] = args.tag + " does not have valid android:name";
2331 return;
2332 }
2333
2334 component = new ComponentName(owner.applicationInfo.packageName,
2335 outInfo.name);
2336 componentShortName = component.flattenToShortString();
2337
2338 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2339 if (iconVal != 0) {
2340 outInfo.icon = iconVal;
2341 outInfo.nonLocalizedLabel = null;
2342 }
2343
2344 TypedValue v = args.sa.peekValue(args.labelRes);
2345 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2346 outInfo.nonLocalizedLabel = v.coerceToString();
2347 }
2348
2349 outInfo.packageName = owner.packageName;
2350 }
2351
2352 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2353 this(args, (PackageItemInfo)outInfo);
2354 if (args.outError[0] != null) {
2355 return;
2356 }
2357
2358 if (args.processRes != 0) {
2359 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
2360 owner.applicationInfo.processName, args.sa.getNonResourceString(args.processRes),
2361 args.flags, args.sepProcesses, args.outError);
2362 }
2363 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 }
2365
2366 public Component(Component<II> clone) {
2367 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002368 intents = clone.intents;
2369 component = clone.component;
2370 componentShortName = clone.componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 metaData = clone.metaData;
2372 }
2373 }
2374
2375 public final static class Permission extends Component<IntentInfo> {
2376 public final PermissionInfo info;
2377 public boolean tree;
2378 public PermissionGroup group;
2379
2380 public Permission(Package _owner) {
2381 super(_owner);
2382 info = new PermissionInfo();
2383 }
2384
2385 public Permission(Package _owner, PermissionInfo _info) {
2386 super(_owner);
2387 info = _info;
2388 }
2389
2390 public String toString() {
2391 return "Permission{"
2392 + Integer.toHexString(System.identityHashCode(this))
2393 + " " + info.name + "}";
2394 }
2395 }
2396
2397 public final static class PermissionGroup extends Component<IntentInfo> {
2398 public final PermissionGroupInfo info;
2399
2400 public PermissionGroup(Package _owner) {
2401 super(_owner);
2402 info = new PermissionGroupInfo();
2403 }
2404
2405 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2406 super(_owner);
2407 info = _info;
2408 }
2409
2410 public String toString() {
2411 return "PermissionGroup{"
2412 + Integer.toHexString(System.identityHashCode(this))
2413 + " " + info.name + "}";
2414 }
2415 }
2416
2417 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
2418 if ((flags & PackageManager.GET_META_DATA) != 0
2419 && (metaData != null || p.mAppMetaData != null)) {
2420 return true;
2421 }
2422 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
2423 && p.usesLibraryFiles != null) {
2424 return true;
2425 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -07002426 if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07002427 && p.supportsDensities != null) {
2428 return true;
2429 }
2430 if ((flags & PackageManager.GET_EXPANDABLE) != 0) {
Mitsuru Oshima8d112672009-04-27 12:01:23 -07002431 return true;
2432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 return false;
2434 }
2435
2436 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
2437 if (p == null) return null;
2438 if (!copyNeeded(flags, p, null)) {
2439 return p.applicationInfo;
2440 }
2441
2442 // Make shallow copy so we can store the metadata/libraries safely
2443 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
2444 if ((flags & PackageManager.GET_META_DATA) != 0) {
2445 ai.metaData = p.mAppMetaData;
2446 }
2447 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
2448 ai.sharedLibraryFiles = p.usesLibraryFiles;
2449 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -07002450 if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0) {
2451 ai.supportsDensities = p.supportsDensities;
2452 }
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07002453 if ((flags & PackageManager.GET_EXPANDABLE) != 0) {
2454 ai.expandable = p.expandable;
2455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 return ai;
2457 }
2458
2459 public static final PermissionInfo generatePermissionInfo(
2460 Permission p, int flags) {
2461 if (p == null) return null;
2462 if ((flags&PackageManager.GET_META_DATA) == 0) {
2463 return p.info;
2464 }
2465 PermissionInfo pi = new PermissionInfo(p.info);
2466 pi.metaData = p.metaData;
2467 return pi;
2468 }
2469
2470 public static final PermissionGroupInfo generatePermissionGroupInfo(
2471 PermissionGroup pg, int flags) {
2472 if (pg == null) return null;
2473 if ((flags&PackageManager.GET_META_DATA) == 0) {
2474 return pg.info;
2475 }
2476 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
2477 pgi.metaData = pg.metaData;
2478 return pgi;
2479 }
2480
2481 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002482 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002484 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
2485 super(args, _info);
2486 info = _info;
2487 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 public String toString() {
2491 return "Activity{"
2492 + Integer.toHexString(System.identityHashCode(this))
2493 + " " + component.flattenToString() + "}";
2494 }
2495 }
2496
2497 public static final ActivityInfo generateActivityInfo(Activity a,
2498 int flags) {
2499 if (a == null) return null;
2500 if (!copyNeeded(flags, a.owner, a.metaData)) {
2501 return a.info;
2502 }
2503 // Make shallow copies so we can store the metadata safely
2504 ActivityInfo ai = new ActivityInfo(a.info);
2505 ai.metaData = a.metaData;
2506 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
2507 return ai;
2508 }
2509
2510 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002511 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002513 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
2514 super(args, _info);
2515 info = _info;
2516 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519 public String toString() {
2520 return "Service{"
2521 + Integer.toHexString(System.identityHashCode(this))
2522 + " " + component.flattenToString() + "}";
2523 }
2524 }
2525
2526 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
2527 if (s == null) return null;
2528 if (!copyNeeded(flags, s.owner, s.metaData)) {
2529 return s.info;
2530 }
2531 // Make shallow copies so we can store the metadata safely
2532 ServiceInfo si = new ServiceInfo(s.info);
2533 si.metaData = s.metaData;
2534 si.applicationInfo = generateApplicationInfo(s.owner, flags);
2535 return si;
2536 }
2537
2538 public final static class Provider extends Component {
2539 public final ProviderInfo info;
2540 public boolean syncable;
2541
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002542 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
2543 super(args, _info);
2544 info = _info;
2545 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 syncable = false;
2547 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 public Provider(Provider existingProvider) {
2550 super(existingProvider);
2551 this.info = existingProvider.info;
2552 this.syncable = existingProvider.syncable;
2553 }
2554
2555 public String toString() {
2556 return "Provider{"
2557 + Integer.toHexString(System.identityHashCode(this))
2558 + " " + info.name + "}";
2559 }
2560 }
2561
2562 public static final ProviderInfo generateProviderInfo(Provider p,
2563 int flags) {
2564 if (p == null) return null;
2565 if (!copyNeeded(flags, p.owner, p.metaData)
2566 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
2567 || p.info.uriPermissionPatterns == null)) {
2568 return p.info;
2569 }
2570 // Make shallow copies so we can store the metadata safely
2571 ProviderInfo pi = new ProviderInfo(p.info);
2572 pi.metaData = p.metaData;
2573 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
2574 pi.uriPermissionPatterns = null;
2575 }
2576 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
2577 return pi;
2578 }
2579
2580 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002581 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002583 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
2584 super(args, _info);
2585 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 public String toString() {
2589 return "Instrumentation{"
2590 + Integer.toHexString(System.identityHashCode(this))
2591 + " " + component.flattenToString() + "}";
2592 }
2593 }
2594
2595 public static final InstrumentationInfo generateInstrumentationInfo(
2596 Instrumentation i, int flags) {
2597 if (i == null) return null;
2598 if ((flags&PackageManager.GET_META_DATA) == 0) {
2599 return i.info;
2600 }
2601 InstrumentationInfo ii = new InstrumentationInfo(i.info);
2602 ii.metaData = i.metaData;
2603 return ii;
2604 }
2605
2606 public static class IntentInfo extends IntentFilter {
2607 public boolean hasDefault;
2608 public int labelRes;
2609 public CharSequence nonLocalizedLabel;
2610 public int icon;
2611 }
2612
2613 public final static class ActivityIntentInfo extends IntentInfo {
2614 public final Activity activity;
2615
2616 public ActivityIntentInfo(Activity _activity) {
2617 activity = _activity;
2618 }
2619
2620 public String toString() {
2621 return "ActivityIntentInfo{"
2622 + Integer.toHexString(System.identityHashCode(this))
2623 + " " + activity.info.name + "}";
2624 }
2625 }
2626
2627 public final static class ServiceIntentInfo extends IntentInfo {
2628 public final Service service;
2629
2630 public ServiceIntentInfo(Service _service) {
2631 service = _service;
2632 }
2633
2634 public String toString() {
2635 return "ServiceIntentInfo{"
2636 + Integer.toHexString(System.identityHashCode(this))
2637 + " " + service.info.name + "}";
2638 }
2639 }
2640}