blob: 358657325bb317f22cf56685d072b34953e28b24 [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;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700292 pi.requiredAccountType = p.mRequiredAccountType;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700293 pi.firstInstallTime = firstInstallTime;
294 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 if ((flags&PackageManager.GET_GIDS) != 0) {
296 pi.gids = gids;
297 }
298 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
299 int N = p.configPreferences.size();
300 if (N > 0) {
301 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700302 p.configPreferences.toArray(pi.configPreferences);
303 }
304 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
305 if (N > 0) {
306 pi.reqFeatures = new FeatureInfo[N];
307 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 }
309 }
310 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
311 int N = p.activities.size();
312 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700313 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
314 pi.activities = new ActivityInfo[N];
315 } else {
316 int num = 0;
317 for (int i=0; i<N; i++) {
318 if (p.activities.get(i).info.enabled) num++;
319 }
320 pi.activities = new ActivityInfo[num];
321 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700322 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 final Activity activity = p.activities.get(i);
324 if (activity.info.enabled
325 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700326 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700327 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 }
329 }
330 }
331 }
332 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
333 int N = p.receivers.size();
334 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700335 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
336 pi.receivers = new ActivityInfo[N];
337 } else {
338 int num = 0;
339 for (int i=0; i<N; i++) {
340 if (p.receivers.get(i).info.enabled) num++;
341 }
342 pi.receivers = new ActivityInfo[num];
343 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700344 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 final Activity activity = p.receivers.get(i);
346 if (activity.info.enabled
347 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700348 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700349 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 }
351 }
352 }
353 }
354 if ((flags&PackageManager.GET_SERVICES) != 0) {
355 int N = p.services.size();
356 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700357 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
358 pi.services = new ServiceInfo[N];
359 } else {
360 int num = 0;
361 for (int i=0; i<N; i++) {
362 if (p.services.get(i).info.enabled) num++;
363 }
364 pi.services = new ServiceInfo[num];
365 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700366 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 final Service service = p.services.get(i);
368 if (service.info.enabled
369 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700370 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
371 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 }
373 }
374 }
375 }
376 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
377 int N = p.providers.size();
378 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700379 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
380 pi.providers = new ProviderInfo[N];
381 } else {
382 int num = 0;
383 for (int i=0; i<N; i++) {
384 if (p.providers.get(i).info.enabled) num++;
385 }
386 pi.providers = new ProviderInfo[num];
387 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700388 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 final Provider provider = p.providers.get(i);
390 if (provider.info.enabled
391 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700392 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
393 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 }
395 }
396 }
397 }
398 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
399 int N = p.instrumentation.size();
400 if (N > 0) {
401 pi.instrumentation = new InstrumentationInfo[N];
402 for (int i=0; i<N; i++) {
403 pi.instrumentation[i] = generateInstrumentationInfo(
404 p.instrumentation.get(i), flags);
405 }
406 }
407 }
408 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
409 int N = p.permissions.size();
410 if (N > 0) {
411 pi.permissions = new PermissionInfo[N];
412 for (int i=0; i<N; i++) {
413 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
414 }
415 }
416 N = p.requestedPermissions.size();
417 if (N > 0) {
418 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800419 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800421 final String perm = p.requestedPermissions.get(i);
422 pi.requestedPermissions[i] = perm;
423 if (p.requestedPermissionsRequired.get(i)) {
424 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
425 }
426 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
427 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430 }
431 }
432 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700433 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
434 if (N > 0) {
435 pi.signatures = new Signature[N];
436 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 }
438 }
439 return pi;
440 }
441
442 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
443 byte[] readBuffer) {
444 try {
445 // We must read the stream for the JarEntry to retrieve
446 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700447 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
449 // not using
450 }
451 is.close();
452 return je != null ? je.getCertificates() : null;
453 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700454 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700456 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700457 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700458 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 }
460 return null;
461 }
462
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800463 public final static int PARSE_IS_SYSTEM = 1<<0;
464 public final static int PARSE_CHATTY = 1<<1;
465 public final static int PARSE_MUST_BE_APK = 1<<2;
466 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
467 public final static int PARSE_FORWARD_LOCK = 1<<4;
468 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700469 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470
471 public int getParseError() {
472 return mParseError;
473 }
474
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800475 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 DisplayMetrics metrics, int flags) {
477 mParseError = PackageManager.INSTALL_SUCCEEDED;
478
479 mArchiveSourcePath = sourceFile.getPath();
480 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700481 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
483 return null;
484 }
485 if (!isPackageFilename(sourceFile.getName())
486 && (flags&PARSE_MUST_BE_APK) != 0) {
487 if ((flags&PARSE_IS_SYSTEM) == 0) {
488 // We expect to have non-.apk files in the system dir,
489 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700490 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
492 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
493 return null;
494 }
495
Kenny Rootd2d29252011-08-08 11:27:57 -0700496 if (DEBUG_JAR)
497 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498
499 XmlResourceParser parser = null;
500 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800501 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 boolean assetError = true;
503 try {
504 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700505 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800506 if (cookie != 0) {
507 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700508 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 -0800509 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700510 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 assetError = false;
512 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700513 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 }
515 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700516 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 + mArchiveSourcePath, e);
518 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800519 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 if (assmgr != null) assmgr.close();
521 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
522 return null;
523 }
524 String[] errorText = new String[1];
525 Package pkg = null;
526 Exception errorException = null;
527 try {
528 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 pkg = parsePackage(res, parser, flags, errorText);
530 } catch (Exception e) {
531 errorException = e;
532 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
533 }
534
535
536 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700537 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
538 // just means to skip this app so don't make a fuss about it.
539 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
540 if (errorException != null) {
541 Slog.w(TAG, mArchiveSourcePath, errorException);
542 } else {
543 Slog.w(TAG, mArchiveSourcePath + " (at "
544 + parser.getPositionDescription()
545 + "): " + errorText[0]);
546 }
547 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
548 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 }
551 parser.close();
552 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 return null;
554 }
555
556 parser.close();
557 assmgr.close();
558
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800559 // Set code and resource paths
560 pkg.mPath = destCodePath;
561 pkg.mScanPath = mArchiveSourcePath;
562 //pkg.applicationInfo.sourceDir = destCodePath;
563 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 pkg.mSignatures = null;
565
566 return pkg;
567 }
568
Kenny Root6c918ce2013-04-02 14:04:24 -0700569 /**
570 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
571 * APK. If it successfully scanned the package and found the
572 * {@code AndroidManifest.xml}, {@code true} is returned.
573 */
574 public boolean collectManifestDigest(Package pkg) {
575 try {
576 final JarFile jarFile = new JarFile(mArchiveSourcePath);
577 try {
578 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
579 if (je != null) {
580 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
581 }
582 } finally {
583 jarFile.close();
584 }
585 return true;
586 } catch (IOException e) {
587 return false;
588 }
589 }
590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 public boolean collectCertificates(Package pkg, int flags) {
592 pkg.mSignatures = null;
593
594 WeakReference<byte[]> readBufferRef;
595 byte[] readBuffer = null;
596 synchronized (mSync) {
597 readBufferRef = mReadBuffer;
598 if (readBufferRef != null) {
599 mReadBuffer = null;
600 readBuffer = readBufferRef.get();
601 }
602 if (readBuffer == null) {
603 readBuffer = new byte[8192];
604 readBufferRef = new WeakReference<byte[]>(readBuffer);
605 }
606 }
607
608 try {
609 JarFile jarFile = new JarFile(mArchiveSourcePath);
610
611 Certificate[] certs = null;
612
613 if ((flags&PARSE_IS_SYSTEM) != 0) {
614 // If this package comes from the system image, then we
615 // can trust it... we'll just use the AndroidManifest.xml
616 // to retrieve its signatures, not validating all of the
617 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700618 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 certs = loadCertificates(jarFile, jarEntry, readBuffer);
620 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700621 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 + " has no certificates at entry "
623 + jarEntry.getName() + "; ignoring!");
624 jarFile.close();
625 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
626 return false;
627 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700628 if (DEBUG_JAR) {
629 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 + " certs=" + (certs != null ? certs.length : 0));
631 if (certs != null) {
632 final int N = certs.length;
633 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700634 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 + certs[i].getPublicKey().getEncoded()
636 + " " + certs[i].getPublicKey());
637 }
638 }
639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700641 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700643 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700645
Kenny Rootbcc954d2011-08-08 16:19:08 -0700646 final String name = je.getName();
647
648 if (name.startsWith("META-INF/"))
649 continue;
650
651 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700652 pkg.manifestDigest =
653 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700654 }
655
656 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700657 if (DEBUG_JAR) {
658 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 + ": certs=" + certs + " ("
660 + (certs != null ? certs.length : 0) + ")");
661 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700664 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 + " has no certificates at entry "
666 + je.getName() + "; ignoring!");
667 jarFile.close();
668 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
669 return false;
670 } else if (certs == null) {
671 certs = localCerts;
672 } else {
673 // Ensure all certificates match.
674 for (int i=0; i<certs.length; i++) {
675 boolean found = false;
676 for (int j=0; j<localCerts.length; j++) {
677 if (certs[i] != null &&
678 certs[i].equals(localCerts[j])) {
679 found = true;
680 break;
681 }
682 }
683 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700684 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 + " has mismatched certificates at entry "
686 + je.getName() + "; ignoring!");
687 jarFile.close();
688 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
689 return false;
690 }
691 }
692 }
693 }
694 }
695 jarFile.close();
696
697 synchronized (mSync) {
698 mReadBuffer = readBufferRef;
699 }
700
701 if (certs != null && certs.length > 0) {
702 final int N = certs.length;
703 pkg.mSignatures = new Signature[certs.length];
704 for (int i=0; i<N; i++) {
705 pkg.mSignatures[i] = new Signature(
706 certs[i].getEncoded());
707 }
708 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700709 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 + " has no certificates; ignoring!");
711 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
712 return false;
713 }
714 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700715 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
717 return false;
718 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700719 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
721 return false;
722 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700723 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
725 return false;
726 }
727
728 return true;
729 }
730
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800731 /*
732 * Utility method that retrieves just the package name and install
733 * location from the apk location at the given file path.
734 * @param packageFilePath file location of the apk
735 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700736 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800737 */
738 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700740 final XmlResourceParser parser;
741 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 try {
743 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700744 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 -0800745 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700748 if (cookie == 0) {
749 return null;
750 }
751
Kenny Root05ca4c92011-09-15 10:36:25 -0700752 final DisplayMetrics metrics = new DisplayMetrics();
753 metrics.setToDefaults();
754 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700755 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 } catch (Exception e) {
757 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700758 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 + packageFilePath, e);
760 return null;
761 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700762
763 final AttributeSet attrs = parser;
764 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800765 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700767 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700769 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700771 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 } finally {
773 if (parser != null) parser.close();
774 if (assmgr != null) assmgr.close();
775 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800776 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700777 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 return null;
779 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800780 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
782
783 private static String validateName(String name, boolean requiresSeparator) {
784 final int N = name.length();
785 boolean hasSep = false;
786 boolean front = true;
787 for (int i=0; i<N; i++) {
788 final char c = name.charAt(i);
789 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
790 front = false;
791 continue;
792 }
793 if (!front) {
794 if ((c >= '0' && c <= '9') || c == '_') {
795 continue;
796 }
797 }
798 if (c == '.') {
799 hasSep = true;
800 front = true;
801 continue;
802 }
803 return "bad character '" + c + "'";
804 }
805 return hasSep || !requiresSeparator
806 ? null : "must have at least one '.' separator";
807 }
808
809 private static String parsePackageName(XmlPullParser parser,
810 AttributeSet attrs, int flags, String[] outError)
811 throws IOException, XmlPullParserException {
812
813 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700814 while ((type = parser.next()) != XmlPullParser.START_TAG
815 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 ;
817 }
818
Kenny Rootd2d29252011-08-08 11:27:57 -0700819 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 outError[0] = "No start tag found";
821 return null;
822 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700823 if (DEBUG_PARSER)
824 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 if (!parser.getName().equals("manifest")) {
826 outError[0] = "No <manifest> tag";
827 return null;
828 }
829 String pkgName = attrs.getAttributeValue(null, "package");
830 if (pkgName == null || pkgName.length() == 0) {
831 outError[0] = "<manifest> does not specify package";
832 return null;
833 }
834 String nameError = validateName(pkgName, true);
835 if (nameError != null && !"android".equals(pkgName)) {
836 outError[0] = "<manifest> specifies bad package name \""
837 + pkgName + "\": " + nameError;
838 return null;
839 }
840
841 return pkgName.intern();
842 }
843
Kenny Root05ca4c92011-09-15 10:36:25 -0700844 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
845 AttributeSet attrs, int flags, String[] outError) throws IOException,
846 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800847
848 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700849 while ((type = parser.next()) != XmlPullParser.START_TAG
850 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800851 ;
852 }
853
Kenny Rootd2d29252011-08-08 11:27:57 -0700854 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800855 outError[0] = "No start tag found";
856 return null;
857 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700858 if (DEBUG_PARSER)
859 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800860 if (!parser.getName().equals("manifest")) {
861 outError[0] = "No <manifest> tag";
862 return null;
863 }
864 String pkgName = attrs.getAttributeValue(null, "package");
865 if (pkgName == null || pkgName.length() == 0) {
866 outError[0] = "<manifest> does not specify package";
867 return null;
868 }
869 String nameError = validateName(pkgName, true);
870 if (nameError != null && !"android".equals(pkgName)) {
871 outError[0] = "<manifest> specifies bad package name \""
872 + pkgName + "\": " + nameError;
873 return null;
874 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700875 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700876 int versionCode = 0;
877 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800878 for (int i = 0; i < attrs.getAttributeCount(); i++) {
879 String attr = attrs.getAttributeName(i);
880 if (attr.equals("installLocation")) {
881 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700882 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700883 numFound++;
884 } else if (attr.equals("versionCode")) {
885 versionCode = attrs.getAttributeIntValue(i, 0);
886 numFound++;
887 }
888 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800889 break;
890 }
891 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700892
893 // Only search the tree when the tag is directly below <manifest>
894 final int searchDepth = parser.getDepth() + 1;
895
896 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
897 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
898 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
899 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
900 continue;
901 }
902
903 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
904 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
905 if (verifier != null) {
906 verifiers.add(verifier);
907 }
908 }
909 }
910
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700911 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800912 }
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 /**
915 * Temporary.
916 */
917 static public Signature stringToSignature(String str) {
918 final int N = str.length();
919 byte[] sig = new byte[N];
920 for (int i=0; i<N; i++) {
921 sig[i] = (byte)str.charAt(i);
922 }
923 return new Signature(sig);
924 }
925
926 private Package parsePackage(
927 Resources res, XmlResourceParser parser, int flags, String[] outError)
928 throws XmlPullParserException, IOException {
929 AttributeSet attrs = parser;
930
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700931 mParseInstrumentationArgs = null;
932 mParseActivityArgs = null;
933 mParseServiceArgs = null;
934 mParseProviderArgs = null;
935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 String pkgName = parsePackageName(parser, attrs, flags, outError);
937 if (pkgName == null) {
938 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
939 return null;
940 }
941 int type;
942
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700943 if (mOnlyCoreApps) {
944 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
945 if (!core) {
946 mParseError = PackageManager.INSTALL_SUCCEEDED;
947 return null;
948 }
949 }
950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 TypedArray sa = res.obtainAttributes(attrs,
955 com.android.internal.R.styleable.AndroidManifest);
956 pkg.mVersionCode = sa.getInteger(
957 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800958 pkg.mVersionName = sa.getNonConfigurationString(
959 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 if (pkg.mVersionName != null) {
961 pkg.mVersionName = pkg.mVersionName.intern();
962 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800963 String str = sa.getNonConfigurationString(
964 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
965 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 String nameError = validateName(str, true);
967 if (nameError != null && !"android".equals(pkgName)) {
968 outError[0] = "<manifest> specifies bad sharedUserId name \""
969 + str + "\": " + nameError;
970 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
971 return null;
972 }
973 pkg.mSharedUserId = str.intern();
974 pkg.mSharedUserLabel = sa.getResourceId(
975 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
976 }
977 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800978
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800979 pkg.installLocation = sa.getInteger(
980 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700981 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700982 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700983
984 /* Set the global "forward lock" flag */
985 if ((flags & PARSE_FORWARD_LOCK) != 0) {
986 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
987 }
988
989 /* Set the global "on SD card" flag */
990 if ((flags & PARSE_ON_SDCARD) != 0) {
991 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
992 }
993
Dianne Hackborn723738c2009-06-25 19:48:04 -0700994 // Resource boolean are -1, so 1 means we don't know the value.
995 int supportsSmallScreens = 1;
996 int supportsNormalScreens = 1;
997 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700998 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700999 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001000 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001003 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1004 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1005 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 continue;
1007 }
1008
1009 String tagName = parser.getName();
1010 if (tagName.equals("application")) {
1011 if (foundApp) {
1012 if (RIGID_PARSER) {
1013 outError[0] = "<manifest> has more than one <application>";
1014 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1015 return null;
1016 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001017 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 XmlUtils.skipCurrentTag(parser);
1019 continue;
1020 }
1021 }
1022
1023 foundApp = true;
1024 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1025 return null;
1026 }
1027 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001028 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 return null;
1030 }
1031 } else if (tagName.equals("permission")) {
1032 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1033 return null;
1034 }
1035 } else if (tagName.equals("permission-tree")) {
1036 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1037 return null;
1038 }
1039 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001040 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1041 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 }
1043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 } else if (tagName.equals("uses-configuration")) {
1045 ConfigurationInfo cPref = new ConfigurationInfo();
1046 sa = res.obtainAttributes(attrs,
1047 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1048 cPref.reqTouchScreen = sa.getInt(
1049 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1050 Configuration.TOUCHSCREEN_UNDEFINED);
1051 cPref.reqKeyboardType = sa.getInt(
1052 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1053 Configuration.KEYBOARD_UNDEFINED);
1054 if (sa.getBoolean(
1055 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1056 false)) {
1057 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1058 }
1059 cPref.reqNavigation = sa.getInt(
1060 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1061 Configuration.NAVIGATION_UNDEFINED);
1062 if (sa.getBoolean(
1063 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1064 false)) {
1065 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1066 }
1067 sa.recycle();
1068 pkg.configPreferences.add(cPref);
1069
1070 XmlUtils.skipCurrentTag(parser);
1071
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001072 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001073 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001074 sa = res.obtainAttributes(attrs,
1075 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001076 // Note: don't allow this value to be a reference to a resource
1077 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001078 fi.name = sa.getNonResourceString(
1079 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1080 if (fi.name == null) {
1081 fi.reqGlEsVersion = sa.getInt(
1082 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1083 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1084 }
1085 if (sa.getBoolean(
1086 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1087 true)) {
1088 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1089 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001090 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001091 if (pkg.reqFeatures == null) {
1092 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1093 }
1094 pkg.reqFeatures.add(fi);
1095
1096 if (fi.name == null) {
1097 ConfigurationInfo cPref = new ConfigurationInfo();
1098 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1099 pkg.configPreferences.add(cPref);
1100 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001101
1102 XmlUtils.skipCurrentTag(parser);
1103
Dianne Hackborn851a5412009-05-08 12:06:44 -07001104 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001105 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 sa = res.obtainAttributes(attrs,
1107 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1108
Dianne Hackborn851a5412009-05-08 12:06:44 -07001109 int minVers = 0;
1110 String minCode = null;
1111 int targetVers = 0;
1112 String targetCode = null;
1113
1114 TypedValue val = sa.peekValue(
1115 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1116 if (val != null) {
1117 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1118 targetCode = minCode = val.string.toString();
1119 } else {
1120 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001121 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001122 }
1123 }
1124
1125 val = sa.peekValue(
1126 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1127 if (val != null) {
1128 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1129 targetCode = minCode = val.string.toString();
1130 } else {
1131 // If it's not a string, it's an integer.
1132 targetVers = val.data;
1133 }
1134 }
1135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 sa.recycle();
1137
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001138 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001139 if (!minCode.equals(SDK_CODENAME)) {
1140 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001141 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001142 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001143 } else {
1144 outError[0] = "Requires development platform " + minCode
1145 + " but this is a release platform.";
1146 }
1147 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1148 return null;
1149 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001150 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001151 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001152 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001153 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1154 return null;
1155 }
1156
Dianne Hackborn851a5412009-05-08 12:06:44 -07001157 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001158 if (!targetCode.equals(SDK_CODENAME)) {
1159 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001160 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001161 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001162 } else {
1163 outError[0] = "Requires development platform " + targetCode
1164 + " but this is a release platform.";
1165 }
1166 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1167 return null;
1168 }
1169 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001170 pkg.applicationInfo.targetSdkVersion
1171 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1172 } else {
1173 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176
1177 XmlUtils.skipCurrentTag(parser);
1178
Dianne Hackborn723738c2009-06-25 19:48:04 -07001179 } else if (tagName.equals("supports-screens")) {
1180 sa = res.obtainAttributes(attrs,
1181 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1182
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001183 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1184 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1185 0);
1186 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1187 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1188 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001189 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1190 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1191 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001192
Dianne Hackborn723738c2009-06-25 19:48:04 -07001193 // This is a trick to get a boolean and still able to detect
1194 // if a value was actually set.
1195 supportsSmallScreens = sa.getInteger(
1196 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1197 supportsSmallScreens);
1198 supportsNormalScreens = sa.getInteger(
1199 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1200 supportsNormalScreens);
1201 supportsLargeScreens = sa.getInteger(
1202 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1203 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001204 supportsXLargeScreens = sa.getInteger(
1205 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1206 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001207 resizeable = sa.getInteger(
1208 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001209 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001210 anyDensity = sa.getInteger(
1211 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1212 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001213
1214 sa.recycle();
1215
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001216 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001217
1218 } else if (tagName.equals("protected-broadcast")) {
1219 sa = res.obtainAttributes(attrs,
1220 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1221
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001222 // Note: don't allow this value to be a reference to a resource
1223 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001224 String name = sa.getNonResourceString(
1225 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1226
1227 sa.recycle();
1228
1229 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1230 if (pkg.protectedBroadcasts == null) {
1231 pkg.protectedBroadcasts = new ArrayList<String>();
1232 }
1233 if (!pkg.protectedBroadcasts.contains(name)) {
1234 pkg.protectedBroadcasts.add(name.intern());
1235 }
1236 }
1237
1238 XmlUtils.skipCurrentTag(parser);
1239
1240 } else if (tagName.equals("instrumentation")) {
1241 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1242 return null;
1243 }
1244
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001245 } else if (tagName.equals("original-package")) {
1246 sa = res.obtainAttributes(attrs,
1247 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1248
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001249 String orig =sa.getNonConfigurationString(
1250 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001251 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001252 if (pkg.mOriginalPackages == null) {
1253 pkg.mOriginalPackages = new ArrayList<String>();
1254 pkg.mRealPackage = pkg.packageName;
1255 }
1256 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001257 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001258
1259 sa.recycle();
1260
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001261 XmlUtils.skipCurrentTag(parser);
1262
1263 } else if (tagName.equals("adopt-permissions")) {
1264 sa = res.obtainAttributes(attrs,
1265 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1266
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001267 String name = sa.getNonConfigurationString(
1268 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001269
1270 sa.recycle();
1271
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001272 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001273 if (pkg.mAdoptPermissions == null) {
1274 pkg.mAdoptPermissions = new ArrayList<String>();
1275 }
1276 pkg.mAdoptPermissions.add(name);
1277 }
1278
1279 XmlUtils.skipCurrentTag(parser);
1280
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001281 } else if (tagName.equals("uses-gl-texture")) {
1282 // Just skip this tag
1283 XmlUtils.skipCurrentTag(parser);
1284 continue;
1285
1286 } else if (tagName.equals("compatible-screens")) {
1287 // Just skip this tag
1288 XmlUtils.skipCurrentTag(parser);
1289 continue;
1290
Dianne Hackborn854060a2009-07-09 18:14:31 -07001291 } else if (tagName.equals("eat-comment")) {
1292 // Just skip this tag
1293 XmlUtils.skipCurrentTag(parser);
1294 continue;
1295
1296 } else if (RIGID_PARSER) {
1297 outError[0] = "Bad element under <manifest>: "
1298 + parser.getName();
1299 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1300 return null;
1301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001303 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001304 + " at " + mArchiveSourcePath + " "
1305 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 XmlUtils.skipCurrentTag(parser);
1307 continue;
1308 }
1309 }
1310
1311 if (!foundApp && pkg.instrumentation.size() == 0) {
1312 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1313 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1314 }
1315
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001316 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001317 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001318 for (int ip=0; ip<NP; ip++) {
1319 final PackageParser.NewPermissionInfo npi
1320 = PackageParser.NEW_PERMISSIONS[ip];
1321 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1322 break;
1323 }
1324 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001325 if (implicitPerms == null) {
1326 implicitPerms = new StringBuilder(128);
1327 implicitPerms.append(pkg.packageName);
1328 implicitPerms.append(": compat added ");
1329 } else {
1330 implicitPerms.append(' ');
1331 }
1332 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001333 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001334 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001335 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001336 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001337 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001338 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001339 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001340
1341 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1342 for (int is=0; is<NS; is++) {
1343 final PackageParser.SplitPermissionInfo spi
1344 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001345 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1346 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001347 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001348 }
1349 for (int in=0; in<spi.newPerms.length; in++) {
1350 final String perm = spi.newPerms[in];
1351 if (!pkg.requestedPermissions.contains(perm)) {
1352 pkg.requestedPermissions.add(perm);
1353 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1354 }
1355 }
1356 }
1357
Dianne Hackborn723738c2009-06-25 19:48:04 -07001358 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1359 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001360 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001361 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1362 }
1363 if (supportsNormalScreens != 0) {
1364 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1365 }
1366 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1367 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001368 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001369 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1370 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001371 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1372 && pkg.applicationInfo.targetSdkVersion
1373 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1374 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1375 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001376 if (resizeable < 0 || (resizeable > 0
1377 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001378 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001379 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1380 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001381 if (anyDensity < 0 || (anyDensity > 0
1382 && pkg.applicationInfo.targetSdkVersion
1383 >= android.os.Build.VERSION_CODES.DONUT)) {
1384 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001385 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001386
Nick Kralevich38f130e2013-04-04 13:19:10 -07001387 /*
1388 * b/8528162: Ignore the <uses-permission android:required> attribute if
1389 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1390 * which are improperly using this attribute, even though it never worked.
1391 */
1392 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1393 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1394 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1395 }
1396 }
1397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 return pkg;
1399 }
1400
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001401 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1402 AttributeSet attrs, String[] outError)
1403 throws XmlPullParserException, IOException {
1404 TypedArray sa = res.obtainAttributes(attrs,
1405 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1406
1407 // Note: don't allow this value to be a reference to a resource
1408 // that may change.
1409 String name = sa.getNonResourceString(
1410 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001411/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001412 boolean required = sa.getBoolean(
1413 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001414*/
1415 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001416
1417 sa.recycle();
1418
1419 if (name != null) {
1420 int index = pkg.requestedPermissions.indexOf(name);
1421 if (index == -1) {
1422 pkg.requestedPermissions.add(name.intern());
1423 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1424 } else {
1425 if (pkg.requestedPermissionsRequired.get(index) != required) {
1426 outError[0] = "conflicting <uses-permission> entries";
1427 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1428 return false;
1429 }
1430 }
1431 }
1432
1433 XmlUtils.skipCurrentTag(parser);
1434 return true;
1435 }
1436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 private static String buildClassName(String pkg, CharSequence clsSeq,
1438 String[] outError) {
1439 if (clsSeq == null || clsSeq.length() <= 0) {
1440 outError[0] = "Empty class name in package " + pkg;
1441 return null;
1442 }
1443 String cls = clsSeq.toString();
1444 char c = cls.charAt(0);
1445 if (c == '.') {
1446 return (pkg + cls).intern();
1447 }
1448 if (cls.indexOf('.') < 0) {
1449 StringBuilder b = new StringBuilder(pkg);
1450 b.append('.');
1451 b.append(cls);
1452 return b.toString().intern();
1453 }
1454 if (c >= 'a' && c <= 'z') {
1455 return cls.intern();
1456 }
1457 outError[0] = "Bad class name " + cls + " in package " + pkg;
1458 return null;
1459 }
1460
1461 private static String buildCompoundName(String pkg,
1462 CharSequence procSeq, String type, String[] outError) {
1463 String proc = procSeq.toString();
1464 char c = proc.charAt(0);
1465 if (pkg != null && c == ':') {
1466 if (proc.length() < 2) {
1467 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1468 + ": must be at least two characters";
1469 return null;
1470 }
1471 String subName = proc.substring(1);
1472 String nameError = validateName(subName, false);
1473 if (nameError != null) {
1474 outError[0] = "Invalid " + type + " name " + proc + " in package "
1475 + pkg + ": " + nameError;
1476 return null;
1477 }
1478 return (pkg + proc).intern();
1479 }
1480 String nameError = validateName(proc, true);
1481 if (nameError != null && !"system".equals(proc)) {
1482 outError[0] = "Invalid " + type + " name " + proc + " in package "
1483 + pkg + ": " + nameError;
1484 return null;
1485 }
1486 return proc.intern();
1487 }
1488
1489 private static String buildProcessName(String pkg, String defProc,
1490 CharSequence procSeq, int flags, String[] separateProcesses,
1491 String[] outError) {
1492 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1493 return defProc != null ? defProc : pkg;
1494 }
1495 if (separateProcesses != null) {
1496 for (int i=separateProcesses.length-1; i>=0; i--) {
1497 String sp = separateProcesses[i];
1498 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1499 return pkg;
1500 }
1501 }
1502 }
1503 if (procSeq == null || procSeq.length() <= 0) {
1504 return defProc;
1505 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001506 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 }
1508
1509 private static String buildTaskAffinityName(String pkg, String defProc,
1510 CharSequence procSeq, String[] outError) {
1511 if (procSeq == null) {
1512 return defProc;
1513 }
1514 if (procSeq.length() <= 0) {
1515 return null;
1516 }
1517 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1518 }
1519
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001520 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 XmlPullParser parser, AttributeSet attrs, String[] outError)
1522 throws XmlPullParserException, IOException {
1523 PermissionGroup perm = new PermissionGroup(owner);
1524
1525 TypedArray sa = res.obtainAttributes(attrs,
1526 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1527
1528 if (!parsePackageItemInfo(owner, perm.info, outError,
1529 "<permission-group>", sa,
1530 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1531 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001532 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1533 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 sa.recycle();
1535 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1536 return null;
1537 }
1538
1539 perm.info.descriptionRes = sa.getResourceId(
1540 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1541 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001542 perm.info.flags = sa.getInt(
1543 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001544 perm.info.priority = sa.getInt(
1545 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001546 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001547 perm.info.priority = 0;
1548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549
1550 sa.recycle();
1551
1552 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1553 outError)) {
1554 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1555 return null;
1556 }
1557
1558 owner.permissionGroups.add(perm);
1559
1560 return perm;
1561 }
1562
1563 private Permission parsePermission(Package owner, Resources res,
1564 XmlPullParser parser, AttributeSet attrs, String[] outError)
1565 throws XmlPullParserException, IOException {
1566 Permission perm = new Permission(owner);
1567
1568 TypedArray sa = res.obtainAttributes(attrs,
1569 com.android.internal.R.styleable.AndroidManifestPermission);
1570
1571 if (!parsePackageItemInfo(owner, perm.info, outError,
1572 "<permission>", sa,
1573 com.android.internal.R.styleable.AndroidManifestPermission_name,
1574 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001575 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1576 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 sa.recycle();
1578 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1579 return null;
1580 }
1581
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001582 // Note: don't allow this value to be a reference to a resource
1583 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 perm.info.group = sa.getNonResourceString(
1585 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1586 if (perm.info.group != null) {
1587 perm.info.group = perm.info.group.intern();
1588 }
1589
1590 perm.info.descriptionRes = sa.getResourceId(
1591 com.android.internal.R.styleable.AndroidManifestPermission_description,
1592 0);
1593
1594 perm.info.protectionLevel = sa.getInt(
1595 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1596 PermissionInfo.PROTECTION_NORMAL);
1597
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001598 perm.info.flags = sa.getInt(
1599 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 if (perm.info.protectionLevel == -1) {
1604 outError[0] = "<permission> does not specify protectionLevel";
1605 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1606 return null;
1607 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001608
1609 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1610
1611 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1612 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1613 PermissionInfo.PROTECTION_SIGNATURE) {
1614 outError[0] = "<permission> protectionLevel specifies a flag but is "
1615 + "not based on signature type";
1616 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1617 return null;
1618 }
1619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620
1621 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1622 outError)) {
1623 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1624 return null;
1625 }
1626
1627 owner.permissions.add(perm);
1628
1629 return perm;
1630 }
1631
1632 private Permission parsePermissionTree(Package owner, Resources res,
1633 XmlPullParser parser, AttributeSet attrs, String[] outError)
1634 throws XmlPullParserException, IOException {
1635 Permission perm = new Permission(owner);
1636
1637 TypedArray sa = res.obtainAttributes(attrs,
1638 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1639
1640 if (!parsePackageItemInfo(owner, perm.info, outError,
1641 "<permission-tree>", sa,
1642 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1643 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001644 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1645 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 sa.recycle();
1647 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1648 return null;
1649 }
1650
1651 sa.recycle();
1652
1653 int index = perm.info.name.indexOf('.');
1654 if (index > 0) {
1655 index = perm.info.name.indexOf('.', index+1);
1656 }
1657 if (index < 0) {
1658 outError[0] = "<permission-tree> name has less than three segments: "
1659 + perm.info.name;
1660 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1661 return null;
1662 }
1663
1664 perm.info.descriptionRes = 0;
1665 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1666 perm.tree = true;
1667
1668 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1669 outError)) {
1670 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1671 return null;
1672 }
1673
1674 owner.permissions.add(perm);
1675
1676 return perm;
1677 }
1678
1679 private Instrumentation parseInstrumentation(Package owner, Resources res,
1680 XmlPullParser parser, AttributeSet attrs, String[] outError)
1681 throws XmlPullParserException, IOException {
1682 TypedArray sa = res.obtainAttributes(attrs,
1683 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1684
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001685 if (mParseInstrumentationArgs == null) {
1686 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1687 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1688 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001689 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1690 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001691 mParseInstrumentationArgs.tag = "<instrumentation>";
1692 }
1693
1694 mParseInstrumentationArgs.sa = sa;
1695
1696 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1697 new InstrumentationInfo());
1698 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 sa.recycle();
1700 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1701 return null;
1702 }
1703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001705 // Note: don't allow this value to be a reference to a resource
1706 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 str = sa.getNonResourceString(
1708 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1709 a.info.targetPackage = str != null ? str.intern() : null;
1710
1711 a.info.handleProfiling = sa.getBoolean(
1712 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1713 false);
1714
1715 a.info.functionalTest = sa.getBoolean(
1716 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1717 false);
1718
1719 sa.recycle();
1720
1721 if (a.info.targetPackage == null) {
1722 outError[0] = "<instrumentation> does not specify targetPackage";
1723 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1724 return null;
1725 }
1726
1727 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1728 outError)) {
1729 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1730 return null;
1731 }
1732
1733 owner.instrumentation.add(a);
1734
1735 return a;
1736 }
1737
1738 private boolean parseApplication(Package owner, Resources res,
1739 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1740 throws XmlPullParserException, IOException {
1741 final ApplicationInfo ai = owner.applicationInfo;
1742 final String pkgName = owner.applicationInfo.packageName;
1743
1744 TypedArray sa = res.obtainAttributes(attrs,
1745 com.android.internal.R.styleable.AndroidManifestApplication);
1746
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001747 String name = sa.getNonConfigurationString(
1748 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 if (name != null) {
1750 ai.className = buildClassName(pkgName, name, outError);
1751 if (ai.className == null) {
1752 sa.recycle();
1753 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1754 return false;
1755 }
1756 }
1757
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001758 String manageSpaceActivity = sa.getNonConfigurationString(
1759 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 if (manageSpaceActivity != null) {
1761 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1762 outError);
1763 }
1764
Christopher Tate181fafa2009-05-14 11:12:14 -07001765 boolean allowBackup = sa.getBoolean(
1766 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1767 if (allowBackup) {
1768 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001769
Christopher Tate3de55bc2010-03-12 17:28:08 -08001770 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1771 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001772 String backupAgent = sa.getNonConfigurationString(
1773 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001774 if (backupAgent != null) {
1775 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001776 if (DEBUG_BACKUP) {
1777 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001778 + " from " + pkgName + "+" + backupAgent);
1779 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001780
1781 if (sa.getBoolean(
1782 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1783 true)) {
1784 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1785 }
1786 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001787 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1788 false)) {
1789 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1790 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001791 }
1792 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 TypedValue v = sa.peekValue(
1795 com.android.internal.R.styleable.AndroidManifestApplication_label);
1796 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1797 ai.nonLocalizedLabel = v.coerceToString();
1798 }
1799
1800 ai.icon = sa.getResourceId(
1801 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001802 ai.logo = sa.getResourceId(
1803 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001805 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 ai.descriptionRes = sa.getResourceId(
1807 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1808
1809 if ((flags&PARSE_IS_SYSTEM) != 0) {
1810 if (sa.getBoolean(
1811 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1812 false)) {
1813 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1814 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001815 if (sa.getBoolean(
1816 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1817 false)) {
1818 owner.mRequiredForAllUsers = true;
1819 }
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001820 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07001821 .AndroidManifestApplication_restrictedAccountType);
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001822 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1823 owner.mRestrictedAccountType = restrictedAccountType;
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07001824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 }
1826
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001827 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1828 .AndroidManifestApplication_requiredAccountType);
1829 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1830 owner.mRequiredAccountType = requiredAccountType;
1831 }
1832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 if (sa.getBoolean(
1834 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1835 false)) {
1836 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1837 }
1838
1839 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001840 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001841 false)) {
1842 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1843 }
1844
Romain Guy529b60a2010-08-03 18:05:47 -07001845 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001846 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001847 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001848
1849 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1851 true)) {
1852 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1853 }
1854
1855 if (sa.getBoolean(
1856 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1857 false)) {
1858 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1859 }
1860
1861 if (sa.getBoolean(
1862 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1863 true)) {
1864 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1865 }
1866
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001867 if (sa.getBoolean(
1868 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001869 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001870 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1871 }
1872
Jason parksa3cdaa52011-01-13 14:15:43 -06001873 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001874 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001875 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001876 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001877 }
1878
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001879 if (sa.getBoolean(
1880 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1881 false /* default is no RTL support*/)) {
1882 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1883 }
1884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001886 str = sa.getNonConfigurationString(
1887 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1889
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001890 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1891 str = sa.getNonConfigurationString(
1892 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1893 } else {
1894 // Some older apps have been seen to use a resource reference
1895 // here that on older builds was ignored (with a warning). We
1896 // need to continue to do this for them so they don't break.
1897 str = sa.getNonResourceString(
1898 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1901 str, outError);
1902
1903 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001904 CharSequence pname;
1905 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1906 pname = sa.getNonConfigurationString(
1907 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1908 } else {
1909 // Some older apps have been seen to use a resource reference
1910 // here that on older builds was ignored (with a warning). We
1911 // need to continue to do this for them so they don't break.
1912 pname = sa.getNonResourceString(
1913 com.android.internal.R.styleable.AndroidManifestApplication_process);
1914 }
1915 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 flags, mSeparateProcesses, outError);
1917
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001918 ai.enabled = sa.getBoolean(
1919 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001920
Dianne Hackborn02486b12010-08-26 14:18:37 -07001921 if (false) {
1922 if (sa.getBoolean(
1923 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1924 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001925 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001926
1927 // A heavy-weight application can not be in a custom process.
1928 // We can do direct compare because we intern all strings.
1929 if (ai.processName != null && ai.processName != ai.packageName) {
1930 outError[0] = "cantSaveState applications can not use custom processes";
1931 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001932 }
1933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 }
1935
Adam Powell269248d2011-08-02 10:26:54 -07001936 ai.uiOptions = sa.getInt(
1937 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 sa.recycle();
1940
1941 if (outError[0] != null) {
1942 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1943 return false;
1944 }
1945
1946 final int innerDepth = parser.getDepth();
1947
1948 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001949 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1950 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1951 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 continue;
1953 }
1954
1955 String tagName = parser.getName();
1956 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001957 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1958 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 if (a == null) {
1960 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1961 return false;
1962 }
1963
1964 owner.activities.add(a);
1965
1966 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001967 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 if (a == null) {
1969 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1970 return false;
1971 }
1972
1973 owner.receivers.add(a);
1974
1975 } else if (tagName.equals("service")) {
1976 Service s = parseService(owner, res, parser, attrs, flags, outError);
1977 if (s == null) {
1978 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1979 return false;
1980 }
1981
1982 owner.services.add(s);
1983
1984 } else if (tagName.equals("provider")) {
1985 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1986 if (p == null) {
1987 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1988 return false;
1989 }
1990
1991 owner.providers.add(p);
1992
1993 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001994 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 if (a == null) {
1996 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1997 return false;
1998 }
1999
2000 owner.activities.add(a);
2001
2002 } else if (parser.getName().equals("meta-data")) {
2003 // note: application meta-data is stored off to the side, so it can
2004 // remain null in the primary copy (we like to avoid extra copies because
2005 // it can be large)
2006 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2007 outError)) == null) {
2008 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2009 return false;
2010 }
2011
Dianne Hackbornc895be72013-03-11 17:48:43 -07002012 } else if (tagName.equals("library")) {
2013 sa = res.obtainAttributes(attrs,
2014 com.android.internal.R.styleable.AndroidManifestLibrary);
2015
2016 // Note: don't allow this value to be a reference to a resource
2017 // that may change.
2018 String lname = sa.getNonResourceString(
2019 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2020
2021 sa.recycle();
2022
2023 if (lname != null) {
2024 if (owner.libraryNames == null) {
2025 owner.libraryNames = new ArrayList<String>();
2026 }
2027 if (!owner.libraryNames.contains(lname)) {
2028 owner.libraryNames.add(lname.intern());
2029 }
2030 }
2031
2032 XmlUtils.skipCurrentTag(parser);
2033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 } else if (tagName.equals("uses-library")) {
2035 sa = res.obtainAttributes(attrs,
2036 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2037
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002038 // Note: don't allow this value to be a reference to a resource
2039 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 String lname = sa.getNonResourceString(
2041 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002042 boolean req = sa.getBoolean(
2043 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2044 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045
2046 sa.recycle();
2047
Dianne Hackborn49237342009-08-27 20:08:01 -07002048 if (lname != null) {
2049 if (req) {
2050 if (owner.usesLibraries == null) {
2051 owner.usesLibraries = new ArrayList<String>();
2052 }
2053 if (!owner.usesLibraries.contains(lname)) {
2054 owner.usesLibraries.add(lname.intern());
2055 }
2056 } else {
2057 if (owner.usesOptionalLibraries == null) {
2058 owner.usesOptionalLibraries = new ArrayList<String>();
2059 }
2060 if (!owner.usesOptionalLibraries.contains(lname)) {
2061 owner.usesOptionalLibraries.add(lname.intern());
2062 }
2063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002064 }
2065
2066 XmlUtils.skipCurrentTag(parser);
2067
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002068 } else if (tagName.equals("uses-package")) {
2069 // Dependencies for app installers; we don't currently try to
2070 // enforce this.
2071 XmlUtils.skipCurrentTag(parser);
2072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 } else {
2074 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002075 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002076 + " at " + mArchiveSourcePath + " "
2077 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 XmlUtils.skipCurrentTag(parser);
2079 continue;
2080 } else {
2081 outError[0] = "Bad element under <application>: " + tagName;
2082 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2083 return false;
2084 }
2085 }
2086 }
2087
2088 return true;
2089 }
2090
2091 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2092 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002093 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002094 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 if (name == null) {
2096 outError[0] = tag + " does not specify android:name";
2097 return false;
2098 }
2099
2100 outInfo.name
2101 = buildClassName(owner.applicationInfo.packageName, name, outError);
2102 if (outInfo.name == null) {
2103 return false;
2104 }
2105
2106 int iconVal = sa.getResourceId(iconRes, 0);
2107 if (iconVal != 0) {
2108 outInfo.icon = iconVal;
2109 outInfo.nonLocalizedLabel = null;
2110 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002111
2112 int logoVal = sa.getResourceId(logoRes, 0);
2113 if (logoVal != 0) {
2114 outInfo.logo = logoVal;
2115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002116
2117 TypedValue v = sa.peekValue(labelRes);
2118 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2119 outInfo.nonLocalizedLabel = v.coerceToString();
2120 }
2121
2122 outInfo.packageName = owner.packageName;
2123
2124 return true;
2125 }
2126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 private Activity parseActivity(Package owner, Resources res,
2128 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002129 boolean receiver, boolean hardwareAccelerated)
2130 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 TypedArray sa = res.obtainAttributes(attrs,
2132 com.android.internal.R.styleable.AndroidManifestActivity);
2133
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002134 if (mParseActivityArgs == null) {
2135 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2136 com.android.internal.R.styleable.AndroidManifestActivity_name,
2137 com.android.internal.R.styleable.AndroidManifestActivity_label,
2138 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002139 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002140 mSeparateProcesses,
2141 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002142 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002143 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2144 }
2145
2146 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2147 mParseActivityArgs.sa = sa;
2148 mParseActivityArgs.flags = flags;
2149
2150 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2151 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 sa.recycle();
2153 return null;
2154 }
2155
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002156 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2158 if (setExported) {
2159 a.info.exported = sa.getBoolean(
2160 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2161 }
2162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002163 a.info.theme = sa.getResourceId(
2164 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2165
Adam Powell269248d2011-08-02 10:26:54 -07002166 a.info.uiOptions = sa.getInt(
2167 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2168 a.info.applicationInfo.uiOptions);
2169
Adam Powelldd8fab22012-03-22 17:47:27 -07002170 String parentName = sa.getNonConfigurationString(
2171 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2172 if (parentName != null) {
2173 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2174 if (outError[0] == null) {
2175 a.info.parentActivityName = parentClassName;
2176 } else {
2177 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2178 parentName);
2179 outError[0] = null;
2180 }
2181 }
2182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002184 str = sa.getNonConfigurationString(
2185 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 if (str == null) {
2187 a.info.permission = owner.applicationInfo.permission;
2188 } else {
2189 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2190 }
2191
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002192 str = sa.getNonConfigurationString(
2193 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2195 owner.applicationInfo.taskAffinity, str, outError);
2196
2197 a.info.flags = 0;
2198 if (sa.getBoolean(
2199 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2200 false)) {
2201 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2202 }
2203
2204 if (sa.getBoolean(
2205 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2206 false)) {
2207 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2208 }
2209
2210 if (sa.getBoolean(
2211 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2212 false)) {
2213 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2214 }
2215
2216 if (sa.getBoolean(
2217 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2218 false)) {
2219 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2220 }
2221
2222 if (sa.getBoolean(
2223 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2224 false)) {
2225 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2226 }
2227
2228 if (sa.getBoolean(
2229 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2230 false)) {
2231 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2232 }
2233
2234 if (sa.getBoolean(
2235 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2236 false)) {
2237 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2238 }
2239
2240 if (sa.getBoolean(
2241 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2242 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2243 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2244 }
2245
Dianne Hackbornffa42482009-09-23 22:20:11 -07002246 if (sa.getBoolean(
2247 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2248 false)) {
2249 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2250 }
2251
Daniel Sandler613dde42010-06-21 13:46:39 -04002252 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002253 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2254 false)) {
2255 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2256 }
2257
2258 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002259 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2260 false)) {
2261 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2262 }
Craig Mautner5962b122012-10-05 14:45:52 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002265 if (sa.getBoolean(
2266 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2267 hardwareAccelerated)) {
2268 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2269 }
2270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 a.info.launchMode = sa.getInt(
2272 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2273 ActivityInfo.LAUNCH_MULTIPLE);
2274 a.info.screenOrientation = sa.getInt(
2275 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2276 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2277 a.info.configChanges = sa.getInt(
2278 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2279 0);
2280 a.info.softInputMode = sa.getInt(
2281 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2282 0);
2283 } else {
2284 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2285 a.info.configChanges = 0;
2286 }
2287
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002288 if (receiver) {
2289 if (sa.getBoolean(
2290 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2291 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002292 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002293 if (a.info.exported) {
2294 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2295 + a.className + " at " + mArchiveSourcePath + " "
2296 + parser.getPositionDescription());
2297 a.info.exported = false;
2298 }
2299 setExported = true;
2300 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002301 if (sa.getBoolean(
2302 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2303 false)) {
2304 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2305 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002306 }
2307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 sa.recycle();
2309
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002310 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002311 // A heavy-weight application can not have receives in its main process
2312 // We can do direct compare because we intern all strings.
2313 if (a.info.processName == owner.packageName) {
2314 outError[0] = "Heavy-weight applications can not have receivers in main process";
2315 }
2316 }
2317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 if (outError[0] != null) {
2319 return null;
2320 }
2321
2322 int outerDepth = parser.getDepth();
2323 int type;
2324 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2325 && (type != XmlPullParser.END_TAG
2326 || parser.getDepth() > outerDepth)) {
2327 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2328 continue;
2329 }
2330
2331 if (parser.getName().equals("intent-filter")) {
2332 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2333 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2334 return null;
2335 }
2336 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002337 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002338 + mArchiveSourcePath + " "
2339 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 } else {
2341 a.intents.add(intent);
2342 }
2343 } else if (parser.getName().equals("meta-data")) {
2344 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2345 outError)) == null) {
2346 return null;
2347 }
2348 } else {
2349 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002350 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002352 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002353 + " at " + mArchiveSourcePath + " "
2354 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002356 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002357 + " at " + mArchiveSourcePath + " "
2358 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 }
2360 XmlUtils.skipCurrentTag(parser);
2361 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002363 if (receiver) {
2364 outError[0] = "Bad element under <receiver>: " + parser.getName();
2365 } else {
2366 outError[0] = "Bad element under <activity>: " + parser.getName();
2367 }
2368 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 }
2371 }
2372
2373 if (!setExported) {
2374 a.info.exported = a.intents.size() > 0;
2375 }
2376
2377 return a;
2378 }
2379
2380 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002381 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2382 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 TypedArray sa = res.obtainAttributes(attrs,
2384 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2385
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002386 String targetActivity = sa.getNonConfigurationString(
2387 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 if (targetActivity == null) {
2389 outError[0] = "<activity-alias> does not specify android:targetActivity";
2390 sa.recycle();
2391 return null;
2392 }
2393
2394 targetActivity = buildClassName(owner.applicationInfo.packageName,
2395 targetActivity, outError);
2396 if (targetActivity == null) {
2397 sa.recycle();
2398 return null;
2399 }
2400
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002401 if (mParseActivityAliasArgs == null) {
2402 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2403 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2404 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2405 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002406 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002407 mSeparateProcesses,
2408 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002409 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002410 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2411 mParseActivityAliasArgs.tag = "<activity-alias>";
2412 }
2413
2414 mParseActivityAliasArgs.sa = sa;
2415 mParseActivityAliasArgs.flags = flags;
2416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 Activity target = null;
2418
2419 final int NA = owner.activities.size();
2420 for (int i=0; i<NA; i++) {
2421 Activity t = owner.activities.get(i);
2422 if (targetActivity.equals(t.info.name)) {
2423 target = t;
2424 break;
2425 }
2426 }
2427
2428 if (target == null) {
2429 outError[0] = "<activity-alias> target activity " + targetActivity
2430 + " not found in manifest";
2431 sa.recycle();
2432 return null;
2433 }
2434
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002435 ActivityInfo info = new ActivityInfo();
2436 info.targetActivity = targetActivity;
2437 info.configChanges = target.info.configChanges;
2438 info.flags = target.info.flags;
2439 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002440 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002441 info.labelRes = target.info.labelRes;
2442 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2443 info.launchMode = target.info.launchMode;
2444 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002445 if (info.descriptionRes == 0) {
2446 info.descriptionRes = target.info.descriptionRes;
2447 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002448 info.screenOrientation = target.info.screenOrientation;
2449 info.taskAffinity = target.info.taskAffinity;
2450 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002451 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002452 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002453 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002454
2455 Activity a = new Activity(mParseActivityAliasArgs, info);
2456 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 sa.recycle();
2458 return null;
2459 }
2460
2461 final boolean setExported = sa.hasValue(
2462 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2463 if (setExported) {
2464 a.info.exported = sa.getBoolean(
2465 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2466 }
2467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002469 str = sa.getNonConfigurationString(
2470 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 if (str != null) {
2472 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2473 }
2474
Adam Powelldd8fab22012-03-22 17:47:27 -07002475 String parentName = sa.getNonConfigurationString(
2476 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2477 0);
2478 if (parentName != null) {
2479 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2480 if (outError[0] == null) {
2481 a.info.parentActivityName = parentClassName;
2482 } else {
2483 Log.e(TAG, "Activity alias " + a.info.name +
2484 " specified invalid parentActivityName " + parentName);
2485 outError[0] = null;
2486 }
2487 }
2488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 sa.recycle();
2490
2491 if (outError[0] != null) {
2492 return null;
2493 }
2494
2495 int outerDepth = parser.getDepth();
2496 int type;
2497 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2498 && (type != XmlPullParser.END_TAG
2499 || parser.getDepth() > outerDepth)) {
2500 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2501 continue;
2502 }
2503
2504 if (parser.getName().equals("intent-filter")) {
2505 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2506 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2507 return null;
2508 }
2509 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002510 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002511 + mArchiveSourcePath + " "
2512 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 } else {
2514 a.intents.add(intent);
2515 }
2516 } else if (parser.getName().equals("meta-data")) {
2517 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2518 outError)) == null) {
2519 return null;
2520 }
2521 } else {
2522 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002523 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002524 + " at " + mArchiveSourcePath + " "
2525 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 XmlUtils.skipCurrentTag(parser);
2527 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002528 } else {
2529 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2530 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 }
2533 }
2534
2535 if (!setExported) {
2536 a.info.exported = a.intents.size() > 0;
2537 }
2538
2539 return a;
2540 }
2541
2542 private Provider parseProvider(Package owner, Resources res,
2543 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2544 throws XmlPullParserException, IOException {
2545 TypedArray sa = res.obtainAttributes(attrs,
2546 com.android.internal.R.styleable.AndroidManifestProvider);
2547
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002548 if (mParseProviderArgs == null) {
2549 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2550 com.android.internal.R.styleable.AndroidManifestProvider_name,
2551 com.android.internal.R.styleable.AndroidManifestProvider_label,
2552 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002553 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002554 mSeparateProcesses,
2555 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002556 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002557 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2558 mParseProviderArgs.tag = "<provider>";
2559 }
2560
2561 mParseProviderArgs.sa = sa;
2562 mParseProviderArgs.flags = flags;
2563
2564 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2565 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 sa.recycle();
2567 return null;
2568 }
2569
Nick Kralevichf097b162012-07-28 12:43:48 -07002570 boolean providerExportedDefault = false;
2571
2572 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2573 // For compatibility, applications targeting API level 16 or lower
2574 // should have their content providers exported by default, unless they
2575 // specify otherwise.
2576 providerExportedDefault = true;
2577 }
2578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002580 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2581 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002583 String cpname = sa.getNonConfigurationString(
2584 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585
2586 p.info.isSyncable = sa.getBoolean(
2587 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2588 false);
2589
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002590 String permission = sa.getNonConfigurationString(
2591 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2592 String str = sa.getNonConfigurationString(
2593 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 if (str == null) {
2595 str = permission;
2596 }
2597 if (str == null) {
2598 p.info.readPermission = owner.applicationInfo.permission;
2599 } else {
2600 p.info.readPermission =
2601 str.length() > 0 ? str.toString().intern() : null;
2602 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002603 str = sa.getNonConfigurationString(
2604 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 if (str == null) {
2606 str = permission;
2607 }
2608 if (str == null) {
2609 p.info.writePermission = owner.applicationInfo.permission;
2610 } else {
2611 p.info.writePermission =
2612 str.length() > 0 ? str.toString().intern() : null;
2613 }
2614
2615 p.info.grantUriPermissions = sa.getBoolean(
2616 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2617 false);
2618
2619 p.info.multiprocess = sa.getBoolean(
2620 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2621 false);
2622
2623 p.info.initOrder = sa.getInt(
2624 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2625 0);
2626
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002627 p.info.flags = 0;
2628
2629 if (sa.getBoolean(
2630 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2631 false)) {
2632 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2633 if (p.info.exported) {
2634 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2635 + p.className + " at " + mArchiveSourcePath + " "
2636 + parser.getPositionDescription());
2637 p.info.exported = false;
2638 }
2639 }
2640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 sa.recycle();
2642
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002643 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002644 // A heavy-weight application can not have providers in its main process
2645 // We can do direct compare because we intern all strings.
2646 if (p.info.processName == owner.packageName) {
2647 outError[0] = "Heavy-weight applications can not have providers in main process";
2648 return null;
2649 }
2650 }
2651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002653 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 return null;
2655 }
2656 p.info.authority = cpname.intern();
2657
2658 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2659 return null;
2660 }
2661
2662 return p;
2663 }
2664
2665 private boolean parseProviderTags(Resources res,
2666 XmlPullParser parser, AttributeSet attrs,
2667 Provider outInfo, String[] outError)
2668 throws XmlPullParserException, IOException {
2669 int outerDepth = parser.getDepth();
2670 int type;
2671 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2672 && (type != XmlPullParser.END_TAG
2673 || parser.getDepth() > outerDepth)) {
2674 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2675 continue;
2676 }
2677
2678 if (parser.getName().equals("meta-data")) {
2679 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2680 outInfo.metaData, outError)) == null) {
2681 return false;
2682 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002684 } else if (parser.getName().equals("grant-uri-permission")) {
2685 TypedArray sa = res.obtainAttributes(attrs,
2686 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2687
2688 PatternMatcher pa = null;
2689
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002690 String str = sa.getNonConfigurationString(
2691 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 if (str != null) {
2693 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2694 }
2695
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002696 str = sa.getNonConfigurationString(
2697 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 if (str != null) {
2699 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2700 }
2701
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002702 str = sa.getNonConfigurationString(
2703 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 if (str != null) {
2705 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2706 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 sa.recycle();
2709
2710 if (pa != null) {
2711 if (outInfo.info.uriPermissionPatterns == null) {
2712 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2713 outInfo.info.uriPermissionPatterns[0] = pa;
2714 } else {
2715 final int N = outInfo.info.uriPermissionPatterns.length;
2716 PatternMatcher[] newp = new PatternMatcher[N+1];
2717 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2718 newp[N] = pa;
2719 outInfo.info.uriPermissionPatterns = newp;
2720 }
2721 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002722 } else {
2723 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002724 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002725 + parser.getName() + " at " + mArchiveSourcePath + " "
2726 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002727 XmlUtils.skipCurrentTag(parser);
2728 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002729 } else {
2730 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2731 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002732 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002733 }
2734 XmlUtils.skipCurrentTag(parser);
2735
2736 } else if (parser.getName().equals("path-permission")) {
2737 TypedArray sa = res.obtainAttributes(attrs,
2738 com.android.internal.R.styleable.AndroidManifestPathPermission);
2739
2740 PathPermission pa = null;
2741
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002742 String permission = sa.getNonConfigurationString(
2743 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2744 String readPermission = sa.getNonConfigurationString(
2745 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002746 if (readPermission == null) {
2747 readPermission = permission;
2748 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002749 String writePermission = sa.getNonConfigurationString(
2750 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002751 if (writePermission == null) {
2752 writePermission = permission;
2753 }
2754
2755 boolean havePerm = false;
2756 if (readPermission != null) {
2757 readPermission = readPermission.intern();
2758 havePerm = true;
2759 }
2760 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002761 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002762 havePerm = true;
2763 }
2764
2765 if (!havePerm) {
2766 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002767 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002768 + parser.getName() + " at " + mArchiveSourcePath + " "
2769 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002770 XmlUtils.skipCurrentTag(parser);
2771 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002772 } else {
2773 outError[0] = "No readPermission or writePermssion for <path-permission>";
2774 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002775 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002776 }
2777
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002778 String path = sa.getNonConfigurationString(
2779 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002780 if (path != null) {
2781 pa = new PathPermission(path,
2782 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2783 }
2784
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002785 path = sa.getNonConfigurationString(
2786 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002787 if (path != null) {
2788 pa = new PathPermission(path,
2789 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2790 }
2791
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002792 path = sa.getNonConfigurationString(
2793 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002794 if (path != null) {
2795 pa = new PathPermission(path,
2796 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2797 }
2798
2799 sa.recycle();
2800
2801 if (pa != null) {
2802 if (outInfo.info.pathPermissions == null) {
2803 outInfo.info.pathPermissions = new PathPermission[1];
2804 outInfo.info.pathPermissions[0] = pa;
2805 } else {
2806 final int N = outInfo.info.pathPermissions.length;
2807 PathPermission[] newp = new PathPermission[N+1];
2808 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2809 newp[N] = pa;
2810 outInfo.info.pathPermissions = newp;
2811 }
2812 } else {
2813 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002814 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002815 + parser.getName() + " at " + mArchiveSourcePath + " "
2816 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002817 XmlUtils.skipCurrentTag(parser);
2818 continue;
2819 }
2820 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2821 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 }
2823 XmlUtils.skipCurrentTag(parser);
2824
2825 } else {
2826 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002827 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002828 + parser.getName() + " at " + mArchiveSourcePath + " "
2829 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 XmlUtils.skipCurrentTag(parser);
2831 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002832 } else {
2833 outError[0] = "Bad element under <provider>: " + parser.getName();
2834 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 }
2837 }
2838 return true;
2839 }
2840
2841 private Service parseService(Package owner, Resources res,
2842 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2843 throws XmlPullParserException, IOException {
2844 TypedArray sa = res.obtainAttributes(attrs,
2845 com.android.internal.R.styleable.AndroidManifestService);
2846
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002847 if (mParseServiceArgs == null) {
2848 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2849 com.android.internal.R.styleable.AndroidManifestService_name,
2850 com.android.internal.R.styleable.AndroidManifestService_label,
2851 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002852 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002853 mSeparateProcesses,
2854 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002855 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002856 com.android.internal.R.styleable.AndroidManifestService_enabled);
2857 mParseServiceArgs.tag = "<service>";
2858 }
2859
2860 mParseServiceArgs.sa = sa;
2861 mParseServiceArgs.flags = flags;
2862
2863 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2864 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 sa.recycle();
2866 return null;
2867 }
2868
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002869 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 com.android.internal.R.styleable.AndroidManifestService_exported);
2871 if (setExported) {
2872 s.info.exported = sa.getBoolean(
2873 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2874 }
2875
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002876 String str = sa.getNonConfigurationString(
2877 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 if (str == null) {
2879 s.info.permission = owner.applicationInfo.permission;
2880 } else {
2881 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2882 }
2883
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002884 s.info.flags = 0;
2885 if (sa.getBoolean(
2886 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2887 false)) {
2888 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2889 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002890 if (sa.getBoolean(
2891 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2892 false)) {
2893 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2894 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002895 if (sa.getBoolean(
2896 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2897 false)) {
2898 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2899 if (s.info.exported) {
2900 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2901 + s.className + " at " + mArchiveSourcePath + " "
2902 + parser.getPositionDescription());
2903 s.info.exported = false;
2904 }
2905 setExported = true;
2906 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 sa.recycle();
2909
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002910 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002911 // A heavy-weight application can not have services in its main process
2912 // We can do direct compare because we intern all strings.
2913 if (s.info.processName == owner.packageName) {
2914 outError[0] = "Heavy-weight applications can not have services in main process";
2915 return null;
2916 }
2917 }
2918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 int outerDepth = parser.getDepth();
2920 int type;
2921 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2922 && (type != XmlPullParser.END_TAG
2923 || parser.getDepth() > outerDepth)) {
2924 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2925 continue;
2926 }
2927
2928 if (parser.getName().equals("intent-filter")) {
2929 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2930 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2931 return null;
2932 }
2933
2934 s.intents.add(intent);
2935 } else if (parser.getName().equals("meta-data")) {
2936 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2937 outError)) == null) {
2938 return null;
2939 }
2940 } else {
2941 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002942 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002943 + parser.getName() + " at " + mArchiveSourcePath + " "
2944 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 XmlUtils.skipCurrentTag(parser);
2946 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002947 } else {
2948 outError[0] = "Bad element under <service>: " + parser.getName();
2949 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 }
2952 }
2953
2954 if (!setExported) {
2955 s.info.exported = s.intents.size() > 0;
2956 }
2957
2958 return s;
2959 }
2960
2961 private boolean parseAllMetaData(Resources res,
2962 XmlPullParser parser, AttributeSet attrs, String tag,
2963 Component outInfo, String[] outError)
2964 throws XmlPullParserException, IOException {
2965 int outerDepth = parser.getDepth();
2966 int type;
2967 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2968 && (type != XmlPullParser.END_TAG
2969 || parser.getDepth() > outerDepth)) {
2970 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2971 continue;
2972 }
2973
2974 if (parser.getName().equals("meta-data")) {
2975 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2976 outInfo.metaData, outError)) == null) {
2977 return false;
2978 }
2979 } else {
2980 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002981 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002982 + parser.getName() + " at " + mArchiveSourcePath + " "
2983 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 XmlUtils.skipCurrentTag(parser);
2985 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002986 } else {
2987 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2988 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 }
2991 }
2992 return true;
2993 }
2994
2995 private Bundle parseMetaData(Resources res,
2996 XmlPullParser parser, AttributeSet attrs,
2997 Bundle data, String[] outError)
2998 throws XmlPullParserException, IOException {
2999
3000 TypedArray sa = res.obtainAttributes(attrs,
3001 com.android.internal.R.styleable.AndroidManifestMetaData);
3002
3003 if (data == null) {
3004 data = new Bundle();
3005 }
3006
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003007 String name = sa.getNonConfigurationString(
3008 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 if (name == null) {
3010 outError[0] = "<meta-data> requires an android:name attribute";
3011 sa.recycle();
3012 return null;
3013 }
3014
Dianne Hackborn854060a2009-07-09 18:14:31 -07003015 name = name.intern();
3016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 TypedValue v = sa.peekValue(
3018 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3019 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003020 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 data.putInt(name, v.resourceId);
3022 } else {
3023 v = sa.peekValue(
3024 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003025 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 if (v != null) {
3027 if (v.type == TypedValue.TYPE_STRING) {
3028 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003029 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3031 data.putBoolean(name, v.data != 0);
3032 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3033 && v.type <= TypedValue.TYPE_LAST_INT) {
3034 data.putInt(name, v.data);
3035 } else if (v.type == TypedValue.TYPE_FLOAT) {
3036 data.putFloat(name, v.getFloat());
3037 } else {
3038 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003039 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003040 + parser.getName() + " at " + mArchiveSourcePath + " "
3041 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 } else {
3043 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3044 data = null;
3045 }
3046 }
3047 } else {
3048 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3049 data = null;
3050 }
3051 }
3052
3053 sa.recycle();
3054
3055 XmlUtils.skipCurrentTag(parser);
3056
3057 return data;
3058 }
3059
Kenny Root05ca4c92011-09-15 10:36:25 -07003060 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3061 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3062 IOException {
3063 final TypedArray sa = res.obtainAttributes(attrs,
3064 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3065
3066 final String packageName = sa.getNonResourceString(
3067 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3068
3069 final String encodedPublicKey = sa.getNonResourceString(
3070 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3071
3072 sa.recycle();
3073
3074 if (packageName == null || packageName.length() == 0) {
3075 Slog.i(TAG, "verifier package name was null; skipping");
3076 return null;
3077 } else if (encodedPublicKey == null) {
3078 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3079 }
3080
3081 EncodedKeySpec keySpec;
3082 try {
3083 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3084 keySpec = new X509EncodedKeySpec(encoded);
3085 } catch (IllegalArgumentException e) {
3086 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
3087 return null;
3088 }
3089
3090 /* First try the key as an RSA key. */
3091 try {
3092 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
3093 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3094 return new VerifierInfo(packageName, publicKey);
3095 } catch (NoSuchAlgorithmException e) {
3096 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3097 return null;
3098 } catch (InvalidKeySpecException e) {
3099 // Not a RSA public key.
3100 }
3101
3102 /* Now try it as a DSA key. */
3103 try {
3104 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3105 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3106 return new VerifierInfo(packageName, publicKey);
3107 } catch (NoSuchAlgorithmException e) {
3108 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3109 return null;
3110 } catch (InvalidKeySpecException e) {
3111 // Not a DSA public key.
3112 }
3113
3114 return null;
3115 }
3116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 private static final String ANDROID_RESOURCES
3118 = "http://schemas.android.com/apk/res/android";
3119
3120 private boolean parseIntent(Resources res,
3121 XmlPullParser parser, AttributeSet attrs, int flags,
3122 IntentInfo outInfo, String[] outError, boolean isActivity)
3123 throws XmlPullParserException, IOException {
3124
3125 TypedArray sa = res.obtainAttributes(attrs,
3126 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3127
3128 int priority = sa.getInt(
3129 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003132 TypedValue v = sa.peekValue(
3133 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3134 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3135 outInfo.nonLocalizedLabel = v.coerceToString();
3136 }
3137
3138 outInfo.icon = sa.getResourceId(
3139 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003140
3141 outInfo.logo = sa.getResourceId(
3142 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143
3144 sa.recycle();
3145
3146 int outerDepth = parser.getDepth();
3147 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003148 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3149 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3150 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 continue;
3152 }
3153
3154 String nodeName = parser.getName();
3155 if (nodeName.equals("action")) {
3156 String value = attrs.getAttributeValue(
3157 ANDROID_RESOURCES, "name");
3158 if (value == null || value == "") {
3159 outError[0] = "No value supplied for <android:name>";
3160 return false;
3161 }
3162 XmlUtils.skipCurrentTag(parser);
3163
3164 outInfo.addAction(value);
3165 } else if (nodeName.equals("category")) {
3166 String value = attrs.getAttributeValue(
3167 ANDROID_RESOURCES, "name");
3168 if (value == null || value == "") {
3169 outError[0] = "No value supplied for <android:name>";
3170 return false;
3171 }
3172 XmlUtils.skipCurrentTag(parser);
3173
3174 outInfo.addCategory(value);
3175
3176 } else if (nodeName.equals("data")) {
3177 sa = res.obtainAttributes(attrs,
3178 com.android.internal.R.styleable.AndroidManifestData);
3179
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003180 String str = sa.getNonConfigurationString(
3181 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 if (str != null) {
3183 try {
3184 outInfo.addDataType(str);
3185 } catch (IntentFilter.MalformedMimeTypeException e) {
3186 outError[0] = e.toString();
3187 sa.recycle();
3188 return false;
3189 }
3190 }
3191
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003192 str = sa.getNonConfigurationString(
3193 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 if (str != null) {
3195 outInfo.addDataScheme(str);
3196 }
3197
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003198 String host = sa.getNonConfigurationString(
3199 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3200 String port = sa.getNonConfigurationString(
3201 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 if (host != null) {
3203 outInfo.addDataAuthority(host, port);
3204 }
3205
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003206 str = sa.getNonConfigurationString(
3207 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 if (str != null) {
3209 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3210 }
3211
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003212 str = sa.getNonConfigurationString(
3213 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 if (str != null) {
3215 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3216 }
3217
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003218 str = sa.getNonConfigurationString(
3219 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 if (str != null) {
3221 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3222 }
3223
3224 sa.recycle();
3225 XmlUtils.skipCurrentTag(parser);
3226 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003227 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003228 + parser.getName() + " at " + mArchiveSourcePath + " "
3229 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 XmlUtils.skipCurrentTag(parser);
3231 } else {
3232 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3233 return false;
3234 }
3235 }
3236
3237 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003238
3239 if (DEBUG_PARSER) {
3240 final StringBuilder cats = new StringBuilder("Intent d=");
3241 cats.append(outInfo.hasDefault);
3242 cats.append(", cat=");
3243
3244 final Iterator<String> it = outInfo.categoriesIterator();
3245 if (it != null) {
3246 while (it.hasNext()) {
3247 cats.append(' ');
3248 cats.append(it.next());
3249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003251 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
3253
3254 return true;
3255 }
3256
3257 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003258
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003259 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260
3261 // For now we only support one application per package.
3262 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3263
3264 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3265 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3266 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3267 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3268 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3269 public final ArrayList<Service> services = new ArrayList<Service>(0);
3270 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3271
3272 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003273 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274
Dianne Hackborn854060a2009-07-09 18:14:31 -07003275 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003276
3277 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003278 public ArrayList<String> usesLibraries = null;
3279 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 public String[] usesLibraryFiles = null;
3281
Dianne Hackbornc1552392010-03-03 16:19:01 -08003282 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003283 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003284 public ArrayList<String> mAdoptPermissions = null;
3285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 // We store the application meta-data independently to avoid multiple unwanted references
3287 public Bundle mAppMetaData = null;
3288
3289 // If this is a 3rd party app, this is the path of the zip file.
3290 public String mPath;
3291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 // The version code declared for this package.
3293 public int mVersionCode;
3294
3295 // The version name declared for this package.
3296 public String mVersionName;
3297
3298 // The shared user id that this package wants to use.
3299 public String mSharedUserId;
3300
3301 // The shared user label that this package wants to use.
3302 public int mSharedUserLabel;
3303
3304 // Signatures that were read from the package.
3305 public Signature mSignatures[];
3306
3307 // For use by package manager service for quick lookup of
3308 // preferred up order.
3309 public int mPreferredOrder = 0;
3310
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003311 // For use by the package manager to keep track of the path to the
3312 // file an app came from.
3313 public String mScanPath;
3314
3315 // For use by package manager to keep track of where it has done dexopt.
3316 public boolean mDidDexOpt;
3317
Amith Yamasani13593602012-03-22 16:16:17 -07003318 // // User set enabled state.
3319 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3320 //
3321 // // Whether the package has been stopped.
3322 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 // Additional data supplied by callers.
3325 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003326
3327 // Whether an operation is currently pending on this package
3328 public boolean mOperationPending;
3329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 /*
3331 * Applications hardware preferences
3332 */
3333 public final ArrayList<ConfigurationInfo> configPreferences =
3334 new ArrayList<ConfigurationInfo>();
3335
Dianne Hackborn49237342009-08-27 20:08:01 -07003336 /*
3337 * Applications requested features
3338 */
3339 public ArrayList<FeatureInfo> reqFeatures = null;
3340
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003341 public int installLocation;
3342
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003343 /* An app that's required for all users and cannot be uninstalled for a user */
3344 public boolean mRequiredForAllUsers;
3345
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003346 /* The restricted account authenticator type that is used by this application */
3347 public String mRestrictedAccountType;
3348
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003349 /* The required account type without which this application will not function */
3350 public String mRequiredAccountType;
3351
Kenny Rootbcc954d2011-08-08 16:19:08 -07003352 /**
3353 * Digest suitable for comparing whether this package's manifest is the
3354 * same as another.
3355 */
3356 public ManifestDigest manifestDigest;
3357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 public Package(String _name) {
3359 packageName = _name;
3360 applicationInfo.packageName = _name;
3361 applicationInfo.uid = -1;
3362 }
3363
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003364 public void setPackageName(String newName) {
3365 packageName = newName;
3366 applicationInfo.packageName = newName;
3367 for (int i=permissions.size()-1; i>=0; i--) {
3368 permissions.get(i).setPackageName(newName);
3369 }
3370 for (int i=permissionGroups.size()-1; i>=0; i--) {
3371 permissionGroups.get(i).setPackageName(newName);
3372 }
3373 for (int i=activities.size()-1; i>=0; i--) {
3374 activities.get(i).setPackageName(newName);
3375 }
3376 for (int i=receivers.size()-1; i>=0; i--) {
3377 receivers.get(i).setPackageName(newName);
3378 }
3379 for (int i=providers.size()-1; i>=0; i--) {
3380 providers.get(i).setPackageName(newName);
3381 }
3382 for (int i=services.size()-1; i>=0; i--) {
3383 services.get(i).setPackageName(newName);
3384 }
3385 for (int i=instrumentation.size()-1; i>=0; i--) {
3386 instrumentation.get(i).setPackageName(newName);
3387 }
3388 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003389
3390 public boolean hasComponentClassName(String name) {
3391 for (int i=activities.size()-1; i>=0; i--) {
3392 if (name.equals(activities.get(i).className)) {
3393 return true;
3394 }
3395 }
3396 for (int i=receivers.size()-1; i>=0; i--) {
3397 if (name.equals(receivers.get(i).className)) {
3398 return true;
3399 }
3400 }
3401 for (int i=providers.size()-1; i>=0; i--) {
3402 if (name.equals(providers.get(i).className)) {
3403 return true;
3404 }
3405 }
3406 for (int i=services.size()-1; i>=0; i--) {
3407 if (name.equals(services.get(i).className)) {
3408 return true;
3409 }
3410 }
3411 for (int i=instrumentation.size()-1; i>=0; i--) {
3412 if (name.equals(instrumentation.get(i).className)) {
3413 return true;
3414 }
3415 }
3416 return false;
3417 }
3418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 public String toString() {
3420 return "Package{"
3421 + Integer.toHexString(System.identityHashCode(this))
3422 + " " + packageName + "}";
3423 }
3424 }
3425
3426 public static class Component<II extends IntentInfo> {
3427 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003428 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003429 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 public Bundle metaData;
3431
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003432 ComponentName componentName;
3433 String componentShortName;
3434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 public Component(Package _owner) {
3436 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003437 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003438 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003439 }
3440
3441 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3442 owner = args.owner;
3443 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003444 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003445 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003446 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003447 args.outError[0] = args.tag + " does not specify android:name";
3448 return;
3449 }
3450
3451 outInfo.name
3452 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3453 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003454 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003455 args.outError[0] = args.tag + " does not have valid android:name";
3456 return;
3457 }
3458
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003459 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003460
3461 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3462 if (iconVal != 0) {
3463 outInfo.icon = iconVal;
3464 outInfo.nonLocalizedLabel = null;
3465 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003466
3467 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3468 if (logoVal != 0) {
3469 outInfo.logo = logoVal;
3470 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003471
3472 TypedValue v = args.sa.peekValue(args.labelRes);
3473 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3474 outInfo.nonLocalizedLabel = v.coerceToString();
3475 }
3476
3477 outInfo.packageName = owner.packageName;
3478 }
3479
3480 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3481 this(args, (PackageItemInfo)outInfo);
3482 if (args.outError[0] != null) {
3483 return;
3484 }
3485
3486 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003487 CharSequence pname;
3488 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3489 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3490 } else {
3491 // Some older apps have been seen to use a resource reference
3492 // here that on older builds was ignored (with a warning). We
3493 // need to continue to do this for them so they don't break.
3494 pname = args.sa.getNonResourceString(args.processRes);
3495 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003496 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003497 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003498 args.flags, args.sepProcesses, args.outError);
3499 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003500
3501 if (args.descriptionRes != 0) {
3502 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3503 }
3504
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003505 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 }
3507
3508 public Component(Component<II> clone) {
3509 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003510 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003511 className = clone.className;
3512 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003513 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003514 }
3515
3516 public ComponentName getComponentName() {
3517 if (componentName != null) {
3518 return componentName;
3519 }
3520 if (className != null) {
3521 componentName = new ComponentName(owner.applicationInfo.packageName,
3522 className);
3523 }
3524 return componentName;
3525 }
3526
3527 public String getComponentShortName() {
3528 if (componentShortName != null) {
3529 return componentShortName;
3530 }
3531 ComponentName component = getComponentName();
3532 if (component != null) {
3533 componentShortName = component.flattenToShortString();
3534 }
3535 return componentShortName;
3536 }
3537
3538 public void setPackageName(String packageName) {
3539 componentName = null;
3540 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 }
3542 }
3543
3544 public final static class Permission extends Component<IntentInfo> {
3545 public final PermissionInfo info;
3546 public boolean tree;
3547 public PermissionGroup group;
3548
3549 public Permission(Package _owner) {
3550 super(_owner);
3551 info = new PermissionInfo();
3552 }
3553
3554 public Permission(Package _owner, PermissionInfo _info) {
3555 super(_owner);
3556 info = _info;
3557 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003558
3559 public void setPackageName(String packageName) {
3560 super.setPackageName(packageName);
3561 info.packageName = packageName;
3562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563
3564 public String toString() {
3565 return "Permission{"
3566 + Integer.toHexString(System.identityHashCode(this))
3567 + " " + info.name + "}";
3568 }
3569 }
3570
3571 public final static class PermissionGroup extends Component<IntentInfo> {
3572 public final PermissionGroupInfo info;
3573
3574 public PermissionGroup(Package _owner) {
3575 super(_owner);
3576 info = new PermissionGroupInfo();
3577 }
3578
3579 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3580 super(_owner);
3581 info = _info;
3582 }
3583
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003584 public void setPackageName(String packageName) {
3585 super.setPackageName(packageName);
3586 info.packageName = packageName;
3587 }
3588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 public String toString() {
3590 return "PermissionGroup{"
3591 + Integer.toHexString(System.identityHashCode(this))
3592 + " " + info.name + "}";
3593 }
3594 }
3595
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003596 private static boolean copyNeeded(int flags, Package p,
3597 PackageUserState state, Bundle metaData, int userId) {
3598 if (userId != 0) {
3599 // We always need to copy for other users, since we need
3600 // to fix up the uid.
3601 return true;
3602 }
3603 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3604 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003605 if (p.applicationInfo.enabled != enabled) {
3606 return true;
3607 }
3608 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003609 if (!state.installed) {
3610 return true;
3611 }
3612 if (state.stopped) {
3613 return true;
3614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 if ((flags & PackageManager.GET_META_DATA) != 0
3616 && (metaData != null || p.mAppMetaData != null)) {
3617 return true;
3618 }
3619 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3620 && p.usesLibraryFiles != null) {
3621 return true;
3622 }
3623 return false;
3624 }
3625
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003626 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3627 PackageUserState state) {
3628 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003629 }
3630
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003631 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3632 PackageUserState state) {
3633 // CompatibilityMode is global state.
3634 if (!sCompatibilityModeEnabled) {
3635 ai.disableCompatibilityMode();
3636 }
3637 if (state.installed) {
3638 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3639 } else {
3640 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3641 }
3642 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3643 ai.enabled = true;
3644 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3645 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3646 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3647 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3648 ai.enabled = false;
3649 }
3650 ai.enabledSetting = state.enabled;
3651 }
3652
Amith Yamasani13593602012-03-22 16:16:17 -07003653 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003654 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003656 if (!checkUseInstalled(flags, state)) {
3657 return null;
3658 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003659 if (!copyNeeded(flags, p, state, null, userId)
3660 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3661 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3662 // In this case it is safe to directly modify the internal ApplicationInfo state:
3663 // - CompatibilityMode is global state, so will be the same for every call.
3664 // - We only come in to here if the app should reported as installed; this is the
3665 // default state, and we will do a copy otherwise.
3666 // - The enable state will always be reported the same for the application across
3667 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3668 // be doing a copy.
3669 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 return p.applicationInfo;
3671 }
3672
3673 // Make shallow copy so we can store the metadata/libraries safely
3674 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003675 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003676 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003677 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 if ((flags & PackageManager.GET_META_DATA) != 0) {
3680 ai.metaData = p.mAppMetaData;
3681 }
3682 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3683 ai.sharedLibraryFiles = p.usesLibraryFiles;
3684 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003685 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003686 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003687 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003688 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003689 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003690 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 return ai;
3692 }
3693
3694 public static final PermissionInfo generatePermissionInfo(
3695 Permission p, int flags) {
3696 if (p == null) return null;
3697 if ((flags&PackageManager.GET_META_DATA) == 0) {
3698 return p.info;
3699 }
3700 PermissionInfo pi = new PermissionInfo(p.info);
3701 pi.metaData = p.metaData;
3702 return pi;
3703 }
3704
3705 public static final PermissionGroupInfo generatePermissionGroupInfo(
3706 PermissionGroup pg, int flags) {
3707 if (pg == null) return null;
3708 if ((flags&PackageManager.GET_META_DATA) == 0) {
3709 return pg.info;
3710 }
3711 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3712 pgi.metaData = pg.metaData;
3713 return pgi;
3714 }
3715
3716 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003717 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003719 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3720 super(args, _info);
3721 info = _info;
3722 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003724
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003725 public void setPackageName(String packageName) {
3726 super.setPackageName(packageName);
3727 info.packageName = packageName;
3728 }
3729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 public String toString() {
3731 return "Activity{"
3732 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003733 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 }
3735 }
3736
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003737 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3738 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003740 if (!checkUseInstalled(flags, state)) {
3741 return null;
3742 }
3743 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 return a.info;
3745 }
3746 // Make shallow copies so we can store the metadata safely
3747 ActivityInfo ai = new ActivityInfo(a.info);
3748 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003749 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 return ai;
3751 }
3752
3753 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003754 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003756 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3757 super(args, _info);
3758 info = _info;
3759 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003761
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003762 public void setPackageName(String packageName) {
3763 super.setPackageName(packageName);
3764 info.packageName = packageName;
3765 }
3766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 public String toString() {
3768 return "Service{"
3769 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003770 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 }
3772 }
3773
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003774 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3775 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003777 if (!checkUseInstalled(flags, state)) {
3778 return null;
3779 }
3780 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 return s.info;
3782 }
3783 // Make shallow copies so we can store the metadata safely
3784 ServiceInfo si = new ServiceInfo(s.info);
3785 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003786 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 return si;
3788 }
3789
3790 public final static class Provider extends Component {
3791 public final ProviderInfo info;
3792 public boolean syncable;
3793
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003794 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3795 super(args, _info);
3796 info = _info;
3797 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 syncable = false;
3799 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 public Provider(Provider existingProvider) {
3802 super(existingProvider);
3803 this.info = existingProvider.info;
3804 this.syncable = existingProvider.syncable;
3805 }
3806
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003807 public void setPackageName(String packageName) {
3808 super.setPackageName(packageName);
3809 info.packageName = packageName;
3810 }
3811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 public String toString() {
3813 return "Provider{"
3814 + Integer.toHexString(System.identityHashCode(this))
3815 + " " + info.name + "}";
3816 }
3817 }
3818
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003819 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3820 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003822 if (!checkUseInstalled(flags, state)) {
3823 return null;
3824 }
3825 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003827 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 return p.info;
3829 }
3830 // Make shallow copies so we can store the metadata safely
3831 ProviderInfo pi = new ProviderInfo(p.info);
3832 pi.metaData = p.metaData;
3833 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3834 pi.uriPermissionPatterns = null;
3835 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003836 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 return pi;
3838 }
3839
3840 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003841 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003843 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3844 super(args, _info);
3845 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003847
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003848 public void setPackageName(String packageName) {
3849 super.setPackageName(packageName);
3850 info.packageName = packageName;
3851 }
3852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 public String toString() {
3854 return "Instrumentation{"
3855 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003856 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 }
3858 }
3859
3860 public static final InstrumentationInfo generateInstrumentationInfo(
3861 Instrumentation i, int flags) {
3862 if (i == null) return null;
3863 if ((flags&PackageManager.GET_META_DATA) == 0) {
3864 return i.info;
3865 }
3866 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3867 ii.metaData = i.metaData;
3868 return ii;
3869 }
3870
3871 public static class IntentInfo extends IntentFilter {
3872 public boolean hasDefault;
3873 public int labelRes;
3874 public CharSequence nonLocalizedLabel;
3875 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003876 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 }
3878
3879 public final static class ActivityIntentInfo extends IntentInfo {
3880 public final Activity activity;
3881
3882 public ActivityIntentInfo(Activity _activity) {
3883 activity = _activity;
3884 }
3885
3886 public String toString() {
3887 return "ActivityIntentInfo{"
3888 + Integer.toHexString(System.identityHashCode(this))
3889 + " " + activity.info.name + "}";
3890 }
3891 }
3892
3893 public final static class ServiceIntentInfo extends IntentInfo {
3894 public final Service service;
3895
3896 public ServiceIntentInfo(Service _service) {
3897 service = _service;
3898 }
3899
3900 public String toString() {
3901 return "ServiceIntentInfo{"
3902 + Integer.toHexString(System.identityHashCode(this))
3903 + " " + service.info.name + "}";
3904 }
3905 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003906
3907 /**
3908 * @hide
3909 */
3910 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3911 sCompatibilityModeEnabled = compatibilityModeEnabled;
3912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913}