blob: e85312033f6357bcc130dfe3b0f45604555e413f [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
1720 } else {
1721 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001722 Log.w(TAG, "Unknown element under <application>: " + tagName
1723 + " at " + mArchiveSourcePath + " "
1724 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725 XmlUtils.skipCurrentTag(parser);
1726 continue;
1727 } else {
1728 outError[0] = "Bad element under <application>: " + tagName;
1729 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1730 return false;
1731 }
1732 }
1733 }
1734
1735 return true;
1736 }
1737
1738 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1739 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001740 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001741 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001742 if (name == null) {
1743 outError[0] = tag + " does not specify android:name";
1744 return false;
1745 }
1746
1747 outInfo.name
1748 = buildClassName(owner.applicationInfo.packageName, name, outError);
1749 if (outInfo.name == null) {
1750 return false;
1751 }
1752
1753 int iconVal = sa.getResourceId(iconRes, 0);
1754 if (iconVal != 0) {
1755 outInfo.icon = iconVal;
1756 outInfo.nonLocalizedLabel = null;
1757 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 TypedValue v = sa.peekValue(labelRes);
1760 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1761 outInfo.nonLocalizedLabel = v.coerceToString();
1762 }
1763
1764 outInfo.packageName = owner.packageName;
1765
1766 return true;
1767 }
1768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 private Activity parseActivity(Package owner, Resources res,
1770 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1771 boolean receiver) throws XmlPullParserException, IOException {
1772 TypedArray sa = res.obtainAttributes(attrs,
1773 com.android.internal.R.styleable.AndroidManifestActivity);
1774
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001775 if (mParseActivityArgs == null) {
1776 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1777 com.android.internal.R.styleable.AndroidManifestActivity_name,
1778 com.android.internal.R.styleable.AndroidManifestActivity_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001779 com.android.internal.R.styleable.AndroidManifestActivity_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001780 mSeparateProcesses,
1781 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001782 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001783 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1784 }
1785
1786 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1787 mParseActivityArgs.sa = sa;
1788 mParseActivityArgs.flags = flags;
1789
1790 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1791 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 sa.recycle();
1793 return null;
1794 }
1795
1796 final boolean setExported = sa.hasValue(
1797 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1798 if (setExported) {
1799 a.info.exported = sa.getBoolean(
1800 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1801 }
1802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 a.info.theme = sa.getResourceId(
1804 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1805
1806 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001807 str = sa.getNonConfigurationString(
1808 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 if (str == null) {
1810 a.info.permission = owner.applicationInfo.permission;
1811 } else {
1812 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1813 }
1814
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001815 str = sa.getNonConfigurationString(
1816 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1818 owner.applicationInfo.taskAffinity, str, outError);
1819
1820 a.info.flags = 0;
1821 if (sa.getBoolean(
1822 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1823 false)) {
1824 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1825 }
1826
1827 if (sa.getBoolean(
1828 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1829 false)) {
1830 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1831 }
1832
1833 if (sa.getBoolean(
1834 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1835 false)) {
1836 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1837 }
1838
1839 if (sa.getBoolean(
1840 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1841 false)) {
1842 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1843 }
1844
1845 if (sa.getBoolean(
1846 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1847 false)) {
1848 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1849 }
1850
1851 if (sa.getBoolean(
1852 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1853 false)) {
1854 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1855 }
1856
1857 if (sa.getBoolean(
1858 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1859 false)) {
1860 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1861 }
1862
1863 if (sa.getBoolean(
1864 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1865 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1866 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1867 }
1868
Dianne Hackbornffa42482009-09-23 22:20:11 -07001869 if (sa.getBoolean(
1870 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1871 false)) {
1872 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1873 }
1874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 if (!receiver) {
1876 a.info.launchMode = sa.getInt(
1877 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1878 ActivityInfo.LAUNCH_MULTIPLE);
1879 a.info.screenOrientation = sa.getInt(
1880 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1881 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1882 a.info.configChanges = sa.getInt(
1883 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1884 0);
1885 a.info.softInputMode = sa.getInt(
1886 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1887 0);
1888 } else {
1889 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1890 a.info.configChanges = 0;
1891 }
1892
1893 sa.recycle();
1894
Dianne Hackborn02486b12010-08-26 14:18:37 -07001895 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001896 // A heavy-weight application can not have receives in its main process
1897 // We can do direct compare because we intern all strings.
1898 if (a.info.processName == owner.packageName) {
1899 outError[0] = "Heavy-weight applications can not have receivers in main process";
1900 }
1901 }
1902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 if (outError[0] != null) {
1904 return null;
1905 }
1906
1907 int outerDepth = parser.getDepth();
1908 int type;
1909 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1910 && (type != XmlPullParser.END_TAG
1911 || parser.getDepth() > outerDepth)) {
1912 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1913 continue;
1914 }
1915
1916 if (parser.getName().equals("intent-filter")) {
1917 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1918 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1919 return null;
1920 }
1921 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001922 Log.w(TAG, "No actions in intent filter at "
1923 + mArchiveSourcePath + " "
1924 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925 } else {
1926 a.intents.add(intent);
1927 }
1928 } else if (parser.getName().equals("meta-data")) {
1929 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1930 outError)) == null) {
1931 return null;
1932 }
1933 } else {
1934 if (!RIGID_PARSER) {
1935 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1936 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001937 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1938 + " at " + mArchiveSourcePath + " "
1939 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001941 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1942 + " at " + mArchiveSourcePath + " "
1943 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 }
1945 XmlUtils.skipCurrentTag(parser);
1946 continue;
1947 }
1948 if (receiver) {
1949 outError[0] = "Bad element under <receiver>: " + parser.getName();
1950 } else {
1951 outError[0] = "Bad element under <activity>: " + parser.getName();
1952 }
1953 return null;
1954 }
1955 }
1956
1957 if (!setExported) {
1958 a.info.exported = a.intents.size() > 0;
1959 }
1960
1961 return a;
1962 }
1963
1964 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001965 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1966 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 TypedArray sa = res.obtainAttributes(attrs,
1968 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1969
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001970 String targetActivity = sa.getNonConfigurationString(
1971 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 if (targetActivity == null) {
1973 outError[0] = "<activity-alias> does not specify android:targetActivity";
1974 sa.recycle();
1975 return null;
1976 }
1977
1978 targetActivity = buildClassName(owner.applicationInfo.packageName,
1979 targetActivity, outError);
1980 if (targetActivity == null) {
1981 sa.recycle();
1982 return null;
1983 }
1984
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001985 if (mParseActivityAliasArgs == null) {
1986 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1987 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1988 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001989 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001990 mSeparateProcesses,
1991 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001992 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001993 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
1994 mParseActivityAliasArgs.tag = "<activity-alias>";
1995 }
1996
1997 mParseActivityAliasArgs.sa = sa;
1998 mParseActivityAliasArgs.flags = flags;
1999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 Activity target = null;
2001
2002 final int NA = owner.activities.size();
2003 for (int i=0; i<NA; i++) {
2004 Activity t = owner.activities.get(i);
2005 if (targetActivity.equals(t.info.name)) {
2006 target = t;
2007 break;
2008 }
2009 }
2010
2011 if (target == null) {
2012 outError[0] = "<activity-alias> target activity " + targetActivity
2013 + " not found in manifest";
2014 sa.recycle();
2015 return null;
2016 }
2017
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002018 ActivityInfo info = new ActivityInfo();
2019 info.targetActivity = targetActivity;
2020 info.configChanges = target.info.configChanges;
2021 info.flags = target.info.flags;
2022 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002023 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002024 info.labelRes = target.info.labelRes;
2025 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2026 info.launchMode = target.info.launchMode;
2027 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002028 if (info.descriptionRes == 0) {
2029 info.descriptionRes = target.info.descriptionRes;
2030 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002031 info.screenOrientation = target.info.screenOrientation;
2032 info.taskAffinity = target.info.taskAffinity;
2033 info.theme = target.info.theme;
2034
2035 Activity a = new Activity(mParseActivityAliasArgs, info);
2036 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 sa.recycle();
2038 return null;
2039 }
2040
2041 final boolean setExported = sa.hasValue(
2042 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2043 if (setExported) {
2044 a.info.exported = sa.getBoolean(
2045 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2046 }
2047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002049 str = sa.getNonConfigurationString(
2050 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 if (str != null) {
2052 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2053 }
2054
2055 sa.recycle();
2056
2057 if (outError[0] != null) {
2058 return null;
2059 }
2060
2061 int outerDepth = parser.getDepth();
2062 int type;
2063 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2064 && (type != XmlPullParser.END_TAG
2065 || parser.getDepth() > outerDepth)) {
2066 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2067 continue;
2068 }
2069
2070 if (parser.getName().equals("intent-filter")) {
2071 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2072 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2073 return null;
2074 }
2075 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002076 Log.w(TAG, "No actions in intent filter at "
2077 + mArchiveSourcePath + " "
2078 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 } else {
2080 a.intents.add(intent);
2081 }
2082 } else if (parser.getName().equals("meta-data")) {
2083 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2084 outError)) == null) {
2085 return null;
2086 }
2087 } else {
2088 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002089 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2090 + " at " + mArchiveSourcePath + " "
2091 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 XmlUtils.skipCurrentTag(parser);
2093 continue;
2094 }
2095 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2096 return null;
2097 }
2098 }
2099
2100 if (!setExported) {
2101 a.info.exported = a.intents.size() > 0;
2102 }
2103
2104 return a;
2105 }
2106
2107 private Provider parseProvider(Package owner, Resources res,
2108 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2109 throws XmlPullParserException, IOException {
2110 TypedArray sa = res.obtainAttributes(attrs,
2111 com.android.internal.R.styleable.AndroidManifestProvider);
2112
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002113 if (mParseProviderArgs == null) {
2114 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2115 com.android.internal.R.styleable.AndroidManifestProvider_name,
2116 com.android.internal.R.styleable.AndroidManifestProvider_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002117 com.android.internal.R.styleable.AndroidManifestProvider_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002118 mSeparateProcesses,
2119 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002120 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002121 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2122 mParseProviderArgs.tag = "<provider>";
2123 }
2124
2125 mParseProviderArgs.sa = sa;
2126 mParseProviderArgs.flags = flags;
2127
2128 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2129 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 sa.recycle();
2131 return null;
2132 }
2133
2134 p.info.exported = sa.getBoolean(
2135 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2136
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002137 String cpname = sa.getNonConfigurationString(
2138 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139
2140 p.info.isSyncable = sa.getBoolean(
2141 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2142 false);
2143
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002144 String permission = sa.getNonConfigurationString(
2145 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2146 String str = sa.getNonConfigurationString(
2147 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 if (str == null) {
2149 str = permission;
2150 }
2151 if (str == null) {
2152 p.info.readPermission = owner.applicationInfo.permission;
2153 } else {
2154 p.info.readPermission =
2155 str.length() > 0 ? str.toString().intern() : null;
2156 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002157 str = sa.getNonConfigurationString(
2158 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 if (str == null) {
2160 str = permission;
2161 }
2162 if (str == null) {
2163 p.info.writePermission = owner.applicationInfo.permission;
2164 } else {
2165 p.info.writePermission =
2166 str.length() > 0 ? str.toString().intern() : null;
2167 }
2168
2169 p.info.grantUriPermissions = sa.getBoolean(
2170 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2171 false);
2172
2173 p.info.multiprocess = sa.getBoolean(
2174 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2175 false);
2176
2177 p.info.initOrder = sa.getInt(
2178 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2179 0);
2180
2181 sa.recycle();
2182
Dianne Hackborn02486b12010-08-26 14:18:37 -07002183 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002184 // A heavy-weight application can not have providers in its main process
2185 // We can do direct compare because we intern all strings.
2186 if (p.info.processName == owner.packageName) {
2187 outError[0] = "Heavy-weight applications can not have providers in main process";
2188 return null;
2189 }
2190 }
2191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (cpname == null) {
2193 outError[0] = "<provider> does not incude authorities attribute";
2194 return null;
2195 }
2196 p.info.authority = cpname.intern();
2197
2198 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2199 return null;
2200 }
2201
2202 return p;
2203 }
2204
2205 private boolean parseProviderTags(Resources res,
2206 XmlPullParser parser, AttributeSet attrs,
2207 Provider outInfo, String[] outError)
2208 throws XmlPullParserException, IOException {
2209 int outerDepth = parser.getDepth();
2210 int type;
2211 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2212 && (type != XmlPullParser.END_TAG
2213 || parser.getDepth() > outerDepth)) {
2214 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2215 continue;
2216 }
2217
2218 if (parser.getName().equals("meta-data")) {
2219 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2220 outInfo.metaData, outError)) == null) {
2221 return false;
2222 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002224 } else if (parser.getName().equals("grant-uri-permission")) {
2225 TypedArray sa = res.obtainAttributes(attrs,
2226 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2227
2228 PatternMatcher pa = null;
2229
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002230 String str = sa.getNonConfigurationString(
2231 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 if (str != null) {
2233 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2234 }
2235
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002236 str = sa.getNonConfigurationString(
2237 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 if (str != null) {
2239 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2240 }
2241
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002242 str = sa.getNonConfigurationString(
2243 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 if (str != null) {
2245 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2246 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 sa.recycle();
2249
2250 if (pa != null) {
2251 if (outInfo.info.uriPermissionPatterns == null) {
2252 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2253 outInfo.info.uriPermissionPatterns[0] = pa;
2254 } else {
2255 final int N = outInfo.info.uriPermissionPatterns.length;
2256 PatternMatcher[] newp = new PatternMatcher[N+1];
2257 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2258 newp[N] = pa;
2259 outInfo.info.uriPermissionPatterns = newp;
2260 }
2261 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002262 } else {
2263 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002264 Log.w(TAG, "Unknown element under <path-permission>: "
2265 + parser.getName() + " at " + mArchiveSourcePath + " "
2266 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002267 XmlUtils.skipCurrentTag(parser);
2268 continue;
2269 }
2270 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2271 return false;
2272 }
2273 XmlUtils.skipCurrentTag(parser);
2274
2275 } else if (parser.getName().equals("path-permission")) {
2276 TypedArray sa = res.obtainAttributes(attrs,
2277 com.android.internal.R.styleable.AndroidManifestPathPermission);
2278
2279 PathPermission pa = null;
2280
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002281 String permission = sa.getNonConfigurationString(
2282 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2283 String readPermission = sa.getNonConfigurationString(
2284 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002285 if (readPermission == null) {
2286 readPermission = permission;
2287 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002288 String writePermission = sa.getNonConfigurationString(
2289 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002290 if (writePermission == null) {
2291 writePermission = permission;
2292 }
2293
2294 boolean havePerm = false;
2295 if (readPermission != null) {
2296 readPermission = readPermission.intern();
2297 havePerm = true;
2298 }
2299 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002300 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002301 havePerm = true;
2302 }
2303
2304 if (!havePerm) {
2305 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002306 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2307 + parser.getName() + " at " + mArchiveSourcePath + " "
2308 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002309 XmlUtils.skipCurrentTag(parser);
2310 continue;
2311 }
2312 outError[0] = "No readPermission or writePermssion for <path-permission>";
2313 return false;
2314 }
2315
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002316 String path = sa.getNonConfigurationString(
2317 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002318 if (path != null) {
2319 pa = new PathPermission(path,
2320 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2321 }
2322
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002323 path = sa.getNonConfigurationString(
2324 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002325 if (path != null) {
2326 pa = new PathPermission(path,
2327 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2328 }
2329
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002330 path = sa.getNonConfigurationString(
2331 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002332 if (path != null) {
2333 pa = new PathPermission(path,
2334 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2335 }
2336
2337 sa.recycle();
2338
2339 if (pa != null) {
2340 if (outInfo.info.pathPermissions == null) {
2341 outInfo.info.pathPermissions = new PathPermission[1];
2342 outInfo.info.pathPermissions[0] = pa;
2343 } else {
2344 final int N = outInfo.info.pathPermissions.length;
2345 PathPermission[] newp = new PathPermission[N+1];
2346 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2347 newp[N] = pa;
2348 outInfo.info.pathPermissions = newp;
2349 }
2350 } else {
2351 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002352 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2353 + parser.getName() + " at " + mArchiveSourcePath + " "
2354 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002355 XmlUtils.skipCurrentTag(parser);
2356 continue;
2357 }
2358 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2359 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 }
2361 XmlUtils.skipCurrentTag(parser);
2362
2363 } else {
2364 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002366 + parser.getName() + " at " + mArchiveSourcePath + " "
2367 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 XmlUtils.skipCurrentTag(parser);
2369 continue;
2370 }
2371 outError[0] = "Bad element under <provider>: "
2372 + parser.getName();
2373 return false;
2374 }
2375 }
2376 return true;
2377 }
2378
2379 private Service parseService(Package owner, Resources res,
2380 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2381 throws XmlPullParserException, IOException {
2382 TypedArray sa = res.obtainAttributes(attrs,
2383 com.android.internal.R.styleable.AndroidManifestService);
2384
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002385 if (mParseServiceArgs == null) {
2386 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2387 com.android.internal.R.styleable.AndroidManifestService_name,
2388 com.android.internal.R.styleable.AndroidManifestService_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002389 com.android.internal.R.styleable.AndroidManifestService_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002390 mSeparateProcesses,
2391 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002392 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002393 com.android.internal.R.styleable.AndroidManifestService_enabled);
2394 mParseServiceArgs.tag = "<service>";
2395 }
2396
2397 mParseServiceArgs.sa = sa;
2398 mParseServiceArgs.flags = flags;
2399
2400 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2401 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 sa.recycle();
2403 return null;
2404 }
2405
2406 final boolean setExported = sa.hasValue(
2407 com.android.internal.R.styleable.AndroidManifestService_exported);
2408 if (setExported) {
2409 s.info.exported = sa.getBoolean(
2410 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2411 }
2412
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002413 String str = sa.getNonConfigurationString(
2414 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 if (str == null) {
2416 s.info.permission = owner.applicationInfo.permission;
2417 } else {
2418 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2419 }
2420
2421 sa.recycle();
2422
Dianne Hackborn02486b12010-08-26 14:18:37 -07002423 if ((owner.applicationInfo.flags&ApplicationInfo.CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002424 // A heavy-weight application can not have services in its main process
2425 // We can do direct compare because we intern all strings.
2426 if (s.info.processName == owner.packageName) {
2427 outError[0] = "Heavy-weight applications can not have services in main process";
2428 return null;
2429 }
2430 }
2431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 int outerDepth = parser.getDepth();
2433 int type;
2434 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2435 && (type != XmlPullParser.END_TAG
2436 || parser.getDepth() > outerDepth)) {
2437 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2438 continue;
2439 }
2440
2441 if (parser.getName().equals("intent-filter")) {
2442 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2443 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2444 return null;
2445 }
2446
2447 s.intents.add(intent);
2448 } else if (parser.getName().equals("meta-data")) {
2449 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2450 outError)) == null) {
2451 return null;
2452 }
2453 } else {
2454 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002456 + parser.getName() + " at " + mArchiveSourcePath + " "
2457 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 XmlUtils.skipCurrentTag(parser);
2459 continue;
2460 }
2461 outError[0] = "Bad element under <service>: "
2462 + parser.getName();
2463 return null;
2464 }
2465 }
2466
2467 if (!setExported) {
2468 s.info.exported = s.intents.size() > 0;
2469 }
2470
2471 return s;
2472 }
2473
2474 private boolean parseAllMetaData(Resources res,
2475 XmlPullParser parser, AttributeSet attrs, String tag,
2476 Component outInfo, String[] outError)
2477 throws XmlPullParserException, IOException {
2478 int outerDepth = parser.getDepth();
2479 int type;
2480 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2481 && (type != XmlPullParser.END_TAG
2482 || parser.getDepth() > outerDepth)) {
2483 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2484 continue;
2485 }
2486
2487 if (parser.getName().equals("meta-data")) {
2488 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2489 outInfo.metaData, outError)) == null) {
2490 return false;
2491 }
2492 } else {
2493 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002495 + parser.getName() + " at " + mArchiveSourcePath + " "
2496 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 XmlUtils.skipCurrentTag(parser);
2498 continue;
2499 }
2500 outError[0] = "Bad element under " + tag + ": "
2501 + parser.getName();
2502 return false;
2503 }
2504 }
2505 return true;
2506 }
2507
2508 private Bundle parseMetaData(Resources res,
2509 XmlPullParser parser, AttributeSet attrs,
2510 Bundle data, String[] outError)
2511 throws XmlPullParserException, IOException {
2512
2513 TypedArray sa = res.obtainAttributes(attrs,
2514 com.android.internal.R.styleable.AndroidManifestMetaData);
2515
2516 if (data == null) {
2517 data = new Bundle();
2518 }
2519
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002520 String name = sa.getNonConfigurationString(
2521 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 if (name == null) {
2523 outError[0] = "<meta-data> requires an android:name attribute";
2524 sa.recycle();
2525 return null;
2526 }
2527
Dianne Hackborn854060a2009-07-09 18:14:31 -07002528 name = name.intern();
2529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 TypedValue v = sa.peekValue(
2531 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2532 if (v != null && v.resourceId != 0) {
2533 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2534 data.putInt(name, v.resourceId);
2535 } else {
2536 v = sa.peekValue(
2537 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2538 //Log.i(TAG, "Meta data " + name + ": " + v);
2539 if (v != null) {
2540 if (v.type == TypedValue.TYPE_STRING) {
2541 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002542 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2544 data.putBoolean(name, v.data != 0);
2545 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2546 && v.type <= TypedValue.TYPE_LAST_INT) {
2547 data.putInt(name, v.data);
2548 } else if (v.type == TypedValue.TYPE_FLOAT) {
2549 data.putFloat(name, v.getFloat());
2550 } else {
2551 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002552 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2553 + parser.getName() + " at " + mArchiveSourcePath + " "
2554 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 } else {
2556 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2557 data = null;
2558 }
2559 }
2560 } else {
2561 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2562 data = null;
2563 }
2564 }
2565
2566 sa.recycle();
2567
2568 XmlUtils.skipCurrentTag(parser);
2569
2570 return data;
2571 }
2572
2573 private static final String ANDROID_RESOURCES
2574 = "http://schemas.android.com/apk/res/android";
2575
2576 private boolean parseIntent(Resources res,
2577 XmlPullParser parser, AttributeSet attrs, int flags,
2578 IntentInfo outInfo, String[] outError, boolean isActivity)
2579 throws XmlPullParserException, IOException {
2580
2581 TypedArray sa = res.obtainAttributes(attrs,
2582 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2583
2584 int priority = sa.getInt(
2585 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2586 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2587 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002588 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 + parser.getPositionDescription());
2590 priority = 0;
2591 }
2592 outInfo.setPriority(priority);
2593
2594 TypedValue v = sa.peekValue(
2595 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2596 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2597 outInfo.nonLocalizedLabel = v.coerceToString();
2598 }
2599
2600 outInfo.icon = sa.getResourceId(
2601 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 sa.recycle();
2604
2605 int outerDepth = parser.getDepth();
2606 int type;
2607 while ((type=parser.next()) != parser.END_DOCUMENT
2608 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2609 if (type == parser.END_TAG || type == parser.TEXT) {
2610 continue;
2611 }
2612
2613 String nodeName = parser.getName();
2614 if (nodeName.equals("action")) {
2615 String value = attrs.getAttributeValue(
2616 ANDROID_RESOURCES, "name");
2617 if (value == null || value == "") {
2618 outError[0] = "No value supplied for <android:name>";
2619 return false;
2620 }
2621 XmlUtils.skipCurrentTag(parser);
2622
2623 outInfo.addAction(value);
2624 } else if (nodeName.equals("category")) {
2625 String value = attrs.getAttributeValue(
2626 ANDROID_RESOURCES, "name");
2627 if (value == null || value == "") {
2628 outError[0] = "No value supplied for <android:name>";
2629 return false;
2630 }
2631 XmlUtils.skipCurrentTag(parser);
2632
2633 outInfo.addCategory(value);
2634
2635 } else if (nodeName.equals("data")) {
2636 sa = res.obtainAttributes(attrs,
2637 com.android.internal.R.styleable.AndroidManifestData);
2638
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002639 String str = sa.getNonConfigurationString(
2640 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 if (str != null) {
2642 try {
2643 outInfo.addDataType(str);
2644 } catch (IntentFilter.MalformedMimeTypeException e) {
2645 outError[0] = e.toString();
2646 sa.recycle();
2647 return false;
2648 }
2649 }
2650
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002651 str = sa.getNonConfigurationString(
2652 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 if (str != null) {
2654 outInfo.addDataScheme(str);
2655 }
2656
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002657 String host = sa.getNonConfigurationString(
2658 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2659 String port = sa.getNonConfigurationString(
2660 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 if (host != null) {
2662 outInfo.addDataAuthority(host, port);
2663 }
2664
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002665 str = sa.getNonConfigurationString(
2666 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 if (str != null) {
2668 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2669 }
2670
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002671 str = sa.getNonConfigurationString(
2672 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 if (str != null) {
2674 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2675 }
2676
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002677 str = sa.getNonConfigurationString(
2678 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 if (str != null) {
2680 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2681 }
2682
2683 sa.recycle();
2684 XmlUtils.skipCurrentTag(parser);
2685 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002686 Log.w(TAG, "Unknown element under <intent-filter>: "
2687 + parser.getName() + " at " + mArchiveSourcePath + " "
2688 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 XmlUtils.skipCurrentTag(parser);
2690 } else {
2691 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2692 return false;
2693 }
2694 }
2695
2696 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2697 if (false) {
2698 String cats = "";
2699 Iterator<String> it = outInfo.categoriesIterator();
2700 while (it != null && it.hasNext()) {
2701 cats += " " + it.next();
2702 }
2703 System.out.println("Intent d=" +
2704 outInfo.hasDefault + ", cat=" + cats);
2705 }
2706
2707 return true;
2708 }
2709
2710 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002711 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712
2713 // For now we only support one application per package.
2714 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2715
2716 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2717 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2718 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2719 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2720 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2721 public final ArrayList<Service> services = new ArrayList<Service>(0);
2722 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2723
2724 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2725
Dianne Hackborn854060a2009-07-09 18:14:31 -07002726 public ArrayList<String> protectedBroadcasts;
2727
Dianne Hackborn49237342009-08-27 20:08:01 -07002728 public ArrayList<String> usesLibraries = null;
2729 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 public String[] usesLibraryFiles = null;
2731
Dianne Hackbornc1552392010-03-03 16:19:01 -08002732 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002733 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002734 public ArrayList<String> mAdoptPermissions = null;
2735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 // We store the application meta-data independently to avoid multiple unwanted references
2737 public Bundle mAppMetaData = null;
2738
2739 // If this is a 3rd party app, this is the path of the zip file.
2740 public String mPath;
2741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 // The version code declared for this package.
2743 public int mVersionCode;
2744
2745 // The version name declared for this package.
2746 public String mVersionName;
2747
2748 // The shared user id that this package wants to use.
2749 public String mSharedUserId;
2750
2751 // The shared user label that this package wants to use.
2752 public int mSharedUserLabel;
2753
2754 // Signatures that were read from the package.
2755 public Signature mSignatures[];
2756
2757 // For use by package manager service for quick lookup of
2758 // preferred up order.
2759 public int mPreferredOrder = 0;
2760
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002761 // For use by the package manager to keep track of the path to the
2762 // file an app came from.
2763 public String mScanPath;
2764
2765 // For use by package manager to keep track of where it has done dexopt.
2766 public boolean mDidDexOpt;
2767
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002768 // User set enabled state.
2769 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 // Additional data supplied by callers.
2772 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002773
2774 // Whether an operation is currently pending on this package
2775 public boolean mOperationPending;
2776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 /*
2778 * Applications hardware preferences
2779 */
2780 public final ArrayList<ConfigurationInfo> configPreferences =
2781 new ArrayList<ConfigurationInfo>();
2782
Dianne Hackborn49237342009-08-27 20:08:01 -07002783 /*
2784 * Applications requested features
2785 */
2786 public ArrayList<FeatureInfo> reqFeatures = null;
2787
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002788 public int installLocation;
2789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 public Package(String _name) {
2791 packageName = _name;
2792 applicationInfo.packageName = _name;
2793 applicationInfo.uid = -1;
2794 }
2795
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002796 public void setPackageName(String newName) {
2797 packageName = newName;
2798 applicationInfo.packageName = newName;
2799 for (int i=permissions.size()-1; i>=0; i--) {
2800 permissions.get(i).setPackageName(newName);
2801 }
2802 for (int i=permissionGroups.size()-1; i>=0; i--) {
2803 permissionGroups.get(i).setPackageName(newName);
2804 }
2805 for (int i=activities.size()-1; i>=0; i--) {
2806 activities.get(i).setPackageName(newName);
2807 }
2808 for (int i=receivers.size()-1; i>=0; i--) {
2809 receivers.get(i).setPackageName(newName);
2810 }
2811 for (int i=providers.size()-1; i>=0; i--) {
2812 providers.get(i).setPackageName(newName);
2813 }
2814 for (int i=services.size()-1; i>=0; i--) {
2815 services.get(i).setPackageName(newName);
2816 }
2817 for (int i=instrumentation.size()-1; i>=0; i--) {
2818 instrumentation.get(i).setPackageName(newName);
2819 }
2820 }
2821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 public String toString() {
2823 return "Package{"
2824 + Integer.toHexString(System.identityHashCode(this))
2825 + " " + packageName + "}";
2826 }
2827 }
2828
2829 public static class Component<II extends IntentInfo> {
2830 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002831 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002832 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 public Bundle metaData;
2834
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002835 ComponentName componentName;
2836 String componentShortName;
2837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 public Component(Package _owner) {
2839 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002840 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002841 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002842 }
2843
2844 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2845 owner = args.owner;
2846 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002847 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002848 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002849 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002850 args.outError[0] = args.tag + " does not specify android:name";
2851 return;
2852 }
2853
2854 outInfo.name
2855 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2856 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002857 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002858 args.outError[0] = args.tag + " does not have valid android:name";
2859 return;
2860 }
2861
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002862 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002863
2864 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2865 if (iconVal != 0) {
2866 outInfo.icon = iconVal;
2867 outInfo.nonLocalizedLabel = null;
2868 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002869
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002870 TypedValue v = args.sa.peekValue(args.labelRes);
2871 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2872 outInfo.nonLocalizedLabel = v.coerceToString();
2873 }
2874
2875 outInfo.packageName = owner.packageName;
2876 }
2877
2878 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2879 this(args, (PackageItemInfo)outInfo);
2880 if (args.outError[0] != null) {
2881 return;
2882 }
2883
2884 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002885 CharSequence pname;
2886 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2887 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2888 } else {
2889 // Some older apps have been seen to use a resource reference
2890 // here that on older builds was ignored (with a warning). We
2891 // need to continue to do this for them so they don't break.
2892 pname = args.sa.getNonResourceString(args.processRes);
2893 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002894 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002895 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002896 args.flags, args.sepProcesses, args.outError);
2897 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002898
2899 if (args.descriptionRes != 0) {
2900 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2901 }
2902
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002903 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 }
2905
2906 public Component(Component<II> clone) {
2907 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002908 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002909 className = clone.className;
2910 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002911 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002912 }
2913
2914 public ComponentName getComponentName() {
2915 if (componentName != null) {
2916 return componentName;
2917 }
2918 if (className != null) {
2919 componentName = new ComponentName(owner.applicationInfo.packageName,
2920 className);
2921 }
2922 return componentName;
2923 }
2924
2925 public String getComponentShortName() {
2926 if (componentShortName != null) {
2927 return componentShortName;
2928 }
2929 ComponentName component = getComponentName();
2930 if (component != null) {
2931 componentShortName = component.flattenToShortString();
2932 }
2933 return componentShortName;
2934 }
2935
2936 public void setPackageName(String packageName) {
2937 componentName = null;
2938 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 }
2940 }
2941
2942 public final static class Permission extends Component<IntentInfo> {
2943 public final PermissionInfo info;
2944 public boolean tree;
2945 public PermissionGroup group;
2946
2947 public Permission(Package _owner) {
2948 super(_owner);
2949 info = new PermissionInfo();
2950 }
2951
2952 public Permission(Package _owner, PermissionInfo _info) {
2953 super(_owner);
2954 info = _info;
2955 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002956
2957 public void setPackageName(String packageName) {
2958 super.setPackageName(packageName);
2959 info.packageName = packageName;
2960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961
2962 public String toString() {
2963 return "Permission{"
2964 + Integer.toHexString(System.identityHashCode(this))
2965 + " " + info.name + "}";
2966 }
2967 }
2968
2969 public final static class PermissionGroup extends Component<IntentInfo> {
2970 public final PermissionGroupInfo info;
2971
2972 public PermissionGroup(Package _owner) {
2973 super(_owner);
2974 info = new PermissionGroupInfo();
2975 }
2976
2977 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2978 super(_owner);
2979 info = _info;
2980 }
2981
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002982 public void setPackageName(String packageName) {
2983 super.setPackageName(packageName);
2984 info.packageName = packageName;
2985 }
2986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 public String toString() {
2988 return "PermissionGroup{"
2989 + Integer.toHexString(System.identityHashCode(this))
2990 + " " + info.name + "}";
2991 }
2992 }
2993
2994 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002995 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
2996 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
2997 if (p.applicationInfo.enabled != enabled) {
2998 return true;
2999 }
3000 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 if ((flags & PackageManager.GET_META_DATA) != 0
3002 && (metaData != null || p.mAppMetaData != null)) {
3003 return true;
3004 }
3005 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3006 && p.usesLibraryFiles != null) {
3007 return true;
3008 }
3009 return false;
3010 }
3011
3012 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3013 if (p == null) return null;
3014 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003015 // CompatibilityMode is global state. It's safe to modify the instance
3016 // of the package.
3017 if (!sCompatibilityModeEnabled) {
3018 p.applicationInfo.disableCompatibilityMode();
3019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 return p.applicationInfo;
3021 }
3022
3023 // Make shallow copy so we can store the metadata/libraries safely
3024 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3025 if ((flags & PackageManager.GET_META_DATA) != 0) {
3026 ai.metaData = p.mAppMetaData;
3027 }
3028 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3029 ai.sharedLibraryFiles = p.usesLibraryFiles;
3030 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003031 if (!sCompatibilityModeEnabled) {
3032 ai.disableCompatibilityMode();
3033 }
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003034 ai.enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 return ai;
3036 }
3037
3038 public static final PermissionInfo generatePermissionInfo(
3039 Permission p, int flags) {
3040 if (p == null) return null;
3041 if ((flags&PackageManager.GET_META_DATA) == 0) {
3042 return p.info;
3043 }
3044 PermissionInfo pi = new PermissionInfo(p.info);
3045 pi.metaData = p.metaData;
3046 return pi;
3047 }
3048
3049 public static final PermissionGroupInfo generatePermissionGroupInfo(
3050 PermissionGroup pg, int flags) {
3051 if (pg == null) return null;
3052 if ((flags&PackageManager.GET_META_DATA) == 0) {
3053 return pg.info;
3054 }
3055 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3056 pgi.metaData = pg.metaData;
3057 return pgi;
3058 }
3059
3060 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003061 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003062
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003063 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3064 super(args, _info);
3065 info = _info;
3066 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003068
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003069 public void setPackageName(String packageName) {
3070 super.setPackageName(packageName);
3071 info.packageName = packageName;
3072 }
3073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 public String toString() {
3075 return "Activity{"
3076 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003077 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 }
3079 }
3080
3081 public static final ActivityInfo generateActivityInfo(Activity a,
3082 int flags) {
3083 if (a == null) return null;
3084 if (!copyNeeded(flags, a.owner, a.metaData)) {
3085 return a.info;
3086 }
3087 // Make shallow copies so we can store the metadata safely
3088 ActivityInfo ai = new ActivityInfo(a.info);
3089 ai.metaData = a.metaData;
3090 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3091 return ai;
3092 }
3093
3094 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003095 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003097 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3098 super(args, _info);
3099 info = _info;
3100 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003102
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003103 public void setPackageName(String packageName) {
3104 super.setPackageName(packageName);
3105 info.packageName = packageName;
3106 }
3107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003108 public String toString() {
3109 return "Service{"
3110 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003111 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 }
3113 }
3114
3115 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3116 if (s == null) return null;
3117 if (!copyNeeded(flags, s.owner, s.metaData)) {
3118 return s.info;
3119 }
3120 // Make shallow copies so we can store the metadata safely
3121 ServiceInfo si = new ServiceInfo(s.info);
3122 si.metaData = s.metaData;
3123 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3124 return si;
3125 }
3126
3127 public final static class Provider extends Component {
3128 public final ProviderInfo info;
3129 public boolean syncable;
3130
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003131 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3132 super(args, _info);
3133 info = _info;
3134 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 syncable = false;
3136 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 public Provider(Provider existingProvider) {
3139 super(existingProvider);
3140 this.info = existingProvider.info;
3141 this.syncable = existingProvider.syncable;
3142 }
3143
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003144 public void setPackageName(String packageName) {
3145 super.setPackageName(packageName);
3146 info.packageName = packageName;
3147 }
3148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 public String toString() {
3150 return "Provider{"
3151 + Integer.toHexString(System.identityHashCode(this))
3152 + " " + info.name + "}";
3153 }
3154 }
3155
3156 public static final ProviderInfo generateProviderInfo(Provider p,
3157 int flags) {
3158 if (p == null) return null;
3159 if (!copyNeeded(flags, p.owner, p.metaData)
3160 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3161 || p.info.uriPermissionPatterns == null)) {
3162 return p.info;
3163 }
3164 // Make shallow copies so we can store the metadata safely
3165 ProviderInfo pi = new ProviderInfo(p.info);
3166 pi.metaData = p.metaData;
3167 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3168 pi.uriPermissionPatterns = null;
3169 }
3170 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3171 return pi;
3172 }
3173
3174 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003175 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003177 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3178 super(args, _info);
3179 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003181
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003182 public void setPackageName(String packageName) {
3183 super.setPackageName(packageName);
3184 info.packageName = packageName;
3185 }
3186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 public String toString() {
3188 return "Instrumentation{"
3189 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003190 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
3192 }
3193
3194 public static final InstrumentationInfo generateInstrumentationInfo(
3195 Instrumentation i, int flags) {
3196 if (i == null) return null;
3197 if ((flags&PackageManager.GET_META_DATA) == 0) {
3198 return i.info;
3199 }
3200 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3201 ii.metaData = i.metaData;
3202 return ii;
3203 }
3204
3205 public static class IntentInfo extends IntentFilter {
3206 public boolean hasDefault;
3207 public int labelRes;
3208 public CharSequence nonLocalizedLabel;
3209 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003210 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 }
3212
3213 public final static class ActivityIntentInfo extends IntentInfo {
3214 public final Activity activity;
3215
3216 public ActivityIntentInfo(Activity _activity) {
3217 activity = _activity;
3218 }
3219
3220 public String toString() {
3221 return "ActivityIntentInfo{"
3222 + Integer.toHexString(System.identityHashCode(this))
3223 + " " + activity.info.name + "}";
3224 }
3225 }
3226
3227 public final static class ServiceIntentInfo extends IntentInfo {
3228 public final Service service;
3229
3230 public ServiceIntentInfo(Service _service) {
3231 service = _service;
3232 }
3233
3234 public String toString() {
3235 return "ServiceIntentInfo{"
3236 + Integer.toHexString(System.identityHashCode(this))
3237 + " " + service.info.name + "}";
3238 }
3239 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003240
3241 /**
3242 * @hide
3243 */
3244 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3245 sCompatibilityModeEnabled = compatibilityModeEnabled;
3246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247}