blob: 54a8842010cb38806108ff39a5efaa3ce01a3f6e [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IntentFilter;
22import android.content.res.AssetManager;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.content.res.XmlResourceParser;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Bundle;
29import android.os.PatternMatcher;
30import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.DisplayMetrics;
32import android.util.Log;
33import android.util.TypedValue;
Jason parksa3cdaa52011-01-13 14:15:43 -060034import com.android.internal.util.XmlUtils;
35import org.xmlpull.v1.XmlPullParser;
36import org.xmlpull.v1.XmlPullParserException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Kenny Rootd63f7db2010-09-27 08:07:48 -070038import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.File;
40import java.io.IOException;
41import java.io.InputStream;
42import java.lang.ref.WeakReference;
43import java.security.cert.Certificate;
44import java.security.cert.CertificateEncodingException;
45import java.util.ArrayList;
46import java.util.Enumeration;
47import java.util.Iterator;
48import java.util.jar.JarEntry;
49import java.util.jar.JarFile;
50
51/**
52 * Package archive parsing
53 *
54 * {@hide}
55 */
56public class PackageParser {
Dianne Hackborna96cbb42009-05-13 15:06:13 -070057 /** @hide */
58 public static class NewPermissionInfo {
59 public final String name;
60 public final int sdkVersion;
61 public final int fileVersion;
62
63 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
64 this.name = name;
65 this.sdkVersion = sdkVersion;
66 this.fileVersion = fileVersion;
67 }
68 }
69
70 /**
71 * List of new permissions that have been added since 1.0.
72 * NOTE: These must be declared in SDK version order, with permissions
73 * added to older SDKs appearing before those added to newer SDKs.
74 * @hide
75 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -070076 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
77 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070078 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070079 android.os.Build.VERSION_CODES.DONUT, 0),
80 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
81 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -070082 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
84 private String mArchiveSourcePath;
85 private String[] mSeparateProcesses;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070086 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
87 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
88 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
90 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
91
92 private static final Object mSync = new Object();
93 private static WeakReference<byte[]> mReadBuffer;
94
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -070095 private static boolean sCompatibilityModeEnabled = true;
96 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -070097
Dianne Hackborn1d442e02009-04-20 18:14:05 -070098 static class ParsePackageItemArgs {
99 final Package owner;
100 final String[] outError;
101 final int nameRes;
102 final int labelRes;
103 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700104 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700105
106 String tag;
107 TypedArray sa;
108
109 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700110 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700111 owner = _owner;
112 outError = _outError;
113 nameRes = _nameRes;
114 labelRes = _labelRes;
115 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700116 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700117 }
118 }
119
120 static class ParseComponentArgs extends ParsePackageItemArgs {
121 final String[] sepProcesses;
122 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800123 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700124 final int enabledRes;
125 int flags;
126
127 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700128 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800129 String[] _sepProcesses, int _processRes,
130 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700131 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700132 sepProcesses = _sepProcesses;
133 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800134 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700135 enabledRes = _enabledRes;
136 }
137 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800138
139 /* Light weight package info.
140 * @hide
141 */
142 public static class PackageLite {
143 public String packageName;
144 public int installLocation;
145 public String mScanPath;
146 public PackageLite(String packageName, int installLocation) {
147 this.packageName = packageName;
148 this.installLocation = installLocation;
149 }
150 }
151
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700152 private ParsePackageItemArgs mParseInstrumentationArgs;
153 private ParseComponentArgs mParseActivityArgs;
154 private ParseComponentArgs mParseActivityAliasArgs;
155 private ParseComponentArgs mParseServiceArgs;
156 private ParseComponentArgs mParseProviderArgs;
157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 /** If set to true, we will only allow package files that exactly match
159 * the DTD. Otherwise, we try to get as much from the package as we
160 * can without failing. This should normally be set to false, to
161 * support extensions to the DTD in future versions. */
162 private static final boolean RIGID_PARSER = false;
163
164 private static final String TAG = "PackageParser";
165
166 public PackageParser(String archiveSourcePath) {
167 mArchiveSourcePath = archiveSourcePath;
168 }
169
170 public void setSeparateProcesses(String[] procs) {
171 mSeparateProcesses = procs;
172 }
173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 private static final boolean isPackageFilename(String name) {
175 return name.endsWith(".apk");
176 }
177
178 /**
179 * Generate and return the {@link PackageInfo} for a parsed package.
180 *
181 * @param p the parsed package.
182 * @param flags indicating which optional information is included.
183 */
184 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborn78d68832010-10-07 01:12:46 -0700185 int gids[], int flags, long firstInstallTime, long lastUpdateTime) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186
187 PackageInfo pi = new PackageInfo();
188 pi.packageName = p.packageName;
189 pi.versionCode = p.mVersionCode;
190 pi.versionName = p.mVersionName;
191 pi.sharedUserId = p.mSharedUserId;
192 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborne4a59512010-12-07 11:08:07 -0800193 pi.applicationInfo = generateApplicationInfo(p, flags);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800194 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700195 pi.firstInstallTime = firstInstallTime;
196 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 if ((flags&PackageManager.GET_GIDS) != 0) {
198 pi.gids = gids;
199 }
200 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
201 int N = p.configPreferences.size();
202 if (N > 0) {
203 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700204 p.configPreferences.toArray(pi.configPreferences);
205 }
206 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
207 if (N > 0) {
208 pi.reqFeatures = new FeatureInfo[N];
209 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 }
211 }
212 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
213 int N = p.activities.size();
214 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700215 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
216 pi.activities = new ActivityInfo[N];
217 } else {
218 int num = 0;
219 for (int i=0; i<N; i++) {
220 if (p.activities.get(i).info.enabled) num++;
221 }
222 pi.activities = new ActivityInfo[num];
223 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700224 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 final Activity activity = p.activities.get(i);
226 if (activity.info.enabled
227 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700228 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
230 }
231 }
232 }
233 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
234 int N = p.receivers.size();
235 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700236 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
237 pi.receivers = new ActivityInfo[N];
238 } else {
239 int num = 0;
240 for (int i=0; i<N; i++) {
241 if (p.receivers.get(i).info.enabled) num++;
242 }
243 pi.receivers = new ActivityInfo[num];
244 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700245 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 final Activity activity = p.receivers.get(i);
247 if (activity.info.enabled
248 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700249 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 }
251 }
252 }
253 }
254 if ((flags&PackageManager.GET_SERVICES) != 0) {
255 int N = p.services.size();
256 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700257 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
258 pi.services = new ServiceInfo[N];
259 } else {
260 int num = 0;
261 for (int i=0; i<N; i++) {
262 if (p.services.get(i).info.enabled) num++;
263 }
264 pi.services = new ServiceInfo[num];
265 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700266 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final Service service = p.services.get(i);
268 if (service.info.enabled
269 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700270 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272 }
273 }
274 }
275 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
276 int N = p.providers.size();
277 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700278 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
279 pi.providers = new ProviderInfo[N];
280 } else {
281 int num = 0;
282 for (int i=0; i<N; i++) {
283 if (p.providers.get(i).info.enabled) num++;
284 }
285 pi.providers = new ProviderInfo[num];
286 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700287 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 final Provider provider = p.providers.get(i);
289 if (provider.info.enabled
290 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700291 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 }
293 }
294 }
295 }
296 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
297 int N = p.instrumentation.size();
298 if (N > 0) {
299 pi.instrumentation = new InstrumentationInfo[N];
300 for (int i=0; i<N; i++) {
301 pi.instrumentation[i] = generateInstrumentationInfo(
302 p.instrumentation.get(i), flags);
303 }
304 }
305 }
306 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
307 int N = p.permissions.size();
308 if (N > 0) {
309 pi.permissions = new PermissionInfo[N];
310 for (int i=0; i<N; i++) {
311 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
312 }
313 }
314 N = p.requestedPermissions.size();
315 if (N > 0) {
316 pi.requestedPermissions = new String[N];
317 for (int i=0; i<N; i++) {
318 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
319 }
320 }
321 }
322 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700323 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
324 if (N > 0) {
325 pi.signatures = new Signature[N];
326 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 }
328 }
329 return pi;
330 }
331
332 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
333 byte[] readBuffer) {
334 try {
335 // We must read the stream for the JarEntry to retrieve
336 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700337 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
339 // not using
340 }
341 is.close();
342 return je != null ? je.getCertificates() : null;
343 } catch (IOException e) {
344 Log.w(TAG, "Exception reading " + je.getName() + " in "
345 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700346 } catch (RuntimeException e) {
347 Log.w(TAG, "Exception reading " + je.getName() + " in "
348 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 }
350 return null;
351 }
352
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800353 public final static int PARSE_IS_SYSTEM = 1<<0;
354 public final static int PARSE_CHATTY = 1<<1;
355 public final static int PARSE_MUST_BE_APK = 1<<2;
356 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
357 public final static int PARSE_FORWARD_LOCK = 1<<4;
358 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700359 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360
361 public int getParseError() {
362 return mParseError;
363 }
364
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800365 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 DisplayMetrics metrics, int flags) {
367 mParseError = PackageManager.INSTALL_SUCCEEDED;
368
369 mArchiveSourcePath = sourceFile.getPath();
370 if (!sourceFile.isFile()) {
371 Log.w(TAG, "Skipping dir: " + mArchiveSourcePath);
372 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
373 return null;
374 }
375 if (!isPackageFilename(sourceFile.getName())
376 && (flags&PARSE_MUST_BE_APK) != 0) {
377 if ((flags&PARSE_IS_SYSTEM) == 0) {
378 // We expect to have non-.apk files in the system dir,
379 // so don't warn about them.
380 Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
381 }
382 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
383 return null;
384 }
385
Joe Onorato43a17652011-04-06 19:22:23 -0700386 if ((flags&PARSE_CHATTY) != 0 && false) Log.d(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 TAG, "Scanning package: " + mArchiveSourcePath);
388
389 XmlResourceParser parser = null;
390 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800391 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 boolean assetError = true;
393 try {
394 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700395 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800396 if (cookie != 0) {
397 res = new Resources(assmgr, metrics, null);
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700398 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800399 Build.VERSION.RESOURCES_SDK_INT);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700400 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 assetError = false;
402 } else {
403 Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
404 }
405 } catch (Exception e) {
406 Log.w(TAG, "Unable to read AndroidManifest.xml of "
407 + mArchiveSourcePath, e);
408 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800409 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 if (assmgr != null) assmgr.close();
411 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
412 return null;
413 }
414 String[] errorText = new String[1];
415 Package pkg = null;
416 Exception errorException = null;
417 try {
418 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 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();
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700598 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800599 Build.VERSION.RESOURCES_SDK_INT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 int cookie = assmgr.addAssetPath(packageFilePath);
601 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
602 } catch (Exception e) {
603 if (assmgr != null) assmgr.close();
604 Log.w(TAG, "Unable to read AndroidManifest.xml of "
605 + packageFilePath, e);
606 return null;
607 }
608 AttributeSet attrs = parser;
609 String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800610 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 try {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800612 packageLite = parsePackageLite(parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 } catch (IOException e) {
614 Log.w(TAG, packageFilePath, e);
615 } catch (XmlPullParserException e) {
616 Log.w(TAG, packageFilePath, e);
617 } finally {
618 if (parser != null) parser.close();
619 if (assmgr != null) assmgr.close();
620 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800621 if (packageLite == null) {
622 Log.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 return null;
624 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800625 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 }
627
628 private static String validateName(String name, boolean requiresSeparator) {
629 final int N = name.length();
630 boolean hasSep = false;
631 boolean front = true;
632 for (int i=0; i<N; i++) {
633 final char c = name.charAt(i);
634 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
635 front = false;
636 continue;
637 }
638 if (!front) {
639 if ((c >= '0' && c <= '9') || c == '_') {
640 continue;
641 }
642 }
643 if (c == '.') {
644 hasSep = true;
645 front = true;
646 continue;
647 }
648 return "bad character '" + c + "'";
649 }
650 return hasSep || !requiresSeparator
651 ? null : "must have at least one '.' separator";
652 }
653
654 private static String parsePackageName(XmlPullParser parser,
655 AttributeSet attrs, int flags, String[] outError)
656 throws IOException, XmlPullParserException {
657
658 int type;
659 while ((type=parser.next()) != parser.START_TAG
660 && type != parser.END_DOCUMENT) {
661 ;
662 }
663
664 if (type != parser.START_TAG) {
665 outError[0] = "No start tag found";
666 return null;
667 }
Joe Onorato43a17652011-04-06 19:22:23 -0700668 if ((flags&PARSE_CHATTY) != 0 && false) Log.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 TAG, "Root element name: '" + parser.getName() + "'");
670 if (!parser.getName().equals("manifest")) {
671 outError[0] = "No <manifest> tag";
672 return null;
673 }
674 String pkgName = attrs.getAttributeValue(null, "package");
675 if (pkgName == null || pkgName.length() == 0) {
676 outError[0] = "<manifest> does not specify package";
677 return null;
678 }
679 String nameError = validateName(pkgName, true);
680 if (nameError != null && !"android".equals(pkgName)) {
681 outError[0] = "<manifest> specifies bad package name \""
682 + pkgName + "\": " + nameError;
683 return null;
684 }
685
686 return pkgName.intern();
687 }
688
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800689 private static PackageLite parsePackageLite(XmlPullParser parser,
690 AttributeSet attrs, int flags, String[] outError)
691 throws IOException, XmlPullParserException {
692
693 int type;
694 while ((type=parser.next()) != parser.START_TAG
695 && type != parser.END_DOCUMENT) {
696 ;
697 }
698
699 if (type != parser.START_TAG) {
700 outError[0] = "No start tag found";
701 return null;
702 }
Joe Onorato43a17652011-04-06 19:22:23 -0700703 if ((flags&PARSE_CHATTY) != 0 && false) Log.v(
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800704 TAG, "Root element name: '" + parser.getName() + "'");
705 if (!parser.getName().equals("manifest")) {
706 outError[0] = "No <manifest> tag";
707 return null;
708 }
709 String pkgName = attrs.getAttributeValue(null, "package");
710 if (pkgName == null || pkgName.length() == 0) {
711 outError[0] = "<manifest> does not specify package";
712 return null;
713 }
714 String nameError = validateName(pkgName, true);
715 if (nameError != null && !"android".equals(pkgName)) {
716 outError[0] = "<manifest> specifies bad package name \""
717 + pkgName + "\": " + nameError;
718 return null;
719 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700720 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800721 for (int i = 0; i < attrs.getAttributeCount(); i++) {
722 String attr = attrs.getAttributeName(i);
723 if (attr.equals("installLocation")) {
724 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700725 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800726 break;
727 }
728 }
729 return new PackageLite(pkgName.intern(), installLocation);
730 }
731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 /**
733 * Temporary.
734 */
735 static public Signature stringToSignature(String str) {
736 final int N = str.length();
737 byte[] sig = new byte[N];
738 for (int i=0; i<N; i++) {
739 sig[i] = (byte)str.charAt(i);
740 }
741 return new Signature(sig);
742 }
743
744 private Package parsePackage(
745 Resources res, XmlResourceParser parser, int flags, String[] outError)
746 throws XmlPullParserException, IOException {
747 AttributeSet attrs = parser;
748
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700749 mParseInstrumentationArgs = null;
750 mParseActivityArgs = null;
751 mParseServiceArgs = null;
752 mParseProviderArgs = null;
753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 String pkgName = parsePackageName(parser, attrs, flags, outError);
755 if (pkgName == null) {
756 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
757 return null;
758 }
759 int type;
760
761 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 TypedArray sa = res.obtainAttributes(attrs,
765 com.android.internal.R.styleable.AndroidManifest);
766 pkg.mVersionCode = sa.getInteger(
767 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800768 pkg.mVersionName = sa.getNonConfigurationString(
769 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 if (pkg.mVersionName != null) {
771 pkg.mVersionName = pkg.mVersionName.intern();
772 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800773 String str = sa.getNonConfigurationString(
774 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
775 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 String nameError = validateName(str, true);
777 if (nameError != null && !"android".equals(pkgName)) {
778 outError[0] = "<manifest> specifies bad sharedUserId name \""
779 + str + "\": " + nameError;
780 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
781 return null;
782 }
783 pkg.mSharedUserId = str.intern();
784 pkg.mSharedUserLabel = sa.getResourceId(
785 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
786 }
787 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800788
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800789 pkg.installLocation = sa.getInteger(
790 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700791 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700792 pkg.applicationInfo.installLocation = pkg.installLocation;
793
Dianne Hackborn723738c2009-06-25 19:48:04 -0700794 // Resource boolean are -1, so 1 means we don't know the value.
795 int supportsSmallScreens = 1;
796 int supportsNormalScreens = 1;
797 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700798 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700799 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700800 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 int outerDepth = parser.getDepth();
803 while ((type=parser.next()) != parser.END_DOCUMENT
804 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
805 if (type == parser.END_TAG || type == parser.TEXT) {
806 continue;
807 }
808
809 String tagName = parser.getName();
810 if (tagName.equals("application")) {
811 if (foundApp) {
812 if (RIGID_PARSER) {
813 outError[0] = "<manifest> has more than one <application>";
814 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
815 return null;
816 } else {
817 Log.w(TAG, "<manifest> has more than one <application>");
818 XmlUtils.skipCurrentTag(parser);
819 continue;
820 }
821 }
822
823 foundApp = true;
824 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
825 return null;
826 }
827 } else if (tagName.equals("permission-group")) {
828 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
829 return null;
830 }
831 } else if (tagName.equals("permission")) {
832 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
833 return null;
834 }
835 } else if (tagName.equals("permission-tree")) {
836 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
837 return null;
838 }
839 } else if (tagName.equals("uses-permission")) {
840 sa = res.obtainAttributes(attrs,
841 com.android.internal.R.styleable.AndroidManifestUsesPermission);
842
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800843 // Note: don't allow this value to be a reference to a resource
844 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 String name = sa.getNonResourceString(
846 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
847
848 sa.recycle();
849
850 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700851 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853
854 XmlUtils.skipCurrentTag(parser);
855
856 } else if (tagName.equals("uses-configuration")) {
857 ConfigurationInfo cPref = new ConfigurationInfo();
858 sa = res.obtainAttributes(attrs,
859 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
860 cPref.reqTouchScreen = sa.getInt(
861 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
862 Configuration.TOUCHSCREEN_UNDEFINED);
863 cPref.reqKeyboardType = sa.getInt(
864 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
865 Configuration.KEYBOARD_UNDEFINED);
866 if (sa.getBoolean(
867 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
868 false)) {
869 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
870 }
871 cPref.reqNavigation = sa.getInt(
872 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
873 Configuration.NAVIGATION_UNDEFINED);
874 if (sa.getBoolean(
875 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
876 false)) {
877 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
878 }
879 sa.recycle();
880 pkg.configPreferences.add(cPref);
881
882 XmlUtils.skipCurrentTag(parser);
883
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700884 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700885 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700886 sa = res.obtainAttributes(attrs,
887 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800888 // Note: don't allow this value to be a reference to a resource
889 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700890 fi.name = sa.getNonResourceString(
891 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
892 if (fi.name == null) {
893 fi.reqGlEsVersion = sa.getInt(
894 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
895 FeatureInfo.GL_ES_VERSION_UNDEFINED);
896 }
897 if (sa.getBoolean(
898 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
899 true)) {
900 fi.flags |= FeatureInfo.FLAG_REQUIRED;
901 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700902 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700903 if (pkg.reqFeatures == null) {
904 pkg.reqFeatures = new ArrayList<FeatureInfo>();
905 }
906 pkg.reqFeatures.add(fi);
907
908 if (fi.name == null) {
909 ConfigurationInfo cPref = new ConfigurationInfo();
910 cPref.reqGlEsVersion = fi.reqGlEsVersion;
911 pkg.configPreferences.add(cPref);
912 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700913
914 XmlUtils.skipCurrentTag(parser);
915
Dianne Hackborn851a5412009-05-08 12:06:44 -0700916 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700917 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 sa = res.obtainAttributes(attrs,
919 com.android.internal.R.styleable.AndroidManifestUsesSdk);
920
Dianne Hackborn851a5412009-05-08 12:06:44 -0700921 int minVers = 0;
922 String minCode = null;
923 int targetVers = 0;
924 String targetCode = null;
925
926 TypedValue val = sa.peekValue(
927 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
928 if (val != null) {
929 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
930 targetCode = minCode = val.string.toString();
931 } else {
932 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700933 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700934 }
935 }
936
937 val = sa.peekValue(
938 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
939 if (val != null) {
940 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
941 targetCode = minCode = val.string.toString();
942 } else {
943 // If it's not a string, it's an integer.
944 targetVers = val.data;
945 }
946 }
947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 sa.recycle();
949
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700950 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700951 if (!minCode.equals(SDK_CODENAME)) {
952 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700953 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700954 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700955 } else {
956 outError[0] = "Requires development platform " + minCode
957 + " but this is a release platform.";
958 }
959 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
960 return null;
961 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700962 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700963 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700964 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700965 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
966 return null;
967 }
968
Dianne Hackborn851a5412009-05-08 12:06:44 -0700969 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700970 if (!targetCode.equals(SDK_CODENAME)) {
971 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700972 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700973 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700974 } else {
975 outError[0] = "Requires development platform " + targetCode
976 + " but this is a release platform.";
977 }
978 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
979 return null;
980 }
981 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700982 pkg.applicationInfo.targetSdkVersion
983 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
984 } else {
985 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 }
988
989 XmlUtils.skipCurrentTag(parser);
990
Dianne Hackborn723738c2009-06-25 19:48:04 -0700991 } else if (tagName.equals("supports-screens")) {
992 sa = res.obtainAttributes(attrs,
993 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
994
995 // This is a trick to get a boolean and still able to detect
996 // if a value was actually set.
997 supportsSmallScreens = sa.getInteger(
998 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
999 supportsSmallScreens);
1000 supportsNormalScreens = sa.getInteger(
1001 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1002 supportsNormalScreens);
1003 supportsLargeScreens = sa.getInteger(
1004 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1005 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001006 supportsXLargeScreens = sa.getInteger(
1007 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1008 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001009 resizeable = sa.getInteger(
1010 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001011 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001012 anyDensity = sa.getInteger(
1013 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1014 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001015
1016 sa.recycle();
1017
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001018 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001019
1020 } else if (tagName.equals("protected-broadcast")) {
1021 sa = res.obtainAttributes(attrs,
1022 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1023
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001024 // Note: don't allow this value to be a reference to a resource
1025 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001026 String name = sa.getNonResourceString(
1027 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1028
1029 sa.recycle();
1030
1031 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1032 if (pkg.protectedBroadcasts == null) {
1033 pkg.protectedBroadcasts = new ArrayList<String>();
1034 }
1035 if (!pkg.protectedBroadcasts.contains(name)) {
1036 pkg.protectedBroadcasts.add(name.intern());
1037 }
1038 }
1039
1040 XmlUtils.skipCurrentTag(parser);
1041
1042 } else if (tagName.equals("instrumentation")) {
1043 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1044 return null;
1045 }
1046
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001047 } else if (tagName.equals("original-package")) {
1048 sa = res.obtainAttributes(attrs,
1049 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1050
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001051 String orig =sa.getNonConfigurationString(
1052 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001053 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001054 if (pkg.mOriginalPackages == null) {
1055 pkg.mOriginalPackages = new ArrayList<String>();
1056 pkg.mRealPackage = pkg.packageName;
1057 }
1058 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001059 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001060
1061 sa.recycle();
1062
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001063 XmlUtils.skipCurrentTag(parser);
1064
1065 } else if (tagName.equals("adopt-permissions")) {
1066 sa = res.obtainAttributes(attrs,
1067 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1068
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001069 String name = sa.getNonConfigurationString(
1070 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001071
1072 sa.recycle();
1073
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001074 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001075 if (pkg.mAdoptPermissions == null) {
1076 pkg.mAdoptPermissions = new ArrayList<String>();
1077 }
1078 pkg.mAdoptPermissions.add(name);
1079 }
1080
1081 XmlUtils.skipCurrentTag(parser);
1082
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001083 } else if (tagName.equals("uses-gl-texture")) {
1084 // Just skip this tag
1085 XmlUtils.skipCurrentTag(parser);
1086 continue;
1087
1088 } else if (tagName.equals("compatible-screens")) {
1089 // Just skip this tag
1090 XmlUtils.skipCurrentTag(parser);
1091 continue;
1092
Dianne Hackborn854060a2009-07-09 18:14:31 -07001093 } else if (tagName.equals("eat-comment")) {
1094 // Just skip this tag
1095 XmlUtils.skipCurrentTag(parser);
1096 continue;
1097
1098 } else if (RIGID_PARSER) {
1099 outError[0] = "Bad element under <manifest>: "
1100 + parser.getName();
1101 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1102 return null;
1103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 } else {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001105 Log.w(TAG, "Unknown element under <manifest>: " + parser.getName()
1106 + " at " + mArchiveSourcePath + " "
1107 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 XmlUtils.skipCurrentTag(parser);
1109 continue;
1110 }
1111 }
1112
1113 if (!foundApp && pkg.instrumentation.size() == 0) {
1114 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1115 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1116 }
1117
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001118 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001119 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001120 for (int ip=0; ip<NP; ip++) {
1121 final PackageParser.NewPermissionInfo npi
1122 = PackageParser.NEW_PERMISSIONS[ip];
1123 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1124 break;
1125 }
1126 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001127 if (implicitPerms == null) {
1128 implicitPerms = new StringBuilder(128);
1129 implicitPerms.append(pkg.packageName);
1130 implicitPerms.append(": compat added ");
1131 } else {
1132 implicitPerms.append(' ');
1133 }
1134 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001135 pkg.requestedPermissions.add(npi.name);
1136 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001137 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001138 if (implicitPerms != null) {
1139 Log.i(TAG, implicitPerms.toString());
1140 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001141
Dianne Hackborn723738c2009-06-25 19:48:04 -07001142 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1143 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001144 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001145 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1146 }
1147 if (supportsNormalScreens != 0) {
1148 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1149 }
1150 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1151 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001152 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001153 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1154 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001155 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1156 && pkg.applicationInfo.targetSdkVersion
1157 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1158 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1159 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001160 if (resizeable < 0 || (resizeable > 0
1161 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001162 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001163 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1164 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001165 if (anyDensity < 0 || (anyDensity > 0
1166 && pkg.applicationInfo.targetSdkVersion
1167 >= android.os.Build.VERSION_CODES.DONUT)) {
1168 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001169 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 return pkg;
1172 }
1173
1174 private static String buildClassName(String pkg, CharSequence clsSeq,
1175 String[] outError) {
1176 if (clsSeq == null || clsSeq.length() <= 0) {
1177 outError[0] = "Empty class name in package " + pkg;
1178 return null;
1179 }
1180 String cls = clsSeq.toString();
1181 char c = cls.charAt(0);
1182 if (c == '.') {
1183 return (pkg + cls).intern();
1184 }
1185 if (cls.indexOf('.') < 0) {
1186 StringBuilder b = new StringBuilder(pkg);
1187 b.append('.');
1188 b.append(cls);
1189 return b.toString().intern();
1190 }
1191 if (c >= 'a' && c <= 'z') {
1192 return cls.intern();
1193 }
1194 outError[0] = "Bad class name " + cls + " in package " + pkg;
1195 return null;
1196 }
1197
1198 private static String buildCompoundName(String pkg,
1199 CharSequence procSeq, String type, String[] outError) {
1200 String proc = procSeq.toString();
1201 char c = proc.charAt(0);
1202 if (pkg != null && c == ':') {
1203 if (proc.length() < 2) {
1204 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1205 + ": must be at least two characters";
1206 return null;
1207 }
1208 String subName = proc.substring(1);
1209 String nameError = validateName(subName, false);
1210 if (nameError != null) {
1211 outError[0] = "Invalid " + type + " name " + proc + " in package "
1212 + pkg + ": " + nameError;
1213 return null;
1214 }
1215 return (pkg + proc).intern();
1216 }
1217 String nameError = validateName(proc, true);
1218 if (nameError != null && !"system".equals(proc)) {
1219 outError[0] = "Invalid " + type + " name " + proc + " in package "
1220 + pkg + ": " + nameError;
1221 return null;
1222 }
1223 return proc.intern();
1224 }
1225
1226 private static String buildProcessName(String pkg, String defProc,
1227 CharSequence procSeq, int flags, String[] separateProcesses,
1228 String[] outError) {
1229 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1230 return defProc != null ? defProc : pkg;
1231 }
1232 if (separateProcesses != null) {
1233 for (int i=separateProcesses.length-1; i>=0; i--) {
1234 String sp = separateProcesses[i];
1235 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1236 return pkg;
1237 }
1238 }
1239 }
1240 if (procSeq == null || procSeq.length() <= 0) {
1241 return defProc;
1242 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001243 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 }
1245
1246 private static String buildTaskAffinityName(String pkg, String defProc,
1247 CharSequence procSeq, String[] outError) {
1248 if (procSeq == null) {
1249 return defProc;
1250 }
1251 if (procSeq.length() <= 0) {
1252 return null;
1253 }
1254 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1255 }
1256
1257 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1258 XmlPullParser parser, AttributeSet attrs, String[] outError)
1259 throws XmlPullParserException, IOException {
1260 PermissionGroup perm = new PermissionGroup(owner);
1261
1262 TypedArray sa = res.obtainAttributes(attrs,
1263 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1264
1265 if (!parsePackageItemInfo(owner, perm.info, outError,
1266 "<permission-group>", sa,
1267 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1268 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001269 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1270 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 sa.recycle();
1272 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1273 return null;
1274 }
1275
1276 perm.info.descriptionRes = sa.getResourceId(
1277 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1278 0);
1279
1280 sa.recycle();
1281
1282 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1283 outError)) {
1284 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1285 return null;
1286 }
1287
1288 owner.permissionGroups.add(perm);
1289
1290 return perm;
1291 }
1292
1293 private Permission parsePermission(Package owner, Resources res,
1294 XmlPullParser parser, AttributeSet attrs, String[] outError)
1295 throws XmlPullParserException, IOException {
1296 Permission perm = new Permission(owner);
1297
1298 TypedArray sa = res.obtainAttributes(attrs,
1299 com.android.internal.R.styleable.AndroidManifestPermission);
1300
1301 if (!parsePackageItemInfo(owner, perm.info, outError,
1302 "<permission>", sa,
1303 com.android.internal.R.styleable.AndroidManifestPermission_name,
1304 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001305 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1306 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 sa.recycle();
1308 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1309 return null;
1310 }
1311
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001312 // Note: don't allow this value to be a reference to a resource
1313 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 perm.info.group = sa.getNonResourceString(
1315 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1316 if (perm.info.group != null) {
1317 perm.info.group = perm.info.group.intern();
1318 }
1319
1320 perm.info.descriptionRes = sa.getResourceId(
1321 com.android.internal.R.styleable.AndroidManifestPermission_description,
1322 0);
1323
1324 perm.info.protectionLevel = sa.getInt(
1325 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1326 PermissionInfo.PROTECTION_NORMAL);
1327
1328 sa.recycle();
1329
1330 if (perm.info.protectionLevel == -1) {
1331 outError[0] = "<permission> does not specify protectionLevel";
1332 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1333 return null;
1334 }
1335
1336 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1337 outError)) {
1338 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1339 return null;
1340 }
1341
1342 owner.permissions.add(perm);
1343
1344 return perm;
1345 }
1346
1347 private Permission parsePermissionTree(Package owner, Resources res,
1348 XmlPullParser parser, AttributeSet attrs, String[] outError)
1349 throws XmlPullParserException, IOException {
1350 Permission perm = new Permission(owner);
1351
1352 TypedArray sa = res.obtainAttributes(attrs,
1353 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1354
1355 if (!parsePackageItemInfo(owner, perm.info, outError,
1356 "<permission-tree>", sa,
1357 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1358 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001359 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1360 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 sa.recycle();
1362 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1363 return null;
1364 }
1365
1366 sa.recycle();
1367
1368 int index = perm.info.name.indexOf('.');
1369 if (index > 0) {
1370 index = perm.info.name.indexOf('.', index+1);
1371 }
1372 if (index < 0) {
1373 outError[0] = "<permission-tree> name has less than three segments: "
1374 + perm.info.name;
1375 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1376 return null;
1377 }
1378
1379 perm.info.descriptionRes = 0;
1380 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1381 perm.tree = true;
1382
1383 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1384 outError)) {
1385 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1386 return null;
1387 }
1388
1389 owner.permissions.add(perm);
1390
1391 return perm;
1392 }
1393
1394 private Instrumentation parseInstrumentation(Package owner, Resources res,
1395 XmlPullParser parser, AttributeSet attrs, String[] outError)
1396 throws XmlPullParserException, IOException {
1397 TypedArray sa = res.obtainAttributes(attrs,
1398 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1399
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001400 if (mParseInstrumentationArgs == null) {
1401 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1402 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1403 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001404 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1405 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001406 mParseInstrumentationArgs.tag = "<instrumentation>";
1407 }
1408
1409 mParseInstrumentationArgs.sa = sa;
1410
1411 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1412 new InstrumentationInfo());
1413 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 sa.recycle();
1415 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1416 return null;
1417 }
1418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001420 // Note: don't allow this value to be a reference to a resource
1421 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 str = sa.getNonResourceString(
1423 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1424 a.info.targetPackage = str != null ? str.intern() : null;
1425
1426 a.info.handleProfiling = sa.getBoolean(
1427 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1428 false);
1429
1430 a.info.functionalTest = sa.getBoolean(
1431 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1432 false);
1433
1434 sa.recycle();
1435
1436 if (a.info.targetPackage == null) {
1437 outError[0] = "<instrumentation> does not specify targetPackage";
1438 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1439 return null;
1440 }
1441
1442 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1443 outError)) {
1444 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1445 return null;
1446 }
1447
1448 owner.instrumentation.add(a);
1449
1450 return a;
1451 }
1452
1453 private boolean parseApplication(Package owner, Resources res,
1454 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1455 throws XmlPullParserException, IOException {
1456 final ApplicationInfo ai = owner.applicationInfo;
1457 final String pkgName = owner.applicationInfo.packageName;
1458
1459 TypedArray sa = res.obtainAttributes(attrs,
1460 com.android.internal.R.styleable.AndroidManifestApplication);
1461
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001462 String name = sa.getNonConfigurationString(
1463 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 if (name != null) {
1465 ai.className = buildClassName(pkgName, name, outError);
1466 if (ai.className == null) {
1467 sa.recycle();
1468 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1469 return false;
1470 }
1471 }
1472
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001473 String manageSpaceActivity = sa.getNonConfigurationString(
1474 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 if (manageSpaceActivity != null) {
1476 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1477 outError);
1478 }
1479
Christopher Tate181fafa2009-05-14 11:12:14 -07001480 boolean allowBackup = sa.getBoolean(
1481 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1482 if (allowBackup) {
1483 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001484
Christopher Tate3de55bc2010-03-12 17:28:08 -08001485 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1486 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001487 String backupAgent = sa.getNonConfigurationString(
1488 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001489 if (backupAgent != null) {
1490 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001491 if (false) {
1492 Log.v(TAG, "android:backupAgent = " + ai.backupAgentName
1493 + " from " + pkgName + "+" + backupAgent);
1494 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001495
1496 if (sa.getBoolean(
1497 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1498 true)) {
1499 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1500 }
1501 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001502 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1503 false)) {
1504 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1505 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001506 }
1507 }
1508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 TypedValue v = sa.peekValue(
1510 com.android.internal.R.styleable.AndroidManifestApplication_label);
1511 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1512 ai.nonLocalizedLabel = v.coerceToString();
1513 }
1514
1515 ai.icon = sa.getResourceId(
1516 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001517 ai.logo = sa.getResourceId(
1518 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001520 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 ai.descriptionRes = sa.getResourceId(
1522 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1523
1524 if ((flags&PARSE_IS_SYSTEM) != 0) {
1525 if (sa.getBoolean(
1526 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1527 false)) {
1528 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1529 }
1530 }
1531
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001532 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1533 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1534 }
1535
1536 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001537 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001538 }
1539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 if (sa.getBoolean(
1541 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1542 false)) {
1543 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1544 }
1545
1546 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001547 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001548 false)) {
1549 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1550 }
1551
Romain Guy529b60a2010-08-03 18:05:47 -07001552 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001553 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Romain Guy529b60a2010-08-03 18:05:47 -07001554 false);
Romain Guy812ccbe2010-06-01 14:07:24 -07001555
1556 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1558 true)) {
1559 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1560 }
1561
1562 if (sa.getBoolean(
1563 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1564 false)) {
1565 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1566 }
1567
1568 if (sa.getBoolean(
1569 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1570 true)) {
1571 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1572 }
1573
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001574 if (sa.getBoolean(
1575 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001576 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001577 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1578 }
1579
Jason parksa3cdaa52011-01-13 14:15:43 -06001580 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001581 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001582 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001583 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001584 }
1585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001587 str = sa.getNonConfigurationString(
1588 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1590
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001591 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1592 str = sa.getNonConfigurationString(
1593 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1594 } else {
1595 // Some older apps have been seen to use a resource reference
1596 // here that on older builds was ignored (with a warning). We
1597 // need to continue to do this for them so they don't break.
1598 str = sa.getNonResourceString(
1599 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1602 str, outError);
1603
1604 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001605 CharSequence pname;
1606 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1607 pname = sa.getNonConfigurationString(
1608 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1609 } else {
1610 // Some older apps have been seen to use a resource reference
1611 // here that on older builds was ignored (with a warning). We
1612 // need to continue to do this for them so they don't break.
1613 pname = sa.getNonResourceString(
1614 com.android.internal.R.styleable.AndroidManifestApplication_process);
1615 }
1616 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 flags, mSeparateProcesses, outError);
1618
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001619 ai.enabled = sa.getBoolean(
1620 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001621
Dianne Hackborn02486b12010-08-26 14:18:37 -07001622 if (false) {
1623 if (sa.getBoolean(
1624 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1625 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001626 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001627
1628 // A heavy-weight application can not be in a custom process.
1629 // We can do direct compare because we intern all strings.
1630 if (ai.processName != null && ai.processName != ai.packageName) {
1631 outError[0] = "cantSaveState applications can not use custom processes";
1632 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001633 }
1634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 }
1636
1637 sa.recycle();
1638
1639 if (outError[0] != null) {
1640 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1641 return false;
1642 }
1643
1644 final int innerDepth = parser.getDepth();
1645
1646 int type;
1647 while ((type=parser.next()) != parser.END_DOCUMENT
1648 && (type != parser.END_TAG || parser.getDepth() > innerDepth)) {
1649 if (type == parser.END_TAG || type == parser.TEXT) {
1650 continue;
1651 }
1652
1653 String tagName = parser.getName();
1654 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001655 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1656 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657 if (a == null) {
1658 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1659 return false;
1660 }
1661
1662 owner.activities.add(a);
1663
1664 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001665 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 if (a == null) {
1667 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1668 return false;
1669 }
1670
1671 owner.receivers.add(a);
1672
1673 } else if (tagName.equals("service")) {
1674 Service s = parseService(owner, res, parser, attrs, flags, outError);
1675 if (s == null) {
1676 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1677 return false;
1678 }
1679
1680 owner.services.add(s);
1681
1682 } else if (tagName.equals("provider")) {
1683 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1684 if (p == null) {
1685 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1686 return false;
1687 }
1688
1689 owner.providers.add(p);
1690
1691 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001692 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 if (a == null) {
1694 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1695 return false;
1696 }
1697
1698 owner.activities.add(a);
1699
1700 } else if (parser.getName().equals("meta-data")) {
1701 // note: application meta-data is stored off to the side, so it can
1702 // remain null in the primary copy (we like to avoid extra copies because
1703 // it can be large)
1704 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1705 outError)) == null) {
1706 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1707 return false;
1708 }
1709
1710 } else if (tagName.equals("uses-library")) {
1711 sa = res.obtainAttributes(attrs,
1712 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1713
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001714 // Note: don't allow this value to be a reference to a resource
1715 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 String lname = sa.getNonResourceString(
1717 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001718 boolean req = sa.getBoolean(
1719 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1720 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721
1722 sa.recycle();
1723
Dianne Hackborn49237342009-08-27 20:08:01 -07001724 if (lname != null) {
1725 if (req) {
1726 if (owner.usesLibraries == null) {
1727 owner.usesLibraries = new ArrayList<String>();
1728 }
1729 if (!owner.usesLibraries.contains(lname)) {
1730 owner.usesLibraries.add(lname.intern());
1731 }
1732 } else {
1733 if (owner.usesOptionalLibraries == null) {
1734 owner.usesOptionalLibraries = new ArrayList<String>();
1735 }
1736 if (!owner.usesOptionalLibraries.contains(lname)) {
1737 owner.usesOptionalLibraries.add(lname.intern());
1738 }
1739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 }
1741
1742 XmlUtils.skipCurrentTag(parser);
1743
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001744 } else if (tagName.equals("uses-package")) {
1745 // Dependencies for app installers; we don't currently try to
1746 // enforce this.
1747 XmlUtils.skipCurrentTag(parser);
1748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 } else {
1750 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001751 Log.w(TAG, "Unknown element under <application>: " + tagName
1752 + " at " + mArchiveSourcePath + " "
1753 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 XmlUtils.skipCurrentTag(parser);
1755 continue;
1756 } else {
1757 outError[0] = "Bad element under <application>: " + tagName;
1758 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1759 return false;
1760 }
1761 }
1762 }
1763
1764 return true;
1765 }
1766
1767 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1768 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001769 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001770 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 if (name == null) {
1772 outError[0] = tag + " does not specify android:name";
1773 return false;
1774 }
1775
1776 outInfo.name
1777 = buildClassName(owner.applicationInfo.packageName, name, outError);
1778 if (outInfo.name == null) {
1779 return false;
1780 }
1781
1782 int iconVal = sa.getResourceId(iconRes, 0);
1783 if (iconVal != 0) {
1784 outInfo.icon = iconVal;
1785 outInfo.nonLocalizedLabel = null;
1786 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001787
1788 int logoVal = sa.getResourceId(logoRes, 0);
1789 if (logoVal != 0) {
1790 outInfo.logo = logoVal;
1791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792
1793 TypedValue v = sa.peekValue(labelRes);
1794 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1795 outInfo.nonLocalizedLabel = v.coerceToString();
1796 }
1797
1798 outInfo.packageName = owner.packageName;
1799
1800 return true;
1801 }
1802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 private Activity parseActivity(Package owner, Resources res,
1804 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07001805 boolean receiver, boolean hardwareAccelerated)
1806 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 TypedArray sa = res.obtainAttributes(attrs,
1808 com.android.internal.R.styleable.AndroidManifestActivity);
1809
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001810 if (mParseActivityArgs == null) {
1811 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1812 com.android.internal.R.styleable.AndroidManifestActivity_name,
1813 com.android.internal.R.styleable.AndroidManifestActivity_label,
1814 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001815 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001816 mSeparateProcesses,
1817 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001818 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001819 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1820 }
1821
1822 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1823 mParseActivityArgs.sa = sa;
1824 mParseActivityArgs.flags = flags;
1825
1826 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1827 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 sa.recycle();
1829 return null;
1830 }
1831
1832 final boolean setExported = sa.hasValue(
1833 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1834 if (setExported) {
1835 a.info.exported = sa.getBoolean(
1836 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1837 }
1838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 a.info.theme = sa.getResourceId(
1840 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1841
1842 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001843 str = sa.getNonConfigurationString(
1844 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 if (str == null) {
1846 a.info.permission = owner.applicationInfo.permission;
1847 } else {
1848 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1849 }
1850
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001851 str = sa.getNonConfigurationString(
1852 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1854 owner.applicationInfo.taskAffinity, str, outError);
1855
1856 a.info.flags = 0;
1857 if (sa.getBoolean(
1858 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1859 false)) {
1860 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1861 }
1862
1863 if (sa.getBoolean(
1864 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1865 false)) {
1866 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1867 }
1868
1869 if (sa.getBoolean(
1870 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1871 false)) {
1872 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1873 }
1874
1875 if (sa.getBoolean(
1876 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1877 false)) {
1878 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1879 }
1880
1881 if (sa.getBoolean(
1882 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1883 false)) {
1884 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1885 }
1886
1887 if (sa.getBoolean(
1888 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1889 false)) {
1890 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1891 }
1892
1893 if (sa.getBoolean(
1894 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1895 false)) {
1896 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1897 }
1898
1899 if (sa.getBoolean(
1900 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1901 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1902 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1903 }
1904
Dianne Hackbornffa42482009-09-23 22:20:11 -07001905 if (sa.getBoolean(
1906 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1907 false)) {
1908 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1909 }
1910
Daniel Sandler613dde42010-06-21 13:46:39 -04001911 if (sa.getBoolean(
1912 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
1913 false)) {
1914 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
1915 }
Romain Guy529b60a2010-08-03 18:05:47 -07001916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07001918 if (sa.getBoolean(
1919 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
1920 hardwareAccelerated)) {
1921 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
1922 }
1923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 a.info.launchMode = sa.getInt(
1925 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1926 ActivityInfo.LAUNCH_MULTIPLE);
1927 a.info.screenOrientation = sa.getInt(
1928 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1929 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1930 a.info.configChanges = sa.getInt(
1931 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1932 0);
Dianne Hackborn3fc982f2011-03-30 16:20:26 -07001933 if (owner.applicationInfo.targetSdkVersion
1934 < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
1935 a.info.configChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
1936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 a.info.softInputMode = sa.getInt(
1938 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1939 0);
1940 } else {
1941 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1942 a.info.configChanges = 0;
1943 }
1944
1945 sa.recycle();
1946
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001947 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001948 // A heavy-weight application can not have receives in its main process
1949 // We can do direct compare because we intern all strings.
1950 if (a.info.processName == owner.packageName) {
1951 outError[0] = "Heavy-weight applications can not have receivers in main process";
1952 }
1953 }
1954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 if (outError[0] != null) {
1956 return null;
1957 }
1958
1959 int outerDepth = parser.getDepth();
1960 int type;
1961 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1962 && (type != XmlPullParser.END_TAG
1963 || parser.getDepth() > outerDepth)) {
1964 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1965 continue;
1966 }
1967
1968 if (parser.getName().equals("intent-filter")) {
1969 ActivityIntentInfo intent = new ActivityIntentInfo(a);
1970 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
1971 return null;
1972 }
1973 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001974 Log.w(TAG, "No actions in intent filter at "
1975 + mArchiveSourcePath + " "
1976 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 } else {
1978 a.intents.add(intent);
1979 }
1980 } else if (parser.getName().equals("meta-data")) {
1981 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
1982 outError)) == null) {
1983 return null;
1984 }
1985 } else {
1986 if (!RIGID_PARSER) {
1987 Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
1988 if (receiver) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001989 Log.w(TAG, "Unknown element under <receiver>: " + parser.getName()
1990 + " at " + mArchiveSourcePath + " "
1991 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 } else {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001993 Log.w(TAG, "Unknown element under <activity>: " + parser.getName()
1994 + " at " + mArchiveSourcePath + " "
1995 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 }
1997 XmlUtils.skipCurrentTag(parser);
1998 continue;
1999 }
2000 if (receiver) {
2001 outError[0] = "Bad element under <receiver>: " + parser.getName();
2002 } else {
2003 outError[0] = "Bad element under <activity>: " + parser.getName();
2004 }
2005 return null;
2006 }
2007 }
2008
2009 if (!setExported) {
2010 a.info.exported = a.intents.size() > 0;
2011 }
2012
2013 return a;
2014 }
2015
2016 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002017 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2018 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 TypedArray sa = res.obtainAttributes(attrs,
2020 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2021
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002022 String targetActivity = sa.getNonConfigurationString(
2023 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 if (targetActivity == null) {
2025 outError[0] = "<activity-alias> does not specify android:targetActivity";
2026 sa.recycle();
2027 return null;
2028 }
2029
2030 targetActivity = buildClassName(owner.applicationInfo.packageName,
2031 targetActivity, outError);
2032 if (targetActivity == null) {
2033 sa.recycle();
2034 return null;
2035 }
2036
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002037 if (mParseActivityAliasArgs == null) {
2038 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2039 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2040 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2041 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002042 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002043 mSeparateProcesses,
2044 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002045 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002046 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2047 mParseActivityAliasArgs.tag = "<activity-alias>";
2048 }
2049
2050 mParseActivityAliasArgs.sa = sa;
2051 mParseActivityAliasArgs.flags = flags;
2052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 Activity target = null;
2054
2055 final int NA = owner.activities.size();
2056 for (int i=0; i<NA; i++) {
2057 Activity t = owner.activities.get(i);
2058 if (targetActivity.equals(t.info.name)) {
2059 target = t;
2060 break;
2061 }
2062 }
2063
2064 if (target == null) {
2065 outError[0] = "<activity-alias> target activity " + targetActivity
2066 + " not found in manifest";
2067 sa.recycle();
2068 return null;
2069 }
2070
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002071 ActivityInfo info = new ActivityInfo();
2072 info.targetActivity = targetActivity;
2073 info.configChanges = target.info.configChanges;
2074 info.flags = target.info.flags;
2075 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002076 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002077 info.labelRes = target.info.labelRes;
2078 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2079 info.launchMode = target.info.launchMode;
2080 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002081 if (info.descriptionRes == 0) {
2082 info.descriptionRes = target.info.descriptionRes;
2083 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002084 info.screenOrientation = target.info.screenOrientation;
2085 info.taskAffinity = target.info.taskAffinity;
2086 info.theme = target.info.theme;
2087
2088 Activity a = new Activity(mParseActivityAliasArgs, info);
2089 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 sa.recycle();
2091 return null;
2092 }
2093
2094 final boolean setExported = sa.hasValue(
2095 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2096 if (setExported) {
2097 a.info.exported = sa.getBoolean(
2098 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2099 }
2100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002102 str = sa.getNonConfigurationString(
2103 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 if (str != null) {
2105 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2106 }
2107
2108 sa.recycle();
2109
2110 if (outError[0] != null) {
2111 return null;
2112 }
2113
2114 int outerDepth = parser.getDepth();
2115 int type;
2116 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2117 && (type != XmlPullParser.END_TAG
2118 || parser.getDepth() > outerDepth)) {
2119 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2120 continue;
2121 }
2122
2123 if (parser.getName().equals("intent-filter")) {
2124 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2125 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2126 return null;
2127 }
2128 if (intent.countActions() == 0) {
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002129 Log.w(TAG, "No actions in intent filter at "
2130 + mArchiveSourcePath + " "
2131 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 } else {
2133 a.intents.add(intent);
2134 }
2135 } else if (parser.getName().equals("meta-data")) {
2136 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2137 outError)) == null) {
2138 return null;
2139 }
2140 } else {
2141 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002142 Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
2143 + " at " + mArchiveSourcePath + " "
2144 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 XmlUtils.skipCurrentTag(parser);
2146 continue;
2147 }
2148 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2149 return null;
2150 }
2151 }
2152
2153 if (!setExported) {
2154 a.info.exported = a.intents.size() > 0;
2155 }
2156
2157 return a;
2158 }
2159
2160 private Provider parseProvider(Package owner, Resources res,
2161 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2162 throws XmlPullParserException, IOException {
2163 TypedArray sa = res.obtainAttributes(attrs,
2164 com.android.internal.R.styleable.AndroidManifestProvider);
2165
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002166 if (mParseProviderArgs == null) {
2167 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2168 com.android.internal.R.styleable.AndroidManifestProvider_name,
2169 com.android.internal.R.styleable.AndroidManifestProvider_label,
2170 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002171 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002172 mSeparateProcesses,
2173 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002174 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002175 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2176 mParseProviderArgs.tag = "<provider>";
2177 }
2178
2179 mParseProviderArgs.sa = sa;
2180 mParseProviderArgs.flags = flags;
2181
2182 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2183 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 sa.recycle();
2185 return null;
2186 }
2187
2188 p.info.exported = sa.getBoolean(
2189 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2190
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002191 String cpname = sa.getNonConfigurationString(
2192 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193
2194 p.info.isSyncable = sa.getBoolean(
2195 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2196 false);
2197
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002198 String permission = sa.getNonConfigurationString(
2199 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2200 String str = sa.getNonConfigurationString(
2201 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (str == null) {
2203 str = permission;
2204 }
2205 if (str == null) {
2206 p.info.readPermission = owner.applicationInfo.permission;
2207 } else {
2208 p.info.readPermission =
2209 str.length() > 0 ? str.toString().intern() : null;
2210 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002211 str = sa.getNonConfigurationString(
2212 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 if (str == null) {
2214 str = permission;
2215 }
2216 if (str == null) {
2217 p.info.writePermission = owner.applicationInfo.permission;
2218 } else {
2219 p.info.writePermission =
2220 str.length() > 0 ? str.toString().intern() : null;
2221 }
2222
2223 p.info.grantUriPermissions = sa.getBoolean(
2224 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2225 false);
2226
2227 p.info.multiprocess = sa.getBoolean(
2228 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2229 false);
2230
2231 p.info.initOrder = sa.getInt(
2232 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2233 0);
2234
2235 sa.recycle();
2236
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002237 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002238 // A heavy-weight application can not have providers in its main process
2239 // We can do direct compare because we intern all strings.
2240 if (p.info.processName == owner.packageName) {
2241 outError[0] = "Heavy-weight applications can not have providers in main process";
2242 return null;
2243 }
2244 }
2245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 if (cpname == null) {
2247 outError[0] = "<provider> does not incude authorities attribute";
2248 return null;
2249 }
2250 p.info.authority = cpname.intern();
2251
2252 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2253 return null;
2254 }
2255
2256 return p;
2257 }
2258
2259 private boolean parseProviderTags(Resources res,
2260 XmlPullParser parser, AttributeSet attrs,
2261 Provider outInfo, String[] outError)
2262 throws XmlPullParserException, IOException {
2263 int outerDepth = parser.getDepth();
2264 int type;
2265 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2266 && (type != XmlPullParser.END_TAG
2267 || parser.getDepth() > outerDepth)) {
2268 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2269 continue;
2270 }
2271
2272 if (parser.getName().equals("meta-data")) {
2273 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2274 outInfo.metaData, outError)) == null) {
2275 return false;
2276 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 } else if (parser.getName().equals("grant-uri-permission")) {
2279 TypedArray sa = res.obtainAttributes(attrs,
2280 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2281
2282 PatternMatcher pa = null;
2283
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002284 String str = sa.getNonConfigurationString(
2285 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 if (str != null) {
2287 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2288 }
2289
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002290 str = sa.getNonConfigurationString(
2291 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 if (str != null) {
2293 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2294 }
2295
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002296 str = sa.getNonConfigurationString(
2297 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 if (str != null) {
2299 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2300 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 sa.recycle();
2303
2304 if (pa != null) {
2305 if (outInfo.info.uriPermissionPatterns == null) {
2306 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2307 outInfo.info.uriPermissionPatterns[0] = pa;
2308 } else {
2309 final int N = outInfo.info.uriPermissionPatterns.length;
2310 PatternMatcher[] newp = new PatternMatcher[N+1];
2311 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2312 newp[N] = pa;
2313 outInfo.info.uriPermissionPatterns = newp;
2314 }
2315 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002316 } else {
2317 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002318 Log.w(TAG, "Unknown element under <path-permission>: "
2319 + parser.getName() + " at " + mArchiveSourcePath + " "
2320 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002321 XmlUtils.skipCurrentTag(parser);
2322 continue;
2323 }
2324 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2325 return false;
2326 }
2327 XmlUtils.skipCurrentTag(parser);
2328
2329 } else if (parser.getName().equals("path-permission")) {
2330 TypedArray sa = res.obtainAttributes(attrs,
2331 com.android.internal.R.styleable.AndroidManifestPathPermission);
2332
2333 PathPermission pa = null;
2334
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002335 String permission = sa.getNonConfigurationString(
2336 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2337 String readPermission = sa.getNonConfigurationString(
2338 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002339 if (readPermission == null) {
2340 readPermission = permission;
2341 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002342 String writePermission = sa.getNonConfigurationString(
2343 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002344 if (writePermission == null) {
2345 writePermission = permission;
2346 }
2347
2348 boolean havePerm = false;
2349 if (readPermission != null) {
2350 readPermission = readPermission.intern();
2351 havePerm = true;
2352 }
2353 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002354 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002355 havePerm = true;
2356 }
2357
2358 if (!havePerm) {
2359 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002360 Log.w(TAG, "No readPermission or writePermssion for <path-permission>: "
2361 + parser.getName() + " at " + mArchiveSourcePath + " "
2362 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002363 XmlUtils.skipCurrentTag(parser);
2364 continue;
2365 }
2366 outError[0] = "No readPermission or writePermssion for <path-permission>";
2367 return false;
2368 }
2369
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002370 String path = sa.getNonConfigurationString(
2371 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002372 if (path != null) {
2373 pa = new PathPermission(path,
2374 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2375 }
2376
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002377 path = sa.getNonConfigurationString(
2378 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002379 if (path != null) {
2380 pa = new PathPermission(path,
2381 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2382 }
2383
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002384 path = sa.getNonConfigurationString(
2385 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002386 if (path != null) {
2387 pa = new PathPermission(path,
2388 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2389 }
2390
2391 sa.recycle();
2392
2393 if (pa != null) {
2394 if (outInfo.info.pathPermissions == null) {
2395 outInfo.info.pathPermissions = new PathPermission[1];
2396 outInfo.info.pathPermissions[0] = pa;
2397 } else {
2398 final int N = outInfo.info.pathPermissions.length;
2399 PathPermission[] newp = new PathPermission[N+1];
2400 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2401 newp[N] = pa;
2402 outInfo.info.pathPermissions = newp;
2403 }
2404 } else {
2405 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002406 Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
2407 + parser.getName() + " at " + mArchiveSourcePath + " "
2408 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002409 XmlUtils.skipCurrentTag(parser);
2410 continue;
2411 }
2412 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2413 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 }
2415 XmlUtils.skipCurrentTag(parser);
2416
2417 } else {
2418 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 Log.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002420 + parser.getName() + " at " + mArchiveSourcePath + " "
2421 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 XmlUtils.skipCurrentTag(parser);
2423 continue;
2424 }
2425 outError[0] = "Bad element under <provider>: "
2426 + parser.getName();
2427 return false;
2428 }
2429 }
2430 return true;
2431 }
2432
2433 private Service parseService(Package owner, Resources res,
2434 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2435 throws XmlPullParserException, IOException {
2436 TypedArray sa = res.obtainAttributes(attrs,
2437 com.android.internal.R.styleable.AndroidManifestService);
2438
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002439 if (mParseServiceArgs == null) {
2440 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2441 com.android.internal.R.styleable.AndroidManifestService_name,
2442 com.android.internal.R.styleable.AndroidManifestService_label,
2443 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002444 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002445 mSeparateProcesses,
2446 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002447 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002448 com.android.internal.R.styleable.AndroidManifestService_enabled);
2449 mParseServiceArgs.tag = "<service>";
2450 }
2451
2452 mParseServiceArgs.sa = sa;
2453 mParseServiceArgs.flags = flags;
2454
2455 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2456 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 sa.recycle();
2458 return null;
2459 }
2460
2461 final boolean setExported = sa.hasValue(
2462 com.android.internal.R.styleable.AndroidManifestService_exported);
2463 if (setExported) {
2464 s.info.exported = sa.getBoolean(
2465 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2466 }
2467
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002468 String str = sa.getNonConfigurationString(
2469 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 if (str == null) {
2471 s.info.permission = owner.applicationInfo.permission;
2472 } else {
2473 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2474 }
2475
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002476 s.info.flags = 0;
2477 if (sa.getBoolean(
2478 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2479 false)) {
2480 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2481 }
2482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 sa.recycle();
2484
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002485 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002486 // A heavy-weight application can not have services in its main process
2487 // We can do direct compare because we intern all strings.
2488 if (s.info.processName == owner.packageName) {
2489 outError[0] = "Heavy-weight applications can not have services in main process";
2490 return null;
2491 }
2492 }
2493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 int outerDepth = parser.getDepth();
2495 int type;
2496 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2497 && (type != XmlPullParser.END_TAG
2498 || parser.getDepth() > outerDepth)) {
2499 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2500 continue;
2501 }
2502
2503 if (parser.getName().equals("intent-filter")) {
2504 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2505 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2506 return null;
2507 }
2508
2509 s.intents.add(intent);
2510 } else if (parser.getName().equals("meta-data")) {
2511 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2512 outError)) == null) {
2513 return null;
2514 }
2515 } else {
2516 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 Log.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002518 + parser.getName() + " at " + mArchiveSourcePath + " "
2519 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 XmlUtils.skipCurrentTag(parser);
2521 continue;
2522 }
2523 outError[0] = "Bad element under <service>: "
2524 + parser.getName();
2525 return null;
2526 }
2527 }
2528
2529 if (!setExported) {
2530 s.info.exported = s.intents.size() > 0;
2531 }
2532
2533 return s;
2534 }
2535
2536 private boolean parseAllMetaData(Resources res,
2537 XmlPullParser parser, AttributeSet attrs, String tag,
2538 Component outInfo, String[] outError)
2539 throws XmlPullParserException, IOException {
2540 int outerDepth = parser.getDepth();
2541 int type;
2542 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2543 && (type != XmlPullParser.END_TAG
2544 || parser.getDepth() > outerDepth)) {
2545 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2546 continue;
2547 }
2548
2549 if (parser.getName().equals("meta-data")) {
2550 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2551 outInfo.metaData, outError)) == null) {
2552 return false;
2553 }
2554 } else {
2555 if (!RIGID_PARSER) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 Log.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002557 + parser.getName() + " at " + mArchiveSourcePath + " "
2558 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 XmlUtils.skipCurrentTag(parser);
2560 continue;
2561 }
2562 outError[0] = "Bad element under " + tag + ": "
2563 + parser.getName();
2564 return false;
2565 }
2566 }
2567 return true;
2568 }
2569
2570 private Bundle parseMetaData(Resources res,
2571 XmlPullParser parser, AttributeSet attrs,
2572 Bundle data, String[] outError)
2573 throws XmlPullParserException, IOException {
2574
2575 TypedArray sa = res.obtainAttributes(attrs,
2576 com.android.internal.R.styleable.AndroidManifestMetaData);
2577
2578 if (data == null) {
2579 data = new Bundle();
2580 }
2581
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002582 String name = sa.getNonConfigurationString(
2583 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 if (name == null) {
2585 outError[0] = "<meta-data> requires an android:name attribute";
2586 sa.recycle();
2587 return null;
2588 }
2589
Dianne Hackborn854060a2009-07-09 18:14:31 -07002590 name = name.intern();
2591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 TypedValue v = sa.peekValue(
2593 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2594 if (v != null && v.resourceId != 0) {
2595 //Log.i(TAG, "Meta data ref " + name + ": " + v);
2596 data.putInt(name, v.resourceId);
2597 } else {
2598 v = sa.peekValue(
2599 com.android.internal.R.styleable.AndroidManifestMetaData_value);
2600 //Log.i(TAG, "Meta data " + name + ": " + v);
2601 if (v != null) {
2602 if (v.type == TypedValue.TYPE_STRING) {
2603 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002604 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2606 data.putBoolean(name, v.data != 0);
2607 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2608 && v.type <= TypedValue.TYPE_LAST_INT) {
2609 data.putInt(name, v.data);
2610 } else if (v.type == TypedValue.TYPE_FLOAT) {
2611 data.putFloat(name, v.getFloat());
2612 } else {
2613 if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002614 Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
2615 + parser.getName() + " at " + mArchiveSourcePath + " "
2616 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 } else {
2618 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2619 data = null;
2620 }
2621 }
2622 } else {
2623 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2624 data = null;
2625 }
2626 }
2627
2628 sa.recycle();
2629
2630 XmlUtils.skipCurrentTag(parser);
2631
2632 return data;
2633 }
2634
2635 private static final String ANDROID_RESOURCES
2636 = "http://schemas.android.com/apk/res/android";
2637
2638 private boolean parseIntent(Resources res,
2639 XmlPullParser parser, AttributeSet attrs, int flags,
2640 IntentInfo outInfo, String[] outError, boolean isActivity)
2641 throws XmlPullParserException, IOException {
2642
2643 TypedArray sa = res.obtainAttributes(attrs,
2644 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2645
2646 int priority = sa.getInt(
2647 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 TypedValue v = sa.peekValue(
2651 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2652 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2653 outInfo.nonLocalizedLabel = v.coerceToString();
2654 }
2655
2656 outInfo.icon = sa.getResourceId(
2657 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002658
2659 outInfo.logo = sa.getResourceId(
2660 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661
2662 sa.recycle();
2663
2664 int outerDepth = parser.getDepth();
2665 int type;
2666 while ((type=parser.next()) != parser.END_DOCUMENT
2667 && (type != parser.END_TAG || parser.getDepth() > outerDepth)) {
2668 if (type == parser.END_TAG || type == parser.TEXT) {
2669 continue;
2670 }
2671
2672 String nodeName = parser.getName();
2673 if (nodeName.equals("action")) {
2674 String value = attrs.getAttributeValue(
2675 ANDROID_RESOURCES, "name");
2676 if (value == null || value == "") {
2677 outError[0] = "No value supplied for <android:name>";
2678 return false;
2679 }
2680 XmlUtils.skipCurrentTag(parser);
2681
2682 outInfo.addAction(value);
2683 } else if (nodeName.equals("category")) {
2684 String value = attrs.getAttributeValue(
2685 ANDROID_RESOURCES, "name");
2686 if (value == null || value == "") {
2687 outError[0] = "No value supplied for <android:name>";
2688 return false;
2689 }
2690 XmlUtils.skipCurrentTag(parser);
2691
2692 outInfo.addCategory(value);
2693
2694 } else if (nodeName.equals("data")) {
2695 sa = res.obtainAttributes(attrs,
2696 com.android.internal.R.styleable.AndroidManifestData);
2697
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002698 String str = sa.getNonConfigurationString(
2699 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 if (str != null) {
2701 try {
2702 outInfo.addDataType(str);
2703 } catch (IntentFilter.MalformedMimeTypeException e) {
2704 outError[0] = e.toString();
2705 sa.recycle();
2706 return false;
2707 }
2708 }
2709
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002710 str = sa.getNonConfigurationString(
2711 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 if (str != null) {
2713 outInfo.addDataScheme(str);
2714 }
2715
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002716 String host = sa.getNonConfigurationString(
2717 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2718 String port = sa.getNonConfigurationString(
2719 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720 if (host != null) {
2721 outInfo.addDataAuthority(host, port);
2722 }
2723
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002724 str = sa.getNonConfigurationString(
2725 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 if (str != null) {
2727 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2728 }
2729
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002730 str = sa.getNonConfigurationString(
2731 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 if (str != null) {
2733 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2734 }
2735
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002736 str = sa.getNonConfigurationString(
2737 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 if (str != null) {
2739 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2740 }
2741
2742 sa.recycle();
2743 XmlUtils.skipCurrentTag(parser);
2744 } else if (!RIGID_PARSER) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002745 Log.w(TAG, "Unknown element under <intent-filter>: "
2746 + parser.getName() + " at " + mArchiveSourcePath + " "
2747 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 XmlUtils.skipCurrentTag(parser);
2749 } else {
2750 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2751 return false;
2752 }
2753 }
2754
2755 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
2756 if (false) {
2757 String cats = "";
2758 Iterator<String> it = outInfo.categoriesIterator();
2759 while (it != null && it.hasNext()) {
2760 cats += " " + it.next();
2761 }
2762 System.out.println("Intent d=" +
2763 outInfo.hasDefault + ", cat=" + cats);
2764 }
2765
2766 return true;
2767 }
2768
2769 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002770 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771
2772 // For now we only support one application per package.
2773 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2774
2775 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2776 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2777 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2778 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2779 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2780 public final ArrayList<Service> services = new ArrayList<Service>(0);
2781 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2782
2783 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2784
Dianne Hackborn854060a2009-07-09 18:14:31 -07002785 public ArrayList<String> protectedBroadcasts;
2786
Dianne Hackborn49237342009-08-27 20:08:01 -07002787 public ArrayList<String> usesLibraries = null;
2788 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 public String[] usesLibraryFiles = null;
2790
Dianne Hackbornc1552392010-03-03 16:19:01 -08002791 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002792 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002793 public ArrayList<String> mAdoptPermissions = null;
2794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 // We store the application meta-data independently to avoid multiple unwanted references
2796 public Bundle mAppMetaData = null;
2797
2798 // If this is a 3rd party app, this is the path of the zip file.
2799 public String mPath;
2800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 // The version code declared for this package.
2802 public int mVersionCode;
2803
2804 // The version name declared for this package.
2805 public String mVersionName;
2806
2807 // The shared user id that this package wants to use.
2808 public String mSharedUserId;
2809
2810 // The shared user label that this package wants to use.
2811 public int mSharedUserLabel;
2812
2813 // Signatures that were read from the package.
2814 public Signature mSignatures[];
2815
2816 // For use by package manager service for quick lookup of
2817 // preferred up order.
2818 public int mPreferredOrder = 0;
2819
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002820 // For use by the package manager to keep track of the path to the
2821 // file an app came from.
2822 public String mScanPath;
2823
2824 // For use by package manager to keep track of where it has done dexopt.
2825 public boolean mDidDexOpt;
2826
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002827 // User set enabled state.
2828 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2829
Dianne Hackborne7f97212011-02-24 14:40:20 -08002830 // Whether the package has been stopped.
2831 public boolean mSetStopped = false;
2832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 // Additional data supplied by callers.
2834 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002835
2836 // Whether an operation is currently pending on this package
2837 public boolean mOperationPending;
2838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 /*
2840 * Applications hardware preferences
2841 */
2842 public final ArrayList<ConfigurationInfo> configPreferences =
2843 new ArrayList<ConfigurationInfo>();
2844
Dianne Hackborn49237342009-08-27 20:08:01 -07002845 /*
2846 * Applications requested features
2847 */
2848 public ArrayList<FeatureInfo> reqFeatures = null;
2849
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002850 public int installLocation;
2851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 public Package(String _name) {
2853 packageName = _name;
2854 applicationInfo.packageName = _name;
2855 applicationInfo.uid = -1;
2856 }
2857
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002858 public void setPackageName(String newName) {
2859 packageName = newName;
2860 applicationInfo.packageName = newName;
2861 for (int i=permissions.size()-1; i>=0; i--) {
2862 permissions.get(i).setPackageName(newName);
2863 }
2864 for (int i=permissionGroups.size()-1; i>=0; i--) {
2865 permissionGroups.get(i).setPackageName(newName);
2866 }
2867 for (int i=activities.size()-1; i>=0; i--) {
2868 activities.get(i).setPackageName(newName);
2869 }
2870 for (int i=receivers.size()-1; i>=0; i--) {
2871 receivers.get(i).setPackageName(newName);
2872 }
2873 for (int i=providers.size()-1; i>=0; i--) {
2874 providers.get(i).setPackageName(newName);
2875 }
2876 for (int i=services.size()-1; i>=0; i--) {
2877 services.get(i).setPackageName(newName);
2878 }
2879 for (int i=instrumentation.size()-1; i>=0; i--) {
2880 instrumentation.get(i).setPackageName(newName);
2881 }
2882 }
2883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 public String toString() {
2885 return "Package{"
2886 + Integer.toHexString(System.identityHashCode(this))
2887 + " " + packageName + "}";
2888 }
2889 }
2890
2891 public static class Component<II extends IntentInfo> {
2892 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002893 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002894 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 public Bundle metaData;
2896
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002897 ComponentName componentName;
2898 String componentShortName;
2899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 public Component(Package _owner) {
2901 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002902 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002903 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002904 }
2905
2906 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2907 owner = args.owner;
2908 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002909 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002910 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002911 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002912 args.outError[0] = args.tag + " does not specify android:name";
2913 return;
2914 }
2915
2916 outInfo.name
2917 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2918 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002919 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002920 args.outError[0] = args.tag + " does not have valid android:name";
2921 return;
2922 }
2923
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002924 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002925
2926 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2927 if (iconVal != 0) {
2928 outInfo.icon = iconVal;
2929 outInfo.nonLocalizedLabel = null;
2930 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002931
2932 int logoVal = args.sa.getResourceId(args.logoRes, 0);
2933 if (logoVal != 0) {
2934 outInfo.logo = logoVal;
2935 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002936
2937 TypedValue v = args.sa.peekValue(args.labelRes);
2938 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2939 outInfo.nonLocalizedLabel = v.coerceToString();
2940 }
2941
2942 outInfo.packageName = owner.packageName;
2943 }
2944
2945 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
2946 this(args, (PackageItemInfo)outInfo);
2947 if (args.outError[0] != null) {
2948 return;
2949 }
2950
2951 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002952 CharSequence pname;
2953 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2954 pname = args.sa.getNonConfigurationString(args.processRes, 0);
2955 } else {
2956 // Some older apps have been seen to use a resource reference
2957 // here that on older builds was ignored (with a warning). We
2958 // need to continue to do this for them so they don't break.
2959 pname = args.sa.getNonResourceString(args.processRes);
2960 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002961 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002962 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002963 args.flags, args.sepProcesses, args.outError);
2964 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002965
2966 if (args.descriptionRes != 0) {
2967 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
2968 }
2969
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002970 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 }
2972
2973 public Component(Component<II> clone) {
2974 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002975 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002976 className = clone.className;
2977 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002978 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002979 }
2980
2981 public ComponentName getComponentName() {
2982 if (componentName != null) {
2983 return componentName;
2984 }
2985 if (className != null) {
2986 componentName = new ComponentName(owner.applicationInfo.packageName,
2987 className);
2988 }
2989 return componentName;
2990 }
2991
2992 public String getComponentShortName() {
2993 if (componentShortName != null) {
2994 return componentShortName;
2995 }
2996 ComponentName component = getComponentName();
2997 if (component != null) {
2998 componentShortName = component.flattenToShortString();
2999 }
3000 return componentShortName;
3001 }
3002
3003 public void setPackageName(String packageName) {
3004 componentName = null;
3005 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 }
3007 }
3008
3009 public final static class Permission extends Component<IntentInfo> {
3010 public final PermissionInfo info;
3011 public boolean tree;
3012 public PermissionGroup group;
3013
3014 public Permission(Package _owner) {
3015 super(_owner);
3016 info = new PermissionInfo();
3017 }
3018
3019 public Permission(Package _owner, PermissionInfo _info) {
3020 super(_owner);
3021 info = _info;
3022 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003023
3024 public void setPackageName(String packageName) {
3025 super.setPackageName(packageName);
3026 info.packageName = packageName;
3027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028
3029 public String toString() {
3030 return "Permission{"
3031 + Integer.toHexString(System.identityHashCode(this))
3032 + " " + info.name + "}";
3033 }
3034 }
3035
3036 public final static class PermissionGroup extends Component<IntentInfo> {
3037 public final PermissionGroupInfo info;
3038
3039 public PermissionGroup(Package _owner) {
3040 super(_owner);
3041 info = new PermissionGroupInfo();
3042 }
3043
3044 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3045 super(_owner);
3046 info = _info;
3047 }
3048
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003049 public void setPackageName(String packageName) {
3050 super.setPackageName(packageName);
3051 info.packageName = packageName;
3052 }
3053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 public String toString() {
3055 return "PermissionGroup{"
3056 + Integer.toHexString(System.identityHashCode(this))
3057 + " " + info.name + "}";
3058 }
3059 }
3060
3061 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003062 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3063 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3064 if (p.applicationInfo.enabled != enabled) {
3065 return true;
3066 }
3067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 if ((flags & PackageManager.GET_META_DATA) != 0
3069 && (metaData != null || p.mAppMetaData != null)) {
3070 return true;
3071 }
3072 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3073 && p.usesLibraryFiles != null) {
3074 return true;
3075 }
3076 return false;
3077 }
3078
3079 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3080 if (p == null) return null;
3081 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003082 // CompatibilityMode is global state. It's safe to modify the instance
3083 // of the package.
3084 if (!sCompatibilityModeEnabled) {
3085 p.applicationInfo.disableCompatibilityMode();
3086 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003087 if (p.mSetStopped) {
3088 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3089 } else {
3090 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3091 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003092 return p.applicationInfo;
3093 }
3094
3095 // Make shallow copy so we can store the metadata/libraries safely
3096 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3097 if ((flags & PackageManager.GET_META_DATA) != 0) {
3098 ai.metaData = p.mAppMetaData;
3099 }
3100 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3101 ai.sharedLibraryFiles = p.usesLibraryFiles;
3102 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003103 if (!sCompatibilityModeEnabled) {
3104 ai.disableCompatibilityMode();
3105 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003106 if (p.mSetStopped) {
3107 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3108 } else {
3109 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3110 }
John Reck4b7b7cc2011-02-02 11:57:44 -08003111 if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3112 ai.enabled = true;
3113 } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
3114 ai.enabled = false;
3115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116 return ai;
3117 }
3118
3119 public static final PermissionInfo generatePermissionInfo(
3120 Permission p, int flags) {
3121 if (p == null) return null;
3122 if ((flags&PackageManager.GET_META_DATA) == 0) {
3123 return p.info;
3124 }
3125 PermissionInfo pi = new PermissionInfo(p.info);
3126 pi.metaData = p.metaData;
3127 return pi;
3128 }
3129
3130 public static final PermissionGroupInfo generatePermissionGroupInfo(
3131 PermissionGroup pg, int flags) {
3132 if (pg == null) return null;
3133 if ((flags&PackageManager.GET_META_DATA) == 0) {
3134 return pg.info;
3135 }
3136 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3137 pgi.metaData = pg.metaData;
3138 return pgi;
3139 }
3140
3141 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003142 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003144 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3145 super(args, _info);
3146 info = _info;
3147 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003149
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 "Activity{"
3157 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003158 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 }
3160 }
3161
3162 public static final ActivityInfo generateActivityInfo(Activity a,
3163 int flags) {
3164 if (a == null) return null;
3165 if (!copyNeeded(flags, a.owner, a.metaData)) {
3166 return a.info;
3167 }
3168 // Make shallow copies so we can store the metadata safely
3169 ActivityInfo ai = new ActivityInfo(a.info);
3170 ai.metaData = a.metaData;
3171 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3172 return ai;
3173 }
3174
3175 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003176 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003178 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3179 super(args, _info);
3180 info = _info;
3181 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003183
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003184 public void setPackageName(String packageName) {
3185 super.setPackageName(packageName);
3186 info.packageName = packageName;
3187 }
3188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public String toString() {
3190 return "Service{"
3191 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003192 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
3194 }
3195
3196 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3197 if (s == null) return null;
3198 if (!copyNeeded(flags, s.owner, s.metaData)) {
3199 return s.info;
3200 }
3201 // Make shallow copies so we can store the metadata safely
3202 ServiceInfo si = new ServiceInfo(s.info);
3203 si.metaData = s.metaData;
3204 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3205 return si;
3206 }
3207
3208 public final static class Provider extends Component {
3209 public final ProviderInfo info;
3210 public boolean syncable;
3211
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003212 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3213 super(args, _info);
3214 info = _info;
3215 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 syncable = false;
3217 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 public Provider(Provider existingProvider) {
3220 super(existingProvider);
3221 this.info = existingProvider.info;
3222 this.syncable = existingProvider.syncable;
3223 }
3224
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003225 public void setPackageName(String packageName) {
3226 super.setPackageName(packageName);
3227 info.packageName = packageName;
3228 }
3229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 public String toString() {
3231 return "Provider{"
3232 + Integer.toHexString(System.identityHashCode(this))
3233 + " " + info.name + "}";
3234 }
3235 }
3236
3237 public static final ProviderInfo generateProviderInfo(Provider p,
3238 int flags) {
3239 if (p == null) return null;
3240 if (!copyNeeded(flags, p.owner, p.metaData)
3241 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3242 || p.info.uriPermissionPatterns == null)) {
3243 return p.info;
3244 }
3245 // Make shallow copies so we can store the metadata safely
3246 ProviderInfo pi = new ProviderInfo(p.info);
3247 pi.metaData = p.metaData;
3248 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3249 pi.uriPermissionPatterns = null;
3250 }
3251 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3252 return pi;
3253 }
3254
3255 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003256 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003258 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3259 super(args, _info);
3260 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003262
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003263 public void setPackageName(String packageName) {
3264 super.setPackageName(packageName);
3265 info.packageName = packageName;
3266 }
3267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 public String toString() {
3269 return "Instrumentation{"
3270 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003271 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 }
3273 }
3274
3275 public static final InstrumentationInfo generateInstrumentationInfo(
3276 Instrumentation i, int flags) {
3277 if (i == null) return null;
3278 if ((flags&PackageManager.GET_META_DATA) == 0) {
3279 return i.info;
3280 }
3281 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3282 ii.metaData = i.metaData;
3283 return ii;
3284 }
3285
3286 public static class IntentInfo extends IntentFilter {
3287 public boolean hasDefault;
3288 public int labelRes;
3289 public CharSequence nonLocalizedLabel;
3290 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003291 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 }
3293
3294 public final static class ActivityIntentInfo extends IntentInfo {
3295 public final Activity activity;
3296
3297 public ActivityIntentInfo(Activity _activity) {
3298 activity = _activity;
3299 }
3300
3301 public String toString() {
3302 return "ActivityIntentInfo{"
3303 + Integer.toHexString(System.identityHashCode(this))
3304 + " " + activity.info.name + "}";
3305 }
3306 }
3307
3308 public final static class ServiceIntentInfo extends IntentInfo {
3309 public final Service service;
3310
3311 public ServiceIntentInfo(Service _service) {
3312 service = _service;
3313 }
3314
3315 public String toString() {
3316 return "ServiceIntentInfo{"
3317 + Integer.toHexString(System.identityHashCode(this))
3318 + " " + service.info.name + "}";
3319 }
3320 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003321
3322 /**
3323 * @hide
3324 */
3325 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3326 sCompatibilityModeEnabled = compatibilityModeEnabled;
3327 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328}