blob: c61e32fc9c15481a1699f112254e018cdfe14c63 [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;
Kenny Rootd2d29252011-08-08 11:27:57 -070032import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import 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;
Kenny Rootbcc954d2011-08-08 16:19:08 -070048import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import java.util.jar.JarEntry;
50import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070051import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53/**
54 * Package archive parsing
55 *
56 * {@hide}
57 */
58public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070059 private static final boolean DEBUG_JAR = false;
60 private static final boolean DEBUG_PARSER = false;
61 private static final boolean DEBUG_BACKUP = false;
62
Kenny Rootbcc954d2011-08-08 16:19:08 -070063 /** File name in an APK for the Android manifest. */
64 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
65
Dianne Hackborna96cbb42009-05-13 15:06:13 -070066 /** @hide */
67 public static class NewPermissionInfo {
68 public final String name;
69 public final int sdkVersion;
70 public final int fileVersion;
71
72 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
73 this.name = name;
74 this.sdkVersion = sdkVersion;
75 this.fileVersion = fileVersion;
76 }
77 }
78
79 /**
80 * List of new permissions that have been added since 1.0.
81 * NOTE: These must be declared in SDK version order, with permissions
82 * added to older SDKs appearing before those added to newer SDKs.
83 * @hide
84 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -070085 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
86 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -070087 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -070088 android.os.Build.VERSION_CODES.DONUT, 0),
89 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
90 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -070091 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 private String mArchiveSourcePath;
94 private String[] mSeparateProcesses;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070095 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
96 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
97 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
100
101 private static final Object mSync = new Object();
102 private static WeakReference<byte[]> mReadBuffer;
103
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700104 private static boolean sCompatibilityModeEnabled = true;
105 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700106
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700107 static class ParsePackageItemArgs {
108 final Package owner;
109 final String[] outError;
110 final int nameRes;
111 final int labelRes;
112 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700113 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700114
115 String tag;
116 TypedArray sa;
117
118 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700119 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700120 owner = _owner;
121 outError = _outError;
122 nameRes = _nameRes;
123 labelRes = _labelRes;
124 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700125 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700126 }
127 }
128
129 static class ParseComponentArgs extends ParsePackageItemArgs {
130 final String[] sepProcesses;
131 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800132 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700133 final int enabledRes;
134 int flags;
135
136 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700137 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800138 String[] _sepProcesses, int _processRes,
139 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700140 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700141 sepProcesses = _sepProcesses;
142 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800143 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700144 enabledRes = _enabledRes;
145 }
146 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800147
148 /* Light weight package info.
149 * @hide
150 */
151 public static class PackageLite {
152 public String packageName;
153 public int installLocation;
154 public String mScanPath;
155 public PackageLite(String packageName, int installLocation) {
156 this.packageName = packageName;
157 this.installLocation = installLocation;
158 }
159 }
160
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700161 private ParsePackageItemArgs mParseInstrumentationArgs;
162 private ParseComponentArgs mParseActivityArgs;
163 private ParseComponentArgs mParseActivityAliasArgs;
164 private ParseComponentArgs mParseServiceArgs;
165 private ParseComponentArgs mParseProviderArgs;
166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 /** If set to true, we will only allow package files that exactly match
168 * the DTD. Otherwise, we try to get as much from the package as we
169 * can without failing. This should normally be set to false, to
170 * support extensions to the DTD in future versions. */
171 private static final boolean RIGID_PARSER = false;
172
173 private static final String TAG = "PackageParser";
174
175 public PackageParser(String archiveSourcePath) {
176 mArchiveSourcePath = archiveSourcePath;
177 }
178
179 public void setSeparateProcesses(String[] procs) {
180 mSeparateProcesses = procs;
181 }
182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 private static final boolean isPackageFilename(String name) {
184 return name.endsWith(".apk");
185 }
186
187 /**
188 * Generate and return the {@link PackageInfo} for a parsed package.
189 *
190 * @param p the parsed package.
191 * @param flags indicating which optional information is included.
192 */
193 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborn78d68832010-10-07 01:12:46 -0700194 int gids[], int flags, long firstInstallTime, long lastUpdateTime) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195
196 PackageInfo pi = new PackageInfo();
197 pi.packageName = p.packageName;
198 pi.versionCode = p.mVersionCode;
199 pi.versionName = p.mVersionName;
200 pi.sharedUserId = p.mSharedUserId;
201 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborne4a59512010-12-07 11:08:07 -0800202 pi.applicationInfo = generateApplicationInfo(p, flags);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800203 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700204 pi.firstInstallTime = firstInstallTime;
205 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 if ((flags&PackageManager.GET_GIDS) != 0) {
207 pi.gids = gids;
208 }
209 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
210 int N = p.configPreferences.size();
211 if (N > 0) {
212 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700213 p.configPreferences.toArray(pi.configPreferences);
214 }
215 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
216 if (N > 0) {
217 pi.reqFeatures = new FeatureInfo[N];
218 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 }
220 }
221 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
222 int N = p.activities.size();
223 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700224 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
225 pi.activities = new ActivityInfo[N];
226 } else {
227 int num = 0;
228 for (int i=0; i<N; i++) {
229 if (p.activities.get(i).info.enabled) num++;
230 }
231 pi.activities = new ActivityInfo[num];
232 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700233 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 final Activity activity = p.activities.get(i);
235 if (activity.info.enabled
236 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700237 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 }
239 }
240 }
241 }
242 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
243 int N = p.receivers.size();
244 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700245 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
246 pi.receivers = new ActivityInfo[N];
247 } else {
248 int num = 0;
249 for (int i=0; i<N; i++) {
250 if (p.receivers.get(i).info.enabled) num++;
251 }
252 pi.receivers = new ActivityInfo[num];
253 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700254 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 final Activity activity = p.receivers.get(i);
256 if (activity.info.enabled
257 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700258 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 }
262 }
263 if ((flags&PackageManager.GET_SERVICES) != 0) {
264 int N = p.services.size();
265 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700266 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
267 pi.services = new ServiceInfo[N];
268 } else {
269 int num = 0;
270 for (int i=0; i<N; i++) {
271 if (p.services.get(i).info.enabled) num++;
272 }
273 pi.services = new ServiceInfo[num];
274 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700275 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final Service service = p.services.get(i);
277 if (service.info.enabled
278 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700279 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 }
281 }
282 }
283 }
284 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
285 int N = p.providers.size();
286 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700287 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
288 pi.providers = new ProviderInfo[N];
289 } else {
290 int num = 0;
291 for (int i=0; i<N; i++) {
292 if (p.providers.get(i).info.enabled) num++;
293 }
294 pi.providers = new ProviderInfo[num];
295 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700296 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 final Provider provider = p.providers.get(i);
298 if (provider.info.enabled
299 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700300 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 }
302 }
303 }
304 }
305 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
306 int N = p.instrumentation.size();
307 if (N > 0) {
308 pi.instrumentation = new InstrumentationInfo[N];
309 for (int i=0; i<N; i++) {
310 pi.instrumentation[i] = generateInstrumentationInfo(
311 p.instrumentation.get(i), flags);
312 }
313 }
314 }
315 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
316 int N = p.permissions.size();
317 if (N > 0) {
318 pi.permissions = new PermissionInfo[N];
319 for (int i=0; i<N; i++) {
320 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
321 }
322 }
323 N = p.requestedPermissions.size();
324 if (N > 0) {
325 pi.requestedPermissions = new String[N];
326 for (int i=0; i<N; i++) {
327 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
328 }
329 }
330 }
331 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700332 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
333 if (N > 0) {
334 pi.signatures = new Signature[N];
335 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 }
337 }
338 return pi;
339 }
340
341 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
342 byte[] readBuffer) {
343 try {
344 // We must read the stream for the JarEntry to retrieve
345 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700346 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
348 // not using
349 }
350 is.close();
351 return je != null ? je.getCertificates() : null;
352 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700353 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700355 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700356 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700357 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359 return null;
360 }
361
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800362 public final static int PARSE_IS_SYSTEM = 1<<0;
363 public final static int PARSE_CHATTY = 1<<1;
364 public final static int PARSE_MUST_BE_APK = 1<<2;
365 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
366 public final static int PARSE_FORWARD_LOCK = 1<<4;
367 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700368 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369
370 public int getParseError() {
371 return mParseError;
372 }
373
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800374 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 DisplayMetrics metrics, int flags) {
376 mParseError = PackageManager.INSTALL_SUCCEEDED;
377
378 mArchiveSourcePath = sourceFile.getPath();
379 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700380 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
382 return null;
383 }
384 if (!isPackageFilename(sourceFile.getName())
385 && (flags&PARSE_MUST_BE_APK) != 0) {
386 if ((flags&PARSE_IS_SYSTEM) == 0) {
387 // We expect to have non-.apk files in the system dir,
388 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700389 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 }
391 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
392 return null;
393 }
394
Kenny Rootd2d29252011-08-08 11:27:57 -0700395 if (DEBUG_JAR)
396 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397
398 XmlResourceParser parser = null;
399 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800400 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 boolean assetError = true;
402 try {
403 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700404 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800405 if (cookie != 0) {
406 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700407 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800408 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700409 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 assetError = false;
411 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700412 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700415 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 + mArchiveSourcePath, e);
417 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800418 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 if (assmgr != null) assmgr.close();
420 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
421 return null;
422 }
423 String[] errorText = new String[1];
424 Package pkg = null;
425 Exception errorException = null;
426 try {
427 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 pkg = parsePackage(res, parser, flags, errorText);
429 } catch (Exception e) {
430 errorException = e;
431 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
432 }
433
434
435 if (pkg == null) {
436 if (errorException != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700437 Slog.w(TAG, mArchiveSourcePath, errorException);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700439 Slog.w(TAG, mArchiveSourcePath + " (at "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 + parser.getPositionDescription()
441 + "): " + errorText[0]);
442 }
443 parser.close();
444 assmgr.close();
445 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
446 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
447 }
448 return null;
449 }
450
451 parser.close();
452 assmgr.close();
453
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800454 // Set code and resource paths
455 pkg.mPath = destCodePath;
456 pkg.mScanPath = mArchiveSourcePath;
457 //pkg.applicationInfo.sourceDir = destCodePath;
458 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 pkg.mSignatures = null;
460
461 return pkg;
462 }
463
464 public boolean collectCertificates(Package pkg, int flags) {
465 pkg.mSignatures = null;
466
467 WeakReference<byte[]> readBufferRef;
468 byte[] readBuffer = null;
469 synchronized (mSync) {
470 readBufferRef = mReadBuffer;
471 if (readBufferRef != null) {
472 mReadBuffer = null;
473 readBuffer = readBufferRef.get();
474 }
475 if (readBuffer == null) {
476 readBuffer = new byte[8192];
477 readBufferRef = new WeakReference<byte[]>(readBuffer);
478 }
479 }
480
481 try {
482 JarFile jarFile = new JarFile(mArchiveSourcePath);
483
484 Certificate[] certs = null;
485
486 if ((flags&PARSE_IS_SYSTEM) != 0) {
487 // If this package comes from the system image, then we
488 // can trust it... we'll just use the AndroidManifest.xml
489 // to retrieve its signatures, not validating all of the
490 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700491 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 certs = loadCertificates(jarFile, jarEntry, readBuffer);
493 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700494 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 + " has no certificates at entry "
496 + jarEntry.getName() + "; ignoring!");
497 jarFile.close();
498 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
499 return false;
500 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700501 if (DEBUG_JAR) {
502 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 + " certs=" + (certs != null ? certs.length : 0));
504 if (certs != null) {
505 final int N = certs.length;
506 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700507 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 + certs[i].getPublicKey().getEncoded()
509 + " " + certs[i].getPublicKey());
510 }
511 }
512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700514 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700515 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700517 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700519
Kenny Rootbcc954d2011-08-08 16:19:08 -0700520 final String name = je.getName();
521
522 if (name.startsWith("META-INF/"))
523 continue;
524
525 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
526 final Attributes attributes = manifest.getAttributes(name);
527 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
528 }
529
530 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700531 if (DEBUG_JAR) {
532 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 + ": certs=" + certs + " ("
534 + (certs != null ? certs.length : 0) + ")");
535 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700538 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 + " has no certificates at entry "
540 + je.getName() + "; ignoring!");
541 jarFile.close();
542 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
543 return false;
544 } else if (certs == null) {
545 certs = localCerts;
546 } else {
547 // Ensure all certificates match.
548 for (int i=0; i<certs.length; i++) {
549 boolean found = false;
550 for (int j=0; j<localCerts.length; j++) {
551 if (certs[i] != null &&
552 certs[i].equals(localCerts[j])) {
553 found = true;
554 break;
555 }
556 }
557 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700558 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 + " has mismatched certificates at entry "
560 + je.getName() + "; ignoring!");
561 jarFile.close();
562 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
563 return false;
564 }
565 }
566 }
567 }
568 }
569 jarFile.close();
570
571 synchronized (mSync) {
572 mReadBuffer = readBufferRef;
573 }
574
575 if (certs != null && certs.length > 0) {
576 final int N = certs.length;
577 pkg.mSignatures = new Signature[certs.length];
578 for (int i=0; i<N; i++) {
579 pkg.mSignatures[i] = new Signature(
580 certs[i].getEncoded());
581 }
582 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700583 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 + " has no certificates; ignoring!");
585 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
586 return false;
587 }
588 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700589 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
591 return false;
592 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700593 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
595 return false;
596 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700597 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
599 return false;
600 }
601
602 return true;
603 }
604
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800605 /*
606 * Utility method that retrieves just the package name and install
607 * location from the apk location at the given file path.
608 * @param packageFilePath file location of the apk
609 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700610 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800611 */
612 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 XmlResourceParser parser = null;
614 AssetManager assmgr = null;
615 try {
616 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700617 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800618 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700621 if (cookie == 0) {
622 return null;
623 }
624
Kenny Rootbcc954d2011-08-08 16:19:08 -0700625 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 } catch (Exception e) {
627 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700628 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 + packageFilePath, e);
630 return null;
631 }
632 AttributeSet attrs = parser;
633 String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800634 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 try {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800636 packageLite = parsePackageLite(parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700638 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700640 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 } finally {
642 if (parser != null) parser.close();
643 if (assmgr != null) assmgr.close();
644 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800645 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700646 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 return null;
648 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800649 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
651
652 private static String validateName(String name, boolean requiresSeparator) {
653 final int N = name.length();
654 boolean hasSep = false;
655 boolean front = true;
656 for (int i=0; i<N; i++) {
657 final char c = name.charAt(i);
658 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
659 front = false;
660 continue;
661 }
662 if (!front) {
663 if ((c >= '0' && c <= '9') || c == '_') {
664 continue;
665 }
666 }
667 if (c == '.') {
668 hasSep = true;
669 front = true;
670 continue;
671 }
672 return "bad character '" + c + "'";
673 }
674 return hasSep || !requiresSeparator
675 ? null : "must have at least one '.' separator";
676 }
677
678 private static String parsePackageName(XmlPullParser parser,
679 AttributeSet attrs, int flags, String[] outError)
680 throws IOException, XmlPullParserException {
681
682 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700683 while ((type = parser.next()) != XmlPullParser.START_TAG
684 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 ;
686 }
687
Kenny Rootd2d29252011-08-08 11:27:57 -0700688 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 outError[0] = "No start tag found";
690 return null;
691 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700692 if (DEBUG_PARSER)
693 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if (!parser.getName().equals("manifest")) {
695 outError[0] = "No <manifest> tag";
696 return null;
697 }
698 String pkgName = attrs.getAttributeValue(null, "package");
699 if (pkgName == null || pkgName.length() == 0) {
700 outError[0] = "<manifest> does not specify package";
701 return null;
702 }
703 String nameError = validateName(pkgName, true);
704 if (nameError != null && !"android".equals(pkgName)) {
705 outError[0] = "<manifest> specifies bad package name \""
706 + pkgName + "\": " + nameError;
707 return null;
708 }
709
710 return pkgName.intern();
711 }
712
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800713 private static PackageLite parsePackageLite(XmlPullParser parser,
714 AttributeSet attrs, int flags, String[] outError)
715 throws IOException, XmlPullParserException {
716
717 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700718 while ((type = parser.next()) != XmlPullParser.START_TAG
719 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800720 ;
721 }
722
Kenny Rootd2d29252011-08-08 11:27:57 -0700723 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800724 outError[0] = "No start tag found";
725 return null;
726 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700727 if (DEBUG_PARSER)
728 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800729 if (!parser.getName().equals("manifest")) {
730 outError[0] = "No <manifest> tag";
731 return null;
732 }
733 String pkgName = attrs.getAttributeValue(null, "package");
734 if (pkgName == null || pkgName.length() == 0) {
735 outError[0] = "<manifest> does not specify package";
736 return null;
737 }
738 String nameError = validateName(pkgName, true);
739 if (nameError != null && !"android".equals(pkgName)) {
740 outError[0] = "<manifest> specifies bad package name \""
741 + pkgName + "\": " + nameError;
742 return null;
743 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700744 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800745 for (int i = 0; i < attrs.getAttributeCount(); i++) {
746 String attr = attrs.getAttributeName(i);
747 if (attr.equals("installLocation")) {
748 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700749 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800750 break;
751 }
752 }
753 return new PackageLite(pkgName.intern(), installLocation);
754 }
755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 /**
757 * Temporary.
758 */
759 static public Signature stringToSignature(String str) {
760 final int N = str.length();
761 byte[] sig = new byte[N];
762 for (int i=0; i<N; i++) {
763 sig[i] = (byte)str.charAt(i);
764 }
765 return new Signature(sig);
766 }
767
768 private Package parsePackage(
769 Resources res, XmlResourceParser parser, int flags, String[] outError)
770 throws XmlPullParserException, IOException {
771 AttributeSet attrs = parser;
772
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700773 mParseInstrumentationArgs = null;
774 mParseActivityArgs = null;
775 mParseServiceArgs = null;
776 mParseProviderArgs = null;
777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 String pkgName = parsePackageName(parser, attrs, flags, outError);
779 if (pkgName == null) {
780 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
781 return null;
782 }
783 int type;
784
785 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 TypedArray sa = res.obtainAttributes(attrs,
789 com.android.internal.R.styleable.AndroidManifest);
790 pkg.mVersionCode = sa.getInteger(
791 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800792 pkg.mVersionName = sa.getNonConfigurationString(
793 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 if (pkg.mVersionName != null) {
795 pkg.mVersionName = pkg.mVersionName.intern();
796 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800797 String str = sa.getNonConfigurationString(
798 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
799 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 String nameError = validateName(str, true);
801 if (nameError != null && !"android".equals(pkgName)) {
802 outError[0] = "<manifest> specifies bad sharedUserId name \""
803 + str + "\": " + nameError;
804 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
805 return null;
806 }
807 pkg.mSharedUserId = str.intern();
808 pkg.mSharedUserLabel = sa.getResourceId(
809 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
810 }
811 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800812
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800813 pkg.installLocation = sa.getInteger(
814 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700815 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700816 pkg.applicationInfo.installLocation = pkg.installLocation;
817
Dianne Hackborn723738c2009-06-25 19:48:04 -0700818 // Resource boolean are -1, so 1 means we don't know the value.
819 int supportsSmallScreens = 1;
820 int supportsNormalScreens = 1;
821 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700822 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700823 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700824 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700827 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
828 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
829 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 continue;
831 }
832
833 String tagName = parser.getName();
834 if (tagName.equals("application")) {
835 if (foundApp) {
836 if (RIGID_PARSER) {
837 outError[0] = "<manifest> has more than one <application>";
838 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
839 return null;
840 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700841 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 XmlUtils.skipCurrentTag(parser);
843 continue;
844 }
845 }
846
847 foundApp = true;
848 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
849 return null;
850 }
851 } else if (tagName.equals("permission-group")) {
852 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
853 return null;
854 }
855 } else if (tagName.equals("permission")) {
856 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
857 return null;
858 }
859 } else if (tagName.equals("permission-tree")) {
860 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
861 return null;
862 }
863 } else if (tagName.equals("uses-permission")) {
864 sa = res.obtainAttributes(attrs,
865 com.android.internal.R.styleable.AndroidManifestUsesPermission);
866
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800867 // Note: don't allow this value to be a reference to a resource
868 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 String name = sa.getNonResourceString(
870 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
871
872 sa.recycle();
873
874 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700875 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 }
877
878 XmlUtils.skipCurrentTag(parser);
879
880 } else if (tagName.equals("uses-configuration")) {
881 ConfigurationInfo cPref = new ConfigurationInfo();
882 sa = res.obtainAttributes(attrs,
883 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
884 cPref.reqTouchScreen = sa.getInt(
885 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
886 Configuration.TOUCHSCREEN_UNDEFINED);
887 cPref.reqKeyboardType = sa.getInt(
888 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
889 Configuration.KEYBOARD_UNDEFINED);
890 if (sa.getBoolean(
891 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
892 false)) {
893 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
894 }
895 cPref.reqNavigation = sa.getInt(
896 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
897 Configuration.NAVIGATION_UNDEFINED);
898 if (sa.getBoolean(
899 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
900 false)) {
901 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
902 }
903 sa.recycle();
904 pkg.configPreferences.add(cPref);
905
906 XmlUtils.skipCurrentTag(parser);
907
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700908 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700909 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700910 sa = res.obtainAttributes(attrs,
911 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800912 // Note: don't allow this value to be a reference to a resource
913 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700914 fi.name = sa.getNonResourceString(
915 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
916 if (fi.name == null) {
917 fi.reqGlEsVersion = sa.getInt(
918 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
919 FeatureInfo.GL_ES_VERSION_UNDEFINED);
920 }
921 if (sa.getBoolean(
922 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
923 true)) {
924 fi.flags |= FeatureInfo.FLAG_REQUIRED;
925 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700926 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700927 if (pkg.reqFeatures == null) {
928 pkg.reqFeatures = new ArrayList<FeatureInfo>();
929 }
930 pkg.reqFeatures.add(fi);
931
932 if (fi.name == null) {
933 ConfigurationInfo cPref = new ConfigurationInfo();
934 cPref.reqGlEsVersion = fi.reqGlEsVersion;
935 pkg.configPreferences.add(cPref);
936 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700937
938 XmlUtils.skipCurrentTag(parser);
939
Dianne Hackborn851a5412009-05-08 12:06:44 -0700940 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700941 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 sa = res.obtainAttributes(attrs,
943 com.android.internal.R.styleable.AndroidManifestUsesSdk);
944
Dianne Hackborn851a5412009-05-08 12:06:44 -0700945 int minVers = 0;
946 String minCode = null;
947 int targetVers = 0;
948 String targetCode = null;
949
950 TypedValue val = sa.peekValue(
951 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
952 if (val != null) {
953 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
954 targetCode = minCode = val.string.toString();
955 } else {
956 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700957 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700958 }
959 }
960
961 val = sa.peekValue(
962 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
963 if (val != null) {
964 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
965 targetCode = minCode = val.string.toString();
966 } else {
967 // If it's not a string, it's an integer.
968 targetVers = val.data;
969 }
970 }
971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 sa.recycle();
973
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700974 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700975 if (!minCode.equals(SDK_CODENAME)) {
976 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700977 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700978 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700979 } else {
980 outError[0] = "Requires development platform " + minCode
981 + " but this is a release platform.";
982 }
983 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
984 return null;
985 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700986 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700987 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700988 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700989 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
990 return null;
991 }
992
Dianne Hackborn851a5412009-05-08 12:06:44 -0700993 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700994 if (!targetCode.equals(SDK_CODENAME)) {
995 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -0700996 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700997 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -0700998 } else {
999 outError[0] = "Requires development platform " + targetCode
1000 + " but this is a release platform.";
1001 }
1002 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1003 return null;
1004 }
1005 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001006 pkg.applicationInfo.targetSdkVersion
1007 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1008 } else {
1009 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 }
1012
1013 XmlUtils.skipCurrentTag(parser);
1014
Dianne Hackborn723738c2009-06-25 19:48:04 -07001015 } else if (tagName.equals("supports-screens")) {
1016 sa = res.obtainAttributes(attrs,
1017 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1018
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001019 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1020 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1021 0);
1022 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1023 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1024 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001025 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1026 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1027 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001028
Dianne Hackborn723738c2009-06-25 19:48:04 -07001029 // This is a trick to get a boolean and still able to detect
1030 // if a value was actually set.
1031 supportsSmallScreens = sa.getInteger(
1032 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1033 supportsSmallScreens);
1034 supportsNormalScreens = sa.getInteger(
1035 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1036 supportsNormalScreens);
1037 supportsLargeScreens = sa.getInteger(
1038 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1039 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001040 supportsXLargeScreens = sa.getInteger(
1041 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1042 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001043 resizeable = sa.getInteger(
1044 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001045 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001046 anyDensity = sa.getInteger(
1047 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1048 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001049
1050 sa.recycle();
1051
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001052 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001053
1054 } else if (tagName.equals("protected-broadcast")) {
1055 sa = res.obtainAttributes(attrs,
1056 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1057
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001058 // Note: don't allow this value to be a reference to a resource
1059 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001060 String name = sa.getNonResourceString(
1061 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1062
1063 sa.recycle();
1064
1065 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1066 if (pkg.protectedBroadcasts == null) {
1067 pkg.protectedBroadcasts = new ArrayList<String>();
1068 }
1069 if (!pkg.protectedBroadcasts.contains(name)) {
1070 pkg.protectedBroadcasts.add(name.intern());
1071 }
1072 }
1073
1074 XmlUtils.skipCurrentTag(parser);
1075
1076 } else if (tagName.equals("instrumentation")) {
1077 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1078 return null;
1079 }
1080
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001081 } else if (tagName.equals("original-package")) {
1082 sa = res.obtainAttributes(attrs,
1083 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1084
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001085 String orig =sa.getNonConfigurationString(
1086 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001087 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001088 if (pkg.mOriginalPackages == null) {
1089 pkg.mOriginalPackages = new ArrayList<String>();
1090 pkg.mRealPackage = pkg.packageName;
1091 }
1092 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001093 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001094
1095 sa.recycle();
1096
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001097 XmlUtils.skipCurrentTag(parser);
1098
1099 } else if (tagName.equals("adopt-permissions")) {
1100 sa = res.obtainAttributes(attrs,
1101 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1102
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001103 String name = sa.getNonConfigurationString(
1104 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001105
1106 sa.recycle();
1107
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001108 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001109 if (pkg.mAdoptPermissions == null) {
1110 pkg.mAdoptPermissions = new ArrayList<String>();
1111 }
1112 pkg.mAdoptPermissions.add(name);
1113 }
1114
1115 XmlUtils.skipCurrentTag(parser);
1116
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001117 } else if (tagName.equals("uses-gl-texture")) {
1118 // Just skip this tag
1119 XmlUtils.skipCurrentTag(parser);
1120 continue;
1121
1122 } else if (tagName.equals("compatible-screens")) {
1123 // Just skip this tag
1124 XmlUtils.skipCurrentTag(parser);
1125 continue;
1126
Dianne Hackborn854060a2009-07-09 18:14:31 -07001127 } else if (tagName.equals("eat-comment")) {
1128 // Just skip this tag
1129 XmlUtils.skipCurrentTag(parser);
1130 continue;
1131
1132 } else if (RIGID_PARSER) {
1133 outError[0] = "Bad element under <manifest>: "
1134 + parser.getName();
1135 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1136 return null;
1137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001139 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001140 + " at " + mArchiveSourcePath + " "
1141 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 XmlUtils.skipCurrentTag(parser);
1143 continue;
1144 }
1145 }
1146
1147 if (!foundApp && pkg.instrumentation.size() == 0) {
1148 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1149 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1150 }
1151
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001152 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001153 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001154 for (int ip=0; ip<NP; ip++) {
1155 final PackageParser.NewPermissionInfo npi
1156 = PackageParser.NEW_PERMISSIONS[ip];
1157 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1158 break;
1159 }
1160 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001161 if (implicitPerms == null) {
1162 implicitPerms = new StringBuilder(128);
1163 implicitPerms.append(pkg.packageName);
1164 implicitPerms.append(": compat added ");
1165 } else {
1166 implicitPerms.append(' ');
1167 }
1168 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001169 pkg.requestedPermissions.add(npi.name);
1170 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001171 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001172 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001173 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001174 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001175
Dianne Hackborn723738c2009-06-25 19:48:04 -07001176 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1177 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001178 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001179 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1180 }
1181 if (supportsNormalScreens != 0) {
1182 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1183 }
1184 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1185 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001186 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001187 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1188 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001189 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1190 && pkg.applicationInfo.targetSdkVersion
1191 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1192 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1193 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001194 if (resizeable < 0 || (resizeable > 0
1195 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001196 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001197 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1198 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001199 if (anyDensity < 0 || (anyDensity > 0
1200 && pkg.applicationInfo.targetSdkVersion
1201 >= android.os.Build.VERSION_CODES.DONUT)) {
1202 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001203 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 return pkg;
1206 }
1207
1208 private static String buildClassName(String pkg, CharSequence clsSeq,
1209 String[] outError) {
1210 if (clsSeq == null || clsSeq.length() <= 0) {
1211 outError[0] = "Empty class name in package " + pkg;
1212 return null;
1213 }
1214 String cls = clsSeq.toString();
1215 char c = cls.charAt(0);
1216 if (c == '.') {
1217 return (pkg + cls).intern();
1218 }
1219 if (cls.indexOf('.') < 0) {
1220 StringBuilder b = new StringBuilder(pkg);
1221 b.append('.');
1222 b.append(cls);
1223 return b.toString().intern();
1224 }
1225 if (c >= 'a' && c <= 'z') {
1226 return cls.intern();
1227 }
1228 outError[0] = "Bad class name " + cls + " in package " + pkg;
1229 return null;
1230 }
1231
1232 private static String buildCompoundName(String pkg,
1233 CharSequence procSeq, String type, String[] outError) {
1234 String proc = procSeq.toString();
1235 char c = proc.charAt(0);
1236 if (pkg != null && c == ':') {
1237 if (proc.length() < 2) {
1238 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1239 + ": must be at least two characters";
1240 return null;
1241 }
1242 String subName = proc.substring(1);
1243 String nameError = validateName(subName, false);
1244 if (nameError != null) {
1245 outError[0] = "Invalid " + type + " name " + proc + " in package "
1246 + pkg + ": " + nameError;
1247 return null;
1248 }
1249 return (pkg + proc).intern();
1250 }
1251 String nameError = validateName(proc, true);
1252 if (nameError != null && !"system".equals(proc)) {
1253 outError[0] = "Invalid " + type + " name " + proc + " in package "
1254 + pkg + ": " + nameError;
1255 return null;
1256 }
1257 return proc.intern();
1258 }
1259
1260 private static String buildProcessName(String pkg, String defProc,
1261 CharSequence procSeq, int flags, String[] separateProcesses,
1262 String[] outError) {
1263 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1264 return defProc != null ? defProc : pkg;
1265 }
1266 if (separateProcesses != null) {
1267 for (int i=separateProcesses.length-1; i>=0; i--) {
1268 String sp = separateProcesses[i];
1269 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1270 return pkg;
1271 }
1272 }
1273 }
1274 if (procSeq == null || procSeq.length() <= 0) {
1275 return defProc;
1276 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001277 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 }
1279
1280 private static String buildTaskAffinityName(String pkg, String defProc,
1281 CharSequence procSeq, String[] outError) {
1282 if (procSeq == null) {
1283 return defProc;
1284 }
1285 if (procSeq.length() <= 0) {
1286 return null;
1287 }
1288 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1289 }
1290
1291 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1292 XmlPullParser parser, AttributeSet attrs, String[] outError)
1293 throws XmlPullParserException, IOException {
1294 PermissionGroup perm = new PermissionGroup(owner);
1295
1296 TypedArray sa = res.obtainAttributes(attrs,
1297 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1298
1299 if (!parsePackageItemInfo(owner, perm.info, outError,
1300 "<permission-group>", sa,
1301 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1302 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001303 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1304 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 sa.recycle();
1306 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1307 return null;
1308 }
1309
1310 perm.info.descriptionRes = sa.getResourceId(
1311 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1312 0);
1313
1314 sa.recycle();
1315
1316 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1317 outError)) {
1318 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1319 return null;
1320 }
1321
1322 owner.permissionGroups.add(perm);
1323
1324 return perm;
1325 }
1326
1327 private Permission parsePermission(Package owner, Resources res,
1328 XmlPullParser parser, AttributeSet attrs, String[] outError)
1329 throws XmlPullParserException, IOException {
1330 Permission perm = new Permission(owner);
1331
1332 TypedArray sa = res.obtainAttributes(attrs,
1333 com.android.internal.R.styleable.AndroidManifestPermission);
1334
1335 if (!parsePackageItemInfo(owner, perm.info, outError,
1336 "<permission>", sa,
1337 com.android.internal.R.styleable.AndroidManifestPermission_name,
1338 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001339 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1340 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 sa.recycle();
1342 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1343 return null;
1344 }
1345
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001346 // Note: don't allow this value to be a reference to a resource
1347 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 perm.info.group = sa.getNonResourceString(
1349 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1350 if (perm.info.group != null) {
1351 perm.info.group = perm.info.group.intern();
1352 }
1353
1354 perm.info.descriptionRes = sa.getResourceId(
1355 com.android.internal.R.styleable.AndroidManifestPermission_description,
1356 0);
1357
1358 perm.info.protectionLevel = sa.getInt(
1359 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1360 PermissionInfo.PROTECTION_NORMAL);
1361
1362 sa.recycle();
1363
1364 if (perm.info.protectionLevel == -1) {
1365 outError[0] = "<permission> does not specify protectionLevel";
1366 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1367 return null;
1368 }
1369
1370 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1371 outError)) {
1372 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1373 return null;
1374 }
1375
1376 owner.permissions.add(perm);
1377
1378 return perm;
1379 }
1380
1381 private Permission parsePermissionTree(Package owner, Resources res,
1382 XmlPullParser parser, AttributeSet attrs, String[] outError)
1383 throws XmlPullParserException, IOException {
1384 Permission perm = new Permission(owner);
1385
1386 TypedArray sa = res.obtainAttributes(attrs,
1387 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1388
1389 if (!parsePackageItemInfo(owner, perm.info, outError,
1390 "<permission-tree>", sa,
1391 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1392 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001393 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1394 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 sa.recycle();
1396 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1397 return null;
1398 }
1399
1400 sa.recycle();
1401
1402 int index = perm.info.name.indexOf('.');
1403 if (index > 0) {
1404 index = perm.info.name.indexOf('.', index+1);
1405 }
1406 if (index < 0) {
1407 outError[0] = "<permission-tree> name has less than three segments: "
1408 + perm.info.name;
1409 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1410 return null;
1411 }
1412
1413 perm.info.descriptionRes = 0;
1414 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1415 perm.tree = true;
1416
1417 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1418 outError)) {
1419 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1420 return null;
1421 }
1422
1423 owner.permissions.add(perm);
1424
1425 return perm;
1426 }
1427
1428 private Instrumentation parseInstrumentation(Package owner, Resources res,
1429 XmlPullParser parser, AttributeSet attrs, String[] outError)
1430 throws XmlPullParserException, IOException {
1431 TypedArray sa = res.obtainAttributes(attrs,
1432 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1433
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001434 if (mParseInstrumentationArgs == null) {
1435 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1436 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1437 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001438 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1439 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001440 mParseInstrumentationArgs.tag = "<instrumentation>";
1441 }
1442
1443 mParseInstrumentationArgs.sa = sa;
1444
1445 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1446 new InstrumentationInfo());
1447 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 sa.recycle();
1449 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1450 return null;
1451 }
1452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001454 // Note: don't allow this value to be a reference to a resource
1455 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 str = sa.getNonResourceString(
1457 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1458 a.info.targetPackage = str != null ? str.intern() : null;
1459
1460 a.info.handleProfiling = sa.getBoolean(
1461 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1462 false);
1463
1464 a.info.functionalTest = sa.getBoolean(
1465 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1466 false);
1467
1468 sa.recycle();
1469
1470 if (a.info.targetPackage == null) {
1471 outError[0] = "<instrumentation> does not specify targetPackage";
1472 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1473 return null;
1474 }
1475
1476 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1477 outError)) {
1478 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1479 return null;
1480 }
1481
1482 owner.instrumentation.add(a);
1483
1484 return a;
1485 }
1486
1487 private boolean parseApplication(Package owner, Resources res,
1488 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1489 throws XmlPullParserException, IOException {
1490 final ApplicationInfo ai = owner.applicationInfo;
1491 final String pkgName = owner.applicationInfo.packageName;
1492
1493 TypedArray sa = res.obtainAttributes(attrs,
1494 com.android.internal.R.styleable.AndroidManifestApplication);
1495
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001496 String name = sa.getNonConfigurationString(
1497 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 if (name != null) {
1499 ai.className = buildClassName(pkgName, name, outError);
1500 if (ai.className == null) {
1501 sa.recycle();
1502 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1503 return false;
1504 }
1505 }
1506
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001507 String manageSpaceActivity = sa.getNonConfigurationString(
1508 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 if (manageSpaceActivity != null) {
1510 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1511 outError);
1512 }
1513
Christopher Tate181fafa2009-05-14 11:12:14 -07001514 boolean allowBackup = sa.getBoolean(
1515 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1516 if (allowBackup) {
1517 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001518
Christopher Tate3de55bc2010-03-12 17:28:08 -08001519 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1520 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001521 String backupAgent = sa.getNonConfigurationString(
1522 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001523 if (backupAgent != null) {
1524 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001525 if (DEBUG_BACKUP) {
1526 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001527 + " from " + pkgName + "+" + backupAgent);
1528 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001529
1530 if (sa.getBoolean(
1531 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1532 true)) {
1533 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1534 }
1535 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001536 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1537 false)) {
1538 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1539 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001540 }
1541 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 TypedValue v = sa.peekValue(
1544 com.android.internal.R.styleable.AndroidManifestApplication_label);
1545 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1546 ai.nonLocalizedLabel = v.coerceToString();
1547 }
1548
1549 ai.icon = sa.getResourceId(
1550 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001551 ai.logo = sa.getResourceId(
1552 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001554 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 ai.descriptionRes = sa.getResourceId(
1556 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1557
1558 if ((flags&PARSE_IS_SYSTEM) != 0) {
1559 if (sa.getBoolean(
1560 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1561 false)) {
1562 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1563 }
1564 }
1565
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001566 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1567 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1568 }
1569
1570 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001571 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001572 }
1573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 if (sa.getBoolean(
1575 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1576 false)) {
1577 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1578 }
1579
1580 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001581 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001582 false)) {
1583 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1584 }
1585
Romain Guy529b60a2010-08-03 18:05:47 -07001586 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001587 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001588 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001589
1590 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1592 true)) {
1593 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1594 }
1595
1596 if (sa.getBoolean(
1597 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1598 false)) {
1599 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1600 }
1601
1602 if (sa.getBoolean(
1603 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1604 true)) {
1605 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1606 }
1607
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001608 if (sa.getBoolean(
1609 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001610 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001611 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1612 }
1613
Jason parksa3cdaa52011-01-13 14:15:43 -06001614 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001615 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001616 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001617 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001618 }
1619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001621 str = sa.getNonConfigurationString(
1622 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1624
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001625 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1626 str = sa.getNonConfigurationString(
1627 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1628 } else {
1629 // Some older apps have been seen to use a resource reference
1630 // here that on older builds was ignored (with a warning). We
1631 // need to continue to do this for them so they don't break.
1632 str = sa.getNonResourceString(
1633 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1636 str, outError);
1637
1638 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001639 CharSequence pname;
1640 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1641 pname = sa.getNonConfigurationString(
1642 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1643 } else {
1644 // Some older apps have been seen to use a resource reference
1645 // here that on older builds was ignored (with a warning). We
1646 // need to continue to do this for them so they don't break.
1647 pname = sa.getNonResourceString(
1648 com.android.internal.R.styleable.AndroidManifestApplication_process);
1649 }
1650 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 flags, mSeparateProcesses, outError);
1652
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001653 ai.enabled = sa.getBoolean(
1654 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001655
Dianne Hackborn02486b12010-08-26 14:18:37 -07001656 if (false) {
1657 if (sa.getBoolean(
1658 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1659 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001660 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001661
1662 // A heavy-weight application can not be in a custom process.
1663 // We can do direct compare because we intern all strings.
1664 if (ai.processName != null && ai.processName != ai.packageName) {
1665 outError[0] = "cantSaveState applications can not use custom processes";
1666 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001667 }
1668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 }
1670
Adam Powell269248d2011-08-02 10:26:54 -07001671 ai.uiOptions = sa.getInt(
1672 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 sa.recycle();
1675
1676 if (outError[0] != null) {
1677 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1678 return false;
1679 }
1680
1681 final int innerDepth = parser.getDepth();
1682
1683 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001684 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1685 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1686 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 continue;
1688 }
1689
1690 String tagName = parser.getName();
1691 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001692 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1693 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 if (a == null) {
1695 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1696 return false;
1697 }
1698
1699 owner.activities.add(a);
1700
1701 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001702 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 if (a == null) {
1704 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1705 return false;
1706 }
1707
1708 owner.receivers.add(a);
1709
1710 } else if (tagName.equals("service")) {
1711 Service s = parseService(owner, res, parser, attrs, flags, outError);
1712 if (s == null) {
1713 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1714 return false;
1715 }
1716
1717 owner.services.add(s);
1718
1719 } else if (tagName.equals("provider")) {
1720 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1721 if (p == null) {
1722 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1723 return false;
1724 }
1725
1726 owner.providers.add(p);
1727
1728 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001729 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 if (a == null) {
1731 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1732 return false;
1733 }
1734
1735 owner.activities.add(a);
1736
1737 } else if (parser.getName().equals("meta-data")) {
1738 // note: application meta-data is stored off to the side, so it can
1739 // remain null in the primary copy (we like to avoid extra copies because
1740 // it can be large)
1741 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1742 outError)) == null) {
1743 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1744 return false;
1745 }
1746
1747 } else if (tagName.equals("uses-library")) {
1748 sa = res.obtainAttributes(attrs,
1749 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1750
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001751 // Note: don't allow this value to be a reference to a resource
1752 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 String lname = sa.getNonResourceString(
1754 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001755 boolean req = sa.getBoolean(
1756 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1757 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758
1759 sa.recycle();
1760
Dianne Hackborn49237342009-08-27 20:08:01 -07001761 if (lname != null) {
1762 if (req) {
1763 if (owner.usesLibraries == null) {
1764 owner.usesLibraries = new ArrayList<String>();
1765 }
1766 if (!owner.usesLibraries.contains(lname)) {
1767 owner.usesLibraries.add(lname.intern());
1768 }
1769 } else {
1770 if (owner.usesOptionalLibraries == null) {
1771 owner.usesOptionalLibraries = new ArrayList<String>();
1772 }
1773 if (!owner.usesOptionalLibraries.contains(lname)) {
1774 owner.usesOptionalLibraries.add(lname.intern());
1775 }
1776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 }
1778
1779 XmlUtils.skipCurrentTag(parser);
1780
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001781 } else if (tagName.equals("uses-package")) {
1782 // Dependencies for app installers; we don't currently try to
1783 // enforce this.
1784 XmlUtils.skipCurrentTag(parser);
1785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 } else {
1787 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001788 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001789 + " at " + mArchiveSourcePath + " "
1790 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 XmlUtils.skipCurrentTag(parser);
1792 continue;
1793 } else {
1794 outError[0] = "Bad element under <application>: " + tagName;
1795 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1796 return false;
1797 }
1798 }
1799 }
1800
1801 return true;
1802 }
1803
1804 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1805 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001806 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001807 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 if (name == null) {
1809 outError[0] = tag + " does not specify android:name";
1810 return false;
1811 }
1812
1813 outInfo.name
1814 = buildClassName(owner.applicationInfo.packageName, name, outError);
1815 if (outInfo.name == null) {
1816 return false;
1817 }
1818
1819 int iconVal = sa.getResourceId(iconRes, 0);
1820 if (iconVal != 0) {
1821 outInfo.icon = iconVal;
1822 outInfo.nonLocalizedLabel = null;
1823 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001824
1825 int logoVal = sa.getResourceId(logoRes, 0);
1826 if (logoVal != 0) {
1827 outInfo.logo = logoVal;
1828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829
1830 TypedValue v = sa.peekValue(labelRes);
1831 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1832 outInfo.nonLocalizedLabel = v.coerceToString();
1833 }
1834
1835 outInfo.packageName = owner.packageName;
1836
1837 return true;
1838 }
1839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 private Activity parseActivity(Package owner, Resources res,
1841 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07001842 boolean receiver, boolean hardwareAccelerated)
1843 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 TypedArray sa = res.obtainAttributes(attrs,
1845 com.android.internal.R.styleable.AndroidManifestActivity);
1846
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001847 if (mParseActivityArgs == null) {
1848 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1849 com.android.internal.R.styleable.AndroidManifestActivity_name,
1850 com.android.internal.R.styleable.AndroidManifestActivity_label,
1851 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001852 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001853 mSeparateProcesses,
1854 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001855 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001856 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1857 }
1858
1859 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1860 mParseActivityArgs.sa = sa;
1861 mParseActivityArgs.flags = flags;
1862
1863 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1864 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 sa.recycle();
1866 return null;
1867 }
1868
1869 final boolean setExported = sa.hasValue(
1870 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1871 if (setExported) {
1872 a.info.exported = sa.getBoolean(
1873 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1874 }
1875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 a.info.theme = sa.getResourceId(
1877 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1878
Adam Powell269248d2011-08-02 10:26:54 -07001879 a.info.uiOptions = sa.getInt(
1880 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
1881 a.info.applicationInfo.uiOptions);
1882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001884 str = sa.getNonConfigurationString(
1885 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 if (str == null) {
1887 a.info.permission = owner.applicationInfo.permission;
1888 } else {
1889 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1890 }
1891
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001892 str = sa.getNonConfigurationString(
1893 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1895 owner.applicationInfo.taskAffinity, str, outError);
1896
1897 a.info.flags = 0;
1898 if (sa.getBoolean(
1899 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1900 false)) {
1901 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1902 }
1903
1904 if (sa.getBoolean(
1905 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1906 false)) {
1907 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1908 }
1909
1910 if (sa.getBoolean(
1911 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1912 false)) {
1913 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1914 }
1915
1916 if (sa.getBoolean(
1917 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1918 false)) {
1919 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1920 }
1921
1922 if (sa.getBoolean(
1923 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1924 false)) {
1925 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1926 }
1927
1928 if (sa.getBoolean(
1929 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1930 false)) {
1931 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1932 }
1933
1934 if (sa.getBoolean(
1935 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1936 false)) {
1937 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1938 }
1939
1940 if (sa.getBoolean(
1941 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1942 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1943 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1944 }
1945
Dianne Hackbornffa42482009-09-23 22:20:11 -07001946 if (sa.getBoolean(
1947 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1948 false)) {
1949 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1950 }
1951
Daniel Sandler613dde42010-06-21 13:46:39 -04001952 if (sa.getBoolean(
1953 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
1954 false)) {
1955 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
1956 }
Romain Guy529b60a2010-08-03 18:05:47 -07001957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07001959 if (sa.getBoolean(
1960 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
1961 hardwareAccelerated)) {
1962 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
1963 }
1964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 a.info.launchMode = sa.getInt(
1966 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1967 ActivityInfo.LAUNCH_MULTIPLE);
1968 a.info.screenOrientation = sa.getInt(
1969 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1970 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1971 a.info.configChanges = sa.getInt(
1972 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1973 0);
1974 a.info.softInputMode = sa.getInt(
1975 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1976 0);
1977 } else {
1978 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1979 a.info.configChanges = 0;
1980 }
1981
1982 sa.recycle();
1983
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001984 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07001985 // A heavy-weight application can not have receives in its main process
1986 // We can do direct compare because we intern all strings.
1987 if (a.info.processName == owner.packageName) {
1988 outError[0] = "Heavy-weight applications can not have receivers in main process";
1989 }
1990 }
1991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 if (outError[0] != null) {
1993 return null;
1994 }
1995
1996 int outerDepth = parser.getDepth();
1997 int type;
1998 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1999 && (type != XmlPullParser.END_TAG
2000 || parser.getDepth() > outerDepth)) {
2001 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2002 continue;
2003 }
2004
2005 if (parser.getName().equals("intent-filter")) {
2006 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2007 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2008 return null;
2009 }
2010 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002011 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002012 + mArchiveSourcePath + " "
2013 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 } else {
2015 a.intents.add(intent);
2016 }
2017 } else if (parser.getName().equals("meta-data")) {
2018 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2019 outError)) == null) {
2020 return null;
2021 }
2022 } else {
2023 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002024 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002026 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002027 + " at " + mArchiveSourcePath + " "
2028 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002030 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002031 + " at " + mArchiveSourcePath + " "
2032 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 }
2034 XmlUtils.skipCurrentTag(parser);
2035 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002037 if (receiver) {
2038 outError[0] = "Bad element under <receiver>: " + parser.getName();
2039 } else {
2040 outError[0] = "Bad element under <activity>: " + parser.getName();
2041 }
2042 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 }
2045 }
2046
2047 if (!setExported) {
2048 a.info.exported = a.intents.size() > 0;
2049 }
2050
2051 return a;
2052 }
2053
2054 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002055 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2056 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 TypedArray sa = res.obtainAttributes(attrs,
2058 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2059
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002060 String targetActivity = sa.getNonConfigurationString(
2061 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 if (targetActivity == null) {
2063 outError[0] = "<activity-alias> does not specify android:targetActivity";
2064 sa.recycle();
2065 return null;
2066 }
2067
2068 targetActivity = buildClassName(owner.applicationInfo.packageName,
2069 targetActivity, outError);
2070 if (targetActivity == null) {
2071 sa.recycle();
2072 return null;
2073 }
2074
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002075 if (mParseActivityAliasArgs == null) {
2076 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2077 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2078 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2079 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002080 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002081 mSeparateProcesses,
2082 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002083 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002084 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2085 mParseActivityAliasArgs.tag = "<activity-alias>";
2086 }
2087
2088 mParseActivityAliasArgs.sa = sa;
2089 mParseActivityAliasArgs.flags = flags;
2090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 Activity target = null;
2092
2093 final int NA = owner.activities.size();
2094 for (int i=0; i<NA; i++) {
2095 Activity t = owner.activities.get(i);
2096 if (targetActivity.equals(t.info.name)) {
2097 target = t;
2098 break;
2099 }
2100 }
2101
2102 if (target == null) {
2103 outError[0] = "<activity-alias> target activity " + targetActivity
2104 + " not found in manifest";
2105 sa.recycle();
2106 return null;
2107 }
2108
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002109 ActivityInfo info = new ActivityInfo();
2110 info.targetActivity = targetActivity;
2111 info.configChanges = target.info.configChanges;
2112 info.flags = target.info.flags;
2113 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002114 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002115 info.labelRes = target.info.labelRes;
2116 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2117 info.launchMode = target.info.launchMode;
2118 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002119 if (info.descriptionRes == 0) {
2120 info.descriptionRes = target.info.descriptionRes;
2121 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002122 info.screenOrientation = target.info.screenOrientation;
2123 info.taskAffinity = target.info.taskAffinity;
2124 info.theme = target.info.theme;
Adam Powell269248d2011-08-02 10:26:54 -07002125 info.uiOptions = target.info.uiOptions;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002126
2127 Activity a = new Activity(mParseActivityAliasArgs, info);
2128 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002129 sa.recycle();
2130 return null;
2131 }
2132
2133 final boolean setExported = sa.hasValue(
2134 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2135 if (setExported) {
2136 a.info.exported = sa.getBoolean(
2137 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2138 }
2139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002141 str = sa.getNonConfigurationString(
2142 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 if (str != null) {
2144 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2145 }
2146
2147 sa.recycle();
2148
2149 if (outError[0] != null) {
2150 return null;
2151 }
2152
2153 int outerDepth = parser.getDepth();
2154 int type;
2155 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2156 && (type != XmlPullParser.END_TAG
2157 || parser.getDepth() > outerDepth)) {
2158 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2159 continue;
2160 }
2161
2162 if (parser.getName().equals("intent-filter")) {
2163 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2164 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2165 return null;
2166 }
2167 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002168 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002169 + mArchiveSourcePath + " "
2170 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 } else {
2172 a.intents.add(intent);
2173 }
2174 } else if (parser.getName().equals("meta-data")) {
2175 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2176 outError)) == null) {
2177 return null;
2178 }
2179 } else {
2180 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002181 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002182 + " at " + mArchiveSourcePath + " "
2183 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 XmlUtils.skipCurrentTag(parser);
2185 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002186 } else {
2187 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2188 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 }
2191 }
2192
2193 if (!setExported) {
2194 a.info.exported = a.intents.size() > 0;
2195 }
2196
2197 return a;
2198 }
2199
2200 private Provider parseProvider(Package owner, Resources res,
2201 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2202 throws XmlPullParserException, IOException {
2203 TypedArray sa = res.obtainAttributes(attrs,
2204 com.android.internal.R.styleable.AndroidManifestProvider);
2205
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002206 if (mParseProviderArgs == null) {
2207 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2208 com.android.internal.R.styleable.AndroidManifestProvider_name,
2209 com.android.internal.R.styleable.AndroidManifestProvider_label,
2210 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002211 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002212 mSeparateProcesses,
2213 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002214 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002215 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2216 mParseProviderArgs.tag = "<provider>";
2217 }
2218
2219 mParseProviderArgs.sa = sa;
2220 mParseProviderArgs.flags = flags;
2221
2222 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2223 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002224 sa.recycle();
2225 return null;
2226 }
2227
2228 p.info.exported = sa.getBoolean(
2229 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2230
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002231 String cpname = sa.getNonConfigurationString(
2232 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233
2234 p.info.isSyncable = sa.getBoolean(
2235 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2236 false);
2237
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002238 String permission = sa.getNonConfigurationString(
2239 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2240 String str = sa.getNonConfigurationString(
2241 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 if (str == null) {
2243 str = permission;
2244 }
2245 if (str == null) {
2246 p.info.readPermission = owner.applicationInfo.permission;
2247 } else {
2248 p.info.readPermission =
2249 str.length() > 0 ? str.toString().intern() : null;
2250 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002251 str = sa.getNonConfigurationString(
2252 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 if (str == null) {
2254 str = permission;
2255 }
2256 if (str == null) {
2257 p.info.writePermission = owner.applicationInfo.permission;
2258 } else {
2259 p.info.writePermission =
2260 str.length() > 0 ? str.toString().intern() : null;
2261 }
2262
2263 p.info.grantUriPermissions = sa.getBoolean(
2264 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2265 false);
2266
2267 p.info.multiprocess = sa.getBoolean(
2268 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2269 false);
2270
2271 p.info.initOrder = sa.getInt(
2272 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2273 0);
2274
2275 sa.recycle();
2276
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002277 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002278 // A heavy-weight application can not have providers in its main process
2279 // We can do direct compare because we intern all strings.
2280 if (p.info.processName == owner.packageName) {
2281 outError[0] = "Heavy-weight applications can not have providers in main process";
2282 return null;
2283 }
2284 }
2285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 if (cpname == null) {
2287 outError[0] = "<provider> does not incude authorities attribute";
2288 return null;
2289 }
2290 p.info.authority = cpname.intern();
2291
2292 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2293 return null;
2294 }
2295
2296 return p;
2297 }
2298
2299 private boolean parseProviderTags(Resources res,
2300 XmlPullParser parser, AttributeSet attrs,
2301 Provider outInfo, String[] outError)
2302 throws XmlPullParserException, IOException {
2303 int outerDepth = parser.getDepth();
2304 int type;
2305 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2306 && (type != XmlPullParser.END_TAG
2307 || parser.getDepth() > outerDepth)) {
2308 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2309 continue;
2310 }
2311
2312 if (parser.getName().equals("meta-data")) {
2313 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2314 outInfo.metaData, outError)) == null) {
2315 return false;
2316 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 } else if (parser.getName().equals("grant-uri-permission")) {
2319 TypedArray sa = res.obtainAttributes(attrs,
2320 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2321
2322 PatternMatcher pa = null;
2323
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002324 String str = sa.getNonConfigurationString(
2325 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 if (str != null) {
2327 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2328 }
2329
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002330 str = sa.getNonConfigurationString(
2331 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 if (str != null) {
2333 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2334 }
2335
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002336 str = sa.getNonConfigurationString(
2337 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 if (str != null) {
2339 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2340 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 sa.recycle();
2343
2344 if (pa != null) {
2345 if (outInfo.info.uriPermissionPatterns == null) {
2346 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2347 outInfo.info.uriPermissionPatterns[0] = pa;
2348 } else {
2349 final int N = outInfo.info.uriPermissionPatterns.length;
2350 PatternMatcher[] newp = new PatternMatcher[N+1];
2351 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2352 newp[N] = pa;
2353 outInfo.info.uriPermissionPatterns = newp;
2354 }
2355 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002356 } else {
2357 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002358 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002359 + parser.getName() + " at " + mArchiveSourcePath + " "
2360 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002361 XmlUtils.skipCurrentTag(parser);
2362 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002363 } else {
2364 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2365 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002366 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002367 }
2368 XmlUtils.skipCurrentTag(parser);
2369
2370 } else if (parser.getName().equals("path-permission")) {
2371 TypedArray sa = res.obtainAttributes(attrs,
2372 com.android.internal.R.styleable.AndroidManifestPathPermission);
2373
2374 PathPermission pa = null;
2375
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002376 String permission = sa.getNonConfigurationString(
2377 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2378 String readPermission = sa.getNonConfigurationString(
2379 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002380 if (readPermission == null) {
2381 readPermission = permission;
2382 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002383 String writePermission = sa.getNonConfigurationString(
2384 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002385 if (writePermission == null) {
2386 writePermission = permission;
2387 }
2388
2389 boolean havePerm = false;
2390 if (readPermission != null) {
2391 readPermission = readPermission.intern();
2392 havePerm = true;
2393 }
2394 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002395 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002396 havePerm = true;
2397 }
2398
2399 if (!havePerm) {
2400 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002401 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002402 + parser.getName() + " at " + mArchiveSourcePath + " "
2403 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002404 XmlUtils.skipCurrentTag(parser);
2405 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002406 } else {
2407 outError[0] = "No readPermission or writePermssion for <path-permission>";
2408 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002409 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002410 }
2411
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002412 String path = sa.getNonConfigurationString(
2413 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002414 if (path != null) {
2415 pa = new PathPermission(path,
2416 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2417 }
2418
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002419 path = sa.getNonConfigurationString(
2420 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002421 if (path != null) {
2422 pa = new PathPermission(path,
2423 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2424 }
2425
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002426 path = sa.getNonConfigurationString(
2427 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002428 if (path != null) {
2429 pa = new PathPermission(path,
2430 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2431 }
2432
2433 sa.recycle();
2434
2435 if (pa != null) {
2436 if (outInfo.info.pathPermissions == null) {
2437 outInfo.info.pathPermissions = new PathPermission[1];
2438 outInfo.info.pathPermissions[0] = pa;
2439 } else {
2440 final int N = outInfo.info.pathPermissions.length;
2441 PathPermission[] newp = new PathPermission[N+1];
2442 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2443 newp[N] = pa;
2444 outInfo.info.pathPermissions = newp;
2445 }
2446 } else {
2447 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002448 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002449 + parser.getName() + " at " + mArchiveSourcePath + " "
2450 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002451 XmlUtils.skipCurrentTag(parser);
2452 continue;
2453 }
2454 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2455 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 }
2457 XmlUtils.skipCurrentTag(parser);
2458
2459 } else {
2460 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002461 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002462 + parser.getName() + " at " + mArchiveSourcePath + " "
2463 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 XmlUtils.skipCurrentTag(parser);
2465 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002466 } else {
2467 outError[0] = "Bad element under <provider>: " + parser.getName();
2468 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 }
2471 }
2472 return true;
2473 }
2474
2475 private Service parseService(Package owner, Resources res,
2476 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2477 throws XmlPullParserException, IOException {
2478 TypedArray sa = res.obtainAttributes(attrs,
2479 com.android.internal.R.styleable.AndroidManifestService);
2480
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002481 if (mParseServiceArgs == null) {
2482 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2483 com.android.internal.R.styleable.AndroidManifestService_name,
2484 com.android.internal.R.styleable.AndroidManifestService_label,
2485 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002486 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002487 mSeparateProcesses,
2488 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002489 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002490 com.android.internal.R.styleable.AndroidManifestService_enabled);
2491 mParseServiceArgs.tag = "<service>";
2492 }
2493
2494 mParseServiceArgs.sa = sa;
2495 mParseServiceArgs.flags = flags;
2496
2497 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2498 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 sa.recycle();
2500 return null;
2501 }
2502
2503 final boolean setExported = sa.hasValue(
2504 com.android.internal.R.styleable.AndroidManifestService_exported);
2505 if (setExported) {
2506 s.info.exported = sa.getBoolean(
2507 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2508 }
2509
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002510 String str = sa.getNonConfigurationString(
2511 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 if (str == null) {
2513 s.info.permission = owner.applicationInfo.permission;
2514 } else {
2515 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2516 }
2517
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002518 s.info.flags = 0;
2519 if (sa.getBoolean(
2520 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2521 false)) {
2522 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2523 }
2524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 sa.recycle();
2526
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002527 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002528 // A heavy-weight application can not have services in its main process
2529 // We can do direct compare because we intern all strings.
2530 if (s.info.processName == owner.packageName) {
2531 outError[0] = "Heavy-weight applications can not have services in main process";
2532 return null;
2533 }
2534 }
2535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 int outerDepth = parser.getDepth();
2537 int type;
2538 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2539 && (type != XmlPullParser.END_TAG
2540 || parser.getDepth() > outerDepth)) {
2541 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2542 continue;
2543 }
2544
2545 if (parser.getName().equals("intent-filter")) {
2546 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2547 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2548 return null;
2549 }
2550
2551 s.intents.add(intent);
2552 } else if (parser.getName().equals("meta-data")) {
2553 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2554 outError)) == null) {
2555 return null;
2556 }
2557 } else {
2558 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002559 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002560 + parser.getName() + " at " + mArchiveSourcePath + " "
2561 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 XmlUtils.skipCurrentTag(parser);
2563 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002564 } else {
2565 outError[0] = "Bad element under <service>: " + parser.getName();
2566 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 }
2569 }
2570
2571 if (!setExported) {
2572 s.info.exported = s.intents.size() > 0;
2573 }
2574
2575 return s;
2576 }
2577
2578 private boolean parseAllMetaData(Resources res,
2579 XmlPullParser parser, AttributeSet attrs, String tag,
2580 Component outInfo, String[] outError)
2581 throws XmlPullParserException, IOException {
2582 int outerDepth = parser.getDepth();
2583 int type;
2584 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2585 && (type != XmlPullParser.END_TAG
2586 || parser.getDepth() > outerDepth)) {
2587 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2588 continue;
2589 }
2590
2591 if (parser.getName().equals("meta-data")) {
2592 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2593 outInfo.metaData, outError)) == null) {
2594 return false;
2595 }
2596 } else {
2597 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002598 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002599 + parser.getName() + " at " + mArchiveSourcePath + " "
2600 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 XmlUtils.skipCurrentTag(parser);
2602 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002603 } else {
2604 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2605 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 }
2608 }
2609 return true;
2610 }
2611
2612 private Bundle parseMetaData(Resources res,
2613 XmlPullParser parser, AttributeSet attrs,
2614 Bundle data, String[] outError)
2615 throws XmlPullParserException, IOException {
2616
2617 TypedArray sa = res.obtainAttributes(attrs,
2618 com.android.internal.R.styleable.AndroidManifestMetaData);
2619
2620 if (data == null) {
2621 data = new Bundle();
2622 }
2623
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002624 String name = sa.getNonConfigurationString(
2625 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002626 if (name == null) {
2627 outError[0] = "<meta-data> requires an android:name attribute";
2628 sa.recycle();
2629 return null;
2630 }
2631
Dianne Hackborn854060a2009-07-09 18:14:31 -07002632 name = name.intern();
2633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 TypedValue v = sa.peekValue(
2635 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2636 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002637 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 data.putInt(name, v.resourceId);
2639 } else {
2640 v = sa.peekValue(
2641 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002642 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 if (v != null) {
2644 if (v.type == TypedValue.TYPE_STRING) {
2645 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002646 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2648 data.putBoolean(name, v.data != 0);
2649 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2650 && v.type <= TypedValue.TYPE_LAST_INT) {
2651 data.putInt(name, v.data);
2652 } else if (v.type == TypedValue.TYPE_FLOAT) {
2653 data.putFloat(name, v.getFloat());
2654 } else {
2655 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002656 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002657 + parser.getName() + " at " + mArchiveSourcePath + " "
2658 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 } else {
2660 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2661 data = null;
2662 }
2663 }
2664 } else {
2665 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2666 data = null;
2667 }
2668 }
2669
2670 sa.recycle();
2671
2672 XmlUtils.skipCurrentTag(parser);
2673
2674 return data;
2675 }
2676
2677 private static final String ANDROID_RESOURCES
2678 = "http://schemas.android.com/apk/res/android";
2679
2680 private boolean parseIntent(Resources res,
2681 XmlPullParser parser, AttributeSet attrs, int flags,
2682 IntentInfo outInfo, String[] outError, boolean isActivity)
2683 throws XmlPullParserException, IOException {
2684
2685 TypedArray sa = res.obtainAttributes(attrs,
2686 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2687
2688 int priority = sa.getInt(
2689 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 TypedValue v = sa.peekValue(
2693 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2694 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2695 outInfo.nonLocalizedLabel = v.coerceToString();
2696 }
2697
2698 outInfo.icon = sa.getResourceId(
2699 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002700
2701 outInfo.logo = sa.getResourceId(
2702 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703
2704 sa.recycle();
2705
2706 int outerDepth = parser.getDepth();
2707 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002708 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2709 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2710 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 continue;
2712 }
2713
2714 String nodeName = parser.getName();
2715 if (nodeName.equals("action")) {
2716 String value = attrs.getAttributeValue(
2717 ANDROID_RESOURCES, "name");
2718 if (value == null || value == "") {
2719 outError[0] = "No value supplied for <android:name>";
2720 return false;
2721 }
2722 XmlUtils.skipCurrentTag(parser);
2723
2724 outInfo.addAction(value);
2725 } else if (nodeName.equals("category")) {
2726 String value = attrs.getAttributeValue(
2727 ANDROID_RESOURCES, "name");
2728 if (value == null || value == "") {
2729 outError[0] = "No value supplied for <android:name>";
2730 return false;
2731 }
2732 XmlUtils.skipCurrentTag(parser);
2733
2734 outInfo.addCategory(value);
2735
2736 } else if (nodeName.equals("data")) {
2737 sa = res.obtainAttributes(attrs,
2738 com.android.internal.R.styleable.AndroidManifestData);
2739
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002740 String str = sa.getNonConfigurationString(
2741 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 if (str != null) {
2743 try {
2744 outInfo.addDataType(str);
2745 } catch (IntentFilter.MalformedMimeTypeException e) {
2746 outError[0] = e.toString();
2747 sa.recycle();
2748 return false;
2749 }
2750 }
2751
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002752 str = sa.getNonConfigurationString(
2753 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 if (str != null) {
2755 outInfo.addDataScheme(str);
2756 }
2757
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002758 String host = sa.getNonConfigurationString(
2759 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2760 String port = sa.getNonConfigurationString(
2761 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 if (host != null) {
2763 outInfo.addDataAuthority(host, port);
2764 }
2765
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002766 str = sa.getNonConfigurationString(
2767 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002768 if (str != null) {
2769 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2770 }
2771
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002772 str = sa.getNonConfigurationString(
2773 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 if (str != null) {
2775 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2776 }
2777
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002778 str = sa.getNonConfigurationString(
2779 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 if (str != null) {
2781 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2782 }
2783
2784 sa.recycle();
2785 XmlUtils.skipCurrentTag(parser);
2786 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002787 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002788 + parser.getName() + " at " + mArchiveSourcePath + " "
2789 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 XmlUtils.skipCurrentTag(parser);
2791 } else {
2792 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2793 return false;
2794 }
2795 }
2796
2797 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07002798
2799 if (DEBUG_PARSER) {
2800 final StringBuilder cats = new StringBuilder("Intent d=");
2801 cats.append(outInfo.hasDefault);
2802 cats.append(", cat=");
2803
2804 final Iterator<String> it = outInfo.categoriesIterator();
2805 if (it != null) {
2806 while (it.hasNext()) {
2807 cats.append(' ');
2808 cats.append(it.next());
2809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 }
Kenny Rootd2d29252011-08-08 11:27:57 -07002811 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 }
2813
2814 return true;
2815 }
2816
2817 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002818 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819
2820 // For now we only support one application per package.
2821 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2822
2823 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2824 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2825 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2826 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2827 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2828 public final ArrayList<Service> services = new ArrayList<Service>(0);
2829 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2830
2831 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2832
Dianne Hackborn854060a2009-07-09 18:14:31 -07002833 public ArrayList<String> protectedBroadcasts;
2834
Dianne Hackborn49237342009-08-27 20:08:01 -07002835 public ArrayList<String> usesLibraries = null;
2836 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 public String[] usesLibraryFiles = null;
2838
Dianne Hackbornc1552392010-03-03 16:19:01 -08002839 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002840 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002841 public ArrayList<String> mAdoptPermissions = null;
2842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 // We store the application meta-data independently to avoid multiple unwanted references
2844 public Bundle mAppMetaData = null;
2845
2846 // If this is a 3rd party app, this is the path of the zip file.
2847 public String mPath;
2848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 // The version code declared for this package.
2850 public int mVersionCode;
2851
2852 // The version name declared for this package.
2853 public String mVersionName;
2854
2855 // The shared user id that this package wants to use.
2856 public String mSharedUserId;
2857
2858 // The shared user label that this package wants to use.
2859 public int mSharedUserLabel;
2860
2861 // Signatures that were read from the package.
2862 public Signature mSignatures[];
2863
2864 // For use by package manager service for quick lookup of
2865 // preferred up order.
2866 public int mPreferredOrder = 0;
2867
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002868 // For use by the package manager to keep track of the path to the
2869 // file an app came from.
2870 public String mScanPath;
2871
2872 // For use by package manager to keep track of where it has done dexopt.
2873 public boolean mDidDexOpt;
2874
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002875 // User set enabled state.
2876 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2877
Dianne Hackborne7f97212011-02-24 14:40:20 -08002878 // Whether the package has been stopped.
2879 public boolean mSetStopped = false;
2880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 // Additional data supplied by callers.
2882 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002883
2884 // Whether an operation is currently pending on this package
2885 public boolean mOperationPending;
2886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 /*
2888 * Applications hardware preferences
2889 */
2890 public final ArrayList<ConfigurationInfo> configPreferences =
2891 new ArrayList<ConfigurationInfo>();
2892
Dianne Hackborn49237342009-08-27 20:08:01 -07002893 /*
2894 * Applications requested features
2895 */
2896 public ArrayList<FeatureInfo> reqFeatures = null;
2897
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002898 public int installLocation;
2899
Kenny Rootbcc954d2011-08-08 16:19:08 -07002900 /**
2901 * Digest suitable for comparing whether this package's manifest is the
2902 * same as another.
2903 */
2904 public ManifestDigest manifestDigest;
2905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 public Package(String _name) {
2907 packageName = _name;
2908 applicationInfo.packageName = _name;
2909 applicationInfo.uid = -1;
2910 }
2911
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002912 public void setPackageName(String newName) {
2913 packageName = newName;
2914 applicationInfo.packageName = newName;
2915 for (int i=permissions.size()-1; i>=0; i--) {
2916 permissions.get(i).setPackageName(newName);
2917 }
2918 for (int i=permissionGroups.size()-1; i>=0; i--) {
2919 permissionGroups.get(i).setPackageName(newName);
2920 }
2921 for (int i=activities.size()-1; i>=0; i--) {
2922 activities.get(i).setPackageName(newName);
2923 }
2924 for (int i=receivers.size()-1; i>=0; i--) {
2925 receivers.get(i).setPackageName(newName);
2926 }
2927 for (int i=providers.size()-1; i>=0; i--) {
2928 providers.get(i).setPackageName(newName);
2929 }
2930 for (int i=services.size()-1; i>=0; i--) {
2931 services.get(i).setPackageName(newName);
2932 }
2933 for (int i=instrumentation.size()-1; i>=0; i--) {
2934 instrumentation.get(i).setPackageName(newName);
2935 }
2936 }
2937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 public String toString() {
2939 return "Package{"
2940 + Integer.toHexString(System.identityHashCode(this))
2941 + " " + packageName + "}";
2942 }
2943 }
2944
2945 public static class Component<II extends IntentInfo> {
2946 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002947 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002948 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 public Bundle metaData;
2950
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002951 ComponentName componentName;
2952 String componentShortName;
2953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 public Component(Package _owner) {
2955 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002956 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002957 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002958 }
2959
2960 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2961 owner = args.owner;
2962 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002963 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002964 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002965 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002966 args.outError[0] = args.tag + " does not specify android:name";
2967 return;
2968 }
2969
2970 outInfo.name
2971 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2972 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002973 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002974 args.outError[0] = args.tag + " does not have valid android:name";
2975 return;
2976 }
2977
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002978 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002979
2980 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2981 if (iconVal != 0) {
2982 outInfo.icon = iconVal;
2983 outInfo.nonLocalizedLabel = null;
2984 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002985
2986 int logoVal = args.sa.getResourceId(args.logoRes, 0);
2987 if (logoVal != 0) {
2988 outInfo.logo = logoVal;
2989 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002990
2991 TypedValue v = args.sa.peekValue(args.labelRes);
2992 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2993 outInfo.nonLocalizedLabel = v.coerceToString();
2994 }
2995
2996 outInfo.packageName = owner.packageName;
2997 }
2998
2999 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3000 this(args, (PackageItemInfo)outInfo);
3001 if (args.outError[0] != null) {
3002 return;
3003 }
3004
3005 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003006 CharSequence pname;
3007 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3008 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3009 } else {
3010 // Some older apps have been seen to use a resource reference
3011 // here that on older builds was ignored (with a warning). We
3012 // need to continue to do this for them so they don't break.
3013 pname = args.sa.getNonResourceString(args.processRes);
3014 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003015 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003016 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003017 args.flags, args.sepProcesses, args.outError);
3018 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003019
3020 if (args.descriptionRes != 0) {
3021 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3022 }
3023
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003024 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 }
3026
3027 public Component(Component<II> clone) {
3028 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003029 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003030 className = clone.className;
3031 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003032 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003033 }
3034
3035 public ComponentName getComponentName() {
3036 if (componentName != null) {
3037 return componentName;
3038 }
3039 if (className != null) {
3040 componentName = new ComponentName(owner.applicationInfo.packageName,
3041 className);
3042 }
3043 return componentName;
3044 }
3045
3046 public String getComponentShortName() {
3047 if (componentShortName != null) {
3048 return componentShortName;
3049 }
3050 ComponentName component = getComponentName();
3051 if (component != null) {
3052 componentShortName = component.flattenToShortString();
3053 }
3054 return componentShortName;
3055 }
3056
3057 public void setPackageName(String packageName) {
3058 componentName = null;
3059 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
3061 }
3062
3063 public final static class Permission extends Component<IntentInfo> {
3064 public final PermissionInfo info;
3065 public boolean tree;
3066 public PermissionGroup group;
3067
3068 public Permission(Package _owner) {
3069 super(_owner);
3070 info = new PermissionInfo();
3071 }
3072
3073 public Permission(Package _owner, PermissionInfo _info) {
3074 super(_owner);
3075 info = _info;
3076 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003077
3078 public void setPackageName(String packageName) {
3079 super.setPackageName(packageName);
3080 info.packageName = packageName;
3081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082
3083 public String toString() {
3084 return "Permission{"
3085 + Integer.toHexString(System.identityHashCode(this))
3086 + " " + info.name + "}";
3087 }
3088 }
3089
3090 public final static class PermissionGroup extends Component<IntentInfo> {
3091 public final PermissionGroupInfo info;
3092
3093 public PermissionGroup(Package _owner) {
3094 super(_owner);
3095 info = new PermissionGroupInfo();
3096 }
3097
3098 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3099 super(_owner);
3100 info = _info;
3101 }
3102
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003103 public void setPackageName(String packageName) {
3104 super.setPackageName(packageName);
3105 info.packageName = packageName;
3106 }
3107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003108 public String toString() {
3109 return "PermissionGroup{"
3110 + Integer.toHexString(System.identityHashCode(this))
3111 + " " + info.name + "}";
3112 }
3113 }
3114
3115 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003116 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3117 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3118 if (p.applicationInfo.enabled != enabled) {
3119 return true;
3120 }
3121 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 if ((flags & PackageManager.GET_META_DATA) != 0
3123 && (metaData != null || p.mAppMetaData != null)) {
3124 return true;
3125 }
3126 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3127 && p.usesLibraryFiles != null) {
3128 return true;
3129 }
3130 return false;
3131 }
3132
3133 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3134 if (p == null) return null;
3135 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003136 // CompatibilityMode is global state. It's safe to modify the instance
3137 // of the package.
3138 if (!sCompatibilityModeEnabled) {
3139 p.applicationInfo.disableCompatibilityMode();
3140 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003141 if (p.mSetStopped) {
3142 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3143 } else {
3144 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 return p.applicationInfo;
3147 }
3148
3149 // Make shallow copy so we can store the metadata/libraries safely
3150 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3151 if ((flags & PackageManager.GET_META_DATA) != 0) {
3152 ai.metaData = p.mAppMetaData;
3153 }
3154 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3155 ai.sharedLibraryFiles = p.usesLibraryFiles;
3156 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003157 if (!sCompatibilityModeEnabled) {
3158 ai.disableCompatibilityMode();
3159 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003160 if (p.mSetStopped) {
3161 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3162 } else {
3163 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3164 }
John Reck4b7b7cc2011-02-02 11:57:44 -08003165 if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3166 ai.enabled = true;
Dianne Hackborn0ac30312011-06-17 14:49:23 -07003167 } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3168 || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003169 ai.enabled = false;
3170 }
Dianne Hackborn0ac30312011-06-17 14:49:23 -07003171 ai.enabledSetting = p.mSetEnabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 return ai;
3173 }
3174
3175 public static final PermissionInfo generatePermissionInfo(
3176 Permission p, int flags) {
3177 if (p == null) return null;
3178 if ((flags&PackageManager.GET_META_DATA) == 0) {
3179 return p.info;
3180 }
3181 PermissionInfo pi = new PermissionInfo(p.info);
3182 pi.metaData = p.metaData;
3183 return pi;
3184 }
3185
3186 public static final PermissionGroupInfo generatePermissionGroupInfo(
3187 PermissionGroup pg, int flags) {
3188 if (pg == null) return null;
3189 if ((flags&PackageManager.GET_META_DATA) == 0) {
3190 return pg.info;
3191 }
3192 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3193 pgi.metaData = pg.metaData;
3194 return pgi;
3195 }
3196
3197 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003198 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003200 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3201 super(args, _info);
3202 info = _info;
3203 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003205
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003206 public void setPackageName(String packageName) {
3207 super.setPackageName(packageName);
3208 info.packageName = packageName;
3209 }
3210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 public String toString() {
3212 return "Activity{"
3213 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003214 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 }
3216 }
3217
3218 public static final ActivityInfo generateActivityInfo(Activity a,
3219 int flags) {
3220 if (a == null) return null;
3221 if (!copyNeeded(flags, a.owner, a.metaData)) {
3222 return a.info;
3223 }
3224 // Make shallow copies so we can store the metadata safely
3225 ActivityInfo ai = new ActivityInfo(a.info);
3226 ai.metaData = a.metaData;
3227 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3228 return ai;
3229 }
3230
3231 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003232 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003234 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3235 super(args, _info);
3236 info = _info;
3237 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003239
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003240 public void setPackageName(String packageName) {
3241 super.setPackageName(packageName);
3242 info.packageName = packageName;
3243 }
3244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 public String toString() {
3246 return "Service{"
3247 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003248 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 }
3250 }
3251
3252 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3253 if (s == null) return null;
3254 if (!copyNeeded(flags, s.owner, s.metaData)) {
3255 return s.info;
3256 }
3257 // Make shallow copies so we can store the metadata safely
3258 ServiceInfo si = new ServiceInfo(s.info);
3259 si.metaData = s.metaData;
3260 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3261 return si;
3262 }
3263
3264 public final static class Provider extends Component {
3265 public final ProviderInfo info;
3266 public boolean syncable;
3267
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003268 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3269 super(args, _info);
3270 info = _info;
3271 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 syncable = false;
3273 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 public Provider(Provider existingProvider) {
3276 super(existingProvider);
3277 this.info = existingProvider.info;
3278 this.syncable = existingProvider.syncable;
3279 }
3280
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003281 public void setPackageName(String packageName) {
3282 super.setPackageName(packageName);
3283 info.packageName = packageName;
3284 }
3285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 public String toString() {
3287 return "Provider{"
3288 + Integer.toHexString(System.identityHashCode(this))
3289 + " " + info.name + "}";
3290 }
3291 }
3292
3293 public static final ProviderInfo generateProviderInfo(Provider p,
3294 int flags) {
3295 if (p == null) return null;
3296 if (!copyNeeded(flags, p.owner, p.metaData)
3297 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3298 || p.info.uriPermissionPatterns == null)) {
3299 return p.info;
3300 }
3301 // Make shallow copies so we can store the metadata safely
3302 ProviderInfo pi = new ProviderInfo(p.info);
3303 pi.metaData = p.metaData;
3304 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3305 pi.uriPermissionPatterns = null;
3306 }
3307 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3308 return pi;
3309 }
3310
3311 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003312 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003314 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3315 super(args, _info);
3316 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003318
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003319 public void setPackageName(String packageName) {
3320 super.setPackageName(packageName);
3321 info.packageName = packageName;
3322 }
3323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 public String toString() {
3325 return "Instrumentation{"
3326 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003327 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 }
3329 }
3330
3331 public static final InstrumentationInfo generateInstrumentationInfo(
3332 Instrumentation i, int flags) {
3333 if (i == null) return null;
3334 if ((flags&PackageManager.GET_META_DATA) == 0) {
3335 return i.info;
3336 }
3337 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3338 ii.metaData = i.metaData;
3339 return ii;
3340 }
3341
3342 public static class IntentInfo extends IntentFilter {
3343 public boolean hasDefault;
3344 public int labelRes;
3345 public CharSequence nonLocalizedLabel;
3346 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003347 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 }
3349
3350 public final static class ActivityIntentInfo extends IntentInfo {
3351 public final Activity activity;
3352
3353 public ActivityIntentInfo(Activity _activity) {
3354 activity = _activity;
3355 }
3356
3357 public String toString() {
3358 return "ActivityIntentInfo{"
3359 + Integer.toHexString(System.identityHashCode(this))
3360 + " " + activity.info.name + "}";
3361 }
3362 }
3363
3364 public final static class ServiceIntentInfo extends IntentInfo {
3365 public final Service service;
3366
3367 public ServiceIntentInfo(Service _service) {
3368 service = _service;
3369 }
3370
3371 public String toString() {
3372 return "ServiceIntentInfo{"
3373 + Integer.toHexString(System.identityHashCode(this))
3374 + " " + service.info.name + "}";
3375 }
3376 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003377
3378 /**
3379 * @hide
3380 */
3381 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3382 sCompatibilityModeEnabled = compatibilityModeEnabled;
3383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384}