blob: 34e0c124bb962648d1a5ec3639283a6afe92212d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IntentFilter;
22import android.content.res.AssetManager;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.content.res.XmlResourceParser;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Bundle;
29import android.os.PatternMatcher;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070030import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070032import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070034import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070035import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Kenny Rootd63f7db2010-09-27 08:07:48 -070038import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.File;
40import java.io.IOException;
41import java.io.InputStream;
42import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070043import java.security.KeyFactory;
44import java.security.NoSuchAlgorithmException;
45import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import java.security.cert.Certificate;
47import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070048import java.security.spec.EncodedKeySpec;
49import java.security.spec.InvalidKeySpecException;
50import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import java.util.ArrayList;
52import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080053import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070055import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import java.util.jar.JarEntry;
57import java.util.jar.JarFile;
Kenny Root6c918ce2013-04-02 14:04:24 -070058import java.util.zip.ZipEntry;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Amith Yamasani742a6712011-05-04 14:49:28 -070060import com.android.internal.util.XmlUtils;
61
62import org.xmlpull.v1.XmlPullParser;
63import org.xmlpull.v1.XmlPullParserException;
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065/**
66 * Package archive parsing
67 *
68 * {@hide}
69 */
70public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070071 private static final boolean DEBUG_JAR = false;
72 private static final boolean DEBUG_PARSER = false;
73 private static final boolean DEBUG_BACKUP = false;
74
Kenny Rootbcc954d2011-08-08 16:19:08 -070075 /** File name in an APK for the Android manifest. */
76 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
77
Dianne Hackborna96cbb42009-05-13 15:06:13 -070078 /** @hide */
79 public static class NewPermissionInfo {
80 public final String name;
81 public final int sdkVersion;
82 public final int fileVersion;
83
84 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
85 this.name = name;
86 this.sdkVersion = sdkVersion;
87 this.fileVersion = fileVersion;
88 }
89 }
Dianne Hackborn79245122012-03-12 10:51:26 -070090
91 /** @hide */
92 public static class SplitPermissionInfo {
93 public final String rootPerm;
94 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070095 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070096
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -070098 this.rootPerm = rootPerm;
99 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700100 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700101 }
102 }
103
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700104 /**
105 * List of new permissions that have been added since 1.0.
106 * NOTE: These must be declared in SDK version order, with permissions
107 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700108 * If sdkVersion is 0, then this is not a permission that we want to
109 * automatically add to older apps, but we do want to allow it to be
110 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700111 * @hide
112 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700113 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
114 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700115 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700116 android.os.Build.VERSION_CODES.DONUT, 0),
117 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
118 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700119 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
Dianne Hackborn79245122012-03-12 10:51:26 -0700121 /**
122 * List of permissions that have been split into more granular or dependent
123 * permissions.
124 * @hide
125 */
126 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
127 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700128 // READ_EXTERNAL_STORAGE is always required when an app requests
129 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
130 // write access without read access. The hack here with the target
131 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700132 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700133 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700134 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700135 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
136 new String[] { android.Manifest.permission.READ_CALL_LOG },
137 android.os.Build.VERSION_CODES.JELLY_BEAN),
138 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
139 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
140 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700141 };
142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 private String mArchiveSourcePath;
144 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700145 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700146 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
147 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
148 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
150 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
151
152 private static final Object mSync = new Object();
153 private static WeakReference<byte[]> mReadBuffer;
154
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700155 private static boolean sCompatibilityModeEnabled = true;
156 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700157
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700158 static class ParsePackageItemArgs {
159 final Package owner;
160 final String[] outError;
161 final int nameRes;
162 final int labelRes;
163 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700164 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700165
166 String tag;
167 TypedArray sa;
168
169 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700170 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700171 owner = _owner;
172 outError = _outError;
173 nameRes = _nameRes;
174 labelRes = _labelRes;
175 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700176 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700177 }
178 }
179
180 static class ParseComponentArgs extends ParsePackageItemArgs {
181 final String[] sepProcesses;
182 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800183 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 final int enabledRes;
185 int flags;
186
187 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700188 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800189 String[] _sepProcesses, int _processRes,
190 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700191 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700192 sepProcesses = _sepProcesses;
193 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800194 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700195 enabledRes = _enabledRes;
196 }
197 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800198
199 /* Light weight package info.
200 * @hide
201 */
202 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700203 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700204 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700205 public final int installLocation;
206 public final VerifierInfo[] verifiers;
207
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700208 public PackageLite(String packageName, int versionCode,
209 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800210 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700211 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800212 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700213 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800214 }
215 }
216
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700217 private ParsePackageItemArgs mParseInstrumentationArgs;
218 private ParseComponentArgs mParseActivityArgs;
219 private ParseComponentArgs mParseActivityAliasArgs;
220 private ParseComponentArgs mParseServiceArgs;
221 private ParseComponentArgs mParseProviderArgs;
222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 /** If set to true, we will only allow package files that exactly match
224 * the DTD. Otherwise, we try to get as much from the package as we
225 * can without failing. This should normally be set to false, to
226 * support extensions to the DTD in future versions. */
227 private static final boolean RIGID_PARSER = false;
228
229 private static final String TAG = "PackageParser";
230
231 public PackageParser(String archiveSourcePath) {
232 mArchiveSourcePath = archiveSourcePath;
233 }
234
235 public void setSeparateProcesses(String[] procs) {
236 mSeparateProcesses = procs;
237 }
238
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700239 public void setOnlyCoreApps(boolean onlyCoreApps) {
240 mOnlyCoreApps = onlyCoreApps;
241 }
242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 private static final boolean isPackageFilename(String name) {
244 return name.endsWith(".apk");
245 }
246
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700247 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700248 public static PackageInfo generatePackageInfo(PackageParser.Package p,
249 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
250 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700251 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700252 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700253 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700254 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700255 */
Amith Yamasani13593602012-03-22 16:16:17 -0700256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 /**
258 * Generate and return the {@link PackageInfo} for a parsed package.
259 *
260 * @param p the parsed package.
261 * @param flags indicating which optional information is included.
262 */
263 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800264 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700265 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266
Amith Yamasani483f3b02012-03-13 16:08:00 -0700267 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700268 grantedPermissions, state, UserHandle.getCallingUserId());
269 }
270
271 private static boolean checkUseInstalled(int flags, PackageUserState state) {
272 return state.installed || ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700273 }
274
Amith Yamasani13593602012-03-22 16:16:17 -0700275 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700276 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700277 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700278
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700279 if (!checkUseInstalled(flags, state)) {
280 return null;
281 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 PackageInfo pi = new PackageInfo();
283 pi.packageName = p.packageName;
284 pi.versionCode = p.mVersionCode;
285 pi.versionName = p.mVersionName;
286 pi.sharedUserId = p.mSharedUserId;
287 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700288 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800289 pi.installLocation = p.installLocation;
Amith Yamasani0d8750d2013-05-01 15:25:28 -0700290 if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0
291 || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
292 pi.requiredForAllUsers = p.mRequiredForAllUsers;
293 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700294 pi.restrictedAccountType = p.mRestrictedAccountType;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700295 pi.requiredAccountType = p.mRequiredAccountType;
Dianne Hackborn78d6883692010-10-07 01:12:46 -0700296 pi.firstInstallTime = firstInstallTime;
297 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 if ((flags&PackageManager.GET_GIDS) != 0) {
299 pi.gids = gids;
300 }
301 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
302 int N = p.configPreferences.size();
303 if (N > 0) {
304 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700305 p.configPreferences.toArray(pi.configPreferences);
306 }
307 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
308 if (N > 0) {
309 pi.reqFeatures = new FeatureInfo[N];
310 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 }
312 }
313 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
314 int N = p.activities.size();
315 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700316 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
317 pi.activities = new ActivityInfo[N];
318 } else {
319 int num = 0;
320 for (int i=0; i<N; i++) {
321 if (p.activities.get(i).info.enabled) num++;
322 }
323 pi.activities = new ActivityInfo[num];
324 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700325 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 final Activity activity = p.activities.get(i);
327 if (activity.info.enabled
328 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700329 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700330 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
332 }
333 }
334 }
335 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
336 int N = p.receivers.size();
337 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700338 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
339 pi.receivers = new ActivityInfo[N];
340 } else {
341 int num = 0;
342 for (int i=0; i<N; i++) {
343 if (p.receivers.get(i).info.enabled) num++;
344 }
345 pi.receivers = new ActivityInfo[num];
346 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700347 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 final Activity activity = p.receivers.get(i);
349 if (activity.info.enabled
350 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700351 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700352 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354 }
355 }
356 }
357 if ((flags&PackageManager.GET_SERVICES) != 0) {
358 int N = p.services.size();
359 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700360 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
361 pi.services = new ServiceInfo[N];
362 } else {
363 int num = 0;
364 for (int i=0; i<N; i++) {
365 if (p.services.get(i).info.enabled) num++;
366 }
367 pi.services = new ServiceInfo[num];
368 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700369 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 final Service service = p.services.get(i);
371 if (service.info.enabled
372 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700373 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
374 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 }
376 }
377 }
378 }
379 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
380 int N = p.providers.size();
381 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700382 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
383 pi.providers = new ProviderInfo[N];
384 } else {
385 int num = 0;
386 for (int i=0; i<N; i++) {
387 if (p.providers.get(i).info.enabled) num++;
388 }
389 pi.providers = new ProviderInfo[num];
390 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700391 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 final Provider provider = p.providers.get(i);
393 if (provider.info.enabled
394 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700395 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
396 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 }
398 }
399 }
400 }
401 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
402 int N = p.instrumentation.size();
403 if (N > 0) {
404 pi.instrumentation = new InstrumentationInfo[N];
405 for (int i=0; i<N; i++) {
406 pi.instrumentation[i] = generateInstrumentationInfo(
407 p.instrumentation.get(i), flags);
408 }
409 }
410 }
411 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
412 int N = p.permissions.size();
413 if (N > 0) {
414 pi.permissions = new PermissionInfo[N];
415 for (int i=0; i<N; i++) {
416 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
417 }
418 }
419 N = p.requestedPermissions.size();
420 if (N > 0) {
421 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800422 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800424 final String perm = p.requestedPermissions.get(i);
425 pi.requestedPermissions[i] = perm;
426 if (p.requestedPermissionsRequired.get(i)) {
427 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
428 }
429 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
430 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
433 }
434 }
435 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700436 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
437 if (N > 0) {
438 pi.signatures = new Signature[N];
439 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 }
441 }
442 return pi;
443 }
444
445 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
446 byte[] readBuffer) {
447 try {
448 // We must read the stream for the JarEntry to retrieve
449 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700450 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
452 // not using
453 }
454 is.close();
455 return je != null ? je.getCertificates() : null;
456 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700457 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700459 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700460 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700461 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463 return null;
464 }
465
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800466 public final static int PARSE_IS_SYSTEM = 1<<0;
467 public final static int PARSE_CHATTY = 1<<1;
468 public final static int PARSE_MUST_BE_APK = 1<<2;
469 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
470 public final static int PARSE_FORWARD_LOCK = 1<<4;
471 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700472 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473
474 public int getParseError() {
475 return mParseError;
476 }
477
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800478 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 DisplayMetrics metrics, int flags) {
480 mParseError = PackageManager.INSTALL_SUCCEEDED;
481
482 mArchiveSourcePath = sourceFile.getPath();
483 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700484 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
486 return null;
487 }
488 if (!isPackageFilename(sourceFile.getName())
489 && (flags&PARSE_MUST_BE_APK) != 0) {
490 if ((flags&PARSE_IS_SYSTEM) == 0) {
491 // We expect to have non-.apk files in the system dir,
492 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700493 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 }
495 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
496 return null;
497 }
498
Kenny Rootd2d29252011-08-08 11:27:57 -0700499 if (DEBUG_JAR)
500 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
502 XmlResourceParser parser = null;
503 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800504 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 boolean assetError = true;
506 try {
507 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700508 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800509 if (cookie != 0) {
510 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700511 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 -0800512 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700513 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 assetError = false;
515 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700516 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
518 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700519 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 + mArchiveSourcePath, e);
521 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800522 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 if (assmgr != null) assmgr.close();
524 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
525 return null;
526 }
527 String[] errorText = new String[1];
528 Package pkg = null;
529 Exception errorException = null;
530 try {
531 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 pkg = parsePackage(res, parser, flags, errorText);
533 } catch (Exception e) {
534 errorException = e;
535 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
536 }
537
538
539 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700540 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
541 // just means to skip this app so don't make a fuss about it.
542 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
543 if (errorException != null) {
544 Slog.w(TAG, mArchiveSourcePath, errorException);
545 } else {
546 Slog.w(TAG, mArchiveSourcePath + " (at "
547 + parser.getPositionDescription()
548 + "): " + errorText[0]);
549 }
550 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
551 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 }
554 parser.close();
555 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 return null;
557 }
558
559 parser.close();
560 assmgr.close();
561
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800562 // Set code and resource paths
563 pkg.mPath = destCodePath;
564 pkg.mScanPath = mArchiveSourcePath;
565 //pkg.applicationInfo.sourceDir = destCodePath;
566 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 pkg.mSignatures = null;
568
569 return pkg;
570 }
571
Kenny Root6c918ce2013-04-02 14:04:24 -0700572 /**
573 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
574 * APK. If it successfully scanned the package and found the
575 * {@code AndroidManifest.xml}, {@code true} is returned.
576 */
577 public boolean collectManifestDigest(Package pkg) {
578 try {
579 final JarFile jarFile = new JarFile(mArchiveSourcePath);
580 try {
581 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
582 if (je != null) {
583 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
584 }
585 } finally {
586 jarFile.close();
587 }
588 return true;
589 } catch (IOException e) {
590 return false;
591 }
592 }
593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 public boolean collectCertificates(Package pkg, int flags) {
595 pkg.mSignatures = null;
596
597 WeakReference<byte[]> readBufferRef;
598 byte[] readBuffer = null;
599 synchronized (mSync) {
600 readBufferRef = mReadBuffer;
601 if (readBufferRef != null) {
602 mReadBuffer = null;
603 readBuffer = readBufferRef.get();
604 }
605 if (readBuffer == null) {
606 readBuffer = new byte[8192];
607 readBufferRef = new WeakReference<byte[]>(readBuffer);
608 }
609 }
610
611 try {
612 JarFile jarFile = new JarFile(mArchiveSourcePath);
613
614 Certificate[] certs = null;
615
616 if ((flags&PARSE_IS_SYSTEM) != 0) {
617 // If this package comes from the system image, then we
618 // can trust it... we'll just use the AndroidManifest.xml
619 // to retrieve its signatures, not validating all of the
620 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700621 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 certs = loadCertificates(jarFile, jarEntry, readBuffer);
623 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700624 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 + " has no certificates at entry "
626 + jarEntry.getName() + "; ignoring!");
627 jarFile.close();
628 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
629 return false;
630 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700631 if (DEBUG_JAR) {
632 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 + " certs=" + (certs != null ? certs.length : 0));
634 if (certs != null) {
635 final int N = certs.length;
636 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700637 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 + certs[i].getPublicKey().getEncoded()
639 + " " + certs[i].getPublicKey());
640 }
641 }
642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700644 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700646 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700648
Kenny Rootbcc954d2011-08-08 16:19:08 -0700649 final String name = je.getName();
650
651 if (name.startsWith("META-INF/"))
652 continue;
653
654 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700655 pkg.manifestDigest =
656 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700657 }
658
659 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700660 if (DEBUG_JAR) {
661 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 + ": certs=" + certs + " ("
663 + (certs != null ? certs.length : 0) + ")");
664 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700667 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 + " has no certificates at entry "
669 + je.getName() + "; ignoring!");
670 jarFile.close();
671 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
672 return false;
673 } else if (certs == null) {
674 certs = localCerts;
675 } else {
676 // Ensure all certificates match.
677 for (int i=0; i<certs.length; i++) {
678 boolean found = false;
679 for (int j=0; j<localCerts.length; j++) {
680 if (certs[i] != null &&
681 certs[i].equals(localCerts[j])) {
682 found = true;
683 break;
684 }
685 }
686 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700687 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 + " has mismatched certificates at entry "
689 + je.getName() + "; ignoring!");
690 jarFile.close();
691 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
692 return false;
693 }
694 }
695 }
696 }
697 }
698 jarFile.close();
699
700 synchronized (mSync) {
701 mReadBuffer = readBufferRef;
702 }
703
704 if (certs != null && certs.length > 0) {
705 final int N = certs.length;
706 pkg.mSignatures = new Signature[certs.length];
707 for (int i=0; i<N; i++) {
708 pkg.mSignatures[i] = new Signature(
709 certs[i].getEncoded());
710 }
711 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700712 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 + " has no certificates; ignoring!");
714 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
715 return false;
716 }
717 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700718 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
720 return false;
721 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700722 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
724 return false;
725 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700726 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
728 return false;
729 }
730
731 return true;
732 }
733
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800734 /*
735 * Utility method that retrieves just the package name and install
736 * location from the apk location at the given file path.
737 * @param packageFilePath file location of the apk
738 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700739 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800740 */
741 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700743 final XmlResourceParser parser;
744 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 try {
746 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700747 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 -0800748 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700751 if (cookie == 0) {
752 return null;
753 }
754
Kenny Root05ca4c92011-09-15 10:36:25 -0700755 final DisplayMetrics metrics = new DisplayMetrics();
756 metrics.setToDefaults();
757 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700758 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 } catch (Exception e) {
760 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700761 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 + packageFilePath, e);
763 return null;
764 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700765
766 final AttributeSet attrs = parser;
767 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800768 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700770 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700772 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700774 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 } finally {
776 if (parser != null) parser.close();
777 if (assmgr != null) assmgr.close();
778 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800779 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700780 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 return null;
782 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800783 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 }
785
786 private static String validateName(String name, boolean requiresSeparator) {
787 final int N = name.length();
788 boolean hasSep = false;
789 boolean front = true;
790 for (int i=0; i<N; i++) {
791 final char c = name.charAt(i);
792 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
793 front = false;
794 continue;
795 }
796 if (!front) {
797 if ((c >= '0' && c <= '9') || c == '_') {
798 continue;
799 }
800 }
801 if (c == '.') {
802 hasSep = true;
803 front = true;
804 continue;
805 }
806 return "bad character '" + c + "'";
807 }
808 return hasSep || !requiresSeparator
809 ? null : "must have at least one '.' separator";
810 }
811
812 private static String parsePackageName(XmlPullParser parser,
813 AttributeSet attrs, int flags, String[] outError)
814 throws IOException, XmlPullParserException {
815
816 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700817 while ((type = parser.next()) != XmlPullParser.START_TAG
818 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 ;
820 }
821
Kenny Rootd2d29252011-08-08 11:27:57 -0700822 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 outError[0] = "No start tag found";
824 return null;
825 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700826 if (DEBUG_PARSER)
827 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 if (!parser.getName().equals("manifest")) {
829 outError[0] = "No <manifest> tag";
830 return null;
831 }
832 String pkgName = attrs.getAttributeValue(null, "package");
833 if (pkgName == null || pkgName.length() == 0) {
834 outError[0] = "<manifest> does not specify package";
835 return null;
836 }
837 String nameError = validateName(pkgName, true);
838 if (nameError != null && !"android".equals(pkgName)) {
839 outError[0] = "<manifest> specifies bad package name \""
840 + pkgName + "\": " + nameError;
841 return null;
842 }
843
844 return pkgName.intern();
845 }
846
Kenny Root05ca4c92011-09-15 10:36:25 -0700847 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
848 AttributeSet attrs, int flags, String[] outError) throws IOException,
849 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800850
851 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700852 while ((type = parser.next()) != XmlPullParser.START_TAG
853 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800854 ;
855 }
856
Kenny Rootd2d29252011-08-08 11:27:57 -0700857 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800858 outError[0] = "No start tag found";
859 return null;
860 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700861 if (DEBUG_PARSER)
862 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800863 if (!parser.getName().equals("manifest")) {
864 outError[0] = "No <manifest> tag";
865 return null;
866 }
867 String pkgName = attrs.getAttributeValue(null, "package");
868 if (pkgName == null || pkgName.length() == 0) {
869 outError[0] = "<manifest> does not specify package";
870 return null;
871 }
872 String nameError = validateName(pkgName, true);
873 if (nameError != null && !"android".equals(pkgName)) {
874 outError[0] = "<manifest> specifies bad package name \""
875 + pkgName + "\": " + nameError;
876 return null;
877 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700878 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700879 int versionCode = 0;
880 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800881 for (int i = 0; i < attrs.getAttributeCount(); i++) {
882 String attr = attrs.getAttributeName(i);
883 if (attr.equals("installLocation")) {
884 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700885 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700886 numFound++;
887 } else if (attr.equals("versionCode")) {
888 versionCode = attrs.getAttributeIntValue(i, 0);
889 numFound++;
890 }
891 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800892 break;
893 }
894 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700895
896 // Only search the tree when the tag is directly below <manifest>
897 final int searchDepth = parser.getDepth() + 1;
898
899 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
900 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
901 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
902 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
903 continue;
904 }
905
906 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
907 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
908 if (verifier != null) {
909 verifiers.add(verifier);
910 }
911 }
912 }
913
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700914 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800915 }
916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 /**
918 * Temporary.
919 */
920 static public Signature stringToSignature(String str) {
921 final int N = str.length();
922 byte[] sig = new byte[N];
923 for (int i=0; i<N; i++) {
924 sig[i] = (byte)str.charAt(i);
925 }
926 return new Signature(sig);
927 }
928
929 private Package parsePackage(
930 Resources res, XmlResourceParser parser, int flags, String[] outError)
931 throws XmlPullParserException, IOException {
932 AttributeSet attrs = parser;
933
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700934 mParseInstrumentationArgs = null;
935 mParseActivityArgs = null;
936 mParseServiceArgs = null;
937 mParseProviderArgs = null;
938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 String pkgName = parsePackageName(parser, attrs, flags, outError);
940 if (pkgName == null) {
941 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
942 return null;
943 }
944 int type;
945
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700946 if (mOnlyCoreApps) {
947 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
948 if (!core) {
949 mParseError = PackageManager.INSTALL_SUCCEEDED;
950 return null;
951 }
952 }
953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 TypedArray sa = res.obtainAttributes(attrs,
958 com.android.internal.R.styleable.AndroidManifest);
959 pkg.mVersionCode = sa.getInteger(
960 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800961 pkg.mVersionName = sa.getNonConfigurationString(
962 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 if (pkg.mVersionName != null) {
964 pkg.mVersionName = pkg.mVersionName.intern();
965 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800966 String str = sa.getNonConfigurationString(
967 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
968 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 String nameError = validateName(str, true);
970 if (nameError != null && !"android".equals(pkgName)) {
971 outError[0] = "<manifest> specifies bad sharedUserId name \""
972 + str + "\": " + nameError;
973 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
974 return null;
975 }
976 pkg.mSharedUserId = str.intern();
977 pkg.mSharedUserLabel = sa.getResourceId(
978 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
979 }
980 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800981
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800982 pkg.installLocation = sa.getInteger(
983 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700984 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700985 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700986
987 /* Set the global "forward lock" flag */
988 if ((flags & PARSE_FORWARD_LOCK) != 0) {
989 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
990 }
991
992 /* Set the global "on SD card" flag */
993 if ((flags & PARSE_ON_SDCARD) != 0) {
994 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
995 }
996
Dianne Hackborn723738c2009-06-25 19:48:04 -0700997 // Resource boolean are -1, so 1 means we don't know the value.
998 int supportsSmallScreens = 1;
999 int supportsNormalScreens = 1;
1000 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001001 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001002 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001003 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001006 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1007 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1008 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 continue;
1010 }
1011
1012 String tagName = parser.getName();
1013 if (tagName.equals("application")) {
1014 if (foundApp) {
1015 if (RIGID_PARSER) {
1016 outError[0] = "<manifest> has more than one <application>";
1017 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1018 return null;
1019 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001020 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 XmlUtils.skipCurrentTag(parser);
1022 continue;
1023 }
1024 }
1025
1026 foundApp = true;
1027 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1028 return null;
1029 }
1030 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001031 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 return null;
1033 }
1034 } else if (tagName.equals("permission")) {
1035 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1036 return null;
1037 }
1038 } else if (tagName.equals("permission-tree")) {
1039 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1040 return null;
1041 }
1042 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001043 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1044 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 } else if (tagName.equals("uses-configuration")) {
1048 ConfigurationInfo cPref = new ConfigurationInfo();
1049 sa = res.obtainAttributes(attrs,
1050 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1051 cPref.reqTouchScreen = sa.getInt(
1052 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1053 Configuration.TOUCHSCREEN_UNDEFINED);
1054 cPref.reqKeyboardType = sa.getInt(
1055 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1056 Configuration.KEYBOARD_UNDEFINED);
1057 if (sa.getBoolean(
1058 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1059 false)) {
1060 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1061 }
1062 cPref.reqNavigation = sa.getInt(
1063 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1064 Configuration.NAVIGATION_UNDEFINED);
1065 if (sa.getBoolean(
1066 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1067 false)) {
1068 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1069 }
1070 sa.recycle();
1071 pkg.configPreferences.add(cPref);
1072
1073 XmlUtils.skipCurrentTag(parser);
1074
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001075 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001076 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001077 sa = res.obtainAttributes(attrs,
1078 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001079 // Note: don't allow this value to be a reference to a resource
1080 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001081 fi.name = sa.getNonResourceString(
1082 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1083 if (fi.name == null) {
1084 fi.reqGlEsVersion = sa.getInt(
1085 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1086 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1087 }
1088 if (sa.getBoolean(
1089 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1090 true)) {
1091 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1092 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001093 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001094 if (pkg.reqFeatures == null) {
1095 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1096 }
1097 pkg.reqFeatures.add(fi);
1098
1099 if (fi.name == null) {
1100 ConfigurationInfo cPref = new ConfigurationInfo();
1101 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1102 pkg.configPreferences.add(cPref);
1103 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001104
1105 XmlUtils.skipCurrentTag(parser);
1106
Dianne Hackborn851a5412009-05-08 12:06:44 -07001107 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001108 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 sa = res.obtainAttributes(attrs,
1110 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1111
Dianne Hackborn851a5412009-05-08 12:06:44 -07001112 int minVers = 0;
1113 String minCode = null;
1114 int targetVers = 0;
1115 String targetCode = null;
1116
1117 TypedValue val = sa.peekValue(
1118 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1119 if (val != null) {
1120 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1121 targetCode = minCode = val.string.toString();
1122 } else {
1123 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001124 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001125 }
1126 }
1127
1128 val = sa.peekValue(
1129 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1130 if (val != null) {
1131 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1132 targetCode = minCode = val.string.toString();
1133 } else {
1134 // If it's not a string, it's an integer.
1135 targetVers = val.data;
1136 }
1137 }
1138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 sa.recycle();
1140
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001141 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001142 if (!minCode.equals(SDK_CODENAME)) {
1143 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001144 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001145 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001146 } else {
1147 outError[0] = "Requires development platform " + minCode
1148 + " but this is a release platform.";
1149 }
1150 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1151 return null;
1152 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001153 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001154 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001155 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001156 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1157 return null;
1158 }
1159
Dianne Hackborn851a5412009-05-08 12:06:44 -07001160 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001161 if (!targetCode.equals(SDK_CODENAME)) {
1162 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001163 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001164 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001165 } else {
1166 outError[0] = "Requires development platform " + targetCode
1167 + " but this is a release platform.";
1168 }
1169 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1170 return null;
1171 }
1172 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001173 pkg.applicationInfo.targetSdkVersion
1174 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1175 } else {
1176 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179
1180 XmlUtils.skipCurrentTag(parser);
1181
Dianne Hackborn723738c2009-06-25 19:48:04 -07001182 } else if (tagName.equals("supports-screens")) {
1183 sa = res.obtainAttributes(attrs,
1184 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1185
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001186 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1187 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1188 0);
1189 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1190 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1191 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001192 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1193 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1194 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001195
Dianne Hackborn723738c2009-06-25 19:48:04 -07001196 // This is a trick to get a boolean and still able to detect
1197 // if a value was actually set.
1198 supportsSmallScreens = sa.getInteger(
1199 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1200 supportsSmallScreens);
1201 supportsNormalScreens = sa.getInteger(
1202 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1203 supportsNormalScreens);
1204 supportsLargeScreens = sa.getInteger(
1205 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1206 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001207 supportsXLargeScreens = sa.getInteger(
1208 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1209 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001210 resizeable = sa.getInteger(
1211 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001212 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001213 anyDensity = sa.getInteger(
1214 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1215 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001216
1217 sa.recycle();
1218
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001219 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060af2009-07-09 18:14:31 -07001220
1221 } else if (tagName.equals("protected-broadcast")) {
1222 sa = res.obtainAttributes(attrs,
1223 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1224
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001225 // Note: don't allow this value to be a reference to a resource
1226 // that may change.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001227 String name = sa.getNonResourceString(
1228 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1229
1230 sa.recycle();
1231
1232 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1233 if (pkg.protectedBroadcasts == null) {
1234 pkg.protectedBroadcasts = new ArrayList<String>();
1235 }
1236 if (!pkg.protectedBroadcasts.contains(name)) {
1237 pkg.protectedBroadcasts.add(name.intern());
1238 }
1239 }
1240
1241 XmlUtils.skipCurrentTag(parser);
1242
1243 } else if (tagName.equals("instrumentation")) {
1244 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1245 return null;
1246 }
1247
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001248 } else if (tagName.equals("original-package")) {
1249 sa = res.obtainAttributes(attrs,
1250 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1251
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001252 String orig =sa.getNonConfigurationString(
1253 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001254 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001255 if (pkg.mOriginalPackages == null) {
1256 pkg.mOriginalPackages = new ArrayList<String>();
1257 pkg.mRealPackage = pkg.packageName;
1258 }
1259 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001260 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001261
1262 sa.recycle();
1263
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001264 XmlUtils.skipCurrentTag(parser);
1265
1266 } else if (tagName.equals("adopt-permissions")) {
1267 sa = res.obtainAttributes(attrs,
1268 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1269
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001270 String name = sa.getNonConfigurationString(
1271 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001272
1273 sa.recycle();
1274
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001275 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001276 if (pkg.mAdoptPermissions == null) {
1277 pkg.mAdoptPermissions = new ArrayList<String>();
1278 }
1279 pkg.mAdoptPermissions.add(name);
1280 }
1281
1282 XmlUtils.skipCurrentTag(parser);
1283
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001284 } else if (tagName.equals("uses-gl-texture")) {
1285 // Just skip this tag
1286 XmlUtils.skipCurrentTag(parser);
1287 continue;
1288
1289 } else if (tagName.equals("compatible-screens")) {
1290 // Just skip this tag
1291 XmlUtils.skipCurrentTag(parser);
1292 continue;
1293
Dianne Hackborn854060af2009-07-09 18:14:31 -07001294 } else if (tagName.equals("eat-comment")) {
1295 // Just skip this tag
1296 XmlUtils.skipCurrentTag(parser);
1297 continue;
1298
1299 } else if (RIGID_PARSER) {
1300 outError[0] = "Bad element under <manifest>: "
1301 + parser.getName();
1302 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1303 return null;
1304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001306 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001307 + " at " + mArchiveSourcePath + " "
1308 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 XmlUtils.skipCurrentTag(parser);
1310 continue;
1311 }
1312 }
1313
1314 if (!foundApp && pkg.instrumentation.size() == 0) {
1315 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1316 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1317 }
1318
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001319 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001320 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001321 for (int ip=0; ip<NP; ip++) {
1322 final PackageParser.NewPermissionInfo npi
1323 = PackageParser.NEW_PERMISSIONS[ip];
1324 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1325 break;
1326 }
1327 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001328 if (implicitPerms == null) {
1329 implicitPerms = new StringBuilder(128);
1330 implicitPerms.append(pkg.packageName);
1331 implicitPerms.append(": compat added ");
1332 } else {
1333 implicitPerms.append(' ');
1334 }
1335 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001336 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001337 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001338 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001339 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001340 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001341 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001342 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001343
1344 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1345 for (int is=0; is<NS; is++) {
1346 final PackageParser.SplitPermissionInfo spi
1347 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001348 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1349 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001350 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001351 }
1352 for (int in=0; in<spi.newPerms.length; in++) {
1353 final String perm = spi.newPerms[in];
1354 if (!pkg.requestedPermissions.contains(perm)) {
1355 pkg.requestedPermissions.add(perm);
1356 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1357 }
1358 }
1359 }
1360
Dianne Hackborn723738c2009-06-25 19:48:04 -07001361 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1362 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001363 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001364 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1365 }
1366 if (supportsNormalScreens != 0) {
1367 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1368 }
1369 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1370 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001371 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001372 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1373 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001374 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1375 && pkg.applicationInfo.targetSdkVersion
1376 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1377 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1378 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001379 if (resizeable < 0 || (resizeable > 0
1380 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001381 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001382 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1383 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001384 if (anyDensity < 0 || (anyDensity > 0
1385 && pkg.applicationInfo.targetSdkVersion
1386 >= android.os.Build.VERSION_CODES.DONUT)) {
1387 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001388 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001389
Nick Kralevich38f130e2013-04-04 13:19:10 -07001390 /*
1391 * b/8528162: Ignore the <uses-permission android:required> attribute if
1392 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1393 * which are improperly using this attribute, even though it never worked.
1394 */
1395 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1396 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1397 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1398 }
1399 }
1400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 return pkg;
1402 }
1403
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001404 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1405 AttributeSet attrs, String[] outError)
1406 throws XmlPullParserException, IOException {
1407 TypedArray sa = res.obtainAttributes(attrs,
1408 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1409
1410 // Note: don't allow this value to be a reference to a resource
1411 // that may change.
1412 String name = sa.getNonResourceString(
1413 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b182013-04-11 10:20:09 -07001414/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001415 boolean required = sa.getBoolean(
1416 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b182013-04-11 10:20:09 -07001417*/
1418 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001419
1420 sa.recycle();
1421
1422 if (name != null) {
1423 int index = pkg.requestedPermissions.indexOf(name);
1424 if (index == -1) {
1425 pkg.requestedPermissions.add(name.intern());
1426 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1427 } else {
1428 if (pkg.requestedPermissionsRequired.get(index) != required) {
1429 outError[0] = "conflicting <uses-permission> entries";
1430 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1431 return false;
1432 }
1433 }
1434 }
1435
1436 XmlUtils.skipCurrentTag(parser);
1437 return true;
1438 }
1439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 private static String buildClassName(String pkg, CharSequence clsSeq,
1441 String[] outError) {
1442 if (clsSeq == null || clsSeq.length() <= 0) {
1443 outError[0] = "Empty class name in package " + pkg;
1444 return null;
1445 }
1446 String cls = clsSeq.toString();
1447 char c = cls.charAt(0);
1448 if (c == '.') {
1449 return (pkg + cls).intern();
1450 }
1451 if (cls.indexOf('.') < 0) {
1452 StringBuilder b = new StringBuilder(pkg);
1453 b.append('.');
1454 b.append(cls);
1455 return b.toString().intern();
1456 }
1457 if (c >= 'a' && c <= 'z') {
1458 return cls.intern();
1459 }
1460 outError[0] = "Bad class name " + cls + " in package " + pkg;
1461 return null;
1462 }
1463
1464 private static String buildCompoundName(String pkg,
1465 CharSequence procSeq, String type, String[] outError) {
1466 String proc = procSeq.toString();
1467 char c = proc.charAt(0);
1468 if (pkg != null && c == ':') {
1469 if (proc.length() < 2) {
1470 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1471 + ": must be at least two characters";
1472 return null;
1473 }
1474 String subName = proc.substring(1);
1475 String nameError = validateName(subName, false);
1476 if (nameError != null) {
1477 outError[0] = "Invalid " + type + " name " + proc + " in package "
1478 + pkg + ": " + nameError;
1479 return null;
1480 }
1481 return (pkg + proc).intern();
1482 }
1483 String nameError = validateName(proc, true);
1484 if (nameError != null && !"system".equals(proc)) {
1485 outError[0] = "Invalid " + type + " name " + proc + " in package "
1486 + pkg + ": " + nameError;
1487 return null;
1488 }
1489 return proc.intern();
1490 }
1491
1492 private static String buildProcessName(String pkg, String defProc,
1493 CharSequence procSeq, int flags, String[] separateProcesses,
1494 String[] outError) {
1495 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1496 return defProc != null ? defProc : pkg;
1497 }
1498 if (separateProcesses != null) {
1499 for (int i=separateProcesses.length-1; i>=0; i--) {
1500 String sp = separateProcesses[i];
1501 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1502 return pkg;
1503 }
1504 }
1505 }
1506 if (procSeq == null || procSeq.length() <= 0) {
1507 return defProc;
1508 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001509 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 }
1511
1512 private static String buildTaskAffinityName(String pkg, String defProc,
1513 CharSequence procSeq, String[] outError) {
1514 if (procSeq == null) {
1515 return defProc;
1516 }
1517 if (procSeq.length() <= 0) {
1518 return null;
1519 }
1520 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1521 }
1522
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001523 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 XmlPullParser parser, AttributeSet attrs, String[] outError)
1525 throws XmlPullParserException, IOException {
1526 PermissionGroup perm = new PermissionGroup(owner);
1527
1528 TypedArray sa = res.obtainAttributes(attrs,
1529 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1530
1531 if (!parsePackageItemInfo(owner, perm.info, outError,
1532 "<permission-group>", sa,
1533 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1534 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001535 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1536 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 sa.recycle();
1538 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1539 return null;
1540 }
1541
1542 perm.info.descriptionRes = sa.getResourceId(
1543 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1544 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001545 perm.info.flags = sa.getInt(
1546 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001547 perm.info.priority = sa.getInt(
1548 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001549 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001550 perm.info.priority = 0;
1551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552
1553 sa.recycle();
1554
1555 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1556 outError)) {
1557 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1558 return null;
1559 }
1560
1561 owner.permissionGroups.add(perm);
1562
1563 return perm;
1564 }
1565
1566 private Permission parsePermission(Package owner, Resources res,
1567 XmlPullParser parser, AttributeSet attrs, String[] outError)
1568 throws XmlPullParserException, IOException {
1569 Permission perm = new Permission(owner);
1570
1571 TypedArray sa = res.obtainAttributes(attrs,
1572 com.android.internal.R.styleable.AndroidManifestPermission);
1573
1574 if (!parsePackageItemInfo(owner, perm.info, outError,
1575 "<permission>", sa,
1576 com.android.internal.R.styleable.AndroidManifestPermission_name,
1577 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001578 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1579 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 sa.recycle();
1581 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1582 return null;
1583 }
1584
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001585 // Note: don't allow this value to be a reference to a resource
1586 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 perm.info.group = sa.getNonResourceString(
1588 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1589 if (perm.info.group != null) {
1590 perm.info.group = perm.info.group.intern();
1591 }
1592
1593 perm.info.descriptionRes = sa.getResourceId(
1594 com.android.internal.R.styleable.AndroidManifestPermission_description,
1595 0);
1596
1597 perm.info.protectionLevel = sa.getInt(
1598 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1599 PermissionInfo.PROTECTION_NORMAL);
1600
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001601 perm.info.flags = sa.getInt(
1602 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 if (perm.info.protectionLevel == -1) {
1607 outError[0] = "<permission> does not specify protectionLevel";
1608 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1609 return null;
1610 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001611
1612 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1613
1614 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1615 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1616 PermissionInfo.PROTECTION_SIGNATURE) {
1617 outError[0] = "<permission> protectionLevel specifies a flag but is "
1618 + "not based on signature type";
1619 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1620 return null;
1621 }
1622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623
1624 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1625 outError)) {
1626 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1627 return null;
1628 }
1629
1630 owner.permissions.add(perm);
1631
1632 return perm;
1633 }
1634
1635 private Permission parsePermissionTree(Package owner, Resources res,
1636 XmlPullParser parser, AttributeSet attrs, String[] outError)
1637 throws XmlPullParserException, IOException {
1638 Permission perm = new Permission(owner);
1639
1640 TypedArray sa = res.obtainAttributes(attrs,
1641 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1642
1643 if (!parsePackageItemInfo(owner, perm.info, outError,
1644 "<permission-tree>", sa,
1645 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1646 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001647 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1648 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
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
1654 sa.recycle();
1655
1656 int index = perm.info.name.indexOf('.');
1657 if (index > 0) {
1658 index = perm.info.name.indexOf('.', index+1);
1659 }
1660 if (index < 0) {
1661 outError[0] = "<permission-tree> name has less than three segments: "
1662 + perm.info.name;
1663 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1664 return null;
1665 }
1666
1667 perm.info.descriptionRes = 0;
1668 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1669 perm.tree = true;
1670
1671 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1672 outError)) {
1673 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1674 return null;
1675 }
1676
1677 owner.permissions.add(perm);
1678
1679 return perm;
1680 }
1681
1682 private Instrumentation parseInstrumentation(Package owner, Resources res,
1683 XmlPullParser parser, AttributeSet attrs, String[] outError)
1684 throws XmlPullParserException, IOException {
1685 TypedArray sa = res.obtainAttributes(attrs,
1686 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1687
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001688 if (mParseInstrumentationArgs == null) {
1689 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1690 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1691 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001692 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1693 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001694 mParseInstrumentationArgs.tag = "<instrumentation>";
1695 }
1696
1697 mParseInstrumentationArgs.sa = sa;
1698
1699 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1700 new InstrumentationInfo());
1701 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 sa.recycle();
1703 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1704 return null;
1705 }
1706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001708 // Note: don't allow this value to be a reference to a resource
1709 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 str = sa.getNonResourceString(
1711 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1712 a.info.targetPackage = str != null ? str.intern() : null;
1713
1714 a.info.handleProfiling = sa.getBoolean(
1715 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1716 false);
1717
1718 a.info.functionalTest = sa.getBoolean(
1719 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1720 false);
1721
1722 sa.recycle();
1723
1724 if (a.info.targetPackage == null) {
1725 outError[0] = "<instrumentation> does not specify targetPackage";
1726 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1727 return null;
1728 }
1729
1730 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1731 outError)) {
1732 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1733 return null;
1734 }
1735
1736 owner.instrumentation.add(a);
1737
1738 return a;
1739 }
1740
1741 private boolean parseApplication(Package owner, Resources res,
1742 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1743 throws XmlPullParserException, IOException {
1744 final ApplicationInfo ai = owner.applicationInfo;
1745 final String pkgName = owner.applicationInfo.packageName;
1746
1747 TypedArray sa = res.obtainAttributes(attrs,
1748 com.android.internal.R.styleable.AndroidManifestApplication);
1749
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001750 String name = sa.getNonConfigurationString(
1751 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 if (name != null) {
1753 ai.className = buildClassName(pkgName, name, outError);
1754 if (ai.className == null) {
1755 sa.recycle();
1756 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1757 return false;
1758 }
1759 }
1760
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001761 String manageSpaceActivity = sa.getNonConfigurationString(
1762 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 if (manageSpaceActivity != null) {
1764 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1765 outError);
1766 }
1767
Christopher Tate181fafa2009-05-14 11:12:14 -07001768 boolean allowBackup = sa.getBoolean(
1769 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1770 if (allowBackup) {
1771 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001772
Christopher Tate3de55bc2010-03-12 17:28:08 -08001773 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1774 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001775 String backupAgent = sa.getNonConfigurationString(
1776 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001777 if (backupAgent != null) {
1778 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001779 if (DEBUG_BACKUP) {
1780 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001781 + " from " + pkgName + "+" + backupAgent);
1782 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001783
1784 if (sa.getBoolean(
1785 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1786 true)) {
1787 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1788 }
1789 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001790 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1791 false)) {
1792 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1793 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001794 }
1795 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 TypedValue v = sa.peekValue(
1798 com.android.internal.R.styleable.AndroidManifestApplication_label);
1799 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1800 ai.nonLocalizedLabel = v.coerceToString();
1801 }
1802
1803 ai.icon = sa.getResourceId(
1804 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001805 ai.logo = sa.getResourceId(
1806 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001808 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 ai.descriptionRes = sa.getResourceId(
1810 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1811
1812 if ((flags&PARSE_IS_SYSTEM) != 0) {
1813 if (sa.getBoolean(
1814 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1815 false)) {
1816 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1817 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001818 }
1819
1820 if (sa.getBoolean(
1821 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1822 false)) {
1823 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001824 }
1825
1826 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1827 .AndroidManifestApplication_restrictedAccountType);
1828 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1829 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 }
1831
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001832 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1833 .AndroidManifestApplication_requiredAccountType);
1834 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1835 owner.mRequiredAccountType = requiredAccountType;
1836 }
1837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 if (sa.getBoolean(
1839 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1840 false)) {
1841 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1842 }
1843
1844 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001845 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001846 false)) {
1847 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1848 }
1849
Romain Guy529b60a2010-08-03 18:05:47 -07001850 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001851 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001852 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001853
1854 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1856 true)) {
1857 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1858 }
1859
1860 if (sa.getBoolean(
1861 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1862 false)) {
1863 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1864 }
1865
1866 if (sa.getBoolean(
1867 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1868 true)) {
1869 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1870 }
1871
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001872 if (sa.getBoolean(
1873 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001874 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001875 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1876 }
1877
Jason parksa3cdaa52011-01-13 14:15:43 -06001878 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001879 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001880 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001881 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001882 }
1883
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001884 if (sa.getBoolean(
1885 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1886 false /* default is no RTL support*/)) {
1887 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1888 }
1889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001891 str = sa.getNonConfigurationString(
1892 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1894
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001895 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1896 str = sa.getNonConfigurationString(
1897 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1898 } else {
1899 // Some older apps have been seen to use a resource reference
1900 // here that on older builds was ignored (with a warning). We
1901 // need to continue to do this for them so they don't break.
1902 str = sa.getNonResourceString(
1903 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1906 str, outError);
1907
1908 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001909 CharSequence pname;
1910 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1911 pname = sa.getNonConfigurationString(
1912 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1913 } else {
1914 // Some older apps have been seen to use a resource reference
1915 // here that on older builds was ignored (with a warning). We
1916 // need to continue to do this for them so they don't break.
1917 pname = sa.getNonResourceString(
1918 com.android.internal.R.styleable.AndroidManifestApplication_process);
1919 }
1920 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 flags, mSeparateProcesses, outError);
1922
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001923 ai.enabled = sa.getBoolean(
1924 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001925
Dianne Hackborn02486b12010-08-26 14:18:37 -07001926 if (false) {
1927 if (sa.getBoolean(
1928 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1929 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001930 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001931
1932 // A heavy-weight application can not be in a custom process.
1933 // We can do direct compare because we intern all strings.
1934 if (ai.processName != null && ai.processName != ai.packageName) {
1935 outError[0] = "cantSaveState applications can not use custom processes";
1936 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001937 }
1938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 }
1940
Adam Powell269248d2011-08-02 10:26:54 -07001941 ai.uiOptions = sa.getInt(
1942 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 sa.recycle();
1945
1946 if (outError[0] != null) {
1947 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1948 return false;
1949 }
1950
1951 final int innerDepth = parser.getDepth();
1952
1953 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001954 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1955 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1956 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 continue;
1958 }
1959
1960 String tagName = parser.getName();
1961 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001962 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1963 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 if (a == null) {
1965 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1966 return false;
1967 }
1968
1969 owner.activities.add(a);
1970
1971 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001972 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 if (a == null) {
1974 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1975 return false;
1976 }
1977
1978 owner.receivers.add(a);
1979
1980 } else if (tagName.equals("service")) {
1981 Service s = parseService(owner, res, parser, attrs, flags, outError);
1982 if (s == null) {
1983 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1984 return false;
1985 }
1986
1987 owner.services.add(s);
1988
1989 } else if (tagName.equals("provider")) {
1990 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1991 if (p == null) {
1992 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1993 return false;
1994 }
1995
1996 owner.providers.add(p);
1997
1998 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001999 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 if (a == null) {
2001 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2002 return false;
2003 }
2004
2005 owner.activities.add(a);
2006
2007 } else if (parser.getName().equals("meta-data")) {
2008 // note: application meta-data is stored off to the side, so it can
2009 // remain null in the primary copy (we like to avoid extra copies because
2010 // it can be large)
2011 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2012 outError)) == null) {
2013 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2014 return false;
2015 }
2016
Dianne Hackbornc895be72013-03-11 17:48:43 -07002017 } else if (tagName.equals("library")) {
2018 sa = res.obtainAttributes(attrs,
2019 com.android.internal.R.styleable.AndroidManifestLibrary);
2020
2021 // Note: don't allow this value to be a reference to a resource
2022 // that may change.
2023 String lname = sa.getNonResourceString(
2024 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2025
2026 sa.recycle();
2027
2028 if (lname != null) {
2029 if (owner.libraryNames == null) {
2030 owner.libraryNames = new ArrayList<String>();
2031 }
2032 if (!owner.libraryNames.contains(lname)) {
2033 owner.libraryNames.add(lname.intern());
2034 }
2035 }
2036
2037 XmlUtils.skipCurrentTag(parser);
2038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 } else if (tagName.equals("uses-library")) {
2040 sa = res.obtainAttributes(attrs,
2041 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2042
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002043 // Note: don't allow this value to be a reference to a resource
2044 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 String lname = sa.getNonResourceString(
2046 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002047 boolean req = sa.getBoolean(
2048 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2049 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050
2051 sa.recycle();
2052
Dianne Hackborn49237342009-08-27 20:08:01 -07002053 if (lname != null) {
2054 if (req) {
2055 if (owner.usesLibraries == null) {
2056 owner.usesLibraries = new ArrayList<String>();
2057 }
2058 if (!owner.usesLibraries.contains(lname)) {
2059 owner.usesLibraries.add(lname.intern());
2060 }
2061 } else {
2062 if (owner.usesOptionalLibraries == null) {
2063 owner.usesOptionalLibraries = new ArrayList<String>();
2064 }
2065 if (!owner.usesOptionalLibraries.contains(lname)) {
2066 owner.usesOptionalLibraries.add(lname.intern());
2067 }
2068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 }
2070
2071 XmlUtils.skipCurrentTag(parser);
2072
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002073 } else if (tagName.equals("uses-package")) {
2074 // Dependencies for app installers; we don't currently try to
2075 // enforce this.
2076 XmlUtils.skipCurrentTag(parser);
2077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 } else {
2079 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002080 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002081 + " at " + mArchiveSourcePath + " "
2082 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 XmlUtils.skipCurrentTag(parser);
2084 continue;
2085 } else {
2086 outError[0] = "Bad element under <application>: " + tagName;
2087 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2088 return false;
2089 }
2090 }
2091 }
2092
2093 return true;
2094 }
2095
2096 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2097 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002098 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002099 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 if (name == null) {
2101 outError[0] = tag + " does not specify android:name";
2102 return false;
2103 }
2104
2105 outInfo.name
2106 = buildClassName(owner.applicationInfo.packageName, name, outError);
2107 if (outInfo.name == null) {
2108 return false;
2109 }
2110
2111 int iconVal = sa.getResourceId(iconRes, 0);
2112 if (iconVal != 0) {
2113 outInfo.icon = iconVal;
2114 outInfo.nonLocalizedLabel = null;
2115 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002116
2117 int logoVal = sa.getResourceId(logoRes, 0);
2118 if (logoVal != 0) {
2119 outInfo.logo = logoVal;
2120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121
2122 TypedValue v = sa.peekValue(labelRes);
2123 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2124 outInfo.nonLocalizedLabel = v.coerceToString();
2125 }
2126
2127 outInfo.packageName = owner.packageName;
2128
2129 return true;
2130 }
2131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 private Activity parseActivity(Package owner, Resources res,
2133 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002134 boolean receiver, boolean hardwareAccelerated)
2135 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 TypedArray sa = res.obtainAttributes(attrs,
2137 com.android.internal.R.styleable.AndroidManifestActivity);
2138
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002139 if (mParseActivityArgs == null) {
2140 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2141 com.android.internal.R.styleable.AndroidManifestActivity_name,
2142 com.android.internal.R.styleable.AndroidManifestActivity_label,
2143 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002144 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002145 mSeparateProcesses,
2146 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002147 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002148 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2149 }
2150
2151 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2152 mParseActivityArgs.sa = sa;
2153 mParseActivityArgs.flags = flags;
2154
2155 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2156 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 sa.recycle();
2158 return null;
2159 }
2160
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002161 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2163 if (setExported) {
2164 a.info.exported = sa.getBoolean(
2165 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2166 }
2167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 a.info.theme = sa.getResourceId(
2169 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2170
Adam Powell269248d2011-08-02 10:26:54 -07002171 a.info.uiOptions = sa.getInt(
2172 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2173 a.info.applicationInfo.uiOptions);
2174
Adam Powelldd8fab22012-03-22 17:47:27 -07002175 String parentName = sa.getNonConfigurationString(
2176 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2177 if (parentName != null) {
2178 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2179 if (outError[0] == null) {
2180 a.info.parentActivityName = parentClassName;
2181 } else {
2182 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2183 parentName);
2184 outError[0] = null;
2185 }
2186 }
2187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002189 str = sa.getNonConfigurationString(
2190 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 if (str == null) {
2192 a.info.permission = owner.applicationInfo.permission;
2193 } else {
2194 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2195 }
2196
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002197 str = sa.getNonConfigurationString(
2198 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2200 owner.applicationInfo.taskAffinity, str, outError);
2201
2202 a.info.flags = 0;
2203 if (sa.getBoolean(
2204 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2205 false)) {
2206 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2207 }
2208
2209 if (sa.getBoolean(
2210 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2211 false)) {
2212 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2213 }
2214
2215 if (sa.getBoolean(
2216 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2217 false)) {
2218 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2219 }
2220
2221 if (sa.getBoolean(
2222 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2223 false)) {
2224 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2225 }
2226
2227 if (sa.getBoolean(
2228 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2229 false)) {
2230 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2231 }
2232
2233 if (sa.getBoolean(
2234 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2235 false)) {
2236 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2237 }
2238
2239 if (sa.getBoolean(
2240 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2241 false)) {
2242 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2243 }
2244
2245 if (sa.getBoolean(
2246 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2247 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2248 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2249 }
2250
Dianne Hackbornffa42482009-09-23 22:20:11 -07002251 if (sa.getBoolean(
2252 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2253 false)) {
2254 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2255 }
2256
Daniel Sandler613dde42010-06-21 13:46:39 -04002257 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002258 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2259 false)) {
2260 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2261 }
2262
2263 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002264 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2265 false)) {
2266 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2267 }
Craig Mautner5962b122012-10-05 14:45:52 -07002268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002270 if (sa.getBoolean(
2271 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2272 hardwareAccelerated)) {
2273 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2274 }
2275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 a.info.launchMode = sa.getInt(
2277 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2278 ActivityInfo.LAUNCH_MULTIPLE);
2279 a.info.screenOrientation = sa.getInt(
2280 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2281 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2282 a.info.configChanges = sa.getInt(
2283 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2284 0);
2285 a.info.softInputMode = sa.getInt(
2286 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2287 0);
2288 } else {
2289 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2290 a.info.configChanges = 0;
2291 }
2292
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002293 if (receiver) {
2294 if (sa.getBoolean(
2295 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2296 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002297 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002298 if (a.info.exported) {
2299 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2300 + a.className + " at " + mArchiveSourcePath + " "
2301 + parser.getPositionDescription());
2302 a.info.exported = false;
2303 }
2304 setExported = true;
2305 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002306 if (sa.getBoolean(
2307 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2308 false)) {
2309 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2310 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002311 }
2312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 sa.recycle();
2314
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002315 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002316 // A heavy-weight application can not have receives in its main process
2317 // We can do direct compare because we intern all strings.
2318 if (a.info.processName == owner.packageName) {
2319 outError[0] = "Heavy-weight applications can not have receivers in main process";
2320 }
2321 }
2322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 if (outError[0] != null) {
2324 return null;
2325 }
2326
2327 int outerDepth = parser.getDepth();
2328 int type;
2329 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2330 && (type != XmlPullParser.END_TAG
2331 || parser.getDepth() > outerDepth)) {
2332 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2333 continue;
2334 }
2335
2336 if (parser.getName().equals("intent-filter")) {
2337 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2338 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2339 return null;
2340 }
2341 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002342 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002343 + mArchiveSourcePath + " "
2344 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 } else {
2346 a.intents.add(intent);
2347 }
2348 } else if (parser.getName().equals("meta-data")) {
2349 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2350 outError)) == null) {
2351 return null;
2352 }
2353 } else {
2354 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002355 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002357 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002358 + " at " + mArchiveSourcePath + " "
2359 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002361 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002362 + " at " + mArchiveSourcePath + " "
2363 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 }
2365 XmlUtils.skipCurrentTag(parser);
2366 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002368 if (receiver) {
2369 outError[0] = "Bad element under <receiver>: " + parser.getName();
2370 } else {
2371 outError[0] = "Bad element under <activity>: " + parser.getName();
2372 }
2373 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 }
2376 }
2377
2378 if (!setExported) {
2379 a.info.exported = a.intents.size() > 0;
2380 }
2381
2382 return a;
2383 }
2384
2385 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002386 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2387 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 TypedArray sa = res.obtainAttributes(attrs,
2389 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2390
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002391 String targetActivity = sa.getNonConfigurationString(
2392 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 if (targetActivity == null) {
2394 outError[0] = "<activity-alias> does not specify android:targetActivity";
2395 sa.recycle();
2396 return null;
2397 }
2398
2399 targetActivity = buildClassName(owner.applicationInfo.packageName,
2400 targetActivity, outError);
2401 if (targetActivity == null) {
2402 sa.recycle();
2403 return null;
2404 }
2405
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002406 if (mParseActivityAliasArgs == null) {
2407 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2408 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2409 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2410 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002411 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002412 mSeparateProcesses,
2413 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002414 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002415 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2416 mParseActivityAliasArgs.tag = "<activity-alias>";
2417 }
2418
2419 mParseActivityAliasArgs.sa = sa;
2420 mParseActivityAliasArgs.flags = flags;
2421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 Activity target = null;
2423
2424 final int NA = owner.activities.size();
2425 for (int i=0; i<NA; i++) {
2426 Activity t = owner.activities.get(i);
2427 if (targetActivity.equals(t.info.name)) {
2428 target = t;
2429 break;
2430 }
2431 }
2432
2433 if (target == null) {
2434 outError[0] = "<activity-alias> target activity " + targetActivity
2435 + " not found in manifest";
2436 sa.recycle();
2437 return null;
2438 }
2439
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002440 ActivityInfo info = new ActivityInfo();
2441 info.targetActivity = targetActivity;
2442 info.configChanges = target.info.configChanges;
2443 info.flags = target.info.flags;
2444 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002445 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002446 info.labelRes = target.info.labelRes;
2447 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2448 info.launchMode = target.info.launchMode;
2449 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002450 if (info.descriptionRes == 0) {
2451 info.descriptionRes = target.info.descriptionRes;
2452 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002453 info.screenOrientation = target.info.screenOrientation;
2454 info.taskAffinity = target.info.taskAffinity;
2455 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002456 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002457 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002458 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002459
2460 Activity a = new Activity(mParseActivityAliasArgs, info);
2461 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 sa.recycle();
2463 return null;
2464 }
2465
2466 final boolean setExported = sa.hasValue(
2467 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2468 if (setExported) {
2469 a.info.exported = sa.getBoolean(
2470 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2471 }
2472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002474 str = sa.getNonConfigurationString(
2475 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 if (str != null) {
2477 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2478 }
2479
Adam Powelldd8fab22012-03-22 17:47:27 -07002480 String parentName = sa.getNonConfigurationString(
2481 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2482 0);
2483 if (parentName != null) {
2484 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2485 if (outError[0] == null) {
2486 a.info.parentActivityName = parentClassName;
2487 } else {
2488 Log.e(TAG, "Activity alias " + a.info.name +
2489 " specified invalid parentActivityName " + parentName);
2490 outError[0] = null;
2491 }
2492 }
2493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 sa.recycle();
2495
2496 if (outError[0] != null) {
2497 return null;
2498 }
2499
2500 int outerDepth = parser.getDepth();
2501 int type;
2502 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2503 && (type != XmlPullParser.END_TAG
2504 || parser.getDepth() > outerDepth)) {
2505 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2506 continue;
2507 }
2508
2509 if (parser.getName().equals("intent-filter")) {
2510 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2511 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2512 return null;
2513 }
2514 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002515 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002516 + mArchiveSourcePath + " "
2517 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 } else {
2519 a.intents.add(intent);
2520 }
2521 } else if (parser.getName().equals("meta-data")) {
2522 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2523 outError)) == null) {
2524 return null;
2525 }
2526 } else {
2527 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002528 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002529 + " at " + mArchiveSourcePath + " "
2530 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 XmlUtils.skipCurrentTag(parser);
2532 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002533 } else {
2534 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2535 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 }
2538 }
2539
2540 if (!setExported) {
2541 a.info.exported = a.intents.size() > 0;
2542 }
2543
2544 return a;
2545 }
2546
2547 private Provider parseProvider(Package owner, Resources res,
2548 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2549 throws XmlPullParserException, IOException {
2550 TypedArray sa = res.obtainAttributes(attrs,
2551 com.android.internal.R.styleable.AndroidManifestProvider);
2552
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002553 if (mParseProviderArgs == null) {
2554 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2555 com.android.internal.R.styleable.AndroidManifestProvider_name,
2556 com.android.internal.R.styleable.AndroidManifestProvider_label,
2557 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002558 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002559 mSeparateProcesses,
2560 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002561 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002562 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2563 mParseProviderArgs.tag = "<provider>";
2564 }
2565
2566 mParseProviderArgs.sa = sa;
2567 mParseProviderArgs.flags = flags;
2568
2569 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2570 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 sa.recycle();
2572 return null;
2573 }
2574
Nick Kralevichf097b162012-07-28 12:43:48 -07002575 boolean providerExportedDefault = false;
2576
2577 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2578 // For compatibility, applications targeting API level 16 or lower
2579 // should have their content providers exported by default, unless they
2580 // specify otherwise.
2581 providerExportedDefault = true;
2582 }
2583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002585 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2586 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002588 String cpname = sa.getNonConfigurationString(
2589 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590
2591 p.info.isSyncable = sa.getBoolean(
2592 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2593 false);
2594
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002595 String permission = sa.getNonConfigurationString(
2596 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2597 String str = sa.getNonConfigurationString(
2598 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 if (str == null) {
2600 str = permission;
2601 }
2602 if (str == null) {
2603 p.info.readPermission = owner.applicationInfo.permission;
2604 } else {
2605 p.info.readPermission =
2606 str.length() > 0 ? str.toString().intern() : null;
2607 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002608 str = sa.getNonConfigurationString(
2609 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 if (str == null) {
2611 str = permission;
2612 }
2613 if (str == null) {
2614 p.info.writePermission = owner.applicationInfo.permission;
2615 } else {
2616 p.info.writePermission =
2617 str.length() > 0 ? str.toString().intern() : null;
2618 }
2619
2620 p.info.grantUriPermissions = sa.getBoolean(
2621 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2622 false);
2623
2624 p.info.multiprocess = sa.getBoolean(
2625 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2626 false);
2627
2628 p.info.initOrder = sa.getInt(
2629 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2630 0);
2631
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002632 p.info.flags = 0;
2633
2634 if (sa.getBoolean(
2635 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2636 false)) {
2637 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2638 if (p.info.exported) {
2639 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2640 + p.className + " at " + mArchiveSourcePath + " "
2641 + parser.getPositionDescription());
2642 p.info.exported = false;
2643 }
2644 }
2645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 sa.recycle();
2647
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002648 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002649 // A heavy-weight application can not have providers in its main process
2650 // We can do direct compare because we intern all strings.
2651 if (p.info.processName == owner.packageName) {
2652 outError[0] = "Heavy-weight applications can not have providers in main process";
2653 return null;
2654 }
2655 }
2656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002658 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 return null;
2660 }
2661 p.info.authority = cpname.intern();
2662
2663 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2664 return null;
2665 }
2666
2667 return p;
2668 }
2669
2670 private boolean parseProviderTags(Resources res,
2671 XmlPullParser parser, AttributeSet attrs,
2672 Provider outInfo, String[] outError)
2673 throws XmlPullParserException, IOException {
2674 int outerDepth = parser.getDepth();
2675 int type;
2676 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2677 && (type != XmlPullParser.END_TAG
2678 || parser.getDepth() > outerDepth)) {
2679 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2680 continue;
2681 }
2682
2683 if (parser.getName().equals("meta-data")) {
2684 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2685 outInfo.metaData, outError)) == null) {
2686 return false;
2687 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 } else if (parser.getName().equals("grant-uri-permission")) {
2690 TypedArray sa = res.obtainAttributes(attrs,
2691 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2692
2693 PatternMatcher pa = null;
2694
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002695 String str = sa.getNonConfigurationString(
2696 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 if (str != null) {
2698 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2699 }
2700
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002701 str = sa.getNonConfigurationString(
2702 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 if (str != null) {
2704 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2705 }
2706
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002707 str = sa.getNonConfigurationString(
2708 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 if (str != null) {
2710 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2711 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 sa.recycle();
2714
2715 if (pa != null) {
2716 if (outInfo.info.uriPermissionPatterns == null) {
2717 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2718 outInfo.info.uriPermissionPatterns[0] = pa;
2719 } else {
2720 final int N = outInfo.info.uriPermissionPatterns.length;
2721 PatternMatcher[] newp = new PatternMatcher[N+1];
2722 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2723 newp[N] = pa;
2724 outInfo.info.uriPermissionPatterns = newp;
2725 }
2726 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002727 } else {
2728 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002729 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002730 + parser.getName() + " at " + mArchiveSourcePath + " "
2731 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002732 XmlUtils.skipCurrentTag(parser);
2733 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002734 } else {
2735 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2736 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002737 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002738 }
2739 XmlUtils.skipCurrentTag(parser);
2740
2741 } else if (parser.getName().equals("path-permission")) {
2742 TypedArray sa = res.obtainAttributes(attrs,
2743 com.android.internal.R.styleable.AndroidManifestPathPermission);
2744
2745 PathPermission pa = null;
2746
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002747 String permission = sa.getNonConfigurationString(
2748 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2749 String readPermission = sa.getNonConfigurationString(
2750 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002751 if (readPermission == null) {
2752 readPermission = permission;
2753 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002754 String writePermission = sa.getNonConfigurationString(
2755 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002756 if (writePermission == null) {
2757 writePermission = permission;
2758 }
2759
2760 boolean havePerm = false;
2761 if (readPermission != null) {
2762 readPermission = readPermission.intern();
2763 havePerm = true;
2764 }
2765 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002766 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002767 havePerm = true;
2768 }
2769
2770 if (!havePerm) {
2771 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002772 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002773 + parser.getName() + " at " + mArchiveSourcePath + " "
2774 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002775 XmlUtils.skipCurrentTag(parser);
2776 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002777 } else {
2778 outError[0] = "No readPermission or writePermssion for <path-permission>";
2779 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002780 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002781 }
2782
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002783 String path = sa.getNonConfigurationString(
2784 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002785 if (path != null) {
2786 pa = new PathPermission(path,
2787 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2788 }
2789
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002790 path = sa.getNonConfigurationString(
2791 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002792 if (path != null) {
2793 pa = new PathPermission(path,
2794 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2795 }
2796
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002797 path = sa.getNonConfigurationString(
2798 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002799 if (path != null) {
2800 pa = new PathPermission(path,
2801 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2802 }
2803
2804 sa.recycle();
2805
2806 if (pa != null) {
2807 if (outInfo.info.pathPermissions == null) {
2808 outInfo.info.pathPermissions = new PathPermission[1];
2809 outInfo.info.pathPermissions[0] = pa;
2810 } else {
2811 final int N = outInfo.info.pathPermissions.length;
2812 PathPermission[] newp = new PathPermission[N+1];
2813 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2814 newp[N] = pa;
2815 outInfo.info.pathPermissions = newp;
2816 }
2817 } else {
2818 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002819 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002820 + parser.getName() + " at " + mArchiveSourcePath + " "
2821 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002822 XmlUtils.skipCurrentTag(parser);
2823 continue;
2824 }
2825 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2826 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 }
2828 XmlUtils.skipCurrentTag(parser);
2829
2830 } else {
2831 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002832 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002833 + parser.getName() + " at " + mArchiveSourcePath + " "
2834 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 XmlUtils.skipCurrentTag(parser);
2836 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002837 } else {
2838 outError[0] = "Bad element under <provider>: " + parser.getName();
2839 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 }
2842 }
2843 return true;
2844 }
2845
2846 private Service parseService(Package owner, Resources res,
2847 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2848 throws XmlPullParserException, IOException {
2849 TypedArray sa = res.obtainAttributes(attrs,
2850 com.android.internal.R.styleable.AndroidManifestService);
2851
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002852 if (mParseServiceArgs == null) {
2853 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2854 com.android.internal.R.styleable.AndroidManifestService_name,
2855 com.android.internal.R.styleable.AndroidManifestService_label,
2856 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002857 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002858 mSeparateProcesses,
2859 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002860 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002861 com.android.internal.R.styleable.AndroidManifestService_enabled);
2862 mParseServiceArgs.tag = "<service>";
2863 }
2864
2865 mParseServiceArgs.sa = sa;
2866 mParseServiceArgs.flags = flags;
2867
2868 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2869 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 sa.recycle();
2871 return null;
2872 }
2873
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002874 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 com.android.internal.R.styleable.AndroidManifestService_exported);
2876 if (setExported) {
2877 s.info.exported = sa.getBoolean(
2878 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2879 }
2880
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002881 String str = sa.getNonConfigurationString(
2882 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 if (str == null) {
2884 s.info.permission = owner.applicationInfo.permission;
2885 } else {
2886 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2887 }
2888
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002889 s.info.flags = 0;
2890 if (sa.getBoolean(
2891 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2892 false)) {
2893 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2894 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002895 if (sa.getBoolean(
2896 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2897 false)) {
2898 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2899 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002900 if (sa.getBoolean(
2901 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2902 false)) {
2903 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2904 if (s.info.exported) {
2905 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2906 + s.className + " at " + mArchiveSourcePath + " "
2907 + parser.getPositionDescription());
2908 s.info.exported = false;
2909 }
2910 setExported = true;
2911 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 sa.recycle();
2914
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002915 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002916 // A heavy-weight application can not have services in its main process
2917 // We can do direct compare because we intern all strings.
2918 if (s.info.processName == owner.packageName) {
2919 outError[0] = "Heavy-weight applications can not have services in main process";
2920 return null;
2921 }
2922 }
2923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 int outerDepth = parser.getDepth();
2925 int type;
2926 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2927 && (type != XmlPullParser.END_TAG
2928 || parser.getDepth() > outerDepth)) {
2929 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2930 continue;
2931 }
2932
2933 if (parser.getName().equals("intent-filter")) {
2934 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2935 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2936 return null;
2937 }
2938
2939 s.intents.add(intent);
2940 } else if (parser.getName().equals("meta-data")) {
2941 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2942 outError)) == null) {
2943 return null;
2944 }
2945 } else {
2946 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002947 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002948 + parser.getName() + " at " + mArchiveSourcePath + " "
2949 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 XmlUtils.skipCurrentTag(parser);
2951 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002952 } else {
2953 outError[0] = "Bad element under <service>: " + parser.getName();
2954 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 }
2957 }
2958
2959 if (!setExported) {
2960 s.info.exported = s.intents.size() > 0;
2961 }
2962
2963 return s;
2964 }
2965
2966 private boolean parseAllMetaData(Resources res,
2967 XmlPullParser parser, AttributeSet attrs, String tag,
2968 Component outInfo, String[] outError)
2969 throws XmlPullParserException, IOException {
2970 int outerDepth = parser.getDepth();
2971 int type;
2972 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2973 && (type != XmlPullParser.END_TAG
2974 || parser.getDepth() > outerDepth)) {
2975 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2976 continue;
2977 }
2978
2979 if (parser.getName().equals("meta-data")) {
2980 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2981 outInfo.metaData, outError)) == null) {
2982 return false;
2983 }
2984 } else {
2985 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002986 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002987 + parser.getName() + " at " + mArchiveSourcePath + " "
2988 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 XmlUtils.skipCurrentTag(parser);
2990 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002991 } else {
2992 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2993 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 }
2996 }
2997 return true;
2998 }
2999
3000 private Bundle parseMetaData(Resources res,
3001 XmlPullParser parser, AttributeSet attrs,
3002 Bundle data, String[] outError)
3003 throws XmlPullParserException, IOException {
3004
3005 TypedArray sa = res.obtainAttributes(attrs,
3006 com.android.internal.R.styleable.AndroidManifestMetaData);
3007
3008 if (data == null) {
3009 data = new Bundle();
3010 }
3011
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003012 String name = sa.getNonConfigurationString(
3013 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 if (name == null) {
3015 outError[0] = "<meta-data> requires an android:name attribute";
3016 sa.recycle();
3017 return null;
3018 }
3019
Dianne Hackborn854060af2009-07-09 18:14:31 -07003020 name = name.intern();
3021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 TypedValue v = sa.peekValue(
3023 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3024 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003025 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 data.putInt(name, v.resourceId);
3027 } else {
3028 v = sa.peekValue(
3029 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003030 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 if (v != null) {
3032 if (v.type == TypedValue.TYPE_STRING) {
3033 CharSequence cs = v.coerceToString();
Dianne Hackborn854060af2009-07-09 18:14:31 -07003034 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3036 data.putBoolean(name, v.data != 0);
3037 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3038 && v.type <= TypedValue.TYPE_LAST_INT) {
3039 data.putInt(name, v.data);
3040 } else if (v.type == TypedValue.TYPE_FLOAT) {
3041 data.putFloat(name, v.getFloat());
3042 } else {
3043 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003044 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003045 + parser.getName() + " at " + mArchiveSourcePath + " "
3046 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 } else {
3048 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3049 data = null;
3050 }
3051 }
3052 } else {
3053 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3054 data = null;
3055 }
3056 }
3057
3058 sa.recycle();
3059
3060 XmlUtils.skipCurrentTag(parser);
3061
3062 return data;
3063 }
3064
Kenny Root05ca4c92011-09-15 10:36:25 -07003065 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3066 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3067 IOException {
3068 final TypedArray sa = res.obtainAttributes(attrs,
3069 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3070
3071 final String packageName = sa.getNonResourceString(
3072 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3073
3074 final String encodedPublicKey = sa.getNonResourceString(
3075 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3076
3077 sa.recycle();
3078
3079 if (packageName == null || packageName.length() == 0) {
3080 Slog.i(TAG, "verifier package name was null; skipping");
3081 return null;
3082 } else if (encodedPublicKey == null) {
3083 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3084 }
3085
3086 EncodedKeySpec keySpec;
3087 try {
3088 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3089 keySpec = new X509EncodedKeySpec(encoded);
3090 } catch (IllegalArgumentException e) {
3091 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
3092 return null;
3093 }
3094
3095 /* First try the key as an RSA key. */
3096 try {
3097 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
3098 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3099 return new VerifierInfo(packageName, publicKey);
3100 } catch (NoSuchAlgorithmException e) {
3101 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3102 return null;
3103 } catch (InvalidKeySpecException e) {
3104 // Not a RSA public key.
3105 }
3106
3107 /* Now try it as a DSA key. */
3108 try {
3109 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3110 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3111 return new VerifierInfo(packageName, publicKey);
3112 } catch (NoSuchAlgorithmException e) {
3113 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3114 return null;
3115 } catch (InvalidKeySpecException e) {
3116 // Not a DSA public key.
3117 }
3118
3119 return null;
3120 }
3121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 private static final String ANDROID_RESOURCES
3123 = "http://schemas.android.com/apk/res/android";
3124
3125 private boolean parseIntent(Resources res,
3126 XmlPullParser parser, AttributeSet attrs, int flags,
3127 IntentInfo outInfo, String[] outError, boolean isActivity)
3128 throws XmlPullParserException, IOException {
3129
3130 TypedArray sa = res.obtainAttributes(attrs,
3131 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3132
3133 int priority = sa.getInt(
3134 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003137 TypedValue v = sa.peekValue(
3138 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3139 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3140 outInfo.nonLocalizedLabel = v.coerceToString();
3141 }
3142
3143 outInfo.icon = sa.getResourceId(
3144 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003145
3146 outInfo.logo = sa.getResourceId(
3147 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148
3149 sa.recycle();
3150
3151 int outerDepth = parser.getDepth();
3152 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003153 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3154 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3155 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 continue;
3157 }
3158
3159 String nodeName = parser.getName();
3160 if (nodeName.equals("action")) {
3161 String value = attrs.getAttributeValue(
3162 ANDROID_RESOURCES, "name");
3163 if (value == null || value == "") {
3164 outError[0] = "No value supplied for <android:name>";
3165 return false;
3166 }
3167 XmlUtils.skipCurrentTag(parser);
3168
3169 outInfo.addAction(value);
3170 } else if (nodeName.equals("category")) {
3171 String value = attrs.getAttributeValue(
3172 ANDROID_RESOURCES, "name");
3173 if (value == null || value == "") {
3174 outError[0] = "No value supplied for <android:name>";
3175 return false;
3176 }
3177 XmlUtils.skipCurrentTag(parser);
3178
3179 outInfo.addCategory(value);
3180
3181 } else if (nodeName.equals("data")) {
3182 sa = res.obtainAttributes(attrs,
3183 com.android.internal.R.styleable.AndroidManifestData);
3184
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003185 String str = sa.getNonConfigurationString(
3186 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 if (str != null) {
3188 try {
3189 outInfo.addDataType(str);
3190 } catch (IntentFilter.MalformedMimeTypeException e) {
3191 outError[0] = e.toString();
3192 sa.recycle();
3193 return false;
3194 }
3195 }
3196
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003197 str = sa.getNonConfigurationString(
3198 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 if (str != null) {
3200 outInfo.addDataScheme(str);
3201 }
3202
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003203 String host = sa.getNonConfigurationString(
3204 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3205 String port = sa.getNonConfigurationString(
3206 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 if (host != null) {
3208 outInfo.addDataAuthority(host, port);
3209 }
3210
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003211 str = sa.getNonConfigurationString(
3212 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 if (str != null) {
3214 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3215 }
3216
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003217 str = sa.getNonConfigurationString(
3218 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 if (str != null) {
3220 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3221 }
3222
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003223 str = sa.getNonConfigurationString(
3224 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 if (str != null) {
3226 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3227 }
3228
3229 sa.recycle();
3230 XmlUtils.skipCurrentTag(parser);
3231 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003232 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003233 + parser.getName() + " at " + mArchiveSourcePath + " "
3234 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 XmlUtils.skipCurrentTag(parser);
3236 } else {
3237 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3238 return false;
3239 }
3240 }
3241
3242 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003243
3244 if (DEBUG_PARSER) {
3245 final StringBuilder cats = new StringBuilder("Intent d=");
3246 cats.append(outInfo.hasDefault);
3247 cats.append(", cat=");
3248
3249 final Iterator<String> it = outInfo.categoriesIterator();
3250 if (it != null) {
3251 while (it.hasNext()) {
3252 cats.append(' ');
3253 cats.append(it.next());
3254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003256 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 }
3258
3259 return true;
3260 }
3261
3262 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003263
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003264 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265
3266 // For now we only support one application per package.
3267 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3268
3269 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3270 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3271 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3272 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3273 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3274 public final ArrayList<Service> services = new ArrayList<Service>(0);
3275 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3276
3277 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003278 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279
Dianne Hackborn854060af2009-07-09 18:14:31 -07003280 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003281
3282 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003283 public ArrayList<String> usesLibraries = null;
3284 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 public String[] usesLibraryFiles = null;
3286
Dianne Hackbornc1552392010-03-03 16:19:01 -08003287 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003288 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003289 public ArrayList<String> mAdoptPermissions = null;
3290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 // We store the application meta-data independently to avoid multiple unwanted references
3292 public Bundle mAppMetaData = null;
3293
3294 // If this is a 3rd party app, this is the path of the zip file.
3295 public String mPath;
3296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 // The version code declared for this package.
3298 public int mVersionCode;
3299
3300 // The version name declared for this package.
3301 public String mVersionName;
3302
3303 // The shared user id that this package wants to use.
3304 public String mSharedUserId;
3305
3306 // The shared user label that this package wants to use.
3307 public int mSharedUserLabel;
3308
3309 // Signatures that were read from the package.
3310 public Signature mSignatures[];
3311
3312 // For use by package manager service for quick lookup of
3313 // preferred up order.
3314 public int mPreferredOrder = 0;
3315
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003316 // For use by the package manager to keep track of the path to the
3317 // file an app came from.
3318 public String mScanPath;
3319
3320 // For use by package manager to keep track of where it has done dexopt.
3321 public boolean mDidDexOpt;
3322
Amith Yamasani13593602012-03-22 16:16:17 -07003323 // // User set enabled state.
3324 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3325 //
3326 // // Whether the package has been stopped.
3327 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 // Additional data supplied by callers.
3330 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003331
3332 // Whether an operation is currently pending on this package
3333 public boolean mOperationPending;
3334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 /*
3336 * Applications hardware preferences
3337 */
3338 public final ArrayList<ConfigurationInfo> configPreferences =
3339 new ArrayList<ConfigurationInfo>();
3340
Dianne Hackborn49237342009-08-27 20:08:01 -07003341 /*
3342 * Applications requested features
3343 */
3344 public ArrayList<FeatureInfo> reqFeatures = null;
3345
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003346 public int installLocation;
3347
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003348 /* An app that's required for all users and cannot be uninstalled for a user */
3349 public boolean mRequiredForAllUsers;
3350
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003351 /* The restricted account authenticator type that is used by this application */
3352 public String mRestrictedAccountType;
3353
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003354 /* The required account type without which this application will not function */
3355 public String mRequiredAccountType;
3356
Kenny Rootbcc954d2011-08-08 16:19:08 -07003357 /**
3358 * Digest suitable for comparing whether this package's manifest is the
3359 * same as another.
3360 */
3361 public ManifestDigest manifestDigest;
3362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 public Package(String _name) {
3364 packageName = _name;
3365 applicationInfo.packageName = _name;
3366 applicationInfo.uid = -1;
3367 }
3368
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003369 public void setPackageName(String newName) {
3370 packageName = newName;
3371 applicationInfo.packageName = newName;
3372 for (int i=permissions.size()-1; i>=0; i--) {
3373 permissions.get(i).setPackageName(newName);
3374 }
3375 for (int i=permissionGroups.size()-1; i>=0; i--) {
3376 permissionGroups.get(i).setPackageName(newName);
3377 }
3378 for (int i=activities.size()-1; i>=0; i--) {
3379 activities.get(i).setPackageName(newName);
3380 }
3381 for (int i=receivers.size()-1; i>=0; i--) {
3382 receivers.get(i).setPackageName(newName);
3383 }
3384 for (int i=providers.size()-1; i>=0; i--) {
3385 providers.get(i).setPackageName(newName);
3386 }
3387 for (int i=services.size()-1; i>=0; i--) {
3388 services.get(i).setPackageName(newName);
3389 }
3390 for (int i=instrumentation.size()-1; i>=0; i--) {
3391 instrumentation.get(i).setPackageName(newName);
3392 }
3393 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003394
3395 public boolean hasComponentClassName(String name) {
3396 for (int i=activities.size()-1; i>=0; i--) {
3397 if (name.equals(activities.get(i).className)) {
3398 return true;
3399 }
3400 }
3401 for (int i=receivers.size()-1; i>=0; i--) {
3402 if (name.equals(receivers.get(i).className)) {
3403 return true;
3404 }
3405 }
3406 for (int i=providers.size()-1; i>=0; i--) {
3407 if (name.equals(providers.get(i).className)) {
3408 return true;
3409 }
3410 }
3411 for (int i=services.size()-1; i>=0; i--) {
3412 if (name.equals(services.get(i).className)) {
3413 return true;
3414 }
3415 }
3416 for (int i=instrumentation.size()-1; i>=0; i--) {
3417 if (name.equals(instrumentation.get(i).className)) {
3418 return true;
3419 }
3420 }
3421 return false;
3422 }
3423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 public String toString() {
3425 return "Package{"
3426 + Integer.toHexString(System.identityHashCode(this))
3427 + " " + packageName + "}";
3428 }
3429 }
3430
3431 public static class Component<II extends IntentInfo> {
3432 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003433 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003434 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 public Bundle metaData;
3436
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003437 ComponentName componentName;
3438 String componentShortName;
3439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 public Component(Package _owner) {
3441 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003442 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003443 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003444 }
3445
3446 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3447 owner = args.owner;
3448 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003449 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003450 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003451 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003452 args.outError[0] = args.tag + " does not specify android:name";
3453 return;
3454 }
3455
3456 outInfo.name
3457 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3458 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003459 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003460 args.outError[0] = args.tag + " does not have valid android:name";
3461 return;
3462 }
3463
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003464 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003465
3466 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3467 if (iconVal != 0) {
3468 outInfo.icon = iconVal;
3469 outInfo.nonLocalizedLabel = null;
3470 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003471
3472 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3473 if (logoVal != 0) {
3474 outInfo.logo = logoVal;
3475 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003476
3477 TypedValue v = args.sa.peekValue(args.labelRes);
3478 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3479 outInfo.nonLocalizedLabel = v.coerceToString();
3480 }
3481
3482 outInfo.packageName = owner.packageName;
3483 }
3484
3485 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3486 this(args, (PackageItemInfo)outInfo);
3487 if (args.outError[0] != null) {
3488 return;
3489 }
3490
3491 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003492 CharSequence pname;
3493 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3494 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3495 } else {
3496 // Some older apps have been seen to use a resource reference
3497 // here that on older builds was ignored (with a warning). We
3498 // need to continue to do this for them so they don't break.
3499 pname = args.sa.getNonResourceString(args.processRes);
3500 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003501 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003502 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003503 args.flags, args.sepProcesses, args.outError);
3504 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003505
3506 if (args.descriptionRes != 0) {
3507 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3508 }
3509
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003510 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 }
3512
3513 public Component(Component<II> clone) {
3514 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003515 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003516 className = clone.className;
3517 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003518 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003519 }
3520
3521 public ComponentName getComponentName() {
3522 if (componentName != null) {
3523 return componentName;
3524 }
3525 if (className != null) {
3526 componentName = new ComponentName(owner.applicationInfo.packageName,
3527 className);
3528 }
3529 return componentName;
3530 }
3531
3532 public String getComponentShortName() {
3533 if (componentShortName != null) {
3534 return componentShortName;
3535 }
3536 ComponentName component = getComponentName();
3537 if (component != null) {
3538 componentShortName = component.flattenToShortString();
3539 }
3540 return componentShortName;
3541 }
3542
3543 public void setPackageName(String packageName) {
3544 componentName = null;
3545 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 }
3547 }
3548
3549 public final static class Permission extends Component<IntentInfo> {
3550 public final PermissionInfo info;
3551 public boolean tree;
3552 public PermissionGroup group;
3553
3554 public Permission(Package _owner) {
3555 super(_owner);
3556 info = new PermissionInfo();
3557 }
3558
3559 public Permission(Package _owner, PermissionInfo _info) {
3560 super(_owner);
3561 info = _info;
3562 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003563
3564 public void setPackageName(String packageName) {
3565 super.setPackageName(packageName);
3566 info.packageName = packageName;
3567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568
3569 public String toString() {
3570 return "Permission{"
3571 + Integer.toHexString(System.identityHashCode(this))
3572 + " " + info.name + "}";
3573 }
3574 }
3575
3576 public final static class PermissionGroup extends Component<IntentInfo> {
3577 public final PermissionGroupInfo info;
3578
3579 public PermissionGroup(Package _owner) {
3580 super(_owner);
3581 info = new PermissionGroupInfo();
3582 }
3583
3584 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3585 super(_owner);
3586 info = _info;
3587 }
3588
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003589 public void setPackageName(String packageName) {
3590 super.setPackageName(packageName);
3591 info.packageName = packageName;
3592 }
3593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 public String toString() {
3595 return "PermissionGroup{"
3596 + Integer.toHexString(System.identityHashCode(this))
3597 + " " + info.name + "}";
3598 }
3599 }
3600
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003601 private static boolean copyNeeded(int flags, Package p,
3602 PackageUserState state, Bundle metaData, int userId) {
3603 if (userId != 0) {
3604 // We always need to copy for other users, since we need
3605 // to fix up the uid.
3606 return true;
3607 }
3608 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3609 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003610 if (p.applicationInfo.enabled != enabled) {
3611 return true;
3612 }
3613 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003614 if (!state.installed) {
3615 return true;
3616 }
3617 if (state.stopped) {
3618 return true;
3619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 if ((flags & PackageManager.GET_META_DATA) != 0
3621 && (metaData != null || p.mAppMetaData != null)) {
3622 return true;
3623 }
3624 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3625 && p.usesLibraryFiles != null) {
3626 return true;
3627 }
3628 return false;
3629 }
3630
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003631 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3632 PackageUserState state) {
3633 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003634 }
3635
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003636 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3637 PackageUserState state) {
3638 // CompatibilityMode is global state.
3639 if (!sCompatibilityModeEnabled) {
3640 ai.disableCompatibilityMode();
3641 }
3642 if (state.installed) {
3643 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3644 } else {
3645 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3646 }
3647 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3648 ai.enabled = true;
3649 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3650 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3651 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3652 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3653 ai.enabled = false;
3654 }
3655 ai.enabledSetting = state.enabled;
3656 }
3657
Amith Yamasani13593602012-03-22 16:16:17 -07003658 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003659 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003661 if (!checkUseInstalled(flags, state)) {
3662 return null;
3663 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003664 if (!copyNeeded(flags, p, state, null, userId)
3665 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3666 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3667 // In this case it is safe to directly modify the internal ApplicationInfo state:
3668 // - CompatibilityMode is global state, so will be the same for every call.
3669 // - We only come in to here if the app should reported as installed; this is the
3670 // default state, and we will do a copy otherwise.
3671 // - The enable state will always be reported the same for the application across
3672 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3673 // be doing a copy.
3674 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 return p.applicationInfo;
3676 }
3677
3678 // Make shallow copy so we can store the metadata/libraries safely
3679 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003680 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003681 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003682 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 if ((flags & PackageManager.GET_META_DATA) != 0) {
3685 ai.metaData = p.mAppMetaData;
3686 }
3687 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3688 ai.sharedLibraryFiles = p.usesLibraryFiles;
3689 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003690 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003691 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003692 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003693 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003694 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003695 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 return ai;
3697 }
3698
3699 public static final PermissionInfo generatePermissionInfo(
3700 Permission p, int flags) {
3701 if (p == null) return null;
3702 if ((flags&PackageManager.GET_META_DATA) == 0) {
3703 return p.info;
3704 }
3705 PermissionInfo pi = new PermissionInfo(p.info);
3706 pi.metaData = p.metaData;
3707 return pi;
3708 }
3709
3710 public static final PermissionGroupInfo generatePermissionGroupInfo(
3711 PermissionGroup pg, int flags) {
3712 if (pg == null) return null;
3713 if ((flags&PackageManager.GET_META_DATA) == 0) {
3714 return pg.info;
3715 }
3716 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3717 pgi.metaData = pg.metaData;
3718 return pgi;
3719 }
3720
3721 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003722 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003724 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3725 super(args, _info);
3726 info = _info;
3727 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003729
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003730 public void setPackageName(String packageName) {
3731 super.setPackageName(packageName);
3732 info.packageName = packageName;
3733 }
3734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 public String toString() {
3736 return "Activity{"
3737 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003738 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 }
3740 }
3741
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003742 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3743 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003745 if (!checkUseInstalled(flags, state)) {
3746 return null;
3747 }
3748 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 return a.info;
3750 }
3751 // Make shallow copies so we can store the metadata safely
3752 ActivityInfo ai = new ActivityInfo(a.info);
3753 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003754 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 return ai;
3756 }
3757
3758 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003759 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003761 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3762 super(args, _info);
3763 info = _info;
3764 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003766
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003767 public void setPackageName(String packageName) {
3768 super.setPackageName(packageName);
3769 info.packageName = packageName;
3770 }
3771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 public String toString() {
3773 return "Service{"
3774 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003775 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 }
3777 }
3778
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003779 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3780 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003782 if (!checkUseInstalled(flags, state)) {
3783 return null;
3784 }
3785 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 return s.info;
3787 }
3788 // Make shallow copies so we can store the metadata safely
3789 ServiceInfo si = new ServiceInfo(s.info);
3790 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003791 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 return si;
3793 }
3794
3795 public final static class Provider extends Component {
3796 public final ProviderInfo info;
3797 public boolean syncable;
3798
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003799 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3800 super(args, _info);
3801 info = _info;
3802 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 syncable = false;
3804 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 public Provider(Provider existingProvider) {
3807 super(existingProvider);
3808 this.info = existingProvider.info;
3809 this.syncable = existingProvider.syncable;
3810 }
3811
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003812 public void setPackageName(String packageName) {
3813 super.setPackageName(packageName);
3814 info.packageName = packageName;
3815 }
3816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 public String toString() {
3818 return "Provider{"
3819 + Integer.toHexString(System.identityHashCode(this))
3820 + " " + info.name + "}";
3821 }
3822 }
3823
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003824 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3825 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003827 if (!checkUseInstalled(flags, state)) {
3828 return null;
3829 }
3830 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003832 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 return p.info;
3834 }
3835 // Make shallow copies so we can store the metadata safely
3836 ProviderInfo pi = new ProviderInfo(p.info);
3837 pi.metaData = p.metaData;
3838 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3839 pi.uriPermissionPatterns = null;
3840 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003841 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 return pi;
3843 }
3844
3845 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003846 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003848 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3849 super(args, _info);
3850 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003852
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003853 public void setPackageName(String packageName) {
3854 super.setPackageName(packageName);
3855 info.packageName = packageName;
3856 }
3857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 public String toString() {
3859 return "Instrumentation{"
3860 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003861 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 }
3863 }
3864
3865 public static final InstrumentationInfo generateInstrumentationInfo(
3866 Instrumentation i, int flags) {
3867 if (i == null) return null;
3868 if ((flags&PackageManager.GET_META_DATA) == 0) {
3869 return i.info;
3870 }
3871 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3872 ii.metaData = i.metaData;
3873 return ii;
3874 }
3875
3876 public static class IntentInfo extends IntentFilter {
3877 public boolean hasDefault;
3878 public int labelRes;
3879 public CharSequence nonLocalizedLabel;
3880 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003881 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882 }
3883
3884 public final static class ActivityIntentInfo extends IntentInfo {
3885 public final Activity activity;
3886
3887 public ActivityIntentInfo(Activity _activity) {
3888 activity = _activity;
3889 }
3890
3891 public String toString() {
3892 return "ActivityIntentInfo{"
3893 + Integer.toHexString(System.identityHashCode(this))
3894 + " " + activity.info.name + "}";
3895 }
3896 }
3897
3898 public final static class ServiceIntentInfo extends IntentInfo {
3899 public final Service service;
3900
3901 public ServiceIntentInfo(Service _service) {
3902 service = _service;
3903 }
3904
3905 public String toString() {
3906 return "ServiceIntentInfo{"
3907 + Integer.toHexString(System.identityHashCode(this))
3908 + " " + service.info.name + "}";
3909 }
3910 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003911
3912 /**
3913 * @hide
3914 */
3915 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3916 sCompatibilityModeEnabled = compatibilityModeEnabled;
3917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918}