blob: 8893538d629a280a2d96e621dad4b1f60af59515 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IntentFilter;
22import android.content.res.AssetManager;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.content.res.XmlResourceParser;
Amith Yamasani742a6712011-05-04 14:49:28 -070027import android.os.Binder;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070028import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Bundle;
30import android.os.PatternMatcher;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070031import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070033import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070035import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070036import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kenny Rootd63f7db2010-09-27 08:07:48 -070039import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Kenny Rootbcc954d2011-08-08 16:19:08 -070057import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.jar.JarEntry;
59import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070060import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Amith Yamasani742a6712011-05-04 14:49:28 -070062import com.android.internal.util.XmlUtils;
63
64import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
68 * Package archive parsing
69 *
70 * {@hide}
71 */
72public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070073 private static final boolean DEBUG_JAR = false;
74 private static final boolean DEBUG_PARSER = false;
75 private static final boolean DEBUG_BACKUP = false;
76
Kenny Rootbcc954d2011-08-08 16:19:08 -070077 /** File name in an APK for the Android manifest. */
78 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
79
Dianne Hackborna96cbb42009-05-13 15:06:13 -070080 /** @hide */
81 public static class NewPermissionInfo {
82 public final String name;
83 public final int sdkVersion;
84 public final int fileVersion;
85
86 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
87 this.name = name;
88 this.sdkVersion = sdkVersion;
89 this.fileVersion = fileVersion;
90 }
91 }
Dianne Hackborn79245122012-03-12 10:51:26 -070092
93 /** @hide */
94 public static class SplitPermissionInfo {
95 public final String rootPerm;
96 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070098
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700100 this.rootPerm = rootPerm;
101 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700102 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700103 }
104 }
105
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700106 /**
107 * List of new permissions that have been added since 1.0.
108 * NOTE: These must be declared in SDK version order, with permissions
109 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700110 * If sdkVersion is 0, then this is not a permission that we want to
111 * automatically add to older apps, but we do want to allow it to be
112 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700113 * @hide
114 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700115 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
116 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700117 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700118 android.os.Build.VERSION_CODES.DONUT, 0),
119 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
120 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700121 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Dianne Hackborn79245122012-03-12 10:51:26 -0700123 /**
124 * List of permissions that have been split into more granular or dependent
125 * permissions.
126 * @hide
127 */
128 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
129 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700130 // READ_EXTERNAL_STORAGE is always required when an app requests
131 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
132 // write access without read access. The hack here with the target
133 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700134 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700135 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700136 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700137 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
138 new String[] { android.Manifest.permission.READ_CALL_LOG },
139 android.os.Build.VERSION_CODES.JELLY_BEAN),
140 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
141 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
142 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700143 };
144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 private String mArchiveSourcePath;
146 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700147 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700148 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
149 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
150 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151
152 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
153
154 private static final Object mSync = new Object();
155 private static WeakReference<byte[]> mReadBuffer;
156
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700157 private static boolean sCompatibilityModeEnabled = true;
158 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700159
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700160 static class ParsePackageItemArgs {
161 final Package owner;
162 final String[] outError;
163 final int nameRes;
164 final int labelRes;
165 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700166 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700167
168 String tag;
169 TypedArray sa;
170
171 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700172 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700173 owner = _owner;
174 outError = _outError;
175 nameRes = _nameRes;
176 labelRes = _labelRes;
177 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700178 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700179 }
180 }
181
182 static class ParseComponentArgs extends ParsePackageItemArgs {
183 final String[] sepProcesses;
184 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800185 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700186 final int enabledRes;
187 int flags;
188
189 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700190 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800191 String[] _sepProcesses, int _processRes,
192 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700193 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700194 sepProcesses = _sepProcesses;
195 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800196 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700197 enabledRes = _enabledRes;
198 }
199 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800200
201 /* Light weight package info.
202 * @hide
203 */
204 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700205 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700206 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700207 public final int installLocation;
208 public final VerifierInfo[] verifiers;
209
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700210 public PackageLite(String packageName, int versionCode,
211 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800212 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700213 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800214 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700215 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800216 }
217 }
218
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700219 private ParsePackageItemArgs mParseInstrumentationArgs;
220 private ParseComponentArgs mParseActivityArgs;
221 private ParseComponentArgs mParseActivityAliasArgs;
222 private ParseComponentArgs mParseServiceArgs;
223 private ParseComponentArgs mParseProviderArgs;
224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 /** If set to true, we will only allow package files that exactly match
226 * the DTD. Otherwise, we try to get as much from the package as we
227 * can without failing. This should normally be set to false, to
228 * support extensions to the DTD in future versions. */
229 private static final boolean RIGID_PARSER = false;
230
231 private static final String TAG = "PackageParser";
232
233 public PackageParser(String archiveSourcePath) {
234 mArchiveSourcePath = archiveSourcePath;
235 }
236
237 public void setSeparateProcesses(String[] procs) {
238 mSeparateProcesses = procs;
239 }
240
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700241 public void setOnlyCoreApps(boolean onlyCoreApps) {
242 mOnlyCoreApps = onlyCoreApps;
243 }
244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 private static final boolean isPackageFilename(String name) {
246 return name.endsWith(".apk");
247 }
248
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700249 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700250 public static PackageInfo generatePackageInfo(PackageParser.Package p,
251 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
252 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700253 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700254 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700255 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700256 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700257 */
Amith Yamasani13593602012-03-22 16:16:17 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * Generate and return the {@link PackageInfo} for a parsed package.
261 *
262 * @param p the parsed package.
263 * @param flags indicating which optional information is included.
264 */
265 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800266 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700267 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268
Amith Yamasani483f3b02012-03-13 16:08:00 -0700269 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700270 grantedPermissions, state, UserHandle.getCallingUserId());
271 }
272
273 private static boolean checkUseInstalled(int flags, PackageUserState state) {
274 return state.installed || ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700275 }
276
Amith Yamasani13593602012-03-22 16:16:17 -0700277 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700278 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700279 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700280
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700281 if (!checkUseInstalled(flags, state)) {
282 return null;
283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 PackageInfo pi = new PackageInfo();
285 pi.packageName = p.packageName;
286 pi.versionCode = p.mVersionCode;
287 pi.versionName = p.mVersionName;
288 pi.sharedUserId = p.mSharedUserId;
289 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700290 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800291 pi.installLocation = p.installLocation;
Amith Yamasanidf2e92a2013-03-01 17:04:38 -0800292 pi.requiredForAllUsers = p.mRequiredForAllUsers;
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700293 pi.restrictedAccountType = p.mRestrictedAccountType;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700294 pi.firstInstallTime = firstInstallTime;
295 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 if ((flags&PackageManager.GET_GIDS) != 0) {
297 pi.gids = gids;
298 }
299 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
300 int N = p.configPreferences.size();
301 if (N > 0) {
302 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700303 p.configPreferences.toArray(pi.configPreferences);
304 }
305 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
306 if (N > 0) {
307 pi.reqFeatures = new FeatureInfo[N];
308 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
310 }
311 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
312 int N = p.activities.size();
313 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700314 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
315 pi.activities = new ActivityInfo[N];
316 } else {
317 int num = 0;
318 for (int i=0; i<N; i++) {
319 if (p.activities.get(i).info.enabled) num++;
320 }
321 pi.activities = new ActivityInfo[num];
322 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700323 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 final Activity activity = p.activities.get(i);
325 if (activity.info.enabled
326 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700327 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700328 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 }
330 }
331 }
332 }
333 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
334 int N = p.receivers.size();
335 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700336 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
337 pi.receivers = new ActivityInfo[N];
338 } else {
339 int num = 0;
340 for (int i=0; i<N; i++) {
341 if (p.receivers.get(i).info.enabled) num++;
342 }
343 pi.receivers = new ActivityInfo[num];
344 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700345 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 final Activity activity = p.receivers.get(i);
347 if (activity.info.enabled
348 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700349 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700350 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
352 }
353 }
354 }
355 if ((flags&PackageManager.GET_SERVICES) != 0) {
356 int N = p.services.size();
357 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700358 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
359 pi.services = new ServiceInfo[N];
360 } else {
361 int num = 0;
362 for (int i=0; i<N; i++) {
363 if (p.services.get(i).info.enabled) num++;
364 }
365 pi.services = new ServiceInfo[num];
366 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700367 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 final Service service = p.services.get(i);
369 if (service.info.enabled
370 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700371 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
372 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 }
374 }
375 }
376 }
377 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
378 int N = p.providers.size();
379 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700380 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
381 pi.providers = new ProviderInfo[N];
382 } else {
383 int num = 0;
384 for (int i=0; i<N; i++) {
385 if (p.providers.get(i).info.enabled) num++;
386 }
387 pi.providers = new ProviderInfo[num];
388 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700389 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 final Provider provider = p.providers.get(i);
391 if (provider.info.enabled
392 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700393 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
394 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 }
396 }
397 }
398 }
399 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
400 int N = p.instrumentation.size();
401 if (N > 0) {
402 pi.instrumentation = new InstrumentationInfo[N];
403 for (int i=0; i<N; i++) {
404 pi.instrumentation[i] = generateInstrumentationInfo(
405 p.instrumentation.get(i), flags);
406 }
407 }
408 }
409 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
410 int N = p.permissions.size();
411 if (N > 0) {
412 pi.permissions = new PermissionInfo[N];
413 for (int i=0; i<N; i++) {
414 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
415 }
416 }
417 N = p.requestedPermissions.size();
418 if (N > 0) {
419 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800420 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800422 final String perm = p.requestedPermissions.get(i);
423 pi.requestedPermissions[i] = perm;
424 if (p.requestedPermissionsRequired.get(i)) {
425 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
426 }
427 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
428 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 }
431 }
432 }
433 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700434 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
435 if (N > 0) {
436 pi.signatures = new Signature[N];
437 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 }
439 }
440 return pi;
441 }
442
443 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
444 byte[] readBuffer) {
445 try {
446 // We must read the stream for the JarEntry to retrieve
447 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700448 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
450 // not using
451 }
452 is.close();
453 return je != null ? je.getCertificates() : null;
454 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700455 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700457 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700458 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700459 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 }
461 return null;
462 }
463
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800464 public final static int PARSE_IS_SYSTEM = 1<<0;
465 public final static int PARSE_CHATTY = 1<<1;
466 public final static int PARSE_MUST_BE_APK = 1<<2;
467 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
468 public final static int PARSE_FORWARD_LOCK = 1<<4;
469 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700470 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471
472 public int getParseError() {
473 return mParseError;
474 }
475
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800476 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 DisplayMetrics metrics, int flags) {
478 mParseError = PackageManager.INSTALL_SUCCEEDED;
479
480 mArchiveSourcePath = sourceFile.getPath();
481 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700482 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
484 return null;
485 }
486 if (!isPackageFilename(sourceFile.getName())
487 && (flags&PARSE_MUST_BE_APK) != 0) {
488 if ((flags&PARSE_IS_SYSTEM) == 0) {
489 // We expect to have non-.apk files in the system dir,
490 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700491 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 }
493 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
494 return null;
495 }
496
Kenny Rootd2d29252011-08-08 11:27:57 -0700497 if (DEBUG_JAR)
498 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499
500 XmlResourceParser parser = null;
501 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800502 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 boolean assetError = true;
504 try {
505 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700506 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800507 if (cookie != 0) {
508 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700509 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 -0800510 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700511 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 assetError = false;
513 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700514 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 }
516 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700517 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 + mArchiveSourcePath, e);
519 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800520 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 if (assmgr != null) assmgr.close();
522 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
523 return null;
524 }
525 String[] errorText = new String[1];
526 Package pkg = null;
527 Exception errorException = null;
528 try {
529 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 pkg = parsePackage(res, parser, flags, errorText);
531 } catch (Exception e) {
532 errorException = e;
533 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
534 }
535
536
537 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700538 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
539 // just means to skip this app so don't make a fuss about it.
540 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
541 if (errorException != null) {
542 Slog.w(TAG, mArchiveSourcePath, errorException);
543 } else {
544 Slog.w(TAG, mArchiveSourcePath + " (at "
545 + parser.getPositionDescription()
546 + "): " + errorText[0]);
547 }
548 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
549 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
552 parser.close();
553 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 return null;
555 }
556
557 parser.close();
558 assmgr.close();
559
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800560 // Set code and resource paths
561 pkg.mPath = destCodePath;
562 pkg.mScanPath = mArchiveSourcePath;
563 //pkg.applicationInfo.sourceDir = destCodePath;
564 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 pkg.mSignatures = null;
566
567 return pkg;
568 }
569
570 public boolean collectCertificates(Package pkg, int flags) {
571 pkg.mSignatures = null;
572
573 WeakReference<byte[]> readBufferRef;
574 byte[] readBuffer = null;
575 synchronized (mSync) {
576 readBufferRef = mReadBuffer;
577 if (readBufferRef != null) {
578 mReadBuffer = null;
579 readBuffer = readBufferRef.get();
580 }
581 if (readBuffer == null) {
582 readBuffer = new byte[8192];
583 readBufferRef = new WeakReference<byte[]>(readBuffer);
584 }
585 }
586
587 try {
588 JarFile jarFile = new JarFile(mArchiveSourcePath);
589
590 Certificate[] certs = null;
591
592 if ((flags&PARSE_IS_SYSTEM) != 0) {
593 // If this package comes from the system image, then we
594 // can trust it... we'll just use the AndroidManifest.xml
595 // to retrieve its signatures, not validating all of the
596 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700597 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 certs = loadCertificates(jarFile, jarEntry, readBuffer);
599 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700600 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 + " has no certificates at entry "
602 + jarEntry.getName() + "; ignoring!");
603 jarFile.close();
604 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
605 return false;
606 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700607 if (DEBUG_JAR) {
608 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 + " certs=" + (certs != null ? certs.length : 0));
610 if (certs != null) {
611 final int N = certs.length;
612 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700613 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 + certs[i].getPublicKey().getEncoded()
615 + " " + certs[i].getPublicKey());
616 }
617 }
618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700620 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700621 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700623 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700625
Kenny Rootbcc954d2011-08-08 16:19:08 -0700626 final String name = je.getName();
627
628 if (name.startsWith("META-INF/"))
629 continue;
630
631 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
632 final Attributes attributes = manifest.getAttributes(name);
633 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
634 }
635
636 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700637 if (DEBUG_JAR) {
638 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 + ": certs=" + certs + " ("
640 + (certs != null ? certs.length : 0) + ")");
641 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700644 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 + " has no certificates at entry "
646 + je.getName() + "; ignoring!");
647 jarFile.close();
648 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
649 return false;
650 } else if (certs == null) {
651 certs = localCerts;
652 } else {
653 // Ensure all certificates match.
654 for (int i=0; i<certs.length; i++) {
655 boolean found = false;
656 for (int j=0; j<localCerts.length; j++) {
657 if (certs[i] != null &&
658 certs[i].equals(localCerts[j])) {
659 found = true;
660 break;
661 }
662 }
663 if (!found || certs.length != localCerts.length) {
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 mismatched certificates at entry "
666 + je.getName() + "; ignoring!");
667 jarFile.close();
668 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
669 return false;
670 }
671 }
672 }
673 }
674 }
675 jarFile.close();
676
677 synchronized (mSync) {
678 mReadBuffer = readBufferRef;
679 }
680
681 if (certs != null && certs.length > 0) {
682 final int N = certs.length;
683 pkg.mSignatures = new Signature[certs.length];
684 for (int i=0; i<N; i++) {
685 pkg.mSignatures[i] = new Signature(
686 certs[i].getEncoded());
687 }
688 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700689 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 + " has no certificates; ignoring!");
691 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
692 return false;
693 }
694 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700695 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
697 return false;
698 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700699 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
701 return false;
702 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700703 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
705 return false;
706 }
707
708 return true;
709 }
710
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800711 /*
712 * Utility method that retrieves just the package name and install
713 * location from the apk location at the given file path.
714 * @param packageFilePath file location of the apk
715 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700716 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800717 */
718 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700720 final XmlResourceParser parser;
721 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 try {
723 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700724 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 -0800725 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700728 if (cookie == 0) {
729 return null;
730 }
731
Kenny Root05ca4c92011-09-15 10:36:25 -0700732 final DisplayMetrics metrics = new DisplayMetrics();
733 metrics.setToDefaults();
734 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700735 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 } catch (Exception e) {
737 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700738 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 + packageFilePath, e);
740 return null;
741 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700742
743 final AttributeSet attrs = parser;
744 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800745 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700747 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700749 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700751 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 } finally {
753 if (parser != null) parser.close();
754 if (assmgr != null) assmgr.close();
755 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800756 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700757 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 return null;
759 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800760 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762
763 private static String validateName(String name, boolean requiresSeparator) {
764 final int N = name.length();
765 boolean hasSep = false;
766 boolean front = true;
767 for (int i=0; i<N; i++) {
768 final char c = name.charAt(i);
769 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
770 front = false;
771 continue;
772 }
773 if (!front) {
774 if ((c >= '0' && c <= '9') || c == '_') {
775 continue;
776 }
777 }
778 if (c == '.') {
779 hasSep = true;
780 front = true;
781 continue;
782 }
783 return "bad character '" + c + "'";
784 }
785 return hasSep || !requiresSeparator
786 ? null : "must have at least one '.' separator";
787 }
788
789 private static String parsePackageName(XmlPullParser parser,
790 AttributeSet attrs, int flags, String[] outError)
791 throws IOException, XmlPullParserException {
792
793 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700794 while ((type = parser.next()) != XmlPullParser.START_TAG
795 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 ;
797 }
798
Kenny Rootd2d29252011-08-08 11:27:57 -0700799 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 outError[0] = "No start tag found";
801 return null;
802 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700803 if (DEBUG_PARSER)
804 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 if (!parser.getName().equals("manifest")) {
806 outError[0] = "No <manifest> tag";
807 return null;
808 }
809 String pkgName = attrs.getAttributeValue(null, "package");
810 if (pkgName == null || pkgName.length() == 0) {
811 outError[0] = "<manifest> does not specify package";
812 return null;
813 }
814 String nameError = validateName(pkgName, true);
815 if (nameError != null && !"android".equals(pkgName)) {
816 outError[0] = "<manifest> specifies bad package name \""
817 + pkgName + "\": " + nameError;
818 return null;
819 }
820
821 return pkgName.intern();
822 }
823
Kenny Root05ca4c92011-09-15 10:36:25 -0700824 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
825 AttributeSet attrs, int flags, String[] outError) throws IOException,
826 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800827
828 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700829 while ((type = parser.next()) != XmlPullParser.START_TAG
830 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800831 ;
832 }
833
Kenny Rootd2d29252011-08-08 11:27:57 -0700834 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800835 outError[0] = "No start tag found";
836 return null;
837 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700838 if (DEBUG_PARSER)
839 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800840 if (!parser.getName().equals("manifest")) {
841 outError[0] = "No <manifest> tag";
842 return null;
843 }
844 String pkgName = attrs.getAttributeValue(null, "package");
845 if (pkgName == null || pkgName.length() == 0) {
846 outError[0] = "<manifest> does not specify package";
847 return null;
848 }
849 String nameError = validateName(pkgName, true);
850 if (nameError != null && !"android".equals(pkgName)) {
851 outError[0] = "<manifest> specifies bad package name \""
852 + pkgName + "\": " + nameError;
853 return null;
854 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700855 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700856 int versionCode = 0;
857 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800858 for (int i = 0; i < attrs.getAttributeCount(); i++) {
859 String attr = attrs.getAttributeName(i);
860 if (attr.equals("installLocation")) {
861 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700862 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700863 numFound++;
864 } else if (attr.equals("versionCode")) {
865 versionCode = attrs.getAttributeIntValue(i, 0);
866 numFound++;
867 }
868 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800869 break;
870 }
871 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700872
873 // Only search the tree when the tag is directly below <manifest>
874 final int searchDepth = parser.getDepth() + 1;
875
876 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
877 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
878 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
879 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
880 continue;
881 }
882
883 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
884 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
885 if (verifier != null) {
886 verifiers.add(verifier);
887 }
888 }
889 }
890
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700891 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800892 }
893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 /**
895 * Temporary.
896 */
897 static public Signature stringToSignature(String str) {
898 final int N = str.length();
899 byte[] sig = new byte[N];
900 for (int i=0; i<N; i++) {
901 sig[i] = (byte)str.charAt(i);
902 }
903 return new Signature(sig);
904 }
905
906 private Package parsePackage(
907 Resources res, XmlResourceParser parser, int flags, String[] outError)
908 throws XmlPullParserException, IOException {
909 AttributeSet attrs = parser;
910
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700911 mParseInstrumentationArgs = null;
912 mParseActivityArgs = null;
913 mParseServiceArgs = null;
914 mParseProviderArgs = null;
915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 String pkgName = parsePackageName(parser, attrs, flags, outError);
917 if (pkgName == null) {
918 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
919 return null;
920 }
921 int type;
922
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700923 if (mOnlyCoreApps) {
924 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
925 if (!core) {
926 mParseError = PackageManager.INSTALL_SUCCEEDED;
927 return null;
928 }
929 }
930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 TypedArray sa = res.obtainAttributes(attrs,
935 com.android.internal.R.styleable.AndroidManifest);
936 pkg.mVersionCode = sa.getInteger(
937 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800938 pkg.mVersionName = sa.getNonConfigurationString(
939 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 if (pkg.mVersionName != null) {
941 pkg.mVersionName = pkg.mVersionName.intern();
942 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800943 String str = sa.getNonConfigurationString(
944 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
945 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 String nameError = validateName(str, true);
947 if (nameError != null && !"android".equals(pkgName)) {
948 outError[0] = "<manifest> specifies bad sharedUserId name \""
949 + str + "\": " + nameError;
950 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
951 return null;
952 }
953 pkg.mSharedUserId = str.intern();
954 pkg.mSharedUserLabel = sa.getResourceId(
955 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
956 }
957 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800958
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800959 pkg.installLocation = sa.getInteger(
960 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700961 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700962 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700963
964 /* Set the global "forward lock" flag */
965 if ((flags & PARSE_FORWARD_LOCK) != 0) {
966 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
967 }
968
969 /* Set the global "on SD card" flag */
970 if ((flags & PARSE_ON_SDCARD) != 0) {
971 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
972 }
973
Dianne Hackborn723738c2009-06-25 19:48:04 -0700974 // Resource boolean are -1, so 1 means we don't know the value.
975 int supportsSmallScreens = 1;
976 int supportsNormalScreens = 1;
977 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700978 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700979 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700980 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700983 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
984 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
985 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 continue;
987 }
988
989 String tagName = parser.getName();
990 if (tagName.equals("application")) {
991 if (foundApp) {
992 if (RIGID_PARSER) {
993 outError[0] = "<manifest> has more than one <application>";
994 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
995 return null;
996 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700997 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 XmlUtils.skipCurrentTag(parser);
999 continue;
1000 }
1001 }
1002
1003 foundApp = true;
1004 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1005 return null;
1006 }
1007 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001008 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 return null;
1010 }
1011 } else if (tagName.equals("permission")) {
1012 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1013 return null;
1014 }
1015 } else if (tagName.equals("permission-tree")) {
1016 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1017 return null;
1018 }
1019 } else if (tagName.equals("uses-permission")) {
1020 sa = res.obtainAttributes(attrs,
1021 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1022
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001023 // Note: don't allow this value to be a reference to a resource
1024 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 String name = sa.getNonResourceString(
1026 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne8241202012-04-06 13:39:09 -07001027 /* Not supporting optional permissions yet.
Dianne Hackborne639da72012-02-21 15:11:13 -08001028 boolean required = sa.getBoolean(
1029 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Dianne Hackborne8241202012-04-06 13:39:09 -07001030 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031
1032 sa.recycle();
1033
1034 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -07001035 pkg.requestedPermissions.add(name.intern());
Dianne Hackborne8241202012-04-06 13:39:09 -07001036 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 }
1038
1039 XmlUtils.skipCurrentTag(parser);
1040
1041 } else if (tagName.equals("uses-configuration")) {
1042 ConfigurationInfo cPref = new ConfigurationInfo();
1043 sa = res.obtainAttributes(attrs,
1044 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1045 cPref.reqTouchScreen = sa.getInt(
1046 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1047 Configuration.TOUCHSCREEN_UNDEFINED);
1048 cPref.reqKeyboardType = sa.getInt(
1049 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1050 Configuration.KEYBOARD_UNDEFINED);
1051 if (sa.getBoolean(
1052 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1053 false)) {
1054 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1055 }
1056 cPref.reqNavigation = sa.getInt(
1057 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1058 Configuration.NAVIGATION_UNDEFINED);
1059 if (sa.getBoolean(
1060 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1061 false)) {
1062 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1063 }
1064 sa.recycle();
1065 pkg.configPreferences.add(cPref);
1066
1067 XmlUtils.skipCurrentTag(parser);
1068
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001069 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001070 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001071 sa = res.obtainAttributes(attrs,
1072 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001073 // Note: don't allow this value to be a reference to a resource
1074 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001075 fi.name = sa.getNonResourceString(
1076 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1077 if (fi.name == null) {
1078 fi.reqGlEsVersion = sa.getInt(
1079 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1080 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1081 }
1082 if (sa.getBoolean(
1083 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1084 true)) {
1085 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1086 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001087 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001088 if (pkg.reqFeatures == null) {
1089 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1090 }
1091 pkg.reqFeatures.add(fi);
1092
1093 if (fi.name == null) {
1094 ConfigurationInfo cPref = new ConfigurationInfo();
1095 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1096 pkg.configPreferences.add(cPref);
1097 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001098
1099 XmlUtils.skipCurrentTag(parser);
1100
Dianne Hackborn851a5412009-05-08 12:06:44 -07001101 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001102 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 sa = res.obtainAttributes(attrs,
1104 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1105
Dianne Hackborn851a5412009-05-08 12:06:44 -07001106 int minVers = 0;
1107 String minCode = null;
1108 int targetVers = 0;
1109 String targetCode = null;
1110
1111 TypedValue val = sa.peekValue(
1112 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1113 if (val != null) {
1114 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1115 targetCode = minCode = val.string.toString();
1116 } else {
1117 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001118 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001119 }
1120 }
1121
1122 val = sa.peekValue(
1123 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1124 if (val != null) {
1125 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1126 targetCode = minCode = val.string.toString();
1127 } else {
1128 // If it's not a string, it's an integer.
1129 targetVers = val.data;
1130 }
1131 }
1132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 sa.recycle();
1134
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001135 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001136 if (!minCode.equals(SDK_CODENAME)) {
1137 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001138 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001139 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001140 } else {
1141 outError[0] = "Requires development platform " + minCode
1142 + " but this is a release platform.";
1143 }
1144 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1145 return null;
1146 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001147 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001148 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001149 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001150 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1151 return null;
1152 }
1153
Dianne Hackborn851a5412009-05-08 12:06:44 -07001154 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001155 if (!targetCode.equals(SDK_CODENAME)) {
1156 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001157 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001158 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001159 } else {
1160 outError[0] = "Requires development platform " + targetCode
1161 + " but this is a release platform.";
1162 }
1163 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1164 return null;
1165 }
1166 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001167 pkg.applicationInfo.targetSdkVersion
1168 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1169 } else {
1170 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001171 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 }
1173
1174 XmlUtils.skipCurrentTag(parser);
1175
Dianne Hackborn723738c2009-06-25 19:48:04 -07001176 } else if (tagName.equals("supports-screens")) {
1177 sa = res.obtainAttributes(attrs,
1178 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1179
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001180 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1181 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1182 0);
1183 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1184 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1185 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001186 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1187 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1188 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001189
Dianne Hackborn723738c2009-06-25 19:48:04 -07001190 // This is a trick to get a boolean and still able to detect
1191 // if a value was actually set.
1192 supportsSmallScreens = sa.getInteger(
1193 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1194 supportsSmallScreens);
1195 supportsNormalScreens = sa.getInteger(
1196 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1197 supportsNormalScreens);
1198 supportsLargeScreens = sa.getInteger(
1199 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1200 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001201 supportsXLargeScreens = sa.getInteger(
1202 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1203 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001204 resizeable = sa.getInteger(
1205 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001206 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001207 anyDensity = sa.getInteger(
1208 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1209 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001210
1211 sa.recycle();
1212
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001213 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001214
1215 } else if (tagName.equals("protected-broadcast")) {
1216 sa = res.obtainAttributes(attrs,
1217 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1218
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001219 // Note: don't allow this value to be a reference to a resource
1220 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001221 String name = sa.getNonResourceString(
1222 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1223
1224 sa.recycle();
1225
1226 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1227 if (pkg.protectedBroadcasts == null) {
1228 pkg.protectedBroadcasts = new ArrayList<String>();
1229 }
1230 if (!pkg.protectedBroadcasts.contains(name)) {
1231 pkg.protectedBroadcasts.add(name.intern());
1232 }
1233 }
1234
1235 XmlUtils.skipCurrentTag(parser);
1236
1237 } else if (tagName.equals("instrumentation")) {
1238 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1239 return null;
1240 }
1241
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001242 } else if (tagName.equals("original-package")) {
1243 sa = res.obtainAttributes(attrs,
1244 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1245
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001246 String orig =sa.getNonConfigurationString(
1247 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001248 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001249 if (pkg.mOriginalPackages == null) {
1250 pkg.mOriginalPackages = new ArrayList<String>();
1251 pkg.mRealPackage = pkg.packageName;
1252 }
1253 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001254 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001255
1256 sa.recycle();
1257
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001258 XmlUtils.skipCurrentTag(parser);
1259
1260 } else if (tagName.equals("adopt-permissions")) {
1261 sa = res.obtainAttributes(attrs,
1262 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1263
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001264 String name = sa.getNonConfigurationString(
1265 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001266
1267 sa.recycle();
1268
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001269 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001270 if (pkg.mAdoptPermissions == null) {
1271 pkg.mAdoptPermissions = new ArrayList<String>();
1272 }
1273 pkg.mAdoptPermissions.add(name);
1274 }
1275
1276 XmlUtils.skipCurrentTag(parser);
1277
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001278 } else if (tagName.equals("uses-gl-texture")) {
1279 // Just skip this tag
1280 XmlUtils.skipCurrentTag(parser);
1281 continue;
1282
1283 } else if (tagName.equals("compatible-screens")) {
1284 // Just skip this tag
1285 XmlUtils.skipCurrentTag(parser);
1286 continue;
1287
Dianne Hackborn854060a2009-07-09 18:14:31 -07001288 } else if (tagName.equals("eat-comment")) {
1289 // Just skip this tag
1290 XmlUtils.skipCurrentTag(parser);
1291 continue;
1292
1293 } else if (RIGID_PARSER) {
1294 outError[0] = "Bad element under <manifest>: "
1295 + parser.getName();
1296 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1297 return null;
1298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001300 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001301 + " at " + mArchiveSourcePath + " "
1302 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 XmlUtils.skipCurrentTag(parser);
1304 continue;
1305 }
1306 }
1307
1308 if (!foundApp && pkg.instrumentation.size() == 0) {
1309 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1310 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1311 }
1312
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001313 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001314 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001315 for (int ip=0; ip<NP; ip++) {
1316 final PackageParser.NewPermissionInfo npi
1317 = PackageParser.NEW_PERMISSIONS[ip];
1318 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1319 break;
1320 }
1321 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001322 if (implicitPerms == null) {
1323 implicitPerms = new StringBuilder(128);
1324 implicitPerms.append(pkg.packageName);
1325 implicitPerms.append(": compat added ");
1326 } else {
1327 implicitPerms.append(' ');
1328 }
1329 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001330 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001331 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001332 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001333 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001334 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001335 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001336 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001337
1338 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1339 for (int is=0; is<NS; is++) {
1340 final PackageParser.SplitPermissionInfo spi
1341 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001342 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1343 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001344 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001345 }
1346 for (int in=0; in<spi.newPerms.length; in++) {
1347 final String perm = spi.newPerms[in];
1348 if (!pkg.requestedPermissions.contains(perm)) {
1349 pkg.requestedPermissions.add(perm);
1350 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1351 }
1352 }
1353 }
1354
Dianne Hackborn723738c2009-06-25 19:48:04 -07001355 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1356 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001357 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001358 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1359 }
1360 if (supportsNormalScreens != 0) {
1361 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1362 }
1363 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1364 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001365 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001366 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1367 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001368 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1369 && pkg.applicationInfo.targetSdkVersion
1370 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1371 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1372 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001373 if (resizeable < 0 || (resizeable > 0
1374 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001375 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001376 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1377 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001378 if (anyDensity < 0 || (anyDensity > 0
1379 && pkg.applicationInfo.targetSdkVersion
1380 >= android.os.Build.VERSION_CODES.DONUT)) {
1381 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001382 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 return pkg;
1385 }
1386
1387 private static String buildClassName(String pkg, CharSequence clsSeq,
1388 String[] outError) {
1389 if (clsSeq == null || clsSeq.length() <= 0) {
1390 outError[0] = "Empty class name in package " + pkg;
1391 return null;
1392 }
1393 String cls = clsSeq.toString();
1394 char c = cls.charAt(0);
1395 if (c == '.') {
1396 return (pkg + cls).intern();
1397 }
1398 if (cls.indexOf('.') < 0) {
1399 StringBuilder b = new StringBuilder(pkg);
1400 b.append('.');
1401 b.append(cls);
1402 return b.toString().intern();
1403 }
1404 if (c >= 'a' && c <= 'z') {
1405 return cls.intern();
1406 }
1407 outError[0] = "Bad class name " + cls + " in package " + pkg;
1408 return null;
1409 }
1410
1411 private static String buildCompoundName(String pkg,
1412 CharSequence procSeq, String type, String[] outError) {
1413 String proc = procSeq.toString();
1414 char c = proc.charAt(0);
1415 if (pkg != null && c == ':') {
1416 if (proc.length() < 2) {
1417 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1418 + ": must be at least two characters";
1419 return null;
1420 }
1421 String subName = proc.substring(1);
1422 String nameError = validateName(subName, false);
1423 if (nameError != null) {
1424 outError[0] = "Invalid " + type + " name " + proc + " in package "
1425 + pkg + ": " + nameError;
1426 return null;
1427 }
1428 return (pkg + proc).intern();
1429 }
1430 String nameError = validateName(proc, true);
1431 if (nameError != null && !"system".equals(proc)) {
1432 outError[0] = "Invalid " + type + " name " + proc + " in package "
1433 + pkg + ": " + nameError;
1434 return null;
1435 }
1436 return proc.intern();
1437 }
1438
1439 private static String buildProcessName(String pkg, String defProc,
1440 CharSequence procSeq, int flags, String[] separateProcesses,
1441 String[] outError) {
1442 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1443 return defProc != null ? defProc : pkg;
1444 }
1445 if (separateProcesses != null) {
1446 for (int i=separateProcesses.length-1; i>=0; i--) {
1447 String sp = separateProcesses[i];
1448 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1449 return pkg;
1450 }
1451 }
1452 }
1453 if (procSeq == null || procSeq.length() <= 0) {
1454 return defProc;
1455 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001456 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 }
1458
1459 private static String buildTaskAffinityName(String pkg, String defProc,
1460 CharSequence procSeq, String[] outError) {
1461 if (procSeq == null) {
1462 return defProc;
1463 }
1464 if (procSeq.length() <= 0) {
1465 return null;
1466 }
1467 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1468 }
1469
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001470 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 XmlPullParser parser, AttributeSet attrs, String[] outError)
1472 throws XmlPullParserException, IOException {
1473 PermissionGroup perm = new PermissionGroup(owner);
1474
1475 TypedArray sa = res.obtainAttributes(attrs,
1476 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1477
1478 if (!parsePackageItemInfo(owner, perm.info, outError,
1479 "<permission-group>", sa,
1480 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1481 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001482 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1483 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 sa.recycle();
1485 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1486 return null;
1487 }
1488
1489 perm.info.descriptionRes = sa.getResourceId(
1490 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1491 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001492 perm.info.flags = sa.getInt(
1493 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001494 perm.info.priority = sa.getInt(
1495 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001496 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001497 perm.info.priority = 0;
1498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499
1500 sa.recycle();
1501
1502 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1503 outError)) {
1504 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1505 return null;
1506 }
1507
1508 owner.permissionGroups.add(perm);
1509
1510 return perm;
1511 }
1512
1513 private Permission parsePermission(Package owner, Resources res,
1514 XmlPullParser parser, AttributeSet attrs, String[] outError)
1515 throws XmlPullParserException, IOException {
1516 Permission perm = new Permission(owner);
1517
1518 TypedArray sa = res.obtainAttributes(attrs,
1519 com.android.internal.R.styleable.AndroidManifestPermission);
1520
1521 if (!parsePackageItemInfo(owner, perm.info, outError,
1522 "<permission>", sa,
1523 com.android.internal.R.styleable.AndroidManifestPermission_name,
1524 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001525 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1526 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 sa.recycle();
1528 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1529 return null;
1530 }
1531
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001532 // Note: don't allow this value to be a reference to a resource
1533 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 perm.info.group = sa.getNonResourceString(
1535 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1536 if (perm.info.group != null) {
1537 perm.info.group = perm.info.group.intern();
1538 }
1539
1540 perm.info.descriptionRes = sa.getResourceId(
1541 com.android.internal.R.styleable.AndroidManifestPermission_description,
1542 0);
1543
1544 perm.info.protectionLevel = sa.getInt(
1545 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1546 PermissionInfo.PROTECTION_NORMAL);
1547
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001548 perm.info.flags = sa.getInt(
1549 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 if (perm.info.protectionLevel == -1) {
1554 outError[0] = "<permission> does not specify protectionLevel";
1555 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1556 return null;
1557 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001558
1559 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1560
1561 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1562 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1563 PermissionInfo.PROTECTION_SIGNATURE) {
1564 outError[0] = "<permission> protectionLevel specifies a flag but is "
1565 + "not based on signature type";
1566 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1567 return null;
1568 }
1569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570
1571 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1572 outError)) {
1573 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1574 return null;
1575 }
1576
1577 owner.permissions.add(perm);
1578
1579 return perm;
1580 }
1581
1582 private Permission parsePermissionTree(Package owner, Resources res,
1583 XmlPullParser parser, AttributeSet attrs, String[] outError)
1584 throws XmlPullParserException, IOException {
1585 Permission perm = new Permission(owner);
1586
1587 TypedArray sa = res.obtainAttributes(attrs,
1588 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1589
1590 if (!parsePackageItemInfo(owner, perm.info, outError,
1591 "<permission-tree>", sa,
1592 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1593 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001594 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1595 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 sa.recycle();
1597 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1598 return null;
1599 }
1600
1601 sa.recycle();
1602
1603 int index = perm.info.name.indexOf('.');
1604 if (index > 0) {
1605 index = perm.info.name.indexOf('.', index+1);
1606 }
1607 if (index < 0) {
1608 outError[0] = "<permission-tree> name has less than three segments: "
1609 + perm.info.name;
1610 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1611 return null;
1612 }
1613
1614 perm.info.descriptionRes = 0;
1615 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1616 perm.tree = true;
1617
1618 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1619 outError)) {
1620 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1621 return null;
1622 }
1623
1624 owner.permissions.add(perm);
1625
1626 return perm;
1627 }
1628
1629 private Instrumentation parseInstrumentation(Package owner, Resources res,
1630 XmlPullParser parser, AttributeSet attrs, String[] outError)
1631 throws XmlPullParserException, IOException {
1632 TypedArray sa = res.obtainAttributes(attrs,
1633 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1634
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001635 if (mParseInstrumentationArgs == null) {
1636 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1637 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1638 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001639 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1640 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001641 mParseInstrumentationArgs.tag = "<instrumentation>";
1642 }
1643
1644 mParseInstrumentationArgs.sa = sa;
1645
1646 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1647 new InstrumentationInfo());
1648 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 sa.recycle();
1650 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1651 return null;
1652 }
1653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001655 // Note: don't allow this value to be a reference to a resource
1656 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657 str = sa.getNonResourceString(
1658 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1659 a.info.targetPackage = str != null ? str.intern() : null;
1660
1661 a.info.handleProfiling = sa.getBoolean(
1662 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1663 false);
1664
1665 a.info.functionalTest = sa.getBoolean(
1666 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1667 false);
1668
1669 sa.recycle();
1670
1671 if (a.info.targetPackage == null) {
1672 outError[0] = "<instrumentation> does not specify targetPackage";
1673 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1674 return null;
1675 }
1676
1677 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1678 outError)) {
1679 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1680 return null;
1681 }
1682
1683 owner.instrumentation.add(a);
1684
1685 return a;
1686 }
1687
1688 private boolean parseApplication(Package owner, Resources res,
1689 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1690 throws XmlPullParserException, IOException {
1691 final ApplicationInfo ai = owner.applicationInfo;
1692 final String pkgName = owner.applicationInfo.packageName;
1693
1694 TypedArray sa = res.obtainAttributes(attrs,
1695 com.android.internal.R.styleable.AndroidManifestApplication);
1696
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001697 String name = sa.getNonConfigurationString(
1698 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 if (name != null) {
1700 ai.className = buildClassName(pkgName, name, outError);
1701 if (ai.className == null) {
1702 sa.recycle();
1703 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1704 return false;
1705 }
1706 }
1707
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001708 String manageSpaceActivity = sa.getNonConfigurationString(
1709 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 if (manageSpaceActivity != null) {
1711 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1712 outError);
1713 }
1714
Christopher Tate181fafa2009-05-14 11:12:14 -07001715 boolean allowBackup = sa.getBoolean(
1716 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1717 if (allowBackup) {
1718 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001719
Christopher Tate3de55bc2010-03-12 17:28:08 -08001720 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1721 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001722 String backupAgent = sa.getNonConfigurationString(
1723 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001724 if (backupAgent != null) {
1725 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001726 if (DEBUG_BACKUP) {
1727 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001728 + " from " + pkgName + "+" + backupAgent);
1729 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001730
1731 if (sa.getBoolean(
1732 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1733 true)) {
1734 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1735 }
1736 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001737 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1738 false)) {
1739 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1740 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001741 }
1742 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 TypedValue v = sa.peekValue(
1745 com.android.internal.R.styleable.AndroidManifestApplication_label);
1746 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1747 ai.nonLocalizedLabel = v.coerceToString();
1748 }
1749
1750 ai.icon = sa.getResourceId(
1751 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001752 ai.logo = sa.getResourceId(
1753 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001755 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 ai.descriptionRes = sa.getResourceId(
1757 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1758
1759 if ((flags&PARSE_IS_SYSTEM) != 0) {
1760 if (sa.getBoolean(
1761 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1762 false)) {
1763 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1764 }
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08001765 if (sa.getBoolean(
1766 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1767 false)) {
1768 owner.mRequiredForAllUsers = true;
1769 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07001770 String accountType = sa.getString(com.android.internal.R.styleable
1771 .AndroidManifestApplication_restrictedAccountType);
1772 if (accountType != null && accountType.length() > 0) {
1773 owner.mRestrictedAccountType = accountType;
1774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 }
1776
1777 if (sa.getBoolean(
1778 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1779 false)) {
1780 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1781 }
1782
1783 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001784 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001785 false)) {
1786 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1787 }
1788
Romain Guy529b60a2010-08-03 18:05:47 -07001789 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001790 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001791 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001792
1793 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1795 true)) {
1796 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1797 }
1798
1799 if (sa.getBoolean(
1800 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1801 false)) {
1802 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1803 }
1804
1805 if (sa.getBoolean(
1806 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1807 true)) {
1808 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1809 }
1810
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001811 if (sa.getBoolean(
1812 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001813 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001814 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1815 }
1816
Jason parksa3cdaa52011-01-13 14:15:43 -06001817 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001818 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001819 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001820 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001821 }
1822
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001823 if (sa.getBoolean(
1824 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1825 false /* default is no RTL support*/)) {
1826 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1827 }
1828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001830 str = sa.getNonConfigurationString(
1831 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001832 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1833
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001834 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1835 str = sa.getNonConfigurationString(
1836 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1837 } else {
1838 // Some older apps have been seen to use a resource reference
1839 // here that on older builds was ignored (with a warning). We
1840 // need to continue to do this for them so they don't break.
1841 str = sa.getNonResourceString(
1842 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1843 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1845 str, outError);
1846
1847 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001848 CharSequence pname;
1849 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1850 pname = sa.getNonConfigurationString(
1851 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1852 } else {
1853 // Some older apps have been seen to use a resource reference
1854 // here that on older builds was ignored (with a warning). We
1855 // need to continue to do this for them so they don't break.
1856 pname = sa.getNonResourceString(
1857 com.android.internal.R.styleable.AndroidManifestApplication_process);
1858 }
1859 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 flags, mSeparateProcesses, outError);
1861
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001862 ai.enabled = sa.getBoolean(
1863 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001864
Dianne Hackborn02486b12010-08-26 14:18:37 -07001865 if (false) {
1866 if (sa.getBoolean(
1867 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1868 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001869 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001870
1871 // A heavy-weight application can not be in a custom process.
1872 // We can do direct compare because we intern all strings.
1873 if (ai.processName != null && ai.processName != ai.packageName) {
1874 outError[0] = "cantSaveState applications can not use custom processes";
1875 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001876 }
1877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 }
1879
Adam Powell269248d2011-08-02 10:26:54 -07001880 ai.uiOptions = sa.getInt(
1881 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 sa.recycle();
1884
1885 if (outError[0] != null) {
1886 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1887 return false;
1888 }
1889
1890 final int innerDepth = parser.getDepth();
1891
1892 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001893 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1894 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1895 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 continue;
1897 }
1898
1899 String tagName = parser.getName();
1900 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001901 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1902 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 if (a == null) {
1904 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1905 return false;
1906 }
1907
1908 owner.activities.add(a);
1909
1910 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001911 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 if (a == null) {
1913 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1914 return false;
1915 }
1916
1917 owner.receivers.add(a);
1918
1919 } else if (tagName.equals("service")) {
1920 Service s = parseService(owner, res, parser, attrs, flags, outError);
1921 if (s == null) {
1922 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1923 return false;
1924 }
1925
1926 owner.services.add(s);
1927
1928 } else if (tagName.equals("provider")) {
1929 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1930 if (p == null) {
1931 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1932 return false;
1933 }
1934
1935 owner.providers.add(p);
1936
1937 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001938 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 if (a == null) {
1940 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1941 return false;
1942 }
1943
1944 owner.activities.add(a);
1945
1946 } else if (parser.getName().equals("meta-data")) {
1947 // note: application meta-data is stored off to the side, so it can
1948 // remain null in the primary copy (we like to avoid extra copies because
1949 // it can be large)
1950 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1951 outError)) == null) {
1952 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1953 return false;
1954 }
1955
Dianne Hackbornc895be72013-03-11 17:48:43 -07001956 } else if (tagName.equals("library")) {
1957 sa = res.obtainAttributes(attrs,
1958 com.android.internal.R.styleable.AndroidManifestLibrary);
1959
1960 // Note: don't allow this value to be a reference to a resource
1961 // that may change.
1962 String lname = sa.getNonResourceString(
1963 com.android.internal.R.styleable.AndroidManifestLibrary_name);
1964
1965 sa.recycle();
1966
1967 if (lname != null) {
1968 if (owner.libraryNames == null) {
1969 owner.libraryNames = new ArrayList<String>();
1970 }
1971 if (!owner.libraryNames.contains(lname)) {
1972 owner.libraryNames.add(lname.intern());
1973 }
1974 }
1975
1976 XmlUtils.skipCurrentTag(parser);
1977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 } else if (tagName.equals("uses-library")) {
1979 sa = res.obtainAttributes(attrs,
1980 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1981
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001982 // Note: don't allow this value to be a reference to a resource
1983 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 String lname = sa.getNonResourceString(
1985 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001986 boolean req = sa.getBoolean(
1987 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1988 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989
1990 sa.recycle();
1991
Dianne Hackborn49237342009-08-27 20:08:01 -07001992 if (lname != null) {
1993 if (req) {
1994 if (owner.usesLibraries == null) {
1995 owner.usesLibraries = new ArrayList<String>();
1996 }
1997 if (!owner.usesLibraries.contains(lname)) {
1998 owner.usesLibraries.add(lname.intern());
1999 }
2000 } else {
2001 if (owner.usesOptionalLibraries == null) {
2002 owner.usesOptionalLibraries = new ArrayList<String>();
2003 }
2004 if (!owner.usesOptionalLibraries.contains(lname)) {
2005 owner.usesOptionalLibraries.add(lname.intern());
2006 }
2007 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 }
2009
2010 XmlUtils.skipCurrentTag(parser);
2011
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002012 } else if (tagName.equals("uses-package")) {
2013 // Dependencies for app installers; we don't currently try to
2014 // enforce this.
2015 XmlUtils.skipCurrentTag(parser);
2016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 } else {
2018 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002019 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002020 + " at " + mArchiveSourcePath + " "
2021 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 XmlUtils.skipCurrentTag(parser);
2023 continue;
2024 } else {
2025 outError[0] = "Bad element under <application>: " + tagName;
2026 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2027 return false;
2028 }
2029 }
2030 }
2031
2032 return true;
2033 }
2034
2035 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2036 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002037 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002038 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 if (name == null) {
2040 outError[0] = tag + " does not specify android:name";
2041 return false;
2042 }
2043
2044 outInfo.name
2045 = buildClassName(owner.applicationInfo.packageName, name, outError);
2046 if (outInfo.name == null) {
2047 return false;
2048 }
2049
2050 int iconVal = sa.getResourceId(iconRes, 0);
2051 if (iconVal != 0) {
2052 outInfo.icon = iconVal;
2053 outInfo.nonLocalizedLabel = null;
2054 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002055
2056 int logoVal = sa.getResourceId(logoRes, 0);
2057 if (logoVal != 0) {
2058 outInfo.logo = logoVal;
2059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060
2061 TypedValue v = sa.peekValue(labelRes);
2062 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2063 outInfo.nonLocalizedLabel = v.coerceToString();
2064 }
2065
2066 outInfo.packageName = owner.packageName;
2067
2068 return true;
2069 }
2070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 private Activity parseActivity(Package owner, Resources res,
2072 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002073 boolean receiver, boolean hardwareAccelerated)
2074 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 TypedArray sa = res.obtainAttributes(attrs,
2076 com.android.internal.R.styleable.AndroidManifestActivity);
2077
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002078 if (mParseActivityArgs == null) {
2079 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2080 com.android.internal.R.styleable.AndroidManifestActivity_name,
2081 com.android.internal.R.styleable.AndroidManifestActivity_label,
2082 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002083 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002084 mSeparateProcesses,
2085 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002086 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002087 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2088 }
2089
2090 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2091 mParseActivityArgs.sa = sa;
2092 mParseActivityArgs.flags = flags;
2093
2094 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2095 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 sa.recycle();
2097 return null;
2098 }
2099
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002100 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2102 if (setExported) {
2103 a.info.exported = sa.getBoolean(
2104 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2105 }
2106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 a.info.theme = sa.getResourceId(
2108 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2109
Adam Powell269248d2011-08-02 10:26:54 -07002110 a.info.uiOptions = sa.getInt(
2111 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2112 a.info.applicationInfo.uiOptions);
2113
Adam Powelldd8fab22012-03-22 17:47:27 -07002114 String parentName = sa.getNonConfigurationString(
2115 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2116 if (parentName != null) {
2117 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2118 if (outError[0] == null) {
2119 a.info.parentActivityName = parentClassName;
2120 } else {
2121 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2122 parentName);
2123 outError[0] = null;
2124 }
2125 }
2126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002128 str = sa.getNonConfigurationString(
2129 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 if (str == null) {
2131 a.info.permission = owner.applicationInfo.permission;
2132 } else {
2133 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2134 }
2135
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002136 str = sa.getNonConfigurationString(
2137 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2139 owner.applicationInfo.taskAffinity, str, outError);
2140
2141 a.info.flags = 0;
2142 if (sa.getBoolean(
2143 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2144 false)) {
2145 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2146 }
2147
2148 if (sa.getBoolean(
2149 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2150 false)) {
2151 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2152 }
2153
2154 if (sa.getBoolean(
2155 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2156 false)) {
2157 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2158 }
2159
2160 if (sa.getBoolean(
2161 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2162 false)) {
2163 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2164 }
2165
2166 if (sa.getBoolean(
2167 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2168 false)) {
2169 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2170 }
2171
2172 if (sa.getBoolean(
2173 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2174 false)) {
2175 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2176 }
2177
2178 if (sa.getBoolean(
2179 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2180 false)) {
2181 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2182 }
2183
2184 if (sa.getBoolean(
2185 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2186 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2187 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2188 }
2189
Dianne Hackbornffa42482009-09-23 22:20:11 -07002190 if (sa.getBoolean(
2191 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2192 false)) {
2193 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2194 }
2195
Daniel Sandler613dde42010-06-21 13:46:39 -04002196 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002197 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2198 false)) {
2199 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2200 }
2201
2202 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002203 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2204 false)) {
2205 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2206 }
Craig Mautner5962b122012-10-05 14:45:52 -07002207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002209 if (sa.getBoolean(
2210 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2211 hardwareAccelerated)) {
2212 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2213 }
2214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 a.info.launchMode = sa.getInt(
2216 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2217 ActivityInfo.LAUNCH_MULTIPLE);
2218 a.info.screenOrientation = sa.getInt(
2219 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2220 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2221 a.info.configChanges = sa.getInt(
2222 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2223 0);
2224 a.info.softInputMode = sa.getInt(
2225 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2226 0);
2227 } else {
2228 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2229 a.info.configChanges = 0;
2230 }
2231
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002232 if (receiver) {
2233 if (sa.getBoolean(
2234 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2235 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002236 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002237 if (a.info.exported) {
2238 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2239 + a.className + " at " + mArchiveSourcePath + " "
2240 + parser.getPositionDescription());
2241 a.info.exported = false;
2242 }
2243 setExported = true;
2244 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002245 if (sa.getBoolean(
2246 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2247 false)) {
2248 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2249 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002250 }
2251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 sa.recycle();
2253
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002254 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002255 // A heavy-weight application can not have receives in its main process
2256 // We can do direct compare because we intern all strings.
2257 if (a.info.processName == owner.packageName) {
2258 outError[0] = "Heavy-weight applications can not have receivers in main process";
2259 }
2260 }
2261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 if (outError[0] != null) {
2263 return null;
2264 }
2265
2266 int outerDepth = parser.getDepth();
2267 int type;
2268 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2269 && (type != XmlPullParser.END_TAG
2270 || parser.getDepth() > outerDepth)) {
2271 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2272 continue;
2273 }
2274
2275 if (parser.getName().equals("intent-filter")) {
2276 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2277 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2278 return null;
2279 }
2280 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002281 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002282 + mArchiveSourcePath + " "
2283 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 } else {
2285 a.intents.add(intent);
2286 }
2287 } else if (parser.getName().equals("meta-data")) {
2288 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2289 outError)) == null) {
2290 return null;
2291 }
2292 } else {
2293 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002294 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002296 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002297 + " at " + mArchiveSourcePath + " "
2298 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002300 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002301 + " at " + mArchiveSourcePath + " "
2302 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 }
2304 XmlUtils.skipCurrentTag(parser);
2305 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002307 if (receiver) {
2308 outError[0] = "Bad element under <receiver>: " + parser.getName();
2309 } else {
2310 outError[0] = "Bad element under <activity>: " + parser.getName();
2311 }
2312 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 }
2315 }
2316
2317 if (!setExported) {
2318 a.info.exported = a.intents.size() > 0;
2319 }
2320
2321 return a;
2322 }
2323
2324 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002325 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2326 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 TypedArray sa = res.obtainAttributes(attrs,
2328 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2329
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002330 String targetActivity = sa.getNonConfigurationString(
2331 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 if (targetActivity == null) {
2333 outError[0] = "<activity-alias> does not specify android:targetActivity";
2334 sa.recycle();
2335 return null;
2336 }
2337
2338 targetActivity = buildClassName(owner.applicationInfo.packageName,
2339 targetActivity, outError);
2340 if (targetActivity == null) {
2341 sa.recycle();
2342 return null;
2343 }
2344
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002345 if (mParseActivityAliasArgs == null) {
2346 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2347 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2348 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2349 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002350 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002351 mSeparateProcesses,
2352 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002353 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002354 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2355 mParseActivityAliasArgs.tag = "<activity-alias>";
2356 }
2357
2358 mParseActivityAliasArgs.sa = sa;
2359 mParseActivityAliasArgs.flags = flags;
2360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 Activity target = null;
2362
2363 final int NA = owner.activities.size();
2364 for (int i=0; i<NA; i++) {
2365 Activity t = owner.activities.get(i);
2366 if (targetActivity.equals(t.info.name)) {
2367 target = t;
2368 break;
2369 }
2370 }
2371
2372 if (target == null) {
2373 outError[0] = "<activity-alias> target activity " + targetActivity
2374 + " not found in manifest";
2375 sa.recycle();
2376 return null;
2377 }
2378
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002379 ActivityInfo info = new ActivityInfo();
2380 info.targetActivity = targetActivity;
2381 info.configChanges = target.info.configChanges;
2382 info.flags = target.info.flags;
2383 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002384 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002385 info.labelRes = target.info.labelRes;
2386 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2387 info.launchMode = target.info.launchMode;
2388 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002389 if (info.descriptionRes == 0) {
2390 info.descriptionRes = target.info.descriptionRes;
2391 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002392 info.screenOrientation = target.info.screenOrientation;
2393 info.taskAffinity = target.info.taskAffinity;
2394 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002395 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002396 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002397 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002398
2399 Activity a = new Activity(mParseActivityAliasArgs, info);
2400 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 sa.recycle();
2402 return null;
2403 }
2404
2405 final boolean setExported = sa.hasValue(
2406 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2407 if (setExported) {
2408 a.info.exported = sa.getBoolean(
2409 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2410 }
2411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002413 str = sa.getNonConfigurationString(
2414 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 if (str != null) {
2416 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2417 }
2418
Adam Powelldd8fab22012-03-22 17:47:27 -07002419 String parentName = sa.getNonConfigurationString(
2420 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2421 0);
2422 if (parentName != null) {
2423 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2424 if (outError[0] == null) {
2425 a.info.parentActivityName = parentClassName;
2426 } else {
2427 Log.e(TAG, "Activity alias " + a.info.name +
2428 " specified invalid parentActivityName " + parentName);
2429 outError[0] = null;
2430 }
2431 }
2432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 sa.recycle();
2434
2435 if (outError[0] != null) {
2436 return null;
2437 }
2438
2439 int outerDepth = parser.getDepth();
2440 int type;
2441 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2442 && (type != XmlPullParser.END_TAG
2443 || parser.getDepth() > outerDepth)) {
2444 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2445 continue;
2446 }
2447
2448 if (parser.getName().equals("intent-filter")) {
2449 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2450 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2451 return null;
2452 }
2453 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002454 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002455 + mArchiveSourcePath + " "
2456 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 } else {
2458 a.intents.add(intent);
2459 }
2460 } else if (parser.getName().equals("meta-data")) {
2461 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2462 outError)) == null) {
2463 return null;
2464 }
2465 } else {
2466 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002467 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002468 + " at " + mArchiveSourcePath + " "
2469 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 XmlUtils.skipCurrentTag(parser);
2471 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002472 } else {
2473 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2474 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 }
2477 }
2478
2479 if (!setExported) {
2480 a.info.exported = a.intents.size() > 0;
2481 }
2482
2483 return a;
2484 }
2485
2486 private Provider parseProvider(Package owner, Resources res,
2487 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2488 throws XmlPullParserException, IOException {
2489 TypedArray sa = res.obtainAttributes(attrs,
2490 com.android.internal.R.styleable.AndroidManifestProvider);
2491
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002492 if (mParseProviderArgs == null) {
2493 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2494 com.android.internal.R.styleable.AndroidManifestProvider_name,
2495 com.android.internal.R.styleable.AndroidManifestProvider_label,
2496 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002497 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002498 mSeparateProcesses,
2499 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002500 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002501 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2502 mParseProviderArgs.tag = "<provider>";
2503 }
2504
2505 mParseProviderArgs.sa = sa;
2506 mParseProviderArgs.flags = flags;
2507
2508 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2509 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 sa.recycle();
2511 return null;
2512 }
2513
Nick Kralevichf097b162012-07-28 12:43:48 -07002514 boolean providerExportedDefault = false;
2515
2516 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2517 // For compatibility, applications targeting API level 16 or lower
2518 // should have their content providers exported by default, unless they
2519 // specify otherwise.
2520 providerExportedDefault = true;
2521 }
2522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002524 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2525 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002527 String cpname = sa.getNonConfigurationString(
2528 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529
2530 p.info.isSyncable = sa.getBoolean(
2531 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2532 false);
2533
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002534 String permission = sa.getNonConfigurationString(
2535 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2536 String str = sa.getNonConfigurationString(
2537 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 if (str == null) {
2539 str = permission;
2540 }
2541 if (str == null) {
2542 p.info.readPermission = owner.applicationInfo.permission;
2543 } else {
2544 p.info.readPermission =
2545 str.length() > 0 ? str.toString().intern() : null;
2546 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002547 str = sa.getNonConfigurationString(
2548 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 if (str == null) {
2550 str = permission;
2551 }
2552 if (str == null) {
2553 p.info.writePermission = owner.applicationInfo.permission;
2554 } else {
2555 p.info.writePermission =
2556 str.length() > 0 ? str.toString().intern() : null;
2557 }
2558
2559 p.info.grantUriPermissions = sa.getBoolean(
2560 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2561 false);
2562
2563 p.info.multiprocess = sa.getBoolean(
2564 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2565 false);
2566
2567 p.info.initOrder = sa.getInt(
2568 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2569 0);
2570
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002571 p.info.flags = 0;
2572
2573 if (sa.getBoolean(
2574 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2575 false)) {
2576 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2577 if (p.info.exported) {
2578 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2579 + p.className + " at " + mArchiveSourcePath + " "
2580 + parser.getPositionDescription());
2581 p.info.exported = false;
2582 }
2583 }
2584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 sa.recycle();
2586
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002587 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002588 // A heavy-weight application can not have providers in its main process
2589 // We can do direct compare because we intern all strings.
2590 if (p.info.processName == owner.packageName) {
2591 outError[0] = "Heavy-weight applications can not have providers in main process";
2592 return null;
2593 }
2594 }
2595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002597 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 return null;
2599 }
2600 p.info.authority = cpname.intern();
2601
2602 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2603 return null;
2604 }
2605
2606 return p;
2607 }
2608
2609 private boolean parseProviderTags(Resources res,
2610 XmlPullParser parser, AttributeSet attrs,
2611 Provider outInfo, String[] outError)
2612 throws XmlPullParserException, IOException {
2613 int outerDepth = parser.getDepth();
2614 int type;
2615 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2616 && (type != XmlPullParser.END_TAG
2617 || parser.getDepth() > outerDepth)) {
2618 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2619 continue;
2620 }
2621
2622 if (parser.getName().equals("meta-data")) {
2623 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2624 outInfo.metaData, outError)) == null) {
2625 return false;
2626 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 } else if (parser.getName().equals("grant-uri-permission")) {
2629 TypedArray sa = res.obtainAttributes(attrs,
2630 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2631
2632 PatternMatcher pa = null;
2633
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002634 String str = sa.getNonConfigurationString(
2635 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 if (str != null) {
2637 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2638 }
2639
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002640 str = sa.getNonConfigurationString(
2641 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 if (str != null) {
2643 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2644 }
2645
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002646 str = sa.getNonConfigurationString(
2647 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if (str != null) {
2649 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2650 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 sa.recycle();
2653
2654 if (pa != null) {
2655 if (outInfo.info.uriPermissionPatterns == null) {
2656 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2657 outInfo.info.uriPermissionPatterns[0] = pa;
2658 } else {
2659 final int N = outInfo.info.uriPermissionPatterns.length;
2660 PatternMatcher[] newp = new PatternMatcher[N+1];
2661 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2662 newp[N] = pa;
2663 outInfo.info.uriPermissionPatterns = newp;
2664 }
2665 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002666 } else {
2667 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002668 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002669 + parser.getName() + " at " + mArchiveSourcePath + " "
2670 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002671 XmlUtils.skipCurrentTag(parser);
2672 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002673 } else {
2674 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2675 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002676 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002677 }
2678 XmlUtils.skipCurrentTag(parser);
2679
2680 } else if (parser.getName().equals("path-permission")) {
2681 TypedArray sa = res.obtainAttributes(attrs,
2682 com.android.internal.R.styleable.AndroidManifestPathPermission);
2683
2684 PathPermission pa = null;
2685
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002686 String permission = sa.getNonConfigurationString(
2687 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2688 String readPermission = sa.getNonConfigurationString(
2689 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002690 if (readPermission == null) {
2691 readPermission = permission;
2692 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002693 String writePermission = sa.getNonConfigurationString(
2694 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002695 if (writePermission == null) {
2696 writePermission = permission;
2697 }
2698
2699 boolean havePerm = false;
2700 if (readPermission != null) {
2701 readPermission = readPermission.intern();
2702 havePerm = true;
2703 }
2704 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002705 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002706 havePerm = true;
2707 }
2708
2709 if (!havePerm) {
2710 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002711 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002712 + parser.getName() + " at " + mArchiveSourcePath + " "
2713 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002714 XmlUtils.skipCurrentTag(parser);
2715 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002716 } else {
2717 outError[0] = "No readPermission or writePermssion for <path-permission>";
2718 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002719 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002720 }
2721
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002722 String path = sa.getNonConfigurationString(
2723 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002724 if (path != null) {
2725 pa = new PathPermission(path,
2726 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2727 }
2728
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002729 path = sa.getNonConfigurationString(
2730 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002731 if (path != null) {
2732 pa = new PathPermission(path,
2733 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2734 }
2735
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002736 path = sa.getNonConfigurationString(
2737 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002738 if (path != null) {
2739 pa = new PathPermission(path,
2740 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2741 }
2742
2743 sa.recycle();
2744
2745 if (pa != null) {
2746 if (outInfo.info.pathPermissions == null) {
2747 outInfo.info.pathPermissions = new PathPermission[1];
2748 outInfo.info.pathPermissions[0] = pa;
2749 } else {
2750 final int N = outInfo.info.pathPermissions.length;
2751 PathPermission[] newp = new PathPermission[N+1];
2752 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2753 newp[N] = pa;
2754 outInfo.info.pathPermissions = newp;
2755 }
2756 } else {
2757 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002758 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002759 + parser.getName() + " at " + mArchiveSourcePath + " "
2760 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002761 XmlUtils.skipCurrentTag(parser);
2762 continue;
2763 }
2764 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2765 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 }
2767 XmlUtils.skipCurrentTag(parser);
2768
2769 } else {
2770 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002771 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002772 + parser.getName() + " at " + mArchiveSourcePath + " "
2773 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 XmlUtils.skipCurrentTag(parser);
2775 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002776 } else {
2777 outError[0] = "Bad element under <provider>: " + parser.getName();
2778 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 }
2781 }
2782 return true;
2783 }
2784
2785 private Service parseService(Package owner, Resources res,
2786 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2787 throws XmlPullParserException, IOException {
2788 TypedArray sa = res.obtainAttributes(attrs,
2789 com.android.internal.R.styleable.AndroidManifestService);
2790
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002791 if (mParseServiceArgs == null) {
2792 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2793 com.android.internal.R.styleable.AndroidManifestService_name,
2794 com.android.internal.R.styleable.AndroidManifestService_label,
2795 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002796 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002797 mSeparateProcesses,
2798 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002799 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002800 com.android.internal.R.styleable.AndroidManifestService_enabled);
2801 mParseServiceArgs.tag = "<service>";
2802 }
2803
2804 mParseServiceArgs.sa = sa;
2805 mParseServiceArgs.flags = flags;
2806
2807 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2808 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 sa.recycle();
2810 return null;
2811 }
2812
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002813 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 com.android.internal.R.styleable.AndroidManifestService_exported);
2815 if (setExported) {
2816 s.info.exported = sa.getBoolean(
2817 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2818 }
2819
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002820 String str = sa.getNonConfigurationString(
2821 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 if (str == null) {
2823 s.info.permission = owner.applicationInfo.permission;
2824 } else {
2825 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2826 }
2827
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002828 s.info.flags = 0;
2829 if (sa.getBoolean(
2830 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2831 false)) {
2832 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2833 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002834 if (sa.getBoolean(
2835 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2836 false)) {
2837 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2838 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002839 if (sa.getBoolean(
2840 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2841 false)) {
2842 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2843 if (s.info.exported) {
2844 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2845 + s.className + " at " + mArchiveSourcePath + " "
2846 + parser.getPositionDescription());
2847 s.info.exported = false;
2848 }
2849 setExported = true;
2850 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 sa.recycle();
2853
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002854 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002855 // A heavy-weight application can not have services in its main process
2856 // We can do direct compare because we intern all strings.
2857 if (s.info.processName == owner.packageName) {
2858 outError[0] = "Heavy-weight applications can not have services in main process";
2859 return null;
2860 }
2861 }
2862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 int outerDepth = parser.getDepth();
2864 int type;
2865 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2866 && (type != XmlPullParser.END_TAG
2867 || parser.getDepth() > outerDepth)) {
2868 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2869 continue;
2870 }
2871
2872 if (parser.getName().equals("intent-filter")) {
2873 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2874 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2875 return null;
2876 }
2877
2878 s.intents.add(intent);
2879 } else if (parser.getName().equals("meta-data")) {
2880 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2881 outError)) == null) {
2882 return null;
2883 }
2884 } else {
2885 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002886 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002887 + parser.getName() + " at " + mArchiveSourcePath + " "
2888 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 XmlUtils.skipCurrentTag(parser);
2890 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002891 } else {
2892 outError[0] = "Bad element under <service>: " + parser.getName();
2893 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 }
2896 }
2897
2898 if (!setExported) {
2899 s.info.exported = s.intents.size() > 0;
2900 }
2901
2902 return s;
2903 }
2904
2905 private boolean parseAllMetaData(Resources res,
2906 XmlPullParser parser, AttributeSet attrs, String tag,
2907 Component outInfo, String[] outError)
2908 throws XmlPullParserException, IOException {
2909 int outerDepth = parser.getDepth();
2910 int type;
2911 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2912 && (type != XmlPullParser.END_TAG
2913 || parser.getDepth() > outerDepth)) {
2914 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2915 continue;
2916 }
2917
2918 if (parser.getName().equals("meta-data")) {
2919 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2920 outInfo.metaData, outError)) == null) {
2921 return false;
2922 }
2923 } else {
2924 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002925 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002926 + parser.getName() + " at " + mArchiveSourcePath + " "
2927 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 XmlUtils.skipCurrentTag(parser);
2929 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002930 } else {
2931 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2932 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 }
2935 }
2936 return true;
2937 }
2938
2939 private Bundle parseMetaData(Resources res,
2940 XmlPullParser parser, AttributeSet attrs,
2941 Bundle data, String[] outError)
2942 throws XmlPullParserException, IOException {
2943
2944 TypedArray sa = res.obtainAttributes(attrs,
2945 com.android.internal.R.styleable.AndroidManifestMetaData);
2946
2947 if (data == null) {
2948 data = new Bundle();
2949 }
2950
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002951 String name = sa.getNonConfigurationString(
2952 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 if (name == null) {
2954 outError[0] = "<meta-data> requires an android:name attribute";
2955 sa.recycle();
2956 return null;
2957 }
2958
Dianne Hackborn854060a2009-07-09 18:14:31 -07002959 name = name.intern();
2960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 TypedValue v = sa.peekValue(
2962 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2963 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002964 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 data.putInt(name, v.resourceId);
2966 } else {
2967 v = sa.peekValue(
2968 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002969 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 if (v != null) {
2971 if (v.type == TypedValue.TYPE_STRING) {
2972 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002973 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2975 data.putBoolean(name, v.data != 0);
2976 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2977 && v.type <= TypedValue.TYPE_LAST_INT) {
2978 data.putInt(name, v.data);
2979 } else if (v.type == TypedValue.TYPE_FLOAT) {
2980 data.putFloat(name, v.getFloat());
2981 } else {
2982 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002983 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002984 + parser.getName() + " at " + mArchiveSourcePath + " "
2985 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 } else {
2987 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2988 data = null;
2989 }
2990 }
2991 } else {
2992 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2993 data = null;
2994 }
2995 }
2996
2997 sa.recycle();
2998
2999 XmlUtils.skipCurrentTag(parser);
3000
3001 return data;
3002 }
3003
Kenny Root05ca4c92011-09-15 10:36:25 -07003004 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3005 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3006 IOException {
3007 final TypedArray sa = res.obtainAttributes(attrs,
3008 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3009
3010 final String packageName = sa.getNonResourceString(
3011 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3012
3013 final String encodedPublicKey = sa.getNonResourceString(
3014 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3015
3016 sa.recycle();
3017
3018 if (packageName == null || packageName.length() == 0) {
3019 Slog.i(TAG, "verifier package name was null; skipping");
3020 return null;
3021 } else if (encodedPublicKey == null) {
3022 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3023 }
3024
3025 EncodedKeySpec keySpec;
3026 try {
3027 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3028 keySpec = new X509EncodedKeySpec(encoded);
3029 } catch (IllegalArgumentException e) {
3030 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
3031 return null;
3032 }
3033
3034 /* First try the key as an RSA key. */
3035 try {
3036 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
3037 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3038 return new VerifierInfo(packageName, publicKey);
3039 } catch (NoSuchAlgorithmException e) {
3040 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3041 return null;
3042 } catch (InvalidKeySpecException e) {
3043 // Not a RSA public key.
3044 }
3045
3046 /* Now try it as a DSA key. */
3047 try {
3048 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3049 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3050 return new VerifierInfo(packageName, publicKey);
3051 } catch (NoSuchAlgorithmException e) {
3052 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3053 return null;
3054 } catch (InvalidKeySpecException e) {
3055 // Not a DSA public key.
3056 }
3057
3058 return null;
3059 }
3060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 private static final String ANDROID_RESOURCES
3062 = "http://schemas.android.com/apk/res/android";
3063
3064 private boolean parseIntent(Resources res,
3065 XmlPullParser parser, AttributeSet attrs, int flags,
3066 IntentInfo outInfo, String[] outError, boolean isActivity)
3067 throws XmlPullParserException, IOException {
3068
3069 TypedArray sa = res.obtainAttributes(attrs,
3070 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3071
3072 int priority = sa.getInt(
3073 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 TypedValue v = sa.peekValue(
3077 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3078 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3079 outInfo.nonLocalizedLabel = v.coerceToString();
3080 }
3081
3082 outInfo.icon = sa.getResourceId(
3083 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003084
3085 outInfo.logo = sa.getResourceId(
3086 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087
3088 sa.recycle();
3089
3090 int outerDepth = parser.getDepth();
3091 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003092 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3093 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3094 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 continue;
3096 }
3097
3098 String nodeName = parser.getName();
3099 if (nodeName.equals("action")) {
3100 String value = attrs.getAttributeValue(
3101 ANDROID_RESOURCES, "name");
3102 if (value == null || value == "") {
3103 outError[0] = "No value supplied for <android:name>";
3104 return false;
3105 }
3106 XmlUtils.skipCurrentTag(parser);
3107
3108 outInfo.addAction(value);
3109 } else if (nodeName.equals("category")) {
3110 String value = attrs.getAttributeValue(
3111 ANDROID_RESOURCES, "name");
3112 if (value == null || value == "") {
3113 outError[0] = "No value supplied for <android:name>";
3114 return false;
3115 }
3116 XmlUtils.skipCurrentTag(parser);
3117
3118 outInfo.addCategory(value);
3119
3120 } else if (nodeName.equals("data")) {
3121 sa = res.obtainAttributes(attrs,
3122 com.android.internal.R.styleable.AndroidManifestData);
3123
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003124 String str = sa.getNonConfigurationString(
3125 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 if (str != null) {
3127 try {
3128 outInfo.addDataType(str);
3129 } catch (IntentFilter.MalformedMimeTypeException e) {
3130 outError[0] = e.toString();
3131 sa.recycle();
3132 return false;
3133 }
3134 }
3135
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003136 str = sa.getNonConfigurationString(
3137 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 if (str != null) {
3139 outInfo.addDataScheme(str);
3140 }
3141
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003142 String host = sa.getNonConfigurationString(
3143 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3144 String port = sa.getNonConfigurationString(
3145 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 if (host != null) {
3147 outInfo.addDataAuthority(host, port);
3148 }
3149
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003150 str = sa.getNonConfigurationString(
3151 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 if (str != null) {
3153 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3154 }
3155
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003156 str = sa.getNonConfigurationString(
3157 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 if (str != null) {
3159 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3160 }
3161
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003162 str = sa.getNonConfigurationString(
3163 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 if (str != null) {
3165 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3166 }
3167
3168 sa.recycle();
3169 XmlUtils.skipCurrentTag(parser);
3170 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003171 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003172 + parser.getName() + " at " + mArchiveSourcePath + " "
3173 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 XmlUtils.skipCurrentTag(parser);
3175 } else {
3176 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3177 return false;
3178 }
3179 }
3180
3181 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003182
3183 if (DEBUG_PARSER) {
3184 final StringBuilder cats = new StringBuilder("Intent d=");
3185 cats.append(outInfo.hasDefault);
3186 cats.append(", cat=");
3187
3188 final Iterator<String> it = outInfo.categoriesIterator();
3189 if (it != null) {
3190 while (it.hasNext()) {
3191 cats.append(' ');
3192 cats.append(it.next());
3193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003195 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 }
3197
3198 return true;
3199 }
3200
3201 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003202
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003203 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204
3205 // For now we only support one application per package.
3206 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3207
3208 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3209 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3210 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3211 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3212 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3213 public final ArrayList<Service> services = new ArrayList<Service>(0);
3214 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3215
3216 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003217 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218
Dianne Hackborn854060a2009-07-09 18:14:31 -07003219 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003220
3221 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003222 public ArrayList<String> usesLibraries = null;
3223 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 public String[] usesLibraryFiles = null;
3225
Dianne Hackbornc1552392010-03-03 16:19:01 -08003226 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003227 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003228 public ArrayList<String> mAdoptPermissions = null;
3229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 // We store the application meta-data independently to avoid multiple unwanted references
3231 public Bundle mAppMetaData = null;
3232
3233 // If this is a 3rd party app, this is the path of the zip file.
3234 public String mPath;
3235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 // The version code declared for this package.
3237 public int mVersionCode;
3238
3239 // The version name declared for this package.
3240 public String mVersionName;
3241
3242 // The shared user id that this package wants to use.
3243 public String mSharedUserId;
3244
3245 // The shared user label that this package wants to use.
3246 public int mSharedUserLabel;
3247
3248 // Signatures that were read from the package.
3249 public Signature mSignatures[];
3250
3251 // For use by package manager service for quick lookup of
3252 // preferred up order.
3253 public int mPreferredOrder = 0;
3254
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003255 // For use by the package manager to keep track of the path to the
3256 // file an app came from.
3257 public String mScanPath;
3258
3259 // For use by package manager to keep track of where it has done dexopt.
3260 public boolean mDidDexOpt;
3261
Amith Yamasani13593602012-03-22 16:16:17 -07003262 // // User set enabled state.
3263 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3264 //
3265 // // Whether the package has been stopped.
3266 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 // Additional data supplied by callers.
3269 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003270
3271 // Whether an operation is currently pending on this package
3272 public boolean mOperationPending;
3273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 /*
3275 * Applications hardware preferences
3276 */
3277 public final ArrayList<ConfigurationInfo> configPreferences =
3278 new ArrayList<ConfigurationInfo>();
3279
Dianne Hackborn49237342009-08-27 20:08:01 -07003280 /*
3281 * Applications requested features
3282 */
3283 public ArrayList<FeatureInfo> reqFeatures = null;
3284
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003285 public int installLocation;
3286
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003287 /* An app that's required for all users and cannot be uninstalled for a user */
3288 public boolean mRequiredForAllUsers;
3289
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003290 /* The restricted account authenticator type that is used by this application */
3291 public String mRestrictedAccountType;
3292
Kenny Rootbcc954d2011-08-08 16:19:08 -07003293 /**
3294 * Digest suitable for comparing whether this package's manifest is the
3295 * same as another.
3296 */
3297 public ManifestDigest manifestDigest;
3298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 public Package(String _name) {
3300 packageName = _name;
3301 applicationInfo.packageName = _name;
3302 applicationInfo.uid = -1;
3303 }
3304
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003305 public void setPackageName(String newName) {
3306 packageName = newName;
3307 applicationInfo.packageName = newName;
3308 for (int i=permissions.size()-1; i>=0; i--) {
3309 permissions.get(i).setPackageName(newName);
3310 }
3311 for (int i=permissionGroups.size()-1; i>=0; i--) {
3312 permissionGroups.get(i).setPackageName(newName);
3313 }
3314 for (int i=activities.size()-1; i>=0; i--) {
3315 activities.get(i).setPackageName(newName);
3316 }
3317 for (int i=receivers.size()-1; i>=0; i--) {
3318 receivers.get(i).setPackageName(newName);
3319 }
3320 for (int i=providers.size()-1; i>=0; i--) {
3321 providers.get(i).setPackageName(newName);
3322 }
3323 for (int i=services.size()-1; i>=0; i--) {
3324 services.get(i).setPackageName(newName);
3325 }
3326 for (int i=instrumentation.size()-1; i>=0; i--) {
3327 instrumentation.get(i).setPackageName(newName);
3328 }
3329 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003330
3331 public boolean hasComponentClassName(String name) {
3332 for (int i=activities.size()-1; i>=0; i--) {
3333 if (name.equals(activities.get(i).className)) {
3334 return true;
3335 }
3336 }
3337 for (int i=receivers.size()-1; i>=0; i--) {
3338 if (name.equals(receivers.get(i).className)) {
3339 return true;
3340 }
3341 }
3342 for (int i=providers.size()-1; i>=0; i--) {
3343 if (name.equals(providers.get(i).className)) {
3344 return true;
3345 }
3346 }
3347 for (int i=services.size()-1; i>=0; i--) {
3348 if (name.equals(services.get(i).className)) {
3349 return true;
3350 }
3351 }
3352 for (int i=instrumentation.size()-1; i>=0; i--) {
3353 if (name.equals(instrumentation.get(i).className)) {
3354 return true;
3355 }
3356 }
3357 return false;
3358 }
3359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 public String toString() {
3361 return "Package{"
3362 + Integer.toHexString(System.identityHashCode(this))
3363 + " " + packageName + "}";
3364 }
3365 }
3366
3367 public static class Component<II extends IntentInfo> {
3368 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003369 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003370 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 public Bundle metaData;
3372
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003373 ComponentName componentName;
3374 String componentShortName;
3375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 public Component(Package _owner) {
3377 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003378 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003379 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003380 }
3381
3382 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3383 owner = args.owner;
3384 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003385 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003386 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003387 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003388 args.outError[0] = args.tag + " does not specify android:name";
3389 return;
3390 }
3391
3392 outInfo.name
3393 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3394 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003395 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003396 args.outError[0] = args.tag + " does not have valid android:name";
3397 return;
3398 }
3399
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003400 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003401
3402 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3403 if (iconVal != 0) {
3404 outInfo.icon = iconVal;
3405 outInfo.nonLocalizedLabel = null;
3406 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003407
3408 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3409 if (logoVal != 0) {
3410 outInfo.logo = logoVal;
3411 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003412
3413 TypedValue v = args.sa.peekValue(args.labelRes);
3414 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3415 outInfo.nonLocalizedLabel = v.coerceToString();
3416 }
3417
3418 outInfo.packageName = owner.packageName;
3419 }
3420
3421 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3422 this(args, (PackageItemInfo)outInfo);
3423 if (args.outError[0] != null) {
3424 return;
3425 }
3426
3427 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003428 CharSequence pname;
3429 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3430 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3431 } else {
3432 // Some older apps have been seen to use a resource reference
3433 // here that on older builds was ignored (with a warning). We
3434 // need to continue to do this for them so they don't break.
3435 pname = args.sa.getNonResourceString(args.processRes);
3436 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003437 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003438 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003439 args.flags, args.sepProcesses, args.outError);
3440 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003441
3442 if (args.descriptionRes != 0) {
3443 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3444 }
3445
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003446 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 }
3448
3449 public Component(Component<II> clone) {
3450 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003451 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003452 className = clone.className;
3453 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003454 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003455 }
3456
3457 public ComponentName getComponentName() {
3458 if (componentName != null) {
3459 return componentName;
3460 }
3461 if (className != null) {
3462 componentName = new ComponentName(owner.applicationInfo.packageName,
3463 className);
3464 }
3465 return componentName;
3466 }
3467
3468 public String getComponentShortName() {
3469 if (componentShortName != null) {
3470 return componentShortName;
3471 }
3472 ComponentName component = getComponentName();
3473 if (component != null) {
3474 componentShortName = component.flattenToShortString();
3475 }
3476 return componentShortName;
3477 }
3478
3479 public void setPackageName(String packageName) {
3480 componentName = null;
3481 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 }
3483 }
3484
3485 public final static class Permission extends Component<IntentInfo> {
3486 public final PermissionInfo info;
3487 public boolean tree;
3488 public PermissionGroup group;
3489
3490 public Permission(Package _owner) {
3491 super(_owner);
3492 info = new PermissionInfo();
3493 }
3494
3495 public Permission(Package _owner, PermissionInfo _info) {
3496 super(_owner);
3497 info = _info;
3498 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003499
3500 public void setPackageName(String packageName) {
3501 super.setPackageName(packageName);
3502 info.packageName = packageName;
3503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003504
3505 public String toString() {
3506 return "Permission{"
3507 + Integer.toHexString(System.identityHashCode(this))
3508 + " " + info.name + "}";
3509 }
3510 }
3511
3512 public final static class PermissionGroup extends Component<IntentInfo> {
3513 public final PermissionGroupInfo info;
3514
3515 public PermissionGroup(Package _owner) {
3516 super(_owner);
3517 info = new PermissionGroupInfo();
3518 }
3519
3520 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3521 super(_owner);
3522 info = _info;
3523 }
3524
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003525 public void setPackageName(String packageName) {
3526 super.setPackageName(packageName);
3527 info.packageName = packageName;
3528 }
3529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 public String toString() {
3531 return "PermissionGroup{"
3532 + Integer.toHexString(System.identityHashCode(this))
3533 + " " + info.name + "}";
3534 }
3535 }
3536
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003537 private static boolean copyNeeded(int flags, Package p,
3538 PackageUserState state, Bundle metaData, int userId) {
3539 if (userId != 0) {
3540 // We always need to copy for other users, since we need
3541 // to fix up the uid.
3542 return true;
3543 }
3544 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3545 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003546 if (p.applicationInfo.enabled != enabled) {
3547 return true;
3548 }
3549 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003550 if (!state.installed) {
3551 return true;
3552 }
3553 if (state.stopped) {
3554 return true;
3555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 if ((flags & PackageManager.GET_META_DATA) != 0
3557 && (metaData != null || p.mAppMetaData != null)) {
3558 return true;
3559 }
3560 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3561 && p.usesLibraryFiles != null) {
3562 return true;
3563 }
3564 return false;
3565 }
3566
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003567 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3568 PackageUserState state) {
3569 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003570 }
3571
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003572 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3573 PackageUserState state) {
3574 // CompatibilityMode is global state.
3575 if (!sCompatibilityModeEnabled) {
3576 ai.disableCompatibilityMode();
3577 }
3578 if (state.installed) {
3579 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3580 } else {
3581 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3582 }
3583 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3584 ai.enabled = true;
3585 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3586 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3587 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3588 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3589 ai.enabled = false;
3590 }
3591 ai.enabledSetting = state.enabled;
3592 }
3593
Amith Yamasani13593602012-03-22 16:16:17 -07003594 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003595 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003597 if (!checkUseInstalled(flags, state)) {
3598 return null;
3599 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003600 if (!copyNeeded(flags, p, state, null, userId)
3601 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3602 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3603 // In this case it is safe to directly modify the internal ApplicationInfo state:
3604 // - CompatibilityMode is global state, so will be the same for every call.
3605 // - We only come in to here if the app should reported as installed; this is the
3606 // default state, and we will do a copy otherwise.
3607 // - The enable state will always be reported the same for the application across
3608 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3609 // be doing a copy.
3610 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 return p.applicationInfo;
3612 }
3613
3614 // Make shallow copy so we can store the metadata/libraries safely
3615 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003616 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003617 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003618 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 if ((flags & PackageManager.GET_META_DATA) != 0) {
3621 ai.metaData = p.mAppMetaData;
3622 }
3623 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3624 ai.sharedLibraryFiles = p.usesLibraryFiles;
3625 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003626 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003627 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003628 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003629 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003630 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003631 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 return ai;
3633 }
3634
3635 public static final PermissionInfo generatePermissionInfo(
3636 Permission p, int flags) {
3637 if (p == null) return null;
3638 if ((flags&PackageManager.GET_META_DATA) == 0) {
3639 return p.info;
3640 }
3641 PermissionInfo pi = new PermissionInfo(p.info);
3642 pi.metaData = p.metaData;
3643 return pi;
3644 }
3645
3646 public static final PermissionGroupInfo generatePermissionGroupInfo(
3647 PermissionGroup pg, int flags) {
3648 if (pg == null) return null;
3649 if ((flags&PackageManager.GET_META_DATA) == 0) {
3650 return pg.info;
3651 }
3652 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3653 pgi.metaData = pg.metaData;
3654 return pgi;
3655 }
3656
3657 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003658 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003660 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3661 super(args, _info);
3662 info = _info;
3663 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003665
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003666 public void setPackageName(String packageName) {
3667 super.setPackageName(packageName);
3668 info.packageName = packageName;
3669 }
3670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 public String toString() {
3672 return "Activity{"
3673 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003674 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 }
3676 }
3677
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003678 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3679 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003681 if (!checkUseInstalled(flags, state)) {
3682 return null;
3683 }
3684 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 return a.info;
3686 }
3687 // Make shallow copies so we can store the metadata safely
3688 ActivityInfo ai = new ActivityInfo(a.info);
3689 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003690 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 return ai;
3692 }
3693
3694 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003695 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003697 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3698 super(args, _info);
3699 info = _info;
3700 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003702
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003703 public void setPackageName(String packageName) {
3704 super.setPackageName(packageName);
3705 info.packageName = packageName;
3706 }
3707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 public String toString() {
3709 return "Service{"
3710 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003711 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 }
3713 }
3714
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003715 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3716 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003718 if (!checkUseInstalled(flags, state)) {
3719 return null;
3720 }
3721 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 return s.info;
3723 }
3724 // Make shallow copies so we can store the metadata safely
3725 ServiceInfo si = new ServiceInfo(s.info);
3726 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003727 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 return si;
3729 }
3730
3731 public final static class Provider extends Component {
3732 public final ProviderInfo info;
3733 public boolean syncable;
3734
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003735 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3736 super(args, _info);
3737 info = _info;
3738 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 syncable = false;
3740 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 public Provider(Provider existingProvider) {
3743 super(existingProvider);
3744 this.info = existingProvider.info;
3745 this.syncable = existingProvider.syncable;
3746 }
3747
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003748 public void setPackageName(String packageName) {
3749 super.setPackageName(packageName);
3750 info.packageName = packageName;
3751 }
3752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 public String toString() {
3754 return "Provider{"
3755 + Integer.toHexString(System.identityHashCode(this))
3756 + " " + info.name + "}";
3757 }
3758 }
3759
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003760 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3761 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003763 if (!checkUseInstalled(flags, state)) {
3764 return null;
3765 }
3766 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003768 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 return p.info;
3770 }
3771 // Make shallow copies so we can store the metadata safely
3772 ProviderInfo pi = new ProviderInfo(p.info);
3773 pi.metaData = p.metaData;
3774 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3775 pi.uriPermissionPatterns = null;
3776 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003777 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 return pi;
3779 }
3780
3781 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003782 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003784 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3785 super(args, _info);
3786 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003788
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003789 public void setPackageName(String packageName) {
3790 super.setPackageName(packageName);
3791 info.packageName = packageName;
3792 }
3793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 public String toString() {
3795 return "Instrumentation{"
3796 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003797 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 }
3799 }
3800
3801 public static final InstrumentationInfo generateInstrumentationInfo(
3802 Instrumentation i, int flags) {
3803 if (i == null) return null;
3804 if ((flags&PackageManager.GET_META_DATA) == 0) {
3805 return i.info;
3806 }
3807 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3808 ii.metaData = i.metaData;
3809 return ii;
3810 }
3811
3812 public static class IntentInfo extends IntentFilter {
3813 public boolean hasDefault;
3814 public int labelRes;
3815 public CharSequence nonLocalizedLabel;
3816 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003817 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 }
3819
3820 public final static class ActivityIntentInfo extends IntentInfo {
3821 public final Activity activity;
3822
3823 public ActivityIntentInfo(Activity _activity) {
3824 activity = _activity;
3825 }
3826
3827 public String toString() {
3828 return "ActivityIntentInfo{"
3829 + Integer.toHexString(System.identityHashCode(this))
3830 + " " + activity.info.name + "}";
3831 }
3832 }
3833
3834 public final static class ServiceIntentInfo extends IntentInfo {
3835 public final Service service;
3836
3837 public ServiceIntentInfo(Service _service) {
3838 service = _service;
3839 }
3840
3841 public String toString() {
3842 return "ServiceIntentInfo{"
3843 + Integer.toHexString(System.identityHashCode(this))
3844 + " " + service.info.name + "}";
3845 }
3846 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003847
3848 /**
3849 * @hide
3850 */
3851 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3852 sCompatibilityModeEnabled = compatibilityModeEnabled;
3853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003854}