blob: 5a50ec29db0e91c6c1b423c1aed2b276ad201f49 [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;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Bundle;
29import android.os.PatternMatcher;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070030import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070032import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070034import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070035import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Kenny Rootd63f7db2010-09-27 08:07:48 -070038import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.File;
40import java.io.IOException;
41import java.io.InputStream;
42import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070043import java.security.KeyFactory;
44import java.security.NoSuchAlgorithmException;
45import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import java.security.cert.Certificate;
47import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070048import java.security.spec.EncodedKeySpec;
49import java.security.spec.InvalidKeySpecException;
50import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import java.util.ArrayList;
52import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080053import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070055import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import java.util.jar.JarEntry;
57import java.util.jar.JarFile;
Kenny Root6c918ce2013-04-02 14:04:24 -070058import java.util.zip.ZipEntry;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Amith Yamasani742a6712011-05-04 14:49:28 -070060import com.android.internal.util.XmlUtils;
61
62import org.xmlpull.v1.XmlPullParser;
63import org.xmlpull.v1.XmlPullParserException;
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065/**
66 * Package archive parsing
67 *
68 * {@hide}
69 */
70public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070071 private static final boolean DEBUG_JAR = false;
72 private static final boolean DEBUG_PARSER = false;
73 private static final boolean DEBUG_BACKUP = false;
74
Kenny Rootbcc954d2011-08-08 16:19:08 -070075 /** File name in an APK for the Android manifest. */
76 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
77
Dianne Hackborna96cbb42009-05-13 15:06:13 -070078 /** @hide */
79 public static class NewPermissionInfo {
80 public final String name;
81 public final int sdkVersion;
82 public final int fileVersion;
83
84 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
85 this.name = name;
86 this.sdkVersion = sdkVersion;
87 this.fileVersion = fileVersion;
88 }
89 }
Dianne Hackborn79245122012-03-12 10:51:26 -070090
91 /** @hide */
92 public static class SplitPermissionInfo {
93 public final String rootPerm;
94 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070095 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070096
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -070098 this.rootPerm = rootPerm;
99 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700100 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700101 }
102 }
103
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700104 /**
105 * List of new permissions that have been added since 1.0.
106 * NOTE: These must be declared in SDK version order, with permissions
107 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700108 * If sdkVersion is 0, then this is not a permission that we want to
109 * automatically add to older apps, but we do want to allow it to be
110 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700111 * @hide
112 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700113 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
114 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700115 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700116 android.os.Build.VERSION_CODES.DONUT, 0),
117 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
118 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700119 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
Dianne Hackborn79245122012-03-12 10:51:26 -0700121 /**
122 * List of permissions that have been split into more granular or dependent
123 * permissions.
124 * @hide
125 */
126 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
127 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700128 // READ_EXTERNAL_STORAGE is always required when an app requests
129 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
130 // write access without read access. The hack here with the target
131 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700132 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700133 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700134 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700135 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
136 new String[] { android.Manifest.permission.READ_CALL_LOG },
137 android.os.Build.VERSION_CODES.JELLY_BEAN),
138 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
139 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
140 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700141 };
142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 private String mArchiveSourcePath;
144 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700145 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700146 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
147 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
148 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
150 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
151
152 private static final Object mSync = new Object();
153 private static WeakReference<byte[]> mReadBuffer;
154
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700155 private static boolean sCompatibilityModeEnabled = true;
156 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700157
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700158 static class ParsePackageItemArgs {
159 final Package owner;
160 final String[] outError;
161 final int nameRes;
162 final int labelRes;
163 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700164 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700165
166 String tag;
167 TypedArray sa;
168
169 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700170 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700171 owner = _owner;
172 outError = _outError;
173 nameRes = _nameRes;
174 labelRes = _labelRes;
175 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700176 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700177 }
178 }
179
180 static class ParseComponentArgs extends ParsePackageItemArgs {
181 final String[] sepProcesses;
182 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800183 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 final int enabledRes;
185 int flags;
186
187 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700188 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800189 String[] _sepProcesses, int _processRes,
190 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700191 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700192 sepProcesses = _sepProcesses;
193 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800194 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700195 enabledRes = _enabledRes;
196 }
197 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800198
199 /* Light weight package info.
200 * @hide
201 */
202 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700203 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700204 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700205 public final int installLocation;
206 public final VerifierInfo[] verifiers;
207
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700208 public PackageLite(String packageName, int versionCode,
209 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800210 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700211 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800212 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700213 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800214 }
215 }
216
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700217 private ParsePackageItemArgs mParseInstrumentationArgs;
218 private ParseComponentArgs mParseActivityArgs;
219 private ParseComponentArgs mParseActivityAliasArgs;
220 private ParseComponentArgs mParseServiceArgs;
221 private ParseComponentArgs mParseProviderArgs;
222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 /** If set to true, we will only allow package files that exactly match
224 * the DTD. Otherwise, we try to get as much from the package as we
225 * can without failing. This should normally be set to false, to
226 * support extensions to the DTD in future versions. */
227 private static final boolean RIGID_PARSER = false;
228
229 private static final String TAG = "PackageParser";
230
231 public PackageParser(String archiveSourcePath) {
232 mArchiveSourcePath = archiveSourcePath;
233 }
234
235 public void setSeparateProcesses(String[] procs) {
236 mSeparateProcesses = procs;
237 }
238
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700239 public void setOnlyCoreApps(boolean onlyCoreApps) {
240 mOnlyCoreApps = onlyCoreApps;
241 }
242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 private static final boolean isPackageFilename(String name) {
244 return name.endsWith(".apk");
245 }
246
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700247 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700248 public static PackageInfo generatePackageInfo(PackageParser.Package p,
249 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
250 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700251 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700252 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700253 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700254 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700255 */
Amith Yamasani13593602012-03-22 16:16:17 -0700256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 /**
258 * Generate and return the {@link PackageInfo} for a parsed package.
259 *
260 * @param p the parsed package.
261 * @param flags indicating which optional information is included.
262 */
263 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800264 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700265 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266
Amith Yamasani483f3b02012-03-13 16:08:00 -0700267 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700268 grantedPermissions, state, UserHandle.getCallingUserId());
269 }
270
271 private static boolean checkUseInstalled(int flags, PackageUserState state) {
272 return state.installed || ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700273 }
274
Amith Yamasani13593602012-03-22 16:16:17 -0700275 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700276 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700277 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700278
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700279 if (!checkUseInstalled(flags, state)) {
280 return null;
281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 PackageInfo pi = new PackageInfo();
283 pi.packageName = p.packageName;
284 pi.versionCode = p.mVersionCode;
285 pi.versionName = p.mVersionName;
286 pi.sharedUserId = p.mSharedUserId;
287 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700288 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800289 pi.installLocation = p.installLocation;
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800290 pi.requiredForAllUsers = p.mRequiredForAllUsers;
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700291 pi.restrictedAccountType = p.mRestrictedAccountType;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700292 pi.firstInstallTime = firstInstallTime;
293 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 if ((flags&PackageManager.GET_GIDS) != 0) {
295 pi.gids = gids;
296 }
297 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
298 int N = p.configPreferences.size();
299 if (N > 0) {
300 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700301 p.configPreferences.toArray(pi.configPreferences);
302 }
303 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
304 if (N > 0) {
305 pi.reqFeatures = new FeatureInfo[N];
306 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308 }
309 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
310 int N = p.activities.size();
311 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700312 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
313 pi.activities = new ActivityInfo[N];
314 } else {
315 int num = 0;
316 for (int i=0; i<N; i++) {
317 if (p.activities.get(i).info.enabled) num++;
318 }
319 pi.activities = new ActivityInfo[num];
320 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700321 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 final Activity activity = p.activities.get(i);
323 if (activity.info.enabled
324 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700325 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700326 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 }
328 }
329 }
330 }
331 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
332 int N = p.receivers.size();
333 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700334 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
335 pi.receivers = new ActivityInfo[N];
336 } else {
337 int num = 0;
338 for (int i=0; i<N; i++) {
339 if (p.receivers.get(i).info.enabled) num++;
340 }
341 pi.receivers = new ActivityInfo[num];
342 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700343 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 final Activity activity = p.receivers.get(i);
345 if (activity.info.enabled
346 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700347 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700348 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 }
350 }
351 }
352 }
353 if ((flags&PackageManager.GET_SERVICES) != 0) {
354 int N = p.services.size();
355 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700356 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
357 pi.services = new ServiceInfo[N];
358 } else {
359 int num = 0;
360 for (int i=0; i<N; i++) {
361 if (p.services.get(i).info.enabled) num++;
362 }
363 pi.services = new ServiceInfo[num];
364 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700365 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 final Service service = p.services.get(i);
367 if (service.info.enabled
368 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700369 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
370 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372 }
373 }
374 }
375 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
376 int N = p.providers.size();
377 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700378 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
379 pi.providers = new ProviderInfo[N];
380 } else {
381 int num = 0;
382 for (int i=0; i<N; i++) {
383 if (p.providers.get(i).info.enabled) num++;
384 }
385 pi.providers = new ProviderInfo[num];
386 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700387 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 final Provider provider = p.providers.get(i);
389 if (provider.info.enabled
390 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700391 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
392 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 }
394 }
395 }
396 }
397 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
398 int N = p.instrumentation.size();
399 if (N > 0) {
400 pi.instrumentation = new InstrumentationInfo[N];
401 for (int i=0; i<N; i++) {
402 pi.instrumentation[i] = generateInstrumentationInfo(
403 p.instrumentation.get(i), flags);
404 }
405 }
406 }
407 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
408 int N = p.permissions.size();
409 if (N > 0) {
410 pi.permissions = new PermissionInfo[N];
411 for (int i=0; i<N; i++) {
412 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
413 }
414 }
415 N = p.requestedPermissions.size();
416 if (N > 0) {
417 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800418 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800420 final String perm = p.requestedPermissions.get(i);
421 pi.requestedPermissions[i] = perm;
422 if (p.requestedPermissionsRequired.get(i)) {
423 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
424 }
425 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
426 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 }
429 }
430 }
431 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700432 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
433 if (N > 0) {
434 pi.signatures = new Signature[N];
435 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437 }
438 return pi;
439 }
440
441 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
442 byte[] readBuffer) {
443 try {
444 // We must read the stream for the JarEntry to retrieve
445 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700446 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
448 // not using
449 }
450 is.close();
451 return je != null ? je.getCertificates() : null;
452 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700453 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700455 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700456 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700457 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
459 return null;
460 }
461
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800462 public final static int PARSE_IS_SYSTEM = 1<<0;
463 public final static int PARSE_CHATTY = 1<<1;
464 public final static int PARSE_MUST_BE_APK = 1<<2;
465 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
466 public final static int PARSE_FORWARD_LOCK = 1<<4;
467 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700468 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469
470 public int getParseError() {
471 return mParseError;
472 }
473
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800474 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 DisplayMetrics metrics, int flags) {
476 mParseError = PackageManager.INSTALL_SUCCEEDED;
477
478 mArchiveSourcePath = sourceFile.getPath();
479 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700480 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
482 return null;
483 }
484 if (!isPackageFilename(sourceFile.getName())
485 && (flags&PARSE_MUST_BE_APK) != 0) {
486 if ((flags&PARSE_IS_SYSTEM) == 0) {
487 // We expect to have non-.apk files in the system dir,
488 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700489 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
492 return null;
493 }
494
Kenny Rootd2d29252011-08-08 11:27:57 -0700495 if (DEBUG_JAR)
496 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497
498 XmlResourceParser parser = null;
499 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800500 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 boolean assetError = true;
502 try {
503 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700504 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800505 if (cookie != 0) {
506 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700507 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 -0800508 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700509 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 assetError = false;
511 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700512 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700515 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 + mArchiveSourcePath, e);
517 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800518 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 if (assmgr != null) assmgr.close();
520 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
521 return null;
522 }
523 String[] errorText = new String[1];
524 Package pkg = null;
525 Exception errorException = null;
526 try {
527 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 pkg = parsePackage(res, parser, flags, errorText);
529 } catch (Exception e) {
530 errorException = e;
531 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
532 }
533
534
535 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700536 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
537 // just means to skip this app so don't make a fuss about it.
538 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
539 if (errorException != null) {
540 Slog.w(TAG, mArchiveSourcePath, errorException);
541 } else {
542 Slog.w(TAG, mArchiveSourcePath + " (at "
543 + parser.getPositionDescription()
544 + "): " + errorText[0]);
545 }
546 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
547 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 parser.close();
551 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 return null;
553 }
554
555 parser.close();
556 assmgr.close();
557
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800558 // Set code and resource paths
559 pkg.mPath = destCodePath;
560 pkg.mScanPath = mArchiveSourcePath;
561 //pkg.applicationInfo.sourceDir = destCodePath;
562 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 pkg.mSignatures = null;
564
565 return pkg;
566 }
567
Kenny Root6c918ce2013-04-02 14:04:24 -0700568 /**
569 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
570 * APK. If it successfully scanned the package and found the
571 * {@code AndroidManifest.xml}, {@code true} is returned.
572 */
573 public boolean collectManifestDigest(Package pkg) {
574 try {
575 final JarFile jarFile = new JarFile(mArchiveSourcePath);
576 try {
577 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
578 if (je != null) {
579 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
580 }
581 } finally {
582 jarFile.close();
583 }
584 return true;
585 } catch (IOException e) {
586 return false;
587 }
588 }
589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 public boolean collectCertificates(Package pkg, int flags) {
591 pkg.mSignatures = null;
592
593 WeakReference<byte[]> readBufferRef;
594 byte[] readBuffer = null;
595 synchronized (mSync) {
596 readBufferRef = mReadBuffer;
597 if (readBufferRef != null) {
598 mReadBuffer = null;
599 readBuffer = readBufferRef.get();
600 }
601 if (readBuffer == null) {
602 readBuffer = new byte[8192];
603 readBufferRef = new WeakReference<byte[]>(readBuffer);
604 }
605 }
606
607 try {
608 JarFile jarFile = new JarFile(mArchiveSourcePath);
609
610 Certificate[] certs = null;
611
612 if ((flags&PARSE_IS_SYSTEM) != 0) {
613 // If this package comes from the system image, then we
614 // can trust it... we'll just use the AndroidManifest.xml
615 // to retrieve its signatures, not validating all of the
616 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700617 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 certs = loadCertificates(jarFile, jarEntry, readBuffer);
619 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700620 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 + " has no certificates at entry "
622 + jarEntry.getName() + "; ignoring!");
623 jarFile.close();
624 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
625 return false;
626 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700627 if (DEBUG_JAR) {
628 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 + " certs=" + (certs != null ? certs.length : 0));
630 if (certs != null) {
631 final int N = certs.length;
632 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700633 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 + certs[i].getPublicKey().getEncoded()
635 + " " + certs[i].getPublicKey());
636 }
637 }
638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700640 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700642 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700644
Kenny Rootbcc954d2011-08-08 16:19:08 -0700645 final String name = je.getName();
646
647 if (name.startsWith("META-INF/"))
648 continue;
649
650 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700651 pkg.manifestDigest =
652 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700653 }
654
655 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700656 if (DEBUG_JAR) {
657 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 + ": certs=" + certs + " ("
659 + (certs != null ? certs.length : 0) + ")");
660 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700663 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 + " has no certificates at entry "
665 + je.getName() + "; ignoring!");
666 jarFile.close();
667 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
668 return false;
669 } else if (certs == null) {
670 certs = localCerts;
671 } else {
672 // Ensure all certificates match.
673 for (int i=0; i<certs.length; i++) {
674 boolean found = false;
675 for (int j=0; j<localCerts.length; j++) {
676 if (certs[i] != null &&
677 certs[i].equals(localCerts[j])) {
678 found = true;
679 break;
680 }
681 }
682 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700683 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 + " has mismatched certificates at entry "
685 + je.getName() + "; ignoring!");
686 jarFile.close();
687 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
688 return false;
689 }
690 }
691 }
692 }
693 }
694 jarFile.close();
695
696 synchronized (mSync) {
697 mReadBuffer = readBufferRef;
698 }
699
700 if (certs != null && certs.length > 0) {
701 final int N = certs.length;
702 pkg.mSignatures = new Signature[certs.length];
703 for (int i=0; i<N; i++) {
704 pkg.mSignatures[i] = new Signature(
705 certs[i].getEncoded());
706 }
707 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700708 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 + " has no certificates; ignoring!");
710 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
711 return false;
712 }
713 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700714 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
716 return false;
717 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700718 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
720 return false;
721 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700722 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
724 return false;
725 }
726
727 return true;
728 }
729
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800730 /*
731 * Utility method that retrieves just the package name and install
732 * location from the apk location at the given file path.
733 * @param packageFilePath file location of the apk
734 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700735 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800736 */
737 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700739 final XmlResourceParser parser;
740 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 try {
742 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700743 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 -0800744 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700747 if (cookie == 0) {
748 return null;
749 }
750
Kenny Root05ca4c92011-09-15 10:36:25 -0700751 final DisplayMetrics metrics = new DisplayMetrics();
752 metrics.setToDefaults();
753 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700754 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 } catch (Exception e) {
756 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700757 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 + packageFilePath, e);
759 return null;
760 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700761
762 final AttributeSet attrs = parser;
763 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800764 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700766 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700768 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700770 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 } finally {
772 if (parser != null) parser.close();
773 if (assmgr != null) assmgr.close();
774 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800775 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700776 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 return null;
778 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800779 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 }
781
782 private static String validateName(String name, boolean requiresSeparator) {
783 final int N = name.length();
784 boolean hasSep = false;
785 boolean front = true;
786 for (int i=0; i<N; i++) {
787 final char c = name.charAt(i);
788 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
789 front = false;
790 continue;
791 }
792 if (!front) {
793 if ((c >= '0' && c <= '9') || c == '_') {
794 continue;
795 }
796 }
797 if (c == '.') {
798 hasSep = true;
799 front = true;
800 continue;
801 }
802 return "bad character '" + c + "'";
803 }
804 return hasSep || !requiresSeparator
805 ? null : "must have at least one '.' separator";
806 }
807
808 private static String parsePackageName(XmlPullParser parser,
809 AttributeSet attrs, int flags, String[] outError)
810 throws IOException, XmlPullParserException {
811
812 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700813 while ((type = parser.next()) != XmlPullParser.START_TAG
814 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 ;
816 }
817
Kenny Rootd2d29252011-08-08 11:27:57 -0700818 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 outError[0] = "No start tag found";
820 return null;
821 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700822 if (DEBUG_PARSER)
823 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 if (!parser.getName().equals("manifest")) {
825 outError[0] = "No <manifest> tag";
826 return null;
827 }
828 String pkgName = attrs.getAttributeValue(null, "package");
829 if (pkgName == null || pkgName.length() == 0) {
830 outError[0] = "<manifest> does not specify package";
831 return null;
832 }
833 String nameError = validateName(pkgName, true);
834 if (nameError != null && !"android".equals(pkgName)) {
835 outError[0] = "<manifest> specifies bad package name \""
836 + pkgName + "\": " + nameError;
837 return null;
838 }
839
840 return pkgName.intern();
841 }
842
Kenny Root05ca4c92011-09-15 10:36:25 -0700843 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
844 AttributeSet attrs, int flags, String[] outError) throws IOException,
845 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800846
847 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700848 while ((type = parser.next()) != XmlPullParser.START_TAG
849 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800850 ;
851 }
852
Kenny Rootd2d29252011-08-08 11:27:57 -0700853 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800854 outError[0] = "No start tag found";
855 return null;
856 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700857 if (DEBUG_PARSER)
858 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800859 if (!parser.getName().equals("manifest")) {
860 outError[0] = "No <manifest> tag";
861 return null;
862 }
863 String pkgName = attrs.getAttributeValue(null, "package");
864 if (pkgName == null || pkgName.length() == 0) {
865 outError[0] = "<manifest> does not specify package";
866 return null;
867 }
868 String nameError = validateName(pkgName, true);
869 if (nameError != null && !"android".equals(pkgName)) {
870 outError[0] = "<manifest> specifies bad package name \""
871 + pkgName + "\": " + nameError;
872 return null;
873 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700874 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700875 int versionCode = 0;
876 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800877 for (int i = 0; i < attrs.getAttributeCount(); i++) {
878 String attr = attrs.getAttributeName(i);
879 if (attr.equals("installLocation")) {
880 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700881 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700882 numFound++;
883 } else if (attr.equals("versionCode")) {
884 versionCode = attrs.getAttributeIntValue(i, 0);
885 numFound++;
886 }
887 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800888 break;
889 }
890 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700891
892 // Only search the tree when the tag is directly below <manifest>
893 final int searchDepth = parser.getDepth() + 1;
894
895 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
896 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
897 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
898 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
899 continue;
900 }
901
902 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
903 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
904 if (verifier != null) {
905 verifiers.add(verifier);
906 }
907 }
908 }
909
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700910 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800911 }
912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 /**
914 * Temporary.
915 */
916 static public Signature stringToSignature(String str) {
917 final int N = str.length();
918 byte[] sig = new byte[N];
919 for (int i=0; i<N; i++) {
920 sig[i] = (byte)str.charAt(i);
921 }
922 return new Signature(sig);
923 }
924
925 private Package parsePackage(
926 Resources res, XmlResourceParser parser, int flags, String[] outError)
927 throws XmlPullParserException, IOException {
928 AttributeSet attrs = parser;
929
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700930 mParseInstrumentationArgs = null;
931 mParseActivityArgs = null;
932 mParseServiceArgs = null;
933 mParseProviderArgs = null;
934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 String pkgName = parsePackageName(parser, attrs, flags, outError);
936 if (pkgName == null) {
937 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
938 return null;
939 }
940 int type;
941
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700942 if (mOnlyCoreApps) {
943 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
944 if (!core) {
945 mParseError = PackageManager.INSTALL_SUCCEEDED;
946 return null;
947 }
948 }
949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 TypedArray sa = res.obtainAttributes(attrs,
954 com.android.internal.R.styleable.AndroidManifest);
955 pkg.mVersionCode = sa.getInteger(
956 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800957 pkg.mVersionName = sa.getNonConfigurationString(
958 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 if (pkg.mVersionName != null) {
960 pkg.mVersionName = pkg.mVersionName.intern();
961 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800962 String str = sa.getNonConfigurationString(
963 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
964 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 String nameError = validateName(str, true);
966 if (nameError != null && !"android".equals(pkgName)) {
967 outError[0] = "<manifest> specifies bad sharedUserId name \""
968 + str + "\": " + nameError;
969 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
970 return null;
971 }
972 pkg.mSharedUserId = str.intern();
973 pkg.mSharedUserLabel = sa.getResourceId(
974 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
975 }
976 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800977
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800978 pkg.installLocation = sa.getInteger(
979 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700980 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700981 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700982
983 /* Set the global "forward lock" flag */
984 if ((flags & PARSE_FORWARD_LOCK) != 0) {
985 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
986 }
987
988 /* Set the global "on SD card" flag */
989 if ((flags & PARSE_ON_SDCARD) != 0) {
990 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
991 }
992
Dianne Hackborn723738c2009-06-25 19:48:04 -0700993 // Resource boolean are -1, so 1 means we don't know the value.
994 int supportsSmallScreens = 1;
995 int supportsNormalScreens = 1;
996 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700997 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700998 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700999 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001002 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1003 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1004 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 continue;
1006 }
1007
1008 String tagName = parser.getName();
1009 if (tagName.equals("application")) {
1010 if (foundApp) {
1011 if (RIGID_PARSER) {
1012 outError[0] = "<manifest> has more than one <application>";
1013 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1014 return null;
1015 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001016 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 XmlUtils.skipCurrentTag(parser);
1018 continue;
1019 }
1020 }
1021
1022 foundApp = true;
1023 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1024 return null;
1025 }
1026 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001027 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 return null;
1029 }
1030 } else if (tagName.equals("permission")) {
1031 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1032 return null;
1033 }
1034 } else if (tagName.equals("permission-tree")) {
1035 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1036 return null;
1037 }
1038 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001039 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1040 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 }
1042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 } else if (tagName.equals("uses-configuration")) {
1044 ConfigurationInfo cPref = new ConfigurationInfo();
1045 sa = res.obtainAttributes(attrs,
1046 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1047 cPref.reqTouchScreen = sa.getInt(
1048 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1049 Configuration.TOUCHSCREEN_UNDEFINED);
1050 cPref.reqKeyboardType = sa.getInt(
1051 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1052 Configuration.KEYBOARD_UNDEFINED);
1053 if (sa.getBoolean(
1054 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1055 false)) {
1056 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1057 }
1058 cPref.reqNavigation = sa.getInt(
1059 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1060 Configuration.NAVIGATION_UNDEFINED);
1061 if (sa.getBoolean(
1062 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1063 false)) {
1064 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1065 }
1066 sa.recycle();
1067 pkg.configPreferences.add(cPref);
1068
1069 XmlUtils.skipCurrentTag(parser);
1070
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001071 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001072 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001073 sa = res.obtainAttributes(attrs,
1074 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001075 // Note: don't allow this value to be a reference to a resource
1076 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001077 fi.name = sa.getNonResourceString(
1078 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1079 if (fi.name == null) {
1080 fi.reqGlEsVersion = sa.getInt(
1081 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1082 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1083 }
1084 if (sa.getBoolean(
1085 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1086 true)) {
1087 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1088 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001089 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001090 if (pkg.reqFeatures == null) {
1091 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1092 }
1093 pkg.reqFeatures.add(fi);
1094
1095 if (fi.name == null) {
1096 ConfigurationInfo cPref = new ConfigurationInfo();
1097 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1098 pkg.configPreferences.add(cPref);
1099 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001100
1101 XmlUtils.skipCurrentTag(parser);
1102
Dianne Hackborn851a5412009-05-08 12:06:44 -07001103 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001104 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 sa = res.obtainAttributes(attrs,
1106 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1107
Dianne Hackborn851a5412009-05-08 12:06:44 -07001108 int minVers = 0;
1109 String minCode = null;
1110 int targetVers = 0;
1111 String targetCode = null;
1112
1113 TypedValue val = sa.peekValue(
1114 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1115 if (val != null) {
1116 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1117 targetCode = minCode = val.string.toString();
1118 } else {
1119 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001120 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001121 }
1122 }
1123
1124 val = sa.peekValue(
1125 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1126 if (val != null) {
1127 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1128 targetCode = minCode = val.string.toString();
1129 } else {
1130 // If it's not a string, it's an integer.
1131 targetVers = val.data;
1132 }
1133 }
1134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 sa.recycle();
1136
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001137 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001138 if (!minCode.equals(SDK_CODENAME)) {
1139 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001140 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001141 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001142 } else {
1143 outError[0] = "Requires development platform " + minCode
1144 + " but this is a release platform.";
1145 }
1146 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1147 return null;
1148 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001149 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001150 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001151 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001152 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1153 return null;
1154 }
1155
Dianne Hackborn851a5412009-05-08 12:06:44 -07001156 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001157 if (!targetCode.equals(SDK_CODENAME)) {
1158 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001159 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001160 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001161 } else {
1162 outError[0] = "Requires development platform " + targetCode
1163 + " but this is a release platform.";
1164 }
1165 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1166 return null;
1167 }
1168 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001169 pkg.applicationInfo.targetSdkVersion
1170 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1171 } else {
1172 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175
1176 XmlUtils.skipCurrentTag(parser);
1177
Dianne Hackborn723738c2009-06-25 19:48:04 -07001178 } else if (tagName.equals("supports-screens")) {
1179 sa = res.obtainAttributes(attrs,
1180 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1181
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001182 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1183 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1184 0);
1185 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1186 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1187 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001188 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1189 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1190 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001191
Dianne Hackborn723738c2009-06-25 19:48:04 -07001192 // This is a trick to get a boolean and still able to detect
1193 // if a value was actually set.
1194 supportsSmallScreens = sa.getInteger(
1195 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1196 supportsSmallScreens);
1197 supportsNormalScreens = sa.getInteger(
1198 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1199 supportsNormalScreens);
1200 supportsLargeScreens = sa.getInteger(
1201 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1202 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001203 supportsXLargeScreens = sa.getInteger(
1204 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1205 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001206 resizeable = sa.getInteger(
1207 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001208 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001209 anyDensity = sa.getInteger(
1210 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1211 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001212
1213 sa.recycle();
1214
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001215 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001216
1217 } else if (tagName.equals("protected-broadcast")) {
1218 sa = res.obtainAttributes(attrs,
1219 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1220
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001221 // Note: don't allow this value to be a reference to a resource
1222 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001223 String name = sa.getNonResourceString(
1224 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1225
1226 sa.recycle();
1227
1228 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1229 if (pkg.protectedBroadcasts == null) {
1230 pkg.protectedBroadcasts = new ArrayList<String>();
1231 }
1232 if (!pkg.protectedBroadcasts.contains(name)) {
1233 pkg.protectedBroadcasts.add(name.intern());
1234 }
1235 }
1236
1237 XmlUtils.skipCurrentTag(parser);
1238
1239 } else if (tagName.equals("instrumentation")) {
1240 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1241 return null;
1242 }
1243
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001244 } else if (tagName.equals("original-package")) {
1245 sa = res.obtainAttributes(attrs,
1246 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1247
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001248 String orig =sa.getNonConfigurationString(
1249 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001250 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001251 if (pkg.mOriginalPackages == null) {
1252 pkg.mOriginalPackages = new ArrayList<String>();
1253 pkg.mRealPackage = pkg.packageName;
1254 }
1255 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001256 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001257
1258 sa.recycle();
1259
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001260 XmlUtils.skipCurrentTag(parser);
1261
1262 } else if (tagName.equals("adopt-permissions")) {
1263 sa = res.obtainAttributes(attrs,
1264 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1265
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001266 String name = sa.getNonConfigurationString(
1267 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001268
1269 sa.recycle();
1270
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001271 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001272 if (pkg.mAdoptPermissions == null) {
1273 pkg.mAdoptPermissions = new ArrayList<String>();
1274 }
1275 pkg.mAdoptPermissions.add(name);
1276 }
1277
1278 XmlUtils.skipCurrentTag(parser);
1279
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001280 } else if (tagName.equals("uses-gl-texture")) {
1281 // Just skip this tag
1282 XmlUtils.skipCurrentTag(parser);
1283 continue;
1284
1285 } else if (tagName.equals("compatible-screens")) {
1286 // Just skip this tag
1287 XmlUtils.skipCurrentTag(parser);
1288 continue;
1289
Dianne Hackborn854060a2009-07-09 18:14:31 -07001290 } else if (tagName.equals("eat-comment")) {
1291 // Just skip this tag
1292 XmlUtils.skipCurrentTag(parser);
1293 continue;
1294
1295 } else if (RIGID_PARSER) {
1296 outError[0] = "Bad element under <manifest>: "
1297 + parser.getName();
1298 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1299 return null;
1300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001302 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001303 + " at " + mArchiveSourcePath + " "
1304 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 XmlUtils.skipCurrentTag(parser);
1306 continue;
1307 }
1308 }
1309
1310 if (!foundApp && pkg.instrumentation.size() == 0) {
1311 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1312 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1313 }
1314
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001315 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001316 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001317 for (int ip=0; ip<NP; ip++) {
1318 final PackageParser.NewPermissionInfo npi
1319 = PackageParser.NEW_PERMISSIONS[ip];
1320 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1321 break;
1322 }
1323 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001324 if (implicitPerms == null) {
1325 implicitPerms = new StringBuilder(128);
1326 implicitPerms.append(pkg.packageName);
1327 implicitPerms.append(": compat added ");
1328 } else {
1329 implicitPerms.append(' ');
1330 }
1331 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001332 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001333 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001334 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001335 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001336 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001337 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001338 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001339
1340 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1341 for (int is=0; is<NS; is++) {
1342 final PackageParser.SplitPermissionInfo spi
1343 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001344 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1345 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001346 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001347 }
1348 for (int in=0; in<spi.newPerms.length; in++) {
1349 final String perm = spi.newPerms[in];
1350 if (!pkg.requestedPermissions.contains(perm)) {
1351 pkg.requestedPermissions.add(perm);
1352 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1353 }
1354 }
1355 }
1356
Dianne Hackborn723738c2009-06-25 19:48:04 -07001357 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1358 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001359 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001360 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1361 }
1362 if (supportsNormalScreens != 0) {
1363 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1364 }
1365 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1366 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001367 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001368 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1369 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001370 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1371 && pkg.applicationInfo.targetSdkVersion
1372 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1373 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1374 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001375 if (resizeable < 0 || (resizeable > 0
1376 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001377 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001378 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1379 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001380 if (anyDensity < 0 || (anyDensity > 0
1381 && pkg.applicationInfo.targetSdkVersion
1382 >= android.os.Build.VERSION_CODES.DONUT)) {
1383 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001384 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001385
Nick Kralevich38f130e2013-04-04 13:19:10 -07001386 /*
1387 * b/8528162: Ignore the <uses-permission android:required> attribute if
1388 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1389 * which are improperly using this attribute, even though it never worked.
1390 */
1391 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1392 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1393 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1394 }
1395 }
1396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 return pkg;
1398 }
1399
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001400 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1401 AttributeSet attrs, String[] outError)
1402 throws XmlPullParserException, IOException {
1403 TypedArray sa = res.obtainAttributes(attrs,
1404 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1405
1406 // Note: don't allow this value to be a reference to a resource
1407 // that may change.
1408 String name = sa.getNonResourceString(
1409 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001410/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001411 boolean required = sa.getBoolean(
1412 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001413*/
1414 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001415
1416 sa.recycle();
1417
1418 if (name != null) {
1419 int index = pkg.requestedPermissions.indexOf(name);
1420 if (index == -1) {
1421 pkg.requestedPermissions.add(name.intern());
1422 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1423 } else {
1424 if (pkg.requestedPermissionsRequired.get(index) != required) {
1425 outError[0] = "conflicting <uses-permission> entries";
1426 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1427 return false;
1428 }
1429 }
1430 }
1431
1432 XmlUtils.skipCurrentTag(parser);
1433 return true;
1434 }
1435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 private static String buildClassName(String pkg, CharSequence clsSeq,
1437 String[] outError) {
1438 if (clsSeq == null || clsSeq.length() <= 0) {
1439 outError[0] = "Empty class name in package " + pkg;
1440 return null;
1441 }
1442 String cls = clsSeq.toString();
1443 char c = cls.charAt(0);
1444 if (c == '.') {
1445 return (pkg + cls).intern();
1446 }
1447 if (cls.indexOf('.') < 0) {
1448 StringBuilder b = new StringBuilder(pkg);
1449 b.append('.');
1450 b.append(cls);
1451 return b.toString().intern();
1452 }
1453 if (c >= 'a' && c <= 'z') {
1454 return cls.intern();
1455 }
1456 outError[0] = "Bad class name " + cls + " in package " + pkg;
1457 return null;
1458 }
1459
1460 private static String buildCompoundName(String pkg,
1461 CharSequence procSeq, String type, String[] outError) {
1462 String proc = procSeq.toString();
1463 char c = proc.charAt(0);
1464 if (pkg != null && c == ':') {
1465 if (proc.length() < 2) {
1466 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1467 + ": must be at least two characters";
1468 return null;
1469 }
1470 String subName = proc.substring(1);
1471 String nameError = validateName(subName, false);
1472 if (nameError != null) {
1473 outError[0] = "Invalid " + type + " name " + proc + " in package "
1474 + pkg + ": " + nameError;
1475 return null;
1476 }
1477 return (pkg + proc).intern();
1478 }
1479 String nameError = validateName(proc, true);
1480 if (nameError != null && !"system".equals(proc)) {
1481 outError[0] = "Invalid " + type + " name " + proc + " in package "
1482 + pkg + ": " + nameError;
1483 return null;
1484 }
1485 return proc.intern();
1486 }
1487
1488 private static String buildProcessName(String pkg, String defProc,
1489 CharSequence procSeq, int flags, String[] separateProcesses,
1490 String[] outError) {
1491 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1492 return defProc != null ? defProc : pkg;
1493 }
1494 if (separateProcesses != null) {
1495 for (int i=separateProcesses.length-1; i>=0; i--) {
1496 String sp = separateProcesses[i];
1497 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1498 return pkg;
1499 }
1500 }
1501 }
1502 if (procSeq == null || procSeq.length() <= 0) {
1503 return defProc;
1504 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001505 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 }
1507
1508 private static String buildTaskAffinityName(String pkg, String defProc,
1509 CharSequence procSeq, String[] outError) {
1510 if (procSeq == null) {
1511 return defProc;
1512 }
1513 if (procSeq.length() <= 0) {
1514 return null;
1515 }
1516 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1517 }
1518
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001519 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 XmlPullParser parser, AttributeSet attrs, String[] outError)
1521 throws XmlPullParserException, IOException {
1522 PermissionGroup perm = new PermissionGroup(owner);
1523
1524 TypedArray sa = res.obtainAttributes(attrs,
1525 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1526
1527 if (!parsePackageItemInfo(owner, perm.info, outError,
1528 "<permission-group>", sa,
1529 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1530 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001531 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1532 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 sa.recycle();
1534 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1535 return null;
1536 }
1537
1538 perm.info.descriptionRes = sa.getResourceId(
1539 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1540 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001541 perm.info.flags = sa.getInt(
1542 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001543 perm.info.priority = sa.getInt(
1544 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001545 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001546 perm.info.priority = 0;
1547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548
1549 sa.recycle();
1550
1551 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1552 outError)) {
1553 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1554 return null;
1555 }
1556
1557 owner.permissionGroups.add(perm);
1558
1559 return perm;
1560 }
1561
1562 private Permission parsePermission(Package owner, Resources res,
1563 XmlPullParser parser, AttributeSet attrs, String[] outError)
1564 throws XmlPullParserException, IOException {
1565 Permission perm = new Permission(owner);
1566
1567 TypedArray sa = res.obtainAttributes(attrs,
1568 com.android.internal.R.styleable.AndroidManifestPermission);
1569
1570 if (!parsePackageItemInfo(owner, perm.info, outError,
1571 "<permission>", sa,
1572 com.android.internal.R.styleable.AndroidManifestPermission_name,
1573 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001574 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1575 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 sa.recycle();
1577 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1578 return null;
1579 }
1580
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001581 // Note: don't allow this value to be a reference to a resource
1582 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 perm.info.group = sa.getNonResourceString(
1584 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1585 if (perm.info.group != null) {
1586 perm.info.group = perm.info.group.intern();
1587 }
1588
1589 perm.info.descriptionRes = sa.getResourceId(
1590 com.android.internal.R.styleable.AndroidManifestPermission_description,
1591 0);
1592
1593 perm.info.protectionLevel = sa.getInt(
1594 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1595 PermissionInfo.PROTECTION_NORMAL);
1596
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001597 perm.info.flags = sa.getInt(
1598 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 if (perm.info.protectionLevel == -1) {
1603 outError[0] = "<permission> does not specify protectionLevel";
1604 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1605 return null;
1606 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001607
1608 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1609
1610 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1611 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1612 PermissionInfo.PROTECTION_SIGNATURE) {
1613 outError[0] = "<permission> protectionLevel specifies a flag but is "
1614 + "not based on signature type";
1615 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1616 return null;
1617 }
1618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619
1620 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1621 outError)) {
1622 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1623 return null;
1624 }
1625
1626 owner.permissions.add(perm);
1627
1628 return perm;
1629 }
1630
1631 private Permission parsePermissionTree(Package owner, Resources res,
1632 XmlPullParser parser, AttributeSet attrs, String[] outError)
1633 throws XmlPullParserException, IOException {
1634 Permission perm = new Permission(owner);
1635
1636 TypedArray sa = res.obtainAttributes(attrs,
1637 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1638
1639 if (!parsePackageItemInfo(owner, perm.info, outError,
1640 "<permission-tree>", sa,
1641 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1642 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001643 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1644 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 sa.recycle();
1646 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1647 return null;
1648 }
1649
1650 sa.recycle();
1651
1652 int index = perm.info.name.indexOf('.');
1653 if (index > 0) {
1654 index = perm.info.name.indexOf('.', index+1);
1655 }
1656 if (index < 0) {
1657 outError[0] = "<permission-tree> name has less than three segments: "
1658 + perm.info.name;
1659 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1660 return null;
1661 }
1662
1663 perm.info.descriptionRes = 0;
1664 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1665 perm.tree = true;
1666
1667 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1668 outError)) {
1669 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1670 return null;
1671 }
1672
1673 owner.permissions.add(perm);
1674
1675 return perm;
1676 }
1677
1678 private Instrumentation parseInstrumentation(Package owner, Resources res,
1679 XmlPullParser parser, AttributeSet attrs, String[] outError)
1680 throws XmlPullParserException, IOException {
1681 TypedArray sa = res.obtainAttributes(attrs,
1682 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1683
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001684 if (mParseInstrumentationArgs == null) {
1685 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1686 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1687 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001688 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1689 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001690 mParseInstrumentationArgs.tag = "<instrumentation>";
1691 }
1692
1693 mParseInstrumentationArgs.sa = sa;
1694
1695 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1696 new InstrumentationInfo());
1697 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 sa.recycle();
1699 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1700 return null;
1701 }
1702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001704 // Note: don't allow this value to be a reference to a resource
1705 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 str = sa.getNonResourceString(
1707 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1708 a.info.targetPackage = str != null ? str.intern() : null;
1709
1710 a.info.handleProfiling = sa.getBoolean(
1711 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1712 false);
1713
1714 a.info.functionalTest = sa.getBoolean(
1715 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1716 false);
1717
1718 sa.recycle();
1719
1720 if (a.info.targetPackage == null) {
1721 outError[0] = "<instrumentation> does not specify targetPackage";
1722 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1723 return null;
1724 }
1725
1726 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1727 outError)) {
1728 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1729 return null;
1730 }
1731
1732 owner.instrumentation.add(a);
1733
1734 return a;
1735 }
1736
1737 private boolean parseApplication(Package owner, Resources res,
1738 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1739 throws XmlPullParserException, IOException {
1740 final ApplicationInfo ai = owner.applicationInfo;
1741 final String pkgName = owner.applicationInfo.packageName;
1742
1743 TypedArray sa = res.obtainAttributes(attrs,
1744 com.android.internal.R.styleable.AndroidManifestApplication);
1745
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001746 String name = sa.getNonConfigurationString(
1747 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 if (name != null) {
1749 ai.className = buildClassName(pkgName, name, outError);
1750 if (ai.className == null) {
1751 sa.recycle();
1752 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1753 return false;
1754 }
1755 }
1756
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001757 String manageSpaceActivity = sa.getNonConfigurationString(
1758 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 if (manageSpaceActivity != null) {
1760 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1761 outError);
1762 }
1763
Christopher Tate181fafa2009-05-14 11:12:14 -07001764 boolean allowBackup = sa.getBoolean(
1765 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1766 if (allowBackup) {
1767 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001768
Christopher Tate3de55bc2010-03-12 17:28:08 -08001769 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1770 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001771 String backupAgent = sa.getNonConfigurationString(
1772 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001773 if (backupAgent != null) {
1774 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001775 if (DEBUG_BACKUP) {
1776 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001777 + " from " + pkgName + "+" + backupAgent);
1778 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001779
1780 if (sa.getBoolean(
1781 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1782 true)) {
1783 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1784 }
1785 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001786 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1787 false)) {
1788 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1789 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001790 }
1791 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 TypedValue v = sa.peekValue(
1794 com.android.internal.R.styleable.AndroidManifestApplication_label);
1795 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1796 ai.nonLocalizedLabel = v.coerceToString();
1797 }
1798
1799 ai.icon = sa.getResourceId(
1800 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001801 ai.logo = sa.getResourceId(
1802 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001804 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 ai.descriptionRes = sa.getResourceId(
1806 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1807
1808 if ((flags&PARSE_IS_SYSTEM) != 0) {
1809 if (sa.getBoolean(
1810 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1811 false)) {
1812 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1813 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001814 if (sa.getBoolean(
1815 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1816 false)) {
1817 owner.mRequiredForAllUsers = true;
1818 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07001819 String accountType = sa.getString(com.android.internal.R.styleable
1820 .AndroidManifestApplication_restrictedAccountType);
1821 if (accountType != null && accountType.length() > 0) {
1822 owner.mRestrictedAccountType = accountType;
1823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 }
1825
1826 if (sa.getBoolean(
1827 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1828 false)) {
1829 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1830 }
1831
1832 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001833 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001834 false)) {
1835 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1836 }
1837
Romain Guy529b60a2010-08-03 18:05:47 -07001838 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001839 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001840 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001841
1842 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1844 true)) {
1845 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1846 }
1847
1848 if (sa.getBoolean(
1849 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1850 false)) {
1851 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1852 }
1853
1854 if (sa.getBoolean(
1855 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1856 true)) {
1857 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1858 }
1859
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001860 if (sa.getBoolean(
1861 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001862 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001863 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1864 }
1865
Jason parksa3cdaa52011-01-13 14:15:43 -06001866 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001867 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001868 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001869 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001870 }
1871
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001872 if (sa.getBoolean(
1873 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1874 false /* default is no RTL support*/)) {
1875 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1876 }
1877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001879 str = sa.getNonConfigurationString(
1880 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1882
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001883 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1884 str = sa.getNonConfigurationString(
1885 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1886 } else {
1887 // Some older apps have been seen to use a resource reference
1888 // here that on older builds was ignored (with a warning). We
1889 // need to continue to do this for them so they don't break.
1890 str = sa.getNonResourceString(
1891 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1894 str, outError);
1895
1896 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001897 CharSequence pname;
1898 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1899 pname = sa.getNonConfigurationString(
1900 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1901 } else {
1902 // Some older apps have been seen to use a resource reference
1903 // here that on older builds was ignored (with a warning). We
1904 // need to continue to do this for them so they don't break.
1905 pname = sa.getNonResourceString(
1906 com.android.internal.R.styleable.AndroidManifestApplication_process);
1907 }
1908 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 flags, mSeparateProcesses, outError);
1910
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001911 ai.enabled = sa.getBoolean(
1912 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001913
Dianne Hackborn02486b12010-08-26 14:18:37 -07001914 if (false) {
1915 if (sa.getBoolean(
1916 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1917 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001918 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001919
1920 // A heavy-weight application can not be in a custom process.
1921 // We can do direct compare because we intern all strings.
1922 if (ai.processName != null && ai.processName != ai.packageName) {
1923 outError[0] = "cantSaveState applications can not use custom processes";
1924 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001925 }
1926 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 }
1928
Adam Powell269248d2011-08-02 10:26:54 -07001929 ai.uiOptions = sa.getInt(
1930 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 sa.recycle();
1933
1934 if (outError[0] != null) {
1935 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1936 return false;
1937 }
1938
1939 final int innerDepth = parser.getDepth();
1940
1941 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001942 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1943 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1944 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 continue;
1946 }
1947
1948 String tagName = parser.getName();
1949 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001950 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1951 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 if (a == null) {
1953 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1954 return false;
1955 }
1956
1957 owner.activities.add(a);
1958
1959 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001960 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 if (a == null) {
1962 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1963 return false;
1964 }
1965
1966 owner.receivers.add(a);
1967
1968 } else if (tagName.equals("service")) {
1969 Service s = parseService(owner, res, parser, attrs, flags, outError);
1970 if (s == null) {
1971 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1972 return false;
1973 }
1974
1975 owner.services.add(s);
1976
1977 } else if (tagName.equals("provider")) {
1978 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1979 if (p == null) {
1980 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1981 return false;
1982 }
1983
1984 owner.providers.add(p);
1985
1986 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001987 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 if (a == null) {
1989 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1990 return false;
1991 }
1992
1993 owner.activities.add(a);
1994
1995 } else if (parser.getName().equals("meta-data")) {
1996 // note: application meta-data is stored off to the side, so it can
1997 // remain null in the primary copy (we like to avoid extra copies because
1998 // it can be large)
1999 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2000 outError)) == null) {
2001 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2002 return false;
2003 }
2004
Dianne Hackbornc895be72013-03-11 17:48:43 -07002005 } else if (tagName.equals("library")) {
2006 sa = res.obtainAttributes(attrs,
2007 com.android.internal.R.styleable.AndroidManifestLibrary);
2008
2009 // Note: don't allow this value to be a reference to a resource
2010 // that may change.
2011 String lname = sa.getNonResourceString(
2012 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2013
2014 sa.recycle();
2015
2016 if (lname != null) {
2017 if (owner.libraryNames == null) {
2018 owner.libraryNames = new ArrayList<String>();
2019 }
2020 if (!owner.libraryNames.contains(lname)) {
2021 owner.libraryNames.add(lname.intern());
2022 }
2023 }
2024
2025 XmlUtils.skipCurrentTag(parser);
2026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 } else if (tagName.equals("uses-library")) {
2028 sa = res.obtainAttributes(attrs,
2029 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2030
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002031 // Note: don't allow this value to be a reference to a resource
2032 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 String lname = sa.getNonResourceString(
2034 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002035 boolean req = sa.getBoolean(
2036 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2037 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038
2039 sa.recycle();
2040
Dianne Hackborn49237342009-08-27 20:08:01 -07002041 if (lname != null) {
2042 if (req) {
2043 if (owner.usesLibraries == null) {
2044 owner.usesLibraries = new ArrayList<String>();
2045 }
2046 if (!owner.usesLibraries.contains(lname)) {
2047 owner.usesLibraries.add(lname.intern());
2048 }
2049 } else {
2050 if (owner.usesOptionalLibraries == null) {
2051 owner.usesOptionalLibraries = new ArrayList<String>();
2052 }
2053 if (!owner.usesOptionalLibraries.contains(lname)) {
2054 owner.usesOptionalLibraries.add(lname.intern());
2055 }
2056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 }
2058
2059 XmlUtils.skipCurrentTag(parser);
2060
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002061 } else if (tagName.equals("uses-package")) {
2062 // Dependencies for app installers; we don't currently try to
2063 // enforce this.
2064 XmlUtils.skipCurrentTag(parser);
2065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 } else {
2067 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002068 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002069 + " at " + mArchiveSourcePath + " "
2070 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 XmlUtils.skipCurrentTag(parser);
2072 continue;
2073 } else {
2074 outError[0] = "Bad element under <application>: " + tagName;
2075 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2076 return false;
2077 }
2078 }
2079 }
2080
2081 return true;
2082 }
2083
2084 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2085 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002086 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002087 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 if (name == null) {
2089 outError[0] = tag + " does not specify android:name";
2090 return false;
2091 }
2092
2093 outInfo.name
2094 = buildClassName(owner.applicationInfo.packageName, name, outError);
2095 if (outInfo.name == null) {
2096 return false;
2097 }
2098
2099 int iconVal = sa.getResourceId(iconRes, 0);
2100 if (iconVal != 0) {
2101 outInfo.icon = iconVal;
2102 outInfo.nonLocalizedLabel = null;
2103 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002104
2105 int logoVal = sa.getResourceId(logoRes, 0);
2106 if (logoVal != 0) {
2107 outInfo.logo = logoVal;
2108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109
2110 TypedValue v = sa.peekValue(labelRes);
2111 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2112 outInfo.nonLocalizedLabel = v.coerceToString();
2113 }
2114
2115 outInfo.packageName = owner.packageName;
2116
2117 return true;
2118 }
2119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 private Activity parseActivity(Package owner, Resources res,
2121 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002122 boolean receiver, boolean hardwareAccelerated)
2123 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 TypedArray sa = res.obtainAttributes(attrs,
2125 com.android.internal.R.styleable.AndroidManifestActivity);
2126
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002127 if (mParseActivityArgs == null) {
2128 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2129 com.android.internal.R.styleable.AndroidManifestActivity_name,
2130 com.android.internal.R.styleable.AndroidManifestActivity_label,
2131 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002132 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002133 mSeparateProcesses,
2134 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002135 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002136 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2137 }
2138
2139 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2140 mParseActivityArgs.sa = sa;
2141 mParseActivityArgs.flags = flags;
2142
2143 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2144 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 sa.recycle();
2146 return null;
2147 }
2148
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002149 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2151 if (setExported) {
2152 a.info.exported = sa.getBoolean(
2153 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2154 }
2155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 a.info.theme = sa.getResourceId(
2157 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2158
Adam Powell269248d2011-08-02 10:26:54 -07002159 a.info.uiOptions = sa.getInt(
2160 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2161 a.info.applicationInfo.uiOptions);
2162
Adam Powelldd8fab22012-03-22 17:47:27 -07002163 String parentName = sa.getNonConfigurationString(
2164 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2165 if (parentName != null) {
2166 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2167 if (outError[0] == null) {
2168 a.info.parentActivityName = parentClassName;
2169 } else {
2170 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2171 parentName);
2172 outError[0] = null;
2173 }
2174 }
2175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002177 str = sa.getNonConfigurationString(
2178 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 if (str == null) {
2180 a.info.permission = owner.applicationInfo.permission;
2181 } else {
2182 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2183 }
2184
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002185 str = sa.getNonConfigurationString(
2186 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2188 owner.applicationInfo.taskAffinity, str, outError);
2189
2190 a.info.flags = 0;
2191 if (sa.getBoolean(
2192 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2193 false)) {
2194 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2195 }
2196
2197 if (sa.getBoolean(
2198 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2199 false)) {
2200 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2201 }
2202
2203 if (sa.getBoolean(
2204 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2205 false)) {
2206 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2207 }
2208
2209 if (sa.getBoolean(
2210 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2211 false)) {
2212 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2213 }
2214
2215 if (sa.getBoolean(
2216 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2217 false)) {
2218 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2219 }
2220
2221 if (sa.getBoolean(
2222 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2223 false)) {
2224 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2225 }
2226
2227 if (sa.getBoolean(
2228 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2229 false)) {
2230 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2231 }
2232
2233 if (sa.getBoolean(
2234 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2235 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2236 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2237 }
2238
Dianne Hackbornffa42482009-09-23 22:20:11 -07002239 if (sa.getBoolean(
2240 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2241 false)) {
2242 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2243 }
2244
Daniel Sandler613dde42010-06-21 13:46:39 -04002245 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002246 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2247 false)) {
2248 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2249 }
2250
2251 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002252 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2253 false)) {
2254 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2255 }
Craig Mautner5962b122012-10-05 14:45:52 -07002256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002258 if (sa.getBoolean(
2259 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2260 hardwareAccelerated)) {
2261 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2262 }
2263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 a.info.launchMode = sa.getInt(
2265 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2266 ActivityInfo.LAUNCH_MULTIPLE);
2267 a.info.screenOrientation = sa.getInt(
2268 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2269 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2270 a.info.configChanges = sa.getInt(
2271 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2272 0);
2273 a.info.softInputMode = sa.getInt(
2274 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2275 0);
2276 } else {
2277 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2278 a.info.configChanges = 0;
2279 }
2280
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002281 if (receiver) {
2282 if (sa.getBoolean(
2283 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2284 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002285 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002286 if (a.info.exported) {
2287 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2288 + a.className + " at " + mArchiveSourcePath + " "
2289 + parser.getPositionDescription());
2290 a.info.exported = false;
2291 }
2292 setExported = true;
2293 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002294 if (sa.getBoolean(
2295 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2296 false)) {
2297 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2298 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002299 }
2300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 sa.recycle();
2302
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002303 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002304 // A heavy-weight application can not have receives in its main process
2305 // We can do direct compare because we intern all strings.
2306 if (a.info.processName == owner.packageName) {
2307 outError[0] = "Heavy-weight applications can not have receivers in main process";
2308 }
2309 }
2310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 if (outError[0] != null) {
2312 return null;
2313 }
2314
2315 int outerDepth = parser.getDepth();
2316 int type;
2317 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2318 && (type != XmlPullParser.END_TAG
2319 || parser.getDepth() > outerDepth)) {
2320 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2321 continue;
2322 }
2323
2324 if (parser.getName().equals("intent-filter")) {
2325 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2326 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2327 return null;
2328 }
2329 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002330 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002331 + mArchiveSourcePath + " "
2332 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 } else {
2334 a.intents.add(intent);
2335 }
2336 } else if (parser.getName().equals("meta-data")) {
2337 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2338 outError)) == null) {
2339 return null;
2340 }
2341 } else {
2342 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002343 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002345 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002346 + " at " + mArchiveSourcePath + " "
2347 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002349 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002350 + " at " + mArchiveSourcePath + " "
2351 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 }
2353 XmlUtils.skipCurrentTag(parser);
2354 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002356 if (receiver) {
2357 outError[0] = "Bad element under <receiver>: " + parser.getName();
2358 } else {
2359 outError[0] = "Bad element under <activity>: " + parser.getName();
2360 }
2361 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 }
2364 }
2365
2366 if (!setExported) {
2367 a.info.exported = a.intents.size() > 0;
2368 }
2369
2370 return a;
2371 }
2372
2373 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002374 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2375 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 TypedArray sa = res.obtainAttributes(attrs,
2377 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2378
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002379 String targetActivity = sa.getNonConfigurationString(
2380 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 if (targetActivity == null) {
2382 outError[0] = "<activity-alias> does not specify android:targetActivity";
2383 sa.recycle();
2384 return null;
2385 }
2386
2387 targetActivity = buildClassName(owner.applicationInfo.packageName,
2388 targetActivity, outError);
2389 if (targetActivity == null) {
2390 sa.recycle();
2391 return null;
2392 }
2393
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002394 if (mParseActivityAliasArgs == null) {
2395 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2396 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2397 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2398 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002399 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002400 mSeparateProcesses,
2401 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002402 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002403 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2404 mParseActivityAliasArgs.tag = "<activity-alias>";
2405 }
2406
2407 mParseActivityAliasArgs.sa = sa;
2408 mParseActivityAliasArgs.flags = flags;
2409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 Activity target = null;
2411
2412 final int NA = owner.activities.size();
2413 for (int i=0; i<NA; i++) {
2414 Activity t = owner.activities.get(i);
2415 if (targetActivity.equals(t.info.name)) {
2416 target = t;
2417 break;
2418 }
2419 }
2420
2421 if (target == null) {
2422 outError[0] = "<activity-alias> target activity " + targetActivity
2423 + " not found in manifest";
2424 sa.recycle();
2425 return null;
2426 }
2427
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002428 ActivityInfo info = new ActivityInfo();
2429 info.targetActivity = targetActivity;
2430 info.configChanges = target.info.configChanges;
2431 info.flags = target.info.flags;
2432 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002433 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002434 info.labelRes = target.info.labelRes;
2435 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2436 info.launchMode = target.info.launchMode;
2437 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002438 if (info.descriptionRes == 0) {
2439 info.descriptionRes = target.info.descriptionRes;
2440 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002441 info.screenOrientation = target.info.screenOrientation;
2442 info.taskAffinity = target.info.taskAffinity;
2443 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002444 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002445 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002446 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002447
2448 Activity a = new Activity(mParseActivityAliasArgs, info);
2449 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 sa.recycle();
2451 return null;
2452 }
2453
2454 final boolean setExported = sa.hasValue(
2455 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2456 if (setExported) {
2457 a.info.exported = sa.getBoolean(
2458 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2459 }
2460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002462 str = sa.getNonConfigurationString(
2463 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 if (str != null) {
2465 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2466 }
2467
Adam Powelldd8fab22012-03-22 17:47:27 -07002468 String parentName = sa.getNonConfigurationString(
2469 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2470 0);
2471 if (parentName != null) {
2472 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2473 if (outError[0] == null) {
2474 a.info.parentActivityName = parentClassName;
2475 } else {
2476 Log.e(TAG, "Activity alias " + a.info.name +
2477 " specified invalid parentActivityName " + parentName);
2478 outError[0] = null;
2479 }
2480 }
2481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 sa.recycle();
2483
2484 if (outError[0] != null) {
2485 return null;
2486 }
2487
2488 int outerDepth = parser.getDepth();
2489 int type;
2490 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2491 && (type != XmlPullParser.END_TAG
2492 || parser.getDepth() > outerDepth)) {
2493 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2494 continue;
2495 }
2496
2497 if (parser.getName().equals("intent-filter")) {
2498 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2499 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2500 return null;
2501 }
2502 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002503 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002504 + mArchiveSourcePath + " "
2505 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 } else {
2507 a.intents.add(intent);
2508 }
2509 } else if (parser.getName().equals("meta-data")) {
2510 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2511 outError)) == null) {
2512 return null;
2513 }
2514 } else {
2515 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002516 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002517 + " at " + mArchiveSourcePath + " "
2518 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519 XmlUtils.skipCurrentTag(parser);
2520 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002521 } else {
2522 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2523 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 }
2526 }
2527
2528 if (!setExported) {
2529 a.info.exported = a.intents.size() > 0;
2530 }
2531
2532 return a;
2533 }
2534
2535 private Provider parseProvider(Package owner, Resources res,
2536 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2537 throws XmlPullParserException, IOException {
2538 TypedArray sa = res.obtainAttributes(attrs,
2539 com.android.internal.R.styleable.AndroidManifestProvider);
2540
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002541 if (mParseProviderArgs == null) {
2542 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2543 com.android.internal.R.styleable.AndroidManifestProvider_name,
2544 com.android.internal.R.styleable.AndroidManifestProvider_label,
2545 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002546 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002547 mSeparateProcesses,
2548 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002549 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002550 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2551 mParseProviderArgs.tag = "<provider>";
2552 }
2553
2554 mParseProviderArgs.sa = sa;
2555 mParseProviderArgs.flags = flags;
2556
2557 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2558 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 sa.recycle();
2560 return null;
2561 }
2562
Nick Kralevichf097b162012-07-28 12:43:48 -07002563 boolean providerExportedDefault = false;
2564
2565 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2566 // For compatibility, applications targeting API level 16 or lower
2567 // should have their content providers exported by default, unless they
2568 // specify otherwise.
2569 providerExportedDefault = true;
2570 }
2571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002573 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2574 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002576 String cpname = sa.getNonConfigurationString(
2577 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578
2579 p.info.isSyncable = sa.getBoolean(
2580 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2581 false);
2582
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002583 String permission = sa.getNonConfigurationString(
2584 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2585 String str = sa.getNonConfigurationString(
2586 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 if (str == null) {
2588 str = permission;
2589 }
2590 if (str == null) {
2591 p.info.readPermission = owner.applicationInfo.permission;
2592 } else {
2593 p.info.readPermission =
2594 str.length() > 0 ? str.toString().intern() : null;
2595 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002596 str = sa.getNonConfigurationString(
2597 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 if (str == null) {
2599 str = permission;
2600 }
2601 if (str == null) {
2602 p.info.writePermission = owner.applicationInfo.permission;
2603 } else {
2604 p.info.writePermission =
2605 str.length() > 0 ? str.toString().intern() : null;
2606 }
2607
2608 p.info.grantUriPermissions = sa.getBoolean(
2609 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2610 false);
2611
2612 p.info.multiprocess = sa.getBoolean(
2613 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2614 false);
2615
2616 p.info.initOrder = sa.getInt(
2617 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2618 0);
2619
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002620 p.info.flags = 0;
2621
2622 if (sa.getBoolean(
2623 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2624 false)) {
2625 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2626 if (p.info.exported) {
2627 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2628 + p.className + " at " + mArchiveSourcePath + " "
2629 + parser.getPositionDescription());
2630 p.info.exported = false;
2631 }
2632 }
2633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 sa.recycle();
2635
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002636 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002637 // A heavy-weight application can not have providers in its main process
2638 // We can do direct compare because we intern all strings.
2639 if (p.info.processName == owner.packageName) {
2640 outError[0] = "Heavy-weight applications can not have providers in main process";
2641 return null;
2642 }
2643 }
2644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002646 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 return null;
2648 }
2649 p.info.authority = cpname.intern();
2650
2651 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2652 return null;
2653 }
2654
2655 return p;
2656 }
2657
2658 private boolean parseProviderTags(Resources res,
2659 XmlPullParser parser, AttributeSet attrs,
2660 Provider outInfo, String[] outError)
2661 throws XmlPullParserException, IOException {
2662 int outerDepth = parser.getDepth();
2663 int type;
2664 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2665 && (type != XmlPullParser.END_TAG
2666 || parser.getDepth() > outerDepth)) {
2667 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2668 continue;
2669 }
2670
2671 if (parser.getName().equals("meta-data")) {
2672 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2673 outInfo.metaData, outError)) == null) {
2674 return false;
2675 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 } else if (parser.getName().equals("grant-uri-permission")) {
2678 TypedArray sa = res.obtainAttributes(attrs,
2679 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2680
2681 PatternMatcher pa = null;
2682
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002683 String str = sa.getNonConfigurationString(
2684 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 if (str != null) {
2686 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2687 }
2688
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002689 str = sa.getNonConfigurationString(
2690 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 if (str != null) {
2692 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2693 }
2694
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002695 str = sa.getNonConfigurationString(
2696 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 if (str != null) {
2698 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2699 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 sa.recycle();
2702
2703 if (pa != null) {
2704 if (outInfo.info.uriPermissionPatterns == null) {
2705 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2706 outInfo.info.uriPermissionPatterns[0] = pa;
2707 } else {
2708 final int N = outInfo.info.uriPermissionPatterns.length;
2709 PatternMatcher[] newp = new PatternMatcher[N+1];
2710 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2711 newp[N] = pa;
2712 outInfo.info.uriPermissionPatterns = newp;
2713 }
2714 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002715 } else {
2716 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002717 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002718 + parser.getName() + " at " + mArchiveSourcePath + " "
2719 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002720 XmlUtils.skipCurrentTag(parser);
2721 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002722 } else {
2723 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2724 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002725 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002726 }
2727 XmlUtils.skipCurrentTag(parser);
2728
2729 } else if (parser.getName().equals("path-permission")) {
2730 TypedArray sa = res.obtainAttributes(attrs,
2731 com.android.internal.R.styleable.AndroidManifestPathPermission);
2732
2733 PathPermission pa = null;
2734
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002735 String permission = sa.getNonConfigurationString(
2736 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2737 String readPermission = sa.getNonConfigurationString(
2738 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002739 if (readPermission == null) {
2740 readPermission = permission;
2741 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002742 String writePermission = sa.getNonConfigurationString(
2743 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002744 if (writePermission == null) {
2745 writePermission = permission;
2746 }
2747
2748 boolean havePerm = false;
2749 if (readPermission != null) {
2750 readPermission = readPermission.intern();
2751 havePerm = true;
2752 }
2753 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002754 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002755 havePerm = true;
2756 }
2757
2758 if (!havePerm) {
2759 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002760 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002761 + parser.getName() + " at " + mArchiveSourcePath + " "
2762 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002763 XmlUtils.skipCurrentTag(parser);
2764 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002765 } else {
2766 outError[0] = "No readPermission or writePermssion for <path-permission>";
2767 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002768 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002769 }
2770
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002771 String path = sa.getNonConfigurationString(
2772 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002773 if (path != null) {
2774 pa = new PathPermission(path,
2775 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2776 }
2777
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002778 path = sa.getNonConfigurationString(
2779 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002780 if (path != null) {
2781 pa = new PathPermission(path,
2782 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2783 }
2784
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002785 path = sa.getNonConfigurationString(
2786 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002787 if (path != null) {
2788 pa = new PathPermission(path,
2789 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2790 }
2791
2792 sa.recycle();
2793
2794 if (pa != null) {
2795 if (outInfo.info.pathPermissions == null) {
2796 outInfo.info.pathPermissions = new PathPermission[1];
2797 outInfo.info.pathPermissions[0] = pa;
2798 } else {
2799 final int N = outInfo.info.pathPermissions.length;
2800 PathPermission[] newp = new PathPermission[N+1];
2801 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2802 newp[N] = pa;
2803 outInfo.info.pathPermissions = newp;
2804 }
2805 } else {
2806 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002807 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002808 + parser.getName() + " at " + mArchiveSourcePath + " "
2809 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002810 XmlUtils.skipCurrentTag(parser);
2811 continue;
2812 }
2813 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2814 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 }
2816 XmlUtils.skipCurrentTag(parser);
2817
2818 } else {
2819 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002820 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002821 + parser.getName() + " at " + mArchiveSourcePath + " "
2822 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 XmlUtils.skipCurrentTag(parser);
2824 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002825 } else {
2826 outError[0] = "Bad element under <provider>: " + parser.getName();
2827 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 }
2830 }
2831 return true;
2832 }
2833
2834 private Service parseService(Package owner, Resources res,
2835 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2836 throws XmlPullParserException, IOException {
2837 TypedArray sa = res.obtainAttributes(attrs,
2838 com.android.internal.R.styleable.AndroidManifestService);
2839
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002840 if (mParseServiceArgs == null) {
2841 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2842 com.android.internal.R.styleable.AndroidManifestService_name,
2843 com.android.internal.R.styleable.AndroidManifestService_label,
2844 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002845 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002846 mSeparateProcesses,
2847 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002848 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002849 com.android.internal.R.styleable.AndroidManifestService_enabled);
2850 mParseServiceArgs.tag = "<service>";
2851 }
2852
2853 mParseServiceArgs.sa = sa;
2854 mParseServiceArgs.flags = flags;
2855
2856 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2857 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 sa.recycle();
2859 return null;
2860 }
2861
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002862 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 com.android.internal.R.styleable.AndroidManifestService_exported);
2864 if (setExported) {
2865 s.info.exported = sa.getBoolean(
2866 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2867 }
2868
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002869 String str = sa.getNonConfigurationString(
2870 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 if (str == null) {
2872 s.info.permission = owner.applicationInfo.permission;
2873 } else {
2874 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2875 }
2876
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002877 s.info.flags = 0;
2878 if (sa.getBoolean(
2879 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2880 false)) {
2881 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2882 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002883 if (sa.getBoolean(
2884 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2885 false)) {
2886 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2887 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002888 if (sa.getBoolean(
2889 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2890 false)) {
2891 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2892 if (s.info.exported) {
2893 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2894 + s.className + " at " + mArchiveSourcePath + " "
2895 + parser.getPositionDescription());
2896 s.info.exported = false;
2897 }
2898 setExported = true;
2899 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 sa.recycle();
2902
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002903 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002904 // A heavy-weight application can not have services in its main process
2905 // We can do direct compare because we intern all strings.
2906 if (s.info.processName == owner.packageName) {
2907 outError[0] = "Heavy-weight applications can not have services in main process";
2908 return null;
2909 }
2910 }
2911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 int outerDepth = parser.getDepth();
2913 int type;
2914 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2915 && (type != XmlPullParser.END_TAG
2916 || parser.getDepth() > outerDepth)) {
2917 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2918 continue;
2919 }
2920
2921 if (parser.getName().equals("intent-filter")) {
2922 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2923 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2924 return null;
2925 }
2926
2927 s.intents.add(intent);
2928 } else if (parser.getName().equals("meta-data")) {
2929 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2930 outError)) == null) {
2931 return null;
2932 }
2933 } else {
2934 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002935 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002936 + parser.getName() + " at " + mArchiveSourcePath + " "
2937 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 XmlUtils.skipCurrentTag(parser);
2939 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002940 } else {
2941 outError[0] = "Bad element under <service>: " + parser.getName();
2942 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 }
2945 }
2946
2947 if (!setExported) {
2948 s.info.exported = s.intents.size() > 0;
2949 }
2950
2951 return s;
2952 }
2953
2954 private boolean parseAllMetaData(Resources res,
2955 XmlPullParser parser, AttributeSet attrs, String tag,
2956 Component outInfo, String[] outError)
2957 throws XmlPullParserException, IOException {
2958 int outerDepth = parser.getDepth();
2959 int type;
2960 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2961 && (type != XmlPullParser.END_TAG
2962 || parser.getDepth() > outerDepth)) {
2963 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2964 continue;
2965 }
2966
2967 if (parser.getName().equals("meta-data")) {
2968 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2969 outInfo.metaData, outError)) == null) {
2970 return false;
2971 }
2972 } else {
2973 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002974 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002975 + parser.getName() + " at " + mArchiveSourcePath + " "
2976 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 XmlUtils.skipCurrentTag(parser);
2978 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002979 } else {
2980 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2981 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 }
2984 }
2985 return true;
2986 }
2987
2988 private Bundle parseMetaData(Resources res,
2989 XmlPullParser parser, AttributeSet attrs,
2990 Bundle data, String[] outError)
2991 throws XmlPullParserException, IOException {
2992
2993 TypedArray sa = res.obtainAttributes(attrs,
2994 com.android.internal.R.styleable.AndroidManifestMetaData);
2995
2996 if (data == null) {
2997 data = new Bundle();
2998 }
2999
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003000 String name = sa.getNonConfigurationString(
3001 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 if (name == null) {
3003 outError[0] = "<meta-data> requires an android:name attribute";
3004 sa.recycle();
3005 return null;
3006 }
3007
Dianne Hackborn854060a2009-07-09 18:14:31 -07003008 name = name.intern();
3009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 TypedValue v = sa.peekValue(
3011 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3012 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003013 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 data.putInt(name, v.resourceId);
3015 } else {
3016 v = sa.peekValue(
3017 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003018 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 if (v != null) {
3020 if (v.type == TypedValue.TYPE_STRING) {
3021 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003022 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3024 data.putBoolean(name, v.data != 0);
3025 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3026 && v.type <= TypedValue.TYPE_LAST_INT) {
3027 data.putInt(name, v.data);
3028 } else if (v.type == TypedValue.TYPE_FLOAT) {
3029 data.putFloat(name, v.getFloat());
3030 } else {
3031 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003032 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003033 + parser.getName() + " at " + mArchiveSourcePath + " "
3034 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 } else {
3036 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3037 data = null;
3038 }
3039 }
3040 } else {
3041 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3042 data = null;
3043 }
3044 }
3045
3046 sa.recycle();
3047
3048 XmlUtils.skipCurrentTag(parser);
3049
3050 return data;
3051 }
3052
Kenny Root05ca4c92011-09-15 10:36:25 -07003053 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3054 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3055 IOException {
3056 final TypedArray sa = res.obtainAttributes(attrs,
3057 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3058
3059 final String packageName = sa.getNonResourceString(
3060 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3061
3062 final String encodedPublicKey = sa.getNonResourceString(
3063 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3064
3065 sa.recycle();
3066
3067 if (packageName == null || packageName.length() == 0) {
3068 Slog.i(TAG, "verifier package name was null; skipping");
3069 return null;
3070 } else if (encodedPublicKey == null) {
3071 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3072 }
3073
3074 EncodedKeySpec keySpec;
3075 try {
3076 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3077 keySpec = new X509EncodedKeySpec(encoded);
3078 } catch (IllegalArgumentException e) {
3079 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
3080 return null;
3081 }
3082
3083 /* First try the key as an RSA key. */
3084 try {
3085 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
3086 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3087 return new VerifierInfo(packageName, publicKey);
3088 } catch (NoSuchAlgorithmException e) {
3089 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3090 return null;
3091 } catch (InvalidKeySpecException e) {
3092 // Not a RSA public key.
3093 }
3094
3095 /* Now try it as a DSA key. */
3096 try {
3097 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3098 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3099 return new VerifierInfo(packageName, publicKey);
3100 } catch (NoSuchAlgorithmException e) {
3101 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3102 return null;
3103 } catch (InvalidKeySpecException e) {
3104 // Not a DSA public key.
3105 }
3106
3107 return null;
3108 }
3109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 private static final String ANDROID_RESOURCES
3111 = "http://schemas.android.com/apk/res/android";
3112
3113 private boolean parseIntent(Resources res,
3114 XmlPullParser parser, AttributeSet attrs, int flags,
3115 IntentInfo outInfo, String[] outError, boolean isActivity)
3116 throws XmlPullParserException, IOException {
3117
3118 TypedArray sa = res.obtainAttributes(attrs,
3119 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3120
3121 int priority = sa.getInt(
3122 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 TypedValue v = sa.peekValue(
3126 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3127 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3128 outInfo.nonLocalizedLabel = v.coerceToString();
3129 }
3130
3131 outInfo.icon = sa.getResourceId(
3132 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003133
3134 outInfo.logo = sa.getResourceId(
3135 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136
3137 sa.recycle();
3138
3139 int outerDepth = parser.getDepth();
3140 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003141 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3142 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3143 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 continue;
3145 }
3146
3147 String nodeName = parser.getName();
3148 if (nodeName.equals("action")) {
3149 String value = attrs.getAttributeValue(
3150 ANDROID_RESOURCES, "name");
3151 if (value == null || value == "") {
3152 outError[0] = "No value supplied for <android:name>";
3153 return false;
3154 }
3155 XmlUtils.skipCurrentTag(parser);
3156
3157 outInfo.addAction(value);
3158 } else if (nodeName.equals("category")) {
3159 String value = attrs.getAttributeValue(
3160 ANDROID_RESOURCES, "name");
3161 if (value == null || value == "") {
3162 outError[0] = "No value supplied for <android:name>";
3163 return false;
3164 }
3165 XmlUtils.skipCurrentTag(parser);
3166
3167 outInfo.addCategory(value);
3168
3169 } else if (nodeName.equals("data")) {
3170 sa = res.obtainAttributes(attrs,
3171 com.android.internal.R.styleable.AndroidManifestData);
3172
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003173 String str = sa.getNonConfigurationString(
3174 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 if (str != null) {
3176 try {
3177 outInfo.addDataType(str);
3178 } catch (IntentFilter.MalformedMimeTypeException e) {
3179 outError[0] = e.toString();
3180 sa.recycle();
3181 return false;
3182 }
3183 }
3184
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003185 str = sa.getNonConfigurationString(
3186 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 if (str != null) {
3188 outInfo.addDataScheme(str);
3189 }
3190
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003191 String host = sa.getNonConfigurationString(
3192 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3193 String port = sa.getNonConfigurationString(
3194 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 if (host != null) {
3196 outInfo.addDataAuthority(host, port);
3197 }
3198
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003199 str = sa.getNonConfigurationString(
3200 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 if (str != null) {
3202 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3203 }
3204
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003205 str = sa.getNonConfigurationString(
3206 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 if (str != null) {
3208 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3209 }
3210
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003211 str = sa.getNonConfigurationString(
3212 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 if (str != null) {
3214 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3215 }
3216
3217 sa.recycle();
3218 XmlUtils.skipCurrentTag(parser);
3219 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003220 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003221 + parser.getName() + " at " + mArchiveSourcePath + " "
3222 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 XmlUtils.skipCurrentTag(parser);
3224 } else {
3225 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3226 return false;
3227 }
3228 }
3229
3230 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003231
3232 if (DEBUG_PARSER) {
3233 final StringBuilder cats = new StringBuilder("Intent d=");
3234 cats.append(outInfo.hasDefault);
3235 cats.append(", cat=");
3236
3237 final Iterator<String> it = outInfo.categoriesIterator();
3238 if (it != null) {
3239 while (it.hasNext()) {
3240 cats.append(' ');
3241 cats.append(it.next());
3242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003244 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246
3247 return true;
3248 }
3249
3250 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003251
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003252 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253
3254 // For now we only support one application per package.
3255 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3256
3257 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3258 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3259 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3260 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3261 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3262 public final ArrayList<Service> services = new ArrayList<Service>(0);
3263 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3264
3265 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003266 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267
Dianne Hackborn854060a2009-07-09 18:14:31 -07003268 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003269
3270 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003271 public ArrayList<String> usesLibraries = null;
3272 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 public String[] usesLibraryFiles = null;
3274
Dianne Hackbornc1552392010-03-03 16:19:01 -08003275 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003276 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003277 public ArrayList<String> mAdoptPermissions = null;
3278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 // We store the application meta-data independently to avoid multiple unwanted references
3280 public Bundle mAppMetaData = null;
3281
3282 // If this is a 3rd party app, this is the path of the zip file.
3283 public String mPath;
3284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 // The version code declared for this package.
3286 public int mVersionCode;
3287
3288 // The version name declared for this package.
3289 public String mVersionName;
3290
3291 // The shared user id that this package wants to use.
3292 public String mSharedUserId;
3293
3294 // The shared user label that this package wants to use.
3295 public int mSharedUserLabel;
3296
3297 // Signatures that were read from the package.
3298 public Signature mSignatures[];
3299
3300 // For use by package manager service for quick lookup of
3301 // preferred up order.
3302 public int mPreferredOrder = 0;
3303
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003304 // For use by the package manager to keep track of the path to the
3305 // file an app came from.
3306 public String mScanPath;
3307
3308 // For use by package manager to keep track of where it has done dexopt.
3309 public boolean mDidDexOpt;
3310
Amith Yamasani13593602012-03-22 16:16:17 -07003311 // // User set enabled state.
3312 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3313 //
3314 // // Whether the package has been stopped.
3315 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 // Additional data supplied by callers.
3318 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003319
3320 // Whether an operation is currently pending on this package
3321 public boolean mOperationPending;
3322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 /*
3324 * Applications hardware preferences
3325 */
3326 public final ArrayList<ConfigurationInfo> configPreferences =
3327 new ArrayList<ConfigurationInfo>();
3328
Dianne Hackborn49237342009-08-27 20:08:01 -07003329 /*
3330 * Applications requested features
3331 */
3332 public ArrayList<FeatureInfo> reqFeatures = null;
3333
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003334 public int installLocation;
3335
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003336 /* An app that's required for all users and cannot be uninstalled for a user */
3337 public boolean mRequiredForAllUsers;
3338
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003339 /* The restricted account authenticator type that is used by this application */
3340 public String mRestrictedAccountType;
3341
Kenny Rootbcc954d2011-08-08 16:19:08 -07003342 /**
3343 * Digest suitable for comparing whether this package's manifest is the
3344 * same as another.
3345 */
3346 public ManifestDigest manifestDigest;
3347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 public Package(String _name) {
3349 packageName = _name;
3350 applicationInfo.packageName = _name;
3351 applicationInfo.uid = -1;
3352 }
3353
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003354 public void setPackageName(String newName) {
3355 packageName = newName;
3356 applicationInfo.packageName = newName;
3357 for (int i=permissions.size()-1; i>=0; i--) {
3358 permissions.get(i).setPackageName(newName);
3359 }
3360 for (int i=permissionGroups.size()-1; i>=0; i--) {
3361 permissionGroups.get(i).setPackageName(newName);
3362 }
3363 for (int i=activities.size()-1; i>=0; i--) {
3364 activities.get(i).setPackageName(newName);
3365 }
3366 for (int i=receivers.size()-1; i>=0; i--) {
3367 receivers.get(i).setPackageName(newName);
3368 }
3369 for (int i=providers.size()-1; i>=0; i--) {
3370 providers.get(i).setPackageName(newName);
3371 }
3372 for (int i=services.size()-1; i>=0; i--) {
3373 services.get(i).setPackageName(newName);
3374 }
3375 for (int i=instrumentation.size()-1; i>=0; i--) {
3376 instrumentation.get(i).setPackageName(newName);
3377 }
3378 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003379
3380 public boolean hasComponentClassName(String name) {
3381 for (int i=activities.size()-1; i>=0; i--) {
3382 if (name.equals(activities.get(i).className)) {
3383 return true;
3384 }
3385 }
3386 for (int i=receivers.size()-1; i>=0; i--) {
3387 if (name.equals(receivers.get(i).className)) {
3388 return true;
3389 }
3390 }
3391 for (int i=providers.size()-1; i>=0; i--) {
3392 if (name.equals(providers.get(i).className)) {
3393 return true;
3394 }
3395 }
3396 for (int i=services.size()-1; i>=0; i--) {
3397 if (name.equals(services.get(i).className)) {
3398 return true;
3399 }
3400 }
3401 for (int i=instrumentation.size()-1; i>=0; i--) {
3402 if (name.equals(instrumentation.get(i).className)) {
3403 return true;
3404 }
3405 }
3406 return false;
3407 }
3408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 public String toString() {
3410 return "Package{"
3411 + Integer.toHexString(System.identityHashCode(this))
3412 + " " + packageName + "}";
3413 }
3414 }
3415
3416 public static class Component<II extends IntentInfo> {
3417 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003418 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003419 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 public Bundle metaData;
3421
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003422 ComponentName componentName;
3423 String componentShortName;
3424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 public Component(Package _owner) {
3426 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003427 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003428 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003429 }
3430
3431 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3432 owner = args.owner;
3433 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003434 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003435 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003436 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003437 args.outError[0] = args.tag + " does not specify android:name";
3438 return;
3439 }
3440
3441 outInfo.name
3442 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3443 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003444 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003445 args.outError[0] = args.tag + " does not have valid android:name";
3446 return;
3447 }
3448
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003449 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003450
3451 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3452 if (iconVal != 0) {
3453 outInfo.icon = iconVal;
3454 outInfo.nonLocalizedLabel = null;
3455 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003456
3457 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3458 if (logoVal != 0) {
3459 outInfo.logo = logoVal;
3460 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003461
3462 TypedValue v = args.sa.peekValue(args.labelRes);
3463 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3464 outInfo.nonLocalizedLabel = v.coerceToString();
3465 }
3466
3467 outInfo.packageName = owner.packageName;
3468 }
3469
3470 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3471 this(args, (PackageItemInfo)outInfo);
3472 if (args.outError[0] != null) {
3473 return;
3474 }
3475
3476 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003477 CharSequence pname;
3478 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3479 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3480 } else {
3481 // Some older apps have been seen to use a resource reference
3482 // here that on older builds was ignored (with a warning). We
3483 // need to continue to do this for them so they don't break.
3484 pname = args.sa.getNonResourceString(args.processRes);
3485 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003486 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003487 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003488 args.flags, args.sepProcesses, args.outError);
3489 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003490
3491 if (args.descriptionRes != 0) {
3492 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3493 }
3494
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003495 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 }
3497
3498 public Component(Component<II> clone) {
3499 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003500 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003501 className = clone.className;
3502 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003503 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003504 }
3505
3506 public ComponentName getComponentName() {
3507 if (componentName != null) {
3508 return componentName;
3509 }
3510 if (className != null) {
3511 componentName = new ComponentName(owner.applicationInfo.packageName,
3512 className);
3513 }
3514 return componentName;
3515 }
3516
3517 public String getComponentShortName() {
3518 if (componentShortName != null) {
3519 return componentShortName;
3520 }
3521 ComponentName component = getComponentName();
3522 if (component != null) {
3523 componentShortName = component.flattenToShortString();
3524 }
3525 return componentShortName;
3526 }
3527
3528 public void setPackageName(String packageName) {
3529 componentName = null;
3530 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 }
3532 }
3533
3534 public final static class Permission extends Component<IntentInfo> {
3535 public final PermissionInfo info;
3536 public boolean tree;
3537 public PermissionGroup group;
3538
3539 public Permission(Package _owner) {
3540 super(_owner);
3541 info = new PermissionInfo();
3542 }
3543
3544 public Permission(Package _owner, PermissionInfo _info) {
3545 super(_owner);
3546 info = _info;
3547 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003548
3549 public void setPackageName(String packageName) {
3550 super.setPackageName(packageName);
3551 info.packageName = packageName;
3552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553
3554 public String toString() {
3555 return "Permission{"
3556 + Integer.toHexString(System.identityHashCode(this))
3557 + " " + info.name + "}";
3558 }
3559 }
3560
3561 public final static class PermissionGroup extends Component<IntentInfo> {
3562 public final PermissionGroupInfo info;
3563
3564 public PermissionGroup(Package _owner) {
3565 super(_owner);
3566 info = new PermissionGroupInfo();
3567 }
3568
3569 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3570 super(_owner);
3571 info = _info;
3572 }
3573
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003574 public void setPackageName(String packageName) {
3575 super.setPackageName(packageName);
3576 info.packageName = packageName;
3577 }
3578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 public String toString() {
3580 return "PermissionGroup{"
3581 + Integer.toHexString(System.identityHashCode(this))
3582 + " " + info.name + "}";
3583 }
3584 }
3585
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003586 private static boolean copyNeeded(int flags, Package p,
3587 PackageUserState state, Bundle metaData, int userId) {
3588 if (userId != 0) {
3589 // We always need to copy for other users, since we need
3590 // to fix up the uid.
3591 return true;
3592 }
3593 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3594 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003595 if (p.applicationInfo.enabled != enabled) {
3596 return true;
3597 }
3598 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003599 if (!state.installed) {
3600 return true;
3601 }
3602 if (state.stopped) {
3603 return true;
3604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 if ((flags & PackageManager.GET_META_DATA) != 0
3606 && (metaData != null || p.mAppMetaData != null)) {
3607 return true;
3608 }
3609 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3610 && p.usesLibraryFiles != null) {
3611 return true;
3612 }
3613 return false;
3614 }
3615
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003616 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3617 PackageUserState state) {
3618 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003619 }
3620
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003621 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3622 PackageUserState state) {
3623 // CompatibilityMode is global state.
3624 if (!sCompatibilityModeEnabled) {
3625 ai.disableCompatibilityMode();
3626 }
3627 if (state.installed) {
3628 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3629 } else {
3630 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3631 }
3632 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3633 ai.enabled = true;
3634 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3635 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3636 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3637 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3638 ai.enabled = false;
3639 }
3640 ai.enabledSetting = state.enabled;
3641 }
3642
Amith Yamasani13593602012-03-22 16:16:17 -07003643 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003644 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003646 if (!checkUseInstalled(flags, state)) {
3647 return null;
3648 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003649 if (!copyNeeded(flags, p, state, null, userId)
3650 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3651 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3652 // In this case it is safe to directly modify the internal ApplicationInfo state:
3653 // - CompatibilityMode is global state, so will be the same for every call.
3654 // - We only come in to here if the app should reported as installed; this is the
3655 // default state, and we will do a copy otherwise.
3656 // - The enable state will always be reported the same for the application across
3657 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3658 // be doing a copy.
3659 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 return p.applicationInfo;
3661 }
3662
3663 // Make shallow copy so we can store the metadata/libraries safely
3664 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003665 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003666 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003667 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 if ((flags & PackageManager.GET_META_DATA) != 0) {
3670 ai.metaData = p.mAppMetaData;
3671 }
3672 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3673 ai.sharedLibraryFiles = p.usesLibraryFiles;
3674 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003675 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003676 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003677 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003678 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003679 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003680 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 return ai;
3682 }
3683
3684 public static final PermissionInfo generatePermissionInfo(
3685 Permission p, int flags) {
3686 if (p == null) return null;
3687 if ((flags&PackageManager.GET_META_DATA) == 0) {
3688 return p.info;
3689 }
3690 PermissionInfo pi = new PermissionInfo(p.info);
3691 pi.metaData = p.metaData;
3692 return pi;
3693 }
3694
3695 public static final PermissionGroupInfo generatePermissionGroupInfo(
3696 PermissionGroup pg, int flags) {
3697 if (pg == null) return null;
3698 if ((flags&PackageManager.GET_META_DATA) == 0) {
3699 return pg.info;
3700 }
3701 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3702 pgi.metaData = pg.metaData;
3703 return pgi;
3704 }
3705
3706 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003707 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003709 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3710 super(args, _info);
3711 info = _info;
3712 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003714
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003715 public void setPackageName(String packageName) {
3716 super.setPackageName(packageName);
3717 info.packageName = packageName;
3718 }
3719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 public String toString() {
3721 return "Activity{"
3722 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003723 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 }
3725 }
3726
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003727 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3728 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003730 if (!checkUseInstalled(flags, state)) {
3731 return null;
3732 }
3733 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 return a.info;
3735 }
3736 // Make shallow copies so we can store the metadata safely
3737 ActivityInfo ai = new ActivityInfo(a.info);
3738 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003739 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 return ai;
3741 }
3742
3743 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003744 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003746 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3747 super(args, _info);
3748 info = _info;
3749 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003751
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003752 public void setPackageName(String packageName) {
3753 super.setPackageName(packageName);
3754 info.packageName = packageName;
3755 }
3756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 public String toString() {
3758 return "Service{"
3759 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003760 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 }
3762 }
3763
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003764 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3765 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003767 if (!checkUseInstalled(flags, state)) {
3768 return null;
3769 }
3770 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 return s.info;
3772 }
3773 // Make shallow copies so we can store the metadata safely
3774 ServiceInfo si = new ServiceInfo(s.info);
3775 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003776 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 return si;
3778 }
3779
3780 public final static class Provider extends Component {
3781 public final ProviderInfo info;
3782 public boolean syncable;
3783
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003784 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3785 super(args, _info);
3786 info = _info;
3787 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 syncable = false;
3789 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 public Provider(Provider existingProvider) {
3792 super(existingProvider);
3793 this.info = existingProvider.info;
3794 this.syncable = existingProvider.syncable;
3795 }
3796
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003797 public void setPackageName(String packageName) {
3798 super.setPackageName(packageName);
3799 info.packageName = packageName;
3800 }
3801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 public String toString() {
3803 return "Provider{"
3804 + Integer.toHexString(System.identityHashCode(this))
3805 + " " + info.name + "}";
3806 }
3807 }
3808
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003809 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3810 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003812 if (!checkUseInstalled(flags, state)) {
3813 return null;
3814 }
3815 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003817 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 return p.info;
3819 }
3820 // Make shallow copies so we can store the metadata safely
3821 ProviderInfo pi = new ProviderInfo(p.info);
3822 pi.metaData = p.metaData;
3823 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3824 pi.uriPermissionPatterns = null;
3825 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003826 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 return pi;
3828 }
3829
3830 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003831 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003833 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3834 super(args, _info);
3835 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003837
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003838 public void setPackageName(String packageName) {
3839 super.setPackageName(packageName);
3840 info.packageName = packageName;
3841 }
3842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 public String toString() {
3844 return "Instrumentation{"
3845 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003846 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 }
3848 }
3849
3850 public static final InstrumentationInfo generateInstrumentationInfo(
3851 Instrumentation i, int flags) {
3852 if (i == null) return null;
3853 if ((flags&PackageManager.GET_META_DATA) == 0) {
3854 return i.info;
3855 }
3856 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3857 ii.metaData = i.metaData;
3858 return ii;
3859 }
3860
3861 public static class IntentInfo extends IntentFilter {
3862 public boolean hasDefault;
3863 public int labelRes;
3864 public CharSequence nonLocalizedLabel;
3865 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003866 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 }
3868
3869 public final static class ActivityIntentInfo extends IntentInfo {
3870 public final Activity activity;
3871
3872 public ActivityIntentInfo(Activity _activity) {
3873 activity = _activity;
3874 }
3875
3876 public String toString() {
3877 return "ActivityIntentInfo{"
3878 + Integer.toHexString(System.identityHashCode(this))
3879 + " " + activity.info.name + "}";
3880 }
3881 }
3882
3883 public final static class ServiceIntentInfo extends IntentInfo {
3884 public final Service service;
3885
3886 public ServiceIntentInfo(Service _service) {
3887 service = _service;
3888 }
3889
3890 public String toString() {
3891 return "ServiceIntentInfo{"
3892 + Integer.toHexString(System.identityHashCode(this))
3893 + " " + service.info.name + "}";
3894 }
3895 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003896
3897 /**
3898 * @hide
3899 */
3900 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3901 sCompatibilityModeEnabled = compatibilityModeEnabled;
3902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903}