blob: 6760f49174967d043dd01f897360bfb7ef6a8a1b [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;
Michael Wrighteaeb1902013-09-05 18:15:57 -07001314 } else if (tagName.equals("supports-input")) {
1315 XmlUtils.skipCurrentTag(parser);
1316 continue;
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001317
Dianne Hackborn854060a2009-07-09 18:14:31 -07001318 } else if (tagName.equals("eat-comment")) {
1319 // Just skip this tag
1320 XmlUtils.skipCurrentTag(parser);
1321 continue;
1322
1323 } else if (RIGID_PARSER) {
1324 outError[0] = "Bad element under <manifest>: "
1325 + parser.getName();
1326 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1327 return null;
1328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001330 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001331 + " at " + mArchiveSourcePath + " "
1332 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 XmlUtils.skipCurrentTag(parser);
1334 continue;
1335 }
1336 }
1337
1338 if (!foundApp && pkg.instrumentation.size() == 0) {
1339 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1340 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1341 }
1342
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001343 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001344 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001345 for (int ip=0; ip<NP; ip++) {
1346 final PackageParser.NewPermissionInfo npi
1347 = PackageParser.NEW_PERMISSIONS[ip];
1348 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1349 break;
1350 }
1351 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001352 if (implicitPerms == null) {
1353 implicitPerms = new StringBuilder(128);
1354 implicitPerms.append(pkg.packageName);
1355 implicitPerms.append(": compat added ");
1356 } else {
1357 implicitPerms.append(' ');
1358 }
1359 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001360 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001361 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001362 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001363 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001364 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001365 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001366 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001367
1368 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1369 for (int is=0; is<NS; is++) {
1370 final PackageParser.SplitPermissionInfo spi
1371 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001372 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1373 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001374 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001375 }
1376 for (int in=0; in<spi.newPerms.length; in++) {
1377 final String perm = spi.newPerms[in];
1378 if (!pkg.requestedPermissions.contains(perm)) {
1379 pkg.requestedPermissions.add(perm);
1380 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1381 }
1382 }
1383 }
1384
Dianne Hackborn723738c2009-06-25 19:48:04 -07001385 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1386 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001387 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001388 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1389 }
1390 if (supportsNormalScreens != 0) {
1391 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1392 }
1393 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1394 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001395 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001396 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1397 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001398 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1399 && pkg.applicationInfo.targetSdkVersion
1400 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1401 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1402 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001403 if (resizeable < 0 || (resizeable > 0
1404 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001405 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001406 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1407 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001408 if (anyDensity < 0 || (anyDensity > 0
1409 && pkg.applicationInfo.targetSdkVersion
1410 >= android.os.Build.VERSION_CODES.DONUT)) {
1411 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001412 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001413
Nick Kralevich38f130e2013-04-04 13:19:10 -07001414 /*
1415 * b/8528162: Ignore the <uses-permission android:required> attribute if
1416 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1417 * which are improperly using this attribute, even though it never worked.
1418 */
1419 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1420 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1421 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1422 }
1423 }
1424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 return pkg;
1426 }
1427
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001428 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1429 AttributeSet attrs, String[] outError)
1430 throws XmlPullParserException, IOException {
1431 TypedArray sa = res.obtainAttributes(attrs,
1432 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1433
1434 // Note: don't allow this value to be a reference to a resource
1435 // that may change.
1436 String name = sa.getNonResourceString(
1437 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001438/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001439 boolean required = sa.getBoolean(
1440 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001441*/
1442 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001443
1444 sa.recycle();
1445
1446 if (name != null) {
1447 int index = pkg.requestedPermissions.indexOf(name);
1448 if (index == -1) {
1449 pkg.requestedPermissions.add(name.intern());
1450 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1451 } else {
1452 if (pkg.requestedPermissionsRequired.get(index) != required) {
1453 outError[0] = "conflicting <uses-permission> entries";
1454 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1455 return false;
1456 }
1457 }
1458 }
1459
1460 XmlUtils.skipCurrentTag(parser);
1461 return true;
1462 }
1463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 private static String buildClassName(String pkg, CharSequence clsSeq,
1465 String[] outError) {
1466 if (clsSeq == null || clsSeq.length() <= 0) {
1467 outError[0] = "Empty class name in package " + pkg;
1468 return null;
1469 }
1470 String cls = clsSeq.toString();
1471 char c = cls.charAt(0);
1472 if (c == '.') {
1473 return (pkg + cls).intern();
1474 }
1475 if (cls.indexOf('.') < 0) {
1476 StringBuilder b = new StringBuilder(pkg);
1477 b.append('.');
1478 b.append(cls);
1479 return b.toString().intern();
1480 }
1481 if (c >= 'a' && c <= 'z') {
1482 return cls.intern();
1483 }
1484 outError[0] = "Bad class name " + cls + " in package " + pkg;
1485 return null;
1486 }
1487
1488 private static String buildCompoundName(String pkg,
1489 CharSequence procSeq, String type, String[] outError) {
1490 String proc = procSeq.toString();
1491 char c = proc.charAt(0);
1492 if (pkg != null && c == ':') {
1493 if (proc.length() < 2) {
1494 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1495 + ": must be at least two characters";
1496 return null;
1497 }
1498 String subName = proc.substring(1);
1499 String nameError = validateName(subName, false);
1500 if (nameError != null) {
1501 outError[0] = "Invalid " + type + " name " + proc + " in package "
1502 + pkg + ": " + nameError;
1503 return null;
1504 }
1505 return (pkg + proc).intern();
1506 }
1507 String nameError = validateName(proc, true);
1508 if (nameError != null && !"system".equals(proc)) {
1509 outError[0] = "Invalid " + type + " name " + proc + " in package "
1510 + pkg + ": " + nameError;
1511 return null;
1512 }
1513 return proc.intern();
1514 }
1515
1516 private static String buildProcessName(String pkg, String defProc,
1517 CharSequence procSeq, int flags, String[] separateProcesses,
1518 String[] outError) {
1519 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1520 return defProc != null ? defProc : pkg;
1521 }
1522 if (separateProcesses != null) {
1523 for (int i=separateProcesses.length-1; i>=0; i--) {
1524 String sp = separateProcesses[i];
1525 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1526 return pkg;
1527 }
1528 }
1529 }
1530 if (procSeq == null || procSeq.length() <= 0) {
1531 return defProc;
1532 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001533 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 }
1535
1536 private static String buildTaskAffinityName(String pkg, String defProc,
1537 CharSequence procSeq, String[] outError) {
1538 if (procSeq == null) {
1539 return defProc;
1540 }
1541 if (procSeq.length() <= 0) {
1542 return null;
1543 }
1544 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1545 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001546
1547 private boolean parseKeys(Package owner, Resources res,
1548 XmlPullParser parser, AttributeSet attrs, String[] outError)
1549 throws XmlPullParserException, IOException {
1550 // we've encountered the 'keys' tag
1551 // all the keys and keysets that we want must be defined here
1552 // so we're going to iterate over the parser and pull out the things we want
1553 int outerDepth = parser.getDepth();
1554
1555 int type;
1556 PublicKey currentKey = null;
Kenny Root37dca152013-07-10 14:01:49 -07001557 int currentKeyDepth = -1;
Geremy Condraf1bcca82013-01-07 22:35:24 -08001558 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1559 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1560 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1561 if (type == XmlPullParser.END_TAG) {
Kenny Root37dca152013-07-10 14:01:49 -07001562 if (parser.getDepth() == currentKeyDepth) {
1563 currentKey = null;
1564 currentKeyDepth = -1;
1565 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001566 continue;
1567 }
1568 String tagname = parser.getName();
1569 if (tagname.equals("publicKey")) {
1570 final TypedArray sa = res.obtainAttributes(attrs,
1571 com.android.internal.R.styleable.PublicKey);
1572 final String encodedKey = sa.getNonResourceString(
1573 com.android.internal.R.styleable.PublicKey_value);
1574 currentKey = parsePublicKey(encodedKey);
Kenny Root37dca152013-07-10 14:01:49 -07001575 if (currentKey == null) {
1576 Slog.w(TAG, "No valid key in 'publicKey' tag at "
1577 + parser.getPositionDescription());
1578 sa.recycle();
1579 continue;
1580 }
1581 currentKeyDepth = parser.getDepth();
Geremy Condraf1bcca82013-01-07 22:35:24 -08001582 definedKeySets.put(currentKey, new HashSet<String>());
1583 sa.recycle();
Kenny Root2758e292013-07-08 09:32:59 -07001584 } else if (tagname.equals("keyset")) {
Kenny Root37dca152013-07-10 14:01:49 -07001585 if (currentKey == null) {
1586 Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
1587 + parser.getPositionDescription());
1588 continue;
1589 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001590 final TypedArray sa = res.obtainAttributes(attrs,
1591 com.android.internal.R.styleable.KeySet);
1592 final String name = sa.getNonResourceString(
1593 com.android.internal.R.styleable.KeySet_name);
1594 definedKeySets.get(currentKey).add(name);
1595 sa.recycle();
1596 } else if (RIGID_PARSER) {
1597 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1598 + " at " + mArchiveSourcePath + " "
1599 + parser.getPositionDescription());
1600 return false;
1601 } else {
1602 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1603 + " at " + mArchiveSourcePath + " "
1604 + parser.getPositionDescription());
1605 XmlUtils.skipCurrentTag(parser);
1606 continue;
1607 }
1608 }
1609
1610 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1611 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1612 PublicKey key = e.getKey();
1613 Set<String> keySetNames = e.getValue();
1614 for (String alias : keySetNames) {
1615 if (owner.mKeySetMapping.containsKey(alias)) {
1616 owner.mKeySetMapping.get(alias).add(key);
1617 } else {
1618 Set<PublicKey> keys = new HashSet<PublicKey>();
1619 keys.add(key);
1620 owner.mKeySetMapping.put(alias, keys);
1621 }
1622 }
1623 }
1624
1625 return true;
1626 }
1627
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001628 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 XmlPullParser parser, AttributeSet attrs, String[] outError)
1630 throws XmlPullParserException, IOException {
1631 PermissionGroup perm = new PermissionGroup(owner);
1632
1633 TypedArray sa = res.obtainAttributes(attrs,
1634 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1635
1636 if (!parsePackageItemInfo(owner, perm.info, outError,
1637 "<permission-group>", sa,
1638 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1639 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001640 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1641 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 sa.recycle();
1643 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1644 return null;
1645 }
1646
1647 perm.info.descriptionRes = sa.getResourceId(
1648 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1649 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001650 perm.info.flags = sa.getInt(
1651 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001652 perm.info.priority = sa.getInt(
1653 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001654 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001655 perm.info.priority = 0;
1656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657
1658 sa.recycle();
1659
1660 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1661 outError)) {
1662 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1663 return null;
1664 }
1665
1666 owner.permissionGroups.add(perm);
1667
1668 return perm;
1669 }
1670
1671 private Permission parsePermission(Package owner, Resources res,
1672 XmlPullParser parser, AttributeSet attrs, String[] outError)
1673 throws XmlPullParserException, IOException {
1674 Permission perm = new Permission(owner);
1675
1676 TypedArray sa = res.obtainAttributes(attrs,
1677 com.android.internal.R.styleable.AndroidManifestPermission);
1678
1679 if (!parsePackageItemInfo(owner, perm.info, outError,
1680 "<permission>", sa,
1681 com.android.internal.R.styleable.AndroidManifestPermission_name,
1682 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001683 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1684 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 sa.recycle();
1686 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1687 return null;
1688 }
1689
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001690 // Note: don't allow this value to be a reference to a resource
1691 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 perm.info.group = sa.getNonResourceString(
1693 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1694 if (perm.info.group != null) {
1695 perm.info.group = perm.info.group.intern();
1696 }
1697
1698 perm.info.descriptionRes = sa.getResourceId(
1699 com.android.internal.R.styleable.AndroidManifestPermission_description,
1700 0);
1701
1702 perm.info.protectionLevel = sa.getInt(
1703 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1704 PermissionInfo.PROTECTION_NORMAL);
1705
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001706 perm.info.flags = sa.getInt(
1707 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 if (perm.info.protectionLevel == -1) {
1712 outError[0] = "<permission> does not specify protectionLevel";
1713 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1714 return null;
1715 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001716
1717 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1718
1719 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1720 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1721 PermissionInfo.PROTECTION_SIGNATURE) {
1722 outError[0] = "<permission> protectionLevel specifies a flag but is "
1723 + "not based on signature type";
1724 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1725 return null;
1726 }
1727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728
1729 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1730 outError)) {
1731 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1732 return null;
1733 }
1734
1735 owner.permissions.add(perm);
1736
1737 return perm;
1738 }
1739
1740 private Permission parsePermissionTree(Package owner, Resources res,
1741 XmlPullParser parser, AttributeSet attrs, String[] outError)
1742 throws XmlPullParserException, IOException {
1743 Permission perm = new Permission(owner);
1744
1745 TypedArray sa = res.obtainAttributes(attrs,
1746 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1747
1748 if (!parsePackageItemInfo(owner, perm.info, outError,
1749 "<permission-tree>", sa,
1750 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1751 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001752 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1753 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 sa.recycle();
1755 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1756 return null;
1757 }
1758
1759 sa.recycle();
1760
1761 int index = perm.info.name.indexOf('.');
1762 if (index > 0) {
1763 index = perm.info.name.indexOf('.', index+1);
1764 }
1765 if (index < 0) {
1766 outError[0] = "<permission-tree> name has less than three segments: "
1767 + perm.info.name;
1768 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1769 return null;
1770 }
1771
1772 perm.info.descriptionRes = 0;
1773 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1774 perm.tree = true;
1775
1776 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1777 outError)) {
1778 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1779 return null;
1780 }
1781
1782 owner.permissions.add(perm);
1783
1784 return perm;
1785 }
1786
1787 private Instrumentation parseInstrumentation(Package owner, Resources res,
1788 XmlPullParser parser, AttributeSet attrs, String[] outError)
1789 throws XmlPullParserException, IOException {
1790 TypedArray sa = res.obtainAttributes(attrs,
1791 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1792
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001793 if (mParseInstrumentationArgs == null) {
1794 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1795 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1796 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001797 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1798 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001799 mParseInstrumentationArgs.tag = "<instrumentation>";
1800 }
1801
1802 mParseInstrumentationArgs.sa = sa;
1803
1804 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1805 new InstrumentationInfo());
1806 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 sa.recycle();
1808 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1809 return null;
1810 }
1811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001813 // Note: don't allow this value to be a reference to a resource
1814 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 str = sa.getNonResourceString(
1816 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1817 a.info.targetPackage = str != null ? str.intern() : null;
1818
1819 a.info.handleProfiling = sa.getBoolean(
1820 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1821 false);
1822
1823 a.info.functionalTest = sa.getBoolean(
1824 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1825 false);
1826
1827 sa.recycle();
1828
1829 if (a.info.targetPackage == null) {
1830 outError[0] = "<instrumentation> does not specify targetPackage";
1831 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1832 return null;
1833 }
1834
1835 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1836 outError)) {
1837 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1838 return null;
1839 }
1840
1841 owner.instrumentation.add(a);
1842
1843 return a;
1844 }
1845
1846 private boolean parseApplication(Package owner, Resources res,
1847 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1848 throws XmlPullParserException, IOException {
1849 final ApplicationInfo ai = owner.applicationInfo;
1850 final String pkgName = owner.applicationInfo.packageName;
1851
1852 TypedArray sa = res.obtainAttributes(attrs,
1853 com.android.internal.R.styleable.AndroidManifestApplication);
1854
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001855 String name = sa.getNonConfigurationString(
1856 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 if (name != null) {
1858 ai.className = buildClassName(pkgName, name, outError);
1859 if (ai.className == null) {
1860 sa.recycle();
1861 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1862 return false;
1863 }
1864 }
1865
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001866 String manageSpaceActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001867 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
1868 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 if (manageSpaceActivity != null) {
1870 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1871 outError);
1872 }
1873
Christopher Tate181fafa2009-05-14 11:12:14 -07001874 boolean allowBackup = sa.getBoolean(
1875 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1876 if (allowBackup) {
1877 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001878
Christopher Tate3de55bc2010-03-12 17:28:08 -08001879 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1880 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001881 String backupAgent = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001882 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
1883 Configuration.NATIVE_CONFIG_VERSION);
Christopher Tate181fafa2009-05-14 11:12:14 -07001884 if (backupAgent != null) {
1885 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001886 if (DEBUG_BACKUP) {
1887 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001888 + " from " + pkgName + "+" + backupAgent);
1889 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001890
1891 if (sa.getBoolean(
1892 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1893 true)) {
1894 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1895 }
1896 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001897 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1898 false)) {
1899 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1900 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001901 }
1902 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 TypedValue v = sa.peekValue(
1905 com.android.internal.R.styleable.AndroidManifestApplication_label);
1906 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1907 ai.nonLocalizedLabel = v.coerceToString();
1908 }
1909
1910 ai.icon = sa.getResourceId(
1911 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001912 ai.logo = sa.getResourceId(
1913 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001914 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001915 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 ai.descriptionRes = sa.getResourceId(
1917 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1918
1919 if ((flags&PARSE_IS_SYSTEM) != 0) {
1920 if (sa.getBoolean(
1921 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1922 false)) {
1923 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1924 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001925 }
1926
1927 if (sa.getBoolean(
1928 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1929 false)) {
1930 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001931 }
1932
1933 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1934 .AndroidManifestApplication_restrictedAccountType);
1935 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1936 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
1938
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001939 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1940 .AndroidManifestApplication_requiredAccountType);
1941 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1942 owner.mRequiredAccountType = requiredAccountType;
1943 }
1944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 if (sa.getBoolean(
1946 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1947 false)) {
1948 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1949 }
1950
1951 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001952 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001953 false)) {
1954 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1955 }
1956
Romain Guy529b60a2010-08-03 18:05:47 -07001957 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001958 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001959 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001960
1961 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1963 true)) {
1964 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1965 }
1966
1967 if (sa.getBoolean(
1968 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1969 false)) {
1970 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1971 }
1972
1973 if (sa.getBoolean(
1974 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1975 true)) {
1976 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1977 }
1978
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001979 if (sa.getBoolean(
1980 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001981 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001982 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1983 }
1984
Jason parksa3cdaa52011-01-13 14:15:43 -06001985 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001986 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001987 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001988 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001989 }
1990
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001991 if (sa.getBoolean(
1992 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1993 false /* default is no RTL support*/)) {
1994 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1995 }
1996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001998 str = sa.getNonConfigurationString(
1999 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
2001
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002002 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2003 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002004 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
2005 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002006 } else {
2007 // Some older apps have been seen to use a resource reference
2008 // here that on older builds was ignored (with a warning). We
2009 // need to continue to do this for them so they don't break.
2010 str = sa.getNonResourceString(
2011 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
2012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
2014 str, outError);
2015
2016 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002017 CharSequence pname;
2018 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2019 pname = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002020 com.android.internal.R.styleable.AndroidManifestApplication_process,
2021 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002022 } else {
2023 // Some older apps have been seen to use a resource reference
2024 // here that on older builds was ignored (with a warning). We
2025 // need to continue to do this for them so they don't break.
2026 pname = sa.getNonResourceString(
2027 com.android.internal.R.styleable.AndroidManifestApplication_process);
2028 }
2029 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 flags, mSeparateProcesses, outError);
2031
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002032 ai.enabled = sa.getBoolean(
2033 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002034
Dianne Hackborn02486b12010-08-26 14:18:37 -07002035 if (false) {
2036 if (sa.getBoolean(
2037 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2038 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002039 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002040
2041 // A heavy-weight application can not be in a custom process.
2042 // We can do direct compare because we intern all strings.
2043 if (ai.processName != null && ai.processName != ai.packageName) {
2044 outError[0] = "cantSaveState applications can not use custom processes";
2045 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002046 }
2047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 }
2049
Adam Powell269248d2011-08-02 10:26:54 -07002050 ai.uiOptions = sa.getInt(
2051 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 sa.recycle();
2054
2055 if (outError[0] != null) {
2056 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2057 return false;
2058 }
2059
2060 final int innerDepth = parser.getDepth();
2061
2062 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002063 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2064 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2065 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 continue;
2067 }
2068
2069 String tagName = parser.getName();
2070 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002071 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2072 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 if (a == null) {
2074 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2075 return false;
2076 }
2077
2078 owner.activities.add(a);
2079
2080 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002081 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 if (a == null) {
2083 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2084 return false;
2085 }
2086
2087 owner.receivers.add(a);
2088
2089 } else if (tagName.equals("service")) {
2090 Service s = parseService(owner, res, parser, attrs, flags, outError);
2091 if (s == null) {
2092 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2093 return false;
2094 }
2095
2096 owner.services.add(s);
2097
2098 } else if (tagName.equals("provider")) {
2099 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2100 if (p == null) {
2101 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2102 return false;
2103 }
2104
2105 owner.providers.add(p);
2106
2107 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002108 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 if (a == null) {
2110 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2111 return false;
2112 }
2113
2114 owner.activities.add(a);
2115
2116 } else if (parser.getName().equals("meta-data")) {
2117 // note: application meta-data is stored off to the side, so it can
2118 // remain null in the primary copy (we like to avoid extra copies because
2119 // it can be large)
2120 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2121 outError)) == null) {
2122 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2123 return false;
2124 }
2125
Dianne Hackbornc895be72013-03-11 17:48:43 -07002126 } else if (tagName.equals("library")) {
2127 sa = res.obtainAttributes(attrs,
2128 com.android.internal.R.styleable.AndroidManifestLibrary);
2129
2130 // Note: don't allow this value to be a reference to a resource
2131 // that may change.
2132 String lname = sa.getNonResourceString(
2133 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2134
2135 sa.recycle();
2136
2137 if (lname != null) {
2138 if (owner.libraryNames == null) {
2139 owner.libraryNames = new ArrayList<String>();
2140 }
2141 if (!owner.libraryNames.contains(lname)) {
2142 owner.libraryNames.add(lname.intern());
2143 }
2144 }
2145
2146 XmlUtils.skipCurrentTag(parser);
2147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 } else if (tagName.equals("uses-library")) {
2149 sa = res.obtainAttributes(attrs,
2150 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2151
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002152 // Note: don't allow this value to be a reference to a resource
2153 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 String lname = sa.getNonResourceString(
2155 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002156 boolean req = sa.getBoolean(
2157 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2158 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159
2160 sa.recycle();
2161
Dianne Hackborn49237342009-08-27 20:08:01 -07002162 if (lname != null) {
2163 if (req) {
2164 if (owner.usesLibraries == null) {
2165 owner.usesLibraries = new ArrayList<String>();
2166 }
2167 if (!owner.usesLibraries.contains(lname)) {
2168 owner.usesLibraries.add(lname.intern());
2169 }
2170 } else {
2171 if (owner.usesOptionalLibraries == null) {
2172 owner.usesOptionalLibraries = new ArrayList<String>();
2173 }
2174 if (!owner.usesOptionalLibraries.contains(lname)) {
2175 owner.usesOptionalLibraries.add(lname.intern());
2176 }
2177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 }
2179
2180 XmlUtils.skipCurrentTag(parser);
2181
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002182 } else if (tagName.equals("uses-package")) {
2183 // Dependencies for app installers; we don't currently try to
2184 // enforce this.
2185 XmlUtils.skipCurrentTag(parser);
2186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 } else {
2188 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002189 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002190 + " at " + mArchiveSourcePath + " "
2191 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 XmlUtils.skipCurrentTag(parser);
2193 continue;
2194 } else {
2195 outError[0] = "Bad element under <application>: " + tagName;
2196 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2197 return false;
2198 }
2199 }
2200 }
2201
2202 return true;
2203 }
2204
2205 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2206 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002207 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002208 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 if (name == null) {
2210 outError[0] = tag + " does not specify android:name";
2211 return false;
2212 }
2213
2214 outInfo.name
2215 = buildClassName(owner.applicationInfo.packageName, name, outError);
2216 if (outInfo.name == null) {
2217 return false;
2218 }
2219
2220 int iconVal = sa.getResourceId(iconRes, 0);
2221 if (iconVal != 0) {
2222 outInfo.icon = iconVal;
2223 outInfo.nonLocalizedLabel = null;
2224 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002225
2226 int logoVal = sa.getResourceId(logoRes, 0);
2227 if (logoVal != 0) {
2228 outInfo.logo = logoVal;
2229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230
2231 TypedValue v = sa.peekValue(labelRes);
2232 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2233 outInfo.nonLocalizedLabel = v.coerceToString();
2234 }
2235
2236 outInfo.packageName = owner.packageName;
2237
2238 return true;
2239 }
2240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 private Activity parseActivity(Package owner, Resources res,
2242 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002243 boolean receiver, boolean hardwareAccelerated)
2244 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 TypedArray sa = res.obtainAttributes(attrs,
2246 com.android.internal.R.styleable.AndroidManifestActivity);
2247
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002248 if (mParseActivityArgs == null) {
2249 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2250 com.android.internal.R.styleable.AndroidManifestActivity_name,
2251 com.android.internal.R.styleable.AndroidManifestActivity_label,
2252 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002253 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002254 mSeparateProcesses,
2255 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002256 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2258 }
2259
2260 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2261 mParseActivityArgs.sa = sa;
2262 mParseActivityArgs.flags = flags;
2263
2264 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2265 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 sa.recycle();
2267 return null;
2268 }
2269
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002270 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2272 if (setExported) {
2273 a.info.exported = sa.getBoolean(
2274 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2275 }
2276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 a.info.theme = sa.getResourceId(
2278 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2279
Adam Powell269248d2011-08-02 10:26:54 -07002280 a.info.uiOptions = sa.getInt(
2281 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2282 a.info.applicationInfo.uiOptions);
2283
Adam Powelldd8fab22012-03-22 17:47:27 -07002284 String parentName = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002285 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName,
2286 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002287 if (parentName != null) {
2288 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2289 if (outError[0] == null) {
2290 a.info.parentActivityName = parentClassName;
2291 } else {
2292 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2293 parentName);
2294 outError[0] = null;
2295 }
2296 }
2297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002299 str = sa.getNonConfigurationString(
2300 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 if (str == null) {
2302 a.info.permission = owner.applicationInfo.permission;
2303 } else {
2304 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2305 }
2306
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002307 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002308 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity,
2309 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2311 owner.applicationInfo.taskAffinity, str, outError);
2312
2313 a.info.flags = 0;
2314 if (sa.getBoolean(
2315 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2316 false)) {
2317 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2318 }
2319
2320 if (sa.getBoolean(
2321 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2322 false)) {
2323 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2324 }
2325
2326 if (sa.getBoolean(
2327 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2328 false)) {
2329 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2330 }
2331
2332 if (sa.getBoolean(
2333 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2334 false)) {
2335 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2336 }
2337
2338 if (sa.getBoolean(
2339 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2340 false)) {
2341 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2342 }
2343
2344 if (sa.getBoolean(
2345 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2346 false)) {
2347 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2348 }
2349
2350 if (sa.getBoolean(
2351 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2352 false)) {
2353 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2354 }
2355
2356 if (sa.getBoolean(
2357 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2358 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2359 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2360 }
2361
Dianne Hackbornffa42482009-09-23 22:20:11 -07002362 if (sa.getBoolean(
2363 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2364 false)) {
2365 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2366 }
2367
Daniel Sandler613dde42010-06-21 13:46:39 -04002368 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002369 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2370 false)) {
2371 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2372 }
2373
2374 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002375 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2376 false)) {
2377 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2378 }
Craig Mautner5962b122012-10-05 14:45:52 -07002379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002381 if (sa.getBoolean(
2382 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2383 hardwareAccelerated)) {
2384 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2385 }
2386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 a.info.launchMode = sa.getInt(
2388 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2389 ActivityInfo.LAUNCH_MULTIPLE);
2390 a.info.screenOrientation = sa.getInt(
2391 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2392 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2393 a.info.configChanges = sa.getInt(
2394 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2395 0);
2396 a.info.softInputMode = sa.getInt(
2397 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2398 0);
2399 } else {
2400 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2401 a.info.configChanges = 0;
2402 }
2403
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002404 if (receiver) {
2405 if (sa.getBoolean(
2406 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2407 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002408 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002409 if (a.info.exported) {
2410 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2411 + a.className + " at " + mArchiveSourcePath + " "
2412 + parser.getPositionDescription());
2413 a.info.exported = false;
2414 }
2415 setExported = true;
2416 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002417 if (sa.getBoolean(
2418 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2419 false)) {
2420 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2421 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002422 }
2423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 sa.recycle();
2425
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002426 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002427 // A heavy-weight application can not have receives in its main process
2428 // We can do direct compare because we intern all strings.
2429 if (a.info.processName == owner.packageName) {
2430 outError[0] = "Heavy-weight applications can not have receivers in main process";
2431 }
2432 }
2433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 if (outError[0] != null) {
2435 return null;
2436 }
2437
2438 int outerDepth = parser.getDepth();
2439 int type;
2440 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2441 && (type != XmlPullParser.END_TAG
2442 || parser.getDepth() > outerDepth)) {
2443 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2444 continue;
2445 }
2446
2447 if (parser.getName().equals("intent-filter")) {
2448 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002449 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 return null;
2451 }
2452 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002453 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002454 + mArchiveSourcePath + " "
2455 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 } else {
2457 a.intents.add(intent);
2458 }
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002459 } else if (!receiver && parser.getName().equals("preferred")) {
2460 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2461 if (!parseIntent(res, parser, attrs, false, intent, outError)) {
2462 return null;
2463 }
2464 if (intent.countActions() == 0) {
2465 Slog.w(TAG, "No actions in preferred at "
2466 + mArchiveSourcePath + " "
2467 + parser.getPositionDescription());
2468 } else {
2469 if (owner.preferredActivityFilters == null) {
2470 owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>();
2471 }
2472 owner.preferredActivityFilters.add(intent);
2473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 } else if (parser.getName().equals("meta-data")) {
2475 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2476 outError)) == null) {
2477 return null;
2478 }
2479 } else {
2480 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002481 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002483 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002484 + " at " + mArchiveSourcePath + " "
2485 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002487 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002488 + " at " + mArchiveSourcePath + " "
2489 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 }
2491 XmlUtils.skipCurrentTag(parser);
2492 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002494 if (receiver) {
2495 outError[0] = "Bad element under <receiver>: " + parser.getName();
2496 } else {
2497 outError[0] = "Bad element under <activity>: " + parser.getName();
2498 }
2499 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 }
2502 }
2503
2504 if (!setExported) {
2505 a.info.exported = a.intents.size() > 0;
2506 }
2507
2508 return a;
2509 }
2510
2511 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002512 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2513 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 TypedArray sa = res.obtainAttributes(attrs,
2515 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2516
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002517 String targetActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002518 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity,
2519 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 if (targetActivity == null) {
2521 outError[0] = "<activity-alias> does not specify android:targetActivity";
2522 sa.recycle();
2523 return null;
2524 }
2525
2526 targetActivity = buildClassName(owner.applicationInfo.packageName,
2527 targetActivity, outError);
2528 if (targetActivity == null) {
2529 sa.recycle();
2530 return null;
2531 }
2532
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002533 if (mParseActivityAliasArgs == null) {
2534 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2535 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2536 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2537 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002538 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002539 mSeparateProcesses,
2540 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002541 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002542 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2543 mParseActivityAliasArgs.tag = "<activity-alias>";
2544 }
2545
2546 mParseActivityAliasArgs.sa = sa;
2547 mParseActivityAliasArgs.flags = flags;
2548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 Activity target = null;
2550
2551 final int NA = owner.activities.size();
2552 for (int i=0; i<NA; i++) {
2553 Activity t = owner.activities.get(i);
2554 if (targetActivity.equals(t.info.name)) {
2555 target = t;
2556 break;
2557 }
2558 }
2559
2560 if (target == null) {
2561 outError[0] = "<activity-alias> target activity " + targetActivity
2562 + " not found in manifest";
2563 sa.recycle();
2564 return null;
2565 }
2566
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002567 ActivityInfo info = new ActivityInfo();
2568 info.targetActivity = targetActivity;
2569 info.configChanges = target.info.configChanges;
2570 info.flags = target.info.flags;
2571 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002572 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002573 info.labelRes = target.info.labelRes;
2574 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2575 info.launchMode = target.info.launchMode;
2576 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002577 if (info.descriptionRes == 0) {
2578 info.descriptionRes = target.info.descriptionRes;
2579 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002580 info.screenOrientation = target.info.screenOrientation;
2581 info.taskAffinity = target.info.taskAffinity;
2582 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002583 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002584 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002585 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002586
2587 Activity a = new Activity(mParseActivityAliasArgs, info);
2588 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 sa.recycle();
2590 return null;
2591 }
2592
2593 final boolean setExported = sa.hasValue(
2594 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2595 if (setExported) {
2596 a.info.exported = sa.getBoolean(
2597 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2598 }
2599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002601 str = sa.getNonConfigurationString(
2602 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 if (str != null) {
2604 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2605 }
2606
Adam Powelldd8fab22012-03-22 17:47:27 -07002607 String parentName = sa.getNonConfigurationString(
2608 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002609 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002610 if (parentName != null) {
2611 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2612 if (outError[0] == null) {
2613 a.info.parentActivityName = parentClassName;
2614 } else {
2615 Log.e(TAG, "Activity alias " + a.info.name +
2616 " specified invalid parentActivityName " + parentName);
2617 outError[0] = null;
2618 }
2619 }
2620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 sa.recycle();
2622
2623 if (outError[0] != null) {
2624 return null;
2625 }
2626
2627 int outerDepth = parser.getDepth();
2628 int type;
2629 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2630 && (type != XmlPullParser.END_TAG
2631 || parser.getDepth() > outerDepth)) {
2632 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2633 continue;
2634 }
2635
2636 if (parser.getName().equals("intent-filter")) {
2637 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002638 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 return null;
2640 }
2641 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002642 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002643 + mArchiveSourcePath + " "
2644 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 } else {
2646 a.intents.add(intent);
2647 }
2648 } else if (parser.getName().equals("meta-data")) {
2649 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2650 outError)) == null) {
2651 return null;
2652 }
2653 } else {
2654 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002655 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002656 + " at " + mArchiveSourcePath + " "
2657 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 XmlUtils.skipCurrentTag(parser);
2659 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002660 } else {
2661 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2662 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 }
2665 }
2666
2667 if (!setExported) {
2668 a.info.exported = a.intents.size() > 0;
2669 }
2670
2671 return a;
2672 }
2673
2674 private Provider parseProvider(Package owner, Resources res,
2675 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2676 throws XmlPullParserException, IOException {
2677 TypedArray sa = res.obtainAttributes(attrs,
2678 com.android.internal.R.styleable.AndroidManifestProvider);
2679
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002680 if (mParseProviderArgs == null) {
2681 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2682 com.android.internal.R.styleable.AndroidManifestProvider_name,
2683 com.android.internal.R.styleable.AndroidManifestProvider_label,
2684 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002685 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002686 mSeparateProcesses,
2687 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002688 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002689 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2690 mParseProviderArgs.tag = "<provider>";
2691 }
2692
2693 mParseProviderArgs.sa = sa;
2694 mParseProviderArgs.flags = flags;
2695
2696 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2697 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 sa.recycle();
2699 return null;
2700 }
2701
Nick Kralevichf097b162012-07-28 12:43:48 -07002702 boolean providerExportedDefault = false;
2703
2704 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2705 // For compatibility, applications targeting API level 16 or lower
2706 // should have their content providers exported by default, unless they
2707 // specify otherwise.
2708 providerExportedDefault = true;
2709 }
2710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002712 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2713 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002715 String cpname = sa.getNonConfigurationString(
2716 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717
2718 p.info.isSyncable = sa.getBoolean(
2719 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2720 false);
2721
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002722 String permission = sa.getNonConfigurationString(
2723 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2724 String str = sa.getNonConfigurationString(
2725 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 if (str == null) {
2727 str = permission;
2728 }
2729 if (str == null) {
2730 p.info.readPermission = owner.applicationInfo.permission;
2731 } else {
2732 p.info.readPermission =
2733 str.length() > 0 ? str.toString().intern() : null;
2734 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002735 str = sa.getNonConfigurationString(
2736 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 if (str == null) {
2738 str = permission;
2739 }
2740 if (str == null) {
2741 p.info.writePermission = owner.applicationInfo.permission;
2742 } else {
2743 p.info.writePermission =
2744 str.length() > 0 ? str.toString().intern() : null;
2745 }
2746
2747 p.info.grantUriPermissions = sa.getBoolean(
2748 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2749 false);
2750
2751 p.info.multiprocess = sa.getBoolean(
2752 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2753 false);
2754
2755 p.info.initOrder = sa.getInt(
2756 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2757 0);
2758
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002759 p.info.flags = 0;
2760
2761 if (sa.getBoolean(
2762 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2763 false)) {
2764 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2765 if (p.info.exported) {
2766 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2767 + p.className + " at " + mArchiveSourcePath + " "
2768 + parser.getPositionDescription());
2769 p.info.exported = false;
2770 }
2771 }
2772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 sa.recycle();
2774
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002775 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002776 // A heavy-weight application can not have providers in its main process
2777 // We can do direct compare because we intern all strings.
2778 if (p.info.processName == owner.packageName) {
2779 outError[0] = "Heavy-weight applications can not have providers in main process";
2780 return null;
2781 }
2782 }
2783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002785 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 return null;
2787 }
2788 p.info.authority = cpname.intern();
2789
2790 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2791 return null;
2792 }
2793
2794 return p;
2795 }
2796
2797 private boolean parseProviderTags(Resources res,
2798 XmlPullParser parser, AttributeSet attrs,
2799 Provider outInfo, String[] outError)
2800 throws XmlPullParserException, IOException {
2801 int outerDepth = parser.getDepth();
2802 int type;
2803 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2804 && (type != XmlPullParser.END_TAG
2805 || parser.getDepth() > outerDepth)) {
2806 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2807 continue;
2808 }
2809
2810 if (parser.getName().equals("meta-data")) {
2811 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2812 outInfo.metaData, outError)) == null) {
2813 return false;
2814 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 } else if (parser.getName().equals("grant-uri-permission")) {
2817 TypedArray sa = res.obtainAttributes(attrs,
2818 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2819
2820 PatternMatcher pa = null;
2821
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002822 String str = sa.getNonConfigurationString(
2823 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 if (str != null) {
2825 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2826 }
2827
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002828 str = sa.getNonConfigurationString(
2829 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 if (str != null) {
2831 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2832 }
2833
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002834 str = sa.getNonConfigurationString(
2835 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 if (str != null) {
2837 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2838 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 sa.recycle();
2841
2842 if (pa != null) {
2843 if (outInfo.info.uriPermissionPatterns == null) {
2844 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2845 outInfo.info.uriPermissionPatterns[0] = pa;
2846 } else {
2847 final int N = outInfo.info.uriPermissionPatterns.length;
2848 PatternMatcher[] newp = new PatternMatcher[N+1];
2849 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2850 newp[N] = pa;
2851 outInfo.info.uriPermissionPatterns = newp;
2852 }
2853 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002854 } else {
2855 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002856 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002857 + parser.getName() + " at " + mArchiveSourcePath + " "
2858 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002859 XmlUtils.skipCurrentTag(parser);
2860 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002861 } else {
2862 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2863 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002864 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002865 }
2866 XmlUtils.skipCurrentTag(parser);
2867
2868 } else if (parser.getName().equals("path-permission")) {
2869 TypedArray sa = res.obtainAttributes(attrs,
2870 com.android.internal.R.styleable.AndroidManifestPathPermission);
2871
2872 PathPermission pa = null;
2873
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002874 String permission = sa.getNonConfigurationString(
2875 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2876 String readPermission = sa.getNonConfigurationString(
2877 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002878 if (readPermission == null) {
2879 readPermission = permission;
2880 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002881 String writePermission = sa.getNonConfigurationString(
2882 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002883 if (writePermission == null) {
2884 writePermission = permission;
2885 }
2886
2887 boolean havePerm = false;
2888 if (readPermission != null) {
2889 readPermission = readPermission.intern();
2890 havePerm = true;
2891 }
2892 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002893 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002894 havePerm = true;
2895 }
2896
2897 if (!havePerm) {
2898 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002899 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002900 + parser.getName() + " at " + mArchiveSourcePath + " "
2901 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002902 XmlUtils.skipCurrentTag(parser);
2903 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002904 } else {
2905 outError[0] = "No readPermission or writePermssion for <path-permission>";
2906 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002907 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002908 }
2909
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002910 String path = sa.getNonConfigurationString(
2911 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002912 if (path != null) {
2913 pa = new PathPermission(path,
2914 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2915 }
2916
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002917 path = sa.getNonConfigurationString(
2918 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002919 if (path != null) {
2920 pa = new PathPermission(path,
2921 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2922 }
2923
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002924 path = sa.getNonConfigurationString(
2925 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002926 if (path != null) {
2927 pa = new PathPermission(path,
2928 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2929 }
2930
2931 sa.recycle();
2932
2933 if (pa != null) {
2934 if (outInfo.info.pathPermissions == null) {
2935 outInfo.info.pathPermissions = new PathPermission[1];
2936 outInfo.info.pathPermissions[0] = pa;
2937 } else {
2938 final int N = outInfo.info.pathPermissions.length;
2939 PathPermission[] newp = new PathPermission[N+1];
2940 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2941 newp[N] = pa;
2942 outInfo.info.pathPermissions = newp;
2943 }
2944 } else {
2945 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002946 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002947 + parser.getName() + " at " + mArchiveSourcePath + " "
2948 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002949 XmlUtils.skipCurrentTag(parser);
2950 continue;
2951 }
2952 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2953 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 }
2955 XmlUtils.skipCurrentTag(parser);
2956
2957 } else {
2958 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002959 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002960 + parser.getName() + " at " + mArchiveSourcePath + " "
2961 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 XmlUtils.skipCurrentTag(parser);
2963 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002964 } else {
2965 outError[0] = "Bad element under <provider>: " + parser.getName();
2966 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 }
2969 }
2970 return true;
2971 }
2972
2973 private Service parseService(Package owner, Resources res,
2974 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2975 throws XmlPullParserException, IOException {
2976 TypedArray sa = res.obtainAttributes(attrs,
2977 com.android.internal.R.styleable.AndroidManifestService);
2978
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002979 if (mParseServiceArgs == null) {
2980 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2981 com.android.internal.R.styleable.AndroidManifestService_name,
2982 com.android.internal.R.styleable.AndroidManifestService_label,
2983 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002984 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002985 mSeparateProcesses,
2986 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002987 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002988 com.android.internal.R.styleable.AndroidManifestService_enabled);
2989 mParseServiceArgs.tag = "<service>";
2990 }
2991
2992 mParseServiceArgs.sa = sa;
2993 mParseServiceArgs.flags = flags;
2994
2995 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2996 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 sa.recycle();
2998 return null;
2999 }
3000
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003001 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 com.android.internal.R.styleable.AndroidManifestService_exported);
3003 if (setExported) {
3004 s.info.exported = sa.getBoolean(
3005 com.android.internal.R.styleable.AndroidManifestService_exported, false);
3006 }
3007
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003008 String str = sa.getNonConfigurationString(
3009 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 if (str == null) {
3011 s.info.permission = owner.applicationInfo.permission;
3012 } else {
3013 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
3014 }
3015
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003016 s.info.flags = 0;
3017 if (sa.getBoolean(
Adam Skorydfc7fd72013-08-05 19:23:41 -07003018 com.android.internal.R.styleable.AndroidManifestService_provideAssistData,
3019 false)) {
3020 s.info.flags |= ServiceInfo.FLAG_PROVIDE_ASSIST_DATA;
3021 }
3022 if (sa.getBoolean(
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003023 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
3024 false)) {
3025 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
3026 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08003027 if (sa.getBoolean(
3028 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
3029 false)) {
3030 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
3031 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003032 if (sa.getBoolean(
3033 com.android.internal.R.styleable.AndroidManifestService_singleUser,
3034 false)) {
3035 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
3036 if (s.info.exported) {
3037 Slog.w(TAG, "Service exported request ignored due to singleUser: "
3038 + s.className + " at " + mArchiveSourcePath + " "
3039 + parser.getPositionDescription());
3040 s.info.exported = false;
3041 }
3042 setExported = true;
3043 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 sa.recycle();
3046
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003047 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003048 // A heavy-weight application can not have services in its main process
3049 // We can do direct compare because we intern all strings.
3050 if (s.info.processName == owner.packageName) {
3051 outError[0] = "Heavy-weight applications can not have services in main process";
3052 return null;
3053 }
3054 }
3055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003056 int outerDepth = parser.getDepth();
3057 int type;
3058 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3059 && (type != XmlPullParser.END_TAG
3060 || parser.getDepth() > outerDepth)) {
3061 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3062 continue;
3063 }
3064
3065 if (parser.getName().equals("intent-filter")) {
3066 ServiceIntentInfo intent = new ServiceIntentInfo(s);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003067 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 return null;
3069 }
3070
3071 s.intents.add(intent);
3072 } else if (parser.getName().equals("meta-data")) {
3073 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3074 outError)) == null) {
3075 return null;
3076 }
3077 } else {
3078 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003079 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003080 + parser.getName() + " at " + mArchiveSourcePath + " "
3081 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 XmlUtils.skipCurrentTag(parser);
3083 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003084 } else {
3085 outError[0] = "Bad element under <service>: " + parser.getName();
3086 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003088 }
3089 }
3090
3091 if (!setExported) {
3092 s.info.exported = s.intents.size() > 0;
3093 }
3094
3095 return s;
3096 }
3097
3098 private boolean parseAllMetaData(Resources res,
3099 XmlPullParser parser, AttributeSet attrs, String tag,
3100 Component outInfo, String[] outError)
3101 throws XmlPullParserException, IOException {
3102 int outerDepth = parser.getDepth();
3103 int type;
3104 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3105 && (type != XmlPullParser.END_TAG
3106 || parser.getDepth() > outerDepth)) {
3107 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3108 continue;
3109 }
3110
3111 if (parser.getName().equals("meta-data")) {
3112 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3113 outInfo.metaData, outError)) == null) {
3114 return false;
3115 }
3116 } else {
3117 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003118 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003119 + parser.getName() + " at " + mArchiveSourcePath + " "
3120 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 XmlUtils.skipCurrentTag(parser);
3122 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003123 } else {
3124 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3125 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 }
3128 }
3129 return true;
3130 }
3131
3132 private Bundle parseMetaData(Resources res,
3133 XmlPullParser parser, AttributeSet attrs,
3134 Bundle data, String[] outError)
3135 throws XmlPullParserException, IOException {
3136
3137 TypedArray sa = res.obtainAttributes(attrs,
3138 com.android.internal.R.styleable.AndroidManifestMetaData);
3139
3140 if (data == null) {
3141 data = new Bundle();
3142 }
3143
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003144 String name = sa.getNonConfigurationString(
3145 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 if (name == null) {
3147 outError[0] = "<meta-data> requires an android:name attribute";
3148 sa.recycle();
3149 return null;
3150 }
3151
Dianne Hackborn854060a2009-07-09 18:14:31 -07003152 name = name.intern();
3153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 TypedValue v = sa.peekValue(
3155 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3156 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003157 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 data.putInt(name, v.resourceId);
3159 } else {
3160 v = sa.peekValue(
3161 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003162 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 if (v != null) {
3164 if (v.type == TypedValue.TYPE_STRING) {
3165 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003166 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3168 data.putBoolean(name, v.data != 0);
3169 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3170 && v.type <= TypedValue.TYPE_LAST_INT) {
3171 data.putInt(name, v.data);
3172 } else if (v.type == TypedValue.TYPE_FLOAT) {
3173 data.putFloat(name, v.getFloat());
3174 } else {
3175 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003176 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003177 + parser.getName() + " at " + mArchiveSourcePath + " "
3178 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 } else {
3180 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3181 data = null;
3182 }
3183 }
3184 } else {
3185 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3186 data = null;
3187 }
3188 }
3189
3190 sa.recycle();
3191
3192 XmlUtils.skipCurrentTag(parser);
3193
3194 return data;
3195 }
3196
Kenny Root05ca4c92011-09-15 10:36:25 -07003197 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3198 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3199 IOException {
3200 final TypedArray sa = res.obtainAttributes(attrs,
3201 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3202
3203 final String packageName = sa.getNonResourceString(
3204 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3205
3206 final String encodedPublicKey = sa.getNonResourceString(
3207 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3208
3209 sa.recycle();
3210
3211 if (packageName == null || packageName.length() == 0) {
3212 Slog.i(TAG, "verifier package name was null; skipping");
3213 return null;
3214 } else if (encodedPublicKey == null) {
3215 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3216 }
3217
Geremy Condraf1bcca82013-01-07 22:35:24 -08003218 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3219 if (publicKey != null) {
3220 return new VerifierInfo(packageName, publicKey);
3221 }
3222
3223 return null;
3224 }
3225
3226 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003227 EncodedKeySpec keySpec;
3228 try {
3229 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3230 keySpec = new X509EncodedKeySpec(encoded);
3231 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003232 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003233 return null;
3234 }
3235
3236 /* First try the key as an RSA key. */
3237 try {
3238 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003239 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003240 } catch (NoSuchAlgorithmException e) {
3241 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3242 return null;
3243 } catch (InvalidKeySpecException e) {
3244 // Not a RSA public key.
3245 }
3246
3247 /* Now try it as a DSA key. */
3248 try {
3249 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003250 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003251 } catch (NoSuchAlgorithmException e) {
3252 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3253 return null;
3254 } catch (InvalidKeySpecException e) {
3255 // Not a DSA public key.
3256 }
3257
3258 return null;
3259 }
3260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 private static final String ANDROID_RESOURCES
3262 = "http://schemas.android.com/apk/res/android";
3263
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003264 private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs,
3265 boolean allowGlobs, IntentInfo outInfo, String[] outError)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 throws XmlPullParserException, IOException {
3267
3268 TypedArray sa = res.obtainAttributes(attrs,
3269 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3270
3271 int priority = sa.getInt(
3272 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 TypedValue v = sa.peekValue(
3276 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3277 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3278 outInfo.nonLocalizedLabel = v.coerceToString();
3279 }
3280
3281 outInfo.icon = sa.getResourceId(
3282 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003283
3284 outInfo.logo = sa.getResourceId(
3285 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286
3287 sa.recycle();
3288
3289 int outerDepth = parser.getDepth();
3290 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003291 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3292 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3293 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 continue;
3295 }
3296
3297 String nodeName = parser.getName();
3298 if (nodeName.equals("action")) {
3299 String value = attrs.getAttributeValue(
3300 ANDROID_RESOURCES, "name");
3301 if (value == null || value == "") {
3302 outError[0] = "No value supplied for <android:name>";
3303 return false;
3304 }
3305 XmlUtils.skipCurrentTag(parser);
3306
3307 outInfo.addAction(value);
3308 } else if (nodeName.equals("category")) {
3309 String value = attrs.getAttributeValue(
3310 ANDROID_RESOURCES, "name");
3311 if (value == null || value == "") {
3312 outError[0] = "No value supplied for <android:name>";
3313 return false;
3314 }
3315 XmlUtils.skipCurrentTag(parser);
3316
3317 outInfo.addCategory(value);
3318
3319 } else if (nodeName.equals("data")) {
3320 sa = res.obtainAttributes(attrs,
3321 com.android.internal.R.styleable.AndroidManifestData);
3322
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003323 String str = sa.getNonConfigurationString(
3324 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 if (str != null) {
3326 try {
3327 outInfo.addDataType(str);
3328 } catch (IntentFilter.MalformedMimeTypeException e) {
3329 outError[0] = e.toString();
3330 sa.recycle();
3331 return false;
3332 }
3333 }
3334
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003335 str = sa.getNonConfigurationString(
3336 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 if (str != null) {
3338 outInfo.addDataScheme(str);
3339 }
3340
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003341 str = sa.getNonConfigurationString(
3342 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3343 if (str != null) {
3344 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3345 }
3346
3347 str = sa.getNonConfigurationString(
3348 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3349 if (str != null) {
3350 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3351 }
3352
3353 str = sa.getNonConfigurationString(
3354 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3355 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003356 if (!allowGlobs) {
3357 outError[0] = "sspPattern not allowed here; ssp must be literal";
3358 return false;
3359 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003360 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3361 }
3362
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003363 String host = sa.getNonConfigurationString(
3364 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3365 String port = sa.getNonConfigurationString(
3366 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 if (host != null) {
3368 outInfo.addDataAuthority(host, port);
3369 }
3370
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003371 str = sa.getNonConfigurationString(
3372 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 if (str != null) {
3374 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3375 }
3376
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003377 str = sa.getNonConfigurationString(
3378 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 if (str != null) {
3380 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3381 }
3382
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003383 str = sa.getNonConfigurationString(
3384 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003386 if (!allowGlobs) {
3387 outError[0] = "pathPattern not allowed here; path must be literal";
3388 return false;
3389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3391 }
3392
3393 sa.recycle();
3394 XmlUtils.skipCurrentTag(parser);
3395 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003396 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003397 + parser.getName() + " at " + mArchiveSourcePath + " "
3398 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 XmlUtils.skipCurrentTag(parser);
3400 } else {
3401 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3402 return false;
3403 }
3404 }
3405
3406 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003407
3408 if (DEBUG_PARSER) {
3409 final StringBuilder cats = new StringBuilder("Intent d=");
3410 cats.append(outInfo.hasDefault);
3411 cats.append(", cat=");
3412
3413 final Iterator<String> it = outInfo.categoriesIterator();
3414 if (it != null) {
3415 while (it.hasNext()) {
3416 cats.append(' ');
3417 cats.append(it.next());
3418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003420 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 }
3422
3423 return true;
3424 }
3425
3426 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003427
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003428 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429
3430 // For now we only support one application per package.
3431 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3432
3433 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3434 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3435 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3436 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3437 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3438 public final ArrayList<Service> services = new ArrayList<Service>(0);
3439 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3440
3441 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003442 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443
Dianne Hackborn854060a2009-07-09 18:14:31 -07003444 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003445
3446 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003447 public ArrayList<String> usesLibraries = null;
3448 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 public String[] usesLibraryFiles = null;
3450
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003451 public ArrayList<ActivityIntentInfo> preferredActivityFilters = null;
3452
Dianne Hackbornc1552392010-03-03 16:19:01 -08003453 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003454 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003455 public ArrayList<String> mAdoptPermissions = null;
3456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 // We store the application meta-data independently to avoid multiple unwanted references
3458 public Bundle mAppMetaData = null;
3459
3460 // If this is a 3rd party app, this is the path of the zip file.
3461 public String mPath;
3462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 // The version code declared for this package.
3464 public int mVersionCode;
3465
3466 // The version name declared for this package.
3467 public String mVersionName;
3468
3469 // The shared user id that this package wants to use.
3470 public String mSharedUserId;
3471
3472 // The shared user label that this package wants to use.
3473 public int mSharedUserLabel;
3474
3475 // Signatures that were read from the package.
3476 public Signature mSignatures[];
3477
3478 // For use by package manager service for quick lookup of
3479 // preferred up order.
3480 public int mPreferredOrder = 0;
3481
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003482 // For use by the package manager to keep track of the path to the
3483 // file an app came from.
3484 public String mScanPath;
3485
3486 // For use by package manager to keep track of where it has done dexopt.
3487 public boolean mDidDexOpt;
3488
Amith Yamasani13593602012-03-22 16:16:17 -07003489 // // User set enabled state.
3490 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3491 //
3492 // // Whether the package has been stopped.
3493 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 // Additional data supplied by callers.
3496 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003497
3498 // Whether an operation is currently pending on this package
3499 public boolean mOperationPending;
3500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 /*
3502 * Applications hardware preferences
3503 */
3504 public final ArrayList<ConfigurationInfo> configPreferences =
3505 new ArrayList<ConfigurationInfo>();
3506
Dianne Hackborn49237342009-08-27 20:08:01 -07003507 /*
3508 * Applications requested features
3509 */
3510 public ArrayList<FeatureInfo> reqFeatures = null;
3511
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003512 public int installLocation;
3513
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003514 /* An app that's required for all users and cannot be uninstalled for a user */
3515 public boolean mRequiredForAllUsers;
3516
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003517 /* The restricted account authenticator type that is used by this application */
3518 public String mRestrictedAccountType;
3519
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003520 /* The required account type without which this application will not function */
3521 public String mRequiredAccountType;
3522
Kenny Rootbcc954d2011-08-08 16:19:08 -07003523 /**
3524 * Digest suitable for comparing whether this package's manifest is the
3525 * same as another.
3526 */
3527 public ManifestDigest manifestDigest;
3528
Geremy Condraf1bcca82013-01-07 22:35:24 -08003529 /**
3530 * Data used to feed the KeySetManager
3531 */
3532 public Set<PublicKey> mSigningKeys;
3533 public Map<String, Set<PublicKey>> mKeySetMapping;
3534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 public Package(String _name) {
3536 packageName = _name;
3537 applicationInfo.packageName = _name;
3538 applicationInfo.uid = -1;
3539 }
3540
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003541 public void setPackageName(String newName) {
3542 packageName = newName;
3543 applicationInfo.packageName = newName;
3544 for (int i=permissions.size()-1; i>=0; i--) {
3545 permissions.get(i).setPackageName(newName);
3546 }
3547 for (int i=permissionGroups.size()-1; i>=0; i--) {
3548 permissionGroups.get(i).setPackageName(newName);
3549 }
3550 for (int i=activities.size()-1; i>=0; i--) {
3551 activities.get(i).setPackageName(newName);
3552 }
3553 for (int i=receivers.size()-1; i>=0; i--) {
3554 receivers.get(i).setPackageName(newName);
3555 }
3556 for (int i=providers.size()-1; i>=0; i--) {
3557 providers.get(i).setPackageName(newName);
3558 }
3559 for (int i=services.size()-1; i>=0; i--) {
3560 services.get(i).setPackageName(newName);
3561 }
3562 for (int i=instrumentation.size()-1; i>=0; i--) {
3563 instrumentation.get(i).setPackageName(newName);
3564 }
3565 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003566
3567 public boolean hasComponentClassName(String name) {
3568 for (int i=activities.size()-1; i>=0; i--) {
3569 if (name.equals(activities.get(i).className)) {
3570 return true;
3571 }
3572 }
3573 for (int i=receivers.size()-1; i>=0; i--) {
3574 if (name.equals(receivers.get(i).className)) {
3575 return true;
3576 }
3577 }
3578 for (int i=providers.size()-1; i>=0; i--) {
3579 if (name.equals(providers.get(i).className)) {
3580 return true;
3581 }
3582 }
3583 for (int i=services.size()-1; i>=0; i--) {
3584 if (name.equals(services.get(i).className)) {
3585 return true;
3586 }
3587 }
3588 for (int i=instrumentation.size()-1; i>=0; i--) {
3589 if (name.equals(instrumentation.get(i).className)) {
3590 return true;
3591 }
3592 }
3593 return false;
3594 }
3595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 public String toString() {
3597 return "Package{"
3598 + Integer.toHexString(System.identityHashCode(this))
3599 + " " + packageName + "}";
3600 }
3601 }
3602
3603 public static class Component<II extends IntentInfo> {
3604 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003605 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003606 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 public Bundle metaData;
3608
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003609 ComponentName componentName;
3610 String componentShortName;
3611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 public Component(Package _owner) {
3613 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003614 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003615 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003616 }
3617
3618 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3619 owner = args.owner;
3620 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003621 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003622 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003623 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003624 args.outError[0] = args.tag + " does not specify android:name";
3625 return;
3626 }
3627
3628 outInfo.name
3629 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3630 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003631 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003632 args.outError[0] = args.tag + " does not have valid android:name";
3633 return;
3634 }
3635
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003636 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003637
3638 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3639 if (iconVal != 0) {
3640 outInfo.icon = iconVal;
3641 outInfo.nonLocalizedLabel = null;
3642 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003643
3644 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3645 if (logoVal != 0) {
3646 outInfo.logo = logoVal;
3647 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003648
3649 TypedValue v = args.sa.peekValue(args.labelRes);
3650 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3651 outInfo.nonLocalizedLabel = v.coerceToString();
3652 }
3653
3654 outInfo.packageName = owner.packageName;
3655 }
3656
3657 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3658 this(args, (PackageItemInfo)outInfo);
3659 if (args.outError[0] != null) {
3660 return;
3661 }
3662
3663 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003664 CharSequence pname;
3665 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07003666 pname = args.sa.getNonConfigurationString(args.processRes,
3667 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003668 } else {
3669 // Some older apps have been seen to use a resource reference
3670 // here that on older builds was ignored (with a warning). We
3671 // need to continue to do this for them so they don't break.
3672 pname = args.sa.getNonResourceString(args.processRes);
3673 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003674 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003675 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003676 args.flags, args.sepProcesses, args.outError);
3677 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003678
3679 if (args.descriptionRes != 0) {
3680 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3681 }
3682
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003683 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 }
3685
3686 public Component(Component<II> clone) {
3687 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003688 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003689 className = clone.className;
3690 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003691 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003692 }
3693
3694 public ComponentName getComponentName() {
3695 if (componentName != null) {
3696 return componentName;
3697 }
3698 if (className != null) {
3699 componentName = new ComponentName(owner.applicationInfo.packageName,
3700 className);
3701 }
3702 return componentName;
3703 }
3704
3705 public String getComponentShortName() {
3706 if (componentShortName != null) {
3707 return componentShortName;
3708 }
3709 ComponentName component = getComponentName();
3710 if (component != null) {
3711 componentShortName = component.flattenToShortString();
3712 }
3713 return componentShortName;
3714 }
3715
3716 public void setPackageName(String packageName) {
3717 componentName = null;
3718 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720 }
3721
3722 public final static class Permission extends Component<IntentInfo> {
3723 public final PermissionInfo info;
3724 public boolean tree;
3725 public PermissionGroup group;
3726
3727 public Permission(Package _owner) {
3728 super(_owner);
3729 info = new PermissionInfo();
3730 }
3731
3732 public Permission(Package _owner, PermissionInfo _info) {
3733 super(_owner);
3734 info = _info;
3735 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003736
3737 public void setPackageName(String packageName) {
3738 super.setPackageName(packageName);
3739 info.packageName = packageName;
3740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741
3742 public String toString() {
3743 return "Permission{"
3744 + Integer.toHexString(System.identityHashCode(this))
3745 + " " + info.name + "}";
3746 }
3747 }
3748
3749 public final static class PermissionGroup extends Component<IntentInfo> {
3750 public final PermissionGroupInfo info;
3751
3752 public PermissionGroup(Package _owner) {
3753 super(_owner);
3754 info = new PermissionGroupInfo();
3755 }
3756
3757 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3758 super(_owner);
3759 info = _info;
3760 }
3761
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003762 public void setPackageName(String packageName) {
3763 super.setPackageName(packageName);
3764 info.packageName = packageName;
3765 }
3766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 public String toString() {
3768 return "PermissionGroup{"
3769 + Integer.toHexString(System.identityHashCode(this))
3770 + " " + info.name + "}";
3771 }
3772 }
3773
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003774 private static boolean copyNeeded(int flags, Package p,
3775 PackageUserState state, Bundle metaData, int userId) {
3776 if (userId != 0) {
3777 // We always need to copy for other users, since we need
3778 // to fix up the uid.
3779 return true;
3780 }
3781 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3782 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003783 if (p.applicationInfo.enabled != enabled) {
3784 return true;
3785 }
3786 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003787 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003788 return true;
3789 }
3790 if (state.stopped) {
3791 return true;
3792 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 if ((flags & PackageManager.GET_META_DATA) != 0
3794 && (metaData != null || p.mAppMetaData != null)) {
3795 return true;
3796 }
3797 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3798 && p.usesLibraryFiles != null) {
3799 return true;
3800 }
3801 return false;
3802 }
3803
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003804 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3805 PackageUserState state) {
3806 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003807 }
3808
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003809 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3810 PackageUserState state) {
3811 // CompatibilityMode is global state.
3812 if (!sCompatibilityModeEnabled) {
3813 ai.disableCompatibilityMode();
3814 }
3815 if (state.installed) {
3816 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3817 } else {
3818 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3819 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003820 if (state.blocked) {
3821 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3822 } else {
3823 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3824 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003825 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3826 ai.enabled = true;
3827 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3828 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3829 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3830 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3831 ai.enabled = false;
3832 }
3833 ai.enabledSetting = state.enabled;
3834 }
3835
Amith Yamasani13593602012-03-22 16:16:17 -07003836 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003837 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003839 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003840 return null;
3841 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003842 if (!copyNeeded(flags, p, state, null, userId)
3843 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3844 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3845 // In this case it is safe to directly modify the internal ApplicationInfo state:
3846 // - CompatibilityMode is global state, so will be the same for every call.
3847 // - We only come in to here if the app should reported as installed; this is the
3848 // default state, and we will do a copy otherwise.
3849 // - The enable state will always be reported the same for the application across
3850 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3851 // be doing a copy.
3852 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 return p.applicationInfo;
3854 }
3855
3856 // Make shallow copy so we can store the metadata/libraries safely
3857 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003858 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003859 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003860 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 if ((flags & PackageManager.GET_META_DATA) != 0) {
3863 ai.metaData = p.mAppMetaData;
3864 }
3865 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3866 ai.sharedLibraryFiles = p.usesLibraryFiles;
3867 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003868 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003869 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003870 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003871 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003872 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003873 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 return ai;
3875 }
3876
3877 public static final PermissionInfo generatePermissionInfo(
3878 Permission p, int flags) {
3879 if (p == null) return null;
3880 if ((flags&PackageManager.GET_META_DATA) == 0) {
3881 return p.info;
3882 }
3883 PermissionInfo pi = new PermissionInfo(p.info);
3884 pi.metaData = p.metaData;
3885 return pi;
3886 }
3887
3888 public static final PermissionGroupInfo generatePermissionGroupInfo(
3889 PermissionGroup pg, int flags) {
3890 if (pg == null) return null;
3891 if ((flags&PackageManager.GET_META_DATA) == 0) {
3892 return pg.info;
3893 }
3894 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3895 pgi.metaData = pg.metaData;
3896 return pgi;
3897 }
3898
3899 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003900 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003902 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3903 super(args, _info);
3904 info = _info;
3905 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003907
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003908 public void setPackageName(String packageName) {
3909 super.setPackageName(packageName);
3910 info.packageName = packageName;
3911 }
3912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 public String toString() {
3914 return "Activity{"
3915 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003916 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 }
3918 }
3919
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003920 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3921 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003923 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003924 return null;
3925 }
3926 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 return a.info;
3928 }
3929 // Make shallow copies so we can store the metadata safely
3930 ActivityInfo ai = new ActivityInfo(a.info);
3931 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003932 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 return ai;
3934 }
3935
3936 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003937 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003939 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3940 super(args, _info);
3941 info = _info;
3942 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003944
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003945 public void setPackageName(String packageName) {
3946 super.setPackageName(packageName);
3947 info.packageName = packageName;
3948 }
3949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 public String toString() {
3951 return "Service{"
3952 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003953 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 }
3955 }
3956
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003957 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3958 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003960 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003961 return null;
3962 }
3963 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 return s.info;
3965 }
3966 // Make shallow copies so we can store the metadata safely
3967 ServiceInfo si = new ServiceInfo(s.info);
3968 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003969 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 return si;
3971 }
3972
3973 public final static class Provider extends Component {
3974 public final ProviderInfo info;
3975 public boolean syncable;
3976
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003977 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3978 super(args, _info);
3979 info = _info;
3980 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 syncable = false;
3982 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003984 public Provider(Provider existingProvider) {
3985 super(existingProvider);
3986 this.info = existingProvider.info;
3987 this.syncable = existingProvider.syncable;
3988 }
3989
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003990 public void setPackageName(String packageName) {
3991 super.setPackageName(packageName);
3992 info.packageName = packageName;
3993 }
3994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 public String toString() {
3996 return "Provider{"
3997 + Integer.toHexString(System.identityHashCode(this))
3998 + " " + info.name + "}";
3999 }
4000 }
4001
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004002 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
4003 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07004005 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004006 return null;
4007 }
4008 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004010 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 return p.info;
4012 }
4013 // Make shallow copies so we can store the metadata safely
4014 ProviderInfo pi = new ProviderInfo(p.info);
4015 pi.metaData = p.metaData;
4016 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
4017 pi.uriPermissionPatterns = null;
4018 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004019 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 return pi;
4021 }
4022
4023 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004024 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004026 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
4027 super(args, _info);
4028 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004030
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004031 public void setPackageName(String packageName) {
4032 super.setPackageName(packageName);
4033 info.packageName = packageName;
4034 }
4035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 public String toString() {
4037 return "Instrumentation{"
4038 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004039 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 }
4041 }
4042
4043 public static final InstrumentationInfo generateInstrumentationInfo(
4044 Instrumentation i, int flags) {
4045 if (i == null) return null;
4046 if ((flags&PackageManager.GET_META_DATA) == 0) {
4047 return i.info;
4048 }
4049 InstrumentationInfo ii = new InstrumentationInfo(i.info);
4050 ii.metaData = i.metaData;
4051 return ii;
4052 }
4053
4054 public static class IntentInfo extends IntentFilter {
4055 public boolean hasDefault;
4056 public int labelRes;
4057 public CharSequence nonLocalizedLabel;
4058 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004059 public int logo;
Dianne Hackbornb09491f2013-07-22 15:30:11 -07004060 public int preferred;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004061 }
4062
4063 public final static class ActivityIntentInfo extends IntentInfo {
4064 public final Activity activity;
4065
4066 public ActivityIntentInfo(Activity _activity) {
4067 activity = _activity;
4068 }
4069
4070 public String toString() {
4071 return "ActivityIntentInfo{"
4072 + Integer.toHexString(System.identityHashCode(this))
4073 + " " + activity.info.name + "}";
4074 }
4075 }
4076
4077 public final static class ServiceIntentInfo extends IntentInfo {
4078 public final Service service;
4079
4080 public ServiceIntentInfo(Service _service) {
4081 service = _service;
4082 }
4083
4084 public String toString() {
4085 return "ServiceIntentInfo{"
4086 + Integer.toHexString(System.identityHashCode(this))
4087 + " " + service.info.name + "}";
4088 }
4089 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004090
4091 /**
4092 * @hide
4093 */
4094 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4095 sCompatibilityModeEnabled = compatibilityModeEnabled;
4096 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097}