blob: 0754cbfe081e1f8200eefae564a1619ed92706c5 [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;
Tom Taylord4a47292009-12-21 13:59:18 -080038import com.android.common.XmlUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
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 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700204 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 final Activity activity = p.activities.get(i);
206 if (activity.info.enabled
207 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700208 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 }
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 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700225 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 final Activity activity = p.receivers.get(i);
227 if (activity.info.enabled
228 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700229 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
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 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700246 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 final Service service = p.services.get(i);
248 if (service.info.enabled
249 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700250 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 }
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 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700267 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Provider provider = p.providers.get(i);
269 if (provider.info.enabled
270 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700271 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 }
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 Amalapurapud83006c2009-10-28 23:39:46 -0700303 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
304 if (N > 0) {
305 pi.signatures = new Signature[N];
306 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308 }
309 return pi;
310 }
311
312 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
313 byte[] readBuffer) {
314 try {
315 // We must read the stream for the JarEntry to retrieve
316 // its certificates.
317 InputStream is = jarFile.getInputStream(je);
318 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
319 // not using
320 }
321 is.close();
322 return je != null ? je.getCertificates() : null;
323 } catch (IOException e) {
324 Log.w(TAG, "Exception reading " + je.getName() + " in "
325 + jarFile.getName(), e);
326 }
327 return null;
328 }
329
330 public final static int PARSE_IS_SYSTEM = 0x0001;
331 public final static int PARSE_CHATTY = 0x0002;
332 public final static int PARSE_MUST_BE_APK = 0x0004;
333 public final static int PARSE_IGNORE_PROCESSES = 0x0008;
334
335 public int getParseError() {
336 return mParseError;
337 }
338
339 public Package parsePackage(File sourceFile, String destFileName,
340 DisplayMetrics metrics, int flags) {
341 mParseError = PackageManager.INSTALL_SUCCEEDED;
342
343 mArchiveSourcePath = sourceFile.getPath();
344 if (!sourceFile.isFile()) {
345 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
346 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
347 return null;
348 }
349 if (!isPackageFilename(sourceFile.getName())
350 && (flags&PARSE_MUST_BE_APK) != 0) {
351 if ((flags&PARSE_IS_SYSTEM) == 0) {
352 // We expect to have non-.apk files in the system dir,
353 // so don't warn about them.
354 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
355 }
356 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
357 return null;
358 }
359
360 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
361 TAG, "Scanning package: " + mArchiveSourcePath);
362
363 XmlResourceParser parser = null;
364 AssetManager assmgr = null;
365 boolean assetError = true;
366 try {
367 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700368 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
369 if(cookie != 0) {
370 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 assetError = false;
372 } else {
373 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
374 }
375 } catch (Exception e) {
376 Log.w(TAG, "Unable to read AndroidManifest.xml of "
377 + mArchiveSourcePath, e);
378 }
379 if(assetError) {
380 if (assmgr != null) assmgr.close();
381 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
382 return null;
383 }
384 String[] errorText = new String[1];
385 Package pkg = null;
386 Exception errorException = null;
387 try {
388 // XXXX todo: need to figure out correct configuration.
389 Resources res = new Resources(assmgr, metrics, null);
390 pkg = parsePackage(res, parser, flags, errorText);
391 } catch (Exception e) {
392 errorException = e;
393 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
394 }
395
396
397 if (pkg == null) {
398 if (errorException != null) {
399 Log.w(TAG, mArchiveSourcePath, errorException);
400 } else {
401 Log.w(TAG, mArchiveSourcePath + " (at "
402 + parser.getPositionDescription()
403 + "): " + errorText[0]);
404 }
405 parser.close();
406 assmgr.close();
407 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
408 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
409 }
410 return null;
411 }
412
413 parser.close();
414 assmgr.close();
415
416 pkg.applicationInfo.sourceDir = destFileName;
417 pkg.applicationInfo.publicSourceDir = destFileName;
418 pkg.mSignatures = null;
419
420 return pkg;
421 }
422
423 public boolean collectCertificates(Package pkg, int flags) {
424 pkg.mSignatures = null;
425
426 WeakReference<byte[]> readBufferRef;
427 byte[] readBuffer = null;
428 synchronized (mSync) {
429 readBufferRef = mReadBuffer;
430 if (readBufferRef != null) {
431 mReadBuffer = null;
432 readBuffer = readBufferRef.get();
433 }
434 if (readBuffer == null) {
435 readBuffer = new byte[8192];
436 readBufferRef = new WeakReference<byte[]>(readBuffer);
437 }
438 }
439
440 try {
441 JarFile jarFile = new JarFile(mArchiveSourcePath);
442
443 Certificate[] certs = null;
444
445 if ((flags&PARSE_IS_SYSTEM) != 0) {
446 // If this package comes from the system image, then we
447 // can trust it... we'll just use the AndroidManifest.xml
448 // to retrieve its signatures, not validating all of the
449 // files.
450 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
451 certs = loadCertificates(jarFile, jarEntry, readBuffer);
452 if (certs == null) {
453 Log.e(TAG, "Package " + pkg.packageName
454 + " has no certificates at entry "
455 + jarEntry.getName() + "; ignoring!");
456 jarFile.close();
457 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
458 return false;
459 }
460 if (false) {
461 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
462 + " certs=" + (certs != null ? certs.length : 0));
463 if (certs != null) {
464 final int N = certs.length;
465 for (int i=0; i<N; i++) {
466 Log.i(TAG, " Public key: "
467 + certs[i].getPublicKey().getEncoded()
468 + " " + certs[i].getPublicKey());
469 }
470 }
471 }
472
473 } else {
474 Enumeration entries = jarFile.entries();
475 while (entries.hasMoreElements()) {
476 JarEntry je = (JarEntry)entries.nextElement();
477 if (je.isDirectory()) continue;
478 if (je.getName().startsWith("META-INF/")) continue;
479 Certificate[] localCerts = loadCertificates(jarFile, je,
480 readBuffer);
481 if (false) {
482 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
483 + ": certs=" + certs + " ("
484 + (certs != null ? certs.length : 0) + ")");
485 }
486 if (localCerts == null) {
487 Log.e(TAG, "Package " + pkg.packageName
488 + " has no certificates at entry "
489 + je.getName() + "; ignoring!");
490 jarFile.close();
491 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
492 return false;
493 } else if (certs == null) {
494 certs = localCerts;
495 } else {
496 // Ensure all certificates match.
497 for (int i=0; i<certs.length; i++) {
498 boolean found = false;
499 for (int j=0; j<localCerts.length; j++) {
500 if (certs[i] != null &&
501 certs[i].equals(localCerts[j])) {
502 found = true;
503 break;
504 }
505 }
506 if (!found || certs.length != localCerts.length) {
507 Log.e(TAG, "Package " + pkg.packageName
508 + " has mismatched certificates at entry "
509 + je.getName() + "; ignoring!");
510 jarFile.close();
511 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
512 return false;
513 }
514 }
515 }
516 }
517 }
518 jarFile.close();
519
520 synchronized (mSync) {
521 mReadBuffer = readBufferRef;
522 }
523
524 if (certs != null && certs.length > 0) {
525 final int N = certs.length;
526 pkg.mSignatures = new Signature[certs.length];
527 for (int i=0; i<N; i++) {
528 pkg.mSignatures[i] = new Signature(
529 certs[i].getEncoded());
530 }
531 } else {
532 Log.e(TAG, "Package " + pkg.packageName
533 + " has no certificates; ignoring!");
534 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
535 return false;
536 }
537 } catch (CertificateEncodingException e) {
538 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
539 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
540 return false;
541 } catch (IOException e) {
542 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
543 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
544 return false;
545 } catch (RuntimeException e) {
546 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
547 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
548 return false;
549 }
550
551 return true;
552 }
553
554 public static String parsePackageName(String packageFilePath, int flags) {
555 XmlResourceParser parser = null;
556 AssetManager assmgr = null;
557 try {
558 assmgr = new AssetManager();
559 int cookie = assmgr.addAssetPath(packageFilePath);
560 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
561 } catch (Exception e) {
562 if (assmgr != null) assmgr.close();
563 Log.w(TAG, "Unable to read AndroidManifest.xml of "
564 + packageFilePath, e);
565 return null;
566 }
567 AttributeSet attrs = parser;
568 String errors[] = new String[1];
569 String packageName = null;
570 try {
571 packageName = parsePackageName(parser, attrs, flags, errors);
572 } catch (IOException e) {
573 Log.w(TAG, packageFilePath, e);
574 } catch (XmlPullParserException e) {
575 Log.w(TAG, packageFilePath, e);
576 } finally {
577 if (parser != null) parser.close();
578 if (assmgr != null) assmgr.close();
579 }
580 if (packageName == null) {
581 Log.e(TAG, "parsePackageName error: " + errors[0]);
582 return null;
583 }
584 return packageName;
585 }
586
587 private static String validateName(String name, boolean requiresSeparator) {
588 final int N = name.length();
589 boolean hasSep = false;
590 boolean front = true;
591 for (int i=0; i<N; i++) {
592 final char c = name.charAt(i);
593 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
594 front = false;
595 continue;
596 }
597 if (!front) {
598 if ((c >= '0' && c <= '9') || c == '_') {
599 continue;
600 }
601 }
602 if (c == '.') {
603 hasSep = true;
604 front = true;
605 continue;
606 }
607 return "bad character '" + c + "'";
608 }
609 return hasSep || !requiresSeparator
610 ? null : "must have at least one '.' separator";
611 }
612
613 private static String parsePackageName(XmlPullParser parser,
614 AttributeSet attrs, int flags, String[] outError)
615 throws IOException, XmlPullParserException {
616
617 int type;
618 while ((type=parser.next()) != parser.START_TAG
619 && type != parser.END_DOCUMENT) {
620 ;
621 }
622
623 if (type != parser.START_TAG) {
624 outError[0] = "No start tag found";
625 return null;
626 }
627 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
628 TAG, "Root element name: '" + parser.getName() + "'");
629 if (!parser.getName().equals("manifest")) {
630 outError[0] = "No <manifest> tag";
631 return null;
632 }
633 String pkgName = attrs.getAttributeValue(null, "package");
634 if (pkgName == null || pkgName.length() == 0) {
635 outError[0] = "<manifest> does not specify package";
636 return null;
637 }
638 String nameError = validateName(pkgName, true);
639 if (nameError != null && !"android".equals(pkgName)) {
640 outError[0] = "<manifest> specifies bad package name \""
641 + pkgName + "\": " + nameError;
642 return null;
643 }
644
645 return pkgName.intern();
646 }
647
648 /**
649 * Temporary.
650 */
651 static public Signature stringToSignature(String str) {
652 final int N = str.length();
653 byte[] sig = new byte[N];
654 for (int i=0; i<N; i++) {
655 sig[i] = (byte)str.charAt(i);
656 }
657 return new Signature(sig);
658 }
659
660 private Package parsePackage(
661 Resources res, XmlResourceParser parser, int flags, String[] outError)
662 throws XmlPullParserException, IOException {
663 AttributeSet attrs = parser;
664
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700665 mParseInstrumentationArgs = null;
666 mParseActivityArgs = null;
667 mParseServiceArgs = null;
668 mParseProviderArgs = null;
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 String pkgName = parsePackageName(parser, attrs, flags, outError);
671 if (pkgName == null) {
672 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
673 return null;
674 }
675 int type;
676
677 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 TypedArray sa = res.obtainAttributes(attrs,
681 com.android.internal.R.styleable.AndroidManifest);
682 pkg.mVersionCode = sa.getInteger(
683 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
684 pkg.mVersionName = sa.getNonResourceString(
685 com.android.internal.R.styleable.AndroidManifest_versionName);
686 if (pkg.mVersionName != null) {
687 pkg.mVersionName = pkg.mVersionName.intern();
688 }
689 String str = sa.getNonResourceString(
690 com.android.internal.R.styleable.AndroidManifest_sharedUserId);
691 if (str != null) {
692 String nameError = validateName(str, true);
693 if (nameError != null && !"android".equals(pkgName)) {
694 outError[0] = "<manifest> specifies bad sharedUserId name \""
695 + str + "\": " + nameError;
696 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
697 return null;
698 }
699 pkg.mSharedUserId = str.intern();
700 pkg.mSharedUserLabel = sa.getResourceId(
701 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
702 }
703 sa.recycle();
704
Dianne Hackborn723738c2009-06-25 19:48:04 -0700705 // Resource boolean are -1, so 1 means we don't know the value.
706 int supportsSmallScreens = 1;
707 int supportsNormalScreens = 1;
708 int supportsLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700709 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700710 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 int outerDepth = parser.getDepth();
713 while ((type=parser.next()) != parser.END_DOCUMENT
714 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
715 if (type == parser.END_TAG || type == parser.TEXT) {
716 continue;
717 }
718
719 String tagName = parser.getName();
720 if (tagName.equals("application")) {
721 if (foundApp) {
722 if (RIGID_PARSER) {
723 outError[0] = "<manifest> has more than one <application>";
724 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
725 return null;
726 } else {
727 Log.w(TAG, "<manifest> has more than one <application>");
728 XmlUtils.skipCurrentTag(parser);
729 continue;
730 }
731 }
732
733 foundApp = true;
734 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
735 return null;
736 }
737 } else if (tagName.equals("permission-group")) {
738 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
739 return null;
740 }
741 } else if (tagName.equals("permission")) {
742 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
743 return null;
744 }
745 } else if (tagName.equals("permission-tree")) {
746 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
747 return null;
748 }
749 } else if (tagName.equals("uses-permission")) {
750 sa = res.obtainAttributes(attrs,
751 com.android.internal.R.styleable.AndroidManifestUsesPermission);
752
753 String name = sa.getNonResourceString(
754 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
755
756 sa.recycle();
757
758 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060af2009-07-09 18:14:31 -0700759 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 }
761
762 XmlUtils.skipCurrentTag(parser);
763
764 } else if (tagName.equals("uses-configuration")) {
765 ConfigurationInfo cPref = new ConfigurationInfo();
766 sa = res.obtainAttributes(attrs,
767 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
768 cPref.reqTouchScreen = sa.getInt(
769 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
770 Configuration.TOUCHSCREEN_UNDEFINED);
771 cPref.reqKeyboardType = sa.getInt(
772 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
773 Configuration.KEYBOARD_UNDEFINED);
774 if (sa.getBoolean(
775 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
776 false)) {
777 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
778 }
779 cPref.reqNavigation = sa.getInt(
780 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
781 Configuration.NAVIGATION_UNDEFINED);
782 if (sa.getBoolean(
783 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
784 false)) {
785 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
786 }
787 sa.recycle();
788 pkg.configPreferences.add(cPref);
789
790 XmlUtils.skipCurrentTag(parser);
791
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700792 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700793 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700794 sa = res.obtainAttributes(attrs,
795 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborn49237342009-08-27 20:08:01 -0700796 fi.name = sa.getNonResourceString(
797 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
798 if (fi.name == null) {
799 fi.reqGlEsVersion = sa.getInt(
800 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
801 FeatureInfo.GL_ES_VERSION_UNDEFINED);
802 }
803 if (sa.getBoolean(
804 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
805 true)) {
806 fi.flags |= FeatureInfo.FLAG_REQUIRED;
807 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700808 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700809 if (pkg.reqFeatures == null) {
810 pkg.reqFeatures = new ArrayList<FeatureInfo>();
811 }
812 pkg.reqFeatures.add(fi);
813
814 if (fi.name == null) {
815 ConfigurationInfo cPref = new ConfigurationInfo();
816 cPref.reqGlEsVersion = fi.reqGlEsVersion;
817 pkg.configPreferences.add(cPref);
818 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700819
820 XmlUtils.skipCurrentTag(parser);
821
Dianne Hackborn851a5412009-05-08 12:06:44 -0700822 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700823 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 sa = res.obtainAttributes(attrs,
825 com.android.internal.R.styleable.AndroidManifestUsesSdk);
826
Dianne Hackborn851a5412009-05-08 12:06:44 -0700827 int minVers = 0;
828 String minCode = null;
829 int targetVers = 0;
830 String targetCode = null;
831
832 TypedValue val = sa.peekValue(
833 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
834 if (val != null) {
835 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
836 targetCode = minCode = val.string.toString();
837 } else {
838 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700839 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700840 }
841 }
842
843 val = sa.peekValue(
844 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
845 if (val != null) {
846 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
847 targetCode = minCode = val.string.toString();
848 } else {
849 // If it's not a string, it's an integer.
850 targetVers = val.data;
851 }
852 }
853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 sa.recycle();
855
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700856 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700857 if (!minCode.equals(SDK_CODENAME)) {
858 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700859 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700860 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700861 } else {
862 outError[0] = "Requires development platform " + minCode
863 + " but this is a release platform.";
864 }
865 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
866 return null;
867 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700868 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700869 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700870 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700871 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
872 return null;
873 }
874
Dianne Hackborn851a5412009-05-08 12:06:44 -0700875 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700876 if (!targetCode.equals(SDK_CODENAME)) {
877 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700878 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700879 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700880 } else {
881 outError[0] = "Requires development platform " + targetCode
882 + " but this is a release platform.";
883 }
884 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
885 return null;
886 }
887 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700888 pkg.applicationInfo.targetSdkVersion
889 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
890 } else {
891 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 }
894
895 XmlUtils.skipCurrentTag(parser);
896
Dianne Hackborn723738c2009-06-25 19:48:04 -0700897 } else if (tagName.equals("supports-screens")) {
898 sa = res.obtainAttributes(attrs,
899 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
900
901 // This is a trick to get a boolean and still able to detect
902 // if a value was actually set.
903 supportsSmallScreens = sa.getInteger(
904 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
905 supportsSmallScreens);
906 supportsNormalScreens = sa.getInteger(
907 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
908 supportsNormalScreens);
909 supportsLargeScreens = sa.getInteger(
910 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
911 supportsLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700912 resizeable = sa.getInteger(
913 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
914 supportsLargeScreens);
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700915 anyDensity = sa.getInteger(
916 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
917 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700918
919 sa.recycle();
920
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700921 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060af2009-07-09 18:14:31 -0700922
923 } else if (tagName.equals("protected-broadcast")) {
924 sa = res.obtainAttributes(attrs,
925 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
926
927 String name = sa.getNonResourceString(
928 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
929
930 sa.recycle();
931
932 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
933 if (pkg.protectedBroadcasts == null) {
934 pkg.protectedBroadcasts = new ArrayList<String>();
935 }
936 if (!pkg.protectedBroadcasts.contains(name)) {
937 pkg.protectedBroadcasts.add(name.intern());
938 }
939 }
940
941 XmlUtils.skipCurrentTag(parser);
942
943 } else if (tagName.equals("instrumentation")) {
944 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
945 return null;
946 }
947
948 } else if (tagName.equals("eat-comment")) {
949 // Just skip this tag
950 XmlUtils.skipCurrentTag(parser);
951 continue;
952
953 } else if (RIGID_PARSER) {
954 outError[0] = "Bad element under <manifest>: "
955 + parser.getName();
956 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
957 return null;
958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -0700960 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
961 + " at " + mArchiveSourcePath + " "
962 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 XmlUtils.skipCurrentTag(parser);
964 continue;
965 }
966 }
967
968 if (!foundApp && pkg.instrumentation.size() == 0) {
969 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
970 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
971 }
972
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700973 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700974 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700975 for (int ip=0; ip<NP; ip++) {
976 final PackageParser.NewPermissionInfo npi
977 = PackageParser.NEW_PERMISSIONS[ip];
978 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
979 break;
980 }
981 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700982 if (implicitPerms == null) {
983 implicitPerms = new StringBuilder(128);
984 implicitPerms.append(pkg.packageName);
985 implicitPerms.append(": compat added ");
986 } else {
987 implicitPerms.append(' ');
988 }
989 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700990 pkg.requestedPermissions.add(npi.name);
991 }
Dianne Hackborn851a5412009-05-08 12:06:44 -0700992 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700993 if (implicitPerms != null) {
994 Log.i(TAG, implicitPerms.toString());
995 }
Dianne Hackborn851a5412009-05-08 12:06:44 -0700996
Dianne Hackborn723738c2009-06-25 19:48:04 -0700997 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
998 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700999 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001000 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1001 }
1002 if (supportsNormalScreens != 0) {
1003 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1004 }
1005 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1006 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001007 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001008 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1009 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001010 if (resizeable < 0 || (resizeable > 0
1011 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001012 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001013 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1014 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001015 if (anyDensity < 0 || (anyDensity > 0
1016 && pkg.applicationInfo.targetSdkVersion
1017 >= android.os.Build.VERSION_CODES.DONUT)) {
1018 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001019 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 return pkg;
1022 }
1023
1024 private static String buildClassName(String pkg, CharSequence clsSeq,
1025 String[] outError) {
1026 if (clsSeq == null || clsSeq.length() <= 0) {
1027 outError[0] = "Empty class name in package " + pkg;
1028 return null;
1029 }
1030 String cls = clsSeq.toString();
1031 char c = cls.charAt(0);
1032 if (c == '.') {
1033 return (pkg + cls).intern();
1034 }
1035 if (cls.indexOf('.') < 0) {
1036 StringBuilder b = new StringBuilder(pkg);
1037 b.append('.');
1038 b.append(cls);
1039 return b.toString().intern();
1040 }
1041 if (c >= 'a' && c <= 'z') {
1042 return cls.intern();
1043 }
1044 outError[0] = "Bad class name " + cls + " in package " + pkg;
1045 return null;
1046 }
1047
1048 private static String buildCompoundName(String pkg,
1049 CharSequence procSeq, String type, String[] outError) {
1050 String proc = procSeq.toString();
1051 char c = proc.charAt(0);
1052 if (pkg != null && c == ':') {
1053 if (proc.length() < 2) {
1054 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1055 + ": must be at least two characters";
1056 return null;
1057 }
1058 String subName = proc.substring(1);
1059 String nameError = validateName(subName, false);
1060 if (nameError != null) {
1061 outError[0] = "Invalid " + type + " name " + proc + " in package "
1062 + pkg + ": " + nameError;
1063 return null;
1064 }
1065 return (pkg + proc).intern();
1066 }
1067 String nameError = validateName(proc, true);
1068 if (nameError != null && !"system".equals(proc)) {
1069 outError[0] = "Invalid " + type + " name " + proc + " in package "
1070 + pkg + ": " + nameError;
1071 return null;
1072 }
1073 return proc.intern();
1074 }
1075
1076 private static String buildProcessName(String pkg, String defProc,
1077 CharSequence procSeq, int flags, String[] separateProcesses,
1078 String[] outError) {
1079 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1080 return defProc != null ? defProc : pkg;
1081 }
1082 if (separateProcesses != null) {
1083 for (int i=separateProcesses.length-1; i>=0; i--) {
1084 String sp = separateProcesses[i];
1085 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1086 return pkg;
1087 }
1088 }
1089 }
1090 if (procSeq == null || procSeq.length() <= 0) {
1091 return defProc;
1092 }
1093 return buildCompoundName(pkg, procSeq, "package", outError);
1094 }
1095
1096 private static String buildTaskAffinityName(String pkg, String defProc,
1097 CharSequence procSeq, String[] outError) {
1098 if (procSeq == null) {
1099 return defProc;
1100 }
1101 if (procSeq.length() <= 0) {
1102 return null;
1103 }
1104 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1105 }
1106
1107 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1108 XmlPullParser parser, AttributeSet attrs, String[] outError)
1109 throws XmlPullParserException, IOException {
1110 PermissionGroup perm = new PermissionGroup(owner);
1111
1112 TypedArray sa = res.obtainAttributes(attrs,
1113 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1114
1115 if (!parsePackageItemInfo(owner, perm.info, outError,
1116 "<permission-group>", sa,
1117 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1118 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
1119 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon)) {
1120 sa.recycle();
1121 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1122 return null;
1123 }
1124
1125 perm.info.descriptionRes = sa.getResourceId(
1126 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1127 0);
1128
1129 sa.recycle();
1130
1131 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1132 outError)) {
1133 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1134 return null;
1135 }
1136
1137 owner.permissionGroups.add(perm);
1138
1139 return perm;
1140 }
1141
1142 private Permission parsePermission(Package owner, Resources res,
1143 XmlPullParser parser, AttributeSet attrs, String[] outError)
1144 throws XmlPullParserException, IOException {
1145 Permission perm = new Permission(owner);
1146
1147 TypedArray sa = res.obtainAttributes(attrs,
1148 com.android.internal.R.styleable.AndroidManifestPermission);
1149
1150 if (!parsePackageItemInfo(owner, perm.info, outError,
1151 "<permission>", sa,
1152 com.android.internal.R.styleable.AndroidManifestPermission_name,
1153 com.android.internal.R.styleable.AndroidManifestPermission_label,
1154 com.android.internal.R.styleable.AndroidManifestPermission_icon)) {
1155 sa.recycle();
1156 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1157 return null;
1158 }
1159
1160 perm.info.group = sa.getNonResourceString(
1161 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1162 if (perm.info.group != null) {
1163 perm.info.group = perm.info.group.intern();
1164 }
1165
1166 perm.info.descriptionRes = sa.getResourceId(
1167 com.android.internal.R.styleable.AndroidManifestPermission_description,
1168 0);
1169
1170 perm.info.protectionLevel = sa.getInt(
1171 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1172 PermissionInfo.PROTECTION_NORMAL);
1173
1174 sa.recycle();
1175
1176 if (perm.info.protectionLevel == -1) {
1177 outError[0] = "<permission> does not specify protectionLevel";
1178 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1179 return null;
1180 }
1181
1182 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1183 outError)) {
1184 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1185 return null;
1186 }
1187
1188 owner.permissions.add(perm);
1189
1190 return perm;
1191 }
1192
1193 private Permission parsePermissionTree(Package owner, Resources res,
1194 XmlPullParser parser, AttributeSet attrs, String[] outError)
1195 throws XmlPullParserException, IOException {
1196 Permission perm = new Permission(owner);
1197
1198 TypedArray sa = res.obtainAttributes(attrs,
1199 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1200
1201 if (!parsePackageItemInfo(owner, perm.info, outError,
1202 "<permission-tree>", sa,
1203 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1204 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
1205 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon)) {
1206 sa.recycle();
1207 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1208 return null;
1209 }
1210
1211 sa.recycle();
1212
1213 int index = perm.info.name.indexOf('.');
1214 if (index > 0) {
1215 index = perm.info.name.indexOf('.', index+1);
1216 }
1217 if (index < 0) {
1218 outError[0] = "<permission-tree> name has less than three segments: "
1219 + perm.info.name;
1220 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1221 return null;
1222 }
1223
1224 perm.info.descriptionRes = 0;
1225 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1226 perm.tree = true;
1227
1228 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1229 outError)) {
1230 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1231 return null;
1232 }
1233
1234 owner.permissions.add(perm);
1235
1236 return perm;
1237 }
1238
1239 private Instrumentation parseInstrumentation(Package owner, Resources res,
1240 XmlPullParser parser, AttributeSet attrs, String[] outError)
1241 throws XmlPullParserException, IOException {
1242 TypedArray sa = res.obtainAttributes(attrs,
1243 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1244
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001245 if (mParseInstrumentationArgs == null) {
1246 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1247 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1248 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
1249 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon);
1250 mParseInstrumentationArgs.tag = "<instrumentation>";
1251 }
1252
1253 mParseInstrumentationArgs.sa = sa;
1254
1255 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1256 new InstrumentationInfo());
1257 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 sa.recycle();
1259 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1260 return null;
1261 }
1262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 String str;
1264 str = sa.getNonResourceString(
1265 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1266 a.info.targetPackage = str != null ? str.intern() : null;
1267
1268 a.info.handleProfiling = sa.getBoolean(
1269 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1270 false);
1271
1272 a.info.functionalTest = sa.getBoolean(
1273 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1274 false);
1275
1276 sa.recycle();
1277
1278 if (a.info.targetPackage == null) {
1279 outError[0] = "<instrumentation> does not specify targetPackage";
1280 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1281 return null;
1282 }
1283
1284 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1285 outError)) {
1286 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1287 return null;
1288 }
1289
1290 owner.instrumentation.add(a);
1291
1292 return a;
1293 }
1294
1295 private boolean parseApplication(Package owner, Resources res,
1296 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1297 throws XmlPullParserException, IOException {
1298 final ApplicationInfo ai = owner.applicationInfo;
1299 final String pkgName = owner.applicationInfo.packageName;
1300
1301 TypedArray sa = res.obtainAttributes(attrs,
1302 com.android.internal.R.styleable.AndroidManifestApplication);
1303
1304 String name = sa.getNonResourceString(
1305 com.android.internal.R.styleable.AndroidManifestApplication_name);
1306 if (name != null) {
1307 ai.className = buildClassName(pkgName, name, outError);
1308 if (ai.className == null) {
1309 sa.recycle();
1310 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1311 return false;
1312 }
1313 }
1314
1315 String manageSpaceActivity = sa.getNonResourceString(
1316 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity);
1317 if (manageSpaceActivity != null) {
1318 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1319 outError);
1320 }
1321
Christopher Tate181fafa2009-05-14 11:12:14 -07001322 boolean allowBackup = sa.getBoolean(
1323 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1324 if (allowBackup) {
1325 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001326
1327 // backupAgent, killAfterRestore, and restoreNeedsApplication are only relevant
1328 // if backup is possible for the given application.
Christopher Tate181fafa2009-05-14 11:12:14 -07001329 String backupAgent = sa.getNonResourceString(
1330 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent);
1331 if (backupAgent != null) {
1332 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001333 if (false) {
1334 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1335 + " from " + pkgName + "+" + backupAgent);
1336 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001337
1338 if (sa.getBoolean(
1339 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1340 true)) {
1341 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1342 }
1343 if (sa.getBoolean(
1344 com.android.internal.R.styleable.AndroidManifestApplication_restoreNeedsApplication,
1345 false)) {
1346 ai.flags |= ApplicationInfo.FLAG_RESTORE_NEEDS_APPLICATION;
1347 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001348 }
1349 }
1350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 TypedValue v = sa.peekValue(
1352 com.android.internal.R.styleable.AndroidManifestApplication_label);
1353 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1354 ai.nonLocalizedLabel = v.coerceToString();
1355 }
1356
1357 ai.icon = sa.getResourceId(
1358 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1359 ai.theme = sa.getResourceId(
1360 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1361 ai.descriptionRes = sa.getResourceId(
1362 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1363
1364 if ((flags&PARSE_IS_SYSTEM) != 0) {
1365 if (sa.getBoolean(
1366 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1367 false)) {
1368 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1369 }
1370 }
1371
1372 if (sa.getBoolean(
1373 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1374 false)) {
1375 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1376 }
1377
1378 if (sa.getBoolean(
1379 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1380 true)) {
1381 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1382 }
1383
1384 if (sa.getBoolean(
1385 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1386 false)) {
1387 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1388 }
1389
1390 if (sa.getBoolean(
1391 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1392 true)) {
1393 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1394 }
1395
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001396 if (sa.getBoolean(
1397 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001398 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001399 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1400 }
1401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 String str;
1403 str = sa.getNonResourceString(
1404 com.android.internal.R.styleable.AndroidManifestApplication_permission);
1405 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1406
1407 str = sa.getNonResourceString(
1408 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1409 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1410 str, outError);
1411
1412 if (outError[0] == null) {
1413 ai.processName = buildProcessName(ai.packageName, null, sa.getNonResourceString(
1414 com.android.internal.R.styleable.AndroidManifestApplication_process),
1415 flags, mSeparateProcesses, outError);
1416
1417 ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
1418 }
1419
1420 sa.recycle();
1421
1422 if (outError[0] != null) {
1423 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1424 return false;
1425 }
1426
1427 final int innerDepth = parser.getDepth();
1428
1429 int type;
1430 while ((type=parser.next()) != parser.END_DOCUMENT
1431 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1432 if (type == parser.END_TAG || type == parser.TEXT) {
1433 continue;
1434 }
1435
1436 String tagName = parser.getName();
1437 if (tagName.equals("activity")) {
1438 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1439 if (a == null) {
1440 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1441 return false;
1442 }
1443
1444 owner.activities.add(a);
1445
1446 } else if (tagName.equals("receiver")) {
1447 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1448 if (a == null) {
1449 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1450 return false;
1451 }
1452
1453 owner.receivers.add(a);
1454
1455 } else if (tagName.equals("service")) {
1456 Service s = parseService(owner, res, parser, attrs, flags, outError);
1457 if (s == null) {
1458 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1459 return false;
1460 }
1461
1462 owner.services.add(s);
1463
1464 } else if (tagName.equals("provider")) {
1465 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1466 if (p == null) {
1467 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1468 return false;
1469 }
1470
1471 owner.providers.add(p);
1472
1473 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001474 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 if (a == null) {
1476 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1477 return false;
1478 }
1479
1480 owner.activities.add(a);
1481
1482 } else if (parser.getName().equals("meta-data")) {
1483 // note: application meta-data is stored off to the side, so it can
1484 // remain null in the primary copy (we like to avoid extra copies because
1485 // it can be large)
1486 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1487 outError)) == null) {
1488 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1489 return false;
1490 }
1491
1492 } else if (tagName.equals("uses-library")) {
1493 sa = res.obtainAttributes(attrs,
1494 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1495
1496 String lname = sa.getNonResourceString(
1497 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001498 boolean req = sa.getBoolean(
1499 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1500 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501
1502 sa.recycle();
1503
Dianne Hackborn49237342009-08-27 20:08:01 -07001504 if (lname != null) {
1505 if (req) {
1506 if (owner.usesLibraries == null) {
1507 owner.usesLibraries = new ArrayList<String>();
1508 }
1509 if (!owner.usesLibraries.contains(lname)) {
1510 owner.usesLibraries.add(lname.intern());
1511 }
1512 } else {
1513 if (owner.usesOptionalLibraries == null) {
1514 owner.usesOptionalLibraries = new ArrayList<String>();
1515 }
1516 if (!owner.usesOptionalLibraries.contains(lname)) {
1517 owner.usesOptionalLibraries.add(lname.intern());
1518 }
1519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 }
1521
1522 XmlUtils.skipCurrentTag(parser);
1523
1524 } else {
1525 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001526 Log.w(TAG, "Unknown element under <application>: " + tagName
1527 + " at " + mArchiveSourcePath + " "
1528 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 XmlUtils.skipCurrentTag(parser);
1530 continue;
1531 } else {
1532 outError[0] = "Bad element under <application>: " + tagName;
1533 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1534 return false;
1535 }
1536 }
1537 }
1538
1539 return true;
1540 }
1541
1542 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1543 String[] outError, String tag, TypedArray sa,
1544 int nameRes, int labelRes, int iconRes) {
1545 String name = sa.getNonResourceString(nameRes);
1546 if (name == null) {
1547 outError[0] = tag + " does not specify android:name";
1548 return false;
1549 }
1550
1551 outInfo.name
1552 = buildClassName(owner.applicationInfo.packageName, name, outError);
1553 if (outInfo.name == null) {
1554 return false;
1555 }
1556
1557 int iconVal = sa.getResourceId(iconRes, 0);
1558 if (iconVal != 0) {
1559 outInfo.icon = iconVal;
1560 outInfo.nonLocalizedLabel = null;
1561 }
1562
1563 TypedValue v = sa.peekValue(labelRes);
1564 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1565 outInfo.nonLocalizedLabel = v.coerceToString();
1566 }
1567
1568 outInfo.packageName = owner.packageName;
1569
1570 return true;
1571 }
1572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 private Activity parseActivity(Package owner, Resources res,
1574 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1575 boolean receiver) throws XmlPullParserException, IOException {
1576 TypedArray sa = res.obtainAttributes(attrs,
1577 com.android.internal.R.styleable.AndroidManifestActivity);
1578
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001579 if (mParseActivityArgs == null) {
1580 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1581 com.android.internal.R.styleable.AndroidManifestActivity_name,
1582 com.android.internal.R.styleable.AndroidManifestActivity_label,
1583 com.android.internal.R.styleable.AndroidManifestActivity_icon,
1584 mSeparateProcesses,
1585 com.android.internal.R.styleable.AndroidManifestActivity_process,
1586 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1587 }
1588
1589 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1590 mParseActivityArgs.sa = sa;
1591 mParseActivityArgs.flags = flags;
1592
1593 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1594 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 sa.recycle();
1596 return null;
1597 }
1598
1599 final boolean setExported = sa.hasValue(
1600 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1601 if (setExported) {
1602 a.info.exported = sa.getBoolean(
1603 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1604 }
1605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 a.info.theme = sa.getResourceId(
1607 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1608
1609 String str;
1610 str = sa.getNonResourceString(
1611 com.android.internal.R.styleable.AndroidManifestActivity_permission);
1612 if (str == null) {
1613 a.info.permission = owner.applicationInfo.permission;
1614 } else {
1615 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1616 }
1617
1618 str = sa.getNonResourceString(
1619 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity);
1620 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1621 owner.applicationInfo.taskAffinity, str, outError);
1622
1623 a.info.flags = 0;
1624 if (sa.getBoolean(
1625 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1626 false)) {
1627 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1628 }
1629
1630 if (sa.getBoolean(
1631 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1632 false)) {
1633 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1634 }
1635
1636 if (sa.getBoolean(
1637 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1638 false)) {
1639 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1640 }
1641
1642 if (sa.getBoolean(
1643 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1644 false)) {
1645 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1646 }
1647
1648 if (sa.getBoolean(
1649 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1650 false)) {
1651 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1652 }
1653
1654 if (sa.getBoolean(
1655 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1656 false)) {
1657 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1658 }
1659
1660 if (sa.getBoolean(
1661 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1662 false)) {
1663 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1664 }
1665
1666 if (sa.getBoolean(
1667 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1668 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1669 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1670 }
1671
Dianne Hackbornffa42482009-09-23 22:20:11 -07001672 if (sa.getBoolean(
1673 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1674 false)) {
1675 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1676 }
1677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 if (!receiver) {
1679 a.info.launchMode = sa.getInt(
1680 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1681 ActivityInfo.LAUNCH_MULTIPLE);
1682 a.info.screenOrientation = sa.getInt(
1683 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1684 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1685 a.info.configChanges = sa.getInt(
1686 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1687 0);
1688 a.info.softInputMode = sa.getInt(
1689 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1690 0);
1691 } else {
1692 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1693 a.info.configChanges = 0;
1694 }
1695
1696 sa.recycle();
1697
1698 if (outError[0] != null) {
1699 return null;
1700 }
1701
1702 int outerDepth = parser.getDepth();
1703 int type;
1704 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1705 && (type != XmlPullParser.END_TAG
1706 || parser.getDepth() > outerDepth)) {
1707 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1708 continue;
1709 }
1710
1711 if (parser.getName().equals("intent-filter")) {
1712 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1713 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1714 return null;
1715 }
1716 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001717 Log.w(TAG, "No actions in intent filter at "
1718 + mArchiveSourcePath + " "
1719 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 } else {
1721 a.intents.add(intent);
1722 }
1723 } else if (parser.getName().equals("meta-data")) {
1724 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1725 outError)) == null) {
1726 return null;
1727 }
1728 } else {
1729 if (!RIGID_PARSER) {
1730 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1731 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001732 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1733 + " at " + mArchiveSourcePath + " "
1734 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001736 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1737 + " at " + mArchiveSourcePath + " "
1738 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 }
1740 XmlUtils.skipCurrentTag(parser);
1741 continue;
1742 }
1743 if (receiver) {
1744 outError[0] = "Bad element under <receiver>: " + parser.getName();
1745 } else {
1746 outError[0] = "Bad element under <activity>: " + parser.getName();
1747 }
1748 return null;
1749 }
1750 }
1751
1752 if (!setExported) {
1753 a.info.exported = a.intents.size() > 0;
1754 }
1755
1756 return a;
1757 }
1758
1759 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001760 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1761 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 TypedArray sa = res.obtainAttributes(attrs,
1763 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1764
1765 String targetActivity = sa.getNonResourceString(
1766 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity);
1767 if (targetActivity == null) {
1768 outError[0] = "<activity-alias> does not specify android:targetActivity";
1769 sa.recycle();
1770 return null;
1771 }
1772
1773 targetActivity = buildClassName(owner.applicationInfo.packageName,
1774 targetActivity, outError);
1775 if (targetActivity == null) {
1776 sa.recycle();
1777 return null;
1778 }
1779
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001780 if (mParseActivityAliasArgs == null) {
1781 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1782 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1783 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1784 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
1785 mSeparateProcesses,
1786 0,
1787 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1788 mParseActivityAliasArgs.tag = "<activity-alias>";
1789 }
1790
1791 mParseActivityAliasArgs.sa = sa;
1792 mParseActivityAliasArgs.flags = flags;
1793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 Activity target = null;
1795
1796 final int NA = owner.activities.size();
1797 for (int i=0; i<NA; i++) {
1798 Activity t = owner.activities.get(i);
1799 if (targetActivity.equals(t.info.name)) {
1800 target = t;
1801 break;
1802 }
1803 }
1804
1805 if (target == null) {
1806 outError[0] = "<activity-alias> target activity " + targetActivity
1807 + " not found in manifest";
1808 sa.recycle();
1809 return null;
1810 }
1811
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001812 ActivityInfo info = new ActivityInfo();
1813 info.targetActivity = targetActivity;
1814 info.configChanges = target.info.configChanges;
1815 info.flags = target.info.flags;
1816 info.icon = target.info.icon;
1817 info.labelRes = target.info.labelRes;
1818 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
1819 info.launchMode = target.info.launchMode;
1820 info.processName = target.info.processName;
1821 info.screenOrientation = target.info.screenOrientation;
1822 info.taskAffinity = target.info.taskAffinity;
1823 info.theme = target.info.theme;
1824
1825 Activity a = new Activity(mParseActivityAliasArgs, info);
1826 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 sa.recycle();
1828 return null;
1829 }
1830
1831 final boolean setExported = sa.hasValue(
1832 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
1833 if (setExported) {
1834 a.info.exported = sa.getBoolean(
1835 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
1836 }
1837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 String str;
1839 str = sa.getNonResourceString(
1840 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission);
1841 if (str != null) {
1842 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1843 }
1844
1845 sa.recycle();
1846
1847 if (outError[0] != null) {
1848 return null;
1849 }
1850
1851 int outerDepth = parser.getDepth();
1852 int type;
1853 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1854 && (type != XmlPullParser.END_TAG
1855 || parser.getDepth() > outerDepth)) {
1856 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1857 continue;
1858 }
1859
1860 if (parser.getName().equals("intent-filter")) {
1861 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1862 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
1863 return null;
1864 }
1865 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001866 Log.w(TAG, "No actions in intent filter at "
1867 + mArchiveSourcePath + " "
1868 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 } else {
1870 a.intents.add(intent);
1871 }
1872 } else if (parser.getName().equals("meta-data")) {
1873 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1874 outError)) == null) {
1875 return null;
1876 }
1877 } else {
1878 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001879 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
1880 + " at " + mArchiveSourcePath + " "
1881 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 XmlUtils.skipCurrentTag(parser);
1883 continue;
1884 }
1885 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
1886 return null;
1887 }
1888 }
1889
1890 if (!setExported) {
1891 a.info.exported = a.intents.size() > 0;
1892 }
1893
1894 return a;
1895 }
1896
1897 private Provider parseProvider(Package owner, Resources res,
1898 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1899 throws XmlPullParserException, IOException {
1900 TypedArray sa = res.obtainAttributes(attrs,
1901 com.android.internal.R.styleable.AndroidManifestProvider);
1902
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001903 if (mParseProviderArgs == null) {
1904 mParseProviderArgs = new ParseComponentArgs(owner, outError,
1905 com.android.internal.R.styleable.AndroidManifestProvider_name,
1906 com.android.internal.R.styleable.AndroidManifestProvider_label,
1907 com.android.internal.R.styleable.AndroidManifestProvider_icon,
1908 mSeparateProcesses,
1909 com.android.internal.R.styleable.AndroidManifestProvider_process,
1910 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
1911 mParseProviderArgs.tag = "<provider>";
1912 }
1913
1914 mParseProviderArgs.sa = sa;
1915 mParseProviderArgs.flags = flags;
1916
1917 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
1918 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 sa.recycle();
1920 return null;
1921 }
1922
1923 p.info.exported = sa.getBoolean(
1924 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
1925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 String cpname = sa.getNonResourceString(
1927 com.android.internal.R.styleable.AndroidManifestProvider_authorities);
1928
1929 p.info.isSyncable = sa.getBoolean(
1930 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
1931 false);
1932
1933 String permission = sa.getNonResourceString(
1934 com.android.internal.R.styleable.AndroidManifestProvider_permission);
1935 String str = sa.getNonResourceString(
1936 com.android.internal.R.styleable.AndroidManifestProvider_readPermission);
1937 if (str == null) {
1938 str = permission;
1939 }
1940 if (str == null) {
1941 p.info.readPermission = owner.applicationInfo.permission;
1942 } else {
1943 p.info.readPermission =
1944 str.length() > 0 ? str.toString().intern() : null;
1945 }
1946 str = sa.getNonResourceString(
1947 com.android.internal.R.styleable.AndroidManifestProvider_writePermission);
1948 if (str == null) {
1949 str = permission;
1950 }
1951 if (str == null) {
1952 p.info.writePermission = owner.applicationInfo.permission;
1953 } else {
1954 p.info.writePermission =
1955 str.length() > 0 ? str.toString().intern() : null;
1956 }
1957
1958 p.info.grantUriPermissions = sa.getBoolean(
1959 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
1960 false);
1961
1962 p.info.multiprocess = sa.getBoolean(
1963 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
1964 false);
1965
1966 p.info.initOrder = sa.getInt(
1967 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
1968 0);
1969
1970 sa.recycle();
1971
1972 if (cpname == null) {
1973 outError[0] = "<provider> does not incude authorities attribute";
1974 return null;
1975 }
1976 p.info.authority = cpname.intern();
1977
1978 if (!parseProviderTags(res, parser, attrs, p, outError)) {
1979 return null;
1980 }
1981
1982 return p;
1983 }
1984
1985 private boolean parseProviderTags(Resources res,
1986 XmlPullParser parser, AttributeSet attrs,
1987 Provider outInfo, String[] outError)
1988 throws XmlPullParserException, IOException {
1989 int outerDepth = parser.getDepth();
1990 int type;
1991 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1992 && (type != XmlPullParser.END_TAG
1993 || parser.getDepth() > outerDepth)) {
1994 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1995 continue;
1996 }
1997
1998 if (parser.getName().equals("meta-data")) {
1999 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2000 outInfo.metaData, outError)) == null) {
2001 return false;
2002 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 } else if (parser.getName().equals("grant-uri-permission")) {
2005 TypedArray sa = res.obtainAttributes(attrs,
2006 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2007
2008 PatternMatcher pa = null;
2009
2010 String str = sa.getNonResourceString(
2011 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path);
2012 if (str != null) {
2013 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2014 }
2015
2016 str = sa.getNonResourceString(
2017 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix);
2018 if (str != null) {
2019 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2020 }
2021
2022 str = sa.getNonResourceString(
2023 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern);
2024 if (str != null) {
2025 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2026 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 sa.recycle();
2029
2030 if (pa != null) {
2031 if (outInfo.info.uriPermissionPatterns == null) {
2032 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2033 outInfo.info.uriPermissionPatterns[0] = pa;
2034 } else {
2035 final int N = outInfo.info.uriPermissionPatterns.length;
2036 PatternMatcher[] newp = new PatternMatcher[N+1];
2037 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2038 newp[N] = pa;
2039 outInfo.info.uriPermissionPatterns = newp;
2040 }
2041 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002042 } else {
2043 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002044 Log.w(TAG, "Unknown element under <path-permission>: "
2045 + parser.getName() + " at " + mArchiveSourcePath + " "
2046 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002047 XmlUtils.skipCurrentTag(parser);
2048 continue;
2049 }
2050 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2051 return false;
2052 }
2053 XmlUtils.skipCurrentTag(parser);
2054
2055 } else if (parser.getName().equals("path-permission")) {
2056 TypedArray sa = res.obtainAttributes(attrs,
2057 com.android.internal.R.styleable.AndroidManifestPathPermission);
2058
2059 PathPermission pa = null;
2060
2061 String permission = sa.getNonResourceString(
2062 com.android.internal.R.styleable.AndroidManifestPathPermission_permission);
2063 String readPermission = sa.getNonResourceString(
2064 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission);
2065 if (readPermission == null) {
2066 readPermission = permission;
2067 }
2068 String writePermission = sa.getNonResourceString(
2069 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission);
2070 if (writePermission == null) {
2071 writePermission = permission;
2072 }
2073
2074 boolean havePerm = false;
2075 if (readPermission != null) {
2076 readPermission = readPermission.intern();
2077 havePerm = true;
2078 }
2079 if (writePermission != null) {
2080 writePermission = readPermission.intern();
2081 havePerm = true;
2082 }
2083
2084 if (!havePerm) {
2085 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002086 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2087 + parser.getName() + " at " + mArchiveSourcePath + " "
2088 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002089 XmlUtils.skipCurrentTag(parser);
2090 continue;
2091 }
2092 outError[0] = "No readPermission or writePermssion for <path-permission>";
2093 return false;
2094 }
2095
2096 String path = sa.getNonResourceString(
2097 com.android.internal.R.styleable.AndroidManifestPathPermission_path);
2098 if (path != null) {
2099 pa = new PathPermission(path,
2100 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2101 }
2102
2103 path = sa.getNonResourceString(
2104 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix);
2105 if (path != null) {
2106 pa = new PathPermission(path,
2107 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2108 }
2109
2110 path = sa.getNonResourceString(
2111 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern);
2112 if (path != null) {
2113 pa = new PathPermission(path,
2114 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2115 }
2116
2117 sa.recycle();
2118
2119 if (pa != null) {
2120 if (outInfo.info.pathPermissions == null) {
2121 outInfo.info.pathPermissions = new PathPermission[1];
2122 outInfo.info.pathPermissions[0] = pa;
2123 } else {
2124 final int N = outInfo.info.pathPermissions.length;
2125 PathPermission[] newp = new PathPermission[N+1];
2126 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2127 newp[N] = pa;
2128 outInfo.info.pathPermissions = newp;
2129 }
2130 } else {
2131 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002132 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2133 + parser.getName() + " at " + mArchiveSourcePath + " "
2134 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002135 XmlUtils.skipCurrentTag(parser);
2136 continue;
2137 }
2138 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2139 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 }
2141 XmlUtils.skipCurrentTag(parser);
2142
2143 } else {
2144 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002146 + parser.getName() + " at " + mArchiveSourcePath + " "
2147 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 XmlUtils.skipCurrentTag(parser);
2149 continue;
2150 }
2151 outError[0] = "Bad element under <provider>: "
2152 + parser.getName();
2153 return false;
2154 }
2155 }
2156 return true;
2157 }
2158
2159 private Service parseService(Package owner, Resources res,
2160 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2161 throws XmlPullParserException, IOException {
2162 TypedArray sa = res.obtainAttributes(attrs,
2163 com.android.internal.R.styleable.AndroidManifestService);
2164
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002165 if (mParseServiceArgs == null) {
2166 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2167 com.android.internal.R.styleable.AndroidManifestService_name,
2168 com.android.internal.R.styleable.AndroidManifestService_label,
2169 com.android.internal.R.styleable.AndroidManifestService_icon,
2170 mSeparateProcesses,
2171 com.android.internal.R.styleable.AndroidManifestService_process,
2172 com.android.internal.R.styleable.AndroidManifestService_enabled);
2173 mParseServiceArgs.tag = "<service>";
2174 }
2175
2176 mParseServiceArgs.sa = sa;
2177 mParseServiceArgs.flags = flags;
2178
2179 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2180 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 sa.recycle();
2182 return null;
2183 }
2184
2185 final boolean setExported = sa.hasValue(
2186 com.android.internal.R.styleable.AndroidManifestService_exported);
2187 if (setExported) {
2188 s.info.exported = sa.getBoolean(
2189 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2190 }
2191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 String str = sa.getNonResourceString(
2193 com.android.internal.R.styleable.AndroidManifestService_permission);
2194 if (str == null) {
2195 s.info.permission = owner.applicationInfo.permission;
2196 } else {
2197 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2198 }
2199
2200 sa.recycle();
2201
2202 int outerDepth = parser.getDepth();
2203 int type;
2204 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2205 && (type != XmlPullParser.END_TAG
2206 || parser.getDepth() > outerDepth)) {
2207 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2208 continue;
2209 }
2210
2211 if (parser.getName().equals("intent-filter")) {
2212 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2213 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2214 return null;
2215 }
2216
2217 s.intents.add(intent);
2218 } else if (parser.getName().equals("meta-data")) {
2219 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2220 outError)) == null) {
2221 return null;
2222 }
2223 } else {
2224 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002226 + parser.getName() + " at " + mArchiveSourcePath + " "
2227 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 XmlUtils.skipCurrentTag(parser);
2229 continue;
2230 }
2231 outError[0] = "Bad element under <service>: "
2232 + parser.getName();
2233 return null;
2234 }
2235 }
2236
2237 if (!setExported) {
2238 s.info.exported = s.intents.size() > 0;
2239 }
2240
2241 return s;
2242 }
2243
2244 private boolean parseAllMetaData(Resources res,
2245 XmlPullParser parser, AttributeSet attrs, String tag,
2246 Component outInfo, String[] outError)
2247 throws XmlPullParserException, IOException {
2248 int outerDepth = parser.getDepth();
2249 int type;
2250 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2251 && (type != XmlPullParser.END_TAG
2252 || parser.getDepth() > outerDepth)) {
2253 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2254 continue;
2255 }
2256
2257 if (parser.getName().equals("meta-data")) {
2258 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2259 outInfo.metaData, outError)) == null) {
2260 return false;
2261 }
2262 } else {
2263 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002265 + parser.getName() + " at " + mArchiveSourcePath + " "
2266 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 XmlUtils.skipCurrentTag(parser);
2268 continue;
2269 }
2270 outError[0] = "Bad element under " + tag + ": "
2271 + parser.getName();
2272 return false;
2273 }
2274 }
2275 return true;
2276 }
2277
2278 private Bundle parseMetaData(Resources res,
2279 XmlPullParser parser, AttributeSet attrs,
2280 Bundle data, String[] outError)
2281 throws XmlPullParserException, IOException {
2282
2283 TypedArray sa = res.obtainAttributes(attrs,
2284 com.android.internal.R.styleable.AndroidManifestMetaData);
2285
2286 if (data == null) {
2287 data = new Bundle();
2288 }
2289
2290 String name = sa.getNonResourceString(
2291 com.android.internal.R.styleable.AndroidManifestMetaData_name);
2292 if (name == null) {
2293 outError[0] = "<meta-data> requires an android:name attribute";
2294 sa.recycle();
2295 return null;
2296 }
2297
Dianne Hackborn854060af2009-07-09 18:14:31 -07002298 name = name.intern();
2299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 TypedValue v = sa.peekValue(
2301 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2302 if (v != null && v.resourceId != 0) {
2303 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2304 data.putInt(name, v.resourceId);
2305 } else {
2306 v = sa.peekValue(
2307 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2308 //Log.i(TAG, "Meta data " + name + ": " + v);
2309 if (v != null) {
2310 if (v.type == TypedValue.TYPE_STRING) {
2311 CharSequence cs = v.coerceToString();
Dianne Hackborn854060af2009-07-09 18:14:31 -07002312 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2314 data.putBoolean(name, v.data != 0);
2315 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2316 && v.type <= TypedValue.TYPE_LAST_INT) {
2317 data.putInt(name, v.data);
2318 } else if (v.type == TypedValue.TYPE_FLOAT) {
2319 data.putFloat(name, v.getFloat());
2320 } else {
2321 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002322 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2323 + parser.getName() + " at " + mArchiveSourcePath + " "
2324 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 } else {
2326 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2327 data = null;
2328 }
2329 }
2330 } else {
2331 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2332 data = null;
2333 }
2334 }
2335
2336 sa.recycle();
2337
2338 XmlUtils.skipCurrentTag(parser);
2339
2340 return data;
2341 }
2342
2343 private static final String ANDROID_RESOURCES
2344 = "http://schemas.android.com/apk/res/android";
2345
2346 private boolean parseIntent(Resources res,
2347 XmlPullParser parser, AttributeSet attrs, int flags,
2348 IntentInfo outInfo, String[] outError, boolean isActivity)
2349 throws XmlPullParserException, IOException {
2350
2351 TypedArray sa = res.obtainAttributes(attrs,
2352 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2353
2354 int priority = sa.getInt(
2355 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2356 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2357 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002358 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 + parser.getPositionDescription());
2360 priority = 0;
2361 }
2362 outInfo.setPriority(priority);
2363
2364 TypedValue v = sa.peekValue(
2365 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2366 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2367 outInfo.nonLocalizedLabel = v.coerceToString();
2368 }
2369
2370 outInfo.icon = sa.getResourceId(
2371 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
2372
2373 sa.recycle();
2374
2375 int outerDepth = parser.getDepth();
2376 int type;
2377 while ((type=parser.next()) != parser.END_DOCUMENT
2378 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2379 if (type == parser.END_TAG || type == parser.TEXT) {
2380 continue;
2381 }
2382
2383 String nodeName = parser.getName();
2384 if (nodeName.equals("action")) {
2385 String value = attrs.getAttributeValue(
2386 ANDROID_RESOURCES, "name");
2387 if (value == null || value == "") {
2388 outError[0] = "No value supplied for <android:name>";
2389 return false;
2390 }
2391 XmlUtils.skipCurrentTag(parser);
2392
2393 outInfo.addAction(value);
2394 } else if (nodeName.equals("category")) {
2395 String value = attrs.getAttributeValue(
2396 ANDROID_RESOURCES, "name");
2397 if (value == null || value == "") {
2398 outError[0] = "No value supplied for <android:name>";
2399 return false;
2400 }
2401 XmlUtils.skipCurrentTag(parser);
2402
2403 outInfo.addCategory(value);
2404
2405 } else if (nodeName.equals("data")) {
2406 sa = res.obtainAttributes(attrs,
2407 com.android.internal.R.styleable.AndroidManifestData);
2408
2409 String str = sa.getNonResourceString(
2410 com.android.internal.R.styleable.AndroidManifestData_mimeType);
2411 if (str != null) {
2412 try {
2413 outInfo.addDataType(str);
2414 } catch (IntentFilter.MalformedMimeTypeException e) {
2415 outError[0] = e.toString();
2416 sa.recycle();
2417 return false;
2418 }
2419 }
2420
2421 str = sa.getNonResourceString(
2422 com.android.internal.R.styleable.AndroidManifestData_scheme);
2423 if (str != null) {
2424 outInfo.addDataScheme(str);
2425 }
2426
2427 String host = sa.getNonResourceString(
2428 com.android.internal.R.styleable.AndroidManifestData_host);
2429 String port = sa.getNonResourceString(
2430 com.android.internal.R.styleable.AndroidManifestData_port);
2431 if (host != null) {
2432 outInfo.addDataAuthority(host, port);
2433 }
2434
2435 str = sa.getNonResourceString(
2436 com.android.internal.R.styleable.AndroidManifestData_path);
2437 if (str != null) {
2438 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2439 }
2440
2441 str = sa.getNonResourceString(
2442 com.android.internal.R.styleable.AndroidManifestData_pathPrefix);
2443 if (str != null) {
2444 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2445 }
2446
2447 str = sa.getNonResourceString(
2448 com.android.internal.R.styleable.AndroidManifestData_pathPattern);
2449 if (str != null) {
2450 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2451 }
2452
2453 sa.recycle();
2454 XmlUtils.skipCurrentTag(parser);
2455 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002456 Log.w(TAG, "Unknown element under <intent-filter>: "
2457 + parser.getName() + " at " + mArchiveSourcePath + " "
2458 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 XmlUtils.skipCurrentTag(parser);
2460 } else {
2461 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2462 return false;
2463 }
2464 }
2465
2466 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2467 if (false) {
2468 String cats = "";
2469 Iterator<String> it = outInfo.categoriesIterator();
2470 while (it != null && it.hasNext()) {
2471 cats += " " + it.next();
2472 }
2473 System.out.println("Intent d=" +
2474 outInfo.hasDefault + ", cat=" + cats);
2475 }
2476
2477 return true;
2478 }
2479
2480 public final static class Package {
2481 public final String packageName;
2482
2483 // For now we only support one application per package.
2484 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2485
2486 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2487 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2488 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2489 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2490 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2491 public final ArrayList<Service> services = new ArrayList<Service>(0);
2492 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2493
2494 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2495
Dianne Hackborn854060af2009-07-09 18:14:31 -07002496 public ArrayList<String> protectedBroadcasts;
2497
Dianne Hackborn49237342009-08-27 20:08:01 -07002498 public ArrayList<String> usesLibraries = null;
2499 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 public String[] usesLibraryFiles = null;
2501
2502 // We store the application meta-data independently to avoid multiple unwanted references
2503 public Bundle mAppMetaData = null;
2504
2505 // If this is a 3rd party app, this is the path of the zip file.
2506 public String mPath;
2507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 // The version code declared for this package.
2509 public int mVersionCode;
2510
2511 // The version name declared for this package.
2512 public String mVersionName;
2513
2514 // The shared user id that this package wants to use.
2515 public String mSharedUserId;
2516
2517 // The shared user label that this package wants to use.
2518 public int mSharedUserLabel;
2519
2520 // Signatures that were read from the package.
2521 public Signature mSignatures[];
2522
2523 // For use by package manager service for quick lookup of
2524 // preferred up order.
2525 public int mPreferredOrder = 0;
2526
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002527 // For use by package manager service to keep track of which apps
2528 // have been installed with forward locking.
2529 public boolean mForwardLocked;
2530
2531 // For use by the package manager to keep track of the path to the
2532 // file an app came from.
2533 public String mScanPath;
2534
2535 // For use by package manager to keep track of where it has done dexopt.
2536 public boolean mDidDexOpt;
2537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 // Additional data supplied by callers.
2539 public Object mExtras;
2540
2541 /*
2542 * Applications hardware preferences
2543 */
2544 public final ArrayList<ConfigurationInfo> configPreferences =
2545 new ArrayList<ConfigurationInfo>();
2546
Dianne Hackborn49237342009-08-27 20:08:01 -07002547 /*
2548 * Applications requested features
2549 */
2550 public ArrayList<FeatureInfo> reqFeatures = null;
2551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 public Package(String _name) {
2553 packageName = _name;
2554 applicationInfo.packageName = _name;
2555 applicationInfo.uid = -1;
2556 }
2557
2558 public String toString() {
2559 return "Package{"
2560 + Integer.toHexString(System.identityHashCode(this))
2561 + " " + packageName + "}";
2562 }
2563 }
2564
2565 public static class Component<II extends IntentInfo> {
2566 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002567 public final ArrayList<II> intents;
2568 public final ComponentName component;
2569 public final String componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 public Bundle metaData;
2571
2572 public Component(Package _owner) {
2573 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002574 intents = null;
2575 component = null;
2576 componentShortName = null;
2577 }
2578
2579 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2580 owner = args.owner;
2581 intents = new ArrayList<II>(0);
2582 String name = args.sa.getNonResourceString(args.nameRes);
2583 if (name == null) {
2584 component = null;
2585 componentShortName = null;
2586 args.outError[0] = args.tag + " does not specify android:name";
2587 return;
2588 }
2589
2590 outInfo.name
2591 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2592 if (outInfo.name == null) {
2593 component = null;
2594 componentShortName = null;
2595 args.outError[0] = args.tag + " does not have valid android:name";
2596 return;
2597 }
2598
2599 component = new ComponentName(owner.applicationInfo.packageName,
2600 outInfo.name);
2601 componentShortName = component.flattenToShortString();
2602
2603 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2604 if (iconVal != 0) {
2605 outInfo.icon = iconVal;
2606 outInfo.nonLocalizedLabel = null;
2607 }
2608
2609 TypedValue v = args.sa.peekValue(args.labelRes);
2610 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2611 outInfo.nonLocalizedLabel = v.coerceToString();
2612 }
2613
2614 outInfo.packageName = owner.packageName;
2615 }
2616
2617 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2618 this(args, (PackageItemInfo)outInfo);
2619 if (args.outError[0] != null) {
2620 return;
2621 }
2622
2623 if (args.processRes != 0) {
2624 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
2625 owner.applicationInfo.processName, args.sa.getNonResourceString(args.processRes),
2626 args.flags, args.sepProcesses, args.outError);
2627 }
2628 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 }
2630
2631 public Component(Component<II> clone) {
2632 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002633 intents = clone.intents;
2634 component = clone.component;
2635 componentShortName = clone.componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 metaData = clone.metaData;
2637 }
2638 }
2639
2640 public final static class Permission extends Component<IntentInfo> {
2641 public final PermissionInfo info;
2642 public boolean tree;
2643 public PermissionGroup group;
2644
2645 public Permission(Package _owner) {
2646 super(_owner);
2647 info = new PermissionInfo();
2648 }
2649
2650 public Permission(Package _owner, PermissionInfo _info) {
2651 super(_owner);
2652 info = _info;
2653 }
2654
2655 public String toString() {
2656 return "Permission{"
2657 + Integer.toHexString(System.identityHashCode(this))
2658 + " " + info.name + "}";
2659 }
2660 }
2661
2662 public final static class PermissionGroup extends Component<IntentInfo> {
2663 public final PermissionGroupInfo info;
2664
2665 public PermissionGroup(Package _owner) {
2666 super(_owner);
2667 info = new PermissionGroupInfo();
2668 }
2669
2670 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2671 super(_owner);
2672 info = _info;
2673 }
2674
2675 public String toString() {
2676 return "PermissionGroup{"
2677 + Integer.toHexString(System.identityHashCode(this))
2678 + " " + info.name + "}";
2679 }
2680 }
2681
2682 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
2683 if ((flags & PackageManager.GET_META_DATA) != 0
2684 && (metaData != null || p.mAppMetaData != null)) {
2685 return true;
2686 }
2687 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
2688 && p.usesLibraryFiles != null) {
2689 return true;
2690 }
2691 return false;
2692 }
2693
2694 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
2695 if (p == null) return null;
2696 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002697 // CompatibilityMode is global state. It's safe to modify the instance
2698 // of the package.
2699 if (!sCompatibilityModeEnabled) {
2700 p.applicationInfo.disableCompatibilityMode();
2701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 return p.applicationInfo;
2703 }
2704
2705 // Make shallow copy so we can store the metadata/libraries safely
2706 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
2707 if ((flags & PackageManager.GET_META_DATA) != 0) {
2708 ai.metaData = p.mAppMetaData;
2709 }
2710 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
2711 ai.sharedLibraryFiles = p.usesLibraryFiles;
2712 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002713 if (!sCompatibilityModeEnabled) {
2714 ai.disableCompatibilityMode();
2715 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 return ai;
2717 }
2718
2719 public static final PermissionInfo generatePermissionInfo(
2720 Permission p, int flags) {
2721 if (p == null) return null;
2722 if ((flags&PackageManager.GET_META_DATA) == 0) {
2723 return p.info;
2724 }
2725 PermissionInfo pi = new PermissionInfo(p.info);
2726 pi.metaData = p.metaData;
2727 return pi;
2728 }
2729
2730 public static final PermissionGroupInfo generatePermissionGroupInfo(
2731 PermissionGroup pg, int flags) {
2732 if (pg == null) return null;
2733 if ((flags&PackageManager.GET_META_DATA) == 0) {
2734 return pg.info;
2735 }
2736 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
2737 pgi.metaData = pg.metaData;
2738 return pgi;
2739 }
2740
2741 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002742 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002744 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
2745 super(args, _info);
2746 info = _info;
2747 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 public String toString() {
2751 return "Activity{"
2752 + Integer.toHexString(System.identityHashCode(this))
2753 + " " + component.flattenToString() + "}";
2754 }
2755 }
2756
2757 public static final ActivityInfo generateActivityInfo(Activity a,
2758 int flags) {
2759 if (a == null) return null;
2760 if (!copyNeeded(flags, a.owner, a.metaData)) {
2761 return a.info;
2762 }
2763 // Make shallow copies so we can store the metadata safely
2764 ActivityInfo ai = new ActivityInfo(a.info);
2765 ai.metaData = a.metaData;
2766 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
2767 return ai;
2768 }
2769
2770 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002771 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002773 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
2774 super(args, _info);
2775 info = _info;
2776 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 public String toString() {
2780 return "Service{"
2781 + Integer.toHexString(System.identityHashCode(this))
2782 + " " + component.flattenToString() + "}";
2783 }
2784 }
2785
2786 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
2787 if (s == null) return null;
2788 if (!copyNeeded(flags, s.owner, s.metaData)) {
2789 return s.info;
2790 }
2791 // Make shallow copies so we can store the metadata safely
2792 ServiceInfo si = new ServiceInfo(s.info);
2793 si.metaData = s.metaData;
2794 si.applicationInfo = generateApplicationInfo(s.owner, flags);
2795 return si;
2796 }
2797
2798 public final static class Provider extends Component {
2799 public final ProviderInfo info;
2800 public boolean syncable;
2801
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002802 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
2803 super(args, _info);
2804 info = _info;
2805 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 syncable = false;
2807 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 public Provider(Provider existingProvider) {
2810 super(existingProvider);
2811 this.info = existingProvider.info;
2812 this.syncable = existingProvider.syncable;
2813 }
2814
2815 public String toString() {
2816 return "Provider{"
2817 + Integer.toHexString(System.identityHashCode(this))
2818 + " " + info.name + "}";
2819 }
2820 }
2821
2822 public static final ProviderInfo generateProviderInfo(Provider p,
2823 int flags) {
2824 if (p == null) return null;
2825 if (!copyNeeded(flags, p.owner, p.metaData)
2826 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
2827 || p.info.uriPermissionPatterns == null)) {
2828 return p.info;
2829 }
2830 // Make shallow copies so we can store the metadata safely
2831 ProviderInfo pi = new ProviderInfo(p.info);
2832 pi.metaData = p.metaData;
2833 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
2834 pi.uriPermissionPatterns = null;
2835 }
2836 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
2837 return pi;
2838 }
2839
2840 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002841 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002843 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
2844 super(args, _info);
2845 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 public String toString() {
2849 return "Instrumentation{"
2850 + Integer.toHexString(System.identityHashCode(this))
2851 + " " + component.flattenToString() + "}";
2852 }
2853 }
2854
2855 public static final InstrumentationInfo generateInstrumentationInfo(
2856 Instrumentation i, int flags) {
2857 if (i == null) return null;
2858 if ((flags&PackageManager.GET_META_DATA) == 0) {
2859 return i.info;
2860 }
2861 InstrumentationInfo ii = new InstrumentationInfo(i.info);
2862 ii.metaData = i.metaData;
2863 return ii;
2864 }
2865
2866 public static class IntentInfo extends IntentFilter {
2867 public boolean hasDefault;
2868 public int labelRes;
2869 public CharSequence nonLocalizedLabel;
2870 public int icon;
2871 }
2872
2873 public final static class ActivityIntentInfo extends IntentInfo {
2874 public final Activity activity;
2875
2876 public ActivityIntentInfo(Activity _activity) {
2877 activity = _activity;
2878 }
2879
2880 public String toString() {
2881 return "ActivityIntentInfo{"
2882 + Integer.toHexString(System.identityHashCode(this))
2883 + " " + activity.info.name + "}";
2884 }
2885 }
2886
2887 public final static class ServiceIntentInfo extends IntentInfo {
2888 public final Service service;
2889
2890 public ServiceIntentInfo(Service _service) {
2891 service = _service;
2892 }
2893
2894 public String toString() {
2895 return "ServiceIntentInfo{"
2896 + Integer.toHexString(System.identityHashCode(this))
2897 + " " + service.info.name + "}";
2898 }
2899 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002900
2901 /**
2902 * @hide
2903 */
2904 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
2905 sCompatibilityModeEnabled = compatibilityModeEnabled;
2906 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907}