blob: acb3725b6cf2fdc870e8c8a016021c063d97ea7e [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 Yamasanie993ae12013-04-15 13:42:57 -07001820 }
1821
1822 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1823 .AndroidManifestApplication_restrictedAccountType);
1824 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1825 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 }
1827
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001828 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1829 .AndroidManifestApplication_requiredAccountType);
1830 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1831 owner.mRequiredAccountType = requiredAccountType;
1832 }
1833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 if (sa.getBoolean(
1835 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1836 false)) {
1837 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1838 }
1839
1840 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001841 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001842 false)) {
1843 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1844 }
1845
Romain Guy529b60a2010-08-03 18:05:47 -07001846 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001847 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001848 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001849
1850 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1852 true)) {
1853 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1854 }
1855
1856 if (sa.getBoolean(
1857 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1858 false)) {
1859 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1860 }
1861
1862 if (sa.getBoolean(
1863 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1864 true)) {
1865 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1866 }
1867
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001868 if (sa.getBoolean(
1869 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001870 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001871 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1872 }
1873
Jason parksa3cdaa52011-01-13 14:15:43 -06001874 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001875 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001876 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001877 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001878 }
1879
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001880 if (sa.getBoolean(
1881 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1882 false /* default is no RTL support*/)) {
1883 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1884 }
1885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001887 str = sa.getNonConfigurationString(
1888 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1890
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001891 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1892 str = sa.getNonConfigurationString(
1893 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1894 } else {
1895 // Some older apps have been seen to use a resource reference
1896 // here that on older builds was ignored (with a warning). We
1897 // need to continue to do this for them so they don't break.
1898 str = sa.getNonResourceString(
1899 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1902 str, outError);
1903
1904 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001905 CharSequence pname;
1906 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1907 pname = sa.getNonConfigurationString(
1908 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1909 } else {
1910 // Some older apps have been seen to use a resource reference
1911 // here that on older builds was ignored (with a warning). We
1912 // need to continue to do this for them so they don't break.
1913 pname = sa.getNonResourceString(
1914 com.android.internal.R.styleable.AndroidManifestApplication_process);
1915 }
1916 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 flags, mSeparateProcesses, outError);
1918
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001919 ai.enabled = sa.getBoolean(
1920 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001921
Dianne Hackborn02486b12010-08-26 14:18:37 -07001922 if (false) {
1923 if (sa.getBoolean(
1924 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1925 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001926 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001927
1928 // A heavy-weight application can not be in a custom process.
1929 // We can do direct compare because we intern all strings.
1930 if (ai.processName != null && ai.processName != ai.packageName) {
1931 outError[0] = "cantSaveState applications can not use custom processes";
1932 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001933 }
1934 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 }
1936
Adam Powell269248d2011-08-02 10:26:54 -07001937 ai.uiOptions = sa.getInt(
1938 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 sa.recycle();
1941
1942 if (outError[0] != null) {
1943 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1944 return false;
1945 }
1946
1947 final int innerDepth = parser.getDepth();
1948
1949 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001950 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1951 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1952 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 continue;
1954 }
1955
1956 String tagName = parser.getName();
1957 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001958 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1959 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 if (a == null) {
1961 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1962 return false;
1963 }
1964
1965 owner.activities.add(a);
1966
1967 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001968 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 if (a == null) {
1970 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1971 return false;
1972 }
1973
1974 owner.receivers.add(a);
1975
1976 } else if (tagName.equals("service")) {
1977 Service s = parseService(owner, res, parser, attrs, flags, outError);
1978 if (s == null) {
1979 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1980 return false;
1981 }
1982
1983 owner.services.add(s);
1984
1985 } else if (tagName.equals("provider")) {
1986 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1987 if (p == null) {
1988 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1989 return false;
1990 }
1991
1992 owner.providers.add(p);
1993
1994 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001995 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 if (a == null) {
1997 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1998 return false;
1999 }
2000
2001 owner.activities.add(a);
2002
2003 } else if (parser.getName().equals("meta-data")) {
2004 // note: application meta-data is stored off to the side, so it can
2005 // remain null in the primary copy (we like to avoid extra copies because
2006 // it can be large)
2007 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2008 outError)) == null) {
2009 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2010 return false;
2011 }
2012
Dianne Hackbornc895be72013-03-11 17:48:43 -07002013 } else if (tagName.equals("library")) {
2014 sa = res.obtainAttributes(attrs,
2015 com.android.internal.R.styleable.AndroidManifestLibrary);
2016
2017 // Note: don't allow this value to be a reference to a resource
2018 // that may change.
2019 String lname = sa.getNonResourceString(
2020 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2021
2022 sa.recycle();
2023
2024 if (lname != null) {
2025 if (owner.libraryNames == null) {
2026 owner.libraryNames = new ArrayList<String>();
2027 }
2028 if (!owner.libraryNames.contains(lname)) {
2029 owner.libraryNames.add(lname.intern());
2030 }
2031 }
2032
2033 XmlUtils.skipCurrentTag(parser);
2034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035 } else if (tagName.equals("uses-library")) {
2036 sa = res.obtainAttributes(attrs,
2037 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2038
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002039 // Note: don't allow this value to be a reference to a resource
2040 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 String lname = sa.getNonResourceString(
2042 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002043 boolean req = sa.getBoolean(
2044 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2045 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046
2047 sa.recycle();
2048
Dianne Hackborn49237342009-08-27 20:08:01 -07002049 if (lname != null) {
2050 if (req) {
2051 if (owner.usesLibraries == null) {
2052 owner.usesLibraries = new ArrayList<String>();
2053 }
2054 if (!owner.usesLibraries.contains(lname)) {
2055 owner.usesLibraries.add(lname.intern());
2056 }
2057 } else {
2058 if (owner.usesOptionalLibraries == null) {
2059 owner.usesOptionalLibraries = new ArrayList<String>();
2060 }
2061 if (!owner.usesOptionalLibraries.contains(lname)) {
2062 owner.usesOptionalLibraries.add(lname.intern());
2063 }
2064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 }
2066
2067 XmlUtils.skipCurrentTag(parser);
2068
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002069 } else if (tagName.equals("uses-package")) {
2070 // Dependencies for app installers; we don't currently try to
2071 // enforce this.
2072 XmlUtils.skipCurrentTag(parser);
2073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 } else {
2075 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002076 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002077 + " at " + mArchiveSourcePath + " "
2078 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 XmlUtils.skipCurrentTag(parser);
2080 continue;
2081 } else {
2082 outError[0] = "Bad element under <application>: " + tagName;
2083 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2084 return false;
2085 }
2086 }
2087 }
2088
2089 return true;
2090 }
2091
2092 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2093 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002094 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002095 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 if (name == null) {
2097 outError[0] = tag + " does not specify android:name";
2098 return false;
2099 }
2100
2101 outInfo.name
2102 = buildClassName(owner.applicationInfo.packageName, name, outError);
2103 if (outInfo.name == null) {
2104 return false;
2105 }
2106
2107 int iconVal = sa.getResourceId(iconRes, 0);
2108 if (iconVal != 0) {
2109 outInfo.icon = iconVal;
2110 outInfo.nonLocalizedLabel = null;
2111 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002112
2113 int logoVal = sa.getResourceId(logoRes, 0);
2114 if (logoVal != 0) {
2115 outInfo.logo = logoVal;
2116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117
2118 TypedValue v = sa.peekValue(labelRes);
2119 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2120 outInfo.nonLocalizedLabel = v.coerceToString();
2121 }
2122
2123 outInfo.packageName = owner.packageName;
2124
2125 return true;
2126 }
2127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 private Activity parseActivity(Package owner, Resources res,
2129 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002130 boolean receiver, boolean hardwareAccelerated)
2131 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 TypedArray sa = res.obtainAttributes(attrs,
2133 com.android.internal.R.styleable.AndroidManifestActivity);
2134
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002135 if (mParseActivityArgs == null) {
2136 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2137 com.android.internal.R.styleable.AndroidManifestActivity_name,
2138 com.android.internal.R.styleable.AndroidManifestActivity_label,
2139 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002140 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002141 mSeparateProcesses,
2142 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002143 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002144 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2145 }
2146
2147 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2148 mParseActivityArgs.sa = sa;
2149 mParseActivityArgs.flags = flags;
2150
2151 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2152 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 sa.recycle();
2154 return null;
2155 }
2156
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002157 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2159 if (setExported) {
2160 a.info.exported = sa.getBoolean(
2161 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2162 }
2163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 a.info.theme = sa.getResourceId(
2165 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2166
Adam Powell269248d2011-08-02 10:26:54 -07002167 a.info.uiOptions = sa.getInt(
2168 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2169 a.info.applicationInfo.uiOptions);
2170
Adam Powelldd8fab22012-03-22 17:47:27 -07002171 String parentName = sa.getNonConfigurationString(
2172 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2173 if (parentName != null) {
2174 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2175 if (outError[0] == null) {
2176 a.info.parentActivityName = parentClassName;
2177 } else {
2178 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2179 parentName);
2180 outError[0] = null;
2181 }
2182 }
2183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002185 str = sa.getNonConfigurationString(
2186 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 if (str == null) {
2188 a.info.permission = owner.applicationInfo.permission;
2189 } else {
2190 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2191 }
2192
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002193 str = sa.getNonConfigurationString(
2194 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2196 owner.applicationInfo.taskAffinity, str, outError);
2197
2198 a.info.flags = 0;
2199 if (sa.getBoolean(
2200 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2201 false)) {
2202 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2203 }
2204
2205 if (sa.getBoolean(
2206 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2207 false)) {
2208 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2209 }
2210
2211 if (sa.getBoolean(
2212 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2213 false)) {
2214 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2215 }
2216
2217 if (sa.getBoolean(
2218 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2219 false)) {
2220 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2221 }
2222
2223 if (sa.getBoolean(
2224 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2225 false)) {
2226 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2227 }
2228
2229 if (sa.getBoolean(
2230 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2231 false)) {
2232 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2233 }
2234
2235 if (sa.getBoolean(
2236 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2237 false)) {
2238 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2239 }
2240
2241 if (sa.getBoolean(
2242 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2243 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2244 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2245 }
2246
Dianne Hackbornffa42482009-09-23 22:20:11 -07002247 if (sa.getBoolean(
2248 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2249 false)) {
2250 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2251 }
2252
Daniel Sandler613dde42010-06-21 13:46:39 -04002253 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002254 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2255 false)) {
2256 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2257 }
2258
2259 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002260 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2261 false)) {
2262 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2263 }
Craig Mautner5962b122012-10-05 14:45:52 -07002264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002266 if (sa.getBoolean(
2267 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2268 hardwareAccelerated)) {
2269 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2270 }
2271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 a.info.launchMode = sa.getInt(
2273 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2274 ActivityInfo.LAUNCH_MULTIPLE);
2275 a.info.screenOrientation = sa.getInt(
2276 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2277 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2278 a.info.configChanges = sa.getInt(
2279 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2280 0);
2281 a.info.softInputMode = sa.getInt(
2282 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2283 0);
2284 } else {
2285 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2286 a.info.configChanges = 0;
2287 }
2288
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002289 if (receiver) {
2290 if (sa.getBoolean(
2291 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2292 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002293 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002294 if (a.info.exported) {
2295 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2296 + a.className + " at " + mArchiveSourcePath + " "
2297 + parser.getPositionDescription());
2298 a.info.exported = false;
2299 }
2300 setExported = true;
2301 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002302 if (sa.getBoolean(
2303 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2304 false)) {
2305 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2306 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002307 }
2308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 sa.recycle();
2310
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002311 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002312 // A heavy-weight application can not have receives in its main process
2313 // We can do direct compare because we intern all strings.
2314 if (a.info.processName == owner.packageName) {
2315 outError[0] = "Heavy-weight applications can not have receivers in main process";
2316 }
2317 }
2318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 if (outError[0] != null) {
2320 return null;
2321 }
2322
2323 int outerDepth = parser.getDepth();
2324 int type;
2325 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2326 && (type != XmlPullParser.END_TAG
2327 || parser.getDepth() > outerDepth)) {
2328 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2329 continue;
2330 }
2331
2332 if (parser.getName().equals("intent-filter")) {
2333 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2334 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2335 return null;
2336 }
2337 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002338 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002339 + mArchiveSourcePath + " "
2340 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 } else {
2342 a.intents.add(intent);
2343 }
2344 } else if (parser.getName().equals("meta-data")) {
2345 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2346 outError)) == null) {
2347 return null;
2348 }
2349 } else {
2350 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002351 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002353 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002354 + " at " + mArchiveSourcePath + " "
2355 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002357 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002358 + " at " + mArchiveSourcePath + " "
2359 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 }
2361 XmlUtils.skipCurrentTag(parser);
2362 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002364 if (receiver) {
2365 outError[0] = "Bad element under <receiver>: " + parser.getName();
2366 } else {
2367 outError[0] = "Bad element under <activity>: " + parser.getName();
2368 }
2369 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 }
2372 }
2373
2374 if (!setExported) {
2375 a.info.exported = a.intents.size() > 0;
2376 }
2377
2378 return a;
2379 }
2380
2381 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002382 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2383 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 TypedArray sa = res.obtainAttributes(attrs,
2385 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2386
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002387 String targetActivity = sa.getNonConfigurationString(
2388 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 if (targetActivity == null) {
2390 outError[0] = "<activity-alias> does not specify android:targetActivity";
2391 sa.recycle();
2392 return null;
2393 }
2394
2395 targetActivity = buildClassName(owner.applicationInfo.packageName,
2396 targetActivity, outError);
2397 if (targetActivity == null) {
2398 sa.recycle();
2399 return null;
2400 }
2401
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002402 if (mParseActivityAliasArgs == null) {
2403 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2404 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2405 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2406 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002407 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002408 mSeparateProcesses,
2409 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002410 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002411 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2412 mParseActivityAliasArgs.tag = "<activity-alias>";
2413 }
2414
2415 mParseActivityAliasArgs.sa = sa;
2416 mParseActivityAliasArgs.flags = flags;
2417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 Activity target = null;
2419
2420 final int NA = owner.activities.size();
2421 for (int i=0; i<NA; i++) {
2422 Activity t = owner.activities.get(i);
2423 if (targetActivity.equals(t.info.name)) {
2424 target = t;
2425 break;
2426 }
2427 }
2428
2429 if (target == null) {
2430 outError[0] = "<activity-alias> target activity " + targetActivity
2431 + " not found in manifest";
2432 sa.recycle();
2433 return null;
2434 }
2435
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002436 ActivityInfo info = new ActivityInfo();
2437 info.targetActivity = targetActivity;
2438 info.configChanges = target.info.configChanges;
2439 info.flags = target.info.flags;
2440 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002441 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002442 info.labelRes = target.info.labelRes;
2443 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2444 info.launchMode = target.info.launchMode;
2445 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002446 if (info.descriptionRes == 0) {
2447 info.descriptionRes = target.info.descriptionRes;
2448 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002449 info.screenOrientation = target.info.screenOrientation;
2450 info.taskAffinity = target.info.taskAffinity;
2451 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002452 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002453 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002454 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002455
2456 Activity a = new Activity(mParseActivityAliasArgs, info);
2457 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 sa.recycle();
2459 return null;
2460 }
2461
2462 final boolean setExported = sa.hasValue(
2463 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2464 if (setExported) {
2465 a.info.exported = sa.getBoolean(
2466 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2467 }
2468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002470 str = sa.getNonConfigurationString(
2471 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 if (str != null) {
2473 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2474 }
2475
Adam Powelldd8fab22012-03-22 17:47:27 -07002476 String parentName = sa.getNonConfigurationString(
2477 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2478 0);
2479 if (parentName != null) {
2480 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2481 if (outError[0] == null) {
2482 a.info.parentActivityName = parentClassName;
2483 } else {
2484 Log.e(TAG, "Activity alias " + a.info.name +
2485 " specified invalid parentActivityName " + parentName);
2486 outError[0] = null;
2487 }
2488 }
2489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 sa.recycle();
2491
2492 if (outError[0] != null) {
2493 return null;
2494 }
2495
2496 int outerDepth = parser.getDepth();
2497 int type;
2498 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2499 && (type != XmlPullParser.END_TAG
2500 || parser.getDepth() > outerDepth)) {
2501 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2502 continue;
2503 }
2504
2505 if (parser.getName().equals("intent-filter")) {
2506 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2507 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2508 return null;
2509 }
2510 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002511 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002512 + mArchiveSourcePath + " "
2513 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 } else {
2515 a.intents.add(intent);
2516 }
2517 } else if (parser.getName().equals("meta-data")) {
2518 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2519 outError)) == null) {
2520 return null;
2521 }
2522 } else {
2523 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002524 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002525 + " at " + mArchiveSourcePath + " "
2526 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 XmlUtils.skipCurrentTag(parser);
2528 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002529 } else {
2530 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2531 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 }
2534 }
2535
2536 if (!setExported) {
2537 a.info.exported = a.intents.size() > 0;
2538 }
2539
2540 return a;
2541 }
2542
2543 private Provider parseProvider(Package owner, Resources res,
2544 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2545 throws XmlPullParserException, IOException {
2546 TypedArray sa = res.obtainAttributes(attrs,
2547 com.android.internal.R.styleable.AndroidManifestProvider);
2548
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002549 if (mParseProviderArgs == null) {
2550 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2551 com.android.internal.R.styleable.AndroidManifestProvider_name,
2552 com.android.internal.R.styleable.AndroidManifestProvider_label,
2553 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002554 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002555 mSeparateProcesses,
2556 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002557 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002558 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2559 mParseProviderArgs.tag = "<provider>";
2560 }
2561
2562 mParseProviderArgs.sa = sa;
2563 mParseProviderArgs.flags = flags;
2564
2565 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2566 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 sa.recycle();
2568 return null;
2569 }
2570
Nick Kralevichf097b162012-07-28 12:43:48 -07002571 boolean providerExportedDefault = false;
2572
2573 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2574 // For compatibility, applications targeting API level 16 or lower
2575 // should have their content providers exported by default, unless they
2576 // specify otherwise.
2577 providerExportedDefault = true;
2578 }
2579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002581 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2582 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002584 String cpname = sa.getNonConfigurationString(
2585 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002586
2587 p.info.isSyncable = sa.getBoolean(
2588 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2589 false);
2590
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002591 String permission = sa.getNonConfigurationString(
2592 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2593 String str = sa.getNonConfigurationString(
2594 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 if (str == null) {
2596 str = permission;
2597 }
2598 if (str == null) {
2599 p.info.readPermission = owner.applicationInfo.permission;
2600 } else {
2601 p.info.readPermission =
2602 str.length() > 0 ? str.toString().intern() : null;
2603 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002604 str = sa.getNonConfigurationString(
2605 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 if (str == null) {
2607 str = permission;
2608 }
2609 if (str == null) {
2610 p.info.writePermission = owner.applicationInfo.permission;
2611 } else {
2612 p.info.writePermission =
2613 str.length() > 0 ? str.toString().intern() : null;
2614 }
2615
2616 p.info.grantUriPermissions = sa.getBoolean(
2617 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2618 false);
2619
2620 p.info.multiprocess = sa.getBoolean(
2621 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2622 false);
2623
2624 p.info.initOrder = sa.getInt(
2625 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2626 0);
2627
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002628 p.info.flags = 0;
2629
2630 if (sa.getBoolean(
2631 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2632 false)) {
2633 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2634 if (p.info.exported) {
2635 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2636 + p.className + " at " + mArchiveSourcePath + " "
2637 + parser.getPositionDescription());
2638 p.info.exported = false;
2639 }
2640 }
2641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 sa.recycle();
2643
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002644 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002645 // A heavy-weight application can not have providers in its main process
2646 // We can do direct compare because we intern all strings.
2647 if (p.info.processName == owner.packageName) {
2648 outError[0] = "Heavy-weight applications can not have providers in main process";
2649 return null;
2650 }
2651 }
2652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002654 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 return null;
2656 }
2657 p.info.authority = cpname.intern();
2658
2659 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2660 return null;
2661 }
2662
2663 return p;
2664 }
2665
2666 private boolean parseProviderTags(Resources res,
2667 XmlPullParser parser, AttributeSet attrs,
2668 Provider outInfo, String[] outError)
2669 throws XmlPullParserException, IOException {
2670 int outerDepth = parser.getDepth();
2671 int type;
2672 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2673 && (type != XmlPullParser.END_TAG
2674 || parser.getDepth() > outerDepth)) {
2675 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2676 continue;
2677 }
2678
2679 if (parser.getName().equals("meta-data")) {
2680 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2681 outInfo.metaData, outError)) == null) {
2682 return false;
2683 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 } else if (parser.getName().equals("grant-uri-permission")) {
2686 TypedArray sa = res.obtainAttributes(attrs,
2687 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2688
2689 PatternMatcher pa = null;
2690
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002691 String str = sa.getNonConfigurationString(
2692 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 if (str != null) {
2694 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2695 }
2696
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002697 str = sa.getNonConfigurationString(
2698 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 if (str != null) {
2700 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2701 }
2702
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002703 str = sa.getNonConfigurationString(
2704 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 if (str != null) {
2706 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2707 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 sa.recycle();
2710
2711 if (pa != null) {
2712 if (outInfo.info.uriPermissionPatterns == null) {
2713 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2714 outInfo.info.uriPermissionPatterns[0] = pa;
2715 } else {
2716 final int N = outInfo.info.uriPermissionPatterns.length;
2717 PatternMatcher[] newp = new PatternMatcher[N+1];
2718 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2719 newp[N] = pa;
2720 outInfo.info.uriPermissionPatterns = newp;
2721 }
2722 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002723 } else {
2724 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002725 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002726 + parser.getName() + " at " + mArchiveSourcePath + " "
2727 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002728 XmlUtils.skipCurrentTag(parser);
2729 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002730 } else {
2731 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2732 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002733 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002734 }
2735 XmlUtils.skipCurrentTag(parser);
2736
2737 } else if (parser.getName().equals("path-permission")) {
2738 TypedArray sa = res.obtainAttributes(attrs,
2739 com.android.internal.R.styleable.AndroidManifestPathPermission);
2740
2741 PathPermission pa = null;
2742
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002743 String permission = sa.getNonConfigurationString(
2744 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2745 String readPermission = sa.getNonConfigurationString(
2746 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002747 if (readPermission == null) {
2748 readPermission = permission;
2749 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002750 String writePermission = sa.getNonConfigurationString(
2751 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002752 if (writePermission == null) {
2753 writePermission = permission;
2754 }
2755
2756 boolean havePerm = false;
2757 if (readPermission != null) {
2758 readPermission = readPermission.intern();
2759 havePerm = true;
2760 }
2761 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002762 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002763 havePerm = true;
2764 }
2765
2766 if (!havePerm) {
2767 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002768 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002769 + parser.getName() + " at " + mArchiveSourcePath + " "
2770 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002771 XmlUtils.skipCurrentTag(parser);
2772 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002773 } else {
2774 outError[0] = "No readPermission or writePermssion for <path-permission>";
2775 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002776 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002777 }
2778
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002779 String path = sa.getNonConfigurationString(
2780 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002781 if (path != null) {
2782 pa = new PathPermission(path,
2783 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2784 }
2785
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002786 path = sa.getNonConfigurationString(
2787 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002788 if (path != null) {
2789 pa = new PathPermission(path,
2790 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2791 }
2792
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002793 path = sa.getNonConfigurationString(
2794 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002795 if (path != null) {
2796 pa = new PathPermission(path,
2797 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2798 }
2799
2800 sa.recycle();
2801
2802 if (pa != null) {
2803 if (outInfo.info.pathPermissions == null) {
2804 outInfo.info.pathPermissions = new PathPermission[1];
2805 outInfo.info.pathPermissions[0] = pa;
2806 } else {
2807 final int N = outInfo.info.pathPermissions.length;
2808 PathPermission[] newp = new PathPermission[N+1];
2809 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2810 newp[N] = pa;
2811 outInfo.info.pathPermissions = newp;
2812 }
2813 } else {
2814 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002815 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002816 + parser.getName() + " at " + mArchiveSourcePath + " "
2817 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002818 XmlUtils.skipCurrentTag(parser);
2819 continue;
2820 }
2821 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2822 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 }
2824 XmlUtils.skipCurrentTag(parser);
2825
2826 } else {
2827 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002828 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002829 + parser.getName() + " at " + mArchiveSourcePath + " "
2830 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 XmlUtils.skipCurrentTag(parser);
2832 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002833 } else {
2834 outError[0] = "Bad element under <provider>: " + parser.getName();
2835 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 }
2838 }
2839 return true;
2840 }
2841
2842 private Service parseService(Package owner, Resources res,
2843 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2844 throws XmlPullParserException, IOException {
2845 TypedArray sa = res.obtainAttributes(attrs,
2846 com.android.internal.R.styleable.AndroidManifestService);
2847
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002848 if (mParseServiceArgs == null) {
2849 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2850 com.android.internal.R.styleable.AndroidManifestService_name,
2851 com.android.internal.R.styleable.AndroidManifestService_label,
2852 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002853 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002854 mSeparateProcesses,
2855 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002856 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002857 com.android.internal.R.styleable.AndroidManifestService_enabled);
2858 mParseServiceArgs.tag = "<service>";
2859 }
2860
2861 mParseServiceArgs.sa = sa;
2862 mParseServiceArgs.flags = flags;
2863
2864 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2865 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 sa.recycle();
2867 return null;
2868 }
2869
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002870 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 com.android.internal.R.styleable.AndroidManifestService_exported);
2872 if (setExported) {
2873 s.info.exported = sa.getBoolean(
2874 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2875 }
2876
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002877 String str = sa.getNonConfigurationString(
2878 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 if (str == null) {
2880 s.info.permission = owner.applicationInfo.permission;
2881 } else {
2882 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2883 }
2884
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002885 s.info.flags = 0;
2886 if (sa.getBoolean(
2887 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2888 false)) {
2889 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2890 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002891 if (sa.getBoolean(
2892 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2893 false)) {
2894 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2895 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002896 if (sa.getBoolean(
2897 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2898 false)) {
2899 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2900 if (s.info.exported) {
2901 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2902 + s.className + " at " + mArchiveSourcePath + " "
2903 + parser.getPositionDescription());
2904 s.info.exported = false;
2905 }
2906 setExported = true;
2907 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 sa.recycle();
2910
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002911 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002912 // A heavy-weight application can not have services in its main process
2913 // We can do direct compare because we intern all strings.
2914 if (s.info.processName == owner.packageName) {
2915 outError[0] = "Heavy-weight applications can not have services in main process";
2916 return null;
2917 }
2918 }
2919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 int outerDepth = parser.getDepth();
2921 int type;
2922 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2923 && (type != XmlPullParser.END_TAG
2924 || parser.getDepth() > outerDepth)) {
2925 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2926 continue;
2927 }
2928
2929 if (parser.getName().equals("intent-filter")) {
2930 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2931 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2932 return null;
2933 }
2934
2935 s.intents.add(intent);
2936 } else if (parser.getName().equals("meta-data")) {
2937 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2938 outError)) == null) {
2939 return null;
2940 }
2941 } else {
2942 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002943 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002944 + parser.getName() + " at " + mArchiveSourcePath + " "
2945 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 XmlUtils.skipCurrentTag(parser);
2947 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002948 } else {
2949 outError[0] = "Bad element under <service>: " + parser.getName();
2950 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 }
2953 }
2954
2955 if (!setExported) {
2956 s.info.exported = s.intents.size() > 0;
2957 }
2958
2959 return s;
2960 }
2961
2962 private boolean parseAllMetaData(Resources res,
2963 XmlPullParser parser, AttributeSet attrs, String tag,
2964 Component outInfo, String[] outError)
2965 throws XmlPullParserException, IOException {
2966 int outerDepth = parser.getDepth();
2967 int type;
2968 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2969 && (type != XmlPullParser.END_TAG
2970 || parser.getDepth() > outerDepth)) {
2971 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2972 continue;
2973 }
2974
2975 if (parser.getName().equals("meta-data")) {
2976 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2977 outInfo.metaData, outError)) == null) {
2978 return false;
2979 }
2980 } else {
2981 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002982 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002983 + parser.getName() + " at " + mArchiveSourcePath + " "
2984 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 XmlUtils.skipCurrentTag(parser);
2986 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002987 } else {
2988 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2989 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 }
2992 }
2993 return true;
2994 }
2995
2996 private Bundle parseMetaData(Resources res,
2997 XmlPullParser parser, AttributeSet attrs,
2998 Bundle data, String[] outError)
2999 throws XmlPullParserException, IOException {
3000
3001 TypedArray sa = res.obtainAttributes(attrs,
3002 com.android.internal.R.styleable.AndroidManifestMetaData);
3003
3004 if (data == null) {
3005 data = new Bundle();
3006 }
3007
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003008 String name = sa.getNonConfigurationString(
3009 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 if (name == null) {
3011 outError[0] = "<meta-data> requires an android:name attribute";
3012 sa.recycle();
3013 return null;
3014 }
3015
Dianne Hackborn854060a2009-07-09 18:14:31 -07003016 name = name.intern();
3017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 TypedValue v = sa.peekValue(
3019 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3020 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003021 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 data.putInt(name, v.resourceId);
3023 } else {
3024 v = sa.peekValue(
3025 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003026 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 if (v != null) {
3028 if (v.type == TypedValue.TYPE_STRING) {
3029 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003030 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3032 data.putBoolean(name, v.data != 0);
3033 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3034 && v.type <= TypedValue.TYPE_LAST_INT) {
3035 data.putInt(name, v.data);
3036 } else if (v.type == TypedValue.TYPE_FLOAT) {
3037 data.putFloat(name, v.getFloat());
3038 } else {
3039 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003040 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003041 + parser.getName() + " at " + mArchiveSourcePath + " "
3042 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 } else {
3044 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3045 data = null;
3046 }
3047 }
3048 } else {
3049 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3050 data = null;
3051 }
3052 }
3053
3054 sa.recycle();
3055
3056 XmlUtils.skipCurrentTag(parser);
3057
3058 return data;
3059 }
3060
Kenny Root05ca4c92011-09-15 10:36:25 -07003061 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3062 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3063 IOException {
3064 final TypedArray sa = res.obtainAttributes(attrs,
3065 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3066
3067 final String packageName = sa.getNonResourceString(
3068 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3069
3070 final String encodedPublicKey = sa.getNonResourceString(
3071 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3072
3073 sa.recycle();
3074
3075 if (packageName == null || packageName.length() == 0) {
3076 Slog.i(TAG, "verifier package name was null; skipping");
3077 return null;
3078 } else if (encodedPublicKey == null) {
3079 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3080 }
3081
3082 EncodedKeySpec keySpec;
3083 try {
3084 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3085 keySpec = new X509EncodedKeySpec(encoded);
3086 } catch (IllegalArgumentException e) {
3087 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
3088 return null;
3089 }
3090
3091 /* First try the key as an RSA key. */
3092 try {
3093 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
3094 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3095 return new VerifierInfo(packageName, publicKey);
3096 } catch (NoSuchAlgorithmException e) {
3097 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3098 return null;
3099 } catch (InvalidKeySpecException e) {
3100 // Not a RSA public key.
3101 }
3102
3103 /* Now try it as a DSA key. */
3104 try {
3105 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3106 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3107 return new VerifierInfo(packageName, publicKey);
3108 } catch (NoSuchAlgorithmException e) {
3109 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3110 return null;
3111 } catch (InvalidKeySpecException e) {
3112 // Not a DSA public key.
3113 }
3114
3115 return null;
3116 }
3117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 private static final String ANDROID_RESOURCES
3119 = "http://schemas.android.com/apk/res/android";
3120
3121 private boolean parseIntent(Resources res,
3122 XmlPullParser parser, AttributeSet attrs, int flags,
3123 IntentInfo outInfo, String[] outError, boolean isActivity)
3124 throws XmlPullParserException, IOException {
3125
3126 TypedArray sa = res.obtainAttributes(attrs,
3127 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3128
3129 int priority = sa.getInt(
3130 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 TypedValue v = sa.peekValue(
3134 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3135 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3136 outInfo.nonLocalizedLabel = v.coerceToString();
3137 }
3138
3139 outInfo.icon = sa.getResourceId(
3140 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003141
3142 outInfo.logo = sa.getResourceId(
3143 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144
3145 sa.recycle();
3146
3147 int outerDepth = parser.getDepth();
3148 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003149 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3150 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3151 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 continue;
3153 }
3154
3155 String nodeName = parser.getName();
3156 if (nodeName.equals("action")) {
3157 String value = attrs.getAttributeValue(
3158 ANDROID_RESOURCES, "name");
3159 if (value == null || value == "") {
3160 outError[0] = "No value supplied for <android:name>";
3161 return false;
3162 }
3163 XmlUtils.skipCurrentTag(parser);
3164
3165 outInfo.addAction(value);
3166 } else if (nodeName.equals("category")) {
3167 String value = attrs.getAttributeValue(
3168 ANDROID_RESOURCES, "name");
3169 if (value == null || value == "") {
3170 outError[0] = "No value supplied for <android:name>";
3171 return false;
3172 }
3173 XmlUtils.skipCurrentTag(parser);
3174
3175 outInfo.addCategory(value);
3176
3177 } else if (nodeName.equals("data")) {
3178 sa = res.obtainAttributes(attrs,
3179 com.android.internal.R.styleable.AndroidManifestData);
3180
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003181 String str = sa.getNonConfigurationString(
3182 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 if (str != null) {
3184 try {
3185 outInfo.addDataType(str);
3186 } catch (IntentFilter.MalformedMimeTypeException e) {
3187 outError[0] = e.toString();
3188 sa.recycle();
3189 return false;
3190 }
3191 }
3192
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003193 str = sa.getNonConfigurationString(
3194 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 if (str != null) {
3196 outInfo.addDataScheme(str);
3197 }
3198
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003199 String host = sa.getNonConfigurationString(
3200 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3201 String port = sa.getNonConfigurationString(
3202 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 if (host != null) {
3204 outInfo.addDataAuthority(host, port);
3205 }
3206
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003207 str = sa.getNonConfigurationString(
3208 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 if (str != null) {
3210 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3211 }
3212
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003213 str = sa.getNonConfigurationString(
3214 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 if (str != null) {
3216 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3217 }
3218
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003219 str = sa.getNonConfigurationString(
3220 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 if (str != null) {
3222 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3223 }
3224
3225 sa.recycle();
3226 XmlUtils.skipCurrentTag(parser);
3227 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003228 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003229 + parser.getName() + " at " + mArchiveSourcePath + " "
3230 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 XmlUtils.skipCurrentTag(parser);
3232 } else {
3233 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3234 return false;
3235 }
3236 }
3237
3238 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003239
3240 if (DEBUG_PARSER) {
3241 final StringBuilder cats = new StringBuilder("Intent d=");
3242 cats.append(outInfo.hasDefault);
3243 cats.append(", cat=");
3244
3245 final Iterator<String> it = outInfo.categoriesIterator();
3246 if (it != null) {
3247 while (it.hasNext()) {
3248 cats.append(' ');
3249 cats.append(it.next());
3250 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003252 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003253 }
3254
3255 return true;
3256 }
3257
3258 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003259
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003260 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261
3262 // For now we only support one application per package.
3263 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3264
3265 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3266 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3267 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3268 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3269 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3270 public final ArrayList<Service> services = new ArrayList<Service>(0);
3271 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3272
3273 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003274 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275
Dianne Hackborn854060a2009-07-09 18:14:31 -07003276 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003277
3278 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003279 public ArrayList<String> usesLibraries = null;
3280 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 public String[] usesLibraryFiles = null;
3282
Dianne Hackbornc1552392010-03-03 16:19:01 -08003283 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003284 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003285 public ArrayList<String> mAdoptPermissions = null;
3286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 // We store the application meta-data independently to avoid multiple unwanted references
3288 public Bundle mAppMetaData = null;
3289
3290 // If this is a 3rd party app, this is the path of the zip file.
3291 public String mPath;
3292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 // The version code declared for this package.
3294 public int mVersionCode;
3295
3296 // The version name declared for this package.
3297 public String mVersionName;
3298
3299 // The shared user id that this package wants to use.
3300 public String mSharedUserId;
3301
3302 // The shared user label that this package wants to use.
3303 public int mSharedUserLabel;
3304
3305 // Signatures that were read from the package.
3306 public Signature mSignatures[];
3307
3308 // For use by package manager service for quick lookup of
3309 // preferred up order.
3310 public int mPreferredOrder = 0;
3311
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003312 // For use by the package manager to keep track of the path to the
3313 // file an app came from.
3314 public String mScanPath;
3315
3316 // For use by package manager to keep track of where it has done dexopt.
3317 public boolean mDidDexOpt;
3318
Amith Yamasani13593602012-03-22 16:16:17 -07003319 // // User set enabled state.
3320 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3321 //
3322 // // Whether the package has been stopped.
3323 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 // Additional data supplied by callers.
3326 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003327
3328 // Whether an operation is currently pending on this package
3329 public boolean mOperationPending;
3330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 /*
3332 * Applications hardware preferences
3333 */
3334 public final ArrayList<ConfigurationInfo> configPreferences =
3335 new ArrayList<ConfigurationInfo>();
3336
Dianne Hackborn49237342009-08-27 20:08:01 -07003337 /*
3338 * Applications requested features
3339 */
3340 public ArrayList<FeatureInfo> reqFeatures = null;
3341
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003342 public int installLocation;
3343
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003344 /* An app that's required for all users and cannot be uninstalled for a user */
3345 public boolean mRequiredForAllUsers;
3346
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003347 /* The restricted account authenticator type that is used by this application */
3348 public String mRestrictedAccountType;
3349
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003350 /* The required account type without which this application will not function */
3351 public String mRequiredAccountType;
3352
Kenny Rootbcc954d2011-08-08 16:19:08 -07003353 /**
3354 * Digest suitable for comparing whether this package's manifest is the
3355 * same as another.
3356 */
3357 public ManifestDigest manifestDigest;
3358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 public Package(String _name) {
3360 packageName = _name;
3361 applicationInfo.packageName = _name;
3362 applicationInfo.uid = -1;
3363 }
3364
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003365 public void setPackageName(String newName) {
3366 packageName = newName;
3367 applicationInfo.packageName = newName;
3368 for (int i=permissions.size()-1; i>=0; i--) {
3369 permissions.get(i).setPackageName(newName);
3370 }
3371 for (int i=permissionGroups.size()-1; i>=0; i--) {
3372 permissionGroups.get(i).setPackageName(newName);
3373 }
3374 for (int i=activities.size()-1; i>=0; i--) {
3375 activities.get(i).setPackageName(newName);
3376 }
3377 for (int i=receivers.size()-1; i>=0; i--) {
3378 receivers.get(i).setPackageName(newName);
3379 }
3380 for (int i=providers.size()-1; i>=0; i--) {
3381 providers.get(i).setPackageName(newName);
3382 }
3383 for (int i=services.size()-1; i>=0; i--) {
3384 services.get(i).setPackageName(newName);
3385 }
3386 for (int i=instrumentation.size()-1; i>=0; i--) {
3387 instrumentation.get(i).setPackageName(newName);
3388 }
3389 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003390
3391 public boolean hasComponentClassName(String name) {
3392 for (int i=activities.size()-1; i>=0; i--) {
3393 if (name.equals(activities.get(i).className)) {
3394 return true;
3395 }
3396 }
3397 for (int i=receivers.size()-1; i>=0; i--) {
3398 if (name.equals(receivers.get(i).className)) {
3399 return true;
3400 }
3401 }
3402 for (int i=providers.size()-1; i>=0; i--) {
3403 if (name.equals(providers.get(i).className)) {
3404 return true;
3405 }
3406 }
3407 for (int i=services.size()-1; i>=0; i--) {
3408 if (name.equals(services.get(i).className)) {
3409 return true;
3410 }
3411 }
3412 for (int i=instrumentation.size()-1; i>=0; i--) {
3413 if (name.equals(instrumentation.get(i).className)) {
3414 return true;
3415 }
3416 }
3417 return false;
3418 }
3419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 public String toString() {
3421 return "Package{"
3422 + Integer.toHexString(System.identityHashCode(this))
3423 + " " + packageName + "}";
3424 }
3425 }
3426
3427 public static class Component<II extends IntentInfo> {
3428 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003429 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003430 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 public Bundle metaData;
3432
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003433 ComponentName componentName;
3434 String componentShortName;
3435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 public Component(Package _owner) {
3437 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003438 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003439 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003440 }
3441
3442 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3443 owner = args.owner;
3444 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003445 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003446 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003447 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003448 args.outError[0] = args.tag + " does not specify android:name";
3449 return;
3450 }
3451
3452 outInfo.name
3453 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3454 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003455 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003456 args.outError[0] = args.tag + " does not have valid android:name";
3457 return;
3458 }
3459
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003460 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003461
3462 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3463 if (iconVal != 0) {
3464 outInfo.icon = iconVal;
3465 outInfo.nonLocalizedLabel = null;
3466 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003467
3468 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3469 if (logoVal != 0) {
3470 outInfo.logo = logoVal;
3471 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003472
3473 TypedValue v = args.sa.peekValue(args.labelRes);
3474 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3475 outInfo.nonLocalizedLabel = v.coerceToString();
3476 }
3477
3478 outInfo.packageName = owner.packageName;
3479 }
3480
3481 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3482 this(args, (PackageItemInfo)outInfo);
3483 if (args.outError[0] != null) {
3484 return;
3485 }
3486
3487 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003488 CharSequence pname;
3489 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3490 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3491 } else {
3492 // Some older apps have been seen to use a resource reference
3493 // here that on older builds was ignored (with a warning). We
3494 // need to continue to do this for them so they don't break.
3495 pname = args.sa.getNonResourceString(args.processRes);
3496 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003497 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003498 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003499 args.flags, args.sepProcesses, args.outError);
3500 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003501
3502 if (args.descriptionRes != 0) {
3503 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3504 }
3505
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003506 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 }
3508
3509 public Component(Component<II> clone) {
3510 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003511 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003512 className = clone.className;
3513 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003514 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003515 }
3516
3517 public ComponentName getComponentName() {
3518 if (componentName != null) {
3519 return componentName;
3520 }
3521 if (className != null) {
3522 componentName = new ComponentName(owner.applicationInfo.packageName,
3523 className);
3524 }
3525 return componentName;
3526 }
3527
3528 public String getComponentShortName() {
3529 if (componentShortName != null) {
3530 return componentShortName;
3531 }
3532 ComponentName component = getComponentName();
3533 if (component != null) {
3534 componentShortName = component.flattenToShortString();
3535 }
3536 return componentShortName;
3537 }
3538
3539 public void setPackageName(String packageName) {
3540 componentName = null;
3541 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 }
3543 }
3544
3545 public final static class Permission extends Component<IntentInfo> {
3546 public final PermissionInfo info;
3547 public boolean tree;
3548 public PermissionGroup group;
3549
3550 public Permission(Package _owner) {
3551 super(_owner);
3552 info = new PermissionInfo();
3553 }
3554
3555 public Permission(Package _owner, PermissionInfo _info) {
3556 super(_owner);
3557 info = _info;
3558 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003559
3560 public void setPackageName(String packageName) {
3561 super.setPackageName(packageName);
3562 info.packageName = packageName;
3563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564
3565 public String toString() {
3566 return "Permission{"
3567 + Integer.toHexString(System.identityHashCode(this))
3568 + " " + info.name + "}";
3569 }
3570 }
3571
3572 public final static class PermissionGroup extends Component<IntentInfo> {
3573 public final PermissionGroupInfo info;
3574
3575 public PermissionGroup(Package _owner) {
3576 super(_owner);
3577 info = new PermissionGroupInfo();
3578 }
3579
3580 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3581 super(_owner);
3582 info = _info;
3583 }
3584
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003585 public void setPackageName(String packageName) {
3586 super.setPackageName(packageName);
3587 info.packageName = packageName;
3588 }
3589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 public String toString() {
3591 return "PermissionGroup{"
3592 + Integer.toHexString(System.identityHashCode(this))
3593 + " " + info.name + "}";
3594 }
3595 }
3596
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003597 private static boolean copyNeeded(int flags, Package p,
3598 PackageUserState state, Bundle metaData, int userId) {
3599 if (userId != 0) {
3600 // We always need to copy for other users, since we need
3601 // to fix up the uid.
3602 return true;
3603 }
3604 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3605 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003606 if (p.applicationInfo.enabled != enabled) {
3607 return true;
3608 }
3609 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003610 if (!state.installed) {
3611 return true;
3612 }
3613 if (state.stopped) {
3614 return true;
3615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 if ((flags & PackageManager.GET_META_DATA) != 0
3617 && (metaData != null || p.mAppMetaData != null)) {
3618 return true;
3619 }
3620 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3621 && p.usesLibraryFiles != null) {
3622 return true;
3623 }
3624 return false;
3625 }
3626
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003627 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3628 PackageUserState state) {
3629 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003630 }
3631
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003632 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3633 PackageUserState state) {
3634 // CompatibilityMode is global state.
3635 if (!sCompatibilityModeEnabled) {
3636 ai.disableCompatibilityMode();
3637 }
3638 if (state.installed) {
3639 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3640 } else {
3641 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3642 }
3643 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3644 ai.enabled = true;
3645 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3646 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3647 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3648 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3649 ai.enabled = false;
3650 }
3651 ai.enabledSetting = state.enabled;
3652 }
3653
Amith Yamasani13593602012-03-22 16:16:17 -07003654 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003655 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003657 if (!checkUseInstalled(flags, state)) {
3658 return null;
3659 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003660 if (!copyNeeded(flags, p, state, null, userId)
3661 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3662 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3663 // In this case it is safe to directly modify the internal ApplicationInfo state:
3664 // - CompatibilityMode is global state, so will be the same for every call.
3665 // - We only come in to here if the app should reported as installed; this is the
3666 // default state, and we will do a copy otherwise.
3667 // - The enable state will always be reported the same for the application across
3668 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3669 // be doing a copy.
3670 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 return p.applicationInfo;
3672 }
3673
3674 // Make shallow copy so we can store the metadata/libraries safely
3675 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003676 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003677 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003678 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 if ((flags & PackageManager.GET_META_DATA) != 0) {
3681 ai.metaData = p.mAppMetaData;
3682 }
3683 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3684 ai.sharedLibraryFiles = p.usesLibraryFiles;
3685 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003686 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003687 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003688 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003689 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003690 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003691 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 return ai;
3693 }
3694
3695 public static final PermissionInfo generatePermissionInfo(
3696 Permission p, int flags) {
3697 if (p == null) return null;
3698 if ((flags&PackageManager.GET_META_DATA) == 0) {
3699 return p.info;
3700 }
3701 PermissionInfo pi = new PermissionInfo(p.info);
3702 pi.metaData = p.metaData;
3703 return pi;
3704 }
3705
3706 public static final PermissionGroupInfo generatePermissionGroupInfo(
3707 PermissionGroup pg, int flags) {
3708 if (pg == null) return null;
3709 if ((flags&PackageManager.GET_META_DATA) == 0) {
3710 return pg.info;
3711 }
3712 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3713 pgi.metaData = pg.metaData;
3714 return pgi;
3715 }
3716
3717 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003718 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003720 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3721 super(args, _info);
3722 info = _info;
3723 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003725
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003726 public void setPackageName(String packageName) {
3727 super.setPackageName(packageName);
3728 info.packageName = packageName;
3729 }
3730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 public String toString() {
3732 return "Activity{"
3733 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003734 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 }
3736 }
3737
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003738 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3739 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003741 if (!checkUseInstalled(flags, state)) {
3742 return null;
3743 }
3744 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 return a.info;
3746 }
3747 // Make shallow copies so we can store the metadata safely
3748 ActivityInfo ai = new ActivityInfo(a.info);
3749 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003750 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 return ai;
3752 }
3753
3754 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003755 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003757 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3758 super(args, _info);
3759 info = _info;
3760 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003762
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003763 public void setPackageName(String packageName) {
3764 super.setPackageName(packageName);
3765 info.packageName = packageName;
3766 }
3767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 public String toString() {
3769 return "Service{"
3770 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003771 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 }
3773 }
3774
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003775 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3776 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003778 if (!checkUseInstalled(flags, state)) {
3779 return null;
3780 }
3781 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 return s.info;
3783 }
3784 // Make shallow copies so we can store the metadata safely
3785 ServiceInfo si = new ServiceInfo(s.info);
3786 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003787 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 return si;
3789 }
3790
3791 public final static class Provider extends Component {
3792 public final ProviderInfo info;
3793 public boolean syncable;
3794
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003795 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3796 super(args, _info);
3797 info = _info;
3798 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 syncable = false;
3800 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 public Provider(Provider existingProvider) {
3803 super(existingProvider);
3804 this.info = existingProvider.info;
3805 this.syncable = existingProvider.syncable;
3806 }
3807
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003808 public void setPackageName(String packageName) {
3809 super.setPackageName(packageName);
3810 info.packageName = packageName;
3811 }
3812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 public String toString() {
3814 return "Provider{"
3815 + Integer.toHexString(System.identityHashCode(this))
3816 + " " + info.name + "}";
3817 }
3818 }
3819
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003820 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3821 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003823 if (!checkUseInstalled(flags, state)) {
3824 return null;
3825 }
3826 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003828 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 return p.info;
3830 }
3831 // Make shallow copies so we can store the metadata safely
3832 ProviderInfo pi = new ProviderInfo(p.info);
3833 pi.metaData = p.metaData;
3834 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3835 pi.uriPermissionPatterns = null;
3836 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003837 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 return pi;
3839 }
3840
3841 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003842 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003844 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3845 super(args, _info);
3846 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003848
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003849 public void setPackageName(String packageName) {
3850 super.setPackageName(packageName);
3851 info.packageName = packageName;
3852 }
3853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854 public String toString() {
3855 return "Instrumentation{"
3856 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003857 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 }
3859 }
3860
3861 public static final InstrumentationInfo generateInstrumentationInfo(
3862 Instrumentation i, int flags) {
3863 if (i == null) return null;
3864 if ((flags&PackageManager.GET_META_DATA) == 0) {
3865 return i.info;
3866 }
3867 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3868 ii.metaData = i.metaData;
3869 return ii;
3870 }
3871
3872 public static class IntentInfo extends IntentFilter {
3873 public boolean hasDefault;
3874 public int labelRes;
3875 public CharSequence nonLocalizedLabel;
3876 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003877 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 }
3879
3880 public final static class ActivityIntentInfo extends IntentInfo {
3881 public final Activity activity;
3882
3883 public ActivityIntentInfo(Activity _activity) {
3884 activity = _activity;
3885 }
3886
3887 public String toString() {
3888 return "ActivityIntentInfo{"
3889 + Integer.toHexString(System.identityHashCode(this))
3890 + " " + activity.info.name + "}";
3891 }
3892 }
3893
3894 public final static class ServiceIntentInfo extends IntentInfo {
3895 public final Service service;
3896
3897 public ServiceIntentInfo(Service _service) {
3898 service = _service;
3899 }
3900
3901 public String toString() {
3902 return "ServiceIntentInfo{"
3903 + Integer.toHexString(System.identityHashCode(this))
3904 + " " + service.info.name + "}";
3905 }
3906 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003907
3908 /**
3909 * @hide
3910 */
3911 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3912 sCompatibilityModeEnabled = compatibilityModeEnabled;
3913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914}