blob: 6a4fefcd629921b32aa2083243e7efaafa281801 [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;
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -080033import android.provider.Settings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.AttributeSet;
35import android.util.Config;
36import android.util.DisplayMetrics;
37import android.util.Log;
38import android.util.TypedValue;
Dianne Hackborn2269d152010-02-24 19:54:22 -080039
40import com.android.internal.util.XmlUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42import java.io.File;
43import java.io.IOException;
44import java.io.InputStream;
45import java.lang.ref.WeakReference;
46import java.security.cert.Certificate;
47import java.security.cert.CertificateEncodingException;
48import java.util.ArrayList;
49import java.util.Enumeration;
50import java.util.Iterator;
Mitsuru Oshima8d112672009-04-27 12:01:23 -070051import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.jar.JarEntry;
53import java.util.jar.JarFile;
54
55/**
56 * Package archive parsing
57 *
58 * {@hide}
59 */
60public class PackageParser {
Dianne Hackborna96cbb42009-05-13 15:06:13 -070061 /** @hide */
62 public static class NewPermissionInfo {
63 public final String name;
64 public final int sdkVersion;
65 public final int fileVersion;
66
67 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
68 this.name = name;
69 this.sdkVersion = sdkVersion;
70 this.fileVersion = fileVersion;
71 }
72 }
73
74 /**
75 * List of new permissions that have been added since 1.0.
76 * NOTE: These must be declared in SDK version order, with permissions
77 * added to older SDKs appearing before those added to newer SDKs.
78 * @hide
79 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -070080 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
81 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070082 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070083 android.os.Build.VERSION_CODES.DONUT, 0),
84 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
85 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -070086 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
88 private String mArchiveSourcePath;
89 private String[] mSeparateProcesses;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070090 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
91 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
92 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
95
96 private static final Object mSync = new Object();
97 private static WeakReference<byte[]> mReadBuffer;
98
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -070099 private static boolean sCompatibilityModeEnabled = true;
100 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700101
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700102 static class ParsePackageItemArgs {
103 final Package owner;
104 final String[] outError;
105 final int nameRes;
106 final int labelRes;
107 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700108 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700109
110 String tag;
111 TypedArray sa;
112
113 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700114 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700115 owner = _owner;
116 outError = _outError;
117 nameRes = _nameRes;
118 labelRes = _labelRes;
119 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700120 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700121 }
122 }
123
124 static class ParseComponentArgs extends ParsePackageItemArgs {
125 final String[] sepProcesses;
126 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800127 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700128 final int enabledRes;
129 int flags;
130
131 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700132 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800133 String[] _sepProcesses, int _processRes,
134 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700135 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700136 sepProcesses = _sepProcesses;
137 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800138 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700139 enabledRes = _enabledRes;
140 }
141 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800142
143 /* Light weight package info.
144 * @hide
145 */
146 public static class PackageLite {
147 public String packageName;
148 public int installLocation;
149 public String mScanPath;
150 public PackageLite(String packageName, int installLocation) {
151 this.packageName = packageName;
152 this.installLocation = installLocation;
153 }
154 }
155
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700156 private ParsePackageItemArgs mParseInstrumentationArgs;
157 private ParseComponentArgs mParseActivityArgs;
158 private ParseComponentArgs mParseActivityAliasArgs;
159 private ParseComponentArgs mParseServiceArgs;
160 private ParseComponentArgs mParseProviderArgs;
161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 /** If set to true, we will only allow package files that exactly match
163 * the DTD. Otherwise, we try to get as much from the package as we
164 * can without failing. This should normally be set to false, to
165 * support extensions to the DTD in future versions. */
166 private static final boolean RIGID_PARSER = false;
167
168 private static final String TAG = "PackageParser";
169
170 public PackageParser(String archiveSourcePath) {
171 mArchiveSourcePath = archiveSourcePath;
172 }
173
174 public void setSeparateProcesses(String[] procs) {
175 mSeparateProcesses = procs;
176 }
177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 private static final boolean isPackageFilename(String name) {
179 return name.endsWith(".apk");
180 }
181
182 /**
183 * Generate and return the {@link PackageInfo} for a parsed package.
184 *
185 * @param p the parsed package.
186 * @param flags indicating which optional information is included.
187 */
188 public static PackageInfo generatePackageInfo(PackageParser.Package p,
189 int gids[], int flags) {
190
191 PackageInfo pi = new PackageInfo();
192 pi.packageName = p.packageName;
193 pi.versionCode = p.mVersionCode;
194 pi.versionName = p.mVersionName;
195 pi.sharedUserId = p.mSharedUserId;
196 pi.sharedUserLabel = p.mSharedUserLabel;
197 pi.applicationInfo = p.applicationInfo;
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800198 pi.installLocation = p.installLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 if ((flags&PackageManager.GET_GIDS) != 0) {
200 pi.gids = gids;
201 }
202 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
203 int N = p.configPreferences.size();
204 if (N > 0) {
205 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700206 p.configPreferences.toArray(pi.configPreferences);
207 }
208 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
209 if (N > 0) {
210 pi.reqFeatures = new FeatureInfo[N];
211 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
213 }
214 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
215 int N = p.activities.size();
216 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700217 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
218 pi.activities = new ActivityInfo[N];
219 } else {
220 int num = 0;
221 for (int i=0; i<N; i++) {
222 if (p.activities.get(i).info.enabled) num++;
223 }
224 pi.activities = new ActivityInfo[num];
225 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700226 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 final Activity activity = p.activities.get(i);
228 if (activity.info.enabled
229 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700230 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 }
232 }
233 }
234 }
235 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
236 int N = p.receivers.size();
237 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700238 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
239 pi.receivers = new ActivityInfo[N];
240 } else {
241 int num = 0;
242 for (int i=0; i<N; i++) {
243 if (p.receivers.get(i).info.enabled) num++;
244 }
245 pi.receivers = new ActivityInfo[num];
246 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700247 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 final Activity activity = p.receivers.get(i);
249 if (activity.info.enabled
250 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700251 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 }
255 }
256 if ((flags&PackageManager.GET_SERVICES) != 0) {
257 int N = p.services.size();
258 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700259 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
260 pi.services = new ServiceInfo[N];
261 } else {
262 int num = 0;
263 for (int i=0; i<N; i++) {
264 if (p.services.get(i).info.enabled) num++;
265 }
266 pi.services = new ServiceInfo[num];
267 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700268 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final Service service = p.services.get(i);
270 if (service.info.enabled
271 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700272 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 }
274 }
275 }
276 }
277 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
278 int N = p.providers.size();
279 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700280 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
281 pi.providers = new ProviderInfo[N];
282 } else {
283 int num = 0;
284 for (int i=0; i<N; i++) {
285 if (p.providers.get(i).info.enabled) num++;
286 }
287 pi.providers = new ProviderInfo[num];
288 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700289 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 final Provider provider = p.providers.get(i);
291 if (provider.info.enabled
292 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700293 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 }
295 }
296 }
297 }
298 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
299 int N = p.instrumentation.size();
300 if (N > 0) {
301 pi.instrumentation = new InstrumentationInfo[N];
302 for (int i=0; i<N; i++) {
303 pi.instrumentation[i] = generateInstrumentationInfo(
304 p.instrumentation.get(i), flags);
305 }
306 }
307 }
308 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
309 int N = p.permissions.size();
310 if (N > 0) {
311 pi.permissions = new PermissionInfo[N];
312 for (int i=0; i<N; i++) {
313 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
314 }
315 }
316 N = p.requestedPermissions.size();
317 if (N > 0) {
318 pi.requestedPermissions = new String[N];
319 for (int i=0; i<N; i++) {
320 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
321 }
322 }
323 }
324 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700325 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
326 if (N > 0) {
327 pi.signatures = new Signature[N];
328 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 }
330 }
331 return pi;
332 }
333
334 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
335 byte[] readBuffer) {
336 try {
337 // We must read the stream for the JarEntry to retrieve
338 // its certificates.
339 InputStream is = jarFile.getInputStream(je);
340 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
341 // not using
342 }
343 is.close();
344 return je != null ? je.getCertificates() : null;
345 } catch (IOException e) {
346 Log.w(TAG, "Exception reading " + je.getName() + " in "
347 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700348 } catch (RuntimeException e) {
349 Log.w(TAG, "Exception reading " + je.getName() + " in "
350 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
352 return null;
353 }
354
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800355 public final static int PARSE_IS_SYSTEM = 1<<0;
356 public final static int PARSE_CHATTY = 1<<1;
357 public final static int PARSE_MUST_BE_APK = 1<<2;
358 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
359 public final static int PARSE_FORWARD_LOCK = 1<<4;
360 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700361 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362
363 public int getParseError() {
364 return mParseError;
365 }
366
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800367 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 DisplayMetrics metrics, int flags) {
369 mParseError = PackageManager.INSTALL_SUCCEEDED;
370
371 mArchiveSourcePath = sourceFile.getPath();
372 if (!sourceFile.isFile()) {
373 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
374 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
375 return null;
376 }
377 if (!isPackageFilename(sourceFile.getName())
378 && (flags&PARSE_MUST_BE_APK) != 0) {
379 if ((flags&PARSE_IS_SYSTEM) == 0) {
380 // We expect to have non-.apk files in the system dir,
381 // so don't warn about them.
382 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
383 }
384 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
385 return null;
386 }
387
388 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
389 TAG, "Scanning package: " + mArchiveSourcePath);
390
391 XmlResourceParser parser = null;
392 AssetManager assmgr = null;
393 boolean assetError = true;
394 try {
395 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700396 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
397 if(cookie != 0) {
398 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 assetError = false;
400 } else {
401 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
402 }
403 } catch (Exception e) {
404 Log.w(TAG, "Unable to read AndroidManifest.xml of "
405 + mArchiveSourcePath, e);
406 }
407 if(assetError) {
408 if (assmgr != null) assmgr.close();
409 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
410 return null;
411 }
412 String[] errorText = new String[1];
413 Package pkg = null;
414 Exception errorException = null;
415 try {
416 // XXXX todo: need to figure out correct configuration.
417 Resources res = new Resources(assmgr, metrics, null);
418 pkg = parsePackage(res, parser, flags, errorText);
419 } catch (Exception e) {
420 errorException = e;
421 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
422 }
423
424
425 if (pkg == null) {
426 if (errorException != null) {
427 Log.w(TAG, mArchiveSourcePath, errorException);
428 } else {
429 Log.w(TAG, mArchiveSourcePath + " (at "
430 + parser.getPositionDescription()
431 + "): " + errorText[0]);
432 }
433 parser.close();
434 assmgr.close();
435 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
436 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
437 }
438 return null;
439 }
440
441 parser.close();
442 assmgr.close();
443
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800444 // Set code and resource paths
445 pkg.mPath = destCodePath;
446 pkg.mScanPath = mArchiveSourcePath;
447 //pkg.applicationInfo.sourceDir = destCodePath;
448 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 pkg.mSignatures = null;
450
451 return pkg;
452 }
453
454 public boolean collectCertificates(Package pkg, int flags) {
455 pkg.mSignatures = null;
456
457 WeakReference<byte[]> readBufferRef;
458 byte[] readBuffer = null;
459 synchronized (mSync) {
460 readBufferRef = mReadBuffer;
461 if (readBufferRef != null) {
462 mReadBuffer = null;
463 readBuffer = readBufferRef.get();
464 }
465 if (readBuffer == null) {
466 readBuffer = new byte[8192];
467 readBufferRef = new WeakReference<byte[]>(readBuffer);
468 }
469 }
470
471 try {
472 JarFile jarFile = new JarFile(mArchiveSourcePath);
473
474 Certificate[] certs = null;
475
476 if ((flags&PARSE_IS_SYSTEM) != 0) {
477 // If this package comes from the system image, then we
478 // can trust it... we'll just use the AndroidManifest.xml
479 // to retrieve its signatures, not validating all of the
480 // files.
481 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
482 certs = loadCertificates(jarFile, jarEntry, readBuffer);
483 if (certs == null) {
484 Log.e(TAG, "Package " + pkg.packageName
485 + " has no certificates at entry "
486 + jarEntry.getName() + "; ignoring!");
487 jarFile.close();
488 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
489 return false;
490 }
491 if (false) {
492 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
493 + " certs=" + (certs != null ? certs.length : 0));
494 if (certs != null) {
495 final int N = certs.length;
496 for (int i=0; i<N; i++) {
497 Log.i(TAG, " Public key: "
498 + certs[i].getPublicKey().getEncoded()
499 + " " + certs[i].getPublicKey());
500 }
501 }
502 }
503
504 } else {
505 Enumeration entries = jarFile.entries();
506 while (entries.hasMoreElements()) {
507 JarEntry je = (JarEntry)entries.nextElement();
508 if (je.isDirectory()) continue;
509 if (je.getName().startsWith("META-INF/")) continue;
510 Certificate[] localCerts = loadCertificates(jarFile, je,
511 readBuffer);
512 if (false) {
513 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
514 + ": certs=" + certs + " ("
515 + (certs != null ? certs.length : 0) + ")");
516 }
517 if (localCerts == null) {
518 Log.e(TAG, "Package " + pkg.packageName
519 + " has no certificates at entry "
520 + je.getName() + "; ignoring!");
521 jarFile.close();
522 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
523 return false;
524 } else if (certs == null) {
525 certs = localCerts;
526 } else {
527 // Ensure all certificates match.
528 for (int i=0; i<certs.length; i++) {
529 boolean found = false;
530 for (int j=0; j<localCerts.length; j++) {
531 if (certs[i] != null &&
532 certs[i].equals(localCerts[j])) {
533 found = true;
534 break;
535 }
536 }
537 if (!found || certs.length != localCerts.length) {
538 Log.e(TAG, "Package " + pkg.packageName
539 + " has mismatched certificates at entry "
540 + je.getName() + "; ignoring!");
541 jarFile.close();
542 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
543 return false;
544 }
545 }
546 }
547 }
548 }
549 jarFile.close();
550
551 synchronized (mSync) {
552 mReadBuffer = readBufferRef;
553 }
554
555 if (certs != null && certs.length > 0) {
556 final int N = certs.length;
557 pkg.mSignatures = new Signature[certs.length];
558 for (int i=0; i<N; i++) {
559 pkg.mSignatures[i] = new Signature(
560 certs[i].getEncoded());
561 }
562 } else {
563 Log.e(TAG, "Package " + pkg.packageName
564 + " has no certificates; ignoring!");
565 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
566 return false;
567 }
568 } catch (CertificateEncodingException e) {
569 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
570 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
571 return false;
572 } catch (IOException e) {
573 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
574 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
575 return false;
576 } catch (RuntimeException e) {
577 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
578 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
579 return false;
580 }
581
582 return true;
583 }
584
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800585 /*
586 * Utility method that retrieves just the package name and install
587 * location from the apk location at the given file path.
588 * @param packageFilePath file location of the apk
589 * @param flags Special parse flags
590 * @return PackageLite object with package information.
591 */
592 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 XmlResourceParser parser = null;
594 AssetManager assmgr = null;
595 try {
596 assmgr = new AssetManager();
597 int cookie = assmgr.addAssetPath(packageFilePath);
598 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
599 } catch (Exception e) {
600 if (assmgr != null) assmgr.close();
601 Log.w(TAG, "Unable to read AndroidManifest.xml of "
602 + packageFilePath, e);
603 return null;
604 }
605 AttributeSet attrs = parser;
606 String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800607 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 try {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800609 packageLite = parsePackageLite(parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 } catch (IOException e) {
611 Log.w(TAG, packageFilePath, e);
612 } catch (XmlPullParserException e) {
613 Log.w(TAG, packageFilePath, e);
614 } finally {
615 if (parser != null) parser.close();
616 if (assmgr != null) assmgr.close();
617 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800618 if (packageLite == null) {
619 Log.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 return null;
621 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800622 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624
625 private static String validateName(String name, boolean requiresSeparator) {
626 final int N = name.length();
627 boolean hasSep = false;
628 boolean front = true;
629 for (int i=0; i<N; i++) {
630 final char c = name.charAt(i);
631 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
632 front = false;
633 continue;
634 }
635 if (!front) {
636 if ((c >= '0' && c <= '9') || c == '_') {
637 continue;
638 }
639 }
640 if (c == '.') {
641 hasSep = true;
642 front = true;
643 continue;
644 }
645 return "bad character '" + c + "'";
646 }
647 return hasSep || !requiresSeparator
648 ? null : "must have at least one '.' separator";
649 }
650
651 private static String parsePackageName(XmlPullParser parser,
652 AttributeSet attrs, int flags, String[] outError)
653 throws IOException, XmlPullParserException {
654
655 int type;
656 while ((type=parser.next()) != parser.START_TAG
657 && type != parser.END_DOCUMENT) {
658 ;
659 }
660
661 if (type != parser.START_TAG) {
662 outError[0] = "No start tag found";
663 return null;
664 }
665 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
666 TAG, "Root element name: '" + parser.getName() + "'");
667 if (!parser.getName().equals("manifest")) {
668 outError[0] = "No <manifest> tag";
669 return null;
670 }
671 String pkgName = attrs.getAttributeValue(null, "package");
672 if (pkgName == null || pkgName.length() == 0) {
673 outError[0] = "<manifest> does not specify package";
674 return null;
675 }
676 String nameError = validateName(pkgName, true);
677 if (nameError != null && !"android".equals(pkgName)) {
678 outError[0] = "<manifest> specifies bad package name \""
679 + pkgName + "\": " + nameError;
680 return null;
681 }
682
683 return pkgName.intern();
684 }
685
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800686 private static PackageLite parsePackageLite(XmlPullParser parser,
687 AttributeSet attrs, int flags, String[] outError)
688 throws IOException, XmlPullParserException {
689
690 int type;
691 while ((type=parser.next()) != parser.START_TAG
692 && type != parser.END_DOCUMENT) {
693 ;
694 }
695
696 if (type != parser.START_TAG) {
697 outError[0] = "No start tag found";
698 return null;
699 }
700 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
701 TAG, "Root element name: '" + parser.getName() + "'");
702 if (!parser.getName().equals("manifest")) {
703 outError[0] = "No <manifest> tag";
704 return null;
705 }
706 String pkgName = attrs.getAttributeValue(null, "package");
707 if (pkgName == null || pkgName.length() == 0) {
708 outError[0] = "<manifest> does not specify package";
709 return null;
710 }
711 String nameError = validateName(pkgName, true);
712 if (nameError != null && !"android".equals(pkgName)) {
713 outError[0] = "<manifest> specifies bad package name \""
714 + pkgName + "\": " + nameError;
715 return null;
716 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700717 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800718 for (int i = 0; i < attrs.getAttributeCount(); i++) {
719 String attr = attrs.getAttributeName(i);
720 if (attr.equals("installLocation")) {
721 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700722 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800723 break;
724 }
725 }
726 return new PackageLite(pkgName.intern(), installLocation);
727 }
728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 /**
730 * Temporary.
731 */
732 static public Signature stringToSignature(String str) {
733 final int N = str.length();
734 byte[] sig = new byte[N];
735 for (int i=0; i<N; i++) {
736 sig[i] = (byte)str.charAt(i);
737 }
738 return new Signature(sig);
739 }
740
741 private Package parsePackage(
742 Resources res, XmlResourceParser parser, int flags, String[] outError)
743 throws XmlPullParserException, IOException {
744 AttributeSet attrs = parser;
745
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700746 mParseInstrumentationArgs = null;
747 mParseActivityArgs = null;
748 mParseServiceArgs = null;
749 mParseProviderArgs = null;
750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 String pkgName = parsePackageName(parser, attrs, flags, outError);
752 if (pkgName == null) {
753 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
754 return null;
755 }
756 int type;
757
758 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 TypedArray sa = res.obtainAttributes(attrs,
762 com.android.internal.R.styleable.AndroidManifest);
763 pkg.mVersionCode = sa.getInteger(
764 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800765 pkg.mVersionName = sa.getNonConfigurationString(
766 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 if (pkg.mVersionName != null) {
768 pkg.mVersionName = pkg.mVersionName.intern();
769 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800770 String str = sa.getNonConfigurationString(
771 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
772 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 String nameError = validateName(str, true);
774 if (nameError != null && !"android".equals(pkgName)) {
775 outError[0] = "<manifest> specifies bad sharedUserId name \""
776 + str + "\": " + nameError;
777 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
778 return null;
779 }
780 pkg.mSharedUserId = str.intern();
781 pkg.mSharedUserLabel = sa.getResourceId(
782 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
783 }
784 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800785
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800786 pkg.installLocation = sa.getInteger(
787 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700788 PARSE_DEFAULT_INSTALL_LOCATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789
Dianne Hackborn723738c2009-06-25 19:48:04 -0700790 // Resource boolean are -1, so 1 means we don't know the value.
791 int supportsSmallScreens = 1;
792 int supportsNormalScreens = 1;
793 int supportsLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700794 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700795 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 int outerDepth = parser.getDepth();
798 while ((type=parser.next()) != parser.END_DOCUMENT
799 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
800 if (type == parser.END_TAG || type == parser.TEXT) {
801 continue;
802 }
803
804 String tagName = parser.getName();
805 if (tagName.equals("application")) {
806 if (foundApp) {
807 if (RIGID_PARSER) {
808 outError[0] = "<manifest> has more than one <application>";
809 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
810 return null;
811 } else {
812 Log.w(TAG, "<manifest> has more than one <application>");
813 XmlUtils.skipCurrentTag(parser);
814 continue;
815 }
816 }
817
818 foundApp = true;
819 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
820 return null;
821 }
822 } else if (tagName.equals("permission-group")) {
823 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
824 return null;
825 }
826 } else if (tagName.equals("permission")) {
827 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
828 return null;
829 }
830 } else if (tagName.equals("permission-tree")) {
831 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
832 return null;
833 }
834 } else if (tagName.equals("uses-permission")) {
835 sa = res.obtainAttributes(attrs,
836 com.android.internal.R.styleable.AndroidManifestUsesPermission);
837
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800838 // Note: don't allow this value to be a reference to a resource
839 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 String name = sa.getNonResourceString(
841 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
842
843 sa.recycle();
844
845 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700846 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
848
849 XmlUtils.skipCurrentTag(parser);
850
851 } else if (tagName.equals("uses-configuration")) {
852 ConfigurationInfo cPref = new ConfigurationInfo();
853 sa = res.obtainAttributes(attrs,
854 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
855 cPref.reqTouchScreen = sa.getInt(
856 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
857 Configuration.TOUCHSCREEN_UNDEFINED);
858 cPref.reqKeyboardType = sa.getInt(
859 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
860 Configuration.KEYBOARD_UNDEFINED);
861 if (sa.getBoolean(
862 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
863 false)) {
864 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
865 }
866 cPref.reqNavigation = sa.getInt(
867 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
868 Configuration.NAVIGATION_UNDEFINED);
869 if (sa.getBoolean(
870 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
871 false)) {
872 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
873 }
874 sa.recycle();
875 pkg.configPreferences.add(cPref);
876
877 XmlUtils.skipCurrentTag(parser);
878
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700879 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700880 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700881 sa = res.obtainAttributes(attrs,
882 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800883 // Note: don't allow this value to be a reference to a resource
884 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700885 fi.name = sa.getNonResourceString(
886 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
887 if (fi.name == null) {
888 fi.reqGlEsVersion = sa.getInt(
889 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
890 FeatureInfo.GL_ES_VERSION_UNDEFINED);
891 }
892 if (sa.getBoolean(
893 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
894 true)) {
895 fi.flags |= FeatureInfo.FLAG_REQUIRED;
896 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700897 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700898 if (pkg.reqFeatures == null) {
899 pkg.reqFeatures = new ArrayList<FeatureInfo>();
900 }
901 pkg.reqFeatures.add(fi);
902
903 if (fi.name == null) {
904 ConfigurationInfo cPref = new ConfigurationInfo();
905 cPref.reqGlEsVersion = fi.reqGlEsVersion;
906 pkg.configPreferences.add(cPref);
907 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700908
909 XmlUtils.skipCurrentTag(parser);
910
Dianne Hackborn851a5412009-05-08 12:06:44 -0700911 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700912 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 sa = res.obtainAttributes(attrs,
914 com.android.internal.R.styleable.AndroidManifestUsesSdk);
915
Dianne Hackborn851a5412009-05-08 12:06:44 -0700916 int minVers = 0;
917 String minCode = null;
918 int targetVers = 0;
919 String targetCode = null;
920
921 TypedValue val = sa.peekValue(
922 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
923 if (val != null) {
924 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
925 targetCode = minCode = val.string.toString();
926 } else {
927 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700928 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700929 }
930 }
931
932 val = sa.peekValue(
933 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
934 if (val != null) {
935 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
936 targetCode = minCode = val.string.toString();
937 } else {
938 // If it's not a string, it's an integer.
939 targetVers = val.data;
940 }
941 }
942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 sa.recycle();
944
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700945 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700946 if (!minCode.equals(SDK_CODENAME)) {
947 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700948 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700949 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700950 } else {
951 outError[0] = "Requires development platform " + minCode
952 + " but this is a release platform.";
953 }
954 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
955 return null;
956 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700957 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700958 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700959 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700960 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
961 return null;
962 }
963
Dianne Hackborn851a5412009-05-08 12:06:44 -0700964 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700965 if (!targetCode.equals(SDK_CODENAME)) {
966 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700967 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700968 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700969 } else {
970 outError[0] = "Requires development platform " + targetCode
971 + " but this is a release platform.";
972 }
973 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
974 return null;
975 }
976 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700977 pkg.applicationInfo.targetSdkVersion
978 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
979 } else {
980 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700981 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 }
983
984 XmlUtils.skipCurrentTag(parser);
985
Dianne Hackborn723738c2009-06-25 19:48:04 -0700986 } else if (tagName.equals("supports-screens")) {
987 sa = res.obtainAttributes(attrs,
988 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
989
990 // This is a trick to get a boolean and still able to detect
991 // if a value was actually set.
992 supportsSmallScreens = sa.getInteger(
993 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
994 supportsSmallScreens);
995 supportsNormalScreens = sa.getInteger(
996 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
997 supportsNormalScreens);
998 supportsLargeScreens = sa.getInteger(
999 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1000 supportsLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001001 resizeable = sa.getInteger(
1002 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
1003 supportsLargeScreens);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001004 anyDensity = sa.getInteger(
1005 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1006 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001007
1008 sa.recycle();
1009
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001010 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001011
1012 } else if (tagName.equals("protected-broadcast")) {
1013 sa = res.obtainAttributes(attrs,
1014 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1015
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001016 // Note: don't allow this value to be a reference to a resource
1017 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001018 String name = sa.getNonResourceString(
1019 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1020
1021 sa.recycle();
1022
1023 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1024 if (pkg.protectedBroadcasts == null) {
1025 pkg.protectedBroadcasts = new ArrayList<String>();
1026 }
1027 if (!pkg.protectedBroadcasts.contains(name)) {
1028 pkg.protectedBroadcasts.add(name.intern());
1029 }
1030 }
1031
1032 XmlUtils.skipCurrentTag(parser);
1033
1034 } else if (tagName.equals("instrumentation")) {
1035 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1036 return null;
1037 }
1038
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001039 } else if (tagName.equals("original-package")) {
1040 sa = res.obtainAttributes(attrs,
1041 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1042
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001043 String orig =sa.getNonConfigurationString(
1044 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001045 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001046 if (pkg.mOriginalPackages == null) {
1047 pkg.mOriginalPackages = new ArrayList<String>();
1048 pkg.mRealPackage = pkg.packageName;
1049 }
1050 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001051 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001052
1053 sa.recycle();
1054
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001055 XmlUtils.skipCurrentTag(parser);
1056
1057 } else if (tagName.equals("adopt-permissions")) {
1058 sa = res.obtainAttributes(attrs,
1059 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1060
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001061 String name = sa.getNonConfigurationString(
1062 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001063
1064 sa.recycle();
1065
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001066 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001067 if (pkg.mAdoptPermissions == null) {
1068 pkg.mAdoptPermissions = new ArrayList<String>();
1069 }
1070 pkg.mAdoptPermissions.add(name);
1071 }
1072
1073 XmlUtils.skipCurrentTag(parser);
1074
Dianne Hackborn854060a2009-07-09 18:14:31 -07001075 } else if (tagName.equals("eat-comment")) {
1076 // Just skip this tag
1077 XmlUtils.skipCurrentTag(parser);
1078 continue;
1079
1080 } else if (RIGID_PARSER) {
1081 outError[0] = "Bad element under <manifest>: "
1082 + parser.getName();
1083 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1084 return null;
1085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001087 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
1088 + " at " + mArchiveSourcePath + " "
1089 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 XmlUtils.skipCurrentTag(parser);
1091 continue;
1092 }
1093 }
1094
1095 if (!foundApp && pkg.instrumentation.size() == 0) {
1096 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1097 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1098 }
1099
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001100 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001101 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001102 for (int ip=0; ip<NP; ip++) {
1103 final PackageParser.NewPermissionInfo npi
1104 = PackageParser.NEW_PERMISSIONS[ip];
1105 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1106 break;
1107 }
1108 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001109 if (implicitPerms == null) {
1110 implicitPerms = new StringBuilder(128);
1111 implicitPerms.append(pkg.packageName);
1112 implicitPerms.append(": compat added ");
1113 } else {
1114 implicitPerms.append(' ');
1115 }
1116 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001117 pkg.requestedPermissions.add(npi.name);
1118 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001119 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001120 if (implicitPerms != null) {
1121 Log.i(TAG, implicitPerms.toString());
1122 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001123
Dianne Hackborn723738c2009-06-25 19:48:04 -07001124 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1125 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001126 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001127 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1128 }
1129 if (supportsNormalScreens != 0) {
1130 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1131 }
1132 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1133 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001134 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001135 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1136 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001137 if (resizeable < 0 || (resizeable > 0
1138 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001139 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001140 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1141 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001142 if (anyDensity < 0 || (anyDensity > 0
1143 && pkg.applicationInfo.targetSdkVersion
1144 >= android.os.Build.VERSION_CODES.DONUT)) {
1145 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001146 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 return pkg;
1149 }
1150
1151 private static String buildClassName(String pkg, CharSequence clsSeq,
1152 String[] outError) {
1153 if (clsSeq == null || clsSeq.length() <= 0) {
1154 outError[0] = "Empty class name in package " + pkg;
1155 return null;
1156 }
1157 String cls = clsSeq.toString();
1158 char c = cls.charAt(0);
1159 if (c == '.') {
1160 return (pkg + cls).intern();
1161 }
1162 if (cls.indexOf('.') < 0) {
1163 StringBuilder b = new StringBuilder(pkg);
1164 b.append('.');
1165 b.append(cls);
1166 return b.toString().intern();
1167 }
1168 if (c >= 'a' && c <= 'z') {
1169 return cls.intern();
1170 }
1171 outError[0] = "Bad class name " + cls + " in package " + pkg;
1172 return null;
1173 }
1174
1175 private static String buildCompoundName(String pkg,
1176 CharSequence procSeq, String type, String[] outError) {
1177 String proc = procSeq.toString();
1178 char c = proc.charAt(0);
1179 if (pkg != null && c == ':') {
1180 if (proc.length() < 2) {
1181 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1182 + ": must be at least two characters";
1183 return null;
1184 }
1185 String subName = proc.substring(1);
1186 String nameError = validateName(subName, false);
1187 if (nameError != null) {
1188 outError[0] = "Invalid " + type + " name " + proc + " in package "
1189 + pkg + ": " + nameError;
1190 return null;
1191 }
1192 return (pkg + proc).intern();
1193 }
1194 String nameError = validateName(proc, true);
1195 if (nameError != null && !"system".equals(proc)) {
1196 outError[0] = "Invalid " + type + " name " + proc + " in package "
1197 + pkg + ": " + nameError;
1198 return null;
1199 }
1200 return proc.intern();
1201 }
1202
1203 private static String buildProcessName(String pkg, String defProc,
1204 CharSequence procSeq, int flags, String[] separateProcesses,
1205 String[] outError) {
1206 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1207 return defProc != null ? defProc : pkg;
1208 }
1209 if (separateProcesses != null) {
1210 for (int i=separateProcesses.length-1; i>=0; i--) {
1211 String sp = separateProcesses[i];
1212 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1213 return pkg;
1214 }
1215 }
1216 }
1217 if (procSeq == null || procSeq.length() <= 0) {
1218 return defProc;
1219 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001220 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
1222
1223 private static String buildTaskAffinityName(String pkg, String defProc,
1224 CharSequence procSeq, String[] outError) {
1225 if (procSeq == null) {
1226 return defProc;
1227 }
1228 if (procSeq.length() <= 0) {
1229 return null;
1230 }
1231 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1232 }
1233
1234 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1235 XmlPullParser parser, AttributeSet attrs, String[] outError)
1236 throws XmlPullParserException, IOException {
1237 PermissionGroup perm = new PermissionGroup(owner);
1238
1239 TypedArray sa = res.obtainAttributes(attrs,
1240 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1241
1242 if (!parsePackageItemInfo(owner, perm.info, outError,
1243 "<permission-group>", sa,
1244 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1245 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001246 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1247 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 sa.recycle();
1249 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1250 return null;
1251 }
1252
1253 perm.info.descriptionRes = sa.getResourceId(
1254 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1255 0);
1256
1257 sa.recycle();
1258
1259 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1260 outError)) {
1261 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1262 return null;
1263 }
1264
1265 owner.permissionGroups.add(perm);
1266
1267 return perm;
1268 }
1269
1270 private Permission parsePermission(Package owner, Resources res,
1271 XmlPullParser parser, AttributeSet attrs, String[] outError)
1272 throws XmlPullParserException, IOException {
1273 Permission perm = new Permission(owner);
1274
1275 TypedArray sa = res.obtainAttributes(attrs,
1276 com.android.internal.R.styleable.AndroidManifestPermission);
1277
1278 if (!parsePackageItemInfo(owner, perm.info, outError,
1279 "<permission>", sa,
1280 com.android.internal.R.styleable.AndroidManifestPermission_name,
1281 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001282 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1283 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 sa.recycle();
1285 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1286 return null;
1287 }
1288
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001289 // Note: don't allow this value to be a reference to a resource
1290 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 perm.info.group = sa.getNonResourceString(
1292 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1293 if (perm.info.group != null) {
1294 perm.info.group = perm.info.group.intern();
1295 }
1296
1297 perm.info.descriptionRes = sa.getResourceId(
1298 com.android.internal.R.styleable.AndroidManifestPermission_description,
1299 0);
1300
1301 perm.info.protectionLevel = sa.getInt(
1302 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1303 PermissionInfo.PROTECTION_NORMAL);
1304
1305 sa.recycle();
1306
1307 if (perm.info.protectionLevel == -1) {
1308 outError[0] = "<permission> does not specify protectionLevel";
1309 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1310 return null;
1311 }
1312
1313 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1314 outError)) {
1315 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1316 return null;
1317 }
1318
1319 owner.permissions.add(perm);
1320
1321 return perm;
1322 }
1323
1324 private Permission parsePermissionTree(Package owner, Resources res,
1325 XmlPullParser parser, AttributeSet attrs, String[] outError)
1326 throws XmlPullParserException, IOException {
1327 Permission perm = new Permission(owner);
1328
1329 TypedArray sa = res.obtainAttributes(attrs,
1330 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1331
1332 if (!parsePackageItemInfo(owner, perm.info, outError,
1333 "<permission-tree>", sa,
1334 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1335 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001336 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1337 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 sa.recycle();
1339 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1340 return null;
1341 }
1342
1343 sa.recycle();
1344
1345 int index = perm.info.name.indexOf('.');
1346 if (index > 0) {
1347 index = perm.info.name.indexOf('.', index+1);
1348 }
1349 if (index < 0) {
1350 outError[0] = "<permission-tree> name has less than three segments: "
1351 + perm.info.name;
1352 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1353 return null;
1354 }
1355
1356 perm.info.descriptionRes = 0;
1357 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1358 perm.tree = true;
1359
1360 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1361 outError)) {
1362 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1363 return null;
1364 }
1365
1366 owner.permissions.add(perm);
1367
1368 return perm;
1369 }
1370
1371 private Instrumentation parseInstrumentation(Package owner, Resources res,
1372 XmlPullParser parser, AttributeSet attrs, String[] outError)
1373 throws XmlPullParserException, IOException {
1374 TypedArray sa = res.obtainAttributes(attrs,
1375 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1376
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001377 if (mParseInstrumentationArgs == null) {
1378 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1379 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1380 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001381 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1382 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001383 mParseInstrumentationArgs.tag = "<instrumentation>";
1384 }
1385
1386 mParseInstrumentationArgs.sa = sa;
1387
1388 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1389 new InstrumentationInfo());
1390 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 sa.recycle();
1392 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1393 return null;
1394 }
1395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001397 // Note: don't allow this value to be a reference to a resource
1398 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 str = sa.getNonResourceString(
1400 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1401 a.info.targetPackage = str != null ? str.intern() : null;
1402
1403 a.info.handleProfiling = sa.getBoolean(
1404 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1405 false);
1406
1407 a.info.functionalTest = sa.getBoolean(
1408 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1409 false);
1410
1411 sa.recycle();
1412
1413 if (a.info.targetPackage == null) {
1414 outError[0] = "<instrumentation> does not specify targetPackage";
1415 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1416 return null;
1417 }
1418
1419 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1420 outError)) {
1421 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1422 return null;
1423 }
1424
1425 owner.instrumentation.add(a);
1426
1427 return a;
1428 }
1429
1430 private boolean parseApplication(Package owner, Resources res,
1431 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1432 throws XmlPullParserException, IOException {
1433 final ApplicationInfo ai = owner.applicationInfo;
1434 final String pkgName = owner.applicationInfo.packageName;
1435
1436 TypedArray sa = res.obtainAttributes(attrs,
1437 com.android.internal.R.styleable.AndroidManifestApplication);
1438
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001439 String name = sa.getNonConfigurationString(
1440 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 if (name != null) {
1442 ai.className = buildClassName(pkgName, name, outError);
1443 if (ai.className == null) {
1444 sa.recycle();
1445 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1446 return false;
1447 }
1448 }
1449
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001450 String manageSpaceActivity = sa.getNonConfigurationString(
1451 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 if (manageSpaceActivity != null) {
1453 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1454 outError);
1455 }
1456
Christopher Tate181fafa2009-05-14 11:12:14 -07001457 boolean allowBackup = sa.getBoolean(
1458 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1459 if (allowBackup) {
1460 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001461
Christopher Tate3de55bc2010-03-12 17:28:08 -08001462 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1463 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001464 String backupAgent = sa.getNonConfigurationString(
1465 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001466 if (backupAgent != null) {
1467 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001468 if (false) {
1469 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1470 + " from " + pkgName + "+" + backupAgent);
1471 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001472
1473 if (sa.getBoolean(
1474 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1475 true)) {
1476 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1477 }
1478 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001479 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1480 false)) {
1481 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1482 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001483 }
1484 }
1485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 TypedValue v = sa.peekValue(
1487 com.android.internal.R.styleable.AndroidManifestApplication_label);
1488 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1489 ai.nonLocalizedLabel = v.coerceToString();
1490 }
1491
1492 ai.icon = sa.getResourceId(
1493 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001494 ai.logo = sa.getResourceId(
1495 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 ai.theme = sa.getResourceId(
1497 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1498 ai.descriptionRes = sa.getResourceId(
1499 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1500
1501 if ((flags&PARSE_IS_SYSTEM) != 0) {
1502 if (sa.getBoolean(
1503 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1504 false)) {
1505 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1506 }
1507 }
1508
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001509 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1510 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1511 }
1512
1513 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001514 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001515 }
1516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 if (sa.getBoolean(
1518 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1519 false)) {
1520 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1521 }
1522
1523 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001524 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001525 false)) {
1526 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1527 }
1528
1529 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1531 true)) {
1532 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1533 }
1534
1535 if (sa.getBoolean(
1536 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1537 false)) {
1538 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1539 }
1540
1541 if (sa.getBoolean(
1542 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1543 true)) {
1544 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1545 }
1546
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001547 if (sa.getBoolean(
1548 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001549 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001550 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1551 }
1552
Oscar Montemayor1874aa42009-11-10 18:35:33 -08001553 if (sa.getBoolean(
1554 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt,
1555 false)) {
1556 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT;
1557 }
1558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001560 str = sa.getNonConfigurationString(
1561 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1563
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001564 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1565 str = sa.getNonConfigurationString(
1566 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1567 } else {
1568 // Some older apps have been seen to use a resource reference
1569 // here that on older builds was ignored (with a warning). We
1570 // need to continue to do this for them so they don't break.
1571 str = sa.getNonResourceString(
1572 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1575 str, outError);
1576
1577 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001578 CharSequence pname;
1579 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1580 pname = sa.getNonConfigurationString(
1581 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1582 } else {
1583 // Some older apps have been seen to use a resource reference
1584 // here that on older builds was ignored (with a warning). We
1585 // need to continue to do this for them so they don't break.
1586 pname = sa.getNonResourceString(
1587 com.android.internal.R.styleable.AndroidManifestApplication_process);
1588 }
1589 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 flags, mSeparateProcesses, outError);
1591
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001592 ai.enabled = sa.getBoolean(
1593 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 }
1595
1596 sa.recycle();
1597
1598 if (outError[0] != null) {
1599 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1600 return false;
1601 }
1602
1603 final int innerDepth = parser.getDepth();
1604
1605 int type;
1606 while ((type=parser.next()) != parser.END_DOCUMENT
1607 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1608 if (type == parser.END_TAG || type == parser.TEXT) {
1609 continue;
1610 }
1611
1612 String tagName = parser.getName();
1613 if (tagName.equals("activity")) {
1614 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1615 if (a == null) {
1616 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1617 return false;
1618 }
1619
1620 owner.activities.add(a);
1621
1622 } else if (tagName.equals("receiver")) {
1623 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1624 if (a == null) {
1625 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1626 return false;
1627 }
1628
1629 owner.receivers.add(a);
1630
1631 } else if (tagName.equals("service")) {
1632 Service s = parseService(owner, res, parser, attrs, flags, outError);
1633 if (s == null) {
1634 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1635 return false;
1636 }
1637
1638 owner.services.add(s);
1639
1640 } else if (tagName.equals("provider")) {
1641 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1642 if (p == null) {
1643 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1644 return false;
1645 }
1646
1647 owner.providers.add(p);
1648
1649 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001650 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 if (a == null) {
1652 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1653 return false;
1654 }
1655
1656 owner.activities.add(a);
1657
1658 } else if (parser.getName().equals("meta-data")) {
1659 // note: application meta-data is stored off to the side, so it can
1660 // remain null in the primary copy (we like to avoid extra copies because
1661 // it can be large)
1662 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1663 outError)) == null) {
1664 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1665 return false;
1666 }
1667
1668 } else if (tagName.equals("uses-library")) {
1669 sa = res.obtainAttributes(attrs,
1670 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1671
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001672 // Note: don't allow this value to be a reference to a resource
1673 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 String lname = sa.getNonResourceString(
1675 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001676 boolean req = sa.getBoolean(
1677 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1678 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679
1680 sa.recycle();
1681
Dianne Hackborn49237342009-08-27 20:08:01 -07001682 if (lname != null) {
1683 if (req) {
1684 if (owner.usesLibraries == null) {
1685 owner.usesLibraries = new ArrayList<String>();
1686 }
1687 if (!owner.usesLibraries.contains(lname)) {
1688 owner.usesLibraries.add(lname.intern());
1689 }
1690 } else {
1691 if (owner.usesOptionalLibraries == null) {
1692 owner.usesOptionalLibraries = new ArrayList<String>();
1693 }
1694 if (!owner.usesOptionalLibraries.contains(lname)) {
1695 owner.usesOptionalLibraries.add(lname.intern());
1696 }
1697 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 }
1699
1700 XmlUtils.skipCurrentTag(parser);
1701
1702 } else {
1703 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001704 Log.w(TAG, "Unknown element under <application>: " + tagName
1705 + " at " + mArchiveSourcePath + " "
1706 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 XmlUtils.skipCurrentTag(parser);
1708 continue;
1709 } else {
1710 outError[0] = "Bad element under <application>: " + tagName;
1711 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1712 return false;
1713 }
1714 }
1715 }
1716
1717 return true;
1718 }
1719
1720 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1721 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001722 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001723 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 if (name == null) {
1725 outError[0] = tag + " does not specify android:name";
1726 return false;
1727 }
1728
1729 outInfo.name
1730 = buildClassName(owner.applicationInfo.packageName, name, outError);
1731 if (outInfo.name == null) {
1732 return false;
1733 }
1734
1735 int iconVal = sa.getResourceId(iconRes, 0);
1736 if (iconVal != 0) {
1737 outInfo.icon = iconVal;
1738 outInfo.nonLocalizedLabel = null;
1739 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001740
1741 int logoVal = sa.getResourceId(logoRes, 0);
1742 if (logoVal != 0) {
1743 outInfo.logo = logoVal;
1744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001745
1746 TypedValue v = sa.peekValue(labelRes);
1747 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1748 outInfo.nonLocalizedLabel = v.coerceToString();
1749 }
1750
1751 outInfo.packageName = owner.packageName;
1752
1753 return true;
1754 }
1755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 private Activity parseActivity(Package owner, Resources res,
1757 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1758 boolean receiver) throws XmlPullParserException, IOException {
1759 TypedArray sa = res.obtainAttributes(attrs,
1760 com.android.internal.R.styleable.AndroidManifestActivity);
1761
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001762 if (mParseActivityArgs == null) {
1763 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1764 com.android.internal.R.styleable.AndroidManifestActivity_name,
1765 com.android.internal.R.styleable.AndroidManifestActivity_label,
1766 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001767 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001768 mSeparateProcesses,
1769 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001770 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001771 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1772 }
1773
1774 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1775 mParseActivityArgs.sa = sa;
1776 mParseActivityArgs.flags = flags;
1777
1778 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1779 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 sa.recycle();
1781 return null;
1782 }
1783
1784 final boolean setExported = sa.hasValue(
1785 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1786 if (setExported) {
1787 a.info.exported = sa.getBoolean(
1788 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1789 }
1790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 a.info.theme = sa.getResourceId(
1792 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1793
1794 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001795 str = sa.getNonConfigurationString(
1796 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 if (str == null) {
1798 a.info.permission = owner.applicationInfo.permission;
1799 } else {
1800 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1801 }
1802
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001803 str = sa.getNonConfigurationString(
1804 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1806 owner.applicationInfo.taskAffinity, str, outError);
1807
1808 a.info.flags = 0;
1809 if (sa.getBoolean(
1810 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1811 false)) {
1812 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1813 }
1814
1815 if (sa.getBoolean(
1816 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1817 false)) {
1818 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1819 }
1820
1821 if (sa.getBoolean(
1822 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1823 false)) {
1824 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1825 }
1826
1827 if (sa.getBoolean(
1828 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1829 false)) {
1830 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1831 }
1832
1833 if (sa.getBoolean(
1834 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1835 false)) {
1836 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1837 }
1838
1839 if (sa.getBoolean(
1840 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1841 false)) {
1842 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1843 }
1844
1845 if (sa.getBoolean(
1846 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1847 false)) {
1848 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1849 }
1850
1851 if (sa.getBoolean(
1852 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1853 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1854 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1855 }
1856
Dianne Hackbornffa42482009-09-23 22:20:11 -07001857 if (sa.getBoolean(
1858 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1859 false)) {
1860 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1861 }
1862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 if (!receiver) {
1864 a.info.launchMode = sa.getInt(
1865 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1866 ActivityInfo.LAUNCH_MULTIPLE);
1867 a.info.screenOrientation = sa.getInt(
1868 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1869 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1870 a.info.configChanges = sa.getInt(
1871 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1872 0);
1873 a.info.softInputMode = sa.getInt(
1874 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1875 0);
1876 } else {
1877 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1878 a.info.configChanges = 0;
1879 }
1880
1881 sa.recycle();
1882
1883 if (outError[0] != null) {
1884 return null;
1885 }
1886
1887 int outerDepth = parser.getDepth();
1888 int type;
1889 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1890 && (type != XmlPullParser.END_TAG
1891 || parser.getDepth() > outerDepth)) {
1892 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1893 continue;
1894 }
1895
1896 if (parser.getName().equals("intent-filter")) {
1897 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1898 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1899 return null;
1900 }
1901 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001902 Log.w(TAG, "No actions in intent filter at "
1903 + mArchiveSourcePath + " "
1904 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 } else {
1906 a.intents.add(intent);
1907 }
1908 } else if (parser.getName().equals("meta-data")) {
1909 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1910 outError)) == null) {
1911 return null;
1912 }
1913 } else {
1914 if (!RIGID_PARSER) {
1915 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1916 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001917 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1918 + " at " + mArchiveSourcePath + " "
1919 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001921 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1922 + " at " + mArchiveSourcePath + " "
1923 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 }
1925 XmlUtils.skipCurrentTag(parser);
1926 continue;
1927 }
1928 if (receiver) {
1929 outError[0] = "Bad element under <receiver>: " + parser.getName();
1930 } else {
1931 outError[0] = "Bad element under <activity>: " + parser.getName();
1932 }
1933 return null;
1934 }
1935 }
1936
1937 if (!setExported) {
1938 a.info.exported = a.intents.size() > 0;
1939 }
1940
1941 return a;
1942 }
1943
1944 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001945 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1946 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 TypedArray sa = res.obtainAttributes(attrs,
1948 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1949
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001950 String targetActivity = sa.getNonConfigurationString(
1951 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 if (targetActivity == null) {
1953 outError[0] = "<activity-alias> does not specify android:targetActivity";
1954 sa.recycle();
1955 return null;
1956 }
1957
1958 targetActivity = buildClassName(owner.applicationInfo.packageName,
1959 targetActivity, outError);
1960 if (targetActivity == null) {
1961 sa.recycle();
1962 return null;
1963 }
1964
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001965 if (mParseActivityAliasArgs == null) {
1966 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1967 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1968 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
1969 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001970 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001971 mSeparateProcesses,
1972 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001973 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001974 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1975 mParseActivityAliasArgs.tag = "<activity-alias>";
1976 }
1977
1978 mParseActivityAliasArgs.sa = sa;
1979 mParseActivityAliasArgs.flags = flags;
1980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 Activity target = null;
1982
1983 final int NA = owner.activities.size();
1984 for (int i=0; i<NA; i++) {
1985 Activity t = owner.activities.get(i);
1986 if (targetActivity.equals(t.info.name)) {
1987 target = t;
1988 break;
1989 }
1990 }
1991
1992 if (target == null) {
1993 outError[0] = "<activity-alias> target activity " + targetActivity
1994 + " not found in manifest";
1995 sa.recycle();
1996 return null;
1997 }
1998
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001999 ActivityInfo info = new ActivityInfo();
2000 info.targetActivity = targetActivity;
2001 info.configChanges = target.info.configChanges;
2002 info.flags = target.info.flags;
2003 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002004 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002005 info.labelRes = target.info.labelRes;
2006 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2007 info.launchMode = target.info.launchMode;
2008 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002009 if (info.descriptionRes == 0) {
2010 info.descriptionRes = target.info.descriptionRes;
2011 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002012 info.screenOrientation = target.info.screenOrientation;
2013 info.taskAffinity = target.info.taskAffinity;
2014 info.theme = target.info.theme;
2015
2016 Activity a = new Activity(mParseActivityAliasArgs, info);
2017 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 sa.recycle();
2019 return null;
2020 }
2021
2022 final boolean setExported = sa.hasValue(
2023 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2024 if (setExported) {
2025 a.info.exported = sa.getBoolean(
2026 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2027 }
2028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002030 str = sa.getNonConfigurationString(
2031 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 if (str != null) {
2033 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2034 }
2035
2036 sa.recycle();
2037
2038 if (outError[0] != null) {
2039 return null;
2040 }
2041
2042 int outerDepth = parser.getDepth();
2043 int type;
2044 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2045 && (type != XmlPullParser.END_TAG
2046 || parser.getDepth() > outerDepth)) {
2047 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2048 continue;
2049 }
2050
2051 if (parser.getName().equals("intent-filter")) {
2052 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2053 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2054 return null;
2055 }
2056 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002057 Log.w(TAG, "No actions in intent filter at "
2058 + mArchiveSourcePath + " "
2059 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 } else {
2061 a.intents.add(intent);
2062 }
2063 } else if (parser.getName().equals("meta-data")) {
2064 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2065 outError)) == null) {
2066 return null;
2067 }
2068 } else {
2069 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002070 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2071 + " at " + mArchiveSourcePath + " "
2072 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 XmlUtils.skipCurrentTag(parser);
2074 continue;
2075 }
2076 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2077 return null;
2078 }
2079 }
2080
2081 if (!setExported) {
2082 a.info.exported = a.intents.size() > 0;
2083 }
2084
2085 return a;
2086 }
2087
2088 private Provider parseProvider(Package owner, Resources res,
2089 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2090 throws XmlPullParserException, IOException {
2091 TypedArray sa = res.obtainAttributes(attrs,
2092 com.android.internal.R.styleable.AndroidManifestProvider);
2093
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002094 if (mParseProviderArgs == null) {
2095 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2096 com.android.internal.R.styleable.AndroidManifestProvider_name,
2097 com.android.internal.R.styleable.AndroidManifestProvider_label,
2098 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002099 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002100 mSeparateProcesses,
2101 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002102 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002103 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2104 mParseProviderArgs.tag = "<provider>";
2105 }
2106
2107 mParseProviderArgs.sa = sa;
2108 mParseProviderArgs.flags = flags;
2109
2110 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2111 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 sa.recycle();
2113 return null;
2114 }
2115
2116 p.info.exported = sa.getBoolean(
2117 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2118
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002119 String cpname = sa.getNonConfigurationString(
2120 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121
2122 p.info.isSyncable = sa.getBoolean(
2123 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2124 false);
2125
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002126 String permission = sa.getNonConfigurationString(
2127 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2128 String str = sa.getNonConfigurationString(
2129 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 if (str == null) {
2131 str = permission;
2132 }
2133 if (str == null) {
2134 p.info.readPermission = owner.applicationInfo.permission;
2135 } else {
2136 p.info.readPermission =
2137 str.length() > 0 ? str.toString().intern() : null;
2138 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002139 str = sa.getNonConfigurationString(
2140 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 if (str == null) {
2142 str = permission;
2143 }
2144 if (str == null) {
2145 p.info.writePermission = owner.applicationInfo.permission;
2146 } else {
2147 p.info.writePermission =
2148 str.length() > 0 ? str.toString().intern() : null;
2149 }
2150
2151 p.info.grantUriPermissions = sa.getBoolean(
2152 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2153 false);
2154
2155 p.info.multiprocess = sa.getBoolean(
2156 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2157 false);
2158
2159 p.info.initOrder = sa.getInt(
2160 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2161 0);
2162
2163 sa.recycle();
2164
2165 if (cpname == null) {
2166 outError[0] = "<provider> does not incude authorities attribute";
2167 return null;
2168 }
2169 p.info.authority = cpname.intern();
2170
2171 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2172 return null;
2173 }
2174
2175 return p;
2176 }
2177
2178 private boolean parseProviderTags(Resources res,
2179 XmlPullParser parser, AttributeSet attrs,
2180 Provider outInfo, String[] outError)
2181 throws XmlPullParserException, IOException {
2182 int outerDepth = parser.getDepth();
2183 int type;
2184 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2185 && (type != XmlPullParser.END_TAG
2186 || parser.getDepth() > outerDepth)) {
2187 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2188 continue;
2189 }
2190
2191 if (parser.getName().equals("meta-data")) {
2192 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2193 outInfo.metaData, outError)) == null) {
2194 return false;
2195 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 } else if (parser.getName().equals("grant-uri-permission")) {
2198 TypedArray sa = res.obtainAttributes(attrs,
2199 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2200
2201 PatternMatcher pa = null;
2202
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002203 String str = sa.getNonConfigurationString(
2204 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 if (str != null) {
2206 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2207 }
2208
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002209 str = sa.getNonConfigurationString(
2210 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 if (str != null) {
2212 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2213 }
2214
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002215 str = sa.getNonConfigurationString(
2216 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 if (str != null) {
2218 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2219 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 sa.recycle();
2222
2223 if (pa != null) {
2224 if (outInfo.info.uriPermissionPatterns == null) {
2225 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2226 outInfo.info.uriPermissionPatterns[0] = pa;
2227 } else {
2228 final int N = outInfo.info.uriPermissionPatterns.length;
2229 PatternMatcher[] newp = new PatternMatcher[N+1];
2230 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2231 newp[N] = pa;
2232 outInfo.info.uriPermissionPatterns = newp;
2233 }
2234 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002235 } else {
2236 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002237 Log.w(TAG, "Unknown element under <path-permission>: "
2238 + parser.getName() + " at " + mArchiveSourcePath + " "
2239 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002240 XmlUtils.skipCurrentTag(parser);
2241 continue;
2242 }
2243 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2244 return false;
2245 }
2246 XmlUtils.skipCurrentTag(parser);
2247
2248 } else if (parser.getName().equals("path-permission")) {
2249 TypedArray sa = res.obtainAttributes(attrs,
2250 com.android.internal.R.styleable.AndroidManifestPathPermission);
2251
2252 PathPermission pa = null;
2253
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002254 String permission = sa.getNonConfigurationString(
2255 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2256 String readPermission = sa.getNonConfigurationString(
2257 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002258 if (readPermission == null) {
2259 readPermission = permission;
2260 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002261 String writePermission = sa.getNonConfigurationString(
2262 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002263 if (writePermission == null) {
2264 writePermission = permission;
2265 }
2266
2267 boolean havePerm = false;
2268 if (readPermission != null) {
2269 readPermission = readPermission.intern();
2270 havePerm = true;
2271 }
2272 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002273 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002274 havePerm = true;
2275 }
2276
2277 if (!havePerm) {
2278 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002279 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2280 + parser.getName() + " at " + mArchiveSourcePath + " "
2281 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002282 XmlUtils.skipCurrentTag(parser);
2283 continue;
2284 }
2285 outError[0] = "No readPermission or writePermssion for <path-permission>";
2286 return false;
2287 }
2288
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002289 String path = sa.getNonConfigurationString(
2290 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002291 if (path != null) {
2292 pa = new PathPermission(path,
2293 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2294 }
2295
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002296 path = sa.getNonConfigurationString(
2297 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002298 if (path != null) {
2299 pa = new PathPermission(path,
2300 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2301 }
2302
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002303 path = sa.getNonConfigurationString(
2304 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002305 if (path != null) {
2306 pa = new PathPermission(path,
2307 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2308 }
2309
2310 sa.recycle();
2311
2312 if (pa != null) {
2313 if (outInfo.info.pathPermissions == null) {
2314 outInfo.info.pathPermissions = new PathPermission[1];
2315 outInfo.info.pathPermissions[0] = pa;
2316 } else {
2317 final int N = outInfo.info.pathPermissions.length;
2318 PathPermission[] newp = new PathPermission[N+1];
2319 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2320 newp[N] = pa;
2321 outInfo.info.pathPermissions = newp;
2322 }
2323 } else {
2324 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002325 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2326 + parser.getName() + " at " + mArchiveSourcePath + " "
2327 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002328 XmlUtils.skipCurrentTag(parser);
2329 continue;
2330 }
2331 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2332 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 }
2334 XmlUtils.skipCurrentTag(parser);
2335
2336 } else {
2337 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002339 + parser.getName() + " at " + mArchiveSourcePath + " "
2340 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 XmlUtils.skipCurrentTag(parser);
2342 continue;
2343 }
2344 outError[0] = "Bad element under <provider>: "
2345 + parser.getName();
2346 return false;
2347 }
2348 }
2349 return true;
2350 }
2351
2352 private Service parseService(Package owner, Resources res,
2353 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2354 throws XmlPullParserException, IOException {
2355 TypedArray sa = res.obtainAttributes(attrs,
2356 com.android.internal.R.styleable.AndroidManifestService);
2357
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002358 if (mParseServiceArgs == null) {
2359 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2360 com.android.internal.R.styleable.AndroidManifestService_name,
2361 com.android.internal.R.styleable.AndroidManifestService_label,
2362 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002363 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002364 mSeparateProcesses,
2365 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002366 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002367 com.android.internal.R.styleable.AndroidManifestService_enabled);
2368 mParseServiceArgs.tag = "<service>";
2369 }
2370
2371 mParseServiceArgs.sa = sa;
2372 mParseServiceArgs.flags = flags;
2373
2374 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2375 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 sa.recycle();
2377 return null;
2378 }
2379
2380 final boolean setExported = sa.hasValue(
2381 com.android.internal.R.styleable.AndroidManifestService_exported);
2382 if (setExported) {
2383 s.info.exported = sa.getBoolean(
2384 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2385 }
2386
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002387 String str = sa.getNonConfigurationString(
2388 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 if (str == null) {
2390 s.info.permission = owner.applicationInfo.permission;
2391 } else {
2392 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2393 }
2394
2395 sa.recycle();
2396
2397 int outerDepth = parser.getDepth();
2398 int type;
2399 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2400 && (type != XmlPullParser.END_TAG
2401 || parser.getDepth() > outerDepth)) {
2402 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2403 continue;
2404 }
2405
2406 if (parser.getName().equals("intent-filter")) {
2407 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2408 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2409 return null;
2410 }
2411
2412 s.intents.add(intent);
2413 } else if (parser.getName().equals("meta-data")) {
2414 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2415 outError)) == null) {
2416 return null;
2417 }
2418 } else {
2419 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002421 + parser.getName() + " at " + mArchiveSourcePath + " "
2422 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 XmlUtils.skipCurrentTag(parser);
2424 continue;
2425 }
2426 outError[0] = "Bad element under <service>: "
2427 + parser.getName();
2428 return null;
2429 }
2430 }
2431
2432 if (!setExported) {
2433 s.info.exported = s.intents.size() > 0;
2434 }
2435
2436 return s;
2437 }
2438
2439 private boolean parseAllMetaData(Resources res,
2440 XmlPullParser parser, AttributeSet attrs, String tag,
2441 Component outInfo, String[] outError)
2442 throws XmlPullParserException, IOException {
2443 int outerDepth = parser.getDepth();
2444 int type;
2445 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2446 && (type != XmlPullParser.END_TAG
2447 || parser.getDepth() > outerDepth)) {
2448 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2449 continue;
2450 }
2451
2452 if (parser.getName().equals("meta-data")) {
2453 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2454 outInfo.metaData, outError)) == null) {
2455 return false;
2456 }
2457 } else {
2458 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002460 + parser.getName() + " at " + mArchiveSourcePath + " "
2461 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 XmlUtils.skipCurrentTag(parser);
2463 continue;
2464 }
2465 outError[0] = "Bad element under " + tag + ": "
2466 + parser.getName();
2467 return false;
2468 }
2469 }
2470 return true;
2471 }
2472
2473 private Bundle parseMetaData(Resources res,
2474 XmlPullParser parser, AttributeSet attrs,
2475 Bundle data, String[] outError)
2476 throws XmlPullParserException, IOException {
2477
2478 TypedArray sa = res.obtainAttributes(attrs,
2479 com.android.internal.R.styleable.AndroidManifestMetaData);
2480
2481 if (data == null) {
2482 data = new Bundle();
2483 }
2484
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002485 String name = sa.getNonConfigurationString(
2486 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 if (name == null) {
2488 outError[0] = "<meta-data> requires an android:name attribute";
2489 sa.recycle();
2490 return null;
2491 }
2492
Dianne Hackborn854060a2009-07-09 18:14:31 -07002493 name = name.intern();
2494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 TypedValue v = sa.peekValue(
2496 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2497 if (v != null && v.resourceId != 0) {
2498 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2499 data.putInt(name, v.resourceId);
2500 } else {
2501 v = sa.peekValue(
2502 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2503 //Log.i(TAG, "Meta data " + name + ": " + v);
2504 if (v != null) {
2505 if (v.type == TypedValue.TYPE_STRING) {
2506 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002507 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2509 data.putBoolean(name, v.data != 0);
2510 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2511 && v.type <= TypedValue.TYPE_LAST_INT) {
2512 data.putInt(name, v.data);
2513 } else if (v.type == TypedValue.TYPE_FLOAT) {
2514 data.putFloat(name, v.getFloat());
2515 } else {
2516 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002517 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2518 + parser.getName() + " at " + mArchiveSourcePath + " "
2519 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 } else {
2521 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2522 data = null;
2523 }
2524 }
2525 } else {
2526 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2527 data = null;
2528 }
2529 }
2530
2531 sa.recycle();
2532
2533 XmlUtils.skipCurrentTag(parser);
2534
2535 return data;
2536 }
2537
2538 private static final String ANDROID_RESOURCES
2539 = "http://schemas.android.com/apk/res/android";
2540
2541 private boolean parseIntent(Resources res,
2542 XmlPullParser parser, AttributeSet attrs, int flags,
2543 IntentInfo outInfo, String[] outError, boolean isActivity)
2544 throws XmlPullParserException, IOException {
2545
2546 TypedArray sa = res.obtainAttributes(attrs,
2547 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2548
2549 int priority = sa.getInt(
2550 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2551 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2552 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002553 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 + parser.getPositionDescription());
2555 priority = 0;
2556 }
2557 outInfo.setPriority(priority);
2558
2559 TypedValue v = sa.peekValue(
2560 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2561 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2562 outInfo.nonLocalizedLabel = v.coerceToString();
2563 }
2564
2565 outInfo.icon = sa.getResourceId(
2566 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002567
2568 outInfo.logo = sa.getResourceId(
2569 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570
2571 sa.recycle();
2572
2573 int outerDepth = parser.getDepth();
2574 int type;
2575 while ((type=parser.next()) != parser.END_DOCUMENT
2576 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2577 if (type == parser.END_TAG || type == parser.TEXT) {
2578 continue;
2579 }
2580
2581 String nodeName = parser.getName();
2582 if (nodeName.equals("action")) {
2583 String value = attrs.getAttributeValue(
2584 ANDROID_RESOURCES, "name");
2585 if (value == null || value == "") {
2586 outError[0] = "No value supplied for <android:name>";
2587 return false;
2588 }
2589 XmlUtils.skipCurrentTag(parser);
2590
2591 outInfo.addAction(value);
2592 } else if (nodeName.equals("category")) {
2593 String value = attrs.getAttributeValue(
2594 ANDROID_RESOURCES, "name");
2595 if (value == null || value == "") {
2596 outError[0] = "No value supplied for <android:name>";
2597 return false;
2598 }
2599 XmlUtils.skipCurrentTag(parser);
2600
2601 outInfo.addCategory(value);
2602
2603 } else if (nodeName.equals("data")) {
2604 sa = res.obtainAttributes(attrs,
2605 com.android.internal.R.styleable.AndroidManifestData);
2606
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002607 String str = sa.getNonConfigurationString(
2608 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 if (str != null) {
2610 try {
2611 outInfo.addDataType(str);
2612 } catch (IntentFilter.MalformedMimeTypeException e) {
2613 outError[0] = e.toString();
2614 sa.recycle();
2615 return false;
2616 }
2617 }
2618
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002619 str = sa.getNonConfigurationString(
2620 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 if (str != null) {
2622 outInfo.addDataScheme(str);
2623 }
2624
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002625 String host = sa.getNonConfigurationString(
2626 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2627 String port = sa.getNonConfigurationString(
2628 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 if (host != null) {
2630 outInfo.addDataAuthority(host, port);
2631 }
2632
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002633 str = sa.getNonConfigurationString(
2634 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 if (str != null) {
2636 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2637 }
2638
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002639 str = sa.getNonConfigurationString(
2640 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 if (str != null) {
2642 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2643 }
2644
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002645 str = sa.getNonConfigurationString(
2646 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 if (str != null) {
2648 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2649 }
2650
2651 sa.recycle();
2652 XmlUtils.skipCurrentTag(parser);
2653 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002654 Log.w(TAG, "Unknown element under <intent-filter>: "
2655 + parser.getName() + " at " + mArchiveSourcePath + " "
2656 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 XmlUtils.skipCurrentTag(parser);
2658 } else {
2659 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2660 return false;
2661 }
2662 }
2663
2664 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2665 if (false) {
2666 String cats = "";
2667 Iterator<String> it = outInfo.categoriesIterator();
2668 while (it != null && it.hasNext()) {
2669 cats += " " + it.next();
2670 }
2671 System.out.println("Intent d=" +
2672 outInfo.hasDefault + ", cat=" + cats);
2673 }
2674
2675 return true;
2676 }
2677
2678 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002679 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680
2681 // For now we only support one application per package.
2682 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2683
2684 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2685 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2686 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2687 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2688 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2689 public final ArrayList<Service> services = new ArrayList<Service>(0);
2690 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2691
2692 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2693
Dianne Hackborn854060a2009-07-09 18:14:31 -07002694 public ArrayList<String> protectedBroadcasts;
2695
Dianne Hackborn49237342009-08-27 20:08:01 -07002696 public ArrayList<String> usesLibraries = null;
2697 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 public String[] usesLibraryFiles = null;
2699
Dianne Hackbornc1552392010-03-03 16:19:01 -08002700 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002701 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002702 public ArrayList<String> mAdoptPermissions = null;
2703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 // We store the application meta-data independently to avoid multiple unwanted references
2705 public Bundle mAppMetaData = null;
2706
2707 // If this is a 3rd party app, this is the path of the zip file.
2708 public String mPath;
2709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 // The version code declared for this package.
2711 public int mVersionCode;
2712
2713 // The version name declared for this package.
2714 public String mVersionName;
2715
2716 // The shared user id that this package wants to use.
2717 public String mSharedUserId;
2718
2719 // The shared user label that this package wants to use.
2720 public int mSharedUserLabel;
2721
2722 // Signatures that were read from the package.
2723 public Signature mSignatures[];
2724
2725 // For use by package manager service for quick lookup of
2726 // preferred up order.
2727 public int mPreferredOrder = 0;
2728
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002729 // For use by the package manager to keep track of the path to the
2730 // file an app came from.
2731 public String mScanPath;
2732
2733 // For use by package manager to keep track of where it has done dexopt.
2734 public boolean mDidDexOpt;
2735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 // Additional data supplied by callers.
2737 public Object mExtras;
2738
2739 /*
2740 * Applications hardware preferences
2741 */
2742 public final ArrayList<ConfigurationInfo> configPreferences =
2743 new ArrayList<ConfigurationInfo>();
2744
Dianne Hackborn49237342009-08-27 20:08:01 -07002745 /*
2746 * Applications requested features
2747 */
2748 public ArrayList<FeatureInfo> reqFeatures = null;
2749
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002750 public int installLocation;
2751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 public Package(String _name) {
2753 packageName = _name;
2754 applicationInfo.packageName = _name;
2755 applicationInfo.uid = -1;
2756 }
2757
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002758 public void setPackageName(String newName) {
2759 packageName = newName;
2760 applicationInfo.packageName = newName;
2761 for (int i=permissions.size()-1; i>=0; i--) {
2762 permissions.get(i).setPackageName(newName);
2763 }
2764 for (int i=permissionGroups.size()-1; i>=0; i--) {
2765 permissionGroups.get(i).setPackageName(newName);
2766 }
2767 for (int i=activities.size()-1; i>=0; i--) {
2768 activities.get(i).setPackageName(newName);
2769 }
2770 for (int i=receivers.size()-1; i>=0; i--) {
2771 receivers.get(i).setPackageName(newName);
2772 }
2773 for (int i=providers.size()-1; i>=0; i--) {
2774 providers.get(i).setPackageName(newName);
2775 }
2776 for (int i=services.size()-1; i>=0; i--) {
2777 services.get(i).setPackageName(newName);
2778 }
2779 for (int i=instrumentation.size()-1; i>=0; i--) {
2780 instrumentation.get(i).setPackageName(newName);
2781 }
2782 }
2783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 public String toString() {
2785 return "Package{"
2786 + Integer.toHexString(System.identityHashCode(this))
2787 + " " + packageName + "}";
2788 }
2789 }
2790
2791 public static class Component<II extends IntentInfo> {
2792 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002793 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002794 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 public Bundle metaData;
2796
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002797 ComponentName componentName;
2798 String componentShortName;
2799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 public Component(Package _owner) {
2801 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002802 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002803 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002804 }
2805
2806 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2807 owner = args.owner;
2808 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002809 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002810 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002811 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002812 args.outError[0] = args.tag + " does not specify android:name";
2813 return;
2814 }
2815
2816 outInfo.name
2817 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2818 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002819 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002820 args.outError[0] = args.tag + " does not have valid android:name";
2821 return;
2822 }
2823
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002824 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002825
2826 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2827 if (iconVal != 0) {
2828 outInfo.icon = iconVal;
2829 outInfo.nonLocalizedLabel = null;
2830 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002831
2832 int logoVal = args.sa.getResourceId(args.logoRes, 0);
2833 if (logoVal != 0) {
2834 outInfo.logo = logoVal;
2835 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002836
2837 TypedValue v = args.sa.peekValue(args.labelRes);
2838 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2839 outInfo.nonLocalizedLabel = v.coerceToString();
2840 }
2841
2842 outInfo.packageName = owner.packageName;
2843 }
2844
2845 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2846 this(args, (PackageItemInfo)outInfo);
2847 if (args.outError[0] != null) {
2848 return;
2849 }
2850
2851 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002852 CharSequence pname;
2853 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2854 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2855 } else {
2856 // Some older apps have been seen to use a resource reference
2857 // here that on older builds was ignored (with a warning). We
2858 // need to continue to do this for them so they don't break.
2859 pname = args.sa.getNonResourceString(args.processRes);
2860 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002861 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002862 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002863 args.flags, args.sepProcesses, args.outError);
2864 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002865
2866 if (args.descriptionRes != 0) {
2867 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2868 }
2869
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002870 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872
2873 public Component(Component<II> clone) {
2874 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002875 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002876 className = clone.className;
2877 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002878 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002879 }
2880
2881 public ComponentName getComponentName() {
2882 if (componentName != null) {
2883 return componentName;
2884 }
2885 if (className != null) {
2886 componentName = new ComponentName(owner.applicationInfo.packageName,
2887 className);
2888 }
2889 return componentName;
2890 }
2891
2892 public String getComponentShortName() {
2893 if (componentShortName != null) {
2894 return componentShortName;
2895 }
2896 ComponentName component = getComponentName();
2897 if (component != null) {
2898 componentShortName = component.flattenToShortString();
2899 }
2900 return componentShortName;
2901 }
2902
2903 public void setPackageName(String packageName) {
2904 componentName = null;
2905 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 }
2907 }
2908
2909 public final static class Permission extends Component<IntentInfo> {
2910 public final PermissionInfo info;
2911 public boolean tree;
2912 public PermissionGroup group;
2913
2914 public Permission(Package _owner) {
2915 super(_owner);
2916 info = new PermissionInfo();
2917 }
2918
2919 public Permission(Package _owner, PermissionInfo _info) {
2920 super(_owner);
2921 info = _info;
2922 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002923
2924 public void setPackageName(String packageName) {
2925 super.setPackageName(packageName);
2926 info.packageName = packageName;
2927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928
2929 public String toString() {
2930 return "Permission{"
2931 + Integer.toHexString(System.identityHashCode(this))
2932 + " " + info.name + "}";
2933 }
2934 }
2935
2936 public final static class PermissionGroup extends Component<IntentInfo> {
2937 public final PermissionGroupInfo info;
2938
2939 public PermissionGroup(Package _owner) {
2940 super(_owner);
2941 info = new PermissionGroupInfo();
2942 }
2943
2944 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2945 super(_owner);
2946 info = _info;
2947 }
2948
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002949 public void setPackageName(String packageName) {
2950 super.setPackageName(packageName);
2951 info.packageName = packageName;
2952 }
2953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 public String toString() {
2955 return "PermissionGroup{"
2956 + Integer.toHexString(System.identityHashCode(this))
2957 + " " + info.name + "}";
2958 }
2959 }
2960
2961 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
2962 if ((flags & PackageManager.GET_META_DATA) != 0
2963 && (metaData != null || p.mAppMetaData != null)) {
2964 return true;
2965 }
2966 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
2967 && p.usesLibraryFiles != null) {
2968 return true;
2969 }
2970 return false;
2971 }
2972
2973 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
2974 if (p == null) return null;
2975 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002976 // CompatibilityMode is global state. It's safe to modify the instance
2977 // of the package.
2978 if (!sCompatibilityModeEnabled) {
2979 p.applicationInfo.disableCompatibilityMode();
2980 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 return p.applicationInfo;
2982 }
2983
2984 // Make shallow copy so we can store the metadata/libraries safely
2985 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
2986 if ((flags & PackageManager.GET_META_DATA) != 0) {
2987 ai.metaData = p.mAppMetaData;
2988 }
2989 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
2990 ai.sharedLibraryFiles = p.usesLibraryFiles;
2991 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07002992 if (!sCompatibilityModeEnabled) {
2993 ai.disableCompatibilityMode();
2994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 return ai;
2996 }
2997
2998 public static final PermissionInfo generatePermissionInfo(
2999 Permission p, int flags) {
3000 if (p == null) return null;
3001 if ((flags&PackageManager.GET_META_DATA) == 0) {
3002 return p.info;
3003 }
3004 PermissionInfo pi = new PermissionInfo(p.info);
3005 pi.metaData = p.metaData;
3006 return pi;
3007 }
3008
3009 public static final PermissionGroupInfo generatePermissionGroupInfo(
3010 PermissionGroup pg, int flags) {
3011 if (pg == null) return null;
3012 if ((flags&PackageManager.GET_META_DATA) == 0) {
3013 return pg.info;
3014 }
3015 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3016 pgi.metaData = pg.metaData;
3017 return pgi;
3018 }
3019
3020 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003021 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003023 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3024 super(args, _info);
3025 info = _info;
3026 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003028
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003029 public void setPackageName(String packageName) {
3030 super.setPackageName(packageName);
3031 info.packageName = packageName;
3032 }
3033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 public String toString() {
3035 return "Activity{"
3036 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003037 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 }
3039 }
3040
3041 public static final ActivityInfo generateActivityInfo(Activity a,
3042 int flags) {
3043 if (a == null) return null;
3044 if (!copyNeeded(flags, a.owner, a.metaData)) {
3045 return a.info;
3046 }
3047 // Make shallow copies so we can store the metadata safely
3048 ActivityInfo ai = new ActivityInfo(a.info);
3049 ai.metaData = a.metaData;
3050 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3051 return ai;
3052 }
3053
3054 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003055 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003057 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3058 super(args, _info);
3059 info = _info;
3060 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003062
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003063 public void setPackageName(String packageName) {
3064 super.setPackageName(packageName);
3065 info.packageName = packageName;
3066 }
3067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 public String toString() {
3069 return "Service{"
3070 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003071 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 }
3073 }
3074
3075 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3076 if (s == null) return null;
3077 if (!copyNeeded(flags, s.owner, s.metaData)) {
3078 return s.info;
3079 }
3080 // Make shallow copies so we can store the metadata safely
3081 ServiceInfo si = new ServiceInfo(s.info);
3082 si.metaData = s.metaData;
3083 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3084 return si;
3085 }
3086
3087 public final static class Provider extends Component {
3088 public final ProviderInfo info;
3089 public boolean syncable;
3090
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003091 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3092 super(args, _info);
3093 info = _info;
3094 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 syncable = false;
3096 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098 public Provider(Provider existingProvider) {
3099 super(existingProvider);
3100 this.info = existingProvider.info;
3101 this.syncable = existingProvider.syncable;
3102 }
3103
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003104 public void setPackageName(String packageName) {
3105 super.setPackageName(packageName);
3106 info.packageName = packageName;
3107 }
3108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 public String toString() {
3110 return "Provider{"
3111 + Integer.toHexString(System.identityHashCode(this))
3112 + " " + info.name + "}";
3113 }
3114 }
3115
3116 public static final ProviderInfo generateProviderInfo(Provider p,
3117 int flags) {
3118 if (p == null) return null;
3119 if (!copyNeeded(flags, p.owner, p.metaData)
3120 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3121 || p.info.uriPermissionPatterns == null)) {
3122 return p.info;
3123 }
3124 // Make shallow copies so we can store the metadata safely
3125 ProviderInfo pi = new ProviderInfo(p.info);
3126 pi.metaData = p.metaData;
3127 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3128 pi.uriPermissionPatterns = null;
3129 }
3130 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3131 return pi;
3132 }
3133
3134 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003135 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003137 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3138 super(args, _info);
3139 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003141
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003142 public void setPackageName(String packageName) {
3143 super.setPackageName(packageName);
3144 info.packageName = packageName;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 public String toString() {
3148 return "Instrumentation{"
3149 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003150 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
3152 }
3153
3154 public static final InstrumentationInfo generateInstrumentationInfo(
3155 Instrumentation i, int flags) {
3156 if (i == null) return null;
3157 if ((flags&PackageManager.GET_META_DATA) == 0) {
3158 return i.info;
3159 }
3160 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3161 ii.metaData = i.metaData;
3162 return ii;
3163 }
3164
3165 public static class IntentInfo extends IntentFilter {
3166 public boolean hasDefault;
3167 public int labelRes;
3168 public CharSequence nonLocalizedLabel;
3169 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003170 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 }
3172
3173 public final static class ActivityIntentInfo extends IntentInfo {
3174 public final Activity activity;
3175
3176 public ActivityIntentInfo(Activity _activity) {
3177 activity = _activity;
3178 }
3179
3180 public String toString() {
3181 return "ActivityIntentInfo{"
3182 + Integer.toHexString(System.identityHashCode(this))
3183 + " " + activity.info.name + "}";
3184 }
3185 }
3186
3187 public final static class ServiceIntentInfo extends IntentInfo {
3188 public final Service service;
3189
3190 public ServiceIntentInfo(Service _service) {
3191 service = _service;
3192 }
3193
3194 public String toString() {
3195 return "ServiceIntentInfo{"
3196 + Integer.toHexString(System.identityHashCode(this))
3197 + " " + service.info.name + "}";
3198 }
3199 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003200
3201 /**
3202 * @hide
3203 */
3204 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3205 sCompatibilityModeEnabled = compatibilityModeEnabled;
3206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207}