blob: 8a5df324e60deca85a83809e748325dac0c86131 [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
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800330 public final static int PARSE_IS_SYSTEM = 1<<0;
331 public final static int PARSE_CHATTY = 1<<1;
332 public final static int PARSE_MUST_BE_APK = 1<<2;
333 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
334 public final static int PARSE_FORWARD_LOCK = 1<<4;
335 public final static int PARSE_ON_SDCARD = 1<<5;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 public int getParseError() {
338 return mParseError;
339 }
340
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800341 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 DisplayMetrics metrics, int flags) {
343 mParseError = PackageManager.INSTALL_SUCCEEDED;
344
345 mArchiveSourcePath = sourceFile.getPath();
346 if (!sourceFile.isFile()) {
347 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
348 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
349 return null;
350 }
351 if (!isPackageFilename(sourceFile.getName())
352 && (flags&PARSE_MUST_BE_APK) != 0) {
353 if ((flags&PARSE_IS_SYSTEM) == 0) {
354 // We expect to have non-.apk files in the system dir,
355 // so don't warn about them.
356 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
357 }
358 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
359 return null;
360 }
361
362 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
363 TAG, "Scanning package: " + mArchiveSourcePath);
364
365 XmlResourceParser parser = null;
366 AssetManager assmgr = null;
367 boolean assetError = true;
368 try {
369 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700370 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
371 if(cookie != 0) {
372 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 assetError = false;
374 } else {
375 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
376 }
377 } catch (Exception e) {
378 Log.w(TAG, "Unable to read AndroidManifest.xml of "
379 + mArchiveSourcePath, e);
380 }
381 if(assetError) {
382 if (assmgr != null) assmgr.close();
383 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
384 return null;
385 }
386 String[] errorText = new String[1];
387 Package pkg = null;
388 Exception errorException = null;
389 try {
390 // XXXX todo: need to figure out correct configuration.
391 Resources res = new Resources(assmgr, metrics, null);
392 pkg = parsePackage(res, parser, flags, errorText);
393 } catch (Exception e) {
394 errorException = e;
395 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
396 }
397
398
399 if (pkg == null) {
400 if (errorException != null) {
401 Log.w(TAG, mArchiveSourcePath, errorException);
402 } else {
403 Log.w(TAG, mArchiveSourcePath + " (at "
404 + parser.getPositionDescription()
405 + "): " + errorText[0]);
406 }
407 parser.close();
408 assmgr.close();
409 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
410 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
411 }
412 return null;
413 }
414
415 parser.close();
416 assmgr.close();
417
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800418 // Set code and resource paths
419 pkg.mPath = destCodePath;
420 pkg.mScanPath = mArchiveSourcePath;
421 //pkg.applicationInfo.sourceDir = destCodePath;
422 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 pkg.mSignatures = null;
424
425 return pkg;
426 }
427
428 public boolean collectCertificates(Package pkg, int flags) {
429 pkg.mSignatures = null;
430
431 WeakReference<byte[]> readBufferRef;
432 byte[] readBuffer = null;
433 synchronized (mSync) {
434 readBufferRef = mReadBuffer;
435 if (readBufferRef != null) {
436 mReadBuffer = null;
437 readBuffer = readBufferRef.get();
438 }
439 if (readBuffer == null) {
440 readBuffer = new byte[8192];
441 readBufferRef = new WeakReference<byte[]>(readBuffer);
442 }
443 }
444
445 try {
446 JarFile jarFile = new JarFile(mArchiveSourcePath);
447
448 Certificate[] certs = null;
449
450 if ((flags&PARSE_IS_SYSTEM) != 0) {
451 // If this package comes from the system image, then we
452 // can trust it... we'll just use the AndroidManifest.xml
453 // to retrieve its signatures, not validating all of the
454 // files.
455 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
456 certs = loadCertificates(jarFile, jarEntry, readBuffer);
457 if (certs == null) {
458 Log.e(TAG, "Package " + pkg.packageName
459 + " has no certificates at entry "
460 + jarEntry.getName() + "; ignoring!");
461 jarFile.close();
462 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
463 return false;
464 }
465 if (false) {
466 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
467 + " certs=" + (certs != null ? certs.length : 0));
468 if (certs != null) {
469 final int N = certs.length;
470 for (int i=0; i<N; i++) {
471 Log.i(TAG, " Public key: "
472 + certs[i].getPublicKey().getEncoded()
473 + " " + certs[i].getPublicKey());
474 }
475 }
476 }
477
478 } else {
479 Enumeration entries = jarFile.entries();
480 while (entries.hasMoreElements()) {
481 JarEntry je = (JarEntry)entries.nextElement();
482 if (je.isDirectory()) continue;
483 if (je.getName().startsWith("META-INF/")) continue;
484 Certificate[] localCerts = loadCertificates(jarFile, je,
485 readBuffer);
486 if (false) {
487 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
488 + ": certs=" + certs + " ("
489 + (certs != null ? certs.length : 0) + ")");
490 }
491 if (localCerts == null) {
492 Log.e(TAG, "Package " + pkg.packageName
493 + " has no certificates at entry "
494 + je.getName() + "; ignoring!");
495 jarFile.close();
496 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
497 return false;
498 } else if (certs == null) {
499 certs = localCerts;
500 } else {
501 // Ensure all certificates match.
502 for (int i=0; i<certs.length; i++) {
503 boolean found = false;
504 for (int j=0; j<localCerts.length; j++) {
505 if (certs[i] != null &&
506 certs[i].equals(localCerts[j])) {
507 found = true;
508 break;
509 }
510 }
511 if (!found || certs.length != localCerts.length) {
512 Log.e(TAG, "Package " + pkg.packageName
513 + " has mismatched certificates at entry "
514 + je.getName() + "; ignoring!");
515 jarFile.close();
516 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
517 return false;
518 }
519 }
520 }
521 }
522 }
523 jarFile.close();
524
525 synchronized (mSync) {
526 mReadBuffer = readBufferRef;
527 }
528
529 if (certs != null && certs.length > 0) {
530 final int N = certs.length;
531 pkg.mSignatures = new Signature[certs.length];
532 for (int i=0; i<N; i++) {
533 pkg.mSignatures[i] = new Signature(
534 certs[i].getEncoded());
535 }
536 } else {
537 Log.e(TAG, "Package " + pkg.packageName
538 + " has no certificates; ignoring!");
539 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
540 return false;
541 }
542 } catch (CertificateEncodingException e) {
543 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
544 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
545 return false;
546 } catch (IOException e) {
547 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
548 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
549 return false;
550 } catch (RuntimeException e) {
551 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
552 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
553 return false;
554 }
555
556 return true;
557 }
558
559 public static String parsePackageName(String packageFilePath, int flags) {
560 XmlResourceParser parser = null;
561 AssetManager assmgr = null;
562 try {
563 assmgr = new AssetManager();
564 int cookie = assmgr.addAssetPath(packageFilePath);
565 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
566 } catch (Exception e) {
567 if (assmgr != null) assmgr.close();
568 Log.w(TAG, "Unable to read AndroidManifest.xml of "
569 + packageFilePath, e);
570 return null;
571 }
572 AttributeSet attrs = parser;
573 String errors[] = new String[1];
574 String packageName = null;
575 try {
576 packageName = parsePackageName(parser, attrs, flags, errors);
577 } catch (IOException e) {
578 Log.w(TAG, packageFilePath, e);
579 } catch (XmlPullParserException e) {
580 Log.w(TAG, packageFilePath, e);
581 } finally {
582 if (parser != null) parser.close();
583 if (assmgr != null) assmgr.close();
584 }
585 if (packageName == null) {
586 Log.e(TAG, "parsePackageName error: " + errors[0]);
587 return null;
588 }
589 return packageName;
590 }
591
592 private static String validateName(String name, boolean requiresSeparator) {
593 final int N = name.length();
594 boolean hasSep = false;
595 boolean front = true;
596 for (int i=0; i<N; i++) {
597 final char c = name.charAt(i);
598 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
599 front = false;
600 continue;
601 }
602 if (!front) {
603 if ((c >= '0' && c <= '9') || c == '_') {
604 continue;
605 }
606 }
607 if (c == '.') {
608 hasSep = true;
609 front = true;
610 continue;
611 }
612 return "bad character '" + c + "'";
613 }
614 return hasSep || !requiresSeparator
615 ? null : "must have at least one '.' separator";
616 }
617
618 private static String parsePackageName(XmlPullParser parser,
619 AttributeSet attrs, int flags, String[] outError)
620 throws IOException, XmlPullParserException {
621
622 int type;
623 while ((type=parser.next()) != parser.START_TAG
624 && type != parser.END_DOCUMENT) {
625 ;
626 }
627
628 if (type != parser.START_TAG) {
629 outError[0] = "No start tag found";
630 return null;
631 }
632 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
633 TAG, "Root element name: '" + parser.getName() + "'");
634 if (!parser.getName().equals("manifest")) {
635 outError[0] = "No <manifest> tag";
636 return null;
637 }
638 String pkgName = attrs.getAttributeValue(null, "package");
639 if (pkgName == null || pkgName.length() == 0) {
640 outError[0] = "<manifest> does not specify package";
641 return null;
642 }
643 String nameError = validateName(pkgName, true);
644 if (nameError != null && !"android".equals(pkgName)) {
645 outError[0] = "<manifest> specifies bad package name \""
646 + pkgName + "\": " + nameError;
647 return null;
648 }
649
650 return pkgName.intern();
651 }
652
653 /**
654 * Temporary.
655 */
656 static public Signature stringToSignature(String str) {
657 final int N = str.length();
658 byte[] sig = new byte[N];
659 for (int i=0; i<N; i++) {
660 sig[i] = (byte)str.charAt(i);
661 }
662 return new Signature(sig);
663 }
664
665 private Package parsePackage(
666 Resources res, XmlResourceParser parser, int flags, String[] outError)
667 throws XmlPullParserException, IOException {
668 AttributeSet attrs = parser;
669
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700670 mParseInstrumentationArgs = null;
671 mParseActivityArgs = null;
672 mParseServiceArgs = null;
673 mParseProviderArgs = null;
674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 String pkgName = parsePackageName(parser, attrs, flags, outError);
676 if (pkgName == null) {
677 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
678 return null;
679 }
680 int type;
681
682 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 TypedArray sa = res.obtainAttributes(attrs,
686 com.android.internal.R.styleable.AndroidManifest);
687 pkg.mVersionCode = sa.getInteger(
688 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
689 pkg.mVersionName = sa.getNonResourceString(
690 com.android.internal.R.styleable.AndroidManifest_versionName);
691 if (pkg.mVersionName != null) {
692 pkg.mVersionName = pkg.mVersionName.intern();
693 }
694 String str = sa.getNonResourceString(
695 com.android.internal.R.styleable.AndroidManifest_sharedUserId);
696 if (str != null) {
697 String nameError = validateName(str, true);
698 if (nameError != null && !"android".equals(pkgName)) {
699 outError[0] = "<manifest> specifies bad sharedUserId name \""
700 + str + "\": " + nameError;
701 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
702 return null;
703 }
704 pkg.mSharedUserId = str.intern();
705 pkg.mSharedUserLabel = sa.getResourceId(
706 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
707 }
708 sa.recycle();
709
Dianne Hackborn723738c2009-06-25 19:48:04 -0700710 // Resource boolean are -1, so 1 means we don't know the value.
711 int supportsSmallScreens = 1;
712 int supportsNormalScreens = 1;
713 int supportsLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700714 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700715 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 int outerDepth = parser.getDepth();
718 while ((type=parser.next()) != parser.END_DOCUMENT
719 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
720 if (type == parser.END_TAG || type == parser.TEXT) {
721 continue;
722 }
723
724 String tagName = parser.getName();
725 if (tagName.equals("application")) {
726 if (foundApp) {
727 if (RIGID_PARSER) {
728 outError[0] = "<manifest> has more than one <application>";
729 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
730 return null;
731 } else {
732 Log.w(TAG, "<manifest> has more than one <application>");
733 XmlUtils.skipCurrentTag(parser);
734 continue;
735 }
736 }
737
738 foundApp = true;
739 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
740 return null;
741 }
742 } else if (tagName.equals("permission-group")) {
743 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
744 return null;
745 }
746 } else if (tagName.equals("permission")) {
747 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
748 return null;
749 }
750 } else if (tagName.equals("permission-tree")) {
751 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
752 return null;
753 }
754 } else if (tagName.equals("uses-permission")) {
755 sa = res.obtainAttributes(attrs,
756 com.android.internal.R.styleable.AndroidManifestUsesPermission);
757
758 String name = sa.getNonResourceString(
759 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
760
761 sa.recycle();
762
763 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700764 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766
767 XmlUtils.skipCurrentTag(parser);
768
769 } else if (tagName.equals("uses-configuration")) {
770 ConfigurationInfo cPref = new ConfigurationInfo();
771 sa = res.obtainAttributes(attrs,
772 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
773 cPref.reqTouchScreen = sa.getInt(
774 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
775 Configuration.TOUCHSCREEN_UNDEFINED);
776 cPref.reqKeyboardType = sa.getInt(
777 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
778 Configuration.KEYBOARD_UNDEFINED);
779 if (sa.getBoolean(
780 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
781 false)) {
782 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
783 }
784 cPref.reqNavigation = sa.getInt(
785 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
786 Configuration.NAVIGATION_UNDEFINED);
787 if (sa.getBoolean(
788 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
789 false)) {
790 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
791 }
792 sa.recycle();
793 pkg.configPreferences.add(cPref);
794
795 XmlUtils.skipCurrentTag(parser);
796
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700797 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700798 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700799 sa = res.obtainAttributes(attrs,
800 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborn49237342009-08-27 20:08:01 -0700801 fi.name = sa.getNonResourceString(
802 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
803 if (fi.name == null) {
804 fi.reqGlEsVersion = sa.getInt(
805 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
806 FeatureInfo.GL_ES_VERSION_UNDEFINED);
807 }
808 if (sa.getBoolean(
809 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
810 true)) {
811 fi.flags |= FeatureInfo.FLAG_REQUIRED;
812 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700813 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700814 if (pkg.reqFeatures == null) {
815 pkg.reqFeatures = new ArrayList<FeatureInfo>();
816 }
817 pkg.reqFeatures.add(fi);
818
819 if (fi.name == null) {
820 ConfigurationInfo cPref = new ConfigurationInfo();
821 cPref.reqGlEsVersion = fi.reqGlEsVersion;
822 pkg.configPreferences.add(cPref);
823 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700824
825 XmlUtils.skipCurrentTag(parser);
826
Dianne Hackborn851a5412009-05-08 12:06:44 -0700827 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700828 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 sa = res.obtainAttributes(attrs,
830 com.android.internal.R.styleable.AndroidManifestUsesSdk);
831
Dianne Hackborn851a5412009-05-08 12:06:44 -0700832 int minVers = 0;
833 String minCode = null;
834 int targetVers = 0;
835 String targetCode = null;
836
837 TypedValue val = sa.peekValue(
838 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
839 if (val != null) {
840 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
841 targetCode = minCode = val.string.toString();
842 } else {
843 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700844 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700845 }
846 }
847
848 val = sa.peekValue(
849 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
850 if (val != null) {
851 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
852 targetCode = minCode = val.string.toString();
853 } else {
854 // If it's not a string, it's an integer.
855 targetVers = val.data;
856 }
857 }
858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 sa.recycle();
860
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700861 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700862 if (!minCode.equals(SDK_CODENAME)) {
863 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700864 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700865 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700866 } else {
867 outError[0] = "Requires development platform " + minCode
868 + " but this is a release platform.";
869 }
870 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
871 return null;
872 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700873 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700874 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700875 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700876 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
877 return null;
878 }
879
Dianne Hackborn851a5412009-05-08 12:06:44 -0700880 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700881 if (!targetCode.equals(SDK_CODENAME)) {
882 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700883 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700884 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700885 } else {
886 outError[0] = "Requires development platform " + targetCode
887 + " but this is a release platform.";
888 }
889 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
890 return null;
891 }
892 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700893 pkg.applicationInfo.targetSdkVersion
894 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
895 } else {
896 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 }
899
900 XmlUtils.skipCurrentTag(parser);
901
Dianne Hackborn723738c2009-06-25 19:48:04 -0700902 } else if (tagName.equals("supports-screens")) {
903 sa = res.obtainAttributes(attrs,
904 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
905
906 // This is a trick to get a boolean and still able to detect
907 // if a value was actually set.
908 supportsSmallScreens = sa.getInteger(
909 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
910 supportsSmallScreens);
911 supportsNormalScreens = sa.getInteger(
912 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
913 supportsNormalScreens);
914 supportsLargeScreens = sa.getInteger(
915 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
916 supportsLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700917 resizeable = sa.getInteger(
918 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
919 supportsLargeScreens);
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700920 anyDensity = sa.getInteger(
921 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
922 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700923
924 sa.recycle();
925
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700926 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -0700927
928 } else if (tagName.equals("protected-broadcast")) {
929 sa = res.obtainAttributes(attrs,
930 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
931
932 String name = sa.getNonResourceString(
933 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
934
935 sa.recycle();
936
937 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
938 if (pkg.protectedBroadcasts == null) {
939 pkg.protectedBroadcasts = new ArrayList<String>();
940 }
941 if (!pkg.protectedBroadcasts.contains(name)) {
942 pkg.protectedBroadcasts.add(name.intern());
943 }
944 }
945
946 XmlUtils.skipCurrentTag(parser);
947
948 } else if (tagName.equals("instrumentation")) {
949 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
950 return null;
951 }
952
953 } else if (tagName.equals("eat-comment")) {
954 // Just skip this tag
955 XmlUtils.skipCurrentTag(parser);
956 continue;
957
958 } else if (RIGID_PARSER) {
959 outError[0] = "Bad element under <manifest>: "
960 + parser.getName();
961 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
962 return null;
963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -0700965 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
966 + " at " + mArchiveSourcePath + " "
967 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 XmlUtils.skipCurrentTag(parser);
969 continue;
970 }
971 }
972
973 if (!foundApp && pkg.instrumentation.size() == 0) {
974 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
975 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
976 }
977
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700978 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700979 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700980 for (int ip=0; ip<NP; ip++) {
981 final PackageParser.NewPermissionInfo npi
982 = PackageParser.NEW_PERMISSIONS[ip];
983 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
984 break;
985 }
986 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700987 if (implicitPerms == null) {
988 implicitPerms = new StringBuilder(128);
989 implicitPerms.append(pkg.packageName);
990 implicitPerms.append(": compat added ");
991 } else {
992 implicitPerms.append(' ');
993 }
994 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700995 pkg.requestedPermissions.add(npi.name);
996 }
Dianne Hackborn851a5412009-05-08 12:06:44 -0700997 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700998 if (implicitPerms != null) {
999 Log.i(TAG, implicitPerms.toString());
1000 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001001
Dianne Hackborn723738c2009-06-25 19:48:04 -07001002 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1003 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001004 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001005 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1006 }
1007 if (supportsNormalScreens != 0) {
1008 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1009 }
1010 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1011 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001012 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001013 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1014 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001015 if (resizeable < 0 || (resizeable > 0
1016 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001017 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001018 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1019 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001020 if (anyDensity < 0 || (anyDensity > 0
1021 && pkg.applicationInfo.targetSdkVersion
1022 >= android.os.Build.VERSION_CODES.DONUT)) {
1023 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001024 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 return pkg;
1027 }
1028
1029 private static String buildClassName(String pkg, CharSequence clsSeq,
1030 String[] outError) {
1031 if (clsSeq == null || clsSeq.length() <= 0) {
1032 outError[0] = "Empty class name in package " + pkg;
1033 return null;
1034 }
1035 String cls = clsSeq.toString();
1036 char c = cls.charAt(0);
1037 if (c == '.') {
1038 return (pkg + cls).intern();
1039 }
1040 if (cls.indexOf('.') < 0) {
1041 StringBuilder b = new StringBuilder(pkg);
1042 b.append('.');
1043 b.append(cls);
1044 return b.toString().intern();
1045 }
1046 if (c >= 'a' && c <= 'z') {
1047 return cls.intern();
1048 }
1049 outError[0] = "Bad class name " + cls + " in package " + pkg;
1050 return null;
1051 }
1052
1053 private static String buildCompoundName(String pkg,
1054 CharSequence procSeq, String type, String[] outError) {
1055 String proc = procSeq.toString();
1056 char c = proc.charAt(0);
1057 if (pkg != null && c == ':') {
1058 if (proc.length() < 2) {
1059 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1060 + ": must be at least two characters";
1061 return null;
1062 }
1063 String subName = proc.substring(1);
1064 String nameError = validateName(subName, false);
1065 if (nameError != null) {
1066 outError[0] = "Invalid " + type + " name " + proc + " in package "
1067 + pkg + ": " + nameError;
1068 return null;
1069 }
1070 return (pkg + proc).intern();
1071 }
1072 String nameError = validateName(proc, true);
1073 if (nameError != null && !"system".equals(proc)) {
1074 outError[0] = "Invalid " + type + " name " + proc + " in package "
1075 + pkg + ": " + nameError;
1076 return null;
1077 }
1078 return proc.intern();
1079 }
1080
1081 private static String buildProcessName(String pkg, String defProc,
1082 CharSequence procSeq, int flags, String[] separateProcesses,
1083 String[] outError) {
1084 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1085 return defProc != null ? defProc : pkg;
1086 }
1087 if (separateProcesses != null) {
1088 for (int i=separateProcesses.length-1; i>=0; i--) {
1089 String sp = separateProcesses[i];
1090 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1091 return pkg;
1092 }
1093 }
1094 }
1095 if (procSeq == null || procSeq.length() <= 0) {
1096 return defProc;
1097 }
1098 return buildCompoundName(pkg, procSeq, "package", outError);
1099 }
1100
1101 private static String buildTaskAffinityName(String pkg, String defProc,
1102 CharSequence procSeq, String[] outError) {
1103 if (procSeq == null) {
1104 return defProc;
1105 }
1106 if (procSeq.length() <= 0) {
1107 return null;
1108 }
1109 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1110 }
1111
1112 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1113 XmlPullParser parser, AttributeSet attrs, String[] outError)
1114 throws XmlPullParserException, IOException {
1115 PermissionGroup perm = new PermissionGroup(owner);
1116
1117 TypedArray sa = res.obtainAttributes(attrs,
1118 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1119
1120 if (!parsePackageItemInfo(owner, perm.info, outError,
1121 "<permission-group>", sa,
1122 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1123 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
1124 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon)) {
1125 sa.recycle();
1126 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1127 return null;
1128 }
1129
1130 perm.info.descriptionRes = sa.getResourceId(
1131 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1132 0);
1133
1134 sa.recycle();
1135
1136 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1137 outError)) {
1138 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1139 return null;
1140 }
1141
1142 owner.permissionGroups.add(perm);
1143
1144 return perm;
1145 }
1146
1147 private Permission parsePermission(Package owner, Resources res,
1148 XmlPullParser parser, AttributeSet attrs, String[] outError)
1149 throws XmlPullParserException, IOException {
1150 Permission perm = new Permission(owner);
1151
1152 TypedArray sa = res.obtainAttributes(attrs,
1153 com.android.internal.R.styleable.AndroidManifestPermission);
1154
1155 if (!parsePackageItemInfo(owner, perm.info, outError,
1156 "<permission>", sa,
1157 com.android.internal.R.styleable.AndroidManifestPermission_name,
1158 com.android.internal.R.styleable.AndroidManifestPermission_label,
1159 com.android.internal.R.styleable.AndroidManifestPermission_icon)) {
1160 sa.recycle();
1161 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1162 return null;
1163 }
1164
1165 perm.info.group = sa.getNonResourceString(
1166 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1167 if (perm.info.group != null) {
1168 perm.info.group = perm.info.group.intern();
1169 }
1170
1171 perm.info.descriptionRes = sa.getResourceId(
1172 com.android.internal.R.styleable.AndroidManifestPermission_description,
1173 0);
1174
1175 perm.info.protectionLevel = sa.getInt(
1176 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1177 PermissionInfo.PROTECTION_NORMAL);
1178
1179 sa.recycle();
1180
1181 if (perm.info.protectionLevel == -1) {
1182 outError[0] = "<permission> does not specify protectionLevel";
1183 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1184 return null;
1185 }
1186
1187 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1188 outError)) {
1189 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1190 return null;
1191 }
1192
1193 owner.permissions.add(perm);
1194
1195 return perm;
1196 }
1197
1198 private Permission parsePermissionTree(Package owner, Resources res,
1199 XmlPullParser parser, AttributeSet attrs, String[] outError)
1200 throws XmlPullParserException, IOException {
1201 Permission perm = new Permission(owner);
1202
1203 TypedArray sa = res.obtainAttributes(attrs,
1204 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1205
1206 if (!parsePackageItemInfo(owner, perm.info, outError,
1207 "<permission-tree>", sa,
1208 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1209 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
1210 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon)) {
1211 sa.recycle();
1212 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1213 return null;
1214 }
1215
1216 sa.recycle();
1217
1218 int index = perm.info.name.indexOf('.');
1219 if (index > 0) {
1220 index = perm.info.name.indexOf('.', index+1);
1221 }
1222 if (index < 0) {
1223 outError[0] = "<permission-tree> name has less than three segments: "
1224 + perm.info.name;
1225 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1226 return null;
1227 }
1228
1229 perm.info.descriptionRes = 0;
1230 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1231 perm.tree = true;
1232
1233 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1234 outError)) {
1235 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1236 return null;
1237 }
1238
1239 owner.permissions.add(perm);
1240
1241 return perm;
1242 }
1243
1244 private Instrumentation parseInstrumentation(Package owner, Resources res,
1245 XmlPullParser parser, AttributeSet attrs, String[] outError)
1246 throws XmlPullParserException, IOException {
1247 TypedArray sa = res.obtainAttributes(attrs,
1248 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1249
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001250 if (mParseInstrumentationArgs == null) {
1251 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1252 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1253 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
1254 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon);
1255 mParseInstrumentationArgs.tag = "<instrumentation>";
1256 }
1257
1258 mParseInstrumentationArgs.sa = sa;
1259
1260 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1261 new InstrumentationInfo());
1262 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 sa.recycle();
1264 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1265 return null;
1266 }
1267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 String str;
1269 str = sa.getNonResourceString(
1270 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1271 a.info.targetPackage = str != null ? str.intern() : null;
1272
1273 a.info.handleProfiling = sa.getBoolean(
1274 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1275 false);
1276
1277 a.info.functionalTest = sa.getBoolean(
1278 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1279 false);
1280
1281 sa.recycle();
1282
1283 if (a.info.targetPackage == null) {
1284 outError[0] = "<instrumentation> does not specify targetPackage";
1285 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1286 return null;
1287 }
1288
1289 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1290 outError)) {
1291 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1292 return null;
1293 }
1294
1295 owner.instrumentation.add(a);
1296
1297 return a;
1298 }
1299
1300 private boolean parseApplication(Package owner, Resources res,
1301 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1302 throws XmlPullParserException, IOException {
1303 final ApplicationInfo ai = owner.applicationInfo;
1304 final String pkgName = owner.applicationInfo.packageName;
1305
1306 TypedArray sa = res.obtainAttributes(attrs,
1307 com.android.internal.R.styleable.AndroidManifestApplication);
1308
1309 String name = sa.getNonResourceString(
1310 com.android.internal.R.styleable.AndroidManifestApplication_name);
1311 if (name != null) {
1312 ai.className = buildClassName(pkgName, name, outError);
1313 if (ai.className == null) {
1314 sa.recycle();
1315 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1316 return false;
1317 }
1318 }
1319
1320 String manageSpaceActivity = sa.getNonResourceString(
1321 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity);
1322 if (manageSpaceActivity != null) {
1323 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1324 outError);
1325 }
1326
Christopher Tate181fafa2009-05-14 11:12:14 -07001327 boolean allowBackup = sa.getBoolean(
1328 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1329 if (allowBackup) {
1330 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001331
1332 // backupAgent, killAfterRestore, and restoreNeedsApplication are only relevant
1333 // if backup is possible for the given application.
Christopher Tate181fafa2009-05-14 11:12:14 -07001334 String backupAgent = sa.getNonResourceString(
1335 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent);
1336 if (backupAgent != null) {
1337 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001338 if (false) {
1339 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1340 + " from " + pkgName + "+" + backupAgent);
1341 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001342
1343 if (sa.getBoolean(
1344 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1345 true)) {
1346 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1347 }
1348 if (sa.getBoolean(
1349 com.android.internal.R.styleable.AndroidManifestApplication_restoreNeedsApplication,
1350 false)) {
1351 ai.flags |= ApplicationInfo.FLAG_RESTORE_NEEDS_APPLICATION;
1352 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001353 }
1354 }
1355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 TypedValue v = sa.peekValue(
1357 com.android.internal.R.styleable.AndroidManifestApplication_label);
1358 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1359 ai.nonLocalizedLabel = v.coerceToString();
1360 }
1361
1362 ai.icon = sa.getResourceId(
1363 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1364 ai.theme = sa.getResourceId(
1365 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1366 ai.descriptionRes = sa.getResourceId(
1367 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1368
1369 if ((flags&PARSE_IS_SYSTEM) != 0) {
1370 if (sa.getBoolean(
1371 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1372 false)) {
1373 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1374 }
1375 }
1376
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001377 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1378 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1379 }
1380
1381 if ((flags & PARSE_ON_SDCARD) != 0) {
1382 ai.flags |= ApplicationInfo.FLAG_ON_SDCARD;
1383 }
1384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 if (sa.getBoolean(
1386 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1387 false)) {
1388 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1389 }
1390
1391 if (sa.getBoolean(
1392 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1393 true)) {
1394 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1395 }
1396
1397 if (sa.getBoolean(
1398 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1399 false)) {
1400 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1401 }
1402
1403 if (sa.getBoolean(
1404 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1405 true)) {
1406 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1407 }
1408
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001409 if (sa.getBoolean(
1410 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001411 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001412 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1413 }
1414
Oscar Montemayor1874aa42009-11-10 18:35:33 -08001415 if (sa.getBoolean(
1416 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt,
1417 false)) {
1418 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT;
1419 }
1420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 String str;
1422 str = sa.getNonResourceString(
1423 com.android.internal.R.styleable.AndroidManifestApplication_permission);
1424 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1425
1426 str = sa.getNonResourceString(
1427 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1428 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1429 str, outError);
1430
1431 if (outError[0] == null) {
1432 ai.processName = buildProcessName(ai.packageName, null, sa.getNonResourceString(
1433 com.android.internal.R.styleable.AndroidManifestApplication_process),
1434 flags, mSeparateProcesses, outError);
1435
1436 ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
1437 }
1438
1439 sa.recycle();
1440
1441 if (outError[0] != null) {
1442 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1443 return false;
1444 }
1445
1446 final int innerDepth = parser.getDepth();
1447
1448 int type;
1449 while ((type=parser.next()) != parser.END_DOCUMENT
1450 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1451 if (type == parser.END_TAG || type == parser.TEXT) {
1452 continue;
1453 }
1454
1455 String tagName = parser.getName();
1456 if (tagName.equals("activity")) {
1457 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1458 if (a == null) {
1459 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1460 return false;
1461 }
1462
1463 owner.activities.add(a);
1464
1465 } else if (tagName.equals("receiver")) {
1466 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1467 if (a == null) {
1468 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1469 return false;
1470 }
1471
1472 owner.receivers.add(a);
1473
1474 } else if (tagName.equals("service")) {
1475 Service s = parseService(owner, res, parser, attrs, flags, outError);
1476 if (s == null) {
1477 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1478 return false;
1479 }
1480
1481 owner.services.add(s);
1482
1483 } else if (tagName.equals("provider")) {
1484 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1485 if (p == null) {
1486 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1487 return false;
1488 }
1489
1490 owner.providers.add(p);
1491
1492 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001493 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 if (a == null) {
1495 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1496 return false;
1497 }
1498
1499 owner.activities.add(a);
1500
1501 } else if (parser.getName().equals("meta-data")) {
1502 // note: application meta-data is stored off to the side, so it can
1503 // remain null in the primary copy (we like to avoid extra copies because
1504 // it can be large)
1505 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1506 outError)) == null) {
1507 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1508 return false;
1509 }
1510
1511 } else if (tagName.equals("uses-library")) {
1512 sa = res.obtainAttributes(attrs,
1513 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1514
1515 String lname = sa.getNonResourceString(
1516 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001517 boolean req = sa.getBoolean(
1518 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1519 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520
1521 sa.recycle();
1522
Dianne Hackborn49237342009-08-27 20:08:01 -07001523 if (lname != null) {
1524 if (req) {
1525 if (owner.usesLibraries == null) {
1526 owner.usesLibraries = new ArrayList<String>();
1527 }
1528 if (!owner.usesLibraries.contains(lname)) {
1529 owner.usesLibraries.add(lname.intern());
1530 }
1531 } else {
1532 if (owner.usesOptionalLibraries == null) {
1533 owner.usesOptionalLibraries = new ArrayList<String>();
1534 }
1535 if (!owner.usesOptionalLibraries.contains(lname)) {
1536 owner.usesOptionalLibraries.add(lname.intern());
1537 }
1538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 }
1540
1541 XmlUtils.skipCurrentTag(parser);
1542
1543 } else {
1544 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001545 Log.w(TAG, "Unknown element under <application>: " + tagName
1546 + " at " + mArchiveSourcePath + " "
1547 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 XmlUtils.skipCurrentTag(parser);
1549 continue;
1550 } else {
1551 outError[0] = "Bad element under <application>: " + tagName;
1552 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1553 return false;
1554 }
1555 }
1556 }
1557
1558 return true;
1559 }
1560
1561 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1562 String[] outError, String tag, TypedArray sa,
1563 int nameRes, int labelRes, int iconRes) {
1564 String name = sa.getNonResourceString(nameRes);
1565 if (name == null) {
1566 outError[0] = tag + " does not specify android:name";
1567 return false;
1568 }
1569
1570 outInfo.name
1571 = buildClassName(owner.applicationInfo.packageName, name, outError);
1572 if (outInfo.name == null) {
1573 return false;
1574 }
1575
1576 int iconVal = sa.getResourceId(iconRes, 0);
1577 if (iconVal != 0) {
1578 outInfo.icon = iconVal;
1579 outInfo.nonLocalizedLabel = null;
1580 }
1581
1582 TypedValue v = sa.peekValue(labelRes);
1583 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1584 outInfo.nonLocalizedLabel = v.coerceToString();
1585 }
1586
1587 outInfo.packageName = owner.packageName;
1588
1589 return true;
1590 }
1591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 private Activity parseActivity(Package owner, Resources res,
1593 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1594 boolean receiver) throws XmlPullParserException, IOException {
1595 TypedArray sa = res.obtainAttributes(attrs,
1596 com.android.internal.R.styleable.AndroidManifestActivity);
1597
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001598 if (mParseActivityArgs == null) {
1599 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1600 com.android.internal.R.styleable.AndroidManifestActivity_name,
1601 com.android.internal.R.styleable.AndroidManifestActivity_label,
1602 com.android.internal.R.styleable.AndroidManifestActivity_icon,
1603 mSeparateProcesses,
1604 com.android.internal.R.styleable.AndroidManifestActivity_process,
1605 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1606 }
1607
1608 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1609 mParseActivityArgs.sa = sa;
1610 mParseActivityArgs.flags = flags;
1611
1612 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1613 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 sa.recycle();
1615 return null;
1616 }
1617
1618 final boolean setExported = sa.hasValue(
1619 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1620 if (setExported) {
1621 a.info.exported = sa.getBoolean(
1622 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1623 }
1624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 a.info.theme = sa.getResourceId(
1626 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1627
1628 String str;
1629 str = sa.getNonResourceString(
1630 com.android.internal.R.styleable.AndroidManifestActivity_permission);
1631 if (str == null) {
1632 a.info.permission = owner.applicationInfo.permission;
1633 } else {
1634 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1635 }
1636
1637 str = sa.getNonResourceString(
1638 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity);
1639 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1640 owner.applicationInfo.taskAffinity, str, outError);
1641
1642 a.info.flags = 0;
1643 if (sa.getBoolean(
1644 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1645 false)) {
1646 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1647 }
1648
1649 if (sa.getBoolean(
1650 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1651 false)) {
1652 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1653 }
1654
1655 if (sa.getBoolean(
1656 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1657 false)) {
1658 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1659 }
1660
1661 if (sa.getBoolean(
1662 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1663 false)) {
1664 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1665 }
1666
1667 if (sa.getBoolean(
1668 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1669 false)) {
1670 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1671 }
1672
1673 if (sa.getBoolean(
1674 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1675 false)) {
1676 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1677 }
1678
1679 if (sa.getBoolean(
1680 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1681 false)) {
1682 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1683 }
1684
1685 if (sa.getBoolean(
1686 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1687 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1688 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1689 }
1690
Dianne Hackbornffa42482009-09-23 22:20:11 -07001691 if (sa.getBoolean(
1692 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1693 false)) {
1694 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1695 }
1696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 if (!receiver) {
1698 a.info.launchMode = sa.getInt(
1699 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1700 ActivityInfo.LAUNCH_MULTIPLE);
1701 a.info.screenOrientation = sa.getInt(
1702 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1703 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1704 a.info.configChanges = sa.getInt(
1705 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1706 0);
1707 a.info.softInputMode = sa.getInt(
1708 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1709 0);
1710 } else {
1711 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1712 a.info.configChanges = 0;
1713 }
1714
1715 sa.recycle();
1716
1717 if (outError[0] != null) {
1718 return null;
1719 }
1720
1721 int outerDepth = parser.getDepth();
1722 int type;
1723 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1724 && (type != XmlPullParser.END_TAG
1725 || parser.getDepth() > outerDepth)) {
1726 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1727 continue;
1728 }
1729
1730 if (parser.getName().equals("intent-filter")) {
1731 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1732 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1733 return null;
1734 }
1735 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001736 Log.w(TAG, "No actions in intent filter at "
1737 + mArchiveSourcePath + " "
1738 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 } else {
1740 a.intents.add(intent);
1741 }
1742 } else if (parser.getName().equals("meta-data")) {
1743 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1744 outError)) == null) {
1745 return null;
1746 }
1747 } else {
1748 if (!RIGID_PARSER) {
1749 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1750 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001751 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1752 + " at " + mArchiveSourcePath + " "
1753 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001755 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1756 + " at " + mArchiveSourcePath + " "
1757 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 }
1759 XmlUtils.skipCurrentTag(parser);
1760 continue;
1761 }
1762 if (receiver) {
1763 outError[0] = "Bad element under <receiver>: " + parser.getName();
1764 } else {
1765 outError[0] = "Bad element under <activity>: " + parser.getName();
1766 }
1767 return null;
1768 }
1769 }
1770
1771 if (!setExported) {
1772 a.info.exported = a.intents.size() > 0;
1773 }
1774
1775 return a;
1776 }
1777
1778 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001779 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1780 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 TypedArray sa = res.obtainAttributes(attrs,
1782 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1783
1784 String targetActivity = sa.getNonResourceString(
1785 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity);
1786 if (targetActivity == null) {
1787 outError[0] = "<activity-alias> does not specify android:targetActivity";
1788 sa.recycle();
1789 return null;
1790 }
1791
1792 targetActivity = buildClassName(owner.applicationInfo.packageName,
1793 targetActivity, outError);
1794 if (targetActivity == null) {
1795 sa.recycle();
1796 return null;
1797 }
1798
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001799 if (mParseActivityAliasArgs == null) {
1800 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1801 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1802 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1803 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
1804 mSeparateProcesses,
1805 0,
1806 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1807 mParseActivityAliasArgs.tag = "<activity-alias>";
1808 }
1809
1810 mParseActivityAliasArgs.sa = sa;
1811 mParseActivityAliasArgs.flags = flags;
1812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 Activity target = null;
1814
1815 final int NA = owner.activities.size();
1816 for (int i=0; i<NA; i++) {
1817 Activity t = owner.activities.get(i);
1818 if (targetActivity.equals(t.info.name)) {
1819 target = t;
1820 break;
1821 }
1822 }
1823
1824 if (target == null) {
1825 outError[0] = "<activity-alias> target activity " + targetActivity
1826 + " not found in manifest";
1827 sa.recycle();
1828 return null;
1829 }
1830
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001831 ActivityInfo info = new ActivityInfo();
1832 info.targetActivity = targetActivity;
1833 info.configChanges = target.info.configChanges;
1834 info.flags = target.info.flags;
1835 info.icon = target.info.icon;
1836 info.labelRes = target.info.labelRes;
1837 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
1838 info.launchMode = target.info.launchMode;
1839 info.processName = target.info.processName;
1840 info.screenOrientation = target.info.screenOrientation;
1841 info.taskAffinity = target.info.taskAffinity;
1842 info.theme = target.info.theme;
1843
1844 Activity a = new Activity(mParseActivityAliasArgs, info);
1845 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 sa.recycle();
1847 return null;
1848 }
1849
1850 final boolean setExported = sa.hasValue(
1851 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
1852 if (setExported) {
1853 a.info.exported = sa.getBoolean(
1854 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
1855 }
1856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 String str;
1858 str = sa.getNonResourceString(
1859 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission);
1860 if (str != null) {
1861 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1862 }
1863
1864 sa.recycle();
1865
1866 if (outError[0] != null) {
1867 return null;
1868 }
1869
1870 int outerDepth = parser.getDepth();
1871 int type;
1872 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1873 && (type != XmlPullParser.END_TAG
1874 || parser.getDepth() > outerDepth)) {
1875 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1876 continue;
1877 }
1878
1879 if (parser.getName().equals("intent-filter")) {
1880 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1881 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
1882 return null;
1883 }
1884 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001885 Log.w(TAG, "No actions in intent filter at "
1886 + mArchiveSourcePath + " "
1887 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 } else {
1889 a.intents.add(intent);
1890 }
1891 } else if (parser.getName().equals("meta-data")) {
1892 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1893 outError)) == null) {
1894 return null;
1895 }
1896 } else {
1897 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001898 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
1899 + " at " + mArchiveSourcePath + " "
1900 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 XmlUtils.skipCurrentTag(parser);
1902 continue;
1903 }
1904 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
1905 return null;
1906 }
1907 }
1908
1909 if (!setExported) {
1910 a.info.exported = a.intents.size() > 0;
1911 }
1912
1913 return a;
1914 }
1915
1916 private Provider parseProvider(Package owner, Resources res,
1917 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1918 throws XmlPullParserException, IOException {
1919 TypedArray sa = res.obtainAttributes(attrs,
1920 com.android.internal.R.styleable.AndroidManifestProvider);
1921
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001922 if (mParseProviderArgs == null) {
1923 mParseProviderArgs = new ParseComponentArgs(owner, outError,
1924 com.android.internal.R.styleable.AndroidManifestProvider_name,
1925 com.android.internal.R.styleable.AndroidManifestProvider_label,
1926 com.android.internal.R.styleable.AndroidManifestProvider_icon,
1927 mSeparateProcesses,
1928 com.android.internal.R.styleable.AndroidManifestProvider_process,
1929 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
1930 mParseProviderArgs.tag = "<provider>";
1931 }
1932
1933 mParseProviderArgs.sa = sa;
1934 mParseProviderArgs.flags = flags;
1935
1936 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
1937 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 sa.recycle();
1939 return null;
1940 }
1941
1942 p.info.exported = sa.getBoolean(
1943 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
1944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 String cpname = sa.getNonResourceString(
1946 com.android.internal.R.styleable.AndroidManifestProvider_authorities);
1947
1948 p.info.isSyncable = sa.getBoolean(
1949 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
1950 false);
1951
1952 String permission = sa.getNonResourceString(
1953 com.android.internal.R.styleable.AndroidManifestProvider_permission);
1954 String str = sa.getNonResourceString(
1955 com.android.internal.R.styleable.AndroidManifestProvider_readPermission);
1956 if (str == null) {
1957 str = permission;
1958 }
1959 if (str == null) {
1960 p.info.readPermission = owner.applicationInfo.permission;
1961 } else {
1962 p.info.readPermission =
1963 str.length() > 0 ? str.toString().intern() : null;
1964 }
1965 str = sa.getNonResourceString(
1966 com.android.internal.R.styleable.AndroidManifestProvider_writePermission);
1967 if (str == null) {
1968 str = permission;
1969 }
1970 if (str == null) {
1971 p.info.writePermission = owner.applicationInfo.permission;
1972 } else {
1973 p.info.writePermission =
1974 str.length() > 0 ? str.toString().intern() : null;
1975 }
1976
1977 p.info.grantUriPermissions = sa.getBoolean(
1978 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
1979 false);
1980
1981 p.info.multiprocess = sa.getBoolean(
1982 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
1983 false);
1984
1985 p.info.initOrder = sa.getInt(
1986 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
1987 0);
1988
1989 sa.recycle();
1990
1991 if (cpname == null) {
1992 outError[0] = "<provider> does not incude authorities attribute";
1993 return null;
1994 }
1995 p.info.authority = cpname.intern();
1996
1997 if (!parseProviderTags(res, parser, attrs, p, outError)) {
1998 return null;
1999 }
2000
2001 return p;
2002 }
2003
2004 private boolean parseProviderTags(Resources res,
2005 XmlPullParser parser, AttributeSet attrs,
2006 Provider outInfo, String[] outError)
2007 throws XmlPullParserException, IOException {
2008 int outerDepth = parser.getDepth();
2009 int type;
2010 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2011 && (type != XmlPullParser.END_TAG
2012 || parser.getDepth() > outerDepth)) {
2013 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2014 continue;
2015 }
2016
2017 if (parser.getName().equals("meta-data")) {
2018 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2019 outInfo.metaData, outError)) == null) {
2020 return false;
2021 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 } else if (parser.getName().equals("grant-uri-permission")) {
2024 TypedArray sa = res.obtainAttributes(attrs,
2025 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2026
2027 PatternMatcher pa = null;
2028
2029 String str = sa.getNonResourceString(
2030 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path);
2031 if (str != null) {
2032 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2033 }
2034
2035 str = sa.getNonResourceString(
2036 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix);
2037 if (str != null) {
2038 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2039 }
2040
2041 str = sa.getNonResourceString(
2042 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern);
2043 if (str != null) {
2044 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2045 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 sa.recycle();
2048
2049 if (pa != null) {
2050 if (outInfo.info.uriPermissionPatterns == null) {
2051 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2052 outInfo.info.uriPermissionPatterns[0] = pa;
2053 } else {
2054 final int N = outInfo.info.uriPermissionPatterns.length;
2055 PatternMatcher[] newp = new PatternMatcher[N+1];
2056 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2057 newp[N] = pa;
2058 outInfo.info.uriPermissionPatterns = newp;
2059 }
2060 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002061 } else {
2062 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002063 Log.w(TAG, "Unknown element under <path-permission>: "
2064 + parser.getName() + " at " + mArchiveSourcePath + " "
2065 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002066 XmlUtils.skipCurrentTag(parser);
2067 continue;
2068 }
2069 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2070 return false;
2071 }
2072 XmlUtils.skipCurrentTag(parser);
2073
2074 } else if (parser.getName().equals("path-permission")) {
2075 TypedArray sa = res.obtainAttributes(attrs,
2076 com.android.internal.R.styleable.AndroidManifestPathPermission);
2077
2078 PathPermission pa = null;
2079
2080 String permission = sa.getNonResourceString(
2081 com.android.internal.R.styleable.AndroidManifestPathPermission_permission);
2082 String readPermission = sa.getNonResourceString(
2083 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission);
2084 if (readPermission == null) {
2085 readPermission = permission;
2086 }
2087 String writePermission = sa.getNonResourceString(
2088 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission);
2089 if (writePermission == null) {
2090 writePermission = permission;
2091 }
2092
2093 boolean havePerm = false;
2094 if (readPermission != null) {
2095 readPermission = readPermission.intern();
2096 havePerm = true;
2097 }
2098 if (writePermission != null) {
2099 writePermission = readPermission.intern();
2100 havePerm = true;
2101 }
2102
2103 if (!havePerm) {
2104 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002105 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2106 + parser.getName() + " at " + mArchiveSourcePath + " "
2107 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002108 XmlUtils.skipCurrentTag(parser);
2109 continue;
2110 }
2111 outError[0] = "No readPermission or writePermssion for <path-permission>";
2112 return false;
2113 }
2114
2115 String path = sa.getNonResourceString(
2116 com.android.internal.R.styleable.AndroidManifestPathPermission_path);
2117 if (path != null) {
2118 pa = new PathPermission(path,
2119 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2120 }
2121
2122 path = sa.getNonResourceString(
2123 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix);
2124 if (path != null) {
2125 pa = new PathPermission(path,
2126 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2127 }
2128
2129 path = sa.getNonResourceString(
2130 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern);
2131 if (path != null) {
2132 pa = new PathPermission(path,
2133 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2134 }
2135
2136 sa.recycle();
2137
2138 if (pa != null) {
2139 if (outInfo.info.pathPermissions == null) {
2140 outInfo.info.pathPermissions = new PathPermission[1];
2141 outInfo.info.pathPermissions[0] = pa;
2142 } else {
2143 final int N = outInfo.info.pathPermissions.length;
2144 PathPermission[] newp = new PathPermission[N+1];
2145 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2146 newp[N] = pa;
2147 outInfo.info.pathPermissions = newp;
2148 }
2149 } else {
2150 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002151 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2152 + parser.getName() + " at " + mArchiveSourcePath + " "
2153 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002154 XmlUtils.skipCurrentTag(parser);
2155 continue;
2156 }
2157 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2158 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 }
2160 XmlUtils.skipCurrentTag(parser);
2161
2162 } else {
2163 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002165 + parser.getName() + " at " + mArchiveSourcePath + " "
2166 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 XmlUtils.skipCurrentTag(parser);
2168 continue;
2169 }
2170 outError[0] = "Bad element under <provider>: "
2171 + parser.getName();
2172 return false;
2173 }
2174 }
2175 return true;
2176 }
2177
2178 private Service parseService(Package owner, Resources res,
2179 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2180 throws XmlPullParserException, IOException {
2181 TypedArray sa = res.obtainAttributes(attrs,
2182 com.android.internal.R.styleable.AndroidManifestService);
2183
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002184 if (mParseServiceArgs == null) {
2185 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2186 com.android.internal.R.styleable.AndroidManifestService_name,
2187 com.android.internal.R.styleable.AndroidManifestService_label,
2188 com.android.internal.R.styleable.AndroidManifestService_icon,
2189 mSeparateProcesses,
2190 com.android.internal.R.styleable.AndroidManifestService_process,
2191 com.android.internal.R.styleable.AndroidManifestService_enabled);
2192 mParseServiceArgs.tag = "<service>";
2193 }
2194
2195 mParseServiceArgs.sa = sa;
2196 mParseServiceArgs.flags = flags;
2197
2198 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2199 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 sa.recycle();
2201 return null;
2202 }
2203
2204 final boolean setExported = sa.hasValue(
2205 com.android.internal.R.styleable.AndroidManifestService_exported);
2206 if (setExported) {
2207 s.info.exported = sa.getBoolean(
2208 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2209 }
2210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 String str = sa.getNonResourceString(
2212 com.android.internal.R.styleable.AndroidManifestService_permission);
2213 if (str == null) {
2214 s.info.permission = owner.applicationInfo.permission;
2215 } else {
2216 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2217 }
2218
2219 sa.recycle();
2220
2221 int outerDepth = parser.getDepth();
2222 int type;
2223 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2224 && (type != XmlPullParser.END_TAG
2225 || parser.getDepth() > outerDepth)) {
2226 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2227 continue;
2228 }
2229
2230 if (parser.getName().equals("intent-filter")) {
2231 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2232 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2233 return null;
2234 }
2235
2236 s.intents.add(intent);
2237 } else if (parser.getName().equals("meta-data")) {
2238 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2239 outError)) == null) {
2240 return null;
2241 }
2242 } else {
2243 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002245 + parser.getName() + " at " + mArchiveSourcePath + " "
2246 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 XmlUtils.skipCurrentTag(parser);
2248 continue;
2249 }
2250 outError[0] = "Bad element under <service>: "
2251 + parser.getName();
2252 return null;
2253 }
2254 }
2255
2256 if (!setExported) {
2257 s.info.exported = s.intents.size() > 0;
2258 }
2259
2260 return s;
2261 }
2262
2263 private boolean parseAllMetaData(Resources res,
2264 XmlPullParser parser, AttributeSet attrs, String tag,
2265 Component outInfo, String[] outError)
2266 throws XmlPullParserException, IOException {
2267 int outerDepth = parser.getDepth();
2268 int type;
2269 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2270 && (type != XmlPullParser.END_TAG
2271 || parser.getDepth() > outerDepth)) {
2272 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2273 continue;
2274 }
2275
2276 if (parser.getName().equals("meta-data")) {
2277 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2278 outInfo.metaData, outError)) == null) {
2279 return false;
2280 }
2281 } else {
2282 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002284 + parser.getName() + " at " + mArchiveSourcePath + " "
2285 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 XmlUtils.skipCurrentTag(parser);
2287 continue;
2288 }
2289 outError[0] = "Bad element under " + tag + ": "
2290 + parser.getName();
2291 return false;
2292 }
2293 }
2294 return true;
2295 }
2296
2297 private Bundle parseMetaData(Resources res,
2298 XmlPullParser parser, AttributeSet attrs,
2299 Bundle data, String[] outError)
2300 throws XmlPullParserException, IOException {
2301
2302 TypedArray sa = res.obtainAttributes(attrs,
2303 com.android.internal.R.styleable.AndroidManifestMetaData);
2304
2305 if (data == null) {
2306 data = new Bundle();
2307 }
2308
2309 String name = sa.getNonResourceString(
2310 com.android.internal.R.styleable.AndroidManifestMetaData_name);
2311 if (name == null) {
2312 outError[0] = "<meta-data> requires an android:name attribute";
2313 sa.recycle();
2314 return null;
2315 }
2316
Dianne Hackborn854060a2009-07-09 18:14:31 -07002317 name = name.intern();
2318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 TypedValue v = sa.peekValue(
2320 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2321 if (v != null && v.resourceId != 0) {
2322 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2323 data.putInt(name, v.resourceId);
2324 } else {
2325 v = sa.peekValue(
2326 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2327 //Log.i(TAG, "Meta data " + name + ": " + v);
2328 if (v != null) {
2329 if (v.type == TypedValue.TYPE_STRING) {
2330 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002331 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2333 data.putBoolean(name, v.data != 0);
2334 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2335 && v.type <= TypedValue.TYPE_LAST_INT) {
2336 data.putInt(name, v.data);
2337 } else if (v.type == TypedValue.TYPE_FLOAT) {
2338 data.putFloat(name, v.getFloat());
2339 } else {
2340 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002341 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2342 + parser.getName() + " at " + mArchiveSourcePath + " "
2343 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 } else {
2345 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2346 data = null;
2347 }
2348 }
2349 } else {
2350 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2351 data = null;
2352 }
2353 }
2354
2355 sa.recycle();
2356
2357 XmlUtils.skipCurrentTag(parser);
2358
2359 return data;
2360 }
2361
2362 private static final String ANDROID_RESOURCES
2363 = "http://schemas.android.com/apk/res/android";
2364
2365 private boolean parseIntent(Resources res,
2366 XmlPullParser parser, AttributeSet attrs, int flags,
2367 IntentInfo outInfo, String[] outError, boolean isActivity)
2368 throws XmlPullParserException, IOException {
2369
2370 TypedArray sa = res.obtainAttributes(attrs,
2371 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2372
2373 int priority = sa.getInt(
2374 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2375 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2376 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002377 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 + parser.getPositionDescription());
2379 priority = 0;
2380 }
2381 outInfo.setPriority(priority);
2382
2383 TypedValue v = sa.peekValue(
2384 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2385 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2386 outInfo.nonLocalizedLabel = v.coerceToString();
2387 }
2388
2389 outInfo.icon = sa.getResourceId(
2390 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
2391
2392 sa.recycle();
2393
2394 int outerDepth = parser.getDepth();
2395 int type;
2396 while ((type=parser.next()) != parser.END_DOCUMENT
2397 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2398 if (type == parser.END_TAG || type == parser.TEXT) {
2399 continue;
2400 }
2401
2402 String nodeName = parser.getName();
2403 if (nodeName.equals("action")) {
2404 String value = attrs.getAttributeValue(
2405 ANDROID_RESOURCES, "name");
2406 if (value == null || value == "") {
2407 outError[0] = "No value supplied for <android:name>";
2408 return false;
2409 }
2410 XmlUtils.skipCurrentTag(parser);
2411
2412 outInfo.addAction(value);
2413 } else if (nodeName.equals("category")) {
2414 String value = attrs.getAttributeValue(
2415 ANDROID_RESOURCES, "name");
2416 if (value == null || value == "") {
2417 outError[0] = "No value supplied for <android:name>";
2418 return false;
2419 }
2420 XmlUtils.skipCurrentTag(parser);
2421
2422 outInfo.addCategory(value);
2423
2424 } else if (nodeName.equals("data")) {
2425 sa = res.obtainAttributes(attrs,
2426 com.android.internal.R.styleable.AndroidManifestData);
2427
2428 String str = sa.getNonResourceString(
2429 com.android.internal.R.styleable.AndroidManifestData_mimeType);
2430 if (str != null) {
2431 try {
2432 outInfo.addDataType(str);
2433 } catch (IntentFilter.MalformedMimeTypeException e) {
2434 outError[0] = e.toString();
2435 sa.recycle();
2436 return false;
2437 }
2438 }
2439
2440 str = sa.getNonResourceString(
2441 com.android.internal.R.styleable.AndroidManifestData_scheme);
2442 if (str != null) {
2443 outInfo.addDataScheme(str);
2444 }
2445
2446 String host = sa.getNonResourceString(
2447 com.android.internal.R.styleable.AndroidManifestData_host);
2448 String port = sa.getNonResourceString(
2449 com.android.internal.R.styleable.AndroidManifestData_port);
2450 if (host != null) {
2451 outInfo.addDataAuthority(host, port);
2452 }
2453
2454 str = sa.getNonResourceString(
2455 com.android.internal.R.styleable.AndroidManifestData_path);
2456 if (str != null) {
2457 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2458 }
2459
2460 str = sa.getNonResourceString(
2461 com.android.internal.R.styleable.AndroidManifestData_pathPrefix);
2462 if (str != null) {
2463 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2464 }
2465
2466 str = sa.getNonResourceString(
2467 com.android.internal.R.styleable.AndroidManifestData_pathPattern);
2468 if (str != null) {
2469 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2470 }
2471
2472 sa.recycle();
2473 XmlUtils.skipCurrentTag(parser);
2474 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002475 Log.w(TAG, "Unknown element under <intent-filter>: "
2476 + parser.getName() + " at " + mArchiveSourcePath + " "
2477 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 XmlUtils.skipCurrentTag(parser);
2479 } else {
2480 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2481 return false;
2482 }
2483 }
2484
2485 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2486 if (false) {
2487 String cats = "";
2488 Iterator<String> it = outInfo.categoriesIterator();
2489 while (it != null && it.hasNext()) {
2490 cats += " " + it.next();
2491 }
2492 System.out.println("Intent d=" +
2493 outInfo.hasDefault + ", cat=" + cats);
2494 }
2495
2496 return true;
2497 }
2498
2499 public final static class Package {
2500 public final String packageName;
2501
2502 // For now we only support one application per package.
2503 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2504
2505 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2506 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2507 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2508 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2509 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2510 public final ArrayList<Service> services = new ArrayList<Service>(0);
2511 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2512
2513 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2514
Dianne Hackborn854060a2009-07-09 18:14:31 -07002515 public ArrayList<String> protectedBroadcasts;
2516
Dianne Hackborn49237342009-08-27 20:08:01 -07002517 public ArrayList<String> usesLibraries = null;
2518 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519 public String[] usesLibraryFiles = null;
2520
2521 // We store the application meta-data independently to avoid multiple unwanted references
2522 public Bundle mAppMetaData = null;
2523
2524 // If this is a 3rd party app, this is the path of the zip file.
2525 public String mPath;
2526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 // The version code declared for this package.
2528 public int mVersionCode;
2529
2530 // The version name declared for this package.
2531 public String mVersionName;
2532
2533 // The shared user id that this package wants to use.
2534 public String mSharedUserId;
2535
2536 // The shared user label that this package wants to use.
2537 public int mSharedUserLabel;
2538
2539 // Signatures that were read from the package.
2540 public Signature mSignatures[];
2541
2542 // For use by package manager service for quick lookup of
2543 // preferred up order.
2544 public int mPreferredOrder = 0;
2545
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002546 // For use by the package manager to keep track of the path to the
2547 // file an app came from.
2548 public String mScanPath;
2549
2550 // For use by package manager to keep track of where it has done dexopt.
2551 public boolean mDidDexOpt;
2552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 // Additional data supplied by callers.
2554 public Object mExtras;
2555
2556 /*
2557 * Applications hardware preferences
2558 */
2559 public final ArrayList<ConfigurationInfo> configPreferences =
2560 new ArrayList<ConfigurationInfo>();
2561
Dianne Hackborn49237342009-08-27 20:08:01 -07002562 /*
2563 * Applications requested features
2564 */
2565 public ArrayList<FeatureInfo> reqFeatures = null;
2566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 public Package(String _name) {
2568 packageName = _name;
2569 applicationInfo.packageName = _name;
2570 applicationInfo.uid = -1;
2571 }
2572
2573 public String toString() {
2574 return "Package{"
2575 + Integer.toHexString(System.identityHashCode(this))
2576 + " " + packageName + "}";
2577 }
2578 }
2579
2580 public static class Component<II extends IntentInfo> {
2581 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002582 public final ArrayList<II> intents;
2583 public final ComponentName component;
2584 public final String componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 public Bundle metaData;
2586
2587 public Component(Package _owner) {
2588 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002589 intents = null;
2590 component = null;
2591 componentShortName = null;
2592 }
2593
2594 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2595 owner = args.owner;
2596 intents = new ArrayList<II>(0);
2597 String name = args.sa.getNonResourceString(args.nameRes);
2598 if (name == null) {
2599 component = null;
2600 componentShortName = null;
2601 args.outError[0] = args.tag + " does not specify android:name";
2602 return;
2603 }
2604
2605 outInfo.name
2606 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2607 if (outInfo.name == null) {
2608 component = null;
2609 componentShortName = null;
2610 args.outError[0] = args.tag + " does not have valid android:name";
2611 return;
2612 }
2613
2614 component = new ComponentName(owner.applicationInfo.packageName,
2615 outInfo.name);
2616 componentShortName = component.flattenToShortString();
2617
2618 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2619 if (iconVal != 0) {
2620 outInfo.icon = iconVal;
2621 outInfo.nonLocalizedLabel = null;
2622 }
2623
2624 TypedValue v = args.sa.peekValue(args.labelRes);
2625 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2626 outInfo.nonLocalizedLabel = v.coerceToString();
2627 }
2628
2629 outInfo.packageName = owner.packageName;
2630 }
2631
2632 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2633 this(args, (PackageItemInfo)outInfo);
2634 if (args.outError[0] != null) {
2635 return;
2636 }
2637
2638 if (args.processRes != 0) {
2639 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
2640 owner.applicationInfo.processName, args.sa.getNonResourceString(args.processRes),
2641 args.flags, args.sepProcesses, args.outError);
2642 }
2643 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 }
2645
2646 public Component(Component<II> clone) {
2647 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002648 intents = clone.intents;
2649 component = clone.component;
2650 componentShortName = clone.componentShortName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 metaData = clone.metaData;
2652 }
2653 }
2654
2655 public final static class Permission extends Component<IntentInfo> {
2656 public final PermissionInfo info;
2657 public boolean tree;
2658 public PermissionGroup group;
2659
2660 public Permission(Package _owner) {
2661 super(_owner);
2662 info = new PermissionInfo();
2663 }
2664
2665 public Permission(Package _owner, PermissionInfo _info) {
2666 super(_owner);
2667 info = _info;
2668 }
2669
2670 public String toString() {
2671 return "Permission{"
2672 + Integer.toHexString(System.identityHashCode(this))
2673 + " " + info.name + "}";
2674 }
2675 }
2676
2677 public final static class PermissionGroup extends Component<IntentInfo> {
2678 public final PermissionGroupInfo info;
2679
2680 public PermissionGroup(Package _owner) {
2681 super(_owner);
2682 info = new PermissionGroupInfo();
2683 }
2684
2685 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2686 super(_owner);
2687 info = _info;
2688 }
2689
2690 public String toString() {
2691 return "PermissionGroup{"
2692 + Integer.toHexString(System.identityHashCode(this))
2693 + " " + info.name + "}";
2694 }
2695 }
2696
2697 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
2698 if ((flags & PackageManager.GET_META_DATA) != 0
2699 && (metaData != null || p.mAppMetaData != null)) {
2700 return true;
2701 }
2702 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
2703 && p.usesLibraryFiles != null) {
2704 return true;
2705 }
2706 return false;
2707 }
2708
2709 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
2710 if (p == null) return null;
2711 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002712 // CompatibilityMode is global state. It's safe to modify the instance
2713 // of the package.
2714 if (!sCompatibilityModeEnabled) {
2715 p.applicationInfo.disableCompatibilityMode();
2716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 return p.applicationInfo;
2718 }
2719
2720 // Make shallow copy so we can store the metadata/libraries safely
2721 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
2722 if ((flags & PackageManager.GET_META_DATA) != 0) {
2723 ai.metaData = p.mAppMetaData;
2724 }
2725 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
2726 ai.sharedLibraryFiles = p.usesLibraryFiles;
2727 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002728 if (!sCompatibilityModeEnabled) {
2729 ai.disableCompatibilityMode();
2730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 return ai;
2732 }
2733
2734 public static final PermissionInfo generatePermissionInfo(
2735 Permission p, int flags) {
2736 if (p == null) return null;
2737 if ((flags&PackageManager.GET_META_DATA) == 0) {
2738 return p.info;
2739 }
2740 PermissionInfo pi = new PermissionInfo(p.info);
2741 pi.metaData = p.metaData;
2742 return pi;
2743 }
2744
2745 public static final PermissionGroupInfo generatePermissionGroupInfo(
2746 PermissionGroup pg, int flags) {
2747 if (pg == null) return null;
2748 if ((flags&PackageManager.GET_META_DATA) == 0) {
2749 return pg.info;
2750 }
2751 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
2752 pgi.metaData = pg.metaData;
2753 return pgi;
2754 }
2755
2756 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002757 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002759 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
2760 super(args, _info);
2761 info = _info;
2762 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 public String toString() {
2766 return "Activity{"
2767 + Integer.toHexString(System.identityHashCode(this))
2768 + " " + component.flattenToString() + "}";
2769 }
2770 }
2771
2772 public static final ActivityInfo generateActivityInfo(Activity a,
2773 int flags) {
2774 if (a == null) return null;
2775 if (!copyNeeded(flags, a.owner, a.metaData)) {
2776 return a.info;
2777 }
2778 // Make shallow copies so we can store the metadata safely
2779 ActivityInfo ai = new ActivityInfo(a.info);
2780 ai.metaData = a.metaData;
2781 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
2782 return ai;
2783 }
2784
2785 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002786 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002788 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
2789 super(args, _info);
2790 info = _info;
2791 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 public String toString() {
2795 return "Service{"
2796 + Integer.toHexString(System.identityHashCode(this))
2797 + " " + component.flattenToString() + "}";
2798 }
2799 }
2800
2801 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
2802 if (s == null) return null;
2803 if (!copyNeeded(flags, s.owner, s.metaData)) {
2804 return s.info;
2805 }
2806 // Make shallow copies so we can store the metadata safely
2807 ServiceInfo si = new ServiceInfo(s.info);
2808 si.metaData = s.metaData;
2809 si.applicationInfo = generateApplicationInfo(s.owner, flags);
2810 return si;
2811 }
2812
2813 public final static class Provider extends Component {
2814 public final ProviderInfo info;
2815 public boolean syncable;
2816
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002817 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
2818 super(args, _info);
2819 info = _info;
2820 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 syncable = false;
2822 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 public Provider(Provider existingProvider) {
2825 super(existingProvider);
2826 this.info = existingProvider.info;
2827 this.syncable = existingProvider.syncable;
2828 }
2829
2830 public String toString() {
2831 return "Provider{"
2832 + Integer.toHexString(System.identityHashCode(this))
2833 + " " + info.name + "}";
2834 }
2835 }
2836
2837 public static final ProviderInfo generateProviderInfo(Provider p,
2838 int flags) {
2839 if (p == null) return null;
2840 if (!copyNeeded(flags, p.owner, p.metaData)
2841 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
2842 || p.info.uriPermissionPatterns == null)) {
2843 return p.info;
2844 }
2845 // Make shallow copies so we can store the metadata safely
2846 ProviderInfo pi = new ProviderInfo(p.info);
2847 pi.metaData = p.metaData;
2848 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
2849 pi.uriPermissionPatterns = null;
2850 }
2851 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
2852 return pi;
2853 }
2854
2855 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002856 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002858 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
2859 super(args, _info);
2860 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 public String toString() {
2864 return "Instrumentation{"
2865 + Integer.toHexString(System.identityHashCode(this))
2866 + " " + component.flattenToString() + "}";
2867 }
2868 }
2869
2870 public static final InstrumentationInfo generateInstrumentationInfo(
2871 Instrumentation i, int flags) {
2872 if (i == null) return null;
2873 if ((flags&PackageManager.GET_META_DATA) == 0) {
2874 return i.info;
2875 }
2876 InstrumentationInfo ii = new InstrumentationInfo(i.info);
2877 ii.metaData = i.metaData;
2878 return ii;
2879 }
2880
2881 public static class IntentInfo extends IntentFilter {
2882 public boolean hasDefault;
2883 public int labelRes;
2884 public CharSequence nonLocalizedLabel;
2885 public int icon;
2886 }
2887
2888 public final static class ActivityIntentInfo extends IntentInfo {
2889 public final Activity activity;
2890
2891 public ActivityIntentInfo(Activity _activity) {
2892 activity = _activity;
2893 }
2894
2895 public String toString() {
2896 return "ActivityIntentInfo{"
2897 + Integer.toHexString(System.identityHashCode(this))
2898 + " " + activity.info.name + "}";
2899 }
2900 }
2901
2902 public final static class ServiceIntentInfo extends IntentInfo {
2903 public final Service service;
2904
2905 public ServiceIntentInfo(Service _service) {
2906 service = _service;
2907 }
2908
2909 public String toString() {
2910 return "ServiceIntentInfo{"
2911 + Integer.toHexString(System.identityHashCode(this))
2912 + " " + service.info.name + "}";
2913 }
2914 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002915
2916 /**
2917 * @hide
2918 */
2919 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
2920 sCompatibilityModeEnabled = compatibilityModeEnabled;
2921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922}