blob: 7571993e20c4ecc79fd2d8abd50e7a4e412968dc [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;
Amith Yamasani742a6712011-05-04 14:49:28 -070027import android.os.Binder;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070028import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Bundle;
30import android.os.PatternMatcher;
Amith Yamasani742a6712011-05-04 14:49:28 -070031import android.os.UserId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070033import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070035import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070036import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kenny Rootd63f7db2010-09-27 08:07:48 -070039import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Kenny Rootbcc954d2011-08-08 16:19:08 -070057import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.jar.JarEntry;
59import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070060import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Amith Yamasani742a6712011-05-04 14:49:28 -070062import com.android.internal.util.XmlUtils;
63
64import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
68 * Package archive parsing
69 *
70 * {@hide}
71 */
72public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070073 private static final boolean DEBUG_JAR = false;
74 private static final boolean DEBUG_PARSER = false;
75 private static final boolean DEBUG_BACKUP = false;
76
Kenny Rootbcc954d2011-08-08 16:19:08 -070077 /** File name in an APK for the Android manifest. */
78 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
79
Dianne Hackborna96cbb42009-05-13 15:06:13 -070080 /** @hide */
81 public static class NewPermissionInfo {
82 public final String name;
83 public final int sdkVersion;
84 public final int fileVersion;
85
86 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
87 this.name = name;
88 this.sdkVersion = sdkVersion;
89 this.fileVersion = fileVersion;
90 }
91 }
Dianne Hackborn79245122012-03-12 10:51:26 -070092
93 /** @hide */
94 public static class SplitPermissionInfo {
95 public final String rootPerm;
96 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070098
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700100 this.rootPerm = rootPerm;
101 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700102 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700103 }
104 }
105
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700106 /**
107 * List of new permissions that have been added since 1.0.
108 * NOTE: These must be declared in SDK version order, with permissions
109 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700110 * If sdkVersion is 0, then this is not a permission that we want to
111 * automatically add to older apps, but we do want to allow it to be
112 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700113 * @hide
114 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700115 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
116 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700117 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700118 android.os.Build.VERSION_CODES.DONUT, 0),
119 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
120 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700121 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Dianne Hackborn79245122012-03-12 10:51:26 -0700123 /**
124 * List of permissions that have been split into more granular or dependent
125 * permissions.
126 * @hide
127 */
128 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
129 new PackageParser.SplitPermissionInfo[] {
130 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700131 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
132 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
133 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
134 new String[] { android.Manifest.permission.READ_CALL_LOG },
135 android.os.Build.VERSION_CODES.JELLY_BEAN),
136 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
137 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
138 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700139 };
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 private String mArchiveSourcePath;
142 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700143 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700144 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
145 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
146 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147
148 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
149
150 private static final Object mSync = new Object();
151 private static WeakReference<byte[]> mReadBuffer;
152
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700153 private static boolean sCompatibilityModeEnabled = true;
154 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700155
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700156 static class ParsePackageItemArgs {
157 final Package owner;
158 final String[] outError;
159 final int nameRes;
160 final int labelRes;
161 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700162 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700163
164 String tag;
165 TypedArray sa;
166
167 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700168 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700169 owner = _owner;
170 outError = _outError;
171 nameRes = _nameRes;
172 labelRes = _labelRes;
173 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700174 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700175 }
176 }
177
178 static class ParseComponentArgs extends ParsePackageItemArgs {
179 final String[] sepProcesses;
180 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800181 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700182 final int enabledRes;
183 int flags;
184
185 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700186 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800187 String[] _sepProcesses, int _processRes,
188 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700189 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700190 sepProcesses = _sepProcesses;
191 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800192 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700193 enabledRes = _enabledRes;
194 }
195 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800196
197 /* Light weight package info.
198 * @hide
199 */
200 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700201 public final String packageName;
202 public final int installLocation;
203 public final VerifierInfo[] verifiers;
204
205 public PackageLite(String packageName, int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800206 this.packageName = packageName;
207 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700208 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800209 }
210 }
211
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700212 private ParsePackageItemArgs mParseInstrumentationArgs;
213 private ParseComponentArgs mParseActivityArgs;
214 private ParseComponentArgs mParseActivityAliasArgs;
215 private ParseComponentArgs mParseServiceArgs;
216 private ParseComponentArgs mParseProviderArgs;
217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 /** If set to true, we will only allow package files that exactly match
219 * the DTD. Otherwise, we try to get as much from the package as we
220 * can without failing. This should normally be set to false, to
221 * support extensions to the DTD in future versions. */
222 private static final boolean RIGID_PARSER = false;
223
224 private static final String TAG = "PackageParser";
225
226 public PackageParser(String archiveSourcePath) {
227 mArchiveSourcePath = archiveSourcePath;
228 }
229
230 public void setSeparateProcesses(String[] procs) {
231 mSeparateProcesses = procs;
232 }
233
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700234 public void setOnlyCoreApps(boolean onlyCoreApps) {
235 mOnlyCoreApps = onlyCoreApps;
236 }
237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 private static final boolean isPackageFilename(String name) {
239 return name.endsWith(".apk");
240 }
241
Amith Yamasani13593602012-03-22 16:16:17 -0700242 public static PackageInfo generatePackageInfo(PackageParser.Package p,
243 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
244 HashSet<String> grantedPermissions) {
245
246 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
247 grantedPermissions, false, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
248 UserId.getCallingUserId());
249 }
250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 /**
252 * Generate and return the {@link PackageInfo} for a parsed package.
253 *
254 * @param p the parsed package.
255 * @param flags indicating which optional information is included.
256 */
257 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800258 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700259 HashSet<String> grantedPermissions, boolean stopped, int enabledState) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260
Amith Yamasani483f3b02012-03-13 16:08:00 -0700261 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700262 grantedPermissions, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani483f3b02012-03-13 16:08:00 -0700263 }
264
Amith Yamasani13593602012-03-22 16:16:17 -0700265 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700266 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700267 HashSet<String> grantedPermissions, boolean stopped, int enabledState, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 PackageInfo pi = new PackageInfo();
270 pi.packageName = p.packageName;
271 pi.versionCode = p.mVersionCode;
272 pi.versionName = p.mVersionName;
273 pi.sharedUserId = p.mSharedUserId;
274 pi.sharedUserLabel = p.mSharedUserLabel;
Amith Yamasani13593602012-03-22 16:16:17 -0700275 pi.applicationInfo = generateApplicationInfo(p, flags, stopped, enabledState, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800276 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700277 pi.firstInstallTime = firstInstallTime;
278 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 if ((flags&PackageManager.GET_GIDS) != 0) {
280 pi.gids = gids;
281 }
282 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
283 int N = p.configPreferences.size();
284 if (N > 0) {
285 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700286 p.configPreferences.toArray(pi.configPreferences);
287 }
288 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
289 if (N > 0) {
290 pi.reqFeatures = new FeatureInfo[N];
291 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 }
293 }
294 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
295 int N = p.activities.size();
296 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700297 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
298 pi.activities = new ActivityInfo[N];
299 } else {
300 int num = 0;
301 for (int i=0; i<N; i++) {
302 if (p.activities.get(i).info.enabled) num++;
303 }
304 pi.activities = new ActivityInfo[num];
305 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700306 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 final Activity activity = p.activities.get(i);
308 if (activity.info.enabled
309 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700310 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Amith Yamasani13593602012-03-22 16:16:17 -0700311 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313 }
314 }
315 }
316 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
317 int N = p.receivers.size();
318 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700319 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
320 pi.receivers = new ActivityInfo[N];
321 } else {
322 int num = 0;
323 for (int i=0; i<N; i++) {
324 if (p.receivers.get(i).info.enabled) num++;
325 }
326 pi.receivers = new ActivityInfo[num];
327 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700328 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 final Activity activity = p.receivers.get(i);
330 if (activity.info.enabled
331 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700332 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
333 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
335 }
336 }
337 }
338 if ((flags&PackageManager.GET_SERVICES) != 0) {
339 int N = p.services.size();
340 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700341 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
342 pi.services = new ServiceInfo[N];
343 } else {
344 int num = 0;
345 for (int i=0; i<N; i++) {
346 if (p.services.get(i).info.enabled) num++;
347 }
348 pi.services = new ServiceInfo[num];
349 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700350 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 final Service service = p.services.get(i);
352 if (service.info.enabled
353 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700354 pi.services[j++] = generateServiceInfo(p.services.get(i), flags, stopped,
355 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 }
357 }
358 }
359 }
360 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
361 int N = p.providers.size();
362 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700363 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
364 pi.providers = new ProviderInfo[N];
365 } else {
366 int num = 0;
367 for (int i=0; i<N; i++) {
368 if (p.providers.get(i).info.enabled) num++;
369 }
370 pi.providers = new ProviderInfo[num];
371 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700372 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 final Provider provider = p.providers.get(i);
374 if (provider.info.enabled
375 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700376 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, stopped,
377 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379 }
380 }
381 }
382 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
383 int N = p.instrumentation.size();
384 if (N > 0) {
385 pi.instrumentation = new InstrumentationInfo[N];
386 for (int i=0; i<N; i++) {
387 pi.instrumentation[i] = generateInstrumentationInfo(
388 p.instrumentation.get(i), flags);
389 }
390 }
391 }
392 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
393 int N = p.permissions.size();
394 if (N > 0) {
395 pi.permissions = new PermissionInfo[N];
396 for (int i=0; i<N; i++) {
397 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
398 }
399 }
400 N = p.requestedPermissions.size();
401 if (N > 0) {
402 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800403 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800405 final String perm = p.requestedPermissions.get(i);
406 pi.requestedPermissions[i] = perm;
407 if (p.requestedPermissionsRequired.get(i)) {
408 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
409 }
410 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
411 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414 }
415 }
416 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700417 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
418 if (N > 0) {
419 pi.signatures = new Signature[N];
420 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 }
422 }
423 return pi;
424 }
425
426 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
427 byte[] readBuffer) {
428 try {
429 // We must read the stream for the JarEntry to retrieve
430 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700431 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
433 // not using
434 }
435 is.close();
436 return je != null ? je.getCertificates() : null;
437 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700438 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700440 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700441 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700442 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
444 return null;
445 }
446
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800447 public final static int PARSE_IS_SYSTEM = 1<<0;
448 public final static int PARSE_CHATTY = 1<<1;
449 public final static int PARSE_MUST_BE_APK = 1<<2;
450 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
451 public final static int PARSE_FORWARD_LOCK = 1<<4;
452 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700453 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454
455 public int getParseError() {
456 return mParseError;
457 }
458
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800459 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 DisplayMetrics metrics, int flags) {
461 mParseError = PackageManager.INSTALL_SUCCEEDED;
462
463 mArchiveSourcePath = sourceFile.getPath();
464 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700465 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
467 return null;
468 }
469 if (!isPackageFilename(sourceFile.getName())
470 && (flags&PARSE_MUST_BE_APK) != 0) {
471 if ((flags&PARSE_IS_SYSTEM) == 0) {
472 // We expect to have non-.apk files in the system dir,
473 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700474 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 }
476 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
477 return null;
478 }
479
Kenny Rootd2d29252011-08-08 11:27:57 -0700480 if (DEBUG_JAR)
481 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482
483 XmlResourceParser parser = null;
484 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800485 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 boolean assetError = true;
487 try {
488 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700489 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800490 if (cookie != 0) {
491 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700492 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 -0800493 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700494 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 assetError = false;
496 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700497 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700500 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 + mArchiveSourcePath, e);
502 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800503 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 if (assmgr != null) assmgr.close();
505 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
506 return null;
507 }
508 String[] errorText = new String[1];
509 Package pkg = null;
510 Exception errorException = null;
511 try {
512 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 pkg = parsePackage(res, parser, flags, errorText);
514 } catch (Exception e) {
515 errorException = e;
516 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
517 }
518
519
520 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700521 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
522 // just means to skip this app so don't make a fuss about it.
523 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
524 if (errorException != null) {
525 Slog.w(TAG, mArchiveSourcePath, errorException);
526 } else {
527 Slog.w(TAG, mArchiveSourcePath + " (at "
528 + parser.getPositionDescription()
529 + "): " + errorText[0]);
530 }
531 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
532 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 }
535 parser.close();
536 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 return null;
538 }
539
540 parser.close();
541 assmgr.close();
542
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800543 // Set code and resource paths
544 pkg.mPath = destCodePath;
545 pkg.mScanPath = mArchiveSourcePath;
546 //pkg.applicationInfo.sourceDir = destCodePath;
547 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 pkg.mSignatures = null;
549
550 return pkg;
551 }
552
553 public boolean collectCertificates(Package pkg, int flags) {
554 pkg.mSignatures = null;
555
556 WeakReference<byte[]> readBufferRef;
557 byte[] readBuffer = null;
558 synchronized (mSync) {
559 readBufferRef = mReadBuffer;
560 if (readBufferRef != null) {
561 mReadBuffer = null;
562 readBuffer = readBufferRef.get();
563 }
564 if (readBuffer == null) {
565 readBuffer = new byte[8192];
566 readBufferRef = new WeakReference<byte[]>(readBuffer);
567 }
568 }
569
570 try {
571 JarFile jarFile = new JarFile(mArchiveSourcePath);
572
573 Certificate[] certs = null;
574
575 if ((flags&PARSE_IS_SYSTEM) != 0) {
576 // If this package comes from the system image, then we
577 // can trust it... we'll just use the AndroidManifest.xml
578 // to retrieve its signatures, not validating all of the
579 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700580 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 certs = loadCertificates(jarFile, jarEntry, readBuffer);
582 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700583 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 + " has no certificates at entry "
585 + jarEntry.getName() + "; ignoring!");
586 jarFile.close();
587 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
588 return false;
589 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700590 if (DEBUG_JAR) {
591 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 + " certs=" + (certs != null ? certs.length : 0));
593 if (certs != null) {
594 final int N = certs.length;
595 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700596 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 + certs[i].getPublicKey().getEncoded()
598 + " " + certs[i].getPublicKey());
599 }
600 }
601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700603 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700604 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700606 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700608
Kenny Rootbcc954d2011-08-08 16:19:08 -0700609 final String name = je.getName();
610
611 if (name.startsWith("META-INF/"))
612 continue;
613
614 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
615 final Attributes attributes = manifest.getAttributes(name);
616 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
617 }
618
619 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700620 if (DEBUG_JAR) {
621 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 + ": certs=" + certs + " ("
623 + (certs != null ? certs.length : 0) + ")");
624 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700627 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 + " has no certificates at entry "
629 + je.getName() + "; ignoring!");
630 jarFile.close();
631 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
632 return false;
633 } else if (certs == null) {
634 certs = localCerts;
635 } else {
636 // Ensure all certificates match.
637 for (int i=0; i<certs.length; i++) {
638 boolean found = false;
639 for (int j=0; j<localCerts.length; j++) {
640 if (certs[i] != null &&
641 certs[i].equals(localCerts[j])) {
642 found = true;
643 break;
644 }
645 }
646 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700647 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 + " has mismatched certificates at entry "
649 + je.getName() + "; ignoring!");
650 jarFile.close();
651 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
652 return false;
653 }
654 }
655 }
656 }
657 }
658 jarFile.close();
659
660 synchronized (mSync) {
661 mReadBuffer = readBufferRef;
662 }
663
664 if (certs != null && certs.length > 0) {
665 final int N = certs.length;
666 pkg.mSignatures = new Signature[certs.length];
667 for (int i=0; i<N; i++) {
668 pkg.mSignatures[i] = new Signature(
669 certs[i].getEncoded());
670 }
671 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700672 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 + " has no certificates; ignoring!");
674 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
675 return false;
676 }
677 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700678 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
680 return false;
681 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700682 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
684 return false;
685 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700686 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
688 return false;
689 }
690
691 return true;
692 }
693
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800694 /*
695 * Utility method that retrieves just the package name and install
696 * location from the apk location at the given file path.
697 * @param packageFilePath file location of the apk
698 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700699 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800700 */
701 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700703 final XmlResourceParser parser;
704 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 try {
706 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700707 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 -0800708 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700711 if (cookie == 0) {
712 return null;
713 }
714
Kenny Root05ca4c92011-09-15 10:36:25 -0700715 final DisplayMetrics metrics = new DisplayMetrics();
716 metrics.setToDefaults();
717 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700718 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 } catch (Exception e) {
720 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700721 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 + packageFilePath, e);
723 return null;
724 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700725
726 final AttributeSet attrs = parser;
727 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800728 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700730 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700732 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700734 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 } finally {
736 if (parser != null) parser.close();
737 if (assmgr != null) assmgr.close();
738 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800739 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700740 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 return null;
742 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800743 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745
746 private static String validateName(String name, boolean requiresSeparator) {
747 final int N = name.length();
748 boolean hasSep = false;
749 boolean front = true;
750 for (int i=0; i<N; i++) {
751 final char c = name.charAt(i);
752 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
753 front = false;
754 continue;
755 }
756 if (!front) {
757 if ((c >= '0' && c <= '9') || c == '_') {
758 continue;
759 }
760 }
761 if (c == '.') {
762 hasSep = true;
763 front = true;
764 continue;
765 }
766 return "bad character '" + c + "'";
767 }
768 return hasSep || !requiresSeparator
769 ? null : "must have at least one '.' separator";
770 }
771
772 private static String parsePackageName(XmlPullParser parser,
773 AttributeSet attrs, int flags, String[] outError)
774 throws IOException, XmlPullParserException {
775
776 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700777 while ((type = parser.next()) != XmlPullParser.START_TAG
778 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 ;
780 }
781
Kenny Rootd2d29252011-08-08 11:27:57 -0700782 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 outError[0] = "No start tag found";
784 return null;
785 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700786 if (DEBUG_PARSER)
787 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 if (!parser.getName().equals("manifest")) {
789 outError[0] = "No <manifest> tag";
790 return null;
791 }
792 String pkgName = attrs.getAttributeValue(null, "package");
793 if (pkgName == null || pkgName.length() == 0) {
794 outError[0] = "<manifest> does not specify package";
795 return null;
796 }
797 String nameError = validateName(pkgName, true);
798 if (nameError != null && !"android".equals(pkgName)) {
799 outError[0] = "<manifest> specifies bad package name \""
800 + pkgName + "\": " + nameError;
801 return null;
802 }
803
804 return pkgName.intern();
805 }
806
Kenny Root05ca4c92011-09-15 10:36:25 -0700807 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
808 AttributeSet attrs, int flags, String[] outError) throws IOException,
809 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800810
811 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700812 while ((type = parser.next()) != XmlPullParser.START_TAG
813 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800814 ;
815 }
816
Kenny Rootd2d29252011-08-08 11:27:57 -0700817 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800818 outError[0] = "No start tag found";
819 return null;
820 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700821 if (DEBUG_PARSER)
822 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800823 if (!parser.getName().equals("manifest")) {
824 outError[0] = "No <manifest> tag";
825 return null;
826 }
827 String pkgName = attrs.getAttributeValue(null, "package");
828 if (pkgName == null || pkgName.length() == 0) {
829 outError[0] = "<manifest> does not specify package";
830 return null;
831 }
832 String nameError = validateName(pkgName, true);
833 if (nameError != null && !"android".equals(pkgName)) {
834 outError[0] = "<manifest> specifies bad package name \""
835 + pkgName + "\": " + nameError;
836 return null;
837 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700838 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800839 for (int i = 0; i < attrs.getAttributeCount(); i++) {
840 String attr = attrs.getAttributeName(i);
841 if (attr.equals("installLocation")) {
842 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700843 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800844 break;
845 }
846 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700847
848 // Only search the tree when the tag is directly below <manifest>
849 final int searchDepth = parser.getDepth() + 1;
850
851 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
852 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
853 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
854 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
855 continue;
856 }
857
858 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
859 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
860 if (verifier != null) {
861 verifiers.add(verifier);
862 }
863 }
864 }
865
866 return new PackageLite(pkgName.intern(), installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800867 }
868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 /**
870 * Temporary.
871 */
872 static public Signature stringToSignature(String str) {
873 final int N = str.length();
874 byte[] sig = new byte[N];
875 for (int i=0; i<N; i++) {
876 sig[i] = (byte)str.charAt(i);
877 }
878 return new Signature(sig);
879 }
880
881 private Package parsePackage(
882 Resources res, XmlResourceParser parser, int flags, String[] outError)
883 throws XmlPullParserException, IOException {
884 AttributeSet attrs = parser;
885
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700886 mParseInstrumentationArgs = null;
887 mParseActivityArgs = null;
888 mParseServiceArgs = null;
889 mParseProviderArgs = null;
890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 String pkgName = parsePackageName(parser, attrs, flags, outError);
892 if (pkgName == null) {
893 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
894 return null;
895 }
896 int type;
897
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700898 if (mOnlyCoreApps) {
899 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
900 if (!core) {
901 mParseError = PackageManager.INSTALL_SUCCEEDED;
902 return null;
903 }
904 }
905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 TypedArray sa = res.obtainAttributes(attrs,
910 com.android.internal.R.styleable.AndroidManifest);
911 pkg.mVersionCode = sa.getInteger(
912 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800913 pkg.mVersionName = sa.getNonConfigurationString(
914 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 if (pkg.mVersionName != null) {
916 pkg.mVersionName = pkg.mVersionName.intern();
917 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800918 String str = sa.getNonConfigurationString(
919 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
920 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 String nameError = validateName(str, true);
922 if (nameError != null && !"android".equals(pkgName)) {
923 outError[0] = "<manifest> specifies bad sharedUserId name \""
924 + str + "\": " + nameError;
925 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
926 return null;
927 }
928 pkg.mSharedUserId = str.intern();
929 pkg.mSharedUserLabel = sa.getResourceId(
930 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
931 }
932 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800933
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800934 pkg.installLocation = sa.getInteger(
935 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700936 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700937 pkg.applicationInfo.installLocation = pkg.installLocation;
938
Dianne Hackborn723738c2009-06-25 19:48:04 -0700939 // Resource boolean are -1, so 1 means we don't know the value.
940 int supportsSmallScreens = 1;
941 int supportsNormalScreens = 1;
942 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700943 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700944 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700945 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700948 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
949 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
950 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 continue;
952 }
953
954 String tagName = parser.getName();
955 if (tagName.equals("application")) {
956 if (foundApp) {
957 if (RIGID_PARSER) {
958 outError[0] = "<manifest> has more than one <application>";
959 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
960 return null;
961 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700962 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 XmlUtils.skipCurrentTag(parser);
964 continue;
965 }
966 }
967
968 foundApp = true;
969 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
970 return null;
971 }
972 } else if (tagName.equals("permission-group")) {
973 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
974 return null;
975 }
976 } else if (tagName.equals("permission")) {
977 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
978 return null;
979 }
980 } else if (tagName.equals("permission-tree")) {
981 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
982 return null;
983 }
984 } else if (tagName.equals("uses-permission")) {
985 sa = res.obtainAttributes(attrs,
986 com.android.internal.R.styleable.AndroidManifestUsesPermission);
987
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800988 // Note: don't allow this value to be a reference to a resource
989 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 String name = sa.getNonResourceString(
991 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne639da72012-02-21 15:11:13 -0800992 boolean required = sa.getBoolean(
993 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994
995 sa.recycle();
996
997 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700998 pkg.requestedPermissions.add(name.intern());
Dianne Hackborn65696252012-03-05 18:49:21 -0800999 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 }
1001
1002 XmlUtils.skipCurrentTag(parser);
1003
1004 } else if (tagName.equals("uses-configuration")) {
1005 ConfigurationInfo cPref = new ConfigurationInfo();
1006 sa = res.obtainAttributes(attrs,
1007 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1008 cPref.reqTouchScreen = sa.getInt(
1009 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1010 Configuration.TOUCHSCREEN_UNDEFINED);
1011 cPref.reqKeyboardType = sa.getInt(
1012 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1013 Configuration.KEYBOARD_UNDEFINED);
1014 if (sa.getBoolean(
1015 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1016 false)) {
1017 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1018 }
1019 cPref.reqNavigation = sa.getInt(
1020 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1021 Configuration.NAVIGATION_UNDEFINED);
1022 if (sa.getBoolean(
1023 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1024 false)) {
1025 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1026 }
1027 sa.recycle();
1028 pkg.configPreferences.add(cPref);
1029
1030 XmlUtils.skipCurrentTag(parser);
1031
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001032 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001033 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001034 sa = res.obtainAttributes(attrs,
1035 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001036 // Note: don't allow this value to be a reference to a resource
1037 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001038 fi.name = sa.getNonResourceString(
1039 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1040 if (fi.name == null) {
1041 fi.reqGlEsVersion = sa.getInt(
1042 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1043 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1044 }
1045 if (sa.getBoolean(
1046 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1047 true)) {
1048 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1049 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001050 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001051 if (pkg.reqFeatures == null) {
1052 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1053 }
1054 pkg.reqFeatures.add(fi);
1055
1056 if (fi.name == null) {
1057 ConfigurationInfo cPref = new ConfigurationInfo();
1058 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1059 pkg.configPreferences.add(cPref);
1060 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001061
1062 XmlUtils.skipCurrentTag(parser);
1063
Dianne Hackborn851a5412009-05-08 12:06:44 -07001064 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001065 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 sa = res.obtainAttributes(attrs,
1067 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1068
Dianne Hackborn851a5412009-05-08 12:06:44 -07001069 int minVers = 0;
1070 String minCode = null;
1071 int targetVers = 0;
1072 String targetCode = null;
1073
1074 TypedValue val = sa.peekValue(
1075 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1076 if (val != null) {
1077 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1078 targetCode = minCode = val.string.toString();
1079 } else {
1080 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001081 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001082 }
1083 }
1084
1085 val = sa.peekValue(
1086 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1087 if (val != null) {
1088 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1089 targetCode = minCode = val.string.toString();
1090 } else {
1091 // If it's not a string, it's an integer.
1092 targetVers = val.data;
1093 }
1094 }
1095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 sa.recycle();
1097
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001098 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001099 if (!minCode.equals(SDK_CODENAME)) {
1100 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001101 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001102 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001103 } else {
1104 outError[0] = "Requires development platform " + minCode
1105 + " but this is a release platform.";
1106 }
1107 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1108 return null;
1109 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001110 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001111 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001112 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001113 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1114 return null;
1115 }
1116
Dianne Hackborn851a5412009-05-08 12:06:44 -07001117 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001118 if (!targetCode.equals(SDK_CODENAME)) {
1119 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001120 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001121 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001122 } else {
1123 outError[0] = "Requires development platform " + targetCode
1124 + " but this is a release platform.";
1125 }
1126 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1127 return null;
1128 }
1129 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001130 pkg.applicationInfo.targetSdkVersion
1131 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1132 } else {
1133 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136
1137 XmlUtils.skipCurrentTag(parser);
1138
Dianne Hackborn723738c2009-06-25 19:48:04 -07001139 } else if (tagName.equals("supports-screens")) {
1140 sa = res.obtainAttributes(attrs,
1141 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1142
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001143 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1144 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1145 0);
1146 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1147 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1148 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001149 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1150 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1151 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001152
Dianne Hackborn723738c2009-06-25 19:48:04 -07001153 // This is a trick to get a boolean and still able to detect
1154 // if a value was actually set.
1155 supportsSmallScreens = sa.getInteger(
1156 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1157 supportsSmallScreens);
1158 supportsNormalScreens = sa.getInteger(
1159 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1160 supportsNormalScreens);
1161 supportsLargeScreens = sa.getInteger(
1162 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1163 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001164 supportsXLargeScreens = sa.getInteger(
1165 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1166 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001167 resizeable = sa.getInteger(
1168 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001169 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001170 anyDensity = sa.getInteger(
1171 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1172 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001173
1174 sa.recycle();
1175
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001176 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001177
1178 } else if (tagName.equals("protected-broadcast")) {
1179 sa = res.obtainAttributes(attrs,
1180 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1181
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001182 // Note: don't allow this value to be a reference to a resource
1183 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001184 String name = sa.getNonResourceString(
1185 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1186
1187 sa.recycle();
1188
1189 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1190 if (pkg.protectedBroadcasts == null) {
1191 pkg.protectedBroadcasts = new ArrayList<String>();
1192 }
1193 if (!pkg.protectedBroadcasts.contains(name)) {
1194 pkg.protectedBroadcasts.add(name.intern());
1195 }
1196 }
1197
1198 XmlUtils.skipCurrentTag(parser);
1199
1200 } else if (tagName.equals("instrumentation")) {
1201 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1202 return null;
1203 }
1204
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001205 } else if (tagName.equals("original-package")) {
1206 sa = res.obtainAttributes(attrs,
1207 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1208
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001209 String orig =sa.getNonConfigurationString(
1210 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001211 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001212 if (pkg.mOriginalPackages == null) {
1213 pkg.mOriginalPackages = new ArrayList<String>();
1214 pkg.mRealPackage = pkg.packageName;
1215 }
1216 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001217 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001218
1219 sa.recycle();
1220
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001221 XmlUtils.skipCurrentTag(parser);
1222
1223 } else if (tagName.equals("adopt-permissions")) {
1224 sa = res.obtainAttributes(attrs,
1225 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1226
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001227 String name = sa.getNonConfigurationString(
1228 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001229
1230 sa.recycle();
1231
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001232 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001233 if (pkg.mAdoptPermissions == null) {
1234 pkg.mAdoptPermissions = new ArrayList<String>();
1235 }
1236 pkg.mAdoptPermissions.add(name);
1237 }
1238
1239 XmlUtils.skipCurrentTag(parser);
1240
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001241 } else if (tagName.equals("uses-gl-texture")) {
1242 // Just skip this tag
1243 XmlUtils.skipCurrentTag(parser);
1244 continue;
1245
1246 } else if (tagName.equals("compatible-screens")) {
1247 // Just skip this tag
1248 XmlUtils.skipCurrentTag(parser);
1249 continue;
1250
Dianne Hackborn854060a2009-07-09 18:14:31 -07001251 } else if (tagName.equals("eat-comment")) {
1252 // Just skip this tag
1253 XmlUtils.skipCurrentTag(parser);
1254 continue;
1255
1256 } else if (RIGID_PARSER) {
1257 outError[0] = "Bad element under <manifest>: "
1258 + parser.getName();
1259 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1260 return null;
1261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001263 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001264 + " at " + mArchiveSourcePath + " "
1265 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 XmlUtils.skipCurrentTag(parser);
1267 continue;
1268 }
1269 }
1270
1271 if (!foundApp && pkg.instrumentation.size() == 0) {
1272 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1273 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1274 }
1275
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001276 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001277 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001278 for (int ip=0; ip<NP; ip++) {
1279 final PackageParser.NewPermissionInfo npi
1280 = PackageParser.NEW_PERMISSIONS[ip];
1281 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1282 break;
1283 }
1284 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001285 if (implicitPerms == null) {
1286 implicitPerms = new StringBuilder(128);
1287 implicitPerms.append(pkg.packageName);
1288 implicitPerms.append(": compat added ");
1289 } else {
1290 implicitPerms.append(' ');
1291 }
1292 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001293 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001294 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001295 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001296 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001297 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001298 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001299 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001300
1301 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1302 for (int is=0; is<NS; is++) {
1303 final PackageParser.SplitPermissionInfo spi
1304 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001305 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1306 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001307 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001308 }
1309 for (int in=0; in<spi.newPerms.length; in++) {
1310 final String perm = spi.newPerms[in];
1311 if (!pkg.requestedPermissions.contains(perm)) {
1312 pkg.requestedPermissions.add(perm);
1313 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1314 }
1315 }
1316 }
1317
Dianne Hackborn723738c2009-06-25 19:48:04 -07001318 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1319 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001320 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001321 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1322 }
1323 if (supportsNormalScreens != 0) {
1324 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1325 }
1326 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1327 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001328 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001329 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1330 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001331 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1332 && pkg.applicationInfo.targetSdkVersion
1333 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1334 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1335 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001336 if (resizeable < 0 || (resizeable > 0
1337 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001338 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001339 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1340 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001341 if (anyDensity < 0 || (anyDensity > 0
1342 && pkg.applicationInfo.targetSdkVersion
1343 >= android.os.Build.VERSION_CODES.DONUT)) {
1344 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001345 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 return pkg;
1348 }
1349
1350 private static String buildClassName(String pkg, CharSequence clsSeq,
1351 String[] outError) {
1352 if (clsSeq == null || clsSeq.length() <= 0) {
1353 outError[0] = "Empty class name in package " + pkg;
1354 return null;
1355 }
1356 String cls = clsSeq.toString();
1357 char c = cls.charAt(0);
1358 if (c == '.') {
1359 return (pkg + cls).intern();
1360 }
1361 if (cls.indexOf('.') < 0) {
1362 StringBuilder b = new StringBuilder(pkg);
1363 b.append('.');
1364 b.append(cls);
1365 return b.toString().intern();
1366 }
1367 if (c >= 'a' && c <= 'z') {
1368 return cls.intern();
1369 }
1370 outError[0] = "Bad class name " + cls + " in package " + pkg;
1371 return null;
1372 }
1373
1374 private static String buildCompoundName(String pkg,
1375 CharSequence procSeq, String type, String[] outError) {
1376 String proc = procSeq.toString();
1377 char c = proc.charAt(0);
1378 if (pkg != null && c == ':') {
1379 if (proc.length() < 2) {
1380 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1381 + ": must be at least two characters";
1382 return null;
1383 }
1384 String subName = proc.substring(1);
1385 String nameError = validateName(subName, false);
1386 if (nameError != null) {
1387 outError[0] = "Invalid " + type + " name " + proc + " in package "
1388 + pkg + ": " + nameError;
1389 return null;
1390 }
1391 return (pkg + proc).intern();
1392 }
1393 String nameError = validateName(proc, true);
1394 if (nameError != null && !"system".equals(proc)) {
1395 outError[0] = "Invalid " + type + " name " + proc + " in package "
1396 + pkg + ": " + nameError;
1397 return null;
1398 }
1399 return proc.intern();
1400 }
1401
1402 private static String buildProcessName(String pkg, String defProc,
1403 CharSequence procSeq, int flags, String[] separateProcesses,
1404 String[] outError) {
1405 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1406 return defProc != null ? defProc : pkg;
1407 }
1408 if (separateProcesses != null) {
1409 for (int i=separateProcesses.length-1; i>=0; i--) {
1410 String sp = separateProcesses[i];
1411 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1412 return pkg;
1413 }
1414 }
1415 }
1416 if (procSeq == null || procSeq.length() <= 0) {
1417 return defProc;
1418 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001419 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 }
1421
1422 private static String buildTaskAffinityName(String pkg, String defProc,
1423 CharSequence procSeq, String[] outError) {
1424 if (procSeq == null) {
1425 return defProc;
1426 }
1427 if (procSeq.length() <= 0) {
1428 return null;
1429 }
1430 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1431 }
1432
1433 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1434 XmlPullParser parser, AttributeSet attrs, String[] outError)
1435 throws XmlPullParserException, IOException {
1436 PermissionGroup perm = new PermissionGroup(owner);
1437
1438 TypedArray sa = res.obtainAttributes(attrs,
1439 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1440
1441 if (!parsePackageItemInfo(owner, perm.info, outError,
1442 "<permission-group>", sa,
1443 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1444 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001445 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1446 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 sa.recycle();
1448 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1449 return null;
1450 }
1451
1452 perm.info.descriptionRes = sa.getResourceId(
1453 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1454 0);
1455
1456 sa.recycle();
1457
1458 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1459 outError)) {
1460 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1461 return null;
1462 }
1463
1464 owner.permissionGroups.add(perm);
1465
1466 return perm;
1467 }
1468
1469 private Permission parsePermission(Package owner, Resources res,
1470 XmlPullParser parser, AttributeSet attrs, String[] outError)
1471 throws XmlPullParserException, IOException {
1472 Permission perm = new Permission(owner);
1473
1474 TypedArray sa = res.obtainAttributes(attrs,
1475 com.android.internal.R.styleable.AndroidManifestPermission);
1476
1477 if (!parsePackageItemInfo(owner, perm.info, outError,
1478 "<permission>", sa,
1479 com.android.internal.R.styleable.AndroidManifestPermission_name,
1480 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001481 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1482 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 sa.recycle();
1484 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1485 return null;
1486 }
1487
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001488 // Note: don't allow this value to be a reference to a resource
1489 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 perm.info.group = sa.getNonResourceString(
1491 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1492 if (perm.info.group != null) {
1493 perm.info.group = perm.info.group.intern();
1494 }
1495
1496 perm.info.descriptionRes = sa.getResourceId(
1497 com.android.internal.R.styleable.AndroidManifestPermission_description,
1498 0);
1499
1500 perm.info.protectionLevel = sa.getInt(
1501 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1502 PermissionInfo.PROTECTION_NORMAL);
1503
1504 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 if (perm.info.protectionLevel == -1) {
1507 outError[0] = "<permission> does not specify protectionLevel";
1508 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1509 return null;
1510 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001511
1512 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1513
1514 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1515 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1516 PermissionInfo.PROTECTION_SIGNATURE) {
1517 outError[0] = "<permission> protectionLevel specifies a flag but is "
1518 + "not based on signature type";
1519 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1520 return null;
1521 }
1522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523
1524 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1525 outError)) {
1526 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1527 return null;
1528 }
1529
1530 owner.permissions.add(perm);
1531
1532 return perm;
1533 }
1534
1535 private Permission parsePermissionTree(Package owner, Resources res,
1536 XmlPullParser parser, AttributeSet attrs, String[] outError)
1537 throws XmlPullParserException, IOException {
1538 Permission perm = new Permission(owner);
1539
1540 TypedArray sa = res.obtainAttributes(attrs,
1541 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1542
1543 if (!parsePackageItemInfo(owner, perm.info, outError,
1544 "<permission-tree>", sa,
1545 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1546 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001547 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1548 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 sa.recycle();
1550 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1551 return null;
1552 }
1553
1554 sa.recycle();
1555
1556 int index = perm.info.name.indexOf('.');
1557 if (index > 0) {
1558 index = perm.info.name.indexOf('.', index+1);
1559 }
1560 if (index < 0) {
1561 outError[0] = "<permission-tree> name has less than three segments: "
1562 + perm.info.name;
1563 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1564 return null;
1565 }
1566
1567 perm.info.descriptionRes = 0;
1568 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1569 perm.tree = true;
1570
1571 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1572 outError)) {
1573 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1574 return null;
1575 }
1576
1577 owner.permissions.add(perm);
1578
1579 return perm;
1580 }
1581
1582 private Instrumentation parseInstrumentation(Package owner, Resources res,
1583 XmlPullParser parser, AttributeSet attrs, String[] outError)
1584 throws XmlPullParserException, IOException {
1585 TypedArray sa = res.obtainAttributes(attrs,
1586 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1587
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001588 if (mParseInstrumentationArgs == null) {
1589 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1590 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1591 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001592 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1593 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001594 mParseInstrumentationArgs.tag = "<instrumentation>";
1595 }
1596
1597 mParseInstrumentationArgs.sa = sa;
1598
1599 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1600 new InstrumentationInfo());
1601 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 sa.recycle();
1603 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1604 return null;
1605 }
1606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001608 // Note: don't allow this value to be a reference to a resource
1609 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 str = sa.getNonResourceString(
1611 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1612 a.info.targetPackage = str != null ? str.intern() : null;
1613
1614 a.info.handleProfiling = sa.getBoolean(
1615 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1616 false);
1617
1618 a.info.functionalTest = sa.getBoolean(
1619 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1620 false);
1621
1622 sa.recycle();
1623
1624 if (a.info.targetPackage == null) {
1625 outError[0] = "<instrumentation> does not specify targetPackage";
1626 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1627 return null;
1628 }
1629
1630 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1631 outError)) {
1632 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1633 return null;
1634 }
1635
1636 owner.instrumentation.add(a);
1637
1638 return a;
1639 }
1640
1641 private boolean parseApplication(Package owner, Resources res,
1642 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1643 throws XmlPullParserException, IOException {
1644 final ApplicationInfo ai = owner.applicationInfo;
1645 final String pkgName = owner.applicationInfo.packageName;
1646
1647 TypedArray sa = res.obtainAttributes(attrs,
1648 com.android.internal.R.styleable.AndroidManifestApplication);
1649
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001650 String name = sa.getNonConfigurationString(
1651 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 if (name != null) {
1653 ai.className = buildClassName(pkgName, name, outError);
1654 if (ai.className == null) {
1655 sa.recycle();
1656 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1657 return false;
1658 }
1659 }
1660
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001661 String manageSpaceActivity = sa.getNonConfigurationString(
1662 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 if (manageSpaceActivity != null) {
1664 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1665 outError);
1666 }
1667
Christopher Tate181fafa2009-05-14 11:12:14 -07001668 boolean allowBackup = sa.getBoolean(
1669 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1670 if (allowBackup) {
1671 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001672
Christopher Tate3de55bc2010-03-12 17:28:08 -08001673 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1674 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001675 String backupAgent = sa.getNonConfigurationString(
1676 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001677 if (backupAgent != null) {
1678 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001679 if (DEBUG_BACKUP) {
1680 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001681 + " from " + pkgName + "+" + backupAgent);
1682 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001683
1684 if (sa.getBoolean(
1685 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1686 true)) {
1687 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1688 }
1689 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001690 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1691 false)) {
1692 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1693 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001694 }
1695 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 TypedValue v = sa.peekValue(
1698 com.android.internal.R.styleable.AndroidManifestApplication_label);
1699 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1700 ai.nonLocalizedLabel = v.coerceToString();
1701 }
1702
1703 ai.icon = sa.getResourceId(
1704 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001705 ai.logo = sa.getResourceId(
1706 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001708 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 ai.descriptionRes = sa.getResourceId(
1710 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1711
1712 if ((flags&PARSE_IS_SYSTEM) != 0) {
1713 if (sa.getBoolean(
1714 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1715 false)) {
1716 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1717 }
1718 }
1719
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001720 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1721 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1722 }
1723
1724 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001725 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001726 }
1727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 if (sa.getBoolean(
1729 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1730 false)) {
1731 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1732 }
1733
1734 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001735 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001736 false)) {
1737 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1738 }
1739
Romain Guy529b60a2010-08-03 18:05:47 -07001740 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001741 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001742 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001743
1744 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001745 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1746 true)) {
1747 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1748 }
1749
1750 if (sa.getBoolean(
1751 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1752 false)) {
1753 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1754 }
1755
1756 if (sa.getBoolean(
1757 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1758 true)) {
1759 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1760 }
1761
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001762 if (sa.getBoolean(
1763 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001764 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001765 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1766 }
1767
Jason parksa3cdaa52011-01-13 14:15:43 -06001768 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001769 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001770 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001771 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001772 }
1773
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001774 if (sa.getBoolean(
1775 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1776 false /* default is no RTL support*/)) {
1777 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1778 }
1779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001781 str = sa.getNonConfigurationString(
1782 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1784
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001785 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1786 str = sa.getNonConfigurationString(
1787 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1788 } else {
1789 // Some older apps have been seen to use a resource reference
1790 // here that on older builds was ignored (with a warning). We
1791 // need to continue to do this for them so they don't break.
1792 str = sa.getNonResourceString(
1793 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1796 str, outError);
1797
1798 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001799 CharSequence pname;
1800 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1801 pname = sa.getNonConfigurationString(
1802 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1803 } else {
1804 // Some older apps have been seen to use a resource reference
1805 // here that on older builds was ignored (with a warning). We
1806 // need to continue to do this for them so they don't break.
1807 pname = sa.getNonResourceString(
1808 com.android.internal.R.styleable.AndroidManifestApplication_process);
1809 }
1810 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 flags, mSeparateProcesses, outError);
1812
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001813 ai.enabled = sa.getBoolean(
1814 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001815
Dianne Hackborn02486b12010-08-26 14:18:37 -07001816 if (false) {
1817 if (sa.getBoolean(
1818 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1819 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001820 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001821
1822 // A heavy-weight application can not be in a custom process.
1823 // We can do direct compare because we intern all strings.
1824 if (ai.processName != null && ai.processName != ai.packageName) {
1825 outError[0] = "cantSaveState applications can not use custom processes";
1826 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001827 }
1828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 }
1830
Adam Powell269248d2011-08-02 10:26:54 -07001831 ai.uiOptions = sa.getInt(
1832 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 sa.recycle();
1835
1836 if (outError[0] != null) {
1837 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1838 return false;
1839 }
1840
1841 final int innerDepth = parser.getDepth();
1842
1843 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001844 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1845 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1846 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 continue;
1848 }
1849
1850 String tagName = parser.getName();
1851 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001852 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1853 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 if (a == null) {
1855 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1856 return false;
1857 }
1858
1859 owner.activities.add(a);
1860
1861 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001862 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 if (a == null) {
1864 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1865 return false;
1866 }
1867
1868 owner.receivers.add(a);
1869
1870 } else if (tagName.equals("service")) {
1871 Service s = parseService(owner, res, parser, attrs, flags, outError);
1872 if (s == null) {
1873 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1874 return false;
1875 }
1876
1877 owner.services.add(s);
1878
1879 } else if (tagName.equals("provider")) {
1880 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1881 if (p == null) {
1882 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1883 return false;
1884 }
1885
1886 owner.providers.add(p);
1887
1888 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001889 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 if (a == null) {
1891 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1892 return false;
1893 }
1894
1895 owner.activities.add(a);
1896
1897 } else if (parser.getName().equals("meta-data")) {
1898 // note: application meta-data is stored off to the side, so it can
1899 // remain null in the primary copy (we like to avoid extra copies because
1900 // it can be large)
1901 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1902 outError)) == null) {
1903 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1904 return false;
1905 }
1906
1907 } else if (tagName.equals("uses-library")) {
1908 sa = res.obtainAttributes(attrs,
1909 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1910
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001911 // Note: don't allow this value to be a reference to a resource
1912 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 String lname = sa.getNonResourceString(
1914 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001915 boolean req = sa.getBoolean(
1916 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1917 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918
1919 sa.recycle();
1920
Dianne Hackborn49237342009-08-27 20:08:01 -07001921 if (lname != null) {
1922 if (req) {
1923 if (owner.usesLibraries == null) {
1924 owner.usesLibraries = new ArrayList<String>();
1925 }
1926 if (!owner.usesLibraries.contains(lname)) {
1927 owner.usesLibraries.add(lname.intern());
1928 }
1929 } else {
1930 if (owner.usesOptionalLibraries == null) {
1931 owner.usesOptionalLibraries = new ArrayList<String>();
1932 }
1933 if (!owner.usesOptionalLibraries.contains(lname)) {
1934 owner.usesOptionalLibraries.add(lname.intern());
1935 }
1936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
1938
1939 XmlUtils.skipCurrentTag(parser);
1940
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001941 } else if (tagName.equals("uses-package")) {
1942 // Dependencies for app installers; we don't currently try to
1943 // enforce this.
1944 XmlUtils.skipCurrentTag(parser);
1945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 } else {
1947 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001948 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001949 + " at " + mArchiveSourcePath + " "
1950 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 XmlUtils.skipCurrentTag(parser);
1952 continue;
1953 } else {
1954 outError[0] = "Bad element under <application>: " + tagName;
1955 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1956 return false;
1957 }
1958 }
1959 }
1960
1961 return true;
1962 }
1963
1964 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1965 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001966 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001967 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 if (name == null) {
1969 outError[0] = tag + " does not specify android:name";
1970 return false;
1971 }
1972
1973 outInfo.name
1974 = buildClassName(owner.applicationInfo.packageName, name, outError);
1975 if (outInfo.name == null) {
1976 return false;
1977 }
1978
1979 int iconVal = sa.getResourceId(iconRes, 0);
1980 if (iconVal != 0) {
1981 outInfo.icon = iconVal;
1982 outInfo.nonLocalizedLabel = null;
1983 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001984
1985 int logoVal = sa.getResourceId(logoRes, 0);
1986 if (logoVal != 0) {
1987 outInfo.logo = logoVal;
1988 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989
1990 TypedValue v = sa.peekValue(labelRes);
1991 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1992 outInfo.nonLocalizedLabel = v.coerceToString();
1993 }
1994
1995 outInfo.packageName = owner.packageName;
1996
1997 return true;
1998 }
1999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 private Activity parseActivity(Package owner, Resources res,
2001 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002002 boolean receiver, boolean hardwareAccelerated)
2003 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 TypedArray sa = res.obtainAttributes(attrs,
2005 com.android.internal.R.styleable.AndroidManifestActivity);
2006
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002007 if (mParseActivityArgs == null) {
2008 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2009 com.android.internal.R.styleable.AndroidManifestActivity_name,
2010 com.android.internal.R.styleable.AndroidManifestActivity_label,
2011 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002012 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002013 mSeparateProcesses,
2014 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002015 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002016 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2017 }
2018
2019 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2020 mParseActivityArgs.sa = sa;
2021 mParseActivityArgs.flags = flags;
2022
2023 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2024 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 sa.recycle();
2026 return null;
2027 }
2028
2029 final boolean setExported = sa.hasValue(
2030 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2031 if (setExported) {
2032 a.info.exported = sa.getBoolean(
2033 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2034 }
2035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 a.info.theme = sa.getResourceId(
2037 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2038
Adam Powell269248d2011-08-02 10:26:54 -07002039 a.info.uiOptions = sa.getInt(
2040 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2041 a.info.applicationInfo.uiOptions);
2042
Adam Powelldd8fab22012-03-22 17:47:27 -07002043 String parentName = sa.getNonConfigurationString(
2044 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2045 if (parentName != null) {
2046 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2047 if (outError[0] == null) {
2048 a.info.parentActivityName = parentClassName;
2049 } else {
2050 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2051 parentName);
2052 outError[0] = null;
2053 }
2054 }
2055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002057 str = sa.getNonConfigurationString(
2058 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 if (str == null) {
2060 a.info.permission = owner.applicationInfo.permission;
2061 } else {
2062 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2063 }
2064
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002065 str = sa.getNonConfigurationString(
2066 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2068 owner.applicationInfo.taskAffinity, str, outError);
2069
2070 a.info.flags = 0;
2071 if (sa.getBoolean(
2072 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2073 false)) {
2074 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2075 }
2076
2077 if (sa.getBoolean(
2078 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2079 false)) {
2080 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2081 }
2082
2083 if (sa.getBoolean(
2084 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2085 false)) {
2086 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2087 }
2088
2089 if (sa.getBoolean(
2090 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2091 false)) {
2092 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2093 }
2094
2095 if (sa.getBoolean(
2096 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2097 false)) {
2098 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2099 }
2100
2101 if (sa.getBoolean(
2102 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2103 false)) {
2104 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2105 }
2106
2107 if (sa.getBoolean(
2108 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2109 false)) {
2110 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2111 }
2112
2113 if (sa.getBoolean(
2114 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2115 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2116 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2117 }
2118
Dianne Hackbornffa42482009-09-23 22:20:11 -07002119 if (sa.getBoolean(
2120 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2121 false)) {
2122 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2123 }
2124
Daniel Sandler613dde42010-06-21 13:46:39 -04002125 if (sa.getBoolean(
2126 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2127 false)) {
2128 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2129 }
Romain Guy529b60a2010-08-03 18:05:47 -07002130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002132 if (sa.getBoolean(
2133 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2134 hardwareAccelerated)) {
2135 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2136 }
2137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 a.info.launchMode = sa.getInt(
2139 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2140 ActivityInfo.LAUNCH_MULTIPLE);
2141 a.info.screenOrientation = sa.getInt(
2142 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2143 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2144 a.info.configChanges = sa.getInt(
2145 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2146 0);
2147 a.info.softInputMode = sa.getInt(
2148 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2149 0);
2150 } else {
2151 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2152 a.info.configChanges = 0;
2153 }
2154
2155 sa.recycle();
2156
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002157 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002158 // A heavy-weight application can not have receives in its main process
2159 // We can do direct compare because we intern all strings.
2160 if (a.info.processName == owner.packageName) {
2161 outError[0] = "Heavy-weight applications can not have receivers in main process";
2162 }
2163 }
2164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 if (outError[0] != null) {
2166 return null;
2167 }
2168
2169 int outerDepth = parser.getDepth();
2170 int type;
2171 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2172 && (type != XmlPullParser.END_TAG
2173 || parser.getDepth() > outerDepth)) {
2174 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2175 continue;
2176 }
2177
2178 if (parser.getName().equals("intent-filter")) {
2179 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2180 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2181 return null;
2182 }
2183 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002184 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002185 + mArchiveSourcePath + " "
2186 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 } else {
2188 a.intents.add(intent);
2189 }
2190 } else if (parser.getName().equals("meta-data")) {
2191 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2192 outError)) == null) {
2193 return null;
2194 }
2195 } else {
2196 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002197 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002199 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002200 + " at " + mArchiveSourcePath + " "
2201 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002203 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002204 + " at " + mArchiveSourcePath + " "
2205 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
2207 XmlUtils.skipCurrentTag(parser);
2208 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002210 if (receiver) {
2211 outError[0] = "Bad element under <receiver>: " + parser.getName();
2212 } else {
2213 outError[0] = "Bad element under <activity>: " + parser.getName();
2214 }
2215 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 }
2218 }
2219
2220 if (!setExported) {
2221 a.info.exported = a.intents.size() > 0;
2222 }
2223
2224 return a;
2225 }
2226
2227 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002228 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2229 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 TypedArray sa = res.obtainAttributes(attrs,
2231 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2232
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002233 String targetActivity = sa.getNonConfigurationString(
2234 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 if (targetActivity == null) {
2236 outError[0] = "<activity-alias> does not specify android:targetActivity";
2237 sa.recycle();
2238 return null;
2239 }
2240
2241 targetActivity = buildClassName(owner.applicationInfo.packageName,
2242 targetActivity, outError);
2243 if (targetActivity == null) {
2244 sa.recycle();
2245 return null;
2246 }
2247
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002248 if (mParseActivityAliasArgs == null) {
2249 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2250 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2251 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2252 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002253 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002254 mSeparateProcesses,
2255 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002256 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2258 mParseActivityAliasArgs.tag = "<activity-alias>";
2259 }
2260
2261 mParseActivityAliasArgs.sa = sa;
2262 mParseActivityAliasArgs.flags = flags;
2263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 Activity target = null;
2265
2266 final int NA = owner.activities.size();
2267 for (int i=0; i<NA; i++) {
2268 Activity t = owner.activities.get(i);
2269 if (targetActivity.equals(t.info.name)) {
2270 target = t;
2271 break;
2272 }
2273 }
2274
2275 if (target == null) {
2276 outError[0] = "<activity-alias> target activity " + targetActivity
2277 + " not found in manifest";
2278 sa.recycle();
2279 return null;
2280 }
2281
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002282 ActivityInfo info = new ActivityInfo();
2283 info.targetActivity = targetActivity;
2284 info.configChanges = target.info.configChanges;
2285 info.flags = target.info.flags;
2286 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002287 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002288 info.labelRes = target.info.labelRes;
2289 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2290 info.launchMode = target.info.launchMode;
2291 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002292 if (info.descriptionRes == 0) {
2293 info.descriptionRes = target.info.descriptionRes;
2294 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002295 info.screenOrientation = target.info.screenOrientation;
2296 info.taskAffinity = target.info.taskAffinity;
2297 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002298 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002299 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002300 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002301
2302 Activity a = new Activity(mParseActivityAliasArgs, info);
2303 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 sa.recycle();
2305 return null;
2306 }
2307
2308 final boolean setExported = sa.hasValue(
2309 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2310 if (setExported) {
2311 a.info.exported = sa.getBoolean(
2312 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2313 }
2314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002316 str = sa.getNonConfigurationString(
2317 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (str != null) {
2319 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2320 }
2321
Adam Powelldd8fab22012-03-22 17:47:27 -07002322 String parentName = sa.getNonConfigurationString(
2323 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2324 0);
2325 if (parentName != null) {
2326 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2327 if (outError[0] == null) {
2328 a.info.parentActivityName = parentClassName;
2329 } else {
2330 Log.e(TAG, "Activity alias " + a.info.name +
2331 " specified invalid parentActivityName " + parentName);
2332 outError[0] = null;
2333 }
2334 }
2335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002336 sa.recycle();
2337
2338 if (outError[0] != null) {
2339 return null;
2340 }
2341
2342 int outerDepth = parser.getDepth();
2343 int type;
2344 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2345 && (type != XmlPullParser.END_TAG
2346 || parser.getDepth() > outerDepth)) {
2347 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2348 continue;
2349 }
2350
2351 if (parser.getName().equals("intent-filter")) {
2352 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2353 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2354 return null;
2355 }
2356 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002357 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002358 + mArchiveSourcePath + " "
2359 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 } else {
2361 a.intents.add(intent);
2362 }
2363 } else if (parser.getName().equals("meta-data")) {
2364 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2365 outError)) == null) {
2366 return null;
2367 }
2368 } else {
2369 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002370 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002371 + " at " + mArchiveSourcePath + " "
2372 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 XmlUtils.skipCurrentTag(parser);
2374 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002375 } else {
2376 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2377 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 }
2380 }
2381
2382 if (!setExported) {
2383 a.info.exported = a.intents.size() > 0;
2384 }
2385
2386 return a;
2387 }
2388
2389 private Provider parseProvider(Package owner, Resources res,
2390 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2391 throws XmlPullParserException, IOException {
2392 TypedArray sa = res.obtainAttributes(attrs,
2393 com.android.internal.R.styleable.AndroidManifestProvider);
2394
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002395 if (mParseProviderArgs == null) {
2396 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2397 com.android.internal.R.styleable.AndroidManifestProvider_name,
2398 com.android.internal.R.styleable.AndroidManifestProvider_label,
2399 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002400 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002401 mSeparateProcesses,
2402 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002403 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002404 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2405 mParseProviderArgs.tag = "<provider>";
2406 }
2407
2408 mParseProviderArgs.sa = sa;
2409 mParseProviderArgs.flags = flags;
2410
2411 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2412 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 sa.recycle();
2414 return null;
2415 }
2416
2417 p.info.exported = sa.getBoolean(
2418 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2419
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002420 String cpname = sa.getNonConfigurationString(
2421 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422
2423 p.info.isSyncable = sa.getBoolean(
2424 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2425 false);
2426
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002427 String permission = sa.getNonConfigurationString(
2428 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2429 String str = sa.getNonConfigurationString(
2430 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 if (str == null) {
2432 str = permission;
2433 }
2434 if (str == null) {
2435 p.info.readPermission = owner.applicationInfo.permission;
2436 } else {
2437 p.info.readPermission =
2438 str.length() > 0 ? str.toString().intern() : null;
2439 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002440 str = sa.getNonConfigurationString(
2441 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 if (str == null) {
2443 str = permission;
2444 }
2445 if (str == null) {
2446 p.info.writePermission = owner.applicationInfo.permission;
2447 } else {
2448 p.info.writePermission =
2449 str.length() > 0 ? str.toString().intern() : null;
2450 }
2451
2452 p.info.grantUriPermissions = sa.getBoolean(
2453 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2454 false);
2455
2456 p.info.multiprocess = sa.getBoolean(
2457 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2458 false);
2459
2460 p.info.initOrder = sa.getInt(
2461 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2462 0);
2463
2464 sa.recycle();
2465
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002466 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002467 // A heavy-weight application can not have providers in its main process
2468 // We can do direct compare because we intern all strings.
2469 if (p.info.processName == owner.packageName) {
2470 outError[0] = "Heavy-weight applications can not have providers in main process";
2471 return null;
2472 }
2473 }
2474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 if (cpname == null) {
2476 outError[0] = "<provider> does not incude authorities attribute";
2477 return null;
2478 }
2479 p.info.authority = cpname.intern();
2480
2481 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2482 return null;
2483 }
2484
2485 return p;
2486 }
2487
2488 private boolean parseProviderTags(Resources res,
2489 XmlPullParser parser, AttributeSet attrs,
2490 Provider outInfo, String[] outError)
2491 throws XmlPullParserException, IOException {
2492 int outerDepth = parser.getDepth();
2493 int type;
2494 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2495 && (type != XmlPullParser.END_TAG
2496 || parser.getDepth() > outerDepth)) {
2497 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2498 continue;
2499 }
2500
2501 if (parser.getName().equals("meta-data")) {
2502 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2503 outInfo.metaData, outError)) == null) {
2504 return false;
2505 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 } else if (parser.getName().equals("grant-uri-permission")) {
2508 TypedArray sa = res.obtainAttributes(attrs,
2509 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2510
2511 PatternMatcher pa = null;
2512
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002513 String str = sa.getNonConfigurationString(
2514 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 if (str != null) {
2516 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2517 }
2518
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002519 str = sa.getNonConfigurationString(
2520 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 if (str != null) {
2522 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2523 }
2524
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002525 str = sa.getNonConfigurationString(
2526 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (str != null) {
2528 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2529 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 sa.recycle();
2532
2533 if (pa != null) {
2534 if (outInfo.info.uriPermissionPatterns == null) {
2535 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2536 outInfo.info.uriPermissionPatterns[0] = pa;
2537 } else {
2538 final int N = outInfo.info.uriPermissionPatterns.length;
2539 PatternMatcher[] newp = new PatternMatcher[N+1];
2540 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2541 newp[N] = pa;
2542 outInfo.info.uriPermissionPatterns = newp;
2543 }
2544 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002545 } else {
2546 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002547 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002548 + parser.getName() + " at " + mArchiveSourcePath + " "
2549 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002550 XmlUtils.skipCurrentTag(parser);
2551 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002552 } else {
2553 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2554 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002555 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002556 }
2557 XmlUtils.skipCurrentTag(parser);
2558
2559 } else if (parser.getName().equals("path-permission")) {
2560 TypedArray sa = res.obtainAttributes(attrs,
2561 com.android.internal.R.styleable.AndroidManifestPathPermission);
2562
2563 PathPermission pa = null;
2564
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002565 String permission = sa.getNonConfigurationString(
2566 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2567 String readPermission = sa.getNonConfigurationString(
2568 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002569 if (readPermission == null) {
2570 readPermission = permission;
2571 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002572 String writePermission = sa.getNonConfigurationString(
2573 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002574 if (writePermission == null) {
2575 writePermission = permission;
2576 }
2577
2578 boolean havePerm = false;
2579 if (readPermission != null) {
2580 readPermission = readPermission.intern();
2581 havePerm = true;
2582 }
2583 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002584 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002585 havePerm = true;
2586 }
2587
2588 if (!havePerm) {
2589 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002590 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002591 + parser.getName() + " at " + mArchiveSourcePath + " "
2592 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002593 XmlUtils.skipCurrentTag(parser);
2594 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002595 } else {
2596 outError[0] = "No readPermission or writePermssion for <path-permission>";
2597 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002598 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002599 }
2600
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002601 String path = sa.getNonConfigurationString(
2602 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002603 if (path != null) {
2604 pa = new PathPermission(path,
2605 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2606 }
2607
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002608 path = sa.getNonConfigurationString(
2609 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002610 if (path != null) {
2611 pa = new PathPermission(path,
2612 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2613 }
2614
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002615 path = sa.getNonConfigurationString(
2616 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002617 if (path != null) {
2618 pa = new PathPermission(path,
2619 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2620 }
2621
2622 sa.recycle();
2623
2624 if (pa != null) {
2625 if (outInfo.info.pathPermissions == null) {
2626 outInfo.info.pathPermissions = new PathPermission[1];
2627 outInfo.info.pathPermissions[0] = pa;
2628 } else {
2629 final int N = outInfo.info.pathPermissions.length;
2630 PathPermission[] newp = new PathPermission[N+1];
2631 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2632 newp[N] = pa;
2633 outInfo.info.pathPermissions = newp;
2634 }
2635 } else {
2636 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002637 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002638 + parser.getName() + " at " + mArchiveSourcePath + " "
2639 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002640 XmlUtils.skipCurrentTag(parser);
2641 continue;
2642 }
2643 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2644 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 }
2646 XmlUtils.skipCurrentTag(parser);
2647
2648 } else {
2649 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002650 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002651 + parser.getName() + " at " + mArchiveSourcePath + " "
2652 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 XmlUtils.skipCurrentTag(parser);
2654 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002655 } else {
2656 outError[0] = "Bad element under <provider>: " + parser.getName();
2657 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 }
2660 }
2661 return true;
2662 }
2663
2664 private Service parseService(Package owner, Resources res,
2665 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2666 throws XmlPullParserException, IOException {
2667 TypedArray sa = res.obtainAttributes(attrs,
2668 com.android.internal.R.styleable.AndroidManifestService);
2669
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002670 if (mParseServiceArgs == null) {
2671 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2672 com.android.internal.R.styleable.AndroidManifestService_name,
2673 com.android.internal.R.styleable.AndroidManifestService_label,
2674 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002675 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002676 mSeparateProcesses,
2677 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002678 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002679 com.android.internal.R.styleable.AndroidManifestService_enabled);
2680 mParseServiceArgs.tag = "<service>";
2681 }
2682
2683 mParseServiceArgs.sa = sa;
2684 mParseServiceArgs.flags = flags;
2685
2686 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2687 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 sa.recycle();
2689 return null;
2690 }
2691
2692 final boolean setExported = sa.hasValue(
2693 com.android.internal.R.styleable.AndroidManifestService_exported);
2694 if (setExported) {
2695 s.info.exported = sa.getBoolean(
2696 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2697 }
2698
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002699 String str = sa.getNonConfigurationString(
2700 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 if (str == null) {
2702 s.info.permission = owner.applicationInfo.permission;
2703 } else {
2704 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2705 }
2706
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002707 s.info.flags = 0;
2708 if (sa.getBoolean(
2709 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2710 false)) {
2711 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2712 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002713 if (sa.getBoolean(
2714 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2715 false)) {
2716 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2717 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719 sa.recycle();
2720
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002721 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002722 // A heavy-weight application can not have services in its main process
2723 // We can do direct compare because we intern all strings.
2724 if (s.info.processName == owner.packageName) {
2725 outError[0] = "Heavy-weight applications can not have services in main process";
2726 return null;
2727 }
2728 }
2729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 int outerDepth = parser.getDepth();
2731 int type;
2732 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2733 && (type != XmlPullParser.END_TAG
2734 || parser.getDepth() > outerDepth)) {
2735 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2736 continue;
2737 }
2738
2739 if (parser.getName().equals("intent-filter")) {
2740 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2741 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2742 return null;
2743 }
2744
2745 s.intents.add(intent);
2746 } else if (parser.getName().equals("meta-data")) {
2747 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2748 outError)) == null) {
2749 return null;
2750 }
2751 } else {
2752 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002753 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002754 + parser.getName() + " at " + mArchiveSourcePath + " "
2755 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 XmlUtils.skipCurrentTag(parser);
2757 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002758 } else {
2759 outError[0] = "Bad element under <service>: " + parser.getName();
2760 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 }
2763 }
2764
2765 if (!setExported) {
2766 s.info.exported = s.intents.size() > 0;
2767 }
2768
2769 return s;
2770 }
2771
2772 private boolean parseAllMetaData(Resources res,
2773 XmlPullParser parser, AttributeSet attrs, String tag,
2774 Component outInfo, String[] outError)
2775 throws XmlPullParserException, IOException {
2776 int outerDepth = parser.getDepth();
2777 int type;
2778 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2779 && (type != XmlPullParser.END_TAG
2780 || parser.getDepth() > outerDepth)) {
2781 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2782 continue;
2783 }
2784
2785 if (parser.getName().equals("meta-data")) {
2786 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2787 outInfo.metaData, outError)) == null) {
2788 return false;
2789 }
2790 } else {
2791 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002792 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002793 + parser.getName() + " at " + mArchiveSourcePath + " "
2794 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 XmlUtils.skipCurrentTag(parser);
2796 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002797 } else {
2798 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2799 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 }
2802 }
2803 return true;
2804 }
2805
2806 private Bundle parseMetaData(Resources res,
2807 XmlPullParser parser, AttributeSet attrs,
2808 Bundle data, String[] outError)
2809 throws XmlPullParserException, IOException {
2810
2811 TypedArray sa = res.obtainAttributes(attrs,
2812 com.android.internal.R.styleable.AndroidManifestMetaData);
2813
2814 if (data == null) {
2815 data = new Bundle();
2816 }
2817
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002818 String name = sa.getNonConfigurationString(
2819 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 if (name == null) {
2821 outError[0] = "<meta-data> requires an android:name attribute";
2822 sa.recycle();
2823 return null;
2824 }
2825
Dianne Hackborn854060a2009-07-09 18:14:31 -07002826 name = name.intern();
2827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 TypedValue v = sa.peekValue(
2829 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2830 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002831 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 data.putInt(name, v.resourceId);
2833 } else {
2834 v = sa.peekValue(
2835 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002836 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 if (v != null) {
2838 if (v.type == TypedValue.TYPE_STRING) {
2839 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002840 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2842 data.putBoolean(name, v.data != 0);
2843 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2844 && v.type <= TypedValue.TYPE_LAST_INT) {
2845 data.putInt(name, v.data);
2846 } else if (v.type == TypedValue.TYPE_FLOAT) {
2847 data.putFloat(name, v.getFloat());
2848 } else {
2849 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002850 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002851 + parser.getName() + " at " + mArchiveSourcePath + " "
2852 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 } else {
2854 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2855 data = null;
2856 }
2857 }
2858 } else {
2859 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2860 data = null;
2861 }
2862 }
2863
2864 sa.recycle();
2865
2866 XmlUtils.skipCurrentTag(parser);
2867
2868 return data;
2869 }
2870
Kenny Root05ca4c92011-09-15 10:36:25 -07002871 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2872 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2873 IOException {
2874 final TypedArray sa = res.obtainAttributes(attrs,
2875 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2876
2877 final String packageName = sa.getNonResourceString(
2878 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2879
2880 final String encodedPublicKey = sa.getNonResourceString(
2881 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2882
2883 sa.recycle();
2884
2885 if (packageName == null || packageName.length() == 0) {
2886 Slog.i(TAG, "verifier package name was null; skipping");
2887 return null;
2888 } else if (encodedPublicKey == null) {
2889 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2890 }
2891
2892 EncodedKeySpec keySpec;
2893 try {
2894 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2895 keySpec = new X509EncodedKeySpec(encoded);
2896 } catch (IllegalArgumentException e) {
2897 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2898 return null;
2899 }
2900
2901 /* First try the key as an RSA key. */
2902 try {
2903 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2904 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2905 return new VerifierInfo(packageName, publicKey);
2906 } catch (NoSuchAlgorithmException e) {
2907 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2908 return null;
2909 } catch (InvalidKeySpecException e) {
2910 // Not a RSA public key.
2911 }
2912
2913 /* Now try it as a DSA key. */
2914 try {
2915 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
2916 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2917 return new VerifierInfo(packageName, publicKey);
2918 } catch (NoSuchAlgorithmException e) {
2919 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
2920 return null;
2921 } catch (InvalidKeySpecException e) {
2922 // Not a DSA public key.
2923 }
2924
2925 return null;
2926 }
2927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 private static final String ANDROID_RESOURCES
2929 = "http://schemas.android.com/apk/res/android";
2930
2931 private boolean parseIntent(Resources res,
2932 XmlPullParser parser, AttributeSet attrs, int flags,
2933 IntentInfo outInfo, String[] outError, boolean isActivity)
2934 throws XmlPullParserException, IOException {
2935
2936 TypedArray sa = res.obtainAttributes(attrs,
2937 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2938
2939 int priority = sa.getInt(
2940 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 TypedValue v = sa.peekValue(
2944 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2945 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2946 outInfo.nonLocalizedLabel = v.coerceToString();
2947 }
2948
2949 outInfo.icon = sa.getResourceId(
2950 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002951
2952 outInfo.logo = sa.getResourceId(
2953 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954
2955 sa.recycle();
2956
2957 int outerDepth = parser.getDepth();
2958 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002959 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2960 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2961 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 continue;
2963 }
2964
2965 String nodeName = parser.getName();
2966 if (nodeName.equals("action")) {
2967 String value = attrs.getAttributeValue(
2968 ANDROID_RESOURCES, "name");
2969 if (value == null || value == "") {
2970 outError[0] = "No value supplied for <android:name>";
2971 return false;
2972 }
2973 XmlUtils.skipCurrentTag(parser);
2974
2975 outInfo.addAction(value);
2976 } else if (nodeName.equals("category")) {
2977 String value = attrs.getAttributeValue(
2978 ANDROID_RESOURCES, "name");
2979 if (value == null || value == "") {
2980 outError[0] = "No value supplied for <android:name>";
2981 return false;
2982 }
2983 XmlUtils.skipCurrentTag(parser);
2984
2985 outInfo.addCategory(value);
2986
2987 } else if (nodeName.equals("data")) {
2988 sa = res.obtainAttributes(attrs,
2989 com.android.internal.R.styleable.AndroidManifestData);
2990
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002991 String str = sa.getNonConfigurationString(
2992 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 if (str != null) {
2994 try {
2995 outInfo.addDataType(str);
2996 } catch (IntentFilter.MalformedMimeTypeException e) {
2997 outError[0] = e.toString();
2998 sa.recycle();
2999 return false;
3000 }
3001 }
3002
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003003 str = sa.getNonConfigurationString(
3004 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 if (str != null) {
3006 outInfo.addDataScheme(str);
3007 }
3008
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003009 String host = sa.getNonConfigurationString(
3010 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3011 String port = sa.getNonConfigurationString(
3012 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 if (host != null) {
3014 outInfo.addDataAuthority(host, port);
3015 }
3016
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003017 str = sa.getNonConfigurationString(
3018 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 if (str != null) {
3020 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3021 }
3022
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003023 str = sa.getNonConfigurationString(
3024 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 if (str != null) {
3026 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3027 }
3028
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003029 str = sa.getNonConfigurationString(
3030 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 if (str != null) {
3032 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3033 }
3034
3035 sa.recycle();
3036 XmlUtils.skipCurrentTag(parser);
3037 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003038 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003039 + parser.getName() + " at " + mArchiveSourcePath + " "
3040 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 XmlUtils.skipCurrentTag(parser);
3042 } else {
3043 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3044 return false;
3045 }
3046 }
3047
3048 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003049
3050 if (DEBUG_PARSER) {
3051 final StringBuilder cats = new StringBuilder("Intent d=");
3052 cats.append(outInfo.hasDefault);
3053 cats.append(", cat=");
3054
3055 final Iterator<String> it = outInfo.categoriesIterator();
3056 if (it != null) {
3057 while (it.hasNext()) {
3058 cats.append(' ');
3059 cats.append(it.next());
3060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003062 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 }
3064
3065 return true;
3066 }
3067
3068 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003069 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070
3071 // For now we only support one application per package.
3072 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3073
3074 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3075 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3076 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3077 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3078 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3079 public final ArrayList<Service> services = new ArrayList<Service>(0);
3080 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3081
3082 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003083 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084
Dianne Hackborn854060a2009-07-09 18:14:31 -07003085 public ArrayList<String> protectedBroadcasts;
3086
Dianne Hackborn49237342009-08-27 20:08:01 -07003087 public ArrayList<String> usesLibraries = null;
3088 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 public String[] usesLibraryFiles = null;
3090
Dianne Hackbornc1552392010-03-03 16:19:01 -08003091 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003092 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003093 public ArrayList<String> mAdoptPermissions = null;
3094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 // We store the application meta-data independently to avoid multiple unwanted references
3096 public Bundle mAppMetaData = null;
3097
3098 // If this is a 3rd party app, this is the path of the zip file.
3099 public String mPath;
3100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 // The version code declared for this package.
3102 public int mVersionCode;
3103
3104 // The version name declared for this package.
3105 public String mVersionName;
3106
3107 // The shared user id that this package wants to use.
3108 public String mSharedUserId;
3109
3110 // The shared user label that this package wants to use.
3111 public int mSharedUserLabel;
3112
3113 // Signatures that were read from the package.
3114 public Signature mSignatures[];
3115
3116 // For use by package manager service for quick lookup of
3117 // preferred up order.
3118 public int mPreferredOrder = 0;
3119
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003120 // For use by the package manager to keep track of the path to the
3121 // file an app came from.
3122 public String mScanPath;
3123
3124 // For use by package manager to keep track of where it has done dexopt.
3125 public boolean mDidDexOpt;
3126
Amith Yamasani13593602012-03-22 16:16:17 -07003127 // // User set enabled state.
3128 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3129 //
3130 // // Whether the package has been stopped.
3131 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 // Additional data supplied by callers.
3134 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003135
3136 // Whether an operation is currently pending on this package
3137 public boolean mOperationPending;
3138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 /*
3140 * Applications hardware preferences
3141 */
3142 public final ArrayList<ConfigurationInfo> configPreferences =
3143 new ArrayList<ConfigurationInfo>();
3144
Dianne Hackborn49237342009-08-27 20:08:01 -07003145 /*
3146 * Applications requested features
3147 */
3148 public ArrayList<FeatureInfo> reqFeatures = null;
3149
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003150 public int installLocation;
3151
Kenny Rootbcc954d2011-08-08 16:19:08 -07003152 /**
3153 * Digest suitable for comparing whether this package's manifest is the
3154 * same as another.
3155 */
3156 public ManifestDigest manifestDigest;
3157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 public Package(String _name) {
3159 packageName = _name;
3160 applicationInfo.packageName = _name;
3161 applicationInfo.uid = -1;
3162 }
3163
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003164 public void setPackageName(String newName) {
3165 packageName = newName;
3166 applicationInfo.packageName = newName;
3167 for (int i=permissions.size()-1; i>=0; i--) {
3168 permissions.get(i).setPackageName(newName);
3169 }
3170 for (int i=permissionGroups.size()-1; i>=0; i--) {
3171 permissionGroups.get(i).setPackageName(newName);
3172 }
3173 for (int i=activities.size()-1; i>=0; i--) {
3174 activities.get(i).setPackageName(newName);
3175 }
3176 for (int i=receivers.size()-1; i>=0; i--) {
3177 receivers.get(i).setPackageName(newName);
3178 }
3179 for (int i=providers.size()-1; i>=0; i--) {
3180 providers.get(i).setPackageName(newName);
3181 }
3182 for (int i=services.size()-1; i>=0; i--) {
3183 services.get(i).setPackageName(newName);
3184 }
3185 for (int i=instrumentation.size()-1; i>=0; i--) {
3186 instrumentation.get(i).setPackageName(newName);
3187 }
3188 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003189
3190 public boolean hasComponentClassName(String name) {
3191 for (int i=activities.size()-1; i>=0; i--) {
3192 if (name.equals(activities.get(i).className)) {
3193 return true;
3194 }
3195 }
3196 for (int i=receivers.size()-1; i>=0; i--) {
3197 if (name.equals(receivers.get(i).className)) {
3198 return true;
3199 }
3200 }
3201 for (int i=providers.size()-1; i>=0; i--) {
3202 if (name.equals(providers.get(i).className)) {
3203 return true;
3204 }
3205 }
3206 for (int i=services.size()-1; i>=0; i--) {
3207 if (name.equals(services.get(i).className)) {
3208 return true;
3209 }
3210 }
3211 for (int i=instrumentation.size()-1; i>=0; i--) {
3212 if (name.equals(instrumentation.get(i).className)) {
3213 return true;
3214 }
3215 }
3216 return false;
3217 }
3218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 public String toString() {
3220 return "Package{"
3221 + Integer.toHexString(System.identityHashCode(this))
3222 + " " + packageName + "}";
3223 }
3224 }
3225
3226 public static class Component<II extends IntentInfo> {
3227 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003228 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003229 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 public Bundle metaData;
3231
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003232 ComponentName componentName;
3233 String componentShortName;
3234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 public Component(Package _owner) {
3236 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003237 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003238 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003239 }
3240
3241 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3242 owner = args.owner;
3243 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003244 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003245 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003246 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003247 args.outError[0] = args.tag + " does not specify android:name";
3248 return;
3249 }
3250
3251 outInfo.name
3252 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3253 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003254 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003255 args.outError[0] = args.tag + " does not have valid android:name";
3256 return;
3257 }
3258
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003259 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003260
3261 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3262 if (iconVal != 0) {
3263 outInfo.icon = iconVal;
3264 outInfo.nonLocalizedLabel = null;
3265 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003266
3267 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3268 if (logoVal != 0) {
3269 outInfo.logo = logoVal;
3270 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003271
3272 TypedValue v = args.sa.peekValue(args.labelRes);
3273 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3274 outInfo.nonLocalizedLabel = v.coerceToString();
3275 }
3276
3277 outInfo.packageName = owner.packageName;
3278 }
3279
3280 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3281 this(args, (PackageItemInfo)outInfo);
3282 if (args.outError[0] != null) {
3283 return;
3284 }
3285
3286 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003287 CharSequence pname;
3288 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3289 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3290 } else {
3291 // Some older apps have been seen to use a resource reference
3292 // here that on older builds was ignored (with a warning). We
3293 // need to continue to do this for them so they don't break.
3294 pname = args.sa.getNonResourceString(args.processRes);
3295 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003296 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003297 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003298 args.flags, args.sepProcesses, args.outError);
3299 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003300
3301 if (args.descriptionRes != 0) {
3302 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3303 }
3304
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003305 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 }
3307
3308 public Component(Component<II> clone) {
3309 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003310 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003311 className = clone.className;
3312 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003313 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003314 }
3315
3316 public ComponentName getComponentName() {
3317 if (componentName != null) {
3318 return componentName;
3319 }
3320 if (className != null) {
3321 componentName = new ComponentName(owner.applicationInfo.packageName,
3322 className);
3323 }
3324 return componentName;
3325 }
3326
3327 public String getComponentShortName() {
3328 if (componentShortName != null) {
3329 return componentShortName;
3330 }
3331 ComponentName component = getComponentName();
3332 if (component != null) {
3333 componentShortName = component.flattenToShortString();
3334 }
3335 return componentShortName;
3336 }
3337
3338 public void setPackageName(String packageName) {
3339 componentName = null;
3340 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 }
3342 }
3343
3344 public final static class Permission extends Component<IntentInfo> {
3345 public final PermissionInfo info;
3346 public boolean tree;
3347 public PermissionGroup group;
3348
3349 public Permission(Package _owner) {
3350 super(_owner);
3351 info = new PermissionInfo();
3352 }
3353
3354 public Permission(Package _owner, PermissionInfo _info) {
3355 super(_owner);
3356 info = _info;
3357 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003358
3359 public void setPackageName(String packageName) {
3360 super.setPackageName(packageName);
3361 info.packageName = packageName;
3362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363
3364 public String toString() {
3365 return "Permission{"
3366 + Integer.toHexString(System.identityHashCode(this))
3367 + " " + info.name + "}";
3368 }
3369 }
3370
3371 public final static class PermissionGroup extends Component<IntentInfo> {
3372 public final PermissionGroupInfo info;
3373
3374 public PermissionGroup(Package _owner) {
3375 super(_owner);
3376 info = new PermissionGroupInfo();
3377 }
3378
3379 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3380 super(_owner);
3381 info = _info;
3382 }
3383
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003384 public void setPackageName(String packageName) {
3385 super.setPackageName(packageName);
3386 info.packageName = packageName;
3387 }
3388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 public String toString() {
3390 return "PermissionGroup{"
3391 + Integer.toHexString(System.identityHashCode(this))
3392 + " " + info.name + "}";
3393 }
3394 }
3395
Amith Yamasani13593602012-03-22 16:16:17 -07003396 private static boolean copyNeeded(int flags, Package p, int enabledState, Bundle metaData) {
3397 if (enabledState != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3398 boolean enabled = enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003399 if (p.applicationInfo.enabled != enabled) {
3400 return true;
3401 }
3402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 if ((flags & PackageManager.GET_META_DATA) != 0
3404 && (metaData != null || p.mAppMetaData != null)) {
3405 return true;
3406 }
3407 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3408 && p.usesLibraryFiles != null) {
3409 return true;
3410 }
3411 return false;
3412 }
3413
Amith Yamasani13593602012-03-22 16:16:17 -07003414 public static ApplicationInfo generateApplicationInfo(Package p, int flags, boolean stopped,
3415 int enabledState) {
3416 return generateApplicationInfo(p, flags, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003417 }
3418
Amith Yamasani13593602012-03-22 16:16:17 -07003419 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3420 boolean stopped, int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003422 if (!copyNeeded(flags, p, enabledState, null) && userId == 0) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003423 // CompatibilityMode is global state. It's safe to modify the instance
3424 // of the package.
3425 if (!sCompatibilityModeEnabled) {
3426 p.applicationInfo.disableCompatibilityMode();
3427 }
Amith Yamasani13593602012-03-22 16:16:17 -07003428 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003429 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3430 } else {
3431 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3432 }
Amith Yamasani13593602012-03-22 16:16:17 -07003433 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003434 p.applicationInfo.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003435 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3436 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003437 p.applicationInfo.enabled = false;
3438 }
Amith Yamasani13593602012-03-22 16:16:17 -07003439 p.applicationInfo.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 return p.applicationInfo;
3441 }
3442
3443 // Make shallow copy so we can store the metadata/libraries safely
3444 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003445 if (userId != 0) {
3446 ai.uid = UserId.getUid(userId, ai.uid);
3447 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 if ((flags & PackageManager.GET_META_DATA) != 0) {
3450 ai.metaData = p.mAppMetaData;
3451 }
3452 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3453 ai.sharedLibraryFiles = p.usesLibraryFiles;
3454 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003455 if (!sCompatibilityModeEnabled) {
3456 ai.disableCompatibilityMode();
3457 }
Amith Yamasani13593602012-03-22 16:16:17 -07003458 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003459 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3460 } else {
3461 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3462 }
Amith Yamasani13593602012-03-22 16:16:17 -07003463 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003464 ai.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003465 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3466 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003467 ai.enabled = false;
3468 }
Amith Yamasani13593602012-03-22 16:16:17 -07003469 ai.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 return ai;
3471 }
3472
3473 public static final PermissionInfo generatePermissionInfo(
3474 Permission p, int flags) {
3475 if (p == null) return null;
3476 if ((flags&PackageManager.GET_META_DATA) == 0) {
3477 return p.info;
3478 }
3479 PermissionInfo pi = new PermissionInfo(p.info);
3480 pi.metaData = p.metaData;
3481 return pi;
3482 }
3483
3484 public static final PermissionGroupInfo generatePermissionGroupInfo(
3485 PermissionGroup pg, int flags) {
3486 if (pg == null) return null;
3487 if ((flags&PackageManager.GET_META_DATA) == 0) {
3488 return pg.info;
3489 }
3490 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3491 pgi.metaData = pg.metaData;
3492 return pgi;
3493 }
3494
3495 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003496 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003497
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003498 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3499 super(args, _info);
3500 info = _info;
3501 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003503
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003504 public void setPackageName(String packageName) {
3505 super.setPackageName(packageName);
3506 info.packageName = packageName;
3507 }
3508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 public String toString() {
3510 return "Activity{"
3511 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003512 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 }
3514 }
3515
Amith Yamasani13593602012-03-22 16:16:17 -07003516 public static final ActivityInfo generateActivityInfo(Activity a, int flags, boolean stopped,
3517 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 if (a == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003519 if (!copyNeeded(flags, a.owner, enabledState, a.metaData) && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 return a.info;
3521 }
3522 // Make shallow copies so we can store the metadata safely
3523 ActivityInfo ai = new ActivityInfo(a.info);
3524 ai.metaData = a.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003525 ai.applicationInfo = generateApplicationInfo(a.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 return ai;
3527 }
3528
3529 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003530 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003532 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3533 super(args, _info);
3534 info = _info;
3535 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003537
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003538 public void setPackageName(String packageName) {
3539 super.setPackageName(packageName);
3540 info.packageName = packageName;
3541 }
3542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 public String toString() {
3544 return "Service{"
3545 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003546 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 }
3548 }
3549
Amith Yamasani13593602012-03-22 16:16:17 -07003550 public static final ServiceInfo generateServiceInfo(Service s, int flags, boolean stopped,
3551 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 if (s == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003553 if (!copyNeeded(flags, s.owner, enabledState, s.metaData)
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003554 && userId == UserId.getUserId(s.info.applicationInfo.uid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 return s.info;
3556 }
3557 // Make shallow copies so we can store the metadata safely
3558 ServiceInfo si = new ServiceInfo(s.info);
3559 si.metaData = s.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003560 si.applicationInfo = generateApplicationInfo(s.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 return si;
3562 }
3563
3564 public final static class Provider extends Component {
3565 public final ProviderInfo info;
3566 public boolean syncable;
3567
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003568 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3569 super(args, _info);
3570 info = _info;
3571 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 syncable = false;
3573 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 public Provider(Provider existingProvider) {
3576 super(existingProvider);
3577 this.info = existingProvider.info;
3578 this.syncable = existingProvider.syncable;
3579 }
3580
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003581 public void setPackageName(String packageName) {
3582 super.setPackageName(packageName);
3583 info.packageName = packageName;
3584 }
3585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 public String toString() {
3587 return "Provider{"
3588 + Integer.toHexString(System.identityHashCode(this))
3589 + " " + info.name + "}";
3590 }
3591 }
3592
Amith Yamasani13593602012-03-22 16:16:17 -07003593 public static final ProviderInfo generateProviderInfo(Provider p, int flags, boolean stopped,
3594 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003596 if (!copyNeeded(flags, p.owner, enabledState, p.metaData)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Amith Yamasani742a6712011-05-04 14:49:28 -07003598 || p.info.uriPermissionPatterns == null)
3599 && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 return p.info;
3601 }
3602 // Make shallow copies so we can store the metadata safely
3603 ProviderInfo pi = new ProviderInfo(p.info);
3604 pi.metaData = p.metaData;
3605 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3606 pi.uriPermissionPatterns = null;
3607 }
Amith Yamasani13593602012-03-22 16:16:17 -07003608 pi.applicationInfo = generateApplicationInfo(p.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 return pi;
3610 }
3611
3612 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003613 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003615 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3616 super(args, _info);
3617 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003619
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003620 public void setPackageName(String packageName) {
3621 super.setPackageName(packageName);
3622 info.packageName = packageName;
3623 }
3624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 public String toString() {
3626 return "Instrumentation{"
3627 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003628 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 }
3630 }
3631
3632 public static final InstrumentationInfo generateInstrumentationInfo(
3633 Instrumentation i, int flags) {
3634 if (i == null) return null;
3635 if ((flags&PackageManager.GET_META_DATA) == 0) {
3636 return i.info;
3637 }
3638 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3639 ii.metaData = i.metaData;
3640 return ii;
3641 }
3642
3643 public static class IntentInfo extends IntentFilter {
3644 public boolean hasDefault;
3645 public int labelRes;
3646 public CharSequence nonLocalizedLabel;
3647 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003648 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 }
3650
3651 public final static class ActivityIntentInfo extends IntentInfo {
3652 public final Activity activity;
3653
3654 public ActivityIntentInfo(Activity _activity) {
3655 activity = _activity;
3656 }
3657
3658 public String toString() {
3659 return "ActivityIntentInfo{"
3660 + Integer.toHexString(System.identityHashCode(this))
3661 + " " + activity.info.name + "}";
3662 }
3663 }
3664
3665 public final static class ServiceIntentInfo extends IntentInfo {
3666 public final Service service;
3667
3668 public ServiceIntentInfo(Service _service) {
3669 service = _service;
3670 }
3671
3672 public String toString() {
3673 return "ServiceIntentInfo{"
3674 + Integer.toHexString(System.identityHashCode(this))
3675 + " " + service.info.name + "}";
3676 }
3677 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003678
3679 /**
3680 * @hide
3681 */
3682 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3683 sCompatibilityModeEnabled = compatibilityModeEnabled;
3684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685}