blob: b489ee9e29886b8a28fe12f57d4f3b256f6374d3 [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;
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -070042import java.io.PrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Geremy Condraf1bcca82013-01-07 22:35:24 -080054import java.util.HashMap;
Dianne Hackborne639da72012-02-21 15:11:13 -080055import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070057import java.util.List;
Geremy Condraf1bcca82013-01-07 22:35:24 -080058import java.util.Map;
59import java.util.Set;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import java.util.jar.JarEntry;
61import java.util.jar.JarFile;
Kenny Root6c918ce2013-04-02 14:04:24 -070062import java.util.zip.ZipEntry;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
Amith Yamasani742a6712011-05-04 14:49:28 -070064import com.android.internal.util.XmlUtils;
65
66import org.xmlpull.v1.XmlPullParser;
67import org.xmlpull.v1.XmlPullParserException;
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069/**
70 * Package archive parsing
71 *
72 * {@hide}
73 */
74public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070075 private static final boolean DEBUG_JAR = false;
76 private static final boolean DEBUG_PARSER = false;
77 private static final boolean DEBUG_BACKUP = false;
78
Kenny Rootbcc954d2011-08-08 16:19:08 -070079 /** File name in an APK for the Android manifest. */
80 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
81
Dianne Hackborna96cbb42009-05-13 15:06:13 -070082 /** @hide */
83 public static class NewPermissionInfo {
84 public final String name;
85 public final int sdkVersion;
86 public final int fileVersion;
87
88 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
89 this.name = name;
90 this.sdkVersion = sdkVersion;
91 this.fileVersion = fileVersion;
92 }
93 }
Dianne Hackborn79245122012-03-12 10:51:26 -070094
95 /** @hide */
96 public static class SplitPermissionInfo {
97 public final String rootPerm;
98 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700100
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700101 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700102 this.rootPerm = rootPerm;
103 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700104 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700105 }
106 }
107
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700108 /**
109 * List of new permissions that have been added since 1.0.
110 * NOTE: These must be declared in SDK version order, with permissions
111 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700112 * If sdkVersion is 0, then this is not a permission that we want to
113 * automatically add to older apps, but we do want to allow it to be
114 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700115 * @hide
116 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700117 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
118 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700119 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700120 android.os.Build.VERSION_CODES.DONUT, 0),
121 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
122 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700123 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
Dianne Hackborn79245122012-03-12 10:51:26 -0700125 /**
126 * List of permissions that have been split into more granular or dependent
127 * permissions.
128 * @hide
129 */
130 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
131 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700132 // READ_EXTERNAL_STORAGE is always required when an app requests
133 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
134 // write access without read access. The hack here with the target
135 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700136 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700137 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700138 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700139 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
140 new String[] { android.Manifest.permission.READ_CALL_LOG },
141 android.os.Build.VERSION_CODES.JELLY_BEAN),
142 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
143 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
144 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700145 };
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 private String mArchiveSourcePath;
148 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700149 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700150 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
151 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
152 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
154 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
155
156 private static final Object mSync = new Object();
157 private static WeakReference<byte[]> mReadBuffer;
158
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700159 private static boolean sCompatibilityModeEnabled = true;
Amith Yamasani655d0e22013-06-12 14:19:10 -0700160 private static final int PARSE_DEFAULT_INSTALL_LOCATION =
161 PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700162
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700163 static class ParsePackageItemArgs {
164 final Package owner;
165 final String[] outError;
166 final int nameRes;
167 final int labelRes;
168 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700169 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700170
171 String tag;
172 TypedArray sa;
173
174 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700175 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700176 owner = _owner;
177 outError = _outError;
178 nameRes = _nameRes;
179 labelRes = _labelRes;
180 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700181 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700182 }
183 }
184
185 static class ParseComponentArgs extends ParsePackageItemArgs {
186 final String[] sepProcesses;
187 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800188 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700189 final int enabledRes;
190 int flags;
191
192 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700193 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800194 String[] _sepProcesses, int _processRes,
195 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700196 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700197 sepProcesses = _sepProcesses;
198 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800199 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700200 enabledRes = _enabledRes;
201 }
202 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800203
204 /* Light weight package info.
205 * @hide
206 */
207 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700208 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700209 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700210 public final int installLocation;
211 public final VerifierInfo[] verifiers;
212
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700213 public PackageLite(String packageName, int versionCode,
214 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800215 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700216 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800217 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700218 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800219 }
220 }
221
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700222 private ParsePackageItemArgs mParseInstrumentationArgs;
223 private ParseComponentArgs mParseActivityArgs;
224 private ParseComponentArgs mParseActivityAliasArgs;
225 private ParseComponentArgs mParseServiceArgs;
226 private ParseComponentArgs mParseProviderArgs;
227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 /** If set to true, we will only allow package files that exactly match
229 * the DTD. Otherwise, we try to get as much from the package as we
230 * can without failing. This should normally be set to false, to
231 * support extensions to the DTD in future versions. */
232 private static final boolean RIGID_PARSER = false;
233
234 private static final String TAG = "PackageParser";
235
236 public PackageParser(String archiveSourcePath) {
237 mArchiveSourcePath = archiveSourcePath;
238 }
239
240 public void setSeparateProcesses(String[] procs) {
241 mSeparateProcesses = procs;
242 }
243
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700244 public void setOnlyCoreApps(boolean onlyCoreApps) {
245 mOnlyCoreApps = onlyCoreApps;
246 }
247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 private static final boolean isPackageFilename(String name) {
249 return name.endsWith(".apk");
250 }
251
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700252 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700253 public static PackageInfo generatePackageInfo(PackageParser.Package p,
254 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
255 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700256 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700257 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700258 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700259 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700260 */
Amith Yamasani13593602012-03-22 16:16:17 -0700261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 /**
263 * Generate and return the {@link PackageInfo} for a parsed package.
264 *
265 * @param p the parsed package.
266 * @param flags indicating which optional information is included.
267 */
268 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800269 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700270 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271
Amith Yamasani483f3b02012-03-13 16:08:00 -0700272 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700273 grantedPermissions, state, UserHandle.getCallingUserId());
274 }
275
Amith Yamasani655d0e22013-06-12 14:19:10 -0700276 /**
277 * Returns true if the package is installed and not blocked, or if the caller
278 * explicitly wanted all uninstalled and blocked packages as well.
279 */
280 private static boolean checkUseInstalledOrBlocked(int flags, PackageUserState state) {
281 return (state.installed && !state.blocked)
282 || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700283 }
284
Amith Yamasani13593602012-03-22 16:16:17 -0700285 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700286 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700287 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700288
Amith Yamasani655d0e22013-06-12 14:19:10 -0700289 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700290 return null;
291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 PackageInfo pi = new PackageInfo();
293 pi.packageName = p.packageName;
294 pi.versionCode = p.mVersionCode;
295 pi.versionName = p.mVersionName;
296 pi.sharedUserId = p.mSharedUserId;
297 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700298 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800299 pi.installLocation = p.installLocation;
Amith Yamasani0d8750d2013-05-01 15:25:28 -0700300 if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0
301 || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
302 pi.requiredForAllUsers = p.mRequiredForAllUsers;
303 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700304 pi.restrictedAccountType = p.mRestrictedAccountType;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700305 pi.requiredAccountType = p.mRequiredAccountType;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700306 pi.firstInstallTime = firstInstallTime;
307 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 if ((flags&PackageManager.GET_GIDS) != 0) {
309 pi.gids = gids;
310 }
311 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
312 int N = p.configPreferences.size();
313 if (N > 0) {
314 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700315 p.configPreferences.toArray(pi.configPreferences);
316 }
317 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
318 if (N > 0) {
319 pi.reqFeatures = new FeatureInfo[N];
320 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 }
322 }
323 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
324 int N = p.activities.size();
325 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700326 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
327 pi.activities = new ActivityInfo[N];
328 } else {
329 int num = 0;
330 for (int i=0; i<N; i++) {
331 if (p.activities.get(i).info.enabled) num++;
332 }
333 pi.activities = new ActivityInfo[num];
334 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700335 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 final Activity activity = p.activities.get(i);
337 if (activity.info.enabled
338 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700339 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700340 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 }
342 }
343 }
344 }
345 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
346 int N = p.receivers.size();
347 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700348 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
349 pi.receivers = new ActivityInfo[N];
350 } else {
351 int num = 0;
352 for (int i=0; i<N; i++) {
353 if (p.receivers.get(i).info.enabled) num++;
354 }
355 pi.receivers = new ActivityInfo[num];
356 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700357 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 final Activity activity = p.receivers.get(i);
359 if (activity.info.enabled
360 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700361 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700362 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364 }
365 }
366 }
367 if ((flags&PackageManager.GET_SERVICES) != 0) {
368 int N = p.services.size();
369 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700370 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
371 pi.services = new ServiceInfo[N];
372 } else {
373 int num = 0;
374 for (int i=0; i<N; i++) {
375 if (p.services.get(i).info.enabled) num++;
376 }
377 pi.services = new ServiceInfo[num];
378 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700379 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 final Service service = p.services.get(i);
381 if (service.info.enabled
382 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700383 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
384 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 }
386 }
387 }
388 }
389 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
390 int N = p.providers.size();
391 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700392 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
393 pi.providers = new ProviderInfo[N];
394 } else {
395 int num = 0;
396 for (int i=0; i<N; i++) {
397 if (p.providers.get(i).info.enabled) num++;
398 }
399 pi.providers = new ProviderInfo[num];
400 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700401 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 final Provider provider = p.providers.get(i);
403 if (provider.info.enabled
404 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700405 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
406 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 }
408 }
409 }
410 }
411 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
412 int N = p.instrumentation.size();
413 if (N > 0) {
414 pi.instrumentation = new InstrumentationInfo[N];
415 for (int i=0; i<N; i++) {
416 pi.instrumentation[i] = generateInstrumentationInfo(
417 p.instrumentation.get(i), flags);
418 }
419 }
420 }
421 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
422 int N = p.permissions.size();
423 if (N > 0) {
424 pi.permissions = new PermissionInfo[N];
425 for (int i=0; i<N; i++) {
426 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
427 }
428 }
429 N = p.requestedPermissions.size();
430 if (N > 0) {
431 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800432 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800434 final String perm = p.requestedPermissions.get(i);
435 pi.requestedPermissions[i] = perm;
436 if (p.requestedPermissionsRequired.get(i)) {
437 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
438 }
439 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
440 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 }
443 }
444 }
445 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700446 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
447 if (N > 0) {
448 pi.signatures = new Signature[N];
449 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 }
451 }
452 return pi;
453 }
454
455 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
456 byte[] readBuffer) {
457 try {
458 // We must read the stream for the JarEntry to retrieve
459 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700460 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
462 // not using
463 }
464 is.close();
465 return je != null ? je.getCertificates() : null;
466 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700467 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700469 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700470 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700471 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 }
473 return null;
474 }
475
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800476 public final static int PARSE_IS_SYSTEM = 1<<0;
477 public final static int PARSE_CHATTY = 1<<1;
478 public final static int PARSE_MUST_BE_APK = 1<<2;
479 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
480 public final static int PARSE_FORWARD_LOCK = 1<<4;
481 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700482 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
Christopher Tateccbf84f2013-05-08 15:25:41 -0700483 public final static int PARSE_IS_PRIVILEGED = 1<<7;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484
485 public int getParseError() {
486 return mParseError;
487 }
488
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800489 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 DisplayMetrics metrics, int flags) {
491 mParseError = PackageManager.INSTALL_SUCCEEDED;
492
493 mArchiveSourcePath = sourceFile.getPath();
494 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700495 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
497 return null;
498 }
499 if (!isPackageFilename(sourceFile.getName())
500 && (flags&PARSE_MUST_BE_APK) != 0) {
501 if ((flags&PARSE_IS_SYSTEM) == 0) {
502 // We expect to have non-.apk files in the system dir,
503 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700504 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
506 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
507 return null;
508 }
509
Kenny Rootd2d29252011-08-08 11:27:57 -0700510 if (DEBUG_JAR)
511 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512
513 XmlResourceParser parser = null;
514 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800515 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 boolean assetError = true;
517 try {
518 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700519 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800520 if (cookie != 0) {
521 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700522 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 -0800523 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700524 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 assetError = false;
526 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700527 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 }
529 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700530 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 + mArchiveSourcePath, e);
532 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800533 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 if (assmgr != null) assmgr.close();
535 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
536 return null;
537 }
538 String[] errorText = new String[1];
539 Package pkg = null;
540 Exception errorException = null;
541 try {
542 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 pkg = parsePackage(res, parser, flags, errorText);
544 } catch (Exception e) {
545 errorException = e;
546 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
547 }
548
549
550 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700551 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
552 // just means to skip this app so don't make a fuss about it.
553 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
554 if (errorException != null) {
555 Slog.w(TAG, mArchiveSourcePath, errorException);
556 } else {
557 Slog.w(TAG, mArchiveSourcePath + " (at "
558 + parser.getPositionDescription()
559 + "): " + errorText[0]);
560 }
561 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
562 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565 parser.close();
566 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 return null;
568 }
569
570 parser.close();
571 assmgr.close();
572
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800573 // Set code and resource paths
574 pkg.mPath = destCodePath;
575 pkg.mScanPath = mArchiveSourcePath;
576 //pkg.applicationInfo.sourceDir = destCodePath;
577 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 pkg.mSignatures = null;
579
580 return pkg;
581 }
582
Kenny Root6c918ce2013-04-02 14:04:24 -0700583 /**
584 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
585 * APK. If it successfully scanned the package and found the
586 * {@code AndroidManifest.xml}, {@code true} is returned.
587 */
588 public boolean collectManifestDigest(Package pkg) {
589 try {
590 final JarFile jarFile = new JarFile(mArchiveSourcePath);
591 try {
592 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
593 if (je != null) {
594 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
595 }
596 } finally {
597 jarFile.close();
598 }
599 return true;
600 } catch (IOException e) {
601 return false;
602 }
603 }
604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 public boolean collectCertificates(Package pkg, int flags) {
606 pkg.mSignatures = null;
607
608 WeakReference<byte[]> readBufferRef;
609 byte[] readBuffer = null;
610 synchronized (mSync) {
611 readBufferRef = mReadBuffer;
612 if (readBufferRef != null) {
613 mReadBuffer = null;
614 readBuffer = readBufferRef.get();
615 }
616 if (readBuffer == null) {
617 readBuffer = new byte[8192];
618 readBufferRef = new WeakReference<byte[]>(readBuffer);
619 }
620 }
621
622 try {
623 JarFile jarFile = new JarFile(mArchiveSourcePath);
624
625 Certificate[] certs = null;
626
627 if ((flags&PARSE_IS_SYSTEM) != 0) {
628 // If this package comes from the system image, then we
629 // can trust it... we'll just use the AndroidManifest.xml
630 // to retrieve its signatures, not validating all of the
631 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700632 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 certs = loadCertificates(jarFile, jarEntry, readBuffer);
634 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700635 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 + " has no certificates at entry "
637 + jarEntry.getName() + "; ignoring!");
638 jarFile.close();
639 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
640 return false;
641 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700642 if (DEBUG_JAR) {
643 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 + " certs=" + (certs != null ? certs.length : 0));
645 if (certs != null) {
646 final int N = certs.length;
647 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700648 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 + certs[i].getPublicKey().getEncoded()
650 + " " + certs[i].getPublicKey());
651 }
652 }
653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700655 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700657 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700659
Kenny Rootbcc954d2011-08-08 16:19:08 -0700660 final String name = je.getName();
661
662 if (name.startsWith("META-INF/"))
663 continue;
664
665 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700666 pkg.manifestDigest =
667 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700668 }
669
670 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700671 if (DEBUG_JAR) {
672 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 + ": certs=" + certs + " ("
674 + (certs != null ? certs.length : 0) + ")");
675 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700678 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 + " has no certificates at entry "
680 + je.getName() + "; ignoring!");
681 jarFile.close();
682 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
683 return false;
684 } else if (certs == null) {
685 certs = localCerts;
686 } else {
687 // Ensure all certificates match.
688 for (int i=0; i<certs.length; i++) {
689 boolean found = false;
690 for (int j=0; j<localCerts.length; j++) {
691 if (certs[i] != null &&
692 certs[i].equals(localCerts[j])) {
693 found = true;
694 break;
695 }
696 }
697 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700698 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 + " has mismatched certificates at entry "
700 + je.getName() + "; ignoring!");
701 jarFile.close();
702 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
703 return false;
704 }
705 }
706 }
707 }
708 }
709 jarFile.close();
710
711 synchronized (mSync) {
712 mReadBuffer = readBufferRef;
713 }
714
715 if (certs != null && certs.length > 0) {
716 final int N = certs.length;
717 pkg.mSignatures = new Signature[certs.length];
718 for (int i=0; i<N; i++) {
719 pkg.mSignatures[i] = new Signature(
720 certs[i].getEncoded());
721 }
722 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700723 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 + " has no certificates; ignoring!");
725 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
726 return false;
727 }
Geremy Condraf1bcca82013-01-07 22:35:24 -0800728
729 // Add the signing KeySet to the system
730 pkg.mSigningKeys = new HashSet<PublicKey>();
731 for (int i=0; i < certs.length; i++) {
732 pkg.mSigningKeys.add(certs[i].getPublicKey());
733 }
734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700736 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
738 return false;
739 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700740 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
742 return false;
743 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700744 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
746 return false;
747 }
748
749 return true;
750 }
751
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800752 /*
753 * Utility method that retrieves just the package name and install
754 * location from the apk location at the given file path.
755 * @param packageFilePath file location of the apk
756 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700757 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800758 */
759 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700761 final XmlResourceParser parser;
762 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 try {
764 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700765 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 -0800766 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700769 if (cookie == 0) {
770 return null;
771 }
772
Kenny Root05ca4c92011-09-15 10:36:25 -0700773 final DisplayMetrics metrics = new DisplayMetrics();
774 metrics.setToDefaults();
775 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700776 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 } catch (Exception e) {
778 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700779 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 + packageFilePath, e);
781 return null;
782 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700783
784 final AttributeSet attrs = parser;
785 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800786 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700788 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700790 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700792 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 } finally {
794 if (parser != null) parser.close();
795 if (assmgr != null) assmgr.close();
796 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800797 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700798 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 return null;
800 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800801 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 }
803
804 private static String validateName(String name, boolean requiresSeparator) {
805 final int N = name.length();
806 boolean hasSep = false;
807 boolean front = true;
808 for (int i=0; i<N; i++) {
809 final char c = name.charAt(i);
810 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
811 front = false;
812 continue;
813 }
814 if (!front) {
815 if ((c >= '0' && c <= '9') || c == '_') {
816 continue;
817 }
818 }
819 if (c == '.') {
820 hasSep = true;
821 front = true;
822 continue;
823 }
824 return "bad character '" + c + "'";
825 }
826 return hasSep || !requiresSeparator
827 ? null : "must have at least one '.' separator";
828 }
829
830 private static String parsePackageName(XmlPullParser parser,
831 AttributeSet attrs, int flags, String[] outError)
832 throws IOException, XmlPullParserException {
833
834 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700835 while ((type = parser.next()) != XmlPullParser.START_TAG
836 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 ;
838 }
839
Kenny Rootd2d29252011-08-08 11:27:57 -0700840 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 outError[0] = "No start tag found";
842 return null;
843 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700844 if (DEBUG_PARSER)
845 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 if (!parser.getName().equals("manifest")) {
847 outError[0] = "No <manifest> tag";
848 return null;
849 }
850 String pkgName = attrs.getAttributeValue(null, "package");
851 if (pkgName == null || pkgName.length() == 0) {
852 outError[0] = "<manifest> does not specify package";
853 return null;
854 }
855 String nameError = validateName(pkgName, true);
856 if (nameError != null && !"android".equals(pkgName)) {
857 outError[0] = "<manifest> specifies bad package name \""
858 + pkgName + "\": " + nameError;
859 return null;
860 }
861
862 return pkgName.intern();
863 }
864
Kenny Root05ca4c92011-09-15 10:36:25 -0700865 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
866 AttributeSet attrs, int flags, String[] outError) throws IOException,
867 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800868
869 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700870 while ((type = parser.next()) != XmlPullParser.START_TAG
871 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800872 ;
873 }
874
Kenny Rootd2d29252011-08-08 11:27:57 -0700875 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800876 outError[0] = "No start tag found";
877 return null;
878 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700879 if (DEBUG_PARSER)
880 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800881 if (!parser.getName().equals("manifest")) {
882 outError[0] = "No <manifest> tag";
883 return null;
884 }
885 String pkgName = attrs.getAttributeValue(null, "package");
886 if (pkgName == null || pkgName.length() == 0) {
887 outError[0] = "<manifest> does not specify package";
888 return null;
889 }
890 String nameError = validateName(pkgName, true);
891 if (nameError != null && !"android".equals(pkgName)) {
892 outError[0] = "<manifest> specifies bad package name \""
893 + pkgName + "\": " + nameError;
894 return null;
895 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700896 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700897 int versionCode = 0;
898 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800899 for (int i = 0; i < attrs.getAttributeCount(); i++) {
900 String attr = attrs.getAttributeName(i);
901 if (attr.equals("installLocation")) {
902 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700903 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700904 numFound++;
905 } else if (attr.equals("versionCode")) {
906 versionCode = attrs.getAttributeIntValue(i, 0);
907 numFound++;
908 }
909 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800910 break;
911 }
912 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700913
914 // Only search the tree when the tag is directly below <manifest>
915 final int searchDepth = parser.getDepth() + 1;
916
917 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
918 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
919 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
920 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
921 continue;
922 }
923
924 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
925 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
926 if (verifier != null) {
927 verifiers.add(verifier);
928 }
929 }
930 }
931
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700932 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800933 }
934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 /**
936 * Temporary.
937 */
938 static public Signature stringToSignature(String str) {
939 final int N = str.length();
940 byte[] sig = new byte[N];
941 for (int i=0; i<N; i++) {
942 sig[i] = (byte)str.charAt(i);
943 }
944 return new Signature(sig);
945 }
946
947 private Package parsePackage(
948 Resources res, XmlResourceParser parser, int flags, String[] outError)
949 throws XmlPullParserException, IOException {
950 AttributeSet attrs = parser;
951
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700952 mParseInstrumentationArgs = null;
953 mParseActivityArgs = null;
954 mParseServiceArgs = null;
955 mParseProviderArgs = null;
956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 String pkgName = parsePackageName(parser, attrs, flags, outError);
958 if (pkgName == null) {
959 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
960 return null;
961 }
962 int type;
963
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700964 if (mOnlyCoreApps) {
965 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
966 if (!core) {
967 mParseError = PackageManager.INSTALL_SUCCEEDED;
968 return null;
969 }
970 }
971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 TypedArray sa = res.obtainAttributes(attrs,
976 com.android.internal.R.styleable.AndroidManifest);
977 pkg.mVersionCode = sa.getInteger(
978 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800979 pkg.mVersionName = sa.getNonConfigurationString(
980 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 if (pkg.mVersionName != null) {
982 pkg.mVersionName = pkg.mVersionName.intern();
983 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800984 String str = sa.getNonConfigurationString(
985 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
986 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 String nameError = validateName(str, true);
988 if (nameError != null && !"android".equals(pkgName)) {
989 outError[0] = "<manifest> specifies bad sharedUserId name \""
990 + str + "\": " + nameError;
991 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
992 return null;
993 }
994 pkg.mSharedUserId = str.intern();
995 pkg.mSharedUserLabel = sa.getResourceId(
996 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
997 }
998 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800999
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08001000 pkg.installLocation = sa.getInteger(
1001 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -07001002 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001003 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -07001004
1005 /* Set the global "forward lock" flag */
1006 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1007 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1008 }
1009
1010 /* Set the global "on SD card" flag */
1011 if ((flags & PARSE_ON_SDCARD) != 0) {
1012 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
1013 }
1014
Dianne Hackborn723738c2009-06-25 19:48:04 -07001015 // Resource boolean are -1, so 1 means we don't know the value.
1016 int supportsSmallScreens = 1;
1017 int supportsNormalScreens = 1;
1018 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001019 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001020 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001021 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001024 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1025 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1026 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 continue;
1028 }
1029
1030 String tagName = parser.getName();
1031 if (tagName.equals("application")) {
1032 if (foundApp) {
1033 if (RIGID_PARSER) {
1034 outError[0] = "<manifest> has more than one <application>";
1035 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1036 return null;
1037 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001038 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 XmlUtils.skipCurrentTag(parser);
1040 continue;
1041 }
1042 }
1043
1044 foundApp = true;
1045 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1046 return null;
1047 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001048 } else if (tagName.equals("keys")) {
1049 if (!parseKeys(pkg, res, parser, attrs, outError)) {
1050 return null;
1051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001053 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 return null;
1055 }
1056 } else if (tagName.equals("permission")) {
1057 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1058 return null;
1059 }
1060 } else if (tagName.equals("permission-tree")) {
1061 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1062 return null;
1063 }
1064 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001065 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1066 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 }
1068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 } else if (tagName.equals("uses-configuration")) {
1070 ConfigurationInfo cPref = new ConfigurationInfo();
1071 sa = res.obtainAttributes(attrs,
1072 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1073 cPref.reqTouchScreen = sa.getInt(
1074 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1075 Configuration.TOUCHSCREEN_UNDEFINED);
1076 cPref.reqKeyboardType = sa.getInt(
1077 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1078 Configuration.KEYBOARD_UNDEFINED);
1079 if (sa.getBoolean(
1080 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1081 false)) {
1082 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1083 }
1084 cPref.reqNavigation = sa.getInt(
1085 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1086 Configuration.NAVIGATION_UNDEFINED);
1087 if (sa.getBoolean(
1088 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1089 false)) {
1090 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1091 }
1092 sa.recycle();
1093 pkg.configPreferences.add(cPref);
1094
1095 XmlUtils.skipCurrentTag(parser);
1096
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001097 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001098 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001099 sa = res.obtainAttributes(attrs,
1100 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001101 // Note: don't allow this value to be a reference to a resource
1102 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001103 fi.name = sa.getNonResourceString(
1104 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1105 if (fi.name == null) {
1106 fi.reqGlEsVersion = sa.getInt(
1107 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1108 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1109 }
1110 if (sa.getBoolean(
1111 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1112 true)) {
1113 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1114 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001115 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001116 if (pkg.reqFeatures == null) {
1117 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1118 }
1119 pkg.reqFeatures.add(fi);
1120
1121 if (fi.name == null) {
1122 ConfigurationInfo cPref = new ConfigurationInfo();
1123 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1124 pkg.configPreferences.add(cPref);
1125 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001126
1127 XmlUtils.skipCurrentTag(parser);
1128
Dianne Hackborn851a5412009-05-08 12:06:44 -07001129 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001130 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 sa = res.obtainAttributes(attrs,
1132 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1133
Dianne Hackborn851a5412009-05-08 12:06:44 -07001134 int minVers = 0;
1135 String minCode = null;
1136 int targetVers = 0;
1137 String targetCode = null;
1138
1139 TypedValue val = sa.peekValue(
1140 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1141 if (val != null) {
1142 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1143 targetCode = minCode = val.string.toString();
1144 } else {
1145 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001146 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001147 }
1148 }
1149
1150 val = sa.peekValue(
1151 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1152 if (val != null) {
1153 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1154 targetCode = minCode = val.string.toString();
1155 } else {
1156 // If it's not a string, it's an integer.
1157 targetVers = val.data;
1158 }
1159 }
1160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 sa.recycle();
1162
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001163 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001164 if (!minCode.equals(SDK_CODENAME)) {
1165 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001166 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001167 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001168 } else {
1169 outError[0] = "Requires development platform " + minCode
1170 + " but this is a release platform.";
1171 }
1172 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1173 return null;
1174 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001175 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001176 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001177 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001178 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1179 return null;
1180 }
1181
Dianne Hackborn851a5412009-05-08 12:06:44 -07001182 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001183 if (!targetCode.equals(SDK_CODENAME)) {
1184 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001185 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001186 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001187 } else {
1188 outError[0] = "Requires development platform " + targetCode
1189 + " but this is a release platform.";
1190 }
1191 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1192 return null;
1193 }
1194 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001195 pkg.applicationInfo.targetSdkVersion
1196 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1197 } else {
1198 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 }
1201
1202 XmlUtils.skipCurrentTag(parser);
1203
Dianne Hackborn723738c2009-06-25 19:48:04 -07001204 } else if (tagName.equals("supports-screens")) {
1205 sa = res.obtainAttributes(attrs,
1206 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1207
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001208 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1209 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1210 0);
1211 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1212 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1213 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001214 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1215 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1216 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001217
Dianne Hackborn723738c2009-06-25 19:48:04 -07001218 // This is a trick to get a boolean and still able to detect
1219 // if a value was actually set.
1220 supportsSmallScreens = sa.getInteger(
1221 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1222 supportsSmallScreens);
1223 supportsNormalScreens = sa.getInteger(
1224 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1225 supportsNormalScreens);
1226 supportsLargeScreens = sa.getInteger(
1227 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1228 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001229 supportsXLargeScreens = sa.getInteger(
1230 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1231 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001232 resizeable = sa.getInteger(
1233 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001234 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001235 anyDensity = sa.getInteger(
1236 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1237 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001238
1239 sa.recycle();
1240
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001241 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001242
1243 } else if (tagName.equals("protected-broadcast")) {
1244 sa = res.obtainAttributes(attrs,
1245 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1246
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001247 // Note: don't allow this value to be a reference to a resource
1248 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001249 String name = sa.getNonResourceString(
1250 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1251
1252 sa.recycle();
1253
1254 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1255 if (pkg.protectedBroadcasts == null) {
1256 pkg.protectedBroadcasts = new ArrayList<String>();
1257 }
1258 if (!pkg.protectedBroadcasts.contains(name)) {
1259 pkg.protectedBroadcasts.add(name.intern());
1260 }
1261 }
1262
1263 XmlUtils.skipCurrentTag(parser);
1264
1265 } else if (tagName.equals("instrumentation")) {
1266 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1267 return null;
1268 }
1269
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001270 } else if (tagName.equals("original-package")) {
1271 sa = res.obtainAttributes(attrs,
1272 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1273
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001274 String orig =sa.getNonConfigurationString(
1275 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001276 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001277 if (pkg.mOriginalPackages == null) {
1278 pkg.mOriginalPackages = new ArrayList<String>();
1279 pkg.mRealPackage = pkg.packageName;
1280 }
1281 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001282 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001283
1284 sa.recycle();
1285
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001286 XmlUtils.skipCurrentTag(parser);
1287
1288 } else if (tagName.equals("adopt-permissions")) {
1289 sa = res.obtainAttributes(attrs,
1290 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1291
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001292 String name = sa.getNonConfigurationString(
1293 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001294
1295 sa.recycle();
1296
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001297 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001298 if (pkg.mAdoptPermissions == null) {
1299 pkg.mAdoptPermissions = new ArrayList<String>();
1300 }
1301 pkg.mAdoptPermissions.add(name);
1302 }
1303
1304 XmlUtils.skipCurrentTag(parser);
1305
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001306 } else if (tagName.equals("uses-gl-texture")) {
1307 // Just skip this tag
1308 XmlUtils.skipCurrentTag(parser);
1309 continue;
1310
1311 } else if (tagName.equals("compatible-screens")) {
1312 // Just skip this tag
1313 XmlUtils.skipCurrentTag(parser);
1314 continue;
Michael Wrighteaeb1902013-09-05 18:15:57 -07001315 } else if (tagName.equals("supports-input")) {
1316 XmlUtils.skipCurrentTag(parser);
1317 continue;
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001318
Dianne Hackborn854060a2009-07-09 18:14:31 -07001319 } else if (tagName.equals("eat-comment")) {
1320 // Just skip this tag
1321 XmlUtils.skipCurrentTag(parser);
1322 continue;
1323
1324 } else if (RIGID_PARSER) {
1325 outError[0] = "Bad element under <manifest>: "
1326 + parser.getName();
1327 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1328 return null;
1329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001331 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001332 + " at " + mArchiveSourcePath + " "
1333 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 XmlUtils.skipCurrentTag(parser);
1335 continue;
1336 }
1337 }
1338
1339 if (!foundApp && pkg.instrumentation.size() == 0) {
1340 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1341 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1342 }
1343
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001344 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001345 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001346 for (int ip=0; ip<NP; ip++) {
1347 final PackageParser.NewPermissionInfo npi
1348 = PackageParser.NEW_PERMISSIONS[ip];
1349 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1350 break;
1351 }
1352 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001353 if (implicitPerms == null) {
1354 implicitPerms = new StringBuilder(128);
1355 implicitPerms.append(pkg.packageName);
1356 implicitPerms.append(": compat added ");
1357 } else {
1358 implicitPerms.append(' ');
1359 }
1360 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001361 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001362 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001363 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001364 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001365 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001366 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001367 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001368
1369 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1370 for (int is=0; is<NS; is++) {
1371 final PackageParser.SplitPermissionInfo spi
1372 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001373 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1374 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001375 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001376 }
1377 for (int in=0; in<spi.newPerms.length; in++) {
1378 final String perm = spi.newPerms[in];
1379 if (!pkg.requestedPermissions.contains(perm)) {
1380 pkg.requestedPermissions.add(perm);
1381 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1382 }
1383 }
1384 }
1385
Dianne Hackborn723738c2009-06-25 19:48:04 -07001386 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1387 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001388 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001389 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1390 }
1391 if (supportsNormalScreens != 0) {
1392 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1393 }
1394 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1395 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001396 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001397 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1398 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001399 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1400 && pkg.applicationInfo.targetSdkVersion
1401 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1402 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1403 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001404 if (resizeable < 0 || (resizeable > 0
1405 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001406 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001407 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1408 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001409 if (anyDensity < 0 || (anyDensity > 0
1410 && pkg.applicationInfo.targetSdkVersion
1411 >= android.os.Build.VERSION_CODES.DONUT)) {
1412 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001413 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001414
Nick Kralevich38f130e2013-04-04 13:19:10 -07001415 /*
1416 * b/8528162: Ignore the <uses-permission android:required> attribute if
1417 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1418 * which are improperly using this attribute, even though it never worked.
1419 */
1420 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1421 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1422 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1423 }
1424 }
1425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 return pkg;
1427 }
1428
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001429 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1430 AttributeSet attrs, String[] outError)
1431 throws XmlPullParserException, IOException {
1432 TypedArray sa = res.obtainAttributes(attrs,
1433 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1434
1435 // Note: don't allow this value to be a reference to a resource
1436 // that may change.
1437 String name = sa.getNonResourceString(
1438 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001439/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001440 boolean required = sa.getBoolean(
1441 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001442*/
1443 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001444
Christopher Tatefb0676a2013-09-16 16:34:52 -07001445 int maxSdkVersion = 0;
1446 TypedValue val = sa.peekValue(
1447 com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion);
1448 if (val != null) {
1449 if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
1450 maxSdkVersion = val.data;
1451 }
1452 }
1453
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001454 sa.recycle();
1455
Christopher Tatefb0676a2013-09-16 16:34:52 -07001456 if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) {
1457 if (name != null) {
1458 int index = pkg.requestedPermissions.indexOf(name);
1459 if (index == -1) {
1460 pkg.requestedPermissions.add(name.intern());
1461 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1462 } else {
1463 if (pkg.requestedPermissionsRequired.get(index) != required) {
1464 outError[0] = "conflicting <uses-permission> entries";
1465 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1466 return false;
1467 }
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001468 }
1469 }
1470 }
1471
1472 XmlUtils.skipCurrentTag(parser);
1473 return true;
1474 }
1475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 private static String buildClassName(String pkg, CharSequence clsSeq,
1477 String[] outError) {
1478 if (clsSeq == null || clsSeq.length() <= 0) {
1479 outError[0] = "Empty class name in package " + pkg;
1480 return null;
1481 }
1482 String cls = clsSeq.toString();
1483 char c = cls.charAt(0);
1484 if (c == '.') {
1485 return (pkg + cls).intern();
1486 }
1487 if (cls.indexOf('.') < 0) {
1488 StringBuilder b = new StringBuilder(pkg);
1489 b.append('.');
1490 b.append(cls);
1491 return b.toString().intern();
1492 }
1493 if (c >= 'a' && c <= 'z') {
1494 return cls.intern();
1495 }
1496 outError[0] = "Bad class name " + cls + " in package " + pkg;
1497 return null;
1498 }
1499
1500 private static String buildCompoundName(String pkg,
1501 CharSequence procSeq, String type, String[] outError) {
1502 String proc = procSeq.toString();
1503 char c = proc.charAt(0);
1504 if (pkg != null && c == ':') {
1505 if (proc.length() < 2) {
1506 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1507 + ": must be at least two characters";
1508 return null;
1509 }
1510 String subName = proc.substring(1);
1511 String nameError = validateName(subName, false);
1512 if (nameError != null) {
1513 outError[0] = "Invalid " + type + " name " + proc + " in package "
1514 + pkg + ": " + nameError;
1515 return null;
1516 }
1517 return (pkg + proc).intern();
1518 }
1519 String nameError = validateName(proc, true);
1520 if (nameError != null && !"system".equals(proc)) {
1521 outError[0] = "Invalid " + type + " name " + proc + " in package "
1522 + pkg + ": " + nameError;
1523 return null;
1524 }
1525 return proc.intern();
1526 }
1527
1528 private static String buildProcessName(String pkg, String defProc,
1529 CharSequence procSeq, int flags, String[] separateProcesses,
1530 String[] outError) {
1531 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1532 return defProc != null ? defProc : pkg;
1533 }
1534 if (separateProcesses != null) {
1535 for (int i=separateProcesses.length-1; i>=0; i--) {
1536 String sp = separateProcesses[i];
1537 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1538 return pkg;
1539 }
1540 }
1541 }
1542 if (procSeq == null || procSeq.length() <= 0) {
1543 return defProc;
1544 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001545 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 }
1547
1548 private static String buildTaskAffinityName(String pkg, String defProc,
1549 CharSequence procSeq, String[] outError) {
1550 if (procSeq == null) {
1551 return defProc;
1552 }
1553 if (procSeq.length() <= 0) {
1554 return null;
1555 }
1556 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1557 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001558
1559 private boolean parseKeys(Package owner, Resources res,
1560 XmlPullParser parser, AttributeSet attrs, String[] outError)
1561 throws XmlPullParserException, IOException {
1562 // we've encountered the 'keys' tag
1563 // all the keys and keysets that we want must be defined here
1564 // so we're going to iterate over the parser and pull out the things we want
1565 int outerDepth = parser.getDepth();
1566
1567 int type;
1568 PublicKey currentKey = null;
Kenny Root37dca152013-07-10 14:01:49 -07001569 int currentKeyDepth = -1;
Geremy Condraf1bcca82013-01-07 22:35:24 -08001570 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1571 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1572 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1573 if (type == XmlPullParser.END_TAG) {
Kenny Root37dca152013-07-10 14:01:49 -07001574 if (parser.getDepth() == currentKeyDepth) {
1575 currentKey = null;
1576 currentKeyDepth = -1;
1577 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001578 continue;
1579 }
1580 String tagname = parser.getName();
1581 if (tagname.equals("publicKey")) {
1582 final TypedArray sa = res.obtainAttributes(attrs,
1583 com.android.internal.R.styleable.PublicKey);
1584 final String encodedKey = sa.getNonResourceString(
1585 com.android.internal.R.styleable.PublicKey_value);
1586 currentKey = parsePublicKey(encodedKey);
Kenny Root37dca152013-07-10 14:01:49 -07001587 if (currentKey == null) {
1588 Slog.w(TAG, "No valid key in 'publicKey' tag at "
1589 + parser.getPositionDescription());
1590 sa.recycle();
1591 continue;
1592 }
1593 currentKeyDepth = parser.getDepth();
Geremy Condraf1bcca82013-01-07 22:35:24 -08001594 definedKeySets.put(currentKey, new HashSet<String>());
1595 sa.recycle();
Kenny Root2758e292013-07-08 09:32:59 -07001596 } else if (tagname.equals("keyset")) {
Kenny Root37dca152013-07-10 14:01:49 -07001597 if (currentKey == null) {
1598 Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
1599 + parser.getPositionDescription());
1600 continue;
1601 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001602 final TypedArray sa = res.obtainAttributes(attrs,
1603 com.android.internal.R.styleable.KeySet);
1604 final String name = sa.getNonResourceString(
1605 com.android.internal.R.styleable.KeySet_name);
1606 definedKeySets.get(currentKey).add(name);
1607 sa.recycle();
1608 } else if (RIGID_PARSER) {
1609 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1610 + " at " + mArchiveSourcePath + " "
1611 + parser.getPositionDescription());
1612 return false;
1613 } else {
1614 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1615 + " at " + mArchiveSourcePath + " "
1616 + parser.getPositionDescription());
1617 XmlUtils.skipCurrentTag(parser);
1618 continue;
1619 }
1620 }
1621
1622 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1623 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1624 PublicKey key = e.getKey();
1625 Set<String> keySetNames = e.getValue();
1626 for (String alias : keySetNames) {
1627 if (owner.mKeySetMapping.containsKey(alias)) {
1628 owner.mKeySetMapping.get(alias).add(key);
1629 } else {
1630 Set<PublicKey> keys = new HashSet<PublicKey>();
1631 keys.add(key);
1632 owner.mKeySetMapping.put(alias, keys);
1633 }
1634 }
1635 }
1636
1637 return true;
1638 }
1639
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001640 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 XmlPullParser parser, AttributeSet attrs, String[] outError)
1642 throws XmlPullParserException, IOException {
1643 PermissionGroup perm = new PermissionGroup(owner);
1644
1645 TypedArray sa = res.obtainAttributes(attrs,
1646 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1647
1648 if (!parsePackageItemInfo(owner, perm.info, outError,
1649 "<permission-group>", sa,
1650 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1651 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001652 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1653 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 sa.recycle();
1655 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1656 return null;
1657 }
1658
1659 perm.info.descriptionRes = sa.getResourceId(
1660 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1661 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001662 perm.info.flags = sa.getInt(
1663 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001664 perm.info.priority = sa.getInt(
1665 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001666 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001667 perm.info.priority = 0;
1668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669
1670 sa.recycle();
1671
1672 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1673 outError)) {
1674 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1675 return null;
1676 }
1677
1678 owner.permissionGroups.add(perm);
1679
1680 return perm;
1681 }
1682
1683 private Permission parsePermission(Package owner, Resources res,
1684 XmlPullParser parser, AttributeSet attrs, String[] outError)
1685 throws XmlPullParserException, IOException {
1686 Permission perm = new Permission(owner);
1687
1688 TypedArray sa = res.obtainAttributes(attrs,
1689 com.android.internal.R.styleable.AndroidManifestPermission);
1690
1691 if (!parsePackageItemInfo(owner, perm.info, outError,
1692 "<permission>", sa,
1693 com.android.internal.R.styleable.AndroidManifestPermission_name,
1694 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001695 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1696 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 sa.recycle();
1698 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1699 return null;
1700 }
1701
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001702 // Note: don't allow this value to be a reference to a resource
1703 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 perm.info.group = sa.getNonResourceString(
1705 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1706 if (perm.info.group != null) {
1707 perm.info.group = perm.info.group.intern();
1708 }
1709
1710 perm.info.descriptionRes = sa.getResourceId(
1711 com.android.internal.R.styleable.AndroidManifestPermission_description,
1712 0);
1713
1714 perm.info.protectionLevel = sa.getInt(
1715 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1716 PermissionInfo.PROTECTION_NORMAL);
1717
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001718 perm.info.flags = sa.getInt(
1719 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 if (perm.info.protectionLevel == -1) {
1724 outError[0] = "<permission> does not specify protectionLevel";
1725 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1726 return null;
1727 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001728
1729 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1730
1731 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1732 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1733 PermissionInfo.PROTECTION_SIGNATURE) {
1734 outError[0] = "<permission> protectionLevel specifies a flag but is "
1735 + "not based on signature type";
1736 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1737 return null;
1738 }
1739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740
1741 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1742 outError)) {
1743 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1744 return null;
1745 }
1746
1747 owner.permissions.add(perm);
1748
1749 return perm;
1750 }
1751
1752 private Permission parsePermissionTree(Package owner, Resources res,
1753 XmlPullParser parser, AttributeSet attrs, String[] outError)
1754 throws XmlPullParserException, IOException {
1755 Permission perm = new Permission(owner);
1756
1757 TypedArray sa = res.obtainAttributes(attrs,
1758 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1759
1760 if (!parsePackageItemInfo(owner, perm.info, outError,
1761 "<permission-tree>", sa,
1762 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1763 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001764 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1765 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 sa.recycle();
1767 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1768 return null;
1769 }
1770
1771 sa.recycle();
1772
1773 int index = perm.info.name.indexOf('.');
1774 if (index > 0) {
1775 index = perm.info.name.indexOf('.', index+1);
1776 }
1777 if (index < 0) {
1778 outError[0] = "<permission-tree> name has less than three segments: "
1779 + perm.info.name;
1780 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1781 return null;
1782 }
1783
1784 perm.info.descriptionRes = 0;
1785 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1786 perm.tree = true;
1787
1788 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1789 outError)) {
1790 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1791 return null;
1792 }
1793
1794 owner.permissions.add(perm);
1795
1796 return perm;
1797 }
1798
1799 private Instrumentation parseInstrumentation(Package owner, Resources res,
1800 XmlPullParser parser, AttributeSet attrs, String[] outError)
1801 throws XmlPullParserException, IOException {
1802 TypedArray sa = res.obtainAttributes(attrs,
1803 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1804
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001805 if (mParseInstrumentationArgs == null) {
1806 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1807 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1808 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001809 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1810 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001811 mParseInstrumentationArgs.tag = "<instrumentation>";
1812 }
1813
1814 mParseInstrumentationArgs.sa = sa;
1815
1816 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1817 new InstrumentationInfo());
1818 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 sa.recycle();
1820 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1821 return null;
1822 }
1823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001825 // Note: don't allow this value to be a reference to a resource
1826 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 str = sa.getNonResourceString(
1828 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1829 a.info.targetPackage = str != null ? str.intern() : null;
1830
1831 a.info.handleProfiling = sa.getBoolean(
1832 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1833 false);
1834
1835 a.info.functionalTest = sa.getBoolean(
1836 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1837 false);
1838
1839 sa.recycle();
1840
1841 if (a.info.targetPackage == null) {
1842 outError[0] = "<instrumentation> does not specify targetPackage";
1843 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1844 return null;
1845 }
1846
1847 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1848 outError)) {
1849 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1850 return null;
1851 }
1852
1853 owner.instrumentation.add(a);
1854
1855 return a;
1856 }
1857
1858 private boolean parseApplication(Package owner, Resources res,
1859 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1860 throws XmlPullParserException, IOException {
1861 final ApplicationInfo ai = owner.applicationInfo;
1862 final String pkgName = owner.applicationInfo.packageName;
1863
1864 TypedArray sa = res.obtainAttributes(attrs,
1865 com.android.internal.R.styleable.AndroidManifestApplication);
1866
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001867 String name = sa.getNonConfigurationString(
1868 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 if (name != null) {
1870 ai.className = buildClassName(pkgName, name, outError);
1871 if (ai.className == null) {
1872 sa.recycle();
1873 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1874 return false;
1875 }
1876 }
1877
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001878 String manageSpaceActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001879 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
1880 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 if (manageSpaceActivity != null) {
1882 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1883 outError);
1884 }
1885
Christopher Tate181fafa2009-05-14 11:12:14 -07001886 boolean allowBackup = sa.getBoolean(
1887 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1888 if (allowBackup) {
1889 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001890
Christopher Tate3de55bc2010-03-12 17:28:08 -08001891 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1892 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001893 String backupAgent = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001894 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
1895 Configuration.NATIVE_CONFIG_VERSION);
Christopher Tate181fafa2009-05-14 11:12:14 -07001896 if (backupAgent != null) {
1897 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001898 if (DEBUG_BACKUP) {
1899 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001900 + " from " + pkgName + "+" + backupAgent);
1901 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001902
1903 if (sa.getBoolean(
1904 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1905 true)) {
1906 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1907 }
1908 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001909 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1910 false)) {
1911 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1912 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001913 }
1914 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 TypedValue v = sa.peekValue(
1917 com.android.internal.R.styleable.AndroidManifestApplication_label);
1918 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1919 ai.nonLocalizedLabel = v.coerceToString();
1920 }
1921
1922 ai.icon = sa.getResourceId(
1923 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001924 ai.logo = sa.getResourceId(
1925 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001927 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 ai.descriptionRes = sa.getResourceId(
1929 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1930
1931 if ((flags&PARSE_IS_SYSTEM) != 0) {
1932 if (sa.getBoolean(
1933 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1934 false)) {
1935 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1936 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001937 }
1938
1939 if (sa.getBoolean(
1940 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1941 false)) {
1942 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001943 }
1944
1945 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1946 .AndroidManifestApplication_restrictedAccountType);
1947 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1948 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 }
1950
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001951 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1952 .AndroidManifestApplication_requiredAccountType);
1953 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1954 owner.mRequiredAccountType = requiredAccountType;
1955 }
1956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (sa.getBoolean(
1958 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1959 false)) {
1960 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1961 }
1962
1963 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001964 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001965 false)) {
1966 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1967 }
1968
Romain Guy529b60a2010-08-03 18:05:47 -07001969 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001970 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001971 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001972
1973 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1975 true)) {
1976 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1977 }
1978
1979 if (sa.getBoolean(
1980 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1981 false)) {
1982 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1983 }
1984
1985 if (sa.getBoolean(
1986 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1987 true)) {
1988 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1989 }
1990
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001991 if (sa.getBoolean(
1992 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001993 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001994 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1995 }
1996
Jason parksa3cdaa52011-01-13 14:15:43 -06001997 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001998 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001999 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08002000 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06002001 }
2002
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07002003 if (sa.getBoolean(
2004 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
2005 false /* default is no RTL support*/)) {
2006 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
2007 }
2008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002010 str = sa.getNonConfigurationString(
2011 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
2013
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002014 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2015 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002016 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
2017 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002018 } else {
2019 // Some older apps have been seen to use a resource reference
2020 // here that on older builds was ignored (with a warning). We
2021 // need to continue to do this for them so they don't break.
2022 str = sa.getNonResourceString(
2023 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
2024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
2026 str, outError);
2027
2028 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002029 CharSequence pname;
2030 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2031 pname = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002032 com.android.internal.R.styleable.AndroidManifestApplication_process,
2033 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002034 } else {
2035 // Some older apps have been seen to use a resource reference
2036 // here that on older builds was ignored (with a warning). We
2037 // need to continue to do this for them so they don't break.
2038 pname = sa.getNonResourceString(
2039 com.android.internal.R.styleable.AndroidManifestApplication_process);
2040 }
2041 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 flags, mSeparateProcesses, outError);
2043
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002044 ai.enabled = sa.getBoolean(
2045 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002046
Dianne Hackborn02486b12010-08-26 14:18:37 -07002047 if (false) {
2048 if (sa.getBoolean(
2049 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2050 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002051 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002052
2053 // A heavy-weight application can not be in a custom process.
2054 // We can do direct compare because we intern all strings.
2055 if (ai.processName != null && ai.processName != ai.packageName) {
2056 outError[0] = "cantSaveState applications can not use custom processes";
2057 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002058 }
2059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
2061
Adam Powell269248d2011-08-02 10:26:54 -07002062 ai.uiOptions = sa.getInt(
2063 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 sa.recycle();
2066
2067 if (outError[0] != null) {
2068 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2069 return false;
2070 }
2071
2072 final int innerDepth = parser.getDepth();
2073
2074 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002075 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2076 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2077 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 continue;
2079 }
2080
2081 String tagName = parser.getName();
2082 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002083 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2084 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 if (a == null) {
2086 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2087 return false;
2088 }
2089
2090 owner.activities.add(a);
2091
2092 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002093 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 if (a == null) {
2095 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2096 return false;
2097 }
2098
2099 owner.receivers.add(a);
2100
2101 } else if (tagName.equals("service")) {
2102 Service s = parseService(owner, res, parser, attrs, flags, outError);
2103 if (s == null) {
2104 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2105 return false;
2106 }
2107
2108 owner.services.add(s);
2109
2110 } else if (tagName.equals("provider")) {
2111 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2112 if (p == null) {
2113 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2114 return false;
2115 }
2116
2117 owner.providers.add(p);
2118
2119 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002120 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121 if (a == null) {
2122 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2123 return false;
2124 }
2125
2126 owner.activities.add(a);
2127
2128 } else if (parser.getName().equals("meta-data")) {
2129 // note: application meta-data is stored off to the side, so it can
2130 // remain null in the primary copy (we like to avoid extra copies because
2131 // it can be large)
2132 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2133 outError)) == null) {
2134 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2135 return false;
2136 }
2137
Dianne Hackbornc895be72013-03-11 17:48:43 -07002138 } else if (tagName.equals("library")) {
2139 sa = res.obtainAttributes(attrs,
2140 com.android.internal.R.styleable.AndroidManifestLibrary);
2141
2142 // Note: don't allow this value to be a reference to a resource
2143 // that may change.
2144 String lname = sa.getNonResourceString(
2145 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2146
2147 sa.recycle();
2148
2149 if (lname != null) {
2150 if (owner.libraryNames == null) {
2151 owner.libraryNames = new ArrayList<String>();
2152 }
2153 if (!owner.libraryNames.contains(lname)) {
2154 owner.libraryNames.add(lname.intern());
2155 }
2156 }
2157
2158 XmlUtils.skipCurrentTag(parser);
2159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 } else if (tagName.equals("uses-library")) {
2161 sa = res.obtainAttributes(attrs,
2162 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2163
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002164 // Note: don't allow this value to be a reference to a resource
2165 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 String lname = sa.getNonResourceString(
2167 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002168 boolean req = sa.getBoolean(
2169 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2170 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171
2172 sa.recycle();
2173
Dianne Hackborn49237342009-08-27 20:08:01 -07002174 if (lname != null) {
2175 if (req) {
2176 if (owner.usesLibraries == null) {
2177 owner.usesLibraries = new ArrayList<String>();
2178 }
2179 if (!owner.usesLibraries.contains(lname)) {
2180 owner.usesLibraries.add(lname.intern());
2181 }
2182 } else {
2183 if (owner.usesOptionalLibraries == null) {
2184 owner.usesOptionalLibraries = new ArrayList<String>();
2185 }
2186 if (!owner.usesOptionalLibraries.contains(lname)) {
2187 owner.usesOptionalLibraries.add(lname.intern());
2188 }
2189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 }
2191
2192 XmlUtils.skipCurrentTag(parser);
2193
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002194 } else if (tagName.equals("uses-package")) {
2195 // Dependencies for app installers; we don't currently try to
2196 // enforce this.
2197 XmlUtils.skipCurrentTag(parser);
2198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 } else {
2200 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002201 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002202 + " at " + mArchiveSourcePath + " "
2203 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 XmlUtils.skipCurrentTag(parser);
2205 continue;
2206 } else {
2207 outError[0] = "Bad element under <application>: " + tagName;
2208 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2209 return false;
2210 }
2211 }
2212 }
2213
2214 return true;
2215 }
2216
2217 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2218 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002219 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002220 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 if (name == null) {
2222 outError[0] = tag + " does not specify android:name";
2223 return false;
2224 }
2225
2226 outInfo.name
2227 = buildClassName(owner.applicationInfo.packageName, name, outError);
2228 if (outInfo.name == null) {
2229 return false;
2230 }
2231
2232 int iconVal = sa.getResourceId(iconRes, 0);
2233 if (iconVal != 0) {
2234 outInfo.icon = iconVal;
2235 outInfo.nonLocalizedLabel = null;
2236 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002237
2238 int logoVal = sa.getResourceId(logoRes, 0);
2239 if (logoVal != 0) {
2240 outInfo.logo = logoVal;
2241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242
2243 TypedValue v = sa.peekValue(labelRes);
2244 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2245 outInfo.nonLocalizedLabel = v.coerceToString();
2246 }
2247
2248 outInfo.packageName = owner.packageName;
2249
2250 return true;
2251 }
2252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 private Activity parseActivity(Package owner, Resources res,
2254 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002255 boolean receiver, boolean hardwareAccelerated)
2256 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 TypedArray sa = res.obtainAttributes(attrs,
2258 com.android.internal.R.styleable.AndroidManifestActivity);
2259
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002260 if (mParseActivityArgs == null) {
2261 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2262 com.android.internal.R.styleable.AndroidManifestActivity_name,
2263 com.android.internal.R.styleable.AndroidManifestActivity_label,
2264 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002265 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002266 mSeparateProcesses,
2267 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002268 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002269 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2270 }
2271
2272 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2273 mParseActivityArgs.sa = sa;
2274 mParseActivityArgs.flags = flags;
2275
2276 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2277 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 sa.recycle();
2279 return null;
2280 }
2281
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002282 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2284 if (setExported) {
2285 a.info.exported = sa.getBoolean(
2286 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2287 }
2288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 a.info.theme = sa.getResourceId(
2290 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2291
Adam Powell269248d2011-08-02 10:26:54 -07002292 a.info.uiOptions = sa.getInt(
2293 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2294 a.info.applicationInfo.uiOptions);
2295
Adam Powelldd8fab22012-03-22 17:47:27 -07002296 String parentName = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002297 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName,
2298 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002299 if (parentName != null) {
2300 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2301 if (outError[0] == null) {
2302 a.info.parentActivityName = parentClassName;
2303 } else {
2304 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2305 parentName);
2306 outError[0] = null;
2307 }
2308 }
2309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002311 str = sa.getNonConfigurationString(
2312 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 if (str == null) {
2314 a.info.permission = owner.applicationInfo.permission;
2315 } else {
2316 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2317 }
2318
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002319 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002320 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity,
2321 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2323 owner.applicationInfo.taskAffinity, str, outError);
2324
2325 a.info.flags = 0;
2326 if (sa.getBoolean(
2327 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2328 false)) {
2329 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2330 }
2331
2332 if (sa.getBoolean(
2333 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2334 false)) {
2335 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2336 }
2337
2338 if (sa.getBoolean(
2339 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2340 false)) {
2341 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2342 }
2343
2344 if (sa.getBoolean(
2345 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2346 false)) {
2347 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2348 }
2349
2350 if (sa.getBoolean(
2351 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2352 false)) {
2353 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2354 }
2355
2356 if (sa.getBoolean(
2357 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2358 false)) {
2359 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2360 }
2361
2362 if (sa.getBoolean(
2363 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2364 false)) {
2365 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2366 }
2367
2368 if (sa.getBoolean(
2369 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2370 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2371 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2372 }
2373
Dianne Hackbornffa42482009-09-23 22:20:11 -07002374 if (sa.getBoolean(
2375 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2376 false)) {
2377 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2378 }
2379
Daniel Sandler613dde42010-06-21 13:46:39 -04002380 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002381 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2382 false)) {
2383 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2384 }
2385
2386 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002387 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2388 false)) {
2389 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2390 }
Craig Mautner5962b122012-10-05 14:45:52 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002393 if (sa.getBoolean(
2394 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2395 hardwareAccelerated)) {
2396 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2397 }
2398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 a.info.launchMode = sa.getInt(
2400 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2401 ActivityInfo.LAUNCH_MULTIPLE);
2402 a.info.screenOrientation = sa.getInt(
2403 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2404 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2405 a.info.configChanges = sa.getInt(
2406 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2407 0);
2408 a.info.softInputMode = sa.getInt(
2409 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2410 0);
2411 } else {
2412 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2413 a.info.configChanges = 0;
2414 }
2415
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002416 if (receiver) {
2417 if (sa.getBoolean(
2418 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2419 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002420 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002421 if (a.info.exported) {
2422 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2423 + a.className + " at " + mArchiveSourcePath + " "
2424 + parser.getPositionDescription());
2425 a.info.exported = false;
2426 }
2427 setExported = true;
2428 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002429 if (sa.getBoolean(
2430 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2431 false)) {
2432 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2433 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002434 }
2435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 sa.recycle();
2437
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002438 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002439 // A heavy-weight application can not have receives in its main process
2440 // We can do direct compare because we intern all strings.
2441 if (a.info.processName == owner.packageName) {
2442 outError[0] = "Heavy-weight applications can not have receivers in main process";
2443 }
2444 }
2445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 if (outError[0] != null) {
2447 return null;
2448 }
2449
2450 int outerDepth = parser.getDepth();
2451 int type;
2452 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2453 && (type != XmlPullParser.END_TAG
2454 || parser.getDepth() > outerDepth)) {
2455 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2456 continue;
2457 }
2458
2459 if (parser.getName().equals("intent-filter")) {
2460 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002461 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 return null;
2463 }
2464 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002465 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002466 + mArchiveSourcePath + " "
2467 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 } else {
2469 a.intents.add(intent);
2470 }
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002471 } else if (!receiver && parser.getName().equals("preferred")) {
2472 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2473 if (!parseIntent(res, parser, attrs, false, intent, outError)) {
2474 return null;
2475 }
2476 if (intent.countActions() == 0) {
2477 Slog.w(TAG, "No actions in preferred at "
2478 + mArchiveSourcePath + " "
2479 + parser.getPositionDescription());
2480 } else {
2481 if (owner.preferredActivityFilters == null) {
2482 owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>();
2483 }
2484 owner.preferredActivityFilters.add(intent);
2485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 } else if (parser.getName().equals("meta-data")) {
2487 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2488 outError)) == null) {
2489 return null;
2490 }
2491 } else {
2492 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002493 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002495 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002496 + " at " + mArchiveSourcePath + " "
2497 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002499 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002500 + " at " + mArchiveSourcePath + " "
2501 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 }
2503 XmlUtils.skipCurrentTag(parser);
2504 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002506 if (receiver) {
2507 outError[0] = "Bad element under <receiver>: " + parser.getName();
2508 } else {
2509 outError[0] = "Bad element under <activity>: " + parser.getName();
2510 }
2511 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 }
2514 }
2515
2516 if (!setExported) {
2517 a.info.exported = a.intents.size() > 0;
2518 }
2519
2520 return a;
2521 }
2522
2523 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002524 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2525 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 TypedArray sa = res.obtainAttributes(attrs,
2527 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2528
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002529 String targetActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002530 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity,
2531 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 if (targetActivity == null) {
2533 outError[0] = "<activity-alias> does not specify android:targetActivity";
2534 sa.recycle();
2535 return null;
2536 }
2537
2538 targetActivity = buildClassName(owner.applicationInfo.packageName,
2539 targetActivity, outError);
2540 if (targetActivity == null) {
2541 sa.recycle();
2542 return null;
2543 }
2544
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002545 if (mParseActivityAliasArgs == null) {
2546 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2547 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2548 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2549 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002550 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002551 mSeparateProcesses,
2552 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002553 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002554 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2555 mParseActivityAliasArgs.tag = "<activity-alias>";
2556 }
2557
2558 mParseActivityAliasArgs.sa = sa;
2559 mParseActivityAliasArgs.flags = flags;
2560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 Activity target = null;
2562
2563 final int NA = owner.activities.size();
2564 for (int i=0; i<NA; i++) {
2565 Activity t = owner.activities.get(i);
2566 if (targetActivity.equals(t.info.name)) {
2567 target = t;
2568 break;
2569 }
2570 }
2571
2572 if (target == null) {
2573 outError[0] = "<activity-alias> target activity " + targetActivity
2574 + " not found in manifest";
2575 sa.recycle();
2576 return null;
2577 }
2578
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002579 ActivityInfo info = new ActivityInfo();
2580 info.targetActivity = targetActivity;
2581 info.configChanges = target.info.configChanges;
2582 info.flags = target.info.flags;
2583 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002584 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002585 info.labelRes = target.info.labelRes;
2586 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2587 info.launchMode = target.info.launchMode;
2588 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002589 if (info.descriptionRes == 0) {
2590 info.descriptionRes = target.info.descriptionRes;
2591 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002592 info.screenOrientation = target.info.screenOrientation;
2593 info.taskAffinity = target.info.taskAffinity;
2594 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002595 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002596 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002597 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002598
2599 Activity a = new Activity(mParseActivityAliasArgs, info);
2600 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 sa.recycle();
2602 return null;
2603 }
2604
2605 final boolean setExported = sa.hasValue(
2606 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2607 if (setExported) {
2608 a.info.exported = sa.getBoolean(
2609 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2610 }
2611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002613 str = sa.getNonConfigurationString(
2614 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 if (str != null) {
2616 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2617 }
2618
Adam Powelldd8fab22012-03-22 17:47:27 -07002619 String parentName = sa.getNonConfigurationString(
2620 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002621 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002622 if (parentName != null) {
2623 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2624 if (outError[0] == null) {
2625 a.info.parentActivityName = parentClassName;
2626 } else {
2627 Log.e(TAG, "Activity alias " + a.info.name +
2628 " specified invalid parentActivityName " + parentName);
2629 outError[0] = null;
2630 }
2631 }
2632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 sa.recycle();
2634
2635 if (outError[0] != null) {
2636 return null;
2637 }
2638
2639 int outerDepth = parser.getDepth();
2640 int type;
2641 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2642 && (type != XmlPullParser.END_TAG
2643 || parser.getDepth() > outerDepth)) {
2644 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2645 continue;
2646 }
2647
2648 if (parser.getName().equals("intent-filter")) {
2649 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002650 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 return null;
2652 }
2653 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002654 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002655 + mArchiveSourcePath + " "
2656 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 } else {
2658 a.intents.add(intent);
2659 }
2660 } else if (parser.getName().equals("meta-data")) {
2661 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2662 outError)) == null) {
2663 return null;
2664 }
2665 } else {
2666 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002667 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002668 + " at " + mArchiveSourcePath + " "
2669 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 XmlUtils.skipCurrentTag(parser);
2671 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002672 } else {
2673 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2674 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 }
2677 }
2678
2679 if (!setExported) {
2680 a.info.exported = a.intents.size() > 0;
2681 }
2682
2683 return a;
2684 }
2685
2686 private Provider parseProvider(Package owner, Resources res,
2687 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2688 throws XmlPullParserException, IOException {
2689 TypedArray sa = res.obtainAttributes(attrs,
2690 com.android.internal.R.styleable.AndroidManifestProvider);
2691
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002692 if (mParseProviderArgs == null) {
2693 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2694 com.android.internal.R.styleable.AndroidManifestProvider_name,
2695 com.android.internal.R.styleable.AndroidManifestProvider_label,
2696 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002697 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002698 mSeparateProcesses,
2699 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002700 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002701 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2702 mParseProviderArgs.tag = "<provider>";
2703 }
2704
2705 mParseProviderArgs.sa = sa;
2706 mParseProviderArgs.flags = flags;
2707
2708 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2709 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 sa.recycle();
2711 return null;
2712 }
2713
Nick Kralevichf097b162012-07-28 12:43:48 -07002714 boolean providerExportedDefault = false;
2715
2716 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2717 // For compatibility, applications targeting API level 16 or lower
2718 // should have their content providers exported by default, unless they
2719 // specify otherwise.
2720 providerExportedDefault = true;
2721 }
2722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002724 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2725 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002727 String cpname = sa.getNonConfigurationString(
2728 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729
2730 p.info.isSyncable = sa.getBoolean(
2731 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2732 false);
2733
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002734 String permission = sa.getNonConfigurationString(
2735 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2736 String str = sa.getNonConfigurationString(
2737 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 if (str == null) {
2739 str = permission;
2740 }
2741 if (str == null) {
2742 p.info.readPermission = owner.applicationInfo.permission;
2743 } else {
2744 p.info.readPermission =
2745 str.length() > 0 ? str.toString().intern() : null;
2746 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002747 str = sa.getNonConfigurationString(
2748 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 if (str == null) {
2750 str = permission;
2751 }
2752 if (str == null) {
2753 p.info.writePermission = owner.applicationInfo.permission;
2754 } else {
2755 p.info.writePermission =
2756 str.length() > 0 ? str.toString().intern() : null;
2757 }
2758
2759 p.info.grantUriPermissions = sa.getBoolean(
2760 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2761 false);
2762
2763 p.info.multiprocess = sa.getBoolean(
2764 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2765 false);
2766
2767 p.info.initOrder = sa.getInt(
2768 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2769 0);
2770
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002771 p.info.flags = 0;
2772
2773 if (sa.getBoolean(
2774 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2775 false)) {
2776 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2777 if (p.info.exported) {
2778 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2779 + p.className + " at " + mArchiveSourcePath + " "
2780 + parser.getPositionDescription());
2781 p.info.exported = false;
2782 }
2783 }
2784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 sa.recycle();
2786
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002787 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002788 // A heavy-weight application can not have providers in its main process
2789 // We can do direct compare because we intern all strings.
2790 if (p.info.processName == owner.packageName) {
2791 outError[0] = "Heavy-weight applications can not have providers in main process";
2792 return null;
2793 }
2794 }
2795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002797 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 return null;
2799 }
2800 p.info.authority = cpname.intern();
2801
2802 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2803 return null;
2804 }
2805
2806 return p;
2807 }
2808
2809 private boolean parseProviderTags(Resources res,
2810 XmlPullParser parser, AttributeSet attrs,
2811 Provider outInfo, String[] outError)
2812 throws XmlPullParserException, IOException {
2813 int outerDepth = parser.getDepth();
2814 int type;
2815 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2816 && (type != XmlPullParser.END_TAG
2817 || parser.getDepth() > outerDepth)) {
2818 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2819 continue;
2820 }
2821
2822 if (parser.getName().equals("meta-data")) {
2823 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2824 outInfo.metaData, outError)) == null) {
2825 return false;
2826 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 } else if (parser.getName().equals("grant-uri-permission")) {
2829 TypedArray sa = res.obtainAttributes(attrs,
2830 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2831
2832 PatternMatcher pa = null;
2833
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002834 String str = sa.getNonConfigurationString(
2835 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 if (str != null) {
2837 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2838 }
2839
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002840 str = sa.getNonConfigurationString(
2841 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 if (str != null) {
2843 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2844 }
2845
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002846 str = sa.getNonConfigurationString(
2847 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 if (str != null) {
2849 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2850 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 sa.recycle();
2853
2854 if (pa != null) {
2855 if (outInfo.info.uriPermissionPatterns == null) {
2856 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2857 outInfo.info.uriPermissionPatterns[0] = pa;
2858 } else {
2859 final int N = outInfo.info.uriPermissionPatterns.length;
2860 PatternMatcher[] newp = new PatternMatcher[N+1];
2861 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2862 newp[N] = pa;
2863 outInfo.info.uriPermissionPatterns = newp;
2864 }
2865 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002866 } else {
2867 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002868 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002869 + parser.getName() + " at " + mArchiveSourcePath + " "
2870 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002871 XmlUtils.skipCurrentTag(parser);
2872 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002873 } else {
2874 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2875 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002876 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002877 }
2878 XmlUtils.skipCurrentTag(parser);
2879
2880 } else if (parser.getName().equals("path-permission")) {
2881 TypedArray sa = res.obtainAttributes(attrs,
2882 com.android.internal.R.styleable.AndroidManifestPathPermission);
2883
2884 PathPermission pa = null;
2885
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002886 String permission = sa.getNonConfigurationString(
2887 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2888 String readPermission = sa.getNonConfigurationString(
2889 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002890 if (readPermission == null) {
2891 readPermission = permission;
2892 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002893 String writePermission = sa.getNonConfigurationString(
2894 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002895 if (writePermission == null) {
2896 writePermission = permission;
2897 }
2898
2899 boolean havePerm = false;
2900 if (readPermission != null) {
2901 readPermission = readPermission.intern();
2902 havePerm = true;
2903 }
2904 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002905 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002906 havePerm = true;
2907 }
2908
2909 if (!havePerm) {
2910 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002911 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002912 + parser.getName() + " at " + mArchiveSourcePath + " "
2913 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002914 XmlUtils.skipCurrentTag(parser);
2915 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002916 } else {
2917 outError[0] = "No readPermission or writePermssion for <path-permission>";
2918 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002919 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002920 }
2921
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002922 String path = sa.getNonConfigurationString(
2923 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002924 if (path != null) {
2925 pa = new PathPermission(path,
2926 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2927 }
2928
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002929 path = sa.getNonConfigurationString(
2930 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002931 if (path != null) {
2932 pa = new PathPermission(path,
2933 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2934 }
2935
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002936 path = sa.getNonConfigurationString(
2937 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002938 if (path != null) {
2939 pa = new PathPermission(path,
2940 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2941 }
2942
2943 sa.recycle();
2944
2945 if (pa != null) {
2946 if (outInfo.info.pathPermissions == null) {
2947 outInfo.info.pathPermissions = new PathPermission[1];
2948 outInfo.info.pathPermissions[0] = pa;
2949 } else {
2950 final int N = outInfo.info.pathPermissions.length;
2951 PathPermission[] newp = new PathPermission[N+1];
2952 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2953 newp[N] = pa;
2954 outInfo.info.pathPermissions = newp;
2955 }
2956 } else {
2957 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002958 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002959 + parser.getName() + " at " + mArchiveSourcePath + " "
2960 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002961 XmlUtils.skipCurrentTag(parser);
2962 continue;
2963 }
2964 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2965 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 }
2967 XmlUtils.skipCurrentTag(parser);
2968
2969 } else {
2970 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002971 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002972 + parser.getName() + " at " + mArchiveSourcePath + " "
2973 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 XmlUtils.skipCurrentTag(parser);
2975 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002976 } else {
2977 outError[0] = "Bad element under <provider>: " + parser.getName();
2978 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 }
2981 }
2982 return true;
2983 }
2984
2985 private Service parseService(Package owner, Resources res,
2986 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2987 throws XmlPullParserException, IOException {
2988 TypedArray sa = res.obtainAttributes(attrs,
2989 com.android.internal.R.styleable.AndroidManifestService);
2990
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002991 if (mParseServiceArgs == null) {
2992 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2993 com.android.internal.R.styleable.AndroidManifestService_name,
2994 com.android.internal.R.styleable.AndroidManifestService_label,
2995 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002996 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002997 mSeparateProcesses,
2998 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002999 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003000 com.android.internal.R.styleable.AndroidManifestService_enabled);
3001 mParseServiceArgs.tag = "<service>";
3002 }
3003
3004 mParseServiceArgs.sa = sa;
3005 mParseServiceArgs.flags = flags;
3006
3007 Service s = new Service(mParseServiceArgs, new ServiceInfo());
3008 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 sa.recycle();
3010 return null;
3011 }
3012
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003013 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 com.android.internal.R.styleable.AndroidManifestService_exported);
3015 if (setExported) {
3016 s.info.exported = sa.getBoolean(
3017 com.android.internal.R.styleable.AndroidManifestService_exported, false);
3018 }
3019
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003020 String str = sa.getNonConfigurationString(
3021 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 if (str == null) {
3023 s.info.permission = owner.applicationInfo.permission;
3024 } else {
3025 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
3026 }
3027
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003028 s.info.flags = 0;
3029 if (sa.getBoolean(
3030 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
3031 false)) {
3032 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
3033 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08003034 if (sa.getBoolean(
3035 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
3036 false)) {
3037 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
3038 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003039 if (sa.getBoolean(
3040 com.android.internal.R.styleable.AndroidManifestService_singleUser,
3041 false)) {
3042 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
3043 if (s.info.exported) {
3044 Slog.w(TAG, "Service exported request ignored due to singleUser: "
3045 + s.className + " at " + mArchiveSourcePath + " "
3046 + parser.getPositionDescription());
3047 s.info.exported = false;
3048 }
3049 setExported = true;
3050 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 sa.recycle();
3053
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003054 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003055 // A heavy-weight application can not have services in its main process
3056 // We can do direct compare because we intern all strings.
3057 if (s.info.processName == owner.packageName) {
3058 outError[0] = "Heavy-weight applications can not have services in main process";
3059 return null;
3060 }
3061 }
3062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 int outerDepth = parser.getDepth();
3064 int type;
3065 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3066 && (type != XmlPullParser.END_TAG
3067 || parser.getDepth() > outerDepth)) {
3068 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3069 continue;
3070 }
3071
3072 if (parser.getName().equals("intent-filter")) {
3073 ServiceIntentInfo intent = new ServiceIntentInfo(s);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003074 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 return null;
3076 }
3077
3078 s.intents.add(intent);
3079 } else if (parser.getName().equals("meta-data")) {
3080 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3081 outError)) == null) {
3082 return null;
3083 }
3084 } else {
3085 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003086 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003087 + parser.getName() + " at " + mArchiveSourcePath + " "
3088 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 XmlUtils.skipCurrentTag(parser);
3090 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003091 } else {
3092 outError[0] = "Bad element under <service>: " + parser.getName();
3093 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 }
3096 }
3097
3098 if (!setExported) {
3099 s.info.exported = s.intents.size() > 0;
3100 }
3101
3102 return s;
3103 }
3104
3105 private boolean parseAllMetaData(Resources res,
3106 XmlPullParser parser, AttributeSet attrs, String tag,
3107 Component outInfo, String[] outError)
3108 throws XmlPullParserException, IOException {
3109 int outerDepth = parser.getDepth();
3110 int type;
3111 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3112 && (type != XmlPullParser.END_TAG
3113 || parser.getDepth() > outerDepth)) {
3114 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3115 continue;
3116 }
3117
3118 if (parser.getName().equals("meta-data")) {
3119 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3120 outInfo.metaData, outError)) == null) {
3121 return false;
3122 }
3123 } else {
3124 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003125 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003126 + parser.getName() + " at " + mArchiveSourcePath + " "
3127 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 XmlUtils.skipCurrentTag(parser);
3129 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003130 } else {
3131 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3132 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 }
3135 }
3136 return true;
3137 }
3138
3139 private Bundle parseMetaData(Resources res,
3140 XmlPullParser parser, AttributeSet attrs,
3141 Bundle data, String[] outError)
3142 throws XmlPullParserException, IOException {
3143
3144 TypedArray sa = res.obtainAttributes(attrs,
3145 com.android.internal.R.styleable.AndroidManifestMetaData);
3146
3147 if (data == null) {
3148 data = new Bundle();
3149 }
3150
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003151 String name = sa.getNonConfigurationString(
3152 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 if (name == null) {
3154 outError[0] = "<meta-data> requires an android:name attribute";
3155 sa.recycle();
3156 return null;
3157 }
3158
Dianne Hackborn854060a2009-07-09 18:14:31 -07003159 name = name.intern();
3160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 TypedValue v = sa.peekValue(
3162 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3163 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003164 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003165 data.putInt(name, v.resourceId);
3166 } else {
3167 v = sa.peekValue(
3168 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003169 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 if (v != null) {
3171 if (v.type == TypedValue.TYPE_STRING) {
3172 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003173 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3175 data.putBoolean(name, v.data != 0);
3176 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3177 && v.type <= TypedValue.TYPE_LAST_INT) {
3178 data.putInt(name, v.data);
3179 } else if (v.type == TypedValue.TYPE_FLOAT) {
3180 data.putFloat(name, v.getFloat());
3181 } else {
3182 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003183 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003184 + parser.getName() + " at " + mArchiveSourcePath + " "
3185 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 } else {
3187 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3188 data = null;
3189 }
3190 }
3191 } else {
3192 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3193 data = null;
3194 }
3195 }
3196
3197 sa.recycle();
3198
3199 XmlUtils.skipCurrentTag(parser);
3200
3201 return data;
3202 }
3203
Kenny Root05ca4c92011-09-15 10:36:25 -07003204 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3205 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3206 IOException {
3207 final TypedArray sa = res.obtainAttributes(attrs,
3208 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3209
3210 final String packageName = sa.getNonResourceString(
3211 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3212
3213 final String encodedPublicKey = sa.getNonResourceString(
3214 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3215
3216 sa.recycle();
3217
3218 if (packageName == null || packageName.length() == 0) {
3219 Slog.i(TAG, "verifier package name was null; skipping");
3220 return null;
3221 } else if (encodedPublicKey == null) {
3222 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3223 }
3224
Geremy Condraf1bcca82013-01-07 22:35:24 -08003225 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3226 if (publicKey != null) {
3227 return new VerifierInfo(packageName, publicKey);
3228 }
3229
3230 return null;
3231 }
3232
3233 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003234 EncodedKeySpec keySpec;
3235 try {
3236 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3237 keySpec = new X509EncodedKeySpec(encoded);
3238 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003239 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003240 return null;
3241 }
3242
3243 /* First try the key as an RSA key. */
3244 try {
3245 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003246 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003247 } catch (NoSuchAlgorithmException e) {
3248 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3249 return null;
3250 } catch (InvalidKeySpecException e) {
3251 // Not a RSA public key.
3252 }
3253
3254 /* Now try it as a DSA key. */
3255 try {
3256 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003257 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003258 } catch (NoSuchAlgorithmException e) {
3259 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3260 return null;
3261 } catch (InvalidKeySpecException e) {
3262 // Not a DSA public key.
3263 }
3264
3265 return null;
3266 }
3267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 private static final String ANDROID_RESOURCES
3269 = "http://schemas.android.com/apk/res/android";
3270
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003271 private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs,
3272 boolean allowGlobs, IntentInfo outInfo, String[] outError)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 throws XmlPullParserException, IOException {
3274
3275 TypedArray sa = res.obtainAttributes(attrs,
3276 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3277
3278 int priority = sa.getInt(
3279 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 TypedValue v = sa.peekValue(
3283 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3284 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3285 outInfo.nonLocalizedLabel = v.coerceToString();
3286 }
3287
3288 outInfo.icon = sa.getResourceId(
3289 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003290
3291 outInfo.logo = sa.getResourceId(
3292 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293
3294 sa.recycle();
3295
3296 int outerDepth = parser.getDepth();
3297 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003298 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3299 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3300 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 continue;
3302 }
3303
3304 String nodeName = parser.getName();
3305 if (nodeName.equals("action")) {
3306 String value = attrs.getAttributeValue(
3307 ANDROID_RESOURCES, "name");
3308 if (value == null || value == "") {
3309 outError[0] = "No value supplied for <android:name>";
3310 return false;
3311 }
3312 XmlUtils.skipCurrentTag(parser);
3313
3314 outInfo.addAction(value);
3315 } else if (nodeName.equals("category")) {
3316 String value = attrs.getAttributeValue(
3317 ANDROID_RESOURCES, "name");
3318 if (value == null || value == "") {
3319 outError[0] = "No value supplied for <android:name>";
3320 return false;
3321 }
3322 XmlUtils.skipCurrentTag(parser);
3323
3324 outInfo.addCategory(value);
3325
3326 } else if (nodeName.equals("data")) {
3327 sa = res.obtainAttributes(attrs,
3328 com.android.internal.R.styleable.AndroidManifestData);
3329
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003330 String str = sa.getNonConfigurationString(
3331 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 if (str != null) {
3333 try {
3334 outInfo.addDataType(str);
3335 } catch (IntentFilter.MalformedMimeTypeException e) {
3336 outError[0] = e.toString();
3337 sa.recycle();
3338 return false;
3339 }
3340 }
3341
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003342 str = sa.getNonConfigurationString(
3343 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 if (str != null) {
3345 outInfo.addDataScheme(str);
3346 }
3347
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003348 str = sa.getNonConfigurationString(
3349 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3350 if (str != null) {
3351 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3352 }
3353
3354 str = sa.getNonConfigurationString(
3355 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3356 if (str != null) {
3357 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3358 }
3359
3360 str = sa.getNonConfigurationString(
3361 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3362 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003363 if (!allowGlobs) {
3364 outError[0] = "sspPattern not allowed here; ssp must be literal";
3365 return false;
3366 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003367 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3368 }
3369
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003370 String host = sa.getNonConfigurationString(
3371 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3372 String port = sa.getNonConfigurationString(
3373 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 if (host != null) {
3375 outInfo.addDataAuthority(host, port);
3376 }
3377
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003378 str = sa.getNonConfigurationString(
3379 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 if (str != null) {
3381 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3382 }
3383
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003384 str = sa.getNonConfigurationString(
3385 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 if (str != null) {
3387 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3388 }
3389
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003390 str = sa.getNonConfigurationString(
3391 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003393 if (!allowGlobs) {
3394 outError[0] = "pathPattern not allowed here; path must be literal";
3395 return false;
3396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3398 }
3399
3400 sa.recycle();
3401 XmlUtils.skipCurrentTag(parser);
3402 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003403 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003404 + parser.getName() + " at " + mArchiveSourcePath + " "
3405 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 XmlUtils.skipCurrentTag(parser);
3407 } else {
3408 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3409 return false;
3410 }
3411 }
3412
3413 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003414
3415 if (DEBUG_PARSER) {
3416 final StringBuilder cats = new StringBuilder("Intent d=");
3417 cats.append(outInfo.hasDefault);
3418 cats.append(", cat=");
3419
3420 final Iterator<String> it = outInfo.categoriesIterator();
3421 if (it != null) {
3422 while (it.hasNext()) {
3423 cats.append(' ');
3424 cats.append(it.next());
3425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003427 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 }
3429
3430 return true;
3431 }
3432
3433 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003434
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003435 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436
3437 // For now we only support one application per package.
3438 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3439
3440 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3441 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3442 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3443 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3444 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3445 public final ArrayList<Service> services = new ArrayList<Service>(0);
3446 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3447
3448 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003449 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450
Dianne Hackborn854060a2009-07-09 18:14:31 -07003451 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003452
3453 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003454 public ArrayList<String> usesLibraries = null;
3455 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 public String[] usesLibraryFiles = null;
3457
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003458 public ArrayList<ActivityIntentInfo> preferredActivityFilters = null;
3459
Dianne Hackbornc1552392010-03-03 16:19:01 -08003460 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003461 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003462 public ArrayList<String> mAdoptPermissions = null;
3463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 // We store the application meta-data independently to avoid multiple unwanted references
3465 public Bundle mAppMetaData = null;
3466
3467 // If this is a 3rd party app, this is the path of the zip file.
3468 public String mPath;
3469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 // The version code declared for this package.
3471 public int mVersionCode;
3472
3473 // The version name declared for this package.
3474 public String mVersionName;
3475
3476 // The shared user id that this package wants to use.
3477 public String mSharedUserId;
3478
3479 // The shared user label that this package wants to use.
3480 public int mSharedUserLabel;
3481
3482 // Signatures that were read from the package.
3483 public Signature mSignatures[];
3484
3485 // For use by package manager service for quick lookup of
3486 // preferred up order.
3487 public int mPreferredOrder = 0;
3488
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003489 // For use by the package manager to keep track of the path to the
3490 // file an app came from.
3491 public String mScanPath;
3492
3493 // For use by package manager to keep track of where it has done dexopt.
3494 public boolean mDidDexOpt;
3495
Amith Yamasani13593602012-03-22 16:16:17 -07003496 // // User set enabled state.
3497 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3498 //
3499 // // Whether the package has been stopped.
3500 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 // Additional data supplied by callers.
3503 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003504
3505 // Whether an operation is currently pending on this package
3506 public boolean mOperationPending;
3507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 /*
3509 * Applications hardware preferences
3510 */
3511 public final ArrayList<ConfigurationInfo> configPreferences =
3512 new ArrayList<ConfigurationInfo>();
3513
Dianne Hackborn49237342009-08-27 20:08:01 -07003514 /*
3515 * Applications requested features
3516 */
3517 public ArrayList<FeatureInfo> reqFeatures = null;
3518
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003519 public int installLocation;
3520
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003521 /* An app that's required for all users and cannot be uninstalled for a user */
3522 public boolean mRequiredForAllUsers;
3523
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003524 /* The restricted account authenticator type that is used by this application */
3525 public String mRestrictedAccountType;
3526
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003527 /* The required account type without which this application will not function */
3528 public String mRequiredAccountType;
3529
Kenny Rootbcc954d2011-08-08 16:19:08 -07003530 /**
3531 * Digest suitable for comparing whether this package's manifest is the
3532 * same as another.
3533 */
3534 public ManifestDigest manifestDigest;
3535
Geremy Condraf1bcca82013-01-07 22:35:24 -08003536 /**
3537 * Data used to feed the KeySetManager
3538 */
3539 public Set<PublicKey> mSigningKeys;
3540 public Map<String, Set<PublicKey>> mKeySetMapping;
3541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 public Package(String _name) {
3543 packageName = _name;
3544 applicationInfo.packageName = _name;
3545 applicationInfo.uid = -1;
3546 }
3547
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003548 public void setPackageName(String newName) {
3549 packageName = newName;
3550 applicationInfo.packageName = newName;
3551 for (int i=permissions.size()-1; i>=0; i--) {
3552 permissions.get(i).setPackageName(newName);
3553 }
3554 for (int i=permissionGroups.size()-1; i>=0; i--) {
3555 permissionGroups.get(i).setPackageName(newName);
3556 }
3557 for (int i=activities.size()-1; i>=0; i--) {
3558 activities.get(i).setPackageName(newName);
3559 }
3560 for (int i=receivers.size()-1; i>=0; i--) {
3561 receivers.get(i).setPackageName(newName);
3562 }
3563 for (int i=providers.size()-1; i>=0; i--) {
3564 providers.get(i).setPackageName(newName);
3565 }
3566 for (int i=services.size()-1; i>=0; i--) {
3567 services.get(i).setPackageName(newName);
3568 }
3569 for (int i=instrumentation.size()-1; i>=0; i--) {
3570 instrumentation.get(i).setPackageName(newName);
3571 }
3572 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003573
3574 public boolean hasComponentClassName(String name) {
3575 for (int i=activities.size()-1; i>=0; i--) {
3576 if (name.equals(activities.get(i).className)) {
3577 return true;
3578 }
3579 }
3580 for (int i=receivers.size()-1; i>=0; i--) {
3581 if (name.equals(receivers.get(i).className)) {
3582 return true;
3583 }
3584 }
3585 for (int i=providers.size()-1; i>=0; i--) {
3586 if (name.equals(providers.get(i).className)) {
3587 return true;
3588 }
3589 }
3590 for (int i=services.size()-1; i>=0; i--) {
3591 if (name.equals(services.get(i).className)) {
3592 return true;
3593 }
3594 }
3595 for (int i=instrumentation.size()-1; i>=0; i--) {
3596 if (name.equals(instrumentation.get(i).className)) {
3597 return true;
3598 }
3599 }
3600 return false;
3601 }
3602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 public String toString() {
3604 return "Package{"
3605 + Integer.toHexString(System.identityHashCode(this))
3606 + " " + packageName + "}";
3607 }
3608 }
3609
3610 public static class Component<II extends IntentInfo> {
3611 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003612 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003613 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 public Bundle metaData;
3615
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003616 ComponentName componentName;
3617 String componentShortName;
3618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 public Component(Package _owner) {
3620 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003621 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003622 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003623 }
3624
3625 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3626 owner = args.owner;
3627 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003628 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003629 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003630 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003631 args.outError[0] = args.tag + " does not specify android:name";
3632 return;
3633 }
3634
3635 outInfo.name
3636 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3637 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003638 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003639 args.outError[0] = args.tag + " does not have valid android:name";
3640 return;
3641 }
3642
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003643 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003644
3645 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3646 if (iconVal != 0) {
3647 outInfo.icon = iconVal;
3648 outInfo.nonLocalizedLabel = null;
3649 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003650
3651 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3652 if (logoVal != 0) {
3653 outInfo.logo = logoVal;
3654 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003655
3656 TypedValue v = args.sa.peekValue(args.labelRes);
3657 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3658 outInfo.nonLocalizedLabel = v.coerceToString();
3659 }
3660
3661 outInfo.packageName = owner.packageName;
3662 }
3663
3664 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3665 this(args, (PackageItemInfo)outInfo);
3666 if (args.outError[0] != null) {
3667 return;
3668 }
3669
3670 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003671 CharSequence pname;
3672 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07003673 pname = args.sa.getNonConfigurationString(args.processRes,
3674 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003675 } else {
3676 // Some older apps have been seen to use a resource reference
3677 // here that on older builds was ignored (with a warning). We
3678 // need to continue to do this for them so they don't break.
3679 pname = args.sa.getNonResourceString(args.processRes);
3680 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003681 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003682 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003683 args.flags, args.sepProcesses, args.outError);
3684 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003685
3686 if (args.descriptionRes != 0) {
3687 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3688 }
3689
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003690 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 }
3692
3693 public Component(Component<II> clone) {
3694 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003695 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003696 className = clone.className;
3697 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003698 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003699 }
3700
3701 public ComponentName getComponentName() {
3702 if (componentName != null) {
3703 return componentName;
3704 }
3705 if (className != null) {
3706 componentName = new ComponentName(owner.applicationInfo.packageName,
3707 className);
3708 }
3709 return componentName;
3710 }
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003711
3712 public void appendComponentShortName(StringBuilder sb) {
3713 ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003714 }
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003715
3716 public void printComponentShortName(PrintWriter pw) {
3717 ComponentName.printShortString(pw, owner.applicationInfo.packageName, className);
3718 }
3719
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003720 public void setPackageName(String packageName) {
3721 componentName = null;
3722 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 }
3724 }
3725
3726 public final static class Permission extends Component<IntentInfo> {
3727 public final PermissionInfo info;
3728 public boolean tree;
3729 public PermissionGroup group;
3730
3731 public Permission(Package _owner) {
3732 super(_owner);
3733 info = new PermissionInfo();
3734 }
3735
3736 public Permission(Package _owner, PermissionInfo _info) {
3737 super(_owner);
3738 info = _info;
3739 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003740
3741 public void setPackageName(String packageName) {
3742 super.setPackageName(packageName);
3743 info.packageName = packageName;
3744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745
3746 public String toString() {
3747 return "Permission{"
3748 + Integer.toHexString(System.identityHashCode(this))
3749 + " " + info.name + "}";
3750 }
3751 }
3752
3753 public final static class PermissionGroup extends Component<IntentInfo> {
3754 public final PermissionGroupInfo info;
3755
3756 public PermissionGroup(Package _owner) {
3757 super(_owner);
3758 info = new PermissionGroupInfo();
3759 }
3760
3761 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3762 super(_owner);
3763 info = _info;
3764 }
3765
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003766 public void setPackageName(String packageName) {
3767 super.setPackageName(packageName);
3768 info.packageName = packageName;
3769 }
3770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 public String toString() {
3772 return "PermissionGroup{"
3773 + Integer.toHexString(System.identityHashCode(this))
3774 + " " + info.name + "}";
3775 }
3776 }
3777
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003778 private static boolean copyNeeded(int flags, Package p,
3779 PackageUserState state, Bundle metaData, int userId) {
3780 if (userId != 0) {
3781 // We always need to copy for other users, since we need
3782 // to fix up the uid.
3783 return true;
3784 }
3785 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3786 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003787 if (p.applicationInfo.enabled != enabled) {
3788 return true;
3789 }
3790 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003791 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003792 return true;
3793 }
3794 if (state.stopped) {
3795 return true;
3796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 if ((flags & PackageManager.GET_META_DATA) != 0
3798 && (metaData != null || p.mAppMetaData != null)) {
3799 return true;
3800 }
3801 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3802 && p.usesLibraryFiles != null) {
3803 return true;
3804 }
3805 return false;
3806 }
3807
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003808 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3809 PackageUserState state) {
3810 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003811 }
3812
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003813 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3814 PackageUserState state) {
3815 // CompatibilityMode is global state.
3816 if (!sCompatibilityModeEnabled) {
3817 ai.disableCompatibilityMode();
3818 }
3819 if (state.installed) {
3820 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3821 } else {
3822 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3823 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003824 if (state.blocked) {
3825 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3826 } else {
3827 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3828 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003829 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3830 ai.enabled = true;
3831 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3832 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3833 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3834 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3835 ai.enabled = false;
3836 }
3837 ai.enabledSetting = state.enabled;
3838 }
3839
Amith Yamasani13593602012-03-22 16:16:17 -07003840 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003841 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003843 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003844 return null;
3845 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003846 if (!copyNeeded(flags, p, state, null, userId)
3847 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3848 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3849 // In this case it is safe to directly modify the internal ApplicationInfo state:
3850 // - CompatibilityMode is global state, so will be the same for every call.
3851 // - We only come in to here if the app should reported as installed; this is the
3852 // default state, and we will do a copy otherwise.
3853 // - The enable state will always be reported the same for the application across
3854 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3855 // be doing a copy.
3856 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 return p.applicationInfo;
3858 }
3859
3860 // Make shallow copy so we can store the metadata/libraries safely
3861 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003862 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003863 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003864 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 if ((flags & PackageManager.GET_META_DATA) != 0) {
3867 ai.metaData = p.mAppMetaData;
3868 }
3869 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3870 ai.sharedLibraryFiles = p.usesLibraryFiles;
3871 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003872 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003873 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003874 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003875 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003876 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003877 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 return ai;
3879 }
3880
3881 public static final PermissionInfo generatePermissionInfo(
3882 Permission p, int flags) {
3883 if (p == null) return null;
3884 if ((flags&PackageManager.GET_META_DATA) == 0) {
3885 return p.info;
3886 }
3887 PermissionInfo pi = new PermissionInfo(p.info);
3888 pi.metaData = p.metaData;
3889 return pi;
3890 }
3891
3892 public static final PermissionGroupInfo generatePermissionGroupInfo(
3893 PermissionGroup pg, int flags) {
3894 if (pg == null) return null;
3895 if ((flags&PackageManager.GET_META_DATA) == 0) {
3896 return pg.info;
3897 }
3898 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3899 pgi.metaData = pg.metaData;
3900 return pgi;
3901 }
3902
3903 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003904 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003906 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3907 super(args, _info);
3908 info = _info;
3909 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003911
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003912 public void setPackageName(String packageName) {
3913 super.setPackageName(packageName);
3914 info.packageName = packageName;
3915 }
3916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003918 StringBuilder sb = new StringBuilder(128);
3919 sb.append("Activity{");
3920 sb.append(Integer.toHexString(System.identityHashCode(this)));
3921 sb.append(' ');
3922 appendComponentShortName(sb);
3923 sb.append('}');
3924 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 }
3926 }
3927
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003928 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3929 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003931 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003932 return null;
3933 }
3934 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 return a.info;
3936 }
3937 // Make shallow copies so we can store the metadata safely
3938 ActivityInfo ai = new ActivityInfo(a.info);
3939 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003940 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 return ai;
3942 }
3943
3944 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003945 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003947 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3948 super(args, _info);
3949 info = _info;
3950 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003952
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003953 public void setPackageName(String packageName) {
3954 super.setPackageName(packageName);
3955 info.packageName = packageName;
3956 }
3957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003959 StringBuilder sb = new StringBuilder(128);
3960 sb.append("Service{");
3961 sb.append(Integer.toHexString(System.identityHashCode(this)));
3962 sb.append(' ');
3963 appendComponentShortName(sb);
3964 sb.append('}');
3965 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 }
3967 }
3968
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003969 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3970 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003972 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003973 return null;
3974 }
3975 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 return s.info;
3977 }
3978 // Make shallow copies so we can store the metadata safely
3979 ServiceInfo si = new ServiceInfo(s.info);
3980 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003981 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 return si;
3983 }
3984
3985 public final static class Provider extends Component {
3986 public final ProviderInfo info;
3987 public boolean syncable;
3988
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003989 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3990 super(args, _info);
3991 info = _info;
3992 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 syncable = false;
3994 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 public Provider(Provider existingProvider) {
3997 super(existingProvider);
3998 this.info = existingProvider.info;
3999 this.syncable = existingProvider.syncable;
4000 }
4001
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004002 public void setPackageName(String packageName) {
4003 super.setPackageName(packageName);
4004 info.packageName = packageName;
4005 }
4006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004008 StringBuilder sb = new StringBuilder(128);
4009 sb.append("Provider{");
4010 sb.append(Integer.toHexString(System.identityHashCode(this)));
4011 sb.append(' ');
4012 appendComponentShortName(sb);
4013 sb.append('}');
4014 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 }
4016 }
4017
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004018 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
4019 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07004021 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004022 return null;
4023 }
4024 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004026 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 return p.info;
4028 }
4029 // Make shallow copies so we can store the metadata safely
4030 ProviderInfo pi = new ProviderInfo(p.info);
4031 pi.metaData = p.metaData;
4032 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
4033 pi.uriPermissionPatterns = null;
4034 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004035 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 return pi;
4037 }
4038
4039 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004040 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004041
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004042 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
4043 super(args, _info);
4044 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004046
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004047 public void setPackageName(String packageName) {
4048 super.setPackageName(packageName);
4049 info.packageName = packageName;
4050 }
4051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004053 StringBuilder sb = new StringBuilder(128);
4054 sb.append("Instrumentation{");
4055 sb.append(Integer.toHexString(System.identityHashCode(this)));
4056 sb.append(' ');
4057 appendComponentShortName(sb);
4058 sb.append('}');
4059 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 }
4061 }
4062
4063 public static final InstrumentationInfo generateInstrumentationInfo(
4064 Instrumentation i, int flags) {
4065 if (i == null) return null;
4066 if ((flags&PackageManager.GET_META_DATA) == 0) {
4067 return i.info;
4068 }
4069 InstrumentationInfo ii = new InstrumentationInfo(i.info);
4070 ii.metaData = i.metaData;
4071 return ii;
4072 }
4073
4074 public static class IntentInfo extends IntentFilter {
4075 public boolean hasDefault;
4076 public int labelRes;
4077 public CharSequence nonLocalizedLabel;
4078 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004079 public int logo;
Dianne Hackbornb09491f2013-07-22 15:30:11 -07004080 public int preferred;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081 }
4082
4083 public final static class ActivityIntentInfo extends IntentInfo {
4084 public final Activity activity;
4085
4086 public ActivityIntentInfo(Activity _activity) {
4087 activity = _activity;
4088 }
4089
4090 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004091 StringBuilder sb = new StringBuilder(128);
4092 sb.append("ActivityIntentInfo{");
4093 sb.append(Integer.toHexString(System.identityHashCode(this)));
4094 sb.append(' ');
4095 activity.appendComponentShortName(sb);
4096 sb.append('}');
4097 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 }
4099 }
4100
4101 public final static class ServiceIntentInfo extends IntentInfo {
4102 public final Service service;
4103
4104 public ServiceIntentInfo(Service _service) {
4105 service = _service;
4106 }
4107
4108 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004109 StringBuilder sb = new StringBuilder(128);
4110 sb.append("ServiceIntentInfo{");
4111 sb.append(Integer.toHexString(System.identityHashCode(this)));
4112 sb.append(' ');
4113 service.appendComponentShortName(sb);
4114 sb.append('}');
4115 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004118
4119 /**
4120 * @hide
4121 */
4122 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4123 sCompatibilityModeEnabled = compatibilityModeEnabled;
4124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125}