blob: 83e63b9c435eccb343bf817e55226574f3d33380 [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
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -070095 private static boolean sCompatibilityModeEnabled = true;
96
Dianne Hackborn1d442e02009-04-20 18:14:05 -070097 static class ParsePackageItemArgs {
98 final Package owner;
99 final String[] outError;
100 final int nameRes;
101 final int labelRes;
102 final int iconRes;
103
104 String tag;
105 TypedArray sa;
106
107 ParsePackageItemArgs(Package _owner, String[] _outError,
108 int _nameRes, int _labelRes, int _iconRes) {
109 owner = _owner;
110 outError = _outError;
111 nameRes = _nameRes;
112 labelRes = _labelRes;
113 iconRes = _iconRes;
114 }
115 }
116
117 static class ParseComponentArgs extends ParsePackageItemArgs {
118 final String[] sepProcesses;
119 final int processRes;
120 final int enabledRes;
121 int flags;
122
123 ParseComponentArgs(Package _owner, String[] _outError,
124 int _nameRes, int _labelRes, int _iconRes,
125 String[] _sepProcesses, int _processRes,int _enabledRes) {
126 super(_owner, _outError, _nameRes, _labelRes, _iconRes);
127 sepProcesses = _sepProcesses;
128 processRes = _processRes;
129 enabledRes = _enabledRes;
130 }
131 }
132
133 private ParsePackageItemArgs mParseInstrumentationArgs;
134 private ParseComponentArgs mParseActivityArgs;
135 private ParseComponentArgs mParseActivityAliasArgs;
136 private ParseComponentArgs mParseServiceArgs;
137 private ParseComponentArgs mParseProviderArgs;
138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 /** If set to true, we will only allow package files that exactly match
140 * the DTD. Otherwise, we try to get as much from the package as we
141 * can without failing. This should normally be set to false, to
142 * support extensions to the DTD in future versions. */
143 private static final boolean RIGID_PARSER = false;
144
145 private static final String TAG = "PackageParser";
146
147 public PackageParser(String archiveSourcePath) {
148 mArchiveSourcePath = archiveSourcePath;
149 }
150
151 public void setSeparateProcesses(String[] procs) {
152 mSeparateProcesses = procs;
153 }
154
Dianne Hackborn851a5412009-05-08 12:06:44 -0700155 public void setSdkVersion(int sdkVersion, String codename) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 mSdkVersion = sdkVersion;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700157 mSdkCodename = codename;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 }
159
160 private static final boolean isPackageFilename(String name) {
161 return name.endsWith(".apk");
162 }
163
164 /**
165 * Generate and return the {@link PackageInfo} for a parsed package.
166 *
167 * @param p the parsed package.
168 * @param flags indicating which optional information is included.
169 */
170 public static PackageInfo generatePackageInfo(PackageParser.Package p,
171 int gids[], int flags) {
172
173 PackageInfo pi = new PackageInfo();
174 pi.packageName = p.packageName;
175 pi.versionCode = p.mVersionCode;
176 pi.versionName = p.mVersionName;
177 pi.sharedUserId = p.mSharedUserId;
178 pi.sharedUserLabel = p.mSharedUserLabel;
179 pi.applicationInfo = p.applicationInfo;
180 if ((flags&PackageManager.GET_GIDS) != 0) {
181 pi.gids = gids;
182 }
183 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
184 int N = p.configPreferences.size();
185 if (N > 0) {
186 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700187 p.configPreferences.toArray(pi.configPreferences);
188 }
189 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
190 if (N > 0) {
191 pi.reqFeatures = new FeatureInfo[N];
192 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194 }
195 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
196 int N = p.activities.size();
197 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700198 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
199 pi.activities = new ActivityInfo[N];
200 } else {
201 int num = 0;
202 for (int i=0; i<N; i++) {
203 if (p.activities.get(i).info.enabled) num++;
204 }
205 pi.activities = new ActivityInfo[num];
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 for (int i=0; i<N; i++) {
208 final Activity activity = p.activities.get(i);
209 if (activity.info.enabled
210 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
211 pi.activities[i] = generateActivityInfo(p.activities.get(i), flags);
212 }
213 }
214 }
215 }
216 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
217 int N = p.receivers.size();
218 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700219 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
220 pi.receivers = new ActivityInfo[N];
221 } else {
222 int num = 0;
223 for (int i=0; i<N; i++) {
224 if (p.receivers.get(i).info.enabled) num++;
225 }
226 pi.receivers = new ActivityInfo[num];
227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 for (int i=0; i<N; i++) {
229 final Activity activity = p.receivers.get(i);
230 if (activity.info.enabled
231 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
232 pi.receivers[i] = generateActivityInfo(p.receivers.get(i), flags);
233 }
234 }
235 }
236 }
237 if ((flags&PackageManager.GET_SERVICES) != 0) {
238 int N = p.services.size();
239 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700240 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
241 pi.services = new ServiceInfo[N];
242 } else {
243 int num = 0;
244 for (int i=0; i<N; i++) {
245 if (p.services.get(i).info.enabled) num++;
246 }
247 pi.services = new ServiceInfo[num];
248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 for (int i=0; i<N; i++) {
250 final Service service = p.services.get(i);
251 if (service.info.enabled
252 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
253 pi.services[i] = generateServiceInfo(p.services.get(i), flags);
254 }
255 }
256 }
257 }
258 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
259 int N = p.providers.size();
260 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700261 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
262 pi.providers = new ProviderInfo[N];
263 } else {
264 int num = 0;
265 for (int i=0; i<N; i++) {
266 if (p.providers.get(i).info.enabled) num++;
267 }
268 pi.providers = new ProviderInfo[num];
269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 for (int i=0; i<N; i++) {
271 final Provider provider = p.providers.get(i);
272 if (provider.info.enabled
273 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
274 pi.providers[i] = generateProviderInfo(p.providers.get(i), flags);
275 }
276 }
277 }
278 }
279 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
280 int N = p.instrumentation.size();
281 if (N > 0) {
282 pi.instrumentation = new InstrumentationInfo[N];
283 for (int i=0; i<N; i++) {
284 pi.instrumentation[i] = generateInstrumentationInfo(
285 p.instrumentation.get(i), flags);
286 }
287 }
288 }
289 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
290 int N = p.permissions.size();
291 if (N > 0) {
292 pi.permissions = new PermissionInfo[N];
293 for (int i=0; i<N; i++) {
294 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
295 }
296 }
297 N = p.requestedPermissions.size();
298 if (N > 0) {
299 pi.requestedPermissions = new String[N];
300 for (int i=0; i<N; i++) {
301 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
302 }
303 }
304 }
305 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapuc7485412009-08-27 12:28:09 -0700306 if (p.mSignatures != null) {
307 int N = p.mSignatures.length;
308 if (N > 0) {
309 pi.signatures = new Signature[N];
310 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313 }
314 return pi;
315 }
316
317 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
318 byte[] readBuffer) {
319 try {
320 // We must read the stream for the JarEntry to retrieve
321 // its certificates.
322 InputStream is = jarFile.getInputStream(je);
323 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
324 // not using
325 }
326 is.close();
327 return je != null ? je.getCertificates() : null;
328 } catch (IOException e) {
329 Log.w(TAG, "Exception reading " + je.getName() + " in "
330 + jarFile.getName(), e);
331 }
332 return null;
333 }
334
335 public final static int PARSE_IS_SYSTEM = 0x0001;
336 public final static int PARSE_CHATTY = 0x0002;
337 public final static int PARSE_MUST_BE_APK = 0x0004;
338 public final static int PARSE_IGNORE_PROCESSES = 0x0008;
339
340 public int getParseError() {
341 return mParseError;
342 }
343
344 public Package parsePackage(File sourceFile, String destFileName,
345 DisplayMetrics metrics, int flags) {
346 mParseError = PackageManager.INSTALL_SUCCEEDED;
347
348 mArchiveSourcePath = sourceFile.getPath();
349 if (!sourceFile.isFile()) {
350 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
351 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
352 return null;
353 }
354 if (!isPackageFilename(sourceFile.getName())
355 && (flags&PARSE_MUST_BE_APK) != 0) {
356 if ((flags&PARSE_IS_SYSTEM) == 0) {
357 // We expect to have non-.apk files in the system dir,
358 // so don't warn about them.
359 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
360 }
361 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
362 return null;
363 }
364
365 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
366 TAG, "Scanning package: " + mArchiveSourcePath);
367
368 XmlResourceParser parser = null;
369 AssetManager assmgr = null;
370 boolean assetError = true;
371 try {
372 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700373 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
374 if(cookie != 0) {
375 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 assetError = false;
377 } else {
378 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
379 }
380 } catch (Exception e) {
381 Log.w(TAG, "Unable to read AndroidManifest.xml of "
382 + mArchiveSourcePath, e);
383 }
384 if(assetError) {
385 if (assmgr != null) assmgr.close();
386 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
387 return null;
388 }
389 String[] errorText = new String[1];
390 Package pkg = null;
391 Exception errorException = null;
392 try {
393 // XXXX todo: need to figure out correct configuration.
394 Resources res = new Resources(assmgr, metrics, null);
395 pkg = parsePackage(res, parser, flags, errorText);
396 } catch (Exception e) {
397 errorException = e;
398 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
399 }
400
401
402 if (pkg == null) {
403 if (errorException != null) {
404 Log.w(TAG, mArchiveSourcePath, errorException);
405 } else {
406 Log.w(TAG, mArchiveSourcePath + " (at "
407 + parser.getPositionDescription()
408 + "): " + errorText[0]);
409 }
410 parser.close();
411 assmgr.close();
412 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
413 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
414 }
415 return null;
416 }
417
418 parser.close();
419 assmgr.close();
420
421 pkg.applicationInfo.sourceDir = destFileName;
422 pkg.applicationInfo.publicSourceDir = destFileName;
423 pkg.mSignatures = null;
424
425 return pkg;
426 }
427
428 public boolean collectCertificates(Package pkg, int flags) {
429 pkg.mSignatures = null;
430
431 WeakReference<byte[]> readBufferRef;
432 byte[] readBuffer = null;
433 synchronized (mSync) {
434 readBufferRef = mReadBuffer;
435 if (readBufferRef != null) {
436 mReadBuffer = null;
437 readBuffer = readBufferRef.get();
438 }
439 if (readBuffer == null) {
440 readBuffer = new byte[8192];
441 readBufferRef = new WeakReference<byte[]>(readBuffer);
442 }
443 }
444
445 try {
446 JarFile jarFile = new JarFile(mArchiveSourcePath);
447
448 Certificate[] certs = null;
449
450 if ((flags&PARSE_IS_SYSTEM) != 0) {
451 // If this package comes from the system image, then we
452 // can trust it... we'll just use the AndroidManifest.xml
453 // to retrieve its signatures, not validating all of the
454 // files.
455 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
456 certs = loadCertificates(jarFile, jarEntry, readBuffer);
457 if (certs == null) {
458 Log.e(TAG, "Package " + pkg.packageName
459 + " has no certificates at entry "
460 + jarEntry.getName() + "; ignoring!");
461 jarFile.close();
462 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
463 return false;
464 }
465 if (false) {
466 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
467 + " certs=" + (certs != null ? certs.length : 0));
468 if (certs != null) {
469 final int N = certs.length;
470 for (int i=0; i<N; i++) {
471 Log.i(TAG, " Public key: "
472 + certs[i].getPublicKey().getEncoded()
473 + " " + certs[i].getPublicKey());
474 }
475 }
476 }
477
478 } else {
479 Enumeration entries = jarFile.entries();
480 while (entries.hasMoreElements()) {
481 JarEntry je = (JarEntry)entries.nextElement();
482 if (je.isDirectory()) continue;
483 if (je.getName().startsWith("META-INF/")) continue;
484 Certificate[] localCerts = loadCertificates(jarFile, je,
485 readBuffer);
486 if (false) {
487 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
488 + ": certs=" + certs + " ("
489 + (certs != null ? certs.length : 0) + ")");
490 }
491 if (localCerts == null) {
492 Log.e(TAG, "Package " + pkg.packageName
493 + " has no certificates at entry "
494 + je.getName() + "; ignoring!");
495 jarFile.close();
496 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
497 return false;
498 } else if (certs == null) {
499 certs = localCerts;
500 } else {
501 // Ensure all certificates match.
502 for (int i=0; i<certs.length; i++) {
503 boolean found = false;
504 for (int j=0; j<localCerts.length; j++) {
505 if (certs[i] != null &&
506 certs[i].equals(localCerts[j])) {
507 found = true;
508 break;
509 }
510 }
511 if (!found || certs.length != localCerts.length) {
512 Log.e(TAG, "Package " + pkg.packageName
513 + " has mismatched certificates at entry "
514 + je.getName() + "; ignoring!");
515 jarFile.close();
516 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
517 return false;
518 }
519 }
520 }
521 }
522 }
523 jarFile.close();
524
525 synchronized (mSync) {
526 mReadBuffer = readBufferRef;
527 }
528
529 if (certs != null && certs.length > 0) {
530 final int N = certs.length;
531 pkg.mSignatures = new Signature[certs.length];
532 for (int i=0; i<N; i++) {
533 pkg.mSignatures[i] = new Signature(
534 certs[i].getEncoded());
535 }
536 } else {
537 Log.e(TAG, "Package " + pkg.packageName
538 + " has no certificates; ignoring!");
539 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
540 return false;
541 }
542 } catch (CertificateEncodingException e) {
543 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
544 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
545 return false;
546 } catch (IOException e) {
547 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
548 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
549 return false;
550 } catch (RuntimeException e) {
551 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
552 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
553 return false;
554 }
555
556 return true;
557 }
558
559 public static String parsePackageName(String packageFilePath, int flags) {
560 XmlResourceParser parser = null;
561 AssetManager assmgr = null;
562 try {
563 assmgr = new AssetManager();
564 int cookie = assmgr.addAssetPath(packageFilePath);
565 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
566 } catch (Exception e) {
567 if (assmgr != null) assmgr.close();
568 Log.w(TAG, "Unable to read AndroidManifest.xml of "
569 + packageFilePath, e);
570 return null;
571 }
572 AttributeSet attrs = parser;
573 String errors[] = new String[1];
574 String packageName = null;
575 try {
576 packageName = parsePackageName(parser, attrs, flags, errors);
577 } catch (IOException e) {
578 Log.w(TAG, packageFilePath, e);
579 } catch (XmlPullParserException e) {
580 Log.w(TAG, packageFilePath, e);
581 } finally {
582 if (parser != null) parser.close();
583 if (assmgr != null) assmgr.close();
584 }
585 if (packageName == null) {
586 Log.e(TAG, "parsePackageName error: " + errors[0]);
587 return null;
588 }
589 return packageName;
590 }
591
592 private static String validateName(String name, boolean requiresSeparator) {
593 final int N = name.length();
594 boolean hasSep = false;
595 boolean front = true;
596 for (int i=0; i<N; i++) {
597 final char c = name.charAt(i);
598 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
599 front = false;
600 continue;
601 }
602 if (!front) {
603 if ((c >= '0' && c <= '9') || c == '_') {
604 continue;
605 }
606 }
607 if (c == '.') {
608 hasSep = true;
609 front = true;
610 continue;
611 }
612 return "bad character '" + c + "'";
613 }
614 return hasSep || !requiresSeparator
615 ? null : "must have at least one '.' separator";
616 }
617
618 private static String parsePackageName(XmlPullParser parser,
619 AttributeSet attrs, int flags, String[] outError)
620 throws IOException, XmlPullParserException {
621
622 int type;
623 while ((type=parser.next()) != parser.START_TAG
624 && type != parser.END_DOCUMENT) {
625 ;
626 }
627
628 if (type != parser.START_TAG) {
629 outError[0] = "No start tag found";
630 return null;
631 }
632 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
633 TAG, "Root element name: '" + parser.getName() + "'");
634 if (!parser.getName().equals("manifest")) {
635 outError[0] = "No <manifest> tag";
636 return null;
637 }
638 String pkgName = attrs.getAttributeValue(null, "package");
639 if (pkgName == null || pkgName.length() == 0) {
640 outError[0] = "<manifest> does not specify package";
641 return null;
642 }
643 String nameError = validateName(pkgName, true);
644 if (nameError != null && !"android".equals(pkgName)) {
645 outError[0] = "<manifest> specifies bad package name \""
646 + pkgName + "\": " + nameError;
647 return null;
648 }
649
650 return pkgName.intern();
651 }
652
653 /**
654 * Temporary.
655 */
656 static public Signature stringToSignature(String str) {
657 final int N = str.length();
658 byte[] sig = new byte[N];
659 for (int i=0; i<N; i++) {
660 sig[i] = (byte)str.charAt(i);
661 }
662 return new Signature(sig);
663 }
664
665 private Package parsePackage(
666 Resources res, XmlResourceParser parser, int flags, String[] outError)
667 throws XmlPullParserException, IOException {
668 AttributeSet attrs = parser;
669
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700670 mParseInstrumentationArgs = null;
671 mParseActivityArgs = null;
672 mParseServiceArgs = null;
673 mParseProviderArgs = null;
674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 String pkgName = parsePackageName(parser, attrs, flags, outError);
676 if (pkgName == null) {
677 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
678 return null;
679 }
680 int type;
681
682 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 TypedArray sa = res.obtainAttributes(attrs,
686 com.android.internal.R.styleable.AndroidManifest);
687 pkg.mVersionCode = sa.getInteger(
688 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
689 pkg.mVersionName = sa.getNonResourceString(
690 com.android.internal.R.styleable.AndroidManifest_versionName);
691 if (pkg.mVersionName != null) {
692 pkg.mVersionName = pkg.mVersionName.intern();
693 }
694 String str = sa.getNonResourceString(
695 com.android.internal.R.styleable.AndroidManifest_sharedUserId);
696 if (str != null) {
697 String nameError = validateName(str, true);
698 if (nameError != null && !"android".equals(pkgName)) {
699 outError[0] = "<manifest> specifies bad sharedUserId name \""
700 + str + "\": " + nameError;
701 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
702 return null;
703 }
704 pkg.mSharedUserId = str.intern();
705 pkg.mSharedUserLabel = sa.getResourceId(
706 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
707 }
708 sa.recycle();
709
Dianne Hackborn723738c2009-06-25 19:48:04 -0700710 // Resource boolean are -1, so 1 means we don't know the value.
711 int supportsSmallScreens = 1;
712 int supportsNormalScreens = 1;
713 int supportsLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700714 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700715 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 int outerDepth = parser.getDepth();
718 while ((type=parser.next()) != parser.END_DOCUMENT
719 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
720 if (type == parser.END_TAG || type == parser.TEXT) {
721 continue;
722 }
723
724 String tagName = parser.getName();
725 if (tagName.equals("application")) {
726 if (foundApp) {
727 if (RIGID_PARSER) {
728 outError[0] = "<manifest> has more than one <application>";
729 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
730 return null;
731 } else {
732 Log.w(TAG, "<manifest> has more than one <application>");
733 XmlUtils.skipCurrentTag(parser);
734 continue;
735 }
736 }
737
738 foundApp = true;
739 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
740 return null;
741 }
742 } else if (tagName.equals("permission-group")) {
743 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
744 return null;
745 }
746 } else if (tagName.equals("permission")) {
747 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
748 return null;
749 }
750 } else if (tagName.equals("permission-tree")) {
751 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
752 return null;
753 }
754 } else if (tagName.equals("uses-permission")) {
755 sa = res.obtainAttributes(attrs,
756 com.android.internal.R.styleable.AndroidManifestUsesPermission);
757
758 String name = sa.getNonResourceString(
759 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
760
761 sa.recycle();
762
763 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700764 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766
767 XmlUtils.skipCurrentTag(parser);
768
769 } else if (tagName.equals("uses-configuration")) {
770 ConfigurationInfo cPref = new ConfigurationInfo();
771 sa = res.obtainAttributes(attrs,
772 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
773 cPref.reqTouchScreen = sa.getInt(
774 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
775 Configuration.TOUCHSCREEN_UNDEFINED);
776 cPref.reqKeyboardType = sa.getInt(
777 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
778 Configuration.KEYBOARD_UNDEFINED);
779 if (sa.getBoolean(
780 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
781 false)) {
782 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
783 }
784 cPref.reqNavigation = sa.getInt(
785 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
786 Configuration.NAVIGATION_UNDEFINED);
787 if (sa.getBoolean(
788 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
789 false)) {
790 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
791 }
792 sa.recycle();
793 pkg.configPreferences.add(cPref);
794
795 XmlUtils.skipCurrentTag(parser);
796
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700797 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700798 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700799 sa = res.obtainAttributes(attrs,
800 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborn49237342009-08-27 20:08:01 -0700801 fi.name = sa.getNonResourceString(
802 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
803 if (fi.name == null) {
804 fi.reqGlEsVersion = sa.getInt(
805 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
806 FeatureInfo.GL_ES_VERSION_UNDEFINED);
807 }
808 if (sa.getBoolean(
809 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
810 true)) {
811 fi.flags |= FeatureInfo.FLAG_REQUIRED;
812 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700813 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700814 if (pkg.reqFeatures == null) {
815 pkg.reqFeatures = new ArrayList<FeatureInfo>();
816 }
817 pkg.reqFeatures.add(fi);
818
819 if (fi.name == null) {
820 ConfigurationInfo cPref = new ConfigurationInfo();
821 cPref.reqGlEsVersion = fi.reqGlEsVersion;
822 pkg.configPreferences.add(cPref);
823 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700824
825 XmlUtils.skipCurrentTag(parser);
826
Dianne Hackborn851a5412009-05-08 12:06:44 -0700827 } else if (tagName.equals("uses-sdk")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 if (mSdkVersion > 0) {
829 sa = res.obtainAttributes(attrs,
830 com.android.internal.R.styleable.AndroidManifestUsesSdk);
831
Dianne Hackborn851a5412009-05-08 12:06:44 -0700832 int minVers = 0;
833 String minCode = null;
834 int targetVers = 0;
835 String targetCode = null;
836
837 TypedValue val = sa.peekValue(
838 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
839 if (val != null) {
840 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
841 targetCode = minCode = val.string.toString();
842 } else {
843 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700844 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700845 }
846 }
847
848 val = sa.peekValue(
849 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
850 if (val != null) {
851 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
852 targetCode = minCode = val.string.toString();
853 } else {
854 // If it's not a string, it's an integer.
855 targetVers = val.data;
856 }
857 }
858
859 int maxVers = sa.getInt(
860 com.android.internal.R.styleable.AndroidManifestUsesSdk_maxSdkVersion,
861 mSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862
863 sa.recycle();
864
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700865 if (minCode != null) {
866 if (!minCode.equals(mSdkCodename)) {
867 if (mSdkCodename != null) {
868 outError[0] = "Requires development platform " + minCode
869 + " (current platform is " + mSdkCodename + ")";
870 } else {
871 outError[0] = "Requires development platform " + minCode
872 + " but this is a release platform.";
873 }
874 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
875 return null;
876 }
877 } else if (minVers > mSdkVersion) {
878 outError[0] = "Requires newer sdk version #" + minVers
879 + " (current version is #" + mSdkVersion + ")";
880 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
881 return null;
882 }
883
Dianne Hackborn851a5412009-05-08 12:06:44 -0700884 if (targetCode != null) {
885 if (!targetCode.equals(mSdkCodename)) {
886 if (mSdkCodename != null) {
887 outError[0] = "Requires development platform " + targetCode
888 + " (current platform is " + mSdkCodename + ")";
889 } else {
890 outError[0] = "Requires development platform " + targetCode
891 + " but this is a release platform.";
892 }
893 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
894 return null;
895 }
896 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700897 pkg.applicationInfo.targetSdkVersion
898 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
899 } else {
900 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700901 }
902
Dianne Hackborn851a5412009-05-08 12:06:44 -0700903 if (maxVers < mSdkVersion) {
904 outError[0] = "Requires older sdk version #" + maxVers
905 + " (current version is #" + mSdkVersion + ")";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
907 return null;
908 }
909 }
910
911 XmlUtils.skipCurrentTag(parser);
912
Dianne Hackborn723738c2009-06-25 19:48:04 -0700913 } else if (tagName.equals("supports-screens")) {
914 sa = res.obtainAttributes(attrs,
915 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
916
917 // This is a trick to get a boolean and still able to detect
918 // if a value was actually set.
919 supportsSmallScreens = sa.getInteger(
920 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
921 supportsSmallScreens);
922 supportsNormalScreens = sa.getInteger(
923 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
924 supportsNormalScreens);
925 supportsLargeScreens = sa.getInteger(
926 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
927 supportsLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700928 resizeable = sa.getInteger(
929 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
930 supportsLargeScreens);
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700931 anyDensity = sa.getInteger(
932 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
933 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700934
935 sa.recycle();
936
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700937 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -0700938
939 } else if (tagName.equals("protected-broadcast")) {
940 sa = res.obtainAttributes(attrs,
941 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
942
943 String name = sa.getNonResourceString(
944 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
945
946 sa.recycle();
947
948 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
949 if (pkg.protectedBroadcasts == null) {
950 pkg.protectedBroadcasts = new ArrayList<String>();
951 }
952 if (!pkg.protectedBroadcasts.contains(name)) {
953 pkg.protectedBroadcasts.add(name.intern());
954 }
955 }
956
957 XmlUtils.skipCurrentTag(parser);
958
959 } else if (tagName.equals("instrumentation")) {
960 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
961 return null;
962 }
963
964 } else if (tagName.equals("eat-comment")) {
965 // Just skip this tag
966 XmlUtils.skipCurrentTag(parser);
967 continue;
968
969 } else if (RIGID_PARSER) {
970 outError[0] = "Bad element under <manifest>: "
971 + parser.getName();
972 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
973 return null;
974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 } else {
976 Log.w(TAG, "Bad element under <manifest>: "
977 + parser.getName());
978 XmlUtils.skipCurrentTag(parser);
979 continue;
980 }
981 }
982
983 if (!foundApp && pkg.instrumentation.size() == 0) {
984 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
985 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
986 }
987
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700988 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700989 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700990 for (int ip=0; ip<NP; ip++) {
991 final PackageParser.NewPermissionInfo npi
992 = PackageParser.NEW_PERMISSIONS[ip];
993 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
994 break;
995 }
996 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700997 if (implicitPerms == null) {
998 implicitPerms = new StringBuilder(128);
999 implicitPerms.append(pkg.packageName);
1000 implicitPerms.append(": compat added ");
1001 } else {
1002 implicitPerms.append(' ');
1003 }
1004 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001005 pkg.requestedPermissions.add(npi.name);
1006 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001007 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001008 if (implicitPerms != null) {
1009 Log.i(TAG, implicitPerms.toString());
1010 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001011
Dianne Hackborn723738c2009-06-25 19:48:04 -07001012 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1013 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001014 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001015 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1016 }
1017 if (supportsNormalScreens != 0) {
1018 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1019 }
1020 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1021 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001022 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001023 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1024 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001025 if (resizeable < 0 || (resizeable > 0
1026 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001027 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001028 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1029 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001030 if (anyDensity < 0 || (anyDensity > 0
1031 && pkg.applicationInfo.targetSdkVersion
1032 >= android.os.Build.VERSION_CODES.DONUT)) {
1033 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001034 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 return pkg;
1037 }
1038
1039 private static String buildClassName(String pkg, CharSequence clsSeq,
1040 String[] outError) {
1041 if (clsSeq == null || clsSeq.length() <= 0) {
1042 outError[0] = "Empty class name in package " + pkg;
1043 return null;
1044 }
1045 String cls = clsSeq.toString();
1046 char c = cls.charAt(0);
1047 if (c == '.') {
1048 return (pkg + cls).intern();
1049 }
1050 if (cls.indexOf('.') < 0) {
1051 StringBuilder b = new StringBuilder(pkg);
1052 b.append('.');
1053 b.append(cls);
1054 return b.toString().intern();
1055 }
1056 if (c >= 'a' && c <= 'z') {
1057 return cls.intern();
1058 }
1059 outError[0] = "Bad class name " + cls + " in package " + pkg;
1060 return null;
1061 }
1062
1063 private static String buildCompoundName(String pkg,
1064 CharSequence procSeq, String type, String[] outError) {
1065 String proc = procSeq.toString();
1066 char c = proc.charAt(0);
1067 if (pkg != null && c == ':') {
1068 if (proc.length() < 2) {
1069 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1070 + ": must be at least two characters";
1071 return null;
1072 }
1073 String subName = proc.substring(1);
1074 String nameError = validateName(subName, false);
1075 if (nameError != null) {
1076 outError[0] = "Invalid " + type + " name " + proc + " in package "
1077 + pkg + ": " + nameError;
1078 return null;
1079 }
1080 return (pkg + proc).intern();
1081 }
1082 String nameError = validateName(proc, true);
1083 if (nameError != null && !"system".equals(proc)) {
1084 outError[0] = "Invalid " + type + " name " + proc + " in package "
1085 + pkg + ": " + nameError;
1086 return null;
1087 }
1088 return proc.intern();
1089 }
1090
1091 private static String buildProcessName(String pkg, String defProc,
1092 CharSequence procSeq, int flags, String[] separateProcesses,
1093 String[] outError) {
1094 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1095 return defProc != null ? defProc : pkg;
1096 }
1097 if (separateProcesses != null) {
1098 for (int i=separateProcesses.length-1; i>=0; i--) {
1099 String sp = separateProcesses[i];
1100 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1101 return pkg;
1102 }
1103 }
1104 }
1105 if (procSeq == null || procSeq.length() <= 0) {
1106 return defProc;
1107 }
1108 return buildCompoundName(pkg, procSeq, "package", outError);
1109 }
1110
1111 private static String buildTaskAffinityName(String pkg, String defProc,
1112 CharSequence procSeq, String[] outError) {
1113 if (procSeq == null) {
1114 return defProc;
1115 }
1116 if (procSeq.length() <= 0) {
1117 return null;
1118 }
1119 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1120 }
1121
1122 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1123 XmlPullParser parser, AttributeSet attrs, String[] outError)
1124 throws XmlPullParserException, IOException {
1125 PermissionGroup perm = new PermissionGroup(owner);
1126
1127 TypedArray sa = res.obtainAttributes(attrs,
1128 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1129
1130 if (!parsePackageItemInfo(owner, perm.info, outError,
1131 "<permission-group>", sa,
1132 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1133 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
1134 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon)) {
1135 sa.recycle();
1136 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1137 return null;
1138 }
1139
1140 perm.info.descriptionRes = sa.getResourceId(
1141 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1142 0);
1143
1144 sa.recycle();
1145
1146 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1147 outError)) {
1148 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1149 return null;
1150 }
1151
1152 owner.permissionGroups.add(perm);
1153
1154 return perm;
1155 }
1156
1157 private Permission parsePermission(Package owner, Resources res,
1158 XmlPullParser parser, AttributeSet attrs, String[] outError)
1159 throws XmlPullParserException, IOException {
1160 Permission perm = new Permission(owner);
1161
1162 TypedArray sa = res.obtainAttributes(attrs,
1163 com.android.internal.R.styleable.AndroidManifestPermission);
1164
1165 if (!parsePackageItemInfo(owner, perm.info, outError,
1166 "<permission>", sa,
1167 com.android.internal.R.styleable.AndroidManifestPermission_name,
1168 com.android.internal.R.styleable.AndroidManifestPermission_label,
1169 com.android.internal.R.styleable.AndroidManifestPermission_icon)) {
1170 sa.recycle();
1171 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1172 return null;
1173 }
1174
1175 perm.info.group = sa.getNonResourceString(
1176 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1177 if (perm.info.group != null) {
1178 perm.info.group = perm.info.group.intern();
1179 }
1180
1181 perm.info.descriptionRes = sa.getResourceId(
1182 com.android.internal.R.styleable.AndroidManifestPermission_description,
1183 0);
1184
1185 perm.info.protectionLevel = sa.getInt(
1186 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1187 PermissionInfo.PROTECTION_NORMAL);
1188
1189 sa.recycle();
1190
1191 if (perm.info.protectionLevel == -1) {
1192 outError[0] = "<permission> does not specify protectionLevel";
1193 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1194 return null;
1195 }
1196
1197 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1198 outError)) {
1199 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1200 return null;
1201 }
1202
1203 owner.permissions.add(perm);
1204
1205 return perm;
1206 }
1207
1208 private Permission parsePermissionTree(Package owner, Resources res,
1209 XmlPullParser parser, AttributeSet attrs, String[] outError)
1210 throws XmlPullParserException, IOException {
1211 Permission perm = new Permission(owner);
1212
1213 TypedArray sa = res.obtainAttributes(attrs,
1214 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1215
1216 if (!parsePackageItemInfo(owner, perm.info, outError,
1217 "<permission-tree>", sa,
1218 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1219 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
1220 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon)) {
1221 sa.recycle();
1222 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1223 return null;
1224 }
1225
1226 sa.recycle();
1227
1228 int index = perm.info.name.indexOf('.');
1229 if (index > 0) {
1230 index = perm.info.name.indexOf('.', index+1);
1231 }
1232 if (index < 0) {
1233 outError[0] = "<permission-tree> name has less than three segments: "
1234 + perm.info.name;
1235 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1236 return null;
1237 }
1238
1239 perm.info.descriptionRes = 0;
1240 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1241 perm.tree = true;
1242
1243 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1244 outError)) {
1245 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1246 return null;
1247 }
1248
1249 owner.permissions.add(perm);
1250
1251 return perm;
1252 }
1253
1254 private Instrumentation parseInstrumentation(Package owner, Resources res,
1255 XmlPullParser parser, AttributeSet attrs, String[] outError)
1256 throws XmlPullParserException, IOException {
1257 TypedArray sa = res.obtainAttributes(attrs,
1258 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1259
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001260 if (mParseInstrumentationArgs == null) {
1261 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1262 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1263 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
1264 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon);
1265 mParseInstrumentationArgs.tag = "<instrumentation>";
1266 }
1267
1268 mParseInstrumentationArgs.sa = sa;
1269
1270 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1271 new InstrumentationInfo());
1272 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 sa.recycle();
1274 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1275 return null;
1276 }
1277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 String str;
1279 str = sa.getNonResourceString(
1280 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1281 a.info.targetPackage = str != null ? str.intern() : null;
1282
1283 a.info.handleProfiling = sa.getBoolean(
1284 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1285 false);
1286
1287 a.info.functionalTest = sa.getBoolean(
1288 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1289 false);
1290
1291 sa.recycle();
1292
1293 if (a.info.targetPackage == null) {
1294 outError[0] = "<instrumentation> does not specify targetPackage";
1295 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1296 return null;
1297 }
1298
1299 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1300 outError)) {
1301 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1302 return null;
1303 }
1304
1305 owner.instrumentation.add(a);
1306
1307 return a;
1308 }
1309
1310 private boolean parseApplication(Package owner, Resources res,
1311 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1312 throws XmlPullParserException, IOException {
1313 final ApplicationInfo ai = owner.applicationInfo;
1314 final String pkgName = owner.applicationInfo.packageName;
1315
1316 TypedArray sa = res.obtainAttributes(attrs,
1317 com.android.internal.R.styleable.AndroidManifestApplication);
1318
1319 String name = sa.getNonResourceString(
1320 com.android.internal.R.styleable.AndroidManifestApplication_name);
1321 if (name != null) {
1322 ai.className = buildClassName(pkgName, name, outError);
1323 if (ai.className == null) {
1324 sa.recycle();
1325 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1326 return false;
1327 }
1328 }
1329
1330 String manageSpaceActivity = sa.getNonResourceString(
1331 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity);
1332 if (manageSpaceActivity != null) {
1333 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1334 outError);
1335 }
1336
Christopher Tate181fafa2009-05-14 11:12:14 -07001337 boolean allowBackup = sa.getBoolean(
1338 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1339 if (allowBackup) {
1340 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001341
1342 // backupAgent, killAfterRestore, and restoreNeedsApplication are only relevant
1343 // if backup is possible for the given application.
Christopher Tate181fafa2009-05-14 11:12:14 -07001344 String backupAgent = sa.getNonResourceString(
1345 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent);
1346 if (backupAgent != null) {
1347 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001348 if (false) {
1349 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1350 + " from " + pkgName + "+" + backupAgent);
1351 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001352
1353 if (sa.getBoolean(
1354 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1355 true)) {
1356 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1357 }
1358 if (sa.getBoolean(
1359 com.android.internal.R.styleable.AndroidManifestApplication_restoreNeedsApplication,
1360 false)) {
1361 ai.flags |= ApplicationInfo.FLAG_RESTORE_NEEDS_APPLICATION;
1362 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001363 }
1364 }
1365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 TypedValue v = sa.peekValue(
1367 com.android.internal.R.styleable.AndroidManifestApplication_label);
1368 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1369 ai.nonLocalizedLabel = v.coerceToString();
1370 }
1371
1372 ai.icon = sa.getResourceId(
1373 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1374 ai.theme = sa.getResourceId(
1375 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1376 ai.descriptionRes = sa.getResourceId(
1377 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1378
1379 if ((flags&PARSE_IS_SYSTEM) != 0) {
1380 if (sa.getBoolean(
1381 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1382 false)) {
1383 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1384 }
1385 }
1386
1387 if (sa.getBoolean(
1388 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1389 false)) {
1390 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1391 }
1392
1393 if (sa.getBoolean(
1394 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1395 true)) {
1396 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1397 }
1398
1399 if (sa.getBoolean(
1400 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1401 false)) {
1402 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1403 }
1404
1405 if (sa.getBoolean(
1406 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1407 true)) {
1408 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1409 }
1410
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001411 if (sa.getBoolean(
1412 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001413 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001414 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1415 }
1416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 String str;
1418 str = sa.getNonResourceString(
1419 com.android.internal.R.styleable.AndroidManifestApplication_permission);
1420 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1421
1422 str = sa.getNonResourceString(
1423 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1424 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1425 str, outError);
1426
1427 if (outError[0] == null) {
1428 ai.processName = buildProcessName(ai.packageName, null, sa.getNonResourceString(
1429 com.android.internal.R.styleable.AndroidManifestApplication_process),
1430 flags, mSeparateProcesses, outError);
1431
1432 ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
1433 }
1434
1435 sa.recycle();
1436
1437 if (outError[0] != null) {
1438 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1439 return false;
1440 }
1441
1442 final int innerDepth = parser.getDepth();
1443
1444 int type;
1445 while ((type=parser.next()) != parser.END_DOCUMENT
1446 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1447 if (type == parser.END_TAG || type == parser.TEXT) {
1448 continue;
1449 }
1450
1451 String tagName = parser.getName();
1452 if (tagName.equals("activity")) {
1453 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1454 if (a == null) {
1455 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1456 return false;
1457 }
1458
1459 owner.activities.add(a);
1460
1461 } else if (tagName.equals("receiver")) {
1462 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1463 if (a == null) {
1464 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1465 return false;
1466 }
1467
1468 owner.receivers.add(a);
1469
1470 } else if (tagName.equals("service")) {
1471 Service s = parseService(owner, res, parser, attrs, flags, outError);
1472 if (s == null) {
1473 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1474 return false;
1475 }
1476
1477 owner.services.add(s);
1478
1479 } else if (tagName.equals("provider")) {
1480 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1481 if (p == null) {
1482 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1483 return false;
1484 }
1485
1486 owner.providers.add(p);
1487
1488 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001489 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 if (a == null) {
1491 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1492 return false;
1493 }
1494
1495 owner.activities.add(a);
1496
1497 } else if (parser.getName().equals("meta-data")) {
1498 // note: application meta-data is stored off to the side, so it can
1499 // remain null in the primary copy (we like to avoid extra copies because
1500 // it can be large)
1501 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1502 outError)) == null) {
1503 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1504 return false;
1505 }
1506
1507 } else if (tagName.equals("uses-library")) {
1508 sa = res.obtainAttributes(attrs,
1509 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1510
1511 String lname = sa.getNonResourceString(
1512 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001513 boolean req = sa.getBoolean(
1514 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1515 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516
1517 sa.recycle();
1518
Dianne Hackborn49237342009-08-27 20:08:01 -07001519 if (lname != null) {
1520 if (req) {
1521 if (owner.usesLibraries == null) {
1522 owner.usesLibraries = new ArrayList<String>();
1523 }
1524 if (!owner.usesLibraries.contains(lname)) {
1525 owner.usesLibraries.add(lname.intern());
1526 }
1527 } else {
1528 if (owner.usesOptionalLibraries == null) {
1529 owner.usesOptionalLibraries = new ArrayList<String>();
1530 }
1531 if (!owner.usesOptionalLibraries.contains(lname)) {
1532 owner.usesOptionalLibraries.add(lname.intern());
1533 }
1534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 }
1536
1537 XmlUtils.skipCurrentTag(parser);
1538
1539 } else {
1540 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001541 Log.w(TAG, "Unknown element under <application>: " + tagName
1542 + " at " + mArchiveSourcePath + " "
1543 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 XmlUtils.skipCurrentTag(parser);
1545 continue;
1546 } else {
1547 outError[0] = "Bad element under <application>: " + tagName;
1548 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1549 return false;
1550 }
1551 }
1552 }
1553
1554 return true;
1555 }
1556
1557 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1558 String[] outError, String tag, TypedArray sa,
1559 int nameRes, int labelRes, int iconRes) {
1560 String name = sa.getNonResourceString(nameRes);
1561 if (name == null) {
1562 outError[0] = tag + " does not specify android:name";
1563 return false;
1564 }
1565
1566 outInfo.name
1567 = buildClassName(owner.applicationInfo.packageName, name, outError);
1568 if (outInfo.name == null) {
1569 return false;
1570 }
1571
1572 int iconVal = sa.getResourceId(iconRes, 0);
1573 if (iconVal != 0) {
1574 outInfo.icon = iconVal;
1575 outInfo.nonLocalizedLabel = null;
1576 }
1577
1578 TypedValue v = sa.peekValue(labelRes);
1579 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1580 outInfo.nonLocalizedLabel = v.coerceToString();
1581 }
1582
1583 outInfo.packageName = owner.packageName;
1584
1585 return true;
1586 }
1587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 private Activity parseActivity(Package owner, Resources res,
1589 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1590 boolean receiver) throws XmlPullParserException, IOException {
1591 TypedArray sa = res.obtainAttributes(attrs,
1592 com.android.internal.R.styleable.AndroidManifestActivity);
1593
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001594 if (mParseActivityArgs == null) {
1595 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1596 com.android.internal.R.styleable.AndroidManifestActivity_name,
1597 com.android.internal.R.styleable.AndroidManifestActivity_label,
1598 com.android.internal.R.styleable.AndroidManifestActivity_icon,
1599 mSeparateProcesses,
1600 com.android.internal.R.styleable.AndroidManifestActivity_process,
1601 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1602 }
1603
1604 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1605 mParseActivityArgs.sa = sa;
1606 mParseActivityArgs.flags = flags;
1607
1608 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1609 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 sa.recycle();
1611 return null;
1612 }
1613
1614 final boolean setExported = sa.hasValue(
1615 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1616 if (setExported) {
1617 a.info.exported = sa.getBoolean(
1618 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1619 }
1620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 a.info.theme = sa.getResourceId(
1622 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1623
1624 String str;
1625 str = sa.getNonResourceString(
1626 com.android.internal.R.styleable.AndroidManifestActivity_permission);
1627 if (str == null) {
1628 a.info.permission = owner.applicationInfo.permission;
1629 } else {
1630 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1631 }
1632
1633 str = sa.getNonResourceString(
1634 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity);
1635 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1636 owner.applicationInfo.taskAffinity, str, outError);
1637
1638 a.info.flags = 0;
1639 if (sa.getBoolean(
1640 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1641 false)) {
1642 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1643 }
1644
1645 if (sa.getBoolean(
1646 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1647 false)) {
1648 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1649 }
1650
1651 if (sa.getBoolean(
1652 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1653 false)) {
1654 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1655 }
1656
1657 if (sa.getBoolean(
1658 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1659 false)) {
1660 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1661 }
1662
1663 if (sa.getBoolean(
1664 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1665 false)) {
1666 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1667 }
1668
1669 if (sa.getBoolean(
1670 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1671 false)) {
1672 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1673 }
1674
1675 if (sa.getBoolean(
1676 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1677 false)) {
1678 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1679 }
1680
1681 if (sa.getBoolean(
1682 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1683 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1684 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1685 }
1686
Dianne Hackbornffa42482009-09-23 22:20:11 -07001687 if (sa.getBoolean(
1688 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1689 false)) {
1690 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1691 }
1692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 if (!receiver) {
1694 a.info.launchMode = sa.getInt(
1695 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1696 ActivityInfo.LAUNCH_MULTIPLE);
1697 a.info.screenOrientation = sa.getInt(
1698 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1699 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1700 a.info.configChanges = sa.getInt(
1701 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1702 0);
1703 a.info.softInputMode = sa.getInt(
1704 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1705 0);
1706 } else {
1707 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1708 a.info.configChanges = 0;
1709 }
1710
1711 sa.recycle();
1712
1713 if (outError[0] != null) {
1714 return null;
1715 }
1716
1717 int outerDepth = parser.getDepth();
1718 int type;
1719 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1720 && (type != XmlPullParser.END_TAG
1721 || parser.getDepth() > outerDepth)) {
1722 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1723 continue;
1724 }
1725
1726 if (parser.getName().equals("intent-filter")) {
1727 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1728 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1729 return null;
1730 }
1731 if (intent.countActions() == 0) {
1732 Log.w(TAG, "Intent filter for activity " + intent
1733 + " defines no actions");
1734 } else {
1735 a.intents.add(intent);
1736 }
1737 } else if (parser.getName().equals("meta-data")) {
1738 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1739 outError)) == null) {
1740 return null;
1741 }
1742 } else {
1743 if (!RIGID_PARSER) {
1744 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1745 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001746 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1747 + " at " + mArchiveSourcePath + " "
1748 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001750 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1751 + " at " + mArchiveSourcePath + " "
1752 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 }
1754 XmlUtils.skipCurrentTag(parser);
1755 continue;
1756 }
1757 if (receiver) {
1758 outError[0] = "Bad element under <receiver>: " + parser.getName();
1759 } else {
1760 outError[0] = "Bad element under <activity>: " + parser.getName();
1761 }
1762 return null;
1763 }
1764 }
1765
1766 if (!setExported) {
1767 a.info.exported = a.intents.size() > 0;
1768 }
1769
1770 return a;
1771 }
1772
1773 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001774 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1775 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 TypedArray sa = res.obtainAttributes(attrs,
1777 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1778
1779 String targetActivity = sa.getNonResourceString(
1780 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity);
1781 if (targetActivity == null) {
1782 outError[0] = "<activity-alias> does not specify android:targetActivity";
1783 sa.recycle();
1784 return null;
1785 }
1786
1787 targetActivity = buildClassName(owner.applicationInfo.packageName,
1788 targetActivity, outError);
1789 if (targetActivity == null) {
1790 sa.recycle();
1791 return null;
1792 }
1793
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001794 if (mParseActivityAliasArgs == null) {
1795 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1796 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1797 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1798 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
1799 mSeparateProcesses,
1800 0,
1801 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1802 mParseActivityAliasArgs.tag = "<activity-alias>";
1803 }
1804
1805 mParseActivityAliasArgs.sa = sa;
1806 mParseActivityAliasArgs.flags = flags;
1807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 Activity target = null;
1809
1810 final int NA = owner.activities.size();
1811 for (int i=0; i<NA; i++) {
1812 Activity t = owner.activities.get(i);
1813 if (targetActivity.equals(t.info.name)) {
1814 target = t;
1815 break;
1816 }
1817 }
1818
1819 if (target == null) {
1820 outError[0] = "<activity-alias> target activity " + targetActivity
1821 + " not found in manifest";
1822 sa.recycle();
1823 return null;
1824 }
1825
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001826 ActivityInfo info = new ActivityInfo();
1827 info.targetActivity = targetActivity;
1828 info.configChanges = target.info.configChanges;
1829 info.flags = target.info.flags;
1830 info.icon = target.info.icon;
1831 info.labelRes = target.info.labelRes;
1832 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
1833 info.launchMode = target.info.launchMode;
1834 info.processName = target.info.processName;
1835 info.screenOrientation = target.info.screenOrientation;
1836 info.taskAffinity = target.info.taskAffinity;
1837 info.theme = target.info.theme;
1838
1839 Activity a = new Activity(mParseActivityAliasArgs, info);
1840 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001841 sa.recycle();
1842 return null;
1843 }
1844
1845 final boolean setExported = sa.hasValue(
1846 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
1847 if (setExported) {
1848 a.info.exported = sa.getBoolean(
1849 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
1850 }
1851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 String str;
1853 str = sa.getNonResourceString(
1854 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission);
1855 if (str != null) {
1856 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1857 }
1858
1859 sa.recycle();
1860
1861 if (outError[0] != null) {
1862 return null;
1863 }
1864
1865 int outerDepth = parser.getDepth();
1866 int type;
1867 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1868 && (type != XmlPullParser.END_TAG
1869 || parser.getDepth() > outerDepth)) {
1870 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1871 continue;
1872 }
1873
1874 if (parser.getName().equals("intent-filter")) {
1875 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1876 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
1877 return null;
1878 }
1879 if (intent.countActions() == 0) {
1880 Log.w(TAG, "Intent filter for activity alias " + intent
1881 + " defines no actions");
1882 } else {
1883 a.intents.add(intent);
1884 }
1885 } else if (parser.getName().equals("meta-data")) {
1886 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1887 outError)) == null) {
1888 return null;
1889 }
1890 } else {
1891 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001892 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
1893 + " at " + mArchiveSourcePath + " "
1894 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 XmlUtils.skipCurrentTag(parser);
1896 continue;
1897 }
1898 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
1899 return null;
1900 }
1901 }
1902
1903 if (!setExported) {
1904 a.info.exported = a.intents.size() > 0;
1905 }
1906
1907 return a;
1908 }
1909
1910 private Provider parseProvider(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.AndroidManifestProvider);
1915
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001916 if (mParseProviderArgs == null) {
1917 mParseProviderArgs = new ParseComponentArgs(owner, outError,
1918 com.android.internal.R.styleable.AndroidManifestProvider_name,
1919 com.android.internal.R.styleable.AndroidManifestProvider_label,
1920 com.android.internal.R.styleable.AndroidManifestProvider_icon,
1921 mSeparateProcesses,
1922 com.android.internal.R.styleable.AndroidManifestProvider_process,
1923 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
1924 mParseProviderArgs.tag = "<provider>";
1925 }
1926
1927 mParseProviderArgs.sa = sa;
1928 mParseProviderArgs.flags = flags;
1929
1930 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
1931 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 sa.recycle();
1933 return null;
1934 }
1935
1936 p.info.exported = sa.getBoolean(
1937 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
1938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 String cpname = sa.getNonResourceString(
1940 com.android.internal.R.styleable.AndroidManifestProvider_authorities);
1941
1942 p.info.isSyncable = sa.getBoolean(
1943 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
1944 false);
1945
1946 String permission = sa.getNonResourceString(
1947 com.android.internal.R.styleable.AndroidManifestProvider_permission);
1948 String str = sa.getNonResourceString(
1949 com.android.internal.R.styleable.AndroidManifestProvider_readPermission);
1950 if (str == null) {
1951 str = permission;
1952 }
1953 if (str == null) {
1954 p.info.readPermission = owner.applicationInfo.permission;
1955 } else {
1956 p.info.readPermission =
1957 str.length() > 0 ? str.toString().intern() : null;
1958 }
1959 str = sa.getNonResourceString(
1960 com.android.internal.R.styleable.AndroidManifestProvider_writePermission);
1961 if (str == null) {
1962 str = permission;
1963 }
1964 if (str == null) {
1965 p.info.writePermission = owner.applicationInfo.permission;
1966 } else {
1967 p.info.writePermission =
1968 str.length() > 0 ? str.toString().intern() : null;
1969 }
1970
1971 p.info.grantUriPermissions = sa.getBoolean(
1972 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
1973 false);
1974
1975 p.info.multiprocess = sa.getBoolean(
1976 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
1977 false);
1978
1979 p.info.initOrder = sa.getInt(
1980 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
1981 0);
1982
1983 sa.recycle();
1984
1985 if (cpname == null) {
1986 outError[0] = "<provider> does not incude authorities attribute";
1987 return null;
1988 }
1989 p.info.authority = cpname.intern();
1990
1991 if (!parseProviderTags(res, parser, attrs, p, outError)) {
1992 return null;
1993 }
1994
1995 return p;
1996 }
1997
1998 private boolean parseProviderTags(Resources res,
1999 XmlPullParser parser, AttributeSet attrs,
2000 Provider outInfo, String[] outError)
2001 throws XmlPullParserException, IOException {
2002 int outerDepth = parser.getDepth();
2003 int type;
2004 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2005 && (type != XmlPullParser.END_TAG
2006 || parser.getDepth() > outerDepth)) {
2007 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2008 continue;
2009 }
2010
2011 if (parser.getName().equals("meta-data")) {
2012 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2013 outInfo.metaData, outError)) == null) {
2014 return false;
2015 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 } else if (parser.getName().equals("grant-uri-permission")) {
2018 TypedArray sa = res.obtainAttributes(attrs,
2019 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2020
2021 PatternMatcher pa = null;
2022
2023 String str = sa.getNonResourceString(
2024 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path);
2025 if (str != null) {
2026 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2027 }
2028
2029 str = sa.getNonResourceString(
2030 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix);
2031 if (str != null) {
2032 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2033 }
2034
2035 str = sa.getNonResourceString(
2036 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern);
2037 if (str != null) {
2038 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2039 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 sa.recycle();
2042
2043 if (pa != null) {
2044 if (outInfo.info.uriPermissionPatterns == null) {
2045 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2046 outInfo.info.uriPermissionPatterns[0] = pa;
2047 } else {
2048 final int N = outInfo.info.uriPermissionPatterns.length;
2049 PatternMatcher[] newp = new PatternMatcher[N+1];
2050 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2051 newp[N] = pa;
2052 outInfo.info.uriPermissionPatterns = newp;
2053 }
2054 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002055 } else {
2056 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002057 Log.w(TAG, "Unknown element under <path-permission>: "
2058 + parser.getName() + " at " + mArchiveSourcePath + " "
2059 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002060 XmlUtils.skipCurrentTag(parser);
2061 continue;
2062 }
2063 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2064 return false;
2065 }
2066 XmlUtils.skipCurrentTag(parser);
2067
2068 } else if (parser.getName().equals("path-permission")) {
2069 TypedArray sa = res.obtainAttributes(attrs,
2070 com.android.internal.R.styleable.AndroidManifestPathPermission);
2071
2072 PathPermission pa = null;
2073
2074 String permission = sa.getNonResourceString(
2075 com.android.internal.R.styleable.AndroidManifestPathPermission_permission);
2076 String readPermission = sa.getNonResourceString(
2077 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission);
2078 if (readPermission == null) {
2079 readPermission = permission;
2080 }
2081 String writePermission = sa.getNonResourceString(
2082 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission);
2083 if (writePermission == null) {
2084 writePermission = permission;
2085 }
2086
2087 boolean havePerm = false;
2088 if (readPermission != null) {
2089 readPermission = readPermission.intern();
2090 havePerm = true;
2091 }
2092 if (writePermission != null) {
2093 writePermission = readPermission.intern();
2094 havePerm = true;
2095 }
2096
2097 if (!havePerm) {
2098 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002099 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2100 + parser.getName() + " at " + mArchiveSourcePath + " "
2101 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002102 XmlUtils.skipCurrentTag(parser);
2103 continue;
2104 }
2105 outError[0] = "No readPermission or writePermssion for <path-permission>";
2106 return false;
2107 }
2108
2109 String path = sa.getNonResourceString(
2110 com.android.internal.R.styleable.AndroidManifestPathPermission_path);
2111 if (path != null) {
2112 pa = new PathPermission(path,
2113 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2114 }
2115
2116 path = sa.getNonResourceString(
2117 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix);
2118 if (path != null) {
2119 pa = new PathPermission(path,
2120 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2121 }
2122
2123 path = sa.getNonResourceString(
2124 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern);
2125 if (path != null) {
2126 pa = new PathPermission(path,
2127 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2128 }
2129
2130 sa.recycle();
2131
2132 if (pa != null) {
2133 if (outInfo.info.pathPermissions == null) {
2134 outInfo.info.pathPermissions = new PathPermission[1];
2135 outInfo.info.pathPermissions[0] = pa;
2136 } else {
2137 final int N = outInfo.info.pathPermissions.length;
2138 PathPermission[] newp = new PathPermission[N+1];
2139 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2140 newp[N] = pa;
2141 outInfo.info.pathPermissions = newp;
2142 }
2143 } else {
2144 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002145 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2146 + parser.getName() + " at " + mArchiveSourcePath + " "
2147 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002148 XmlUtils.skipCurrentTag(parser);
2149 continue;
2150 }
2151 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2152 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 }
2154 XmlUtils.skipCurrentTag(parser);
2155
2156 } else {
2157 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002159 + parser.getName() + " at " + mArchiveSourcePath + " "
2160 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 XmlUtils.skipCurrentTag(parser);
2162 continue;
2163 }
2164 outError[0] = "Bad element under <provider>: "
2165 + parser.getName();
2166 return false;
2167 }
2168 }
2169 return true;
2170 }
2171
2172 private Service parseService(Package owner, Resources res,
2173 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2174 throws XmlPullParserException, IOException {
2175 TypedArray sa = res.obtainAttributes(attrs,
2176 com.android.internal.R.styleable.AndroidManifestService);
2177
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002178 if (mParseServiceArgs == null) {
2179 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2180 com.android.internal.R.styleable.AndroidManifestService_name,
2181 com.android.internal.R.styleable.AndroidManifestService_label,
2182 com.android.internal.R.styleable.AndroidManifestService_icon,
2183 mSeparateProcesses,
2184 com.android.internal.R.styleable.AndroidManifestService_process,
2185 com.android.internal.R.styleable.AndroidManifestService_enabled);
2186 mParseServiceArgs.tag = "<service>";
2187 }
2188
2189 mParseServiceArgs.sa = sa;
2190 mParseServiceArgs.flags = flags;
2191
2192 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2193 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 sa.recycle();
2195 return null;
2196 }
2197
2198 final boolean setExported = sa.hasValue(
2199 com.android.internal.R.styleable.AndroidManifestService_exported);
2200 if (setExported) {
2201 s.info.exported = sa.getBoolean(
2202 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2203 }
2204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 String str = sa.getNonResourceString(
2206 com.android.internal.R.styleable.AndroidManifestService_permission);
2207 if (str == null) {
2208 s.info.permission = owner.applicationInfo.permission;
2209 } else {
2210 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2211 }
2212
2213 sa.recycle();
2214
2215 int outerDepth = parser.getDepth();
2216 int type;
2217 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2218 && (type != XmlPullParser.END_TAG
2219 || parser.getDepth() > outerDepth)) {
2220 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2221 continue;
2222 }
2223
2224 if (parser.getName().equals("intent-filter")) {
2225 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2226 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2227 return null;
2228 }
2229
2230 s.intents.add(intent);
2231 } else if (parser.getName().equals("meta-data")) {
2232 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2233 outError)) == null) {
2234 return null;
2235 }
2236 } else {
2237 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002239 + parser.getName() + " at " + mArchiveSourcePath + " "
2240 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 XmlUtils.skipCurrentTag(parser);
2242 continue;
2243 }
2244 outError[0] = "Bad element under <service>: "
2245 + parser.getName();
2246 return null;
2247 }
2248 }
2249
2250 if (!setExported) {
2251 s.info.exported = s.intents.size() > 0;
2252 }
2253
2254 return s;
2255 }
2256
2257 private boolean parseAllMetaData(Resources res,
2258 XmlPullParser parser, AttributeSet attrs, String tag,
2259 Component outInfo, String[] outError)
2260 throws XmlPullParserException, IOException {
2261 int outerDepth = parser.getDepth();
2262 int type;
2263 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2264 && (type != XmlPullParser.END_TAG
2265 || parser.getDepth() > outerDepth)) {
2266 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2267 continue;
2268 }
2269
2270 if (parser.getName().equals("meta-data")) {
2271 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2272 outInfo.metaData, outError)) == null) {
2273 return false;
2274 }
2275 } else {
2276 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002278 + parser.getName() + " at " + mArchiveSourcePath + " "
2279 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 XmlUtils.skipCurrentTag(parser);
2281 continue;
2282 }
2283 outError[0] = "Bad element under " + tag + ": "
2284 + parser.getName();
2285 return false;
2286 }
2287 }
2288 return true;
2289 }
2290
2291 private Bundle parseMetaData(Resources res,
2292 XmlPullParser parser, AttributeSet attrs,
2293 Bundle data, String[] outError)
2294 throws XmlPullParserException, IOException {
2295
2296 TypedArray sa = res.obtainAttributes(attrs,
2297 com.android.internal.R.styleable.AndroidManifestMetaData);
2298
2299 if (data == null) {
2300 data = new Bundle();
2301 }
2302
2303 String name = sa.getNonResourceString(
2304 com.android.internal.R.styleable.AndroidManifestMetaData_name);
2305 if (name == null) {
2306 outError[0] = "<meta-data> requires an android:name attribute";
2307 sa.recycle();
2308 return null;
2309 }
2310
Dianne Hackborn854060a2009-07-09 18:14:31 -07002311 name = name.intern();
2312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 TypedValue v = sa.peekValue(
2314 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2315 if (v != null && v.resourceId != 0) {
2316 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2317 data.putInt(name, v.resourceId);
2318 } else {
2319 v = sa.peekValue(
2320 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2321 //Log.i(TAG, "Meta data " + name + ": " + v);
2322 if (v != null) {
2323 if (v.type == TypedValue.TYPE_STRING) {
2324 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002325 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2327 data.putBoolean(name, v.data != 0);
2328 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2329 && v.type <= TypedValue.TYPE_LAST_INT) {
2330 data.putInt(name, v.data);
2331 } else if (v.type == TypedValue.TYPE_FLOAT) {
2332 data.putFloat(name, v.getFloat());
2333 } else {
2334 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002335 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2336 + parser.getName() + " at " + mArchiveSourcePath + " "
2337 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 } else {
2339 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2340 data = null;
2341 }
2342 }
2343 } else {
2344 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2345 data = null;
2346 }
2347 }
2348
2349 sa.recycle();
2350
2351 XmlUtils.skipCurrentTag(parser);
2352
2353 return data;
2354 }
2355
2356 private static final String ANDROID_RESOURCES
2357 = "http://schemas.android.com/apk/res/android";
2358
2359 private boolean parseIntent(Resources res,
2360 XmlPullParser parser, AttributeSet attrs, int flags,
2361 IntentInfo outInfo, String[] outError, boolean isActivity)
2362 throws XmlPullParserException, IOException {
2363
2364 TypedArray sa = res.obtainAttributes(attrs,
2365 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2366
2367 int priority = sa.getInt(
2368 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2369 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2370 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002371 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 + parser.getPositionDescription());
2373 priority = 0;
2374 }
2375 outInfo.setPriority(priority);
2376
2377 TypedValue v = sa.peekValue(
2378 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2379 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2380 outInfo.nonLocalizedLabel = v.coerceToString();
2381 }
2382
2383 outInfo.icon = sa.getResourceId(
2384 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
2385
2386 sa.recycle();
2387
2388 int outerDepth = parser.getDepth();
2389 int type;
2390 while ((type=parser.next()) != parser.END_DOCUMENT
2391 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2392 if (type == parser.END_TAG || type == parser.TEXT) {
2393 continue;
2394 }
2395
2396 String nodeName = parser.getName();
2397 if (nodeName.equals("action")) {
2398 String value = attrs.getAttributeValue(
2399 ANDROID_RESOURCES, "name");
2400 if (value == null || value == "") {
2401 outError[0] = "No value supplied for <android:name>";
2402 return false;
2403 }
2404 XmlUtils.skipCurrentTag(parser);
2405
2406 outInfo.addAction(value);
2407 } else if (nodeName.equals("category")) {
2408 String value = attrs.getAttributeValue(
2409 ANDROID_RESOURCES, "name");
2410 if (value == null || value == "") {
2411 outError[0] = "No value supplied for <android:name>";
2412 return false;
2413 }
2414 XmlUtils.skipCurrentTag(parser);
2415
2416 outInfo.addCategory(value);
2417
2418 } else if (nodeName.equals("data")) {
2419 sa = res.obtainAttributes(attrs,
2420 com.android.internal.R.styleable.AndroidManifestData);
2421
2422 String str = sa.getNonResourceString(
2423 com.android.internal.R.styleable.AndroidManifestData_mimeType);
2424 if (str != null) {
2425 try {
2426 outInfo.addDataType(str);
2427 } catch (IntentFilter.MalformedMimeTypeException e) {
2428 outError[0] = e.toString();
2429 sa.recycle();
2430 return false;
2431 }
2432 }
2433
2434 str = sa.getNonResourceString(
2435 com.android.internal.R.styleable.AndroidManifestData_scheme);
2436 if (str != null) {
2437 outInfo.addDataScheme(str);
2438 }
2439
2440 String host = sa.getNonResourceString(
2441 com.android.internal.R.styleable.AndroidManifestData_host);
2442 String port = sa.getNonResourceString(
2443 com.android.internal.R.styleable.AndroidManifestData_port);
2444 if (host != null) {
2445 outInfo.addDataAuthority(host, port);
2446 }
2447
2448 str = sa.getNonResourceString(
2449 com.android.internal.R.styleable.AndroidManifestData_path);
2450 if (str != null) {
2451 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2452 }
2453
2454 str = sa.getNonResourceString(
2455 com.android.internal.R.styleable.AndroidManifestData_pathPrefix);
2456 if (str != null) {
2457 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2458 }
2459
2460 str = sa.getNonResourceString(
2461 com.android.internal.R.styleable.AndroidManifestData_pathPattern);
2462 if (str != null) {
2463 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2464 }
2465
2466 sa.recycle();
2467 XmlUtils.skipCurrentTag(parser);
2468 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002469 Log.w(TAG, "Unknown element under <intent-filter>: "
2470 + parser.getName() + " at " + mArchiveSourcePath + " "
2471 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 XmlUtils.skipCurrentTag(parser);
2473 } else {
2474 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2475 return false;
2476 }
2477 }
2478
2479 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2480 if (false) {
2481 String cats = "";
2482 Iterator<String> it = outInfo.categoriesIterator();
2483 while (it != null && it.hasNext()) {
2484 cats += " " + it.next();
2485 }
2486 System.out.println("Intent d=" +
2487 outInfo.hasDefault + ", cat=" + cats);
2488 }
2489
2490 return true;
2491 }
2492
2493 public final static class Package {
2494 public final String packageName;
2495
2496 // For now we only support one application per package.
2497 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2498
2499 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2500 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2501 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2502 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2503 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2504 public final ArrayList<Service> services = new ArrayList<Service>(0);
2505 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2506
2507 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2508
Dianne Hackborn854060a2009-07-09 18:14:31 -07002509 public ArrayList<String> protectedBroadcasts;
2510
Dianne Hackborn49237342009-08-27 20:08:01 -07002511 public ArrayList<String> usesLibraries = null;
2512 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 public String[] usesLibraryFiles = null;
2514
2515 // We store the application meta-data independently to avoid multiple unwanted references
2516 public Bundle mAppMetaData = null;
2517
2518 // If this is a 3rd party app, this is the path of the zip file.
2519 public String mPath;
2520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 // The version code declared for this package.
2522 public int mVersionCode;
2523
2524 // The version name declared for this package.
2525 public String mVersionName;
2526
2527 // The shared user id that this package wants to use.
2528 public String mSharedUserId;
2529
2530 // The shared user label that this package wants to use.
2531 public int mSharedUserLabel;
2532
2533 // Signatures that were read from the package.
2534 public Signature mSignatures[];
2535
2536 // For use by package manager service for quick lookup of
2537 // preferred up order.
2538 public int mPreferredOrder = 0;
2539
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002540 // For use by package manager service to keep track of which apps
2541 // have been installed with forward locking.
2542 public boolean mForwardLocked;
2543
2544 // For use by the package manager to keep track of the path to the
2545 // file an app came from.
2546 public String mScanPath;
2547
2548 // For use by package manager to keep track of where it has done dexopt.
2549 public boolean mDidDexOpt;
2550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 // Additional data supplied by callers.
2552 public Object mExtras;
2553
2554 /*
2555 * Applications hardware preferences
2556 */
2557 public final ArrayList<ConfigurationInfo> configPreferences =
2558 new ArrayList<ConfigurationInfo>();
2559
Dianne Hackborn49237342009-08-27 20:08:01 -07002560 /*
2561 * Applications requested features
2562 */
2563 public ArrayList<FeatureInfo> reqFeatures = null;
2564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 public Package(String _name) {
2566 packageName = _name;
2567 applicationInfo.packageName = _name;
2568 applicationInfo.uid = -1;
2569 }
2570
2571 public String toString() {
2572 return "Package{"
2573 + Integer.toHexString(System.identityHashCode(this))
2574 + " " + packageName + "}";
2575 }
2576 }
2577
2578 public static class Component<II extends IntentInfo> {
2579 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002580 public final ArrayList<II> intents;
2581 public final ComponentName component;
2582 public final String componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 public Bundle metaData;
2584
2585 public Component(Package _owner) {
2586 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002587 intents = null;
2588 component = null;
2589 componentShortName = null;
2590 }
2591
2592 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2593 owner = args.owner;
2594 intents = new ArrayList<II>(0);
2595 String name = args.sa.getNonResourceString(args.nameRes);
2596 if (name == null) {
2597 component = null;
2598 componentShortName = null;
2599 args.outError[0] = args.tag + " does not specify android:name";
2600 return;
2601 }
2602
2603 outInfo.name
2604 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2605 if (outInfo.name == null) {
2606 component = null;
2607 componentShortName = null;
2608 args.outError[0] = args.tag + " does not have valid android:name";
2609 return;
2610 }
2611
2612 component = new ComponentName(owner.applicationInfo.packageName,
2613 outInfo.name);
2614 componentShortName = component.flattenToShortString();
2615
2616 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2617 if (iconVal != 0) {
2618 outInfo.icon = iconVal;
2619 outInfo.nonLocalizedLabel = null;
2620 }
2621
2622 TypedValue v = args.sa.peekValue(args.labelRes);
2623 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2624 outInfo.nonLocalizedLabel = v.coerceToString();
2625 }
2626
2627 outInfo.packageName = owner.packageName;
2628 }
2629
2630 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2631 this(args, (PackageItemInfo)outInfo);
2632 if (args.outError[0] != null) {
2633 return;
2634 }
2635
2636 if (args.processRes != 0) {
2637 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
2638 owner.applicationInfo.processName, args.sa.getNonResourceString(args.processRes),
2639 args.flags, args.sepProcesses, args.outError);
2640 }
2641 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 }
2643
2644 public Component(Component<II> clone) {
2645 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002646 intents = clone.intents;
2647 component = clone.component;
2648 componentShortName = clone.componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 metaData = clone.metaData;
2650 }
2651 }
2652
2653 public final static class Permission extends Component<IntentInfo> {
2654 public final PermissionInfo info;
2655 public boolean tree;
2656 public PermissionGroup group;
2657
2658 public Permission(Package _owner) {
2659 super(_owner);
2660 info = new PermissionInfo();
2661 }
2662
2663 public Permission(Package _owner, PermissionInfo _info) {
2664 super(_owner);
2665 info = _info;
2666 }
2667
2668 public String toString() {
2669 return "Permission{"
2670 + Integer.toHexString(System.identityHashCode(this))
2671 + " " + info.name + "}";
2672 }
2673 }
2674
2675 public final static class PermissionGroup extends Component<IntentInfo> {
2676 public final PermissionGroupInfo info;
2677
2678 public PermissionGroup(Package _owner) {
2679 super(_owner);
2680 info = new PermissionGroupInfo();
2681 }
2682
2683 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2684 super(_owner);
2685 info = _info;
2686 }
2687
2688 public String toString() {
2689 return "PermissionGroup{"
2690 + Integer.toHexString(System.identityHashCode(this))
2691 + " " + info.name + "}";
2692 }
2693 }
2694
2695 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
2696 if ((flags & PackageManager.GET_META_DATA) != 0
2697 && (metaData != null || p.mAppMetaData != null)) {
2698 return true;
2699 }
2700 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
2701 && p.usesLibraryFiles != null) {
2702 return true;
2703 }
2704 return false;
2705 }
2706
2707 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
2708 if (p == null) return null;
2709 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002710 // CompatibilityMode is global state. It's safe to modify the instance
2711 // of the package.
2712 if (!sCompatibilityModeEnabled) {
2713 p.applicationInfo.disableCompatibilityMode();
2714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 return p.applicationInfo;
2716 }
2717
2718 // Make shallow copy so we can store the metadata/libraries safely
2719 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
2720 if ((flags & PackageManager.GET_META_DATA) != 0) {
2721 ai.metaData = p.mAppMetaData;
2722 }
2723 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
2724 ai.sharedLibraryFiles = p.usesLibraryFiles;
2725 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002726 if (!sCompatibilityModeEnabled) {
2727 ai.disableCompatibilityMode();
2728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729 return ai;
2730 }
2731
2732 public static final PermissionInfo generatePermissionInfo(
2733 Permission p, int flags) {
2734 if (p == null) return null;
2735 if ((flags&PackageManager.GET_META_DATA) == 0) {
2736 return p.info;
2737 }
2738 PermissionInfo pi = new PermissionInfo(p.info);
2739 pi.metaData = p.metaData;
2740 return pi;
2741 }
2742
2743 public static final PermissionGroupInfo generatePermissionGroupInfo(
2744 PermissionGroup pg, int flags) {
2745 if (pg == null) return null;
2746 if ((flags&PackageManager.GET_META_DATA) == 0) {
2747 return pg.info;
2748 }
2749 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
2750 pgi.metaData = pg.metaData;
2751 return pgi;
2752 }
2753
2754 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002755 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002757 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
2758 super(args, _info);
2759 info = _info;
2760 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 public String toString() {
2764 return "Activity{"
2765 + Integer.toHexString(System.identityHashCode(this))
2766 + " " + component.flattenToString() + "}";
2767 }
2768 }
2769
2770 public static final ActivityInfo generateActivityInfo(Activity a,
2771 int flags) {
2772 if (a == null) return null;
2773 if (!copyNeeded(flags, a.owner, a.metaData)) {
2774 return a.info;
2775 }
2776 // Make shallow copies so we can store the metadata safely
2777 ActivityInfo ai = new ActivityInfo(a.info);
2778 ai.metaData = a.metaData;
2779 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
2780 return ai;
2781 }
2782
2783 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002784 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002786 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
2787 super(args, _info);
2788 info = _info;
2789 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 public String toString() {
2793 return "Service{"
2794 + Integer.toHexString(System.identityHashCode(this))
2795 + " " + component.flattenToString() + "}";
2796 }
2797 }
2798
2799 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
2800 if (s == null) return null;
2801 if (!copyNeeded(flags, s.owner, s.metaData)) {
2802 return s.info;
2803 }
2804 // Make shallow copies so we can store the metadata safely
2805 ServiceInfo si = new ServiceInfo(s.info);
2806 si.metaData = s.metaData;
2807 si.applicationInfo = generateApplicationInfo(s.owner, flags);
2808 return si;
2809 }
2810
2811 public final static class Provider extends Component {
2812 public final ProviderInfo info;
2813 public boolean syncable;
2814
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002815 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
2816 super(args, _info);
2817 info = _info;
2818 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 syncable = false;
2820 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 public Provider(Provider existingProvider) {
2823 super(existingProvider);
2824 this.info = existingProvider.info;
2825 this.syncable = existingProvider.syncable;
2826 }
2827
2828 public String toString() {
2829 return "Provider{"
2830 + Integer.toHexString(System.identityHashCode(this))
2831 + " " + info.name + "}";
2832 }
2833 }
2834
2835 public static final ProviderInfo generateProviderInfo(Provider p,
2836 int flags) {
2837 if (p == null) return null;
2838 if (!copyNeeded(flags, p.owner, p.metaData)
2839 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
2840 || p.info.uriPermissionPatterns == null)) {
2841 return p.info;
2842 }
2843 // Make shallow copies so we can store the metadata safely
2844 ProviderInfo pi = new ProviderInfo(p.info);
2845 pi.metaData = p.metaData;
2846 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
2847 pi.uriPermissionPatterns = null;
2848 }
2849 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
2850 return pi;
2851 }
2852
2853 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002854 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002856 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
2857 super(args, _info);
2858 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 public String toString() {
2862 return "Instrumentation{"
2863 + Integer.toHexString(System.identityHashCode(this))
2864 + " " + component.flattenToString() + "}";
2865 }
2866 }
2867
2868 public static final InstrumentationInfo generateInstrumentationInfo(
2869 Instrumentation i, int flags) {
2870 if (i == null) return null;
2871 if ((flags&PackageManager.GET_META_DATA) == 0) {
2872 return i.info;
2873 }
2874 InstrumentationInfo ii = new InstrumentationInfo(i.info);
2875 ii.metaData = i.metaData;
2876 return ii;
2877 }
2878
2879 public static class IntentInfo extends IntentFilter {
2880 public boolean hasDefault;
2881 public int labelRes;
2882 public CharSequence nonLocalizedLabel;
2883 public int icon;
2884 }
2885
2886 public final static class ActivityIntentInfo extends IntentInfo {
2887 public final Activity activity;
2888
2889 public ActivityIntentInfo(Activity _activity) {
2890 activity = _activity;
2891 }
2892
2893 public String toString() {
2894 return "ActivityIntentInfo{"
2895 + Integer.toHexString(System.identityHashCode(this))
2896 + " " + activity.info.name + "}";
2897 }
2898 }
2899
2900 public final static class ServiceIntentInfo extends IntentInfo {
2901 public final Service service;
2902
2903 public ServiceIntentInfo(Service _service) {
2904 service = _service;
2905 }
2906
2907 public String toString() {
2908 return "ServiceIntentInfo{"
2909 + Integer.toHexString(System.identityHashCode(this))
2910 + " " + service.info.name + "}";
2911 }
2912 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002913
2914 /**
2915 * @hide
2916 */
2917 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
2918 sCompatibilityModeEnabled = compatibilityModeEnabled;
2919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920}