blob: 6dfc72fee7f13a2b191a353ff4a541907d707c6c [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
Kenny Rootd63f7db2010-09-27 08:07:48 -070042import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import java.io.File;
44import java.io.IOException;
45import java.io.InputStream;
46import java.lang.ref.WeakReference;
47import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
49import java.util.ArrayList;
50import java.util.Enumeration;
51import java.util.Iterator;
Mitsuru Oshima8d112672009-04-27 12:01:23 -070052import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import java.util.jar.JarEntry;
54import java.util.jar.JarFile;
55
56/**
57 * Package archive parsing
58 *
59 * {@hide}
60 */
61public class PackageParser {
Dianne Hackborna96cbb42009-05-13 15:06:13 -070062 /** @hide */
63 public static class NewPermissionInfo {
64 public final String name;
65 public final int sdkVersion;
66 public final int fileVersion;
67
68 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
69 this.name = name;
70 this.sdkVersion = sdkVersion;
71 this.fileVersion = fileVersion;
72 }
73 }
74
75 /**
76 * List of new permissions that have been added since 1.0.
77 * NOTE: These must be declared in SDK version order, with permissions
78 * added to older SDKs appearing before those added to newer SDKs.
79 * @hide
80 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -070081 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
82 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070083 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070084 android.os.Build.VERSION_CODES.DONUT, 0),
85 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
86 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -070087 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89 private String mArchiveSourcePath;
90 private String[] mSeparateProcesses;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070091 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
92 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
93 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
95 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
96
97 private static final Object mSync = new Object();
98 private static WeakReference<byte[]> mReadBuffer;
99
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700100 private static boolean sCompatibilityModeEnabled = true;
101 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700102
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700103 static class ParsePackageItemArgs {
104 final Package owner;
105 final String[] outError;
106 final int nameRes;
107 final int labelRes;
108 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700109 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700110
111 String tag;
112 TypedArray sa;
113
114 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700115 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700116 owner = _owner;
117 outError = _outError;
118 nameRes = _nameRes;
119 labelRes = _labelRes;
120 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700121 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700122 }
123 }
124
125 static class ParseComponentArgs extends ParsePackageItemArgs {
126 final String[] sepProcesses;
127 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800128 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700129 final int enabledRes;
130 int flags;
131
132 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700133 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800134 String[] _sepProcesses, int _processRes,
135 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700136 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700137 sepProcesses = _sepProcesses;
138 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800139 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700140 enabledRes = _enabledRes;
141 }
142 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800143
144 /* Light weight package info.
145 * @hide
146 */
147 public static class PackageLite {
148 public String packageName;
149 public int installLocation;
150 public String mScanPath;
151 public PackageLite(String packageName, int installLocation) {
152 this.packageName = packageName;
153 this.installLocation = installLocation;
154 }
155 }
156
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700157 private ParsePackageItemArgs mParseInstrumentationArgs;
158 private ParseComponentArgs mParseActivityArgs;
159 private ParseComponentArgs mParseActivityAliasArgs;
160 private ParseComponentArgs mParseServiceArgs;
161 private ParseComponentArgs mParseProviderArgs;
162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 /** If set to true, we will only allow package files that exactly match
164 * the DTD. Otherwise, we try to get as much from the package as we
165 * can without failing. This should normally be set to false, to
166 * support extensions to the DTD in future versions. */
167 private static final boolean RIGID_PARSER = false;
168
169 private static final String TAG = "PackageParser";
170
171 public PackageParser(String archiveSourcePath) {
172 mArchiveSourcePath = archiveSourcePath;
173 }
174
175 public void setSeparateProcesses(String[] procs) {
176 mSeparateProcesses = procs;
177 }
178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 private static final boolean isPackageFilename(String name) {
180 return name.endsWith(".apk");
181 }
182
183 /**
184 * Generate and return the {@link PackageInfo} for a parsed package.
185 *
186 * @param p the parsed package.
187 * @param flags indicating which optional information is included.
188 */
189 public static PackageInfo generatePackageInfo(PackageParser.Package p,
190 int gids[], int flags) {
191
192 PackageInfo pi = new PackageInfo();
193 pi.packageName = p.packageName;
194 pi.versionCode = p.mVersionCode;
195 pi.versionName = p.mVersionName;
196 pi.sharedUserId = p.mSharedUserId;
197 pi.sharedUserLabel = p.mSharedUserLabel;
198 pi.applicationInfo = p.applicationInfo;
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800199 pi.installLocation = p.installLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 if ((flags&PackageManager.GET_GIDS) != 0) {
201 pi.gids = gids;
202 }
203 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
204 int N = p.configPreferences.size();
205 if (N > 0) {
206 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700207 p.configPreferences.toArray(pi.configPreferences);
208 }
209 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
210 if (N > 0) {
211 pi.reqFeatures = new FeatureInfo[N];
212 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
214 }
215 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
216 int N = p.activities.size();
217 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700218 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
219 pi.activities = new ActivityInfo[N];
220 } else {
221 int num = 0;
222 for (int i=0; i<N; i++) {
223 if (p.activities.get(i).info.enabled) num++;
224 }
225 pi.activities = new ActivityInfo[num];
226 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700227 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 final Activity activity = p.activities.get(i);
229 if (activity.info.enabled
230 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700231 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 }
233 }
234 }
235 }
236 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
237 int N = p.receivers.size();
238 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700239 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
240 pi.receivers = new ActivityInfo[N];
241 } else {
242 int num = 0;
243 for (int i=0; i<N; i++) {
244 if (p.receivers.get(i).info.enabled) num++;
245 }
246 pi.receivers = new ActivityInfo[num];
247 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700248 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 final Activity activity = p.receivers.get(i);
250 if (activity.info.enabled
251 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700252 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 }
255 }
256 }
257 if ((flags&PackageManager.GET_SERVICES) != 0) {
258 int N = p.services.size();
259 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700260 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
261 pi.services = new ServiceInfo[N];
262 } else {
263 int num = 0;
264 for (int i=0; i<N; i++) {
265 if (p.services.get(i).info.enabled) num++;
266 }
267 pi.services = new ServiceInfo[num];
268 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700269 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final Service service = p.services.get(i);
271 if (service.info.enabled
272 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700273 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 }
275 }
276 }
277 }
278 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
279 int N = p.providers.size();
280 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700281 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
282 pi.providers = new ProviderInfo[N];
283 } else {
284 int num = 0;
285 for (int i=0; i<N; i++) {
286 if (p.providers.get(i).info.enabled) num++;
287 }
288 pi.providers = new ProviderInfo[num];
289 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700290 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 final Provider provider = p.providers.get(i);
292 if (provider.info.enabled
293 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700294 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 }
296 }
297 }
298 }
299 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
300 int N = p.instrumentation.size();
301 if (N > 0) {
302 pi.instrumentation = new InstrumentationInfo[N];
303 for (int i=0; i<N; i++) {
304 pi.instrumentation[i] = generateInstrumentationInfo(
305 p.instrumentation.get(i), flags);
306 }
307 }
308 }
309 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
310 int N = p.permissions.size();
311 if (N > 0) {
312 pi.permissions = new PermissionInfo[N];
313 for (int i=0; i<N; i++) {
314 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
315 }
316 }
317 N = p.requestedPermissions.size();
318 if (N > 0) {
319 pi.requestedPermissions = new String[N];
320 for (int i=0; i<N; i++) {
321 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
322 }
323 }
324 }
325 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700326 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
327 if (N > 0) {
328 pi.signatures = new Signature[N];
329 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 }
331 }
332 return pi;
333 }
334
335 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
336 byte[] readBuffer) {
337 try {
338 // We must read the stream for the JarEntry to retrieve
339 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700340 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
342 // not using
343 }
344 is.close();
345 return je != null ? je.getCertificates() : null;
346 } catch (IOException e) {
347 Log.w(TAG, "Exception reading " + je.getName() + " in "
348 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700349 } catch (RuntimeException e) {
350 Log.w(TAG, "Exception reading " + je.getName() + " in "
351 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 }
353 return null;
354 }
355
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800356 public final static int PARSE_IS_SYSTEM = 1<<0;
357 public final static int PARSE_CHATTY = 1<<1;
358 public final static int PARSE_MUST_BE_APK = 1<<2;
359 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
360 public final static int PARSE_FORWARD_LOCK = 1<<4;
361 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700362 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363
364 public int getParseError() {
365 return mParseError;
366 }
367
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800368 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 DisplayMetrics metrics, int flags) {
370 mParseError = PackageManager.INSTALL_SUCCEEDED;
371
372 mArchiveSourcePath = sourceFile.getPath();
373 if (!sourceFile.isFile()) {
374 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
375 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
376 return null;
377 }
378 if (!isPackageFilename(sourceFile.getName())
379 && (flags&PARSE_MUST_BE_APK) != 0) {
380 if ((flags&PARSE_IS_SYSTEM) == 0) {
381 // We expect to have non-.apk files in the system dir,
382 // so don't warn about them.
383 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
384 }
385 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
386 return null;
387 }
388
389 if ((flags&PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
390 TAG, "Scanning package: " + mArchiveSourcePath);
391
392 XmlResourceParser parser = null;
393 AssetManager assmgr = null;
394 boolean assetError = true;
395 try {
396 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700397 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
398 if(cookie != 0) {
399 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 assetError = false;
401 } else {
402 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
403 }
404 } catch (Exception e) {
405 Log.w(TAG, "Unable to read AndroidManifest.xml of "
406 + mArchiveSourcePath, e);
407 }
408 if(assetError) {
409 if (assmgr != null) assmgr.close();
410 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
411 return null;
412 }
413 String[] errorText = new String[1];
414 Package pkg = null;
415 Exception errorException = null;
416 try {
417 // XXXX todo: need to figure out correct configuration.
418 Resources res = new Resources(assmgr, metrics, null);
419 pkg = parsePackage(res, parser, flags, errorText);
420 } catch (Exception e) {
421 errorException = e;
422 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
423 }
424
425
426 if (pkg == null) {
427 if (errorException != null) {
428 Log.w(TAG, mArchiveSourcePath, errorException);
429 } else {
430 Log.w(TAG, mArchiveSourcePath + " (at "
431 + parser.getPositionDescription()
432 + "): " + errorText[0]);
433 }
434 parser.close();
435 assmgr.close();
436 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
437 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
438 }
439 return null;
440 }
441
442 parser.close();
443 assmgr.close();
444
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800445 // Set code and resource paths
446 pkg.mPath = destCodePath;
447 pkg.mScanPath = mArchiveSourcePath;
448 //pkg.applicationInfo.sourceDir = destCodePath;
449 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 pkg.mSignatures = null;
451
452 return pkg;
453 }
454
455 public boolean collectCertificates(Package pkg, int flags) {
456 pkg.mSignatures = null;
457
458 WeakReference<byte[]> readBufferRef;
459 byte[] readBuffer = null;
460 synchronized (mSync) {
461 readBufferRef = mReadBuffer;
462 if (readBufferRef != null) {
463 mReadBuffer = null;
464 readBuffer = readBufferRef.get();
465 }
466 if (readBuffer == null) {
467 readBuffer = new byte[8192];
468 readBufferRef = new WeakReference<byte[]>(readBuffer);
469 }
470 }
471
472 try {
473 JarFile jarFile = new JarFile(mArchiveSourcePath);
474
475 Certificate[] certs = null;
476
477 if ((flags&PARSE_IS_SYSTEM) != 0) {
478 // If this package comes from the system image, then we
479 // can trust it... we'll just use the AndroidManifest.xml
480 // to retrieve its signatures, not validating all of the
481 // files.
482 JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
483 certs = loadCertificates(jarFile, jarEntry, readBuffer);
484 if (certs == null) {
485 Log.e(TAG, "Package " + pkg.packageName
486 + " has no certificates at entry "
487 + jarEntry.getName() + "; ignoring!");
488 jarFile.close();
489 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
490 return false;
491 }
492 if (false) {
493 Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
494 + " certs=" + (certs != null ? certs.length : 0));
495 if (certs != null) {
496 final int N = certs.length;
497 for (int i=0; i<N; i++) {
498 Log.i(TAG, " Public key: "
499 + certs[i].getPublicKey().getEncoded()
500 + " " + certs[i].getPublicKey());
501 }
502 }
503 }
504
505 } else {
506 Enumeration entries = jarFile.entries();
507 while (entries.hasMoreElements()) {
508 JarEntry je = (JarEntry)entries.nextElement();
509 if (je.isDirectory()) continue;
510 if (je.getName().startsWith("META-INF/")) continue;
511 Certificate[] localCerts = loadCertificates(jarFile, je,
512 readBuffer);
513 if (false) {
514 Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
515 + ": certs=" + certs + " ("
516 + (certs != null ? certs.length : 0) + ")");
517 }
518 if (localCerts == null) {
519 Log.e(TAG, "Package " + pkg.packageName
520 + " has no certificates at entry "
521 + je.getName() + "; ignoring!");
522 jarFile.close();
523 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
524 return false;
525 } else if (certs == null) {
526 certs = localCerts;
527 } else {
528 // Ensure all certificates match.
529 for (int i=0; i<certs.length; i++) {
530 boolean found = false;
531 for (int j=0; j<localCerts.length; j++) {
532 if (certs[i] != null &&
533 certs[i].equals(localCerts[j])) {
534 found = true;
535 break;
536 }
537 }
538 if (!found || certs.length != localCerts.length) {
539 Log.e(TAG, "Package " + pkg.packageName
540 + " has mismatched certificates at entry "
541 + je.getName() + "; ignoring!");
542 jarFile.close();
543 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
544 return false;
545 }
546 }
547 }
548 }
549 }
550 jarFile.close();
551
552 synchronized (mSync) {
553 mReadBuffer = readBufferRef;
554 }
555
556 if (certs != null && certs.length > 0) {
557 final int N = certs.length;
558 pkg.mSignatures = new Signature[certs.length];
559 for (int i=0; i<N; i++) {
560 pkg.mSignatures[i] = new Signature(
561 certs[i].getEncoded());
562 }
563 } else {
564 Log.e(TAG, "Package " + pkg.packageName
565 + " has no certificates; ignoring!");
566 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
567 return false;
568 }
569 } catch (CertificateEncodingException e) {
570 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
571 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
572 return false;
573 } catch (IOException e) {
574 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
575 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
576 return false;
577 } catch (RuntimeException e) {
578 Log.w(TAG, "Exception reading " + mArchiveSourcePath, e);
579 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
580 return false;
581 }
582
583 return true;
584 }
585
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800586 /*
587 * Utility method that retrieves just the package name and install
588 * location from the apk location at the given file path.
589 * @param packageFilePath file location of the apk
590 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700591 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800592 */
593 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 XmlResourceParser parser = null;
595 AssetManager assmgr = null;
596 try {
597 assmgr = new AssetManager();
598 int cookie = assmgr.addAssetPath(packageFilePath);
599 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
600 } catch (Exception e) {
601 if (assmgr != null) assmgr.close();
602 Log.w(TAG, "Unable to read AndroidManifest.xml of "
603 + packageFilePath, e);
604 return null;
605 }
606 AttributeSet attrs = parser;
607 String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800608 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 try {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800610 packageLite = parsePackageLite(parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 } catch (IOException e) {
612 Log.w(TAG, packageFilePath, e);
613 } catch (XmlPullParserException e) {
614 Log.w(TAG, packageFilePath, e);
615 } finally {
616 if (parser != null) parser.close();
617 if (assmgr != null) assmgr.close();
618 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800619 if (packageLite == null) {
620 Log.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 return null;
622 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800623 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 }
625
626 private static String validateName(String name, boolean requiresSeparator) {
627 final int N = name.length();
628 boolean hasSep = false;
629 boolean front = true;
630 for (int i=0; i<N; i++) {
631 final char c = name.charAt(i);
632 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
633 front = false;
634 continue;
635 }
636 if (!front) {
637 if ((c >= '0' && c <= '9') || c == '_') {
638 continue;
639 }
640 }
641 if (c == '.') {
642 hasSep = true;
643 front = true;
644 continue;
645 }
646 return "bad character '" + c + "'";
647 }
648 return hasSep || !requiresSeparator
649 ? null : "must have at least one '.' separator";
650 }
651
652 private static String parsePackageName(XmlPullParser parser,
653 AttributeSet attrs, int flags, String[] outError)
654 throws IOException, XmlPullParserException {
655
656 int type;
657 while ((type=parser.next()) != parser.START_TAG
658 && type != parser.END_DOCUMENT) {
659 ;
660 }
661
662 if (type != parser.START_TAG) {
663 outError[0] = "No start tag found";
664 return null;
665 }
666 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
667 TAG, "Root element name: '" + parser.getName() + "'");
668 if (!parser.getName().equals("manifest")) {
669 outError[0] = "No <manifest> tag";
670 return null;
671 }
672 String pkgName = attrs.getAttributeValue(null, "package");
673 if (pkgName == null || pkgName.length() == 0) {
674 outError[0] = "<manifest> does not specify package";
675 return null;
676 }
677 String nameError = validateName(pkgName, true);
678 if (nameError != null && !"android".equals(pkgName)) {
679 outError[0] = "<manifest> specifies bad package name \""
680 + pkgName + "\": " + nameError;
681 return null;
682 }
683
684 return pkgName.intern();
685 }
686
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800687 private static PackageLite parsePackageLite(XmlPullParser parser,
688 AttributeSet attrs, int flags, String[] outError)
689 throws IOException, XmlPullParserException {
690
691 int type;
692 while ((type=parser.next()) != parser.START_TAG
693 && type != parser.END_DOCUMENT) {
694 ;
695 }
696
697 if (type != parser.START_TAG) {
698 outError[0] = "No start tag found";
699 return null;
700 }
701 if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
702 TAG, "Root element name: '" + parser.getName() + "'");
703 if (!parser.getName().equals("manifest")) {
704 outError[0] = "No <manifest> tag";
705 return null;
706 }
707 String pkgName = attrs.getAttributeValue(null, "package");
708 if (pkgName == null || pkgName.length() == 0) {
709 outError[0] = "<manifest> does not specify package";
710 return null;
711 }
712 String nameError = validateName(pkgName, true);
713 if (nameError != null && !"android".equals(pkgName)) {
714 outError[0] = "<manifest> specifies bad package name \""
715 + pkgName + "\": " + nameError;
716 return null;
717 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700718 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800719 for (int i = 0; i < attrs.getAttributeCount(); i++) {
720 String attr = attrs.getAttributeName(i);
721 if (attr.equals("installLocation")) {
722 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700723 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800724 break;
725 }
726 }
727 return new PackageLite(pkgName.intern(), installLocation);
728 }
729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 /**
731 * Temporary.
732 */
733 static public Signature stringToSignature(String str) {
734 final int N = str.length();
735 byte[] sig = new byte[N];
736 for (int i=0; i<N; i++) {
737 sig[i] = (byte)str.charAt(i);
738 }
739 return new Signature(sig);
740 }
741
742 private Package parsePackage(
743 Resources res, XmlResourceParser parser, int flags, String[] outError)
744 throws XmlPullParserException, IOException {
745 AttributeSet attrs = parser;
746
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700747 mParseInstrumentationArgs = null;
748 mParseActivityArgs = null;
749 mParseServiceArgs = null;
750 mParseProviderArgs = null;
751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 String pkgName = parsePackageName(parser, attrs, flags, outError);
753 if (pkgName == null) {
754 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
755 return null;
756 }
757 int type;
758
759 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 TypedArray sa = res.obtainAttributes(attrs,
763 com.android.internal.R.styleable.AndroidManifest);
764 pkg.mVersionCode = sa.getInteger(
765 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800766 pkg.mVersionName = sa.getNonConfigurationString(
767 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 if (pkg.mVersionName != null) {
769 pkg.mVersionName = pkg.mVersionName.intern();
770 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800771 String str = sa.getNonConfigurationString(
772 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
773 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 String nameError = validateName(str, true);
775 if (nameError != null && !"android".equals(pkgName)) {
776 outError[0] = "<manifest> specifies bad sharedUserId name \""
777 + str + "\": " + nameError;
778 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
779 return null;
780 }
781 pkg.mSharedUserId = str.intern();
782 pkg.mSharedUserLabel = sa.getResourceId(
783 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
784 }
785 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800786
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800787 pkg.installLocation = sa.getInteger(
788 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700789 PARSE_DEFAULT_INSTALL_LOCATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790
Dianne Hackborn723738c2009-06-25 19:48:04 -0700791 // Resource boolean are -1, so 1 means we don't know the value.
792 int supportsSmallScreens = 1;
793 int supportsNormalScreens = 1;
794 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700795 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700796 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700797 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 int outerDepth = parser.getDepth();
800 while ((type=parser.next()) != parser.END_DOCUMENT
801 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
802 if (type == parser.END_TAG || type == parser.TEXT) {
803 continue;
804 }
805
806 String tagName = parser.getName();
807 if (tagName.equals("application")) {
808 if (foundApp) {
809 if (RIGID_PARSER) {
810 outError[0] = "<manifest> has more than one <application>";
811 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
812 return null;
813 } else {
814 Log.w(TAG, "<manifest> has more than one <application>");
815 XmlUtils.skipCurrentTag(parser);
816 continue;
817 }
818 }
819
820 foundApp = true;
821 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
822 return null;
823 }
824 } else if (tagName.equals("permission-group")) {
825 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
826 return null;
827 }
828 } else if (tagName.equals("permission")) {
829 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
830 return null;
831 }
832 } else if (tagName.equals("permission-tree")) {
833 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
834 return null;
835 }
836 } else if (tagName.equals("uses-permission")) {
837 sa = res.obtainAttributes(attrs,
838 com.android.internal.R.styleable.AndroidManifestUsesPermission);
839
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800840 // Note: don't allow this value to be a reference to a resource
841 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 String name = sa.getNonResourceString(
843 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
844
845 sa.recycle();
846
847 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700848 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
850
851 XmlUtils.skipCurrentTag(parser);
852
853 } else if (tagName.equals("uses-configuration")) {
854 ConfigurationInfo cPref = new ConfigurationInfo();
855 sa = res.obtainAttributes(attrs,
856 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
857 cPref.reqTouchScreen = sa.getInt(
858 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
859 Configuration.TOUCHSCREEN_UNDEFINED);
860 cPref.reqKeyboardType = sa.getInt(
861 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
862 Configuration.KEYBOARD_UNDEFINED);
863 if (sa.getBoolean(
864 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
865 false)) {
866 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
867 }
868 cPref.reqNavigation = sa.getInt(
869 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
870 Configuration.NAVIGATION_UNDEFINED);
871 if (sa.getBoolean(
872 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
873 false)) {
874 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
875 }
876 sa.recycle();
877 pkg.configPreferences.add(cPref);
878
879 XmlUtils.skipCurrentTag(parser);
880
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700881 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700882 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700883 sa = res.obtainAttributes(attrs,
884 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800885 // Note: don't allow this value to be a reference to a resource
886 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700887 fi.name = sa.getNonResourceString(
888 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
889 if (fi.name == null) {
890 fi.reqGlEsVersion = sa.getInt(
891 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
892 FeatureInfo.GL_ES_VERSION_UNDEFINED);
893 }
894 if (sa.getBoolean(
895 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
896 true)) {
897 fi.flags |= FeatureInfo.FLAG_REQUIRED;
898 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700899 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700900 if (pkg.reqFeatures == null) {
901 pkg.reqFeatures = new ArrayList<FeatureInfo>();
902 }
903 pkg.reqFeatures.add(fi);
904
905 if (fi.name == null) {
906 ConfigurationInfo cPref = new ConfigurationInfo();
907 cPref.reqGlEsVersion = fi.reqGlEsVersion;
908 pkg.configPreferences.add(cPref);
909 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700910
911 XmlUtils.skipCurrentTag(parser);
912
Dianne Hackborn851a5412009-05-08 12:06:44 -0700913 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700914 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 sa = res.obtainAttributes(attrs,
916 com.android.internal.R.styleable.AndroidManifestUsesSdk);
917
Dianne Hackborn851a5412009-05-08 12:06:44 -0700918 int minVers = 0;
919 String minCode = null;
920 int targetVers = 0;
921 String targetCode = null;
922
923 TypedValue val = sa.peekValue(
924 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
925 if (val != null) {
926 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
927 targetCode = minCode = val.string.toString();
928 } else {
929 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700930 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700931 }
932 }
933
934 val = sa.peekValue(
935 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
936 if (val != null) {
937 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
938 targetCode = minCode = val.string.toString();
939 } else {
940 // If it's not a string, it's an integer.
941 targetVers = val.data;
942 }
943 }
944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 sa.recycle();
946
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700947 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700948 if (!minCode.equals(SDK_CODENAME)) {
949 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700950 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700951 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700952 } else {
953 outError[0] = "Requires development platform " + minCode
954 + " but this is a release platform.";
955 }
956 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
957 return null;
958 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700959 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700960 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700961 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700962 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
963 return null;
964 }
965
Dianne Hackborn851a5412009-05-08 12:06:44 -0700966 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700967 if (!targetCode.equals(SDK_CODENAME)) {
968 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700969 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700970 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700971 } else {
972 outError[0] = "Requires development platform " + targetCode
973 + " but this is a release platform.";
974 }
975 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
976 return null;
977 }
978 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700979 pkg.applicationInfo.targetSdkVersion
980 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
981 } else {
982 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 }
985
986 XmlUtils.skipCurrentTag(parser);
987
Dianne Hackborn723738c2009-06-25 19:48:04 -0700988 } else if (tagName.equals("supports-screens")) {
989 sa = res.obtainAttributes(attrs,
990 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
991
992 // This is a trick to get a boolean and still able to detect
993 // if a value was actually set.
994 supportsSmallScreens = sa.getInteger(
995 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
996 supportsSmallScreens);
997 supportsNormalScreens = sa.getInteger(
998 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
999 supportsNormalScreens);
1000 supportsLargeScreens = sa.getInteger(
1001 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1002 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001003 supportsXLargeScreens = sa.getInteger(
1004 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1005 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001006 resizeable = sa.getInteger(
1007 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001008 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001009 anyDensity = sa.getInteger(
1010 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1011 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001012
1013 sa.recycle();
1014
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001015 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001016
1017 } else if (tagName.equals("protected-broadcast")) {
1018 sa = res.obtainAttributes(attrs,
1019 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1020
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001021 // Note: don't allow this value to be a reference to a resource
1022 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001023 String name = sa.getNonResourceString(
1024 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1025
1026 sa.recycle();
1027
1028 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1029 if (pkg.protectedBroadcasts == null) {
1030 pkg.protectedBroadcasts = new ArrayList<String>();
1031 }
1032 if (!pkg.protectedBroadcasts.contains(name)) {
1033 pkg.protectedBroadcasts.add(name.intern());
1034 }
1035 }
1036
1037 XmlUtils.skipCurrentTag(parser);
1038
1039 } else if (tagName.equals("instrumentation")) {
1040 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1041 return null;
1042 }
1043
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001044 } else if (tagName.equals("original-package")) {
1045 sa = res.obtainAttributes(attrs,
1046 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1047
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001048 String orig =sa.getNonConfigurationString(
1049 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001050 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001051 if (pkg.mOriginalPackages == null) {
1052 pkg.mOriginalPackages = new ArrayList<String>();
1053 pkg.mRealPackage = pkg.packageName;
1054 }
1055 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001056 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001057
1058 sa.recycle();
1059
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001060 XmlUtils.skipCurrentTag(parser);
1061
1062 } else if (tagName.equals("adopt-permissions")) {
1063 sa = res.obtainAttributes(attrs,
1064 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1065
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001066 String name = sa.getNonConfigurationString(
1067 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001068
1069 sa.recycle();
1070
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001071 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001072 if (pkg.mAdoptPermissions == null) {
1073 pkg.mAdoptPermissions = new ArrayList<String>();
1074 }
1075 pkg.mAdoptPermissions.add(name);
1076 }
1077
1078 XmlUtils.skipCurrentTag(parser);
1079
Dianne Hackborn854060a2009-07-09 18:14:31 -07001080 } else if (tagName.equals("eat-comment")) {
1081 // Just skip this tag
1082 XmlUtils.skipCurrentTag(parser);
1083 continue;
1084
1085 } else if (RIGID_PARSER) {
1086 outError[0] = "Bad element under <manifest>: "
1087 + parser.getName();
1088 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1089 return null;
1090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001092 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
1093 + " at " + mArchiveSourcePath + " "
1094 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 XmlUtils.skipCurrentTag(parser);
1096 continue;
1097 }
1098 }
1099
1100 if (!foundApp && pkg.instrumentation.size() == 0) {
1101 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1102 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1103 }
1104
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001105 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001106 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001107 for (int ip=0; ip<NP; ip++) {
1108 final PackageParser.NewPermissionInfo npi
1109 = PackageParser.NEW_PERMISSIONS[ip];
1110 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1111 break;
1112 }
1113 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001114 if (implicitPerms == null) {
1115 implicitPerms = new StringBuilder(128);
1116 implicitPerms.append(pkg.packageName);
1117 implicitPerms.append(": compat added ");
1118 } else {
1119 implicitPerms.append(' ');
1120 }
1121 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001122 pkg.requestedPermissions.add(npi.name);
1123 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001124 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001125 if (implicitPerms != null) {
1126 Log.i(TAG, implicitPerms.toString());
1127 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001128
Dianne Hackborn723738c2009-06-25 19:48:04 -07001129 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1130 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001131 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001132 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1133 }
1134 if (supportsNormalScreens != 0) {
1135 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1136 }
1137 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1138 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001139 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001140 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1141 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001142 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1143 && pkg.applicationInfo.targetSdkVersion
1144 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1145 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1146 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001147 if (resizeable < 0 || (resizeable > 0
1148 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001149 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001150 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1151 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001152 if (anyDensity < 0 || (anyDensity > 0
1153 && pkg.applicationInfo.targetSdkVersion
1154 >= android.os.Build.VERSION_CODES.DONUT)) {
1155 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001156 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 return pkg;
1159 }
1160
1161 private static String buildClassName(String pkg, CharSequence clsSeq,
1162 String[] outError) {
1163 if (clsSeq == null || clsSeq.length() <= 0) {
1164 outError[0] = "Empty class name in package " + pkg;
1165 return null;
1166 }
1167 String cls = clsSeq.toString();
1168 char c = cls.charAt(0);
1169 if (c == '.') {
1170 return (pkg + cls).intern();
1171 }
1172 if (cls.indexOf('.') < 0) {
1173 StringBuilder b = new StringBuilder(pkg);
1174 b.append('.');
1175 b.append(cls);
1176 return b.toString().intern();
1177 }
1178 if (c >= 'a' && c <= 'z') {
1179 return cls.intern();
1180 }
1181 outError[0] = "Bad class name " + cls + " in package " + pkg;
1182 return null;
1183 }
1184
1185 private static String buildCompoundName(String pkg,
1186 CharSequence procSeq, String type, String[] outError) {
1187 String proc = procSeq.toString();
1188 char c = proc.charAt(0);
1189 if (pkg != null && c == ':') {
1190 if (proc.length() < 2) {
1191 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1192 + ": must be at least two characters";
1193 return null;
1194 }
1195 String subName = proc.substring(1);
1196 String nameError = validateName(subName, false);
1197 if (nameError != null) {
1198 outError[0] = "Invalid " + type + " name " + proc + " in package "
1199 + pkg + ": " + nameError;
1200 return null;
1201 }
1202 return (pkg + proc).intern();
1203 }
1204 String nameError = validateName(proc, true);
1205 if (nameError != null && !"system".equals(proc)) {
1206 outError[0] = "Invalid " + type + " name " + proc + " in package "
1207 + pkg + ": " + nameError;
1208 return null;
1209 }
1210 return proc.intern();
1211 }
1212
1213 private static String buildProcessName(String pkg, String defProc,
1214 CharSequence procSeq, int flags, String[] separateProcesses,
1215 String[] outError) {
1216 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1217 return defProc != null ? defProc : pkg;
1218 }
1219 if (separateProcesses != null) {
1220 for (int i=separateProcesses.length-1; i>=0; i--) {
1221 String sp = separateProcesses[i];
1222 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1223 return pkg;
1224 }
1225 }
1226 }
1227 if (procSeq == null || procSeq.length() <= 0) {
1228 return defProc;
1229 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001230 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 }
1232
1233 private static String buildTaskAffinityName(String pkg, String defProc,
1234 CharSequence procSeq, String[] outError) {
1235 if (procSeq == null) {
1236 return defProc;
1237 }
1238 if (procSeq.length() <= 0) {
1239 return null;
1240 }
1241 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1242 }
1243
1244 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1245 XmlPullParser parser, AttributeSet attrs, String[] outError)
1246 throws XmlPullParserException, IOException {
1247 PermissionGroup perm = new PermissionGroup(owner);
1248
1249 TypedArray sa = res.obtainAttributes(attrs,
1250 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1251
1252 if (!parsePackageItemInfo(owner, perm.info, outError,
1253 "<permission-group>", sa,
1254 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1255 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001256 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, 0)) {
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,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001291 com.android.internal.R.styleable.AndroidManifestPermission_icon, 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 sa.recycle();
1293 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1294 return null;
1295 }
1296
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001297 // Note: don't allow this value to be a reference to a resource
1298 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 perm.info.group = sa.getNonResourceString(
1300 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1301 if (perm.info.group != null) {
1302 perm.info.group = perm.info.group.intern();
1303 }
1304
1305 perm.info.descriptionRes = sa.getResourceId(
1306 com.android.internal.R.styleable.AndroidManifestPermission_description,
1307 0);
1308
1309 perm.info.protectionLevel = sa.getInt(
1310 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1311 PermissionInfo.PROTECTION_NORMAL);
1312
1313 sa.recycle();
1314
1315 if (perm.info.protectionLevel == -1) {
1316 outError[0] = "<permission> does not specify protectionLevel";
1317 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1318 return null;
1319 }
1320
1321 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1322 outError)) {
1323 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1324 return null;
1325 }
1326
1327 owner.permissions.add(perm);
1328
1329 return perm;
1330 }
1331
1332 private Permission parsePermissionTree(Package owner, Resources res,
1333 XmlPullParser parser, AttributeSet attrs, String[] outError)
1334 throws XmlPullParserException, IOException {
1335 Permission perm = new Permission(owner);
1336
1337 TypedArray sa = res.obtainAttributes(attrs,
1338 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1339
1340 if (!parsePackageItemInfo(owner, perm.info, outError,
1341 "<permission-tree>", sa,
1342 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1343 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001344 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 sa.recycle();
1346 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1347 return null;
1348 }
1349
1350 sa.recycle();
1351
1352 int index = perm.info.name.indexOf('.');
1353 if (index > 0) {
1354 index = perm.info.name.indexOf('.', index+1);
1355 }
1356 if (index < 0) {
1357 outError[0] = "<permission-tree> name has less than three segments: "
1358 + perm.info.name;
1359 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1360 return null;
1361 }
1362
1363 perm.info.descriptionRes = 0;
1364 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1365 perm.tree = true;
1366
1367 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1368 outError)) {
1369 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1370 return null;
1371 }
1372
1373 owner.permissions.add(perm);
1374
1375 return perm;
1376 }
1377
1378 private Instrumentation parseInstrumentation(Package owner, Resources res,
1379 XmlPullParser parser, AttributeSet attrs, String[] outError)
1380 throws XmlPullParserException, IOException {
1381 TypedArray sa = res.obtainAttributes(attrs,
1382 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1383
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001384 if (mParseInstrumentationArgs == null) {
1385 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1386 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1387 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001388 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001389 mParseInstrumentationArgs.tag = "<instrumentation>";
1390 }
1391
1392 mParseInstrumentationArgs.sa = sa;
1393
1394 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1395 new InstrumentationInfo());
1396 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 sa.recycle();
1398 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1399 return null;
1400 }
1401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001403 // Note: don't allow this value to be a reference to a resource
1404 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 str = sa.getNonResourceString(
1406 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1407 a.info.targetPackage = str != null ? str.intern() : null;
1408
1409 a.info.handleProfiling = sa.getBoolean(
1410 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1411 false);
1412
1413 a.info.functionalTest = sa.getBoolean(
1414 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1415 false);
1416
1417 sa.recycle();
1418
1419 if (a.info.targetPackage == null) {
1420 outError[0] = "<instrumentation> does not specify targetPackage";
1421 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1422 return null;
1423 }
1424
1425 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1426 outError)) {
1427 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1428 return null;
1429 }
1430
1431 owner.instrumentation.add(a);
1432
1433 return a;
1434 }
1435
1436 private boolean parseApplication(Package owner, Resources res,
1437 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1438 throws XmlPullParserException, IOException {
1439 final ApplicationInfo ai = owner.applicationInfo;
1440 final String pkgName = owner.applicationInfo.packageName;
1441
1442 TypedArray sa = res.obtainAttributes(attrs,
1443 com.android.internal.R.styleable.AndroidManifestApplication);
1444
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001445 String name = sa.getNonConfigurationString(
1446 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 if (name != null) {
1448 ai.className = buildClassName(pkgName, name, outError);
1449 if (ai.className == null) {
1450 sa.recycle();
1451 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1452 return false;
1453 }
1454 }
1455
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001456 String manageSpaceActivity = sa.getNonConfigurationString(
1457 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 if (manageSpaceActivity != null) {
1459 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1460 outError);
1461 }
1462
Christopher Tate181fafa2009-05-14 11:12:14 -07001463 boolean allowBackup = sa.getBoolean(
1464 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1465 if (allowBackup) {
1466 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001467
Christopher Tate3de55bc2010-03-12 17:28:08 -08001468 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1469 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001470 String backupAgent = sa.getNonConfigurationString(
1471 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001472 if (backupAgent != null) {
1473 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001474 if (false) {
1475 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1476 + " from " + pkgName + "+" + backupAgent);
1477 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001478
1479 if (sa.getBoolean(
1480 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1481 true)) {
1482 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1483 }
1484 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001485 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1486 false)) {
1487 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1488 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001489 }
1490 }
1491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 TypedValue v = sa.peekValue(
1493 com.android.internal.R.styleable.AndroidManifestApplication_label);
1494 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1495 ai.nonLocalizedLabel = v.coerceToString();
1496 }
1497
1498 ai.icon = sa.getResourceId(
1499 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1500 ai.theme = sa.getResourceId(
1501 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1502 ai.descriptionRes = sa.getResourceId(
1503 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1504
1505 if ((flags&PARSE_IS_SYSTEM) != 0) {
1506 if (sa.getBoolean(
1507 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1508 false)) {
1509 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1510 }
1511 }
1512
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001513 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1514 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1515 }
1516
1517 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001518 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001519 }
1520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 if (sa.getBoolean(
1522 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1523 false)) {
1524 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1525 }
1526
1527 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001528 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001529 false)) {
1530 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1531 }
1532
1533 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1535 true)) {
1536 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1537 }
1538
1539 if (sa.getBoolean(
1540 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1541 false)) {
1542 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1543 }
1544
1545 if (sa.getBoolean(
1546 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1547 true)) {
1548 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1549 }
1550
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001551 if (sa.getBoolean(
1552 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001553 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001554 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1555 }
1556
Oscar Montemayor1874aa42009-11-10 18:35:33 -08001557 if (sa.getBoolean(
1558 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt,
1559 false)) {
1560 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT;
1561 }
1562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001564 str = sa.getNonConfigurationString(
1565 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1567
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001568 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1569 str = sa.getNonConfigurationString(
1570 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1571 } else {
1572 // Some older apps have been seen to use a resource reference
1573 // here that on older builds was ignored (with a warning). We
1574 // need to continue to do this for them so they don't break.
1575 str = sa.getNonResourceString(
1576 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1579 str, outError);
1580
1581 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001582 CharSequence pname;
1583 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1584 pname = sa.getNonConfigurationString(
1585 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1586 } else {
1587 // Some older apps have been seen to use a resource reference
1588 // here that on older builds was ignored (with a warning). We
1589 // need to continue to do this for them so they don't break.
1590 pname = sa.getNonResourceString(
1591 com.android.internal.R.styleable.AndroidManifestApplication_process);
1592 }
1593 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 flags, mSeparateProcesses, outError);
1595
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001596 ai.enabled = sa.getBoolean(
1597 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001598
Dianne Hackborn02486b12010-08-26 14:18:37 -07001599 if (false) {
1600 if (sa.getBoolean(
1601 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1602 false)) {
1603 ai.flags |= ApplicationInfo.CANT_SAVE_STATE;
1604
1605 // A heavy-weight application can not be in a custom process.
1606 // We can do direct compare because we intern all strings.
1607 if (ai.processName != null && ai.processName != ai.packageName) {
1608 outError[0] = "cantSaveState applications can not use custom processes";
1609 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001610 }
1611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 }
1613
1614 sa.recycle();
1615
1616 if (outError[0] != null) {
1617 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1618 return false;
1619 }
1620
1621 final int innerDepth = parser.getDepth();
1622
1623 int type;
1624 while ((type=parser.next()) != parser.END_DOCUMENT
1625 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1626 if (type == parser.END_TAG || type == parser.TEXT) {
1627 continue;
1628 }
1629
1630 String tagName = parser.getName();
1631 if (tagName.equals("activity")) {
1632 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1633 if (a == null) {
1634 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1635 return false;
1636 }
1637
1638 owner.activities.add(a);
1639
1640 } else if (tagName.equals("receiver")) {
1641 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1642 if (a == null) {
1643 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1644 return false;
1645 }
1646
1647 owner.receivers.add(a);
1648
1649 } else if (tagName.equals("service")) {
1650 Service s = parseService(owner, res, parser, attrs, flags, outError);
1651 if (s == null) {
1652 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1653 return false;
1654 }
1655
1656 owner.services.add(s);
1657
1658 } else if (tagName.equals("provider")) {
1659 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1660 if (p == null) {
1661 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1662 return false;
1663 }
1664
1665 owner.providers.add(p);
1666
1667 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001668 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 if (a == null) {
1670 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1671 return false;
1672 }
1673
1674 owner.activities.add(a);
1675
1676 } else if (parser.getName().equals("meta-data")) {
1677 // note: application meta-data is stored off to the side, so it can
1678 // remain null in the primary copy (we like to avoid extra copies because
1679 // it can be large)
1680 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1681 outError)) == null) {
1682 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1683 return false;
1684 }
1685
1686 } else if (tagName.equals("uses-library")) {
1687 sa = res.obtainAttributes(attrs,
1688 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1689
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001690 // Note: don't allow this value to be a reference to a resource
1691 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 String lname = sa.getNonResourceString(
1693 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001694 boolean req = sa.getBoolean(
1695 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1696 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697
1698 sa.recycle();
1699
Dianne Hackborn49237342009-08-27 20:08:01 -07001700 if (lname != null) {
1701 if (req) {
1702 if (owner.usesLibraries == null) {
1703 owner.usesLibraries = new ArrayList<String>();
1704 }
1705 if (!owner.usesLibraries.contains(lname)) {
1706 owner.usesLibraries.add(lname.intern());
1707 }
1708 } else {
1709 if (owner.usesOptionalLibraries == null) {
1710 owner.usesOptionalLibraries = new ArrayList<String>();
1711 }
1712 if (!owner.usesOptionalLibraries.contains(lname)) {
1713 owner.usesOptionalLibraries.add(lname.intern());
1714 }
1715 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 }
1717
1718 XmlUtils.skipCurrentTag(parser);
1719
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001720 } else if (tagName.equals("uses-package")) {
1721 // Dependencies for app installers; we don't currently try to
1722 // enforce this.
1723 XmlUtils.skipCurrentTag(parser);
1724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725 } 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 TypedValue v = sa.peekValue(labelRes);
1765 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1766 outInfo.nonLocalizedLabel = v.coerceToString();
1767 }
1768
1769 outInfo.packageName = owner.packageName;
1770
1771 return true;
1772 }
1773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001774 private Activity parseActivity(Package owner, Resources res,
1775 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1776 boolean receiver) throws XmlPullParserException, IOException {
1777 TypedArray sa = res.obtainAttributes(attrs,
1778 com.android.internal.R.styleable.AndroidManifestActivity);
1779
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001780 if (mParseActivityArgs == null) {
1781 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1782 com.android.internal.R.styleable.AndroidManifestActivity_name,
1783 com.android.internal.R.styleable.AndroidManifestActivity_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001784 com.android.internal.R.styleable.AndroidManifestActivity_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001785 mSeparateProcesses,
1786 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001787 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001788 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1789 }
1790
1791 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1792 mParseActivityArgs.sa = sa;
1793 mParseActivityArgs.flags = flags;
1794
1795 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1796 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 sa.recycle();
1798 return null;
1799 }
1800
1801 final boolean setExported = sa.hasValue(
1802 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1803 if (setExported) {
1804 a.info.exported = sa.getBoolean(
1805 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1806 }
1807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 a.info.theme = sa.getResourceId(
1809 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1810
1811 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001812 str = sa.getNonConfigurationString(
1813 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 if (str == null) {
1815 a.info.permission = owner.applicationInfo.permission;
1816 } else {
1817 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1818 }
1819
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001820 str = sa.getNonConfigurationString(
1821 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1823 owner.applicationInfo.taskAffinity, str, outError);
1824
1825 a.info.flags = 0;
1826 if (sa.getBoolean(
1827 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1828 false)) {
1829 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1830 }
1831
1832 if (sa.getBoolean(
1833 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1834 false)) {
1835 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1836 }
1837
1838 if (sa.getBoolean(
1839 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1840 false)) {
1841 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1842 }
1843
1844 if (sa.getBoolean(
1845 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1846 false)) {
1847 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1848 }
1849
1850 if (sa.getBoolean(
1851 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1852 false)) {
1853 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1854 }
1855
1856 if (sa.getBoolean(
1857 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1858 false)) {
1859 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1860 }
1861
1862 if (sa.getBoolean(
1863 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1864 false)) {
1865 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1866 }
1867
1868 if (sa.getBoolean(
1869 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1870 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1871 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1872 }
1873
Dianne Hackbornffa42482009-09-23 22:20:11 -07001874 if (sa.getBoolean(
1875 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1876 false)) {
1877 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1878 }
1879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 if (!receiver) {
1881 a.info.launchMode = sa.getInt(
1882 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1883 ActivityInfo.LAUNCH_MULTIPLE);
1884 a.info.screenOrientation = sa.getInt(
1885 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1886 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1887 a.info.configChanges = sa.getInt(
1888 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1889 0);
1890 a.info.softInputMode = sa.getInt(
1891 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1892 0);
1893 } else {
1894 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1895 a.info.configChanges = 0;
1896 }
1897
1898 sa.recycle();
1899
Dianne Hackborn02486b12010-08-26 14:18:37 -07001900 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001901 // A heavy-weight application can not have receives in its main process
1902 // We can do direct compare because we intern all strings.
1903 if (a.info.processName == owner.packageName) {
1904 outError[0] = "Heavy-weight applications can not have receivers in main process";
1905 }
1906 }
1907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001908 if (outError[0] != null) {
1909 return null;
1910 }
1911
1912 int outerDepth = parser.getDepth();
1913 int type;
1914 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1915 && (type != XmlPullParser.END_TAG
1916 || parser.getDepth() > outerDepth)) {
1917 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1918 continue;
1919 }
1920
1921 if (parser.getName().equals("intent-filter")) {
1922 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1923 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1924 return null;
1925 }
1926 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001927 Log.w(TAG, "No actions in intent filter at "
1928 + mArchiveSourcePath + " "
1929 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 } else {
1931 a.intents.add(intent);
1932 }
1933 } else if (parser.getName().equals("meta-data")) {
1934 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1935 outError)) == null) {
1936 return null;
1937 }
1938 } else {
1939 if (!RIGID_PARSER) {
1940 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1941 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001942 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1943 + " at " + mArchiveSourcePath + " "
1944 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001946 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1947 + " at " + mArchiveSourcePath + " "
1948 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 }
1950 XmlUtils.skipCurrentTag(parser);
1951 continue;
1952 }
1953 if (receiver) {
1954 outError[0] = "Bad element under <receiver>: " + parser.getName();
1955 } else {
1956 outError[0] = "Bad element under <activity>: " + parser.getName();
1957 }
1958 return null;
1959 }
1960 }
1961
1962 if (!setExported) {
1963 a.info.exported = a.intents.size() > 0;
1964 }
1965
1966 return a;
1967 }
1968
1969 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001970 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1971 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 TypedArray sa = res.obtainAttributes(attrs,
1973 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1974
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001975 String targetActivity = sa.getNonConfigurationString(
1976 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 if (targetActivity == null) {
1978 outError[0] = "<activity-alias> does not specify android:targetActivity";
1979 sa.recycle();
1980 return null;
1981 }
1982
1983 targetActivity = buildClassName(owner.applicationInfo.packageName,
1984 targetActivity, outError);
1985 if (targetActivity == null) {
1986 sa.recycle();
1987 return null;
1988 }
1989
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001990 if (mParseActivityAliasArgs == null) {
1991 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1992 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1993 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001994 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001995 mSeparateProcesses,
1996 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001997 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001998 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1999 mParseActivityAliasArgs.tag = "<activity-alias>";
2000 }
2001
2002 mParseActivityAliasArgs.sa = sa;
2003 mParseActivityAliasArgs.flags = flags;
2004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 Activity target = null;
2006
2007 final int NA = owner.activities.size();
2008 for (int i=0; i<NA; i++) {
2009 Activity t = owner.activities.get(i);
2010 if (targetActivity.equals(t.info.name)) {
2011 target = t;
2012 break;
2013 }
2014 }
2015
2016 if (target == null) {
2017 outError[0] = "<activity-alias> target activity " + targetActivity
2018 + " not found in manifest";
2019 sa.recycle();
2020 return null;
2021 }
2022
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002023 ActivityInfo info = new ActivityInfo();
2024 info.targetActivity = targetActivity;
2025 info.configChanges = target.info.configChanges;
2026 info.flags = target.info.flags;
2027 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002028 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002029 info.labelRes = target.info.labelRes;
2030 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2031 info.launchMode = target.info.launchMode;
2032 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002033 if (info.descriptionRes == 0) {
2034 info.descriptionRes = target.info.descriptionRes;
2035 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002036 info.screenOrientation = target.info.screenOrientation;
2037 info.taskAffinity = target.info.taskAffinity;
2038 info.theme = target.info.theme;
2039
2040 Activity a = new Activity(mParseActivityAliasArgs, info);
2041 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 sa.recycle();
2043 return null;
2044 }
2045
2046 final boolean setExported = sa.hasValue(
2047 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2048 if (setExported) {
2049 a.info.exported = sa.getBoolean(
2050 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2051 }
2052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002054 str = sa.getNonConfigurationString(
2055 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 if (str != null) {
2057 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2058 }
2059
2060 sa.recycle();
2061
2062 if (outError[0] != null) {
2063 return null;
2064 }
2065
2066 int outerDepth = parser.getDepth();
2067 int type;
2068 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2069 && (type != XmlPullParser.END_TAG
2070 || parser.getDepth() > outerDepth)) {
2071 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2072 continue;
2073 }
2074
2075 if (parser.getName().equals("intent-filter")) {
2076 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2077 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2078 return null;
2079 }
2080 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002081 Log.w(TAG, "No actions in intent filter at "
2082 + mArchiveSourcePath + " "
2083 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 } else {
2085 a.intents.add(intent);
2086 }
2087 } else if (parser.getName().equals("meta-data")) {
2088 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2089 outError)) == null) {
2090 return null;
2091 }
2092 } else {
2093 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002094 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2095 + " at " + mArchiveSourcePath + " "
2096 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 XmlUtils.skipCurrentTag(parser);
2098 continue;
2099 }
2100 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2101 return null;
2102 }
2103 }
2104
2105 if (!setExported) {
2106 a.info.exported = a.intents.size() > 0;
2107 }
2108
2109 return a;
2110 }
2111
2112 private Provider parseProvider(Package owner, Resources res,
2113 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2114 throws XmlPullParserException, IOException {
2115 TypedArray sa = res.obtainAttributes(attrs,
2116 com.android.internal.R.styleable.AndroidManifestProvider);
2117
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002118 if (mParseProviderArgs == null) {
2119 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2120 com.android.internal.R.styleable.AndroidManifestProvider_name,
2121 com.android.internal.R.styleable.AndroidManifestProvider_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002122 com.android.internal.R.styleable.AndroidManifestProvider_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002123 mSeparateProcesses,
2124 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002125 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002126 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2127 mParseProviderArgs.tag = "<provider>";
2128 }
2129
2130 mParseProviderArgs.sa = sa;
2131 mParseProviderArgs.flags = flags;
2132
2133 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2134 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 sa.recycle();
2136 return null;
2137 }
2138
2139 p.info.exported = sa.getBoolean(
2140 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2141
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002142 String cpname = sa.getNonConfigurationString(
2143 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144
2145 p.info.isSyncable = sa.getBoolean(
2146 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2147 false);
2148
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002149 String permission = sa.getNonConfigurationString(
2150 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2151 String str = sa.getNonConfigurationString(
2152 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 if (str == null) {
2154 str = permission;
2155 }
2156 if (str == null) {
2157 p.info.readPermission = owner.applicationInfo.permission;
2158 } else {
2159 p.info.readPermission =
2160 str.length() > 0 ? str.toString().intern() : null;
2161 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002162 str = sa.getNonConfigurationString(
2163 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 if (str == null) {
2165 str = permission;
2166 }
2167 if (str == null) {
2168 p.info.writePermission = owner.applicationInfo.permission;
2169 } else {
2170 p.info.writePermission =
2171 str.length() > 0 ? str.toString().intern() : null;
2172 }
2173
2174 p.info.grantUriPermissions = sa.getBoolean(
2175 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2176 false);
2177
2178 p.info.multiprocess = sa.getBoolean(
2179 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2180 false);
2181
2182 p.info.initOrder = sa.getInt(
2183 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2184 0);
2185
2186 sa.recycle();
2187
Dianne Hackborn02486b12010-08-26 14:18:37 -07002188 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002189 // A heavy-weight application can not have providers in its main process
2190 // We can do direct compare because we intern all strings.
2191 if (p.info.processName == owner.packageName) {
2192 outError[0] = "Heavy-weight applications can not have providers in main process";
2193 return null;
2194 }
2195 }
2196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 if (cpname == null) {
2198 outError[0] = "<provider> does not incude authorities attribute";
2199 return null;
2200 }
2201 p.info.authority = cpname.intern();
2202
2203 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2204 return null;
2205 }
2206
2207 return p;
2208 }
2209
2210 private boolean parseProviderTags(Resources res,
2211 XmlPullParser parser, AttributeSet attrs,
2212 Provider outInfo, String[] outError)
2213 throws XmlPullParserException, IOException {
2214 int outerDepth = parser.getDepth();
2215 int type;
2216 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2217 && (type != XmlPullParser.END_TAG
2218 || parser.getDepth() > outerDepth)) {
2219 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2220 continue;
2221 }
2222
2223 if (parser.getName().equals("meta-data")) {
2224 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2225 outInfo.metaData, outError)) == null) {
2226 return false;
2227 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229 } else if (parser.getName().equals("grant-uri-permission")) {
2230 TypedArray sa = res.obtainAttributes(attrs,
2231 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2232
2233 PatternMatcher pa = null;
2234
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002235 String str = sa.getNonConfigurationString(
2236 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 if (str != null) {
2238 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2239 }
2240
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002241 str = sa.getNonConfigurationString(
2242 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 if (str != null) {
2244 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2245 }
2246
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002247 str = sa.getNonConfigurationString(
2248 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 if (str != null) {
2250 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2251 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 sa.recycle();
2254
2255 if (pa != null) {
2256 if (outInfo.info.uriPermissionPatterns == null) {
2257 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2258 outInfo.info.uriPermissionPatterns[0] = pa;
2259 } else {
2260 final int N = outInfo.info.uriPermissionPatterns.length;
2261 PatternMatcher[] newp = new PatternMatcher[N+1];
2262 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2263 newp[N] = pa;
2264 outInfo.info.uriPermissionPatterns = newp;
2265 }
2266 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002267 } else {
2268 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002269 Log.w(TAG, "Unknown element under <path-permission>: "
2270 + parser.getName() + " at " + mArchiveSourcePath + " "
2271 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002272 XmlUtils.skipCurrentTag(parser);
2273 continue;
2274 }
2275 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2276 return false;
2277 }
2278 XmlUtils.skipCurrentTag(parser);
2279
2280 } else if (parser.getName().equals("path-permission")) {
2281 TypedArray sa = res.obtainAttributes(attrs,
2282 com.android.internal.R.styleable.AndroidManifestPathPermission);
2283
2284 PathPermission pa = null;
2285
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002286 String permission = sa.getNonConfigurationString(
2287 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2288 String readPermission = sa.getNonConfigurationString(
2289 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002290 if (readPermission == null) {
2291 readPermission = permission;
2292 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002293 String writePermission = sa.getNonConfigurationString(
2294 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002295 if (writePermission == null) {
2296 writePermission = permission;
2297 }
2298
2299 boolean havePerm = false;
2300 if (readPermission != null) {
2301 readPermission = readPermission.intern();
2302 havePerm = true;
2303 }
2304 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002305 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002306 havePerm = true;
2307 }
2308
2309 if (!havePerm) {
2310 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002311 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2312 + parser.getName() + " at " + mArchiveSourcePath + " "
2313 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002314 XmlUtils.skipCurrentTag(parser);
2315 continue;
2316 }
2317 outError[0] = "No readPermission or writePermssion for <path-permission>";
2318 return false;
2319 }
2320
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002321 String path = sa.getNonConfigurationString(
2322 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002323 if (path != null) {
2324 pa = new PathPermission(path,
2325 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2326 }
2327
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002328 path = sa.getNonConfigurationString(
2329 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002330 if (path != null) {
2331 pa = new PathPermission(path,
2332 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2333 }
2334
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002335 path = sa.getNonConfigurationString(
2336 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002337 if (path != null) {
2338 pa = new PathPermission(path,
2339 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2340 }
2341
2342 sa.recycle();
2343
2344 if (pa != null) {
2345 if (outInfo.info.pathPermissions == null) {
2346 outInfo.info.pathPermissions = new PathPermission[1];
2347 outInfo.info.pathPermissions[0] = pa;
2348 } else {
2349 final int N = outInfo.info.pathPermissions.length;
2350 PathPermission[] newp = new PathPermission[N+1];
2351 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2352 newp[N] = pa;
2353 outInfo.info.pathPermissions = newp;
2354 }
2355 } else {
2356 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002357 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2358 + parser.getName() + " at " + mArchiveSourcePath + " "
2359 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002360 XmlUtils.skipCurrentTag(parser);
2361 continue;
2362 }
2363 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2364 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 }
2366 XmlUtils.skipCurrentTag(parser);
2367
2368 } else {
2369 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002371 + parser.getName() + " at " + mArchiveSourcePath + " "
2372 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 XmlUtils.skipCurrentTag(parser);
2374 continue;
2375 }
2376 outError[0] = "Bad element under <provider>: "
2377 + parser.getName();
2378 return false;
2379 }
2380 }
2381 return true;
2382 }
2383
2384 private Service parseService(Package owner, Resources res,
2385 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2386 throws XmlPullParserException, IOException {
2387 TypedArray sa = res.obtainAttributes(attrs,
2388 com.android.internal.R.styleable.AndroidManifestService);
2389
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002390 if (mParseServiceArgs == null) {
2391 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2392 com.android.internal.R.styleable.AndroidManifestService_name,
2393 com.android.internal.R.styleable.AndroidManifestService_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002394 com.android.internal.R.styleable.AndroidManifestService_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002395 mSeparateProcesses,
2396 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002397 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002398 com.android.internal.R.styleable.AndroidManifestService_enabled);
2399 mParseServiceArgs.tag = "<service>";
2400 }
2401
2402 mParseServiceArgs.sa = sa;
2403 mParseServiceArgs.flags = flags;
2404
2405 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2406 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 sa.recycle();
2408 return null;
2409 }
2410
2411 final boolean setExported = sa.hasValue(
2412 com.android.internal.R.styleable.AndroidManifestService_exported);
2413 if (setExported) {
2414 s.info.exported = sa.getBoolean(
2415 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2416 }
2417
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002418 String str = sa.getNonConfigurationString(
2419 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 if (str == null) {
2421 s.info.permission = owner.applicationInfo.permission;
2422 } else {
2423 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2424 }
2425
2426 sa.recycle();
2427
Dianne Hackborn02486b12010-08-26 14:18:37 -07002428 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002429 // A heavy-weight application can not have services in its main process
2430 // We can do direct compare because we intern all strings.
2431 if (s.info.processName == owner.packageName) {
2432 outError[0] = "Heavy-weight applications can not have services in main process";
2433 return null;
2434 }
2435 }
2436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 int outerDepth = parser.getDepth();
2438 int type;
2439 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2440 && (type != XmlPullParser.END_TAG
2441 || parser.getDepth() > outerDepth)) {
2442 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2443 continue;
2444 }
2445
2446 if (parser.getName().equals("intent-filter")) {
2447 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2448 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2449 return null;
2450 }
2451
2452 s.intents.add(intent);
2453 } else if (parser.getName().equals("meta-data")) {
2454 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2455 outError)) == null) {
2456 return null;
2457 }
2458 } else {
2459 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002461 + parser.getName() + " at " + mArchiveSourcePath + " "
2462 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 XmlUtils.skipCurrentTag(parser);
2464 continue;
2465 }
2466 outError[0] = "Bad element under <service>: "
2467 + parser.getName();
2468 return null;
2469 }
2470 }
2471
2472 if (!setExported) {
2473 s.info.exported = s.intents.size() > 0;
2474 }
2475
2476 return s;
2477 }
2478
2479 private boolean parseAllMetaData(Resources res,
2480 XmlPullParser parser, AttributeSet attrs, String tag,
2481 Component outInfo, String[] outError)
2482 throws XmlPullParserException, IOException {
2483 int outerDepth = parser.getDepth();
2484 int type;
2485 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2486 && (type != XmlPullParser.END_TAG
2487 || parser.getDepth() > outerDepth)) {
2488 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2489 continue;
2490 }
2491
2492 if (parser.getName().equals("meta-data")) {
2493 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2494 outInfo.metaData, outError)) == null) {
2495 return false;
2496 }
2497 } else {
2498 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002500 + parser.getName() + " at " + mArchiveSourcePath + " "
2501 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 XmlUtils.skipCurrentTag(parser);
2503 continue;
2504 }
2505 outError[0] = "Bad element under " + tag + ": "
2506 + parser.getName();
2507 return false;
2508 }
2509 }
2510 return true;
2511 }
2512
2513 private Bundle parseMetaData(Resources res,
2514 XmlPullParser parser, AttributeSet attrs,
2515 Bundle data, String[] outError)
2516 throws XmlPullParserException, IOException {
2517
2518 TypedArray sa = res.obtainAttributes(attrs,
2519 com.android.internal.R.styleable.AndroidManifestMetaData);
2520
2521 if (data == null) {
2522 data = new Bundle();
2523 }
2524
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002525 String name = sa.getNonConfigurationString(
2526 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (name == null) {
2528 outError[0] = "<meta-data> requires an android:name attribute";
2529 sa.recycle();
2530 return null;
2531 }
2532
Dianne Hackborn854060a2009-07-09 18:14:31 -07002533 name = name.intern();
2534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 TypedValue v = sa.peekValue(
2536 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2537 if (v != null && v.resourceId != 0) {
2538 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2539 data.putInt(name, v.resourceId);
2540 } else {
2541 v = sa.peekValue(
2542 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2543 //Log.i(TAG, "Meta data " + name + ": " + v);
2544 if (v != null) {
2545 if (v.type == TypedValue.TYPE_STRING) {
2546 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002547 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2549 data.putBoolean(name, v.data != 0);
2550 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2551 && v.type <= TypedValue.TYPE_LAST_INT) {
2552 data.putInt(name, v.data);
2553 } else if (v.type == TypedValue.TYPE_FLOAT) {
2554 data.putFloat(name, v.getFloat());
2555 } else {
2556 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002557 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2558 + parser.getName() + " at " + mArchiveSourcePath + " "
2559 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 } else {
2561 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2562 data = null;
2563 }
2564 }
2565 } else {
2566 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2567 data = null;
2568 }
2569 }
2570
2571 sa.recycle();
2572
2573 XmlUtils.skipCurrentTag(parser);
2574
2575 return data;
2576 }
2577
2578 private static final String ANDROID_RESOURCES
2579 = "http://schemas.android.com/apk/res/android";
2580
2581 private boolean parseIntent(Resources res,
2582 XmlPullParser parser, AttributeSet attrs, int flags,
2583 IntentInfo outInfo, String[] outError, boolean isActivity)
2584 throws XmlPullParserException, IOException {
2585
2586 TypedArray sa = res.obtainAttributes(attrs,
2587 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2588
2589 int priority = sa.getInt(
2590 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2591 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2592 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002593 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 + parser.getPositionDescription());
2595 priority = 0;
2596 }
2597 outInfo.setPriority(priority);
2598
2599 TypedValue v = sa.peekValue(
2600 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2601 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2602 outInfo.nonLocalizedLabel = v.coerceToString();
2603 }
2604
2605 outInfo.icon = sa.getResourceId(
2606 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 sa.recycle();
2609
2610 int outerDepth = parser.getDepth();
2611 int type;
2612 while ((type=parser.next()) != parser.END_DOCUMENT
2613 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2614 if (type == parser.END_TAG || type == parser.TEXT) {
2615 continue;
2616 }
2617
2618 String nodeName = parser.getName();
2619 if (nodeName.equals("action")) {
2620 String value = attrs.getAttributeValue(
2621 ANDROID_RESOURCES, "name");
2622 if (value == null || value == "") {
2623 outError[0] = "No value supplied for <android:name>";
2624 return false;
2625 }
2626 XmlUtils.skipCurrentTag(parser);
2627
2628 outInfo.addAction(value);
2629 } else if (nodeName.equals("category")) {
2630 String value = attrs.getAttributeValue(
2631 ANDROID_RESOURCES, "name");
2632 if (value == null || value == "") {
2633 outError[0] = "No value supplied for <android:name>";
2634 return false;
2635 }
2636 XmlUtils.skipCurrentTag(parser);
2637
2638 outInfo.addCategory(value);
2639
2640 } else if (nodeName.equals("data")) {
2641 sa = res.obtainAttributes(attrs,
2642 com.android.internal.R.styleable.AndroidManifestData);
2643
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002644 String str = sa.getNonConfigurationString(
2645 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 if (str != null) {
2647 try {
2648 outInfo.addDataType(str);
2649 } catch (IntentFilter.MalformedMimeTypeException e) {
2650 outError[0] = e.toString();
2651 sa.recycle();
2652 return false;
2653 }
2654 }
2655
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002656 str = sa.getNonConfigurationString(
2657 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 if (str != null) {
2659 outInfo.addDataScheme(str);
2660 }
2661
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002662 String host = sa.getNonConfigurationString(
2663 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2664 String port = sa.getNonConfigurationString(
2665 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 if (host != null) {
2667 outInfo.addDataAuthority(host, port);
2668 }
2669
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002670 str = sa.getNonConfigurationString(
2671 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 if (str != null) {
2673 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2674 }
2675
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002676 str = sa.getNonConfigurationString(
2677 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 if (str != null) {
2679 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2680 }
2681
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002682 str = sa.getNonConfigurationString(
2683 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002684 if (str != null) {
2685 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2686 }
2687
2688 sa.recycle();
2689 XmlUtils.skipCurrentTag(parser);
2690 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002691 Log.w(TAG, "Unknown element under <intent-filter>: "
2692 + parser.getName() + " at " + mArchiveSourcePath + " "
2693 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 XmlUtils.skipCurrentTag(parser);
2695 } else {
2696 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2697 return false;
2698 }
2699 }
2700
2701 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2702 if (false) {
2703 String cats = "";
2704 Iterator<String> it = outInfo.categoriesIterator();
2705 while (it != null && it.hasNext()) {
2706 cats += " " + it.next();
2707 }
2708 System.out.println("Intent d=" +
2709 outInfo.hasDefault + ", cat=" + cats);
2710 }
2711
2712 return true;
2713 }
2714
2715 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002716 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717
2718 // For now we only support one application per package.
2719 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2720
2721 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2722 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2723 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2724 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2725 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2726 public final ArrayList<Service> services = new ArrayList<Service>(0);
2727 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2728
2729 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2730
Dianne Hackborn854060a2009-07-09 18:14:31 -07002731 public ArrayList<String> protectedBroadcasts;
2732
Dianne Hackborn49237342009-08-27 20:08:01 -07002733 public ArrayList<String> usesLibraries = null;
2734 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 public String[] usesLibraryFiles = null;
2736
Dianne Hackbornc1552392010-03-03 16:19:01 -08002737 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002738 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002739 public ArrayList<String> mAdoptPermissions = null;
2740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 // We store the application meta-data independently to avoid multiple unwanted references
2742 public Bundle mAppMetaData = null;
2743
2744 // If this is a 3rd party app, this is the path of the zip file.
2745 public String mPath;
2746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 // The version code declared for this package.
2748 public int mVersionCode;
2749
2750 // The version name declared for this package.
2751 public String mVersionName;
2752
2753 // The shared user id that this package wants to use.
2754 public String mSharedUserId;
2755
2756 // The shared user label that this package wants to use.
2757 public int mSharedUserLabel;
2758
2759 // Signatures that were read from the package.
2760 public Signature mSignatures[];
2761
2762 // For use by package manager service for quick lookup of
2763 // preferred up order.
2764 public int mPreferredOrder = 0;
2765
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002766 // For use by the package manager to keep track of the path to the
2767 // file an app came from.
2768 public String mScanPath;
2769
2770 // For use by package manager to keep track of where it has done dexopt.
2771 public boolean mDidDexOpt;
2772
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002773 // User set enabled state.
2774 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 // Additional data supplied by callers.
2777 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002778
2779 // Whether an operation is currently pending on this package
2780 public boolean mOperationPending;
2781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782 /*
2783 * Applications hardware preferences
2784 */
2785 public final ArrayList<ConfigurationInfo> configPreferences =
2786 new ArrayList<ConfigurationInfo>();
2787
Dianne Hackborn49237342009-08-27 20:08:01 -07002788 /*
2789 * Applications requested features
2790 */
2791 public ArrayList<FeatureInfo> reqFeatures = null;
2792
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002793 public int installLocation;
2794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 public Package(String _name) {
2796 packageName = _name;
2797 applicationInfo.packageName = _name;
2798 applicationInfo.uid = -1;
2799 }
2800
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002801 public void setPackageName(String newName) {
2802 packageName = newName;
2803 applicationInfo.packageName = newName;
2804 for (int i=permissions.size()-1; i>=0; i--) {
2805 permissions.get(i).setPackageName(newName);
2806 }
2807 for (int i=permissionGroups.size()-1; i>=0; i--) {
2808 permissionGroups.get(i).setPackageName(newName);
2809 }
2810 for (int i=activities.size()-1; i>=0; i--) {
2811 activities.get(i).setPackageName(newName);
2812 }
2813 for (int i=receivers.size()-1; i>=0; i--) {
2814 receivers.get(i).setPackageName(newName);
2815 }
2816 for (int i=providers.size()-1; i>=0; i--) {
2817 providers.get(i).setPackageName(newName);
2818 }
2819 for (int i=services.size()-1; i>=0; i--) {
2820 services.get(i).setPackageName(newName);
2821 }
2822 for (int i=instrumentation.size()-1; i>=0; i--) {
2823 instrumentation.get(i).setPackageName(newName);
2824 }
2825 }
2826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 public String toString() {
2828 return "Package{"
2829 + Integer.toHexString(System.identityHashCode(this))
2830 + " " + packageName + "}";
2831 }
2832 }
2833
2834 public static class Component<II extends IntentInfo> {
2835 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002836 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002837 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 public Bundle metaData;
2839
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002840 ComponentName componentName;
2841 String componentShortName;
2842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 public Component(Package _owner) {
2844 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002845 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002846 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002847 }
2848
2849 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2850 owner = args.owner;
2851 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002852 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002853 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002854 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002855 args.outError[0] = args.tag + " does not specify android:name";
2856 return;
2857 }
2858
2859 outInfo.name
2860 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2861 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002862 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002863 args.outError[0] = args.tag + " does not have valid android:name";
2864 return;
2865 }
2866
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002867 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002868
2869 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2870 if (iconVal != 0) {
2871 outInfo.icon = iconVal;
2872 outInfo.nonLocalizedLabel = null;
2873 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002874
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002875 TypedValue v = args.sa.peekValue(args.labelRes);
2876 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2877 outInfo.nonLocalizedLabel = v.coerceToString();
2878 }
2879
2880 outInfo.packageName = owner.packageName;
2881 }
2882
2883 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2884 this(args, (PackageItemInfo)outInfo);
2885 if (args.outError[0] != null) {
2886 return;
2887 }
2888
2889 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002890 CharSequence pname;
2891 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2892 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2893 } else {
2894 // Some older apps have been seen to use a resource reference
2895 // here that on older builds was ignored (with a warning). We
2896 // need to continue to do this for them so they don't break.
2897 pname = args.sa.getNonResourceString(args.processRes);
2898 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002899 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002900 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002901 args.flags, args.sepProcesses, args.outError);
2902 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002903
2904 if (args.descriptionRes != 0) {
2905 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2906 }
2907
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002908 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 }
2910
2911 public Component(Component<II> clone) {
2912 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002913 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002914 className = clone.className;
2915 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002916 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002917 }
2918
2919 public ComponentName getComponentName() {
2920 if (componentName != null) {
2921 return componentName;
2922 }
2923 if (className != null) {
2924 componentName = new ComponentName(owner.applicationInfo.packageName,
2925 className);
2926 }
2927 return componentName;
2928 }
2929
2930 public String getComponentShortName() {
2931 if (componentShortName != null) {
2932 return componentShortName;
2933 }
2934 ComponentName component = getComponentName();
2935 if (component != null) {
2936 componentShortName = component.flattenToShortString();
2937 }
2938 return componentShortName;
2939 }
2940
2941 public void setPackageName(String packageName) {
2942 componentName = null;
2943 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 }
2945 }
2946
2947 public final static class Permission extends Component<IntentInfo> {
2948 public final PermissionInfo info;
2949 public boolean tree;
2950 public PermissionGroup group;
2951
2952 public Permission(Package _owner) {
2953 super(_owner);
2954 info = new PermissionInfo();
2955 }
2956
2957 public Permission(Package _owner, PermissionInfo _info) {
2958 super(_owner);
2959 info = _info;
2960 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002961
2962 public void setPackageName(String packageName) {
2963 super.setPackageName(packageName);
2964 info.packageName = packageName;
2965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966
2967 public String toString() {
2968 return "Permission{"
2969 + Integer.toHexString(System.identityHashCode(this))
2970 + " " + info.name + "}";
2971 }
2972 }
2973
2974 public final static class PermissionGroup extends Component<IntentInfo> {
2975 public final PermissionGroupInfo info;
2976
2977 public PermissionGroup(Package _owner) {
2978 super(_owner);
2979 info = new PermissionGroupInfo();
2980 }
2981
2982 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2983 super(_owner);
2984 info = _info;
2985 }
2986
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002987 public void setPackageName(String packageName) {
2988 super.setPackageName(packageName);
2989 info.packageName = packageName;
2990 }
2991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 public String toString() {
2993 return "PermissionGroup{"
2994 + Integer.toHexString(System.identityHashCode(this))
2995 + " " + info.name + "}";
2996 }
2997 }
2998
2999 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003000 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3001 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3002 if (p.applicationInfo.enabled != enabled) {
3003 return true;
3004 }
3005 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 if ((flags & PackageManager.GET_META_DATA) != 0
3007 && (metaData != null || p.mAppMetaData != null)) {
3008 return true;
3009 }
3010 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3011 && p.usesLibraryFiles != null) {
3012 return true;
3013 }
3014 return false;
3015 }
3016
3017 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3018 if (p == null) return null;
3019 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003020 // CompatibilityMode is global state. It's safe to modify the instance
3021 // of the package.
3022 if (!sCompatibilityModeEnabled) {
3023 p.applicationInfo.disableCompatibilityMode();
3024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 return p.applicationInfo;
3026 }
3027
3028 // Make shallow copy so we can store the metadata/libraries safely
3029 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3030 if ((flags & PackageManager.GET_META_DATA) != 0) {
3031 ai.metaData = p.mAppMetaData;
3032 }
3033 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3034 ai.sharedLibraryFiles = p.usesLibraryFiles;
3035 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003036 if (!sCompatibilityModeEnabled) {
3037 ai.disableCompatibilityMode();
3038 }
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003039 ai.enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 return ai;
3041 }
3042
3043 public static final PermissionInfo generatePermissionInfo(
3044 Permission p, int flags) {
3045 if (p == null) return null;
3046 if ((flags&PackageManager.GET_META_DATA) == 0) {
3047 return p.info;
3048 }
3049 PermissionInfo pi = new PermissionInfo(p.info);
3050 pi.metaData = p.metaData;
3051 return pi;
3052 }
3053
3054 public static final PermissionGroupInfo generatePermissionGroupInfo(
3055 PermissionGroup pg, int flags) {
3056 if (pg == null) return null;
3057 if ((flags&PackageManager.GET_META_DATA) == 0) {
3058 return pg.info;
3059 }
3060 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3061 pgi.metaData = pg.metaData;
3062 return pgi;
3063 }
3064
3065 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003066 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003068 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3069 super(args, _info);
3070 info = _info;
3071 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003073
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003074 public void setPackageName(String packageName) {
3075 super.setPackageName(packageName);
3076 info.packageName = packageName;
3077 }
3078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 public String toString() {
3080 return "Activity{"
3081 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003082 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 }
3084 }
3085
3086 public static final ActivityInfo generateActivityInfo(Activity a,
3087 int flags) {
3088 if (a == null) return null;
3089 if (!copyNeeded(flags, a.owner, a.metaData)) {
3090 return a.info;
3091 }
3092 // Make shallow copies so we can store the metadata safely
3093 ActivityInfo ai = new ActivityInfo(a.info);
3094 ai.metaData = a.metaData;
3095 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3096 return ai;
3097 }
3098
3099 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003100 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003102 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3103 super(args, _info);
3104 info = _info;
3105 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003107
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003108 public void setPackageName(String packageName) {
3109 super.setPackageName(packageName);
3110 info.packageName = packageName;
3111 }
3112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 public String toString() {
3114 return "Service{"
3115 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003116 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 }
3118 }
3119
3120 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3121 if (s == null) return null;
3122 if (!copyNeeded(flags, s.owner, s.metaData)) {
3123 return s.info;
3124 }
3125 // Make shallow copies so we can store the metadata safely
3126 ServiceInfo si = new ServiceInfo(s.info);
3127 si.metaData = s.metaData;
3128 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3129 return si;
3130 }
3131
3132 public final static class Provider extends Component {
3133 public final ProviderInfo info;
3134 public boolean syncable;
3135
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003136 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3137 super(args, _info);
3138 info = _info;
3139 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 syncable = false;
3141 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 public Provider(Provider existingProvider) {
3144 super(existingProvider);
3145 this.info = existingProvider.info;
3146 this.syncable = existingProvider.syncable;
3147 }
3148
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003149 public void setPackageName(String packageName) {
3150 super.setPackageName(packageName);
3151 info.packageName = packageName;
3152 }
3153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 public String toString() {
3155 return "Provider{"
3156 + Integer.toHexString(System.identityHashCode(this))
3157 + " " + info.name + "}";
3158 }
3159 }
3160
3161 public static final ProviderInfo generateProviderInfo(Provider p,
3162 int flags) {
3163 if (p == null) return null;
3164 if (!copyNeeded(flags, p.owner, p.metaData)
3165 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3166 || p.info.uriPermissionPatterns == null)) {
3167 return p.info;
3168 }
3169 // Make shallow copies so we can store the metadata safely
3170 ProviderInfo pi = new ProviderInfo(p.info);
3171 pi.metaData = p.metaData;
3172 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3173 pi.uriPermissionPatterns = null;
3174 }
3175 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3176 return pi;
3177 }
3178
3179 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003180 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003182 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3183 super(args, _info);
3184 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003186
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003187 public void setPackageName(String packageName) {
3188 super.setPackageName(packageName);
3189 info.packageName = packageName;
3190 }
3191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 public String toString() {
3193 return "Instrumentation{"
3194 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003195 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 }
3197 }
3198
3199 public static final InstrumentationInfo generateInstrumentationInfo(
3200 Instrumentation i, int flags) {
3201 if (i == null) return null;
3202 if ((flags&PackageManager.GET_META_DATA) == 0) {
3203 return i.info;
3204 }
3205 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3206 ii.metaData = i.metaData;
3207 return ii;
3208 }
3209
3210 public static class IntentInfo extends IntentFilter {
3211 public boolean hasDefault;
3212 public int labelRes;
3213 public CharSequence nonLocalizedLabel;
3214 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003215 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 }
3217
3218 public final static class ActivityIntentInfo extends IntentInfo {
3219 public final Activity activity;
3220
3221 public ActivityIntentInfo(Activity _activity) {
3222 activity = _activity;
3223 }
3224
3225 public String toString() {
3226 return "ActivityIntentInfo{"
3227 + Integer.toHexString(System.identityHashCode(this))
3228 + " " + activity.info.name + "}";
3229 }
3230 }
3231
3232 public final static class ServiceIntentInfo extends IntentInfo {
3233 public final Service service;
3234
3235 public ServiceIntentInfo(Service _service) {
3236 service = _service;
3237 }
3238
3239 public String toString() {
3240 return "ServiceIntentInfo{"
3241 + Integer.toHexString(System.identityHashCode(this))
3242 + " " + service.info.name + "}";
3243 }
3244 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003245
3246 /**
3247 * @hide
3248 */
3249 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3250 sCompatibilityModeEnabled = compatibilityModeEnabled;
3251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252}