blob: e180df435de06c99b145d4073d3e85eea44f1c09 [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;
Kenny Root7cb9be22012-05-30 15:30:37 -0700938
939 /* Set the global "forward lock" flag */
940 if ((flags & PARSE_FORWARD_LOCK) != 0) {
941 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
942 }
943
944 /* Set the global "on SD card" flag */
945 if ((flags & PARSE_ON_SDCARD) != 0) {
946 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
947 }
948
Dianne Hackborn723738c2009-06-25 19:48:04 -0700949 // Resource boolean are -1, so 1 means we don't know the value.
950 int supportsSmallScreens = 1;
951 int supportsNormalScreens = 1;
952 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700953 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700954 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700955 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700958 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
959 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
960 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 continue;
962 }
963
964 String tagName = parser.getName();
965 if (tagName.equals("application")) {
966 if (foundApp) {
967 if (RIGID_PARSER) {
968 outError[0] = "<manifest> has more than one <application>";
969 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
970 return null;
971 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700972 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 XmlUtils.skipCurrentTag(parser);
974 continue;
975 }
976 }
977
978 foundApp = true;
979 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
980 return null;
981 }
982 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700983 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 return null;
985 }
986 } else if (tagName.equals("permission")) {
987 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
988 return null;
989 }
990 } else if (tagName.equals("permission-tree")) {
991 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
992 return null;
993 }
994 } else if (tagName.equals("uses-permission")) {
995 sa = res.obtainAttributes(attrs,
996 com.android.internal.R.styleable.AndroidManifestUsesPermission);
997
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800998 // Note: don't allow this value to be a reference to a resource
999 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 String name = sa.getNonResourceString(
1001 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne8241202012-04-06 13:39:09 -07001002 /* Not supporting optional permissions yet.
Dianne Hackborne639da72012-02-21 15:11:13 -08001003 boolean required = sa.getBoolean(
1004 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Dianne Hackborne8241202012-04-06 13:39:09 -07001005 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006
1007 sa.recycle();
1008
1009 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -07001010 pkg.requestedPermissions.add(name.intern());
Dianne Hackborne8241202012-04-06 13:39:09 -07001011 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 }
1013
1014 XmlUtils.skipCurrentTag(parser);
1015
1016 } else if (tagName.equals("uses-configuration")) {
1017 ConfigurationInfo cPref = new ConfigurationInfo();
1018 sa = res.obtainAttributes(attrs,
1019 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1020 cPref.reqTouchScreen = sa.getInt(
1021 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1022 Configuration.TOUCHSCREEN_UNDEFINED);
1023 cPref.reqKeyboardType = sa.getInt(
1024 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1025 Configuration.KEYBOARD_UNDEFINED);
1026 if (sa.getBoolean(
1027 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1028 false)) {
1029 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1030 }
1031 cPref.reqNavigation = sa.getInt(
1032 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1033 Configuration.NAVIGATION_UNDEFINED);
1034 if (sa.getBoolean(
1035 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1036 false)) {
1037 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1038 }
1039 sa.recycle();
1040 pkg.configPreferences.add(cPref);
1041
1042 XmlUtils.skipCurrentTag(parser);
1043
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001044 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001045 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001046 sa = res.obtainAttributes(attrs,
1047 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001048 // Note: don't allow this value to be a reference to a resource
1049 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001050 fi.name = sa.getNonResourceString(
1051 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1052 if (fi.name == null) {
1053 fi.reqGlEsVersion = sa.getInt(
1054 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1055 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1056 }
1057 if (sa.getBoolean(
1058 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1059 true)) {
1060 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1061 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001062 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001063 if (pkg.reqFeatures == null) {
1064 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1065 }
1066 pkg.reqFeatures.add(fi);
1067
1068 if (fi.name == null) {
1069 ConfigurationInfo cPref = new ConfigurationInfo();
1070 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1071 pkg.configPreferences.add(cPref);
1072 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001073
1074 XmlUtils.skipCurrentTag(parser);
1075
Dianne Hackborn851a5412009-05-08 12:06:44 -07001076 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001077 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 sa = res.obtainAttributes(attrs,
1079 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1080
Dianne Hackborn851a5412009-05-08 12:06:44 -07001081 int minVers = 0;
1082 String minCode = null;
1083 int targetVers = 0;
1084 String targetCode = null;
1085
1086 TypedValue val = sa.peekValue(
1087 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1088 if (val != null) {
1089 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1090 targetCode = minCode = val.string.toString();
1091 } else {
1092 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001093 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001094 }
1095 }
1096
1097 val = sa.peekValue(
1098 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1099 if (val != null) {
1100 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1101 targetCode = minCode = val.string.toString();
1102 } else {
1103 // If it's not a string, it's an integer.
1104 targetVers = val.data;
1105 }
1106 }
1107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 sa.recycle();
1109
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001110 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001111 if (!minCode.equals(SDK_CODENAME)) {
1112 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001113 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001114 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001115 } else {
1116 outError[0] = "Requires development platform " + minCode
1117 + " but this is a release platform.";
1118 }
1119 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1120 return null;
1121 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001122 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001123 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001124 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001125 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1126 return null;
1127 }
1128
Dianne Hackborn851a5412009-05-08 12:06:44 -07001129 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001130 if (!targetCode.equals(SDK_CODENAME)) {
1131 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001132 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001133 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001134 } else {
1135 outError[0] = "Requires development platform " + targetCode
1136 + " but this is a release platform.";
1137 }
1138 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1139 return null;
1140 }
1141 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001142 pkg.applicationInfo.targetSdkVersion
1143 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1144 } else {
1145 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 }
1148
1149 XmlUtils.skipCurrentTag(parser);
1150
Dianne Hackborn723738c2009-06-25 19:48:04 -07001151 } else if (tagName.equals("supports-screens")) {
1152 sa = res.obtainAttributes(attrs,
1153 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1154
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001155 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1156 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1157 0);
1158 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1159 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1160 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001161 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1162 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1163 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001164
Dianne Hackborn723738c2009-06-25 19:48:04 -07001165 // This is a trick to get a boolean and still able to detect
1166 // if a value was actually set.
1167 supportsSmallScreens = sa.getInteger(
1168 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1169 supportsSmallScreens);
1170 supportsNormalScreens = sa.getInteger(
1171 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1172 supportsNormalScreens);
1173 supportsLargeScreens = sa.getInteger(
1174 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1175 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001176 supportsXLargeScreens = sa.getInteger(
1177 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1178 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001179 resizeable = sa.getInteger(
1180 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001181 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001182 anyDensity = sa.getInteger(
1183 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1184 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001185
1186 sa.recycle();
1187
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001188 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001189
1190 } else if (tagName.equals("protected-broadcast")) {
1191 sa = res.obtainAttributes(attrs,
1192 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1193
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001194 // Note: don't allow this value to be a reference to a resource
1195 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001196 String name = sa.getNonResourceString(
1197 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1198
1199 sa.recycle();
1200
1201 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1202 if (pkg.protectedBroadcasts == null) {
1203 pkg.protectedBroadcasts = new ArrayList<String>();
1204 }
1205 if (!pkg.protectedBroadcasts.contains(name)) {
1206 pkg.protectedBroadcasts.add(name.intern());
1207 }
1208 }
1209
1210 XmlUtils.skipCurrentTag(parser);
1211
1212 } else if (tagName.equals("instrumentation")) {
1213 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1214 return null;
1215 }
1216
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001217 } else if (tagName.equals("original-package")) {
1218 sa = res.obtainAttributes(attrs,
1219 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1220
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001221 String orig =sa.getNonConfigurationString(
1222 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001223 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001224 if (pkg.mOriginalPackages == null) {
1225 pkg.mOriginalPackages = new ArrayList<String>();
1226 pkg.mRealPackage = pkg.packageName;
1227 }
1228 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001229 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001230
1231 sa.recycle();
1232
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001233 XmlUtils.skipCurrentTag(parser);
1234
1235 } else if (tagName.equals("adopt-permissions")) {
1236 sa = res.obtainAttributes(attrs,
1237 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1238
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001239 String name = sa.getNonConfigurationString(
1240 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001241
1242 sa.recycle();
1243
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001244 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001245 if (pkg.mAdoptPermissions == null) {
1246 pkg.mAdoptPermissions = new ArrayList<String>();
1247 }
1248 pkg.mAdoptPermissions.add(name);
1249 }
1250
1251 XmlUtils.skipCurrentTag(parser);
1252
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001253 } else if (tagName.equals("uses-gl-texture")) {
1254 // Just skip this tag
1255 XmlUtils.skipCurrentTag(parser);
1256 continue;
1257
1258 } else if (tagName.equals("compatible-screens")) {
1259 // Just skip this tag
1260 XmlUtils.skipCurrentTag(parser);
1261 continue;
1262
Dianne Hackborn854060a2009-07-09 18:14:31 -07001263 } else if (tagName.equals("eat-comment")) {
1264 // Just skip this tag
1265 XmlUtils.skipCurrentTag(parser);
1266 continue;
1267
1268 } else if (RIGID_PARSER) {
1269 outError[0] = "Bad element under <manifest>: "
1270 + parser.getName();
1271 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1272 return null;
1273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001275 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001276 + " at " + mArchiveSourcePath + " "
1277 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 XmlUtils.skipCurrentTag(parser);
1279 continue;
1280 }
1281 }
1282
1283 if (!foundApp && pkg.instrumentation.size() == 0) {
1284 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1285 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1286 }
1287
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001288 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001289 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001290 for (int ip=0; ip<NP; ip++) {
1291 final PackageParser.NewPermissionInfo npi
1292 = PackageParser.NEW_PERMISSIONS[ip];
1293 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1294 break;
1295 }
1296 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001297 if (implicitPerms == null) {
1298 implicitPerms = new StringBuilder(128);
1299 implicitPerms.append(pkg.packageName);
1300 implicitPerms.append(": compat added ");
1301 } else {
1302 implicitPerms.append(' ');
1303 }
1304 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001305 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001306 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001307 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001308 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001309 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001310 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001311 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001312
1313 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1314 for (int is=0; is<NS; is++) {
1315 final PackageParser.SplitPermissionInfo spi
1316 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001317 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1318 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001319 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001320 }
1321 for (int in=0; in<spi.newPerms.length; in++) {
1322 final String perm = spi.newPerms[in];
1323 if (!pkg.requestedPermissions.contains(perm)) {
1324 pkg.requestedPermissions.add(perm);
1325 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1326 }
1327 }
1328 }
1329
Dianne Hackborn723738c2009-06-25 19:48:04 -07001330 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1331 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001332 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001333 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1334 }
1335 if (supportsNormalScreens != 0) {
1336 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1337 }
1338 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1339 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001340 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001341 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1342 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001343 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1344 && pkg.applicationInfo.targetSdkVersion
1345 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1346 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1347 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001348 if (resizeable < 0 || (resizeable > 0
1349 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001350 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001351 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1352 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001353 if (anyDensity < 0 || (anyDensity > 0
1354 && pkg.applicationInfo.targetSdkVersion
1355 >= android.os.Build.VERSION_CODES.DONUT)) {
1356 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001357 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 return pkg;
1360 }
1361
1362 private static String buildClassName(String pkg, CharSequence clsSeq,
1363 String[] outError) {
1364 if (clsSeq == null || clsSeq.length() <= 0) {
1365 outError[0] = "Empty class name in package " + pkg;
1366 return null;
1367 }
1368 String cls = clsSeq.toString();
1369 char c = cls.charAt(0);
1370 if (c == '.') {
1371 return (pkg + cls).intern();
1372 }
1373 if (cls.indexOf('.') < 0) {
1374 StringBuilder b = new StringBuilder(pkg);
1375 b.append('.');
1376 b.append(cls);
1377 return b.toString().intern();
1378 }
1379 if (c >= 'a' && c <= 'z') {
1380 return cls.intern();
1381 }
1382 outError[0] = "Bad class name " + cls + " in package " + pkg;
1383 return null;
1384 }
1385
1386 private static String buildCompoundName(String pkg,
1387 CharSequence procSeq, String type, String[] outError) {
1388 String proc = procSeq.toString();
1389 char c = proc.charAt(0);
1390 if (pkg != null && c == ':') {
1391 if (proc.length() < 2) {
1392 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1393 + ": must be at least two characters";
1394 return null;
1395 }
1396 String subName = proc.substring(1);
1397 String nameError = validateName(subName, false);
1398 if (nameError != null) {
1399 outError[0] = "Invalid " + type + " name " + proc + " in package "
1400 + pkg + ": " + nameError;
1401 return null;
1402 }
1403 return (pkg + proc).intern();
1404 }
1405 String nameError = validateName(proc, true);
1406 if (nameError != null && !"system".equals(proc)) {
1407 outError[0] = "Invalid " + type + " name " + proc + " in package "
1408 + pkg + ": " + nameError;
1409 return null;
1410 }
1411 return proc.intern();
1412 }
1413
1414 private static String buildProcessName(String pkg, String defProc,
1415 CharSequence procSeq, int flags, String[] separateProcesses,
1416 String[] outError) {
1417 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1418 return defProc != null ? defProc : pkg;
1419 }
1420 if (separateProcesses != null) {
1421 for (int i=separateProcesses.length-1; i>=0; i--) {
1422 String sp = separateProcesses[i];
1423 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1424 return pkg;
1425 }
1426 }
1427 }
1428 if (procSeq == null || procSeq.length() <= 0) {
1429 return defProc;
1430 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001431 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
1433
1434 private static String buildTaskAffinityName(String pkg, String defProc,
1435 CharSequence procSeq, String[] outError) {
1436 if (procSeq == null) {
1437 return defProc;
1438 }
1439 if (procSeq.length() <= 0) {
1440 return null;
1441 }
1442 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1443 }
1444
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001445 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 XmlPullParser parser, AttributeSet attrs, String[] outError)
1447 throws XmlPullParserException, IOException {
1448 PermissionGroup perm = new PermissionGroup(owner);
1449
1450 TypedArray sa = res.obtainAttributes(attrs,
1451 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1452
1453 if (!parsePackageItemInfo(owner, perm.info, outError,
1454 "<permission-group>", sa,
1455 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1456 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001457 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1458 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 sa.recycle();
1460 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1461 return null;
1462 }
1463
1464 perm.info.descriptionRes = sa.getResourceId(
1465 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1466 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001467 perm.info.flags = sa.getInt(
1468 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
1469 perm.info.priority = sa.getInt(
1470 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001471 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001472 perm.info.priority = 0;
1473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474
1475 sa.recycle();
1476
1477 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1478 outError)) {
1479 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1480 return null;
1481 }
1482
1483 owner.permissionGroups.add(perm);
1484
1485 return perm;
1486 }
1487
1488 private Permission parsePermission(Package owner, Resources res,
1489 XmlPullParser parser, AttributeSet attrs, String[] outError)
1490 throws XmlPullParserException, IOException {
1491 Permission perm = new Permission(owner);
1492
1493 TypedArray sa = res.obtainAttributes(attrs,
1494 com.android.internal.R.styleable.AndroidManifestPermission);
1495
1496 if (!parsePackageItemInfo(owner, perm.info, outError,
1497 "<permission>", sa,
1498 com.android.internal.R.styleable.AndroidManifestPermission_name,
1499 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001500 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1501 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 sa.recycle();
1503 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1504 return null;
1505 }
1506
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001507 // Note: don't allow this value to be a reference to a resource
1508 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 perm.info.group = sa.getNonResourceString(
1510 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1511 if (perm.info.group != null) {
1512 perm.info.group = perm.info.group.intern();
1513 }
1514
1515 perm.info.descriptionRes = sa.getResourceId(
1516 com.android.internal.R.styleable.AndroidManifestPermission_description,
1517 0);
1518
1519 perm.info.protectionLevel = sa.getInt(
1520 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1521 PermissionInfo.PROTECTION_NORMAL);
1522
1523 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 if (perm.info.protectionLevel == -1) {
1526 outError[0] = "<permission> does not specify protectionLevel";
1527 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1528 return null;
1529 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001530
1531 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1532
1533 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1534 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1535 PermissionInfo.PROTECTION_SIGNATURE) {
1536 outError[0] = "<permission> protectionLevel specifies a flag but is "
1537 + "not based on signature type";
1538 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1539 return null;
1540 }
1541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542
1543 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1544 outError)) {
1545 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1546 return null;
1547 }
1548
1549 owner.permissions.add(perm);
1550
1551 return perm;
1552 }
1553
1554 private Permission parsePermissionTree(Package owner, Resources res,
1555 XmlPullParser parser, AttributeSet attrs, String[] outError)
1556 throws XmlPullParserException, IOException {
1557 Permission perm = new Permission(owner);
1558
1559 TypedArray sa = res.obtainAttributes(attrs,
1560 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1561
1562 if (!parsePackageItemInfo(owner, perm.info, outError,
1563 "<permission-tree>", sa,
1564 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1565 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001566 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1567 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 sa.recycle();
1569 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1570 return null;
1571 }
1572
1573 sa.recycle();
1574
1575 int index = perm.info.name.indexOf('.');
1576 if (index > 0) {
1577 index = perm.info.name.indexOf('.', index+1);
1578 }
1579 if (index < 0) {
1580 outError[0] = "<permission-tree> name has less than three segments: "
1581 + perm.info.name;
1582 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1583 return null;
1584 }
1585
1586 perm.info.descriptionRes = 0;
1587 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1588 perm.tree = true;
1589
1590 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1591 outError)) {
1592 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1593 return null;
1594 }
1595
1596 owner.permissions.add(perm);
1597
1598 return perm;
1599 }
1600
1601 private Instrumentation parseInstrumentation(Package owner, Resources res,
1602 XmlPullParser parser, AttributeSet attrs, String[] outError)
1603 throws XmlPullParserException, IOException {
1604 TypedArray sa = res.obtainAttributes(attrs,
1605 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1606
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001607 if (mParseInstrumentationArgs == null) {
1608 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1609 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1610 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001611 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1612 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001613 mParseInstrumentationArgs.tag = "<instrumentation>";
1614 }
1615
1616 mParseInstrumentationArgs.sa = sa;
1617
1618 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1619 new InstrumentationInfo());
1620 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 sa.recycle();
1622 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1623 return null;
1624 }
1625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001627 // Note: don't allow this value to be a reference to a resource
1628 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 str = sa.getNonResourceString(
1630 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1631 a.info.targetPackage = str != null ? str.intern() : null;
1632
1633 a.info.handleProfiling = sa.getBoolean(
1634 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1635 false);
1636
1637 a.info.functionalTest = sa.getBoolean(
1638 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1639 false);
1640
1641 sa.recycle();
1642
1643 if (a.info.targetPackage == null) {
1644 outError[0] = "<instrumentation> does not specify targetPackage";
1645 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1646 return null;
1647 }
1648
1649 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1650 outError)) {
1651 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1652 return null;
1653 }
1654
1655 owner.instrumentation.add(a);
1656
1657 return a;
1658 }
1659
1660 private boolean parseApplication(Package owner, Resources res,
1661 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1662 throws XmlPullParserException, IOException {
1663 final ApplicationInfo ai = owner.applicationInfo;
1664 final String pkgName = owner.applicationInfo.packageName;
1665
1666 TypedArray sa = res.obtainAttributes(attrs,
1667 com.android.internal.R.styleable.AndroidManifestApplication);
1668
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001669 String name = sa.getNonConfigurationString(
1670 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 if (name != null) {
1672 ai.className = buildClassName(pkgName, name, outError);
1673 if (ai.className == null) {
1674 sa.recycle();
1675 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1676 return false;
1677 }
1678 }
1679
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001680 String manageSpaceActivity = sa.getNonConfigurationString(
1681 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 if (manageSpaceActivity != null) {
1683 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1684 outError);
1685 }
1686
Christopher Tate181fafa2009-05-14 11:12:14 -07001687 boolean allowBackup = sa.getBoolean(
1688 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1689 if (allowBackup) {
1690 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001691
Christopher Tate3de55bc2010-03-12 17:28:08 -08001692 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1693 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001694 String backupAgent = sa.getNonConfigurationString(
1695 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001696 if (backupAgent != null) {
1697 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001698 if (DEBUG_BACKUP) {
1699 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001700 + " from " + pkgName + "+" + backupAgent);
1701 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001702
1703 if (sa.getBoolean(
1704 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1705 true)) {
1706 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1707 }
1708 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001709 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1710 false)) {
1711 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1712 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001713 }
1714 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 TypedValue v = sa.peekValue(
1717 com.android.internal.R.styleable.AndroidManifestApplication_label);
1718 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1719 ai.nonLocalizedLabel = v.coerceToString();
1720 }
1721
1722 ai.icon = sa.getResourceId(
1723 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001724 ai.logo = sa.getResourceId(
1725 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001727 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 ai.descriptionRes = sa.getResourceId(
1729 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1730
1731 if ((flags&PARSE_IS_SYSTEM) != 0) {
1732 if (sa.getBoolean(
1733 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1734 false)) {
1735 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1736 }
1737 }
1738
1739 if (sa.getBoolean(
1740 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1741 false)) {
1742 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1743 }
1744
1745 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001746 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001747 false)) {
1748 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1749 }
1750
Romain Guy529b60a2010-08-03 18:05:47 -07001751 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001752 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001753 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001754
1755 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1757 true)) {
1758 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1759 }
1760
1761 if (sa.getBoolean(
1762 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1763 false)) {
1764 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1765 }
1766
1767 if (sa.getBoolean(
1768 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1769 true)) {
1770 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1771 }
1772
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001773 if (sa.getBoolean(
1774 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001775 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001776 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1777 }
1778
Jason parksa3cdaa52011-01-13 14:15:43 -06001779 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001780 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001781 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001782 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001783 }
1784
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001785 if (sa.getBoolean(
1786 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1787 false /* default is no RTL support*/)) {
1788 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1789 }
1790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001792 str = sa.getNonConfigurationString(
1793 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1795
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001796 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1797 str = sa.getNonConfigurationString(
1798 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1799 } else {
1800 // Some older apps have been seen to use a resource reference
1801 // here that on older builds was ignored (with a warning). We
1802 // need to continue to do this for them so they don't break.
1803 str = sa.getNonResourceString(
1804 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1805 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1807 str, outError);
1808
1809 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001810 CharSequence pname;
1811 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1812 pname = sa.getNonConfigurationString(
1813 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1814 } else {
1815 // Some older apps have been seen to use a resource reference
1816 // here that on older builds was ignored (with a warning). We
1817 // need to continue to do this for them so they don't break.
1818 pname = sa.getNonResourceString(
1819 com.android.internal.R.styleable.AndroidManifestApplication_process);
1820 }
1821 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 flags, mSeparateProcesses, outError);
1823
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001824 ai.enabled = sa.getBoolean(
1825 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001826
Dianne Hackborn02486b12010-08-26 14:18:37 -07001827 if (false) {
1828 if (sa.getBoolean(
1829 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1830 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001831 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001832
1833 // A heavy-weight application can not be in a custom process.
1834 // We can do direct compare because we intern all strings.
1835 if (ai.processName != null && ai.processName != ai.packageName) {
1836 outError[0] = "cantSaveState applications can not use custom processes";
1837 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001838 }
1839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 }
1841
Adam Powell269248d2011-08-02 10:26:54 -07001842 ai.uiOptions = sa.getInt(
1843 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 sa.recycle();
1846
1847 if (outError[0] != null) {
1848 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1849 return false;
1850 }
1851
1852 final int innerDepth = parser.getDepth();
1853
1854 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001855 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1856 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1857 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 continue;
1859 }
1860
1861 String tagName = parser.getName();
1862 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001863 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1864 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 if (a == null) {
1866 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1867 return false;
1868 }
1869
1870 owner.activities.add(a);
1871
1872 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001873 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 if (a == null) {
1875 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1876 return false;
1877 }
1878
1879 owner.receivers.add(a);
1880
1881 } else if (tagName.equals("service")) {
1882 Service s = parseService(owner, res, parser, attrs, flags, outError);
1883 if (s == null) {
1884 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1885 return false;
1886 }
1887
1888 owner.services.add(s);
1889
1890 } else if (tagName.equals("provider")) {
1891 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1892 if (p == null) {
1893 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1894 return false;
1895 }
1896
1897 owner.providers.add(p);
1898
1899 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001900 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 if (a == null) {
1902 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1903 return false;
1904 }
1905
1906 owner.activities.add(a);
1907
1908 } else if (parser.getName().equals("meta-data")) {
1909 // note: application meta-data is stored off to the side, so it can
1910 // remain null in the primary copy (we like to avoid extra copies because
1911 // it can be large)
1912 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1913 outError)) == null) {
1914 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1915 return false;
1916 }
1917
1918 } else if (tagName.equals("uses-library")) {
1919 sa = res.obtainAttributes(attrs,
1920 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1921
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001922 // Note: don't allow this value to be a reference to a resource
1923 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 String lname = sa.getNonResourceString(
1925 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001926 boolean req = sa.getBoolean(
1927 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1928 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929
1930 sa.recycle();
1931
Dianne Hackborn49237342009-08-27 20:08:01 -07001932 if (lname != null) {
1933 if (req) {
1934 if (owner.usesLibraries == null) {
1935 owner.usesLibraries = new ArrayList<String>();
1936 }
1937 if (!owner.usesLibraries.contains(lname)) {
1938 owner.usesLibraries.add(lname.intern());
1939 }
1940 } else {
1941 if (owner.usesOptionalLibraries == null) {
1942 owner.usesOptionalLibraries = new ArrayList<String>();
1943 }
1944 if (!owner.usesOptionalLibraries.contains(lname)) {
1945 owner.usesOptionalLibraries.add(lname.intern());
1946 }
1947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 }
1949
1950 XmlUtils.skipCurrentTag(parser);
1951
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001952 } else if (tagName.equals("uses-package")) {
1953 // Dependencies for app installers; we don't currently try to
1954 // enforce this.
1955 XmlUtils.skipCurrentTag(parser);
1956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 } else {
1958 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001959 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001960 + " at " + mArchiveSourcePath + " "
1961 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 XmlUtils.skipCurrentTag(parser);
1963 continue;
1964 } else {
1965 outError[0] = "Bad element under <application>: " + tagName;
1966 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1967 return false;
1968 }
1969 }
1970 }
1971
1972 return true;
1973 }
1974
1975 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1976 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001977 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001978 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 if (name == null) {
1980 outError[0] = tag + " does not specify android:name";
1981 return false;
1982 }
1983
1984 outInfo.name
1985 = buildClassName(owner.applicationInfo.packageName, name, outError);
1986 if (outInfo.name == null) {
1987 return false;
1988 }
1989
1990 int iconVal = sa.getResourceId(iconRes, 0);
1991 if (iconVal != 0) {
1992 outInfo.icon = iconVal;
1993 outInfo.nonLocalizedLabel = null;
1994 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001995
1996 int logoVal = sa.getResourceId(logoRes, 0);
1997 if (logoVal != 0) {
1998 outInfo.logo = logoVal;
1999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000
2001 TypedValue v = sa.peekValue(labelRes);
2002 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2003 outInfo.nonLocalizedLabel = v.coerceToString();
2004 }
2005
2006 outInfo.packageName = owner.packageName;
2007
2008 return true;
2009 }
2010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 private Activity parseActivity(Package owner, Resources res,
2012 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002013 boolean receiver, boolean hardwareAccelerated)
2014 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 TypedArray sa = res.obtainAttributes(attrs,
2016 com.android.internal.R.styleable.AndroidManifestActivity);
2017
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002018 if (mParseActivityArgs == null) {
2019 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2020 com.android.internal.R.styleable.AndroidManifestActivity_name,
2021 com.android.internal.R.styleable.AndroidManifestActivity_label,
2022 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002023 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002024 mSeparateProcesses,
2025 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002026 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002027 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2028 }
2029
2030 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2031 mParseActivityArgs.sa = sa;
2032 mParseActivityArgs.flags = flags;
2033
2034 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2035 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 sa.recycle();
2037 return null;
2038 }
2039
2040 final boolean setExported = sa.hasValue(
2041 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2042 if (setExported) {
2043 a.info.exported = sa.getBoolean(
2044 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2045 }
2046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 a.info.theme = sa.getResourceId(
2048 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2049
Adam Powell269248d2011-08-02 10:26:54 -07002050 a.info.uiOptions = sa.getInt(
2051 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2052 a.info.applicationInfo.uiOptions);
2053
Adam Powelldd8fab22012-03-22 17:47:27 -07002054 String parentName = sa.getNonConfigurationString(
2055 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2056 if (parentName != null) {
2057 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2058 if (outError[0] == null) {
2059 a.info.parentActivityName = parentClassName;
2060 } else {
2061 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2062 parentName);
2063 outError[0] = null;
2064 }
2065 }
2066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002068 str = sa.getNonConfigurationString(
2069 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 if (str == null) {
2071 a.info.permission = owner.applicationInfo.permission;
2072 } else {
2073 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2074 }
2075
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002076 str = sa.getNonConfigurationString(
2077 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2079 owner.applicationInfo.taskAffinity, str, outError);
2080
2081 a.info.flags = 0;
2082 if (sa.getBoolean(
2083 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2084 false)) {
2085 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2086 }
2087
2088 if (sa.getBoolean(
2089 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2090 false)) {
2091 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2092 }
2093
2094 if (sa.getBoolean(
2095 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2096 false)) {
2097 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2098 }
2099
2100 if (sa.getBoolean(
2101 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2102 false)) {
2103 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2104 }
2105
2106 if (sa.getBoolean(
2107 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2108 false)) {
2109 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2110 }
2111
2112 if (sa.getBoolean(
2113 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2114 false)) {
2115 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2116 }
2117
2118 if (sa.getBoolean(
2119 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2120 false)) {
2121 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2122 }
2123
2124 if (sa.getBoolean(
2125 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2126 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2127 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2128 }
2129
Dianne Hackbornffa42482009-09-23 22:20:11 -07002130 if (sa.getBoolean(
2131 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2132 false)) {
2133 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2134 }
2135
Daniel Sandler613dde42010-06-21 13:46:39 -04002136 if (sa.getBoolean(
2137 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2138 false)) {
2139 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2140 }
Romain Guy529b60a2010-08-03 18:05:47 -07002141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002143 if (sa.getBoolean(
2144 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2145 hardwareAccelerated)) {
2146 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2147 }
2148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 a.info.launchMode = sa.getInt(
2150 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2151 ActivityInfo.LAUNCH_MULTIPLE);
2152 a.info.screenOrientation = sa.getInt(
2153 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2154 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2155 a.info.configChanges = sa.getInt(
2156 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2157 0);
2158 a.info.softInputMode = sa.getInt(
2159 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2160 0);
2161 } else {
2162 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2163 a.info.configChanges = 0;
2164 }
2165
2166 sa.recycle();
2167
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002168 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002169 // A heavy-weight application can not have receives in its main process
2170 // We can do direct compare because we intern all strings.
2171 if (a.info.processName == owner.packageName) {
2172 outError[0] = "Heavy-weight applications can not have receivers in main process";
2173 }
2174 }
2175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 if (outError[0] != null) {
2177 return null;
2178 }
2179
2180 int outerDepth = parser.getDepth();
2181 int type;
2182 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2183 && (type != XmlPullParser.END_TAG
2184 || parser.getDepth() > outerDepth)) {
2185 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2186 continue;
2187 }
2188
2189 if (parser.getName().equals("intent-filter")) {
2190 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2191 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2192 return null;
2193 }
2194 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002195 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002196 + mArchiveSourcePath + " "
2197 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 } else {
2199 a.intents.add(intent);
2200 }
2201 } else if (parser.getName().equals("meta-data")) {
2202 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2203 outError)) == null) {
2204 return null;
2205 }
2206 } else {
2207 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002208 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002210 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002211 + " at " + mArchiveSourcePath + " "
2212 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002214 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002215 + " at " + mArchiveSourcePath + " "
2216 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 }
2218 XmlUtils.skipCurrentTag(parser);
2219 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002221 if (receiver) {
2222 outError[0] = "Bad element under <receiver>: " + parser.getName();
2223 } else {
2224 outError[0] = "Bad element under <activity>: " + parser.getName();
2225 }
2226 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002228 }
2229 }
2230
2231 if (!setExported) {
2232 a.info.exported = a.intents.size() > 0;
2233 }
2234
2235 return a;
2236 }
2237
2238 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002239 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2240 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 TypedArray sa = res.obtainAttributes(attrs,
2242 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2243
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002244 String targetActivity = sa.getNonConfigurationString(
2245 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 if (targetActivity == null) {
2247 outError[0] = "<activity-alias> does not specify android:targetActivity";
2248 sa.recycle();
2249 return null;
2250 }
2251
2252 targetActivity = buildClassName(owner.applicationInfo.packageName,
2253 targetActivity, outError);
2254 if (targetActivity == null) {
2255 sa.recycle();
2256 return null;
2257 }
2258
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002259 if (mParseActivityAliasArgs == null) {
2260 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2261 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2262 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2263 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002264 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002265 mSeparateProcesses,
2266 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002267 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002268 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2269 mParseActivityAliasArgs.tag = "<activity-alias>";
2270 }
2271
2272 mParseActivityAliasArgs.sa = sa;
2273 mParseActivityAliasArgs.flags = flags;
2274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 Activity target = null;
2276
2277 final int NA = owner.activities.size();
2278 for (int i=0; i<NA; i++) {
2279 Activity t = owner.activities.get(i);
2280 if (targetActivity.equals(t.info.name)) {
2281 target = t;
2282 break;
2283 }
2284 }
2285
2286 if (target == null) {
2287 outError[0] = "<activity-alias> target activity " + targetActivity
2288 + " not found in manifest";
2289 sa.recycle();
2290 return null;
2291 }
2292
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002293 ActivityInfo info = new ActivityInfo();
2294 info.targetActivity = targetActivity;
2295 info.configChanges = target.info.configChanges;
2296 info.flags = target.info.flags;
2297 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002298 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002299 info.labelRes = target.info.labelRes;
2300 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2301 info.launchMode = target.info.launchMode;
2302 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002303 if (info.descriptionRes == 0) {
2304 info.descriptionRes = target.info.descriptionRes;
2305 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002306 info.screenOrientation = target.info.screenOrientation;
2307 info.taskAffinity = target.info.taskAffinity;
2308 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002309 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002310 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002311 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002312
2313 Activity a = new Activity(mParseActivityAliasArgs, info);
2314 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 sa.recycle();
2316 return null;
2317 }
2318
2319 final boolean setExported = sa.hasValue(
2320 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2321 if (setExported) {
2322 a.info.exported = sa.getBoolean(
2323 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2324 }
2325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002327 str = sa.getNonConfigurationString(
2328 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 if (str != null) {
2330 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2331 }
2332
Adam Powelldd8fab22012-03-22 17:47:27 -07002333 String parentName = sa.getNonConfigurationString(
2334 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2335 0);
2336 if (parentName != null) {
2337 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2338 if (outError[0] == null) {
2339 a.info.parentActivityName = parentClassName;
2340 } else {
2341 Log.e(TAG, "Activity alias " + a.info.name +
2342 " specified invalid parentActivityName " + parentName);
2343 outError[0] = null;
2344 }
2345 }
2346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 sa.recycle();
2348
2349 if (outError[0] != null) {
2350 return null;
2351 }
2352
2353 int outerDepth = parser.getDepth();
2354 int type;
2355 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2356 && (type != XmlPullParser.END_TAG
2357 || parser.getDepth() > outerDepth)) {
2358 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2359 continue;
2360 }
2361
2362 if (parser.getName().equals("intent-filter")) {
2363 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2364 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2365 return null;
2366 }
2367 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002368 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002369 + mArchiveSourcePath + " "
2370 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 } else {
2372 a.intents.add(intent);
2373 }
2374 } else if (parser.getName().equals("meta-data")) {
2375 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2376 outError)) == null) {
2377 return null;
2378 }
2379 } else {
2380 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002381 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002382 + " at " + mArchiveSourcePath + " "
2383 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 XmlUtils.skipCurrentTag(parser);
2385 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002386 } else {
2387 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2388 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
2391 }
2392
2393 if (!setExported) {
2394 a.info.exported = a.intents.size() > 0;
2395 }
2396
2397 return a;
2398 }
2399
2400 private Provider parseProvider(Package owner, Resources res,
2401 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2402 throws XmlPullParserException, IOException {
2403 TypedArray sa = res.obtainAttributes(attrs,
2404 com.android.internal.R.styleable.AndroidManifestProvider);
2405
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002406 if (mParseProviderArgs == null) {
2407 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2408 com.android.internal.R.styleable.AndroidManifestProvider_name,
2409 com.android.internal.R.styleable.AndroidManifestProvider_label,
2410 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002411 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002412 mSeparateProcesses,
2413 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002414 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002415 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2416 mParseProviderArgs.tag = "<provider>";
2417 }
2418
2419 mParseProviderArgs.sa = sa;
2420 mParseProviderArgs.flags = flags;
2421
2422 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2423 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 sa.recycle();
2425 return null;
2426 }
2427
2428 p.info.exported = sa.getBoolean(
2429 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2430
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002431 String cpname = sa.getNonConfigurationString(
2432 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433
2434 p.info.isSyncable = sa.getBoolean(
2435 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2436 false);
2437
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002438 String permission = sa.getNonConfigurationString(
2439 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2440 String str = sa.getNonConfigurationString(
2441 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 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.readPermission = owner.applicationInfo.permission;
2447 } else {
2448 p.info.readPermission =
2449 str.length() > 0 ? str.toString().intern() : null;
2450 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002451 str = sa.getNonConfigurationString(
2452 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 if (str == null) {
2454 str = permission;
2455 }
2456 if (str == null) {
2457 p.info.writePermission = owner.applicationInfo.permission;
2458 } else {
2459 p.info.writePermission =
2460 str.length() > 0 ? str.toString().intern() : null;
2461 }
2462
2463 p.info.grantUriPermissions = sa.getBoolean(
2464 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2465 false);
2466
2467 p.info.multiprocess = sa.getBoolean(
2468 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2469 false);
2470
2471 p.info.initOrder = sa.getInt(
2472 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2473 0);
2474
2475 sa.recycle();
2476
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002477 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002478 // A heavy-weight application can not have providers in its main process
2479 // We can do direct compare because we intern all strings.
2480 if (p.info.processName == owner.packageName) {
2481 outError[0] = "Heavy-weight applications can not have providers in main process";
2482 return null;
2483 }
2484 }
2485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 if (cpname == null) {
2487 outError[0] = "<provider> does not incude authorities attribute";
2488 return null;
2489 }
2490 p.info.authority = cpname.intern();
2491
2492 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2493 return null;
2494 }
2495
2496 return p;
2497 }
2498
2499 private boolean parseProviderTags(Resources res,
2500 XmlPullParser parser, AttributeSet attrs,
2501 Provider outInfo, String[] outError)
2502 throws XmlPullParserException, IOException {
2503 int outerDepth = parser.getDepth();
2504 int type;
2505 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2506 && (type != XmlPullParser.END_TAG
2507 || parser.getDepth() > outerDepth)) {
2508 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2509 continue;
2510 }
2511
2512 if (parser.getName().equals("meta-data")) {
2513 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2514 outInfo.metaData, outError)) == null) {
2515 return false;
2516 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 } else if (parser.getName().equals("grant-uri-permission")) {
2519 TypedArray sa = res.obtainAttributes(attrs,
2520 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2521
2522 PatternMatcher pa = null;
2523
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002524 String str = sa.getNonConfigurationString(
2525 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 if (str != null) {
2527 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2528 }
2529
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002530 str = sa.getNonConfigurationString(
2531 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 if (str != null) {
2533 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2534 }
2535
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002536 str = sa.getNonConfigurationString(
2537 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 if (str != null) {
2539 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2540 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 sa.recycle();
2543
2544 if (pa != null) {
2545 if (outInfo.info.uriPermissionPatterns == null) {
2546 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2547 outInfo.info.uriPermissionPatterns[0] = pa;
2548 } else {
2549 final int N = outInfo.info.uriPermissionPatterns.length;
2550 PatternMatcher[] newp = new PatternMatcher[N+1];
2551 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2552 newp[N] = pa;
2553 outInfo.info.uriPermissionPatterns = newp;
2554 }
2555 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002556 } else {
2557 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002558 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002559 + parser.getName() + " at " + mArchiveSourcePath + " "
2560 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002561 XmlUtils.skipCurrentTag(parser);
2562 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002563 } else {
2564 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2565 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002566 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002567 }
2568 XmlUtils.skipCurrentTag(parser);
2569
2570 } else if (parser.getName().equals("path-permission")) {
2571 TypedArray sa = res.obtainAttributes(attrs,
2572 com.android.internal.R.styleable.AndroidManifestPathPermission);
2573
2574 PathPermission pa = null;
2575
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002576 String permission = sa.getNonConfigurationString(
2577 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2578 String readPermission = sa.getNonConfigurationString(
2579 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002580 if (readPermission == null) {
2581 readPermission = permission;
2582 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002583 String writePermission = sa.getNonConfigurationString(
2584 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002585 if (writePermission == null) {
2586 writePermission = permission;
2587 }
2588
2589 boolean havePerm = false;
2590 if (readPermission != null) {
2591 readPermission = readPermission.intern();
2592 havePerm = true;
2593 }
2594 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002595 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002596 havePerm = true;
2597 }
2598
2599 if (!havePerm) {
2600 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002601 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002602 + parser.getName() + " at " + mArchiveSourcePath + " "
2603 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002604 XmlUtils.skipCurrentTag(parser);
2605 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002606 } else {
2607 outError[0] = "No readPermission or writePermssion for <path-permission>";
2608 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002609 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002610 }
2611
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002612 String path = sa.getNonConfigurationString(
2613 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002614 if (path != null) {
2615 pa = new PathPermission(path,
2616 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2617 }
2618
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002619 path = sa.getNonConfigurationString(
2620 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002621 if (path != null) {
2622 pa = new PathPermission(path,
2623 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2624 }
2625
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002626 path = sa.getNonConfigurationString(
2627 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002628 if (path != null) {
2629 pa = new PathPermission(path,
2630 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2631 }
2632
2633 sa.recycle();
2634
2635 if (pa != null) {
2636 if (outInfo.info.pathPermissions == null) {
2637 outInfo.info.pathPermissions = new PathPermission[1];
2638 outInfo.info.pathPermissions[0] = pa;
2639 } else {
2640 final int N = outInfo.info.pathPermissions.length;
2641 PathPermission[] newp = new PathPermission[N+1];
2642 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2643 newp[N] = pa;
2644 outInfo.info.pathPermissions = newp;
2645 }
2646 } else {
2647 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002648 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002649 + parser.getName() + " at " + mArchiveSourcePath + " "
2650 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002651 XmlUtils.skipCurrentTag(parser);
2652 continue;
2653 }
2654 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2655 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 }
2657 XmlUtils.skipCurrentTag(parser);
2658
2659 } else {
2660 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002661 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002662 + parser.getName() + " at " + mArchiveSourcePath + " "
2663 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 XmlUtils.skipCurrentTag(parser);
2665 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002666 } else {
2667 outError[0] = "Bad element under <provider>: " + parser.getName();
2668 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 }
2671 }
2672 return true;
2673 }
2674
2675 private Service parseService(Package owner, Resources res,
2676 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2677 throws XmlPullParserException, IOException {
2678 TypedArray sa = res.obtainAttributes(attrs,
2679 com.android.internal.R.styleable.AndroidManifestService);
2680
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002681 if (mParseServiceArgs == null) {
2682 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2683 com.android.internal.R.styleable.AndroidManifestService_name,
2684 com.android.internal.R.styleable.AndroidManifestService_label,
2685 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002686 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002687 mSeparateProcesses,
2688 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002689 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002690 com.android.internal.R.styleable.AndroidManifestService_enabled);
2691 mParseServiceArgs.tag = "<service>";
2692 }
2693
2694 mParseServiceArgs.sa = sa;
2695 mParseServiceArgs.flags = flags;
2696
2697 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2698 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 sa.recycle();
2700 return null;
2701 }
2702
2703 final boolean setExported = sa.hasValue(
2704 com.android.internal.R.styleable.AndroidManifestService_exported);
2705 if (setExported) {
2706 s.info.exported = sa.getBoolean(
2707 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2708 }
2709
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002710 String str = sa.getNonConfigurationString(
2711 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 if (str == null) {
2713 s.info.permission = owner.applicationInfo.permission;
2714 } else {
2715 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2716 }
2717
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002718 s.info.flags = 0;
2719 if (sa.getBoolean(
2720 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2721 false)) {
2722 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2723 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002724 if (sa.getBoolean(
2725 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2726 false)) {
2727 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2728 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 sa.recycle();
2731
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002732 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002733 // A heavy-weight application can not have services in its main process
2734 // We can do direct compare because we intern all strings.
2735 if (s.info.processName == owner.packageName) {
2736 outError[0] = "Heavy-weight applications can not have services in main process";
2737 return null;
2738 }
2739 }
2740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 int outerDepth = parser.getDepth();
2742 int type;
2743 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2744 && (type != XmlPullParser.END_TAG
2745 || parser.getDepth() > outerDepth)) {
2746 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2747 continue;
2748 }
2749
2750 if (parser.getName().equals("intent-filter")) {
2751 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2752 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2753 return null;
2754 }
2755
2756 s.intents.add(intent);
2757 } else if (parser.getName().equals("meta-data")) {
2758 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2759 outError)) == null) {
2760 return null;
2761 }
2762 } else {
2763 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002764 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002765 + parser.getName() + " at " + mArchiveSourcePath + " "
2766 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 XmlUtils.skipCurrentTag(parser);
2768 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002769 } else {
2770 outError[0] = "Bad element under <service>: " + parser.getName();
2771 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 }
2774 }
2775
2776 if (!setExported) {
2777 s.info.exported = s.intents.size() > 0;
2778 }
2779
2780 return s;
2781 }
2782
2783 private boolean parseAllMetaData(Resources res,
2784 XmlPullParser parser, AttributeSet attrs, String tag,
2785 Component outInfo, String[] outError)
2786 throws XmlPullParserException, IOException {
2787 int outerDepth = parser.getDepth();
2788 int type;
2789 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2790 && (type != XmlPullParser.END_TAG
2791 || parser.getDepth() > outerDepth)) {
2792 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2793 continue;
2794 }
2795
2796 if (parser.getName().equals("meta-data")) {
2797 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2798 outInfo.metaData, outError)) == null) {
2799 return false;
2800 }
2801 } else {
2802 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002803 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002804 + parser.getName() + " at " + mArchiveSourcePath + " "
2805 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 XmlUtils.skipCurrentTag(parser);
2807 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002808 } else {
2809 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2810 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 }
2813 }
2814 return true;
2815 }
2816
2817 private Bundle parseMetaData(Resources res,
2818 XmlPullParser parser, AttributeSet attrs,
2819 Bundle data, String[] outError)
2820 throws XmlPullParserException, IOException {
2821
2822 TypedArray sa = res.obtainAttributes(attrs,
2823 com.android.internal.R.styleable.AndroidManifestMetaData);
2824
2825 if (data == null) {
2826 data = new Bundle();
2827 }
2828
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002829 String name = sa.getNonConfigurationString(
2830 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 if (name == null) {
2832 outError[0] = "<meta-data> requires an android:name attribute";
2833 sa.recycle();
2834 return null;
2835 }
2836
Dianne Hackborn854060a2009-07-09 18:14:31 -07002837 name = name.intern();
2838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 TypedValue v = sa.peekValue(
2840 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2841 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002842 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 data.putInt(name, v.resourceId);
2844 } else {
2845 v = sa.peekValue(
2846 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002847 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 if (v != null) {
2849 if (v.type == TypedValue.TYPE_STRING) {
2850 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002851 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2853 data.putBoolean(name, v.data != 0);
2854 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2855 && v.type <= TypedValue.TYPE_LAST_INT) {
2856 data.putInt(name, v.data);
2857 } else if (v.type == TypedValue.TYPE_FLOAT) {
2858 data.putFloat(name, v.getFloat());
2859 } else {
2860 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002861 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002862 + parser.getName() + " at " + mArchiveSourcePath + " "
2863 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 } else {
2865 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2866 data = null;
2867 }
2868 }
2869 } else {
2870 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2871 data = null;
2872 }
2873 }
2874
2875 sa.recycle();
2876
2877 XmlUtils.skipCurrentTag(parser);
2878
2879 return data;
2880 }
2881
Kenny Root05ca4c92011-09-15 10:36:25 -07002882 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2883 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2884 IOException {
2885 final TypedArray sa = res.obtainAttributes(attrs,
2886 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2887
2888 final String packageName = sa.getNonResourceString(
2889 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2890
2891 final String encodedPublicKey = sa.getNonResourceString(
2892 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2893
2894 sa.recycle();
2895
2896 if (packageName == null || packageName.length() == 0) {
2897 Slog.i(TAG, "verifier package name was null; skipping");
2898 return null;
2899 } else if (encodedPublicKey == null) {
2900 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2901 }
2902
2903 EncodedKeySpec keySpec;
2904 try {
2905 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2906 keySpec = new X509EncodedKeySpec(encoded);
2907 } catch (IllegalArgumentException e) {
2908 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2909 return null;
2910 }
2911
2912 /* First try the key as an RSA key. */
2913 try {
2914 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2915 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2916 return new VerifierInfo(packageName, publicKey);
2917 } catch (NoSuchAlgorithmException e) {
2918 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2919 return null;
2920 } catch (InvalidKeySpecException e) {
2921 // Not a RSA public key.
2922 }
2923
2924 /* Now try it as a DSA key. */
2925 try {
2926 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
2927 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2928 return new VerifierInfo(packageName, publicKey);
2929 } catch (NoSuchAlgorithmException e) {
2930 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
2931 return null;
2932 } catch (InvalidKeySpecException e) {
2933 // Not a DSA public key.
2934 }
2935
2936 return null;
2937 }
2938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 private static final String ANDROID_RESOURCES
2940 = "http://schemas.android.com/apk/res/android";
2941
2942 private boolean parseIntent(Resources res,
2943 XmlPullParser parser, AttributeSet attrs, int flags,
2944 IntentInfo outInfo, String[] outError, boolean isActivity)
2945 throws XmlPullParserException, IOException {
2946
2947 TypedArray sa = res.obtainAttributes(attrs,
2948 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2949
2950 int priority = sa.getInt(
2951 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 TypedValue v = sa.peekValue(
2955 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2956 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2957 outInfo.nonLocalizedLabel = v.coerceToString();
2958 }
2959
2960 outInfo.icon = sa.getResourceId(
2961 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002962
2963 outInfo.logo = sa.getResourceId(
2964 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965
2966 sa.recycle();
2967
2968 int outerDepth = parser.getDepth();
2969 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002970 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2971 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2972 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 continue;
2974 }
2975
2976 String nodeName = parser.getName();
2977 if (nodeName.equals("action")) {
2978 String value = attrs.getAttributeValue(
2979 ANDROID_RESOURCES, "name");
2980 if (value == null || value == "") {
2981 outError[0] = "No value supplied for <android:name>";
2982 return false;
2983 }
2984 XmlUtils.skipCurrentTag(parser);
2985
2986 outInfo.addAction(value);
2987 } else if (nodeName.equals("category")) {
2988 String value = attrs.getAttributeValue(
2989 ANDROID_RESOURCES, "name");
2990 if (value == null || value == "") {
2991 outError[0] = "No value supplied for <android:name>";
2992 return false;
2993 }
2994 XmlUtils.skipCurrentTag(parser);
2995
2996 outInfo.addCategory(value);
2997
2998 } else if (nodeName.equals("data")) {
2999 sa = res.obtainAttributes(attrs,
3000 com.android.internal.R.styleable.AndroidManifestData);
3001
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003002 String str = sa.getNonConfigurationString(
3003 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 if (str != null) {
3005 try {
3006 outInfo.addDataType(str);
3007 } catch (IntentFilter.MalformedMimeTypeException e) {
3008 outError[0] = e.toString();
3009 sa.recycle();
3010 return false;
3011 }
3012 }
3013
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003014 str = sa.getNonConfigurationString(
3015 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 if (str != null) {
3017 outInfo.addDataScheme(str);
3018 }
3019
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003020 String host = sa.getNonConfigurationString(
3021 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3022 String port = sa.getNonConfigurationString(
3023 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 if (host != null) {
3025 outInfo.addDataAuthority(host, port);
3026 }
3027
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003028 str = sa.getNonConfigurationString(
3029 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 if (str != null) {
3031 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3032 }
3033
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003034 str = sa.getNonConfigurationString(
3035 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 if (str != null) {
3037 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3038 }
3039
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003040 str = sa.getNonConfigurationString(
3041 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 if (str != null) {
3043 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3044 }
3045
3046 sa.recycle();
3047 XmlUtils.skipCurrentTag(parser);
3048 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003049 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003050 + parser.getName() + " at " + mArchiveSourcePath + " "
3051 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 XmlUtils.skipCurrentTag(parser);
3053 } else {
3054 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3055 return false;
3056 }
3057 }
3058
3059 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003060
3061 if (DEBUG_PARSER) {
3062 final StringBuilder cats = new StringBuilder("Intent d=");
3063 cats.append(outInfo.hasDefault);
3064 cats.append(", cat=");
3065
3066 final Iterator<String> it = outInfo.categoriesIterator();
3067 if (it != null) {
3068 while (it.hasNext()) {
3069 cats.append(' ');
3070 cats.append(it.next());
3071 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003073 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 }
3075
3076 return true;
3077 }
3078
3079 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003080 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081
3082 // For now we only support one application per package.
3083 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3084
3085 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3086 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3087 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3088 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3089 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3090 public final ArrayList<Service> services = new ArrayList<Service>(0);
3091 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3092
3093 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003094 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095
Dianne Hackborn854060a2009-07-09 18:14:31 -07003096 public ArrayList<String> protectedBroadcasts;
3097
Dianne Hackborn49237342009-08-27 20:08:01 -07003098 public ArrayList<String> usesLibraries = null;
3099 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 public String[] usesLibraryFiles = null;
3101
Dianne Hackbornc1552392010-03-03 16:19:01 -08003102 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003103 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003104 public ArrayList<String> mAdoptPermissions = null;
3105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 // We store the application meta-data independently to avoid multiple unwanted references
3107 public Bundle mAppMetaData = null;
3108
3109 // If this is a 3rd party app, this is the path of the zip file.
3110 public String mPath;
3111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 // The version code declared for this package.
3113 public int mVersionCode;
3114
3115 // The version name declared for this package.
3116 public String mVersionName;
3117
3118 // The shared user id that this package wants to use.
3119 public String mSharedUserId;
3120
3121 // The shared user label that this package wants to use.
3122 public int mSharedUserLabel;
3123
3124 // Signatures that were read from the package.
3125 public Signature mSignatures[];
3126
3127 // For use by package manager service for quick lookup of
3128 // preferred up order.
3129 public int mPreferredOrder = 0;
3130
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003131 // For use by the package manager to keep track of the path to the
3132 // file an app came from.
3133 public String mScanPath;
3134
3135 // For use by package manager to keep track of where it has done dexopt.
3136 public boolean mDidDexOpt;
3137
Amith Yamasani13593602012-03-22 16:16:17 -07003138 // // User set enabled state.
3139 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3140 //
3141 // // Whether the package has been stopped.
3142 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 // Additional data supplied by callers.
3145 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003146
3147 // Whether an operation is currently pending on this package
3148 public boolean mOperationPending;
3149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 /*
3151 * Applications hardware preferences
3152 */
3153 public final ArrayList<ConfigurationInfo> configPreferences =
3154 new ArrayList<ConfigurationInfo>();
3155
Dianne Hackborn49237342009-08-27 20:08:01 -07003156 /*
3157 * Applications requested features
3158 */
3159 public ArrayList<FeatureInfo> reqFeatures = null;
3160
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003161 public int installLocation;
3162
Kenny Rootbcc954d2011-08-08 16:19:08 -07003163 /**
3164 * Digest suitable for comparing whether this package's manifest is the
3165 * same as another.
3166 */
3167 public ManifestDigest manifestDigest;
3168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 public Package(String _name) {
3170 packageName = _name;
3171 applicationInfo.packageName = _name;
3172 applicationInfo.uid = -1;
3173 }
3174
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003175 public void setPackageName(String newName) {
3176 packageName = newName;
3177 applicationInfo.packageName = newName;
3178 for (int i=permissions.size()-1; i>=0; i--) {
3179 permissions.get(i).setPackageName(newName);
3180 }
3181 for (int i=permissionGroups.size()-1; i>=0; i--) {
3182 permissionGroups.get(i).setPackageName(newName);
3183 }
3184 for (int i=activities.size()-1; i>=0; i--) {
3185 activities.get(i).setPackageName(newName);
3186 }
3187 for (int i=receivers.size()-1; i>=0; i--) {
3188 receivers.get(i).setPackageName(newName);
3189 }
3190 for (int i=providers.size()-1; i>=0; i--) {
3191 providers.get(i).setPackageName(newName);
3192 }
3193 for (int i=services.size()-1; i>=0; i--) {
3194 services.get(i).setPackageName(newName);
3195 }
3196 for (int i=instrumentation.size()-1; i>=0; i--) {
3197 instrumentation.get(i).setPackageName(newName);
3198 }
3199 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003200
3201 public boolean hasComponentClassName(String name) {
3202 for (int i=activities.size()-1; i>=0; i--) {
3203 if (name.equals(activities.get(i).className)) {
3204 return true;
3205 }
3206 }
3207 for (int i=receivers.size()-1; i>=0; i--) {
3208 if (name.equals(receivers.get(i).className)) {
3209 return true;
3210 }
3211 }
3212 for (int i=providers.size()-1; i>=0; i--) {
3213 if (name.equals(providers.get(i).className)) {
3214 return true;
3215 }
3216 }
3217 for (int i=services.size()-1; i>=0; i--) {
3218 if (name.equals(services.get(i).className)) {
3219 return true;
3220 }
3221 }
3222 for (int i=instrumentation.size()-1; i>=0; i--) {
3223 if (name.equals(instrumentation.get(i).className)) {
3224 return true;
3225 }
3226 }
3227 return false;
3228 }
3229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 public String toString() {
3231 return "Package{"
3232 + Integer.toHexString(System.identityHashCode(this))
3233 + " " + packageName + "}";
3234 }
3235 }
3236
3237 public static class Component<II extends IntentInfo> {
3238 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003239 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003240 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241 public Bundle metaData;
3242
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003243 ComponentName componentName;
3244 String componentShortName;
3245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 public Component(Package _owner) {
3247 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003248 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003249 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003250 }
3251
3252 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3253 owner = args.owner;
3254 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003255 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003256 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003257 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003258 args.outError[0] = args.tag + " does not specify android:name";
3259 return;
3260 }
3261
3262 outInfo.name
3263 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3264 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003265 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003266 args.outError[0] = args.tag + " does not have valid android:name";
3267 return;
3268 }
3269
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003270 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003271
3272 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3273 if (iconVal != 0) {
3274 outInfo.icon = iconVal;
3275 outInfo.nonLocalizedLabel = null;
3276 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003277
3278 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3279 if (logoVal != 0) {
3280 outInfo.logo = logoVal;
3281 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003282
3283 TypedValue v = args.sa.peekValue(args.labelRes);
3284 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3285 outInfo.nonLocalizedLabel = v.coerceToString();
3286 }
3287
3288 outInfo.packageName = owner.packageName;
3289 }
3290
3291 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3292 this(args, (PackageItemInfo)outInfo);
3293 if (args.outError[0] != null) {
3294 return;
3295 }
3296
3297 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003298 CharSequence pname;
3299 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3300 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3301 } else {
3302 // Some older apps have been seen to use a resource reference
3303 // here that on older builds was ignored (with a warning). We
3304 // need to continue to do this for them so they don't break.
3305 pname = args.sa.getNonResourceString(args.processRes);
3306 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003307 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003308 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003309 args.flags, args.sepProcesses, args.outError);
3310 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003311
3312 if (args.descriptionRes != 0) {
3313 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3314 }
3315
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003316 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 }
3318
3319 public Component(Component<II> clone) {
3320 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003321 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003322 className = clone.className;
3323 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003324 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003325 }
3326
3327 public ComponentName getComponentName() {
3328 if (componentName != null) {
3329 return componentName;
3330 }
3331 if (className != null) {
3332 componentName = new ComponentName(owner.applicationInfo.packageName,
3333 className);
3334 }
3335 return componentName;
3336 }
3337
3338 public String getComponentShortName() {
3339 if (componentShortName != null) {
3340 return componentShortName;
3341 }
3342 ComponentName component = getComponentName();
3343 if (component != null) {
3344 componentShortName = component.flattenToShortString();
3345 }
3346 return componentShortName;
3347 }
3348
3349 public void setPackageName(String packageName) {
3350 componentName = null;
3351 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 }
3353 }
3354
3355 public final static class Permission extends Component<IntentInfo> {
3356 public final PermissionInfo info;
3357 public boolean tree;
3358 public PermissionGroup group;
3359
3360 public Permission(Package _owner) {
3361 super(_owner);
3362 info = new PermissionInfo();
3363 }
3364
3365 public Permission(Package _owner, PermissionInfo _info) {
3366 super(_owner);
3367 info = _info;
3368 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003369
3370 public void setPackageName(String packageName) {
3371 super.setPackageName(packageName);
3372 info.packageName = packageName;
3373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374
3375 public String toString() {
3376 return "Permission{"
3377 + Integer.toHexString(System.identityHashCode(this))
3378 + " " + info.name + "}";
3379 }
3380 }
3381
3382 public final static class PermissionGroup extends Component<IntentInfo> {
3383 public final PermissionGroupInfo info;
3384
3385 public PermissionGroup(Package _owner) {
3386 super(_owner);
3387 info = new PermissionGroupInfo();
3388 }
3389
3390 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3391 super(_owner);
3392 info = _info;
3393 }
3394
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003395 public void setPackageName(String packageName) {
3396 super.setPackageName(packageName);
3397 info.packageName = packageName;
3398 }
3399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 public String toString() {
3401 return "PermissionGroup{"
3402 + Integer.toHexString(System.identityHashCode(this))
3403 + " " + info.name + "}";
3404 }
3405 }
3406
Amith Yamasani13593602012-03-22 16:16:17 -07003407 private static boolean copyNeeded(int flags, Package p, int enabledState, Bundle metaData) {
3408 if (enabledState != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3409 boolean enabled = enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003410 if (p.applicationInfo.enabled != enabled) {
3411 return true;
3412 }
3413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 if ((flags & PackageManager.GET_META_DATA) != 0
3415 && (metaData != null || p.mAppMetaData != null)) {
3416 return true;
3417 }
3418 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3419 && p.usesLibraryFiles != null) {
3420 return true;
3421 }
3422 return false;
3423 }
3424
Amith Yamasani13593602012-03-22 16:16:17 -07003425 public static ApplicationInfo generateApplicationInfo(Package p, int flags, boolean stopped,
3426 int enabledState) {
3427 return generateApplicationInfo(p, flags, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003428 }
3429
Amith Yamasani13593602012-03-22 16:16:17 -07003430 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3431 boolean stopped, int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003433 if (!copyNeeded(flags, p, enabledState, null) && userId == 0) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003434 // CompatibilityMode is global state. It's safe to modify the instance
3435 // of the package.
3436 if (!sCompatibilityModeEnabled) {
3437 p.applicationInfo.disableCompatibilityMode();
3438 }
Amith Yamasani13593602012-03-22 16:16:17 -07003439 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003440 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3441 } else {
3442 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3443 }
Amith Yamasani13593602012-03-22 16:16:17 -07003444 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003445 p.applicationInfo.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003446 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3447 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003448 p.applicationInfo.enabled = false;
3449 }
Amith Yamasani13593602012-03-22 16:16:17 -07003450 p.applicationInfo.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 return p.applicationInfo;
3452 }
3453
3454 // Make shallow copy so we can store the metadata/libraries safely
3455 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003456 if (userId != 0) {
3457 ai.uid = UserId.getUid(userId, ai.uid);
3458 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 if ((flags & PackageManager.GET_META_DATA) != 0) {
3461 ai.metaData = p.mAppMetaData;
3462 }
3463 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3464 ai.sharedLibraryFiles = p.usesLibraryFiles;
3465 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003466 if (!sCompatibilityModeEnabled) {
3467 ai.disableCompatibilityMode();
3468 }
Amith Yamasani13593602012-03-22 16:16:17 -07003469 if (stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003470 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003471 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003472 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003473 }
Amith Yamasani13593602012-03-22 16:16:17 -07003474 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003475 ai.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003476 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3477 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003478 ai.enabled = false;
3479 }
Amith Yamasani13593602012-03-22 16:16:17 -07003480 ai.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 return ai;
3482 }
3483
3484 public static final PermissionInfo generatePermissionInfo(
3485 Permission p, int flags) {
3486 if (p == null) return null;
3487 if ((flags&PackageManager.GET_META_DATA) == 0) {
3488 return p.info;
3489 }
3490 PermissionInfo pi = new PermissionInfo(p.info);
3491 pi.metaData = p.metaData;
3492 return pi;
3493 }
3494
3495 public static final PermissionGroupInfo generatePermissionGroupInfo(
3496 PermissionGroup pg, int flags) {
3497 if (pg == null) return null;
3498 if ((flags&PackageManager.GET_META_DATA) == 0) {
3499 return pg.info;
3500 }
3501 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3502 pgi.metaData = pg.metaData;
3503 return pgi;
3504 }
3505
3506 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003507 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003509 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3510 super(args, _info);
3511 info = _info;
3512 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003514
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003515 public void setPackageName(String packageName) {
3516 super.setPackageName(packageName);
3517 info.packageName = packageName;
3518 }
3519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 public String toString() {
3521 return "Activity{"
3522 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003523 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 }
3525 }
3526
Amith Yamasani13593602012-03-22 16:16:17 -07003527 public static final ActivityInfo generateActivityInfo(Activity a, int flags, boolean stopped,
3528 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 if (a == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003530 if (!copyNeeded(flags, a.owner, enabledState, a.metaData) && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 return a.info;
3532 }
3533 // Make shallow copies so we can store the metadata safely
3534 ActivityInfo ai = new ActivityInfo(a.info);
3535 ai.metaData = a.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003536 ai.applicationInfo = generateApplicationInfo(a.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 return ai;
3538 }
3539
3540 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003541 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003543 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3544 super(args, _info);
3545 info = _info;
3546 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003548
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003549 public void setPackageName(String packageName) {
3550 super.setPackageName(packageName);
3551 info.packageName = packageName;
3552 }
3553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 public String toString() {
3555 return "Service{"
3556 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003557 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 }
3559 }
3560
Amith Yamasani13593602012-03-22 16:16:17 -07003561 public static final ServiceInfo generateServiceInfo(Service s, int flags, boolean stopped,
3562 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 if (s == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003564 if (!copyNeeded(flags, s.owner, enabledState, s.metaData)
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003565 && userId == UserId.getUserId(s.info.applicationInfo.uid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 return s.info;
3567 }
3568 // Make shallow copies so we can store the metadata safely
3569 ServiceInfo si = new ServiceInfo(s.info);
3570 si.metaData = s.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003571 si.applicationInfo = generateApplicationInfo(s.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 return si;
3573 }
3574
3575 public final static class Provider extends Component {
3576 public final ProviderInfo info;
3577 public boolean syncable;
3578
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003579 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3580 super(args, _info);
3581 info = _info;
3582 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 syncable = false;
3584 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 public Provider(Provider existingProvider) {
3587 super(existingProvider);
3588 this.info = existingProvider.info;
3589 this.syncable = existingProvider.syncable;
3590 }
3591
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003592 public void setPackageName(String packageName) {
3593 super.setPackageName(packageName);
3594 info.packageName = packageName;
3595 }
3596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 public String toString() {
3598 return "Provider{"
3599 + Integer.toHexString(System.identityHashCode(this))
3600 + " " + info.name + "}";
3601 }
3602 }
3603
Amith Yamasani13593602012-03-22 16:16:17 -07003604 public static final ProviderInfo generateProviderInfo(Provider p, int flags, boolean stopped,
3605 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003607 if (!copyNeeded(flags, p.owner, enabledState, p.metaData)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Amith Yamasani742a6712011-05-04 14:49:28 -07003609 || p.info.uriPermissionPatterns == null)
3610 && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return p.info;
3612 }
3613 // Make shallow copies so we can store the metadata safely
3614 ProviderInfo pi = new ProviderInfo(p.info);
3615 pi.metaData = p.metaData;
3616 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3617 pi.uriPermissionPatterns = null;
3618 }
Amith Yamasani13593602012-03-22 16:16:17 -07003619 pi.applicationInfo = generateApplicationInfo(p.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 return pi;
3621 }
3622
3623 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003624 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003626 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3627 super(args, _info);
3628 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003630
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003631 public void setPackageName(String packageName) {
3632 super.setPackageName(packageName);
3633 info.packageName = packageName;
3634 }
3635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 public String toString() {
3637 return "Instrumentation{"
3638 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003639 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 }
3641 }
3642
3643 public static final InstrumentationInfo generateInstrumentationInfo(
3644 Instrumentation i, int flags) {
3645 if (i == null) return null;
3646 if ((flags&PackageManager.GET_META_DATA) == 0) {
3647 return i.info;
3648 }
3649 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3650 ii.metaData = i.metaData;
3651 return ii;
3652 }
3653
3654 public static class IntentInfo extends IntentFilter {
3655 public boolean hasDefault;
3656 public int labelRes;
3657 public CharSequence nonLocalizedLabel;
3658 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003659 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 }
3661
3662 public final static class ActivityIntentInfo extends IntentInfo {
3663 public final Activity activity;
3664
3665 public ActivityIntentInfo(Activity _activity) {
3666 activity = _activity;
3667 }
3668
3669 public String toString() {
3670 return "ActivityIntentInfo{"
3671 + Integer.toHexString(System.identityHashCode(this))
3672 + " " + activity.info.name + "}";
3673 }
3674 }
3675
3676 public final static class ServiceIntentInfo extends IntentInfo {
3677 public final Service service;
3678
3679 public ServiceIntentInfo(Service _service) {
3680 service = _service;
3681 }
3682
3683 public String toString() {
3684 return "ServiceIntentInfo{"
3685 + Integer.toHexString(System.identityHashCode(this))
3686 + " " + service.info.name + "}";
3687 }
3688 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003689
3690 /**
3691 * @hide
3692 */
3693 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3694 sCompatibilityModeEnabled = compatibilityModeEnabled;
3695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696}