blob: aaa2640a598b9b2a2266f43b935848881f42e5f6 [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;
Geremy Condraf1bcca82013-01-07 22:35:24 -080053import java.util.HashMap;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Geremy Condraf1bcca82013-01-07 22:35:24 -080057import java.util.Map;
58import java.util.Set;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import java.util.jar.JarEntry;
60import java.util.jar.JarFile;
Kenny Root6c918ce2013-04-02 14:04:24 -070061import java.util.zip.ZipEntry;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Amith Yamasani742a6712011-05-04 14:49:28 -070063import com.android.internal.util.XmlUtils;
64
65import org.xmlpull.v1.XmlPullParser;
66import org.xmlpull.v1.XmlPullParserException;
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068/**
69 * Package archive parsing
70 *
71 * {@hide}
72 */
73public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070074 private static final boolean DEBUG_JAR = false;
75 private static final boolean DEBUG_PARSER = false;
76 private static final boolean DEBUG_BACKUP = false;
77
Kenny Rootbcc954d2011-08-08 16:19:08 -070078 /** File name in an APK for the Android manifest. */
79 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
80
Dianne Hackborna96cbb42009-05-13 15:06:13 -070081 /** @hide */
82 public static class NewPermissionInfo {
83 public final String name;
84 public final int sdkVersion;
85 public final int fileVersion;
86
87 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
88 this.name = name;
89 this.sdkVersion = sdkVersion;
90 this.fileVersion = fileVersion;
91 }
92 }
Dianne Hackborn79245122012-03-12 10:51:26 -070093
94 /** @hide */
95 public static class SplitPermissionInfo {
96 public final String rootPerm;
97 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070098 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070099
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700100 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700101 this.rootPerm = rootPerm;
102 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700103 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700104 }
105 }
106
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700107 /**
108 * List of new permissions that have been added since 1.0.
109 * NOTE: These must be declared in SDK version order, with permissions
110 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700111 * If sdkVersion is 0, then this is not a permission that we want to
112 * automatically add to older apps, but we do want to allow it to be
113 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700114 * @hide
115 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700116 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
117 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700118 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700119 android.os.Build.VERSION_CODES.DONUT, 0),
120 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
121 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700122 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123
Dianne Hackborn79245122012-03-12 10:51:26 -0700124 /**
125 * List of permissions that have been split into more granular or dependent
126 * permissions.
127 * @hide
128 */
129 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
130 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700131 // READ_EXTERNAL_STORAGE is always required when an app requests
132 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
133 // write access without read access. The hack here with the target
134 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700135 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700136 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700137 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700138 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
139 new String[] { android.Manifest.permission.READ_CALL_LOG },
140 android.os.Build.VERSION_CODES.JELLY_BEAN),
141 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
142 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
143 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700144 };
145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private String mArchiveSourcePath;
147 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700148 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700149 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
150 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
151 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152
153 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
154
155 private static final Object mSync = new Object();
156 private static WeakReference<byte[]> mReadBuffer;
157
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700158 private static boolean sCompatibilityModeEnabled = true;
Amith Yamasani655d0e22013-06-12 14:19:10 -0700159 private static final int PARSE_DEFAULT_INSTALL_LOCATION =
160 PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700161
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700162 static class ParsePackageItemArgs {
163 final Package owner;
164 final String[] outError;
165 final int nameRes;
166 final int labelRes;
167 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700168 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700169
170 String tag;
171 TypedArray sa;
172
173 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700174 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700175 owner = _owner;
176 outError = _outError;
177 nameRes = _nameRes;
178 labelRes = _labelRes;
179 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700180 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700181 }
182 }
183
184 static class ParseComponentArgs extends ParsePackageItemArgs {
185 final String[] sepProcesses;
186 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800187 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700188 final int enabledRes;
189 int flags;
190
191 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700192 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800193 String[] _sepProcesses, int _processRes,
194 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700195 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700196 sepProcesses = _sepProcesses;
197 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800198 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700199 enabledRes = _enabledRes;
200 }
201 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800202
203 /* Light weight package info.
204 * @hide
205 */
206 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700207 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700208 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700209 public final int installLocation;
210 public final VerifierInfo[] verifiers;
211
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700212 public PackageLite(String packageName, int versionCode,
213 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800214 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700215 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800216 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700217 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800218 }
219 }
220
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700221 private ParsePackageItemArgs mParseInstrumentationArgs;
222 private ParseComponentArgs mParseActivityArgs;
223 private ParseComponentArgs mParseActivityAliasArgs;
224 private ParseComponentArgs mParseServiceArgs;
225 private ParseComponentArgs mParseProviderArgs;
226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 /** If set to true, we will only allow package files that exactly match
228 * the DTD. Otherwise, we try to get as much from the package as we
229 * can without failing. This should normally be set to false, to
230 * support extensions to the DTD in future versions. */
231 private static final boolean RIGID_PARSER = false;
232
233 private static final String TAG = "PackageParser";
234
235 public PackageParser(String archiveSourcePath) {
236 mArchiveSourcePath = archiveSourcePath;
237 }
238
239 public void setSeparateProcesses(String[] procs) {
240 mSeparateProcesses = procs;
241 }
242
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700243 public void setOnlyCoreApps(boolean onlyCoreApps) {
244 mOnlyCoreApps = onlyCoreApps;
245 }
246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 private static final boolean isPackageFilename(String name) {
248 return name.endsWith(".apk");
249 }
250
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700251 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700252 public static PackageInfo generatePackageInfo(PackageParser.Package p,
253 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
254 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700255 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700256 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700257 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700258 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700259 */
Amith Yamasani13593602012-03-22 16:16:17 -0700260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 /**
262 * Generate and return the {@link PackageInfo} for a parsed package.
263 *
264 * @param p the parsed package.
265 * @param flags indicating which optional information is included.
266 */
267 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800268 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700269 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270
Amith Yamasani483f3b02012-03-13 16:08:00 -0700271 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700272 grantedPermissions, state, UserHandle.getCallingUserId());
273 }
274
Amith Yamasani655d0e22013-06-12 14:19:10 -0700275 /**
276 * Returns true if the package is installed and not blocked, or if the caller
277 * explicitly wanted all uninstalled and blocked packages as well.
278 */
279 private static boolean checkUseInstalledOrBlocked(int flags, PackageUserState state) {
280 return (state.installed && !state.blocked)
281 || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700282 }
283
Amith Yamasani13593602012-03-22 16:16:17 -0700284 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700285 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700286 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700287
Amith Yamasani655d0e22013-06-12 14:19:10 -0700288 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700289 return null;
290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 PackageInfo pi = new PackageInfo();
292 pi.packageName = p.packageName;
293 pi.versionCode = p.mVersionCode;
294 pi.versionName = p.mVersionName;
295 pi.sharedUserId = p.mSharedUserId;
296 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700297 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800298 pi.installLocation = p.installLocation;
Amith Yamasani0d8750d2013-05-01 15:25:28 -0700299 if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0
300 || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
301 pi.requiredForAllUsers = p.mRequiredForAllUsers;
302 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700303 pi.restrictedAccountType = p.mRestrictedAccountType;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700304 pi.requiredAccountType = p.mRequiredAccountType;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700305 pi.firstInstallTime = firstInstallTime;
306 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 if ((flags&PackageManager.GET_GIDS) != 0) {
308 pi.gids = gids;
309 }
310 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
311 int N = p.configPreferences.size();
312 if (N > 0) {
313 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700314 p.configPreferences.toArray(pi.configPreferences);
315 }
316 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
317 if (N > 0) {
318 pi.reqFeatures = new FeatureInfo[N];
319 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 }
321 }
322 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
323 int N = p.activities.size();
324 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700325 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
326 pi.activities = new ActivityInfo[N];
327 } else {
328 int num = 0;
329 for (int i=0; i<N; i++) {
330 if (p.activities.get(i).info.enabled) num++;
331 }
332 pi.activities = new ActivityInfo[num];
333 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700334 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 final Activity activity = p.activities.get(i);
336 if (activity.info.enabled
337 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700338 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700339 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 }
341 }
342 }
343 }
344 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
345 int N = p.receivers.size();
346 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700347 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
348 pi.receivers = new ActivityInfo[N];
349 } else {
350 int num = 0;
351 for (int i=0; i<N; i++) {
352 if (p.receivers.get(i).info.enabled) num++;
353 }
354 pi.receivers = new ActivityInfo[num];
355 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700356 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 final Activity activity = p.receivers.get(i);
358 if (activity.info.enabled
359 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700360 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700361 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 }
363 }
364 }
365 }
366 if ((flags&PackageManager.GET_SERVICES) != 0) {
367 int N = p.services.size();
368 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700369 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
370 pi.services = new ServiceInfo[N];
371 } else {
372 int num = 0;
373 for (int i=0; i<N; i++) {
374 if (p.services.get(i).info.enabled) num++;
375 }
376 pi.services = new ServiceInfo[num];
377 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700378 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 final Service service = p.services.get(i);
380 if (service.info.enabled
381 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700382 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
383 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 }
385 }
386 }
387 }
388 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
389 int N = p.providers.size();
390 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700391 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
392 pi.providers = new ProviderInfo[N];
393 } else {
394 int num = 0;
395 for (int i=0; i<N; i++) {
396 if (p.providers.get(i).info.enabled) num++;
397 }
398 pi.providers = new ProviderInfo[num];
399 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700400 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 final Provider provider = p.providers.get(i);
402 if (provider.info.enabled
403 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700404 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
405 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 }
407 }
408 }
409 }
410 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
411 int N = p.instrumentation.size();
412 if (N > 0) {
413 pi.instrumentation = new InstrumentationInfo[N];
414 for (int i=0; i<N; i++) {
415 pi.instrumentation[i] = generateInstrumentationInfo(
416 p.instrumentation.get(i), flags);
417 }
418 }
419 }
420 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
421 int N = p.permissions.size();
422 if (N > 0) {
423 pi.permissions = new PermissionInfo[N];
424 for (int i=0; i<N; i++) {
425 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
426 }
427 }
428 N = p.requestedPermissions.size();
429 if (N > 0) {
430 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800431 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800433 final String perm = p.requestedPermissions.get(i);
434 pi.requestedPermissions[i] = perm;
435 if (p.requestedPermissionsRequired.get(i)) {
436 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
437 }
438 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
439 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 }
442 }
443 }
444 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700445 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
446 if (N > 0) {
447 pi.signatures = new Signature[N];
448 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 }
450 }
451 return pi;
452 }
453
454 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
455 byte[] readBuffer) {
456 try {
457 // We must read the stream for the JarEntry to retrieve
458 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700459 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
461 // not using
462 }
463 is.close();
464 return je != null ? je.getCertificates() : null;
465 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700466 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700468 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700469 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700470 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472 return null;
473 }
474
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800475 public final static int PARSE_IS_SYSTEM = 1<<0;
476 public final static int PARSE_CHATTY = 1<<1;
477 public final static int PARSE_MUST_BE_APK = 1<<2;
478 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
479 public final static int PARSE_FORWARD_LOCK = 1<<4;
480 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700481 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
Christopher Tateccbf84f2013-05-08 15:25:41 -0700482 public final static int PARSE_IS_PRIVILEGED = 1<<7;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483
484 public int getParseError() {
485 return mParseError;
486 }
487
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800488 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 DisplayMetrics metrics, int flags) {
490 mParseError = PackageManager.INSTALL_SUCCEEDED;
491
492 mArchiveSourcePath = sourceFile.getPath();
493 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700494 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
496 return null;
497 }
498 if (!isPackageFilename(sourceFile.getName())
499 && (flags&PARSE_MUST_BE_APK) != 0) {
500 if ((flags&PARSE_IS_SYSTEM) == 0) {
501 // We expect to have non-.apk files in the system dir,
502 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700503 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
506 return null;
507 }
508
Kenny Rootd2d29252011-08-08 11:27:57 -0700509 if (DEBUG_JAR)
510 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511
512 XmlResourceParser parser = null;
513 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800514 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 boolean assetError = true;
516 try {
517 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700518 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800519 if (cookie != 0) {
520 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700521 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 -0800522 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700523 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 assetError = false;
525 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700526 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 }
528 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700529 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 + mArchiveSourcePath, e);
531 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800532 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 if (assmgr != null) assmgr.close();
534 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
535 return null;
536 }
537 String[] errorText = new String[1];
538 Package pkg = null;
539 Exception errorException = null;
540 try {
541 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 pkg = parsePackage(res, parser, flags, errorText);
543 } catch (Exception e) {
544 errorException = e;
545 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
546 }
547
548
549 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700550 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
551 // just means to skip this app so don't make a fuss about it.
552 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
553 if (errorException != null) {
554 Slog.w(TAG, mArchiveSourcePath, errorException);
555 } else {
556 Slog.w(TAG, mArchiveSourcePath + " (at "
557 + parser.getPositionDescription()
558 + "): " + errorText[0]);
559 }
560 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
561 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564 parser.close();
565 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 return null;
567 }
568
569 parser.close();
570 assmgr.close();
571
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800572 // Set code and resource paths
573 pkg.mPath = destCodePath;
574 pkg.mScanPath = mArchiveSourcePath;
575 //pkg.applicationInfo.sourceDir = destCodePath;
576 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 pkg.mSignatures = null;
578
579 return pkg;
580 }
581
Kenny Root6c918ce2013-04-02 14:04:24 -0700582 /**
583 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
584 * APK. If it successfully scanned the package and found the
585 * {@code AndroidManifest.xml}, {@code true} is returned.
586 */
587 public boolean collectManifestDigest(Package pkg) {
588 try {
589 final JarFile jarFile = new JarFile(mArchiveSourcePath);
590 try {
591 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
592 if (je != null) {
593 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
594 }
595 } finally {
596 jarFile.close();
597 }
598 return true;
599 } catch (IOException e) {
600 return false;
601 }
602 }
603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 public boolean collectCertificates(Package pkg, int flags) {
605 pkg.mSignatures = null;
606
607 WeakReference<byte[]> readBufferRef;
608 byte[] readBuffer = null;
609 synchronized (mSync) {
610 readBufferRef = mReadBuffer;
611 if (readBufferRef != null) {
612 mReadBuffer = null;
613 readBuffer = readBufferRef.get();
614 }
615 if (readBuffer == null) {
616 readBuffer = new byte[8192];
617 readBufferRef = new WeakReference<byte[]>(readBuffer);
618 }
619 }
620
621 try {
622 JarFile jarFile = new JarFile(mArchiveSourcePath);
623
624 Certificate[] certs = null;
625
626 if ((flags&PARSE_IS_SYSTEM) != 0) {
627 // If this package comes from the system image, then we
628 // can trust it... we'll just use the AndroidManifest.xml
629 // to retrieve its signatures, not validating all of the
630 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700631 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 certs = loadCertificates(jarFile, jarEntry, readBuffer);
633 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700634 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 + " has no certificates at entry "
636 + jarEntry.getName() + "; ignoring!");
637 jarFile.close();
638 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
639 return false;
640 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700641 if (DEBUG_JAR) {
642 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 + " certs=" + (certs != null ? certs.length : 0));
644 if (certs != null) {
645 final int N = certs.length;
646 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700647 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 + certs[i].getPublicKey().getEncoded()
649 + " " + certs[i].getPublicKey());
650 }
651 }
652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700654 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700656 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700658
Kenny Rootbcc954d2011-08-08 16:19:08 -0700659 final String name = je.getName();
660
661 if (name.startsWith("META-INF/"))
662 continue;
663
664 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700665 pkg.manifestDigest =
666 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700667 }
668
669 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700670 if (DEBUG_JAR) {
671 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 + ": certs=" + certs + " ("
673 + (certs != null ? certs.length : 0) + ")");
674 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700677 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 + " has no certificates at entry "
679 + je.getName() + "; ignoring!");
680 jarFile.close();
681 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
682 return false;
683 } else if (certs == null) {
684 certs = localCerts;
685 } else {
686 // Ensure all certificates match.
687 for (int i=0; i<certs.length; i++) {
688 boolean found = false;
689 for (int j=0; j<localCerts.length; j++) {
690 if (certs[i] != null &&
691 certs[i].equals(localCerts[j])) {
692 found = true;
693 break;
694 }
695 }
696 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700697 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 + " has mismatched certificates at entry "
699 + je.getName() + "; ignoring!");
700 jarFile.close();
701 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
702 return false;
703 }
704 }
705 }
706 }
707 }
708 jarFile.close();
709
710 synchronized (mSync) {
711 mReadBuffer = readBufferRef;
712 }
713
714 if (certs != null && certs.length > 0) {
715 final int N = certs.length;
716 pkg.mSignatures = new Signature[certs.length];
717 for (int i=0; i<N; i++) {
718 pkg.mSignatures[i] = new Signature(
719 certs[i].getEncoded());
720 }
721 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700722 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 + " has no certificates; ignoring!");
724 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
725 return false;
726 }
Geremy Condraf1bcca82013-01-07 22:35:24 -0800727
728 // Add the signing KeySet to the system
729 pkg.mSigningKeys = new HashSet<PublicKey>();
730 for (int i=0; i < certs.length; i++) {
731 pkg.mSigningKeys.add(certs[i].getPublicKey());
732 }
733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700735 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
737 return false;
738 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700739 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
741 return false;
742 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700743 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
745 return false;
746 }
747
748 return true;
749 }
750
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800751 /*
752 * Utility method that retrieves just the package name and install
753 * location from the apk location at the given file path.
754 * @param packageFilePath file location of the apk
755 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700756 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800757 */
758 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700760 final XmlResourceParser parser;
761 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 try {
763 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700764 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 -0800765 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700768 if (cookie == 0) {
769 return null;
770 }
771
Kenny Root05ca4c92011-09-15 10:36:25 -0700772 final DisplayMetrics metrics = new DisplayMetrics();
773 metrics.setToDefaults();
774 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700775 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 } catch (Exception e) {
777 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700778 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 + packageFilePath, e);
780 return null;
781 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700782
783 final AttributeSet attrs = parser;
784 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800785 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700787 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700789 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700791 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 } finally {
793 if (parser != null) parser.close();
794 if (assmgr != null) assmgr.close();
795 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800796 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700797 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 return null;
799 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800800 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 }
802
803 private static String validateName(String name, boolean requiresSeparator) {
804 final int N = name.length();
805 boolean hasSep = false;
806 boolean front = true;
807 for (int i=0; i<N; i++) {
808 final char c = name.charAt(i);
809 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
810 front = false;
811 continue;
812 }
813 if (!front) {
814 if ((c >= '0' && c <= '9') || c == '_') {
815 continue;
816 }
817 }
818 if (c == '.') {
819 hasSep = true;
820 front = true;
821 continue;
822 }
823 return "bad character '" + c + "'";
824 }
825 return hasSep || !requiresSeparator
826 ? null : "must have at least one '.' separator";
827 }
828
829 private static String parsePackageName(XmlPullParser parser,
830 AttributeSet attrs, int flags, String[] outError)
831 throws IOException, XmlPullParserException {
832
833 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700834 while ((type = parser.next()) != XmlPullParser.START_TAG
835 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 ;
837 }
838
Kenny Rootd2d29252011-08-08 11:27:57 -0700839 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 outError[0] = "No start tag found";
841 return null;
842 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700843 if (DEBUG_PARSER)
844 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 if (!parser.getName().equals("manifest")) {
846 outError[0] = "No <manifest> tag";
847 return null;
848 }
849 String pkgName = attrs.getAttributeValue(null, "package");
850 if (pkgName == null || pkgName.length() == 0) {
851 outError[0] = "<manifest> does not specify package";
852 return null;
853 }
854 String nameError = validateName(pkgName, true);
855 if (nameError != null && !"android".equals(pkgName)) {
856 outError[0] = "<manifest> specifies bad package name \""
857 + pkgName + "\": " + nameError;
858 return null;
859 }
860
861 return pkgName.intern();
862 }
863
Kenny Root05ca4c92011-09-15 10:36:25 -0700864 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
865 AttributeSet attrs, int flags, String[] outError) throws IOException,
866 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800867
868 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700869 while ((type = parser.next()) != XmlPullParser.START_TAG
870 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800871 ;
872 }
873
Kenny Rootd2d29252011-08-08 11:27:57 -0700874 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800875 outError[0] = "No start tag found";
876 return null;
877 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700878 if (DEBUG_PARSER)
879 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800880 if (!parser.getName().equals("manifest")) {
881 outError[0] = "No <manifest> tag";
882 return null;
883 }
884 String pkgName = attrs.getAttributeValue(null, "package");
885 if (pkgName == null || pkgName.length() == 0) {
886 outError[0] = "<manifest> does not specify package";
887 return null;
888 }
889 String nameError = validateName(pkgName, true);
890 if (nameError != null && !"android".equals(pkgName)) {
891 outError[0] = "<manifest> specifies bad package name \""
892 + pkgName + "\": " + nameError;
893 return null;
894 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700895 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700896 int versionCode = 0;
897 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800898 for (int i = 0; i < attrs.getAttributeCount(); i++) {
899 String attr = attrs.getAttributeName(i);
900 if (attr.equals("installLocation")) {
901 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700902 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700903 numFound++;
904 } else if (attr.equals("versionCode")) {
905 versionCode = attrs.getAttributeIntValue(i, 0);
906 numFound++;
907 }
908 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800909 break;
910 }
911 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700912
913 // Only search the tree when the tag is directly below <manifest>
914 final int searchDepth = parser.getDepth() + 1;
915
916 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
917 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
918 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
919 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
920 continue;
921 }
922
923 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
924 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
925 if (verifier != null) {
926 verifiers.add(verifier);
927 }
928 }
929 }
930
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700931 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800932 }
933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 /**
935 * Temporary.
936 */
937 static public Signature stringToSignature(String str) {
938 final int N = str.length();
939 byte[] sig = new byte[N];
940 for (int i=0; i<N; i++) {
941 sig[i] = (byte)str.charAt(i);
942 }
943 return new Signature(sig);
944 }
945
946 private Package parsePackage(
947 Resources res, XmlResourceParser parser, int flags, String[] outError)
948 throws XmlPullParserException, IOException {
949 AttributeSet attrs = parser;
950
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700951 mParseInstrumentationArgs = null;
952 mParseActivityArgs = null;
953 mParseServiceArgs = null;
954 mParseProviderArgs = null;
955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 String pkgName = parsePackageName(parser, attrs, flags, outError);
957 if (pkgName == null) {
958 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
959 return null;
960 }
961 int type;
962
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700963 if (mOnlyCoreApps) {
964 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
965 if (!core) {
966 mParseError = PackageManager.INSTALL_SUCCEEDED;
967 return null;
968 }
969 }
970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 TypedArray sa = res.obtainAttributes(attrs,
975 com.android.internal.R.styleable.AndroidManifest);
976 pkg.mVersionCode = sa.getInteger(
977 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800978 pkg.mVersionName = sa.getNonConfigurationString(
979 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 if (pkg.mVersionName != null) {
981 pkg.mVersionName = pkg.mVersionName.intern();
982 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800983 String str = sa.getNonConfigurationString(
984 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
985 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 String nameError = validateName(str, true);
987 if (nameError != null && !"android".equals(pkgName)) {
988 outError[0] = "<manifest> specifies bad sharedUserId name \""
989 + str + "\": " + nameError;
990 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
991 return null;
992 }
993 pkg.mSharedUserId = str.intern();
994 pkg.mSharedUserLabel = sa.getResourceId(
995 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
996 }
997 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800998
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800999 pkg.installLocation = sa.getInteger(
1000 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -07001001 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001002 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -07001003
1004 /* Set the global "forward lock" flag */
1005 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1006 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1007 }
1008
1009 /* Set the global "on SD card" flag */
1010 if ((flags & PARSE_ON_SDCARD) != 0) {
1011 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
1012 }
1013
Dianne Hackborn723738c2009-06-25 19:48:04 -07001014 // Resource boolean are -1, so 1 means we don't know the value.
1015 int supportsSmallScreens = 1;
1016 int supportsNormalScreens = 1;
1017 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001018 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001019 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001020 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001023 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1024 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1025 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 continue;
1027 }
1028
1029 String tagName = parser.getName();
1030 if (tagName.equals("application")) {
1031 if (foundApp) {
1032 if (RIGID_PARSER) {
1033 outError[0] = "<manifest> has more than one <application>";
1034 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1035 return null;
1036 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001037 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 XmlUtils.skipCurrentTag(parser);
1039 continue;
1040 }
1041 }
1042
1043 foundApp = true;
1044 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1045 return null;
1046 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001047 } else if (tagName.equals("keys")) {
1048 if (!parseKeys(pkg, res, parser, attrs, outError)) {
1049 return null;
1050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001052 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 return null;
1054 }
1055 } else if (tagName.equals("permission")) {
1056 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1057 return null;
1058 }
1059 } else if (tagName.equals("permission-tree")) {
1060 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1061 return null;
1062 }
1063 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001064 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1065 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 } else if (tagName.equals("uses-configuration")) {
1069 ConfigurationInfo cPref = new ConfigurationInfo();
1070 sa = res.obtainAttributes(attrs,
1071 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1072 cPref.reqTouchScreen = sa.getInt(
1073 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1074 Configuration.TOUCHSCREEN_UNDEFINED);
1075 cPref.reqKeyboardType = sa.getInt(
1076 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1077 Configuration.KEYBOARD_UNDEFINED);
1078 if (sa.getBoolean(
1079 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1080 false)) {
1081 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1082 }
1083 cPref.reqNavigation = sa.getInt(
1084 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1085 Configuration.NAVIGATION_UNDEFINED);
1086 if (sa.getBoolean(
1087 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1088 false)) {
1089 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1090 }
1091 sa.recycle();
1092 pkg.configPreferences.add(cPref);
1093
1094 XmlUtils.skipCurrentTag(parser);
1095
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001096 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001097 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001098 sa = res.obtainAttributes(attrs,
1099 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001100 // Note: don't allow this value to be a reference to a resource
1101 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001102 fi.name = sa.getNonResourceString(
1103 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1104 if (fi.name == null) {
1105 fi.reqGlEsVersion = sa.getInt(
1106 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1107 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1108 }
1109 if (sa.getBoolean(
1110 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1111 true)) {
1112 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1113 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001114 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001115 if (pkg.reqFeatures == null) {
1116 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1117 }
1118 pkg.reqFeatures.add(fi);
1119
1120 if (fi.name == null) {
1121 ConfigurationInfo cPref = new ConfigurationInfo();
1122 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1123 pkg.configPreferences.add(cPref);
1124 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001125
1126 XmlUtils.skipCurrentTag(parser);
1127
Dianne Hackborn851a5412009-05-08 12:06:44 -07001128 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001129 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 sa = res.obtainAttributes(attrs,
1131 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1132
Dianne Hackborn851a5412009-05-08 12:06:44 -07001133 int minVers = 0;
1134 String minCode = null;
1135 int targetVers = 0;
1136 String targetCode = null;
1137
1138 TypedValue val = sa.peekValue(
1139 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1140 if (val != null) {
1141 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1142 targetCode = minCode = val.string.toString();
1143 } else {
1144 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001145 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001146 }
1147 }
1148
1149 val = sa.peekValue(
1150 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1151 if (val != null) {
1152 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1153 targetCode = minCode = val.string.toString();
1154 } else {
1155 // If it's not a string, it's an integer.
1156 targetVers = val.data;
1157 }
1158 }
1159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 sa.recycle();
1161
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001162 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001163 if (!minCode.equals(SDK_CODENAME)) {
1164 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001165 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001166 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001167 } else {
1168 outError[0] = "Requires development platform " + minCode
1169 + " but this is a release platform.";
1170 }
1171 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1172 return null;
1173 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001174 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001175 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001176 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001177 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1178 return null;
1179 }
1180
Dianne Hackborn851a5412009-05-08 12:06:44 -07001181 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001182 if (!targetCode.equals(SDK_CODENAME)) {
1183 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001184 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001185 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001186 } else {
1187 outError[0] = "Requires development platform " + targetCode
1188 + " but this is a release platform.";
1189 }
1190 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1191 return null;
1192 }
1193 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001194 pkg.applicationInfo.targetSdkVersion
1195 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1196 } else {
1197 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 }
1200
1201 XmlUtils.skipCurrentTag(parser);
1202
Dianne Hackborn723738c2009-06-25 19:48:04 -07001203 } else if (tagName.equals("supports-screens")) {
1204 sa = res.obtainAttributes(attrs,
1205 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1206
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001207 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1208 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1209 0);
1210 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1211 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1212 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001213 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1214 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1215 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001216
Dianne Hackborn723738c2009-06-25 19:48:04 -07001217 // This is a trick to get a boolean and still able to detect
1218 // if a value was actually set.
1219 supportsSmallScreens = sa.getInteger(
1220 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1221 supportsSmallScreens);
1222 supportsNormalScreens = sa.getInteger(
1223 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1224 supportsNormalScreens);
1225 supportsLargeScreens = sa.getInteger(
1226 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1227 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001228 supportsXLargeScreens = sa.getInteger(
1229 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1230 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001231 resizeable = sa.getInteger(
1232 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001233 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001234 anyDensity = sa.getInteger(
1235 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1236 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001237
1238 sa.recycle();
1239
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001240 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001241
1242 } else if (tagName.equals("protected-broadcast")) {
1243 sa = res.obtainAttributes(attrs,
1244 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1245
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001246 // Note: don't allow this value to be a reference to a resource
1247 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001248 String name = sa.getNonResourceString(
1249 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1250
1251 sa.recycle();
1252
1253 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1254 if (pkg.protectedBroadcasts == null) {
1255 pkg.protectedBroadcasts = new ArrayList<String>();
1256 }
1257 if (!pkg.protectedBroadcasts.contains(name)) {
1258 pkg.protectedBroadcasts.add(name.intern());
1259 }
1260 }
1261
1262 XmlUtils.skipCurrentTag(parser);
1263
1264 } else if (tagName.equals("instrumentation")) {
1265 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1266 return null;
1267 }
1268
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001269 } else if (tagName.equals("original-package")) {
1270 sa = res.obtainAttributes(attrs,
1271 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1272
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001273 String orig =sa.getNonConfigurationString(
1274 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001275 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001276 if (pkg.mOriginalPackages == null) {
1277 pkg.mOriginalPackages = new ArrayList<String>();
1278 pkg.mRealPackage = pkg.packageName;
1279 }
1280 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001281 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001282
1283 sa.recycle();
1284
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001285 XmlUtils.skipCurrentTag(parser);
1286
1287 } else if (tagName.equals("adopt-permissions")) {
1288 sa = res.obtainAttributes(attrs,
1289 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1290
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001291 String name = sa.getNonConfigurationString(
1292 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001293
1294 sa.recycle();
1295
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001296 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001297 if (pkg.mAdoptPermissions == null) {
1298 pkg.mAdoptPermissions = new ArrayList<String>();
1299 }
1300 pkg.mAdoptPermissions.add(name);
1301 }
1302
1303 XmlUtils.skipCurrentTag(parser);
1304
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001305 } else if (tagName.equals("uses-gl-texture")) {
1306 // Just skip this tag
1307 XmlUtils.skipCurrentTag(parser);
1308 continue;
1309
1310 } else if (tagName.equals("compatible-screens")) {
1311 // Just skip this tag
1312 XmlUtils.skipCurrentTag(parser);
1313 continue;
1314
Dianne Hackborn854060a2009-07-09 18:14:31 -07001315 } else if (tagName.equals("eat-comment")) {
1316 // Just skip this tag
1317 XmlUtils.skipCurrentTag(parser);
1318 continue;
1319
1320 } else if (RIGID_PARSER) {
1321 outError[0] = "Bad element under <manifest>: "
1322 + parser.getName();
1323 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1324 return null;
1325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001327 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001328 + " at " + mArchiveSourcePath + " "
1329 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 XmlUtils.skipCurrentTag(parser);
1331 continue;
1332 }
1333 }
1334
1335 if (!foundApp && pkg.instrumentation.size() == 0) {
1336 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1337 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1338 }
1339
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001340 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001341 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001342 for (int ip=0; ip<NP; ip++) {
1343 final PackageParser.NewPermissionInfo npi
1344 = PackageParser.NEW_PERMISSIONS[ip];
1345 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1346 break;
1347 }
1348 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001349 if (implicitPerms == null) {
1350 implicitPerms = new StringBuilder(128);
1351 implicitPerms.append(pkg.packageName);
1352 implicitPerms.append(": compat added ");
1353 } else {
1354 implicitPerms.append(' ');
1355 }
1356 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001357 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001358 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001359 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001360 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001361 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001362 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001363 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001364
1365 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1366 for (int is=0; is<NS; is++) {
1367 final PackageParser.SplitPermissionInfo spi
1368 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001369 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1370 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001371 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001372 }
1373 for (int in=0; in<spi.newPerms.length; in++) {
1374 final String perm = spi.newPerms[in];
1375 if (!pkg.requestedPermissions.contains(perm)) {
1376 pkg.requestedPermissions.add(perm);
1377 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1378 }
1379 }
1380 }
1381
Dianne Hackborn723738c2009-06-25 19:48:04 -07001382 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1383 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001384 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001385 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1386 }
1387 if (supportsNormalScreens != 0) {
1388 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1389 }
1390 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1391 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001392 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001393 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1394 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001395 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1396 && pkg.applicationInfo.targetSdkVersion
1397 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1398 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1399 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001400 if (resizeable < 0 || (resizeable > 0
1401 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001402 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001403 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1404 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001405 if (anyDensity < 0 || (anyDensity > 0
1406 && pkg.applicationInfo.targetSdkVersion
1407 >= android.os.Build.VERSION_CODES.DONUT)) {
1408 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001409 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001410
Nick Kralevich38f130e2013-04-04 13:19:10 -07001411 /*
1412 * b/8528162: Ignore the <uses-permission android:required> attribute if
1413 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1414 * which are improperly using this attribute, even though it never worked.
1415 */
1416 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1417 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1418 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1419 }
1420 }
1421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 return pkg;
1423 }
1424
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001425 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1426 AttributeSet attrs, String[] outError)
1427 throws XmlPullParserException, IOException {
1428 TypedArray sa = res.obtainAttributes(attrs,
1429 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1430
1431 // Note: don't allow this value to be a reference to a resource
1432 // that may change.
1433 String name = sa.getNonResourceString(
1434 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001435/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001436 boolean required = sa.getBoolean(
1437 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001438*/
1439 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001440
1441 sa.recycle();
1442
1443 if (name != null) {
1444 int index = pkg.requestedPermissions.indexOf(name);
1445 if (index == -1) {
1446 pkg.requestedPermissions.add(name.intern());
1447 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1448 } else {
1449 if (pkg.requestedPermissionsRequired.get(index) != required) {
1450 outError[0] = "conflicting <uses-permission> entries";
1451 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1452 return false;
1453 }
1454 }
1455 }
1456
1457 XmlUtils.skipCurrentTag(parser);
1458 return true;
1459 }
1460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 private static String buildClassName(String pkg, CharSequence clsSeq,
1462 String[] outError) {
1463 if (clsSeq == null || clsSeq.length() <= 0) {
1464 outError[0] = "Empty class name in package " + pkg;
1465 return null;
1466 }
1467 String cls = clsSeq.toString();
1468 char c = cls.charAt(0);
1469 if (c == '.') {
1470 return (pkg + cls).intern();
1471 }
1472 if (cls.indexOf('.') < 0) {
1473 StringBuilder b = new StringBuilder(pkg);
1474 b.append('.');
1475 b.append(cls);
1476 return b.toString().intern();
1477 }
1478 if (c >= 'a' && c <= 'z') {
1479 return cls.intern();
1480 }
1481 outError[0] = "Bad class name " + cls + " in package " + pkg;
1482 return null;
1483 }
1484
1485 private static String buildCompoundName(String pkg,
1486 CharSequence procSeq, String type, String[] outError) {
1487 String proc = procSeq.toString();
1488 char c = proc.charAt(0);
1489 if (pkg != null && c == ':') {
1490 if (proc.length() < 2) {
1491 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1492 + ": must be at least two characters";
1493 return null;
1494 }
1495 String subName = proc.substring(1);
1496 String nameError = validateName(subName, false);
1497 if (nameError != null) {
1498 outError[0] = "Invalid " + type + " name " + proc + " in package "
1499 + pkg + ": " + nameError;
1500 return null;
1501 }
1502 return (pkg + proc).intern();
1503 }
1504 String nameError = validateName(proc, true);
1505 if (nameError != null && !"system".equals(proc)) {
1506 outError[0] = "Invalid " + type + " name " + proc + " in package "
1507 + pkg + ": " + nameError;
1508 return null;
1509 }
1510 return proc.intern();
1511 }
1512
1513 private static String buildProcessName(String pkg, String defProc,
1514 CharSequence procSeq, int flags, String[] separateProcesses,
1515 String[] outError) {
1516 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1517 return defProc != null ? defProc : pkg;
1518 }
1519 if (separateProcesses != null) {
1520 for (int i=separateProcesses.length-1; i>=0; i--) {
1521 String sp = separateProcesses[i];
1522 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1523 return pkg;
1524 }
1525 }
1526 }
1527 if (procSeq == null || procSeq.length() <= 0) {
1528 return defProc;
1529 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001530 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 }
1532
1533 private static String buildTaskAffinityName(String pkg, String defProc,
1534 CharSequence procSeq, String[] outError) {
1535 if (procSeq == null) {
1536 return defProc;
1537 }
1538 if (procSeq.length() <= 0) {
1539 return null;
1540 }
1541 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1542 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001543
1544 private boolean parseKeys(Package owner, Resources res,
1545 XmlPullParser parser, AttributeSet attrs, String[] outError)
1546 throws XmlPullParserException, IOException {
1547 // we've encountered the 'keys' tag
1548 // all the keys and keysets that we want must be defined here
1549 // so we're going to iterate over the parser and pull out the things we want
1550 int outerDepth = parser.getDepth();
1551
1552 int type;
1553 PublicKey currentKey = null;
Kenny Root37dca152013-07-10 14:01:49 -07001554 int currentKeyDepth = -1;
Geremy Condraf1bcca82013-01-07 22:35:24 -08001555 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1556 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1557 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1558 if (type == XmlPullParser.END_TAG) {
Kenny Root37dca152013-07-10 14:01:49 -07001559 if (parser.getDepth() == currentKeyDepth) {
1560 currentKey = null;
1561 currentKeyDepth = -1;
1562 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001563 continue;
1564 }
1565 String tagname = parser.getName();
1566 if (tagname.equals("publicKey")) {
1567 final TypedArray sa = res.obtainAttributes(attrs,
1568 com.android.internal.R.styleable.PublicKey);
1569 final String encodedKey = sa.getNonResourceString(
1570 com.android.internal.R.styleable.PublicKey_value);
1571 currentKey = parsePublicKey(encodedKey);
Kenny Root37dca152013-07-10 14:01:49 -07001572 if (currentKey == null) {
1573 Slog.w(TAG, "No valid key in 'publicKey' tag at "
1574 + parser.getPositionDescription());
1575 sa.recycle();
1576 continue;
1577 }
1578 currentKeyDepth = parser.getDepth();
Geremy Condraf1bcca82013-01-07 22:35:24 -08001579 definedKeySets.put(currentKey, new HashSet<String>());
1580 sa.recycle();
Kenny Root2758e292013-07-08 09:32:59 -07001581 } else if (tagname.equals("keyset")) {
Kenny Root37dca152013-07-10 14:01:49 -07001582 if (currentKey == null) {
1583 Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
1584 + parser.getPositionDescription());
1585 continue;
1586 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001587 final TypedArray sa = res.obtainAttributes(attrs,
1588 com.android.internal.R.styleable.KeySet);
1589 final String name = sa.getNonResourceString(
1590 com.android.internal.R.styleable.KeySet_name);
1591 definedKeySets.get(currentKey).add(name);
1592 sa.recycle();
1593 } else if (RIGID_PARSER) {
1594 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1595 + " at " + mArchiveSourcePath + " "
1596 + parser.getPositionDescription());
1597 return false;
1598 } else {
1599 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1600 + " at " + mArchiveSourcePath + " "
1601 + parser.getPositionDescription());
1602 XmlUtils.skipCurrentTag(parser);
1603 continue;
1604 }
1605 }
1606
1607 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1608 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1609 PublicKey key = e.getKey();
1610 Set<String> keySetNames = e.getValue();
1611 for (String alias : keySetNames) {
1612 if (owner.mKeySetMapping.containsKey(alias)) {
1613 owner.mKeySetMapping.get(alias).add(key);
1614 } else {
1615 Set<PublicKey> keys = new HashSet<PublicKey>();
1616 keys.add(key);
1617 owner.mKeySetMapping.put(alias, keys);
1618 }
1619 }
1620 }
1621
1622 return true;
1623 }
1624
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001625 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 XmlPullParser parser, AttributeSet attrs, String[] outError)
1627 throws XmlPullParserException, IOException {
1628 PermissionGroup perm = new PermissionGroup(owner);
1629
1630 TypedArray sa = res.obtainAttributes(attrs,
1631 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1632
1633 if (!parsePackageItemInfo(owner, perm.info, outError,
1634 "<permission-group>", sa,
1635 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1636 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001637 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1638 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 sa.recycle();
1640 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1641 return null;
1642 }
1643
1644 perm.info.descriptionRes = sa.getResourceId(
1645 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1646 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001647 perm.info.flags = sa.getInt(
1648 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001649 perm.info.priority = sa.getInt(
1650 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001651 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001652 perm.info.priority = 0;
1653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654
1655 sa.recycle();
1656
1657 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1658 outError)) {
1659 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1660 return null;
1661 }
1662
1663 owner.permissionGroups.add(perm);
1664
1665 return perm;
1666 }
1667
1668 private Permission parsePermission(Package owner, Resources res,
1669 XmlPullParser parser, AttributeSet attrs, String[] outError)
1670 throws XmlPullParserException, IOException {
1671 Permission perm = new Permission(owner);
1672
1673 TypedArray sa = res.obtainAttributes(attrs,
1674 com.android.internal.R.styleable.AndroidManifestPermission);
1675
1676 if (!parsePackageItemInfo(owner, perm.info, outError,
1677 "<permission>", sa,
1678 com.android.internal.R.styleable.AndroidManifestPermission_name,
1679 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001680 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1681 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 sa.recycle();
1683 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1684 return null;
1685 }
1686
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001687 // Note: don't allow this value to be a reference to a resource
1688 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 perm.info.group = sa.getNonResourceString(
1690 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1691 if (perm.info.group != null) {
1692 perm.info.group = perm.info.group.intern();
1693 }
1694
1695 perm.info.descriptionRes = sa.getResourceId(
1696 com.android.internal.R.styleable.AndroidManifestPermission_description,
1697 0);
1698
1699 perm.info.protectionLevel = sa.getInt(
1700 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1701 PermissionInfo.PROTECTION_NORMAL);
1702
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001703 perm.info.flags = sa.getInt(
1704 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 if (perm.info.protectionLevel == -1) {
1709 outError[0] = "<permission> does not specify protectionLevel";
1710 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1711 return null;
1712 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001713
1714 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1715
1716 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1717 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1718 PermissionInfo.PROTECTION_SIGNATURE) {
1719 outError[0] = "<permission> protectionLevel specifies a flag but is "
1720 + "not based on signature type";
1721 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1722 return null;
1723 }
1724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725
1726 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1727 outError)) {
1728 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1729 return null;
1730 }
1731
1732 owner.permissions.add(perm);
1733
1734 return perm;
1735 }
1736
1737 private Permission parsePermissionTree(Package owner, Resources res,
1738 XmlPullParser parser, AttributeSet attrs, String[] outError)
1739 throws XmlPullParserException, IOException {
1740 Permission perm = new Permission(owner);
1741
1742 TypedArray sa = res.obtainAttributes(attrs,
1743 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1744
1745 if (!parsePackageItemInfo(owner, perm.info, outError,
1746 "<permission-tree>", sa,
1747 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1748 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001749 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1750 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 sa.recycle();
1752 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1753 return null;
1754 }
1755
1756 sa.recycle();
1757
1758 int index = perm.info.name.indexOf('.');
1759 if (index > 0) {
1760 index = perm.info.name.indexOf('.', index+1);
1761 }
1762 if (index < 0) {
1763 outError[0] = "<permission-tree> name has less than three segments: "
1764 + perm.info.name;
1765 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1766 return null;
1767 }
1768
1769 perm.info.descriptionRes = 0;
1770 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1771 perm.tree = true;
1772
1773 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1774 outError)) {
1775 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1776 return null;
1777 }
1778
1779 owner.permissions.add(perm);
1780
1781 return perm;
1782 }
1783
1784 private Instrumentation parseInstrumentation(Package owner, Resources res,
1785 XmlPullParser parser, AttributeSet attrs, String[] outError)
1786 throws XmlPullParserException, IOException {
1787 TypedArray sa = res.obtainAttributes(attrs,
1788 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1789
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001790 if (mParseInstrumentationArgs == null) {
1791 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1792 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1793 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001794 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1795 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001796 mParseInstrumentationArgs.tag = "<instrumentation>";
1797 }
1798
1799 mParseInstrumentationArgs.sa = sa;
1800
1801 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1802 new InstrumentationInfo());
1803 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 sa.recycle();
1805 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1806 return null;
1807 }
1808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001810 // Note: don't allow this value to be a reference to a resource
1811 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 str = sa.getNonResourceString(
1813 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1814 a.info.targetPackage = str != null ? str.intern() : null;
1815
1816 a.info.handleProfiling = sa.getBoolean(
1817 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1818 false);
1819
1820 a.info.functionalTest = sa.getBoolean(
1821 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1822 false);
1823
1824 sa.recycle();
1825
1826 if (a.info.targetPackage == null) {
1827 outError[0] = "<instrumentation> does not specify targetPackage";
1828 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1829 return null;
1830 }
1831
1832 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1833 outError)) {
1834 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1835 return null;
1836 }
1837
1838 owner.instrumentation.add(a);
1839
1840 return a;
1841 }
1842
1843 private boolean parseApplication(Package owner, Resources res,
1844 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1845 throws XmlPullParserException, IOException {
1846 final ApplicationInfo ai = owner.applicationInfo;
1847 final String pkgName = owner.applicationInfo.packageName;
1848
1849 TypedArray sa = res.obtainAttributes(attrs,
1850 com.android.internal.R.styleable.AndroidManifestApplication);
1851
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001852 String name = sa.getNonConfigurationString(
1853 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 if (name != null) {
1855 ai.className = buildClassName(pkgName, name, outError);
1856 if (ai.className == null) {
1857 sa.recycle();
1858 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1859 return false;
1860 }
1861 }
1862
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001863 String manageSpaceActivity = sa.getNonConfigurationString(
1864 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 if (manageSpaceActivity != null) {
1866 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1867 outError);
1868 }
1869
Christopher Tate181fafa2009-05-14 11:12:14 -07001870 boolean allowBackup = sa.getBoolean(
1871 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1872 if (allowBackup) {
1873 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001874
Christopher Tate3de55bc2010-03-12 17:28:08 -08001875 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1876 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001877 String backupAgent = sa.getNonConfigurationString(
1878 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001879 if (backupAgent != null) {
1880 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001881 if (DEBUG_BACKUP) {
1882 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001883 + " from " + pkgName + "+" + backupAgent);
1884 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001885
1886 if (sa.getBoolean(
1887 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1888 true)) {
1889 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1890 }
1891 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001892 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1893 false)) {
1894 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1895 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001896 }
1897 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 TypedValue v = sa.peekValue(
1900 com.android.internal.R.styleable.AndroidManifestApplication_label);
1901 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1902 ai.nonLocalizedLabel = v.coerceToString();
1903 }
1904
1905 ai.icon = sa.getResourceId(
1906 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001907 ai.logo = sa.getResourceId(
1908 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001910 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 ai.descriptionRes = sa.getResourceId(
1912 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1913
1914 if ((flags&PARSE_IS_SYSTEM) != 0) {
1915 if (sa.getBoolean(
1916 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1917 false)) {
1918 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1919 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001920 }
1921
1922 if (sa.getBoolean(
1923 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1924 false)) {
1925 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001926 }
1927
1928 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1929 .AndroidManifestApplication_restrictedAccountType);
1930 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1931 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 }
1933
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001934 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1935 .AndroidManifestApplication_requiredAccountType);
1936 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1937 owner.mRequiredAccountType = requiredAccountType;
1938 }
1939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 if (sa.getBoolean(
1941 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1942 false)) {
1943 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1944 }
1945
1946 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001947 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001948 false)) {
1949 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1950 }
1951
Romain Guy529b60a2010-08-03 18:05:47 -07001952 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001953 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001954 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001955
1956 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1958 true)) {
1959 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1960 }
1961
1962 if (sa.getBoolean(
1963 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1964 false)) {
1965 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1966 }
1967
1968 if (sa.getBoolean(
1969 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1970 true)) {
1971 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1972 }
1973
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001974 if (sa.getBoolean(
1975 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001976 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001977 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1978 }
1979
Jason parksa3cdaa52011-01-13 14:15:43 -06001980 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001981 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001982 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001983 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001984 }
1985
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001986 if (sa.getBoolean(
1987 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1988 false /* default is no RTL support*/)) {
1989 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1990 }
1991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001993 str = sa.getNonConfigurationString(
1994 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1996
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001997 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1998 str = sa.getNonConfigurationString(
1999 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
2000 } else {
2001 // Some older apps have been seen to use a resource reference
2002 // here that on older builds was ignored (with a warning). We
2003 // need to continue to do this for them so they don't break.
2004 str = sa.getNonResourceString(
2005 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
2006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002007 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
2008 str, outError);
2009
2010 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002011 CharSequence pname;
2012 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2013 pname = sa.getNonConfigurationString(
2014 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
2015 } else {
2016 // Some older apps have been seen to use a resource reference
2017 // here that on older builds was ignored (with a warning). We
2018 // need to continue to do this for them so they don't break.
2019 pname = sa.getNonResourceString(
2020 com.android.internal.R.styleable.AndroidManifestApplication_process);
2021 }
2022 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 flags, mSeparateProcesses, outError);
2024
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002025 ai.enabled = sa.getBoolean(
2026 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002027
Dianne Hackborn02486b12010-08-26 14:18:37 -07002028 if (false) {
2029 if (sa.getBoolean(
2030 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2031 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002032 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002033
2034 // A heavy-weight application can not be in a custom process.
2035 // We can do direct compare because we intern all strings.
2036 if (ai.processName != null && ai.processName != ai.packageName) {
2037 outError[0] = "cantSaveState applications can not use custom processes";
2038 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002039 }
2040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 }
2042
Adam Powell269248d2011-08-02 10:26:54 -07002043 ai.uiOptions = sa.getInt(
2044 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 sa.recycle();
2047
2048 if (outError[0] != null) {
2049 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2050 return false;
2051 }
2052
2053 final int innerDepth = parser.getDepth();
2054
2055 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002056 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2057 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2058 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 continue;
2060 }
2061
2062 String tagName = parser.getName();
2063 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002064 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2065 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 if (a == null) {
2067 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2068 return false;
2069 }
2070
2071 owner.activities.add(a);
2072
2073 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002074 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 if (a == null) {
2076 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2077 return false;
2078 }
2079
2080 owner.receivers.add(a);
2081
2082 } else if (tagName.equals("service")) {
2083 Service s = parseService(owner, res, parser, attrs, flags, outError);
2084 if (s == null) {
2085 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2086 return false;
2087 }
2088
2089 owner.services.add(s);
2090
2091 } else if (tagName.equals("provider")) {
2092 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2093 if (p == null) {
2094 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2095 return false;
2096 }
2097
2098 owner.providers.add(p);
2099
2100 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002101 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 if (a == null) {
2103 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2104 return false;
2105 }
2106
2107 owner.activities.add(a);
2108
2109 } else if (parser.getName().equals("meta-data")) {
2110 // note: application meta-data is stored off to the side, so it can
2111 // remain null in the primary copy (we like to avoid extra copies because
2112 // it can be large)
2113 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2114 outError)) == null) {
2115 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2116 return false;
2117 }
2118
Dianne Hackbornc895be72013-03-11 17:48:43 -07002119 } else if (tagName.equals("library")) {
2120 sa = res.obtainAttributes(attrs,
2121 com.android.internal.R.styleable.AndroidManifestLibrary);
2122
2123 // Note: don't allow this value to be a reference to a resource
2124 // that may change.
2125 String lname = sa.getNonResourceString(
2126 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2127
2128 sa.recycle();
2129
2130 if (lname != null) {
2131 if (owner.libraryNames == null) {
2132 owner.libraryNames = new ArrayList<String>();
2133 }
2134 if (!owner.libraryNames.contains(lname)) {
2135 owner.libraryNames.add(lname.intern());
2136 }
2137 }
2138
2139 XmlUtils.skipCurrentTag(parser);
2140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 } else if (tagName.equals("uses-library")) {
2142 sa = res.obtainAttributes(attrs,
2143 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2144
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002145 // Note: don't allow this value to be a reference to a resource
2146 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 String lname = sa.getNonResourceString(
2148 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002149 boolean req = sa.getBoolean(
2150 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2151 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152
2153 sa.recycle();
2154
Dianne Hackborn49237342009-08-27 20:08:01 -07002155 if (lname != null) {
2156 if (req) {
2157 if (owner.usesLibraries == null) {
2158 owner.usesLibraries = new ArrayList<String>();
2159 }
2160 if (!owner.usesLibraries.contains(lname)) {
2161 owner.usesLibraries.add(lname.intern());
2162 }
2163 } else {
2164 if (owner.usesOptionalLibraries == null) {
2165 owner.usesOptionalLibraries = new ArrayList<String>();
2166 }
2167 if (!owner.usesOptionalLibraries.contains(lname)) {
2168 owner.usesOptionalLibraries.add(lname.intern());
2169 }
2170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 }
2172
2173 XmlUtils.skipCurrentTag(parser);
2174
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002175 } else if (tagName.equals("uses-package")) {
2176 // Dependencies for app installers; we don't currently try to
2177 // enforce this.
2178 XmlUtils.skipCurrentTag(parser);
2179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 } else {
2181 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002182 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002183 + " at " + mArchiveSourcePath + " "
2184 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 XmlUtils.skipCurrentTag(parser);
2186 continue;
2187 } else {
2188 outError[0] = "Bad element under <application>: " + tagName;
2189 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2190 return false;
2191 }
2192 }
2193 }
2194
2195 return true;
2196 }
2197
2198 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2199 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002200 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002201 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 if (name == null) {
2203 outError[0] = tag + " does not specify android:name";
2204 return false;
2205 }
2206
2207 outInfo.name
2208 = buildClassName(owner.applicationInfo.packageName, name, outError);
2209 if (outInfo.name == null) {
2210 return false;
2211 }
2212
2213 int iconVal = sa.getResourceId(iconRes, 0);
2214 if (iconVal != 0) {
2215 outInfo.icon = iconVal;
2216 outInfo.nonLocalizedLabel = null;
2217 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002218
2219 int logoVal = sa.getResourceId(logoRes, 0);
2220 if (logoVal != 0) {
2221 outInfo.logo = logoVal;
2222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223
2224 TypedValue v = sa.peekValue(labelRes);
2225 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2226 outInfo.nonLocalizedLabel = v.coerceToString();
2227 }
2228
2229 outInfo.packageName = owner.packageName;
2230
2231 return true;
2232 }
2233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 private Activity parseActivity(Package owner, Resources res,
2235 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002236 boolean receiver, boolean hardwareAccelerated)
2237 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 TypedArray sa = res.obtainAttributes(attrs,
2239 com.android.internal.R.styleable.AndroidManifestActivity);
2240
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002241 if (mParseActivityArgs == null) {
2242 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2243 com.android.internal.R.styleable.AndroidManifestActivity_name,
2244 com.android.internal.R.styleable.AndroidManifestActivity_label,
2245 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002246 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002247 mSeparateProcesses,
2248 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002249 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002250 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2251 }
2252
2253 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2254 mParseActivityArgs.sa = sa;
2255 mParseActivityArgs.flags = flags;
2256
2257 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2258 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 sa.recycle();
2260 return null;
2261 }
2262
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002263 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2265 if (setExported) {
2266 a.info.exported = sa.getBoolean(
2267 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2268 }
2269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 a.info.theme = sa.getResourceId(
2271 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2272
Adam Powell269248d2011-08-02 10:26:54 -07002273 a.info.uiOptions = sa.getInt(
2274 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2275 a.info.applicationInfo.uiOptions);
2276
Adam Powelldd8fab22012-03-22 17:47:27 -07002277 String parentName = sa.getNonConfigurationString(
2278 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2279 if (parentName != null) {
2280 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2281 if (outError[0] == null) {
2282 a.info.parentActivityName = parentClassName;
2283 } else {
2284 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2285 parentName);
2286 outError[0] = null;
2287 }
2288 }
2289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002291 str = sa.getNonConfigurationString(
2292 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 if (str == null) {
2294 a.info.permission = owner.applicationInfo.permission;
2295 } else {
2296 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2297 }
2298
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002299 str = sa.getNonConfigurationString(
2300 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2302 owner.applicationInfo.taskAffinity, str, outError);
2303
2304 a.info.flags = 0;
2305 if (sa.getBoolean(
2306 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2307 false)) {
2308 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2309 }
2310
2311 if (sa.getBoolean(
2312 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2313 false)) {
2314 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2315 }
2316
2317 if (sa.getBoolean(
2318 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2319 false)) {
2320 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2321 }
2322
2323 if (sa.getBoolean(
2324 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2325 false)) {
2326 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2327 }
2328
2329 if (sa.getBoolean(
2330 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2331 false)) {
2332 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2333 }
2334
2335 if (sa.getBoolean(
2336 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2337 false)) {
2338 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2339 }
2340
2341 if (sa.getBoolean(
2342 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2343 false)) {
2344 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2345 }
2346
2347 if (sa.getBoolean(
2348 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2349 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2350 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2351 }
2352
Dianne Hackbornffa42482009-09-23 22:20:11 -07002353 if (sa.getBoolean(
2354 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2355 false)) {
2356 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2357 }
2358
Daniel Sandler613dde42010-06-21 13:46:39 -04002359 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002360 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2361 false)) {
2362 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2363 }
2364
2365 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002366 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2367 false)) {
2368 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2369 }
Craig Mautner5962b122012-10-05 14:45:52 -07002370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002372 if (sa.getBoolean(
2373 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2374 hardwareAccelerated)) {
2375 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2376 }
2377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 a.info.launchMode = sa.getInt(
2379 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2380 ActivityInfo.LAUNCH_MULTIPLE);
2381 a.info.screenOrientation = sa.getInt(
2382 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2383 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2384 a.info.configChanges = sa.getInt(
2385 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2386 0);
2387 a.info.softInputMode = sa.getInt(
2388 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2389 0);
2390 } else {
2391 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2392 a.info.configChanges = 0;
2393 }
2394
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002395 if (receiver) {
2396 if (sa.getBoolean(
2397 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2398 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002399 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002400 if (a.info.exported) {
2401 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2402 + a.className + " at " + mArchiveSourcePath + " "
2403 + parser.getPositionDescription());
2404 a.info.exported = false;
2405 }
2406 setExported = true;
2407 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002408 if (sa.getBoolean(
2409 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2410 false)) {
2411 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2412 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002413 }
2414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 sa.recycle();
2416
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002417 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002418 // A heavy-weight application can not have receives in its main process
2419 // We can do direct compare because we intern all strings.
2420 if (a.info.processName == owner.packageName) {
2421 outError[0] = "Heavy-weight applications can not have receivers in main process";
2422 }
2423 }
2424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 if (outError[0] != null) {
2426 return null;
2427 }
2428
2429 int outerDepth = parser.getDepth();
2430 int type;
2431 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2432 && (type != XmlPullParser.END_TAG
2433 || parser.getDepth() > outerDepth)) {
2434 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2435 continue;
2436 }
2437
2438 if (parser.getName().equals("intent-filter")) {
2439 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002440 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 return null;
2442 }
2443 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002444 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002445 + mArchiveSourcePath + " "
2446 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 } else {
2448 a.intents.add(intent);
2449 }
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002450 } else if (!receiver && parser.getName().equals("preferred")) {
2451 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2452 if (!parseIntent(res, parser, attrs, false, intent, outError)) {
2453 return null;
2454 }
2455 if (intent.countActions() == 0) {
2456 Slog.w(TAG, "No actions in preferred at "
2457 + mArchiveSourcePath + " "
2458 + parser.getPositionDescription());
2459 } else {
2460 if (owner.preferredActivityFilters == null) {
2461 owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>();
2462 }
2463 owner.preferredActivityFilters.add(intent);
2464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 } else if (parser.getName().equals("meta-data")) {
2466 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2467 outError)) == null) {
2468 return null;
2469 }
2470 } else {
2471 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002472 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002474 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002475 + " at " + mArchiveSourcePath + " "
2476 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002478 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002479 + " at " + mArchiveSourcePath + " "
2480 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 }
2482 XmlUtils.skipCurrentTag(parser);
2483 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002485 if (receiver) {
2486 outError[0] = "Bad element under <receiver>: " + parser.getName();
2487 } else {
2488 outError[0] = "Bad element under <activity>: " + parser.getName();
2489 }
2490 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 }
2493 }
2494
2495 if (!setExported) {
2496 a.info.exported = a.intents.size() > 0;
2497 }
2498
2499 return a;
2500 }
2501
2502 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002503 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2504 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 TypedArray sa = res.obtainAttributes(attrs,
2506 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2507
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002508 String targetActivity = sa.getNonConfigurationString(
2509 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 if (targetActivity == null) {
2511 outError[0] = "<activity-alias> does not specify android:targetActivity";
2512 sa.recycle();
2513 return null;
2514 }
2515
2516 targetActivity = buildClassName(owner.applicationInfo.packageName,
2517 targetActivity, outError);
2518 if (targetActivity == null) {
2519 sa.recycle();
2520 return null;
2521 }
2522
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002523 if (mParseActivityAliasArgs == null) {
2524 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2525 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2526 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2527 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002528 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002529 mSeparateProcesses,
2530 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002531 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002532 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2533 mParseActivityAliasArgs.tag = "<activity-alias>";
2534 }
2535
2536 mParseActivityAliasArgs.sa = sa;
2537 mParseActivityAliasArgs.flags = flags;
2538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 Activity target = null;
2540
2541 final int NA = owner.activities.size();
2542 for (int i=0; i<NA; i++) {
2543 Activity t = owner.activities.get(i);
2544 if (targetActivity.equals(t.info.name)) {
2545 target = t;
2546 break;
2547 }
2548 }
2549
2550 if (target == null) {
2551 outError[0] = "<activity-alias> target activity " + targetActivity
2552 + " not found in manifest";
2553 sa.recycle();
2554 return null;
2555 }
2556
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002557 ActivityInfo info = new ActivityInfo();
2558 info.targetActivity = targetActivity;
2559 info.configChanges = target.info.configChanges;
2560 info.flags = target.info.flags;
2561 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002562 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002563 info.labelRes = target.info.labelRes;
2564 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2565 info.launchMode = target.info.launchMode;
2566 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002567 if (info.descriptionRes == 0) {
2568 info.descriptionRes = target.info.descriptionRes;
2569 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002570 info.screenOrientation = target.info.screenOrientation;
2571 info.taskAffinity = target.info.taskAffinity;
2572 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002573 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002574 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002575 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002576
2577 Activity a = new Activity(mParseActivityAliasArgs, info);
2578 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 sa.recycle();
2580 return null;
2581 }
2582
2583 final boolean setExported = sa.hasValue(
2584 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2585 if (setExported) {
2586 a.info.exported = sa.getBoolean(
2587 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2588 }
2589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002591 str = sa.getNonConfigurationString(
2592 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 if (str != null) {
2594 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2595 }
2596
Adam Powelldd8fab22012-03-22 17:47:27 -07002597 String parentName = sa.getNonConfigurationString(
2598 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2599 0);
2600 if (parentName != null) {
2601 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2602 if (outError[0] == null) {
2603 a.info.parentActivityName = parentClassName;
2604 } else {
2605 Log.e(TAG, "Activity alias " + a.info.name +
2606 " specified invalid parentActivityName " + parentName);
2607 outError[0] = null;
2608 }
2609 }
2610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 sa.recycle();
2612
2613 if (outError[0] != null) {
2614 return null;
2615 }
2616
2617 int outerDepth = parser.getDepth();
2618 int type;
2619 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2620 && (type != XmlPullParser.END_TAG
2621 || parser.getDepth() > outerDepth)) {
2622 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2623 continue;
2624 }
2625
2626 if (parser.getName().equals("intent-filter")) {
2627 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002628 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 return null;
2630 }
2631 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002632 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002633 + mArchiveSourcePath + " "
2634 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 } else {
2636 a.intents.add(intent);
2637 }
2638 } else if (parser.getName().equals("meta-data")) {
2639 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2640 outError)) == null) {
2641 return null;
2642 }
2643 } else {
2644 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002645 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002646 + " at " + mArchiveSourcePath + " "
2647 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 XmlUtils.skipCurrentTag(parser);
2649 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002650 } else {
2651 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2652 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 }
2655 }
2656
2657 if (!setExported) {
2658 a.info.exported = a.intents.size() > 0;
2659 }
2660
2661 return a;
2662 }
2663
2664 private Provider parseProvider(Package owner, Resources res,
2665 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2666 throws XmlPullParserException, IOException {
2667 TypedArray sa = res.obtainAttributes(attrs,
2668 com.android.internal.R.styleable.AndroidManifestProvider);
2669
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002670 if (mParseProviderArgs == null) {
2671 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2672 com.android.internal.R.styleable.AndroidManifestProvider_name,
2673 com.android.internal.R.styleable.AndroidManifestProvider_label,
2674 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002675 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002676 mSeparateProcesses,
2677 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002678 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002679 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2680 mParseProviderArgs.tag = "<provider>";
2681 }
2682
2683 mParseProviderArgs.sa = sa;
2684 mParseProviderArgs.flags = flags;
2685
2686 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2687 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 sa.recycle();
2689 return null;
2690 }
2691
Nick Kralevichf097b162012-07-28 12:43:48 -07002692 boolean providerExportedDefault = false;
2693
2694 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2695 // For compatibility, applications targeting API level 16 or lower
2696 // should have their content providers exported by default, unless they
2697 // specify otherwise.
2698 providerExportedDefault = true;
2699 }
2700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002702 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2703 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002705 String cpname = sa.getNonConfigurationString(
2706 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707
2708 p.info.isSyncable = sa.getBoolean(
2709 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2710 false);
2711
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002712 String permission = sa.getNonConfigurationString(
2713 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2714 String str = sa.getNonConfigurationString(
2715 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 if (str == null) {
2717 str = permission;
2718 }
2719 if (str == null) {
2720 p.info.readPermission = owner.applicationInfo.permission;
2721 } else {
2722 p.info.readPermission =
2723 str.length() > 0 ? str.toString().intern() : null;
2724 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002725 str = sa.getNonConfigurationString(
2726 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 if (str == null) {
2728 str = permission;
2729 }
2730 if (str == null) {
2731 p.info.writePermission = owner.applicationInfo.permission;
2732 } else {
2733 p.info.writePermission =
2734 str.length() > 0 ? str.toString().intern() : null;
2735 }
2736
2737 p.info.grantUriPermissions = sa.getBoolean(
2738 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2739 false);
2740
2741 p.info.multiprocess = sa.getBoolean(
2742 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2743 false);
2744
2745 p.info.initOrder = sa.getInt(
2746 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2747 0);
2748
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002749 p.info.flags = 0;
2750
2751 if (sa.getBoolean(
2752 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2753 false)) {
2754 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2755 if (p.info.exported) {
2756 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2757 + p.className + " at " + mArchiveSourcePath + " "
2758 + parser.getPositionDescription());
2759 p.info.exported = false;
2760 }
2761 }
2762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 sa.recycle();
2764
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002765 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002766 // A heavy-weight application can not have providers in its main process
2767 // We can do direct compare because we intern all strings.
2768 if (p.info.processName == owner.packageName) {
2769 outError[0] = "Heavy-weight applications can not have providers in main process";
2770 return null;
2771 }
2772 }
2773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002775 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 return null;
2777 }
2778 p.info.authority = cpname.intern();
2779
2780 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2781 return null;
2782 }
2783
2784 return p;
2785 }
2786
2787 private boolean parseProviderTags(Resources res,
2788 XmlPullParser parser, AttributeSet attrs,
2789 Provider outInfo, String[] outError)
2790 throws XmlPullParserException, IOException {
2791 int outerDepth = parser.getDepth();
2792 int type;
2793 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2794 && (type != XmlPullParser.END_TAG
2795 || parser.getDepth() > outerDepth)) {
2796 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2797 continue;
2798 }
2799
2800 if (parser.getName().equals("meta-data")) {
2801 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2802 outInfo.metaData, outError)) == null) {
2803 return false;
2804 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 } else if (parser.getName().equals("grant-uri-permission")) {
2807 TypedArray sa = res.obtainAttributes(attrs,
2808 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2809
2810 PatternMatcher pa = null;
2811
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002812 String str = sa.getNonConfigurationString(
2813 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 if (str != null) {
2815 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2816 }
2817
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002818 str = sa.getNonConfigurationString(
2819 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 if (str != null) {
2821 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2822 }
2823
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002824 str = sa.getNonConfigurationString(
2825 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 if (str != null) {
2827 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2828 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 sa.recycle();
2831
2832 if (pa != null) {
2833 if (outInfo.info.uriPermissionPatterns == null) {
2834 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2835 outInfo.info.uriPermissionPatterns[0] = pa;
2836 } else {
2837 final int N = outInfo.info.uriPermissionPatterns.length;
2838 PatternMatcher[] newp = new PatternMatcher[N+1];
2839 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2840 newp[N] = pa;
2841 outInfo.info.uriPermissionPatterns = newp;
2842 }
2843 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002844 } else {
2845 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002846 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002847 + parser.getName() + " at " + mArchiveSourcePath + " "
2848 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002849 XmlUtils.skipCurrentTag(parser);
2850 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002851 } else {
2852 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2853 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002854 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002855 }
2856 XmlUtils.skipCurrentTag(parser);
2857
2858 } else if (parser.getName().equals("path-permission")) {
2859 TypedArray sa = res.obtainAttributes(attrs,
2860 com.android.internal.R.styleable.AndroidManifestPathPermission);
2861
2862 PathPermission pa = null;
2863
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002864 String permission = sa.getNonConfigurationString(
2865 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2866 String readPermission = sa.getNonConfigurationString(
2867 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002868 if (readPermission == null) {
2869 readPermission = permission;
2870 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002871 String writePermission = sa.getNonConfigurationString(
2872 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002873 if (writePermission == null) {
2874 writePermission = permission;
2875 }
2876
2877 boolean havePerm = false;
2878 if (readPermission != null) {
2879 readPermission = readPermission.intern();
2880 havePerm = true;
2881 }
2882 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002883 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002884 havePerm = true;
2885 }
2886
2887 if (!havePerm) {
2888 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002889 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002890 + parser.getName() + " at " + mArchiveSourcePath + " "
2891 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002892 XmlUtils.skipCurrentTag(parser);
2893 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002894 } else {
2895 outError[0] = "No readPermission or writePermssion for <path-permission>";
2896 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002897 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002898 }
2899
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002900 String path = sa.getNonConfigurationString(
2901 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002902 if (path != null) {
2903 pa = new PathPermission(path,
2904 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2905 }
2906
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002907 path = sa.getNonConfigurationString(
2908 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002909 if (path != null) {
2910 pa = new PathPermission(path,
2911 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2912 }
2913
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002914 path = sa.getNonConfigurationString(
2915 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002916 if (path != null) {
2917 pa = new PathPermission(path,
2918 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2919 }
2920
2921 sa.recycle();
2922
2923 if (pa != null) {
2924 if (outInfo.info.pathPermissions == null) {
2925 outInfo.info.pathPermissions = new PathPermission[1];
2926 outInfo.info.pathPermissions[0] = pa;
2927 } else {
2928 final int N = outInfo.info.pathPermissions.length;
2929 PathPermission[] newp = new PathPermission[N+1];
2930 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2931 newp[N] = pa;
2932 outInfo.info.pathPermissions = newp;
2933 }
2934 } else {
2935 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002936 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002937 + parser.getName() + " at " + mArchiveSourcePath + " "
2938 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002939 XmlUtils.skipCurrentTag(parser);
2940 continue;
2941 }
2942 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2943 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 }
2945 XmlUtils.skipCurrentTag(parser);
2946
2947 } else {
2948 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002949 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002950 + parser.getName() + " at " + mArchiveSourcePath + " "
2951 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 XmlUtils.skipCurrentTag(parser);
2953 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002954 } else {
2955 outError[0] = "Bad element under <provider>: " + parser.getName();
2956 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 }
2959 }
2960 return true;
2961 }
2962
2963 private Service parseService(Package owner, Resources res,
2964 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2965 throws XmlPullParserException, IOException {
2966 TypedArray sa = res.obtainAttributes(attrs,
2967 com.android.internal.R.styleable.AndroidManifestService);
2968
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002969 if (mParseServiceArgs == null) {
2970 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2971 com.android.internal.R.styleable.AndroidManifestService_name,
2972 com.android.internal.R.styleable.AndroidManifestService_label,
2973 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002974 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002975 mSeparateProcesses,
2976 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002977 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002978 com.android.internal.R.styleable.AndroidManifestService_enabled);
2979 mParseServiceArgs.tag = "<service>";
2980 }
2981
2982 mParseServiceArgs.sa = sa;
2983 mParseServiceArgs.flags = flags;
2984
2985 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2986 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 sa.recycle();
2988 return null;
2989 }
2990
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002991 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 com.android.internal.R.styleable.AndroidManifestService_exported);
2993 if (setExported) {
2994 s.info.exported = sa.getBoolean(
2995 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2996 }
2997
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002998 String str = sa.getNonConfigurationString(
2999 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 if (str == null) {
3001 s.info.permission = owner.applicationInfo.permission;
3002 } else {
3003 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
3004 }
3005
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003006 s.info.flags = 0;
3007 if (sa.getBoolean(
3008 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
3009 false)) {
3010 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
3011 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08003012 if (sa.getBoolean(
3013 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
3014 false)) {
3015 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
3016 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003017 if (sa.getBoolean(
3018 com.android.internal.R.styleable.AndroidManifestService_singleUser,
3019 false)) {
3020 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
3021 if (s.info.exported) {
3022 Slog.w(TAG, "Service exported request ignored due to singleUser: "
3023 + s.className + " at " + mArchiveSourcePath + " "
3024 + parser.getPositionDescription());
3025 s.info.exported = false;
3026 }
3027 setExported = true;
3028 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 sa.recycle();
3031
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003032 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003033 // A heavy-weight application can not have services in its main process
3034 // We can do direct compare because we intern all strings.
3035 if (s.info.processName == owner.packageName) {
3036 outError[0] = "Heavy-weight applications can not have services in main process";
3037 return null;
3038 }
3039 }
3040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041 int outerDepth = parser.getDepth();
3042 int type;
3043 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3044 && (type != XmlPullParser.END_TAG
3045 || parser.getDepth() > outerDepth)) {
3046 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3047 continue;
3048 }
3049
3050 if (parser.getName().equals("intent-filter")) {
3051 ServiceIntentInfo intent = new ServiceIntentInfo(s);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003052 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 return null;
3054 }
3055
3056 s.intents.add(intent);
3057 } else if (parser.getName().equals("meta-data")) {
3058 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3059 outError)) == null) {
3060 return null;
3061 }
3062 } else {
3063 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003064 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003065 + parser.getName() + " at " + mArchiveSourcePath + " "
3066 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 XmlUtils.skipCurrentTag(parser);
3068 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003069 } else {
3070 outError[0] = "Bad element under <service>: " + parser.getName();
3071 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 }
3074 }
3075
3076 if (!setExported) {
3077 s.info.exported = s.intents.size() > 0;
3078 }
3079
3080 return s;
3081 }
3082
3083 private boolean parseAllMetaData(Resources res,
3084 XmlPullParser parser, AttributeSet attrs, String tag,
3085 Component outInfo, String[] outError)
3086 throws XmlPullParserException, IOException {
3087 int outerDepth = parser.getDepth();
3088 int type;
3089 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3090 && (type != XmlPullParser.END_TAG
3091 || parser.getDepth() > outerDepth)) {
3092 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3093 continue;
3094 }
3095
3096 if (parser.getName().equals("meta-data")) {
3097 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3098 outInfo.metaData, outError)) == null) {
3099 return false;
3100 }
3101 } else {
3102 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003103 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003104 + parser.getName() + " at " + mArchiveSourcePath + " "
3105 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 XmlUtils.skipCurrentTag(parser);
3107 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003108 } else {
3109 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3110 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 }
3113 }
3114 return true;
3115 }
3116
3117 private Bundle parseMetaData(Resources res,
3118 XmlPullParser parser, AttributeSet attrs,
3119 Bundle data, String[] outError)
3120 throws XmlPullParserException, IOException {
3121
3122 TypedArray sa = res.obtainAttributes(attrs,
3123 com.android.internal.R.styleable.AndroidManifestMetaData);
3124
3125 if (data == null) {
3126 data = new Bundle();
3127 }
3128
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003129 String name = sa.getNonConfigurationString(
3130 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 if (name == null) {
3132 outError[0] = "<meta-data> requires an android:name attribute";
3133 sa.recycle();
3134 return null;
3135 }
3136
Dianne Hackborn854060a2009-07-09 18:14:31 -07003137 name = name.intern();
3138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 TypedValue v = sa.peekValue(
3140 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3141 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003142 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 data.putInt(name, v.resourceId);
3144 } else {
3145 v = sa.peekValue(
3146 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003147 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 if (v != null) {
3149 if (v.type == TypedValue.TYPE_STRING) {
3150 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003151 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3153 data.putBoolean(name, v.data != 0);
3154 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3155 && v.type <= TypedValue.TYPE_LAST_INT) {
3156 data.putInt(name, v.data);
3157 } else if (v.type == TypedValue.TYPE_FLOAT) {
3158 data.putFloat(name, v.getFloat());
3159 } else {
3160 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003161 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003162 + parser.getName() + " at " + mArchiveSourcePath + " "
3163 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 } else {
3165 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3166 data = null;
3167 }
3168 }
3169 } else {
3170 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3171 data = null;
3172 }
3173 }
3174
3175 sa.recycle();
3176
3177 XmlUtils.skipCurrentTag(parser);
3178
3179 return data;
3180 }
3181
Kenny Root05ca4c92011-09-15 10:36:25 -07003182 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3183 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3184 IOException {
3185 final TypedArray sa = res.obtainAttributes(attrs,
3186 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3187
3188 final String packageName = sa.getNonResourceString(
3189 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3190
3191 final String encodedPublicKey = sa.getNonResourceString(
3192 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3193
3194 sa.recycle();
3195
3196 if (packageName == null || packageName.length() == 0) {
3197 Slog.i(TAG, "verifier package name was null; skipping");
3198 return null;
3199 } else if (encodedPublicKey == null) {
3200 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3201 }
3202
Geremy Condraf1bcca82013-01-07 22:35:24 -08003203 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3204 if (publicKey != null) {
3205 return new VerifierInfo(packageName, publicKey);
3206 }
3207
3208 return null;
3209 }
3210
3211 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003212 EncodedKeySpec keySpec;
3213 try {
3214 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3215 keySpec = new X509EncodedKeySpec(encoded);
3216 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003217 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003218 return null;
3219 }
3220
3221 /* First try the key as an RSA key. */
3222 try {
3223 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003224 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003225 } catch (NoSuchAlgorithmException e) {
3226 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3227 return null;
3228 } catch (InvalidKeySpecException e) {
3229 // Not a RSA public key.
3230 }
3231
3232 /* Now try it as a DSA key. */
3233 try {
3234 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003235 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003236 } catch (NoSuchAlgorithmException e) {
3237 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3238 return null;
3239 } catch (InvalidKeySpecException e) {
3240 // Not a DSA public key.
3241 }
3242
3243 return null;
3244 }
3245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 private static final String ANDROID_RESOURCES
3247 = "http://schemas.android.com/apk/res/android";
3248
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003249 private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs,
3250 boolean allowGlobs, IntentInfo outInfo, String[] outError)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 throws XmlPullParserException, IOException {
3252
3253 TypedArray sa = res.obtainAttributes(attrs,
3254 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3255
3256 int priority = sa.getInt(
3257 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 TypedValue v = sa.peekValue(
3261 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3262 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3263 outInfo.nonLocalizedLabel = v.coerceToString();
3264 }
3265
3266 outInfo.icon = sa.getResourceId(
3267 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003268
3269 outInfo.logo = sa.getResourceId(
3270 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271
3272 sa.recycle();
3273
3274 int outerDepth = parser.getDepth();
3275 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003276 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3277 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3278 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 continue;
3280 }
3281
3282 String nodeName = parser.getName();
3283 if (nodeName.equals("action")) {
3284 String value = attrs.getAttributeValue(
3285 ANDROID_RESOURCES, "name");
3286 if (value == null || value == "") {
3287 outError[0] = "No value supplied for <android:name>";
3288 return false;
3289 }
3290 XmlUtils.skipCurrentTag(parser);
3291
3292 outInfo.addAction(value);
3293 } else if (nodeName.equals("category")) {
3294 String value = attrs.getAttributeValue(
3295 ANDROID_RESOURCES, "name");
3296 if (value == null || value == "") {
3297 outError[0] = "No value supplied for <android:name>";
3298 return false;
3299 }
3300 XmlUtils.skipCurrentTag(parser);
3301
3302 outInfo.addCategory(value);
3303
3304 } else if (nodeName.equals("data")) {
3305 sa = res.obtainAttributes(attrs,
3306 com.android.internal.R.styleable.AndroidManifestData);
3307
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003308 String str = sa.getNonConfigurationString(
3309 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 if (str != null) {
3311 try {
3312 outInfo.addDataType(str);
3313 } catch (IntentFilter.MalformedMimeTypeException e) {
3314 outError[0] = e.toString();
3315 sa.recycle();
3316 return false;
3317 }
3318 }
3319
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003320 str = sa.getNonConfigurationString(
3321 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 if (str != null) {
3323 outInfo.addDataScheme(str);
3324 }
3325
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003326 str = sa.getNonConfigurationString(
3327 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3328 if (str != null) {
3329 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3330 }
3331
3332 str = sa.getNonConfigurationString(
3333 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3334 if (str != null) {
3335 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3336 }
3337
3338 str = sa.getNonConfigurationString(
3339 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3340 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003341 if (!allowGlobs) {
3342 outError[0] = "sspPattern not allowed here; ssp must be literal";
3343 return false;
3344 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003345 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3346 }
3347
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003348 String host = sa.getNonConfigurationString(
3349 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3350 String port = sa.getNonConfigurationString(
3351 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 if (host != null) {
3353 outInfo.addDataAuthority(host, port);
3354 }
3355
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003356 str = sa.getNonConfigurationString(
3357 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 if (str != null) {
3359 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3360 }
3361
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003362 str = sa.getNonConfigurationString(
3363 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 if (str != null) {
3365 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3366 }
3367
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003368 str = sa.getNonConfigurationString(
3369 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003371 if (!allowGlobs) {
3372 outError[0] = "pathPattern not allowed here; path must be literal";
3373 return false;
3374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3376 }
3377
3378 sa.recycle();
3379 XmlUtils.skipCurrentTag(parser);
3380 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003381 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003382 + parser.getName() + " at " + mArchiveSourcePath + " "
3383 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 XmlUtils.skipCurrentTag(parser);
3385 } else {
3386 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3387 return false;
3388 }
3389 }
3390
3391 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003392
3393 if (DEBUG_PARSER) {
3394 final StringBuilder cats = new StringBuilder("Intent d=");
3395 cats.append(outInfo.hasDefault);
3396 cats.append(", cat=");
3397
3398 final Iterator<String> it = outInfo.categoriesIterator();
3399 if (it != null) {
3400 while (it.hasNext()) {
3401 cats.append(' ');
3402 cats.append(it.next());
3403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003405 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 }
3407
3408 return true;
3409 }
3410
3411 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003412
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003413 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414
3415 // For now we only support one application per package.
3416 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3417
3418 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3419 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3420 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3421 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3422 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3423 public final ArrayList<Service> services = new ArrayList<Service>(0);
3424 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3425
3426 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003427 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428
Dianne Hackborn854060a2009-07-09 18:14:31 -07003429 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003430
3431 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003432 public ArrayList<String> usesLibraries = null;
3433 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 public String[] usesLibraryFiles = null;
3435
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003436 public ArrayList<ActivityIntentInfo> preferredActivityFilters = null;
3437
Dianne Hackbornc1552392010-03-03 16:19:01 -08003438 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003439 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003440 public ArrayList<String> mAdoptPermissions = null;
3441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 // We store the application meta-data independently to avoid multiple unwanted references
3443 public Bundle mAppMetaData = null;
3444
3445 // If this is a 3rd party app, this is the path of the zip file.
3446 public String mPath;
3447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 // The version code declared for this package.
3449 public int mVersionCode;
3450
3451 // The version name declared for this package.
3452 public String mVersionName;
3453
3454 // The shared user id that this package wants to use.
3455 public String mSharedUserId;
3456
3457 // The shared user label that this package wants to use.
3458 public int mSharedUserLabel;
3459
3460 // Signatures that were read from the package.
3461 public Signature mSignatures[];
3462
3463 // For use by package manager service for quick lookup of
3464 // preferred up order.
3465 public int mPreferredOrder = 0;
3466
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003467 // For use by the package manager to keep track of the path to the
3468 // file an app came from.
3469 public String mScanPath;
3470
3471 // For use by package manager to keep track of where it has done dexopt.
3472 public boolean mDidDexOpt;
3473
Amith Yamasani13593602012-03-22 16:16:17 -07003474 // // User set enabled state.
3475 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3476 //
3477 // // Whether the package has been stopped.
3478 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 // Additional data supplied by callers.
3481 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003482
3483 // Whether an operation is currently pending on this package
3484 public boolean mOperationPending;
3485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 /*
3487 * Applications hardware preferences
3488 */
3489 public final ArrayList<ConfigurationInfo> configPreferences =
3490 new ArrayList<ConfigurationInfo>();
3491
Dianne Hackborn49237342009-08-27 20:08:01 -07003492 /*
3493 * Applications requested features
3494 */
3495 public ArrayList<FeatureInfo> reqFeatures = null;
3496
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003497 public int installLocation;
3498
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003499 /* An app that's required for all users and cannot be uninstalled for a user */
3500 public boolean mRequiredForAllUsers;
3501
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003502 /* The restricted account authenticator type that is used by this application */
3503 public String mRestrictedAccountType;
3504
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003505 /* The required account type without which this application will not function */
3506 public String mRequiredAccountType;
3507
Kenny Rootbcc954d2011-08-08 16:19:08 -07003508 /**
3509 * Digest suitable for comparing whether this package's manifest is the
3510 * same as another.
3511 */
3512 public ManifestDigest manifestDigest;
3513
Geremy Condraf1bcca82013-01-07 22:35:24 -08003514 /**
3515 * Data used to feed the KeySetManager
3516 */
3517 public Set<PublicKey> mSigningKeys;
3518 public Map<String, Set<PublicKey>> mKeySetMapping;
3519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 public Package(String _name) {
3521 packageName = _name;
3522 applicationInfo.packageName = _name;
3523 applicationInfo.uid = -1;
3524 }
3525
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003526 public void setPackageName(String newName) {
3527 packageName = newName;
3528 applicationInfo.packageName = newName;
3529 for (int i=permissions.size()-1; i>=0; i--) {
3530 permissions.get(i).setPackageName(newName);
3531 }
3532 for (int i=permissionGroups.size()-1; i>=0; i--) {
3533 permissionGroups.get(i).setPackageName(newName);
3534 }
3535 for (int i=activities.size()-1; i>=0; i--) {
3536 activities.get(i).setPackageName(newName);
3537 }
3538 for (int i=receivers.size()-1; i>=0; i--) {
3539 receivers.get(i).setPackageName(newName);
3540 }
3541 for (int i=providers.size()-1; i>=0; i--) {
3542 providers.get(i).setPackageName(newName);
3543 }
3544 for (int i=services.size()-1; i>=0; i--) {
3545 services.get(i).setPackageName(newName);
3546 }
3547 for (int i=instrumentation.size()-1; i>=0; i--) {
3548 instrumentation.get(i).setPackageName(newName);
3549 }
3550 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003551
3552 public boolean hasComponentClassName(String name) {
3553 for (int i=activities.size()-1; i>=0; i--) {
3554 if (name.equals(activities.get(i).className)) {
3555 return true;
3556 }
3557 }
3558 for (int i=receivers.size()-1; i>=0; i--) {
3559 if (name.equals(receivers.get(i).className)) {
3560 return true;
3561 }
3562 }
3563 for (int i=providers.size()-1; i>=0; i--) {
3564 if (name.equals(providers.get(i).className)) {
3565 return true;
3566 }
3567 }
3568 for (int i=services.size()-1; i>=0; i--) {
3569 if (name.equals(services.get(i).className)) {
3570 return true;
3571 }
3572 }
3573 for (int i=instrumentation.size()-1; i>=0; i--) {
3574 if (name.equals(instrumentation.get(i).className)) {
3575 return true;
3576 }
3577 }
3578 return false;
3579 }
3580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 public String toString() {
3582 return "Package{"
3583 + Integer.toHexString(System.identityHashCode(this))
3584 + " " + packageName + "}";
3585 }
3586 }
3587
3588 public static class Component<II extends IntentInfo> {
3589 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003590 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003591 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 public Bundle metaData;
3593
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003594 ComponentName componentName;
3595 String componentShortName;
3596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 public Component(Package _owner) {
3598 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003599 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003600 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003601 }
3602
3603 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3604 owner = args.owner;
3605 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003606 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003607 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003608 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003609 args.outError[0] = args.tag + " does not specify android:name";
3610 return;
3611 }
3612
3613 outInfo.name
3614 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3615 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003616 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003617 args.outError[0] = args.tag + " does not have valid android:name";
3618 return;
3619 }
3620
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003621 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003622
3623 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3624 if (iconVal != 0) {
3625 outInfo.icon = iconVal;
3626 outInfo.nonLocalizedLabel = null;
3627 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003628
3629 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3630 if (logoVal != 0) {
3631 outInfo.logo = logoVal;
3632 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003633
3634 TypedValue v = args.sa.peekValue(args.labelRes);
3635 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3636 outInfo.nonLocalizedLabel = v.coerceToString();
3637 }
3638
3639 outInfo.packageName = owner.packageName;
3640 }
3641
3642 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3643 this(args, (PackageItemInfo)outInfo);
3644 if (args.outError[0] != null) {
3645 return;
3646 }
3647
3648 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003649 CharSequence pname;
3650 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3651 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3652 } else {
3653 // Some older apps have been seen to use a resource reference
3654 // here that on older builds was ignored (with a warning). We
3655 // need to continue to do this for them so they don't break.
3656 pname = args.sa.getNonResourceString(args.processRes);
3657 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003658 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003659 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003660 args.flags, args.sepProcesses, args.outError);
3661 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003662
3663 if (args.descriptionRes != 0) {
3664 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3665 }
3666
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003667 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
3669
3670 public Component(Component<II> clone) {
3671 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003672 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003673 className = clone.className;
3674 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003675 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003676 }
3677
3678 public ComponentName getComponentName() {
3679 if (componentName != null) {
3680 return componentName;
3681 }
3682 if (className != null) {
3683 componentName = new ComponentName(owner.applicationInfo.packageName,
3684 className);
3685 }
3686 return componentName;
3687 }
3688
3689 public String getComponentShortName() {
3690 if (componentShortName != null) {
3691 return componentShortName;
3692 }
3693 ComponentName component = getComponentName();
3694 if (component != null) {
3695 componentShortName = component.flattenToShortString();
3696 }
3697 return componentShortName;
3698 }
3699
3700 public void setPackageName(String packageName) {
3701 componentName = null;
3702 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 }
3704 }
3705
3706 public final static class Permission extends Component<IntentInfo> {
3707 public final PermissionInfo info;
3708 public boolean tree;
3709 public PermissionGroup group;
3710
3711 public Permission(Package _owner) {
3712 super(_owner);
3713 info = new PermissionInfo();
3714 }
3715
3716 public Permission(Package _owner, PermissionInfo _info) {
3717 super(_owner);
3718 info = _info;
3719 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003720
3721 public void setPackageName(String packageName) {
3722 super.setPackageName(packageName);
3723 info.packageName = packageName;
3724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725
3726 public String toString() {
3727 return "Permission{"
3728 + Integer.toHexString(System.identityHashCode(this))
3729 + " " + info.name + "}";
3730 }
3731 }
3732
3733 public final static class PermissionGroup extends Component<IntentInfo> {
3734 public final PermissionGroupInfo info;
3735
3736 public PermissionGroup(Package _owner) {
3737 super(_owner);
3738 info = new PermissionGroupInfo();
3739 }
3740
3741 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3742 super(_owner);
3743 info = _info;
3744 }
3745
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003746 public void setPackageName(String packageName) {
3747 super.setPackageName(packageName);
3748 info.packageName = packageName;
3749 }
3750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 public String toString() {
3752 return "PermissionGroup{"
3753 + Integer.toHexString(System.identityHashCode(this))
3754 + " " + info.name + "}";
3755 }
3756 }
3757
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003758 private static boolean copyNeeded(int flags, Package p,
3759 PackageUserState state, Bundle metaData, int userId) {
3760 if (userId != 0) {
3761 // We always need to copy for other users, since we need
3762 // to fix up the uid.
3763 return true;
3764 }
3765 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3766 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003767 if (p.applicationInfo.enabled != enabled) {
3768 return true;
3769 }
3770 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003771 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003772 return true;
3773 }
3774 if (state.stopped) {
3775 return true;
3776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 if ((flags & PackageManager.GET_META_DATA) != 0
3778 && (metaData != null || p.mAppMetaData != null)) {
3779 return true;
3780 }
3781 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3782 && p.usesLibraryFiles != null) {
3783 return true;
3784 }
3785 return false;
3786 }
3787
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003788 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3789 PackageUserState state) {
3790 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003791 }
3792
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003793 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3794 PackageUserState state) {
3795 // CompatibilityMode is global state.
3796 if (!sCompatibilityModeEnabled) {
3797 ai.disableCompatibilityMode();
3798 }
3799 if (state.installed) {
3800 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3801 } else {
3802 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3803 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003804 if (state.blocked) {
3805 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3806 } else {
3807 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3808 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003809 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3810 ai.enabled = true;
3811 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3812 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3813 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3814 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3815 ai.enabled = false;
3816 }
3817 ai.enabledSetting = state.enabled;
3818 }
3819
Amith Yamasani13593602012-03-22 16:16:17 -07003820 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003821 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003823 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003824 return null;
3825 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003826 if (!copyNeeded(flags, p, state, null, userId)
3827 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3828 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3829 // In this case it is safe to directly modify the internal ApplicationInfo state:
3830 // - CompatibilityMode is global state, so will be the same for every call.
3831 // - We only come in to here if the app should reported as installed; this is the
3832 // default state, and we will do a copy otherwise.
3833 // - The enable state will always be reported the same for the application across
3834 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3835 // be doing a copy.
3836 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 return p.applicationInfo;
3838 }
3839
3840 // Make shallow copy so we can store the metadata/libraries safely
3841 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003842 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003843 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003844 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 if ((flags & PackageManager.GET_META_DATA) != 0) {
3847 ai.metaData = p.mAppMetaData;
3848 }
3849 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3850 ai.sharedLibraryFiles = p.usesLibraryFiles;
3851 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003852 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003853 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003854 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003855 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003856 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003857 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 return ai;
3859 }
3860
3861 public static final PermissionInfo generatePermissionInfo(
3862 Permission p, int flags) {
3863 if (p == null) return null;
3864 if ((flags&PackageManager.GET_META_DATA) == 0) {
3865 return p.info;
3866 }
3867 PermissionInfo pi = new PermissionInfo(p.info);
3868 pi.metaData = p.metaData;
3869 return pi;
3870 }
3871
3872 public static final PermissionGroupInfo generatePermissionGroupInfo(
3873 PermissionGroup pg, int flags) {
3874 if (pg == null) return null;
3875 if ((flags&PackageManager.GET_META_DATA) == 0) {
3876 return pg.info;
3877 }
3878 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3879 pgi.metaData = pg.metaData;
3880 return pgi;
3881 }
3882
3883 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003884 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003886 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3887 super(args, _info);
3888 info = _info;
3889 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003891
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003892 public void setPackageName(String packageName) {
3893 super.setPackageName(packageName);
3894 info.packageName = packageName;
3895 }
3896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003897 public String toString() {
3898 return "Activity{"
3899 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003900 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 }
3902 }
3903
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003904 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3905 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003907 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003908 return null;
3909 }
3910 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 return a.info;
3912 }
3913 // Make shallow copies so we can store the metadata safely
3914 ActivityInfo ai = new ActivityInfo(a.info);
3915 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003916 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 return ai;
3918 }
3919
3920 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003921 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003923 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3924 super(args, _info);
3925 info = _info;
3926 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003928
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003929 public void setPackageName(String packageName) {
3930 super.setPackageName(packageName);
3931 info.packageName = packageName;
3932 }
3933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 public String toString() {
3935 return "Service{"
3936 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003937 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 }
3939 }
3940
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003941 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3942 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003944 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003945 return null;
3946 }
3947 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 return s.info;
3949 }
3950 // Make shallow copies so we can store the metadata safely
3951 ServiceInfo si = new ServiceInfo(s.info);
3952 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003953 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 return si;
3955 }
3956
3957 public final static class Provider extends Component {
3958 public final ProviderInfo info;
3959 public boolean syncable;
3960
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003961 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3962 super(args, _info);
3963 info = _info;
3964 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 syncable = false;
3966 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 public Provider(Provider existingProvider) {
3969 super(existingProvider);
3970 this.info = existingProvider.info;
3971 this.syncable = existingProvider.syncable;
3972 }
3973
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003974 public void setPackageName(String packageName) {
3975 super.setPackageName(packageName);
3976 info.packageName = packageName;
3977 }
3978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 public String toString() {
3980 return "Provider{"
3981 + Integer.toHexString(System.identityHashCode(this))
3982 + " " + info.name + "}";
3983 }
3984 }
3985
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003986 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3987 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003989 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003990 return null;
3991 }
3992 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003994 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 return p.info;
3996 }
3997 // Make shallow copies so we can store the metadata safely
3998 ProviderInfo pi = new ProviderInfo(p.info);
3999 pi.metaData = p.metaData;
4000 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
4001 pi.uriPermissionPatterns = null;
4002 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004003 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 return pi;
4005 }
4006
4007 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004008 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004010 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
4011 super(args, _info);
4012 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004014
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004015 public void setPackageName(String packageName) {
4016 super.setPackageName(packageName);
4017 info.packageName = packageName;
4018 }
4019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 public String toString() {
4021 return "Instrumentation{"
4022 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004023 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 }
4025 }
4026
4027 public static final InstrumentationInfo generateInstrumentationInfo(
4028 Instrumentation i, int flags) {
4029 if (i == null) return null;
4030 if ((flags&PackageManager.GET_META_DATA) == 0) {
4031 return i.info;
4032 }
4033 InstrumentationInfo ii = new InstrumentationInfo(i.info);
4034 ii.metaData = i.metaData;
4035 return ii;
4036 }
4037
4038 public static class IntentInfo extends IntentFilter {
4039 public boolean hasDefault;
4040 public int labelRes;
4041 public CharSequence nonLocalizedLabel;
4042 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004043 public int logo;
Dianne Hackbornb09491f2013-07-22 15:30:11 -07004044 public int preferred;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 }
4046
4047 public final static class ActivityIntentInfo extends IntentInfo {
4048 public final Activity activity;
4049
4050 public ActivityIntentInfo(Activity _activity) {
4051 activity = _activity;
4052 }
4053
4054 public String toString() {
4055 return "ActivityIntentInfo{"
4056 + Integer.toHexString(System.identityHashCode(this))
4057 + " " + activity.info.name + "}";
4058 }
4059 }
4060
4061 public final static class ServiceIntentInfo extends IntentInfo {
4062 public final Service service;
4063
4064 public ServiceIntentInfo(Service _service) {
4065 service = _service;
4066 }
4067
4068 public String toString() {
4069 return "ServiceIntentInfo{"
4070 + Integer.toHexString(System.identityHashCode(this))
4071 + " " + service.info.name + "}";
4072 }
4073 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004074
4075 /**
4076 * @hide
4077 */
4078 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4079 sCompatibilityModeEnabled = compatibilityModeEnabled;
4080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081}