blob: ad52e13873b0e7d26869b0e0597dd7e167f4e283 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IntentFilter;
22import android.content.res.AssetManager;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.content.res.XmlResourceParser;
Amith Yamasani742a6712011-05-04 14:49:28 -070027import android.os.Binder;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070028import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Bundle;
30import android.os.PatternMatcher;
Amith Yamasani742a6712011-05-04 14:49:28 -070031import android.os.UserId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070033import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070035import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070036import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kenny Rootd63f7db2010-09-27 08:07:48 -070039import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Kenny Rootbcc954d2011-08-08 16:19:08 -070057import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.jar.JarEntry;
59import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070060import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Amith Yamasani742a6712011-05-04 14:49:28 -070062import com.android.internal.util.XmlUtils;
63
64import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
68 * Package archive parsing
69 *
70 * {@hide}
71 */
72public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070073 private static final boolean DEBUG_JAR = false;
74 private static final boolean DEBUG_PARSER = false;
75 private static final boolean DEBUG_BACKUP = false;
76
Kenny Rootbcc954d2011-08-08 16:19:08 -070077 /** File name in an APK for the Android manifest. */
78 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
79
Dianne Hackborna96cbb42009-05-13 15:06:13 -070080 /** @hide */
81 public static class NewPermissionInfo {
82 public final String name;
83 public final int sdkVersion;
84 public final int fileVersion;
85
86 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
87 this.name = name;
88 this.sdkVersion = sdkVersion;
89 this.fileVersion = fileVersion;
90 }
91 }
Dianne Hackborn79245122012-03-12 10:51:26 -070092
93 /** @hide */
94 public static class SplitPermissionInfo {
95 public final String rootPerm;
96 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070098
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700100 this.rootPerm = rootPerm;
101 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700102 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700103 }
104 }
105
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700106 /**
107 * List of new permissions that have been added since 1.0.
108 * NOTE: These must be declared in SDK version order, with permissions
109 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700110 * If sdkVersion is 0, then this is not a permission that we want to
111 * automatically add to older apps, but we do want to allow it to be
112 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700113 * @hide
114 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700115 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
116 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700117 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700118 android.os.Build.VERSION_CODES.DONUT, 0),
119 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
120 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700121 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Dianne Hackborn79245122012-03-12 10:51:26 -0700123 /**
124 * List of permissions that have been split into more granular or dependent
125 * permissions.
126 * @hide
127 */
128 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
129 new PackageParser.SplitPermissionInfo[] {
130 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700131 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
132 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
133 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
134 new String[] { android.Manifest.permission.READ_CALL_LOG },
135 android.os.Build.VERSION_CODES.JELLY_BEAN),
136 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
137 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
138 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700139 };
140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 private String mArchiveSourcePath;
142 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700143 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700144 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
145 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
146 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147
148 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
149
150 private static final Object mSync = new Object();
151 private static WeakReference<byte[]> mReadBuffer;
152
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700153 private static boolean sCompatibilityModeEnabled = true;
154 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700155
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700156 static class ParsePackageItemArgs {
157 final Package owner;
158 final String[] outError;
159 final int nameRes;
160 final int labelRes;
161 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700162 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700163
164 String tag;
165 TypedArray sa;
166
167 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700168 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700169 owner = _owner;
170 outError = _outError;
171 nameRes = _nameRes;
172 labelRes = _labelRes;
173 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700174 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700175 }
176 }
177
178 static class ParseComponentArgs extends ParsePackageItemArgs {
179 final String[] sepProcesses;
180 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800181 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700182 final int enabledRes;
183 int flags;
184
185 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700186 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800187 String[] _sepProcesses, int _processRes,
188 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700189 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700190 sepProcesses = _sepProcesses;
191 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800192 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700193 enabledRes = _enabledRes;
194 }
195 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800196
197 /* Light weight package info.
198 * @hide
199 */
200 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700201 public final String packageName;
202 public final int installLocation;
203 public final VerifierInfo[] verifiers;
204
205 public PackageLite(String packageName, int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800206 this.packageName = packageName;
207 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700208 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800209 }
210 }
211
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700212 private ParsePackageItemArgs mParseInstrumentationArgs;
213 private ParseComponentArgs mParseActivityArgs;
214 private ParseComponentArgs mParseActivityAliasArgs;
215 private ParseComponentArgs mParseServiceArgs;
216 private ParseComponentArgs mParseProviderArgs;
217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 /** If set to true, we will only allow package files that exactly match
219 * the DTD. Otherwise, we try to get as much from the package as we
220 * can without failing. This should normally be set to false, to
221 * support extensions to the DTD in future versions. */
222 private static final boolean RIGID_PARSER = false;
223
224 private static final String TAG = "PackageParser";
225
226 public PackageParser(String archiveSourcePath) {
227 mArchiveSourcePath = archiveSourcePath;
228 }
229
230 public void setSeparateProcesses(String[] procs) {
231 mSeparateProcesses = procs;
232 }
233
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700234 public void setOnlyCoreApps(boolean onlyCoreApps) {
235 mOnlyCoreApps = onlyCoreApps;
236 }
237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 private static final boolean isPackageFilename(String name) {
239 return name.endsWith(".apk");
240 }
241
Amith Yamasani13593602012-03-22 16:16:17 -0700242 public static PackageInfo generatePackageInfo(PackageParser.Package p,
243 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
244 HashSet<String> grantedPermissions) {
245
246 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
247 grantedPermissions, false, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
248 UserId.getCallingUserId());
249 }
250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 /**
252 * Generate and return the {@link PackageInfo} for a parsed package.
253 *
254 * @param p the parsed package.
255 * @param flags indicating which optional information is included.
256 */
257 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800258 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700259 HashSet<String> grantedPermissions, boolean stopped, int enabledState) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260
Amith Yamasani483f3b02012-03-13 16:08:00 -0700261 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700262 grantedPermissions, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani483f3b02012-03-13 16:08:00 -0700263 }
264
Amith Yamasani13593602012-03-22 16:16:17 -0700265 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700266 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700267 HashSet<String> grantedPermissions, boolean stopped, int enabledState, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 PackageInfo pi = new PackageInfo();
270 pi.packageName = p.packageName;
271 pi.versionCode = p.mVersionCode;
272 pi.versionName = p.mVersionName;
273 pi.sharedUserId = p.mSharedUserId;
274 pi.sharedUserLabel = p.mSharedUserLabel;
Amith Yamasani13593602012-03-22 16:16:17 -0700275 pi.applicationInfo = generateApplicationInfo(p, flags, stopped, enabledState, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800276 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700277 pi.firstInstallTime = firstInstallTime;
278 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 if ((flags&PackageManager.GET_GIDS) != 0) {
280 pi.gids = gids;
281 }
282 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
283 int N = p.configPreferences.size();
284 if (N > 0) {
285 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700286 p.configPreferences.toArray(pi.configPreferences);
287 }
288 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
289 if (N > 0) {
290 pi.reqFeatures = new FeatureInfo[N];
291 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 }
293 }
294 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
295 int N = p.activities.size();
296 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700297 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
298 pi.activities = new ActivityInfo[N];
299 } else {
300 int num = 0;
301 for (int i=0; i<N; i++) {
302 if (p.activities.get(i).info.enabled) num++;
303 }
304 pi.activities = new ActivityInfo[num];
305 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700306 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 final Activity activity = p.activities.get(i);
308 if (activity.info.enabled
309 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700310 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Amith Yamasani13593602012-03-22 16:16:17 -0700311 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313 }
314 }
315 }
316 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
317 int N = p.receivers.size();
318 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700319 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
320 pi.receivers = new ActivityInfo[N];
321 } else {
322 int num = 0;
323 for (int i=0; i<N; i++) {
324 if (p.receivers.get(i).info.enabled) num++;
325 }
326 pi.receivers = new ActivityInfo[num];
327 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700328 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 final Activity activity = p.receivers.get(i);
330 if (activity.info.enabled
331 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700332 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
333 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
335 }
336 }
337 }
338 if ((flags&PackageManager.GET_SERVICES) != 0) {
339 int N = p.services.size();
340 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700341 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
342 pi.services = new ServiceInfo[N];
343 } else {
344 int num = 0;
345 for (int i=0; i<N; i++) {
346 if (p.services.get(i).info.enabled) num++;
347 }
348 pi.services = new ServiceInfo[num];
349 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700350 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 final Service service = p.services.get(i);
352 if (service.info.enabled
353 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700354 pi.services[j++] = generateServiceInfo(p.services.get(i), flags, stopped,
355 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 }
357 }
358 }
359 }
360 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
361 int N = p.providers.size();
362 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700363 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
364 pi.providers = new ProviderInfo[N];
365 } else {
366 int num = 0;
367 for (int i=0; i<N; i++) {
368 if (p.providers.get(i).info.enabled) num++;
369 }
370 pi.providers = new ProviderInfo[num];
371 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700372 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 final Provider provider = p.providers.get(i);
374 if (provider.info.enabled
375 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700376 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, stopped,
377 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379 }
380 }
381 }
382 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
383 int N = p.instrumentation.size();
384 if (N > 0) {
385 pi.instrumentation = new InstrumentationInfo[N];
386 for (int i=0; i<N; i++) {
387 pi.instrumentation[i] = generateInstrumentationInfo(
388 p.instrumentation.get(i), flags);
389 }
390 }
391 }
392 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
393 int N = p.permissions.size();
394 if (N > 0) {
395 pi.permissions = new PermissionInfo[N];
396 for (int i=0; i<N; i++) {
397 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
398 }
399 }
400 N = p.requestedPermissions.size();
401 if (N > 0) {
402 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800403 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800405 final String perm = p.requestedPermissions.get(i);
406 pi.requestedPermissions[i] = perm;
407 if (p.requestedPermissionsRequired.get(i)) {
408 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
409 }
410 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
411 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414 }
415 }
416 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700417 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
418 if (N > 0) {
419 pi.signatures = new Signature[N];
420 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 }
422 }
423 return pi;
424 }
425
426 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
427 byte[] readBuffer) {
428 try {
429 // We must read the stream for the JarEntry to retrieve
430 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700431 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
433 // not using
434 }
435 is.close();
436 return je != null ? je.getCertificates() : null;
437 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700438 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700440 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700441 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700442 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
444 return null;
445 }
446
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800447 public final static int PARSE_IS_SYSTEM = 1<<0;
448 public final static int PARSE_CHATTY = 1<<1;
449 public final static int PARSE_MUST_BE_APK = 1<<2;
450 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
451 public final static int PARSE_FORWARD_LOCK = 1<<4;
452 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700453 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454
455 public int getParseError() {
456 return mParseError;
457 }
458
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800459 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 DisplayMetrics metrics, int flags) {
461 mParseError = PackageManager.INSTALL_SUCCEEDED;
462
463 mArchiveSourcePath = sourceFile.getPath();
464 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700465 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
467 return null;
468 }
469 if (!isPackageFilename(sourceFile.getName())
470 && (flags&PARSE_MUST_BE_APK) != 0) {
471 if ((flags&PARSE_IS_SYSTEM) == 0) {
472 // We expect to have non-.apk files in the system dir,
473 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700474 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 }
476 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
477 return null;
478 }
479
Kenny Rootd2d29252011-08-08 11:27:57 -0700480 if (DEBUG_JAR)
481 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482
483 XmlResourceParser parser = null;
484 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800485 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 boolean assetError = true;
487 try {
488 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700489 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800490 if (cookie != 0) {
491 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700492 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800493 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700494 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 assetError = false;
496 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700497 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700500 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 + mArchiveSourcePath, e);
502 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800503 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 if (assmgr != null) assmgr.close();
505 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
506 return null;
507 }
508 String[] errorText = new String[1];
509 Package pkg = null;
510 Exception errorException = null;
511 try {
512 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 pkg = parsePackage(res, parser, flags, errorText);
514 } catch (Exception e) {
515 errorException = e;
516 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
517 }
518
519
520 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700521 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
522 // just means to skip this app so don't make a fuss about it.
523 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
524 if (errorException != null) {
525 Slog.w(TAG, mArchiveSourcePath, errorException);
526 } else {
527 Slog.w(TAG, mArchiveSourcePath + " (at "
528 + parser.getPositionDescription()
529 + "): " + errorText[0]);
530 }
531 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
532 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 }
535 parser.close();
536 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 return null;
538 }
539
540 parser.close();
541 assmgr.close();
542
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800543 // Set code and resource paths
544 pkg.mPath = destCodePath;
545 pkg.mScanPath = mArchiveSourcePath;
546 //pkg.applicationInfo.sourceDir = destCodePath;
547 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 pkg.mSignatures = null;
549
550 return pkg;
551 }
552
553 public boolean collectCertificates(Package pkg, int flags) {
554 pkg.mSignatures = null;
555
556 WeakReference<byte[]> readBufferRef;
557 byte[] readBuffer = null;
558 synchronized (mSync) {
559 readBufferRef = mReadBuffer;
560 if (readBufferRef != null) {
561 mReadBuffer = null;
562 readBuffer = readBufferRef.get();
563 }
564 if (readBuffer == null) {
565 readBuffer = new byte[8192];
566 readBufferRef = new WeakReference<byte[]>(readBuffer);
567 }
568 }
569
570 try {
571 JarFile jarFile = new JarFile(mArchiveSourcePath);
572
573 Certificate[] certs = null;
574
575 if ((flags&PARSE_IS_SYSTEM) != 0) {
576 // If this package comes from the system image, then we
577 // can trust it... we'll just use the AndroidManifest.xml
578 // to retrieve its signatures, not validating all of the
579 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700580 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 certs = loadCertificates(jarFile, jarEntry, readBuffer);
582 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700583 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 + " has no certificates at entry "
585 + jarEntry.getName() + "; ignoring!");
586 jarFile.close();
587 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
588 return false;
589 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700590 if (DEBUG_JAR) {
591 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 + " certs=" + (certs != null ? certs.length : 0));
593 if (certs != null) {
594 final int N = certs.length;
595 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700596 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 + certs[i].getPublicKey().getEncoded()
598 + " " + certs[i].getPublicKey());
599 }
600 }
601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700603 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700604 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700606 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700608
Kenny Rootbcc954d2011-08-08 16:19:08 -0700609 final String name = je.getName();
610
611 if (name.startsWith("META-INF/"))
612 continue;
613
614 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
615 final Attributes attributes = manifest.getAttributes(name);
616 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
617 }
618
619 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700620 if (DEBUG_JAR) {
621 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 + ": certs=" + certs + " ("
623 + (certs != null ? certs.length : 0) + ")");
624 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700627 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 + " has no certificates at entry "
629 + je.getName() + "; ignoring!");
630 jarFile.close();
631 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
632 return false;
633 } else if (certs == null) {
634 certs = localCerts;
635 } else {
636 // Ensure all certificates match.
637 for (int i=0; i<certs.length; i++) {
638 boolean found = false;
639 for (int j=0; j<localCerts.length; j++) {
640 if (certs[i] != null &&
641 certs[i].equals(localCerts[j])) {
642 found = true;
643 break;
644 }
645 }
646 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700647 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 + " has mismatched certificates at entry "
649 + je.getName() + "; ignoring!");
650 jarFile.close();
651 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
652 return false;
653 }
654 }
655 }
656 }
657 }
658 jarFile.close();
659
660 synchronized (mSync) {
661 mReadBuffer = readBufferRef;
662 }
663
664 if (certs != null && certs.length > 0) {
665 final int N = certs.length;
666 pkg.mSignatures = new Signature[certs.length];
667 for (int i=0; i<N; i++) {
668 pkg.mSignatures[i] = new Signature(
669 certs[i].getEncoded());
670 }
671 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700672 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 + " has no certificates; ignoring!");
674 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
675 return false;
676 }
677 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700678 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
680 return false;
681 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700682 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
684 return false;
685 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700686 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
688 return false;
689 }
690
691 return true;
692 }
693
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800694 /*
695 * Utility method that retrieves just the package name and install
696 * location from the apk location at the given file path.
697 * @param packageFilePath file location of the apk
698 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700699 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800700 */
701 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700703 final XmlResourceParser parser;
704 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 try {
706 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700707 assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800708 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700711 if (cookie == 0) {
712 return null;
713 }
714
Kenny Root05ca4c92011-09-15 10:36:25 -0700715 final DisplayMetrics metrics = new DisplayMetrics();
716 metrics.setToDefaults();
717 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700718 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 } catch (Exception e) {
720 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700721 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 + packageFilePath, e);
723 return null;
724 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700725
726 final AttributeSet attrs = parser;
727 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800728 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700730 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700732 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700734 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 } finally {
736 if (parser != null) parser.close();
737 if (assmgr != null) assmgr.close();
738 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800739 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700740 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 return null;
742 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800743 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745
746 private static String validateName(String name, boolean requiresSeparator) {
747 final int N = name.length();
748 boolean hasSep = false;
749 boolean front = true;
750 for (int i=0; i<N; i++) {
751 final char c = name.charAt(i);
752 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
753 front = false;
754 continue;
755 }
756 if (!front) {
757 if ((c >= '0' && c <= '9') || c == '_') {
758 continue;
759 }
760 }
761 if (c == '.') {
762 hasSep = true;
763 front = true;
764 continue;
765 }
766 return "bad character '" + c + "'";
767 }
768 return hasSep || !requiresSeparator
769 ? null : "must have at least one '.' separator";
770 }
771
772 private static String parsePackageName(XmlPullParser parser,
773 AttributeSet attrs, int flags, String[] outError)
774 throws IOException, XmlPullParserException {
775
776 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700777 while ((type = parser.next()) != XmlPullParser.START_TAG
778 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 ;
780 }
781
Kenny Rootd2d29252011-08-08 11:27:57 -0700782 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 outError[0] = "No start tag found";
784 return null;
785 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700786 if (DEBUG_PARSER)
787 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 if (!parser.getName().equals("manifest")) {
789 outError[0] = "No <manifest> tag";
790 return null;
791 }
792 String pkgName = attrs.getAttributeValue(null, "package");
793 if (pkgName == null || pkgName.length() == 0) {
794 outError[0] = "<manifest> does not specify package";
795 return null;
796 }
797 String nameError = validateName(pkgName, true);
798 if (nameError != null && !"android".equals(pkgName)) {
799 outError[0] = "<manifest> specifies bad package name \""
800 + pkgName + "\": " + nameError;
801 return null;
802 }
803
804 return pkgName.intern();
805 }
806
Kenny Root05ca4c92011-09-15 10:36:25 -0700807 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
808 AttributeSet attrs, int flags, String[] outError) throws IOException,
809 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800810
811 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700812 while ((type = parser.next()) != XmlPullParser.START_TAG
813 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800814 ;
815 }
816
Kenny Rootd2d29252011-08-08 11:27:57 -0700817 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800818 outError[0] = "No start tag found";
819 return null;
820 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700821 if (DEBUG_PARSER)
822 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800823 if (!parser.getName().equals("manifest")) {
824 outError[0] = "No <manifest> tag";
825 return null;
826 }
827 String pkgName = attrs.getAttributeValue(null, "package");
828 if (pkgName == null || pkgName.length() == 0) {
829 outError[0] = "<manifest> does not specify package";
830 return null;
831 }
832 String nameError = validateName(pkgName, true);
833 if (nameError != null && !"android".equals(pkgName)) {
834 outError[0] = "<manifest> specifies bad package name \""
835 + pkgName + "\": " + nameError;
836 return null;
837 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700838 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800839 for (int i = 0; i < attrs.getAttributeCount(); i++) {
840 String attr = attrs.getAttributeName(i);
841 if (attr.equals("installLocation")) {
842 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700843 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800844 break;
845 }
846 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700847
848 // Only search the tree when the tag is directly below <manifest>
849 final int searchDepth = parser.getDepth() + 1;
850
851 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
852 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
853 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
854 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
855 continue;
856 }
857
858 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
859 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
860 if (verifier != null) {
861 verifiers.add(verifier);
862 }
863 }
864 }
865
866 return new PackageLite(pkgName.intern(), installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800867 }
868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 /**
870 * Temporary.
871 */
872 static public Signature stringToSignature(String str) {
873 final int N = str.length();
874 byte[] sig = new byte[N];
875 for (int i=0; i<N; i++) {
876 sig[i] = (byte)str.charAt(i);
877 }
878 return new Signature(sig);
879 }
880
881 private Package parsePackage(
882 Resources res, XmlResourceParser parser, int flags, String[] outError)
883 throws XmlPullParserException, IOException {
884 AttributeSet attrs = parser;
885
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700886 mParseInstrumentationArgs = null;
887 mParseActivityArgs = null;
888 mParseServiceArgs = null;
889 mParseProviderArgs = null;
890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 String pkgName = parsePackageName(parser, attrs, flags, outError);
892 if (pkgName == null) {
893 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
894 return null;
895 }
896 int type;
897
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700898 if (mOnlyCoreApps) {
899 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
900 if (!core) {
901 mParseError = PackageManager.INSTALL_SUCCEEDED;
902 return null;
903 }
904 }
905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 TypedArray sa = res.obtainAttributes(attrs,
910 com.android.internal.R.styleable.AndroidManifest);
911 pkg.mVersionCode = sa.getInteger(
912 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800913 pkg.mVersionName = sa.getNonConfigurationString(
914 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 if (pkg.mVersionName != null) {
916 pkg.mVersionName = pkg.mVersionName.intern();
917 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800918 String str = sa.getNonConfigurationString(
919 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
920 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 String nameError = validateName(str, true);
922 if (nameError != null && !"android".equals(pkgName)) {
923 outError[0] = "<manifest> specifies bad sharedUserId name \""
924 + str + "\": " + nameError;
925 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
926 return null;
927 }
928 pkg.mSharedUserId = str.intern();
929 pkg.mSharedUserLabel = sa.getResourceId(
930 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
931 }
932 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800933
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800934 pkg.installLocation = sa.getInteger(
935 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700936 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700937 pkg.applicationInfo.installLocation = pkg.installLocation;
938
Dianne Hackborn723738c2009-06-25 19:48:04 -0700939 // Resource boolean are -1, so 1 means we don't know the value.
940 int supportsSmallScreens = 1;
941 int supportsNormalScreens = 1;
942 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700943 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700944 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700945 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700948 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
949 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
950 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 continue;
952 }
953
954 String tagName = parser.getName();
955 if (tagName.equals("application")) {
956 if (foundApp) {
957 if (RIGID_PARSER) {
958 outError[0] = "<manifest> has more than one <application>";
959 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
960 return null;
961 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700962 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 XmlUtils.skipCurrentTag(parser);
964 continue;
965 }
966 }
967
968 foundApp = true;
969 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
970 return null;
971 }
972 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700973 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 return null;
975 }
976 } else if (tagName.equals("permission")) {
977 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
978 return null;
979 }
980 } else if (tagName.equals("permission-tree")) {
981 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
982 return null;
983 }
984 } else if (tagName.equals("uses-permission")) {
985 sa = res.obtainAttributes(attrs,
986 com.android.internal.R.styleable.AndroidManifestUsesPermission);
987
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800988 // Note: don't allow this value to be a reference to a resource
989 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 String name = sa.getNonResourceString(
991 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne8241202012-04-06 13:39:09 -0700992 /* Not supporting optional permissions yet.
Dianne Hackborne639da72012-02-21 15:11:13 -0800993 boolean required = sa.getBoolean(
994 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Dianne Hackborne8241202012-04-06 13:39:09 -0700995 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996
997 sa.recycle();
998
999 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -07001000 pkg.requestedPermissions.add(name.intern());
Dianne Hackborne8241202012-04-06 13:39:09 -07001001 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 }
1003
1004 XmlUtils.skipCurrentTag(parser);
1005
1006 } else if (tagName.equals("uses-configuration")) {
1007 ConfigurationInfo cPref = new ConfigurationInfo();
1008 sa = res.obtainAttributes(attrs,
1009 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1010 cPref.reqTouchScreen = sa.getInt(
1011 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1012 Configuration.TOUCHSCREEN_UNDEFINED);
1013 cPref.reqKeyboardType = sa.getInt(
1014 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1015 Configuration.KEYBOARD_UNDEFINED);
1016 if (sa.getBoolean(
1017 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1018 false)) {
1019 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1020 }
1021 cPref.reqNavigation = sa.getInt(
1022 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1023 Configuration.NAVIGATION_UNDEFINED);
1024 if (sa.getBoolean(
1025 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1026 false)) {
1027 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1028 }
1029 sa.recycle();
1030 pkg.configPreferences.add(cPref);
1031
1032 XmlUtils.skipCurrentTag(parser);
1033
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001034 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001035 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001036 sa = res.obtainAttributes(attrs,
1037 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001038 // Note: don't allow this value to be a reference to a resource
1039 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001040 fi.name = sa.getNonResourceString(
1041 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1042 if (fi.name == null) {
1043 fi.reqGlEsVersion = sa.getInt(
1044 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1045 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1046 }
1047 if (sa.getBoolean(
1048 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1049 true)) {
1050 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1051 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001052 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001053 if (pkg.reqFeatures == null) {
1054 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1055 }
1056 pkg.reqFeatures.add(fi);
1057
1058 if (fi.name == null) {
1059 ConfigurationInfo cPref = new ConfigurationInfo();
1060 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1061 pkg.configPreferences.add(cPref);
1062 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001063
1064 XmlUtils.skipCurrentTag(parser);
1065
Dianne Hackborn851a5412009-05-08 12:06:44 -07001066 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001067 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 sa = res.obtainAttributes(attrs,
1069 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1070
Dianne Hackborn851a5412009-05-08 12:06:44 -07001071 int minVers = 0;
1072 String minCode = null;
1073 int targetVers = 0;
1074 String targetCode = null;
1075
1076 TypedValue val = sa.peekValue(
1077 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1078 if (val != null) {
1079 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1080 targetCode = minCode = val.string.toString();
1081 } else {
1082 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001083 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001084 }
1085 }
1086
1087 val = sa.peekValue(
1088 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1089 if (val != null) {
1090 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1091 targetCode = minCode = val.string.toString();
1092 } else {
1093 // If it's not a string, it's an integer.
1094 targetVers = val.data;
1095 }
1096 }
1097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 sa.recycle();
1099
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001100 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001101 if (!minCode.equals(SDK_CODENAME)) {
1102 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001103 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001104 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001105 } else {
1106 outError[0] = "Requires development platform " + minCode
1107 + " but this is a release platform.";
1108 }
1109 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1110 return null;
1111 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001112 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001113 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001114 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001115 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1116 return null;
1117 }
1118
Dianne Hackborn851a5412009-05-08 12:06:44 -07001119 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001120 if (!targetCode.equals(SDK_CODENAME)) {
1121 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001122 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001123 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001124 } else {
1125 outError[0] = "Requires development platform " + targetCode
1126 + " but this is a release platform.";
1127 }
1128 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1129 return null;
1130 }
1131 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001132 pkg.applicationInfo.targetSdkVersion
1133 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1134 } else {
1135 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 }
1138
1139 XmlUtils.skipCurrentTag(parser);
1140
Dianne Hackborn723738c2009-06-25 19:48:04 -07001141 } else if (tagName.equals("supports-screens")) {
1142 sa = res.obtainAttributes(attrs,
1143 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1144
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001145 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1146 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1147 0);
1148 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1149 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1150 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001151 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1152 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1153 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001154
Dianne Hackborn723738c2009-06-25 19:48:04 -07001155 // This is a trick to get a boolean and still able to detect
1156 // if a value was actually set.
1157 supportsSmallScreens = sa.getInteger(
1158 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1159 supportsSmallScreens);
1160 supportsNormalScreens = sa.getInteger(
1161 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1162 supportsNormalScreens);
1163 supportsLargeScreens = sa.getInteger(
1164 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1165 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001166 supportsXLargeScreens = sa.getInteger(
1167 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1168 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001169 resizeable = sa.getInteger(
1170 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001171 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001172 anyDensity = sa.getInteger(
1173 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1174 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001175
1176 sa.recycle();
1177
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001178 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001179
1180 } else if (tagName.equals("protected-broadcast")) {
1181 sa = res.obtainAttributes(attrs,
1182 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1183
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001184 // Note: don't allow this value to be a reference to a resource
1185 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001186 String name = sa.getNonResourceString(
1187 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1188
1189 sa.recycle();
1190
1191 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1192 if (pkg.protectedBroadcasts == null) {
1193 pkg.protectedBroadcasts = new ArrayList<String>();
1194 }
1195 if (!pkg.protectedBroadcasts.contains(name)) {
1196 pkg.protectedBroadcasts.add(name.intern());
1197 }
1198 }
1199
1200 XmlUtils.skipCurrentTag(parser);
1201
1202 } else if (tagName.equals("instrumentation")) {
1203 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1204 return null;
1205 }
1206
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001207 } else if (tagName.equals("original-package")) {
1208 sa = res.obtainAttributes(attrs,
1209 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1210
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001211 String orig =sa.getNonConfigurationString(
1212 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001213 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001214 if (pkg.mOriginalPackages == null) {
1215 pkg.mOriginalPackages = new ArrayList<String>();
1216 pkg.mRealPackage = pkg.packageName;
1217 }
1218 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001219 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001220
1221 sa.recycle();
1222
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001223 XmlUtils.skipCurrentTag(parser);
1224
1225 } else if (tagName.equals("adopt-permissions")) {
1226 sa = res.obtainAttributes(attrs,
1227 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1228
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001229 String name = sa.getNonConfigurationString(
1230 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001231
1232 sa.recycle();
1233
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001234 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001235 if (pkg.mAdoptPermissions == null) {
1236 pkg.mAdoptPermissions = new ArrayList<String>();
1237 }
1238 pkg.mAdoptPermissions.add(name);
1239 }
1240
1241 XmlUtils.skipCurrentTag(parser);
1242
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001243 } else if (tagName.equals("uses-gl-texture")) {
1244 // Just skip this tag
1245 XmlUtils.skipCurrentTag(parser);
1246 continue;
1247
1248 } else if (tagName.equals("compatible-screens")) {
1249 // Just skip this tag
1250 XmlUtils.skipCurrentTag(parser);
1251 continue;
1252
Dianne Hackborn854060a2009-07-09 18:14:31 -07001253 } else if (tagName.equals("eat-comment")) {
1254 // Just skip this tag
1255 XmlUtils.skipCurrentTag(parser);
1256 continue;
1257
1258 } else if (RIGID_PARSER) {
1259 outError[0] = "Bad element under <manifest>: "
1260 + parser.getName();
1261 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1262 return null;
1263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001265 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001266 + " at " + mArchiveSourcePath + " "
1267 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 XmlUtils.skipCurrentTag(parser);
1269 continue;
1270 }
1271 }
1272
1273 if (!foundApp && pkg.instrumentation.size() == 0) {
1274 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1275 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1276 }
1277
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001278 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001279 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001280 for (int ip=0; ip<NP; ip++) {
1281 final PackageParser.NewPermissionInfo npi
1282 = PackageParser.NEW_PERMISSIONS[ip];
1283 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1284 break;
1285 }
1286 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001287 if (implicitPerms == null) {
1288 implicitPerms = new StringBuilder(128);
1289 implicitPerms.append(pkg.packageName);
1290 implicitPerms.append(": compat added ");
1291 } else {
1292 implicitPerms.append(' ');
1293 }
1294 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001295 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001296 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001297 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001298 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001299 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001300 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001301 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001302
1303 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1304 for (int is=0; is<NS; is++) {
1305 final PackageParser.SplitPermissionInfo spi
1306 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001307 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1308 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001309 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001310 }
1311 for (int in=0; in<spi.newPerms.length; in++) {
1312 final String perm = spi.newPerms[in];
1313 if (!pkg.requestedPermissions.contains(perm)) {
1314 pkg.requestedPermissions.add(perm);
1315 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1316 }
1317 }
1318 }
1319
Dianne Hackborn723738c2009-06-25 19:48:04 -07001320 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1321 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001322 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001323 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1324 }
1325 if (supportsNormalScreens != 0) {
1326 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1327 }
1328 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1329 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001330 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001331 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1332 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001333 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1334 && pkg.applicationInfo.targetSdkVersion
1335 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1336 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1337 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001338 if (resizeable < 0 || (resizeable > 0
1339 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001340 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001341 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1342 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001343 if (anyDensity < 0 || (anyDensity > 0
1344 && pkg.applicationInfo.targetSdkVersion
1345 >= android.os.Build.VERSION_CODES.DONUT)) {
1346 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001347 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 return pkg;
1350 }
1351
1352 private static String buildClassName(String pkg, CharSequence clsSeq,
1353 String[] outError) {
1354 if (clsSeq == null || clsSeq.length() <= 0) {
1355 outError[0] = "Empty class name in package " + pkg;
1356 return null;
1357 }
1358 String cls = clsSeq.toString();
1359 char c = cls.charAt(0);
1360 if (c == '.') {
1361 return (pkg + cls).intern();
1362 }
1363 if (cls.indexOf('.') < 0) {
1364 StringBuilder b = new StringBuilder(pkg);
1365 b.append('.');
1366 b.append(cls);
1367 return b.toString().intern();
1368 }
1369 if (c >= 'a' && c <= 'z') {
1370 return cls.intern();
1371 }
1372 outError[0] = "Bad class name " + cls + " in package " + pkg;
1373 return null;
1374 }
1375
1376 private static String buildCompoundName(String pkg,
1377 CharSequence procSeq, String type, String[] outError) {
1378 String proc = procSeq.toString();
1379 char c = proc.charAt(0);
1380 if (pkg != null && c == ':') {
1381 if (proc.length() < 2) {
1382 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1383 + ": must be at least two characters";
1384 return null;
1385 }
1386 String subName = proc.substring(1);
1387 String nameError = validateName(subName, false);
1388 if (nameError != null) {
1389 outError[0] = "Invalid " + type + " name " + proc + " in package "
1390 + pkg + ": " + nameError;
1391 return null;
1392 }
1393 return (pkg + proc).intern();
1394 }
1395 String nameError = validateName(proc, true);
1396 if (nameError != null && !"system".equals(proc)) {
1397 outError[0] = "Invalid " + type + " name " + proc + " in package "
1398 + pkg + ": " + nameError;
1399 return null;
1400 }
1401 return proc.intern();
1402 }
1403
1404 private static String buildProcessName(String pkg, String defProc,
1405 CharSequence procSeq, int flags, String[] separateProcesses,
1406 String[] outError) {
1407 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1408 return defProc != null ? defProc : pkg;
1409 }
1410 if (separateProcesses != null) {
1411 for (int i=separateProcesses.length-1; i>=0; i--) {
1412 String sp = separateProcesses[i];
1413 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1414 return pkg;
1415 }
1416 }
1417 }
1418 if (procSeq == null || procSeq.length() <= 0) {
1419 return defProc;
1420 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001421 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 }
1423
1424 private static String buildTaskAffinityName(String pkg, String defProc,
1425 CharSequence procSeq, String[] outError) {
1426 if (procSeq == null) {
1427 return defProc;
1428 }
1429 if (procSeq.length() <= 0) {
1430 return null;
1431 }
1432 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1433 }
1434
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001435 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 XmlPullParser parser, AttributeSet attrs, String[] outError)
1437 throws XmlPullParserException, IOException {
1438 PermissionGroup perm = new PermissionGroup(owner);
1439
1440 TypedArray sa = res.obtainAttributes(attrs,
1441 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1442
1443 if (!parsePackageItemInfo(owner, perm.info, outError,
1444 "<permission-group>", sa,
1445 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1446 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001447 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1448 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 sa.recycle();
1450 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1451 return null;
1452 }
1453
1454 perm.info.descriptionRes = sa.getResourceId(
1455 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1456 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001457 perm.info.flags = sa.getInt(
1458 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
1459 perm.info.priority = sa.getInt(
1460 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001461 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001462 perm.info.priority = 0;
1463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464
1465 sa.recycle();
1466
1467 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1468 outError)) {
1469 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1470 return null;
1471 }
1472
1473 owner.permissionGroups.add(perm);
1474
1475 return perm;
1476 }
1477
1478 private Permission parsePermission(Package owner, Resources res,
1479 XmlPullParser parser, AttributeSet attrs, String[] outError)
1480 throws XmlPullParserException, IOException {
1481 Permission perm = new Permission(owner);
1482
1483 TypedArray sa = res.obtainAttributes(attrs,
1484 com.android.internal.R.styleable.AndroidManifestPermission);
1485
1486 if (!parsePackageItemInfo(owner, perm.info, outError,
1487 "<permission>", sa,
1488 com.android.internal.R.styleable.AndroidManifestPermission_name,
1489 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001490 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1491 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 sa.recycle();
1493 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1494 return null;
1495 }
1496
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001497 // Note: don't allow this value to be a reference to a resource
1498 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 perm.info.group = sa.getNonResourceString(
1500 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1501 if (perm.info.group != null) {
1502 perm.info.group = perm.info.group.intern();
1503 }
1504
1505 perm.info.descriptionRes = sa.getResourceId(
1506 com.android.internal.R.styleable.AndroidManifestPermission_description,
1507 0);
1508
1509 perm.info.protectionLevel = sa.getInt(
1510 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1511 PermissionInfo.PROTECTION_NORMAL);
1512
1513 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 if (perm.info.protectionLevel == -1) {
1516 outError[0] = "<permission> does not specify protectionLevel";
1517 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1518 return null;
1519 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001520
1521 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1522
1523 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1524 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1525 PermissionInfo.PROTECTION_SIGNATURE) {
1526 outError[0] = "<permission> protectionLevel specifies a flag but is "
1527 + "not based on signature type";
1528 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1529 return null;
1530 }
1531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532
1533 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1534 outError)) {
1535 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1536 return null;
1537 }
1538
1539 owner.permissions.add(perm);
1540
1541 return perm;
1542 }
1543
1544 private Permission parsePermissionTree(Package owner, Resources res,
1545 XmlPullParser parser, AttributeSet attrs, String[] outError)
1546 throws XmlPullParserException, IOException {
1547 Permission perm = new Permission(owner);
1548
1549 TypedArray sa = res.obtainAttributes(attrs,
1550 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1551
1552 if (!parsePackageItemInfo(owner, perm.info, outError,
1553 "<permission-tree>", sa,
1554 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1555 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001556 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1557 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 sa.recycle();
1559 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1560 return null;
1561 }
1562
1563 sa.recycle();
1564
1565 int index = perm.info.name.indexOf('.');
1566 if (index > 0) {
1567 index = perm.info.name.indexOf('.', index+1);
1568 }
1569 if (index < 0) {
1570 outError[0] = "<permission-tree> name has less than three segments: "
1571 + perm.info.name;
1572 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1573 return null;
1574 }
1575
1576 perm.info.descriptionRes = 0;
1577 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1578 perm.tree = true;
1579
1580 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1581 outError)) {
1582 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1583 return null;
1584 }
1585
1586 owner.permissions.add(perm);
1587
1588 return perm;
1589 }
1590
1591 private Instrumentation parseInstrumentation(Package owner, Resources res,
1592 XmlPullParser parser, AttributeSet attrs, String[] outError)
1593 throws XmlPullParserException, IOException {
1594 TypedArray sa = res.obtainAttributes(attrs,
1595 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1596
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001597 if (mParseInstrumentationArgs == null) {
1598 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1599 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1600 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001601 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1602 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001603 mParseInstrumentationArgs.tag = "<instrumentation>";
1604 }
1605
1606 mParseInstrumentationArgs.sa = sa;
1607
1608 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1609 new InstrumentationInfo());
1610 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 sa.recycle();
1612 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1613 return null;
1614 }
1615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001617 // Note: don't allow this value to be a reference to a resource
1618 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 str = sa.getNonResourceString(
1620 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1621 a.info.targetPackage = str != null ? str.intern() : null;
1622
1623 a.info.handleProfiling = sa.getBoolean(
1624 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1625 false);
1626
1627 a.info.functionalTest = sa.getBoolean(
1628 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1629 false);
1630
1631 sa.recycle();
1632
1633 if (a.info.targetPackage == null) {
1634 outError[0] = "<instrumentation> does not specify targetPackage";
1635 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1636 return null;
1637 }
1638
1639 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1640 outError)) {
1641 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1642 return null;
1643 }
1644
1645 owner.instrumentation.add(a);
1646
1647 return a;
1648 }
1649
1650 private boolean parseApplication(Package owner, Resources res,
1651 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1652 throws XmlPullParserException, IOException {
1653 final ApplicationInfo ai = owner.applicationInfo;
1654 final String pkgName = owner.applicationInfo.packageName;
1655
1656 TypedArray sa = res.obtainAttributes(attrs,
1657 com.android.internal.R.styleable.AndroidManifestApplication);
1658
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001659 String name = sa.getNonConfigurationString(
1660 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 if (name != null) {
1662 ai.className = buildClassName(pkgName, name, outError);
1663 if (ai.className == null) {
1664 sa.recycle();
1665 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1666 return false;
1667 }
1668 }
1669
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001670 String manageSpaceActivity = sa.getNonConfigurationString(
1671 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 if (manageSpaceActivity != null) {
1673 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1674 outError);
1675 }
1676
Christopher Tate181fafa2009-05-14 11:12:14 -07001677 boolean allowBackup = sa.getBoolean(
1678 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1679 if (allowBackup) {
1680 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001681
Christopher Tate3de55bc2010-03-12 17:28:08 -08001682 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1683 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001684 String backupAgent = sa.getNonConfigurationString(
1685 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001686 if (backupAgent != null) {
1687 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001688 if (DEBUG_BACKUP) {
1689 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001690 + " from " + pkgName + "+" + backupAgent);
1691 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001692
1693 if (sa.getBoolean(
1694 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1695 true)) {
1696 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1697 }
1698 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001699 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1700 false)) {
1701 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1702 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001703 }
1704 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 TypedValue v = sa.peekValue(
1707 com.android.internal.R.styleable.AndroidManifestApplication_label);
1708 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1709 ai.nonLocalizedLabel = v.coerceToString();
1710 }
1711
1712 ai.icon = sa.getResourceId(
1713 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001714 ai.logo = sa.getResourceId(
1715 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001717 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 ai.descriptionRes = sa.getResourceId(
1719 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1720
1721 if ((flags&PARSE_IS_SYSTEM) != 0) {
1722 if (sa.getBoolean(
1723 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1724 false)) {
1725 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1726 }
1727 }
1728
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001729 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1730 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1731 }
1732
1733 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001734 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001735 }
1736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 if (sa.getBoolean(
1738 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1739 false)) {
1740 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1741 }
1742
1743 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001744 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001745 false)) {
1746 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1747 }
1748
Romain Guy529b60a2010-08-03 18:05:47 -07001749 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001750 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001751 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001752
1753 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1755 true)) {
1756 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1757 }
1758
1759 if (sa.getBoolean(
1760 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1761 false)) {
1762 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1763 }
1764
1765 if (sa.getBoolean(
1766 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1767 true)) {
1768 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1769 }
1770
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001771 if (sa.getBoolean(
1772 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001773 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001774 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1775 }
1776
Jason parksa3cdaa52011-01-13 14:15:43 -06001777 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001778 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001779 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001780 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001781 }
1782
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001783 if (sa.getBoolean(
1784 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1785 false /* default is no RTL support*/)) {
1786 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1787 }
1788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001790 str = sa.getNonConfigurationString(
1791 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1793
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001794 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1795 str = sa.getNonConfigurationString(
1796 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1797 } else {
1798 // Some older apps have been seen to use a resource reference
1799 // here that on older builds was ignored (with a warning). We
1800 // need to continue to do this for them so they don't break.
1801 str = sa.getNonResourceString(
1802 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1805 str, outError);
1806
1807 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001808 CharSequence pname;
1809 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1810 pname = sa.getNonConfigurationString(
1811 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1812 } else {
1813 // Some older apps have been seen to use a resource reference
1814 // here that on older builds was ignored (with a warning). We
1815 // need to continue to do this for them so they don't break.
1816 pname = sa.getNonResourceString(
1817 com.android.internal.R.styleable.AndroidManifestApplication_process);
1818 }
1819 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 flags, mSeparateProcesses, outError);
1821
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001822 ai.enabled = sa.getBoolean(
1823 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001824
Dianne Hackborn02486b12010-08-26 14:18:37 -07001825 if (false) {
1826 if (sa.getBoolean(
1827 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1828 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001829 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001830
1831 // A heavy-weight application can not be in a custom process.
1832 // We can do direct compare because we intern all strings.
1833 if (ai.processName != null && ai.processName != ai.packageName) {
1834 outError[0] = "cantSaveState applications can not use custom processes";
1835 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001836 }
1837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 }
1839
Adam Powell269248d2011-08-02 10:26:54 -07001840 ai.uiOptions = sa.getInt(
1841 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 sa.recycle();
1844
1845 if (outError[0] != null) {
1846 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1847 return false;
1848 }
1849
1850 final int innerDepth = parser.getDepth();
1851
1852 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001853 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1854 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1855 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 continue;
1857 }
1858
1859 String tagName = parser.getName();
1860 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001861 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1862 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 if (a == null) {
1864 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1865 return false;
1866 }
1867
1868 owner.activities.add(a);
1869
1870 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001871 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001872 if (a == null) {
1873 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1874 return false;
1875 }
1876
1877 owner.receivers.add(a);
1878
1879 } else if (tagName.equals("service")) {
1880 Service s = parseService(owner, res, parser, attrs, flags, outError);
1881 if (s == null) {
1882 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1883 return false;
1884 }
1885
1886 owner.services.add(s);
1887
1888 } else if (tagName.equals("provider")) {
1889 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1890 if (p == null) {
1891 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1892 return false;
1893 }
1894
1895 owner.providers.add(p);
1896
1897 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001898 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 if (a == null) {
1900 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1901 return false;
1902 }
1903
1904 owner.activities.add(a);
1905
1906 } else if (parser.getName().equals("meta-data")) {
1907 // note: application meta-data is stored off to the side, so it can
1908 // remain null in the primary copy (we like to avoid extra copies because
1909 // it can be large)
1910 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1911 outError)) == null) {
1912 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1913 return false;
1914 }
1915
1916 } else if (tagName.equals("uses-library")) {
1917 sa = res.obtainAttributes(attrs,
1918 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1919
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001920 // Note: don't allow this value to be a reference to a resource
1921 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 String lname = sa.getNonResourceString(
1923 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001924 boolean req = sa.getBoolean(
1925 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1926 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927
1928 sa.recycle();
1929
Dianne Hackborn49237342009-08-27 20:08:01 -07001930 if (lname != null) {
1931 if (req) {
1932 if (owner.usesLibraries == null) {
1933 owner.usesLibraries = new ArrayList<String>();
1934 }
1935 if (!owner.usesLibraries.contains(lname)) {
1936 owner.usesLibraries.add(lname.intern());
1937 }
1938 } else {
1939 if (owner.usesOptionalLibraries == null) {
1940 owner.usesOptionalLibraries = new ArrayList<String>();
1941 }
1942 if (!owner.usesOptionalLibraries.contains(lname)) {
1943 owner.usesOptionalLibraries.add(lname.intern());
1944 }
1945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 }
1947
1948 XmlUtils.skipCurrentTag(parser);
1949
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001950 } else if (tagName.equals("uses-package")) {
1951 // Dependencies for app installers; we don't currently try to
1952 // enforce this.
1953 XmlUtils.skipCurrentTag(parser);
1954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 } else {
1956 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001957 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001958 + " at " + mArchiveSourcePath + " "
1959 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 XmlUtils.skipCurrentTag(parser);
1961 continue;
1962 } else {
1963 outError[0] = "Bad element under <application>: " + tagName;
1964 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1965 return false;
1966 }
1967 }
1968 }
1969
1970 return true;
1971 }
1972
1973 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1974 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001975 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001976 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 if (name == null) {
1978 outError[0] = tag + " does not specify android:name";
1979 return false;
1980 }
1981
1982 outInfo.name
1983 = buildClassName(owner.applicationInfo.packageName, name, outError);
1984 if (outInfo.name == null) {
1985 return false;
1986 }
1987
1988 int iconVal = sa.getResourceId(iconRes, 0);
1989 if (iconVal != 0) {
1990 outInfo.icon = iconVal;
1991 outInfo.nonLocalizedLabel = null;
1992 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001993
1994 int logoVal = sa.getResourceId(logoRes, 0);
1995 if (logoVal != 0) {
1996 outInfo.logo = logoVal;
1997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998
1999 TypedValue v = sa.peekValue(labelRes);
2000 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2001 outInfo.nonLocalizedLabel = v.coerceToString();
2002 }
2003
2004 outInfo.packageName = owner.packageName;
2005
2006 return true;
2007 }
2008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 private Activity parseActivity(Package owner, Resources res,
2010 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002011 boolean receiver, boolean hardwareAccelerated)
2012 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 TypedArray sa = res.obtainAttributes(attrs,
2014 com.android.internal.R.styleable.AndroidManifestActivity);
2015
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002016 if (mParseActivityArgs == null) {
2017 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2018 com.android.internal.R.styleable.AndroidManifestActivity_name,
2019 com.android.internal.R.styleable.AndroidManifestActivity_label,
2020 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002021 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002022 mSeparateProcesses,
2023 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002024 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002025 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2026 }
2027
2028 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2029 mParseActivityArgs.sa = sa;
2030 mParseActivityArgs.flags = flags;
2031
2032 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2033 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 sa.recycle();
2035 return null;
2036 }
2037
2038 final boolean setExported = sa.hasValue(
2039 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2040 if (setExported) {
2041 a.info.exported = sa.getBoolean(
2042 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2043 }
2044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 a.info.theme = sa.getResourceId(
2046 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2047
Adam Powell269248d2011-08-02 10:26:54 -07002048 a.info.uiOptions = sa.getInt(
2049 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2050 a.info.applicationInfo.uiOptions);
2051
Adam Powelldd8fab22012-03-22 17:47:27 -07002052 String parentName = sa.getNonConfigurationString(
2053 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2054 if (parentName != null) {
2055 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2056 if (outError[0] == null) {
2057 a.info.parentActivityName = parentClassName;
2058 } else {
2059 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2060 parentName);
2061 outError[0] = null;
2062 }
2063 }
2064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002066 str = sa.getNonConfigurationString(
2067 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 if (str == null) {
2069 a.info.permission = owner.applicationInfo.permission;
2070 } else {
2071 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2072 }
2073
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002074 str = sa.getNonConfigurationString(
2075 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2077 owner.applicationInfo.taskAffinity, str, outError);
2078
2079 a.info.flags = 0;
2080 if (sa.getBoolean(
2081 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2082 false)) {
2083 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2084 }
2085
2086 if (sa.getBoolean(
2087 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2088 false)) {
2089 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2090 }
2091
2092 if (sa.getBoolean(
2093 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2094 false)) {
2095 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2096 }
2097
2098 if (sa.getBoolean(
2099 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2100 false)) {
2101 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2102 }
2103
2104 if (sa.getBoolean(
2105 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2106 false)) {
2107 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2108 }
2109
2110 if (sa.getBoolean(
2111 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2112 false)) {
2113 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2114 }
2115
2116 if (sa.getBoolean(
2117 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2118 false)) {
2119 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2120 }
2121
2122 if (sa.getBoolean(
2123 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2124 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2125 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2126 }
2127
Dianne Hackbornffa42482009-09-23 22:20:11 -07002128 if (sa.getBoolean(
2129 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2130 false)) {
2131 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2132 }
2133
Daniel Sandler613dde42010-06-21 13:46:39 -04002134 if (sa.getBoolean(
2135 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2136 false)) {
2137 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2138 }
Romain Guy529b60a2010-08-03 18:05:47 -07002139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002141 if (sa.getBoolean(
2142 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2143 hardwareAccelerated)) {
2144 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2145 }
2146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 a.info.launchMode = sa.getInt(
2148 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2149 ActivityInfo.LAUNCH_MULTIPLE);
2150 a.info.screenOrientation = sa.getInt(
2151 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2152 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2153 a.info.configChanges = sa.getInt(
2154 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2155 0);
2156 a.info.softInputMode = sa.getInt(
2157 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2158 0);
2159 } else {
2160 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2161 a.info.configChanges = 0;
2162 }
2163
2164 sa.recycle();
2165
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002166 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002167 // A heavy-weight application can not have receives in its main process
2168 // We can do direct compare because we intern all strings.
2169 if (a.info.processName == owner.packageName) {
2170 outError[0] = "Heavy-weight applications can not have receivers in main process";
2171 }
2172 }
2173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 if (outError[0] != null) {
2175 return null;
2176 }
2177
2178 int outerDepth = parser.getDepth();
2179 int type;
2180 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2181 && (type != XmlPullParser.END_TAG
2182 || parser.getDepth() > outerDepth)) {
2183 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2184 continue;
2185 }
2186
2187 if (parser.getName().equals("intent-filter")) {
2188 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2189 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2190 return null;
2191 }
2192 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002193 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002194 + mArchiveSourcePath + " "
2195 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 } else {
2197 a.intents.add(intent);
2198 }
2199 } else if (parser.getName().equals("meta-data")) {
2200 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2201 outError)) == null) {
2202 return null;
2203 }
2204 } else {
2205 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002206 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002208 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002209 + " at " + mArchiveSourcePath + " "
2210 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002212 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002213 + " at " + mArchiveSourcePath + " "
2214 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 }
2216 XmlUtils.skipCurrentTag(parser);
2217 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002219 if (receiver) {
2220 outError[0] = "Bad element under <receiver>: " + parser.getName();
2221 } else {
2222 outError[0] = "Bad element under <activity>: " + parser.getName();
2223 }
2224 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 }
2227 }
2228
2229 if (!setExported) {
2230 a.info.exported = a.intents.size() > 0;
2231 }
2232
2233 return a;
2234 }
2235
2236 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002237 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2238 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 TypedArray sa = res.obtainAttributes(attrs,
2240 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2241
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002242 String targetActivity = sa.getNonConfigurationString(
2243 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 if (targetActivity == null) {
2245 outError[0] = "<activity-alias> does not specify android:targetActivity";
2246 sa.recycle();
2247 return null;
2248 }
2249
2250 targetActivity = buildClassName(owner.applicationInfo.packageName,
2251 targetActivity, outError);
2252 if (targetActivity == null) {
2253 sa.recycle();
2254 return null;
2255 }
2256
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 if (mParseActivityAliasArgs == null) {
2258 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2259 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2260 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2261 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002262 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002263 mSeparateProcesses,
2264 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002265 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002266 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2267 mParseActivityAliasArgs.tag = "<activity-alias>";
2268 }
2269
2270 mParseActivityAliasArgs.sa = sa;
2271 mParseActivityAliasArgs.flags = flags;
2272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 Activity target = null;
2274
2275 final int NA = owner.activities.size();
2276 for (int i=0; i<NA; i++) {
2277 Activity t = owner.activities.get(i);
2278 if (targetActivity.equals(t.info.name)) {
2279 target = t;
2280 break;
2281 }
2282 }
2283
2284 if (target == null) {
2285 outError[0] = "<activity-alias> target activity " + targetActivity
2286 + " not found in manifest";
2287 sa.recycle();
2288 return null;
2289 }
2290
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002291 ActivityInfo info = new ActivityInfo();
2292 info.targetActivity = targetActivity;
2293 info.configChanges = target.info.configChanges;
2294 info.flags = target.info.flags;
2295 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002296 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002297 info.labelRes = target.info.labelRes;
2298 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2299 info.launchMode = target.info.launchMode;
2300 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002301 if (info.descriptionRes == 0) {
2302 info.descriptionRes = target.info.descriptionRes;
2303 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002304 info.screenOrientation = target.info.screenOrientation;
2305 info.taskAffinity = target.info.taskAffinity;
2306 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002307 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002308 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002309 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002310
2311 Activity a = new Activity(mParseActivityAliasArgs, info);
2312 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 sa.recycle();
2314 return null;
2315 }
2316
2317 final boolean setExported = sa.hasValue(
2318 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2319 if (setExported) {
2320 a.info.exported = sa.getBoolean(
2321 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2322 }
2323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002325 str = sa.getNonConfigurationString(
2326 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 if (str != null) {
2328 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2329 }
2330
Adam Powelldd8fab22012-03-22 17:47:27 -07002331 String parentName = sa.getNonConfigurationString(
2332 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2333 0);
2334 if (parentName != null) {
2335 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2336 if (outError[0] == null) {
2337 a.info.parentActivityName = parentClassName;
2338 } else {
2339 Log.e(TAG, "Activity alias " + a.info.name +
2340 " specified invalid parentActivityName " + parentName);
2341 outError[0] = null;
2342 }
2343 }
2344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 sa.recycle();
2346
2347 if (outError[0] != null) {
2348 return null;
2349 }
2350
2351 int outerDepth = parser.getDepth();
2352 int type;
2353 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2354 && (type != XmlPullParser.END_TAG
2355 || parser.getDepth() > outerDepth)) {
2356 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2357 continue;
2358 }
2359
2360 if (parser.getName().equals("intent-filter")) {
2361 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2362 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2363 return null;
2364 }
2365 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002366 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002367 + mArchiveSourcePath + " "
2368 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 } else {
2370 a.intents.add(intent);
2371 }
2372 } else if (parser.getName().equals("meta-data")) {
2373 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2374 outError)) == null) {
2375 return null;
2376 }
2377 } else {
2378 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002379 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002380 + " at " + mArchiveSourcePath + " "
2381 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 XmlUtils.skipCurrentTag(parser);
2383 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002384 } else {
2385 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2386 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 }
2389 }
2390
2391 if (!setExported) {
2392 a.info.exported = a.intents.size() > 0;
2393 }
2394
2395 return a;
2396 }
2397
2398 private Provider parseProvider(Package owner, Resources res,
2399 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2400 throws XmlPullParserException, IOException {
2401 TypedArray sa = res.obtainAttributes(attrs,
2402 com.android.internal.R.styleable.AndroidManifestProvider);
2403
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002404 if (mParseProviderArgs == null) {
2405 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2406 com.android.internal.R.styleable.AndroidManifestProvider_name,
2407 com.android.internal.R.styleable.AndroidManifestProvider_label,
2408 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002409 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002410 mSeparateProcesses,
2411 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002412 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002413 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2414 mParseProviderArgs.tag = "<provider>";
2415 }
2416
2417 mParseProviderArgs.sa = sa;
2418 mParseProviderArgs.flags = flags;
2419
2420 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2421 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 sa.recycle();
2423 return null;
2424 }
2425
2426 p.info.exported = sa.getBoolean(
2427 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2428
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002429 String cpname = sa.getNonConfigurationString(
2430 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431
2432 p.info.isSyncable = sa.getBoolean(
2433 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2434 false);
2435
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002436 String permission = sa.getNonConfigurationString(
2437 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2438 String str = sa.getNonConfigurationString(
2439 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 if (str == null) {
2441 str = permission;
2442 }
2443 if (str == null) {
2444 p.info.readPermission = owner.applicationInfo.permission;
2445 } else {
2446 p.info.readPermission =
2447 str.length() > 0 ? str.toString().intern() : null;
2448 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002449 str = sa.getNonConfigurationString(
2450 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 if (str == null) {
2452 str = permission;
2453 }
2454 if (str == null) {
2455 p.info.writePermission = owner.applicationInfo.permission;
2456 } else {
2457 p.info.writePermission =
2458 str.length() > 0 ? str.toString().intern() : null;
2459 }
2460
2461 p.info.grantUriPermissions = sa.getBoolean(
2462 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2463 false);
2464
2465 p.info.multiprocess = sa.getBoolean(
2466 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2467 false);
2468
2469 p.info.initOrder = sa.getInt(
2470 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2471 0);
2472
2473 sa.recycle();
2474
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002475 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002476 // A heavy-weight application can not have providers in its main process
2477 // We can do direct compare because we intern all strings.
2478 if (p.info.processName == owner.packageName) {
2479 outError[0] = "Heavy-weight applications can not have providers in main process";
2480 return null;
2481 }
2482 }
2483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 if (cpname == null) {
2485 outError[0] = "<provider> does not incude authorities attribute";
2486 return null;
2487 }
2488 p.info.authority = cpname.intern();
2489
2490 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2491 return null;
2492 }
2493
2494 return p;
2495 }
2496
2497 private boolean parseProviderTags(Resources res,
2498 XmlPullParser parser, AttributeSet attrs,
2499 Provider outInfo, String[] outError)
2500 throws XmlPullParserException, IOException {
2501 int outerDepth = parser.getDepth();
2502 int type;
2503 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2504 && (type != XmlPullParser.END_TAG
2505 || parser.getDepth() > outerDepth)) {
2506 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2507 continue;
2508 }
2509
2510 if (parser.getName().equals("meta-data")) {
2511 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2512 outInfo.metaData, outError)) == null) {
2513 return false;
2514 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 } else if (parser.getName().equals("grant-uri-permission")) {
2517 TypedArray sa = res.obtainAttributes(attrs,
2518 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2519
2520 PatternMatcher pa = null;
2521
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002522 String str = sa.getNonConfigurationString(
2523 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 if (str != null) {
2525 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2526 }
2527
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002528 str = sa.getNonConfigurationString(
2529 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 if (str != null) {
2531 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2532 }
2533
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002534 str = sa.getNonConfigurationString(
2535 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 if (str != null) {
2537 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2538 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 sa.recycle();
2541
2542 if (pa != null) {
2543 if (outInfo.info.uriPermissionPatterns == null) {
2544 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2545 outInfo.info.uriPermissionPatterns[0] = pa;
2546 } else {
2547 final int N = outInfo.info.uriPermissionPatterns.length;
2548 PatternMatcher[] newp = new PatternMatcher[N+1];
2549 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2550 newp[N] = pa;
2551 outInfo.info.uriPermissionPatterns = newp;
2552 }
2553 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002554 } else {
2555 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002556 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002557 + parser.getName() + " at " + mArchiveSourcePath + " "
2558 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002559 XmlUtils.skipCurrentTag(parser);
2560 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002561 } else {
2562 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2563 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002564 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002565 }
2566 XmlUtils.skipCurrentTag(parser);
2567
2568 } else if (parser.getName().equals("path-permission")) {
2569 TypedArray sa = res.obtainAttributes(attrs,
2570 com.android.internal.R.styleable.AndroidManifestPathPermission);
2571
2572 PathPermission pa = null;
2573
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002574 String permission = sa.getNonConfigurationString(
2575 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2576 String readPermission = sa.getNonConfigurationString(
2577 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002578 if (readPermission == null) {
2579 readPermission = permission;
2580 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002581 String writePermission = sa.getNonConfigurationString(
2582 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002583 if (writePermission == null) {
2584 writePermission = permission;
2585 }
2586
2587 boolean havePerm = false;
2588 if (readPermission != null) {
2589 readPermission = readPermission.intern();
2590 havePerm = true;
2591 }
2592 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002593 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002594 havePerm = true;
2595 }
2596
2597 if (!havePerm) {
2598 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002599 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002600 + parser.getName() + " at " + mArchiveSourcePath + " "
2601 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002602 XmlUtils.skipCurrentTag(parser);
2603 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002604 } else {
2605 outError[0] = "No readPermission or writePermssion for <path-permission>";
2606 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002607 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002608 }
2609
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002610 String path = sa.getNonConfigurationString(
2611 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002612 if (path != null) {
2613 pa = new PathPermission(path,
2614 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2615 }
2616
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002617 path = sa.getNonConfigurationString(
2618 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002619 if (path != null) {
2620 pa = new PathPermission(path,
2621 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2622 }
2623
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002624 path = sa.getNonConfigurationString(
2625 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002626 if (path != null) {
2627 pa = new PathPermission(path,
2628 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2629 }
2630
2631 sa.recycle();
2632
2633 if (pa != null) {
2634 if (outInfo.info.pathPermissions == null) {
2635 outInfo.info.pathPermissions = new PathPermission[1];
2636 outInfo.info.pathPermissions[0] = pa;
2637 } else {
2638 final int N = outInfo.info.pathPermissions.length;
2639 PathPermission[] newp = new PathPermission[N+1];
2640 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2641 newp[N] = pa;
2642 outInfo.info.pathPermissions = newp;
2643 }
2644 } else {
2645 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002646 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002647 + parser.getName() + " at " + mArchiveSourcePath + " "
2648 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002649 XmlUtils.skipCurrentTag(parser);
2650 continue;
2651 }
2652 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2653 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 }
2655 XmlUtils.skipCurrentTag(parser);
2656
2657 } else {
2658 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002659 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002660 + parser.getName() + " at " + mArchiveSourcePath + " "
2661 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 XmlUtils.skipCurrentTag(parser);
2663 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002664 } else {
2665 outError[0] = "Bad element under <provider>: " + parser.getName();
2666 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 }
2669 }
2670 return true;
2671 }
2672
2673 private Service parseService(Package owner, Resources res,
2674 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2675 throws XmlPullParserException, IOException {
2676 TypedArray sa = res.obtainAttributes(attrs,
2677 com.android.internal.R.styleable.AndroidManifestService);
2678
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002679 if (mParseServiceArgs == null) {
2680 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2681 com.android.internal.R.styleable.AndroidManifestService_name,
2682 com.android.internal.R.styleable.AndroidManifestService_label,
2683 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002684 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002685 mSeparateProcesses,
2686 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002687 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002688 com.android.internal.R.styleable.AndroidManifestService_enabled);
2689 mParseServiceArgs.tag = "<service>";
2690 }
2691
2692 mParseServiceArgs.sa = sa;
2693 mParseServiceArgs.flags = flags;
2694
2695 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2696 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 sa.recycle();
2698 return null;
2699 }
2700
2701 final boolean setExported = sa.hasValue(
2702 com.android.internal.R.styleable.AndroidManifestService_exported);
2703 if (setExported) {
2704 s.info.exported = sa.getBoolean(
2705 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2706 }
2707
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002708 String str = sa.getNonConfigurationString(
2709 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 if (str == null) {
2711 s.info.permission = owner.applicationInfo.permission;
2712 } else {
2713 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2714 }
2715
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002716 s.info.flags = 0;
2717 if (sa.getBoolean(
2718 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2719 false)) {
2720 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2721 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002722 if (sa.getBoolean(
2723 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2724 false)) {
2725 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2726 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 sa.recycle();
2729
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002730 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002731 // A heavy-weight application can not have services in its main process
2732 // We can do direct compare because we intern all strings.
2733 if (s.info.processName == owner.packageName) {
2734 outError[0] = "Heavy-weight applications can not have services in main process";
2735 return null;
2736 }
2737 }
2738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 int outerDepth = parser.getDepth();
2740 int type;
2741 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2742 && (type != XmlPullParser.END_TAG
2743 || parser.getDepth() > outerDepth)) {
2744 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2745 continue;
2746 }
2747
2748 if (parser.getName().equals("intent-filter")) {
2749 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2750 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2751 return null;
2752 }
2753
2754 s.intents.add(intent);
2755 } else if (parser.getName().equals("meta-data")) {
2756 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2757 outError)) == null) {
2758 return null;
2759 }
2760 } else {
2761 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002762 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002763 + parser.getName() + " at " + mArchiveSourcePath + " "
2764 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 XmlUtils.skipCurrentTag(parser);
2766 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002767 } else {
2768 outError[0] = "Bad element under <service>: " + parser.getName();
2769 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 }
2772 }
2773
2774 if (!setExported) {
2775 s.info.exported = s.intents.size() > 0;
2776 }
2777
2778 return s;
2779 }
2780
2781 private boolean parseAllMetaData(Resources res,
2782 XmlPullParser parser, AttributeSet attrs, String tag,
2783 Component outInfo, String[] outError)
2784 throws XmlPullParserException, IOException {
2785 int outerDepth = parser.getDepth();
2786 int type;
2787 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2788 && (type != XmlPullParser.END_TAG
2789 || parser.getDepth() > outerDepth)) {
2790 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2791 continue;
2792 }
2793
2794 if (parser.getName().equals("meta-data")) {
2795 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2796 outInfo.metaData, outError)) == null) {
2797 return false;
2798 }
2799 } else {
2800 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002801 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002802 + parser.getName() + " at " + mArchiveSourcePath + " "
2803 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 XmlUtils.skipCurrentTag(parser);
2805 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002806 } else {
2807 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2808 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 }
2811 }
2812 return true;
2813 }
2814
2815 private Bundle parseMetaData(Resources res,
2816 XmlPullParser parser, AttributeSet attrs,
2817 Bundle data, String[] outError)
2818 throws XmlPullParserException, IOException {
2819
2820 TypedArray sa = res.obtainAttributes(attrs,
2821 com.android.internal.R.styleable.AndroidManifestMetaData);
2822
2823 if (data == null) {
2824 data = new Bundle();
2825 }
2826
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002827 String name = sa.getNonConfigurationString(
2828 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 if (name == null) {
2830 outError[0] = "<meta-data> requires an android:name attribute";
2831 sa.recycle();
2832 return null;
2833 }
2834
Dianne Hackborn854060a2009-07-09 18:14:31 -07002835 name = name.intern();
2836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 TypedValue v = sa.peekValue(
2838 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2839 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002840 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 data.putInt(name, v.resourceId);
2842 } else {
2843 v = sa.peekValue(
2844 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002845 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 if (v != null) {
2847 if (v.type == TypedValue.TYPE_STRING) {
2848 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002849 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2851 data.putBoolean(name, v.data != 0);
2852 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2853 && v.type <= TypedValue.TYPE_LAST_INT) {
2854 data.putInt(name, v.data);
2855 } else if (v.type == TypedValue.TYPE_FLOAT) {
2856 data.putFloat(name, v.getFloat());
2857 } else {
2858 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002859 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002860 + parser.getName() + " at " + mArchiveSourcePath + " "
2861 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 } else {
2863 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2864 data = null;
2865 }
2866 }
2867 } else {
2868 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2869 data = null;
2870 }
2871 }
2872
2873 sa.recycle();
2874
2875 XmlUtils.skipCurrentTag(parser);
2876
2877 return data;
2878 }
2879
Kenny Root05ca4c92011-09-15 10:36:25 -07002880 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2881 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2882 IOException {
2883 final TypedArray sa = res.obtainAttributes(attrs,
2884 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2885
2886 final String packageName = sa.getNonResourceString(
2887 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2888
2889 final String encodedPublicKey = sa.getNonResourceString(
2890 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2891
2892 sa.recycle();
2893
2894 if (packageName == null || packageName.length() == 0) {
2895 Slog.i(TAG, "verifier package name was null; skipping");
2896 return null;
2897 } else if (encodedPublicKey == null) {
2898 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2899 }
2900
2901 EncodedKeySpec keySpec;
2902 try {
2903 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2904 keySpec = new X509EncodedKeySpec(encoded);
2905 } catch (IllegalArgumentException e) {
2906 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2907 return null;
2908 }
2909
2910 /* First try the key as an RSA key. */
2911 try {
2912 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2913 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2914 return new VerifierInfo(packageName, publicKey);
2915 } catch (NoSuchAlgorithmException e) {
2916 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2917 return null;
2918 } catch (InvalidKeySpecException e) {
2919 // Not a RSA public key.
2920 }
2921
2922 /* Now try it as a DSA key. */
2923 try {
2924 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
2925 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2926 return new VerifierInfo(packageName, publicKey);
2927 } catch (NoSuchAlgorithmException e) {
2928 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
2929 return null;
2930 } catch (InvalidKeySpecException e) {
2931 // Not a DSA public key.
2932 }
2933
2934 return null;
2935 }
2936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 private static final String ANDROID_RESOURCES
2938 = "http://schemas.android.com/apk/res/android";
2939
2940 private boolean parseIntent(Resources res,
2941 XmlPullParser parser, AttributeSet attrs, int flags,
2942 IntentInfo outInfo, String[] outError, boolean isActivity)
2943 throws XmlPullParserException, IOException {
2944
2945 TypedArray sa = res.obtainAttributes(attrs,
2946 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2947
2948 int priority = sa.getInt(
2949 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 TypedValue v = sa.peekValue(
2953 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2954 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2955 outInfo.nonLocalizedLabel = v.coerceToString();
2956 }
2957
2958 outInfo.icon = sa.getResourceId(
2959 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002960
2961 outInfo.logo = sa.getResourceId(
2962 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963
2964 sa.recycle();
2965
2966 int outerDepth = parser.getDepth();
2967 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002968 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2969 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2970 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 continue;
2972 }
2973
2974 String nodeName = parser.getName();
2975 if (nodeName.equals("action")) {
2976 String value = attrs.getAttributeValue(
2977 ANDROID_RESOURCES, "name");
2978 if (value == null || value == "") {
2979 outError[0] = "No value supplied for <android:name>";
2980 return false;
2981 }
2982 XmlUtils.skipCurrentTag(parser);
2983
2984 outInfo.addAction(value);
2985 } else if (nodeName.equals("category")) {
2986 String value = attrs.getAttributeValue(
2987 ANDROID_RESOURCES, "name");
2988 if (value == null || value == "") {
2989 outError[0] = "No value supplied for <android:name>";
2990 return false;
2991 }
2992 XmlUtils.skipCurrentTag(parser);
2993
2994 outInfo.addCategory(value);
2995
2996 } else if (nodeName.equals("data")) {
2997 sa = res.obtainAttributes(attrs,
2998 com.android.internal.R.styleable.AndroidManifestData);
2999
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003000 String str = sa.getNonConfigurationString(
3001 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 if (str != null) {
3003 try {
3004 outInfo.addDataType(str);
3005 } catch (IntentFilter.MalformedMimeTypeException e) {
3006 outError[0] = e.toString();
3007 sa.recycle();
3008 return false;
3009 }
3010 }
3011
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003012 str = sa.getNonConfigurationString(
3013 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 if (str != null) {
3015 outInfo.addDataScheme(str);
3016 }
3017
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003018 String host = sa.getNonConfigurationString(
3019 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3020 String port = sa.getNonConfigurationString(
3021 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 if (host != null) {
3023 outInfo.addDataAuthority(host, port);
3024 }
3025
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003026 str = sa.getNonConfigurationString(
3027 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 if (str != null) {
3029 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3030 }
3031
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003032 str = sa.getNonConfigurationString(
3033 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 if (str != null) {
3035 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3036 }
3037
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003038 str = sa.getNonConfigurationString(
3039 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 if (str != null) {
3041 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3042 }
3043
3044 sa.recycle();
3045 XmlUtils.skipCurrentTag(parser);
3046 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003047 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003048 + parser.getName() + " at " + mArchiveSourcePath + " "
3049 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 XmlUtils.skipCurrentTag(parser);
3051 } else {
3052 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3053 return false;
3054 }
3055 }
3056
3057 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003058
3059 if (DEBUG_PARSER) {
3060 final StringBuilder cats = new StringBuilder("Intent d=");
3061 cats.append(outInfo.hasDefault);
3062 cats.append(", cat=");
3063
3064 final Iterator<String> it = outInfo.categoriesIterator();
3065 if (it != null) {
3066 while (it.hasNext()) {
3067 cats.append(' ');
3068 cats.append(it.next());
3069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003071 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 }
3073
3074 return true;
3075 }
3076
3077 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003078 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079
3080 // For now we only support one application per package.
3081 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3082
3083 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3084 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3085 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3086 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3087 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3088 public final ArrayList<Service> services = new ArrayList<Service>(0);
3089 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3090
3091 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003092 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003093
Dianne Hackborn854060a2009-07-09 18:14:31 -07003094 public ArrayList<String> protectedBroadcasts;
3095
Dianne Hackborn49237342009-08-27 20:08:01 -07003096 public ArrayList<String> usesLibraries = null;
3097 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098 public String[] usesLibraryFiles = null;
3099
Dianne Hackbornc1552392010-03-03 16:19:01 -08003100 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003101 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003102 public ArrayList<String> mAdoptPermissions = null;
3103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 // We store the application meta-data independently to avoid multiple unwanted references
3105 public Bundle mAppMetaData = null;
3106
3107 // If this is a 3rd party app, this is the path of the zip file.
3108 public String mPath;
3109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 // The version code declared for this package.
3111 public int mVersionCode;
3112
3113 // The version name declared for this package.
3114 public String mVersionName;
3115
3116 // The shared user id that this package wants to use.
3117 public String mSharedUserId;
3118
3119 // The shared user label that this package wants to use.
3120 public int mSharedUserLabel;
3121
3122 // Signatures that were read from the package.
3123 public Signature mSignatures[];
3124
3125 // For use by package manager service for quick lookup of
3126 // preferred up order.
3127 public int mPreferredOrder = 0;
3128
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003129 // For use by the package manager to keep track of the path to the
3130 // file an app came from.
3131 public String mScanPath;
3132
3133 // For use by package manager to keep track of where it has done dexopt.
3134 public boolean mDidDexOpt;
3135
Amith Yamasani13593602012-03-22 16:16:17 -07003136 // // User set enabled state.
3137 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3138 //
3139 // // Whether the package has been stopped.
3140 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 // Additional data supplied by callers.
3143 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003144
3145 // Whether an operation is currently pending on this package
3146 public boolean mOperationPending;
3147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 /*
3149 * Applications hardware preferences
3150 */
3151 public final ArrayList<ConfigurationInfo> configPreferences =
3152 new ArrayList<ConfigurationInfo>();
3153
Dianne Hackborn49237342009-08-27 20:08:01 -07003154 /*
3155 * Applications requested features
3156 */
3157 public ArrayList<FeatureInfo> reqFeatures = null;
3158
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003159 public int installLocation;
3160
Kenny Rootbcc954d2011-08-08 16:19:08 -07003161 /**
3162 * Digest suitable for comparing whether this package's manifest is the
3163 * same as another.
3164 */
3165 public ManifestDigest manifestDigest;
3166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 public Package(String _name) {
3168 packageName = _name;
3169 applicationInfo.packageName = _name;
3170 applicationInfo.uid = -1;
3171 }
3172
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003173 public void setPackageName(String newName) {
3174 packageName = newName;
3175 applicationInfo.packageName = newName;
3176 for (int i=permissions.size()-1; i>=0; i--) {
3177 permissions.get(i).setPackageName(newName);
3178 }
3179 for (int i=permissionGroups.size()-1; i>=0; i--) {
3180 permissionGroups.get(i).setPackageName(newName);
3181 }
3182 for (int i=activities.size()-1; i>=0; i--) {
3183 activities.get(i).setPackageName(newName);
3184 }
3185 for (int i=receivers.size()-1; i>=0; i--) {
3186 receivers.get(i).setPackageName(newName);
3187 }
3188 for (int i=providers.size()-1; i>=0; i--) {
3189 providers.get(i).setPackageName(newName);
3190 }
3191 for (int i=services.size()-1; i>=0; i--) {
3192 services.get(i).setPackageName(newName);
3193 }
3194 for (int i=instrumentation.size()-1; i>=0; i--) {
3195 instrumentation.get(i).setPackageName(newName);
3196 }
3197 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003198
3199 public boolean hasComponentClassName(String name) {
3200 for (int i=activities.size()-1; i>=0; i--) {
3201 if (name.equals(activities.get(i).className)) {
3202 return true;
3203 }
3204 }
3205 for (int i=receivers.size()-1; i>=0; i--) {
3206 if (name.equals(receivers.get(i).className)) {
3207 return true;
3208 }
3209 }
3210 for (int i=providers.size()-1; i>=0; i--) {
3211 if (name.equals(providers.get(i).className)) {
3212 return true;
3213 }
3214 }
3215 for (int i=services.size()-1; i>=0; i--) {
3216 if (name.equals(services.get(i).className)) {
3217 return true;
3218 }
3219 }
3220 for (int i=instrumentation.size()-1; i>=0; i--) {
3221 if (name.equals(instrumentation.get(i).className)) {
3222 return true;
3223 }
3224 }
3225 return false;
3226 }
3227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 public String toString() {
3229 return "Package{"
3230 + Integer.toHexString(System.identityHashCode(this))
3231 + " " + packageName + "}";
3232 }
3233 }
3234
3235 public static class Component<II extends IntentInfo> {
3236 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003237 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003238 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 public Bundle metaData;
3240
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003241 ComponentName componentName;
3242 String componentShortName;
3243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 public Component(Package _owner) {
3245 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003246 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003247 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003248 }
3249
3250 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3251 owner = args.owner;
3252 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003253 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003254 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003255 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003256 args.outError[0] = args.tag + " does not specify android:name";
3257 return;
3258 }
3259
3260 outInfo.name
3261 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3262 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003263 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003264 args.outError[0] = args.tag + " does not have valid android:name";
3265 return;
3266 }
3267
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003268 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003269
3270 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3271 if (iconVal != 0) {
3272 outInfo.icon = iconVal;
3273 outInfo.nonLocalizedLabel = null;
3274 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003275
3276 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3277 if (logoVal != 0) {
3278 outInfo.logo = logoVal;
3279 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003280
3281 TypedValue v = args.sa.peekValue(args.labelRes);
3282 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3283 outInfo.nonLocalizedLabel = v.coerceToString();
3284 }
3285
3286 outInfo.packageName = owner.packageName;
3287 }
3288
3289 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3290 this(args, (PackageItemInfo)outInfo);
3291 if (args.outError[0] != null) {
3292 return;
3293 }
3294
3295 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003296 CharSequence pname;
3297 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3298 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3299 } else {
3300 // Some older apps have been seen to use a resource reference
3301 // here that on older builds was ignored (with a warning). We
3302 // need to continue to do this for them so they don't break.
3303 pname = args.sa.getNonResourceString(args.processRes);
3304 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003305 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003306 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003307 args.flags, args.sepProcesses, args.outError);
3308 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003309
3310 if (args.descriptionRes != 0) {
3311 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3312 }
3313
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003314 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 }
3316
3317 public Component(Component<II> clone) {
3318 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003319 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003320 className = clone.className;
3321 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003322 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003323 }
3324
3325 public ComponentName getComponentName() {
3326 if (componentName != null) {
3327 return componentName;
3328 }
3329 if (className != null) {
3330 componentName = new ComponentName(owner.applicationInfo.packageName,
3331 className);
3332 }
3333 return componentName;
3334 }
3335
3336 public String getComponentShortName() {
3337 if (componentShortName != null) {
3338 return componentShortName;
3339 }
3340 ComponentName component = getComponentName();
3341 if (component != null) {
3342 componentShortName = component.flattenToShortString();
3343 }
3344 return componentShortName;
3345 }
3346
3347 public void setPackageName(String packageName) {
3348 componentName = null;
3349 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 }
3351 }
3352
3353 public final static class Permission extends Component<IntentInfo> {
3354 public final PermissionInfo info;
3355 public boolean tree;
3356 public PermissionGroup group;
3357
3358 public Permission(Package _owner) {
3359 super(_owner);
3360 info = new PermissionInfo();
3361 }
3362
3363 public Permission(Package _owner, PermissionInfo _info) {
3364 super(_owner);
3365 info = _info;
3366 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003367
3368 public void setPackageName(String packageName) {
3369 super.setPackageName(packageName);
3370 info.packageName = packageName;
3371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372
3373 public String toString() {
3374 return "Permission{"
3375 + Integer.toHexString(System.identityHashCode(this))
3376 + " " + info.name + "}";
3377 }
3378 }
3379
3380 public final static class PermissionGroup extends Component<IntentInfo> {
3381 public final PermissionGroupInfo info;
3382
3383 public PermissionGroup(Package _owner) {
3384 super(_owner);
3385 info = new PermissionGroupInfo();
3386 }
3387
3388 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3389 super(_owner);
3390 info = _info;
3391 }
3392
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003393 public void setPackageName(String packageName) {
3394 super.setPackageName(packageName);
3395 info.packageName = packageName;
3396 }
3397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 public String toString() {
3399 return "PermissionGroup{"
3400 + Integer.toHexString(System.identityHashCode(this))
3401 + " " + info.name + "}";
3402 }
3403 }
3404
Amith Yamasani13593602012-03-22 16:16:17 -07003405 private static boolean copyNeeded(int flags, Package p, int enabledState, Bundle metaData) {
3406 if (enabledState != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3407 boolean enabled = enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003408 if (p.applicationInfo.enabled != enabled) {
3409 return true;
3410 }
3411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 if ((flags & PackageManager.GET_META_DATA) != 0
3413 && (metaData != null || p.mAppMetaData != null)) {
3414 return true;
3415 }
3416 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3417 && p.usesLibraryFiles != null) {
3418 return true;
3419 }
3420 return false;
3421 }
3422
Amith Yamasani13593602012-03-22 16:16:17 -07003423 public static ApplicationInfo generateApplicationInfo(Package p, int flags, boolean stopped,
3424 int enabledState) {
3425 return generateApplicationInfo(p, flags, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003426 }
3427
Amith Yamasani13593602012-03-22 16:16:17 -07003428 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3429 boolean stopped, int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003431 if (!copyNeeded(flags, p, enabledState, null) && userId == 0) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003432 // CompatibilityMode is global state. It's safe to modify the instance
3433 // of the package.
3434 if (!sCompatibilityModeEnabled) {
3435 p.applicationInfo.disableCompatibilityMode();
3436 }
Amith Yamasani13593602012-03-22 16:16:17 -07003437 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003438 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3439 } else {
3440 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3441 }
Amith Yamasani13593602012-03-22 16:16:17 -07003442 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003443 p.applicationInfo.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003444 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3445 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003446 p.applicationInfo.enabled = false;
3447 }
Amith Yamasani13593602012-03-22 16:16:17 -07003448 p.applicationInfo.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 return p.applicationInfo;
3450 }
3451
3452 // Make shallow copy so we can store the metadata/libraries safely
3453 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003454 if (userId != 0) {
3455 ai.uid = UserId.getUid(userId, ai.uid);
3456 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 if ((flags & PackageManager.GET_META_DATA) != 0) {
3459 ai.metaData = p.mAppMetaData;
3460 }
3461 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3462 ai.sharedLibraryFiles = p.usesLibraryFiles;
3463 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003464 if (!sCompatibilityModeEnabled) {
3465 ai.disableCompatibilityMode();
3466 }
Amith Yamasani13593602012-03-22 16:16:17 -07003467 if (stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003468 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003469 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003470 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003471 }
Amith Yamasani13593602012-03-22 16:16:17 -07003472 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003473 ai.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003474 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3475 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003476 ai.enabled = false;
3477 }
Amith Yamasani13593602012-03-22 16:16:17 -07003478 ai.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 return ai;
3480 }
3481
3482 public static final PermissionInfo generatePermissionInfo(
3483 Permission p, int flags) {
3484 if (p == null) return null;
3485 if ((flags&PackageManager.GET_META_DATA) == 0) {
3486 return p.info;
3487 }
3488 PermissionInfo pi = new PermissionInfo(p.info);
3489 pi.metaData = p.metaData;
3490 return pi;
3491 }
3492
3493 public static final PermissionGroupInfo generatePermissionGroupInfo(
3494 PermissionGroup pg, int flags) {
3495 if (pg == null) return null;
3496 if ((flags&PackageManager.GET_META_DATA) == 0) {
3497 return pg.info;
3498 }
3499 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3500 pgi.metaData = pg.metaData;
3501 return pgi;
3502 }
3503
3504 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003505 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003507 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3508 super(args, _info);
3509 info = _info;
3510 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003512
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003513 public void setPackageName(String packageName) {
3514 super.setPackageName(packageName);
3515 info.packageName = packageName;
3516 }
3517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 public String toString() {
3519 return "Activity{"
3520 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003521 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 }
3523 }
3524
Amith Yamasani13593602012-03-22 16:16:17 -07003525 public static final ActivityInfo generateActivityInfo(Activity a, int flags, boolean stopped,
3526 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 if (a == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003528 if (!copyNeeded(flags, a.owner, enabledState, a.metaData) && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 return a.info;
3530 }
3531 // Make shallow copies so we can store the metadata safely
3532 ActivityInfo ai = new ActivityInfo(a.info);
3533 ai.metaData = a.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003534 ai.applicationInfo = generateApplicationInfo(a.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 return ai;
3536 }
3537
3538 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003539 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003541 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3542 super(args, _info);
3543 info = _info;
3544 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003546
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003547 public void setPackageName(String packageName) {
3548 super.setPackageName(packageName);
3549 info.packageName = packageName;
3550 }
3551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 public String toString() {
3553 return "Service{"
3554 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003555 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 }
3557 }
3558
Amith Yamasani13593602012-03-22 16:16:17 -07003559 public static final ServiceInfo generateServiceInfo(Service s, int flags, boolean stopped,
3560 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 if (s == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003562 if (!copyNeeded(flags, s.owner, enabledState, s.metaData)
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003563 && userId == UserId.getUserId(s.info.applicationInfo.uid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 return s.info;
3565 }
3566 // Make shallow copies so we can store the metadata safely
3567 ServiceInfo si = new ServiceInfo(s.info);
3568 si.metaData = s.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003569 si.applicationInfo = generateApplicationInfo(s.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 return si;
3571 }
3572
3573 public final static class Provider extends Component {
3574 public final ProviderInfo info;
3575 public boolean syncable;
3576
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003577 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3578 super(args, _info);
3579 info = _info;
3580 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 syncable = false;
3582 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 public Provider(Provider existingProvider) {
3585 super(existingProvider);
3586 this.info = existingProvider.info;
3587 this.syncable = existingProvider.syncable;
3588 }
3589
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003590 public void setPackageName(String packageName) {
3591 super.setPackageName(packageName);
3592 info.packageName = packageName;
3593 }
3594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 public String toString() {
3596 return "Provider{"
3597 + Integer.toHexString(System.identityHashCode(this))
3598 + " " + info.name + "}";
3599 }
3600 }
3601
Amith Yamasani13593602012-03-22 16:16:17 -07003602 public static final ProviderInfo generateProviderInfo(Provider p, int flags, boolean stopped,
3603 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003605 if (!copyNeeded(flags, p.owner, enabledState, p.metaData)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Amith Yamasani742a6712011-05-04 14:49:28 -07003607 || p.info.uriPermissionPatterns == null)
3608 && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 return p.info;
3610 }
3611 // Make shallow copies so we can store the metadata safely
3612 ProviderInfo pi = new ProviderInfo(p.info);
3613 pi.metaData = p.metaData;
3614 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3615 pi.uriPermissionPatterns = null;
3616 }
Amith Yamasani13593602012-03-22 16:16:17 -07003617 pi.applicationInfo = generateApplicationInfo(p.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 return pi;
3619 }
3620
3621 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003622 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003624 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3625 super(args, _info);
3626 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003628
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003629 public void setPackageName(String packageName) {
3630 super.setPackageName(packageName);
3631 info.packageName = packageName;
3632 }
3633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 public String toString() {
3635 return "Instrumentation{"
3636 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003637 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 }
3639 }
3640
3641 public static final InstrumentationInfo generateInstrumentationInfo(
3642 Instrumentation i, int flags) {
3643 if (i == null) return null;
3644 if ((flags&PackageManager.GET_META_DATA) == 0) {
3645 return i.info;
3646 }
3647 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3648 ii.metaData = i.metaData;
3649 return ii;
3650 }
3651
3652 public static class IntentInfo extends IntentFilter {
3653 public boolean hasDefault;
3654 public int labelRes;
3655 public CharSequence nonLocalizedLabel;
3656 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003657 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 }
3659
3660 public final static class ActivityIntentInfo extends IntentInfo {
3661 public final Activity activity;
3662
3663 public ActivityIntentInfo(Activity _activity) {
3664 activity = _activity;
3665 }
3666
3667 public String toString() {
3668 return "ActivityIntentInfo{"
3669 + Integer.toHexString(System.identityHashCode(this))
3670 + " " + activity.info.name + "}";
3671 }
3672 }
3673
3674 public final static class ServiceIntentInfo extends IntentInfo {
3675 public final Service service;
3676
3677 public ServiceIntentInfo(Service _service) {
3678 service = _service;
3679 }
3680
3681 public String toString() {
3682 return "ServiceIntentInfo{"
3683 + Integer.toHexString(System.identityHashCode(this))
3684 + " " + service.info.name + "}";
3685 }
3686 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003687
3688 /**
3689 * @hide
3690 */
3691 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3692 sCompatibilityModeEnabled = compatibilityModeEnabled;
3693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694}