blob: 2a39dc002eb682fbc9950726cc882bee1f55b228 [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
Kenny Root930d3af2010-07-30 16:52:29 -0700590 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800591 */
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 Hackborn14cee9f2010-04-23 17:51:26 -0700794 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700795 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700796 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 int outerDepth = parser.getDepth();
799 while ((type=parser.next()) != parser.END_DOCUMENT
800 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
801 if (type == parser.END_TAG || type == parser.TEXT) {
802 continue;
803 }
804
805 String tagName = parser.getName();
806 if (tagName.equals("application")) {
807 if (foundApp) {
808 if (RIGID_PARSER) {
809 outError[0] = "<manifest> has more than one <application>";
810 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
811 return null;
812 } else {
813 Log.w(TAG, "<manifest> has more than one <application>");
814 XmlUtils.skipCurrentTag(parser);
815 continue;
816 }
817 }
818
819 foundApp = true;
820 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
821 return null;
822 }
823 } else if (tagName.equals("permission-group")) {
824 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
825 return null;
826 }
827 } else if (tagName.equals("permission")) {
828 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
829 return null;
830 }
831 } else if (tagName.equals("permission-tree")) {
832 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
833 return null;
834 }
835 } else if (tagName.equals("uses-permission")) {
836 sa = res.obtainAttributes(attrs,
837 com.android.internal.R.styleable.AndroidManifestUsesPermission);
838
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800839 // Note: don't allow this value to be a reference to a resource
840 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 String name = sa.getNonResourceString(
842 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
843
844 sa.recycle();
845
846 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700847 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849
850 XmlUtils.skipCurrentTag(parser);
851
852 } else if (tagName.equals("uses-configuration")) {
853 ConfigurationInfo cPref = new ConfigurationInfo();
854 sa = res.obtainAttributes(attrs,
855 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
856 cPref.reqTouchScreen = sa.getInt(
857 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
858 Configuration.TOUCHSCREEN_UNDEFINED);
859 cPref.reqKeyboardType = sa.getInt(
860 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
861 Configuration.KEYBOARD_UNDEFINED);
862 if (sa.getBoolean(
863 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
864 false)) {
865 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
866 }
867 cPref.reqNavigation = sa.getInt(
868 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
869 Configuration.NAVIGATION_UNDEFINED);
870 if (sa.getBoolean(
871 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
872 false)) {
873 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
874 }
875 sa.recycle();
876 pkg.configPreferences.add(cPref);
877
878 XmlUtils.skipCurrentTag(parser);
879
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700880 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700881 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700882 sa = res.obtainAttributes(attrs,
883 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800884 // Note: don't allow this value to be a reference to a resource
885 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700886 fi.name = sa.getNonResourceString(
887 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
888 if (fi.name == null) {
889 fi.reqGlEsVersion = sa.getInt(
890 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
891 FeatureInfo.GL_ES_VERSION_UNDEFINED);
892 }
893 if (sa.getBoolean(
894 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
895 true)) {
896 fi.flags |= FeatureInfo.FLAG_REQUIRED;
897 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700898 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700899 if (pkg.reqFeatures == null) {
900 pkg.reqFeatures = new ArrayList<FeatureInfo>();
901 }
902 pkg.reqFeatures.add(fi);
903
904 if (fi.name == null) {
905 ConfigurationInfo cPref = new ConfigurationInfo();
906 cPref.reqGlEsVersion = fi.reqGlEsVersion;
907 pkg.configPreferences.add(cPref);
908 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700909
910 XmlUtils.skipCurrentTag(parser);
911
Dianne Hackborn851a5412009-05-08 12:06:44 -0700912 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700913 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 sa = res.obtainAttributes(attrs,
915 com.android.internal.R.styleable.AndroidManifestUsesSdk);
916
Dianne Hackborn851a5412009-05-08 12:06:44 -0700917 int minVers = 0;
918 String minCode = null;
919 int targetVers = 0;
920 String targetCode = null;
921
922 TypedValue val = sa.peekValue(
923 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
924 if (val != null) {
925 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
926 targetCode = minCode = val.string.toString();
927 } else {
928 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700929 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700930 }
931 }
932
933 val = sa.peekValue(
934 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
935 if (val != null) {
936 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
937 targetCode = minCode = val.string.toString();
938 } else {
939 // If it's not a string, it's an integer.
940 targetVers = val.data;
941 }
942 }
943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 sa.recycle();
945
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700946 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700947 if (!minCode.equals(SDK_CODENAME)) {
948 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700949 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700950 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700951 } else {
952 outError[0] = "Requires development platform " + minCode
953 + " but this is a release platform.";
954 }
955 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
956 return null;
957 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700958 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700959 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700960 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700961 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
962 return null;
963 }
964
Dianne Hackborn851a5412009-05-08 12:06:44 -0700965 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700966 if (!targetCode.equals(SDK_CODENAME)) {
967 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700968 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700969 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700970 } else {
971 outError[0] = "Requires development platform " + targetCode
972 + " but this is a release platform.";
973 }
974 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
975 return null;
976 }
977 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700978 pkg.applicationInfo.targetSdkVersion
979 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
980 } else {
981 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984
985 XmlUtils.skipCurrentTag(parser);
986
Dianne Hackborn723738c2009-06-25 19:48:04 -0700987 } else if (tagName.equals("supports-screens")) {
988 sa = res.obtainAttributes(attrs,
989 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
990
991 // This is a trick to get a boolean and still able to detect
992 // if a value was actually set.
993 supportsSmallScreens = sa.getInteger(
994 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
995 supportsSmallScreens);
996 supportsNormalScreens = sa.getInteger(
997 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
998 supportsNormalScreens);
999 supportsLargeScreens = sa.getInteger(
1000 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1001 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001002 supportsXLargeScreens = sa.getInteger(
1003 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1004 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001005 resizeable = sa.getInteger(
1006 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001007 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001008 anyDensity = sa.getInteger(
1009 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1010 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001011
1012 sa.recycle();
1013
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001014 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001015
1016 } else if (tagName.equals("protected-broadcast")) {
1017 sa = res.obtainAttributes(attrs,
1018 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1019
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001020 // Note: don't allow this value to be a reference to a resource
1021 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001022 String name = sa.getNonResourceString(
1023 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1024
1025 sa.recycle();
1026
1027 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1028 if (pkg.protectedBroadcasts == null) {
1029 pkg.protectedBroadcasts = new ArrayList<String>();
1030 }
1031 if (!pkg.protectedBroadcasts.contains(name)) {
1032 pkg.protectedBroadcasts.add(name.intern());
1033 }
1034 }
1035
1036 XmlUtils.skipCurrentTag(parser);
1037
1038 } else if (tagName.equals("instrumentation")) {
1039 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1040 return null;
1041 }
1042
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001043 } else if (tagName.equals("original-package")) {
1044 sa = res.obtainAttributes(attrs,
1045 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1046
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001047 String orig =sa.getNonConfigurationString(
1048 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001049 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001050 if (pkg.mOriginalPackages == null) {
1051 pkg.mOriginalPackages = new ArrayList<String>();
1052 pkg.mRealPackage = pkg.packageName;
1053 }
1054 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001055 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001056
1057 sa.recycle();
1058
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001059 XmlUtils.skipCurrentTag(parser);
1060
1061 } else if (tagName.equals("adopt-permissions")) {
1062 sa = res.obtainAttributes(attrs,
1063 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1064
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001065 String name = sa.getNonConfigurationString(
1066 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001067
1068 sa.recycle();
1069
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001070 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001071 if (pkg.mAdoptPermissions == null) {
1072 pkg.mAdoptPermissions = new ArrayList<String>();
1073 }
1074 pkg.mAdoptPermissions.add(name);
1075 }
1076
1077 XmlUtils.skipCurrentTag(parser);
1078
Dianne Hackborn854060a2009-07-09 18:14:31 -07001079 } else if (tagName.equals("eat-comment")) {
1080 // Just skip this tag
1081 XmlUtils.skipCurrentTag(parser);
1082 continue;
1083
1084 } else if (RIGID_PARSER) {
1085 outError[0] = "Bad element under <manifest>: "
1086 + parser.getName();
1087 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1088 return null;
1089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001091 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
1092 + " at " + mArchiveSourcePath + " "
1093 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 XmlUtils.skipCurrentTag(parser);
1095 continue;
1096 }
1097 }
1098
1099 if (!foundApp && pkg.instrumentation.size() == 0) {
1100 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1101 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1102 }
1103
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001104 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001105 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001106 for (int ip=0; ip<NP; ip++) {
1107 final PackageParser.NewPermissionInfo npi
1108 = PackageParser.NEW_PERMISSIONS[ip];
1109 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1110 break;
1111 }
1112 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001113 if (implicitPerms == null) {
1114 implicitPerms = new StringBuilder(128);
1115 implicitPerms.append(pkg.packageName);
1116 implicitPerms.append(": compat added ");
1117 } else {
1118 implicitPerms.append(' ');
1119 }
1120 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001121 pkg.requestedPermissions.add(npi.name);
1122 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001123 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001124 if (implicitPerms != null) {
1125 Log.i(TAG, implicitPerms.toString());
1126 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001127
Dianne Hackborn723738c2009-06-25 19:48:04 -07001128 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1129 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001130 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001131 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1132 }
1133 if (supportsNormalScreens != 0) {
1134 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1135 }
1136 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1137 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001138 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001139 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1140 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001141 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1142 && pkg.applicationInfo.targetSdkVersion
1143 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1144 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1145 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001146 if (resizeable < 0 || (resizeable > 0
1147 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001148 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001149 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1150 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001151 if (anyDensity < 0 || (anyDensity > 0
1152 && pkg.applicationInfo.targetSdkVersion
1153 >= android.os.Build.VERSION_CODES.DONUT)) {
1154 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001155 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 return pkg;
1158 }
1159
1160 private static String buildClassName(String pkg, CharSequence clsSeq,
1161 String[] outError) {
1162 if (clsSeq == null || clsSeq.length() <= 0) {
1163 outError[0] = "Empty class name in package " + pkg;
1164 return null;
1165 }
1166 String cls = clsSeq.toString();
1167 char c = cls.charAt(0);
1168 if (c == '.') {
1169 return (pkg + cls).intern();
1170 }
1171 if (cls.indexOf('.') < 0) {
1172 StringBuilder b = new StringBuilder(pkg);
1173 b.append('.');
1174 b.append(cls);
1175 return b.toString().intern();
1176 }
1177 if (c >= 'a' && c <= 'z') {
1178 return cls.intern();
1179 }
1180 outError[0] = "Bad class name " + cls + " in package " + pkg;
1181 return null;
1182 }
1183
1184 private static String buildCompoundName(String pkg,
1185 CharSequence procSeq, String type, String[] outError) {
1186 String proc = procSeq.toString();
1187 char c = proc.charAt(0);
1188 if (pkg != null && c == ':') {
1189 if (proc.length() < 2) {
1190 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1191 + ": must be at least two characters";
1192 return null;
1193 }
1194 String subName = proc.substring(1);
1195 String nameError = validateName(subName, false);
1196 if (nameError != null) {
1197 outError[0] = "Invalid " + type + " name " + proc + " in package "
1198 + pkg + ": " + nameError;
1199 return null;
1200 }
1201 return (pkg + proc).intern();
1202 }
1203 String nameError = validateName(proc, true);
1204 if (nameError != null && !"system".equals(proc)) {
1205 outError[0] = "Invalid " + type + " name " + proc + " in package "
1206 + pkg + ": " + nameError;
1207 return null;
1208 }
1209 return proc.intern();
1210 }
1211
1212 private static String buildProcessName(String pkg, String defProc,
1213 CharSequence procSeq, int flags, String[] separateProcesses,
1214 String[] outError) {
1215 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1216 return defProc != null ? defProc : pkg;
1217 }
1218 if (separateProcesses != null) {
1219 for (int i=separateProcesses.length-1; i>=0; i--) {
1220 String sp = separateProcesses[i];
1221 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1222 return pkg;
1223 }
1224 }
1225 }
1226 if (procSeq == null || procSeq.length() <= 0) {
1227 return defProc;
1228 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001229 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 }
1231
1232 private static String buildTaskAffinityName(String pkg, String defProc,
1233 CharSequence procSeq, String[] outError) {
1234 if (procSeq == null) {
1235 return defProc;
1236 }
1237 if (procSeq.length() <= 0) {
1238 return null;
1239 }
1240 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1241 }
1242
1243 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1244 XmlPullParser parser, AttributeSet attrs, String[] outError)
1245 throws XmlPullParserException, IOException {
1246 PermissionGroup perm = new PermissionGroup(owner);
1247
1248 TypedArray sa = res.obtainAttributes(attrs,
1249 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1250
1251 if (!parsePackageItemInfo(owner, perm.info, outError,
1252 "<permission-group>", sa,
1253 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1254 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001255 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1256 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 sa.recycle();
1258 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1259 return null;
1260 }
1261
1262 perm.info.descriptionRes = sa.getResourceId(
1263 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1264 0);
1265
1266 sa.recycle();
1267
1268 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1269 outError)) {
1270 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1271 return null;
1272 }
1273
1274 owner.permissionGroups.add(perm);
1275
1276 return perm;
1277 }
1278
1279 private Permission parsePermission(Package owner, Resources res,
1280 XmlPullParser parser, AttributeSet attrs, String[] outError)
1281 throws XmlPullParserException, IOException {
1282 Permission perm = new Permission(owner);
1283
1284 TypedArray sa = res.obtainAttributes(attrs,
1285 com.android.internal.R.styleable.AndroidManifestPermission);
1286
1287 if (!parsePackageItemInfo(owner, perm.info, outError,
1288 "<permission>", sa,
1289 com.android.internal.R.styleable.AndroidManifestPermission_name,
1290 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001291 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1292 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 sa.recycle();
1294 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1295 return null;
1296 }
1297
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001298 // Note: don't allow this value to be a reference to a resource
1299 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 perm.info.group = sa.getNonResourceString(
1301 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1302 if (perm.info.group != null) {
1303 perm.info.group = perm.info.group.intern();
1304 }
1305
1306 perm.info.descriptionRes = sa.getResourceId(
1307 com.android.internal.R.styleable.AndroidManifestPermission_description,
1308 0);
1309
1310 perm.info.protectionLevel = sa.getInt(
1311 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1312 PermissionInfo.PROTECTION_NORMAL);
1313
1314 sa.recycle();
1315
1316 if (perm.info.protectionLevel == -1) {
1317 outError[0] = "<permission> does not specify protectionLevel";
1318 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1319 return null;
1320 }
1321
1322 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1323 outError)) {
1324 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1325 return null;
1326 }
1327
1328 owner.permissions.add(perm);
1329
1330 return perm;
1331 }
1332
1333 private Permission parsePermissionTree(Package owner, Resources res,
1334 XmlPullParser parser, AttributeSet attrs, String[] outError)
1335 throws XmlPullParserException, IOException {
1336 Permission perm = new Permission(owner);
1337
1338 TypedArray sa = res.obtainAttributes(attrs,
1339 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1340
1341 if (!parsePackageItemInfo(owner, perm.info, outError,
1342 "<permission-tree>", sa,
1343 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1344 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001345 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1346 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 sa.recycle();
1348 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1349 return null;
1350 }
1351
1352 sa.recycle();
1353
1354 int index = perm.info.name.indexOf('.');
1355 if (index > 0) {
1356 index = perm.info.name.indexOf('.', index+1);
1357 }
1358 if (index < 0) {
1359 outError[0] = "<permission-tree> name has less than three segments: "
1360 + perm.info.name;
1361 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1362 return null;
1363 }
1364
1365 perm.info.descriptionRes = 0;
1366 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1367 perm.tree = true;
1368
1369 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1370 outError)) {
1371 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1372 return null;
1373 }
1374
1375 owner.permissions.add(perm);
1376
1377 return perm;
1378 }
1379
1380 private Instrumentation parseInstrumentation(Package owner, Resources res,
1381 XmlPullParser parser, AttributeSet attrs, String[] outError)
1382 throws XmlPullParserException, IOException {
1383 TypedArray sa = res.obtainAttributes(attrs,
1384 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1385
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001386 if (mParseInstrumentationArgs == null) {
1387 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1388 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1389 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001390 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1391 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001392 mParseInstrumentationArgs.tag = "<instrumentation>";
1393 }
1394
1395 mParseInstrumentationArgs.sa = sa;
1396
1397 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1398 new InstrumentationInfo());
1399 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 sa.recycle();
1401 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1402 return null;
1403 }
1404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001406 // Note: don't allow this value to be a reference to a resource
1407 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 str = sa.getNonResourceString(
1409 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1410 a.info.targetPackage = str != null ? str.intern() : null;
1411
1412 a.info.handleProfiling = sa.getBoolean(
1413 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1414 false);
1415
1416 a.info.functionalTest = sa.getBoolean(
1417 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1418 false);
1419
1420 sa.recycle();
1421
1422 if (a.info.targetPackage == null) {
1423 outError[0] = "<instrumentation> does not specify targetPackage";
1424 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1425 return null;
1426 }
1427
1428 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1429 outError)) {
1430 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1431 return null;
1432 }
1433
1434 owner.instrumentation.add(a);
1435
1436 return a;
1437 }
1438
1439 private boolean parseApplication(Package owner, Resources res,
1440 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1441 throws XmlPullParserException, IOException {
1442 final ApplicationInfo ai = owner.applicationInfo;
1443 final String pkgName = owner.applicationInfo.packageName;
1444
1445 TypedArray sa = res.obtainAttributes(attrs,
1446 com.android.internal.R.styleable.AndroidManifestApplication);
1447
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001448 String name = sa.getNonConfigurationString(
1449 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 if (name != null) {
1451 ai.className = buildClassName(pkgName, name, outError);
1452 if (ai.className == null) {
1453 sa.recycle();
1454 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1455 return false;
1456 }
1457 }
1458
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001459 String manageSpaceActivity = sa.getNonConfigurationString(
1460 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 if (manageSpaceActivity != null) {
1462 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1463 outError);
1464 }
1465
Christopher Tate181fafa2009-05-14 11:12:14 -07001466 boolean allowBackup = sa.getBoolean(
1467 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1468 if (allowBackup) {
1469 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001470
Christopher Tate3de55bc2010-03-12 17:28:08 -08001471 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1472 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001473 String backupAgent = sa.getNonConfigurationString(
1474 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001475 if (backupAgent != null) {
1476 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001477 if (false) {
1478 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1479 + " from " + pkgName + "+" + backupAgent);
1480 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001481
1482 if (sa.getBoolean(
1483 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1484 true)) {
1485 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1486 }
1487 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001488 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1489 false)) {
1490 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1491 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001492 }
1493 }
1494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 TypedValue v = sa.peekValue(
1496 com.android.internal.R.styleable.AndroidManifestApplication_label);
1497 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1498 ai.nonLocalizedLabel = v.coerceToString();
1499 }
1500
1501 ai.icon = sa.getResourceId(
1502 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001503 ai.logo = sa.getResourceId(
1504 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 ai.theme = sa.getResourceId(
1506 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1507 ai.descriptionRes = sa.getResourceId(
1508 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1509
1510 if ((flags&PARSE_IS_SYSTEM) != 0) {
1511 if (sa.getBoolean(
1512 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1513 false)) {
1514 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1515 }
1516 }
1517
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001518 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1519 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1520 }
1521
1522 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001523 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001524 }
1525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 if (sa.getBoolean(
1527 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1528 false)) {
1529 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1530 }
1531
1532 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001533 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001534 false)) {
1535 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1536 }
1537
1538 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1540 true)) {
1541 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1542 }
1543
1544 if (sa.getBoolean(
1545 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1546 false)) {
1547 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1548 }
1549
1550 if (sa.getBoolean(
1551 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1552 true)) {
1553 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1554 }
1555
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001556 if (sa.getBoolean(
1557 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001558 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001559 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1560 }
1561
Oscar Montemayor1874aa42009-11-10 18:35:33 -08001562 if (sa.getBoolean(
1563 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt,
1564 false)) {
1565 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT;
1566 }
1567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001569 str = sa.getNonConfigurationString(
1570 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1572
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001573 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1574 str = sa.getNonConfigurationString(
1575 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1576 } else {
1577 // Some older apps have been seen to use a resource reference
1578 // here that on older builds was ignored (with a warning). We
1579 // need to continue to do this for them so they don't break.
1580 str = sa.getNonResourceString(
1581 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1584 str, outError);
1585
1586 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001587 CharSequence pname;
1588 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1589 pname = sa.getNonConfigurationString(
1590 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1591 } else {
1592 // Some older apps have been seen to use a resource reference
1593 // here that on older builds was ignored (with a warning). We
1594 // need to continue to do this for them so they don't break.
1595 pname = sa.getNonResourceString(
1596 com.android.internal.R.styleable.AndroidManifestApplication_process);
1597 }
1598 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 flags, mSeparateProcesses, outError);
1600
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001601 ai.enabled = sa.getBoolean(
1602 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001603
Dianne Hackborn02486b12010-08-26 14:18:37 -07001604 if (false) {
1605 if (sa.getBoolean(
1606 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1607 false)) {
1608 ai.flags |= ApplicationInfo.CANT_SAVE_STATE;
1609
1610 // A heavy-weight application can not be in a custom process.
1611 // We can do direct compare because we intern all strings.
1612 if (ai.processName != null && ai.processName != ai.packageName) {
1613 outError[0] = "cantSaveState applications can not use custom processes";
1614 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001615 }
1616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 }
1618
1619 sa.recycle();
1620
1621 if (outError[0] != null) {
1622 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1623 return false;
1624 }
1625
1626 final int innerDepth = parser.getDepth();
1627
1628 int type;
1629 while ((type=parser.next()) != parser.END_DOCUMENT
1630 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1631 if (type == parser.END_TAG || type == parser.TEXT) {
1632 continue;
1633 }
1634
1635 String tagName = parser.getName();
1636 if (tagName.equals("activity")) {
1637 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1638 if (a == null) {
1639 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1640 return false;
1641 }
1642
1643 owner.activities.add(a);
1644
1645 } else if (tagName.equals("receiver")) {
1646 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1647 if (a == null) {
1648 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1649 return false;
1650 }
1651
1652 owner.receivers.add(a);
1653
1654 } else if (tagName.equals("service")) {
1655 Service s = parseService(owner, res, parser, attrs, flags, outError);
1656 if (s == null) {
1657 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1658 return false;
1659 }
1660
1661 owner.services.add(s);
1662
1663 } else if (tagName.equals("provider")) {
1664 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1665 if (p == null) {
1666 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1667 return false;
1668 }
1669
1670 owner.providers.add(p);
1671
1672 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001673 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 if (a == null) {
1675 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1676 return false;
1677 }
1678
1679 owner.activities.add(a);
1680
1681 } else if (parser.getName().equals("meta-data")) {
1682 // note: application meta-data is stored off to the side, so it can
1683 // remain null in the primary copy (we like to avoid extra copies because
1684 // it can be large)
1685 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1686 outError)) == null) {
1687 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1688 return false;
1689 }
1690
1691 } else if (tagName.equals("uses-library")) {
1692 sa = res.obtainAttributes(attrs,
1693 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1694
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001695 // Note: don't allow this value to be a reference to a resource
1696 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 String lname = sa.getNonResourceString(
1698 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001699 boolean req = sa.getBoolean(
1700 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1701 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702
1703 sa.recycle();
1704
Dianne Hackborn49237342009-08-27 20:08:01 -07001705 if (lname != null) {
1706 if (req) {
1707 if (owner.usesLibraries == null) {
1708 owner.usesLibraries = new ArrayList<String>();
1709 }
1710 if (!owner.usesLibraries.contains(lname)) {
1711 owner.usesLibraries.add(lname.intern());
1712 }
1713 } else {
1714 if (owner.usesOptionalLibraries == null) {
1715 owner.usesOptionalLibraries = new ArrayList<String>();
1716 }
1717 if (!owner.usesOptionalLibraries.contains(lname)) {
1718 owner.usesOptionalLibraries.add(lname.intern());
1719 }
1720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 }
1722
1723 XmlUtils.skipCurrentTag(parser);
1724
1725 } else {
1726 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001727 Log.w(TAG, "Unknown element under <application>: " + tagName
1728 + " at " + mArchiveSourcePath + " "
1729 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 XmlUtils.skipCurrentTag(parser);
1731 continue;
1732 } else {
1733 outError[0] = "Bad element under <application>: " + tagName;
1734 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1735 return false;
1736 }
1737 }
1738 }
1739
1740 return true;
1741 }
1742
1743 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1744 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001745 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001746 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 if (name == null) {
1748 outError[0] = tag + " does not specify android:name";
1749 return false;
1750 }
1751
1752 outInfo.name
1753 = buildClassName(owner.applicationInfo.packageName, name, outError);
1754 if (outInfo.name == null) {
1755 return false;
1756 }
1757
1758 int iconVal = sa.getResourceId(iconRes, 0);
1759 if (iconVal != 0) {
1760 outInfo.icon = iconVal;
1761 outInfo.nonLocalizedLabel = null;
1762 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001763
1764 int logoVal = sa.getResourceId(logoRes, 0);
1765 if (logoVal != 0) {
1766 outInfo.logo = logoVal;
1767 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768
1769 TypedValue v = sa.peekValue(labelRes);
1770 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1771 outInfo.nonLocalizedLabel = v.coerceToString();
1772 }
1773
1774 outInfo.packageName = owner.packageName;
1775
1776 return true;
1777 }
1778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 private Activity parseActivity(Package owner, Resources res,
1780 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1781 boolean receiver) throws XmlPullParserException, IOException {
1782 TypedArray sa = res.obtainAttributes(attrs,
1783 com.android.internal.R.styleable.AndroidManifestActivity);
1784
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001785 if (mParseActivityArgs == null) {
1786 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1787 com.android.internal.R.styleable.AndroidManifestActivity_name,
1788 com.android.internal.R.styleable.AndroidManifestActivity_label,
1789 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001790 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001791 mSeparateProcesses,
1792 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001793 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001794 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1795 }
1796
1797 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1798 mParseActivityArgs.sa = sa;
1799 mParseActivityArgs.flags = flags;
1800
1801 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1802 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 sa.recycle();
1804 return null;
1805 }
1806
1807 final boolean setExported = sa.hasValue(
1808 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1809 if (setExported) {
1810 a.info.exported = sa.getBoolean(
1811 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1812 }
1813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 a.info.theme = sa.getResourceId(
1815 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1816
1817 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001818 str = sa.getNonConfigurationString(
1819 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 if (str == null) {
1821 a.info.permission = owner.applicationInfo.permission;
1822 } else {
1823 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1824 }
1825
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001826 str = sa.getNonConfigurationString(
1827 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1829 owner.applicationInfo.taskAffinity, str, outError);
1830
1831 a.info.flags = 0;
1832 if (sa.getBoolean(
1833 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1834 false)) {
1835 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1836 }
1837
1838 if (sa.getBoolean(
1839 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1840 false)) {
1841 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1842 }
1843
1844 if (sa.getBoolean(
1845 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1846 false)) {
1847 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1848 }
1849
1850 if (sa.getBoolean(
1851 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1852 false)) {
1853 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1854 }
1855
1856 if (sa.getBoolean(
1857 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1858 false)) {
1859 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1860 }
1861
1862 if (sa.getBoolean(
1863 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1864 false)) {
1865 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1866 }
1867
1868 if (sa.getBoolean(
1869 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1870 false)) {
1871 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1872 }
1873
1874 if (sa.getBoolean(
1875 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1876 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1877 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1878 }
1879
Dianne Hackbornffa42482009-09-23 22:20:11 -07001880 if (sa.getBoolean(
1881 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1882 false)) {
1883 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1884 }
1885
Daniel Sandler613dde42010-06-21 13:46:39 -04001886 if (sa.getBoolean(
1887 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
1888 false)) {
1889 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
1890 }
1891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 if (!receiver) {
1893 a.info.launchMode = sa.getInt(
1894 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1895 ActivityInfo.LAUNCH_MULTIPLE);
1896 a.info.screenOrientation = sa.getInt(
1897 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1898 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1899 a.info.configChanges = sa.getInt(
1900 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1901 0);
1902 a.info.softInputMode = sa.getInt(
1903 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1904 0);
1905 } else {
1906 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1907 a.info.configChanges = 0;
1908 }
1909
1910 sa.recycle();
1911
Dianne Hackborn02486b12010-08-26 14:18:37 -07001912 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001913 // A heavy-weight application can not have receives in its main process
1914 // We can do direct compare because we intern all strings.
1915 if (a.info.processName == owner.packageName) {
1916 outError[0] = "Heavy-weight applications can not have receivers in main process";
1917 }
1918 }
1919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 if (outError[0] != null) {
1921 return null;
1922 }
1923
1924 int outerDepth = parser.getDepth();
1925 int type;
1926 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1927 && (type != XmlPullParser.END_TAG
1928 || parser.getDepth() > outerDepth)) {
1929 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1930 continue;
1931 }
1932
1933 if (parser.getName().equals("intent-filter")) {
1934 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1935 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1936 return null;
1937 }
1938 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001939 Log.w(TAG, "No actions in intent filter at "
1940 + mArchiveSourcePath + " "
1941 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 } else {
1943 a.intents.add(intent);
1944 }
1945 } else if (parser.getName().equals("meta-data")) {
1946 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1947 outError)) == null) {
1948 return null;
1949 }
1950 } else {
1951 if (!RIGID_PARSER) {
1952 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1953 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001954 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1955 + " at " + mArchiveSourcePath + " "
1956 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001958 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1959 + " at " + mArchiveSourcePath + " "
1960 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 }
1962 XmlUtils.skipCurrentTag(parser);
1963 continue;
1964 }
1965 if (receiver) {
1966 outError[0] = "Bad element under <receiver>: " + parser.getName();
1967 } else {
1968 outError[0] = "Bad element under <activity>: " + parser.getName();
1969 }
1970 return null;
1971 }
1972 }
1973
1974 if (!setExported) {
1975 a.info.exported = a.intents.size() > 0;
1976 }
1977
1978 return a;
1979 }
1980
1981 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001982 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1983 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 TypedArray sa = res.obtainAttributes(attrs,
1985 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1986
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001987 String targetActivity = sa.getNonConfigurationString(
1988 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 if (targetActivity == null) {
1990 outError[0] = "<activity-alias> does not specify android:targetActivity";
1991 sa.recycle();
1992 return null;
1993 }
1994
1995 targetActivity = buildClassName(owner.applicationInfo.packageName,
1996 targetActivity, outError);
1997 if (targetActivity == null) {
1998 sa.recycle();
1999 return null;
2000 }
2001
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002002 if (mParseActivityAliasArgs == null) {
2003 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2004 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2005 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2006 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002007 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002008 mSeparateProcesses,
2009 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002010 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002011 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2012 mParseActivityAliasArgs.tag = "<activity-alias>";
2013 }
2014
2015 mParseActivityAliasArgs.sa = sa;
2016 mParseActivityAliasArgs.flags = flags;
2017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 Activity target = null;
2019
2020 final int NA = owner.activities.size();
2021 for (int i=0; i<NA; i++) {
2022 Activity t = owner.activities.get(i);
2023 if (targetActivity.equals(t.info.name)) {
2024 target = t;
2025 break;
2026 }
2027 }
2028
2029 if (target == null) {
2030 outError[0] = "<activity-alias> target activity " + targetActivity
2031 + " not found in manifest";
2032 sa.recycle();
2033 return null;
2034 }
2035
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002036 ActivityInfo info = new ActivityInfo();
2037 info.targetActivity = targetActivity;
2038 info.configChanges = target.info.configChanges;
2039 info.flags = target.info.flags;
2040 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002041 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002042 info.labelRes = target.info.labelRes;
2043 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2044 info.launchMode = target.info.launchMode;
2045 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002046 if (info.descriptionRes == 0) {
2047 info.descriptionRes = target.info.descriptionRes;
2048 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002049 info.screenOrientation = target.info.screenOrientation;
2050 info.taskAffinity = target.info.taskAffinity;
2051 info.theme = target.info.theme;
2052
2053 Activity a = new Activity(mParseActivityAliasArgs, info);
2054 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 sa.recycle();
2056 return null;
2057 }
2058
2059 final boolean setExported = sa.hasValue(
2060 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2061 if (setExported) {
2062 a.info.exported = sa.getBoolean(
2063 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2064 }
2065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002067 str = sa.getNonConfigurationString(
2068 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 if (str != null) {
2070 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2071 }
2072
2073 sa.recycle();
2074
2075 if (outError[0] != null) {
2076 return null;
2077 }
2078
2079 int outerDepth = parser.getDepth();
2080 int type;
2081 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2082 && (type != XmlPullParser.END_TAG
2083 || parser.getDepth() > outerDepth)) {
2084 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2085 continue;
2086 }
2087
2088 if (parser.getName().equals("intent-filter")) {
2089 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2090 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2091 return null;
2092 }
2093 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002094 Log.w(TAG, "No actions in intent filter at "
2095 + mArchiveSourcePath + " "
2096 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 } else {
2098 a.intents.add(intent);
2099 }
2100 } else if (parser.getName().equals("meta-data")) {
2101 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2102 outError)) == null) {
2103 return null;
2104 }
2105 } else {
2106 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002107 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2108 + " at " + mArchiveSourcePath + " "
2109 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002110 XmlUtils.skipCurrentTag(parser);
2111 continue;
2112 }
2113 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2114 return null;
2115 }
2116 }
2117
2118 if (!setExported) {
2119 a.info.exported = a.intents.size() > 0;
2120 }
2121
2122 return a;
2123 }
2124
2125 private Provider parseProvider(Package owner, Resources res,
2126 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2127 throws XmlPullParserException, IOException {
2128 TypedArray sa = res.obtainAttributes(attrs,
2129 com.android.internal.R.styleable.AndroidManifestProvider);
2130
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002131 if (mParseProviderArgs == null) {
2132 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2133 com.android.internal.R.styleable.AndroidManifestProvider_name,
2134 com.android.internal.R.styleable.AndroidManifestProvider_label,
2135 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002136 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002137 mSeparateProcesses,
2138 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002139 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002140 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2141 mParseProviderArgs.tag = "<provider>";
2142 }
2143
2144 mParseProviderArgs.sa = sa;
2145 mParseProviderArgs.flags = flags;
2146
2147 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2148 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 sa.recycle();
2150 return null;
2151 }
2152
2153 p.info.exported = sa.getBoolean(
2154 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2155
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002156 String cpname = sa.getNonConfigurationString(
2157 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158
2159 p.info.isSyncable = sa.getBoolean(
2160 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2161 false);
2162
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002163 String permission = sa.getNonConfigurationString(
2164 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2165 String str = sa.getNonConfigurationString(
2166 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 if (str == null) {
2168 str = permission;
2169 }
2170 if (str == null) {
2171 p.info.readPermission = owner.applicationInfo.permission;
2172 } else {
2173 p.info.readPermission =
2174 str.length() > 0 ? str.toString().intern() : null;
2175 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002176 str = sa.getNonConfigurationString(
2177 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 if (str == null) {
2179 str = permission;
2180 }
2181 if (str == null) {
2182 p.info.writePermission = owner.applicationInfo.permission;
2183 } else {
2184 p.info.writePermission =
2185 str.length() > 0 ? str.toString().intern() : null;
2186 }
2187
2188 p.info.grantUriPermissions = sa.getBoolean(
2189 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2190 false);
2191
2192 p.info.multiprocess = sa.getBoolean(
2193 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2194 false);
2195
2196 p.info.initOrder = sa.getInt(
2197 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2198 0);
2199
2200 sa.recycle();
2201
Dianne Hackborn02486b12010-08-26 14:18:37 -07002202 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002203 // A heavy-weight application can not have providers in its main process
2204 // We can do direct compare because we intern all strings.
2205 if (p.info.processName == owner.packageName) {
2206 outError[0] = "Heavy-weight applications can not have providers in main process";
2207 return null;
2208 }
2209 }
2210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 if (cpname == null) {
2212 outError[0] = "<provider> does not incude authorities attribute";
2213 return null;
2214 }
2215 p.info.authority = cpname.intern();
2216
2217 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2218 return null;
2219 }
2220
2221 return p;
2222 }
2223
2224 private boolean parseProviderTags(Resources res,
2225 XmlPullParser parser, AttributeSet attrs,
2226 Provider outInfo, String[] outError)
2227 throws XmlPullParserException, IOException {
2228 int outerDepth = parser.getDepth();
2229 int type;
2230 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2231 && (type != XmlPullParser.END_TAG
2232 || parser.getDepth() > outerDepth)) {
2233 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2234 continue;
2235 }
2236
2237 if (parser.getName().equals("meta-data")) {
2238 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2239 outInfo.metaData, outError)) == null) {
2240 return false;
2241 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 } else if (parser.getName().equals("grant-uri-permission")) {
2244 TypedArray sa = res.obtainAttributes(attrs,
2245 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2246
2247 PatternMatcher pa = null;
2248
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002249 String str = sa.getNonConfigurationString(
2250 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 if (str != null) {
2252 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2253 }
2254
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002255 str = sa.getNonConfigurationString(
2256 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 if (str != null) {
2258 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2259 }
2260
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002261 str = sa.getNonConfigurationString(
2262 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 if (str != null) {
2264 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2265 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 sa.recycle();
2268
2269 if (pa != null) {
2270 if (outInfo.info.uriPermissionPatterns == null) {
2271 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2272 outInfo.info.uriPermissionPatterns[0] = pa;
2273 } else {
2274 final int N = outInfo.info.uriPermissionPatterns.length;
2275 PatternMatcher[] newp = new PatternMatcher[N+1];
2276 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2277 newp[N] = pa;
2278 outInfo.info.uriPermissionPatterns = newp;
2279 }
2280 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002281 } else {
2282 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002283 Log.w(TAG, "Unknown element under <path-permission>: "
2284 + parser.getName() + " at " + mArchiveSourcePath + " "
2285 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002286 XmlUtils.skipCurrentTag(parser);
2287 continue;
2288 }
2289 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2290 return false;
2291 }
2292 XmlUtils.skipCurrentTag(parser);
2293
2294 } else if (parser.getName().equals("path-permission")) {
2295 TypedArray sa = res.obtainAttributes(attrs,
2296 com.android.internal.R.styleable.AndroidManifestPathPermission);
2297
2298 PathPermission pa = null;
2299
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002300 String permission = sa.getNonConfigurationString(
2301 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2302 String readPermission = sa.getNonConfigurationString(
2303 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002304 if (readPermission == null) {
2305 readPermission = permission;
2306 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002307 String writePermission = sa.getNonConfigurationString(
2308 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002309 if (writePermission == null) {
2310 writePermission = permission;
2311 }
2312
2313 boolean havePerm = false;
2314 if (readPermission != null) {
2315 readPermission = readPermission.intern();
2316 havePerm = true;
2317 }
2318 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002319 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002320 havePerm = true;
2321 }
2322
2323 if (!havePerm) {
2324 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002325 Log.w(TAG, "No readPermission or writePermssion 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 readPermission or writePermssion for <path-permission>";
2332 return false;
2333 }
2334
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002335 String path = sa.getNonConfigurationString(
2336 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002337 if (path != null) {
2338 pa = new PathPermission(path,
2339 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2340 }
2341
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002342 path = sa.getNonConfigurationString(
2343 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002344 if (path != null) {
2345 pa = new PathPermission(path,
2346 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2347 }
2348
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002349 path = sa.getNonConfigurationString(
2350 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002351 if (path != null) {
2352 pa = new PathPermission(path,
2353 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2354 }
2355
2356 sa.recycle();
2357
2358 if (pa != null) {
2359 if (outInfo.info.pathPermissions == null) {
2360 outInfo.info.pathPermissions = new PathPermission[1];
2361 outInfo.info.pathPermissions[0] = pa;
2362 } else {
2363 final int N = outInfo.info.pathPermissions.length;
2364 PathPermission[] newp = new PathPermission[N+1];
2365 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2366 newp[N] = pa;
2367 outInfo.info.pathPermissions = newp;
2368 }
2369 } else {
2370 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002371 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2372 + parser.getName() + " at " + mArchiveSourcePath + " "
2373 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002374 XmlUtils.skipCurrentTag(parser);
2375 continue;
2376 }
2377 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2378 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 }
2380 XmlUtils.skipCurrentTag(parser);
2381
2382 } else {
2383 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002385 + parser.getName() + " at " + mArchiveSourcePath + " "
2386 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 XmlUtils.skipCurrentTag(parser);
2388 continue;
2389 }
2390 outError[0] = "Bad element under <provider>: "
2391 + parser.getName();
2392 return false;
2393 }
2394 }
2395 return true;
2396 }
2397
2398 private Service parseService(Package owner, Resources res,
2399 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2400 throws XmlPullParserException, IOException {
2401 TypedArray sa = res.obtainAttributes(attrs,
2402 com.android.internal.R.styleable.AndroidManifestService);
2403
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002404 if (mParseServiceArgs == null) {
2405 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2406 com.android.internal.R.styleable.AndroidManifestService_name,
2407 com.android.internal.R.styleable.AndroidManifestService_label,
2408 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002409 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002410 mSeparateProcesses,
2411 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002412 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002413 com.android.internal.R.styleable.AndroidManifestService_enabled);
2414 mParseServiceArgs.tag = "<service>";
2415 }
2416
2417 mParseServiceArgs.sa = sa;
2418 mParseServiceArgs.flags = flags;
2419
2420 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2421 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 sa.recycle();
2423 return null;
2424 }
2425
2426 final boolean setExported = sa.hasValue(
2427 com.android.internal.R.styleable.AndroidManifestService_exported);
2428 if (setExported) {
2429 s.info.exported = sa.getBoolean(
2430 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2431 }
2432
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002433 String str = sa.getNonConfigurationString(
2434 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 if (str == null) {
2436 s.info.permission = owner.applicationInfo.permission;
2437 } else {
2438 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2439 }
2440
2441 sa.recycle();
2442
Dianne Hackborn02486b12010-08-26 14:18:37 -07002443 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002444 // A heavy-weight application can not have services in its main process
2445 // We can do direct compare because we intern all strings.
2446 if (s.info.processName == owner.packageName) {
2447 outError[0] = "Heavy-weight applications can not have services in main process";
2448 return null;
2449 }
2450 }
2451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 int outerDepth = parser.getDepth();
2453 int type;
2454 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2455 && (type != XmlPullParser.END_TAG
2456 || parser.getDepth() > outerDepth)) {
2457 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2458 continue;
2459 }
2460
2461 if (parser.getName().equals("intent-filter")) {
2462 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2463 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2464 return null;
2465 }
2466
2467 s.intents.add(intent);
2468 } else if (parser.getName().equals("meta-data")) {
2469 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2470 outError)) == null) {
2471 return null;
2472 }
2473 } else {
2474 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002476 + parser.getName() + " at " + mArchiveSourcePath + " "
2477 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 XmlUtils.skipCurrentTag(parser);
2479 continue;
2480 }
2481 outError[0] = "Bad element under <service>: "
2482 + parser.getName();
2483 return null;
2484 }
2485 }
2486
2487 if (!setExported) {
2488 s.info.exported = s.intents.size() > 0;
2489 }
2490
2491 return s;
2492 }
2493
2494 private boolean parseAllMetaData(Resources res,
2495 XmlPullParser parser, AttributeSet attrs, String tag,
2496 Component outInfo, String[] outError)
2497 throws XmlPullParserException, IOException {
2498 int outerDepth = parser.getDepth();
2499 int type;
2500 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2501 && (type != XmlPullParser.END_TAG
2502 || parser.getDepth() > outerDepth)) {
2503 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2504 continue;
2505 }
2506
2507 if (parser.getName().equals("meta-data")) {
2508 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2509 outInfo.metaData, outError)) == null) {
2510 return false;
2511 }
2512 } else {
2513 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002515 + parser.getName() + " at " + mArchiveSourcePath + " "
2516 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 XmlUtils.skipCurrentTag(parser);
2518 continue;
2519 }
2520 outError[0] = "Bad element under " + tag + ": "
2521 + parser.getName();
2522 return false;
2523 }
2524 }
2525 return true;
2526 }
2527
2528 private Bundle parseMetaData(Resources res,
2529 XmlPullParser parser, AttributeSet attrs,
2530 Bundle data, String[] outError)
2531 throws XmlPullParserException, IOException {
2532
2533 TypedArray sa = res.obtainAttributes(attrs,
2534 com.android.internal.R.styleable.AndroidManifestMetaData);
2535
2536 if (data == null) {
2537 data = new Bundle();
2538 }
2539
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002540 String name = sa.getNonConfigurationString(
2541 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 if (name == null) {
2543 outError[0] = "<meta-data> requires an android:name attribute";
2544 sa.recycle();
2545 return null;
2546 }
2547
Dianne Hackborn854060a2009-07-09 18:14:31 -07002548 name = name.intern();
2549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 TypedValue v = sa.peekValue(
2551 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2552 if (v != null && v.resourceId != 0) {
2553 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2554 data.putInt(name, v.resourceId);
2555 } else {
2556 v = sa.peekValue(
2557 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2558 //Log.i(TAG, "Meta data " + name + ": " + v);
2559 if (v != null) {
2560 if (v.type == TypedValue.TYPE_STRING) {
2561 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002562 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2564 data.putBoolean(name, v.data != 0);
2565 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2566 && v.type <= TypedValue.TYPE_LAST_INT) {
2567 data.putInt(name, v.data);
2568 } else if (v.type == TypedValue.TYPE_FLOAT) {
2569 data.putFloat(name, v.getFloat());
2570 } else {
2571 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002572 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2573 + parser.getName() + " at " + mArchiveSourcePath + " "
2574 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 } else {
2576 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2577 data = null;
2578 }
2579 }
2580 } else {
2581 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2582 data = null;
2583 }
2584 }
2585
2586 sa.recycle();
2587
2588 XmlUtils.skipCurrentTag(parser);
2589
2590 return data;
2591 }
2592
2593 private static final String ANDROID_RESOURCES
2594 = "http://schemas.android.com/apk/res/android";
2595
2596 private boolean parseIntent(Resources res,
2597 XmlPullParser parser, AttributeSet attrs, int flags,
2598 IntentInfo outInfo, String[] outError, boolean isActivity)
2599 throws XmlPullParserException, IOException {
2600
2601 TypedArray sa = res.obtainAttributes(attrs,
2602 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2603
2604 int priority = sa.getInt(
2605 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2606 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2607 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002608 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 + parser.getPositionDescription());
2610 priority = 0;
2611 }
2612 outInfo.setPriority(priority);
2613
2614 TypedValue v = sa.peekValue(
2615 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2616 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2617 outInfo.nonLocalizedLabel = v.coerceToString();
2618 }
2619
2620 outInfo.icon = sa.getResourceId(
2621 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002622
2623 outInfo.logo = sa.getResourceId(
2624 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625
2626 sa.recycle();
2627
2628 int outerDepth = parser.getDepth();
2629 int type;
2630 while ((type=parser.next()) != parser.END_DOCUMENT
2631 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2632 if (type == parser.END_TAG || type == parser.TEXT) {
2633 continue;
2634 }
2635
2636 String nodeName = parser.getName();
2637 if (nodeName.equals("action")) {
2638 String value = attrs.getAttributeValue(
2639 ANDROID_RESOURCES, "name");
2640 if (value == null || value == "") {
2641 outError[0] = "No value supplied for <android:name>";
2642 return false;
2643 }
2644 XmlUtils.skipCurrentTag(parser);
2645
2646 outInfo.addAction(value);
2647 } else if (nodeName.equals("category")) {
2648 String value = attrs.getAttributeValue(
2649 ANDROID_RESOURCES, "name");
2650 if (value == null || value == "") {
2651 outError[0] = "No value supplied for <android:name>";
2652 return false;
2653 }
2654 XmlUtils.skipCurrentTag(parser);
2655
2656 outInfo.addCategory(value);
2657
2658 } else if (nodeName.equals("data")) {
2659 sa = res.obtainAttributes(attrs,
2660 com.android.internal.R.styleable.AndroidManifestData);
2661
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002662 String str = sa.getNonConfigurationString(
2663 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 if (str != null) {
2665 try {
2666 outInfo.addDataType(str);
2667 } catch (IntentFilter.MalformedMimeTypeException e) {
2668 outError[0] = e.toString();
2669 sa.recycle();
2670 return false;
2671 }
2672 }
2673
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002674 str = sa.getNonConfigurationString(
2675 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 if (str != null) {
2677 outInfo.addDataScheme(str);
2678 }
2679
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002680 String host = sa.getNonConfigurationString(
2681 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2682 String port = sa.getNonConfigurationString(
2683 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002684 if (host != null) {
2685 outInfo.addDataAuthority(host, port);
2686 }
2687
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002688 str = sa.getNonConfigurationString(
2689 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 if (str != null) {
2691 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2692 }
2693
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002694 str = sa.getNonConfigurationString(
2695 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 if (str != null) {
2697 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2698 }
2699
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002700 str = sa.getNonConfigurationString(
2701 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 if (str != null) {
2703 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2704 }
2705
2706 sa.recycle();
2707 XmlUtils.skipCurrentTag(parser);
2708 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002709 Log.w(TAG, "Unknown element under <intent-filter>: "
2710 + parser.getName() + " at " + mArchiveSourcePath + " "
2711 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 XmlUtils.skipCurrentTag(parser);
2713 } else {
2714 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2715 return false;
2716 }
2717 }
2718
2719 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2720 if (false) {
2721 String cats = "";
2722 Iterator<String> it = outInfo.categoriesIterator();
2723 while (it != null && it.hasNext()) {
2724 cats += " " + it.next();
2725 }
2726 System.out.println("Intent d=" +
2727 outInfo.hasDefault + ", cat=" + cats);
2728 }
2729
2730 return true;
2731 }
2732
2733 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002734 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735
2736 // For now we only support one application per package.
2737 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2738
2739 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2740 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2741 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2742 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2743 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2744 public final ArrayList<Service> services = new ArrayList<Service>(0);
2745 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2746
2747 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2748
Dianne Hackborn854060a2009-07-09 18:14:31 -07002749 public ArrayList<String> protectedBroadcasts;
2750
Dianne Hackborn49237342009-08-27 20:08:01 -07002751 public ArrayList<String> usesLibraries = null;
2752 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 public String[] usesLibraryFiles = null;
2754
Dianne Hackbornc1552392010-03-03 16:19:01 -08002755 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002756 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002757 public ArrayList<String> mAdoptPermissions = null;
2758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 // We store the application meta-data independently to avoid multiple unwanted references
2760 public Bundle mAppMetaData = null;
2761
2762 // If this is a 3rd party app, this is the path of the zip file.
2763 public String mPath;
2764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 // The version code declared for this package.
2766 public int mVersionCode;
2767
2768 // The version name declared for this package.
2769 public String mVersionName;
2770
2771 // The shared user id that this package wants to use.
2772 public String mSharedUserId;
2773
2774 // The shared user label that this package wants to use.
2775 public int mSharedUserLabel;
2776
2777 // Signatures that were read from the package.
2778 public Signature mSignatures[];
2779
2780 // For use by package manager service for quick lookup of
2781 // preferred up order.
2782 public int mPreferredOrder = 0;
2783
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002784 // For use by the package manager to keep track of the path to the
2785 // file an app came from.
2786 public String mScanPath;
2787
2788 // For use by package manager to keep track of where it has done dexopt.
2789 public boolean mDidDexOpt;
2790
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002791 // User set enabled state.
2792 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 // Additional data supplied by callers.
2795 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002796
2797 // Whether an operation is currently pending on this package
2798 public boolean mOperationPending;
2799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 /*
2801 * Applications hardware preferences
2802 */
2803 public final ArrayList<ConfigurationInfo> configPreferences =
2804 new ArrayList<ConfigurationInfo>();
2805
Dianne Hackborn49237342009-08-27 20:08:01 -07002806 /*
2807 * Applications requested features
2808 */
2809 public ArrayList<FeatureInfo> reqFeatures = null;
2810
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002811 public int installLocation;
2812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 public Package(String _name) {
2814 packageName = _name;
2815 applicationInfo.packageName = _name;
2816 applicationInfo.uid = -1;
2817 }
2818
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002819 public void setPackageName(String newName) {
2820 packageName = newName;
2821 applicationInfo.packageName = newName;
2822 for (int i=permissions.size()-1; i>=0; i--) {
2823 permissions.get(i).setPackageName(newName);
2824 }
2825 for (int i=permissionGroups.size()-1; i>=0; i--) {
2826 permissionGroups.get(i).setPackageName(newName);
2827 }
2828 for (int i=activities.size()-1; i>=0; i--) {
2829 activities.get(i).setPackageName(newName);
2830 }
2831 for (int i=receivers.size()-1; i>=0; i--) {
2832 receivers.get(i).setPackageName(newName);
2833 }
2834 for (int i=providers.size()-1; i>=0; i--) {
2835 providers.get(i).setPackageName(newName);
2836 }
2837 for (int i=services.size()-1; i>=0; i--) {
2838 services.get(i).setPackageName(newName);
2839 }
2840 for (int i=instrumentation.size()-1; i>=0; i--) {
2841 instrumentation.get(i).setPackageName(newName);
2842 }
2843 }
2844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 public String toString() {
2846 return "Package{"
2847 + Integer.toHexString(System.identityHashCode(this))
2848 + " " + packageName + "}";
2849 }
2850 }
2851
2852 public static class Component<II extends IntentInfo> {
2853 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002854 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002855 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 public Bundle metaData;
2857
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002858 ComponentName componentName;
2859 String componentShortName;
2860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 public Component(Package _owner) {
2862 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002863 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002864 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002865 }
2866
2867 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2868 owner = args.owner;
2869 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002870 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002871 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002872 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002873 args.outError[0] = args.tag + " does not specify android:name";
2874 return;
2875 }
2876
2877 outInfo.name
2878 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2879 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002880 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002881 args.outError[0] = args.tag + " does not have valid android:name";
2882 return;
2883 }
2884
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002885 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002886
2887 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2888 if (iconVal != 0) {
2889 outInfo.icon = iconVal;
2890 outInfo.nonLocalizedLabel = null;
2891 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002892
2893 int logoVal = args.sa.getResourceId(args.logoRes, 0);
2894 if (logoVal != 0) {
2895 outInfo.logo = logoVal;
2896 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002897
2898 TypedValue v = args.sa.peekValue(args.labelRes);
2899 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2900 outInfo.nonLocalizedLabel = v.coerceToString();
2901 }
2902
2903 outInfo.packageName = owner.packageName;
2904 }
2905
2906 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2907 this(args, (PackageItemInfo)outInfo);
2908 if (args.outError[0] != null) {
2909 return;
2910 }
2911
2912 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002913 CharSequence pname;
2914 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2915 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2916 } else {
2917 // Some older apps have been seen to use a resource reference
2918 // here that on older builds was ignored (with a warning). We
2919 // need to continue to do this for them so they don't break.
2920 pname = args.sa.getNonResourceString(args.processRes);
2921 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002922 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002923 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002924 args.flags, args.sepProcesses, args.outError);
2925 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002926
2927 if (args.descriptionRes != 0) {
2928 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2929 }
2930
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002931 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
2933
2934 public Component(Component<II> clone) {
2935 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002936 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002937 className = clone.className;
2938 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002939 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002940 }
2941
2942 public ComponentName getComponentName() {
2943 if (componentName != null) {
2944 return componentName;
2945 }
2946 if (className != null) {
2947 componentName = new ComponentName(owner.applicationInfo.packageName,
2948 className);
2949 }
2950 return componentName;
2951 }
2952
2953 public String getComponentShortName() {
2954 if (componentShortName != null) {
2955 return componentShortName;
2956 }
2957 ComponentName component = getComponentName();
2958 if (component != null) {
2959 componentShortName = component.flattenToShortString();
2960 }
2961 return componentShortName;
2962 }
2963
2964 public void setPackageName(String packageName) {
2965 componentName = null;
2966 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
2968 }
2969
2970 public final static class Permission extends Component<IntentInfo> {
2971 public final PermissionInfo info;
2972 public boolean tree;
2973 public PermissionGroup group;
2974
2975 public Permission(Package _owner) {
2976 super(_owner);
2977 info = new PermissionInfo();
2978 }
2979
2980 public Permission(Package _owner, PermissionInfo _info) {
2981 super(_owner);
2982 info = _info;
2983 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002984
2985 public void setPackageName(String packageName) {
2986 super.setPackageName(packageName);
2987 info.packageName = packageName;
2988 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989
2990 public String toString() {
2991 return "Permission{"
2992 + Integer.toHexString(System.identityHashCode(this))
2993 + " " + info.name + "}";
2994 }
2995 }
2996
2997 public final static class PermissionGroup extends Component<IntentInfo> {
2998 public final PermissionGroupInfo info;
2999
3000 public PermissionGroup(Package _owner) {
3001 super(_owner);
3002 info = new PermissionGroupInfo();
3003 }
3004
3005 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3006 super(_owner);
3007 info = _info;
3008 }
3009
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003010 public void setPackageName(String packageName) {
3011 super.setPackageName(packageName);
3012 info.packageName = packageName;
3013 }
3014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 public String toString() {
3016 return "PermissionGroup{"
3017 + Integer.toHexString(System.identityHashCode(this))
3018 + " " + info.name + "}";
3019 }
3020 }
3021
3022 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003023 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3024 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3025 if (p.applicationInfo.enabled != enabled) {
3026 return true;
3027 }
3028 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 if ((flags & PackageManager.GET_META_DATA) != 0
3030 && (metaData != null || p.mAppMetaData != null)) {
3031 return true;
3032 }
3033 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3034 && p.usesLibraryFiles != null) {
3035 return true;
3036 }
3037 return false;
3038 }
3039
3040 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3041 if (p == null) return null;
3042 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003043 // CompatibilityMode is global state. It's safe to modify the instance
3044 // of the package.
3045 if (!sCompatibilityModeEnabled) {
3046 p.applicationInfo.disableCompatibilityMode();
3047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 return p.applicationInfo;
3049 }
3050
3051 // Make shallow copy so we can store the metadata/libraries safely
3052 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3053 if ((flags & PackageManager.GET_META_DATA) != 0) {
3054 ai.metaData = p.mAppMetaData;
3055 }
3056 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3057 ai.sharedLibraryFiles = p.usesLibraryFiles;
3058 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003059 if (!sCompatibilityModeEnabled) {
3060 ai.disableCompatibilityMode();
3061 }
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003062 ai.enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 return ai;
3064 }
3065
3066 public static final PermissionInfo generatePermissionInfo(
3067 Permission p, int flags) {
3068 if (p == null) return null;
3069 if ((flags&PackageManager.GET_META_DATA) == 0) {
3070 return p.info;
3071 }
3072 PermissionInfo pi = new PermissionInfo(p.info);
3073 pi.metaData = p.metaData;
3074 return pi;
3075 }
3076
3077 public static final PermissionGroupInfo generatePermissionGroupInfo(
3078 PermissionGroup pg, int flags) {
3079 if (pg == null) return null;
3080 if ((flags&PackageManager.GET_META_DATA) == 0) {
3081 return pg.info;
3082 }
3083 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3084 pgi.metaData = pg.metaData;
3085 return pgi;
3086 }
3087
3088 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003089 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003091 public Activity(final ParseComponentArgs args, final ActivityInfo _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 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003096
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003097 public void setPackageName(String packageName) {
3098 super.setPackageName(packageName);
3099 info.packageName = packageName;
3100 }
3101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003102 public String toString() {
3103 return "Activity{"
3104 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003105 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 }
3107 }
3108
3109 public static final ActivityInfo generateActivityInfo(Activity a,
3110 int flags) {
3111 if (a == null) return null;
3112 if (!copyNeeded(flags, a.owner, a.metaData)) {
3113 return a.info;
3114 }
3115 // Make shallow copies so we can store the metadata safely
3116 ActivityInfo ai = new ActivityInfo(a.info);
3117 ai.metaData = a.metaData;
3118 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3119 return ai;
3120 }
3121
3122 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003123 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003125 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3126 super(args, _info);
3127 info = _info;
3128 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003129 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003130
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003131 public void setPackageName(String packageName) {
3132 super.setPackageName(packageName);
3133 info.packageName = packageName;
3134 }
3135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 public String toString() {
3137 return "Service{"
3138 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003139 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
3141 }
3142
3143 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3144 if (s == null) return null;
3145 if (!copyNeeded(flags, s.owner, s.metaData)) {
3146 return s.info;
3147 }
3148 // Make shallow copies so we can store the metadata safely
3149 ServiceInfo si = new ServiceInfo(s.info);
3150 si.metaData = s.metaData;
3151 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3152 return si;
3153 }
3154
3155 public final static class Provider extends Component {
3156 public final ProviderInfo info;
3157 public boolean syncable;
3158
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003159 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3160 super(args, _info);
3161 info = _info;
3162 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 syncable = false;
3164 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 public Provider(Provider existingProvider) {
3167 super(existingProvider);
3168 this.info = existingProvider.info;
3169 this.syncable = existingProvider.syncable;
3170 }
3171
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003172 public void setPackageName(String packageName) {
3173 super.setPackageName(packageName);
3174 info.packageName = packageName;
3175 }
3176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 public String toString() {
3178 return "Provider{"
3179 + Integer.toHexString(System.identityHashCode(this))
3180 + " " + info.name + "}";
3181 }
3182 }
3183
3184 public static final ProviderInfo generateProviderInfo(Provider p,
3185 int flags) {
3186 if (p == null) return null;
3187 if (!copyNeeded(flags, p.owner, p.metaData)
3188 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3189 || p.info.uriPermissionPatterns == null)) {
3190 return p.info;
3191 }
3192 // Make shallow copies so we can store the metadata safely
3193 ProviderInfo pi = new ProviderInfo(p.info);
3194 pi.metaData = p.metaData;
3195 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3196 pi.uriPermissionPatterns = null;
3197 }
3198 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3199 return pi;
3200 }
3201
3202 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003203 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003205 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3206 super(args, _info);
3207 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003209
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003210 public void setPackageName(String packageName) {
3211 super.setPackageName(packageName);
3212 info.packageName = packageName;
3213 }
3214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 public String toString() {
3216 return "Instrumentation{"
3217 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003218 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 }
3220 }
3221
3222 public static final InstrumentationInfo generateInstrumentationInfo(
3223 Instrumentation i, int flags) {
3224 if (i == null) return null;
3225 if ((flags&PackageManager.GET_META_DATA) == 0) {
3226 return i.info;
3227 }
3228 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3229 ii.metaData = i.metaData;
3230 return ii;
3231 }
3232
3233 public static class IntentInfo extends IntentFilter {
3234 public boolean hasDefault;
3235 public int labelRes;
3236 public CharSequence nonLocalizedLabel;
3237 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003238 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 }
3240
3241 public final static class ActivityIntentInfo extends IntentInfo {
3242 public final Activity activity;
3243
3244 public ActivityIntentInfo(Activity _activity) {
3245 activity = _activity;
3246 }
3247
3248 public String toString() {
3249 return "ActivityIntentInfo{"
3250 + Integer.toHexString(System.identityHashCode(this))
3251 + " " + activity.info.name + "}";
3252 }
3253 }
3254
3255 public final static class ServiceIntentInfo extends IntentInfo {
3256 public final Service service;
3257
3258 public ServiceIntentInfo(Service _service) {
3259 service = _service;
3260 }
3261
3262 public String toString() {
3263 return "ServiceIntentInfo{"
3264 + Integer.toHexString(System.identityHashCode(this))
3265 + " " + service.info.name + "}";
3266 }
3267 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003268
3269 /**
3270 * @hide
3271 */
3272 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3273 sCompatibilityModeEnabled = compatibilityModeEnabled;
3274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275}