blob: e7b844c4808bad64c436f65bc44784be3f061277 [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;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -070095 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070096 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
97 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
98 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
100 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
101
102 private static final Object mSync = new Object();
103 private static WeakReference<byte[]> mReadBuffer;
104
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700105 private static boolean sCompatibilityModeEnabled = true;
106 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700107
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700108 static class ParsePackageItemArgs {
109 final Package owner;
110 final String[] outError;
111 final int nameRes;
112 final int labelRes;
113 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700114 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700115
116 String tag;
117 TypedArray sa;
118
119 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700120 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700121 owner = _owner;
122 outError = _outError;
123 nameRes = _nameRes;
124 labelRes = _labelRes;
125 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700126 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700127 }
128 }
129
130 static class ParseComponentArgs extends ParsePackageItemArgs {
131 final String[] sepProcesses;
132 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800133 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700134 final int enabledRes;
135 int flags;
136
137 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700138 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800139 String[] _sepProcesses, int _processRes,
140 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700141 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700142 sepProcesses = _sepProcesses;
143 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800144 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700145 enabledRes = _enabledRes;
146 }
147 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800148
149 /* Light weight package info.
150 * @hide
151 */
152 public static class PackageLite {
153 public String packageName;
154 public int installLocation;
155 public String mScanPath;
156 public PackageLite(String packageName, int installLocation) {
157 this.packageName = packageName;
158 this.installLocation = installLocation;
159 }
160 }
161
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700162 private ParsePackageItemArgs mParseInstrumentationArgs;
163 private ParseComponentArgs mParseActivityArgs;
164 private ParseComponentArgs mParseActivityAliasArgs;
165 private ParseComponentArgs mParseServiceArgs;
166 private ParseComponentArgs mParseProviderArgs;
167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** If set to true, we will only allow package files that exactly match
169 * the DTD. Otherwise, we try to get as much from the package as we
170 * can without failing. This should normally be set to false, to
171 * support extensions to the DTD in future versions. */
172 private static final boolean RIGID_PARSER = false;
173
174 private static final String TAG = "PackageParser";
175
176 public PackageParser(String archiveSourcePath) {
177 mArchiveSourcePath = archiveSourcePath;
178 }
179
180 public void setSeparateProcesses(String[] procs) {
181 mSeparateProcesses = procs;
182 }
183
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700184 public void setOnlyCoreApps(boolean onlyCoreApps) {
185 mOnlyCoreApps = onlyCoreApps;
186 }
187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 private static final boolean isPackageFilename(String name) {
189 return name.endsWith(".apk");
190 }
191
192 /**
193 * Generate and return the {@link PackageInfo} for a parsed package.
194 *
195 * @param p the parsed package.
196 * @param flags indicating which optional information is included.
197 */
198 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborn78d68832010-10-07 01:12:46 -0700199 int gids[], int flags, long firstInstallTime, long lastUpdateTime) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
201 PackageInfo pi = new PackageInfo();
202 pi.packageName = p.packageName;
203 pi.versionCode = p.mVersionCode;
204 pi.versionName = p.mVersionName;
205 pi.sharedUserId = p.mSharedUserId;
206 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborne4a59512010-12-07 11:08:07 -0800207 pi.applicationInfo = generateApplicationInfo(p, flags);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800208 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700209 pi.firstInstallTime = firstInstallTime;
210 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 if ((flags&PackageManager.GET_GIDS) != 0) {
212 pi.gids = gids;
213 }
214 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
215 int N = p.configPreferences.size();
216 if (N > 0) {
217 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700218 p.configPreferences.toArray(pi.configPreferences);
219 }
220 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
221 if (N > 0) {
222 pi.reqFeatures = new FeatureInfo[N];
223 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225 }
226 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
227 int N = p.activities.size();
228 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700229 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
230 pi.activities = new ActivityInfo[N];
231 } else {
232 int num = 0;
233 for (int i=0; i<N; i++) {
234 if (p.activities.get(i).info.enabled) num++;
235 }
236 pi.activities = new ActivityInfo[num];
237 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700238 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 final Activity activity = p.activities.get(i);
240 if (activity.info.enabled
241 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700242 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244 }
245 }
246 }
247 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
248 int N = p.receivers.size();
249 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700250 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
251 pi.receivers = new ActivityInfo[N];
252 } else {
253 int num = 0;
254 for (int i=0; i<N; i++) {
255 if (p.receivers.get(i).info.enabled) num++;
256 }
257 pi.receivers = new ActivityInfo[num];
258 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700259 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 final Activity activity = p.receivers.get(i);
261 if (activity.info.enabled
262 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700263 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 }
265 }
266 }
267 }
268 if ((flags&PackageManager.GET_SERVICES) != 0) {
269 int N = p.services.size();
270 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700271 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
272 pi.services = new ServiceInfo[N];
273 } else {
274 int num = 0;
275 for (int i=0; i<N; i++) {
276 if (p.services.get(i).info.enabled) num++;
277 }
278 pi.services = new ServiceInfo[num];
279 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700280 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final Service service = p.services.get(i);
282 if (service.info.enabled
283 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700284 pi.services[j++] = generateServiceInfo(p.services.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286 }
287 }
288 }
289 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
290 int N = p.providers.size();
291 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700292 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
293 pi.providers = new ProviderInfo[N];
294 } else {
295 int num = 0;
296 for (int i=0; i<N; i++) {
297 if (p.providers.get(i).info.enabled) num++;
298 }
299 pi.providers = new ProviderInfo[num];
300 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700301 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 final Provider provider = p.providers.get(i);
303 if (provider.info.enabled
304 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700305 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 }
307 }
308 }
309 }
310 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
311 int N = p.instrumentation.size();
312 if (N > 0) {
313 pi.instrumentation = new InstrumentationInfo[N];
314 for (int i=0; i<N; i++) {
315 pi.instrumentation[i] = generateInstrumentationInfo(
316 p.instrumentation.get(i), flags);
317 }
318 }
319 }
320 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
321 int N = p.permissions.size();
322 if (N > 0) {
323 pi.permissions = new PermissionInfo[N];
324 for (int i=0; i<N; i++) {
325 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
326 }
327 }
328 N = p.requestedPermissions.size();
329 if (N > 0) {
330 pi.requestedPermissions = new String[N];
331 for (int i=0; i<N; i++) {
332 pi.requestedPermissions[i] = p.requestedPermissions.get(i);
333 }
334 }
335 }
336 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700337 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
338 if (N > 0) {
339 pi.signatures = new Signature[N];
340 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 }
342 }
343 return pi;
344 }
345
346 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
347 byte[] readBuffer) {
348 try {
349 // We must read the stream for the JarEntry to retrieve
350 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700351 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
353 // not using
354 }
355 is.close();
356 return je != null ? je.getCertificates() : null;
357 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700358 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700360 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700361 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700362 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364 return null;
365 }
366
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800367 public final static int PARSE_IS_SYSTEM = 1<<0;
368 public final static int PARSE_CHATTY = 1<<1;
369 public final static int PARSE_MUST_BE_APK = 1<<2;
370 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
371 public final static int PARSE_FORWARD_LOCK = 1<<4;
372 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700373 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374
375 public int getParseError() {
376 return mParseError;
377 }
378
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800379 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 DisplayMetrics metrics, int flags) {
381 mParseError = PackageManager.INSTALL_SUCCEEDED;
382
383 mArchiveSourcePath = sourceFile.getPath();
384 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700385 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
387 return null;
388 }
389 if (!isPackageFilename(sourceFile.getName())
390 && (flags&PARSE_MUST_BE_APK) != 0) {
391 if ((flags&PARSE_IS_SYSTEM) == 0) {
392 // We expect to have non-.apk files in the system dir,
393 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700394 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 }
396 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
397 return null;
398 }
399
Kenny Rootd2d29252011-08-08 11:27:57 -0700400 if (DEBUG_JAR)
401 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402
403 XmlResourceParser parser = null;
404 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800405 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean assetError = true;
407 try {
408 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700409 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800410 if (cookie != 0) {
411 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700412 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 -0800413 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700414 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 assetError = false;
416 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700417 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 }
419 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700420 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 + mArchiveSourcePath, e);
422 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800423 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 if (assmgr != null) assmgr.close();
425 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
426 return null;
427 }
428 String[] errorText = new String[1];
429 Package pkg = null;
430 Exception errorException = null;
431 try {
432 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 pkg = parsePackage(res, parser, flags, errorText);
434 } catch (Exception e) {
435 errorException = e;
436 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
437 }
438
439
440 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700441 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
442 // just means to skip this app so don't make a fuss about it.
443 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
444 if (errorException != null) {
445 Slog.w(TAG, mArchiveSourcePath, errorException);
446 } else {
447 Slog.w(TAG, mArchiveSourcePath + " (at "
448 + parser.getPositionDescription()
449 + "): " + errorText[0]);
450 }
451 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
452 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
453 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 }
455 parser.close();
456 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 return null;
458 }
459
460 parser.close();
461 assmgr.close();
462
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800463 // Set code and resource paths
464 pkg.mPath = destCodePath;
465 pkg.mScanPath = mArchiveSourcePath;
466 //pkg.applicationInfo.sourceDir = destCodePath;
467 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 pkg.mSignatures = null;
469
470 return pkg;
471 }
472
473 public boolean collectCertificates(Package pkg, int flags) {
474 pkg.mSignatures = null;
475
476 WeakReference<byte[]> readBufferRef;
477 byte[] readBuffer = null;
478 synchronized (mSync) {
479 readBufferRef = mReadBuffer;
480 if (readBufferRef != null) {
481 mReadBuffer = null;
482 readBuffer = readBufferRef.get();
483 }
484 if (readBuffer == null) {
485 readBuffer = new byte[8192];
486 readBufferRef = new WeakReference<byte[]>(readBuffer);
487 }
488 }
489
490 try {
491 JarFile jarFile = new JarFile(mArchiveSourcePath);
492
493 Certificate[] certs = null;
494
495 if ((flags&PARSE_IS_SYSTEM) != 0) {
496 // If this package comes from the system image, then we
497 // can trust it... we'll just use the AndroidManifest.xml
498 // to retrieve its signatures, not validating all of the
499 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700500 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 certs = loadCertificates(jarFile, jarEntry, readBuffer);
502 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700503 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 + " has no certificates at entry "
505 + jarEntry.getName() + "; ignoring!");
506 jarFile.close();
507 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
508 return false;
509 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700510 if (DEBUG_JAR) {
511 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 + " certs=" + (certs != null ? certs.length : 0));
513 if (certs != null) {
514 final int N = certs.length;
515 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700516 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 + certs[i].getPublicKey().getEncoded()
518 + " " + certs[i].getPublicKey());
519 }
520 }
521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700523 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700524 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700526 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700528
Kenny Rootbcc954d2011-08-08 16:19:08 -0700529 final String name = je.getName();
530
531 if (name.startsWith("META-INF/"))
532 continue;
533
534 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
535 final Attributes attributes = manifest.getAttributes(name);
536 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
537 }
538
539 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700540 if (DEBUG_JAR) {
541 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 + ": certs=" + certs + " ("
543 + (certs != null ? certs.length : 0) + ")");
544 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700547 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 + " has no certificates at entry "
549 + je.getName() + "; ignoring!");
550 jarFile.close();
551 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
552 return false;
553 } else if (certs == null) {
554 certs = localCerts;
555 } else {
556 // Ensure all certificates match.
557 for (int i=0; i<certs.length; i++) {
558 boolean found = false;
559 for (int j=0; j<localCerts.length; j++) {
560 if (certs[i] != null &&
561 certs[i].equals(localCerts[j])) {
562 found = true;
563 break;
564 }
565 }
566 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700567 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 + " has mismatched certificates at entry "
569 + je.getName() + "; ignoring!");
570 jarFile.close();
571 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
572 return false;
573 }
574 }
575 }
576 }
577 }
578 jarFile.close();
579
580 synchronized (mSync) {
581 mReadBuffer = readBufferRef;
582 }
583
584 if (certs != null && certs.length > 0) {
585 final int N = certs.length;
586 pkg.mSignatures = new Signature[certs.length];
587 for (int i=0; i<N; i++) {
588 pkg.mSignatures[i] = new Signature(
589 certs[i].getEncoded());
590 }
591 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700592 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 + " has no certificates; ignoring!");
594 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
595 return false;
596 }
597 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700598 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
600 return false;
601 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700602 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
604 return false;
605 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700606 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
608 return false;
609 }
610
611 return true;
612 }
613
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800614 /*
615 * Utility method that retrieves just the package name and install
616 * location from the apk location at the given file path.
617 * @param packageFilePath file location of the apk
618 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700619 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800620 */
621 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 XmlResourceParser parser = null;
623 AssetManager assmgr = null;
624 try {
625 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700626 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 -0800627 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700630 if (cookie == 0) {
631 return null;
632 }
633
Kenny Rootbcc954d2011-08-08 16:19:08 -0700634 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 } catch (Exception e) {
636 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700637 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 + packageFilePath, e);
639 return null;
640 }
641 AttributeSet attrs = parser;
642 String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800643 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 try {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800645 packageLite = parsePackageLite(parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700647 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700649 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 } finally {
651 if (parser != null) parser.close();
652 if (assmgr != null) assmgr.close();
653 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800654 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700655 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 return null;
657 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800658 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
661 private static String validateName(String name, boolean requiresSeparator) {
662 final int N = name.length();
663 boolean hasSep = false;
664 boolean front = true;
665 for (int i=0; i<N; i++) {
666 final char c = name.charAt(i);
667 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
668 front = false;
669 continue;
670 }
671 if (!front) {
672 if ((c >= '0' && c <= '9') || c == '_') {
673 continue;
674 }
675 }
676 if (c == '.') {
677 hasSep = true;
678 front = true;
679 continue;
680 }
681 return "bad character '" + c + "'";
682 }
683 return hasSep || !requiresSeparator
684 ? null : "must have at least one '.' separator";
685 }
686
687 private static String parsePackageName(XmlPullParser parser,
688 AttributeSet attrs, int flags, String[] outError)
689 throws IOException, XmlPullParserException {
690
691 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700692 while ((type = parser.next()) != XmlPullParser.START_TAG
693 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 ;
695 }
696
Kenny Rootd2d29252011-08-08 11:27:57 -0700697 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 outError[0] = "No start tag found";
699 return null;
700 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700701 if (DEBUG_PARSER)
702 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 if (!parser.getName().equals("manifest")) {
704 outError[0] = "No <manifest> tag";
705 return null;
706 }
707 String pkgName = attrs.getAttributeValue(null, "package");
708 if (pkgName == null || pkgName.length() == 0) {
709 outError[0] = "<manifest> does not specify package";
710 return null;
711 }
712 String nameError = validateName(pkgName, true);
713 if (nameError != null && !"android".equals(pkgName)) {
714 outError[0] = "<manifest> specifies bad package name \""
715 + pkgName + "\": " + nameError;
716 return null;
717 }
718
719 return pkgName.intern();
720 }
721
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800722 private static PackageLite parsePackageLite(XmlPullParser parser,
723 AttributeSet attrs, int flags, String[] outError)
724 throws IOException, XmlPullParserException {
725
726 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700727 while ((type = parser.next()) != XmlPullParser.START_TAG
728 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800729 ;
730 }
731
Kenny Rootd2d29252011-08-08 11:27:57 -0700732 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800733 outError[0] = "No start tag found";
734 return null;
735 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700736 if (DEBUG_PARSER)
737 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800738 if (!parser.getName().equals("manifest")) {
739 outError[0] = "No <manifest> tag";
740 return null;
741 }
742 String pkgName = attrs.getAttributeValue(null, "package");
743 if (pkgName == null || pkgName.length() == 0) {
744 outError[0] = "<manifest> does not specify package";
745 return null;
746 }
747 String nameError = validateName(pkgName, true);
748 if (nameError != null && !"android".equals(pkgName)) {
749 outError[0] = "<manifest> specifies bad package name \""
750 + pkgName + "\": " + nameError;
751 return null;
752 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700753 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800754 for (int i = 0; i < attrs.getAttributeCount(); i++) {
755 String attr = attrs.getAttributeName(i);
756 if (attr.equals("installLocation")) {
757 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700758 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800759 break;
760 }
761 }
762 return new PackageLite(pkgName.intern(), installLocation);
763 }
764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 /**
766 * Temporary.
767 */
768 static public Signature stringToSignature(String str) {
769 final int N = str.length();
770 byte[] sig = new byte[N];
771 for (int i=0; i<N; i++) {
772 sig[i] = (byte)str.charAt(i);
773 }
774 return new Signature(sig);
775 }
776
777 private Package parsePackage(
778 Resources res, XmlResourceParser parser, int flags, String[] outError)
779 throws XmlPullParserException, IOException {
780 AttributeSet attrs = parser;
781
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700782 mParseInstrumentationArgs = null;
783 mParseActivityArgs = null;
784 mParseServiceArgs = null;
785 mParseProviderArgs = null;
786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 String pkgName = parsePackageName(parser, attrs, flags, outError);
788 if (pkgName == null) {
789 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
790 return null;
791 }
792 int type;
793
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700794 if (mOnlyCoreApps) {
795 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
796 if (!core) {
797 mParseError = PackageManager.INSTALL_SUCCEEDED;
798 return null;
799 }
800 }
801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 TypedArray sa = res.obtainAttributes(attrs,
806 com.android.internal.R.styleable.AndroidManifest);
807 pkg.mVersionCode = sa.getInteger(
808 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800809 pkg.mVersionName = sa.getNonConfigurationString(
810 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 if (pkg.mVersionName != null) {
812 pkg.mVersionName = pkg.mVersionName.intern();
813 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800814 String str = sa.getNonConfigurationString(
815 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
816 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 String nameError = validateName(str, true);
818 if (nameError != null && !"android".equals(pkgName)) {
819 outError[0] = "<manifest> specifies bad sharedUserId name \""
820 + str + "\": " + nameError;
821 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
822 return null;
823 }
824 pkg.mSharedUserId = str.intern();
825 pkg.mSharedUserLabel = sa.getResourceId(
826 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
827 }
828 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800829
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800830 pkg.installLocation = sa.getInteger(
831 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700832 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700833 pkg.applicationInfo.installLocation = pkg.installLocation;
834
Dianne Hackborn723738c2009-06-25 19:48:04 -0700835 // Resource boolean are -1, so 1 means we don't know the value.
836 int supportsSmallScreens = 1;
837 int supportsNormalScreens = 1;
838 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700839 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700840 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700841 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700844 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
845 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
846 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 continue;
848 }
849
850 String tagName = parser.getName();
851 if (tagName.equals("application")) {
852 if (foundApp) {
853 if (RIGID_PARSER) {
854 outError[0] = "<manifest> has more than one <application>";
855 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
856 return null;
857 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700858 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 XmlUtils.skipCurrentTag(parser);
860 continue;
861 }
862 }
863
864 foundApp = true;
865 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
866 return null;
867 }
868 } else if (tagName.equals("permission-group")) {
869 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
870 return null;
871 }
872 } else if (tagName.equals("permission")) {
873 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
874 return null;
875 }
876 } else if (tagName.equals("permission-tree")) {
877 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
878 return null;
879 }
880 } else if (tagName.equals("uses-permission")) {
881 sa = res.obtainAttributes(attrs,
882 com.android.internal.R.styleable.AndroidManifestUsesPermission);
883
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800884 // Note: don't allow this value to be a reference to a resource
885 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 String name = sa.getNonResourceString(
887 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
888
889 sa.recycle();
890
891 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700892 pkg.requestedPermissions.add(name.intern());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 }
894
895 XmlUtils.skipCurrentTag(parser);
896
897 } else if (tagName.equals("uses-configuration")) {
898 ConfigurationInfo cPref = new ConfigurationInfo();
899 sa = res.obtainAttributes(attrs,
900 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
901 cPref.reqTouchScreen = sa.getInt(
902 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
903 Configuration.TOUCHSCREEN_UNDEFINED);
904 cPref.reqKeyboardType = sa.getInt(
905 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
906 Configuration.KEYBOARD_UNDEFINED);
907 if (sa.getBoolean(
908 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
909 false)) {
910 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
911 }
912 cPref.reqNavigation = sa.getInt(
913 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
914 Configuration.NAVIGATION_UNDEFINED);
915 if (sa.getBoolean(
916 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
917 false)) {
918 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
919 }
920 sa.recycle();
921 pkg.configPreferences.add(cPref);
922
923 XmlUtils.skipCurrentTag(parser);
924
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700925 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -0700926 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700927 sa = res.obtainAttributes(attrs,
928 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800929 // Note: don't allow this value to be a reference to a resource
930 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -0700931 fi.name = sa.getNonResourceString(
932 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
933 if (fi.name == null) {
934 fi.reqGlEsVersion = sa.getInt(
935 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
936 FeatureInfo.GL_ES_VERSION_UNDEFINED);
937 }
938 if (sa.getBoolean(
939 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
940 true)) {
941 fi.flags |= FeatureInfo.FLAG_REQUIRED;
942 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700943 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -0700944 if (pkg.reqFeatures == null) {
945 pkg.reqFeatures = new ArrayList<FeatureInfo>();
946 }
947 pkg.reqFeatures.add(fi);
948
949 if (fi.name == null) {
950 ConfigurationInfo cPref = new ConfigurationInfo();
951 cPref.reqGlEsVersion = fi.reqGlEsVersion;
952 pkg.configPreferences.add(cPref);
953 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -0700954
955 XmlUtils.skipCurrentTag(parser);
956
Dianne Hackborn851a5412009-05-08 12:06:44 -0700957 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700958 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 sa = res.obtainAttributes(attrs,
960 com.android.internal.R.styleable.AndroidManifestUsesSdk);
961
Dianne Hackborn851a5412009-05-08 12:06:44 -0700962 int minVers = 0;
963 String minCode = null;
964 int targetVers = 0;
965 String targetCode = null;
966
967 TypedValue val = sa.peekValue(
968 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
969 if (val != null) {
970 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
971 targetCode = minCode = val.string.toString();
972 } else {
973 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700974 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700975 }
976 }
977
978 val = sa.peekValue(
979 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
980 if (val != null) {
981 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
982 targetCode = minCode = val.string.toString();
983 } else {
984 // If it's not a string, it's an integer.
985 targetVers = val.data;
986 }
987 }
988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 sa.recycle();
990
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700991 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700992 if (!minCode.equals(SDK_CODENAME)) {
993 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700994 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700995 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700996 } else {
997 outError[0] = "Requires development platform " + minCode
998 + " but this is a release platform.";
999 }
1000 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1001 return null;
1002 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001003 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001004 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001005 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001006 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1007 return null;
1008 }
1009
Dianne Hackborn851a5412009-05-08 12:06:44 -07001010 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001011 if (!targetCode.equals(SDK_CODENAME)) {
1012 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001013 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001014 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001015 } else {
1016 outError[0] = "Requires development platform " + targetCode
1017 + " but this is a release platform.";
1018 }
1019 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1020 return null;
1021 }
1022 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001023 pkg.applicationInfo.targetSdkVersion
1024 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1025 } else {
1026 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
1029
1030 XmlUtils.skipCurrentTag(parser);
1031
Dianne Hackborn723738c2009-06-25 19:48:04 -07001032 } else if (tagName.equals("supports-screens")) {
1033 sa = res.obtainAttributes(attrs,
1034 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1035
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001036 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1037 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1038 0);
1039 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1040 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1041 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001042 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1043 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1044 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001045
Dianne Hackborn723738c2009-06-25 19:48:04 -07001046 // This is a trick to get a boolean and still able to detect
1047 // if a value was actually set.
1048 supportsSmallScreens = sa.getInteger(
1049 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1050 supportsSmallScreens);
1051 supportsNormalScreens = sa.getInteger(
1052 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1053 supportsNormalScreens);
1054 supportsLargeScreens = sa.getInteger(
1055 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1056 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001057 supportsXLargeScreens = sa.getInteger(
1058 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1059 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001060 resizeable = sa.getInteger(
1061 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001062 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001063 anyDensity = sa.getInteger(
1064 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1065 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001066
1067 sa.recycle();
1068
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001069 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001070
1071 } else if (tagName.equals("protected-broadcast")) {
1072 sa = res.obtainAttributes(attrs,
1073 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1074
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001075 // Note: don't allow this value to be a reference to a resource
1076 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001077 String name = sa.getNonResourceString(
1078 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1079
1080 sa.recycle();
1081
1082 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1083 if (pkg.protectedBroadcasts == null) {
1084 pkg.protectedBroadcasts = new ArrayList<String>();
1085 }
1086 if (!pkg.protectedBroadcasts.contains(name)) {
1087 pkg.protectedBroadcasts.add(name.intern());
1088 }
1089 }
1090
1091 XmlUtils.skipCurrentTag(parser);
1092
1093 } else if (tagName.equals("instrumentation")) {
1094 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1095 return null;
1096 }
1097
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001098 } else if (tagName.equals("original-package")) {
1099 sa = res.obtainAttributes(attrs,
1100 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1101
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001102 String orig =sa.getNonConfigurationString(
1103 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001104 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001105 if (pkg.mOriginalPackages == null) {
1106 pkg.mOriginalPackages = new ArrayList<String>();
1107 pkg.mRealPackage = pkg.packageName;
1108 }
1109 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001110 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001111
1112 sa.recycle();
1113
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001114 XmlUtils.skipCurrentTag(parser);
1115
1116 } else if (tagName.equals("adopt-permissions")) {
1117 sa = res.obtainAttributes(attrs,
1118 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1119
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001120 String name = sa.getNonConfigurationString(
1121 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001122
1123 sa.recycle();
1124
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001125 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001126 if (pkg.mAdoptPermissions == null) {
1127 pkg.mAdoptPermissions = new ArrayList<String>();
1128 }
1129 pkg.mAdoptPermissions.add(name);
1130 }
1131
1132 XmlUtils.skipCurrentTag(parser);
1133
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001134 } else if (tagName.equals("uses-gl-texture")) {
1135 // Just skip this tag
1136 XmlUtils.skipCurrentTag(parser);
1137 continue;
1138
1139 } else if (tagName.equals("compatible-screens")) {
1140 // Just skip this tag
1141 XmlUtils.skipCurrentTag(parser);
1142 continue;
1143
Dianne Hackborn854060a2009-07-09 18:14:31 -07001144 } else if (tagName.equals("eat-comment")) {
1145 // Just skip this tag
1146 XmlUtils.skipCurrentTag(parser);
1147 continue;
1148
1149 } else if (RIGID_PARSER) {
1150 outError[0] = "Bad element under <manifest>: "
1151 + parser.getName();
1152 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1153 return null;
1154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001156 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001157 + " at " + mArchiveSourcePath + " "
1158 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 XmlUtils.skipCurrentTag(parser);
1160 continue;
1161 }
1162 }
1163
1164 if (!foundApp && pkg.instrumentation.size() == 0) {
1165 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1166 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1167 }
1168
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001169 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001170 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001171 for (int ip=0; ip<NP; ip++) {
1172 final PackageParser.NewPermissionInfo npi
1173 = PackageParser.NEW_PERMISSIONS[ip];
1174 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1175 break;
1176 }
1177 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001178 if (implicitPerms == null) {
1179 implicitPerms = new StringBuilder(128);
1180 implicitPerms.append(pkg.packageName);
1181 implicitPerms.append(": compat added ");
1182 } else {
1183 implicitPerms.append(' ');
1184 }
1185 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001186 pkg.requestedPermissions.add(npi.name);
1187 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001188 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001189 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001190 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001191 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001192
Dianne Hackborn723738c2009-06-25 19:48:04 -07001193 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1194 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001195 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001196 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1197 }
1198 if (supportsNormalScreens != 0) {
1199 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1200 }
1201 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1202 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001203 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001204 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1205 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001206 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1207 && pkg.applicationInfo.targetSdkVersion
1208 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1209 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1210 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001211 if (resizeable < 0 || (resizeable > 0
1212 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001213 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001214 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1215 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001216 if (anyDensity < 0 || (anyDensity > 0
1217 && pkg.applicationInfo.targetSdkVersion
1218 >= android.os.Build.VERSION_CODES.DONUT)) {
1219 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001220 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 return pkg;
1223 }
1224
1225 private static String buildClassName(String pkg, CharSequence clsSeq,
1226 String[] outError) {
1227 if (clsSeq == null || clsSeq.length() <= 0) {
1228 outError[0] = "Empty class name in package " + pkg;
1229 return null;
1230 }
1231 String cls = clsSeq.toString();
1232 char c = cls.charAt(0);
1233 if (c == '.') {
1234 return (pkg + cls).intern();
1235 }
1236 if (cls.indexOf('.') < 0) {
1237 StringBuilder b = new StringBuilder(pkg);
1238 b.append('.');
1239 b.append(cls);
1240 return b.toString().intern();
1241 }
1242 if (c >= 'a' && c <= 'z') {
1243 return cls.intern();
1244 }
1245 outError[0] = "Bad class name " + cls + " in package " + pkg;
1246 return null;
1247 }
1248
1249 private static String buildCompoundName(String pkg,
1250 CharSequence procSeq, String type, String[] outError) {
1251 String proc = procSeq.toString();
1252 char c = proc.charAt(0);
1253 if (pkg != null && c == ':') {
1254 if (proc.length() < 2) {
1255 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1256 + ": must be at least two characters";
1257 return null;
1258 }
1259 String subName = proc.substring(1);
1260 String nameError = validateName(subName, false);
1261 if (nameError != null) {
1262 outError[0] = "Invalid " + type + " name " + proc + " in package "
1263 + pkg + ": " + nameError;
1264 return null;
1265 }
1266 return (pkg + proc).intern();
1267 }
1268 String nameError = validateName(proc, true);
1269 if (nameError != null && !"system".equals(proc)) {
1270 outError[0] = "Invalid " + type + " name " + proc + " in package "
1271 + pkg + ": " + nameError;
1272 return null;
1273 }
1274 return proc.intern();
1275 }
1276
1277 private static String buildProcessName(String pkg, String defProc,
1278 CharSequence procSeq, int flags, String[] separateProcesses,
1279 String[] outError) {
1280 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1281 return defProc != null ? defProc : pkg;
1282 }
1283 if (separateProcesses != null) {
1284 for (int i=separateProcesses.length-1; i>=0; i--) {
1285 String sp = separateProcesses[i];
1286 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1287 return pkg;
1288 }
1289 }
1290 }
1291 if (procSeq == null || procSeq.length() <= 0) {
1292 return defProc;
1293 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001294 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 }
1296
1297 private static String buildTaskAffinityName(String pkg, String defProc,
1298 CharSequence procSeq, String[] outError) {
1299 if (procSeq == null) {
1300 return defProc;
1301 }
1302 if (procSeq.length() <= 0) {
1303 return null;
1304 }
1305 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1306 }
1307
1308 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1309 XmlPullParser parser, AttributeSet attrs, String[] outError)
1310 throws XmlPullParserException, IOException {
1311 PermissionGroup perm = new PermissionGroup(owner);
1312
1313 TypedArray sa = res.obtainAttributes(attrs,
1314 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1315
1316 if (!parsePackageItemInfo(owner, perm.info, outError,
1317 "<permission-group>", sa,
1318 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1319 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001320 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1321 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 sa.recycle();
1323 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1324 return null;
1325 }
1326
1327 perm.info.descriptionRes = sa.getResourceId(
1328 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1329 0);
1330
1331 sa.recycle();
1332
1333 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1334 outError)) {
1335 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1336 return null;
1337 }
1338
1339 owner.permissionGroups.add(perm);
1340
1341 return perm;
1342 }
1343
1344 private Permission parsePermission(Package owner, Resources res,
1345 XmlPullParser parser, AttributeSet attrs, String[] outError)
1346 throws XmlPullParserException, IOException {
1347 Permission perm = new Permission(owner);
1348
1349 TypedArray sa = res.obtainAttributes(attrs,
1350 com.android.internal.R.styleable.AndroidManifestPermission);
1351
1352 if (!parsePackageItemInfo(owner, perm.info, outError,
1353 "<permission>", sa,
1354 com.android.internal.R.styleable.AndroidManifestPermission_name,
1355 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001356 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1357 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 sa.recycle();
1359 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1360 return null;
1361 }
1362
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001363 // Note: don't allow this value to be a reference to a resource
1364 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 perm.info.group = sa.getNonResourceString(
1366 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1367 if (perm.info.group != null) {
1368 perm.info.group = perm.info.group.intern();
1369 }
1370
1371 perm.info.descriptionRes = sa.getResourceId(
1372 com.android.internal.R.styleable.AndroidManifestPermission_description,
1373 0);
1374
1375 perm.info.protectionLevel = sa.getInt(
1376 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1377 PermissionInfo.PROTECTION_NORMAL);
1378
1379 sa.recycle();
1380
1381 if (perm.info.protectionLevel == -1) {
1382 outError[0] = "<permission> does not specify protectionLevel";
1383 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1384 return null;
1385 }
1386
1387 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1388 outError)) {
1389 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1390 return null;
1391 }
1392
1393 owner.permissions.add(perm);
1394
1395 return perm;
1396 }
1397
1398 private Permission parsePermissionTree(Package owner, Resources res,
1399 XmlPullParser parser, AttributeSet attrs, String[] outError)
1400 throws XmlPullParserException, IOException {
1401 Permission perm = new Permission(owner);
1402
1403 TypedArray sa = res.obtainAttributes(attrs,
1404 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1405
1406 if (!parsePackageItemInfo(owner, perm.info, outError,
1407 "<permission-tree>", sa,
1408 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1409 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001410 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1411 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 sa.recycle();
1413 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1414 return null;
1415 }
1416
1417 sa.recycle();
1418
1419 int index = perm.info.name.indexOf('.');
1420 if (index > 0) {
1421 index = perm.info.name.indexOf('.', index+1);
1422 }
1423 if (index < 0) {
1424 outError[0] = "<permission-tree> name has less than three segments: "
1425 + perm.info.name;
1426 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1427 return null;
1428 }
1429
1430 perm.info.descriptionRes = 0;
1431 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1432 perm.tree = true;
1433
1434 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1435 outError)) {
1436 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1437 return null;
1438 }
1439
1440 owner.permissions.add(perm);
1441
1442 return perm;
1443 }
1444
1445 private Instrumentation parseInstrumentation(Package owner, Resources res,
1446 XmlPullParser parser, AttributeSet attrs, String[] outError)
1447 throws XmlPullParserException, IOException {
1448 TypedArray sa = res.obtainAttributes(attrs,
1449 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1450
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001451 if (mParseInstrumentationArgs == null) {
1452 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1453 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1454 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001455 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1456 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001457 mParseInstrumentationArgs.tag = "<instrumentation>";
1458 }
1459
1460 mParseInstrumentationArgs.sa = sa;
1461
1462 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1463 new InstrumentationInfo());
1464 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 sa.recycle();
1466 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1467 return null;
1468 }
1469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001471 // Note: don't allow this value to be a reference to a resource
1472 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 str = sa.getNonResourceString(
1474 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1475 a.info.targetPackage = str != null ? str.intern() : null;
1476
1477 a.info.handleProfiling = sa.getBoolean(
1478 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1479 false);
1480
1481 a.info.functionalTest = sa.getBoolean(
1482 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1483 false);
1484
1485 sa.recycle();
1486
1487 if (a.info.targetPackage == null) {
1488 outError[0] = "<instrumentation> does not specify targetPackage";
1489 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1490 return null;
1491 }
1492
1493 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1494 outError)) {
1495 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1496 return null;
1497 }
1498
1499 owner.instrumentation.add(a);
1500
1501 return a;
1502 }
1503
1504 private boolean parseApplication(Package owner, Resources res,
1505 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1506 throws XmlPullParserException, IOException {
1507 final ApplicationInfo ai = owner.applicationInfo;
1508 final String pkgName = owner.applicationInfo.packageName;
1509
1510 TypedArray sa = res.obtainAttributes(attrs,
1511 com.android.internal.R.styleable.AndroidManifestApplication);
1512
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001513 String name = sa.getNonConfigurationString(
1514 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 if (name != null) {
1516 ai.className = buildClassName(pkgName, name, outError);
1517 if (ai.className == null) {
1518 sa.recycle();
1519 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1520 return false;
1521 }
1522 }
1523
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001524 String manageSpaceActivity = sa.getNonConfigurationString(
1525 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 if (manageSpaceActivity != null) {
1527 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1528 outError);
1529 }
1530
Christopher Tate181fafa2009-05-14 11:12:14 -07001531 boolean allowBackup = sa.getBoolean(
1532 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1533 if (allowBackup) {
1534 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001535
Christopher Tate3de55bc2010-03-12 17:28:08 -08001536 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1537 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001538 String backupAgent = sa.getNonConfigurationString(
1539 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001540 if (backupAgent != null) {
1541 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001542 if (DEBUG_BACKUP) {
1543 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001544 + " from " + pkgName + "+" + backupAgent);
1545 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001546
1547 if (sa.getBoolean(
1548 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1549 true)) {
1550 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1551 }
1552 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001553 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1554 false)) {
1555 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1556 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001557 }
1558 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 TypedValue v = sa.peekValue(
1561 com.android.internal.R.styleable.AndroidManifestApplication_label);
1562 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1563 ai.nonLocalizedLabel = v.coerceToString();
1564 }
1565
1566 ai.icon = sa.getResourceId(
1567 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001568 ai.logo = sa.getResourceId(
1569 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001571 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 ai.descriptionRes = sa.getResourceId(
1573 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1574
1575 if ((flags&PARSE_IS_SYSTEM) != 0) {
1576 if (sa.getBoolean(
1577 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1578 false)) {
1579 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1580 }
1581 }
1582
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001583 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1584 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1585 }
1586
1587 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001588 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001589 }
1590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 if (sa.getBoolean(
1592 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1593 false)) {
1594 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1595 }
1596
1597 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001598 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001599 false)) {
1600 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1601 }
1602
Romain Guy529b60a2010-08-03 18:05:47 -07001603 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001604 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001605 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001606
1607 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1609 true)) {
1610 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1611 }
1612
1613 if (sa.getBoolean(
1614 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1615 false)) {
1616 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1617 }
1618
1619 if (sa.getBoolean(
1620 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1621 true)) {
1622 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1623 }
1624
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001625 if (sa.getBoolean(
1626 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001627 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001628 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1629 }
1630
Jason parksa3cdaa52011-01-13 14:15:43 -06001631 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001632 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001633 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001634 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001635 }
1636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001638 str = sa.getNonConfigurationString(
1639 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1641
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001642 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1643 str = sa.getNonConfigurationString(
1644 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1645 } else {
1646 // Some older apps have been seen to use a resource reference
1647 // here that on older builds was ignored (with a warning). We
1648 // need to continue to do this for them so they don't break.
1649 str = sa.getNonResourceString(
1650 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1653 str, outError);
1654
1655 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001656 CharSequence pname;
1657 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1658 pname = sa.getNonConfigurationString(
1659 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1660 } else {
1661 // Some older apps have been seen to use a resource reference
1662 // here that on older builds was ignored (with a warning). We
1663 // need to continue to do this for them so they don't break.
1664 pname = sa.getNonResourceString(
1665 com.android.internal.R.styleable.AndroidManifestApplication_process);
1666 }
1667 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 flags, mSeparateProcesses, outError);
1669
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001670 ai.enabled = sa.getBoolean(
1671 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001672
Dianne Hackborn02486b12010-08-26 14:18:37 -07001673 if (false) {
1674 if (sa.getBoolean(
1675 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1676 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001677 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001678
1679 // A heavy-weight application can not be in a custom process.
1680 // We can do direct compare because we intern all strings.
1681 if (ai.processName != null && ai.processName != ai.packageName) {
1682 outError[0] = "cantSaveState applications can not use custom processes";
1683 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001684 }
1685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 }
1687
Adam Powell269248d2011-08-02 10:26:54 -07001688 ai.uiOptions = sa.getInt(
1689 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 sa.recycle();
1692
1693 if (outError[0] != null) {
1694 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1695 return false;
1696 }
1697
1698 final int innerDepth = parser.getDepth();
1699
1700 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001701 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1702 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1703 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 continue;
1705 }
1706
1707 String tagName = parser.getName();
1708 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001709 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1710 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 if (a == null) {
1712 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1713 return false;
1714 }
1715
1716 owner.activities.add(a);
1717
1718 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001719 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 if (a == null) {
1721 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1722 return false;
1723 }
1724
1725 owner.receivers.add(a);
1726
1727 } else if (tagName.equals("service")) {
1728 Service s = parseService(owner, res, parser, attrs, flags, outError);
1729 if (s == null) {
1730 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1731 return false;
1732 }
1733
1734 owner.services.add(s);
1735
1736 } else if (tagName.equals("provider")) {
1737 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1738 if (p == null) {
1739 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1740 return false;
1741 }
1742
1743 owner.providers.add(p);
1744
1745 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001746 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 if (a == null) {
1748 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1749 return false;
1750 }
1751
1752 owner.activities.add(a);
1753
1754 } else if (parser.getName().equals("meta-data")) {
1755 // note: application meta-data is stored off to the side, so it can
1756 // remain null in the primary copy (we like to avoid extra copies because
1757 // it can be large)
1758 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1759 outError)) == null) {
1760 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1761 return false;
1762 }
1763
1764 } else if (tagName.equals("uses-library")) {
1765 sa = res.obtainAttributes(attrs,
1766 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1767
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001768 // Note: don't allow this value to be a reference to a resource
1769 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 String lname = sa.getNonResourceString(
1771 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001772 boolean req = sa.getBoolean(
1773 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1774 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775
1776 sa.recycle();
1777
Dianne Hackborn49237342009-08-27 20:08:01 -07001778 if (lname != null) {
1779 if (req) {
1780 if (owner.usesLibraries == null) {
1781 owner.usesLibraries = new ArrayList<String>();
1782 }
1783 if (!owner.usesLibraries.contains(lname)) {
1784 owner.usesLibraries.add(lname.intern());
1785 }
1786 } else {
1787 if (owner.usesOptionalLibraries == null) {
1788 owner.usesOptionalLibraries = new ArrayList<String>();
1789 }
1790 if (!owner.usesOptionalLibraries.contains(lname)) {
1791 owner.usesOptionalLibraries.add(lname.intern());
1792 }
1793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 }
1795
1796 XmlUtils.skipCurrentTag(parser);
1797
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001798 } else if (tagName.equals("uses-package")) {
1799 // Dependencies for app installers; we don't currently try to
1800 // enforce this.
1801 XmlUtils.skipCurrentTag(parser);
1802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 } else {
1804 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001805 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001806 + " at " + mArchiveSourcePath + " "
1807 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 XmlUtils.skipCurrentTag(parser);
1809 continue;
1810 } else {
1811 outError[0] = "Bad element under <application>: " + tagName;
1812 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1813 return false;
1814 }
1815 }
1816 }
1817
1818 return true;
1819 }
1820
1821 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1822 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001823 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001824 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 if (name == null) {
1826 outError[0] = tag + " does not specify android:name";
1827 return false;
1828 }
1829
1830 outInfo.name
1831 = buildClassName(owner.applicationInfo.packageName, name, outError);
1832 if (outInfo.name == null) {
1833 return false;
1834 }
1835
1836 int iconVal = sa.getResourceId(iconRes, 0);
1837 if (iconVal != 0) {
1838 outInfo.icon = iconVal;
1839 outInfo.nonLocalizedLabel = null;
1840 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001841
1842 int logoVal = sa.getResourceId(logoRes, 0);
1843 if (logoVal != 0) {
1844 outInfo.logo = logoVal;
1845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846
1847 TypedValue v = sa.peekValue(labelRes);
1848 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1849 outInfo.nonLocalizedLabel = v.coerceToString();
1850 }
1851
1852 outInfo.packageName = owner.packageName;
1853
1854 return true;
1855 }
1856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 private Activity parseActivity(Package owner, Resources res,
1858 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07001859 boolean receiver, boolean hardwareAccelerated)
1860 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 TypedArray sa = res.obtainAttributes(attrs,
1862 com.android.internal.R.styleable.AndroidManifestActivity);
1863
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001864 if (mParseActivityArgs == null) {
1865 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1866 com.android.internal.R.styleable.AndroidManifestActivity_name,
1867 com.android.internal.R.styleable.AndroidManifestActivity_label,
1868 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001869 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001870 mSeparateProcesses,
1871 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001872 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001873 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
1874 }
1875
1876 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
1877 mParseActivityArgs.sa = sa;
1878 mParseActivityArgs.flags = flags;
1879
1880 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
1881 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 sa.recycle();
1883 return null;
1884 }
1885
1886 final boolean setExported = sa.hasValue(
1887 com.android.internal.R.styleable.AndroidManifestActivity_exported);
1888 if (setExported) {
1889 a.info.exported = sa.getBoolean(
1890 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
1891 }
1892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 a.info.theme = sa.getResourceId(
1894 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
1895
Adam Powell269248d2011-08-02 10:26:54 -07001896 a.info.uiOptions = sa.getInt(
1897 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
1898 a.info.applicationInfo.uiOptions);
1899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001901 str = sa.getNonConfigurationString(
1902 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 if (str == null) {
1904 a.info.permission = owner.applicationInfo.permission;
1905 } else {
1906 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
1907 }
1908
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001909 str = sa.getNonConfigurationString(
1910 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
1912 owner.applicationInfo.taskAffinity, str, outError);
1913
1914 a.info.flags = 0;
1915 if (sa.getBoolean(
1916 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
1917 false)) {
1918 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
1919 }
1920
1921 if (sa.getBoolean(
1922 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
1923 false)) {
1924 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
1925 }
1926
1927 if (sa.getBoolean(
1928 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
1929 false)) {
1930 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
1931 }
1932
1933 if (sa.getBoolean(
1934 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
1935 false)) {
1936 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
1937 }
1938
1939 if (sa.getBoolean(
1940 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
1941 false)) {
1942 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
1943 }
1944
1945 if (sa.getBoolean(
1946 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
1947 false)) {
1948 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
1949 }
1950
1951 if (sa.getBoolean(
1952 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
1953 false)) {
1954 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
1955 }
1956
1957 if (sa.getBoolean(
1958 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
1959 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
1960 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
1961 }
1962
Dianne Hackbornffa42482009-09-23 22:20:11 -07001963 if (sa.getBoolean(
1964 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
1965 false)) {
1966 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
1967 }
1968
Daniel Sandler613dde42010-06-21 13:46:39 -04001969 if (sa.getBoolean(
1970 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
1971 false)) {
1972 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
1973 }
Romain Guy529b60a2010-08-03 18:05:47 -07001974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07001976 if (sa.getBoolean(
1977 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
1978 hardwareAccelerated)) {
1979 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
1980 }
1981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 a.info.launchMode = sa.getInt(
1983 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
1984 ActivityInfo.LAUNCH_MULTIPLE);
1985 a.info.screenOrientation = sa.getInt(
1986 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
1987 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1988 a.info.configChanges = sa.getInt(
1989 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
1990 0);
1991 a.info.softInputMode = sa.getInt(
1992 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
1993 0);
1994 } else {
1995 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
1996 a.info.configChanges = 0;
1997 }
1998
1999 sa.recycle();
2000
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002001 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002002 // A heavy-weight application can not have receives in its main process
2003 // We can do direct compare because we intern all strings.
2004 if (a.info.processName == owner.packageName) {
2005 outError[0] = "Heavy-weight applications can not have receivers in main process";
2006 }
2007 }
2008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 if (outError[0] != null) {
2010 return null;
2011 }
2012
2013 int outerDepth = parser.getDepth();
2014 int type;
2015 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2016 && (type != XmlPullParser.END_TAG
2017 || parser.getDepth() > outerDepth)) {
2018 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2019 continue;
2020 }
2021
2022 if (parser.getName().equals("intent-filter")) {
2023 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2024 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2025 return null;
2026 }
2027 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002028 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002029 + mArchiveSourcePath + " "
2030 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 } else {
2032 a.intents.add(intent);
2033 }
2034 } else if (parser.getName().equals("meta-data")) {
2035 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2036 outError)) == null) {
2037 return null;
2038 }
2039 } else {
2040 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002041 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002043 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002044 + " at " + mArchiveSourcePath + " "
2045 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002047 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002048 + " at " + mArchiveSourcePath + " "
2049 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 }
2051 XmlUtils.skipCurrentTag(parser);
2052 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002054 if (receiver) {
2055 outError[0] = "Bad element under <receiver>: " + parser.getName();
2056 } else {
2057 outError[0] = "Bad element under <activity>: " + parser.getName();
2058 }
2059 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 }
2062 }
2063
2064 if (!setExported) {
2065 a.info.exported = a.intents.size() > 0;
2066 }
2067
2068 return a;
2069 }
2070
2071 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002072 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2073 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 TypedArray sa = res.obtainAttributes(attrs,
2075 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2076
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002077 String targetActivity = sa.getNonConfigurationString(
2078 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 if (targetActivity == null) {
2080 outError[0] = "<activity-alias> does not specify android:targetActivity";
2081 sa.recycle();
2082 return null;
2083 }
2084
2085 targetActivity = buildClassName(owner.applicationInfo.packageName,
2086 targetActivity, outError);
2087 if (targetActivity == null) {
2088 sa.recycle();
2089 return null;
2090 }
2091
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002092 if (mParseActivityAliasArgs == null) {
2093 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2094 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2095 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2096 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002097 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002098 mSeparateProcesses,
2099 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002100 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002101 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2102 mParseActivityAliasArgs.tag = "<activity-alias>";
2103 }
2104
2105 mParseActivityAliasArgs.sa = sa;
2106 mParseActivityAliasArgs.flags = flags;
2107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 Activity target = null;
2109
2110 final int NA = owner.activities.size();
2111 for (int i=0; i<NA; i++) {
2112 Activity t = owner.activities.get(i);
2113 if (targetActivity.equals(t.info.name)) {
2114 target = t;
2115 break;
2116 }
2117 }
2118
2119 if (target == null) {
2120 outError[0] = "<activity-alias> target activity " + targetActivity
2121 + " not found in manifest";
2122 sa.recycle();
2123 return null;
2124 }
2125
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002126 ActivityInfo info = new ActivityInfo();
2127 info.targetActivity = targetActivity;
2128 info.configChanges = target.info.configChanges;
2129 info.flags = target.info.flags;
2130 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002131 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002132 info.labelRes = target.info.labelRes;
2133 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2134 info.launchMode = target.info.launchMode;
2135 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002136 if (info.descriptionRes == 0) {
2137 info.descriptionRes = target.info.descriptionRes;
2138 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002139 info.screenOrientation = target.info.screenOrientation;
2140 info.taskAffinity = target.info.taskAffinity;
2141 info.theme = target.info.theme;
Adam Powell269248d2011-08-02 10:26:54 -07002142 info.uiOptions = target.info.uiOptions;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002143
2144 Activity a = new Activity(mParseActivityAliasArgs, info);
2145 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 sa.recycle();
2147 return null;
2148 }
2149
2150 final boolean setExported = sa.hasValue(
2151 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2152 if (setExported) {
2153 a.info.exported = sa.getBoolean(
2154 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2155 }
2156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002158 str = sa.getNonConfigurationString(
2159 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 if (str != null) {
2161 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2162 }
2163
2164 sa.recycle();
2165
2166 if (outError[0] != null) {
2167 return null;
2168 }
2169
2170 int outerDepth = parser.getDepth();
2171 int type;
2172 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2173 && (type != XmlPullParser.END_TAG
2174 || parser.getDepth() > outerDepth)) {
2175 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2176 continue;
2177 }
2178
2179 if (parser.getName().equals("intent-filter")) {
2180 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2181 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2182 return null;
2183 }
2184 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002185 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002186 + mArchiveSourcePath + " "
2187 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 } else {
2189 a.intents.add(intent);
2190 }
2191 } else if (parser.getName().equals("meta-data")) {
2192 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2193 outError)) == null) {
2194 return null;
2195 }
2196 } else {
2197 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002198 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002199 + " at " + mArchiveSourcePath + " "
2200 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 XmlUtils.skipCurrentTag(parser);
2202 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002203 } else {
2204 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2205 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 }
2208 }
2209
2210 if (!setExported) {
2211 a.info.exported = a.intents.size() > 0;
2212 }
2213
2214 return a;
2215 }
2216
2217 private Provider parseProvider(Package owner, Resources res,
2218 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2219 throws XmlPullParserException, IOException {
2220 TypedArray sa = res.obtainAttributes(attrs,
2221 com.android.internal.R.styleable.AndroidManifestProvider);
2222
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002223 if (mParseProviderArgs == null) {
2224 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2225 com.android.internal.R.styleable.AndroidManifestProvider_name,
2226 com.android.internal.R.styleable.AndroidManifestProvider_label,
2227 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002228 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002229 mSeparateProcesses,
2230 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002231 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002232 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2233 mParseProviderArgs.tag = "<provider>";
2234 }
2235
2236 mParseProviderArgs.sa = sa;
2237 mParseProviderArgs.flags = flags;
2238
2239 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2240 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 sa.recycle();
2242 return null;
2243 }
2244
2245 p.info.exported = sa.getBoolean(
2246 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2247
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002248 String cpname = sa.getNonConfigurationString(
2249 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250
2251 p.info.isSyncable = sa.getBoolean(
2252 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2253 false);
2254
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002255 String permission = sa.getNonConfigurationString(
2256 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2257 String str = sa.getNonConfigurationString(
2258 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 if (str == null) {
2260 str = permission;
2261 }
2262 if (str == null) {
2263 p.info.readPermission = owner.applicationInfo.permission;
2264 } else {
2265 p.info.readPermission =
2266 str.length() > 0 ? str.toString().intern() : null;
2267 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002268 str = sa.getNonConfigurationString(
2269 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 if (str == null) {
2271 str = permission;
2272 }
2273 if (str == null) {
2274 p.info.writePermission = owner.applicationInfo.permission;
2275 } else {
2276 p.info.writePermission =
2277 str.length() > 0 ? str.toString().intern() : null;
2278 }
2279
2280 p.info.grantUriPermissions = sa.getBoolean(
2281 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2282 false);
2283
2284 p.info.multiprocess = sa.getBoolean(
2285 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2286 false);
2287
2288 p.info.initOrder = sa.getInt(
2289 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2290 0);
2291
2292 sa.recycle();
2293
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002294 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002295 // A heavy-weight application can not have providers in its main process
2296 // We can do direct compare because we intern all strings.
2297 if (p.info.processName == owner.packageName) {
2298 outError[0] = "Heavy-weight applications can not have providers in main process";
2299 return null;
2300 }
2301 }
2302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 if (cpname == null) {
2304 outError[0] = "<provider> does not incude authorities attribute";
2305 return null;
2306 }
2307 p.info.authority = cpname.intern();
2308
2309 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2310 return null;
2311 }
2312
2313 return p;
2314 }
2315
2316 private boolean parseProviderTags(Resources res,
2317 XmlPullParser parser, AttributeSet attrs,
2318 Provider outInfo, String[] outError)
2319 throws XmlPullParserException, IOException {
2320 int outerDepth = parser.getDepth();
2321 int type;
2322 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2323 && (type != XmlPullParser.END_TAG
2324 || parser.getDepth() > outerDepth)) {
2325 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2326 continue;
2327 }
2328
2329 if (parser.getName().equals("meta-data")) {
2330 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2331 outInfo.metaData, outError)) == null) {
2332 return false;
2333 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 } else if (parser.getName().equals("grant-uri-permission")) {
2336 TypedArray sa = res.obtainAttributes(attrs,
2337 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2338
2339 PatternMatcher pa = null;
2340
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002341 String str = sa.getNonConfigurationString(
2342 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 if (str != null) {
2344 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2345 }
2346
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002347 str = sa.getNonConfigurationString(
2348 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 if (str != null) {
2350 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2351 }
2352
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002353 str = sa.getNonConfigurationString(
2354 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (str != null) {
2356 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2357 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 sa.recycle();
2360
2361 if (pa != null) {
2362 if (outInfo.info.uriPermissionPatterns == null) {
2363 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2364 outInfo.info.uriPermissionPatterns[0] = pa;
2365 } else {
2366 final int N = outInfo.info.uriPermissionPatterns.length;
2367 PatternMatcher[] newp = new PatternMatcher[N+1];
2368 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2369 newp[N] = pa;
2370 outInfo.info.uriPermissionPatterns = newp;
2371 }
2372 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002373 } else {
2374 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002375 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002376 + parser.getName() + " at " + mArchiveSourcePath + " "
2377 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002378 XmlUtils.skipCurrentTag(parser);
2379 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002380 } else {
2381 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2382 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002383 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002384 }
2385 XmlUtils.skipCurrentTag(parser);
2386
2387 } else if (parser.getName().equals("path-permission")) {
2388 TypedArray sa = res.obtainAttributes(attrs,
2389 com.android.internal.R.styleable.AndroidManifestPathPermission);
2390
2391 PathPermission pa = null;
2392
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002393 String permission = sa.getNonConfigurationString(
2394 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2395 String readPermission = sa.getNonConfigurationString(
2396 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002397 if (readPermission == null) {
2398 readPermission = permission;
2399 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002400 String writePermission = sa.getNonConfigurationString(
2401 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002402 if (writePermission == null) {
2403 writePermission = permission;
2404 }
2405
2406 boolean havePerm = false;
2407 if (readPermission != null) {
2408 readPermission = readPermission.intern();
2409 havePerm = true;
2410 }
2411 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002412 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002413 havePerm = true;
2414 }
2415
2416 if (!havePerm) {
2417 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002418 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002419 + parser.getName() + " at " + mArchiveSourcePath + " "
2420 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002421 XmlUtils.skipCurrentTag(parser);
2422 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002423 } else {
2424 outError[0] = "No readPermission or writePermssion for <path-permission>";
2425 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002426 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002427 }
2428
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002429 String path = sa.getNonConfigurationString(
2430 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002431 if (path != null) {
2432 pa = new PathPermission(path,
2433 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2434 }
2435
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002436 path = sa.getNonConfigurationString(
2437 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002438 if (path != null) {
2439 pa = new PathPermission(path,
2440 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2441 }
2442
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002443 path = sa.getNonConfigurationString(
2444 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002445 if (path != null) {
2446 pa = new PathPermission(path,
2447 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2448 }
2449
2450 sa.recycle();
2451
2452 if (pa != null) {
2453 if (outInfo.info.pathPermissions == null) {
2454 outInfo.info.pathPermissions = new PathPermission[1];
2455 outInfo.info.pathPermissions[0] = pa;
2456 } else {
2457 final int N = outInfo.info.pathPermissions.length;
2458 PathPermission[] newp = new PathPermission[N+1];
2459 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2460 newp[N] = pa;
2461 outInfo.info.pathPermissions = newp;
2462 }
2463 } else {
2464 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002465 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002466 + parser.getName() + " at " + mArchiveSourcePath + " "
2467 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002468 XmlUtils.skipCurrentTag(parser);
2469 continue;
2470 }
2471 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2472 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 }
2474 XmlUtils.skipCurrentTag(parser);
2475
2476 } else {
2477 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002478 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002479 + parser.getName() + " at " + mArchiveSourcePath + " "
2480 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 XmlUtils.skipCurrentTag(parser);
2482 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002483 } else {
2484 outError[0] = "Bad element under <provider>: " + parser.getName();
2485 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 }
2488 }
2489 return true;
2490 }
2491
2492 private Service parseService(Package owner, Resources res,
2493 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2494 throws XmlPullParserException, IOException {
2495 TypedArray sa = res.obtainAttributes(attrs,
2496 com.android.internal.R.styleable.AndroidManifestService);
2497
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002498 if (mParseServiceArgs == null) {
2499 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2500 com.android.internal.R.styleable.AndroidManifestService_name,
2501 com.android.internal.R.styleable.AndroidManifestService_label,
2502 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002503 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002504 mSeparateProcesses,
2505 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002506 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002507 com.android.internal.R.styleable.AndroidManifestService_enabled);
2508 mParseServiceArgs.tag = "<service>";
2509 }
2510
2511 mParseServiceArgs.sa = sa;
2512 mParseServiceArgs.flags = flags;
2513
2514 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2515 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 sa.recycle();
2517 return null;
2518 }
2519
2520 final boolean setExported = sa.hasValue(
2521 com.android.internal.R.styleable.AndroidManifestService_exported);
2522 if (setExported) {
2523 s.info.exported = sa.getBoolean(
2524 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2525 }
2526
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002527 String str = sa.getNonConfigurationString(
2528 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 if (str == null) {
2530 s.info.permission = owner.applicationInfo.permission;
2531 } else {
2532 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2533 }
2534
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002535 s.info.flags = 0;
2536 if (sa.getBoolean(
2537 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2538 false)) {
2539 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2540 }
2541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 sa.recycle();
2543
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002544 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002545 // A heavy-weight application can not have services in its main process
2546 // We can do direct compare because we intern all strings.
2547 if (s.info.processName == owner.packageName) {
2548 outError[0] = "Heavy-weight applications can not have services in main process";
2549 return null;
2550 }
2551 }
2552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 int outerDepth = parser.getDepth();
2554 int type;
2555 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2556 && (type != XmlPullParser.END_TAG
2557 || parser.getDepth() > outerDepth)) {
2558 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2559 continue;
2560 }
2561
2562 if (parser.getName().equals("intent-filter")) {
2563 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2564 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2565 return null;
2566 }
2567
2568 s.intents.add(intent);
2569 } else if (parser.getName().equals("meta-data")) {
2570 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2571 outError)) == null) {
2572 return null;
2573 }
2574 } else {
2575 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002576 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002577 + parser.getName() + " at " + mArchiveSourcePath + " "
2578 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 XmlUtils.skipCurrentTag(parser);
2580 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002581 } else {
2582 outError[0] = "Bad element under <service>: " + parser.getName();
2583 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 }
2586 }
2587
2588 if (!setExported) {
2589 s.info.exported = s.intents.size() > 0;
2590 }
2591
2592 return s;
2593 }
2594
2595 private boolean parseAllMetaData(Resources res,
2596 XmlPullParser parser, AttributeSet attrs, String tag,
2597 Component outInfo, String[] outError)
2598 throws XmlPullParserException, IOException {
2599 int outerDepth = parser.getDepth();
2600 int type;
2601 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2602 && (type != XmlPullParser.END_TAG
2603 || parser.getDepth() > outerDepth)) {
2604 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2605 continue;
2606 }
2607
2608 if (parser.getName().equals("meta-data")) {
2609 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2610 outInfo.metaData, outError)) == null) {
2611 return false;
2612 }
2613 } else {
2614 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002615 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002616 + parser.getName() + " at " + mArchiveSourcePath + " "
2617 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 XmlUtils.skipCurrentTag(parser);
2619 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002620 } else {
2621 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2622 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 }
2625 }
2626 return true;
2627 }
2628
2629 private Bundle parseMetaData(Resources res,
2630 XmlPullParser parser, AttributeSet attrs,
2631 Bundle data, String[] outError)
2632 throws XmlPullParserException, IOException {
2633
2634 TypedArray sa = res.obtainAttributes(attrs,
2635 com.android.internal.R.styleable.AndroidManifestMetaData);
2636
2637 if (data == null) {
2638 data = new Bundle();
2639 }
2640
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002641 String name = sa.getNonConfigurationString(
2642 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 if (name == null) {
2644 outError[0] = "<meta-data> requires an android:name attribute";
2645 sa.recycle();
2646 return null;
2647 }
2648
Dianne Hackborn854060a2009-07-09 18:14:31 -07002649 name = name.intern();
2650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 TypedValue v = sa.peekValue(
2652 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2653 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002654 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 data.putInt(name, v.resourceId);
2656 } else {
2657 v = sa.peekValue(
2658 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002659 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 if (v != null) {
2661 if (v.type == TypedValue.TYPE_STRING) {
2662 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002663 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2665 data.putBoolean(name, v.data != 0);
2666 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2667 && v.type <= TypedValue.TYPE_LAST_INT) {
2668 data.putInt(name, v.data);
2669 } else if (v.type == TypedValue.TYPE_FLOAT) {
2670 data.putFloat(name, v.getFloat());
2671 } else {
2672 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002673 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002674 + parser.getName() + " at " + mArchiveSourcePath + " "
2675 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 } else {
2677 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2678 data = null;
2679 }
2680 }
2681 } else {
2682 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2683 data = null;
2684 }
2685 }
2686
2687 sa.recycle();
2688
2689 XmlUtils.skipCurrentTag(parser);
2690
2691 return data;
2692 }
2693
2694 private static final String ANDROID_RESOURCES
2695 = "http://schemas.android.com/apk/res/android";
2696
2697 private boolean parseIntent(Resources res,
2698 XmlPullParser parser, AttributeSet attrs, int flags,
2699 IntentInfo outInfo, String[] outError, boolean isActivity)
2700 throws XmlPullParserException, IOException {
2701
2702 TypedArray sa = res.obtainAttributes(attrs,
2703 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2704
2705 int priority = sa.getInt(
2706 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 TypedValue v = sa.peekValue(
2710 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2711 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2712 outInfo.nonLocalizedLabel = v.coerceToString();
2713 }
2714
2715 outInfo.icon = sa.getResourceId(
2716 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002717
2718 outInfo.logo = sa.getResourceId(
2719 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002720
2721 sa.recycle();
2722
2723 int outerDepth = parser.getDepth();
2724 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002725 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2726 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2727 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 continue;
2729 }
2730
2731 String nodeName = parser.getName();
2732 if (nodeName.equals("action")) {
2733 String value = attrs.getAttributeValue(
2734 ANDROID_RESOURCES, "name");
2735 if (value == null || value == "") {
2736 outError[0] = "No value supplied for <android:name>";
2737 return false;
2738 }
2739 XmlUtils.skipCurrentTag(parser);
2740
2741 outInfo.addAction(value);
2742 } else if (nodeName.equals("category")) {
2743 String value = attrs.getAttributeValue(
2744 ANDROID_RESOURCES, "name");
2745 if (value == null || value == "") {
2746 outError[0] = "No value supplied for <android:name>";
2747 return false;
2748 }
2749 XmlUtils.skipCurrentTag(parser);
2750
2751 outInfo.addCategory(value);
2752
2753 } else if (nodeName.equals("data")) {
2754 sa = res.obtainAttributes(attrs,
2755 com.android.internal.R.styleable.AndroidManifestData);
2756
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002757 String str = sa.getNonConfigurationString(
2758 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 if (str != null) {
2760 try {
2761 outInfo.addDataType(str);
2762 } catch (IntentFilter.MalformedMimeTypeException e) {
2763 outError[0] = e.toString();
2764 sa.recycle();
2765 return false;
2766 }
2767 }
2768
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002769 str = sa.getNonConfigurationString(
2770 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 if (str != null) {
2772 outInfo.addDataScheme(str);
2773 }
2774
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002775 String host = sa.getNonConfigurationString(
2776 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2777 String port = sa.getNonConfigurationString(
2778 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 if (host != null) {
2780 outInfo.addDataAuthority(host, port);
2781 }
2782
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002783 str = sa.getNonConfigurationString(
2784 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 if (str != null) {
2786 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2787 }
2788
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002789 str = sa.getNonConfigurationString(
2790 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 if (str != null) {
2792 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2793 }
2794
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002795 str = sa.getNonConfigurationString(
2796 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 if (str != null) {
2798 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2799 }
2800
2801 sa.recycle();
2802 XmlUtils.skipCurrentTag(parser);
2803 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002804 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002805 + parser.getName() + " at " + mArchiveSourcePath + " "
2806 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 XmlUtils.skipCurrentTag(parser);
2808 } else {
2809 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
2810 return false;
2811 }
2812 }
2813
2814 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07002815
2816 if (DEBUG_PARSER) {
2817 final StringBuilder cats = new StringBuilder("Intent d=");
2818 cats.append(outInfo.hasDefault);
2819 cats.append(", cat=");
2820
2821 final Iterator<String> it = outInfo.categoriesIterator();
2822 if (it != null) {
2823 while (it.hasNext()) {
2824 cats.append(' ');
2825 cats.append(it.next());
2826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 }
Kenny Rootd2d29252011-08-08 11:27:57 -07002828 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 }
2830
2831 return true;
2832 }
2833
2834 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002835 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836
2837 // For now we only support one application per package.
2838 public final ApplicationInfo applicationInfo = new ApplicationInfo();
2839
2840 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
2841 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
2842 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
2843 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
2844 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
2845 public final ArrayList<Service> services = new ArrayList<Service>(0);
2846 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
2847
2848 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
2849
Dianne Hackborn854060a2009-07-09 18:14:31 -07002850 public ArrayList<String> protectedBroadcasts;
2851
Dianne Hackborn49237342009-08-27 20:08:01 -07002852 public ArrayList<String> usesLibraries = null;
2853 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 public String[] usesLibraryFiles = null;
2855
Dianne Hackbornc1552392010-03-03 16:19:01 -08002856 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002857 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08002858 public ArrayList<String> mAdoptPermissions = null;
2859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 // We store the application meta-data independently to avoid multiple unwanted references
2861 public Bundle mAppMetaData = null;
2862
2863 // If this is a 3rd party app, this is the path of the zip file.
2864 public String mPath;
2865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 // The version code declared for this package.
2867 public int mVersionCode;
2868
2869 // The version name declared for this package.
2870 public String mVersionName;
2871
2872 // The shared user id that this package wants to use.
2873 public String mSharedUserId;
2874
2875 // The shared user label that this package wants to use.
2876 public int mSharedUserLabel;
2877
2878 // Signatures that were read from the package.
2879 public Signature mSignatures[];
2880
2881 // For use by package manager service for quick lookup of
2882 // preferred up order.
2883 public int mPreferredOrder = 0;
2884
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07002885 // For use by the package manager to keep track of the path to the
2886 // file an app came from.
2887 public String mScanPath;
2888
2889 // For use by package manager to keep track of where it has done dexopt.
2890 public boolean mDidDexOpt;
2891
Dianne Hackborn46730fc2010-07-24 16:32:42 -07002892 // User set enabled state.
2893 public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
2894
Dianne Hackborne7f97212011-02-24 14:40:20 -08002895 // Whether the package has been stopped.
2896 public boolean mSetStopped = false;
2897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 // Additional data supplied by callers.
2899 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07002900
2901 // Whether an operation is currently pending on this package
2902 public boolean mOperationPending;
2903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 /*
2905 * Applications hardware preferences
2906 */
2907 public final ArrayList<ConfigurationInfo> configPreferences =
2908 new ArrayList<ConfigurationInfo>();
2909
Dianne Hackborn49237342009-08-27 20:08:01 -07002910 /*
2911 * Applications requested features
2912 */
2913 public ArrayList<FeatureInfo> reqFeatures = null;
2914
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08002915 public int installLocation;
2916
Kenny Rootbcc954d2011-08-08 16:19:08 -07002917 /**
2918 * Digest suitable for comparing whether this package's manifest is the
2919 * same as another.
2920 */
2921 public ManifestDigest manifestDigest;
2922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 public Package(String _name) {
2924 packageName = _name;
2925 applicationInfo.packageName = _name;
2926 applicationInfo.uid = -1;
2927 }
2928
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002929 public void setPackageName(String newName) {
2930 packageName = newName;
2931 applicationInfo.packageName = newName;
2932 for (int i=permissions.size()-1; i>=0; i--) {
2933 permissions.get(i).setPackageName(newName);
2934 }
2935 for (int i=permissionGroups.size()-1; i>=0; i--) {
2936 permissionGroups.get(i).setPackageName(newName);
2937 }
2938 for (int i=activities.size()-1; i>=0; i--) {
2939 activities.get(i).setPackageName(newName);
2940 }
2941 for (int i=receivers.size()-1; i>=0; i--) {
2942 receivers.get(i).setPackageName(newName);
2943 }
2944 for (int i=providers.size()-1; i>=0; i--) {
2945 providers.get(i).setPackageName(newName);
2946 }
2947 for (int i=services.size()-1; i>=0; i--) {
2948 services.get(i).setPackageName(newName);
2949 }
2950 for (int i=instrumentation.size()-1; i>=0; i--) {
2951 instrumentation.get(i).setPackageName(newName);
2952 }
2953 }
2954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 public String toString() {
2956 return "Package{"
2957 + Integer.toHexString(System.identityHashCode(this))
2958 + " " + packageName + "}";
2959 }
2960 }
2961
2962 public static class Component<II extends IntentInfo> {
2963 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002964 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002965 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 public Bundle metaData;
2967
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002968 ComponentName componentName;
2969 String componentShortName;
2970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 public Component(Package _owner) {
2972 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002973 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002974 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002975 }
2976
2977 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
2978 owner = args.owner;
2979 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002980 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002981 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002982 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002983 args.outError[0] = args.tag + " does not specify android:name";
2984 return;
2985 }
2986
2987 outInfo.name
2988 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
2989 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002990 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002991 args.outError[0] = args.tag + " does not have valid android:name";
2992 return;
2993 }
2994
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08002995 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002996
2997 int iconVal = args.sa.getResourceId(args.iconRes, 0);
2998 if (iconVal != 0) {
2999 outInfo.icon = iconVal;
3000 outInfo.nonLocalizedLabel = null;
3001 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003002
3003 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3004 if (logoVal != 0) {
3005 outInfo.logo = logoVal;
3006 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003007
3008 TypedValue v = args.sa.peekValue(args.labelRes);
3009 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3010 outInfo.nonLocalizedLabel = v.coerceToString();
3011 }
3012
3013 outInfo.packageName = owner.packageName;
3014 }
3015
3016 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3017 this(args, (PackageItemInfo)outInfo);
3018 if (args.outError[0] != null) {
3019 return;
3020 }
3021
3022 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003023 CharSequence pname;
3024 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3025 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3026 } else {
3027 // Some older apps have been seen to use a resource reference
3028 // here that on older builds was ignored (with a warning). We
3029 // need to continue to do this for them so they don't break.
3030 pname = args.sa.getNonResourceString(args.processRes);
3031 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003032 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003033 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003034 args.flags, args.sepProcesses, args.outError);
3035 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003036
3037 if (args.descriptionRes != 0) {
3038 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3039 }
3040
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003041 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 }
3043
3044 public Component(Component<II> clone) {
3045 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003046 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003047 className = clone.className;
3048 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003049 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003050 }
3051
3052 public ComponentName getComponentName() {
3053 if (componentName != null) {
3054 return componentName;
3055 }
3056 if (className != null) {
3057 componentName = new ComponentName(owner.applicationInfo.packageName,
3058 className);
3059 }
3060 return componentName;
3061 }
3062
3063 public String getComponentShortName() {
3064 if (componentShortName != null) {
3065 return componentShortName;
3066 }
3067 ComponentName component = getComponentName();
3068 if (component != null) {
3069 componentShortName = component.flattenToShortString();
3070 }
3071 return componentShortName;
3072 }
3073
3074 public void setPackageName(String packageName) {
3075 componentName = null;
3076 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 }
3078 }
3079
3080 public final static class Permission extends Component<IntentInfo> {
3081 public final PermissionInfo info;
3082 public boolean tree;
3083 public PermissionGroup group;
3084
3085 public Permission(Package _owner) {
3086 super(_owner);
3087 info = new PermissionInfo();
3088 }
3089
3090 public Permission(Package _owner, PermissionInfo _info) {
3091 super(_owner);
3092 info = _info;
3093 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003094
3095 public void setPackageName(String packageName) {
3096 super.setPackageName(packageName);
3097 info.packageName = packageName;
3098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099
3100 public String toString() {
3101 return "Permission{"
3102 + Integer.toHexString(System.identityHashCode(this))
3103 + " " + info.name + "}";
3104 }
3105 }
3106
3107 public final static class PermissionGroup extends Component<IntentInfo> {
3108 public final PermissionGroupInfo info;
3109
3110 public PermissionGroup(Package _owner) {
3111 super(_owner);
3112 info = new PermissionGroupInfo();
3113 }
3114
3115 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3116 super(_owner);
3117 info = _info;
3118 }
3119
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003120 public void setPackageName(String packageName) {
3121 super.setPackageName(packageName);
3122 info.packageName = packageName;
3123 }
3124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 public String toString() {
3126 return "PermissionGroup{"
3127 + Integer.toHexString(System.identityHashCode(this))
3128 + " " + info.name + "}";
3129 }
3130 }
3131
3132 private static boolean copyNeeded(int flags, Package p, Bundle metaData) {
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003133 if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3134 boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
3135 if (p.applicationInfo.enabled != enabled) {
3136 return true;
3137 }
3138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 if ((flags & PackageManager.GET_META_DATA) != 0
3140 && (metaData != null || p.mAppMetaData != null)) {
3141 return true;
3142 }
3143 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3144 && p.usesLibraryFiles != null) {
3145 return true;
3146 }
3147 return false;
3148 }
3149
3150 public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
3151 if (p == null) return null;
3152 if (!copyNeeded(flags, p, null)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003153 // CompatibilityMode is global state. It's safe to modify the instance
3154 // of the package.
3155 if (!sCompatibilityModeEnabled) {
3156 p.applicationInfo.disableCompatibilityMode();
3157 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003158 if (p.mSetStopped) {
3159 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3160 } else {
3161 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 return p.applicationInfo;
3164 }
3165
3166 // Make shallow copy so we can store the metadata/libraries safely
3167 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
3168 if ((flags & PackageManager.GET_META_DATA) != 0) {
3169 ai.metaData = p.mAppMetaData;
3170 }
3171 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3172 ai.sharedLibraryFiles = p.usesLibraryFiles;
3173 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003174 if (!sCompatibilityModeEnabled) {
3175 ai.disableCompatibilityMode();
3176 }
Dianne Hackborne7f97212011-02-24 14:40:20 -08003177 if (p.mSetStopped) {
3178 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3179 } else {
3180 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3181 }
John Reck4b7b7cc2011-02-02 11:57:44 -08003182 if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3183 ai.enabled = true;
Dianne Hackborn0ac30312011-06-17 14:49:23 -07003184 } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3185 || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003186 ai.enabled = false;
3187 }
Dianne Hackborn0ac30312011-06-17 14:49:23 -07003188 ai.enabledSetting = p.mSetEnabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 return ai;
3190 }
3191
3192 public static final PermissionInfo generatePermissionInfo(
3193 Permission p, int flags) {
3194 if (p == null) return null;
3195 if ((flags&PackageManager.GET_META_DATA) == 0) {
3196 return p.info;
3197 }
3198 PermissionInfo pi = new PermissionInfo(p.info);
3199 pi.metaData = p.metaData;
3200 return pi;
3201 }
3202
3203 public static final PermissionGroupInfo generatePermissionGroupInfo(
3204 PermissionGroup pg, int flags) {
3205 if (pg == null) return null;
3206 if ((flags&PackageManager.GET_META_DATA) == 0) {
3207 return pg.info;
3208 }
3209 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3210 pgi.metaData = pg.metaData;
3211 return pgi;
3212 }
3213
3214 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003215 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003217 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3218 super(args, _info);
3219 info = _info;
3220 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003222
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003223 public void setPackageName(String packageName) {
3224 super.setPackageName(packageName);
3225 info.packageName = packageName;
3226 }
3227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 public String toString() {
3229 return "Activity{"
3230 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003231 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 }
3233 }
3234
3235 public static final ActivityInfo generateActivityInfo(Activity a,
3236 int flags) {
3237 if (a == null) return null;
3238 if (!copyNeeded(flags, a.owner, a.metaData)) {
3239 return a.info;
3240 }
3241 // Make shallow copies so we can store the metadata safely
3242 ActivityInfo ai = new ActivityInfo(a.info);
3243 ai.metaData = a.metaData;
3244 ai.applicationInfo = generateApplicationInfo(a.owner, flags);
3245 return ai;
3246 }
3247
3248 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003249 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003251 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3252 super(args, _info);
3253 info = _info;
3254 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003256
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003257 public void setPackageName(String packageName) {
3258 super.setPackageName(packageName);
3259 info.packageName = packageName;
3260 }
3261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 public String toString() {
3263 return "Service{"
3264 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003265 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 }
3267 }
3268
3269 public static final ServiceInfo generateServiceInfo(Service s, int flags) {
3270 if (s == null) return null;
3271 if (!copyNeeded(flags, s.owner, s.metaData)) {
3272 return s.info;
3273 }
3274 // Make shallow copies so we can store the metadata safely
3275 ServiceInfo si = new ServiceInfo(s.info);
3276 si.metaData = s.metaData;
3277 si.applicationInfo = generateApplicationInfo(s.owner, flags);
3278 return si;
3279 }
3280
3281 public final static class Provider extends Component {
3282 public final ProviderInfo info;
3283 public boolean syncable;
3284
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003285 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3286 super(args, _info);
3287 info = _info;
3288 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 syncable = false;
3290 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 public Provider(Provider existingProvider) {
3293 super(existingProvider);
3294 this.info = existingProvider.info;
3295 this.syncable = existingProvider.syncable;
3296 }
3297
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003298 public void setPackageName(String packageName) {
3299 super.setPackageName(packageName);
3300 info.packageName = packageName;
3301 }
3302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 public String toString() {
3304 return "Provider{"
3305 + Integer.toHexString(System.identityHashCode(this))
3306 + " " + info.name + "}";
3307 }
3308 }
3309
3310 public static final ProviderInfo generateProviderInfo(Provider p,
3311 int flags) {
3312 if (p == null) return null;
3313 if (!copyNeeded(flags, p.owner, p.metaData)
3314 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
3315 || p.info.uriPermissionPatterns == null)) {
3316 return p.info;
3317 }
3318 // Make shallow copies so we can store the metadata safely
3319 ProviderInfo pi = new ProviderInfo(p.info);
3320 pi.metaData = p.metaData;
3321 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3322 pi.uriPermissionPatterns = null;
3323 }
3324 pi.applicationInfo = generateApplicationInfo(p.owner, flags);
3325 return pi;
3326 }
3327
3328 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003329 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003331 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3332 super(args, _info);
3333 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003335
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003336 public void setPackageName(String packageName) {
3337 super.setPackageName(packageName);
3338 info.packageName = packageName;
3339 }
3340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 public String toString() {
3342 return "Instrumentation{"
3343 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003344 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 }
3346 }
3347
3348 public static final InstrumentationInfo generateInstrumentationInfo(
3349 Instrumentation i, int flags) {
3350 if (i == null) return null;
3351 if ((flags&PackageManager.GET_META_DATA) == 0) {
3352 return i.info;
3353 }
3354 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3355 ii.metaData = i.metaData;
3356 return ii;
3357 }
3358
3359 public static class IntentInfo extends IntentFilter {
3360 public boolean hasDefault;
3361 public int labelRes;
3362 public CharSequence nonLocalizedLabel;
3363 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003364 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 }
3366
3367 public final static class ActivityIntentInfo extends IntentInfo {
3368 public final Activity activity;
3369
3370 public ActivityIntentInfo(Activity _activity) {
3371 activity = _activity;
3372 }
3373
3374 public String toString() {
3375 return "ActivityIntentInfo{"
3376 + Integer.toHexString(System.identityHashCode(this))
3377 + " " + activity.info.name + "}";
3378 }
3379 }
3380
3381 public final static class ServiceIntentInfo extends IntentInfo {
3382 public final Service service;
3383
3384 public ServiceIntentInfo(Service _service) {
3385 service = _service;
3386 }
3387
3388 public String toString() {
3389 return "ServiceIntentInfo{"
3390 + Integer.toHexString(System.identityHashCode(this))
3391 + " " + service.info.name + "}";
3392 }
3393 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003394
3395 /**
3396 * @hide
3397 */
3398 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3399 sCompatibilityModeEnabled = compatibilityModeEnabled;
3400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401}