blob: 54015c970bb4b1d67070d6f0d52035e657837ac4 [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;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070030import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Bundle;
32import android.os.PatternMatcher;
33import android.util.AttributeSet;
34import android.util.Config;
35import android.util.DisplayMetrics;
36import android.util.Log;
37import android.util.TypedValue;
38import com.android.internal.util.XmlUtils;
39
40import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
44import java.security.cert.Certificate;
45import java.security.cert.CertificateEncodingException;
46import java.util.ArrayList;
47import java.util.Enumeration;
48import java.util.Iterator;
Mitsuru Oshima8d112672009-04-27 12:01:23 -070049import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import java.util.jar.JarEntry;
51import java.util.jar.JarFile;
52
53/**
54 * Package archive parsing
55 *
56 * {@hide}
57 */
58public class PackageParser {
Dianne Hackborna96cbb42009-05-13 15:06:13 -070059 /** @hide */
60 public static class NewPermissionInfo {
61 public final String name;
62 public final int sdkVersion;
63 public final int fileVersion;
64
65 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
66 this.name = name;
67 this.sdkVersion = sdkVersion;
68 this.fileVersion = fileVersion;
69 }
70 }
71
72 /**
73 * List of new permissions that have been added since 1.0.
74 * NOTE: These must be declared in SDK version order, with permissions
75 * added to older SDKs appearing before those added to newer SDKs.
76 * @hide
77 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -070078 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
79 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070080 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070081 android.os.Build.VERSION_CODES.DONUT, 0),
82 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
83 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -070084 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
86 private String mArchiveSourcePath;
87 private String[] mSeparateProcesses;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070088 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
89 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
90 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
93
94 private static final Object mSync = new Object();
95 private static WeakReference<byte[]> mReadBuffer;
96
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -070097 private static boolean sCompatibilityModeEnabled = true;
98
Dianne Hackborn1d442e02009-04-20 18:14:05 -070099 static class ParsePackageItemArgs {
100 final Package owner;
101 final String[] outError;
102 final int nameRes;
103 final int labelRes;
104 final int iconRes;
105
106 String tag;
107 TypedArray sa;
108
109 ParsePackageItemArgs(Package _owner, String[] _outError,
110 int _nameRes, int _labelRes, int _iconRes) {
111 owner = _owner;
112 outError = _outError;
113 nameRes = _nameRes;
114 labelRes = _labelRes;
115 iconRes = _iconRes;
116 }
117 }
118
119 static class ParseComponentArgs extends ParsePackageItemArgs {
120 final String[] sepProcesses;
121 final int processRes;
122 final int enabledRes;
123 int flags;
124
125 ParseComponentArgs(Package _owner, String[] _outError,
126 int _nameRes, int _labelRes, int _iconRes,
127 String[] _sepProcesses, int _processRes,int _enabledRes) {
128 super(_owner, _outError, _nameRes, _labelRes, _iconRes);
129 sepProcesses = _sepProcesses;
130 processRes = _processRes;
131 enabledRes = _enabledRes;
132 }
133 }
134
135 private ParsePackageItemArgs mParseInstrumentationArgs;
136 private ParseComponentArgs mParseActivityArgs;
137 private ParseComponentArgs mParseActivityAliasArgs;
138 private ParseComponentArgs mParseServiceArgs;
139 private ParseComponentArgs mParseProviderArgs;
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 /** If set to true, we will only allow package files that exactly match
142 * the DTD. Otherwise, we try to get as much from the package as we
143 * can without failing. This should normally be set to false, to
144 * support extensions to the DTD in future versions. */
145 private static final boolean RIGID_PARSER = false;
146
147 private static final String TAG = "PackageParser";
148
149 public PackageParser(String archiveSourcePath) {
150 mArchiveSourcePath = archiveSourcePath;
151 }
152
153 public void setSeparateProcesses(String[] procs) {
154 mSeparateProcesses = procs;
155 }
156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 private static final boolean isPackageFilename(String name) {
158 return name.endsWith(".apk");
159 }
160
161 /**
162 * Generate and return the {@link PackageInfo} for a parsed package.
163 *
164 * @param p the parsed package.
165 * @param flags indicating which optional information is included.
166 */
167 public static PackageInfo generatePackageInfo(PackageParser.Package p,
168 int gids[], int flags) {
169
170 PackageInfo pi = new PackageInfo();
171 pi.packageName = p.packageName;
172 pi.versionCode = p.mVersionCode;
173 pi.versionName = p.mVersionName;
174 pi.sharedUserId = p.mSharedUserId;
175 pi.sharedUserLabel = p.mSharedUserLabel;
176 pi.applicationInfo = p.applicationInfo;
177 if ((flags&PackageManager.GET_GIDS) != 0) {
178 pi.gids = gids;
179 }
180 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
181 int N = p.configPreferences.size();
182 if (N > 0) {
183 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700184 p.configPreferences.toArray(pi.configPreferences);
185 }
186 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
187 if (N > 0) {
188 pi.reqFeatures = new FeatureInfo[N];
189 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 }
191 }
192 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
193 int N = p.activities.size();
194 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700195 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
196 pi.activities = new ActivityInfo[N];
197 } else {
198 int num = 0;
199 for (int i=0; i<N; i++) {
200 if (p.activities.get(i).info.enabled) num++;
201 }
202 pi.activities = new ActivityInfo[num];
203 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 for (int i=0; i<N; i++) {
205 final Activity activity = p.activities.get(i);
206 if (activity.info.enabled
207 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
208 pi.activities[i] = generateActivityInfo(p.activities.get(i), flags);
209 }
210 }
211 }
212 }
213 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
214 int N = p.receivers.size();
215 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700216 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
217 pi.receivers = new ActivityInfo[N];
218 } else {
219 int num = 0;
220 for (int i=0; i<N; i++) {
221 if (p.receivers.get(i).info.enabled) num++;
222 }
223 pi.receivers = new ActivityInfo[num];
224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 for (int i=0; i<N; i++) {
226 final Activity activity = p.receivers.get(i);
227 if (activity.info.enabled
228 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
229 pi.receivers[i] = generateActivityInfo(p.receivers.get(i), flags);
230 }
231 }
232 }
233 }
234 if ((flags&PackageManager.GET_SERVICES) != 0) {
235 int N = p.services.size();
236 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700237 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
238 pi.services = new ServiceInfo[N];
239 } else {
240 int num = 0;
241 for (int i=0; i<N; i++) {
242 if (p.services.get(i).info.enabled) num++;
243 }
244 pi.services = new ServiceInfo[num];
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 for (int i=0; i<N; i++) {
247 final Service service = p.services.get(i);
248 if (service.info.enabled
249 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
250 pi.services[i] = generateServiceInfo(p.services.get(i), flags);
251 }
252 }
253 }
254 }
255 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
256 int N = p.providers.size();
257 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700258 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
259 pi.providers = new ProviderInfo[N];
260 } else {
261 int num = 0;
262 for (int i=0; i<N; i++) {
263 if (p.providers.get(i).info.enabled) num++;
264 }
265 pi.providers = new ProviderInfo[num];
266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 for (int i=0; i<N; i++) {
268 final Provider provider = p.providers.get(i);
269 if (provider.info.enabled
270 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
271 pi.providers[i] = generateProviderInfo(p.providers.get(i), flags);
272 }
273 }
274 }
275 }
276 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
277 int N = p.instrumentation.size();
278 if (N > 0) {
279 pi.instrumentation = new InstrumentationInfo[N];
280 for (int i=0; i<N; i++) {
281 pi.instrumentation[i] = generateInstrumentationInfo(
282 p.instrumentation.get(i), flags);
283 }
284 }
285 }
286 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
287 int N = p.permissions.size();
288 if (N > 0) {
289 pi.permissions = new PermissionInfo[N];
290 for (int i=0; i<N; i++) {
291 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
292 }
293 }
294 N = p.requestedPermissions.size();
295 if (N > 0) {
296 pi.requestedPermissions = new String[N];
297 for (int i=0; i<N; i++) {
298 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
299 }
300 }
301 }
302 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapuc7485412009-08-27 12:28:09 -0700303 if (p.mSignatures != null) {
304 int N = p.mSignatures.length;
305 if (N > 0) {
306 pi.signatures = new Signature[N];
307 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
308 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
310 }
311 return pi;
312 }
313
314 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
315 byte[] readBuffer) {
316 try {
317 // We must read the stream for the JarEntry to retrieve
318 // its certificates.
319 InputStream is = jarFile.getInputStream(je);
320 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
321 // not using
322 }
323 is.close();
324 return je != null ? je.getCertificates() : null;
325 } catch (IOException e) {
326 Log.w(TAG, "Exception reading " + je.getName() + " in "
327 + jarFile.getName(), e);
328 }
329 return null;
330 }
331
332 public final static int PARSE_IS_SYSTEM = 0x0001;
333 public final static int PARSE_CHATTY = 0x0002;
334 public final static int PARSE_MUST_BE_APK = 0x0004;
335 public final static int PARSE_IGNORE_PROCESSES = 0x0008;
336
337 public int getParseError() {
338 return mParseError;
339 }
340
341 public Package parsePackage(File sourceFile, String destFileName,
342 DisplayMetrics metrics, int flags) {
343 mParseError = PackageManager.INSTALL_SUCCEEDED;
344
345 mArchiveSourcePath = sourceFile.getPath();
346 if (!sourceFile.isFile()) {
347 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
348 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
349 return null;
350 }
351 if (!isPackageFilename(sourceFile.getName())
352 && (flags&PARSE_MUST_BE_APK) != 0) {
353 if ((flags&PARSE_IS_SYSTEM) == 0) {
354 // We expect to have non-.apk files in the system dir,
355 // so don't warn about them.
356 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
357 }
358 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
359 return null;
360 }
361
362 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
363 TAG, "Scanning package: " + mArchiveSourcePath);
364
365 XmlResourceParser parser = null;
366 AssetManager assmgr = null;
367 boolean assetError = true;
368 try {
369 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700370 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
371 if(cookie != 0) {
372 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 assetError = false;
374 } else {
375 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
376 }
377 } catch (Exception e) {
378 Log.w(TAG, "Unable to read AndroidManifest.xml of "
379 + mArchiveSourcePath, e);
380 }
381 if(assetError) {
382 if (assmgr != null) assmgr.close();
383 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
384 return null;
385 }
386 String[] errorText = new String[1];
387 Package pkg = null;
388 Exception errorException = null;
389 try {
390 // XXXX todo: need to figure out correct configuration.
391 Resources res = new Resources(assmgr, metrics, null);
392 pkg = parsePackage(res, parser, flags, errorText);
393 } catch (Exception e) {
394 errorException = e;
395 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
396 }
397
398
399 if (pkg == null) {
400 if (errorException != null) {
401 Log.w(TAG, mArchiveSourcePath, errorException);
402 } else {
403 Log.w(TAG, mArchiveSourcePath + " (at "
404 + parser.getPositionDescription()
405 + "): " + errorText[0]);
406 }
407 parser.close();
408 assmgr.close();
409 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
410 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
411 }
412 return null;
413 }
414
415 parser.close();
416 assmgr.close();
417
418 pkg.applicationInfo.sourceDir = destFileName;
419 pkg.applicationInfo.publicSourceDir = destFileName;
420 pkg.mSignatures = null;
421
422 return pkg;
423 }
424
425 public boolean collectCertificates(Package pkg, int flags) {
426 pkg.mSignatures = null;
427
428 WeakReference<byte[]> readBufferRef;
429 byte[] readBuffer = null;
430 synchronized (mSync) {
431 readBufferRef = mReadBuffer;
432 if (readBufferRef != null) {
433 mReadBuffer = null;
434 readBuffer = readBufferRef.get();
435 }
436 if (readBuffer == null) {
437 readBuffer = new byte[8192];
438 readBufferRef = new WeakReference<byte[]>(readBuffer);
439 }
440 }
441
442 try {
443 JarFile jarFile = new JarFile(mArchiveSourcePath);
444
445 Certificate[] certs = null;
446
447 if ((flags&PARSE_IS_SYSTEM) != 0) {
448 // If this package comes from the system image, then we
449 // can trust it... we'll just use the AndroidManifest.xml
450 // to retrieve its signatures, not validating all of the
451 // files.
452 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
453 certs = loadCertificates(jarFile, jarEntry, readBuffer);
454 if (certs == null) {
455 Log.e(TAG, "Package " + pkg.packageName
456 + " has no certificates at entry "
457 + jarEntry.getName() + "; ignoring!");
458 jarFile.close();
459 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
460 return false;
461 }
462 if (false) {
463 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
464 + " certs=" + (certs != null ? certs.length : 0));
465 if (certs != null) {
466 final int N = certs.length;
467 for (int i=0; i<N; i++) {
468 Log.i(TAG, " Public key: "
469 + certs[i].getPublicKey().getEncoded()
470 + " " + certs[i].getPublicKey());
471 }
472 }
473 }
474
475 } else {
476 Enumeration entries = jarFile.entries();
477 while (entries.hasMoreElements()) {
478 JarEntry je = (JarEntry)entries.nextElement();
479 if (je.isDirectory()) continue;
480 if (je.getName().startsWith("META-INF/")) continue;
481 Certificate[] localCerts = loadCertificates(jarFile, je,
482 readBuffer);
483 if (false) {
484 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
485 + ": certs=" + certs + " ("
486 + (certs != null ? certs.length : 0) + ")");
487 }
488 if (localCerts == null) {
489 Log.e(TAG, "Package " + pkg.packageName
490 + " has no certificates at entry "
491 + je.getName() + "; ignoring!");
492 jarFile.close();
493 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
494 return false;
495 } else if (certs == null) {
496 certs = localCerts;
497 } else {
498 // Ensure all certificates match.
499 for (int i=0; i<certs.length; i++) {
500 boolean found = false;
501 for (int j=0; j<localCerts.length; j++) {
502 if (certs[i] != null &&
503 certs[i].equals(localCerts[j])) {
504 found = true;
505 break;
506 }
507 }
508 if (!found || certs.length != localCerts.length) {
509 Log.e(TAG, "Package " + pkg.packageName
510 + " has mismatched certificates at entry "
511 + je.getName() + "; ignoring!");
512 jarFile.close();
513 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
514 return false;
515 }
516 }
517 }
518 }
519 }
520 jarFile.close();
521
522 synchronized (mSync) {
523 mReadBuffer = readBufferRef;
524 }
525
526 if (certs != null && certs.length > 0) {
527 final int N = certs.length;
528 pkg.mSignatures = new Signature[certs.length];
529 for (int i=0; i<N; i++) {
530 pkg.mSignatures[i] = new Signature(
531 certs[i].getEncoded());
532 }
533 } else {
534 Log.e(TAG, "Package " + pkg.packageName
535 + " has no certificates; ignoring!");
536 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
537 return false;
538 }
539 } catch (CertificateEncodingException e) {
540 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
541 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
542 return false;
543 } catch (IOException e) {
544 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
545 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
546 return false;
547 } catch (RuntimeException e) {
548 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
549 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
550 return false;
551 }
552
553 return true;
554 }
555
556 public static String parsePackageName(String packageFilePath, int flags) {
557 XmlResourceParser parser = null;
558 AssetManager assmgr = null;
559 try {
560 assmgr = new AssetManager();
561 int cookie = assmgr.addAssetPath(packageFilePath);
562 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
563 } catch (Exception e) {
564 if (assmgr != null) assmgr.close();
565 Log.w(TAG, "Unable to read AndroidManifest.xml of "
566 + packageFilePath, e);
567 return null;
568 }
569 AttributeSet attrs = parser;
570 String errors[] = new String[1];
571 String packageName = null;
572 try {
573 packageName = parsePackageName(parser, attrs, flags, errors);
574 } catch (IOException e) {
575 Log.w(TAG, packageFilePath, e);
576 } catch (XmlPullParserException e) {
577 Log.w(TAG, packageFilePath, e);
578 } finally {
579 if (parser != null) parser.close();
580 if (assmgr != null) assmgr.close();
581 }
582 if (packageName == null) {
583 Log.e(TAG, "parsePackageName error: " + errors[0]);
584 return null;
585 }
586 return packageName;
587 }
588
589 private static String validateName(String name, boolean requiresSeparator) {
590 final int N = name.length();
591 boolean hasSep = false;
592 boolean front = true;
593 for (int i=0; i<N; i++) {
594 final char c = name.charAt(i);
595 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
596 front = false;
597 continue;
598 }
599 if (!front) {
600 if ((c >= '0' && c <= '9') || c == '_') {
601 continue;
602 }
603 }
604 if (c == '.') {
605 hasSep = true;
606 front = true;
607 continue;
608 }
609 return "bad character '" + c + "'";
610 }
611 return hasSep || !requiresSeparator
612 ? null : "must have at least one '.' separator";
613 }
614
615 private static String parsePackageName(XmlPullParser parser,
616 AttributeSet attrs, int flags, String[] outError)
617 throws IOException, XmlPullParserException {
618
619 int type;
620 while ((type=parser.next()) != parser.START_TAG
621 && type != parser.END_DOCUMENT) {
622 ;
623 }
624
625 if (type != parser.START_TAG) {
626 outError[0] = "No start tag found";
627 return null;
628 }
629 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
630 TAG, "Root element name: '" + parser.getName() + "'");
631 if (!parser.getName().equals("manifest")) {
632 outError[0] = "No <manifest> tag";
633 return null;
634 }
635 String pkgName = attrs.getAttributeValue(null, "package");
636 if (pkgName == null || pkgName.length() == 0) {
637 outError[0] = "<manifest> does not specify package";
638 return null;
639 }
640 String nameError = validateName(pkgName, true);
641 if (nameError != null && !"android".equals(pkgName)) {
642 outError[0] = "<manifest> specifies bad package name \""
643 + pkgName + "\": " + nameError;
644 return null;
645 }
646
647 return pkgName.intern();
648 }
649
650 /**
651 * Temporary.
652 */
653 static public Signature stringToSignature(String str) {
654 final int N = str.length();
655 byte[] sig = new byte[N];
656 for (int i=0; i<N; i++) {
657 sig[i] = (byte)str.charAt(i);
658 }
659 return new Signature(sig);
660 }
661
662 private Package parsePackage(
663 Resources res, XmlResourceParser parser, int flags, String[] outError)
664 throws XmlPullParserException, IOException {
665 AttributeSet attrs = parser;
666
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700667 mParseInstrumentationArgs = null;
668 mParseActivityArgs = null;
669 mParseServiceArgs = null;
670 mParseProviderArgs = null;
671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 String pkgName = parsePackageName(parser, attrs, flags, outError);
673 if (pkgName == null) {
674 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
675 return null;
676 }
677 int type;
678
679 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 TypedArray sa = res.obtainAttributes(attrs,
683 com.android.internal.R.styleable.AndroidManifest);
684 pkg.mVersionCode = sa.getInteger(
685 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
686 pkg.mVersionName = sa.getNonResourceString(
687 com.android.internal.R.styleable.AndroidManifest_versionName);
688 if (pkg.mVersionName != null) {
689 pkg.mVersionName = pkg.mVersionName.intern();
690 }
691 String str = sa.getNonResourceString(
692 com.android.internal.R.styleable.AndroidManifest_sharedUserId);
693 if (str != null) {
694 String nameError = validateName(str, true);
695 if (nameError != null && !"android".equals(pkgName)) {
696 outError[0] = "<manifest> specifies bad sharedUserId name \""
697 + str + "\": " + nameError;
698 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
699 return null;
700 }
701 pkg.mSharedUserId = str.intern();
702 pkg.mSharedUserLabel = sa.getResourceId(
703 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
704 }
705 sa.recycle();
706
Dianne Hackborn723738c2009-06-25 19:48:04 -0700707 // Resource boolean are -1, so 1 means we don't know the value.
708 int supportsSmallScreens = 1;
709 int supportsNormalScreens = 1;
710 int supportsLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700711 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700712 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 int outerDepth = parser.getDepth();
715 while ((type=parser.next()) != parser.END_DOCUMENT
716 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
717 if (type == parser.END_TAG || type == parser.TEXT) {
718 continue;
719 }
720
721 String tagName = parser.getName();
722 if (tagName.equals("application")) {
723 if (foundApp) {
724 if (RIGID_PARSER) {
725 outError[0] = "<manifest> has more than one <application>";
726 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
727 return null;
728 } else {
729 Log.w(TAG, "<manifest> has more than one <application>");
730 XmlUtils.skipCurrentTag(parser);
731 continue;
732 }
733 }
734
735 foundApp = true;
736 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
737 return null;
738 }
739 } else if (tagName.equals("permission-group")) {
740 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
741 return null;
742 }
743 } else if (tagName.equals("permission")) {
744 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
745 return null;
746 }
747 } else if (tagName.equals("permission-tree")) {
748 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
749 return null;
750 }
751 } else if (tagName.equals("uses-permission")) {
752 sa = res.obtainAttributes(attrs,
753 com.android.internal.R.styleable.AndroidManifestUsesPermission);
754
755 String name = sa.getNonResourceString(
756 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
757
758 sa.recycle();
759
760 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700761 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763
764 XmlUtils.skipCurrentTag(parser);
765
766 } else if (tagName.equals("uses-configuration")) {
767 ConfigurationInfo cPref = new ConfigurationInfo();
768 sa = res.obtainAttributes(attrs,
769 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
770 cPref.reqTouchScreen = sa.getInt(
771 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
772 Configuration.TOUCHSCREEN_UNDEFINED);
773 cPref.reqKeyboardType = sa.getInt(
774 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
775 Configuration.KEYBOARD_UNDEFINED);
776 if (sa.getBoolean(
777 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
778 false)) {
779 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
780 }
781 cPref.reqNavigation = sa.getInt(
782 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
783 Configuration.NAVIGATION_UNDEFINED);
784 if (sa.getBoolean(
785 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
786 false)) {
787 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
788 }
789 sa.recycle();
790 pkg.configPreferences.add(cPref);
791
792 XmlUtils.skipCurrentTag(parser);
793
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700794 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700795 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700796 sa = res.obtainAttributes(attrs,
797 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborn49237342009-08-27 20:08:01 -0700798 fi.name = sa.getNonResourceString(
799 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
800 if (fi.name == null) {
801 fi.reqGlEsVersion = sa.getInt(
802 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
803 FeatureInfo.GL_ES_VERSION_UNDEFINED);
804 }
805 if (sa.getBoolean(
806 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
807 true)) {
808 fi.flags |= FeatureInfo.FLAG_REQUIRED;
809 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700810 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700811 if (pkg.reqFeatures == null) {
812 pkg.reqFeatures = new ArrayList<FeatureInfo>();
813 }
814 pkg.reqFeatures.add(fi);
815
816 if (fi.name == null) {
817 ConfigurationInfo cPref = new ConfigurationInfo();
818 cPref.reqGlEsVersion = fi.reqGlEsVersion;
819 pkg.configPreferences.add(cPref);
820 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700821
822 XmlUtils.skipCurrentTag(parser);
823
Dianne Hackborn851a5412009-05-08 12:06:44 -0700824 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700825 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 sa = res.obtainAttributes(attrs,
827 com.android.internal.R.styleable.AndroidManifestUsesSdk);
828
Dianne Hackborn851a5412009-05-08 12:06:44 -0700829 int minVers = 0;
830 String minCode = null;
831 int targetVers = 0;
832 String targetCode = null;
833
834 TypedValue val = sa.peekValue(
835 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
836 if (val != null) {
837 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
838 targetCode = minCode = val.string.toString();
839 } else {
840 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700841 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700842 }
843 }
844
845 val = sa.peekValue(
846 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
847 if (val != null) {
848 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
849 targetCode = minCode = val.string.toString();
850 } else {
851 // If it's not a string, it's an integer.
852 targetVers = val.data;
853 }
854 }
855
856 int maxVers = sa.getInt(
857 com.android.internal.R.styleable.AndroidManifestUsesSdk_maxSdkVersion,
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700858 SDK_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859
860 sa.recycle();
861
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700862 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700863 if (!minCode.equals(SDK_CODENAME)) {
864 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700865 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700866 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700867 } else {
868 outError[0] = "Requires development platform " + minCode
869 + " but this is a release platform.";
870 }
871 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
872 return null;
873 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700874 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700875 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700876 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700877 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
878 return null;
879 }
880
Dianne Hackborn851a5412009-05-08 12:06:44 -0700881 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700882 if (!targetCode.equals(SDK_CODENAME)) {
883 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700884 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700885 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700886 } else {
887 outError[0] = "Requires development platform " + targetCode
888 + " but this is a release platform.";
889 }
890 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
891 return null;
892 }
893 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700894 pkg.applicationInfo.targetSdkVersion
895 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
896 } else {
897 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700898 }
899
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700900 if (maxVers < SDK_VERSION) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700901 outError[0] = "Requires older sdk version #" + maxVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700902 + " (current version is #" + SDK_VERSION + ")";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
904 return null;
905 }
906 }
907
908 XmlUtils.skipCurrentTag(parser);
909
Dianne Hackborn723738c2009-06-25 19:48:04 -0700910 } else if (tagName.equals("supports-screens")) {
911 sa = res.obtainAttributes(attrs,
912 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
913
914 // This is a trick to get a boolean and still able to detect
915 // if a value was actually set.
916 supportsSmallScreens = sa.getInteger(
917 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
918 supportsSmallScreens);
919 supportsNormalScreens = sa.getInteger(
920 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
921 supportsNormalScreens);
922 supportsLargeScreens = sa.getInteger(
923 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
924 supportsLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700925 resizeable = sa.getInteger(
926 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
927 supportsLargeScreens);
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700928 anyDensity = sa.getInteger(
929 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
930 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700931
932 sa.recycle();
933
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700934 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -0700935
936 } else if (tagName.equals("protected-broadcast")) {
937 sa = res.obtainAttributes(attrs,
938 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
939
940 String name = sa.getNonResourceString(
941 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
942
943 sa.recycle();
944
945 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
946 if (pkg.protectedBroadcasts == null) {
947 pkg.protectedBroadcasts = new ArrayList<String>();
948 }
949 if (!pkg.protectedBroadcasts.contains(name)) {
950 pkg.protectedBroadcasts.add(name.intern());
951 }
952 }
953
954 XmlUtils.skipCurrentTag(parser);
955
956 } else if (tagName.equals("instrumentation")) {
957 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
958 return null;
959 }
960
961 } else if (tagName.equals("eat-comment")) {
962 // Just skip this tag
963 XmlUtils.skipCurrentTag(parser);
964 continue;
965
966 } else if (RIGID_PARSER) {
967 outError[0] = "Bad element under <manifest>: "
968 + parser.getName();
969 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
970 return null;
971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -0700973 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
974 + " at " + mArchiveSourcePath + " "
975 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 XmlUtils.skipCurrentTag(parser);
977 continue;
978 }
979 }
980
981 if (!foundApp && pkg.instrumentation.size() == 0) {
982 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
983 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
984 }
985
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700986 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700987 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700988 for (int ip=0; ip<NP; ip++) {
989 final PackageParser.NewPermissionInfo npi
990 = PackageParser.NEW_PERMISSIONS[ip];
991 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
992 break;
993 }
994 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700995 if (implicitPerms == null) {
996 implicitPerms = new StringBuilder(128);
997 implicitPerms.append(pkg.packageName);
998 implicitPerms.append(": compat added ");
999 } else {
1000 implicitPerms.append(' ');
1001 }
1002 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001003 pkg.requestedPermissions.add(npi.name);
1004 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001005 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001006 if (implicitPerms != null) {
1007 Log.i(TAG, implicitPerms.toString());
1008 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001009
Dianne Hackborn723738c2009-06-25 19:48:04 -07001010 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1011 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001012 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001013 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1014 }
1015 if (supportsNormalScreens != 0) {
1016 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1017 }
1018 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1019 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001020 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001021 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1022 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001023 if (resizeable < 0 || (resizeable > 0
1024 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001025 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001026 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1027 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001028 if (anyDensity < 0 || (anyDensity > 0
1029 && pkg.applicationInfo.targetSdkVersion
1030 >= android.os.Build.VERSION_CODES.DONUT)) {
1031 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001032 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 return pkg;
1035 }
1036
1037 private static String buildClassName(String pkg, CharSequence clsSeq,
1038 String[] outError) {
1039 if (clsSeq == null || clsSeq.length() <= 0) {
1040 outError[0] = "Empty class name in package " + pkg;
1041 return null;
1042 }
1043 String cls = clsSeq.toString();
1044 char c = cls.charAt(0);
1045 if (c == '.') {
1046 return (pkg + cls).intern();
1047 }
1048 if (cls.indexOf('.') < 0) {
1049 StringBuilder b = new StringBuilder(pkg);
1050 b.append('.');
1051 b.append(cls);
1052 return b.toString().intern();
1053 }
1054 if (c >= 'a' && c <= 'z') {
1055 return cls.intern();
1056 }
1057 outError[0] = "Bad class name " + cls + " in package " + pkg;
1058 return null;
1059 }
1060
1061 private static String buildCompoundName(String pkg,
1062 CharSequence procSeq, String type, String[] outError) {
1063 String proc = procSeq.toString();
1064 char c = proc.charAt(0);
1065 if (pkg != null && c == ':') {
1066 if (proc.length() < 2) {
1067 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1068 + ": must be at least two characters";
1069 return null;
1070 }
1071 String subName = proc.substring(1);
1072 String nameError = validateName(subName, false);
1073 if (nameError != null) {
1074 outError[0] = "Invalid " + type + " name " + proc + " in package "
1075 + pkg + ": " + nameError;
1076 return null;
1077 }
1078 return (pkg + proc).intern();
1079 }
1080 String nameError = validateName(proc, true);
1081 if (nameError != null && !"system".equals(proc)) {
1082 outError[0] = "Invalid " + type + " name " + proc + " in package "
1083 + pkg + ": " + nameError;
1084 return null;
1085 }
1086 return proc.intern();
1087 }
1088
1089 private static String buildProcessName(String pkg, String defProc,
1090 CharSequence procSeq, int flags, String[] separateProcesses,
1091 String[] outError) {
1092 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1093 return defProc != null ? defProc : pkg;
1094 }
1095 if (separateProcesses != null) {
1096 for (int i=separateProcesses.length-1; i>=0; i--) {
1097 String sp = separateProcesses[i];
1098 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1099 return pkg;
1100 }
1101 }
1102 }
1103 if (procSeq == null || procSeq.length() <= 0) {
1104 return defProc;
1105 }
1106 return buildCompoundName(pkg, procSeq, "package", outError);
1107 }
1108
1109 private static String buildTaskAffinityName(String pkg, String defProc,
1110 CharSequence procSeq, String[] outError) {
1111 if (procSeq == null) {
1112 return defProc;
1113 }
1114 if (procSeq.length() <= 0) {
1115 return null;
1116 }
1117 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1118 }
1119
1120 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1121 XmlPullParser parser, AttributeSet attrs, String[] outError)
1122 throws XmlPullParserException, IOException {
1123 PermissionGroup perm = new PermissionGroup(owner);
1124
1125 TypedArray sa = res.obtainAttributes(attrs,
1126 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1127
1128 if (!parsePackageItemInfo(owner, perm.info, outError,
1129 "<permission-group>", sa,
1130 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1131 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
1132 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon)) {
1133 sa.recycle();
1134 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1135 return null;
1136 }
1137
1138 perm.info.descriptionRes = sa.getResourceId(
1139 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1140 0);
1141
1142 sa.recycle();
1143
1144 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1145 outError)) {
1146 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1147 return null;
1148 }
1149
1150 owner.permissionGroups.add(perm);
1151
1152 return perm;
1153 }
1154
1155 private Permission parsePermission(Package owner, Resources res,
1156 XmlPullParser parser, AttributeSet attrs, String[] outError)
1157 throws XmlPullParserException, IOException {
1158 Permission perm = new Permission(owner);
1159
1160 TypedArray sa = res.obtainAttributes(attrs,
1161 com.android.internal.R.styleable.AndroidManifestPermission);
1162
1163 if (!parsePackageItemInfo(owner, perm.info, outError,
1164 "<permission>", sa,
1165 com.android.internal.R.styleable.AndroidManifestPermission_name,
1166 com.android.internal.R.styleable.AndroidManifestPermission_label,
1167 com.android.internal.R.styleable.AndroidManifestPermission_icon)) {
1168 sa.recycle();
1169 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1170 return null;
1171 }
1172
1173 perm.info.group = sa.getNonResourceString(
1174 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1175 if (perm.info.group != null) {
1176 perm.info.group = perm.info.group.intern();
1177 }
1178
1179 perm.info.descriptionRes = sa.getResourceId(
1180 com.android.internal.R.styleable.AndroidManifestPermission_description,
1181 0);
1182
1183 perm.info.protectionLevel = sa.getInt(
1184 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1185 PermissionInfo.PROTECTION_NORMAL);
1186
1187 sa.recycle();
1188
1189 if (perm.info.protectionLevel == -1) {
1190 outError[0] = "<permission> does not specify protectionLevel";
1191 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1192 return null;
1193 }
1194
1195 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1196 outError)) {
1197 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1198 return null;
1199 }
1200
1201 owner.permissions.add(perm);
1202
1203 return perm;
1204 }
1205
1206 private Permission parsePermissionTree(Package owner, Resources res,
1207 XmlPullParser parser, AttributeSet attrs, String[] outError)
1208 throws XmlPullParserException, IOException {
1209 Permission perm = new Permission(owner);
1210
1211 TypedArray sa = res.obtainAttributes(attrs,
1212 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1213
1214 if (!parsePackageItemInfo(owner, perm.info, outError,
1215 "<permission-tree>", sa,
1216 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1217 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
1218 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon)) {
1219 sa.recycle();
1220 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1221 return null;
1222 }
1223
1224 sa.recycle();
1225
1226 int index = perm.info.name.indexOf('.');
1227 if (index > 0) {
1228 index = perm.info.name.indexOf('.', index+1);
1229 }
1230 if (index < 0) {
1231 outError[0] = "<permission-tree> name has less than three segments: "
1232 + perm.info.name;
1233 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1234 return null;
1235 }
1236
1237 perm.info.descriptionRes = 0;
1238 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1239 perm.tree = true;
1240
1241 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1242 outError)) {
1243 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1244 return null;
1245 }
1246
1247 owner.permissions.add(perm);
1248
1249 return perm;
1250 }
1251
1252 private Instrumentation parseInstrumentation(Package owner, Resources res,
1253 XmlPullParser parser, AttributeSet attrs, String[] outError)
1254 throws XmlPullParserException, IOException {
1255 TypedArray sa = res.obtainAttributes(attrs,
1256 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1257
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001258 if (mParseInstrumentationArgs == null) {
1259 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1260 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1261 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
1262 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon);
1263 mParseInstrumentationArgs.tag = "<instrumentation>";
1264 }
1265
1266 mParseInstrumentationArgs.sa = sa;
1267
1268 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1269 new InstrumentationInfo());
1270 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 sa.recycle();
1272 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1273 return null;
1274 }
1275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 String str;
1277 str = sa.getNonResourceString(
1278 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1279 a.info.targetPackage = str != null ? str.intern() : null;
1280
1281 a.info.handleProfiling = sa.getBoolean(
1282 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1283 false);
1284
1285 a.info.functionalTest = sa.getBoolean(
1286 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1287 false);
1288
1289 sa.recycle();
1290
1291 if (a.info.targetPackage == null) {
1292 outError[0] = "<instrumentation> does not specify targetPackage";
1293 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1294 return null;
1295 }
1296
1297 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1298 outError)) {
1299 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1300 return null;
1301 }
1302
1303 owner.instrumentation.add(a);
1304
1305 return a;
1306 }
1307
1308 private boolean parseApplication(Package owner, Resources res,
1309 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1310 throws XmlPullParserException, IOException {
1311 final ApplicationInfo ai = owner.applicationInfo;
1312 final String pkgName = owner.applicationInfo.packageName;
1313
1314 TypedArray sa = res.obtainAttributes(attrs,
1315 com.android.internal.R.styleable.AndroidManifestApplication);
1316
1317 String name = sa.getNonResourceString(
1318 com.android.internal.R.styleable.AndroidManifestApplication_name);
1319 if (name != null) {
1320 ai.className = buildClassName(pkgName, name, outError);
1321 if (ai.className == null) {
1322 sa.recycle();
1323 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1324 return false;
1325 }
1326 }
1327
1328 String manageSpaceActivity = sa.getNonResourceString(
1329 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity);
1330 if (manageSpaceActivity != null) {
1331 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1332 outError);
1333 }
1334
Christopher Tate181fafa2009-05-14 11:12:14 -07001335 boolean allowBackup = sa.getBoolean(
1336 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1337 if (allowBackup) {
1338 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001339
1340 // backupAgent, killAfterRestore, and restoreNeedsApplication are only relevant
1341 // if backup is possible for the given application.
Christopher Tate181fafa2009-05-14 11:12:14 -07001342 String backupAgent = sa.getNonResourceString(
1343 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent);
1344 if (backupAgent != null) {
1345 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001346 if (false) {
1347 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1348 + " from " + pkgName + "+" + backupAgent);
1349 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001350
1351 if (sa.getBoolean(
1352 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1353 true)) {
1354 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1355 }
1356 if (sa.getBoolean(
1357 com.android.internal.R.styleable.AndroidManifestApplication_restoreNeedsApplication,
1358 false)) {
1359 ai.flags |= ApplicationInfo.FLAG_RESTORE_NEEDS_APPLICATION;
1360 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001361 }
1362 }
1363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 TypedValue v = sa.peekValue(
1365 com.android.internal.R.styleable.AndroidManifestApplication_label);
1366 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1367 ai.nonLocalizedLabel = v.coerceToString();
1368 }
1369
1370 ai.icon = sa.getResourceId(
1371 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1372 ai.theme = sa.getResourceId(
1373 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1374 ai.descriptionRes = sa.getResourceId(
1375 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1376
1377 if ((flags&PARSE_IS_SYSTEM) != 0) {
1378 if (sa.getBoolean(
1379 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1380 false)) {
1381 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1382 }
1383 }
1384
1385 if (sa.getBoolean(
1386 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1387 false)) {
1388 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1389 }
1390
1391 if (sa.getBoolean(
1392 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1393 true)) {
1394 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1395 }
1396
1397 if (sa.getBoolean(
1398 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1399 false)) {
1400 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1401 }
1402
1403 if (sa.getBoolean(
1404 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1405 true)) {
1406 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1407 }
1408
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001409 if (sa.getBoolean(
1410 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001411 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001412 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1413 }
1414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 String str;
1416 str = sa.getNonResourceString(
1417 com.android.internal.R.styleable.AndroidManifestApplication_permission);
1418 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1419
1420 str = sa.getNonResourceString(
1421 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1422 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1423 str, outError);
1424
1425 if (outError[0] == null) {
1426 ai.processName = buildProcessName(ai.packageName, null, sa.getNonResourceString(
1427 com.android.internal.R.styleable.AndroidManifestApplication_process),
1428 flags, mSeparateProcesses, outError);
1429
1430 ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
1431 }
1432
1433 sa.recycle();
1434
1435 if (outError[0] != null) {
1436 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1437 return false;
1438 }
1439
1440 final int innerDepth = parser.getDepth();
1441
1442 int type;
1443 while ((type=parser.next()) != parser.END_DOCUMENT
1444 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1445 if (type == parser.END_TAG || type == parser.TEXT) {
1446 continue;
1447 }
1448
1449 String tagName = parser.getName();
1450 if (tagName.equals("activity")) {
1451 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1452 if (a == null) {
1453 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1454 return false;
1455 }
1456
1457 owner.activities.add(a);
1458
1459 } else if (tagName.equals("receiver")) {
1460 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1461 if (a == null) {
1462 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1463 return false;
1464 }
1465
1466 owner.receivers.add(a);
1467
1468 } else if (tagName.equals("service")) {
1469 Service s = parseService(owner, res, parser, attrs, flags, outError);
1470 if (s == null) {
1471 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1472 return false;
1473 }
1474
1475 owner.services.add(s);
1476
1477 } else if (tagName.equals("provider")) {
1478 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1479 if (p == null) {
1480 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1481 return false;
1482 }
1483
1484 owner.providers.add(p);
1485
1486 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001487 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 if (a == null) {
1489 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1490 return false;
1491 }
1492
1493 owner.activities.add(a);
1494
1495 } else if (parser.getName().equals("meta-data")) {
1496 // note: application meta-data is stored off to the side, so it can
1497 // remain null in the primary copy (we like to avoid extra copies because
1498 // it can be large)
1499 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1500 outError)) == null) {
1501 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1502 return false;
1503 }
1504
1505 } else if (tagName.equals("uses-library")) {
1506 sa = res.obtainAttributes(attrs,
1507 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1508
1509 String lname = sa.getNonResourceString(
1510 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001511 boolean req = sa.getBoolean(
1512 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1513 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514
1515 sa.recycle();
1516
Dianne Hackborn49237342009-08-27 20:08:01 -07001517 if (lname != null) {
1518 if (req) {
1519 if (owner.usesLibraries == null) {
1520 owner.usesLibraries = new ArrayList<String>();
1521 }
1522 if (!owner.usesLibraries.contains(lname)) {
1523 owner.usesLibraries.add(lname.intern());
1524 }
1525 } else {
1526 if (owner.usesOptionalLibraries == null) {
1527 owner.usesOptionalLibraries = new ArrayList<String>();
1528 }
1529 if (!owner.usesOptionalLibraries.contains(lname)) {
1530 owner.usesOptionalLibraries.add(lname.intern());
1531 }
1532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 }
1534
1535 XmlUtils.skipCurrentTag(parser);
1536
1537 } else {
1538 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001539 Log.w(TAG, "Unknown element under <application>: " + tagName
1540 + " at " + mArchiveSourcePath + " "
1541 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 XmlUtils.skipCurrentTag(parser);
1543 continue;
1544 } else {
1545 outError[0] = "Bad element under <application>: " + tagName;
1546 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1547 return false;
1548 }
1549 }
1550 }
1551
1552 return true;
1553 }
1554
1555 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1556 String[] outError, String tag, TypedArray sa,
1557 int nameRes, int labelRes, int iconRes) {
1558 String name = sa.getNonResourceString(nameRes);
1559 if (name == null) {
1560 outError[0] = tag + " does not specify android:name";
1561 return false;
1562 }
1563
1564 outInfo.name
1565 = buildClassName(owner.applicationInfo.packageName, name, outError);
1566 if (outInfo.name == null) {
1567 return false;
1568 }
1569
1570 int iconVal = sa.getResourceId(iconRes, 0);
1571 if (iconVal != 0) {
1572 outInfo.icon = iconVal;
1573 outInfo.nonLocalizedLabel = null;
1574 }
1575
1576 TypedValue v = sa.peekValue(labelRes);
1577 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1578 outInfo.nonLocalizedLabel = v.coerceToString();
1579 }
1580
1581 outInfo.packageName = owner.packageName;
1582
1583 return true;
1584 }
1585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 private Activity parseActivity(Package owner, Resources res,
1587 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1588 boolean receiver) throws XmlPullParserException, IOException {
1589 TypedArray sa = res.obtainAttributes(attrs,
1590 com.android.internal.R.styleable.AndroidManifestActivity);
1591
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001592 if (mParseActivityArgs == null) {
1593 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1594 com.android.internal.R.styleable.AndroidManifestActivity_name,
1595 com.android.internal.R.styleable.AndroidManifestActivity_label,
1596 com.android.internal.R.styleable.AndroidManifestActivity_icon,
1597 mSeparateProcesses,
1598 com.android.internal.R.styleable.AndroidManifestActivity_process,
1599 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1600 }
1601
1602 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1603 mParseActivityArgs.sa = sa;
1604 mParseActivityArgs.flags = flags;
1605
1606 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1607 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 sa.recycle();
1609 return null;
1610 }
1611
1612 final boolean setExported = sa.hasValue(
1613 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1614 if (setExported) {
1615 a.info.exported = sa.getBoolean(
1616 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1617 }
1618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 a.info.theme = sa.getResourceId(
1620 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1621
1622 String str;
1623 str = sa.getNonResourceString(
1624 com.android.internal.R.styleable.AndroidManifestActivity_permission);
1625 if (str == null) {
1626 a.info.permission = owner.applicationInfo.permission;
1627 } else {
1628 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1629 }
1630
1631 str = sa.getNonResourceString(
1632 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity);
1633 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1634 owner.applicationInfo.taskAffinity, str, outError);
1635
1636 a.info.flags = 0;
1637 if (sa.getBoolean(
1638 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1639 false)) {
1640 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1641 }
1642
1643 if (sa.getBoolean(
1644 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1645 false)) {
1646 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1647 }
1648
1649 if (sa.getBoolean(
1650 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1651 false)) {
1652 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1653 }
1654
1655 if (sa.getBoolean(
1656 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1657 false)) {
1658 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1659 }
1660
1661 if (sa.getBoolean(
1662 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1663 false)) {
1664 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1665 }
1666
1667 if (sa.getBoolean(
1668 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1669 false)) {
1670 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1671 }
1672
1673 if (sa.getBoolean(
1674 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1675 false)) {
1676 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1677 }
1678
1679 if (sa.getBoolean(
1680 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1681 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1682 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1683 }
1684
Dianne Hackbornffa42482009-09-23 22:20:11 -07001685 if (sa.getBoolean(
1686 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1687 false)) {
1688 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1689 }
1690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 if (!receiver) {
1692 a.info.launchMode = sa.getInt(
1693 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1694 ActivityInfo.LAUNCH_MULTIPLE);
1695 a.info.screenOrientation = sa.getInt(
1696 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1697 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1698 a.info.configChanges = sa.getInt(
1699 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1700 0);
1701 a.info.softInputMode = sa.getInt(
1702 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1703 0);
1704 } else {
1705 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1706 a.info.configChanges = 0;
1707 }
1708
1709 sa.recycle();
1710
1711 if (outError[0] != null) {
1712 return null;
1713 }
1714
1715 int outerDepth = parser.getDepth();
1716 int type;
1717 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1718 && (type != XmlPullParser.END_TAG
1719 || parser.getDepth() > outerDepth)) {
1720 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1721 continue;
1722 }
1723
1724 if (parser.getName().equals("intent-filter")) {
1725 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1726 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1727 return null;
1728 }
1729 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001730 Log.w(TAG, "No actions in intent filter at "
1731 + mArchiveSourcePath + " "
1732 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001733 } else {
1734 a.intents.add(intent);
1735 }
1736 } else if (parser.getName().equals("meta-data")) {
1737 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1738 outError)) == null) {
1739 return null;
1740 }
1741 } else {
1742 if (!RIGID_PARSER) {
1743 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1744 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001745 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1746 + " at " + mArchiveSourcePath + " "
1747 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001749 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1750 + " at " + mArchiveSourcePath + " "
1751 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 }
1753 XmlUtils.skipCurrentTag(parser);
1754 continue;
1755 }
1756 if (receiver) {
1757 outError[0] = "Bad element under <receiver>: " + parser.getName();
1758 } else {
1759 outError[0] = "Bad element under <activity>: " + parser.getName();
1760 }
1761 return null;
1762 }
1763 }
1764
1765 if (!setExported) {
1766 a.info.exported = a.intents.size() > 0;
1767 }
1768
1769 return a;
1770 }
1771
1772 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001773 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1774 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 TypedArray sa = res.obtainAttributes(attrs,
1776 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1777
1778 String targetActivity = sa.getNonResourceString(
1779 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity);
1780 if (targetActivity == null) {
1781 outError[0] = "<activity-alias> does not specify android:targetActivity";
1782 sa.recycle();
1783 return null;
1784 }
1785
1786 targetActivity = buildClassName(owner.applicationInfo.packageName,
1787 targetActivity, outError);
1788 if (targetActivity == null) {
1789 sa.recycle();
1790 return null;
1791 }
1792
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001793 if (mParseActivityAliasArgs == null) {
1794 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1795 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1796 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1797 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
1798 mSeparateProcesses,
1799 0,
1800 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1801 mParseActivityAliasArgs.tag = "<activity-alias>";
1802 }
1803
1804 mParseActivityAliasArgs.sa = sa;
1805 mParseActivityAliasArgs.flags = flags;
1806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 Activity target = null;
1808
1809 final int NA = owner.activities.size();
1810 for (int i=0; i<NA; i++) {
1811 Activity t = owner.activities.get(i);
1812 if (targetActivity.equals(t.info.name)) {
1813 target = t;
1814 break;
1815 }
1816 }
1817
1818 if (target == null) {
1819 outError[0] = "<activity-alias> target activity " + targetActivity
1820 + " not found in manifest";
1821 sa.recycle();
1822 return null;
1823 }
1824
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001825 ActivityInfo info = new ActivityInfo();
1826 info.targetActivity = targetActivity;
1827 info.configChanges = target.info.configChanges;
1828 info.flags = target.info.flags;
1829 info.icon = target.info.icon;
1830 info.labelRes = target.info.labelRes;
1831 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
1832 info.launchMode = target.info.launchMode;
1833 info.processName = target.info.processName;
1834 info.screenOrientation = target.info.screenOrientation;
1835 info.taskAffinity = target.info.taskAffinity;
1836 info.theme = target.info.theme;
1837
1838 Activity a = new Activity(mParseActivityAliasArgs, info);
1839 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 sa.recycle();
1841 return null;
1842 }
1843
1844 final boolean setExported = sa.hasValue(
1845 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
1846 if (setExported) {
1847 a.info.exported = sa.getBoolean(
1848 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
1849 }
1850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 String str;
1852 str = sa.getNonResourceString(
1853 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission);
1854 if (str != null) {
1855 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1856 }
1857
1858 sa.recycle();
1859
1860 if (outError[0] != null) {
1861 return null;
1862 }
1863
1864 int outerDepth = parser.getDepth();
1865 int type;
1866 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1867 && (type != XmlPullParser.END_TAG
1868 || parser.getDepth() > outerDepth)) {
1869 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1870 continue;
1871 }
1872
1873 if (parser.getName().equals("intent-filter")) {
1874 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1875 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
1876 return null;
1877 }
1878 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001879 Log.w(TAG, "No actions in intent filter at "
1880 + mArchiveSourcePath + " "
1881 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 } 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}