blob: eb8536f4ce597bec950a6af93fd48db61719da38 [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;
97
98 public SplitPermissionInfo(String rootPerm, String[] newPerms) {
99 this.rootPerm = rootPerm;
100 this.newPerms = newPerms;
101 }
102 }
103
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700104 /**
105 * List of new permissions that have been added since 1.0.
106 * NOTE: These must be declared in SDK version order, with permissions
107 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700108 * If sdkVersion is 0, then this is not a permission that we want to
109 * automatically add to older apps, but we do want to allow it to be
110 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700111 * @hide
112 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700113 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
114 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700115 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700116 android.os.Build.VERSION_CODES.DONUT, 0),
117 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
118 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700119 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
Dianne Hackborn79245122012-03-12 10:51:26 -0700121 /**
122 * List of permissions that have been split into more granular or dependent
123 * permissions.
124 * @hide
125 */
126 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
127 new PackageParser.SplitPermissionInfo[] {
128 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
129 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE })
130 };
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 private String mArchiveSourcePath;
133 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700134 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700135 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
136 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
137 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
139 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
140
141 private static final Object mSync = new Object();
142 private static WeakReference<byte[]> mReadBuffer;
143
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700144 private static boolean sCompatibilityModeEnabled = true;
145 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700146
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700147 static class ParsePackageItemArgs {
148 final Package owner;
149 final String[] outError;
150 final int nameRes;
151 final int labelRes;
152 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700153 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700154
155 String tag;
156 TypedArray sa;
157
158 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700159 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700160 owner = _owner;
161 outError = _outError;
162 nameRes = _nameRes;
163 labelRes = _labelRes;
164 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700165 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700166 }
167 }
168
169 static class ParseComponentArgs extends ParsePackageItemArgs {
170 final String[] sepProcesses;
171 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800172 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700173 final int enabledRes;
174 int flags;
175
176 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700177 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800178 String[] _sepProcesses, int _processRes,
179 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700180 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700181 sepProcesses = _sepProcesses;
182 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800183 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 enabledRes = _enabledRes;
185 }
186 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800187
188 /* Light weight package info.
189 * @hide
190 */
191 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700192 public final String packageName;
193 public final int installLocation;
194 public final VerifierInfo[] verifiers;
195
196 public PackageLite(String packageName, int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800197 this.packageName = packageName;
198 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700199 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800200 }
201 }
202
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700203 private ParsePackageItemArgs mParseInstrumentationArgs;
204 private ParseComponentArgs mParseActivityArgs;
205 private ParseComponentArgs mParseActivityAliasArgs;
206 private ParseComponentArgs mParseServiceArgs;
207 private ParseComponentArgs mParseProviderArgs;
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 /** If set to true, we will only allow package files that exactly match
210 * the DTD. Otherwise, we try to get as much from the package as we
211 * can without failing. This should normally be set to false, to
212 * support extensions to the DTD in future versions. */
213 private static final boolean RIGID_PARSER = false;
214
215 private static final String TAG = "PackageParser";
216
217 public PackageParser(String archiveSourcePath) {
218 mArchiveSourcePath = archiveSourcePath;
219 }
220
221 public void setSeparateProcesses(String[] procs) {
222 mSeparateProcesses = procs;
223 }
224
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700225 public void setOnlyCoreApps(boolean onlyCoreApps) {
226 mOnlyCoreApps = onlyCoreApps;
227 }
228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 private static final boolean isPackageFilename(String name) {
230 return name.endsWith(".apk");
231 }
232
Amith Yamasani13593602012-03-22 16:16:17 -0700233 public static PackageInfo generatePackageInfo(PackageParser.Package p,
234 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
235 HashSet<String> grantedPermissions) {
236
237 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
238 grantedPermissions, false, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
239 UserId.getCallingUserId());
240 }
241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 /**
243 * Generate and return the {@link PackageInfo} for a parsed package.
244 *
245 * @param p the parsed package.
246 * @param flags indicating which optional information is included.
247 */
248 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800249 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700250 HashSet<String> grantedPermissions, boolean stopped, int enabledState) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251
Amith Yamasani483f3b02012-03-13 16:08:00 -0700252 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700253 grantedPermissions, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani483f3b02012-03-13 16:08:00 -0700254 }
255
Amith Yamasani13593602012-03-22 16:16:17 -0700256 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700257 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700258 HashSet<String> grantedPermissions, boolean stopped, int enabledState, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 PackageInfo pi = new PackageInfo();
261 pi.packageName = p.packageName;
262 pi.versionCode = p.mVersionCode;
263 pi.versionName = p.mVersionName;
264 pi.sharedUserId = p.mSharedUserId;
265 pi.sharedUserLabel = p.mSharedUserLabel;
Amith Yamasani13593602012-03-22 16:16:17 -0700266 pi.applicationInfo = generateApplicationInfo(p, flags, stopped, enabledState, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800267 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700268 pi.firstInstallTime = firstInstallTime;
269 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 if ((flags&PackageManager.GET_GIDS) != 0) {
271 pi.gids = gids;
272 }
273 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
274 int N = p.configPreferences.size();
275 if (N > 0) {
276 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700277 p.configPreferences.toArray(pi.configPreferences);
278 }
279 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
280 if (N > 0) {
281 pi.reqFeatures = new FeatureInfo[N];
282 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 }
284 }
285 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
286 int N = p.activities.size();
287 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700288 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
289 pi.activities = new ActivityInfo[N];
290 } else {
291 int num = 0;
292 for (int i=0; i<N; i++) {
293 if (p.activities.get(i).info.enabled) num++;
294 }
295 pi.activities = new ActivityInfo[num];
296 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700297 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 final Activity activity = p.activities.get(i);
299 if (activity.info.enabled
300 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700301 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Amith Yamasani13593602012-03-22 16:16:17 -0700302 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 }
304 }
305 }
306 }
307 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
308 int N = p.receivers.size();
309 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700310 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
311 pi.receivers = new ActivityInfo[N];
312 } else {
313 int num = 0;
314 for (int i=0; i<N; i++) {
315 if (p.receivers.get(i).info.enabled) num++;
316 }
317 pi.receivers = new ActivityInfo[num];
318 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700319 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 final Activity activity = p.receivers.get(i);
321 if (activity.info.enabled
322 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700323 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
324 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 }
326 }
327 }
328 }
329 if ((flags&PackageManager.GET_SERVICES) != 0) {
330 int N = p.services.size();
331 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700332 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
333 pi.services = new ServiceInfo[N];
334 } else {
335 int num = 0;
336 for (int i=0; i<N; i++) {
337 if (p.services.get(i).info.enabled) num++;
338 }
339 pi.services = new ServiceInfo[num];
340 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700341 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 final Service service = p.services.get(i);
343 if (service.info.enabled
344 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700345 pi.services[j++] = generateServiceInfo(p.services.get(i), flags, stopped,
346 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348 }
349 }
350 }
351 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
352 int N = p.providers.size();
353 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700354 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
355 pi.providers = new ProviderInfo[N];
356 } else {
357 int num = 0;
358 for (int i=0; i<N; i++) {
359 if (p.providers.get(i).info.enabled) num++;
360 }
361 pi.providers = new ProviderInfo[num];
362 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700363 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 final Provider provider = p.providers.get(i);
365 if (provider.info.enabled
366 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700367 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, stopped,
368 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 }
370 }
371 }
372 }
373 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
374 int N = p.instrumentation.size();
375 if (N > 0) {
376 pi.instrumentation = new InstrumentationInfo[N];
377 for (int i=0; i<N; i++) {
378 pi.instrumentation[i] = generateInstrumentationInfo(
379 p.instrumentation.get(i), flags);
380 }
381 }
382 }
383 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
384 int N = p.permissions.size();
385 if (N > 0) {
386 pi.permissions = new PermissionInfo[N];
387 for (int i=0; i<N; i++) {
388 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
389 }
390 }
391 N = p.requestedPermissions.size();
392 if (N > 0) {
393 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800394 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800396 final String perm = p.requestedPermissions.get(i);
397 pi.requestedPermissions[i] = perm;
398 if (p.requestedPermissionsRequired.get(i)) {
399 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
400 }
401 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
402 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 }
405 }
406 }
407 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700408 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
409 if (N > 0) {
410 pi.signatures = new Signature[N];
411 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
413 }
414 return pi;
415 }
416
417 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
418 byte[] readBuffer) {
419 try {
420 // We must read the stream for the JarEntry to retrieve
421 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700422 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
424 // not using
425 }
426 is.close();
427 return je != null ? je.getCertificates() : null;
428 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700429 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700431 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700432 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700433 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 }
435 return null;
436 }
437
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800438 public final static int PARSE_IS_SYSTEM = 1<<0;
439 public final static int PARSE_CHATTY = 1<<1;
440 public final static int PARSE_MUST_BE_APK = 1<<2;
441 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
442 public final static int PARSE_FORWARD_LOCK = 1<<4;
443 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700444 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445
446 public int getParseError() {
447 return mParseError;
448 }
449
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800450 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 DisplayMetrics metrics, int flags) {
452 mParseError = PackageManager.INSTALL_SUCCEEDED;
453
454 mArchiveSourcePath = sourceFile.getPath();
455 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700456 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
458 return null;
459 }
460 if (!isPackageFilename(sourceFile.getName())
461 && (flags&PARSE_MUST_BE_APK) != 0) {
462 if ((flags&PARSE_IS_SYSTEM) == 0) {
463 // We expect to have non-.apk files in the system dir,
464 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700465 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 }
467 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
468 return null;
469 }
470
Kenny Rootd2d29252011-08-08 11:27:57 -0700471 if (DEBUG_JAR)
472 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473
474 XmlResourceParser parser = null;
475 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800476 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 boolean assetError = true;
478 try {
479 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700480 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800481 if (cookie != 0) {
482 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700483 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 -0800484 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700485 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 assetError = false;
487 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700488 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 }
490 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700491 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 + mArchiveSourcePath, e);
493 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800494 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 if (assmgr != null) assmgr.close();
496 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
497 return null;
498 }
499 String[] errorText = new String[1];
500 Package pkg = null;
501 Exception errorException = null;
502 try {
503 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 pkg = parsePackage(res, parser, flags, errorText);
505 } catch (Exception e) {
506 errorException = e;
507 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
508 }
509
510
511 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700512 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
513 // just means to skip this app so don't make a fuss about it.
514 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
515 if (errorException != null) {
516 Slog.w(TAG, mArchiveSourcePath, errorException);
517 } else {
518 Slog.w(TAG, mArchiveSourcePath + " (at "
519 + parser.getPositionDescription()
520 + "): " + errorText[0]);
521 }
522 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
523 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 }
526 parser.close();
527 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 return null;
529 }
530
531 parser.close();
532 assmgr.close();
533
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800534 // Set code and resource paths
535 pkg.mPath = destCodePath;
536 pkg.mScanPath = mArchiveSourcePath;
537 //pkg.applicationInfo.sourceDir = destCodePath;
538 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 pkg.mSignatures = null;
540
541 return pkg;
542 }
543
544 public boolean collectCertificates(Package pkg, int flags) {
545 pkg.mSignatures = null;
546
547 WeakReference<byte[]> readBufferRef;
548 byte[] readBuffer = null;
549 synchronized (mSync) {
550 readBufferRef = mReadBuffer;
551 if (readBufferRef != null) {
552 mReadBuffer = null;
553 readBuffer = readBufferRef.get();
554 }
555 if (readBuffer == null) {
556 readBuffer = new byte[8192];
557 readBufferRef = new WeakReference<byte[]>(readBuffer);
558 }
559 }
560
561 try {
562 JarFile jarFile = new JarFile(mArchiveSourcePath);
563
564 Certificate[] certs = null;
565
566 if ((flags&PARSE_IS_SYSTEM) != 0) {
567 // If this package comes from the system image, then we
568 // can trust it... we'll just use the AndroidManifest.xml
569 // to retrieve its signatures, not validating all of the
570 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700571 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 certs = loadCertificates(jarFile, jarEntry, readBuffer);
573 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700574 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 + " has no certificates at entry "
576 + jarEntry.getName() + "; ignoring!");
577 jarFile.close();
578 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
579 return false;
580 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700581 if (DEBUG_JAR) {
582 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 + " certs=" + (certs != null ? certs.length : 0));
584 if (certs != null) {
585 final int N = certs.length;
586 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700587 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 + certs[i].getPublicKey().getEncoded()
589 + " " + certs[i].getPublicKey());
590 }
591 }
592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700594 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700595 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700597 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700599
Kenny Rootbcc954d2011-08-08 16:19:08 -0700600 final String name = je.getName();
601
602 if (name.startsWith("META-INF/"))
603 continue;
604
605 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
606 final Attributes attributes = manifest.getAttributes(name);
607 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
608 }
609
610 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700611 if (DEBUG_JAR) {
612 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 + ": certs=" + certs + " ("
614 + (certs != null ? certs.length : 0) + ")");
615 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700618 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 + " has no certificates at entry "
620 + je.getName() + "; ignoring!");
621 jarFile.close();
622 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
623 return false;
624 } else if (certs == null) {
625 certs = localCerts;
626 } else {
627 // Ensure all certificates match.
628 for (int i=0; i<certs.length; i++) {
629 boolean found = false;
630 for (int j=0; j<localCerts.length; j++) {
631 if (certs[i] != null &&
632 certs[i].equals(localCerts[j])) {
633 found = true;
634 break;
635 }
636 }
637 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700638 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 + " has mismatched certificates at entry "
640 + je.getName() + "; ignoring!");
641 jarFile.close();
642 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
643 return false;
644 }
645 }
646 }
647 }
648 }
649 jarFile.close();
650
651 synchronized (mSync) {
652 mReadBuffer = readBufferRef;
653 }
654
655 if (certs != null && certs.length > 0) {
656 final int N = certs.length;
657 pkg.mSignatures = new Signature[certs.length];
658 for (int i=0; i<N; i++) {
659 pkg.mSignatures[i] = new Signature(
660 certs[i].getEncoded());
661 }
662 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700663 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 + " has no certificates; ignoring!");
665 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
666 return false;
667 }
668 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700669 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
671 return false;
672 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700673 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
675 return false;
676 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700677 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
679 return false;
680 }
681
682 return true;
683 }
684
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800685 /*
686 * Utility method that retrieves just the package name and install
687 * location from the apk location at the given file path.
688 * @param packageFilePath file location of the apk
689 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700690 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800691 */
692 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700694 final XmlResourceParser parser;
695 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 try {
697 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700698 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 -0800699 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700702 if (cookie == 0) {
703 return null;
704 }
705
Kenny Root05ca4c92011-09-15 10:36:25 -0700706 final DisplayMetrics metrics = new DisplayMetrics();
707 metrics.setToDefaults();
708 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700709 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 } catch (Exception e) {
711 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700712 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 + packageFilePath, e);
714 return null;
715 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700716
717 final AttributeSet attrs = parser;
718 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800719 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700721 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700723 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700725 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 } finally {
727 if (parser != null) parser.close();
728 if (assmgr != null) assmgr.close();
729 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800730 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700731 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 return null;
733 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800734 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 }
736
737 private static String validateName(String name, boolean requiresSeparator) {
738 final int N = name.length();
739 boolean hasSep = false;
740 boolean front = true;
741 for (int i=0; i<N; i++) {
742 final char c = name.charAt(i);
743 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
744 front = false;
745 continue;
746 }
747 if (!front) {
748 if ((c >= '0' && c <= '9') || c == '_') {
749 continue;
750 }
751 }
752 if (c == '.') {
753 hasSep = true;
754 front = true;
755 continue;
756 }
757 return "bad character '" + c + "'";
758 }
759 return hasSep || !requiresSeparator
760 ? null : "must have at least one '.' separator";
761 }
762
763 private static String parsePackageName(XmlPullParser parser,
764 AttributeSet attrs, int flags, String[] outError)
765 throws IOException, XmlPullParserException {
766
767 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700768 while ((type = parser.next()) != XmlPullParser.START_TAG
769 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 ;
771 }
772
Kenny Rootd2d29252011-08-08 11:27:57 -0700773 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 outError[0] = "No start tag found";
775 return null;
776 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700777 if (DEBUG_PARSER)
778 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 if (!parser.getName().equals("manifest")) {
780 outError[0] = "No <manifest> tag";
781 return null;
782 }
783 String pkgName = attrs.getAttributeValue(null, "package");
784 if (pkgName == null || pkgName.length() == 0) {
785 outError[0] = "<manifest> does not specify package";
786 return null;
787 }
788 String nameError = validateName(pkgName, true);
789 if (nameError != null && !"android".equals(pkgName)) {
790 outError[0] = "<manifest> specifies bad package name \""
791 + pkgName + "\": " + nameError;
792 return null;
793 }
794
795 return pkgName.intern();
796 }
797
Kenny Root05ca4c92011-09-15 10:36:25 -0700798 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
799 AttributeSet attrs, int flags, String[] outError) throws IOException,
800 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800801
802 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700803 while ((type = parser.next()) != XmlPullParser.START_TAG
804 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800805 ;
806 }
807
Kenny Rootd2d29252011-08-08 11:27:57 -0700808 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800809 outError[0] = "No start tag found";
810 return null;
811 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700812 if (DEBUG_PARSER)
813 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800814 if (!parser.getName().equals("manifest")) {
815 outError[0] = "No <manifest> tag";
816 return null;
817 }
818 String pkgName = attrs.getAttributeValue(null, "package");
819 if (pkgName == null || pkgName.length() == 0) {
820 outError[0] = "<manifest> does not specify package";
821 return null;
822 }
823 String nameError = validateName(pkgName, true);
824 if (nameError != null && !"android".equals(pkgName)) {
825 outError[0] = "<manifest> specifies bad package name \""
826 + pkgName + "\": " + nameError;
827 return null;
828 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700829 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800830 for (int i = 0; i < attrs.getAttributeCount(); i++) {
831 String attr = attrs.getAttributeName(i);
832 if (attr.equals("installLocation")) {
833 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700834 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800835 break;
836 }
837 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700838
839 // Only search the tree when the tag is directly below <manifest>
840 final int searchDepth = parser.getDepth() + 1;
841
842 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
843 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
844 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
845 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
846 continue;
847 }
848
849 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
850 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
851 if (verifier != null) {
852 verifiers.add(verifier);
853 }
854 }
855 }
856
857 return new PackageLite(pkgName.intern(), installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800858 }
859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 /**
861 * Temporary.
862 */
863 static public Signature stringToSignature(String str) {
864 final int N = str.length();
865 byte[] sig = new byte[N];
866 for (int i=0; i<N; i++) {
867 sig[i] = (byte)str.charAt(i);
868 }
869 return new Signature(sig);
870 }
871
872 private Package parsePackage(
873 Resources res, XmlResourceParser parser, int flags, String[] outError)
874 throws XmlPullParserException, IOException {
875 AttributeSet attrs = parser;
876
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700877 mParseInstrumentationArgs = null;
878 mParseActivityArgs = null;
879 mParseServiceArgs = null;
880 mParseProviderArgs = null;
881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 String pkgName = parsePackageName(parser, attrs, flags, outError);
883 if (pkgName == null) {
884 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
885 return null;
886 }
887 int type;
888
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700889 if (mOnlyCoreApps) {
890 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
891 if (!core) {
892 mParseError = PackageManager.INSTALL_SUCCEEDED;
893 return null;
894 }
895 }
896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 TypedArray sa = res.obtainAttributes(attrs,
901 com.android.internal.R.styleable.AndroidManifest);
902 pkg.mVersionCode = sa.getInteger(
903 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800904 pkg.mVersionName = sa.getNonConfigurationString(
905 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 if (pkg.mVersionName != null) {
907 pkg.mVersionName = pkg.mVersionName.intern();
908 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800909 String str = sa.getNonConfigurationString(
910 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
911 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 String nameError = validateName(str, true);
913 if (nameError != null && !"android".equals(pkgName)) {
914 outError[0] = "<manifest> specifies bad sharedUserId name \""
915 + str + "\": " + nameError;
916 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
917 return null;
918 }
919 pkg.mSharedUserId = str.intern();
920 pkg.mSharedUserLabel = sa.getResourceId(
921 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
922 }
923 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800924
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800925 pkg.installLocation = sa.getInteger(
926 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700927 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700928 pkg.applicationInfo.installLocation = pkg.installLocation;
929
Dianne Hackborn723738c2009-06-25 19:48:04 -0700930 // Resource boolean are -1, so 1 means we don't know the value.
931 int supportsSmallScreens = 1;
932 int supportsNormalScreens = 1;
933 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700934 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700935 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700936 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700939 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
940 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
941 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 continue;
943 }
944
945 String tagName = parser.getName();
946 if (tagName.equals("application")) {
947 if (foundApp) {
948 if (RIGID_PARSER) {
949 outError[0] = "<manifest> has more than one <application>";
950 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
951 return null;
952 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700953 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 XmlUtils.skipCurrentTag(parser);
955 continue;
956 }
957 }
958
959 foundApp = true;
960 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
961 return null;
962 }
963 } else if (tagName.equals("permission-group")) {
964 if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) {
965 return null;
966 }
967 } else if (tagName.equals("permission")) {
968 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
969 return null;
970 }
971 } else if (tagName.equals("permission-tree")) {
972 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
973 return null;
974 }
975 } else if (tagName.equals("uses-permission")) {
976 sa = res.obtainAttributes(attrs,
977 com.android.internal.R.styleable.AndroidManifestUsesPermission);
978
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800979 // Note: don't allow this value to be a reference to a resource
980 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 String name = sa.getNonResourceString(
982 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne639da72012-02-21 15:11:13 -0800983 boolean required = sa.getBoolean(
984 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985
986 sa.recycle();
987
988 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -0700989 pkg.requestedPermissions.add(name.intern());
Dianne Hackborn65696252012-03-05 18:49:21 -0800990 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 }
992
993 XmlUtils.skipCurrentTag(parser);
994
995 } else if (tagName.equals("uses-configuration")) {
996 ConfigurationInfo cPref = new ConfigurationInfo();
997 sa = res.obtainAttributes(attrs,
998 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
999 cPref.reqTouchScreen = sa.getInt(
1000 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1001 Configuration.TOUCHSCREEN_UNDEFINED);
1002 cPref.reqKeyboardType = sa.getInt(
1003 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1004 Configuration.KEYBOARD_UNDEFINED);
1005 if (sa.getBoolean(
1006 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1007 false)) {
1008 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1009 }
1010 cPref.reqNavigation = sa.getInt(
1011 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1012 Configuration.NAVIGATION_UNDEFINED);
1013 if (sa.getBoolean(
1014 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1015 false)) {
1016 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1017 }
1018 sa.recycle();
1019 pkg.configPreferences.add(cPref);
1020
1021 XmlUtils.skipCurrentTag(parser);
1022
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001023 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001024 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001025 sa = res.obtainAttributes(attrs,
1026 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001027 // Note: don't allow this value to be a reference to a resource
1028 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001029 fi.name = sa.getNonResourceString(
1030 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1031 if (fi.name == null) {
1032 fi.reqGlEsVersion = sa.getInt(
1033 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1034 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1035 }
1036 if (sa.getBoolean(
1037 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1038 true)) {
1039 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1040 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001041 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001042 if (pkg.reqFeatures == null) {
1043 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1044 }
1045 pkg.reqFeatures.add(fi);
1046
1047 if (fi.name == null) {
1048 ConfigurationInfo cPref = new ConfigurationInfo();
1049 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1050 pkg.configPreferences.add(cPref);
1051 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001052
1053 XmlUtils.skipCurrentTag(parser);
1054
Dianne Hackborn851a5412009-05-08 12:06:44 -07001055 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001056 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 sa = res.obtainAttributes(attrs,
1058 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1059
Dianne Hackborn851a5412009-05-08 12:06:44 -07001060 int minVers = 0;
1061 String minCode = null;
1062 int targetVers = 0;
1063 String targetCode = null;
1064
1065 TypedValue val = sa.peekValue(
1066 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1067 if (val != null) {
1068 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1069 targetCode = minCode = val.string.toString();
1070 } else {
1071 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001072 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001073 }
1074 }
1075
1076 val = sa.peekValue(
1077 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
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.
1083 targetVers = val.data;
1084 }
1085 }
1086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 sa.recycle();
1088
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001089 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001090 if (!minCode.equals(SDK_CODENAME)) {
1091 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001092 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001093 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001094 } else {
1095 outError[0] = "Requires development platform " + minCode
1096 + " but this is a release platform.";
1097 }
1098 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1099 return null;
1100 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001101 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001102 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001103 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001104 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1105 return null;
1106 }
1107
Dianne Hackborn851a5412009-05-08 12:06:44 -07001108 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001109 if (!targetCode.equals(SDK_CODENAME)) {
1110 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001111 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001112 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001113 } else {
1114 outError[0] = "Requires development platform " + targetCode
1115 + " but this is a release platform.";
1116 }
1117 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1118 return null;
1119 }
1120 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001121 pkg.applicationInfo.targetSdkVersion
1122 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1123 } else {
1124 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
1127
1128 XmlUtils.skipCurrentTag(parser);
1129
Dianne Hackborn723738c2009-06-25 19:48:04 -07001130 } else if (tagName.equals("supports-screens")) {
1131 sa = res.obtainAttributes(attrs,
1132 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1133
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001134 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1135 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1136 0);
1137 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1138 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1139 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001140 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1141 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1142 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001143
Dianne Hackborn723738c2009-06-25 19:48:04 -07001144 // This is a trick to get a boolean and still able to detect
1145 // if a value was actually set.
1146 supportsSmallScreens = sa.getInteger(
1147 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1148 supportsSmallScreens);
1149 supportsNormalScreens = sa.getInteger(
1150 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1151 supportsNormalScreens);
1152 supportsLargeScreens = sa.getInteger(
1153 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1154 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001155 supportsXLargeScreens = sa.getInteger(
1156 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1157 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001158 resizeable = sa.getInteger(
1159 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001160 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001161 anyDensity = sa.getInteger(
1162 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1163 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001164
1165 sa.recycle();
1166
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001167 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001168
1169 } else if (tagName.equals("protected-broadcast")) {
1170 sa = res.obtainAttributes(attrs,
1171 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1172
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001173 // Note: don't allow this value to be a reference to a resource
1174 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001175 String name = sa.getNonResourceString(
1176 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1177
1178 sa.recycle();
1179
1180 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1181 if (pkg.protectedBroadcasts == null) {
1182 pkg.protectedBroadcasts = new ArrayList<String>();
1183 }
1184 if (!pkg.protectedBroadcasts.contains(name)) {
1185 pkg.protectedBroadcasts.add(name.intern());
1186 }
1187 }
1188
1189 XmlUtils.skipCurrentTag(parser);
1190
1191 } else if (tagName.equals("instrumentation")) {
1192 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1193 return null;
1194 }
1195
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001196 } else if (tagName.equals("original-package")) {
1197 sa = res.obtainAttributes(attrs,
1198 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1199
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001200 String orig =sa.getNonConfigurationString(
1201 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001202 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001203 if (pkg.mOriginalPackages == null) {
1204 pkg.mOriginalPackages = new ArrayList<String>();
1205 pkg.mRealPackage = pkg.packageName;
1206 }
1207 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001208 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001209
1210 sa.recycle();
1211
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001212 XmlUtils.skipCurrentTag(parser);
1213
1214 } else if (tagName.equals("adopt-permissions")) {
1215 sa = res.obtainAttributes(attrs,
1216 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1217
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001218 String name = sa.getNonConfigurationString(
1219 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001220
1221 sa.recycle();
1222
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001223 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001224 if (pkg.mAdoptPermissions == null) {
1225 pkg.mAdoptPermissions = new ArrayList<String>();
1226 }
1227 pkg.mAdoptPermissions.add(name);
1228 }
1229
1230 XmlUtils.skipCurrentTag(parser);
1231
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001232 } else if (tagName.equals("uses-gl-texture")) {
1233 // Just skip this tag
1234 XmlUtils.skipCurrentTag(parser);
1235 continue;
1236
1237 } else if (tagName.equals("compatible-screens")) {
1238 // Just skip this tag
1239 XmlUtils.skipCurrentTag(parser);
1240 continue;
1241
Dianne Hackborn854060a2009-07-09 18:14:31 -07001242 } else if (tagName.equals("eat-comment")) {
1243 // Just skip this tag
1244 XmlUtils.skipCurrentTag(parser);
1245 continue;
1246
1247 } else if (RIGID_PARSER) {
1248 outError[0] = "Bad element under <manifest>: "
1249 + parser.getName();
1250 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1251 return null;
1252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001254 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001255 + " at " + mArchiveSourcePath + " "
1256 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 XmlUtils.skipCurrentTag(parser);
1258 continue;
1259 }
1260 }
1261
1262 if (!foundApp && pkg.instrumentation.size() == 0) {
1263 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1264 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1265 }
1266
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001267 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001268 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001269 for (int ip=0; ip<NP; ip++) {
1270 final PackageParser.NewPermissionInfo npi
1271 = PackageParser.NEW_PERMISSIONS[ip];
1272 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1273 break;
1274 }
1275 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001276 if (implicitPerms == null) {
1277 implicitPerms = new StringBuilder(128);
1278 implicitPerms.append(pkg.packageName);
1279 implicitPerms.append(": compat added ");
1280 } else {
1281 implicitPerms.append(' ');
1282 }
1283 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001284 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001285 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001286 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001287 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001288 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001289 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001290 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001291
1292 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1293 for (int is=0; is<NS; is++) {
1294 final PackageParser.SplitPermissionInfo spi
1295 = PackageParser.SPLIT_PERMISSIONS[is];
1296 if (!pkg.requestedPermissions.contains(spi.rootPerm)) {
1297 break;
1298 }
1299 for (int in=0; in<spi.newPerms.length; in++) {
1300 final String perm = spi.newPerms[in];
1301 if (!pkg.requestedPermissions.contains(perm)) {
1302 pkg.requestedPermissions.add(perm);
1303 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1304 }
1305 }
1306 }
1307
Dianne Hackborn723738c2009-06-25 19:48:04 -07001308 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1309 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001310 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001311 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1312 }
1313 if (supportsNormalScreens != 0) {
1314 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1315 }
1316 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1317 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001318 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001319 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1320 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001321 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1322 && pkg.applicationInfo.targetSdkVersion
1323 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1324 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1325 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001326 if (resizeable < 0 || (resizeable > 0
1327 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001328 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001329 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1330 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001331 if (anyDensity < 0 || (anyDensity > 0
1332 && pkg.applicationInfo.targetSdkVersion
1333 >= android.os.Build.VERSION_CODES.DONUT)) {
1334 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001335 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 return pkg;
1338 }
1339
1340 private static String buildClassName(String pkg, CharSequence clsSeq,
1341 String[] outError) {
1342 if (clsSeq == null || clsSeq.length() <= 0) {
1343 outError[0] = "Empty class name in package " + pkg;
1344 return null;
1345 }
1346 String cls = clsSeq.toString();
1347 char c = cls.charAt(0);
1348 if (c == '.') {
1349 return (pkg + cls).intern();
1350 }
1351 if (cls.indexOf('.') < 0) {
1352 StringBuilder b = new StringBuilder(pkg);
1353 b.append('.');
1354 b.append(cls);
1355 return b.toString().intern();
1356 }
1357 if (c >= 'a' && c <= 'z') {
1358 return cls.intern();
1359 }
1360 outError[0] = "Bad class name " + cls + " in package " + pkg;
1361 return null;
1362 }
1363
1364 private static String buildCompoundName(String pkg,
1365 CharSequence procSeq, String type, String[] outError) {
1366 String proc = procSeq.toString();
1367 char c = proc.charAt(0);
1368 if (pkg != null && c == ':') {
1369 if (proc.length() < 2) {
1370 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1371 + ": must be at least two characters";
1372 return null;
1373 }
1374 String subName = proc.substring(1);
1375 String nameError = validateName(subName, false);
1376 if (nameError != null) {
1377 outError[0] = "Invalid " + type + " name " + proc + " in package "
1378 + pkg + ": " + nameError;
1379 return null;
1380 }
1381 return (pkg + proc).intern();
1382 }
1383 String nameError = validateName(proc, true);
1384 if (nameError != null && !"system".equals(proc)) {
1385 outError[0] = "Invalid " + type + " name " + proc + " in package "
1386 + pkg + ": " + nameError;
1387 return null;
1388 }
1389 return proc.intern();
1390 }
1391
1392 private static String buildProcessName(String pkg, String defProc,
1393 CharSequence procSeq, int flags, String[] separateProcesses,
1394 String[] outError) {
1395 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1396 return defProc != null ? defProc : pkg;
1397 }
1398 if (separateProcesses != null) {
1399 for (int i=separateProcesses.length-1; i>=0; i--) {
1400 String sp = separateProcesses[i];
1401 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1402 return pkg;
1403 }
1404 }
1405 }
1406 if (procSeq == null || procSeq.length() <= 0) {
1407 return defProc;
1408 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001409 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 }
1411
1412 private static String buildTaskAffinityName(String pkg, String defProc,
1413 CharSequence procSeq, String[] outError) {
1414 if (procSeq == null) {
1415 return defProc;
1416 }
1417 if (procSeq.length() <= 0) {
1418 return null;
1419 }
1420 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1421 }
1422
1423 private PermissionGroup parsePermissionGroup(Package owner, Resources res,
1424 XmlPullParser parser, AttributeSet attrs, String[] outError)
1425 throws XmlPullParserException, IOException {
1426 PermissionGroup perm = new PermissionGroup(owner);
1427
1428 TypedArray sa = res.obtainAttributes(attrs,
1429 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1430
1431 if (!parsePackageItemInfo(owner, perm.info, outError,
1432 "<permission-group>", sa,
1433 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1434 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001435 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1436 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 sa.recycle();
1438 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1439 return null;
1440 }
1441
1442 perm.info.descriptionRes = sa.getResourceId(
1443 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1444 0);
1445
1446 sa.recycle();
1447
1448 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1449 outError)) {
1450 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1451 return null;
1452 }
1453
1454 owner.permissionGroups.add(perm);
1455
1456 return perm;
1457 }
1458
1459 private Permission parsePermission(Package owner, Resources res,
1460 XmlPullParser parser, AttributeSet attrs, String[] outError)
1461 throws XmlPullParserException, IOException {
1462 Permission perm = new Permission(owner);
1463
1464 TypedArray sa = res.obtainAttributes(attrs,
1465 com.android.internal.R.styleable.AndroidManifestPermission);
1466
1467 if (!parsePackageItemInfo(owner, perm.info, outError,
1468 "<permission>", sa,
1469 com.android.internal.R.styleable.AndroidManifestPermission_name,
1470 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001471 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1472 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 sa.recycle();
1474 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1475 return null;
1476 }
1477
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001478 // Note: don't allow this value to be a reference to a resource
1479 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 perm.info.group = sa.getNonResourceString(
1481 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1482 if (perm.info.group != null) {
1483 perm.info.group = perm.info.group.intern();
1484 }
1485
1486 perm.info.descriptionRes = sa.getResourceId(
1487 com.android.internal.R.styleable.AndroidManifestPermission_description,
1488 0);
1489
1490 perm.info.protectionLevel = sa.getInt(
1491 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1492 PermissionInfo.PROTECTION_NORMAL);
1493
1494 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 if (perm.info.protectionLevel == -1) {
1497 outError[0] = "<permission> does not specify protectionLevel";
1498 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1499 return null;
1500 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001501
1502 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1503
1504 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1505 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1506 PermissionInfo.PROTECTION_SIGNATURE) {
1507 outError[0] = "<permission> protectionLevel specifies a flag but is "
1508 + "not based on signature type";
1509 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1510 return null;
1511 }
1512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513
1514 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1515 outError)) {
1516 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1517 return null;
1518 }
1519
1520 owner.permissions.add(perm);
1521
1522 return perm;
1523 }
1524
1525 private Permission parsePermissionTree(Package owner, Resources res,
1526 XmlPullParser parser, AttributeSet attrs, String[] outError)
1527 throws XmlPullParserException, IOException {
1528 Permission perm = new Permission(owner);
1529
1530 TypedArray sa = res.obtainAttributes(attrs,
1531 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1532
1533 if (!parsePackageItemInfo(owner, perm.info, outError,
1534 "<permission-tree>", sa,
1535 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1536 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001537 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1538 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 sa.recycle();
1540 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1541 return null;
1542 }
1543
1544 sa.recycle();
1545
1546 int index = perm.info.name.indexOf('.');
1547 if (index > 0) {
1548 index = perm.info.name.indexOf('.', index+1);
1549 }
1550 if (index < 0) {
1551 outError[0] = "<permission-tree> name has less than three segments: "
1552 + perm.info.name;
1553 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1554 return null;
1555 }
1556
1557 perm.info.descriptionRes = 0;
1558 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1559 perm.tree = true;
1560
1561 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1562 outError)) {
1563 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1564 return null;
1565 }
1566
1567 owner.permissions.add(perm);
1568
1569 return perm;
1570 }
1571
1572 private Instrumentation parseInstrumentation(Package owner, Resources res,
1573 XmlPullParser parser, AttributeSet attrs, String[] outError)
1574 throws XmlPullParserException, IOException {
1575 TypedArray sa = res.obtainAttributes(attrs,
1576 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1577
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001578 if (mParseInstrumentationArgs == null) {
1579 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1580 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1581 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001582 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1583 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001584 mParseInstrumentationArgs.tag = "<instrumentation>";
1585 }
1586
1587 mParseInstrumentationArgs.sa = sa;
1588
1589 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1590 new InstrumentationInfo());
1591 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 sa.recycle();
1593 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1594 return null;
1595 }
1596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001598 // Note: don't allow this value to be a reference to a resource
1599 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 str = sa.getNonResourceString(
1601 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1602 a.info.targetPackage = str != null ? str.intern() : null;
1603
1604 a.info.handleProfiling = sa.getBoolean(
1605 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1606 false);
1607
1608 a.info.functionalTest = sa.getBoolean(
1609 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1610 false);
1611
1612 sa.recycle();
1613
1614 if (a.info.targetPackage == null) {
1615 outError[0] = "<instrumentation> does not specify targetPackage";
1616 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1617 return null;
1618 }
1619
1620 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1621 outError)) {
1622 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1623 return null;
1624 }
1625
1626 owner.instrumentation.add(a);
1627
1628 return a;
1629 }
1630
1631 private boolean parseApplication(Package owner, Resources res,
1632 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1633 throws XmlPullParserException, IOException {
1634 final ApplicationInfo ai = owner.applicationInfo;
1635 final String pkgName = owner.applicationInfo.packageName;
1636
1637 TypedArray sa = res.obtainAttributes(attrs,
1638 com.android.internal.R.styleable.AndroidManifestApplication);
1639
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001640 String name = sa.getNonConfigurationString(
1641 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 if (name != null) {
1643 ai.className = buildClassName(pkgName, name, outError);
1644 if (ai.className == null) {
1645 sa.recycle();
1646 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1647 return false;
1648 }
1649 }
1650
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001651 String manageSpaceActivity = sa.getNonConfigurationString(
1652 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 if (manageSpaceActivity != null) {
1654 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1655 outError);
1656 }
1657
Christopher Tate181fafa2009-05-14 11:12:14 -07001658 boolean allowBackup = sa.getBoolean(
1659 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1660 if (allowBackup) {
1661 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001662
Christopher Tate3de55bc2010-03-12 17:28:08 -08001663 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1664 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001665 String backupAgent = sa.getNonConfigurationString(
1666 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001667 if (backupAgent != null) {
1668 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001669 if (DEBUG_BACKUP) {
1670 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001671 + " from " + pkgName + "+" + backupAgent);
1672 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001673
1674 if (sa.getBoolean(
1675 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1676 true)) {
1677 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1678 }
1679 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001680 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1681 false)) {
1682 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1683 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001684 }
1685 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 TypedValue v = sa.peekValue(
1688 com.android.internal.R.styleable.AndroidManifestApplication_label);
1689 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1690 ai.nonLocalizedLabel = v.coerceToString();
1691 }
1692
1693 ai.icon = sa.getResourceId(
1694 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001695 ai.logo = sa.getResourceId(
1696 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001698 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 ai.descriptionRes = sa.getResourceId(
1700 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1701
1702 if ((flags&PARSE_IS_SYSTEM) != 0) {
1703 if (sa.getBoolean(
1704 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1705 false)) {
1706 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1707 }
1708 }
1709
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001710 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1711 ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1712 }
1713
1714 if ((flags & PARSE_ON_SDCARD) != 0) {
Suchi Amalapurapu6069beb2010-03-10 09:46:49 -08001715 ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -08001716 }
1717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 if (sa.getBoolean(
1719 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1720 false)) {
1721 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1722 }
1723
1724 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001725 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001726 false)) {
1727 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1728 }
1729
Romain Guy529b60a2010-08-03 18:05:47 -07001730 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001731 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001732 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001733
1734 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1736 true)) {
1737 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1738 }
1739
1740 if (sa.getBoolean(
1741 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1742 false)) {
1743 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1744 }
1745
1746 if (sa.getBoolean(
1747 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1748 true)) {
1749 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1750 }
1751
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001752 if (sa.getBoolean(
1753 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001754 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001755 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1756 }
1757
Jason parksa3cdaa52011-01-13 14:15:43 -06001758 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001759 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001760 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001761 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001762 }
1763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001765 str = sa.getNonConfigurationString(
1766 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1768
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001769 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1770 str = sa.getNonConfigurationString(
1771 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1772 } else {
1773 // Some older apps have been seen to use a resource reference
1774 // here that on older builds was ignored (with a warning). We
1775 // need to continue to do this for them so they don't break.
1776 str = sa.getNonResourceString(
1777 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1778 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1780 str, outError);
1781
1782 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001783 CharSequence pname;
1784 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1785 pname = sa.getNonConfigurationString(
1786 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1787 } else {
1788 // Some older apps have been seen to use a resource reference
1789 // here that on older builds was ignored (with a warning). We
1790 // need to continue to do this for them so they don't break.
1791 pname = sa.getNonResourceString(
1792 com.android.internal.R.styleable.AndroidManifestApplication_process);
1793 }
1794 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 flags, mSeparateProcesses, outError);
1796
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001797 ai.enabled = sa.getBoolean(
1798 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001799
Dianne Hackborn02486b12010-08-26 14:18:37 -07001800 if (false) {
1801 if (sa.getBoolean(
1802 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1803 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001804 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001805
1806 // A heavy-weight application can not be in a custom process.
1807 // We can do direct compare because we intern all strings.
1808 if (ai.processName != null && ai.processName != ai.packageName) {
1809 outError[0] = "cantSaveState applications can not use custom processes";
1810 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001811 }
1812 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 }
1814
Adam Powell269248d2011-08-02 10:26:54 -07001815 ai.uiOptions = sa.getInt(
1816 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 sa.recycle();
1819
1820 if (outError[0] != null) {
1821 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1822 return false;
1823 }
1824
1825 final int innerDepth = parser.getDepth();
1826
1827 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001828 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1829 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1830 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 continue;
1832 }
1833
1834 String tagName = parser.getName();
1835 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001836 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1837 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 if (a == null) {
1839 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1840 return false;
1841 }
1842
1843 owner.activities.add(a);
1844
1845 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001846 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 if (a == null) {
1848 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1849 return false;
1850 }
1851
1852 owner.receivers.add(a);
1853
1854 } else if (tagName.equals("service")) {
1855 Service s = parseService(owner, res, parser, attrs, flags, outError);
1856 if (s == null) {
1857 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1858 return false;
1859 }
1860
1861 owner.services.add(s);
1862
1863 } else if (tagName.equals("provider")) {
1864 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1865 if (p == null) {
1866 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1867 return false;
1868 }
1869
1870 owner.providers.add(p);
1871
1872 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001873 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 if (a == null) {
1875 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1876 return false;
1877 }
1878
1879 owner.activities.add(a);
1880
1881 } else if (parser.getName().equals("meta-data")) {
1882 // note: application meta-data is stored off to the side, so it can
1883 // remain null in the primary copy (we like to avoid extra copies because
1884 // it can be large)
1885 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1886 outError)) == null) {
1887 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1888 return false;
1889 }
1890
1891 } else if (tagName.equals("uses-library")) {
1892 sa = res.obtainAttributes(attrs,
1893 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1894
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001895 // Note: don't allow this value to be a reference to a resource
1896 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 String lname = sa.getNonResourceString(
1898 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001899 boolean req = sa.getBoolean(
1900 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1901 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001902
1903 sa.recycle();
1904
Dianne Hackborn49237342009-08-27 20:08:01 -07001905 if (lname != null) {
1906 if (req) {
1907 if (owner.usesLibraries == null) {
1908 owner.usesLibraries = new ArrayList<String>();
1909 }
1910 if (!owner.usesLibraries.contains(lname)) {
1911 owner.usesLibraries.add(lname.intern());
1912 }
1913 } else {
1914 if (owner.usesOptionalLibraries == null) {
1915 owner.usesOptionalLibraries = new ArrayList<String>();
1916 }
1917 if (!owner.usesOptionalLibraries.contains(lname)) {
1918 owner.usesOptionalLibraries.add(lname.intern());
1919 }
1920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 }
1922
1923 XmlUtils.skipCurrentTag(parser);
1924
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001925 } else if (tagName.equals("uses-package")) {
1926 // Dependencies for app installers; we don't currently try to
1927 // enforce this.
1928 XmlUtils.skipCurrentTag(parser);
1929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 } else {
1931 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001932 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001933 + " at " + mArchiveSourcePath + " "
1934 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 XmlUtils.skipCurrentTag(parser);
1936 continue;
1937 } else {
1938 outError[0] = "Bad element under <application>: " + tagName;
1939 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1940 return false;
1941 }
1942 }
1943 }
1944
1945 return true;
1946 }
1947
1948 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1949 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001950 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001951 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 if (name == null) {
1953 outError[0] = tag + " does not specify android:name";
1954 return false;
1955 }
1956
1957 outInfo.name
1958 = buildClassName(owner.applicationInfo.packageName, name, outError);
1959 if (outInfo.name == null) {
1960 return false;
1961 }
1962
1963 int iconVal = sa.getResourceId(iconRes, 0);
1964 if (iconVal != 0) {
1965 outInfo.icon = iconVal;
1966 outInfo.nonLocalizedLabel = null;
1967 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001968
1969 int logoVal = sa.getResourceId(logoRes, 0);
1970 if (logoVal != 0) {
1971 outInfo.logo = logoVal;
1972 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973
1974 TypedValue v = sa.peekValue(labelRes);
1975 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
1976 outInfo.nonLocalizedLabel = v.coerceToString();
1977 }
1978
1979 outInfo.packageName = owner.packageName;
1980
1981 return true;
1982 }
1983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 private Activity parseActivity(Package owner, Resources res,
1985 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07001986 boolean receiver, boolean hardwareAccelerated)
1987 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 TypedArray sa = res.obtainAttributes(attrs,
1989 com.android.internal.R.styleable.AndroidManifestActivity);
1990
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001991 if (mParseActivityArgs == null) {
1992 mParseActivityArgs = new ParseComponentArgs(owner, outError,
1993 com.android.internal.R.styleable.AndroidManifestActivity_name,
1994 com.android.internal.R.styleable.AndroidManifestActivity_label,
1995 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07001996 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001997 mSeparateProcesses,
1998 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001999 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002000 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2001 }
2002
2003 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2004 mParseActivityArgs.sa = sa;
2005 mParseActivityArgs.flags = flags;
2006
2007 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2008 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 sa.recycle();
2010 return null;
2011 }
2012
2013 final boolean setExported = sa.hasValue(
2014 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2015 if (setExported) {
2016 a.info.exported = sa.getBoolean(
2017 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2018 }
2019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002020 a.info.theme = sa.getResourceId(
2021 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2022
Adam Powell269248d2011-08-02 10:26:54 -07002023 a.info.uiOptions = sa.getInt(
2024 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2025 a.info.applicationInfo.uiOptions);
2026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002028 str = sa.getNonConfigurationString(
2029 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 if (str == null) {
2031 a.info.permission = owner.applicationInfo.permission;
2032 } else {
2033 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2034 }
2035
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002036 str = sa.getNonConfigurationString(
2037 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2039 owner.applicationInfo.taskAffinity, str, outError);
2040
2041 a.info.flags = 0;
2042 if (sa.getBoolean(
2043 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2044 false)) {
2045 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2046 }
2047
2048 if (sa.getBoolean(
2049 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2050 false)) {
2051 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2052 }
2053
2054 if (sa.getBoolean(
2055 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2056 false)) {
2057 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2058 }
2059
2060 if (sa.getBoolean(
2061 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2062 false)) {
2063 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2064 }
2065
2066 if (sa.getBoolean(
2067 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2068 false)) {
2069 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2070 }
2071
2072 if (sa.getBoolean(
2073 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2074 false)) {
2075 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2076 }
2077
2078 if (sa.getBoolean(
2079 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2080 false)) {
2081 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2082 }
2083
2084 if (sa.getBoolean(
2085 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2086 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2087 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2088 }
2089
Dianne Hackbornffa42482009-09-23 22:20:11 -07002090 if (sa.getBoolean(
2091 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2092 false)) {
2093 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2094 }
2095
Daniel Sandler613dde42010-06-21 13:46:39 -04002096 if (sa.getBoolean(
2097 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2098 false)) {
2099 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2100 }
Romain Guy529b60a2010-08-03 18:05:47 -07002101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002103 if (sa.getBoolean(
2104 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2105 hardwareAccelerated)) {
2106 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2107 }
2108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 a.info.launchMode = sa.getInt(
2110 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2111 ActivityInfo.LAUNCH_MULTIPLE);
2112 a.info.screenOrientation = sa.getInt(
2113 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2114 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2115 a.info.configChanges = sa.getInt(
2116 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2117 0);
2118 a.info.softInputMode = sa.getInt(
2119 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2120 0);
2121 } else {
2122 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2123 a.info.configChanges = 0;
2124 }
2125
2126 sa.recycle();
2127
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002128 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002129 // A heavy-weight application can not have receives in its main process
2130 // We can do direct compare because we intern all strings.
2131 if (a.info.processName == owner.packageName) {
2132 outError[0] = "Heavy-weight applications can not have receivers in main process";
2133 }
2134 }
2135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 if (outError[0] != null) {
2137 return null;
2138 }
2139
2140 int outerDepth = parser.getDepth();
2141 int type;
2142 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2143 && (type != XmlPullParser.END_TAG
2144 || parser.getDepth() > outerDepth)) {
2145 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2146 continue;
2147 }
2148
2149 if (parser.getName().equals("intent-filter")) {
2150 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2151 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2152 return null;
2153 }
2154 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002155 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002156 + mArchiveSourcePath + " "
2157 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 } else {
2159 a.intents.add(intent);
2160 }
2161 } else if (parser.getName().equals("meta-data")) {
2162 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2163 outError)) == null) {
2164 return null;
2165 }
2166 } else {
2167 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002168 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002170 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002171 + " at " + mArchiveSourcePath + " "
2172 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002174 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002175 + " at " + mArchiveSourcePath + " "
2176 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 }
2178 XmlUtils.skipCurrentTag(parser);
2179 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002181 if (receiver) {
2182 outError[0] = "Bad element under <receiver>: " + parser.getName();
2183 } else {
2184 outError[0] = "Bad element under <activity>: " + parser.getName();
2185 }
2186 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 }
2189 }
2190
2191 if (!setExported) {
2192 a.info.exported = a.intents.size() > 0;
2193 }
2194
2195 return a;
2196 }
2197
2198 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002199 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2200 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 TypedArray sa = res.obtainAttributes(attrs,
2202 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2203
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002204 String targetActivity = sa.getNonConfigurationString(
2205 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 if (targetActivity == null) {
2207 outError[0] = "<activity-alias> does not specify android:targetActivity";
2208 sa.recycle();
2209 return null;
2210 }
2211
2212 targetActivity = buildClassName(owner.applicationInfo.packageName,
2213 targetActivity, outError);
2214 if (targetActivity == null) {
2215 sa.recycle();
2216 return null;
2217 }
2218
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002219 if (mParseActivityAliasArgs == null) {
2220 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2221 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2222 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2223 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002224 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002225 mSeparateProcesses,
2226 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002227 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002228 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2229 mParseActivityAliasArgs.tag = "<activity-alias>";
2230 }
2231
2232 mParseActivityAliasArgs.sa = sa;
2233 mParseActivityAliasArgs.flags = flags;
2234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 Activity target = null;
2236
2237 final int NA = owner.activities.size();
2238 for (int i=0; i<NA; i++) {
2239 Activity t = owner.activities.get(i);
2240 if (targetActivity.equals(t.info.name)) {
2241 target = t;
2242 break;
2243 }
2244 }
2245
2246 if (target == null) {
2247 outError[0] = "<activity-alias> target activity " + targetActivity
2248 + " not found in manifest";
2249 sa.recycle();
2250 return null;
2251 }
2252
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002253 ActivityInfo info = new ActivityInfo();
2254 info.targetActivity = targetActivity;
2255 info.configChanges = target.info.configChanges;
2256 info.flags = target.info.flags;
2257 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002258 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002259 info.labelRes = target.info.labelRes;
2260 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2261 info.launchMode = target.info.launchMode;
2262 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002263 if (info.descriptionRes == 0) {
2264 info.descriptionRes = target.info.descriptionRes;
2265 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002266 info.screenOrientation = target.info.screenOrientation;
2267 info.taskAffinity = target.info.taskAffinity;
2268 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002269 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002270 info.uiOptions = target.info.uiOptions;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002271
2272 Activity a = new Activity(mParseActivityAliasArgs, info);
2273 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002274 sa.recycle();
2275 return null;
2276 }
2277
2278 final boolean setExported = sa.hasValue(
2279 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2280 if (setExported) {
2281 a.info.exported = sa.getBoolean(
2282 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2283 }
2284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002286 str = sa.getNonConfigurationString(
2287 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 if (str != null) {
2289 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2290 }
2291
2292 sa.recycle();
2293
2294 if (outError[0] != null) {
2295 return null;
2296 }
2297
2298 int outerDepth = parser.getDepth();
2299 int type;
2300 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2301 && (type != XmlPullParser.END_TAG
2302 || parser.getDepth() > outerDepth)) {
2303 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2304 continue;
2305 }
2306
2307 if (parser.getName().equals("intent-filter")) {
2308 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2309 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2310 return null;
2311 }
2312 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002313 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002314 + mArchiveSourcePath + " "
2315 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 } else {
2317 a.intents.add(intent);
2318 }
2319 } else if (parser.getName().equals("meta-data")) {
2320 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2321 outError)) == null) {
2322 return null;
2323 }
2324 } else {
2325 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002326 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002327 + " at " + mArchiveSourcePath + " "
2328 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 XmlUtils.skipCurrentTag(parser);
2330 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002331 } else {
2332 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2333 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 }
2336 }
2337
2338 if (!setExported) {
2339 a.info.exported = a.intents.size() > 0;
2340 }
2341
2342 return a;
2343 }
2344
2345 private Provider parseProvider(Package owner, Resources res,
2346 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2347 throws XmlPullParserException, IOException {
2348 TypedArray sa = res.obtainAttributes(attrs,
2349 com.android.internal.R.styleable.AndroidManifestProvider);
2350
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002351 if (mParseProviderArgs == null) {
2352 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2353 com.android.internal.R.styleable.AndroidManifestProvider_name,
2354 com.android.internal.R.styleable.AndroidManifestProvider_label,
2355 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002356 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002357 mSeparateProcesses,
2358 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002359 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002360 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2361 mParseProviderArgs.tag = "<provider>";
2362 }
2363
2364 mParseProviderArgs.sa = sa;
2365 mParseProviderArgs.flags = flags;
2366
2367 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2368 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 sa.recycle();
2370 return null;
2371 }
2372
2373 p.info.exported = sa.getBoolean(
2374 com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2375
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002376 String cpname = sa.getNonConfigurationString(
2377 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378
2379 p.info.isSyncable = sa.getBoolean(
2380 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2381 false);
2382
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002383 String permission = sa.getNonConfigurationString(
2384 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2385 String str = sa.getNonConfigurationString(
2386 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 if (str == null) {
2388 str = permission;
2389 }
2390 if (str == null) {
2391 p.info.readPermission = owner.applicationInfo.permission;
2392 } else {
2393 p.info.readPermission =
2394 str.length() > 0 ? str.toString().intern() : null;
2395 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002396 str = sa.getNonConfigurationString(
2397 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 if (str == null) {
2399 str = permission;
2400 }
2401 if (str == null) {
2402 p.info.writePermission = owner.applicationInfo.permission;
2403 } else {
2404 p.info.writePermission =
2405 str.length() > 0 ? str.toString().intern() : null;
2406 }
2407
2408 p.info.grantUriPermissions = sa.getBoolean(
2409 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2410 false);
2411
2412 p.info.multiprocess = sa.getBoolean(
2413 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2414 false);
2415
2416 p.info.initOrder = sa.getInt(
2417 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2418 0);
2419
2420 sa.recycle();
2421
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002422 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002423 // A heavy-weight application can not have providers in its main process
2424 // We can do direct compare because we intern all strings.
2425 if (p.info.processName == owner.packageName) {
2426 outError[0] = "Heavy-weight applications can not have providers in main process";
2427 return null;
2428 }
2429 }
2430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 if (cpname == null) {
2432 outError[0] = "<provider> does not incude authorities attribute";
2433 return null;
2434 }
2435 p.info.authority = cpname.intern();
2436
2437 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2438 return null;
2439 }
2440
2441 return p;
2442 }
2443
2444 private boolean parseProviderTags(Resources res,
2445 XmlPullParser parser, AttributeSet attrs,
2446 Provider outInfo, String[] outError)
2447 throws XmlPullParserException, IOException {
2448 int outerDepth = parser.getDepth();
2449 int type;
2450 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2451 && (type != XmlPullParser.END_TAG
2452 || parser.getDepth() > outerDepth)) {
2453 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2454 continue;
2455 }
2456
2457 if (parser.getName().equals("meta-data")) {
2458 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2459 outInfo.metaData, outError)) == null) {
2460 return false;
2461 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 } else if (parser.getName().equals("grant-uri-permission")) {
2464 TypedArray sa = res.obtainAttributes(attrs,
2465 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2466
2467 PatternMatcher pa = null;
2468
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002469 String str = sa.getNonConfigurationString(
2470 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 if (str != null) {
2472 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2473 }
2474
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002475 str = sa.getNonConfigurationString(
2476 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 if (str != null) {
2478 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2479 }
2480
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002481 str = sa.getNonConfigurationString(
2482 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 if (str != null) {
2484 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2485 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 sa.recycle();
2488
2489 if (pa != null) {
2490 if (outInfo.info.uriPermissionPatterns == null) {
2491 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2492 outInfo.info.uriPermissionPatterns[0] = pa;
2493 } else {
2494 final int N = outInfo.info.uriPermissionPatterns.length;
2495 PatternMatcher[] newp = new PatternMatcher[N+1];
2496 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2497 newp[N] = pa;
2498 outInfo.info.uriPermissionPatterns = newp;
2499 }
2500 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002501 } else {
2502 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002503 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002504 + parser.getName() + " at " + mArchiveSourcePath + " "
2505 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002506 XmlUtils.skipCurrentTag(parser);
2507 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002508 } else {
2509 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2510 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002511 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002512 }
2513 XmlUtils.skipCurrentTag(parser);
2514
2515 } else if (parser.getName().equals("path-permission")) {
2516 TypedArray sa = res.obtainAttributes(attrs,
2517 com.android.internal.R.styleable.AndroidManifestPathPermission);
2518
2519 PathPermission pa = null;
2520
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002521 String permission = sa.getNonConfigurationString(
2522 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2523 String readPermission = sa.getNonConfigurationString(
2524 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002525 if (readPermission == null) {
2526 readPermission = permission;
2527 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002528 String writePermission = sa.getNonConfigurationString(
2529 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002530 if (writePermission == null) {
2531 writePermission = permission;
2532 }
2533
2534 boolean havePerm = false;
2535 if (readPermission != null) {
2536 readPermission = readPermission.intern();
2537 havePerm = true;
2538 }
2539 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002540 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002541 havePerm = true;
2542 }
2543
2544 if (!havePerm) {
2545 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002546 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002547 + parser.getName() + " at " + mArchiveSourcePath + " "
2548 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002549 XmlUtils.skipCurrentTag(parser);
2550 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002551 } else {
2552 outError[0] = "No readPermission or writePermssion for <path-permission>";
2553 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002554 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002555 }
2556
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002557 String path = sa.getNonConfigurationString(
2558 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002559 if (path != null) {
2560 pa = new PathPermission(path,
2561 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2562 }
2563
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002564 path = sa.getNonConfigurationString(
2565 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002566 if (path != null) {
2567 pa = new PathPermission(path,
2568 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2569 }
2570
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002571 path = sa.getNonConfigurationString(
2572 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002573 if (path != null) {
2574 pa = new PathPermission(path,
2575 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2576 }
2577
2578 sa.recycle();
2579
2580 if (pa != null) {
2581 if (outInfo.info.pathPermissions == null) {
2582 outInfo.info.pathPermissions = new PathPermission[1];
2583 outInfo.info.pathPermissions[0] = pa;
2584 } else {
2585 final int N = outInfo.info.pathPermissions.length;
2586 PathPermission[] newp = new PathPermission[N+1];
2587 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2588 newp[N] = pa;
2589 outInfo.info.pathPermissions = newp;
2590 }
2591 } else {
2592 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002593 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002594 + parser.getName() + " at " + mArchiveSourcePath + " "
2595 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002596 XmlUtils.skipCurrentTag(parser);
2597 continue;
2598 }
2599 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2600 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 }
2602 XmlUtils.skipCurrentTag(parser);
2603
2604 } else {
2605 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002606 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002607 + parser.getName() + " at " + mArchiveSourcePath + " "
2608 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 XmlUtils.skipCurrentTag(parser);
2610 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002611 } else {
2612 outError[0] = "Bad element under <provider>: " + parser.getName();
2613 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 }
2616 }
2617 return true;
2618 }
2619
2620 private Service parseService(Package owner, Resources res,
2621 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2622 throws XmlPullParserException, IOException {
2623 TypedArray sa = res.obtainAttributes(attrs,
2624 com.android.internal.R.styleable.AndroidManifestService);
2625
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002626 if (mParseServiceArgs == null) {
2627 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2628 com.android.internal.R.styleable.AndroidManifestService_name,
2629 com.android.internal.R.styleable.AndroidManifestService_label,
2630 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002631 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002632 mSeparateProcesses,
2633 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002634 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002635 com.android.internal.R.styleable.AndroidManifestService_enabled);
2636 mParseServiceArgs.tag = "<service>";
2637 }
2638
2639 mParseServiceArgs.sa = sa;
2640 mParseServiceArgs.flags = flags;
2641
2642 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2643 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 sa.recycle();
2645 return null;
2646 }
2647
2648 final boolean setExported = sa.hasValue(
2649 com.android.internal.R.styleable.AndroidManifestService_exported);
2650 if (setExported) {
2651 s.info.exported = sa.getBoolean(
2652 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2653 }
2654
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002655 String str = sa.getNonConfigurationString(
2656 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 if (str == null) {
2658 s.info.permission = owner.applicationInfo.permission;
2659 } else {
2660 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2661 }
2662
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002663 s.info.flags = 0;
2664 if (sa.getBoolean(
2665 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2666 false)) {
2667 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2668 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002669 if (sa.getBoolean(
2670 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2671 false)) {
2672 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2673 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 sa.recycle();
2676
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002677 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002678 // A heavy-weight application can not have services in its main process
2679 // We can do direct compare because we intern all strings.
2680 if (s.info.processName == owner.packageName) {
2681 outError[0] = "Heavy-weight applications can not have services in main process";
2682 return null;
2683 }
2684 }
2685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 int outerDepth = parser.getDepth();
2687 int type;
2688 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2689 && (type != XmlPullParser.END_TAG
2690 || parser.getDepth() > outerDepth)) {
2691 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2692 continue;
2693 }
2694
2695 if (parser.getName().equals("intent-filter")) {
2696 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2697 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2698 return null;
2699 }
2700
2701 s.intents.add(intent);
2702 } else if (parser.getName().equals("meta-data")) {
2703 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2704 outError)) == null) {
2705 return null;
2706 }
2707 } else {
2708 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002709 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002710 + parser.getName() + " at " + mArchiveSourcePath + " "
2711 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 XmlUtils.skipCurrentTag(parser);
2713 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002714 } else {
2715 outError[0] = "Bad element under <service>: " + parser.getName();
2716 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 }
2719 }
2720
2721 if (!setExported) {
2722 s.info.exported = s.intents.size() > 0;
2723 }
2724
2725 return s;
2726 }
2727
2728 private boolean parseAllMetaData(Resources res,
2729 XmlPullParser parser, AttributeSet attrs, String tag,
2730 Component outInfo, String[] outError)
2731 throws XmlPullParserException, IOException {
2732 int outerDepth = parser.getDepth();
2733 int type;
2734 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2735 && (type != XmlPullParser.END_TAG
2736 || parser.getDepth() > outerDepth)) {
2737 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2738 continue;
2739 }
2740
2741 if (parser.getName().equals("meta-data")) {
2742 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2743 outInfo.metaData, outError)) == null) {
2744 return false;
2745 }
2746 } else {
2747 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002748 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002749 + parser.getName() + " at " + mArchiveSourcePath + " "
2750 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 XmlUtils.skipCurrentTag(parser);
2752 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002753 } else {
2754 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2755 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 }
2758 }
2759 return true;
2760 }
2761
2762 private Bundle parseMetaData(Resources res,
2763 XmlPullParser parser, AttributeSet attrs,
2764 Bundle data, String[] outError)
2765 throws XmlPullParserException, IOException {
2766
2767 TypedArray sa = res.obtainAttributes(attrs,
2768 com.android.internal.R.styleable.AndroidManifestMetaData);
2769
2770 if (data == null) {
2771 data = new Bundle();
2772 }
2773
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002774 String name = sa.getNonConfigurationString(
2775 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 if (name == null) {
2777 outError[0] = "<meta-data> requires an android:name attribute";
2778 sa.recycle();
2779 return null;
2780 }
2781
Dianne Hackborn854060a2009-07-09 18:14:31 -07002782 name = name.intern();
2783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 TypedValue v = sa.peekValue(
2785 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2786 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002787 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 data.putInt(name, v.resourceId);
2789 } else {
2790 v = sa.peekValue(
2791 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002792 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 if (v != null) {
2794 if (v.type == TypedValue.TYPE_STRING) {
2795 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002796 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2798 data.putBoolean(name, v.data != 0);
2799 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2800 && v.type <= TypedValue.TYPE_LAST_INT) {
2801 data.putInt(name, v.data);
2802 } else if (v.type == TypedValue.TYPE_FLOAT) {
2803 data.putFloat(name, v.getFloat());
2804 } else {
2805 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002806 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002807 + parser.getName() + " at " + mArchiveSourcePath + " "
2808 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 } else {
2810 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2811 data = null;
2812 }
2813 }
2814 } else {
2815 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2816 data = null;
2817 }
2818 }
2819
2820 sa.recycle();
2821
2822 XmlUtils.skipCurrentTag(parser);
2823
2824 return data;
2825 }
2826
Kenny Root05ca4c92011-09-15 10:36:25 -07002827 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2828 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2829 IOException {
2830 final TypedArray sa = res.obtainAttributes(attrs,
2831 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2832
2833 final String packageName = sa.getNonResourceString(
2834 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2835
2836 final String encodedPublicKey = sa.getNonResourceString(
2837 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2838
2839 sa.recycle();
2840
2841 if (packageName == null || packageName.length() == 0) {
2842 Slog.i(TAG, "verifier package name was null; skipping");
2843 return null;
2844 } else if (encodedPublicKey == null) {
2845 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2846 }
2847
2848 EncodedKeySpec keySpec;
2849 try {
2850 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2851 keySpec = new X509EncodedKeySpec(encoded);
2852 } catch (IllegalArgumentException e) {
2853 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2854 return null;
2855 }
2856
2857 /* First try the key as an RSA key. */
2858 try {
2859 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2860 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2861 return new VerifierInfo(packageName, publicKey);
2862 } catch (NoSuchAlgorithmException e) {
2863 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2864 return null;
2865 } catch (InvalidKeySpecException e) {
2866 // Not a RSA public key.
2867 }
2868
2869 /* Now try it as a DSA key. */
2870 try {
2871 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
2872 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2873 return new VerifierInfo(packageName, publicKey);
2874 } catch (NoSuchAlgorithmException e) {
2875 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
2876 return null;
2877 } catch (InvalidKeySpecException e) {
2878 // Not a DSA public key.
2879 }
2880
2881 return null;
2882 }
2883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 private static final String ANDROID_RESOURCES
2885 = "http://schemas.android.com/apk/res/android";
2886
2887 private boolean parseIntent(Resources res,
2888 XmlPullParser parser, AttributeSet attrs, int flags,
2889 IntentInfo outInfo, String[] outError, boolean isActivity)
2890 throws XmlPullParserException, IOException {
2891
2892 TypedArray sa = res.obtainAttributes(attrs,
2893 com.android.internal.R.styleable.AndroidManifestIntentFilter);
2894
2895 int priority = sa.getInt(
2896 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08002898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 TypedValue v = sa.peekValue(
2900 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
2901 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2902 outInfo.nonLocalizedLabel = v.coerceToString();
2903 }
2904
2905 outInfo.icon = sa.getResourceId(
2906 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07002907
2908 outInfo.logo = sa.getResourceId(
2909 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910
2911 sa.recycle();
2912
2913 int outerDepth = parser.getDepth();
2914 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002915 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2916 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
2917 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 continue;
2919 }
2920
2921 String nodeName = parser.getName();
2922 if (nodeName.equals("action")) {
2923 String value = attrs.getAttributeValue(
2924 ANDROID_RESOURCES, "name");
2925 if (value == null || value == "") {
2926 outError[0] = "No value supplied for <android:name>";
2927 return false;
2928 }
2929 XmlUtils.skipCurrentTag(parser);
2930
2931 outInfo.addAction(value);
2932 } else if (nodeName.equals("category")) {
2933 String value = attrs.getAttributeValue(
2934 ANDROID_RESOURCES, "name");
2935 if (value == null || value == "") {
2936 outError[0] = "No value supplied for <android:name>";
2937 return false;
2938 }
2939 XmlUtils.skipCurrentTag(parser);
2940
2941 outInfo.addCategory(value);
2942
2943 } else if (nodeName.equals("data")) {
2944 sa = res.obtainAttributes(attrs,
2945 com.android.internal.R.styleable.AndroidManifestData);
2946
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002947 String str = sa.getNonConfigurationString(
2948 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 if (str != null) {
2950 try {
2951 outInfo.addDataType(str);
2952 } catch (IntentFilter.MalformedMimeTypeException e) {
2953 outError[0] = e.toString();
2954 sa.recycle();
2955 return false;
2956 }
2957 }
2958
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002959 str = sa.getNonConfigurationString(
2960 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 if (str != null) {
2962 outInfo.addDataScheme(str);
2963 }
2964
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002965 String host = sa.getNonConfigurationString(
2966 com.android.internal.R.styleable.AndroidManifestData_host, 0);
2967 String port = sa.getNonConfigurationString(
2968 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 if (host != null) {
2970 outInfo.addDataAuthority(host, port);
2971 }
2972
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002973 str = sa.getNonConfigurationString(
2974 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 if (str != null) {
2976 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
2977 }
2978
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002979 str = sa.getNonConfigurationString(
2980 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 if (str != null) {
2982 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
2983 }
2984
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002985 str = sa.getNonConfigurationString(
2986 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 if (str != null) {
2988 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2989 }
2990
2991 sa.recycle();
2992 XmlUtils.skipCurrentTag(parser);
2993 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002994 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002995 + parser.getName() + " at " + mArchiveSourcePath + " "
2996 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 XmlUtils.skipCurrentTag(parser);
2998 } else {
2999 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3000 return false;
3001 }
3002 }
3003
3004 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003005
3006 if (DEBUG_PARSER) {
3007 final StringBuilder cats = new StringBuilder("Intent d=");
3008 cats.append(outInfo.hasDefault);
3009 cats.append(", cat=");
3010
3011 final Iterator<String> it = outInfo.categoriesIterator();
3012 if (it != null) {
3013 while (it.hasNext()) {
3014 cats.append(' ');
3015 cats.append(it.next());
3016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003018 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 }
3020
3021 return true;
3022 }
3023
3024 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003025 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026
3027 // For now we only support one application per package.
3028 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3029
3030 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3031 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3032 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3033 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3034 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3035 public final ArrayList<Service> services = new ArrayList<Service>(0);
3036 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3037
3038 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003039 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040
Dianne Hackborn854060a2009-07-09 18:14:31 -07003041 public ArrayList<String> protectedBroadcasts;
3042
Dianne Hackborn49237342009-08-27 20:08:01 -07003043 public ArrayList<String> usesLibraries = null;
3044 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 public String[] usesLibraryFiles = null;
3046
Dianne Hackbornc1552392010-03-03 16:19:01 -08003047 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003048 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003049 public ArrayList<String> mAdoptPermissions = null;
3050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 // We store the application meta-data independently to avoid multiple unwanted references
3052 public Bundle mAppMetaData = null;
3053
3054 // If this is a 3rd party app, this is the path of the zip file.
3055 public String mPath;
3056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 // The version code declared for this package.
3058 public int mVersionCode;
3059
3060 // The version name declared for this package.
3061 public String mVersionName;
3062
3063 // The shared user id that this package wants to use.
3064 public String mSharedUserId;
3065
3066 // The shared user label that this package wants to use.
3067 public int mSharedUserLabel;
3068
3069 // Signatures that were read from the package.
3070 public Signature mSignatures[];
3071
3072 // For use by package manager service for quick lookup of
3073 // preferred up order.
3074 public int mPreferredOrder = 0;
3075
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003076 // For use by the package manager to keep track of the path to the
3077 // file an app came from.
3078 public String mScanPath;
3079
3080 // For use by package manager to keep track of where it has done dexopt.
3081 public boolean mDidDexOpt;
3082
Amith Yamasani13593602012-03-22 16:16:17 -07003083 // // User set enabled state.
3084 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3085 //
3086 // // Whether the package has been stopped.
3087 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 // Additional data supplied by callers.
3090 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003091
3092 // Whether an operation is currently pending on this package
3093 public boolean mOperationPending;
3094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 /*
3096 * Applications hardware preferences
3097 */
3098 public final ArrayList<ConfigurationInfo> configPreferences =
3099 new ArrayList<ConfigurationInfo>();
3100
Dianne Hackborn49237342009-08-27 20:08:01 -07003101 /*
3102 * Applications requested features
3103 */
3104 public ArrayList<FeatureInfo> reqFeatures = null;
3105
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003106 public int installLocation;
3107
Kenny Rootbcc954d2011-08-08 16:19:08 -07003108 /**
3109 * Digest suitable for comparing whether this package's manifest is the
3110 * same as another.
3111 */
3112 public ManifestDigest manifestDigest;
3113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 public Package(String _name) {
3115 packageName = _name;
3116 applicationInfo.packageName = _name;
3117 applicationInfo.uid = -1;
3118 }
3119
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003120 public void setPackageName(String newName) {
3121 packageName = newName;
3122 applicationInfo.packageName = newName;
3123 for (int i=permissions.size()-1; i>=0; i--) {
3124 permissions.get(i).setPackageName(newName);
3125 }
3126 for (int i=permissionGroups.size()-1; i>=0; i--) {
3127 permissionGroups.get(i).setPackageName(newName);
3128 }
3129 for (int i=activities.size()-1; i>=0; i--) {
3130 activities.get(i).setPackageName(newName);
3131 }
3132 for (int i=receivers.size()-1; i>=0; i--) {
3133 receivers.get(i).setPackageName(newName);
3134 }
3135 for (int i=providers.size()-1; i>=0; i--) {
3136 providers.get(i).setPackageName(newName);
3137 }
3138 for (int i=services.size()-1; i>=0; i--) {
3139 services.get(i).setPackageName(newName);
3140 }
3141 for (int i=instrumentation.size()-1; i>=0; i--) {
3142 instrumentation.get(i).setPackageName(newName);
3143 }
3144 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003145
3146 public boolean hasComponentClassName(String name) {
3147 for (int i=activities.size()-1; i>=0; i--) {
3148 if (name.equals(activities.get(i).className)) {
3149 return true;
3150 }
3151 }
3152 for (int i=receivers.size()-1; i>=0; i--) {
3153 if (name.equals(receivers.get(i).className)) {
3154 return true;
3155 }
3156 }
3157 for (int i=providers.size()-1; i>=0; i--) {
3158 if (name.equals(providers.get(i).className)) {
3159 return true;
3160 }
3161 }
3162 for (int i=services.size()-1; i>=0; i--) {
3163 if (name.equals(services.get(i).className)) {
3164 return true;
3165 }
3166 }
3167 for (int i=instrumentation.size()-1; i>=0; i--) {
3168 if (name.equals(instrumentation.get(i).className)) {
3169 return true;
3170 }
3171 }
3172 return false;
3173 }
3174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 public String toString() {
3176 return "Package{"
3177 + Integer.toHexString(System.identityHashCode(this))
3178 + " " + packageName + "}";
3179 }
3180 }
3181
3182 public static class Component<II extends IntentInfo> {
3183 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003184 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003185 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 public Bundle metaData;
3187
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003188 ComponentName componentName;
3189 String componentShortName;
3190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 public Component(Package _owner) {
3192 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003193 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003194 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003195 }
3196
3197 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3198 owner = args.owner;
3199 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003200 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003201 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003202 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003203 args.outError[0] = args.tag + " does not specify android:name";
3204 return;
3205 }
3206
3207 outInfo.name
3208 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3209 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003210 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003211 args.outError[0] = args.tag + " does not have valid android:name";
3212 return;
3213 }
3214
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003215 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003216
3217 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3218 if (iconVal != 0) {
3219 outInfo.icon = iconVal;
3220 outInfo.nonLocalizedLabel = null;
3221 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003222
3223 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3224 if (logoVal != 0) {
3225 outInfo.logo = logoVal;
3226 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003227
3228 TypedValue v = args.sa.peekValue(args.labelRes);
3229 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3230 outInfo.nonLocalizedLabel = v.coerceToString();
3231 }
3232
3233 outInfo.packageName = owner.packageName;
3234 }
3235
3236 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3237 this(args, (PackageItemInfo)outInfo);
3238 if (args.outError[0] != null) {
3239 return;
3240 }
3241
3242 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003243 CharSequence pname;
3244 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3245 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3246 } else {
3247 // Some older apps have been seen to use a resource reference
3248 // here that on older builds was ignored (with a warning). We
3249 // need to continue to do this for them so they don't break.
3250 pname = args.sa.getNonResourceString(args.processRes);
3251 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003252 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003253 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003254 args.flags, args.sepProcesses, args.outError);
3255 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003256
3257 if (args.descriptionRes != 0) {
3258 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3259 }
3260
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003261 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 }
3263
3264 public Component(Component<II> clone) {
3265 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003266 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003267 className = clone.className;
3268 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003269 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003270 }
3271
3272 public ComponentName getComponentName() {
3273 if (componentName != null) {
3274 return componentName;
3275 }
3276 if (className != null) {
3277 componentName = new ComponentName(owner.applicationInfo.packageName,
3278 className);
3279 }
3280 return componentName;
3281 }
3282
3283 public String getComponentShortName() {
3284 if (componentShortName != null) {
3285 return componentShortName;
3286 }
3287 ComponentName component = getComponentName();
3288 if (component != null) {
3289 componentShortName = component.flattenToShortString();
3290 }
3291 return componentShortName;
3292 }
3293
3294 public void setPackageName(String packageName) {
3295 componentName = null;
3296 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
3298 }
3299
3300 public final static class Permission extends Component<IntentInfo> {
3301 public final PermissionInfo info;
3302 public boolean tree;
3303 public PermissionGroup group;
3304
3305 public Permission(Package _owner) {
3306 super(_owner);
3307 info = new PermissionInfo();
3308 }
3309
3310 public Permission(Package _owner, PermissionInfo _info) {
3311 super(_owner);
3312 info = _info;
3313 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003314
3315 public void setPackageName(String packageName) {
3316 super.setPackageName(packageName);
3317 info.packageName = packageName;
3318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319
3320 public String toString() {
3321 return "Permission{"
3322 + Integer.toHexString(System.identityHashCode(this))
3323 + " " + info.name + "}";
3324 }
3325 }
3326
3327 public final static class PermissionGroup extends Component<IntentInfo> {
3328 public final PermissionGroupInfo info;
3329
3330 public PermissionGroup(Package _owner) {
3331 super(_owner);
3332 info = new PermissionGroupInfo();
3333 }
3334
3335 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3336 super(_owner);
3337 info = _info;
3338 }
3339
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003340 public void setPackageName(String packageName) {
3341 super.setPackageName(packageName);
3342 info.packageName = packageName;
3343 }
3344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 public String toString() {
3346 return "PermissionGroup{"
3347 + Integer.toHexString(System.identityHashCode(this))
3348 + " " + info.name + "}";
3349 }
3350 }
3351
Amith Yamasani13593602012-03-22 16:16:17 -07003352 private static boolean copyNeeded(int flags, Package p, int enabledState, Bundle metaData) {
3353 if (enabledState != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3354 boolean enabled = enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003355 if (p.applicationInfo.enabled != enabled) {
3356 return true;
3357 }
3358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 if ((flags & PackageManager.GET_META_DATA) != 0
3360 && (metaData != null || p.mAppMetaData != null)) {
3361 return true;
3362 }
3363 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3364 && p.usesLibraryFiles != null) {
3365 return true;
3366 }
3367 return false;
3368 }
3369
Amith Yamasani13593602012-03-22 16:16:17 -07003370 public static ApplicationInfo generateApplicationInfo(Package p, int flags, boolean stopped,
3371 int enabledState) {
3372 return generateApplicationInfo(p, flags, stopped, enabledState, UserId.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003373 }
3374
Amith Yamasani13593602012-03-22 16:16:17 -07003375 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3376 boolean stopped, int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003378 if (!copyNeeded(flags, p, enabledState, null) && userId == 0) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003379 // CompatibilityMode is global state. It's safe to modify the instance
3380 // of the package.
3381 if (!sCompatibilityModeEnabled) {
3382 p.applicationInfo.disableCompatibilityMode();
3383 }
Amith Yamasani13593602012-03-22 16:16:17 -07003384 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003385 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3386 } else {
3387 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3388 }
Amith Yamasani13593602012-03-22 16:16:17 -07003389 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003390 p.applicationInfo.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003391 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3392 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003393 p.applicationInfo.enabled = false;
3394 }
Amith Yamasani13593602012-03-22 16:16:17 -07003395 p.applicationInfo.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 return p.applicationInfo;
3397 }
3398
3399 // Make shallow copy so we can store the metadata/libraries safely
3400 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003401 if (userId != 0) {
3402 ai.uid = UserId.getUid(userId, ai.uid);
3403 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 if ((flags & PackageManager.GET_META_DATA) != 0) {
3406 ai.metaData = p.mAppMetaData;
3407 }
3408 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3409 ai.sharedLibraryFiles = p.usesLibraryFiles;
3410 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003411 if (!sCompatibilityModeEnabled) {
3412 ai.disableCompatibilityMode();
3413 }
Amith Yamasani13593602012-03-22 16:16:17 -07003414 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003415 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3416 } else {
3417 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3418 }
Amith Yamasani13593602012-03-22 16:16:17 -07003419 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003420 ai.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003421 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3422 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003423 ai.enabled = false;
3424 }
Amith Yamasani13593602012-03-22 16:16:17 -07003425 ai.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 return ai;
3427 }
3428
3429 public static final PermissionInfo generatePermissionInfo(
3430 Permission p, int flags) {
3431 if (p == null) return null;
3432 if ((flags&PackageManager.GET_META_DATA) == 0) {
3433 return p.info;
3434 }
3435 PermissionInfo pi = new PermissionInfo(p.info);
3436 pi.metaData = p.metaData;
3437 return pi;
3438 }
3439
3440 public static final PermissionGroupInfo generatePermissionGroupInfo(
3441 PermissionGroup pg, int flags) {
3442 if (pg == null) return null;
3443 if ((flags&PackageManager.GET_META_DATA) == 0) {
3444 return pg.info;
3445 }
3446 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3447 pgi.metaData = pg.metaData;
3448 return pgi;
3449 }
3450
3451 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003452 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003453
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003454 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3455 super(args, _info);
3456 info = _info;
3457 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003459
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003460 public void setPackageName(String packageName) {
3461 super.setPackageName(packageName);
3462 info.packageName = packageName;
3463 }
3464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003465 public String toString() {
3466 return "Activity{"
3467 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003468 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 }
3470 }
3471
Amith Yamasani13593602012-03-22 16:16:17 -07003472 public static final ActivityInfo generateActivityInfo(Activity a, int flags, boolean stopped,
3473 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 if (a == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003475 if (!copyNeeded(flags, a.owner, enabledState, a.metaData) && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 return a.info;
3477 }
3478 // Make shallow copies so we can store the metadata safely
3479 ActivityInfo ai = new ActivityInfo(a.info);
3480 ai.metaData = a.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003481 ai.applicationInfo = generateApplicationInfo(a.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 return ai;
3483 }
3484
3485 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003486 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003488 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3489 super(args, _info);
3490 info = _info;
3491 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003493
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003494 public void setPackageName(String packageName) {
3495 super.setPackageName(packageName);
3496 info.packageName = packageName;
3497 }
3498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 public String toString() {
3500 return "Service{"
3501 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003502 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 }
3504 }
3505
Amith Yamasani13593602012-03-22 16:16:17 -07003506 public static final ServiceInfo generateServiceInfo(Service s, int flags, boolean stopped,
3507 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 if (s == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003509 if (!copyNeeded(flags, s.owner, enabledState, s.metaData)
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003510 && userId == UserId.getUserId(s.info.applicationInfo.uid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 return s.info;
3512 }
3513 // Make shallow copies so we can store the metadata safely
3514 ServiceInfo si = new ServiceInfo(s.info);
3515 si.metaData = s.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003516 si.applicationInfo = generateApplicationInfo(s.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 return si;
3518 }
3519
3520 public final static class Provider extends Component {
3521 public final ProviderInfo info;
3522 public boolean syncable;
3523
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003524 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3525 super(args, _info);
3526 info = _info;
3527 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 syncable = false;
3529 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 public Provider(Provider existingProvider) {
3532 super(existingProvider);
3533 this.info = existingProvider.info;
3534 this.syncable = existingProvider.syncable;
3535 }
3536
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003537 public void setPackageName(String packageName) {
3538 super.setPackageName(packageName);
3539 info.packageName = packageName;
3540 }
3541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 public String toString() {
3543 return "Provider{"
3544 + Integer.toHexString(System.identityHashCode(this))
3545 + " " + info.name + "}";
3546 }
3547 }
3548
Amith Yamasani13593602012-03-22 16:16:17 -07003549 public static final ProviderInfo generateProviderInfo(Provider p, int flags, boolean stopped,
3550 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003552 if (!copyNeeded(flags, p.owner, enabledState, p.metaData)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Amith Yamasani742a6712011-05-04 14:49:28 -07003554 || p.info.uriPermissionPatterns == null)
3555 && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 return p.info;
3557 }
3558 // Make shallow copies so we can store the metadata safely
3559 ProviderInfo pi = new ProviderInfo(p.info);
3560 pi.metaData = p.metaData;
3561 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3562 pi.uriPermissionPatterns = null;
3563 }
Amith Yamasani13593602012-03-22 16:16:17 -07003564 pi.applicationInfo = generateApplicationInfo(p.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 return pi;
3566 }
3567
3568 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003569 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003571 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3572 super(args, _info);
3573 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003575
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003576 public void setPackageName(String packageName) {
3577 super.setPackageName(packageName);
3578 info.packageName = packageName;
3579 }
3580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 public String toString() {
3582 return "Instrumentation{"
3583 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003584 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 }
3586 }
3587
3588 public static final InstrumentationInfo generateInstrumentationInfo(
3589 Instrumentation i, int flags) {
3590 if (i == null) return null;
3591 if ((flags&PackageManager.GET_META_DATA) == 0) {
3592 return i.info;
3593 }
3594 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3595 ii.metaData = i.metaData;
3596 return ii;
3597 }
3598
3599 public static class IntentInfo extends IntentFilter {
3600 public boolean hasDefault;
3601 public int labelRes;
3602 public CharSequence nonLocalizedLabel;
3603 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003604 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
3606
3607 public final static class ActivityIntentInfo extends IntentInfo {
3608 public final Activity activity;
3609
3610 public ActivityIntentInfo(Activity _activity) {
3611 activity = _activity;
3612 }
3613
3614 public String toString() {
3615 return "ActivityIntentInfo{"
3616 + Integer.toHexString(System.identityHashCode(this))
3617 + " " + activity.info.name + "}";
3618 }
3619 }
3620
3621 public final static class ServiceIntentInfo extends IntentInfo {
3622 public final Service service;
3623
3624 public ServiceIntentInfo(Service _service) {
3625 service = _service;
3626 }
3627
3628 public String toString() {
3629 return "ServiceIntentInfo{"
3630 + Integer.toHexString(System.identityHashCode(this))
3631 + " " + service.info.name + "}";
3632 }
3633 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003634
3635 /**
3636 * @hide
3637 */
3638 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3639 sCompatibilityModeEnabled = compatibilityModeEnabled;
3640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641}