blob: 89839ce634296573bd99eb3b78b4da2fef424e73 [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);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700790 pkg.applicationInfo.installLocation = pkg.installLocation;
791
Dianne Hackborn723738c2009-06-25 19:48:04 -0700792 // Resource boolean are -1, so 1 means we don't know the value.
793 int supportsSmallScreens = 1;
794 int supportsNormalScreens = 1;
795 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700796 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700797 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700798 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 int outerDepth = parser.getDepth();
801 while ((type=parser.next()) != parser.END_DOCUMENT
802 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
803 if (type == parser.END_TAG || type == parser.TEXT) {
804 continue;
805 }
806
807 String tagName = parser.getName();
808 if (tagName.equals("application")) {
809 if (foundApp) {
810 if (RIGID_PARSER) {
811 outError[0] = "<manifest> has more than one <application>";
812 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
813 return null;
814 } else {
815 Log.w(TAG, "<manifest> has more than one <application>");
816 XmlUtils.skipCurrentTag(parser);
817 continue;
818 }
819 }
820
821 foundApp = true;
822 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
823 return null;
824 }
825 } else if (tagName.equals("permission-group")) {
826 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
827 return null;
828 }
829 } else if (tagName.equals("permission")) {
830 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
831 return null;
832 }
833 } else if (tagName.equals("permission-tree")) {
834 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
835 return null;
836 }
837 } else if (tagName.equals("uses-permission")) {
838 sa = res.obtainAttributes(attrs,
839 com.android.internal.R.styleable.AndroidManifestUsesPermission);
840
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800841 // Note: don't allow this value to be a reference to a resource
842 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 String name = sa.getNonResourceString(
844 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
845
846 sa.recycle();
847
848 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700849 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
851
852 XmlUtils.skipCurrentTag(parser);
853
854 } else if (tagName.equals("uses-configuration")) {
855 ConfigurationInfo cPref = new ConfigurationInfo();
856 sa = res.obtainAttributes(attrs,
857 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
858 cPref.reqTouchScreen = sa.getInt(
859 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
860 Configuration.TOUCHSCREEN_UNDEFINED);
861 cPref.reqKeyboardType = sa.getInt(
862 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
863 Configuration.KEYBOARD_UNDEFINED);
864 if (sa.getBoolean(
865 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
866 false)) {
867 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
868 }
869 cPref.reqNavigation = sa.getInt(
870 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
871 Configuration.NAVIGATION_UNDEFINED);
872 if (sa.getBoolean(
873 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
874 false)) {
875 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
876 }
877 sa.recycle();
878 pkg.configPreferences.add(cPref);
879
880 XmlUtils.skipCurrentTag(parser);
881
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700882 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700883 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700884 sa = res.obtainAttributes(attrs,
885 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800886 // Note: don't allow this value to be a reference to a resource
887 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700888 fi.name = sa.getNonResourceString(
889 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
890 if (fi.name == null) {
891 fi.reqGlEsVersion = sa.getInt(
892 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
893 FeatureInfo.GL_ES_VERSION_UNDEFINED);
894 }
895 if (sa.getBoolean(
896 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
897 true)) {
898 fi.flags |= FeatureInfo.FLAG_REQUIRED;
899 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700900 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700901 if (pkg.reqFeatures == null) {
902 pkg.reqFeatures = new ArrayList<FeatureInfo>();
903 }
904 pkg.reqFeatures.add(fi);
905
906 if (fi.name == null) {
907 ConfigurationInfo cPref = new ConfigurationInfo();
908 cPref.reqGlEsVersion = fi.reqGlEsVersion;
909 pkg.configPreferences.add(cPref);
910 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700911
912 XmlUtils.skipCurrentTag(parser);
913
Dianne Hackborn851a5412009-05-08 12:06:44 -0700914 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700915 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 sa = res.obtainAttributes(attrs,
917 com.android.internal.R.styleable.AndroidManifestUsesSdk);
918
Dianne Hackborn851a5412009-05-08 12:06:44 -0700919 int minVers = 0;
920 String minCode = null;
921 int targetVers = 0;
922 String targetCode = null;
923
924 TypedValue val = sa.peekValue(
925 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
926 if (val != null) {
927 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
928 targetCode = minCode = val.string.toString();
929 } else {
930 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700931 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700932 }
933 }
934
935 val = sa.peekValue(
936 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
937 if (val != null) {
938 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
939 targetCode = minCode = val.string.toString();
940 } else {
941 // If it's not a string, it's an integer.
942 targetVers = val.data;
943 }
944 }
945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 sa.recycle();
947
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700948 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700949 if (!minCode.equals(SDK_CODENAME)) {
950 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700951 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700952 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700953 } else {
954 outError[0] = "Requires development platform " + minCode
955 + " but this is a release platform.";
956 }
957 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
958 return null;
959 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700960 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700961 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700962 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700963 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
964 return null;
965 }
966
Dianne Hackborn851a5412009-05-08 12:06:44 -0700967 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700968 if (!targetCode.equals(SDK_CODENAME)) {
969 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700970 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700971 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700972 } else {
973 outError[0] = "Requires development platform " + targetCode
974 + " but this is a release platform.";
975 }
976 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
977 return null;
978 }
979 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700980 pkg.applicationInfo.targetSdkVersion
981 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
982 } else {
983 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 }
986
987 XmlUtils.skipCurrentTag(parser);
988
Dianne Hackborn723738c2009-06-25 19:48:04 -0700989 } else if (tagName.equals("supports-screens")) {
990 sa = res.obtainAttributes(attrs,
991 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
992
993 // This is a trick to get a boolean and still able to detect
994 // if a value was actually set.
995 supportsSmallScreens = sa.getInteger(
996 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
997 supportsSmallScreens);
998 supportsNormalScreens = sa.getInteger(
999 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1000 supportsNormalScreens);
1001 supportsLargeScreens = sa.getInteger(
1002 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1003 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001004 supportsXLargeScreens = sa.getInteger(
1005 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1006 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001007 resizeable = sa.getInteger(
1008 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001009 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001010 anyDensity = sa.getInteger(
1011 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1012 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001013
1014 sa.recycle();
1015
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001016 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001017
1018 } else if (tagName.equals("protected-broadcast")) {
1019 sa = res.obtainAttributes(attrs,
1020 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1021
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001022 // Note: don't allow this value to be a reference to a resource
1023 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001024 String name = sa.getNonResourceString(
1025 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1026
1027 sa.recycle();
1028
1029 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1030 if (pkg.protectedBroadcasts == null) {
1031 pkg.protectedBroadcasts = new ArrayList<String>();
1032 }
1033 if (!pkg.protectedBroadcasts.contains(name)) {
1034 pkg.protectedBroadcasts.add(name.intern());
1035 }
1036 }
1037
1038 XmlUtils.skipCurrentTag(parser);
1039
1040 } else if (tagName.equals("instrumentation")) {
1041 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1042 return null;
1043 }
1044
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001045 } else if (tagName.equals("original-package")) {
1046 sa = res.obtainAttributes(attrs,
1047 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1048
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001049 String orig =sa.getNonConfigurationString(
1050 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001051 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001052 if (pkg.mOriginalPackages == null) {
1053 pkg.mOriginalPackages = new ArrayList<String>();
1054 pkg.mRealPackage = pkg.packageName;
1055 }
1056 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001057 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001058
1059 sa.recycle();
1060
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001061 XmlUtils.skipCurrentTag(parser);
1062
1063 } else if (tagName.equals("adopt-permissions")) {
1064 sa = res.obtainAttributes(attrs,
1065 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1066
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001067 String name = sa.getNonConfigurationString(
1068 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001069
1070 sa.recycle();
1071
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001072 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001073 if (pkg.mAdoptPermissions == null) {
1074 pkg.mAdoptPermissions = new ArrayList<String>();
1075 }
1076 pkg.mAdoptPermissions.add(name);
1077 }
1078
1079 XmlUtils.skipCurrentTag(parser);
1080
Dianne Hackborn854060a2009-07-09 18:14:31 -07001081 } else if (tagName.equals("eat-comment")) {
1082 // Just skip this tag
1083 XmlUtils.skipCurrentTag(parser);
1084 continue;
1085
1086 } else if (RIGID_PARSER) {
1087 outError[0] = "Bad element under <manifest>: "
1088 + parser.getName();
1089 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1090 return null;
1091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001093 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
1094 + " at " + mArchiveSourcePath + " "
1095 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 XmlUtils.skipCurrentTag(parser);
1097 continue;
1098 }
1099 }
1100
1101 if (!foundApp && pkg.instrumentation.size() == 0) {
1102 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1103 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1104 }
1105
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001106 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001107 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001108 for (int ip=0; ip<NP; ip++) {
1109 final PackageParser.NewPermissionInfo npi
1110 = PackageParser.NEW_PERMISSIONS[ip];
1111 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1112 break;
1113 }
1114 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001115 if (implicitPerms == null) {
1116 implicitPerms = new StringBuilder(128);
1117 implicitPerms.append(pkg.packageName);
1118 implicitPerms.append(": compat added ");
1119 } else {
1120 implicitPerms.append(' ');
1121 }
1122 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001123 pkg.requestedPermissions.add(npi.name);
1124 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001125 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001126 if (implicitPerms != null) {
1127 Log.i(TAG, implicitPerms.toString());
1128 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001129
Dianne Hackborn723738c2009-06-25 19:48:04 -07001130 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1131 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001132 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001133 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1134 }
1135 if (supportsNormalScreens != 0) {
1136 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1137 }
1138 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1139 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001140 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001141 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1142 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001143 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1144 && pkg.applicationInfo.targetSdkVersion
1145 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1146 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1147 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001148 if (resizeable < 0 || (resizeable > 0
1149 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001150 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001151 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1152 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001153 if (anyDensity < 0 || (anyDensity > 0
1154 && pkg.applicationInfo.targetSdkVersion
1155 >= android.os.Build.VERSION_CODES.DONUT)) {
1156 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001157 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 return pkg;
1160 }
1161
1162 private static String buildClassName(String pkg, CharSequence clsSeq,
1163 String[] outError) {
1164 if (clsSeq == null || clsSeq.length() <= 0) {
1165 outError[0] = "Empty class name in package " + pkg;
1166 return null;
1167 }
1168 String cls = clsSeq.toString();
1169 char c = cls.charAt(0);
1170 if (c == '.') {
1171 return (pkg + cls).intern();
1172 }
1173 if (cls.indexOf('.') < 0) {
1174 StringBuilder b = new StringBuilder(pkg);
1175 b.append('.');
1176 b.append(cls);
1177 return b.toString().intern();
1178 }
1179 if (c >= 'a' && c <= 'z') {
1180 return cls.intern();
1181 }
1182 outError[0] = "Bad class name " + cls + " in package " + pkg;
1183 return null;
1184 }
1185
1186 private static String buildCompoundName(String pkg,
1187 CharSequence procSeq, String type, String[] outError) {
1188 String proc = procSeq.toString();
1189 char c = proc.charAt(0);
1190 if (pkg != null && c == ':') {
1191 if (proc.length() < 2) {
1192 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1193 + ": must be at least two characters";
1194 return null;
1195 }
1196 String subName = proc.substring(1);
1197 String nameError = validateName(subName, false);
1198 if (nameError != null) {
1199 outError[0] = "Invalid " + type + " name " + proc + " in package "
1200 + pkg + ": " + nameError;
1201 return null;
1202 }
1203 return (pkg + proc).intern();
1204 }
1205 String nameError = validateName(proc, true);
1206 if (nameError != null && !"system".equals(proc)) {
1207 outError[0] = "Invalid " + type + " name " + proc + " in package "
1208 + pkg + ": " + nameError;
1209 return null;
1210 }
1211 return proc.intern();
1212 }
1213
1214 private static String buildProcessName(String pkg, String defProc,
1215 CharSequence procSeq, int flags, String[] separateProcesses,
1216 String[] outError) {
1217 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1218 return defProc != null ? defProc : pkg;
1219 }
1220 if (separateProcesses != null) {
1221 for (int i=separateProcesses.length-1; i>=0; i--) {
1222 String sp = separateProcesses[i];
1223 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1224 return pkg;
1225 }
1226 }
1227 }
1228 if (procSeq == null || procSeq.length() <= 0) {
1229 return defProc;
1230 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001231 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 }
1233
1234 private static String buildTaskAffinityName(String pkg, String defProc,
1235 CharSequence procSeq, String[] outError) {
1236 if (procSeq == null) {
1237 return defProc;
1238 }
1239 if (procSeq.length() <= 0) {
1240 return null;
1241 }
1242 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1243 }
1244
1245 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1246 XmlPullParser parser, AttributeSet attrs, String[] outError)
1247 throws XmlPullParserException, IOException {
1248 PermissionGroup perm = new PermissionGroup(owner);
1249
1250 TypedArray sa = res.obtainAttributes(attrs,
1251 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1252
1253 if (!parsePackageItemInfo(owner, perm.info, outError,
1254 "<permission-group>", sa,
1255 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1256 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001257 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 sa.recycle();
1259 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1260 return null;
1261 }
1262
1263 perm.info.descriptionRes = sa.getResourceId(
1264 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1265 0);
1266
1267 sa.recycle();
1268
1269 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1270 outError)) {
1271 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1272 return null;
1273 }
1274
1275 owner.permissionGroups.add(perm);
1276
1277 return perm;
1278 }
1279
1280 private Permission parsePermission(Package owner, Resources res,
1281 XmlPullParser parser, AttributeSet attrs, String[] outError)
1282 throws XmlPullParserException, IOException {
1283 Permission perm = new Permission(owner);
1284
1285 TypedArray sa = res.obtainAttributes(attrs,
1286 com.android.internal.R.styleable.AndroidManifestPermission);
1287
1288 if (!parsePackageItemInfo(owner, perm.info, outError,
1289 "<permission>", sa,
1290 com.android.internal.R.styleable.AndroidManifestPermission_name,
1291 com.android.internal.R.styleable.AndroidManifestPermission_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001292 com.android.internal.R.styleable.AndroidManifestPermission_icon, 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 sa.recycle();
1294 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1295 return null;
1296 }
1297
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001298 // Note: don't allow this value to be a reference to a resource
1299 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 perm.info.group = sa.getNonResourceString(
1301 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1302 if (perm.info.group != null) {
1303 perm.info.group = perm.info.group.intern();
1304 }
1305
1306 perm.info.descriptionRes = sa.getResourceId(
1307 com.android.internal.R.styleable.AndroidManifestPermission_description,
1308 0);
1309
1310 perm.info.protectionLevel = sa.getInt(
1311 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1312 PermissionInfo.PROTECTION_NORMAL);
1313
1314 sa.recycle();
1315
1316 if (perm.info.protectionLevel == -1) {
1317 outError[0] = "<permission> does not specify protectionLevel";
1318 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1319 return null;
1320 }
1321
1322 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1323 outError)) {
1324 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1325 return null;
1326 }
1327
1328 owner.permissions.add(perm);
1329
1330 return perm;
1331 }
1332
1333 private Permission parsePermissionTree(Package owner, Resources res,
1334 XmlPullParser parser, AttributeSet attrs, String[] outError)
1335 throws XmlPullParserException, IOException {
1336 Permission perm = new Permission(owner);
1337
1338 TypedArray sa = res.obtainAttributes(attrs,
1339 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1340
1341 if (!parsePackageItemInfo(owner, perm.info, outError,
1342 "<permission-tree>", sa,
1343 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1344 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001345 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 sa.recycle();
1347 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1348 return null;
1349 }
1350
1351 sa.recycle();
1352
1353 int index = perm.info.name.indexOf('.');
1354 if (index > 0) {
1355 index = perm.info.name.indexOf('.', index+1);
1356 }
1357 if (index < 0) {
1358 outError[0] = "<permission-tree> name has less than three segments: "
1359 + perm.info.name;
1360 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1361 return null;
1362 }
1363
1364 perm.info.descriptionRes = 0;
1365 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1366 perm.tree = true;
1367
1368 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1369 outError)) {
1370 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1371 return null;
1372 }
1373
1374 owner.permissions.add(perm);
1375
1376 return perm;
1377 }
1378
1379 private Instrumentation parseInstrumentation(Package owner, Resources res,
1380 XmlPullParser parser, AttributeSet attrs, String[] outError)
1381 throws XmlPullParserException, IOException {
1382 TypedArray sa = res.obtainAttributes(attrs,
1383 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1384
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001385 if (mParseInstrumentationArgs == null) {
1386 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1387 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1388 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001389 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001390 mParseInstrumentationArgs.tag = "<instrumentation>";
1391 }
1392
1393 mParseInstrumentationArgs.sa = sa;
1394
1395 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1396 new InstrumentationInfo());
1397 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 sa.recycle();
1399 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1400 return null;
1401 }
1402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001404 // Note: don't allow this value to be a reference to a resource
1405 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 str = sa.getNonResourceString(
1407 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1408 a.info.targetPackage = str != null ? str.intern() : null;
1409
1410 a.info.handleProfiling = sa.getBoolean(
1411 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1412 false);
1413
1414 a.info.functionalTest = sa.getBoolean(
1415 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1416 false);
1417
1418 sa.recycle();
1419
1420 if (a.info.targetPackage == null) {
1421 outError[0] = "<instrumentation> does not specify targetPackage";
1422 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1423 return null;
1424 }
1425
1426 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1427 outError)) {
1428 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1429 return null;
1430 }
1431
1432 owner.instrumentation.add(a);
1433
1434 return a;
1435 }
1436
1437 private boolean parseApplication(Package owner, Resources res,
1438 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1439 throws XmlPullParserException, IOException {
1440 final ApplicationInfo ai = owner.applicationInfo;
1441 final String pkgName = owner.applicationInfo.packageName;
1442
1443 TypedArray sa = res.obtainAttributes(attrs,
1444 com.android.internal.R.styleable.AndroidManifestApplication);
1445
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001446 String name = sa.getNonConfigurationString(
1447 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 if (name != null) {
1449 ai.className = buildClassName(pkgName, name, outError);
1450 if (ai.className == null) {
1451 sa.recycle();
1452 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1453 return false;
1454 }
1455 }
1456
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001457 String manageSpaceActivity = sa.getNonConfigurationString(
1458 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 if (manageSpaceActivity != null) {
1460 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1461 outError);
1462 }
1463
Christopher Tate181fafa2009-05-14 11:12:14 -07001464 boolean allowBackup = sa.getBoolean(
1465 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1466 if (allowBackup) {
1467 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001468
Christopher Tate3de55bc2010-03-12 17:28:08 -08001469 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1470 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001471 String backupAgent = sa.getNonConfigurationString(
1472 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001473 if (backupAgent != null) {
1474 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001475 if (false) {
1476 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1477 + " from " + pkgName + "+" + backupAgent);
1478 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001479
1480 if (sa.getBoolean(
1481 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1482 true)) {
1483 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1484 }
1485 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001486 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1487 false)) {
1488 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1489 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001490 }
1491 }
1492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 TypedValue v = sa.peekValue(
1494 com.android.internal.R.styleable.AndroidManifestApplication_label);
1495 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1496 ai.nonLocalizedLabel = v.coerceToString();
1497 }
1498
1499 ai.icon = sa.getResourceId(
1500 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
1501 ai.theme = sa.getResourceId(
1502 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
1503 ai.descriptionRes = sa.getResourceId(
1504 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1505
1506 if ((flags&PARSE_IS_SYSTEM) != 0) {
1507 if (sa.getBoolean(
1508 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1509 false)) {
1510 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1511 }
1512 }
1513
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001514 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1515 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1516 }
1517
1518 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001519 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001520 }
1521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 if (sa.getBoolean(
1523 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1524 false)) {
1525 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1526 }
1527
1528 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001529 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001530 false)) {
1531 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1532 }
1533
1534 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1536 true)) {
1537 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1538 }
1539
1540 if (sa.getBoolean(
1541 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1542 false)) {
1543 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1544 }
1545
1546 if (sa.getBoolean(
1547 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1548 true)) {
1549 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1550 }
1551
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001552 if (sa.getBoolean(
1553 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001554 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001555 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1556 }
1557
Oscar Montemayor1874aa42009-11-10 18:35:33 -08001558 if (sa.getBoolean(
1559 com.android.internal.R.styleable.AndroidManifestApplication_neverEncrypt,
1560 false)) {
1561 ai.flags |= ApplicationInfo.FLAG_NEVER_ENCRYPT;
1562 }
1563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001565 str = sa.getNonConfigurationString(
1566 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1568
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001569 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1570 str = sa.getNonConfigurationString(
1571 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1572 } else {
1573 // Some older apps have been seen to use a resource reference
1574 // here that on older builds was ignored (with a warning). We
1575 // need to continue to do this for them so they don't break.
1576 str = sa.getNonResourceString(
1577 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1580 str, outError);
1581
1582 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001583 CharSequence pname;
1584 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1585 pname = sa.getNonConfigurationString(
1586 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1587 } else {
1588 // Some older apps have been seen to use a resource reference
1589 // here that on older builds was ignored (with a warning). We
1590 // need to continue to do this for them so they don't break.
1591 pname = sa.getNonResourceString(
1592 com.android.internal.R.styleable.AndroidManifestApplication_process);
1593 }
1594 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 flags, mSeparateProcesses, outError);
1596
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001597 ai.enabled = sa.getBoolean(
1598 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001599
Dianne Hackborn02486b12010-08-26 14:18:37 -07001600 if (false) {
1601 if (sa.getBoolean(
1602 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1603 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001604 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001605
1606 // A heavy-weight application can not be in a custom process.
1607 // We can do direct compare because we intern all strings.
1608 if (ai.processName != null && ai.processName != ai.packageName) {
1609 outError[0] = "cantSaveState applications can not use custom processes";
1610 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001611 }
1612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 }
1614
1615 sa.recycle();
1616
1617 if (outError[0] != null) {
1618 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1619 return false;
1620 }
1621
1622 final int innerDepth = parser.getDepth();
1623
1624 int type;
1625 while ((type=parser.next()) != parser.END_DOCUMENT
1626 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1627 if (type == parser.END_TAG || type == parser.TEXT) {
1628 continue;
1629 }
1630
1631 String tagName = parser.getName();
1632 if (tagName.equals("activity")) {
1633 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false);
1634 if (a == null) {
1635 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1636 return false;
1637 }
1638
1639 owner.activities.add(a);
1640
1641 } else if (tagName.equals("receiver")) {
1642 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true);
1643 if (a == null) {
1644 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1645 return false;
1646 }
1647
1648 owner.receivers.add(a);
1649
1650 } else if (tagName.equals("service")) {
1651 Service s = parseService(owner, res, parser, attrs, flags, outError);
1652 if (s == null) {
1653 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1654 return false;
1655 }
1656
1657 owner.services.add(s);
1658
1659 } else if (tagName.equals("provider")) {
1660 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1661 if (p == null) {
1662 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1663 return false;
1664 }
1665
1666 owner.providers.add(p);
1667
1668 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001669 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 if (a == null) {
1671 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1672 return false;
1673 }
1674
1675 owner.activities.add(a);
1676
1677 } else if (parser.getName().equals("meta-data")) {
1678 // note: application meta-data is stored off to the side, so it can
1679 // remain null in the primary copy (we like to avoid extra copies because
1680 // it can be large)
1681 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1682 outError)) == null) {
1683 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1684 return false;
1685 }
1686
1687 } else if (tagName.equals("uses-library")) {
1688 sa = res.obtainAttributes(attrs,
1689 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1690
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001691 // Note: don't allow this value to be a reference to a resource
1692 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 String lname = sa.getNonResourceString(
1694 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001695 boolean req = sa.getBoolean(
1696 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1697 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698
1699 sa.recycle();
1700
Dianne Hackborn49237342009-08-27 20:08:01 -07001701 if (lname != null) {
1702 if (req) {
1703 if (owner.usesLibraries == null) {
1704 owner.usesLibraries = new ArrayList<String>();
1705 }
1706 if (!owner.usesLibraries.contains(lname)) {
1707 owner.usesLibraries.add(lname.intern());
1708 }
1709 } else {
1710 if (owner.usesOptionalLibraries == null) {
1711 owner.usesOptionalLibraries = new ArrayList<String>();
1712 }
1713 if (!owner.usesOptionalLibraries.contains(lname)) {
1714 owner.usesOptionalLibraries.add(lname.intern());
1715 }
1716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 }
1718
1719 XmlUtils.skipCurrentTag(parser);
1720
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001721 } else if (tagName.equals("uses-package")) {
1722 // Dependencies for app installers; we don't currently try to
1723 // enforce this.
1724 XmlUtils.skipCurrentTag(parser);
1725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 } else {
1727 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001728 Log.w(TAG, "Unknown element under <application>: " + tagName
1729 + " at " + mArchiveSourcePath + " "
1730 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 XmlUtils.skipCurrentTag(parser);
1732 continue;
1733 } else {
1734 outError[0] = "Bad element under <application>: " + tagName;
1735 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1736 return false;
1737 }
1738 }
1739 }
1740
1741 return true;
1742 }
1743
1744 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1745 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001746 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001747 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 if (name == null) {
1749 outError[0] = tag + " does not specify android:name";
1750 return false;
1751 }
1752
1753 outInfo.name
1754 = buildClassName(owner.applicationInfo.packageName, name, outError);
1755 if (outInfo.name == null) {
1756 return false;
1757 }
1758
1759 int iconVal = sa.getResourceId(iconRes, 0);
1760 if (iconVal != 0) {
1761 outInfo.icon = iconVal;
1762 outInfo.nonLocalizedLabel = null;
1763 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 TypedValue v = sa.peekValue(labelRes);
1766 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1767 outInfo.nonLocalizedLabel = v.coerceToString();
1768 }
1769
1770 outInfo.packageName = owner.packageName;
1771
1772 return true;
1773 }
1774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 private Activity parseActivity(Package owner, Resources res,
1776 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
1777 boolean receiver) throws XmlPullParserException, IOException {
1778 TypedArray sa = res.obtainAttributes(attrs,
1779 com.android.internal.R.styleable.AndroidManifestActivity);
1780
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001781 if (mParseActivityArgs == null) {
1782 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1783 com.android.internal.R.styleable.AndroidManifestActivity_name,
1784 com.android.internal.R.styleable.AndroidManifestActivity_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001785 com.android.internal.R.styleable.AndroidManifestActivity_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001786 mSeparateProcesses,
1787 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001788 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001789 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1790 }
1791
1792 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1793 mParseActivityArgs.sa = sa;
1794 mParseActivityArgs.flags = flags;
1795
1796 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1797 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 sa.recycle();
1799 return null;
1800 }
1801
1802 final boolean setExported = sa.hasValue(
1803 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1804 if (setExported) {
1805 a.info.exported = sa.getBoolean(
1806 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1807 }
1808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 a.info.theme = sa.getResourceId(
1810 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1811
1812 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001813 str = sa.getNonConfigurationString(
1814 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (str == null) {
1816 a.info.permission = owner.applicationInfo.permission;
1817 } else {
1818 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1819 }
1820
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001821 str = sa.getNonConfigurationString(
1822 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1824 owner.applicationInfo.taskAffinity, str, outError);
1825
1826 a.info.flags = 0;
1827 if (sa.getBoolean(
1828 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1829 false)) {
1830 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1831 }
1832
1833 if (sa.getBoolean(
1834 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1835 false)) {
1836 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1837 }
1838
1839 if (sa.getBoolean(
1840 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1841 false)) {
1842 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1843 }
1844
1845 if (sa.getBoolean(
1846 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1847 false)) {
1848 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1849 }
1850
1851 if (sa.getBoolean(
1852 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1853 false)) {
1854 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1855 }
1856
1857 if (sa.getBoolean(
1858 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1859 false)) {
1860 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1861 }
1862
1863 if (sa.getBoolean(
1864 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1865 false)) {
1866 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1867 }
1868
1869 if (sa.getBoolean(
1870 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1871 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1872 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1873 }
1874
Dianne Hackbornffa42482009-09-23 22:20:11 -07001875 if (sa.getBoolean(
1876 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1877 false)) {
1878 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1879 }
1880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 if (!receiver) {
1882 a.info.launchMode = sa.getInt(
1883 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1884 ActivityInfo.LAUNCH_MULTIPLE);
1885 a.info.screenOrientation = sa.getInt(
1886 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1887 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1888 a.info.configChanges = sa.getInt(
1889 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1890 0);
1891 a.info.softInputMode = sa.getInt(
1892 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1893 0);
1894 } else {
1895 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1896 a.info.configChanges = 0;
1897 }
1898
1899 sa.recycle();
1900
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001901 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001902 // A heavy-weight application can not have receives in its main process
1903 // We can do direct compare because we intern all strings.
1904 if (a.info.processName == owner.packageName) {
1905 outError[0] = "Heavy-weight applications can not have receivers in main process";
1906 }
1907 }
1908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 if (outError[0] != null) {
1910 return null;
1911 }
1912
1913 int outerDepth = parser.getDepth();
1914 int type;
1915 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1916 && (type != XmlPullParser.END_TAG
1917 || parser.getDepth() > outerDepth)) {
1918 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1919 continue;
1920 }
1921
1922 if (parser.getName().equals("intent-filter")) {
1923 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1924 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1925 return null;
1926 }
1927 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001928 Log.w(TAG, "No actions in intent filter at "
1929 + mArchiveSourcePath + " "
1930 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 } else {
1932 a.intents.add(intent);
1933 }
1934 } else if (parser.getName().equals("meta-data")) {
1935 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1936 outError)) == null) {
1937 return null;
1938 }
1939 } else {
1940 if (!RIGID_PARSER) {
1941 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1942 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001943 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1944 + " at " + mArchiveSourcePath + " "
1945 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001947 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1948 + " at " + mArchiveSourcePath + " "
1949 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 }
1951 XmlUtils.skipCurrentTag(parser);
1952 continue;
1953 }
1954 if (receiver) {
1955 outError[0] = "Bad element under <receiver>: " + parser.getName();
1956 } else {
1957 outError[0] = "Bad element under <activity>: " + parser.getName();
1958 }
1959 return null;
1960 }
1961 }
1962
1963 if (!setExported) {
1964 a.info.exported = a.intents.size() > 0;
1965 }
1966
1967 return a;
1968 }
1969
1970 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001971 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1972 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 TypedArray sa = res.obtainAttributes(attrs,
1974 com.android.internal.R.styleable.AndroidManifestActivityAlias);
1975
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001976 String targetActivity = sa.getNonConfigurationString(
1977 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 if (targetActivity == null) {
1979 outError[0] = "<activity-alias> does not specify android:targetActivity";
1980 sa.recycle();
1981 return null;
1982 }
1983
1984 targetActivity = buildClassName(owner.applicationInfo.packageName,
1985 targetActivity, outError);
1986 if (targetActivity == null) {
1987 sa.recycle();
1988 return null;
1989 }
1990
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001991 if (mParseActivityAliasArgs == null) {
1992 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
1993 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
1994 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07001995 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001996 mSeparateProcesses,
1997 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001998 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001999 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2000 mParseActivityAliasArgs.tag = "<activity-alias>";
2001 }
2002
2003 mParseActivityAliasArgs.sa = sa;
2004 mParseActivityAliasArgs.flags = flags;
2005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 Activity target = null;
2007
2008 final int NA = owner.activities.size();
2009 for (int i=0; i<NA; i++) {
2010 Activity t = owner.activities.get(i);
2011 if (targetActivity.equals(t.info.name)) {
2012 target = t;
2013 break;
2014 }
2015 }
2016
2017 if (target == null) {
2018 outError[0] = "<activity-alias> target activity " + targetActivity
2019 + " not found in manifest";
2020 sa.recycle();
2021 return null;
2022 }
2023
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002024 ActivityInfo info = new ActivityInfo();
2025 info.targetActivity = targetActivity;
2026 info.configChanges = target.info.configChanges;
2027 info.flags = target.info.flags;
2028 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002029 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002030 info.labelRes = target.info.labelRes;
2031 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2032 info.launchMode = target.info.launchMode;
2033 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002034 if (info.descriptionRes == 0) {
2035 info.descriptionRes = target.info.descriptionRes;
2036 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002037 info.screenOrientation = target.info.screenOrientation;
2038 info.taskAffinity = target.info.taskAffinity;
2039 info.theme = target.info.theme;
2040
2041 Activity a = new Activity(mParseActivityAliasArgs, info);
2042 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 sa.recycle();
2044 return null;
2045 }
2046
2047 final boolean setExported = sa.hasValue(
2048 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2049 if (setExported) {
2050 a.info.exported = sa.getBoolean(
2051 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2052 }
2053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002055 str = sa.getNonConfigurationString(
2056 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 if (str != null) {
2058 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2059 }
2060
2061 sa.recycle();
2062
2063 if (outError[0] != null) {
2064 return null;
2065 }
2066
2067 int outerDepth = parser.getDepth();
2068 int type;
2069 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2070 && (type != XmlPullParser.END_TAG
2071 || parser.getDepth() > outerDepth)) {
2072 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2073 continue;
2074 }
2075
2076 if (parser.getName().equals("intent-filter")) {
2077 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2078 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2079 return null;
2080 }
2081 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002082 Log.w(TAG, "No actions in intent filter at "
2083 + mArchiveSourcePath + " "
2084 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 } else {
2086 a.intents.add(intent);
2087 }
2088 } else if (parser.getName().equals("meta-data")) {
2089 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2090 outError)) == null) {
2091 return null;
2092 }
2093 } else {
2094 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002095 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2096 + " at " + mArchiveSourcePath + " "
2097 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 XmlUtils.skipCurrentTag(parser);
2099 continue;
2100 }
2101 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2102 return null;
2103 }
2104 }
2105
2106 if (!setExported) {
2107 a.info.exported = a.intents.size() > 0;
2108 }
2109
2110 return a;
2111 }
2112
2113 private Provider parseProvider(Package owner, Resources res,
2114 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2115 throws XmlPullParserException, IOException {
2116 TypedArray sa = res.obtainAttributes(attrs,
2117 com.android.internal.R.styleable.AndroidManifestProvider);
2118
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002119 if (mParseProviderArgs == null) {
2120 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2121 com.android.internal.R.styleable.AndroidManifestProvider_name,
2122 com.android.internal.R.styleable.AndroidManifestProvider_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002123 com.android.internal.R.styleable.AndroidManifestProvider_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002124 mSeparateProcesses,
2125 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002126 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002127 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2128 mParseProviderArgs.tag = "<provider>";
2129 }
2130
2131 mParseProviderArgs.sa = sa;
2132 mParseProviderArgs.flags = flags;
2133
2134 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2135 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 sa.recycle();
2137 return null;
2138 }
2139
2140 p.info.exported = sa.getBoolean(
2141 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2142
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002143 String cpname = sa.getNonConfigurationString(
2144 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145
2146 p.info.isSyncable = sa.getBoolean(
2147 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2148 false);
2149
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002150 String permission = sa.getNonConfigurationString(
2151 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2152 String str = sa.getNonConfigurationString(
2153 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 if (str == null) {
2155 str = permission;
2156 }
2157 if (str == null) {
2158 p.info.readPermission = owner.applicationInfo.permission;
2159 } else {
2160 p.info.readPermission =
2161 str.length() > 0 ? str.toString().intern() : null;
2162 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002163 str = sa.getNonConfigurationString(
2164 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 if (str == null) {
2166 str = permission;
2167 }
2168 if (str == null) {
2169 p.info.writePermission = owner.applicationInfo.permission;
2170 } else {
2171 p.info.writePermission =
2172 str.length() > 0 ? str.toString().intern() : null;
2173 }
2174
2175 p.info.grantUriPermissions = sa.getBoolean(
2176 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2177 false);
2178
2179 p.info.multiprocess = sa.getBoolean(
2180 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2181 false);
2182
2183 p.info.initOrder = sa.getInt(
2184 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2185 0);
2186
2187 sa.recycle();
2188
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002189 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002190 // A heavy-weight application can not have providers in its main process
2191 // We can do direct compare because we intern all strings.
2192 if (p.info.processName == owner.packageName) {
2193 outError[0] = "Heavy-weight applications can not have providers in main process";
2194 return null;
2195 }
2196 }
2197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 if (cpname == null) {
2199 outError[0] = "<provider> does not incude authorities attribute";
2200 return null;
2201 }
2202 p.info.authority = cpname.intern();
2203
2204 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2205 return null;
2206 }
2207
2208 return p;
2209 }
2210
2211 private boolean parseProviderTags(Resources res,
2212 XmlPullParser parser, AttributeSet attrs,
2213 Provider outInfo, String[] outError)
2214 throws XmlPullParserException, IOException {
2215 int outerDepth = parser.getDepth();
2216 int type;
2217 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2218 && (type != XmlPullParser.END_TAG
2219 || parser.getDepth() > outerDepth)) {
2220 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2221 continue;
2222 }
2223
2224 if (parser.getName().equals("meta-data")) {
2225 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2226 outInfo.metaData, outError)) == null) {
2227 return false;
2228 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 } else if (parser.getName().equals("grant-uri-permission")) {
2231 TypedArray sa = res.obtainAttributes(attrs,
2232 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2233
2234 PatternMatcher pa = null;
2235
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002236 String str = sa.getNonConfigurationString(
2237 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 if (str != null) {
2239 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2240 }
2241
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002242 str = sa.getNonConfigurationString(
2243 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 if (str != null) {
2245 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2246 }
2247
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002248 str = sa.getNonConfigurationString(
2249 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 if (str != null) {
2251 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2252 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 sa.recycle();
2255
2256 if (pa != null) {
2257 if (outInfo.info.uriPermissionPatterns == null) {
2258 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2259 outInfo.info.uriPermissionPatterns[0] = pa;
2260 } else {
2261 final int N = outInfo.info.uriPermissionPatterns.length;
2262 PatternMatcher[] newp = new PatternMatcher[N+1];
2263 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2264 newp[N] = pa;
2265 outInfo.info.uriPermissionPatterns = newp;
2266 }
2267 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002268 } else {
2269 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002270 Log.w(TAG, "Unknown element under <path-permission>: "
2271 + parser.getName() + " at " + mArchiveSourcePath + " "
2272 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002273 XmlUtils.skipCurrentTag(parser);
2274 continue;
2275 }
2276 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2277 return false;
2278 }
2279 XmlUtils.skipCurrentTag(parser);
2280
2281 } else if (parser.getName().equals("path-permission")) {
2282 TypedArray sa = res.obtainAttributes(attrs,
2283 com.android.internal.R.styleable.AndroidManifestPathPermission);
2284
2285 PathPermission pa = null;
2286
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002287 String permission = sa.getNonConfigurationString(
2288 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2289 String readPermission = sa.getNonConfigurationString(
2290 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002291 if (readPermission == null) {
2292 readPermission = permission;
2293 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002294 String writePermission = sa.getNonConfigurationString(
2295 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002296 if (writePermission == null) {
2297 writePermission = permission;
2298 }
2299
2300 boolean havePerm = false;
2301 if (readPermission != null) {
2302 readPermission = readPermission.intern();
2303 havePerm = true;
2304 }
2305 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002306 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002307 havePerm = true;
2308 }
2309
2310 if (!havePerm) {
2311 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002312 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2313 + parser.getName() + " at " + mArchiveSourcePath + " "
2314 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002315 XmlUtils.skipCurrentTag(parser);
2316 continue;
2317 }
2318 outError[0] = "No readPermission or writePermssion for <path-permission>";
2319 return false;
2320 }
2321
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002322 String path = sa.getNonConfigurationString(
2323 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002324 if (path != null) {
2325 pa = new PathPermission(path,
2326 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2327 }
2328
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002329 path = sa.getNonConfigurationString(
2330 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002331 if (path != null) {
2332 pa = new PathPermission(path,
2333 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2334 }
2335
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002336 path = sa.getNonConfigurationString(
2337 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002338 if (path != null) {
2339 pa = new PathPermission(path,
2340 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2341 }
2342
2343 sa.recycle();
2344
2345 if (pa != null) {
2346 if (outInfo.info.pathPermissions == null) {
2347 outInfo.info.pathPermissions = new PathPermission[1];
2348 outInfo.info.pathPermissions[0] = pa;
2349 } else {
2350 final int N = outInfo.info.pathPermissions.length;
2351 PathPermission[] newp = new PathPermission[N+1];
2352 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2353 newp[N] = pa;
2354 outInfo.info.pathPermissions = newp;
2355 }
2356 } else {
2357 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002358 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2359 + parser.getName() + " at " + mArchiveSourcePath + " "
2360 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002361 XmlUtils.skipCurrentTag(parser);
2362 continue;
2363 }
2364 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2365 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 }
2367 XmlUtils.skipCurrentTag(parser);
2368
2369 } else {
2370 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002372 + parser.getName() + " at " + mArchiveSourcePath + " "
2373 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 XmlUtils.skipCurrentTag(parser);
2375 continue;
2376 }
2377 outError[0] = "Bad element under <provider>: "
2378 + parser.getName();
2379 return false;
2380 }
2381 }
2382 return true;
2383 }
2384
2385 private Service parseService(Package owner, Resources res,
2386 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2387 throws XmlPullParserException, IOException {
2388 TypedArray sa = res.obtainAttributes(attrs,
2389 com.android.internal.R.styleable.AndroidManifestService);
2390
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002391 if (mParseServiceArgs == null) {
2392 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2393 com.android.internal.R.styleable.AndroidManifestService_name,
2394 com.android.internal.R.styleable.AndroidManifestService_label,
Dianne Hackborn234e42d2010-09-24 17:18:53 -07002395 com.android.internal.R.styleable.AndroidManifestService_icon, 0,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002396 mSeparateProcesses,
2397 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002398 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002399 com.android.internal.R.styleable.AndroidManifestService_enabled);
2400 mParseServiceArgs.tag = "<service>";
2401 }
2402
2403 mParseServiceArgs.sa = sa;
2404 mParseServiceArgs.flags = flags;
2405
2406 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2407 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 sa.recycle();
2409 return null;
2410 }
2411
2412 final boolean setExported = sa.hasValue(
2413 com.android.internal.R.styleable.AndroidManifestService_exported);
2414 if (setExported) {
2415 s.info.exported = sa.getBoolean(
2416 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2417 }
2418
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002419 String str = sa.getNonConfigurationString(
2420 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 if (str == null) {
2422 s.info.permission = owner.applicationInfo.permission;
2423 } else {
2424 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2425 }
2426
2427 sa.recycle();
2428
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002429 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002430 // A heavy-weight application can not have services in its main process
2431 // We can do direct compare because we intern all strings.
2432 if (s.info.processName == owner.packageName) {
2433 outError[0] = "Heavy-weight applications can not have services in main process";
2434 return null;
2435 }
2436 }
2437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 int outerDepth = parser.getDepth();
2439 int type;
2440 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2441 && (type != XmlPullParser.END_TAG
2442 || parser.getDepth() > outerDepth)) {
2443 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2444 continue;
2445 }
2446
2447 if (parser.getName().equals("intent-filter")) {
2448 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2449 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2450 return null;
2451 }
2452
2453 s.intents.add(intent);
2454 } else if (parser.getName().equals("meta-data")) {
2455 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2456 outError)) == null) {
2457 return null;
2458 }
2459 } else {
2460 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002462 + parser.getName() + " at " + mArchiveSourcePath + " "
2463 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 XmlUtils.skipCurrentTag(parser);
2465 continue;
2466 }
2467 outError[0] = "Bad element under <service>: "
2468 + parser.getName();
2469 return null;
2470 }
2471 }
2472
2473 if (!setExported) {
2474 s.info.exported = s.intents.size() > 0;
2475 }
2476
2477 return s;
2478 }
2479
2480 private boolean parseAllMetaData(Resources res,
2481 XmlPullParser parser, AttributeSet attrs, String tag,
2482 Component outInfo, String[] outError)
2483 throws XmlPullParserException, IOException {
2484 int outerDepth = parser.getDepth();
2485 int type;
2486 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2487 && (type != XmlPullParser.END_TAG
2488 || parser.getDepth() > outerDepth)) {
2489 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2490 continue;
2491 }
2492
2493 if (parser.getName().equals("meta-data")) {
2494 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2495 outInfo.metaData, outError)) == null) {
2496 return false;
2497 }
2498 } else {
2499 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002501 + parser.getName() + " at " + mArchiveSourcePath + " "
2502 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 XmlUtils.skipCurrentTag(parser);
2504 continue;
2505 }
2506 outError[0] = "Bad element under " + tag + ": "
2507 + parser.getName();
2508 return false;
2509 }
2510 }
2511 return true;
2512 }
2513
2514 private Bundle parseMetaData(Resources res,
2515 XmlPullParser parser, AttributeSet attrs,
2516 Bundle data, String[] outError)
2517 throws XmlPullParserException, IOException {
2518
2519 TypedArray sa = res.obtainAttributes(attrs,
2520 com.android.internal.R.styleable.AndroidManifestMetaData);
2521
2522 if (data == null) {
2523 data = new Bundle();
2524 }
2525
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002526 String name = sa.getNonConfigurationString(
2527 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (name == null) {
2529 outError[0] = "<meta-data> requires an android:name attribute";
2530 sa.recycle();
2531 return null;
2532 }
2533
Dianne Hackborn854060a2009-07-09 18:14:31 -07002534 name = name.intern();
2535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 TypedValue v = sa.peekValue(
2537 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2538 if (v != null && v.resourceId != 0) {
2539 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2540 data.putInt(name, v.resourceId);
2541 } else {
2542 v = sa.peekValue(
2543 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2544 //Log.i(TAG, "Meta data " + name + ": " + v);
2545 if (v != null) {
2546 if (v.type == TypedValue.TYPE_STRING) {
2547 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002548 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2550 data.putBoolean(name, v.data != 0);
2551 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2552 && v.type <= TypedValue.TYPE_LAST_INT) {
2553 data.putInt(name, v.data);
2554 } else if (v.type == TypedValue.TYPE_FLOAT) {
2555 data.putFloat(name, v.getFloat());
2556 } else {
2557 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002558 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2559 + parser.getName() + " at " + mArchiveSourcePath + " "
2560 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 } else {
2562 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2563 data = null;
2564 }
2565 }
2566 } else {
2567 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2568 data = null;
2569 }
2570 }
2571
2572 sa.recycle();
2573
2574 XmlUtils.skipCurrentTag(parser);
2575
2576 return data;
2577 }
2578
2579 private static final String ANDROID_RESOURCES
2580 = "http://schemas.android.com/apk/res/android";
2581
2582 private boolean parseIntent(Resources res,
2583 XmlPullParser parser, AttributeSet attrs, int flags,
2584 IntentInfo outInfo, String[] outError, boolean isActivity)
2585 throws XmlPullParserException, IOException {
2586
2587 TypedArray sa = res.obtainAttributes(attrs,
2588 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2589
2590 int priority = sa.getInt(
2591 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
2592 if (priority > 0 && isActivity && (flags&PARSE_IS_SYSTEM) == 0) {
2593 Log.w(TAG, "Activity with priority > 0, forcing to 0 at "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002594 + mArchiveSourcePath + " "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 + parser.getPositionDescription());
2596 priority = 0;
2597 }
2598 outInfo.setPriority(priority);
2599
2600 TypedValue v = sa.peekValue(
2601 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2602 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2603 outInfo.nonLocalizedLabel = v.coerceToString();
2604 }
2605
2606 outInfo.icon = sa.getResourceId(
2607 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 sa.recycle();
2610
2611 int outerDepth = parser.getDepth();
2612 int type;
2613 while ((type=parser.next()) != parser.END_DOCUMENT
2614 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2615 if (type == parser.END_TAG || type == parser.TEXT) {
2616 continue;
2617 }
2618
2619 String nodeName = parser.getName();
2620 if (nodeName.equals("action")) {
2621 String value = attrs.getAttributeValue(
2622 ANDROID_RESOURCES, "name");
2623 if (value == null || value == "") {
2624 outError[0] = "No value supplied for <android:name>";
2625 return false;
2626 }
2627 XmlUtils.skipCurrentTag(parser);
2628
2629 outInfo.addAction(value);
2630 } else if (nodeName.equals("category")) {
2631 String value = attrs.getAttributeValue(
2632 ANDROID_RESOURCES, "name");
2633 if (value == null || value == "") {
2634 outError[0] = "No value supplied for <android:name>";
2635 return false;
2636 }
2637 XmlUtils.skipCurrentTag(parser);
2638
2639 outInfo.addCategory(value);
2640
2641 } else if (nodeName.equals("data")) {
2642 sa = res.obtainAttributes(attrs,
2643 com.android.internal.R.styleable.AndroidManifestData);
2644
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002645 String str = sa.getNonConfigurationString(
2646 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 if (str != null) {
2648 try {
2649 outInfo.addDataType(str);
2650 } catch (IntentFilter.MalformedMimeTypeException e) {
2651 outError[0] = e.toString();
2652 sa.recycle();
2653 return false;
2654 }
2655 }
2656
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002657 str = sa.getNonConfigurationString(
2658 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 if (str != null) {
2660 outInfo.addDataScheme(str);
2661 }
2662
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002663 String host = sa.getNonConfigurationString(
2664 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2665 String port = sa.getNonConfigurationString(
2666 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 if (host != null) {
2668 outInfo.addDataAuthority(host, port);
2669 }
2670
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002671 str = sa.getNonConfigurationString(
2672 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 if (str != null) {
2674 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2675 }
2676
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002677 str = sa.getNonConfigurationString(
2678 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 if (str != null) {
2680 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2681 }
2682
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002683 str = sa.getNonConfigurationString(
2684 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 if (str != null) {
2686 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2687 }
2688
2689 sa.recycle();
2690 XmlUtils.skipCurrentTag(parser);
2691 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002692 Log.w(TAG, "Unknown element under <intent-filter>: "
2693 + parser.getName() + " at " + mArchiveSourcePath + " "
2694 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 XmlUtils.skipCurrentTag(parser);
2696 } else {
2697 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2698 return false;
2699 }
2700 }
2701
2702 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2703 if (false) {
2704 String cats = "";
2705 Iterator<String> it = outInfo.categoriesIterator();
2706 while (it != null && it.hasNext()) {
2707 cats += " " + it.next();
2708 }
2709 System.out.println("Intent d=" +
2710 outInfo.hasDefault + ", cat=" + cats);
2711 }
2712
2713 return true;
2714 }
2715
2716 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002717 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718
2719 // For now we only support one application per package.
2720 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2721
2722 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2723 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2724 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2725 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2726 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2727 public final ArrayList<Service> services = new ArrayList<Service>(0);
2728 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2729
2730 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2731
Dianne Hackborn854060a2009-07-09 18:14:31 -07002732 public ArrayList<String> protectedBroadcasts;
2733
Dianne Hackborn49237342009-08-27 20:08:01 -07002734 public ArrayList<String> usesLibraries = null;
2735 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002736 public String[] usesLibraryFiles = null;
2737
Dianne Hackbornc1552392010-03-03 16:19:01 -08002738 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002739 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002740 public ArrayList<String> mAdoptPermissions = null;
2741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 // We store the application meta-data independently to avoid multiple unwanted references
2743 public Bundle mAppMetaData = null;
2744
2745 // If this is a 3rd party app, this is the path of the zip file.
2746 public String mPath;
2747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 // The version code declared for this package.
2749 public int mVersionCode;
2750
2751 // The version name declared for this package.
2752 public String mVersionName;
2753
2754 // The shared user id that this package wants to use.
2755 public String mSharedUserId;
2756
2757 // The shared user label that this package wants to use.
2758 public int mSharedUserLabel;
2759
2760 // Signatures that were read from the package.
2761 public Signature mSignatures[];
2762
2763 // For use by package manager service for quick lookup of
2764 // preferred up order.
2765 public int mPreferredOrder = 0;
2766
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002767 // For use by the package manager to keep track of the path to the
2768 // file an app came from.
2769 public String mScanPath;
2770
2771 // For use by package manager to keep track of where it has done dexopt.
2772 public boolean mDidDexOpt;
2773
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002774 // User set enabled state.
2775 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 // Additional data supplied by callers.
2778 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002779
2780 // Whether an operation is currently pending on this package
2781 public boolean mOperationPending;
2782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 /*
2784 * Applications hardware preferences
2785 */
2786 public final ArrayList<ConfigurationInfo> configPreferences =
2787 new ArrayList<ConfigurationInfo>();
2788
Dianne Hackborn49237342009-08-27 20:08:01 -07002789 /*
2790 * Applications requested features
2791 */
2792 public ArrayList<FeatureInfo> reqFeatures = null;
2793
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002794 public int installLocation;
2795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 public Package(String _name) {
2797 packageName = _name;
2798 applicationInfo.packageName = _name;
2799 applicationInfo.uid = -1;
2800 }
2801
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002802 public void setPackageName(String newName) {
2803 packageName = newName;
2804 applicationInfo.packageName = newName;
2805 for (int i=permissions.size()-1; i>=0; i--) {
2806 permissions.get(i).setPackageName(newName);
2807 }
2808 for (int i=permissionGroups.size()-1; i>=0; i--) {
2809 permissionGroups.get(i).setPackageName(newName);
2810 }
2811 for (int i=activities.size()-1; i>=0; i--) {
2812 activities.get(i).setPackageName(newName);
2813 }
2814 for (int i=receivers.size()-1; i>=0; i--) {
2815 receivers.get(i).setPackageName(newName);
2816 }
2817 for (int i=providers.size()-1; i>=0; i--) {
2818 providers.get(i).setPackageName(newName);
2819 }
2820 for (int i=services.size()-1; i>=0; i--) {
2821 services.get(i).setPackageName(newName);
2822 }
2823 for (int i=instrumentation.size()-1; i>=0; i--) {
2824 instrumentation.get(i).setPackageName(newName);
2825 }
2826 }
2827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 public String toString() {
2829 return "Package{"
2830 + Integer.toHexString(System.identityHashCode(this))
2831 + " " + packageName + "}";
2832 }
2833 }
2834
2835 public static class Component<II extends IntentInfo> {
2836 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002837 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002838 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 public Bundle metaData;
2840
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002841 ComponentName componentName;
2842 String componentShortName;
2843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 public Component(Package _owner) {
2845 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002846 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002847 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002848 }
2849
2850 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2851 owner = args.owner;
2852 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002853 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002854 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002855 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002856 args.outError[0] = args.tag + " does not specify android:name";
2857 return;
2858 }
2859
2860 outInfo.name
2861 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2862 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002863 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002864 args.outError[0] = args.tag + " does not have valid android:name";
2865 return;
2866 }
2867
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002868 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002869
2870 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2871 if (iconVal != 0) {
2872 outInfo.icon = iconVal;
2873 outInfo.nonLocalizedLabel = null;
2874 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002875
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002876 TypedValue v = args.sa.peekValue(args.labelRes);
2877 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2878 outInfo.nonLocalizedLabel = v.coerceToString();
2879 }
2880
2881 outInfo.packageName = owner.packageName;
2882 }
2883
2884 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2885 this(args, (PackageItemInfo)outInfo);
2886 if (args.outError[0] != null) {
2887 return;
2888 }
2889
2890 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002891 CharSequence pname;
2892 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2893 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2894 } else {
2895 // Some older apps have been seen to use a resource reference
2896 // here that on older builds was ignored (with a warning). We
2897 // need to continue to do this for them so they don't break.
2898 pname = args.sa.getNonResourceString(args.processRes);
2899 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002900 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002901 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002902 args.flags, args.sepProcesses, args.outError);
2903 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002904
2905 if (args.descriptionRes != 0) {
2906 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2907 }
2908
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002909 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 }
2911
2912 public Component(Component<II> clone) {
2913 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002914 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002915 className = clone.className;
2916 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002917 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002918 }
2919
2920 public ComponentName getComponentName() {
2921 if (componentName != null) {
2922 return componentName;
2923 }
2924 if (className != null) {
2925 componentName = new ComponentName(owner.applicationInfo.packageName,
2926 className);
2927 }
2928 return componentName;
2929 }
2930
2931 public String getComponentShortName() {
2932 if (componentShortName != null) {
2933 return componentShortName;
2934 }
2935 ComponentName component = getComponentName();
2936 if (component != null) {
2937 componentShortName = component.flattenToShortString();
2938 }
2939 return componentShortName;
2940 }
2941
2942 public void setPackageName(String packageName) {
2943 componentName = null;
2944 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
2946 }
2947
2948 public final static class Permission extends Component<IntentInfo> {
2949 public final PermissionInfo info;
2950 public boolean tree;
2951 public PermissionGroup group;
2952
2953 public Permission(Package _owner) {
2954 super(_owner);
2955 info = new PermissionInfo();
2956 }
2957
2958 public Permission(Package _owner, PermissionInfo _info) {
2959 super(_owner);
2960 info = _info;
2961 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002962
2963 public void setPackageName(String packageName) {
2964 super.setPackageName(packageName);
2965 info.packageName = packageName;
2966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967
2968 public String toString() {
2969 return "Permission{"
2970 + Integer.toHexString(System.identityHashCode(this))
2971 + " " + info.name + "}";
2972 }
2973 }
2974
2975 public final static class PermissionGroup extends Component<IntentInfo> {
2976 public final PermissionGroupInfo info;
2977
2978 public PermissionGroup(Package _owner) {
2979 super(_owner);
2980 info = new PermissionGroupInfo();
2981 }
2982
2983 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
2984 super(_owner);
2985 info = _info;
2986 }
2987
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002988 public void setPackageName(String packageName) {
2989 super.setPackageName(packageName);
2990 info.packageName = packageName;
2991 }
2992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 public String toString() {
2994 return "PermissionGroup{"
2995 + Integer.toHexString(System.identityHashCode(this))
2996 + " " + info.name + "}";
2997 }
2998 }
2999
3000 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003001 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3002 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3003 if (p.applicationInfo.enabled != enabled) {
3004 return true;
3005 }
3006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 if ((flags & PackageManager.GET_META_DATA) != 0
3008 && (metaData != null || p.mAppMetaData != null)) {
3009 return true;
3010 }
3011 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3012 && p.usesLibraryFiles != null) {
3013 return true;
3014 }
3015 return false;
3016 }
3017
3018 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3019 if (p == null) return null;
3020 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003021 // CompatibilityMode is global state. It's safe to modify the instance
3022 // of the package.
3023 if (!sCompatibilityModeEnabled) {
3024 p.applicationInfo.disableCompatibilityMode();
3025 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 return p.applicationInfo;
3027 }
3028
3029 // Make shallow copy so we can store the metadata/libraries safely
3030 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3031 if ((flags & PackageManager.GET_META_DATA) != 0) {
3032 ai.metaData = p.mAppMetaData;
3033 }
3034 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3035 ai.sharedLibraryFiles = p.usesLibraryFiles;
3036 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003037 if (!sCompatibilityModeEnabled) {
3038 ai.disableCompatibilityMode();
3039 }
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003040 ai.enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 return ai;
3042 }
3043
3044 public static final PermissionInfo generatePermissionInfo(
3045 Permission p, int flags) {
3046 if (p == null) return null;
3047 if ((flags&PackageManager.GET_META_DATA) == 0) {
3048 return p.info;
3049 }
3050 PermissionInfo pi = new PermissionInfo(p.info);
3051 pi.metaData = p.metaData;
3052 return pi;
3053 }
3054
3055 public static final PermissionGroupInfo generatePermissionGroupInfo(
3056 PermissionGroup pg, int flags) {
3057 if (pg == null) return null;
3058 if ((flags&PackageManager.GET_META_DATA) == 0) {
3059 return pg.info;
3060 }
3061 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3062 pgi.metaData = pg.metaData;
3063 return pgi;
3064 }
3065
3066 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003067 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003069 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3070 super(args, _info);
3071 info = _info;
3072 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003074
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003075 public void setPackageName(String packageName) {
3076 super.setPackageName(packageName);
3077 info.packageName = packageName;
3078 }
3079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 public String toString() {
3081 return "Activity{"
3082 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003083 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 }
3085 }
3086
3087 public static final ActivityInfo generateActivityInfo(Activity a,
3088 int flags) {
3089 if (a == null) return null;
3090 if (!copyNeeded(flags, a.owner, a.metaData)) {
3091 return a.info;
3092 }
3093 // Make shallow copies so we can store the metadata safely
3094 ActivityInfo ai = new ActivityInfo(a.info);
3095 ai.metaData = a.metaData;
3096 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3097 return ai;
3098 }
3099
3100 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003101 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003102
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003103 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3104 super(args, _info);
3105 info = _info;
3106 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003108
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003109 public void setPackageName(String packageName) {
3110 super.setPackageName(packageName);
3111 info.packageName = packageName;
3112 }
3113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 public String toString() {
3115 return "Service{"
3116 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003117 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 }
3119 }
3120
3121 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3122 if (s == null) return null;
3123 if (!copyNeeded(flags, s.owner, s.metaData)) {
3124 return s.info;
3125 }
3126 // Make shallow copies so we can store the metadata safely
3127 ServiceInfo si = new ServiceInfo(s.info);
3128 si.metaData = s.metaData;
3129 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3130 return si;
3131 }
3132
3133 public final static class Provider extends Component {
3134 public final ProviderInfo info;
3135 public boolean syncable;
3136
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003137 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3138 super(args, _info);
3139 info = _info;
3140 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 syncable = false;
3142 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 public Provider(Provider existingProvider) {
3145 super(existingProvider);
3146 this.info = existingProvider.info;
3147 this.syncable = existingProvider.syncable;
3148 }
3149
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003150 public void setPackageName(String packageName) {
3151 super.setPackageName(packageName);
3152 info.packageName = packageName;
3153 }
3154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 public String toString() {
3156 return "Provider{"
3157 + Integer.toHexString(System.identityHashCode(this))
3158 + " " + info.name + "}";
3159 }
3160 }
3161
3162 public static final ProviderInfo generateProviderInfo(Provider p,
3163 int flags) {
3164 if (p == null) return null;
3165 if (!copyNeeded(flags, p.owner, p.metaData)
3166 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3167 || p.info.uriPermissionPatterns == null)) {
3168 return p.info;
3169 }
3170 // Make shallow copies so we can store the metadata safely
3171 ProviderInfo pi = new ProviderInfo(p.info);
3172 pi.metaData = p.metaData;
3173 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3174 pi.uriPermissionPatterns = null;
3175 }
3176 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3177 return pi;
3178 }
3179
3180 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003181 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003183 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3184 super(args, _info);
3185 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003187
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003188 public void setPackageName(String packageName) {
3189 super.setPackageName(packageName);
3190 info.packageName = packageName;
3191 }
3192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 public String toString() {
3194 return "Instrumentation{"
3195 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003196 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 }
3198 }
3199
3200 public static final InstrumentationInfo generateInstrumentationInfo(
3201 Instrumentation i, int flags) {
3202 if (i == null) return null;
3203 if ((flags&PackageManager.GET_META_DATA) == 0) {
3204 return i.info;
3205 }
3206 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3207 ii.metaData = i.metaData;
3208 return ii;
3209 }
3210
3211 public static class IntentInfo extends IntentFilter {
3212 public boolean hasDefault;
3213 public int labelRes;
3214 public CharSequence nonLocalizedLabel;
3215 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003216 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 }
3218
3219 public final static class ActivityIntentInfo extends IntentInfo {
3220 public final Activity activity;
3221
3222 public ActivityIntentInfo(Activity _activity) {
3223 activity = _activity;
3224 }
3225
3226 public String toString() {
3227 return "ActivityIntentInfo{"
3228 + Integer.toHexString(System.identityHashCode(this))
3229 + " " + activity.info.name + "}";
3230 }
3231 }
3232
3233 public final static class ServiceIntentInfo extends IntentInfo {
3234 public final Service service;
3235
3236 public ServiceIntentInfo(Service _service) {
3237 service = _service;
3238 }
3239
3240 public String toString() {
3241 return "ServiceIntentInfo{"
3242 + Integer.toHexString(System.identityHashCode(this))
3243 + " " + service.info.name + "}";
3244 }
3245 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003246
3247 /**
3248 * @hide
3249 */
3250 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3251 sCompatibilityModeEnabled = compatibilityModeEnabled;
3252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253}