blob: ac750401a64e00bba16ad201c4015e91dff6c36e [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;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070031import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070033import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070035import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070036import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kenny Rootd63f7db2010-09-27 08:07:48 -070039import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Kenny Rootbcc954d2011-08-08 16:19:08 -070057import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.jar.JarEntry;
59import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070060import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Amith Yamasani742a6712011-05-04 14:49:28 -070062import com.android.internal.util.XmlUtils;
63
64import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
68 * Package archive parsing
69 *
70 * {@hide}
71 */
72public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070073 private static final boolean DEBUG_JAR = false;
74 private static final boolean DEBUG_PARSER = false;
75 private static final boolean DEBUG_BACKUP = false;
76
Kenny Rootbcc954d2011-08-08 16:19:08 -070077 /** File name in an APK for the Android manifest. */
78 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
79
Dianne Hackborna96cbb42009-05-13 15:06:13 -070080 /** @hide */
81 public static class NewPermissionInfo {
82 public final String name;
83 public final int sdkVersion;
84 public final int fileVersion;
85
86 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
87 this.name = name;
88 this.sdkVersion = sdkVersion;
89 this.fileVersion = fileVersion;
90 }
91 }
Dianne Hackborn79245122012-03-12 10:51:26 -070092
93 /** @hide */
94 public static class SplitPermissionInfo {
95 public final String rootPerm;
96 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070098
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700100 this.rootPerm = rootPerm;
101 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700102 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700103 }
104 }
105
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700106 /**
107 * List of new permissions that have been added since 1.0.
108 * NOTE: These must be declared in SDK version order, with permissions
109 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700110 * If sdkVersion is 0, then this is not a permission that we want to
111 * automatically add to older apps, but we do want to allow it to be
112 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700113 * @hide
114 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700115 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
116 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700117 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700118 android.os.Build.VERSION_CODES.DONUT, 0),
119 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
120 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700121 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Dianne Hackborn79245122012-03-12 10:51:26 -0700123 /**
124 * List of permissions that have been split into more granular or dependent
125 * permissions.
126 * @hide
127 */
128 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
129 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700130 // READ_EXTERNAL_STORAGE is always required when an app requests
131 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
132 // write access without read access. The hack here with the target
133 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700134 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700135 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700136 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700137 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
138 new String[] { android.Manifest.permission.READ_CALL_LOG },
139 android.os.Build.VERSION_CODES.JELLY_BEAN),
140 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
141 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
142 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700143 };
144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 private String mArchiveSourcePath;
146 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700147 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700148 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
149 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
150 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151
152 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
153
154 private static final Object mSync = new Object();
155 private static WeakReference<byte[]> mReadBuffer;
156
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700157 private static boolean sCompatibilityModeEnabled = true;
158 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700159
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700160 static class ParsePackageItemArgs {
161 final Package owner;
162 final String[] outError;
163 final int nameRes;
164 final int labelRes;
165 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700166 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700167
168 String tag;
169 TypedArray sa;
170
171 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700172 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700173 owner = _owner;
174 outError = _outError;
175 nameRes = _nameRes;
176 labelRes = _labelRes;
177 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700178 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700179 }
180 }
181
182 static class ParseComponentArgs extends ParsePackageItemArgs {
183 final String[] sepProcesses;
184 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800185 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700186 final int enabledRes;
187 int flags;
188
189 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700190 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800191 String[] _sepProcesses, int _processRes,
192 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700193 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700194 sepProcesses = _sepProcesses;
195 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800196 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700197 enabledRes = _enabledRes;
198 }
199 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800200
201 /* Light weight package info.
202 * @hide
203 */
204 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700205 public final String packageName;
206 public final int installLocation;
207 public final VerifierInfo[] verifiers;
208
209 public PackageLite(String packageName, int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800210 this.packageName = packageName;
211 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700212 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800213 }
214 }
215
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700216 private ParsePackageItemArgs mParseInstrumentationArgs;
217 private ParseComponentArgs mParseActivityArgs;
218 private ParseComponentArgs mParseActivityAliasArgs;
219 private ParseComponentArgs mParseServiceArgs;
220 private ParseComponentArgs mParseProviderArgs;
221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 /** If set to true, we will only allow package files that exactly match
223 * the DTD. Otherwise, we try to get as much from the package as we
224 * can without failing. This should normally be set to false, to
225 * support extensions to the DTD in future versions. */
226 private static final boolean RIGID_PARSER = false;
227
228 private static final String TAG = "PackageParser";
229
230 public PackageParser(String archiveSourcePath) {
231 mArchiveSourcePath = archiveSourcePath;
232 }
233
234 public void setSeparateProcesses(String[] procs) {
235 mSeparateProcesses = procs;
236 }
237
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700238 public void setOnlyCoreApps(boolean onlyCoreApps) {
239 mOnlyCoreApps = onlyCoreApps;
240 }
241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 private static final boolean isPackageFilename(String name) {
243 return name.endsWith(".apk");
244 }
245
Amith Yamasani13593602012-03-22 16:16:17 -0700246 public static PackageInfo generatePackageInfo(PackageParser.Package p,
247 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
248 HashSet<String> grantedPermissions) {
249
250 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
251 grantedPermissions, false, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700252 UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700253 }
254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 /**
256 * Generate and return the {@link PackageInfo} for a parsed package.
257 *
258 * @param p the parsed package.
259 * @param flags indicating which optional information is included.
260 */
261 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800262 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700263 HashSet<String> grantedPermissions, boolean stopped, int enabledState) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264
Amith Yamasani483f3b02012-03-13 16:08:00 -0700265 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700266 grantedPermissions, stopped, enabledState, UserHandle.getCallingUserId());
Amith Yamasani483f3b02012-03-13 16:08:00 -0700267 }
268
Amith Yamasani13593602012-03-22 16:16:17 -0700269 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700270 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Amith Yamasani13593602012-03-22 16:16:17 -0700271 HashSet<String> grantedPermissions, boolean stopped, int enabledState, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 PackageInfo pi = new PackageInfo();
274 pi.packageName = p.packageName;
275 pi.versionCode = p.mVersionCode;
276 pi.versionName = p.mVersionName;
277 pi.sharedUserId = p.mSharedUserId;
278 pi.sharedUserLabel = p.mSharedUserLabel;
Amith Yamasani13593602012-03-22 16:16:17 -0700279 pi.applicationInfo = generateApplicationInfo(p, flags, stopped, enabledState, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800280 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700281 pi.firstInstallTime = firstInstallTime;
282 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 if ((flags&PackageManager.GET_GIDS) != 0) {
284 pi.gids = gids;
285 }
286 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
287 int N = p.configPreferences.size();
288 if (N > 0) {
289 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700290 p.configPreferences.toArray(pi.configPreferences);
291 }
292 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
293 if (N > 0) {
294 pi.reqFeatures = new FeatureInfo[N];
295 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 }
297 }
298 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
299 int N = p.activities.size();
300 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700301 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
302 pi.activities = new ActivityInfo[N];
303 } else {
304 int num = 0;
305 for (int i=0; i<N; i++) {
306 if (p.activities.get(i).info.enabled) num++;
307 }
308 pi.activities = new ActivityInfo[num];
309 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700310 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 final Activity activity = p.activities.get(i);
312 if (activity.info.enabled
313 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700314 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Amith Yamasani13593602012-03-22 16:16:17 -0700315 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 }
317 }
318 }
319 }
320 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
321 int N = p.receivers.size();
322 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700323 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
324 pi.receivers = new ActivityInfo[N];
325 } else {
326 int num = 0;
327 for (int i=0; i<N; i++) {
328 if (p.receivers.get(i).info.enabled) num++;
329 }
330 pi.receivers = new ActivityInfo[num];
331 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700332 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 final Activity activity = p.receivers.get(i);
334 if (activity.info.enabled
335 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700336 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
337 stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 }
339 }
340 }
341 }
342 if ((flags&PackageManager.GET_SERVICES) != 0) {
343 int N = p.services.size();
344 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700345 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
346 pi.services = new ServiceInfo[N];
347 } else {
348 int num = 0;
349 for (int i=0; i<N; i++) {
350 if (p.services.get(i).info.enabled) num++;
351 }
352 pi.services = new ServiceInfo[num];
353 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700354 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 final Service service = p.services.get(i);
356 if (service.info.enabled
357 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700358 pi.services[j++] = generateServiceInfo(p.services.get(i), flags, stopped,
359 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
361 }
362 }
363 }
364 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
365 int N = p.providers.size();
366 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700367 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
368 pi.providers = new ProviderInfo[N];
369 } else {
370 int num = 0;
371 for (int i=0; i<N; i++) {
372 if (p.providers.get(i).info.enabled) num++;
373 }
374 pi.providers = new ProviderInfo[num];
375 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700376 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 final Provider provider = p.providers.get(i);
378 if (provider.info.enabled
379 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700380 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, stopped,
381 enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
383 }
384 }
385 }
386 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
387 int N = p.instrumentation.size();
388 if (N > 0) {
389 pi.instrumentation = new InstrumentationInfo[N];
390 for (int i=0; i<N; i++) {
391 pi.instrumentation[i] = generateInstrumentationInfo(
392 p.instrumentation.get(i), flags);
393 }
394 }
395 }
396 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
397 int N = p.permissions.size();
398 if (N > 0) {
399 pi.permissions = new PermissionInfo[N];
400 for (int i=0; i<N; i++) {
401 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
402 }
403 }
404 N = p.requestedPermissions.size();
405 if (N > 0) {
406 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800407 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800409 final String perm = p.requestedPermissions.get(i);
410 pi.requestedPermissions[i] = perm;
411 if (p.requestedPermissionsRequired.get(i)) {
412 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
413 }
414 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
415 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 }
418 }
419 }
420 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700421 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
422 if (N > 0) {
423 pi.signatures = new Signature[N];
424 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 }
426 }
427 return pi;
428 }
429
430 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
431 byte[] readBuffer) {
432 try {
433 // We must read the stream for the JarEntry to retrieve
434 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700435 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
437 // not using
438 }
439 is.close();
440 return je != null ? je.getCertificates() : null;
441 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700442 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700444 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700445 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700446 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 }
448 return null;
449 }
450
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800451 public final static int PARSE_IS_SYSTEM = 1<<0;
452 public final static int PARSE_CHATTY = 1<<1;
453 public final static int PARSE_MUST_BE_APK = 1<<2;
454 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
455 public final static int PARSE_FORWARD_LOCK = 1<<4;
456 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700457 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458
459 public int getParseError() {
460 return mParseError;
461 }
462
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800463 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 DisplayMetrics metrics, int flags) {
465 mParseError = PackageManager.INSTALL_SUCCEEDED;
466
467 mArchiveSourcePath = sourceFile.getPath();
468 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700469 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
471 return null;
472 }
473 if (!isPackageFilename(sourceFile.getName())
474 && (flags&PARSE_MUST_BE_APK) != 0) {
475 if ((flags&PARSE_IS_SYSTEM) == 0) {
476 // We expect to have non-.apk files in the system dir,
477 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700478 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
480 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
481 return null;
482 }
483
Kenny Rootd2d29252011-08-08 11:27:57 -0700484 if (DEBUG_JAR)
485 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486
487 XmlResourceParser parser = null;
488 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800489 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 boolean assetError = true;
491 try {
492 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700493 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800494 if (cookie != 0) {
495 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700496 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 -0800497 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700498 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 assetError = false;
500 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700501 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
503 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700504 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 + mArchiveSourcePath, e);
506 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800507 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 if (assmgr != null) assmgr.close();
509 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
510 return null;
511 }
512 String[] errorText = new String[1];
513 Package pkg = null;
514 Exception errorException = null;
515 try {
516 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 pkg = parsePackage(res, parser, flags, errorText);
518 } catch (Exception e) {
519 errorException = e;
520 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
521 }
522
523
524 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700525 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
526 // just means to skip this app so don't make a fuss about it.
527 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
528 if (errorException != null) {
529 Slog.w(TAG, mArchiveSourcePath, errorException);
530 } else {
531 Slog.w(TAG, mArchiveSourcePath + " (at "
532 + parser.getPositionDescription()
533 + "): " + errorText[0]);
534 }
535 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
536 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 }
539 parser.close();
540 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 return null;
542 }
543
544 parser.close();
545 assmgr.close();
546
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800547 // Set code and resource paths
548 pkg.mPath = destCodePath;
549 pkg.mScanPath = mArchiveSourcePath;
550 //pkg.applicationInfo.sourceDir = destCodePath;
551 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 pkg.mSignatures = null;
553
554 return pkg;
555 }
556
557 public boolean collectCertificates(Package pkg, int flags) {
558 pkg.mSignatures = null;
559
560 WeakReference<byte[]> readBufferRef;
561 byte[] readBuffer = null;
562 synchronized (mSync) {
563 readBufferRef = mReadBuffer;
564 if (readBufferRef != null) {
565 mReadBuffer = null;
566 readBuffer = readBufferRef.get();
567 }
568 if (readBuffer == null) {
569 readBuffer = new byte[8192];
570 readBufferRef = new WeakReference<byte[]>(readBuffer);
571 }
572 }
573
574 try {
575 JarFile jarFile = new JarFile(mArchiveSourcePath);
576
577 Certificate[] certs = null;
578
579 if ((flags&PARSE_IS_SYSTEM) != 0) {
580 // If this package comes from the system image, then we
581 // can trust it... we'll just use the AndroidManifest.xml
582 // to retrieve its signatures, not validating all of the
583 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700584 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 certs = loadCertificates(jarFile, jarEntry, readBuffer);
586 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700587 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 + " has no certificates at entry "
589 + jarEntry.getName() + "; ignoring!");
590 jarFile.close();
591 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
592 return false;
593 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700594 if (DEBUG_JAR) {
595 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 + " certs=" + (certs != null ? certs.length : 0));
597 if (certs != null) {
598 final int N = certs.length;
599 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700600 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 + certs[i].getPublicKey().getEncoded()
602 + " " + certs[i].getPublicKey());
603 }
604 }
605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700607 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700608 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700610 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700612
Kenny Rootbcc954d2011-08-08 16:19:08 -0700613 final String name = je.getName();
614
615 if (name.startsWith("META-INF/"))
616 continue;
617
618 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
619 final Attributes attributes = manifest.getAttributes(name);
620 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
621 }
622
623 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700624 if (DEBUG_JAR) {
625 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 + ": certs=" + certs + " ("
627 + (certs != null ? certs.length : 0) + ")");
628 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700631 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 + " has no certificates at entry "
633 + je.getName() + "; ignoring!");
634 jarFile.close();
635 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
636 return false;
637 } else if (certs == null) {
638 certs = localCerts;
639 } else {
640 // Ensure all certificates match.
641 for (int i=0; i<certs.length; i++) {
642 boolean found = false;
643 for (int j=0; j<localCerts.length; j++) {
644 if (certs[i] != null &&
645 certs[i].equals(localCerts[j])) {
646 found = true;
647 break;
648 }
649 }
650 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700651 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 + " has mismatched certificates at entry "
653 + je.getName() + "; ignoring!");
654 jarFile.close();
655 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
656 return false;
657 }
658 }
659 }
660 }
661 }
662 jarFile.close();
663
664 synchronized (mSync) {
665 mReadBuffer = readBufferRef;
666 }
667
668 if (certs != null && certs.length > 0) {
669 final int N = certs.length;
670 pkg.mSignatures = new Signature[certs.length];
671 for (int i=0; i<N; i++) {
672 pkg.mSignatures[i] = new Signature(
673 certs[i].getEncoded());
674 }
675 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700676 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 + " has no certificates; ignoring!");
678 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
679 return false;
680 }
681 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700682 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
684 return false;
685 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700686 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
688 return false;
689 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700690 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
692 return false;
693 }
694
695 return true;
696 }
697
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800698 /*
699 * Utility method that retrieves just the package name and install
700 * location from the apk location at the given file path.
701 * @param packageFilePath file location of the apk
702 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700703 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800704 */
705 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700707 final XmlResourceParser parser;
708 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 try {
710 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700711 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 -0800712 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700715 if (cookie == 0) {
716 return null;
717 }
718
Kenny Root05ca4c92011-09-15 10:36:25 -0700719 final DisplayMetrics metrics = new DisplayMetrics();
720 metrics.setToDefaults();
721 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700722 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 } catch (Exception e) {
724 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700725 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 + packageFilePath, e);
727 return null;
728 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700729
730 final AttributeSet attrs = parser;
731 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800732 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700734 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700736 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700738 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 } finally {
740 if (parser != null) parser.close();
741 if (assmgr != null) assmgr.close();
742 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800743 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700744 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 return null;
746 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800747 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 }
749
750 private static String validateName(String name, boolean requiresSeparator) {
751 final int N = name.length();
752 boolean hasSep = false;
753 boolean front = true;
754 for (int i=0; i<N; i++) {
755 final char c = name.charAt(i);
756 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
757 front = false;
758 continue;
759 }
760 if (!front) {
761 if ((c >= '0' && c <= '9') || c == '_') {
762 continue;
763 }
764 }
765 if (c == '.') {
766 hasSep = true;
767 front = true;
768 continue;
769 }
770 return "bad character '" + c + "'";
771 }
772 return hasSep || !requiresSeparator
773 ? null : "must have at least one '.' separator";
774 }
775
776 private static String parsePackageName(XmlPullParser parser,
777 AttributeSet attrs, int flags, String[] outError)
778 throws IOException, XmlPullParserException {
779
780 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700781 while ((type = parser.next()) != XmlPullParser.START_TAG
782 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 ;
784 }
785
Kenny Rootd2d29252011-08-08 11:27:57 -0700786 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 outError[0] = "No start tag found";
788 return null;
789 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700790 if (DEBUG_PARSER)
791 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 if (!parser.getName().equals("manifest")) {
793 outError[0] = "No <manifest> tag";
794 return null;
795 }
796 String pkgName = attrs.getAttributeValue(null, "package");
797 if (pkgName == null || pkgName.length() == 0) {
798 outError[0] = "<manifest> does not specify package";
799 return null;
800 }
801 String nameError = validateName(pkgName, true);
802 if (nameError != null && !"android".equals(pkgName)) {
803 outError[0] = "<manifest> specifies bad package name \""
804 + pkgName + "\": " + nameError;
805 return null;
806 }
807
808 return pkgName.intern();
809 }
810
Kenny Root05ca4c92011-09-15 10:36:25 -0700811 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
812 AttributeSet attrs, int flags, String[] outError) throws IOException,
813 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800814
815 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700816 while ((type = parser.next()) != XmlPullParser.START_TAG
817 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800818 ;
819 }
820
Kenny Rootd2d29252011-08-08 11:27:57 -0700821 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800822 outError[0] = "No start tag found";
823 return null;
824 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700825 if (DEBUG_PARSER)
826 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800827 if (!parser.getName().equals("manifest")) {
828 outError[0] = "No <manifest> tag";
829 return null;
830 }
831 String pkgName = attrs.getAttributeValue(null, "package");
832 if (pkgName == null || pkgName.length() == 0) {
833 outError[0] = "<manifest> does not specify package";
834 return null;
835 }
836 String nameError = validateName(pkgName, true);
837 if (nameError != null && !"android".equals(pkgName)) {
838 outError[0] = "<manifest> specifies bad package name \""
839 + pkgName + "\": " + nameError;
840 return null;
841 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700842 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800843 for (int i = 0; i < attrs.getAttributeCount(); i++) {
844 String attr = attrs.getAttributeName(i);
845 if (attr.equals("installLocation")) {
846 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700847 PARSE_DEFAULT_INSTALL_LOCATION);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800848 break;
849 }
850 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700851
852 // Only search the tree when the tag is directly below <manifest>
853 final int searchDepth = parser.getDepth() + 1;
854
855 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
856 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
857 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
858 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
859 continue;
860 }
861
862 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
863 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
864 if (verifier != null) {
865 verifiers.add(verifier);
866 }
867 }
868 }
869
870 return new PackageLite(pkgName.intern(), installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800871 }
872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 /**
874 * Temporary.
875 */
876 static public Signature stringToSignature(String str) {
877 final int N = str.length();
878 byte[] sig = new byte[N];
879 for (int i=0; i<N; i++) {
880 sig[i] = (byte)str.charAt(i);
881 }
882 return new Signature(sig);
883 }
884
885 private Package parsePackage(
886 Resources res, XmlResourceParser parser, int flags, String[] outError)
887 throws XmlPullParserException, IOException {
888 AttributeSet attrs = parser;
889
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700890 mParseInstrumentationArgs = null;
891 mParseActivityArgs = null;
892 mParseServiceArgs = null;
893 mParseProviderArgs = null;
894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 String pkgName = parsePackageName(parser, attrs, flags, outError);
896 if (pkgName == null) {
897 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
898 return null;
899 }
900 int type;
901
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700902 if (mOnlyCoreApps) {
903 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
904 if (!core) {
905 mParseError = PackageManager.INSTALL_SUCCEEDED;
906 return null;
907 }
908 }
909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 TypedArray sa = res.obtainAttributes(attrs,
914 com.android.internal.R.styleable.AndroidManifest);
915 pkg.mVersionCode = sa.getInteger(
916 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800917 pkg.mVersionName = sa.getNonConfigurationString(
918 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 if (pkg.mVersionName != null) {
920 pkg.mVersionName = pkg.mVersionName.intern();
921 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800922 String str = sa.getNonConfigurationString(
923 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
924 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 String nameError = validateName(str, true);
926 if (nameError != null && !"android".equals(pkgName)) {
927 outError[0] = "<manifest> specifies bad sharedUserId name \""
928 + str + "\": " + nameError;
929 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
930 return null;
931 }
932 pkg.mSharedUserId = str.intern();
933 pkg.mSharedUserLabel = sa.getResourceId(
934 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
935 }
936 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800937
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800938 pkg.installLocation = sa.getInteger(
939 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700940 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700941 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700942
943 /* Set the global "forward lock" flag */
944 if ((flags & PARSE_FORWARD_LOCK) != 0) {
945 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
946 }
947
948 /* Set the global "on SD card" flag */
949 if ((flags & PARSE_ON_SDCARD) != 0) {
950 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
951 }
952
Dianne Hackborn723738c2009-06-25 19:48:04 -0700953 // Resource boolean are -1, so 1 means we don't know the value.
954 int supportsSmallScreens = 1;
955 int supportsNormalScreens = 1;
956 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700957 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700958 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700959 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700962 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
963 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
964 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 continue;
966 }
967
968 String tagName = parser.getName();
969 if (tagName.equals("application")) {
970 if (foundApp) {
971 if (RIGID_PARSER) {
972 outError[0] = "<manifest> has more than one <application>";
973 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
974 return null;
975 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700976 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 XmlUtils.skipCurrentTag(parser);
978 continue;
979 }
980 }
981
982 foundApp = true;
983 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
984 return null;
985 }
986 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700987 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 return null;
989 }
990 } else if (tagName.equals("permission")) {
991 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
992 return null;
993 }
994 } else if (tagName.equals("permission-tree")) {
995 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
996 return null;
997 }
998 } else if (tagName.equals("uses-permission")) {
999 sa = res.obtainAttributes(attrs,
1000 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1001
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001002 // Note: don't allow this value to be a reference to a resource
1003 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 String name = sa.getNonResourceString(
1005 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne8241202012-04-06 13:39:09 -07001006 /* Not supporting optional permissions yet.
Dianne Hackborne639da72012-02-21 15:11:13 -08001007 boolean required = sa.getBoolean(
1008 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Dianne Hackborne8241202012-04-06 13:39:09 -07001009 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010
1011 sa.recycle();
1012
1013 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -07001014 pkg.requestedPermissions.add(name.intern());
Dianne Hackborne8241202012-04-06 13:39:09 -07001015 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 }
1017
1018 XmlUtils.skipCurrentTag(parser);
1019
1020 } else if (tagName.equals("uses-configuration")) {
1021 ConfigurationInfo cPref = new ConfigurationInfo();
1022 sa = res.obtainAttributes(attrs,
1023 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1024 cPref.reqTouchScreen = sa.getInt(
1025 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1026 Configuration.TOUCHSCREEN_UNDEFINED);
1027 cPref.reqKeyboardType = sa.getInt(
1028 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1029 Configuration.KEYBOARD_UNDEFINED);
1030 if (sa.getBoolean(
1031 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1032 false)) {
1033 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1034 }
1035 cPref.reqNavigation = sa.getInt(
1036 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1037 Configuration.NAVIGATION_UNDEFINED);
1038 if (sa.getBoolean(
1039 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1040 false)) {
1041 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1042 }
1043 sa.recycle();
1044 pkg.configPreferences.add(cPref);
1045
1046 XmlUtils.skipCurrentTag(parser);
1047
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001048 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001049 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001050 sa = res.obtainAttributes(attrs,
1051 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001052 // Note: don't allow this value to be a reference to a resource
1053 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001054 fi.name = sa.getNonResourceString(
1055 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1056 if (fi.name == null) {
1057 fi.reqGlEsVersion = sa.getInt(
1058 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1059 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1060 }
1061 if (sa.getBoolean(
1062 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1063 true)) {
1064 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1065 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001066 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001067 if (pkg.reqFeatures == null) {
1068 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1069 }
1070 pkg.reqFeatures.add(fi);
1071
1072 if (fi.name == null) {
1073 ConfigurationInfo cPref = new ConfigurationInfo();
1074 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1075 pkg.configPreferences.add(cPref);
1076 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001077
1078 XmlUtils.skipCurrentTag(parser);
1079
Dianne Hackborn851a5412009-05-08 12:06:44 -07001080 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001081 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 sa = res.obtainAttributes(attrs,
1083 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1084
Dianne Hackborn851a5412009-05-08 12:06:44 -07001085 int minVers = 0;
1086 String minCode = null;
1087 int targetVers = 0;
1088 String targetCode = null;
1089
1090 TypedValue val = sa.peekValue(
1091 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1092 if (val != null) {
1093 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1094 targetCode = minCode = val.string.toString();
1095 } else {
1096 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001097 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001098 }
1099 }
1100
1101 val = sa.peekValue(
1102 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1103 if (val != null) {
1104 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1105 targetCode = minCode = val.string.toString();
1106 } else {
1107 // If it's not a string, it's an integer.
1108 targetVers = val.data;
1109 }
1110 }
1111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 sa.recycle();
1113
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001114 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001115 if (!minCode.equals(SDK_CODENAME)) {
1116 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001117 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001118 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001119 } else {
1120 outError[0] = "Requires development platform " + minCode
1121 + " but this is a release platform.";
1122 }
1123 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1124 return null;
1125 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001126 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001127 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001128 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001129 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1130 return null;
1131 }
1132
Dianne Hackborn851a5412009-05-08 12:06:44 -07001133 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001134 if (!targetCode.equals(SDK_CODENAME)) {
1135 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001136 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001137 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001138 } else {
1139 outError[0] = "Requires development platform " + targetCode
1140 + " but this is a release platform.";
1141 }
1142 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1143 return null;
1144 }
1145 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001146 pkg.applicationInfo.targetSdkVersion
1147 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1148 } else {
1149 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152
1153 XmlUtils.skipCurrentTag(parser);
1154
Dianne Hackborn723738c2009-06-25 19:48:04 -07001155 } else if (tagName.equals("supports-screens")) {
1156 sa = res.obtainAttributes(attrs,
1157 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1158
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001159 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1160 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1161 0);
1162 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1163 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1164 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001165 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1166 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1167 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001168
Dianne Hackborn723738c2009-06-25 19:48:04 -07001169 // This is a trick to get a boolean and still able to detect
1170 // if a value was actually set.
1171 supportsSmallScreens = sa.getInteger(
1172 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1173 supportsSmallScreens);
1174 supportsNormalScreens = sa.getInteger(
1175 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1176 supportsNormalScreens);
1177 supportsLargeScreens = sa.getInteger(
1178 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1179 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001180 supportsXLargeScreens = sa.getInteger(
1181 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1182 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001183 resizeable = sa.getInteger(
1184 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001185 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001186 anyDensity = sa.getInteger(
1187 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1188 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001189
1190 sa.recycle();
1191
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001192 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001193
1194 } else if (tagName.equals("protected-broadcast")) {
1195 sa = res.obtainAttributes(attrs,
1196 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1197
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001198 // Note: don't allow this value to be a reference to a resource
1199 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001200 String name = sa.getNonResourceString(
1201 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1202
1203 sa.recycle();
1204
1205 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1206 if (pkg.protectedBroadcasts == null) {
1207 pkg.protectedBroadcasts = new ArrayList<String>();
1208 }
1209 if (!pkg.protectedBroadcasts.contains(name)) {
1210 pkg.protectedBroadcasts.add(name.intern());
1211 }
1212 }
1213
1214 XmlUtils.skipCurrentTag(parser);
1215
1216 } else if (tagName.equals("instrumentation")) {
1217 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1218 return null;
1219 }
1220
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001221 } else if (tagName.equals("original-package")) {
1222 sa = res.obtainAttributes(attrs,
1223 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1224
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001225 String orig =sa.getNonConfigurationString(
1226 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001227 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001228 if (pkg.mOriginalPackages == null) {
1229 pkg.mOriginalPackages = new ArrayList<String>();
1230 pkg.mRealPackage = pkg.packageName;
1231 }
1232 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001233 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001234
1235 sa.recycle();
1236
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001237 XmlUtils.skipCurrentTag(parser);
1238
1239 } else if (tagName.equals("adopt-permissions")) {
1240 sa = res.obtainAttributes(attrs,
1241 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1242
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001243 String name = sa.getNonConfigurationString(
1244 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001245
1246 sa.recycle();
1247
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001248 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001249 if (pkg.mAdoptPermissions == null) {
1250 pkg.mAdoptPermissions = new ArrayList<String>();
1251 }
1252 pkg.mAdoptPermissions.add(name);
1253 }
1254
1255 XmlUtils.skipCurrentTag(parser);
1256
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001257 } else if (tagName.equals("uses-gl-texture")) {
1258 // Just skip this tag
1259 XmlUtils.skipCurrentTag(parser);
1260 continue;
1261
1262 } else if (tagName.equals("compatible-screens")) {
1263 // Just skip this tag
1264 XmlUtils.skipCurrentTag(parser);
1265 continue;
1266
Dianne Hackborn854060a2009-07-09 18:14:31 -07001267 } else if (tagName.equals("eat-comment")) {
1268 // Just skip this tag
1269 XmlUtils.skipCurrentTag(parser);
1270 continue;
1271
1272 } else if (RIGID_PARSER) {
1273 outError[0] = "Bad element under <manifest>: "
1274 + parser.getName();
1275 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1276 return null;
1277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001279 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001280 + " at " + mArchiveSourcePath + " "
1281 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 XmlUtils.skipCurrentTag(parser);
1283 continue;
1284 }
1285 }
1286
1287 if (!foundApp && pkg.instrumentation.size() == 0) {
1288 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1289 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1290 }
1291
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001292 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001293 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001294 for (int ip=0; ip<NP; ip++) {
1295 final PackageParser.NewPermissionInfo npi
1296 = PackageParser.NEW_PERMISSIONS[ip];
1297 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1298 break;
1299 }
1300 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001301 if (implicitPerms == null) {
1302 implicitPerms = new StringBuilder(128);
1303 implicitPerms.append(pkg.packageName);
1304 implicitPerms.append(": compat added ");
1305 } else {
1306 implicitPerms.append(' ');
1307 }
1308 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001309 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001310 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001311 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001312 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001313 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001314 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001315 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001316
1317 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1318 for (int is=0; is<NS; is++) {
1319 final PackageParser.SplitPermissionInfo spi
1320 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001321 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1322 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001323 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001324 }
1325 for (int in=0; in<spi.newPerms.length; in++) {
1326 final String perm = spi.newPerms[in];
1327 if (!pkg.requestedPermissions.contains(perm)) {
1328 pkg.requestedPermissions.add(perm);
1329 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1330 }
1331 }
1332 }
1333
Dianne Hackborn723738c2009-06-25 19:48:04 -07001334 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1335 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001336 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001337 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1338 }
1339 if (supportsNormalScreens != 0) {
1340 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1341 }
1342 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1343 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001344 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001345 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1346 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001347 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1348 && pkg.applicationInfo.targetSdkVersion
1349 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1350 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1351 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001352 if (resizeable < 0 || (resizeable > 0
1353 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001354 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001355 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1356 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001357 if (anyDensity < 0 || (anyDensity > 0
1358 && pkg.applicationInfo.targetSdkVersion
1359 >= android.os.Build.VERSION_CODES.DONUT)) {
1360 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001361 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 return pkg;
1364 }
1365
1366 private static String buildClassName(String pkg, CharSequence clsSeq,
1367 String[] outError) {
1368 if (clsSeq == null || clsSeq.length() <= 0) {
1369 outError[0] = "Empty class name in package " + pkg;
1370 return null;
1371 }
1372 String cls = clsSeq.toString();
1373 char c = cls.charAt(0);
1374 if (c == '.') {
1375 return (pkg + cls).intern();
1376 }
1377 if (cls.indexOf('.') < 0) {
1378 StringBuilder b = new StringBuilder(pkg);
1379 b.append('.');
1380 b.append(cls);
1381 return b.toString().intern();
1382 }
1383 if (c >= 'a' && c <= 'z') {
1384 return cls.intern();
1385 }
1386 outError[0] = "Bad class name " + cls + " in package " + pkg;
1387 return null;
1388 }
1389
1390 private static String buildCompoundName(String pkg,
1391 CharSequence procSeq, String type, String[] outError) {
1392 String proc = procSeq.toString();
1393 char c = proc.charAt(0);
1394 if (pkg != null && c == ':') {
1395 if (proc.length() < 2) {
1396 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1397 + ": must be at least two characters";
1398 return null;
1399 }
1400 String subName = proc.substring(1);
1401 String nameError = validateName(subName, false);
1402 if (nameError != null) {
1403 outError[0] = "Invalid " + type + " name " + proc + " in package "
1404 + pkg + ": " + nameError;
1405 return null;
1406 }
1407 return (pkg + proc).intern();
1408 }
1409 String nameError = validateName(proc, true);
1410 if (nameError != null && !"system".equals(proc)) {
1411 outError[0] = "Invalid " + type + " name " + proc + " in package "
1412 + pkg + ": " + nameError;
1413 return null;
1414 }
1415 return proc.intern();
1416 }
1417
1418 private static String buildProcessName(String pkg, String defProc,
1419 CharSequence procSeq, int flags, String[] separateProcesses,
1420 String[] outError) {
1421 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1422 return defProc != null ? defProc : pkg;
1423 }
1424 if (separateProcesses != null) {
1425 for (int i=separateProcesses.length-1; i>=0; i--) {
1426 String sp = separateProcesses[i];
1427 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1428 return pkg;
1429 }
1430 }
1431 }
1432 if (procSeq == null || procSeq.length() <= 0) {
1433 return defProc;
1434 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001435 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 }
1437
1438 private static String buildTaskAffinityName(String pkg, String defProc,
1439 CharSequence procSeq, String[] outError) {
1440 if (procSeq == null) {
1441 return defProc;
1442 }
1443 if (procSeq.length() <= 0) {
1444 return null;
1445 }
1446 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1447 }
1448
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001449 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 XmlPullParser parser, AttributeSet attrs, String[] outError)
1451 throws XmlPullParserException, IOException {
1452 PermissionGroup perm = new PermissionGroup(owner);
1453
1454 TypedArray sa = res.obtainAttributes(attrs,
1455 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1456
1457 if (!parsePackageItemInfo(owner, perm.info, outError,
1458 "<permission-group>", sa,
1459 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1460 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001461 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1462 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 sa.recycle();
1464 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1465 return null;
1466 }
1467
1468 perm.info.descriptionRes = sa.getResourceId(
1469 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1470 0);
Dianne Hackborn4034bc42012-06-01 12:45:49 -07001471 perm.info.flags = 0;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001472 perm.info.priority = sa.getInt(
1473 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001474 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001475 perm.info.priority = 0;
1476 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477
1478 sa.recycle();
1479
1480 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1481 outError)) {
1482 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1483 return null;
1484 }
1485
1486 owner.permissionGroups.add(perm);
1487
1488 return perm;
1489 }
1490
1491 private Permission parsePermission(Package owner, Resources res,
1492 XmlPullParser parser, AttributeSet attrs, String[] outError)
1493 throws XmlPullParserException, IOException {
1494 Permission perm = new Permission(owner);
1495
1496 TypedArray sa = res.obtainAttributes(attrs,
1497 com.android.internal.R.styleable.AndroidManifestPermission);
1498
1499 if (!parsePackageItemInfo(owner, perm.info, outError,
1500 "<permission>", sa,
1501 com.android.internal.R.styleable.AndroidManifestPermission_name,
1502 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001503 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1504 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 sa.recycle();
1506 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1507 return null;
1508 }
1509
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001510 // Note: don't allow this value to be a reference to a resource
1511 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 perm.info.group = sa.getNonResourceString(
1513 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1514 if (perm.info.group != null) {
1515 perm.info.group = perm.info.group.intern();
1516 }
1517
1518 perm.info.descriptionRes = sa.getResourceId(
1519 com.android.internal.R.styleable.AndroidManifestPermission_description,
1520 0);
1521
1522 perm.info.protectionLevel = sa.getInt(
1523 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1524 PermissionInfo.PROTECTION_NORMAL);
1525
1526 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 if (perm.info.protectionLevel == -1) {
1529 outError[0] = "<permission> does not specify protectionLevel";
1530 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1531 return null;
1532 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001533
1534 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1535
1536 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1537 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1538 PermissionInfo.PROTECTION_SIGNATURE) {
1539 outError[0] = "<permission> protectionLevel specifies a flag but is "
1540 + "not based on signature type";
1541 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1542 return null;
1543 }
1544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545
1546 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1547 outError)) {
1548 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1549 return null;
1550 }
1551
1552 owner.permissions.add(perm);
1553
1554 return perm;
1555 }
1556
1557 private Permission parsePermissionTree(Package owner, Resources res,
1558 XmlPullParser parser, AttributeSet attrs, String[] outError)
1559 throws XmlPullParserException, IOException {
1560 Permission perm = new Permission(owner);
1561
1562 TypedArray sa = res.obtainAttributes(attrs,
1563 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1564
1565 if (!parsePackageItemInfo(owner, perm.info, outError,
1566 "<permission-tree>", sa,
1567 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1568 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001569 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1570 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 sa.recycle();
1572 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1573 return null;
1574 }
1575
1576 sa.recycle();
1577
1578 int index = perm.info.name.indexOf('.');
1579 if (index > 0) {
1580 index = perm.info.name.indexOf('.', index+1);
1581 }
1582 if (index < 0) {
1583 outError[0] = "<permission-tree> name has less than three segments: "
1584 + perm.info.name;
1585 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1586 return null;
1587 }
1588
1589 perm.info.descriptionRes = 0;
1590 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1591 perm.tree = true;
1592
1593 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1594 outError)) {
1595 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1596 return null;
1597 }
1598
1599 owner.permissions.add(perm);
1600
1601 return perm;
1602 }
1603
1604 private Instrumentation parseInstrumentation(Package owner, Resources res,
1605 XmlPullParser parser, AttributeSet attrs, String[] outError)
1606 throws XmlPullParserException, IOException {
1607 TypedArray sa = res.obtainAttributes(attrs,
1608 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1609
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001610 if (mParseInstrumentationArgs == null) {
1611 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1612 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1613 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001614 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1615 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001616 mParseInstrumentationArgs.tag = "<instrumentation>";
1617 }
1618
1619 mParseInstrumentationArgs.sa = sa;
1620
1621 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1622 new InstrumentationInfo());
1623 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 sa.recycle();
1625 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1626 return null;
1627 }
1628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001630 // Note: don't allow this value to be a reference to a resource
1631 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 str = sa.getNonResourceString(
1633 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1634 a.info.targetPackage = str != null ? str.intern() : null;
1635
1636 a.info.handleProfiling = sa.getBoolean(
1637 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1638 false);
1639
1640 a.info.functionalTest = sa.getBoolean(
1641 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1642 false);
1643
1644 sa.recycle();
1645
1646 if (a.info.targetPackage == null) {
1647 outError[0] = "<instrumentation> does not specify targetPackage";
1648 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1649 return null;
1650 }
1651
1652 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1653 outError)) {
1654 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1655 return null;
1656 }
1657
1658 owner.instrumentation.add(a);
1659
1660 return a;
1661 }
1662
1663 private boolean parseApplication(Package owner, Resources res,
1664 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1665 throws XmlPullParserException, IOException {
1666 final ApplicationInfo ai = owner.applicationInfo;
1667 final String pkgName = owner.applicationInfo.packageName;
1668
1669 TypedArray sa = res.obtainAttributes(attrs,
1670 com.android.internal.R.styleable.AndroidManifestApplication);
1671
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001672 String name = sa.getNonConfigurationString(
1673 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 if (name != null) {
1675 ai.className = buildClassName(pkgName, name, outError);
1676 if (ai.className == null) {
1677 sa.recycle();
1678 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1679 return false;
1680 }
1681 }
1682
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001683 String manageSpaceActivity = sa.getNonConfigurationString(
1684 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 if (manageSpaceActivity != null) {
1686 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1687 outError);
1688 }
1689
Christopher Tate181fafa2009-05-14 11:12:14 -07001690 boolean allowBackup = sa.getBoolean(
1691 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1692 if (allowBackup) {
1693 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001694
Christopher Tate3de55bc2010-03-12 17:28:08 -08001695 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1696 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001697 String backupAgent = sa.getNonConfigurationString(
1698 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001699 if (backupAgent != null) {
1700 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001701 if (DEBUG_BACKUP) {
1702 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001703 + " from " + pkgName + "+" + backupAgent);
1704 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001705
1706 if (sa.getBoolean(
1707 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1708 true)) {
1709 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1710 }
1711 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001712 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1713 false)) {
1714 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1715 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001716 }
1717 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 TypedValue v = sa.peekValue(
1720 com.android.internal.R.styleable.AndroidManifestApplication_label);
1721 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1722 ai.nonLocalizedLabel = v.coerceToString();
1723 }
1724
1725 ai.icon = sa.getResourceId(
1726 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001727 ai.logo = sa.getResourceId(
1728 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001730 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 ai.descriptionRes = sa.getResourceId(
1732 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1733
1734 if ((flags&PARSE_IS_SYSTEM) != 0) {
1735 if (sa.getBoolean(
1736 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1737 false)) {
1738 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1739 }
1740 }
1741
1742 if (sa.getBoolean(
1743 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1744 false)) {
1745 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1746 }
1747
1748 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001749 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001750 false)) {
1751 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1752 }
1753
Romain Guy529b60a2010-08-03 18:05:47 -07001754 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001755 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001756 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001757
1758 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1760 true)) {
1761 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1762 }
1763
1764 if (sa.getBoolean(
1765 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1766 false)) {
1767 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1768 }
1769
1770 if (sa.getBoolean(
1771 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1772 true)) {
1773 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1774 }
1775
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001776 if (sa.getBoolean(
1777 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001778 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001779 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1780 }
1781
Jason parksa3cdaa52011-01-13 14:15:43 -06001782 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001783 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001784 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001785 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001786 }
1787
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001788 if (sa.getBoolean(
1789 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1790 false /* default is no RTL support*/)) {
1791 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1792 }
1793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001795 str = sa.getNonConfigurationString(
1796 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1798
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001799 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1800 str = sa.getNonConfigurationString(
1801 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1802 } else {
1803 // Some older apps have been seen to use a resource reference
1804 // here that on older builds was ignored (with a warning). We
1805 // need to continue to do this for them so they don't break.
1806 str = sa.getNonResourceString(
1807 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1810 str, outError);
1811
1812 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001813 CharSequence pname;
1814 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1815 pname = sa.getNonConfigurationString(
1816 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1817 } else {
1818 // Some older apps have been seen to use a resource reference
1819 // here that on older builds was ignored (with a warning). We
1820 // need to continue to do this for them so they don't break.
1821 pname = sa.getNonResourceString(
1822 com.android.internal.R.styleable.AndroidManifestApplication_process);
1823 }
1824 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 flags, mSeparateProcesses, outError);
1826
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001827 ai.enabled = sa.getBoolean(
1828 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001829
Dianne Hackborn02486b12010-08-26 14:18:37 -07001830 if (false) {
1831 if (sa.getBoolean(
1832 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1833 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001834 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001835
1836 // A heavy-weight application can not be in a custom process.
1837 // We can do direct compare because we intern all strings.
1838 if (ai.processName != null && ai.processName != ai.packageName) {
1839 outError[0] = "cantSaveState applications can not use custom processes";
1840 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001841 }
1842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 }
1844
Adam Powell269248d2011-08-02 10:26:54 -07001845 ai.uiOptions = sa.getInt(
1846 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 sa.recycle();
1849
1850 if (outError[0] != null) {
1851 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1852 return false;
1853 }
1854
1855 final int innerDepth = parser.getDepth();
1856
1857 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001858 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1859 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1860 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 continue;
1862 }
1863
1864 String tagName = parser.getName();
1865 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001866 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1867 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 if (a == null) {
1869 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1870 return false;
1871 }
1872
1873 owner.activities.add(a);
1874
1875 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001876 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 if (a == null) {
1878 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1879 return false;
1880 }
1881
1882 owner.receivers.add(a);
1883
1884 } else if (tagName.equals("service")) {
1885 Service s = parseService(owner, res, parser, attrs, flags, outError);
1886 if (s == null) {
1887 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1888 return false;
1889 }
1890
1891 owner.services.add(s);
1892
1893 } else if (tagName.equals("provider")) {
1894 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1895 if (p == null) {
1896 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1897 return false;
1898 }
1899
1900 owner.providers.add(p);
1901
1902 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001903 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 if (a == null) {
1905 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1906 return false;
1907 }
1908
1909 owner.activities.add(a);
1910
1911 } else if (parser.getName().equals("meta-data")) {
1912 // note: application meta-data is stored off to the side, so it can
1913 // remain null in the primary copy (we like to avoid extra copies because
1914 // it can be large)
1915 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1916 outError)) == null) {
1917 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1918 return false;
1919 }
1920
1921 } else if (tagName.equals("uses-library")) {
1922 sa = res.obtainAttributes(attrs,
1923 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1924
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001925 // Note: don't allow this value to be a reference to a resource
1926 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 String lname = sa.getNonResourceString(
1928 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001929 boolean req = sa.getBoolean(
1930 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1931 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932
1933 sa.recycle();
1934
Dianne Hackborn49237342009-08-27 20:08:01 -07001935 if (lname != null) {
1936 if (req) {
1937 if (owner.usesLibraries == null) {
1938 owner.usesLibraries = new ArrayList<String>();
1939 }
1940 if (!owner.usesLibraries.contains(lname)) {
1941 owner.usesLibraries.add(lname.intern());
1942 }
1943 } else {
1944 if (owner.usesOptionalLibraries == null) {
1945 owner.usesOptionalLibraries = new ArrayList<String>();
1946 }
1947 if (!owner.usesOptionalLibraries.contains(lname)) {
1948 owner.usesOptionalLibraries.add(lname.intern());
1949 }
1950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 }
1952
1953 XmlUtils.skipCurrentTag(parser);
1954
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001955 } else if (tagName.equals("uses-package")) {
1956 // Dependencies for app installers; we don't currently try to
1957 // enforce this.
1958 XmlUtils.skipCurrentTag(parser);
1959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 } else {
1961 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001962 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001963 + " at " + mArchiveSourcePath + " "
1964 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 XmlUtils.skipCurrentTag(parser);
1966 continue;
1967 } else {
1968 outError[0] = "Bad element under <application>: " + tagName;
1969 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1970 return false;
1971 }
1972 }
1973 }
1974
1975 return true;
1976 }
1977
1978 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1979 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001980 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001981 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 if (name == null) {
1983 outError[0] = tag + " does not specify android:name";
1984 return false;
1985 }
1986
1987 outInfo.name
1988 = buildClassName(owner.applicationInfo.packageName, name, outError);
1989 if (outInfo.name == null) {
1990 return false;
1991 }
1992
1993 int iconVal = sa.getResourceId(iconRes, 0);
1994 if (iconVal != 0) {
1995 outInfo.icon = iconVal;
1996 outInfo.nonLocalizedLabel = null;
1997 }
Adam Powell81cd2e92010-04-21 16:35:18 -07001998
1999 int logoVal = sa.getResourceId(logoRes, 0);
2000 if (logoVal != 0) {
2001 outInfo.logo = logoVal;
2002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003
2004 TypedValue v = sa.peekValue(labelRes);
2005 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2006 outInfo.nonLocalizedLabel = v.coerceToString();
2007 }
2008
2009 outInfo.packageName = owner.packageName;
2010
2011 return true;
2012 }
2013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 private Activity parseActivity(Package owner, Resources res,
2015 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002016 boolean receiver, boolean hardwareAccelerated)
2017 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 TypedArray sa = res.obtainAttributes(attrs,
2019 com.android.internal.R.styleable.AndroidManifestActivity);
2020
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002021 if (mParseActivityArgs == null) {
2022 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2023 com.android.internal.R.styleable.AndroidManifestActivity_name,
2024 com.android.internal.R.styleable.AndroidManifestActivity_label,
2025 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002026 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002027 mSeparateProcesses,
2028 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002029 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002030 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2031 }
2032
2033 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2034 mParseActivityArgs.sa = sa;
2035 mParseActivityArgs.flags = flags;
2036
2037 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2038 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 sa.recycle();
2040 return null;
2041 }
2042
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002043 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2045 if (setExported) {
2046 a.info.exported = sa.getBoolean(
2047 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2048 }
2049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 a.info.theme = sa.getResourceId(
2051 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2052
Adam Powell269248d2011-08-02 10:26:54 -07002053 a.info.uiOptions = sa.getInt(
2054 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2055 a.info.applicationInfo.uiOptions);
2056
Adam Powelldd8fab22012-03-22 17:47:27 -07002057 String parentName = sa.getNonConfigurationString(
2058 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2059 if (parentName != null) {
2060 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2061 if (outError[0] == null) {
2062 a.info.parentActivityName = parentClassName;
2063 } else {
2064 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2065 parentName);
2066 outError[0] = null;
2067 }
2068 }
2069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002071 str = sa.getNonConfigurationString(
2072 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 if (str == null) {
2074 a.info.permission = owner.applicationInfo.permission;
2075 } else {
2076 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2077 }
2078
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002079 str = sa.getNonConfigurationString(
2080 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2082 owner.applicationInfo.taskAffinity, str, outError);
2083
2084 a.info.flags = 0;
2085 if (sa.getBoolean(
2086 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2087 false)) {
2088 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2089 }
2090
2091 if (sa.getBoolean(
2092 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2093 false)) {
2094 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2095 }
2096
2097 if (sa.getBoolean(
2098 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2099 false)) {
2100 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2101 }
2102
2103 if (sa.getBoolean(
2104 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2105 false)) {
2106 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2107 }
2108
2109 if (sa.getBoolean(
2110 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2111 false)) {
2112 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2113 }
2114
2115 if (sa.getBoolean(
2116 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2117 false)) {
2118 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2119 }
2120
2121 if (sa.getBoolean(
2122 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2123 false)) {
2124 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2125 }
2126
2127 if (sa.getBoolean(
2128 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2129 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2130 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2131 }
2132
Dianne Hackbornffa42482009-09-23 22:20:11 -07002133 if (sa.getBoolean(
2134 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2135 false)) {
2136 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2137 }
2138
Daniel Sandler613dde42010-06-21 13:46:39 -04002139 if (sa.getBoolean(
2140 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2141 false)) {
2142 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2143 }
Romain Guy529b60a2010-08-03 18:05:47 -07002144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002146 if (sa.getBoolean(
2147 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2148 hardwareAccelerated)) {
2149 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2150 }
2151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 a.info.launchMode = sa.getInt(
2153 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2154 ActivityInfo.LAUNCH_MULTIPLE);
2155 a.info.screenOrientation = sa.getInt(
2156 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2157 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2158 a.info.configChanges = sa.getInt(
2159 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2160 0);
2161 a.info.softInputMode = sa.getInt(
2162 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2163 0);
2164 } else {
2165 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2166 a.info.configChanges = 0;
2167 }
2168
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002169 if (receiver) {
2170 if (sa.getBoolean(
2171 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2172 false)) {
2173 a.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2174 if (a.info.exported) {
2175 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2176 + a.className + " at " + mArchiveSourcePath + " "
2177 + parser.getPositionDescription());
2178 a.info.exported = false;
2179 }
2180 setExported = true;
2181 }
2182 }
2183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 sa.recycle();
2185
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002186 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002187 // A heavy-weight application can not have receives in its main process
2188 // We can do direct compare because we intern all strings.
2189 if (a.info.processName == owner.packageName) {
2190 outError[0] = "Heavy-weight applications can not have receivers in main process";
2191 }
2192 }
2193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 if (outError[0] != null) {
2195 return null;
2196 }
2197
2198 int outerDepth = parser.getDepth();
2199 int type;
2200 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2201 && (type != XmlPullParser.END_TAG
2202 || parser.getDepth() > outerDepth)) {
2203 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2204 continue;
2205 }
2206
2207 if (parser.getName().equals("intent-filter")) {
2208 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2209 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2210 return null;
2211 }
2212 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002213 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002214 + mArchiveSourcePath + " "
2215 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 } else {
2217 a.intents.add(intent);
2218 }
2219 } else if (parser.getName().equals("meta-data")) {
2220 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2221 outError)) == null) {
2222 return null;
2223 }
2224 } else {
2225 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002226 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002228 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002229 + " at " + mArchiveSourcePath + " "
2230 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002232 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002233 + " at " + mArchiveSourcePath + " "
2234 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 }
2236 XmlUtils.skipCurrentTag(parser);
2237 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002239 if (receiver) {
2240 outError[0] = "Bad element under <receiver>: " + parser.getName();
2241 } else {
2242 outError[0] = "Bad element under <activity>: " + parser.getName();
2243 }
2244 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 }
2247 }
2248
2249 if (!setExported) {
2250 a.info.exported = a.intents.size() > 0;
2251 }
2252
2253 return a;
2254 }
2255
2256 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2258 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 TypedArray sa = res.obtainAttributes(attrs,
2260 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2261
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002262 String targetActivity = sa.getNonConfigurationString(
2263 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 if (targetActivity == null) {
2265 outError[0] = "<activity-alias> does not specify android:targetActivity";
2266 sa.recycle();
2267 return null;
2268 }
2269
2270 targetActivity = buildClassName(owner.applicationInfo.packageName,
2271 targetActivity, outError);
2272 if (targetActivity == null) {
2273 sa.recycle();
2274 return null;
2275 }
2276
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002277 if (mParseActivityAliasArgs == null) {
2278 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2279 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2280 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2281 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002282 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002283 mSeparateProcesses,
2284 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002285 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002286 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2287 mParseActivityAliasArgs.tag = "<activity-alias>";
2288 }
2289
2290 mParseActivityAliasArgs.sa = sa;
2291 mParseActivityAliasArgs.flags = flags;
2292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 Activity target = null;
2294
2295 final int NA = owner.activities.size();
2296 for (int i=0; i<NA; i++) {
2297 Activity t = owner.activities.get(i);
2298 if (targetActivity.equals(t.info.name)) {
2299 target = t;
2300 break;
2301 }
2302 }
2303
2304 if (target == null) {
2305 outError[0] = "<activity-alias> target activity " + targetActivity
2306 + " not found in manifest";
2307 sa.recycle();
2308 return null;
2309 }
2310
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002311 ActivityInfo info = new ActivityInfo();
2312 info.targetActivity = targetActivity;
2313 info.configChanges = target.info.configChanges;
2314 info.flags = target.info.flags;
2315 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002316 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002317 info.labelRes = target.info.labelRes;
2318 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2319 info.launchMode = target.info.launchMode;
2320 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002321 if (info.descriptionRes == 0) {
2322 info.descriptionRes = target.info.descriptionRes;
2323 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002324 info.screenOrientation = target.info.screenOrientation;
2325 info.taskAffinity = target.info.taskAffinity;
2326 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002327 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002328 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002329 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002330
2331 Activity a = new Activity(mParseActivityAliasArgs, info);
2332 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 sa.recycle();
2334 return null;
2335 }
2336
2337 final boolean setExported = sa.hasValue(
2338 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2339 if (setExported) {
2340 a.info.exported = sa.getBoolean(
2341 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2342 }
2343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002345 str = sa.getNonConfigurationString(
2346 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 if (str != null) {
2348 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2349 }
2350
Adam Powelldd8fab22012-03-22 17:47:27 -07002351 String parentName = sa.getNonConfigurationString(
2352 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2353 0);
2354 if (parentName != null) {
2355 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2356 if (outError[0] == null) {
2357 a.info.parentActivityName = parentClassName;
2358 } else {
2359 Log.e(TAG, "Activity alias " + a.info.name +
2360 " specified invalid parentActivityName " + parentName);
2361 outError[0] = null;
2362 }
2363 }
2364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 sa.recycle();
2366
2367 if (outError[0] != null) {
2368 return null;
2369 }
2370
2371 int outerDepth = parser.getDepth();
2372 int type;
2373 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2374 && (type != XmlPullParser.END_TAG
2375 || parser.getDepth() > outerDepth)) {
2376 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2377 continue;
2378 }
2379
2380 if (parser.getName().equals("intent-filter")) {
2381 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2382 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2383 return null;
2384 }
2385 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002386 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002387 + mArchiveSourcePath + " "
2388 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 } else {
2390 a.intents.add(intent);
2391 }
2392 } else if (parser.getName().equals("meta-data")) {
2393 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2394 outError)) == null) {
2395 return null;
2396 }
2397 } else {
2398 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002399 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002400 + " at " + mArchiveSourcePath + " "
2401 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 XmlUtils.skipCurrentTag(parser);
2403 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002404 } else {
2405 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2406 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 }
2409 }
2410
2411 if (!setExported) {
2412 a.info.exported = a.intents.size() > 0;
2413 }
2414
2415 return a;
2416 }
2417
2418 private Provider parseProvider(Package owner, Resources res,
2419 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2420 throws XmlPullParserException, IOException {
2421 TypedArray sa = res.obtainAttributes(attrs,
2422 com.android.internal.R.styleable.AndroidManifestProvider);
2423
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002424 if (mParseProviderArgs == null) {
2425 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2426 com.android.internal.R.styleable.AndroidManifestProvider_name,
2427 com.android.internal.R.styleable.AndroidManifestProvider_label,
2428 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002429 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002430 mSeparateProcesses,
2431 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002432 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002433 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2434 mParseProviderArgs.tag = "<provider>";
2435 }
2436
2437 mParseProviderArgs.sa = sa;
2438 mParseProviderArgs.flags = flags;
2439
2440 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2441 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 sa.recycle();
2443 return null;
2444 }
2445
Nick Kralevichf097b162012-07-28 12:43:48 -07002446 boolean providerExportedDefault = false;
2447
2448 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2449 // For compatibility, applications targeting API level 16 or lower
2450 // should have their content providers exported by default, unless they
2451 // specify otherwise.
2452 providerExportedDefault = true;
2453 }
2454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002456 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2457 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002459 String cpname = sa.getNonConfigurationString(
2460 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461
2462 p.info.isSyncable = sa.getBoolean(
2463 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2464 false);
2465
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002466 String permission = sa.getNonConfigurationString(
2467 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2468 String str = sa.getNonConfigurationString(
2469 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 if (str == null) {
2471 str = permission;
2472 }
2473 if (str == null) {
2474 p.info.readPermission = owner.applicationInfo.permission;
2475 } else {
2476 p.info.readPermission =
2477 str.length() > 0 ? str.toString().intern() : null;
2478 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002479 str = sa.getNonConfigurationString(
2480 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 if (str == null) {
2482 str = permission;
2483 }
2484 if (str == null) {
2485 p.info.writePermission = owner.applicationInfo.permission;
2486 } else {
2487 p.info.writePermission =
2488 str.length() > 0 ? str.toString().intern() : null;
2489 }
2490
2491 p.info.grantUriPermissions = sa.getBoolean(
2492 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2493 false);
2494
2495 p.info.multiprocess = sa.getBoolean(
2496 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2497 false);
2498
2499 p.info.initOrder = sa.getInt(
2500 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2501 0);
2502
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002503 p.info.flags = 0;
2504
2505 if (sa.getBoolean(
2506 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2507 false)) {
2508 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2509 if (p.info.exported) {
2510 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2511 + p.className + " at " + mArchiveSourcePath + " "
2512 + parser.getPositionDescription());
2513 p.info.exported = false;
2514 }
2515 }
2516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 sa.recycle();
2518
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002519 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002520 // A heavy-weight application can not have providers in its main process
2521 // We can do direct compare because we intern all strings.
2522 if (p.info.processName == owner.packageName) {
2523 outError[0] = "Heavy-weight applications can not have providers in main process";
2524 return null;
2525 }
2526 }
2527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002529 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 return null;
2531 }
2532 p.info.authority = cpname.intern();
2533
2534 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2535 return null;
2536 }
2537
2538 return p;
2539 }
2540
2541 private boolean parseProviderTags(Resources res,
2542 XmlPullParser parser, AttributeSet attrs,
2543 Provider outInfo, String[] outError)
2544 throws XmlPullParserException, IOException {
2545 int outerDepth = parser.getDepth();
2546 int type;
2547 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2548 && (type != XmlPullParser.END_TAG
2549 || parser.getDepth() > outerDepth)) {
2550 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2551 continue;
2552 }
2553
2554 if (parser.getName().equals("meta-data")) {
2555 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2556 outInfo.metaData, outError)) == null) {
2557 return false;
2558 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 } else if (parser.getName().equals("grant-uri-permission")) {
2561 TypedArray sa = res.obtainAttributes(attrs,
2562 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2563
2564 PatternMatcher pa = null;
2565
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002566 String str = sa.getNonConfigurationString(
2567 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 if (str != null) {
2569 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2570 }
2571
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002572 str = sa.getNonConfigurationString(
2573 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 if (str != null) {
2575 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2576 }
2577
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002578 str = sa.getNonConfigurationString(
2579 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 if (str != null) {
2581 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2582 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 sa.recycle();
2585
2586 if (pa != null) {
2587 if (outInfo.info.uriPermissionPatterns == null) {
2588 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2589 outInfo.info.uriPermissionPatterns[0] = pa;
2590 } else {
2591 final int N = outInfo.info.uriPermissionPatterns.length;
2592 PatternMatcher[] newp = new PatternMatcher[N+1];
2593 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2594 newp[N] = pa;
2595 outInfo.info.uriPermissionPatterns = newp;
2596 }
2597 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002598 } else {
2599 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002600 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002601 + parser.getName() + " at " + mArchiveSourcePath + " "
2602 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002603 XmlUtils.skipCurrentTag(parser);
2604 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002605 } else {
2606 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2607 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002608 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002609 }
2610 XmlUtils.skipCurrentTag(parser);
2611
2612 } else if (parser.getName().equals("path-permission")) {
2613 TypedArray sa = res.obtainAttributes(attrs,
2614 com.android.internal.R.styleable.AndroidManifestPathPermission);
2615
2616 PathPermission pa = null;
2617
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002618 String permission = sa.getNonConfigurationString(
2619 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2620 String readPermission = sa.getNonConfigurationString(
2621 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002622 if (readPermission == null) {
2623 readPermission = permission;
2624 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002625 String writePermission = sa.getNonConfigurationString(
2626 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002627 if (writePermission == null) {
2628 writePermission = permission;
2629 }
2630
2631 boolean havePerm = false;
2632 if (readPermission != null) {
2633 readPermission = readPermission.intern();
2634 havePerm = true;
2635 }
2636 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002637 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002638 havePerm = true;
2639 }
2640
2641 if (!havePerm) {
2642 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002643 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002644 + parser.getName() + " at " + mArchiveSourcePath + " "
2645 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002646 XmlUtils.skipCurrentTag(parser);
2647 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002648 } else {
2649 outError[0] = "No readPermission or writePermssion for <path-permission>";
2650 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002651 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002652 }
2653
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002654 String path = sa.getNonConfigurationString(
2655 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002656 if (path != null) {
2657 pa = new PathPermission(path,
2658 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2659 }
2660
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002661 path = sa.getNonConfigurationString(
2662 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002663 if (path != null) {
2664 pa = new PathPermission(path,
2665 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2666 }
2667
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002668 path = sa.getNonConfigurationString(
2669 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002670 if (path != null) {
2671 pa = new PathPermission(path,
2672 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2673 }
2674
2675 sa.recycle();
2676
2677 if (pa != null) {
2678 if (outInfo.info.pathPermissions == null) {
2679 outInfo.info.pathPermissions = new PathPermission[1];
2680 outInfo.info.pathPermissions[0] = pa;
2681 } else {
2682 final int N = outInfo.info.pathPermissions.length;
2683 PathPermission[] newp = new PathPermission[N+1];
2684 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2685 newp[N] = pa;
2686 outInfo.info.pathPermissions = newp;
2687 }
2688 } else {
2689 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002690 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002691 + parser.getName() + " at " + mArchiveSourcePath + " "
2692 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002693 XmlUtils.skipCurrentTag(parser);
2694 continue;
2695 }
2696 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2697 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 }
2699 XmlUtils.skipCurrentTag(parser);
2700
2701 } else {
2702 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002703 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002704 + parser.getName() + " at " + mArchiveSourcePath + " "
2705 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002706 XmlUtils.skipCurrentTag(parser);
2707 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002708 } else {
2709 outError[0] = "Bad element under <provider>: " + parser.getName();
2710 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 }
2713 }
2714 return true;
2715 }
2716
2717 private Service parseService(Package owner, Resources res,
2718 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2719 throws XmlPullParserException, IOException {
2720 TypedArray sa = res.obtainAttributes(attrs,
2721 com.android.internal.R.styleable.AndroidManifestService);
2722
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002723 if (mParseServiceArgs == null) {
2724 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2725 com.android.internal.R.styleable.AndroidManifestService_name,
2726 com.android.internal.R.styleable.AndroidManifestService_label,
2727 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002728 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002729 mSeparateProcesses,
2730 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002731 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002732 com.android.internal.R.styleable.AndroidManifestService_enabled);
2733 mParseServiceArgs.tag = "<service>";
2734 }
2735
2736 mParseServiceArgs.sa = sa;
2737 mParseServiceArgs.flags = flags;
2738
2739 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2740 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 sa.recycle();
2742 return null;
2743 }
2744
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002745 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 com.android.internal.R.styleable.AndroidManifestService_exported);
2747 if (setExported) {
2748 s.info.exported = sa.getBoolean(
2749 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2750 }
2751
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002752 String str = sa.getNonConfigurationString(
2753 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 if (str == null) {
2755 s.info.permission = owner.applicationInfo.permission;
2756 } else {
2757 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2758 }
2759
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002760 s.info.flags = 0;
2761 if (sa.getBoolean(
2762 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2763 false)) {
2764 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2765 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002766 if (sa.getBoolean(
2767 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2768 false)) {
2769 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2770 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002771 if (sa.getBoolean(
2772 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2773 false)) {
2774 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2775 if (s.info.exported) {
2776 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2777 + s.className + " at " + mArchiveSourcePath + " "
2778 + parser.getPositionDescription());
2779 s.info.exported = false;
2780 }
2781 setExported = true;
2782 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 sa.recycle();
2785
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002786 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002787 // A heavy-weight application can not have services in its main process
2788 // We can do direct compare because we intern all strings.
2789 if (s.info.processName == owner.packageName) {
2790 outError[0] = "Heavy-weight applications can not have services in main process";
2791 return null;
2792 }
2793 }
2794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 int outerDepth = parser.getDepth();
2796 int type;
2797 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2798 && (type != XmlPullParser.END_TAG
2799 || parser.getDepth() > outerDepth)) {
2800 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2801 continue;
2802 }
2803
2804 if (parser.getName().equals("intent-filter")) {
2805 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2806 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2807 return null;
2808 }
2809
2810 s.intents.add(intent);
2811 } else if (parser.getName().equals("meta-data")) {
2812 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2813 outError)) == null) {
2814 return null;
2815 }
2816 } else {
2817 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002818 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002819 + parser.getName() + " at " + mArchiveSourcePath + " "
2820 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 XmlUtils.skipCurrentTag(parser);
2822 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002823 } else {
2824 outError[0] = "Bad element under <service>: " + parser.getName();
2825 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 }
2828 }
2829
2830 if (!setExported) {
2831 s.info.exported = s.intents.size() > 0;
2832 }
2833
2834 return s;
2835 }
2836
2837 private boolean parseAllMetaData(Resources res,
2838 XmlPullParser parser, AttributeSet attrs, String tag,
2839 Component outInfo, String[] outError)
2840 throws XmlPullParserException, IOException {
2841 int outerDepth = parser.getDepth();
2842 int type;
2843 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2844 && (type != XmlPullParser.END_TAG
2845 || parser.getDepth() > outerDepth)) {
2846 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2847 continue;
2848 }
2849
2850 if (parser.getName().equals("meta-data")) {
2851 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2852 outInfo.metaData, outError)) == null) {
2853 return false;
2854 }
2855 } else {
2856 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002857 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002858 + parser.getName() + " at " + mArchiveSourcePath + " "
2859 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 XmlUtils.skipCurrentTag(parser);
2861 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002862 } else {
2863 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2864 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 }
2867 }
2868 return true;
2869 }
2870
2871 private Bundle parseMetaData(Resources res,
2872 XmlPullParser parser, AttributeSet attrs,
2873 Bundle data, String[] outError)
2874 throws XmlPullParserException, IOException {
2875
2876 TypedArray sa = res.obtainAttributes(attrs,
2877 com.android.internal.R.styleable.AndroidManifestMetaData);
2878
2879 if (data == null) {
2880 data = new Bundle();
2881 }
2882
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002883 String name = sa.getNonConfigurationString(
2884 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 if (name == null) {
2886 outError[0] = "<meta-data> requires an android:name attribute";
2887 sa.recycle();
2888 return null;
2889 }
2890
Dianne Hackborn854060a2009-07-09 18:14:31 -07002891 name = name.intern();
2892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 TypedValue v = sa.peekValue(
2894 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2895 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002896 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 data.putInt(name, v.resourceId);
2898 } else {
2899 v = sa.peekValue(
2900 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002901 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 if (v != null) {
2903 if (v.type == TypedValue.TYPE_STRING) {
2904 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002905 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2907 data.putBoolean(name, v.data != 0);
2908 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2909 && v.type <= TypedValue.TYPE_LAST_INT) {
2910 data.putInt(name, v.data);
2911 } else if (v.type == TypedValue.TYPE_FLOAT) {
2912 data.putFloat(name, v.getFloat());
2913 } else {
2914 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002915 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002916 + parser.getName() + " at " + mArchiveSourcePath + " "
2917 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 } else {
2919 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2920 data = null;
2921 }
2922 }
2923 } else {
2924 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2925 data = null;
2926 }
2927 }
2928
2929 sa.recycle();
2930
2931 XmlUtils.skipCurrentTag(parser);
2932
2933 return data;
2934 }
2935
Kenny Root05ca4c92011-09-15 10:36:25 -07002936 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2937 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2938 IOException {
2939 final TypedArray sa = res.obtainAttributes(attrs,
2940 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2941
2942 final String packageName = sa.getNonResourceString(
2943 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2944
2945 final String encodedPublicKey = sa.getNonResourceString(
2946 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2947
2948 sa.recycle();
2949
2950 if (packageName == null || packageName.length() == 0) {
2951 Slog.i(TAG, "verifier package name was null; skipping");
2952 return null;
2953 } else if (encodedPublicKey == null) {
2954 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2955 }
2956
2957 EncodedKeySpec keySpec;
2958 try {
2959 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2960 keySpec = new X509EncodedKeySpec(encoded);
2961 } catch (IllegalArgumentException e) {
2962 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2963 return null;
2964 }
2965
2966 /* First try the key as an RSA key. */
2967 try {
2968 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2969 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2970 return new VerifierInfo(packageName, publicKey);
2971 } catch (NoSuchAlgorithmException e) {
2972 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2973 return null;
2974 } catch (InvalidKeySpecException e) {
2975 // Not a RSA public key.
2976 }
2977
2978 /* Now try it as a DSA key. */
2979 try {
2980 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
2981 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2982 return new VerifierInfo(packageName, publicKey);
2983 } catch (NoSuchAlgorithmException e) {
2984 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
2985 return null;
2986 } catch (InvalidKeySpecException e) {
2987 // Not a DSA public key.
2988 }
2989
2990 return null;
2991 }
2992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 private static final String ANDROID_RESOURCES
2994 = "http://schemas.android.com/apk/res/android";
2995
2996 private boolean parseIntent(Resources res,
2997 XmlPullParser parser, AttributeSet attrs, int flags,
2998 IntentInfo outInfo, String[] outError, boolean isActivity)
2999 throws XmlPullParserException, IOException {
3000
3001 TypedArray sa = res.obtainAttributes(attrs,
3002 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3003
3004 int priority = sa.getInt(
3005 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 TypedValue v = sa.peekValue(
3009 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3010 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3011 outInfo.nonLocalizedLabel = v.coerceToString();
3012 }
3013
3014 outInfo.icon = sa.getResourceId(
3015 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003016
3017 outInfo.logo = sa.getResourceId(
3018 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019
3020 sa.recycle();
3021
3022 int outerDepth = parser.getDepth();
3023 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003024 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3025 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3026 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 continue;
3028 }
3029
3030 String nodeName = parser.getName();
3031 if (nodeName.equals("action")) {
3032 String value = attrs.getAttributeValue(
3033 ANDROID_RESOURCES, "name");
3034 if (value == null || value == "") {
3035 outError[0] = "No value supplied for <android:name>";
3036 return false;
3037 }
3038 XmlUtils.skipCurrentTag(parser);
3039
3040 outInfo.addAction(value);
3041 } else if (nodeName.equals("category")) {
3042 String value = attrs.getAttributeValue(
3043 ANDROID_RESOURCES, "name");
3044 if (value == null || value == "") {
3045 outError[0] = "No value supplied for <android:name>";
3046 return false;
3047 }
3048 XmlUtils.skipCurrentTag(parser);
3049
3050 outInfo.addCategory(value);
3051
3052 } else if (nodeName.equals("data")) {
3053 sa = res.obtainAttributes(attrs,
3054 com.android.internal.R.styleable.AndroidManifestData);
3055
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003056 String str = sa.getNonConfigurationString(
3057 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 if (str != null) {
3059 try {
3060 outInfo.addDataType(str);
3061 } catch (IntentFilter.MalformedMimeTypeException e) {
3062 outError[0] = e.toString();
3063 sa.recycle();
3064 return false;
3065 }
3066 }
3067
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003068 str = sa.getNonConfigurationString(
3069 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 if (str != null) {
3071 outInfo.addDataScheme(str);
3072 }
3073
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003074 String host = sa.getNonConfigurationString(
3075 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3076 String port = sa.getNonConfigurationString(
3077 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 if (host != null) {
3079 outInfo.addDataAuthority(host, port);
3080 }
3081
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003082 str = sa.getNonConfigurationString(
3083 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 if (str != null) {
3085 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3086 }
3087
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003088 str = sa.getNonConfigurationString(
3089 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 if (str != null) {
3091 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3092 }
3093
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003094 str = sa.getNonConfigurationString(
3095 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096 if (str != null) {
3097 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3098 }
3099
3100 sa.recycle();
3101 XmlUtils.skipCurrentTag(parser);
3102 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003103 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003104 + parser.getName() + " at " + mArchiveSourcePath + " "
3105 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 XmlUtils.skipCurrentTag(parser);
3107 } else {
3108 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3109 return false;
3110 }
3111 }
3112
3113 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003114
3115 if (DEBUG_PARSER) {
3116 final StringBuilder cats = new StringBuilder("Intent d=");
3117 cats.append(outInfo.hasDefault);
3118 cats.append(", cat=");
3119
3120 final Iterator<String> it = outInfo.categoriesIterator();
3121 if (it != null) {
3122 while (it.hasNext()) {
3123 cats.append(' ');
3124 cats.append(it.next());
3125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003127 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 }
3129
3130 return true;
3131 }
3132
3133 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003134 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135
3136 // For now we only support one application per package.
3137 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3138
3139 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3140 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3141 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3142 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3143 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3144 public final ArrayList<Service> services = new ArrayList<Service>(0);
3145 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3146
3147 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003148 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149
Dianne Hackborn854060a2009-07-09 18:14:31 -07003150 public ArrayList<String> protectedBroadcasts;
3151
Dianne Hackborn49237342009-08-27 20:08:01 -07003152 public ArrayList<String> usesLibraries = null;
3153 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 public String[] usesLibraryFiles = null;
3155
Dianne Hackbornc1552392010-03-03 16:19:01 -08003156 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003157 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003158 public ArrayList<String> mAdoptPermissions = null;
3159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 // We store the application meta-data independently to avoid multiple unwanted references
3161 public Bundle mAppMetaData = null;
3162
3163 // If this is a 3rd party app, this is the path of the zip file.
3164 public String mPath;
3165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 // The version code declared for this package.
3167 public int mVersionCode;
3168
3169 // The version name declared for this package.
3170 public String mVersionName;
3171
3172 // The shared user id that this package wants to use.
3173 public String mSharedUserId;
3174
3175 // The shared user label that this package wants to use.
3176 public int mSharedUserLabel;
3177
3178 // Signatures that were read from the package.
3179 public Signature mSignatures[];
3180
3181 // For use by package manager service for quick lookup of
3182 // preferred up order.
3183 public int mPreferredOrder = 0;
3184
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003185 // For use by the package manager to keep track of the path to the
3186 // file an app came from.
3187 public String mScanPath;
3188
3189 // For use by package manager to keep track of where it has done dexopt.
3190 public boolean mDidDexOpt;
3191
Amith Yamasani13593602012-03-22 16:16:17 -07003192 // // User set enabled state.
3193 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3194 //
3195 // // Whether the package has been stopped.
3196 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 // Additional data supplied by callers.
3199 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003200
3201 // Whether an operation is currently pending on this package
3202 public boolean mOperationPending;
3203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 /*
3205 * Applications hardware preferences
3206 */
3207 public final ArrayList<ConfigurationInfo> configPreferences =
3208 new ArrayList<ConfigurationInfo>();
3209
Dianne Hackborn49237342009-08-27 20:08:01 -07003210 /*
3211 * Applications requested features
3212 */
3213 public ArrayList<FeatureInfo> reqFeatures = null;
3214
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003215 public int installLocation;
3216
Kenny Rootbcc954d2011-08-08 16:19:08 -07003217 /**
3218 * Digest suitable for comparing whether this package's manifest is the
3219 * same as another.
3220 */
3221 public ManifestDigest manifestDigest;
3222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 public Package(String _name) {
3224 packageName = _name;
3225 applicationInfo.packageName = _name;
3226 applicationInfo.uid = -1;
3227 }
3228
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003229 public void setPackageName(String newName) {
3230 packageName = newName;
3231 applicationInfo.packageName = newName;
3232 for (int i=permissions.size()-1; i>=0; i--) {
3233 permissions.get(i).setPackageName(newName);
3234 }
3235 for (int i=permissionGroups.size()-1; i>=0; i--) {
3236 permissionGroups.get(i).setPackageName(newName);
3237 }
3238 for (int i=activities.size()-1; i>=0; i--) {
3239 activities.get(i).setPackageName(newName);
3240 }
3241 for (int i=receivers.size()-1; i>=0; i--) {
3242 receivers.get(i).setPackageName(newName);
3243 }
3244 for (int i=providers.size()-1; i>=0; i--) {
3245 providers.get(i).setPackageName(newName);
3246 }
3247 for (int i=services.size()-1; i>=0; i--) {
3248 services.get(i).setPackageName(newName);
3249 }
3250 for (int i=instrumentation.size()-1; i>=0; i--) {
3251 instrumentation.get(i).setPackageName(newName);
3252 }
3253 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003254
3255 public boolean hasComponentClassName(String name) {
3256 for (int i=activities.size()-1; i>=0; i--) {
3257 if (name.equals(activities.get(i).className)) {
3258 return true;
3259 }
3260 }
3261 for (int i=receivers.size()-1; i>=0; i--) {
3262 if (name.equals(receivers.get(i).className)) {
3263 return true;
3264 }
3265 }
3266 for (int i=providers.size()-1; i>=0; i--) {
3267 if (name.equals(providers.get(i).className)) {
3268 return true;
3269 }
3270 }
3271 for (int i=services.size()-1; i>=0; i--) {
3272 if (name.equals(services.get(i).className)) {
3273 return true;
3274 }
3275 }
3276 for (int i=instrumentation.size()-1; i>=0; i--) {
3277 if (name.equals(instrumentation.get(i).className)) {
3278 return true;
3279 }
3280 }
3281 return false;
3282 }
3283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 public String toString() {
3285 return "Package{"
3286 + Integer.toHexString(System.identityHashCode(this))
3287 + " " + packageName + "}";
3288 }
3289 }
3290
3291 public static class Component<II extends IntentInfo> {
3292 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003293 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003294 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 public Bundle metaData;
3296
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003297 ComponentName componentName;
3298 String componentShortName;
3299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 public Component(Package _owner) {
3301 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003302 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003303 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003304 }
3305
3306 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3307 owner = args.owner;
3308 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003309 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003310 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003311 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003312 args.outError[0] = args.tag + " does not specify android:name";
3313 return;
3314 }
3315
3316 outInfo.name
3317 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3318 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003319 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003320 args.outError[0] = args.tag + " does not have valid android:name";
3321 return;
3322 }
3323
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003324 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003325
3326 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3327 if (iconVal != 0) {
3328 outInfo.icon = iconVal;
3329 outInfo.nonLocalizedLabel = null;
3330 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003331
3332 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3333 if (logoVal != 0) {
3334 outInfo.logo = logoVal;
3335 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003336
3337 TypedValue v = args.sa.peekValue(args.labelRes);
3338 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3339 outInfo.nonLocalizedLabel = v.coerceToString();
3340 }
3341
3342 outInfo.packageName = owner.packageName;
3343 }
3344
3345 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3346 this(args, (PackageItemInfo)outInfo);
3347 if (args.outError[0] != null) {
3348 return;
3349 }
3350
3351 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003352 CharSequence pname;
3353 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3354 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3355 } else {
3356 // Some older apps have been seen to use a resource reference
3357 // here that on older builds was ignored (with a warning). We
3358 // need to continue to do this for them so they don't break.
3359 pname = args.sa.getNonResourceString(args.processRes);
3360 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003361 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003362 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003363 args.flags, args.sepProcesses, args.outError);
3364 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003365
3366 if (args.descriptionRes != 0) {
3367 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3368 }
3369
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003370 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 }
3372
3373 public Component(Component<II> clone) {
3374 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003375 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003376 className = clone.className;
3377 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003378 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003379 }
3380
3381 public ComponentName getComponentName() {
3382 if (componentName != null) {
3383 return componentName;
3384 }
3385 if (className != null) {
3386 componentName = new ComponentName(owner.applicationInfo.packageName,
3387 className);
3388 }
3389 return componentName;
3390 }
3391
3392 public String getComponentShortName() {
3393 if (componentShortName != null) {
3394 return componentShortName;
3395 }
3396 ComponentName component = getComponentName();
3397 if (component != null) {
3398 componentShortName = component.flattenToShortString();
3399 }
3400 return componentShortName;
3401 }
3402
3403 public void setPackageName(String packageName) {
3404 componentName = null;
3405 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 }
3407 }
3408
3409 public final static class Permission extends Component<IntentInfo> {
3410 public final PermissionInfo info;
3411 public boolean tree;
3412 public PermissionGroup group;
3413
3414 public Permission(Package _owner) {
3415 super(_owner);
3416 info = new PermissionInfo();
3417 }
3418
3419 public Permission(Package _owner, PermissionInfo _info) {
3420 super(_owner);
3421 info = _info;
3422 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003423
3424 public void setPackageName(String packageName) {
3425 super.setPackageName(packageName);
3426 info.packageName = packageName;
3427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428
3429 public String toString() {
3430 return "Permission{"
3431 + Integer.toHexString(System.identityHashCode(this))
3432 + " " + info.name + "}";
3433 }
3434 }
3435
3436 public final static class PermissionGroup extends Component<IntentInfo> {
3437 public final PermissionGroupInfo info;
3438
3439 public PermissionGroup(Package _owner) {
3440 super(_owner);
3441 info = new PermissionGroupInfo();
3442 }
3443
3444 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3445 super(_owner);
3446 info = _info;
3447 }
3448
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003449 public void setPackageName(String packageName) {
3450 super.setPackageName(packageName);
3451 info.packageName = packageName;
3452 }
3453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 public String toString() {
3455 return "PermissionGroup{"
3456 + Integer.toHexString(System.identityHashCode(this))
3457 + " " + info.name + "}";
3458 }
3459 }
3460
Amith Yamasani13593602012-03-22 16:16:17 -07003461 private static boolean copyNeeded(int flags, Package p, int enabledState, Bundle metaData) {
3462 if (enabledState != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3463 boolean enabled = enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003464 if (p.applicationInfo.enabled != enabled) {
3465 return true;
3466 }
3467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 if ((flags & PackageManager.GET_META_DATA) != 0
3469 && (metaData != null || p.mAppMetaData != null)) {
3470 return true;
3471 }
3472 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3473 && p.usesLibraryFiles != null) {
3474 return true;
3475 }
3476 return false;
3477 }
3478
Amith Yamasani13593602012-03-22 16:16:17 -07003479 public static ApplicationInfo generateApplicationInfo(Package p, int flags, boolean stopped,
3480 int enabledState) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003481 return generateApplicationInfo(p, flags, stopped, enabledState, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003482 }
3483
Amith Yamasani13593602012-03-22 16:16:17 -07003484 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3485 boolean stopped, int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003487 if (!copyNeeded(flags, p, enabledState, null) && userId == 0) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003488 // CompatibilityMode is global state. It's safe to modify the instance
3489 // of the package.
3490 if (!sCompatibilityModeEnabled) {
3491 p.applicationInfo.disableCompatibilityMode();
3492 }
Amith Yamasani13593602012-03-22 16:16:17 -07003493 if (stopped) {
Dianne Hackborne7f97212011-02-24 14:40:20 -08003494 p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED;
3495 } else {
3496 p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
3497 }
Amith Yamasani13593602012-03-22 16:16:17 -07003498 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003499 p.applicationInfo.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003500 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3501 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003502 p.applicationInfo.enabled = false;
3503 }
Amith Yamasani13593602012-03-22 16:16:17 -07003504 p.applicationInfo.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003505 return p.applicationInfo;
3506 }
3507
3508 // Make shallow copy so we can store the metadata/libraries safely
3509 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003510 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003511 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003512 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 if ((flags & PackageManager.GET_META_DATA) != 0) {
3515 ai.metaData = p.mAppMetaData;
3516 }
3517 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3518 ai.sharedLibraryFiles = p.usesLibraryFiles;
3519 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003520 if (!sCompatibilityModeEnabled) {
3521 ai.disableCompatibilityMode();
3522 }
Amith Yamasani13593602012-03-22 16:16:17 -07003523 if (stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003524 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003525 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003526 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003527 }
Amith Yamasani13593602012-03-22 16:16:17 -07003528 if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003529 ai.enabled = true;
Amith Yamasani13593602012-03-22 16:16:17 -07003530 } else if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3531 || enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003532 ai.enabled = false;
3533 }
Amith Yamasani13593602012-03-22 16:16:17 -07003534 ai.enabledSetting = enabledState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 return ai;
3536 }
3537
3538 public static final PermissionInfo generatePermissionInfo(
3539 Permission p, int flags) {
3540 if (p == null) return null;
3541 if ((flags&PackageManager.GET_META_DATA) == 0) {
3542 return p.info;
3543 }
3544 PermissionInfo pi = new PermissionInfo(p.info);
3545 pi.metaData = p.metaData;
3546 return pi;
3547 }
3548
3549 public static final PermissionGroupInfo generatePermissionGroupInfo(
3550 PermissionGroup pg, int flags) {
3551 if (pg == null) return null;
3552 if ((flags&PackageManager.GET_META_DATA) == 0) {
3553 return pg.info;
3554 }
3555 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3556 pgi.metaData = pg.metaData;
3557 return pgi;
3558 }
3559
3560 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003561 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003563 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3564 super(args, _info);
3565 info = _info;
3566 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003568
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003569 public void setPackageName(String packageName) {
3570 super.setPackageName(packageName);
3571 info.packageName = packageName;
3572 }
3573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 public String toString() {
3575 return "Activity{"
3576 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003577 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 }
3579 }
3580
Amith Yamasani13593602012-03-22 16:16:17 -07003581 public static final ActivityInfo generateActivityInfo(Activity a, int flags, boolean stopped,
3582 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 if (a == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003584 if (!copyNeeded(flags, a.owner, enabledState, a.metaData) && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 return a.info;
3586 }
3587 // Make shallow copies so we can store the metadata safely
3588 ActivityInfo ai = new ActivityInfo(a.info);
3589 ai.metaData = a.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003590 ai.applicationInfo = generateApplicationInfo(a.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 return ai;
3592 }
3593
3594 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003595 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003597 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3598 super(args, _info);
3599 info = _info;
3600 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003602
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003603 public void setPackageName(String packageName) {
3604 super.setPackageName(packageName);
3605 info.packageName = packageName;
3606 }
3607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 public String toString() {
3609 return "Service{"
3610 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003611 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 }
3613 }
3614
Amith Yamasani13593602012-03-22 16:16:17 -07003615 public static final ServiceInfo generateServiceInfo(Service s, int flags, boolean stopped,
3616 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 if (s == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003618 if (!copyNeeded(flags, s.owner, enabledState, s.metaData)
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003619 && userId == UserHandle.getUserId(s.info.applicationInfo.uid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 return s.info;
3621 }
3622 // Make shallow copies so we can store the metadata safely
3623 ServiceInfo si = new ServiceInfo(s.info);
3624 si.metaData = s.metaData;
Amith Yamasani13593602012-03-22 16:16:17 -07003625 si.applicationInfo = generateApplicationInfo(s.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 return si;
3627 }
3628
3629 public final static class Provider extends Component {
3630 public final ProviderInfo info;
3631 public boolean syncable;
3632
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003633 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3634 super(args, _info);
3635 info = _info;
3636 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 syncable = false;
3638 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 public Provider(Provider existingProvider) {
3641 super(existingProvider);
3642 this.info = existingProvider.info;
3643 this.syncable = existingProvider.syncable;
3644 }
3645
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003646 public void setPackageName(String packageName) {
3647 super.setPackageName(packageName);
3648 info.packageName = packageName;
3649 }
3650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 public String toString() {
3652 return "Provider{"
3653 + Integer.toHexString(System.identityHashCode(this))
3654 + " " + info.name + "}";
3655 }
3656 }
3657
Amith Yamasani13593602012-03-22 16:16:17 -07003658 public static final ProviderInfo generateProviderInfo(Provider p, int flags, boolean stopped,
3659 int enabledState, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 if (p == null) return null;
Amith Yamasani13593602012-03-22 16:16:17 -07003661 if (!copyNeeded(flags, p.owner, enabledState, p.metaData)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Amith Yamasani742a6712011-05-04 14:49:28 -07003663 || p.info.uriPermissionPatterns == null)
3664 && userId == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 return p.info;
3666 }
3667 // Make shallow copies so we can store the metadata safely
3668 ProviderInfo pi = new ProviderInfo(p.info);
3669 pi.metaData = p.metaData;
3670 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3671 pi.uriPermissionPatterns = null;
3672 }
Amith Yamasani13593602012-03-22 16:16:17 -07003673 pi.applicationInfo = generateApplicationInfo(p.owner, flags, stopped, enabledState, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 return pi;
3675 }
3676
3677 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003678 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003680 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3681 super(args, _info);
3682 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003684
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003685 public void setPackageName(String packageName) {
3686 super.setPackageName(packageName);
3687 info.packageName = packageName;
3688 }
3689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 public String toString() {
3691 return "Instrumentation{"
3692 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003693 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 }
3695 }
3696
3697 public static final InstrumentationInfo generateInstrumentationInfo(
3698 Instrumentation i, int flags) {
3699 if (i == null) return null;
3700 if ((flags&PackageManager.GET_META_DATA) == 0) {
3701 return i.info;
3702 }
3703 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3704 ii.metaData = i.metaData;
3705 return ii;
3706 }
3707
3708 public static class IntentInfo extends IntentFilter {
3709 public boolean hasDefault;
3710 public int labelRes;
3711 public CharSequence nonLocalizedLabel;
3712 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003713 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 }
3715
3716 public final static class ActivityIntentInfo extends IntentInfo {
3717 public final Activity activity;
3718
3719 public ActivityIntentInfo(Activity _activity) {
3720 activity = _activity;
3721 }
3722
3723 public String toString() {
3724 return "ActivityIntentInfo{"
3725 + Integer.toHexString(System.identityHashCode(this))
3726 + " " + activity.info.name + "}";
3727 }
3728 }
3729
3730 public final static class ServiceIntentInfo extends IntentInfo {
3731 public final Service service;
3732
3733 public ServiceIntentInfo(Service _service) {
3734 service = _service;
3735 }
3736
3737 public String toString() {
3738 return "ServiceIntentInfo{"
3739 + Integer.toHexString(System.identityHashCode(this))
3740 + " " + service.info.name + "}";
3741 }
3742 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003743
3744 /**
3745 * @hide
3746 */
3747 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3748 sCompatibilityModeEnabled = compatibilityModeEnabled;
3749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750}