blob: 52564eb401ab0d3e6a57100074f23cbadc45a394 [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;
Narayan Kamath1f0299a2013-12-12 16:54:33 +000061import java.util.jar.StrictJarFile;
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
Christopher Tateba629da2013-11-13 17:42:28 -0800285 public static boolean isAvailable(PackageUserState state) {
286 return checkUseInstalledOrBlocked(0, state);
287 }
288
Amith Yamasani13593602012-03-22 16:16:17 -0700289 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700290 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700291 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700292
Amith Yamasani655d0e22013-06-12 14:19:10 -0700293 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700294 return null;
295 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 PackageInfo pi = new PackageInfo();
297 pi.packageName = p.packageName;
298 pi.versionCode = p.mVersionCode;
299 pi.versionName = p.mVersionName;
300 pi.sharedUserId = p.mSharedUserId;
301 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700302 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800303 pi.installLocation = p.installLocation;
Amith Yamasani0d8750d2013-05-01 15:25:28 -0700304 if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0
305 || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
306 pi.requiredForAllUsers = p.mRequiredForAllUsers;
307 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700308 pi.restrictedAccountType = p.mRestrictedAccountType;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700309 pi.requiredAccountType = p.mRequiredAccountType;
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +0100310 pi.overlayTarget = p.mOverlayTarget;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700311 pi.firstInstallTime = firstInstallTime;
312 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 if ((flags&PackageManager.GET_GIDS) != 0) {
314 pi.gids = gids;
315 }
316 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
317 int N = p.configPreferences.size();
318 if (N > 0) {
319 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700320 p.configPreferences.toArray(pi.configPreferences);
321 }
322 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
323 if (N > 0) {
324 pi.reqFeatures = new FeatureInfo[N];
325 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 }
327 }
328 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
329 int N = p.activities.size();
330 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700331 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
332 pi.activities = new ActivityInfo[N];
333 } else {
334 int num = 0;
335 for (int i=0; i<N; i++) {
336 if (p.activities.get(i).info.enabled) num++;
337 }
338 pi.activities = new ActivityInfo[num];
339 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700340 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 final Activity activity = p.activities.get(i);
342 if (activity.info.enabled
343 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700344 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700345 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347 }
348 }
349 }
350 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
351 int N = p.receivers.size();
352 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700353 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
354 pi.receivers = new ActivityInfo[N];
355 } else {
356 int num = 0;
357 for (int i=0; i<N; i++) {
358 if (p.receivers.get(i).info.enabled) num++;
359 }
360 pi.receivers = new ActivityInfo[num];
361 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700362 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 final Activity activity = p.receivers.get(i);
364 if (activity.info.enabled
365 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700366 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700367 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 }
369 }
370 }
371 }
372 if ((flags&PackageManager.GET_SERVICES) != 0) {
373 int N = p.services.size();
374 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700375 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
376 pi.services = new ServiceInfo[N];
377 } else {
378 int num = 0;
379 for (int i=0; i<N; i++) {
380 if (p.services.get(i).info.enabled) num++;
381 }
382 pi.services = new ServiceInfo[num];
383 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700384 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 final Service service = p.services.get(i);
386 if (service.info.enabled
387 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700388 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
389 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 }
391 }
392 }
393 }
394 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
395 int N = p.providers.size();
396 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700397 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
398 pi.providers = new ProviderInfo[N];
399 } else {
400 int num = 0;
401 for (int i=0; i<N; i++) {
402 if (p.providers.get(i).info.enabled) num++;
403 }
404 pi.providers = new ProviderInfo[num];
405 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700406 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 final Provider provider = p.providers.get(i);
408 if (provider.info.enabled
409 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700410 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
411 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
413 }
414 }
415 }
416 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
417 int N = p.instrumentation.size();
418 if (N > 0) {
419 pi.instrumentation = new InstrumentationInfo[N];
420 for (int i=0; i<N; i++) {
421 pi.instrumentation[i] = generateInstrumentationInfo(
422 p.instrumentation.get(i), flags);
423 }
424 }
425 }
426 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
427 int N = p.permissions.size();
428 if (N > 0) {
429 pi.permissions = new PermissionInfo[N];
430 for (int i=0; i<N; i++) {
431 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
432 }
433 }
434 N = p.requestedPermissions.size();
435 if (N > 0) {
436 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800437 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800439 final String perm = p.requestedPermissions.get(i);
440 pi.requestedPermissions[i] = perm;
441 if (p.requestedPermissionsRequired.get(i)) {
442 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
443 }
444 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
445 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 }
448 }
449 }
450 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700451 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
452 if (N > 0) {
453 pi.signatures = new Signature[N];
454 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 }
456 }
457 return pi;
458 }
459
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000460 private Certificate[] loadCertificates(StrictJarFile jarFile, ZipEntry je,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 byte[] readBuffer) {
462 try {
463 // We must read the stream for the JarEntry to retrieve
464 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700465 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
467 // not using
468 }
469 is.close();
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000470 return je != null ? jarFile.getCertificates(je) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 } catch (IOException e) {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000472 Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700473 } catch (RuntimeException e) {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000474 Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 }
476 return null;
477 }
478
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800479 public final static int PARSE_IS_SYSTEM = 1<<0;
480 public final static int PARSE_CHATTY = 1<<1;
481 public final static int PARSE_MUST_BE_APK = 1<<2;
482 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
483 public final static int PARSE_FORWARD_LOCK = 1<<4;
484 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700485 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
Christopher Tateccbf84f2013-05-08 15:25:41 -0700486 public final static int PARSE_IS_PRIVILEGED = 1<<7;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487
488 public int getParseError() {
489 return mParseError;
490 }
491
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800492 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 DisplayMetrics metrics, int flags) {
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +0100494 return parsePackage(sourceFile, destCodePath, metrics, flags, false);
495 }
496
497 public Package parsePackage(File sourceFile, String destCodePath,
498 DisplayMetrics metrics, int flags, boolean trustedOverlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 mParseError = PackageManager.INSTALL_SUCCEEDED;
500
501 mArchiveSourcePath = sourceFile.getPath();
502 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700503 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
505 return null;
506 }
507 if (!isPackageFilename(sourceFile.getName())
508 && (flags&PARSE_MUST_BE_APK) != 0) {
509 if ((flags&PARSE_IS_SYSTEM) == 0) {
510 // We expect to have non-.apk files in the system dir,
511 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700512 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
515 return null;
516 }
517
Kenny Rootd2d29252011-08-08 11:27:57 -0700518 if (DEBUG_JAR)
519 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520
521 XmlResourceParser parser = null;
522 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800523 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 boolean assetError = true;
525 try {
526 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700527 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800528 if (cookie != 0) {
529 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700530 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 -0800531 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700532 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 assetError = false;
534 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700535 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 }
537 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700538 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 + mArchiveSourcePath, e);
540 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800541 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 if (assmgr != null) assmgr.close();
543 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
544 return null;
545 }
546 String[] errorText = new String[1];
547 Package pkg = null;
548 Exception errorException = null;
549 try {
550 // XXXX todo: need to figure out correct configuration.
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +0100551 pkg = parsePackage(res, parser, flags, trustedOverlay, errorText);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 } catch (Exception e) {
553 errorException = e;
554 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
555 }
556
557
558 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700559 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
560 // just means to skip this app so don't make a fuss about it.
561 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
562 if (errorException != null) {
563 Slog.w(TAG, mArchiveSourcePath, errorException);
564 } else {
565 Slog.w(TAG, mArchiveSourcePath + " (at "
566 + parser.getPositionDescription()
567 + "): " + errorText[0]);
568 }
569 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
570 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573 parser.close();
574 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 return null;
576 }
577
578 parser.close();
579 assmgr.close();
580
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800581 // Set code and resource paths
582 pkg.mPath = destCodePath;
583 pkg.mScanPath = mArchiveSourcePath;
584 //pkg.applicationInfo.sourceDir = destCodePath;
585 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 pkg.mSignatures = null;
587
588 return pkg;
589 }
590
Kenny Root6c918ce2013-04-02 14:04:24 -0700591 /**
592 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
593 * APK. If it successfully scanned the package and found the
594 * {@code AndroidManifest.xml}, {@code true} is returned.
595 */
596 public boolean collectManifestDigest(Package pkg) {
597 try {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000598 final StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
Kenny Root6c918ce2013-04-02 14:04:24 -0700599 try {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000600 final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
Kenny Root6c918ce2013-04-02 14:04:24 -0700601 if (je != null) {
602 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
603 }
604 } finally {
605 jarFile.close();
606 }
607 return true;
608 } catch (IOException e) {
609 return false;
610 }
611 }
612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 public boolean collectCertificates(Package pkg, int flags) {
614 pkg.mSignatures = null;
615
616 WeakReference<byte[]> readBufferRef;
617 byte[] readBuffer = null;
618 synchronized (mSync) {
619 readBufferRef = mReadBuffer;
620 if (readBufferRef != null) {
621 mReadBuffer = null;
622 readBuffer = readBufferRef.get();
623 }
624 if (readBuffer == null) {
625 readBuffer = new byte[8192];
626 readBufferRef = new WeakReference<byte[]>(readBuffer);
627 }
628 }
629
630 try {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000631 StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
633 Certificate[] certs = null;
634
635 if ((flags&PARSE_IS_SYSTEM) != 0) {
636 // If this package comes from the system image, then we
637 // can trust it... we'll just use the AndroidManifest.xml
638 // to retrieve its signatures, not validating all of the
639 // files.
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000640 ZipEntry jarEntry = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 certs = loadCertificates(jarFile, jarEntry, readBuffer);
642 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700643 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 + " has no certificates at entry "
645 + jarEntry.getName() + "; ignoring!");
646 jarFile.close();
647 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
648 return false;
649 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700650 if (DEBUG_JAR) {
651 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 + " certs=" + (certs != null ? certs.length : 0));
653 if (certs != null) {
654 final int N = certs.length;
655 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700656 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 + certs[i].getPublicKey().getEncoded()
658 + " " + certs[i].getPublicKey());
659 }
660 }
661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 } else {
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000663 Iterator<ZipEntry> entries = jarFile.iterator();
664 while (entries.hasNext()) {
665 final ZipEntry je = entries.next();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700667
Kenny Rootbcc954d2011-08-08 16:19:08 -0700668 final String name = je.getName();
669
670 if (name.startsWith("META-INF/"))
671 continue;
672
673 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700674 pkg.manifestDigest =
675 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700676 }
677
678 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700679 if (DEBUG_JAR) {
680 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 + ": certs=" + certs + " ("
682 + (certs != null ? certs.length : 0) + ")");
683 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700686 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 + " has no certificates at entry "
688 + je.getName() + "; ignoring!");
689 jarFile.close();
690 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
691 return false;
692 } else if (certs == null) {
693 certs = localCerts;
694 } else {
695 // Ensure all certificates match.
696 for (int i=0; i<certs.length; i++) {
697 boolean found = false;
698 for (int j=0; j<localCerts.length; j++) {
699 if (certs[i] != null &&
700 certs[i].equals(localCerts[j])) {
701 found = true;
702 break;
703 }
704 }
705 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700706 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 + " has mismatched certificates at entry "
708 + je.getName() + "; ignoring!");
709 jarFile.close();
710 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
711 return false;
712 }
713 }
714 }
715 }
716 }
717 jarFile.close();
718
719 synchronized (mSync) {
720 mReadBuffer = readBufferRef;
721 }
722
723 if (certs != null && certs.length > 0) {
724 final int N = certs.length;
725 pkg.mSignatures = new Signature[certs.length];
726 for (int i=0; i<N; i++) {
727 pkg.mSignatures[i] = new Signature(
728 certs[i].getEncoded());
729 }
730 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700731 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 + " has no certificates; ignoring!");
733 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
734 return false;
735 }
Geremy Condraf1bcca82013-01-07 22:35:24 -0800736
737 // Add the signing KeySet to the system
738 pkg.mSigningKeys = new HashSet<PublicKey>();
739 for (int i=0; i < certs.length; i++) {
740 pkg.mSigningKeys.add(certs[i].getPublicKey());
741 }
742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 } catch (CertificateEncodingException 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_CERTIFICATE_ENCODING;
746 return false;
747 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700748 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
750 return false;
Narayan Kamath1f0299a2013-12-12 16:54:33 +0000751 } catch (SecurityException e) {
752 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
753 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
754 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700756 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
758 return false;
759 }
760
761 return true;
762 }
763
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800764 /*
765 * Utility method that retrieves just the package name and install
766 * location from the apk location at the given file path.
767 * @param packageFilePath file location of the apk
768 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700769 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800770 */
771 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700773 final XmlResourceParser parser;
774 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 try {
776 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700777 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 -0800778 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700781 if (cookie == 0) {
782 return null;
783 }
784
Kenny Root05ca4c92011-09-15 10:36:25 -0700785 final DisplayMetrics metrics = new DisplayMetrics();
786 metrics.setToDefaults();
787 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700788 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 } catch (Exception e) {
790 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700791 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 + packageFilePath, e);
793 return null;
794 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700795
796 final AttributeSet attrs = parser;
797 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800798 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700800 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700802 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700804 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 } finally {
806 if (parser != null) parser.close();
807 if (assmgr != null) assmgr.close();
808 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800809 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700810 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 return null;
812 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800813 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
815
816 private static String validateName(String name, boolean requiresSeparator) {
817 final int N = name.length();
818 boolean hasSep = false;
819 boolean front = true;
820 for (int i=0; i<N; i++) {
821 final char c = name.charAt(i);
822 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
823 front = false;
824 continue;
825 }
826 if (!front) {
827 if ((c >= '0' && c <= '9') || c == '_') {
828 continue;
829 }
830 }
831 if (c == '.') {
832 hasSep = true;
833 front = true;
834 continue;
835 }
836 return "bad character '" + c + "'";
837 }
838 return hasSep || !requiresSeparator
839 ? null : "must have at least one '.' separator";
840 }
841
842 private static String parsePackageName(XmlPullParser parser,
843 AttributeSet attrs, int flags, String[] outError)
844 throws IOException, XmlPullParserException {
845
846 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700847 while ((type = parser.next()) != XmlPullParser.START_TAG
848 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 ;
850 }
851
Kenny Rootd2d29252011-08-08 11:27:57 -0700852 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 outError[0] = "No start tag found";
854 return null;
855 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700856 if (DEBUG_PARSER)
857 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 if (!parser.getName().equals("manifest")) {
859 outError[0] = "No <manifest> tag";
860 return null;
861 }
862 String pkgName = attrs.getAttributeValue(null, "package");
863 if (pkgName == null || pkgName.length() == 0) {
864 outError[0] = "<manifest> does not specify package";
865 return null;
866 }
867 String nameError = validateName(pkgName, true);
868 if (nameError != null && !"android".equals(pkgName)) {
869 outError[0] = "<manifest> specifies bad package name \""
870 + pkgName + "\": " + nameError;
871 return null;
872 }
873
874 return pkgName.intern();
875 }
876
Kenny Root05ca4c92011-09-15 10:36:25 -0700877 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
878 AttributeSet attrs, int flags, String[] outError) throws IOException,
879 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800880
881 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700882 while ((type = parser.next()) != XmlPullParser.START_TAG
883 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800884 ;
885 }
886
Kenny Rootd2d29252011-08-08 11:27:57 -0700887 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800888 outError[0] = "No start tag found";
889 return null;
890 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700891 if (DEBUG_PARSER)
892 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800893 if (!parser.getName().equals("manifest")) {
894 outError[0] = "No <manifest> tag";
895 return null;
896 }
897 String pkgName = attrs.getAttributeValue(null, "package");
898 if (pkgName == null || pkgName.length() == 0) {
899 outError[0] = "<manifest> does not specify package";
900 return null;
901 }
902 String nameError = validateName(pkgName, true);
903 if (nameError != null && !"android".equals(pkgName)) {
904 outError[0] = "<manifest> specifies bad package name \""
905 + pkgName + "\": " + nameError;
906 return null;
907 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700908 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700909 int versionCode = 0;
910 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800911 for (int i = 0; i < attrs.getAttributeCount(); i++) {
912 String attr = attrs.getAttributeName(i);
913 if (attr.equals("installLocation")) {
914 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700915 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700916 numFound++;
917 } else if (attr.equals("versionCode")) {
918 versionCode = attrs.getAttributeIntValue(i, 0);
919 numFound++;
920 }
921 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800922 break;
923 }
924 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700925
926 // Only search the tree when the tag is directly below <manifest>
927 final int searchDepth = parser.getDepth() + 1;
928
929 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
930 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
931 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
932 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
933 continue;
934 }
935
936 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
937 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
938 if (verifier != null) {
939 verifiers.add(verifier);
940 }
941 }
942 }
943
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700944 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800945 }
946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 /**
948 * Temporary.
949 */
950 static public Signature stringToSignature(String str) {
951 final int N = str.length();
952 byte[] sig = new byte[N];
953 for (int i=0; i<N; i++) {
954 sig[i] = (byte)str.charAt(i);
955 }
956 return new Signature(sig);
957 }
958
959 private Package parsePackage(
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +0100960 Resources res, XmlResourceParser parser, int flags, boolean trustedOverlay,
961 String[] outError) throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 AttributeSet attrs = parser;
963
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700964 mParseInstrumentationArgs = null;
965 mParseActivityArgs = null;
966 mParseServiceArgs = null;
967 mParseProviderArgs = null;
968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 String pkgName = parsePackageName(parser, attrs, flags, outError);
970 if (pkgName == null) {
971 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
972 return null;
973 }
974 int type;
975
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700976 if (mOnlyCoreApps) {
977 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
978 if (!core) {
979 mParseError = PackageManager.INSTALL_SUCCEEDED;
980 return null;
981 }
982 }
983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 TypedArray sa = res.obtainAttributes(attrs,
988 com.android.internal.R.styleable.AndroidManifest);
989 pkg.mVersionCode = sa.getInteger(
990 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800991 pkg.mVersionName = sa.getNonConfigurationString(
992 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 if (pkg.mVersionName != null) {
994 pkg.mVersionName = pkg.mVersionName.intern();
995 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800996 String str = sa.getNonConfigurationString(
997 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
998 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 String nameError = validateName(str, true);
1000 if (nameError != null && !"android".equals(pkgName)) {
1001 outError[0] = "<manifest> specifies bad sharedUserId name \""
1002 + str + "\": " + nameError;
1003 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
1004 return null;
1005 }
1006 pkg.mSharedUserId = str.intern();
1007 pkg.mSharedUserLabel = sa.getResourceId(
1008 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
1009 }
1010 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -08001011
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08001012 pkg.installLocation = sa.getInteger(
1013 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -07001014 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001015 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -07001016
1017 /* Set the global "forward lock" flag */
1018 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1019 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1020 }
1021
1022 /* Set the global "on SD card" flag */
1023 if ((flags & PARSE_ON_SDCARD) != 0) {
1024 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
1025 }
1026
Dianne Hackborn723738c2009-06-25 19:48:04 -07001027 // Resource boolean are -1, so 1 means we don't know the value.
1028 int supportsSmallScreens = 1;
1029 int supportsNormalScreens = 1;
1030 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001031 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001032 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001033 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001036 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1037 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1038 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 continue;
1040 }
1041
1042 String tagName = parser.getName();
1043 if (tagName.equals("application")) {
1044 if (foundApp) {
1045 if (RIGID_PARSER) {
1046 outError[0] = "<manifest> has more than one <application>";
1047 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1048 return null;
1049 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001050 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 XmlUtils.skipCurrentTag(parser);
1052 continue;
1053 }
1054 }
1055
1056 foundApp = true;
1057 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1058 return null;
1059 }
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +01001060 } else if (tagName.equals("overlay")) {
1061 pkg.mTrustedOverlay = trustedOverlay;
1062
1063 sa = res.obtainAttributes(attrs,
1064 com.android.internal.R.styleable.AndroidManifestResourceOverlay);
1065 pkg.mOverlayTarget = sa.getString(
1066 com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage);
1067 pkg.mOverlayPriority = sa.getInt(
1068 com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority,
1069 -1);
1070 sa.recycle();
1071
1072 if (pkg.mOverlayTarget == null) {
1073 outError[0] = "<overlay> does not specify a target package";
1074 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1075 return null;
1076 }
1077 if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) {
1078 outError[0] = "<overlay> priority must be between 0 and 9999";
1079 mParseError =
1080 PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1081 return null;
1082 }
1083 XmlUtils.skipCurrentTag(parser);
1084
Geremy Condraf1bcca82013-01-07 22:35:24 -08001085 } else if (tagName.equals("keys")) {
1086 if (!parseKeys(pkg, res, parser, attrs, outError)) {
1087 return null;
1088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001090 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 return null;
1092 }
1093 } else if (tagName.equals("permission")) {
1094 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1095 return null;
1096 }
1097 } else if (tagName.equals("permission-tree")) {
1098 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1099 return null;
1100 }
1101 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001102 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1103 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 } else if (tagName.equals("uses-configuration")) {
1107 ConfigurationInfo cPref = new ConfigurationInfo();
1108 sa = res.obtainAttributes(attrs,
1109 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1110 cPref.reqTouchScreen = sa.getInt(
1111 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1112 Configuration.TOUCHSCREEN_UNDEFINED);
1113 cPref.reqKeyboardType = sa.getInt(
1114 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1115 Configuration.KEYBOARD_UNDEFINED);
1116 if (sa.getBoolean(
1117 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1118 false)) {
1119 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1120 }
1121 cPref.reqNavigation = sa.getInt(
1122 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1123 Configuration.NAVIGATION_UNDEFINED);
1124 if (sa.getBoolean(
1125 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1126 false)) {
1127 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1128 }
1129 sa.recycle();
1130 pkg.configPreferences.add(cPref);
1131
1132 XmlUtils.skipCurrentTag(parser);
1133
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001134 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001135 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001136 sa = res.obtainAttributes(attrs,
1137 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001138 // Note: don't allow this value to be a reference to a resource
1139 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001140 fi.name = sa.getNonResourceString(
1141 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1142 if (fi.name == null) {
1143 fi.reqGlEsVersion = sa.getInt(
1144 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1145 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1146 }
1147 if (sa.getBoolean(
1148 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1149 true)) {
1150 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1151 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001152 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001153 if (pkg.reqFeatures == null) {
1154 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1155 }
1156 pkg.reqFeatures.add(fi);
1157
1158 if (fi.name == null) {
1159 ConfigurationInfo cPref = new ConfigurationInfo();
1160 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1161 pkg.configPreferences.add(cPref);
1162 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001163
1164 XmlUtils.skipCurrentTag(parser);
1165
Dianne Hackborn851a5412009-05-08 12:06:44 -07001166 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001167 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 sa = res.obtainAttributes(attrs,
1169 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1170
Dianne Hackborn851a5412009-05-08 12:06:44 -07001171 int minVers = 0;
1172 String minCode = null;
1173 int targetVers = 0;
1174 String targetCode = null;
1175
1176 TypedValue val = sa.peekValue(
1177 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1178 if (val != null) {
1179 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1180 targetCode = minCode = val.string.toString();
1181 } else {
1182 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001183 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001184 }
1185 }
1186
1187 val = sa.peekValue(
1188 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1189 if (val != null) {
1190 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1191 targetCode = minCode = val.string.toString();
1192 } else {
1193 // If it's not a string, it's an integer.
1194 targetVers = val.data;
1195 }
1196 }
1197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 sa.recycle();
1199
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001200 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001201 if (!minCode.equals(SDK_CODENAME)) {
1202 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001203 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001204 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001205 } else {
1206 outError[0] = "Requires development platform " + minCode
1207 + " but this is a release platform.";
1208 }
1209 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1210 return null;
1211 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001212 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001213 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001214 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001215 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1216 return null;
1217 }
1218
Dianne Hackborn851a5412009-05-08 12:06:44 -07001219 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001220 if (!targetCode.equals(SDK_CODENAME)) {
1221 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001222 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001223 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001224 } else {
1225 outError[0] = "Requires development platform " + targetCode
1226 + " but this is a release platform.";
1227 }
1228 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1229 return null;
1230 }
1231 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001232 pkg.applicationInfo.targetSdkVersion
1233 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1234 } else {
1235 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238
1239 XmlUtils.skipCurrentTag(parser);
1240
Dianne Hackborn723738c2009-06-25 19:48:04 -07001241 } else if (tagName.equals("supports-screens")) {
1242 sa = res.obtainAttributes(attrs,
1243 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1244
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001245 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1246 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1247 0);
1248 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1249 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1250 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001251 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1252 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1253 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001254
Dianne Hackborn723738c2009-06-25 19:48:04 -07001255 // This is a trick to get a boolean and still able to detect
1256 // if a value was actually set.
1257 supportsSmallScreens = sa.getInteger(
1258 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1259 supportsSmallScreens);
1260 supportsNormalScreens = sa.getInteger(
1261 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1262 supportsNormalScreens);
1263 supportsLargeScreens = sa.getInteger(
1264 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1265 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001266 supportsXLargeScreens = sa.getInteger(
1267 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1268 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001269 resizeable = sa.getInteger(
1270 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001271 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001272 anyDensity = sa.getInteger(
1273 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1274 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001275
1276 sa.recycle();
1277
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001278 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001279
1280 } else if (tagName.equals("protected-broadcast")) {
1281 sa = res.obtainAttributes(attrs,
1282 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1283
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001284 // Note: don't allow this value to be a reference to a resource
1285 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001286 String name = sa.getNonResourceString(
1287 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1288
1289 sa.recycle();
1290
1291 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1292 if (pkg.protectedBroadcasts == null) {
1293 pkg.protectedBroadcasts = new ArrayList<String>();
1294 }
1295 if (!pkg.protectedBroadcasts.contains(name)) {
1296 pkg.protectedBroadcasts.add(name.intern());
1297 }
1298 }
1299
1300 XmlUtils.skipCurrentTag(parser);
1301
1302 } else if (tagName.equals("instrumentation")) {
1303 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1304 return null;
1305 }
1306
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001307 } else if (tagName.equals("original-package")) {
1308 sa = res.obtainAttributes(attrs,
1309 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1310
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001311 String orig =sa.getNonConfigurationString(
1312 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001313 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001314 if (pkg.mOriginalPackages == null) {
1315 pkg.mOriginalPackages = new ArrayList<String>();
1316 pkg.mRealPackage = pkg.packageName;
1317 }
1318 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001319 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001320
1321 sa.recycle();
1322
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001323 XmlUtils.skipCurrentTag(parser);
1324
1325 } else if (tagName.equals("adopt-permissions")) {
1326 sa = res.obtainAttributes(attrs,
1327 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1328
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001329 String name = sa.getNonConfigurationString(
1330 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001331
1332 sa.recycle();
1333
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001334 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001335 if (pkg.mAdoptPermissions == null) {
1336 pkg.mAdoptPermissions = new ArrayList<String>();
1337 }
1338 pkg.mAdoptPermissions.add(name);
1339 }
1340
1341 XmlUtils.skipCurrentTag(parser);
1342
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001343 } else if (tagName.equals("uses-gl-texture")) {
1344 // Just skip this tag
1345 XmlUtils.skipCurrentTag(parser);
1346 continue;
1347
1348 } else if (tagName.equals("compatible-screens")) {
1349 // Just skip this tag
1350 XmlUtils.skipCurrentTag(parser);
1351 continue;
Michael Wrighteaeb1902013-09-05 18:15:57 -07001352 } else if (tagName.equals("supports-input")) {
1353 XmlUtils.skipCurrentTag(parser);
1354 continue;
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001355
Dianne Hackborn854060a2009-07-09 18:14:31 -07001356 } else if (tagName.equals("eat-comment")) {
1357 // Just skip this tag
1358 XmlUtils.skipCurrentTag(parser);
1359 continue;
1360
1361 } else if (RIGID_PARSER) {
1362 outError[0] = "Bad element under <manifest>: "
1363 + parser.getName();
1364 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1365 return null;
1366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001368 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001369 + " at " + mArchiveSourcePath + " "
1370 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 XmlUtils.skipCurrentTag(parser);
1372 continue;
1373 }
1374 }
1375
1376 if (!foundApp && pkg.instrumentation.size() == 0) {
1377 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1378 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1379 }
1380
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001381 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001382 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001383 for (int ip=0; ip<NP; ip++) {
1384 final PackageParser.NewPermissionInfo npi
1385 = PackageParser.NEW_PERMISSIONS[ip];
1386 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1387 break;
1388 }
1389 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001390 if (implicitPerms == null) {
1391 implicitPerms = new StringBuilder(128);
1392 implicitPerms.append(pkg.packageName);
1393 implicitPerms.append(": compat added ");
1394 } else {
1395 implicitPerms.append(' ');
1396 }
1397 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001398 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001399 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001400 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001401 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001402 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001403 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001404 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001405
1406 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1407 for (int is=0; is<NS; is++) {
1408 final PackageParser.SplitPermissionInfo spi
1409 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001410 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1411 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001412 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001413 }
1414 for (int in=0; in<spi.newPerms.length; in++) {
1415 final String perm = spi.newPerms[in];
1416 if (!pkg.requestedPermissions.contains(perm)) {
1417 pkg.requestedPermissions.add(perm);
1418 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1419 }
1420 }
1421 }
1422
Dianne Hackborn723738c2009-06-25 19:48:04 -07001423 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1424 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001425 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001426 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1427 }
1428 if (supportsNormalScreens != 0) {
1429 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1430 }
1431 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1432 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001433 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001434 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1435 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001436 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1437 && pkg.applicationInfo.targetSdkVersion
1438 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1439 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1440 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001441 if (resizeable < 0 || (resizeable > 0
1442 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001443 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001444 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1445 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001446 if (anyDensity < 0 || (anyDensity > 0
1447 && pkg.applicationInfo.targetSdkVersion
1448 >= android.os.Build.VERSION_CODES.DONUT)) {
1449 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001450 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001451
Nick Kralevich38f130e2013-04-04 13:19:10 -07001452 /*
1453 * b/8528162: Ignore the <uses-permission android:required> attribute if
1454 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1455 * which are improperly using this attribute, even though it never worked.
1456 */
1457 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1458 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1459 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1460 }
1461 }
1462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 return pkg;
1464 }
1465
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001466 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1467 AttributeSet attrs, String[] outError)
1468 throws XmlPullParserException, IOException {
1469 TypedArray sa = res.obtainAttributes(attrs,
1470 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1471
1472 // Note: don't allow this value to be a reference to a resource
1473 // that may change.
1474 String name = sa.getNonResourceString(
1475 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001476/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001477 boolean required = sa.getBoolean(
1478 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001479*/
1480 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001481
Christopher Tatefb0676a2013-09-16 16:34:52 -07001482 int maxSdkVersion = 0;
1483 TypedValue val = sa.peekValue(
1484 com.android.internal.R.styleable.AndroidManifestUsesPermission_maxSdkVersion);
1485 if (val != null) {
1486 if (val.type >= TypedValue.TYPE_FIRST_INT && val.type <= TypedValue.TYPE_LAST_INT) {
1487 maxSdkVersion = val.data;
1488 }
1489 }
1490
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001491 sa.recycle();
1492
Christopher Tatefb0676a2013-09-16 16:34:52 -07001493 if ((maxSdkVersion == 0) || (maxSdkVersion >= Build.VERSION.RESOURCES_SDK_INT)) {
1494 if (name != null) {
1495 int index = pkg.requestedPermissions.indexOf(name);
1496 if (index == -1) {
1497 pkg.requestedPermissions.add(name.intern());
1498 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1499 } else {
1500 if (pkg.requestedPermissionsRequired.get(index) != required) {
1501 outError[0] = "conflicting <uses-permission> entries";
1502 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1503 return false;
1504 }
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001505 }
1506 }
1507 }
1508
1509 XmlUtils.skipCurrentTag(parser);
1510 return true;
1511 }
1512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 private static String buildClassName(String pkg, CharSequence clsSeq,
1514 String[] outError) {
1515 if (clsSeq == null || clsSeq.length() <= 0) {
1516 outError[0] = "Empty class name in package " + pkg;
1517 return null;
1518 }
1519 String cls = clsSeq.toString();
1520 char c = cls.charAt(0);
1521 if (c == '.') {
1522 return (pkg + cls).intern();
1523 }
1524 if (cls.indexOf('.') < 0) {
1525 StringBuilder b = new StringBuilder(pkg);
1526 b.append('.');
1527 b.append(cls);
1528 return b.toString().intern();
1529 }
1530 if (c >= 'a' && c <= 'z') {
1531 return cls.intern();
1532 }
1533 outError[0] = "Bad class name " + cls + " in package " + pkg;
1534 return null;
1535 }
1536
1537 private static String buildCompoundName(String pkg,
1538 CharSequence procSeq, String type, String[] outError) {
1539 String proc = procSeq.toString();
1540 char c = proc.charAt(0);
1541 if (pkg != null && c == ':') {
1542 if (proc.length() < 2) {
1543 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1544 + ": must be at least two characters";
1545 return null;
1546 }
1547 String subName = proc.substring(1);
1548 String nameError = validateName(subName, false);
1549 if (nameError != null) {
1550 outError[0] = "Invalid " + type + " name " + proc + " in package "
1551 + pkg + ": " + nameError;
1552 return null;
1553 }
1554 return (pkg + proc).intern();
1555 }
1556 String nameError = validateName(proc, true);
1557 if (nameError != null && !"system".equals(proc)) {
1558 outError[0] = "Invalid " + type + " name " + proc + " in package "
1559 + pkg + ": " + nameError;
1560 return null;
1561 }
1562 return proc.intern();
1563 }
1564
1565 private static String buildProcessName(String pkg, String defProc,
1566 CharSequence procSeq, int flags, String[] separateProcesses,
1567 String[] outError) {
1568 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1569 return defProc != null ? defProc : pkg;
1570 }
1571 if (separateProcesses != null) {
1572 for (int i=separateProcesses.length-1; i>=0; i--) {
1573 String sp = separateProcesses[i];
1574 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1575 return pkg;
1576 }
1577 }
1578 }
1579 if (procSeq == null || procSeq.length() <= 0) {
1580 return defProc;
1581 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001582 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 }
1584
1585 private static String buildTaskAffinityName(String pkg, String defProc,
1586 CharSequence procSeq, String[] outError) {
1587 if (procSeq == null) {
1588 return defProc;
1589 }
1590 if (procSeq.length() <= 0) {
1591 return null;
1592 }
1593 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1594 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001595
1596 private boolean parseKeys(Package owner, Resources res,
1597 XmlPullParser parser, AttributeSet attrs, String[] outError)
1598 throws XmlPullParserException, IOException {
1599 // we've encountered the 'keys' tag
1600 // all the keys and keysets that we want must be defined here
1601 // so we're going to iterate over the parser and pull out the things we want
1602 int outerDepth = parser.getDepth();
1603
1604 int type;
1605 PublicKey currentKey = null;
Kenny Root37dca152013-07-10 14:01:49 -07001606 int currentKeyDepth = -1;
Geremy Condraf1bcca82013-01-07 22:35:24 -08001607 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1608 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1609 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1610 if (type == XmlPullParser.END_TAG) {
Kenny Root37dca152013-07-10 14:01:49 -07001611 if (parser.getDepth() == currentKeyDepth) {
1612 currentKey = null;
1613 currentKeyDepth = -1;
1614 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001615 continue;
1616 }
1617 String tagname = parser.getName();
1618 if (tagname.equals("publicKey")) {
1619 final TypedArray sa = res.obtainAttributes(attrs,
1620 com.android.internal.R.styleable.PublicKey);
1621 final String encodedKey = sa.getNonResourceString(
1622 com.android.internal.R.styleable.PublicKey_value);
1623 currentKey = parsePublicKey(encodedKey);
Kenny Root37dca152013-07-10 14:01:49 -07001624 if (currentKey == null) {
1625 Slog.w(TAG, "No valid key in 'publicKey' tag at "
1626 + parser.getPositionDescription());
1627 sa.recycle();
1628 continue;
1629 }
1630 currentKeyDepth = parser.getDepth();
Geremy Condraf1bcca82013-01-07 22:35:24 -08001631 definedKeySets.put(currentKey, new HashSet<String>());
1632 sa.recycle();
Kenny Root2758e292013-07-08 09:32:59 -07001633 } else if (tagname.equals("keyset")) {
Kenny Root37dca152013-07-10 14:01:49 -07001634 if (currentKey == null) {
1635 Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
1636 + parser.getPositionDescription());
1637 continue;
1638 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001639 final TypedArray sa = res.obtainAttributes(attrs,
1640 com.android.internal.R.styleable.KeySet);
1641 final String name = sa.getNonResourceString(
1642 com.android.internal.R.styleable.KeySet_name);
1643 definedKeySets.get(currentKey).add(name);
1644 sa.recycle();
1645 } else if (RIGID_PARSER) {
1646 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1647 + " at " + mArchiveSourcePath + " "
1648 + parser.getPositionDescription());
1649 return false;
1650 } else {
1651 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1652 + " at " + mArchiveSourcePath + " "
1653 + parser.getPositionDescription());
1654 XmlUtils.skipCurrentTag(parser);
1655 continue;
1656 }
1657 }
1658
1659 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1660 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1661 PublicKey key = e.getKey();
1662 Set<String> keySetNames = e.getValue();
1663 for (String alias : keySetNames) {
1664 if (owner.mKeySetMapping.containsKey(alias)) {
1665 owner.mKeySetMapping.get(alias).add(key);
1666 } else {
1667 Set<PublicKey> keys = new HashSet<PublicKey>();
1668 keys.add(key);
1669 owner.mKeySetMapping.put(alias, keys);
1670 }
1671 }
1672 }
1673
1674 return true;
1675 }
1676
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001677 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 XmlPullParser parser, AttributeSet attrs, String[] outError)
1679 throws XmlPullParserException, IOException {
1680 PermissionGroup perm = new PermissionGroup(owner);
1681
1682 TypedArray sa = res.obtainAttributes(attrs,
1683 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1684
1685 if (!parsePackageItemInfo(owner, perm.info, outError,
1686 "<permission-group>", sa,
1687 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1688 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001689 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1690 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 sa.recycle();
1692 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1693 return null;
1694 }
1695
1696 perm.info.descriptionRes = sa.getResourceId(
1697 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1698 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001699 perm.info.flags = sa.getInt(
1700 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001701 perm.info.priority = sa.getInt(
1702 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001703 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001704 perm.info.priority = 0;
1705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706
1707 sa.recycle();
1708
1709 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1710 outError)) {
1711 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1712 return null;
1713 }
1714
1715 owner.permissionGroups.add(perm);
1716
1717 return perm;
1718 }
1719
1720 private Permission parsePermission(Package owner, Resources res,
1721 XmlPullParser parser, AttributeSet attrs, String[] outError)
1722 throws XmlPullParserException, IOException {
1723 Permission perm = new Permission(owner);
1724
1725 TypedArray sa = res.obtainAttributes(attrs,
1726 com.android.internal.R.styleable.AndroidManifestPermission);
1727
1728 if (!parsePackageItemInfo(owner, perm.info, outError,
1729 "<permission>", sa,
1730 com.android.internal.R.styleable.AndroidManifestPermission_name,
1731 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001732 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1733 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 sa.recycle();
1735 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1736 return null;
1737 }
1738
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001739 // Note: don't allow this value to be a reference to a resource
1740 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001741 perm.info.group = sa.getNonResourceString(
1742 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1743 if (perm.info.group != null) {
1744 perm.info.group = perm.info.group.intern();
1745 }
1746
1747 perm.info.descriptionRes = sa.getResourceId(
1748 com.android.internal.R.styleable.AndroidManifestPermission_description,
1749 0);
1750
1751 perm.info.protectionLevel = sa.getInt(
1752 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1753 PermissionInfo.PROTECTION_NORMAL);
1754
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001755 perm.info.flags = sa.getInt(
1756 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 if (perm.info.protectionLevel == -1) {
1761 outError[0] = "<permission> does not specify protectionLevel";
1762 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1763 return null;
1764 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001765
1766 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1767
1768 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1769 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1770 PermissionInfo.PROTECTION_SIGNATURE) {
1771 outError[0] = "<permission> protectionLevel specifies a flag but is "
1772 + "not based on signature type";
1773 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1774 return null;
1775 }
1776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777
1778 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1779 outError)) {
1780 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1781 return null;
1782 }
1783
1784 owner.permissions.add(perm);
1785
1786 return perm;
1787 }
1788
1789 private Permission parsePermissionTree(Package owner, Resources res,
1790 XmlPullParser parser, AttributeSet attrs, String[] outError)
1791 throws XmlPullParserException, IOException {
1792 Permission perm = new Permission(owner);
1793
1794 TypedArray sa = res.obtainAttributes(attrs,
1795 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1796
1797 if (!parsePackageItemInfo(owner, perm.info, outError,
1798 "<permission-tree>", sa,
1799 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1800 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001801 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1802 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 sa.recycle();
1804 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1805 return null;
1806 }
1807
1808 sa.recycle();
1809
1810 int index = perm.info.name.indexOf('.');
1811 if (index > 0) {
1812 index = perm.info.name.indexOf('.', index+1);
1813 }
1814 if (index < 0) {
1815 outError[0] = "<permission-tree> name has less than three segments: "
1816 + perm.info.name;
1817 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1818 return null;
1819 }
1820
1821 perm.info.descriptionRes = 0;
1822 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1823 perm.tree = true;
1824
1825 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1826 outError)) {
1827 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1828 return null;
1829 }
1830
1831 owner.permissions.add(perm);
1832
1833 return perm;
1834 }
1835
1836 private Instrumentation parseInstrumentation(Package owner, Resources res,
1837 XmlPullParser parser, AttributeSet attrs, String[] outError)
1838 throws XmlPullParserException, IOException {
1839 TypedArray sa = res.obtainAttributes(attrs,
1840 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1841
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001842 if (mParseInstrumentationArgs == null) {
1843 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1844 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1845 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001846 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1847 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001848 mParseInstrumentationArgs.tag = "<instrumentation>";
1849 }
1850
1851 mParseInstrumentationArgs.sa = sa;
1852
1853 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1854 new InstrumentationInfo());
1855 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 sa.recycle();
1857 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1858 return null;
1859 }
1860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001862 // Note: don't allow this value to be a reference to a resource
1863 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 str = sa.getNonResourceString(
1865 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1866 a.info.targetPackage = str != null ? str.intern() : null;
1867
1868 a.info.handleProfiling = sa.getBoolean(
1869 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1870 false);
1871
1872 a.info.functionalTest = sa.getBoolean(
1873 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1874 false);
1875
1876 sa.recycle();
1877
1878 if (a.info.targetPackage == null) {
1879 outError[0] = "<instrumentation> does not specify targetPackage";
1880 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1881 return null;
1882 }
1883
1884 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1885 outError)) {
1886 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1887 return null;
1888 }
1889
1890 owner.instrumentation.add(a);
1891
1892 return a;
1893 }
1894
1895 private boolean parseApplication(Package owner, Resources res,
1896 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1897 throws XmlPullParserException, IOException {
1898 final ApplicationInfo ai = owner.applicationInfo;
1899 final String pkgName = owner.applicationInfo.packageName;
1900
1901 TypedArray sa = res.obtainAttributes(attrs,
1902 com.android.internal.R.styleable.AndroidManifestApplication);
1903
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001904 String name = sa.getNonConfigurationString(
1905 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906 if (name != null) {
1907 ai.className = buildClassName(pkgName, name, outError);
1908 if (ai.className == null) {
1909 sa.recycle();
1910 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1911 return false;
1912 }
1913 }
1914
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001915 String manageSpaceActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001916 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
1917 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 if (manageSpaceActivity != null) {
1919 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1920 outError);
1921 }
1922
Christopher Tate181fafa2009-05-14 11:12:14 -07001923 boolean allowBackup = sa.getBoolean(
1924 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1925 if (allowBackup) {
1926 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001927
Christopher Tate3de55bc2010-03-12 17:28:08 -08001928 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1929 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001930 String backupAgent = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07001931 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
1932 Configuration.NATIVE_CONFIG_VERSION);
Christopher Tate181fafa2009-05-14 11:12:14 -07001933 if (backupAgent != null) {
1934 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001935 if (DEBUG_BACKUP) {
1936 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001937 + " from " + pkgName + "+" + backupAgent);
1938 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001939
1940 if (sa.getBoolean(
1941 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1942 true)) {
1943 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1944 }
1945 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001946 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1947 false)) {
1948 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1949 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001950 }
1951 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 TypedValue v = sa.peekValue(
1954 com.android.internal.R.styleable.AndroidManifestApplication_label);
1955 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1956 ai.nonLocalizedLabel = v.coerceToString();
1957 }
1958
1959 ai.icon = sa.getResourceId(
1960 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001961 ai.logo = sa.getResourceId(
1962 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001964 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 ai.descriptionRes = sa.getResourceId(
1966 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1967
1968 if ((flags&PARSE_IS_SYSTEM) != 0) {
1969 if (sa.getBoolean(
1970 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1971 false)) {
1972 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1973 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001974 }
1975
1976 if (sa.getBoolean(
1977 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1978 false)) {
1979 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001980 }
1981
1982 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1983 .AndroidManifestApplication_restrictedAccountType);
1984 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1985 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 }
1987
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001988 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1989 .AndroidManifestApplication_requiredAccountType);
1990 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1991 owner.mRequiredAccountType = requiredAccountType;
1992 }
1993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 if (sa.getBoolean(
1995 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1996 false)) {
1997 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1998 }
1999
2000 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07002001 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08002002 false)) {
2003 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
2004 }
2005
Romain Guy529b60a2010-08-03 18:05:47 -07002006 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07002007 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07002008 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07002009
2010 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
2012 true)) {
2013 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
2014 }
2015
2016 if (sa.getBoolean(
2017 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
2018 false)) {
2019 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
2020 }
2021
2022 if (sa.getBoolean(
2023 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
2024 true)) {
2025 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
2026 }
2027
Dianne Hackbornade3eca2009-05-11 18:54:45 -07002028 if (sa.getBoolean(
2029 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07002030 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07002031 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
2032 }
2033
Jason parksa3cdaa52011-01-13 14:15:43 -06002034 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08002035 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06002036 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08002037 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06002038 }
2039
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07002040 if (sa.getBoolean(
2041 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
2042 false /* default is no RTL support*/)) {
2043 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
2044 }
2045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002047 str = sa.getNonConfigurationString(
2048 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002049 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
2050
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002051 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2052 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002053 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
2054 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002055 } else {
2056 // Some older apps have been seen to use a resource reference
2057 // here that on older builds was ignored (with a warning). We
2058 // need to continue to do this for them so they don't break.
2059 str = sa.getNonResourceString(
2060 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
2061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
2063 str, outError);
2064
2065 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002066 CharSequence pname;
2067 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2068 pname = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002069 com.android.internal.R.styleable.AndroidManifestApplication_process,
2070 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002071 } else {
2072 // Some older apps have been seen to use a resource reference
2073 // here that on older builds was ignored (with a warning). We
2074 // need to continue to do this for them so they don't break.
2075 pname = sa.getNonResourceString(
2076 com.android.internal.R.styleable.AndroidManifestApplication_process);
2077 }
2078 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 flags, mSeparateProcesses, outError);
2080
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002081 ai.enabled = sa.getBoolean(
2082 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002083
Dianne Hackborn02486b12010-08-26 14:18:37 -07002084 if (false) {
2085 if (sa.getBoolean(
2086 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2087 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002088 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002089
2090 // A heavy-weight application can not be in a custom process.
2091 // We can do direct compare because we intern all strings.
2092 if (ai.processName != null && ai.processName != ai.packageName) {
2093 outError[0] = "cantSaveState applications can not use custom processes";
2094 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002095 }
2096 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 }
2098
Adam Powell269248d2011-08-02 10:26:54 -07002099 ai.uiOptions = sa.getInt(
2100 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 sa.recycle();
2103
2104 if (outError[0] != null) {
2105 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2106 return false;
2107 }
2108
2109 final int innerDepth = parser.getDepth();
2110
2111 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002112 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2113 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2114 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 continue;
2116 }
2117
2118 String tagName = parser.getName();
2119 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002120 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2121 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 if (a == null) {
2123 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2124 return false;
2125 }
2126
2127 owner.activities.add(a);
2128
2129 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002130 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 if (a == null) {
2132 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2133 return false;
2134 }
2135
2136 owner.receivers.add(a);
2137
2138 } else if (tagName.equals("service")) {
2139 Service s = parseService(owner, res, parser, attrs, flags, outError);
2140 if (s == null) {
2141 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2142 return false;
2143 }
2144
2145 owner.services.add(s);
2146
2147 } else if (tagName.equals("provider")) {
2148 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2149 if (p == null) {
2150 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2151 return false;
2152 }
2153
2154 owner.providers.add(p);
2155
2156 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002157 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 if (a == null) {
2159 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2160 return false;
2161 }
2162
2163 owner.activities.add(a);
2164
2165 } else if (parser.getName().equals("meta-data")) {
2166 // note: application meta-data is stored off to the side, so it can
2167 // remain null in the primary copy (we like to avoid extra copies because
2168 // it can be large)
2169 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2170 outError)) == null) {
2171 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2172 return false;
2173 }
2174
Dianne Hackbornc895be72013-03-11 17:48:43 -07002175 } else if (tagName.equals("library")) {
2176 sa = res.obtainAttributes(attrs,
2177 com.android.internal.R.styleable.AndroidManifestLibrary);
2178
2179 // Note: don't allow this value to be a reference to a resource
2180 // that may change.
2181 String lname = sa.getNonResourceString(
2182 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2183
2184 sa.recycle();
2185
2186 if (lname != null) {
2187 if (owner.libraryNames == null) {
2188 owner.libraryNames = new ArrayList<String>();
2189 }
2190 if (!owner.libraryNames.contains(lname)) {
2191 owner.libraryNames.add(lname.intern());
2192 }
2193 }
2194
2195 XmlUtils.skipCurrentTag(parser);
2196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 } else if (tagName.equals("uses-library")) {
2198 sa = res.obtainAttributes(attrs,
2199 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2200
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002201 // Note: don't allow this value to be a reference to a resource
2202 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 String lname = sa.getNonResourceString(
2204 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002205 boolean req = sa.getBoolean(
2206 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2207 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208
2209 sa.recycle();
2210
Dianne Hackborn49237342009-08-27 20:08:01 -07002211 if (lname != null) {
2212 if (req) {
2213 if (owner.usesLibraries == null) {
2214 owner.usesLibraries = new ArrayList<String>();
2215 }
2216 if (!owner.usesLibraries.contains(lname)) {
2217 owner.usesLibraries.add(lname.intern());
2218 }
2219 } else {
2220 if (owner.usesOptionalLibraries == null) {
2221 owner.usesOptionalLibraries = new ArrayList<String>();
2222 }
2223 if (!owner.usesOptionalLibraries.contains(lname)) {
2224 owner.usesOptionalLibraries.add(lname.intern());
2225 }
2226 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 }
2228
2229 XmlUtils.skipCurrentTag(parser);
2230
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002231 } else if (tagName.equals("uses-package")) {
2232 // Dependencies for app installers; we don't currently try to
2233 // enforce this.
2234 XmlUtils.skipCurrentTag(parser);
2235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 } else {
2237 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002238 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002239 + " at " + mArchiveSourcePath + " "
2240 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 XmlUtils.skipCurrentTag(parser);
2242 continue;
2243 } else {
2244 outError[0] = "Bad element under <application>: " + tagName;
2245 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2246 return false;
2247 }
2248 }
2249 }
2250
2251 return true;
2252 }
2253
2254 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2255 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002256 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002257 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 if (name == null) {
2259 outError[0] = tag + " does not specify android:name";
2260 return false;
2261 }
2262
2263 outInfo.name
2264 = buildClassName(owner.applicationInfo.packageName, name, outError);
2265 if (outInfo.name == null) {
2266 return false;
2267 }
2268
2269 int iconVal = sa.getResourceId(iconRes, 0);
2270 if (iconVal != 0) {
2271 outInfo.icon = iconVal;
2272 outInfo.nonLocalizedLabel = null;
2273 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002274
2275 int logoVal = sa.getResourceId(logoRes, 0);
2276 if (logoVal != 0) {
2277 outInfo.logo = logoVal;
2278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279
2280 TypedValue v = sa.peekValue(labelRes);
2281 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2282 outInfo.nonLocalizedLabel = v.coerceToString();
2283 }
2284
2285 outInfo.packageName = owner.packageName;
2286
2287 return true;
2288 }
2289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 private Activity parseActivity(Package owner, Resources res,
2291 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002292 boolean receiver, boolean hardwareAccelerated)
2293 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 TypedArray sa = res.obtainAttributes(attrs,
2295 com.android.internal.R.styleable.AndroidManifestActivity);
2296
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002297 if (mParseActivityArgs == null) {
2298 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2299 com.android.internal.R.styleable.AndroidManifestActivity_name,
2300 com.android.internal.R.styleable.AndroidManifestActivity_label,
2301 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002302 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002303 mSeparateProcesses,
2304 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002305 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002306 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2307 }
2308
2309 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2310 mParseActivityArgs.sa = sa;
2311 mParseActivityArgs.flags = flags;
2312
2313 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2314 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 sa.recycle();
2316 return null;
2317 }
2318
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002319 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2321 if (setExported) {
2322 a.info.exported = sa.getBoolean(
2323 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2324 }
2325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 a.info.theme = sa.getResourceId(
2327 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2328
Adam Powell269248d2011-08-02 10:26:54 -07002329 a.info.uiOptions = sa.getInt(
2330 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2331 a.info.applicationInfo.uiOptions);
2332
Adam Powelldd8fab22012-03-22 17:47:27 -07002333 String parentName = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002334 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName,
2335 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002336 if (parentName != null) {
2337 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2338 if (outError[0] == null) {
2339 a.info.parentActivityName = parentClassName;
2340 } else {
2341 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2342 parentName);
2343 outError[0] = null;
2344 }
2345 }
2346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002348 str = sa.getNonConfigurationString(
2349 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 if (str == null) {
2351 a.info.permission = owner.applicationInfo.permission;
2352 } else {
2353 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2354 }
2355
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002356 str = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002357 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity,
2358 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2360 owner.applicationInfo.taskAffinity, str, outError);
2361
2362 a.info.flags = 0;
2363 if (sa.getBoolean(
2364 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2365 false)) {
2366 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2367 }
2368
2369 if (sa.getBoolean(
2370 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2371 false)) {
2372 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2373 }
2374
2375 if (sa.getBoolean(
2376 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2377 false)) {
2378 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2379 }
2380
2381 if (sa.getBoolean(
2382 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2383 false)) {
2384 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2385 }
2386
2387 if (sa.getBoolean(
2388 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2389 false)) {
2390 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2391 }
2392
2393 if (sa.getBoolean(
2394 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2395 false)) {
2396 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2397 }
2398
2399 if (sa.getBoolean(
2400 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2401 false)) {
2402 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2403 }
2404
2405 if (sa.getBoolean(
2406 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2407 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2408 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2409 }
2410
Dianne Hackbornffa42482009-09-23 22:20:11 -07002411 if (sa.getBoolean(
2412 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2413 false)) {
2414 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2415 }
2416
Daniel Sandler613dde42010-06-21 13:46:39 -04002417 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002418 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2419 false)) {
2420 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2421 }
2422
2423 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002424 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2425 false)) {
2426 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2427 }
Craig Mautner5962b122012-10-05 14:45:52 -07002428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002430 if (sa.getBoolean(
2431 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2432 hardwareAccelerated)) {
2433 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2434 }
2435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 a.info.launchMode = sa.getInt(
2437 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2438 ActivityInfo.LAUNCH_MULTIPLE);
2439 a.info.screenOrientation = sa.getInt(
2440 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2441 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2442 a.info.configChanges = sa.getInt(
2443 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2444 0);
2445 a.info.softInputMode = sa.getInt(
2446 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2447 0);
2448 } else {
2449 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2450 a.info.configChanges = 0;
2451 }
2452
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002453 if (receiver) {
2454 if (sa.getBoolean(
2455 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2456 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002457 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002458 if (a.info.exported) {
2459 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2460 + a.className + " at " + mArchiveSourcePath + " "
2461 + parser.getPositionDescription());
2462 a.info.exported = false;
2463 }
2464 setExported = true;
2465 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002466 if (sa.getBoolean(
2467 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2468 false)) {
2469 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2470 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002471 }
2472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 sa.recycle();
2474
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002475 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002476 // A heavy-weight application can not have receives in its main process
2477 // We can do direct compare because we intern all strings.
2478 if (a.info.processName == owner.packageName) {
2479 outError[0] = "Heavy-weight applications can not have receivers in main process";
2480 }
2481 }
2482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 if (outError[0] != null) {
2484 return null;
2485 }
2486
2487 int outerDepth = parser.getDepth();
2488 int type;
2489 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2490 && (type != XmlPullParser.END_TAG
2491 || parser.getDepth() > outerDepth)) {
2492 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2493 continue;
2494 }
2495
2496 if (parser.getName().equals("intent-filter")) {
2497 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002498 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 return null;
2500 }
2501 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002502 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002503 + mArchiveSourcePath + " "
2504 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 } else {
2506 a.intents.add(intent);
2507 }
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002508 } else if (!receiver && parser.getName().equals("preferred")) {
2509 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2510 if (!parseIntent(res, parser, attrs, false, intent, outError)) {
2511 return null;
2512 }
2513 if (intent.countActions() == 0) {
2514 Slog.w(TAG, "No actions in preferred at "
2515 + mArchiveSourcePath + " "
2516 + parser.getPositionDescription());
2517 } else {
2518 if (owner.preferredActivityFilters == null) {
2519 owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>();
2520 }
2521 owner.preferredActivityFilters.add(intent);
2522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 } else if (parser.getName().equals("meta-data")) {
2524 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2525 outError)) == null) {
2526 return null;
2527 }
2528 } else {
2529 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002530 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002532 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002533 + " at " + mArchiveSourcePath + " "
2534 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002536 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002537 + " at " + mArchiveSourcePath + " "
2538 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 }
2540 XmlUtils.skipCurrentTag(parser);
2541 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002543 if (receiver) {
2544 outError[0] = "Bad element under <receiver>: " + parser.getName();
2545 } else {
2546 outError[0] = "Bad element under <activity>: " + parser.getName();
2547 }
2548 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 }
2551 }
2552
2553 if (!setExported) {
2554 a.info.exported = a.intents.size() > 0;
2555 }
2556
2557 return a;
2558 }
2559
2560 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002561 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2562 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 TypedArray sa = res.obtainAttributes(attrs,
2564 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2565
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002566 String targetActivity = sa.getNonConfigurationString(
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002567 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity,
2568 Configuration.NATIVE_CONFIG_VERSION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 if (targetActivity == null) {
2570 outError[0] = "<activity-alias> does not specify android:targetActivity";
2571 sa.recycle();
2572 return null;
2573 }
2574
2575 targetActivity = buildClassName(owner.applicationInfo.packageName,
2576 targetActivity, outError);
2577 if (targetActivity == null) {
2578 sa.recycle();
2579 return null;
2580 }
2581
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002582 if (mParseActivityAliasArgs == null) {
2583 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2584 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2585 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2586 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002587 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002588 mSeparateProcesses,
2589 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002590 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002591 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2592 mParseActivityAliasArgs.tag = "<activity-alias>";
2593 }
2594
2595 mParseActivityAliasArgs.sa = sa;
2596 mParseActivityAliasArgs.flags = flags;
2597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 Activity target = null;
2599
2600 final int NA = owner.activities.size();
2601 for (int i=0; i<NA; i++) {
2602 Activity t = owner.activities.get(i);
2603 if (targetActivity.equals(t.info.name)) {
2604 target = t;
2605 break;
2606 }
2607 }
2608
2609 if (target == null) {
2610 outError[0] = "<activity-alias> target activity " + targetActivity
2611 + " not found in manifest";
2612 sa.recycle();
2613 return null;
2614 }
2615
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002616 ActivityInfo info = new ActivityInfo();
2617 info.targetActivity = targetActivity;
2618 info.configChanges = target.info.configChanges;
2619 info.flags = target.info.flags;
2620 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002621 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002622 info.labelRes = target.info.labelRes;
2623 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2624 info.launchMode = target.info.launchMode;
2625 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002626 if (info.descriptionRes == 0) {
2627 info.descriptionRes = target.info.descriptionRes;
2628 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002629 info.screenOrientation = target.info.screenOrientation;
2630 info.taskAffinity = target.info.taskAffinity;
2631 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002632 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002633 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002634 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002635
2636 Activity a = new Activity(mParseActivityAliasArgs, info);
2637 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 sa.recycle();
2639 return null;
2640 }
2641
2642 final boolean setExported = sa.hasValue(
2643 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2644 if (setExported) {
2645 a.info.exported = sa.getBoolean(
2646 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2647 }
2648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002650 str = sa.getNonConfigurationString(
2651 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 if (str != null) {
2653 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2654 }
2655
Adam Powelldd8fab22012-03-22 17:47:27 -07002656 String parentName = sa.getNonConfigurationString(
2657 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07002658 Configuration.NATIVE_CONFIG_VERSION);
Adam Powelldd8fab22012-03-22 17:47:27 -07002659 if (parentName != null) {
2660 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2661 if (outError[0] == null) {
2662 a.info.parentActivityName = parentClassName;
2663 } else {
2664 Log.e(TAG, "Activity alias " + a.info.name +
2665 " specified invalid parentActivityName " + parentName);
2666 outError[0] = null;
2667 }
2668 }
2669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 sa.recycle();
2671
2672 if (outError[0] != null) {
2673 return null;
2674 }
2675
2676 int outerDepth = parser.getDepth();
2677 int type;
2678 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2679 && (type != XmlPullParser.END_TAG
2680 || parser.getDepth() > outerDepth)) {
2681 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2682 continue;
2683 }
2684
2685 if (parser.getName().equals("intent-filter")) {
2686 ActivityIntentInfo intent = new ActivityIntentInfo(a);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07002687 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 return null;
2689 }
2690 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002691 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002692 + mArchiveSourcePath + " "
2693 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 } else {
2695 a.intents.add(intent);
2696 }
2697 } else if (parser.getName().equals("meta-data")) {
2698 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2699 outError)) == null) {
2700 return null;
2701 }
2702 } else {
2703 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002704 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002705 + " at " + mArchiveSourcePath + " "
2706 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 XmlUtils.skipCurrentTag(parser);
2708 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002709 } else {
2710 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2711 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 }
2714 }
2715
2716 if (!setExported) {
2717 a.info.exported = a.intents.size() > 0;
2718 }
2719
2720 return a;
2721 }
2722
2723 private Provider parseProvider(Package owner, Resources res,
2724 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2725 throws XmlPullParserException, IOException {
2726 TypedArray sa = res.obtainAttributes(attrs,
2727 com.android.internal.R.styleable.AndroidManifestProvider);
2728
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002729 if (mParseProviderArgs == null) {
2730 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2731 com.android.internal.R.styleable.AndroidManifestProvider_name,
2732 com.android.internal.R.styleable.AndroidManifestProvider_label,
2733 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002734 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002735 mSeparateProcesses,
2736 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002737 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002738 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2739 mParseProviderArgs.tag = "<provider>";
2740 }
2741
2742 mParseProviderArgs.sa = sa;
2743 mParseProviderArgs.flags = flags;
2744
2745 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2746 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 sa.recycle();
2748 return null;
2749 }
2750
Nick Kralevichf097b162012-07-28 12:43:48 -07002751 boolean providerExportedDefault = false;
2752
2753 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2754 // For compatibility, applications targeting API level 16 or lower
2755 // should have their content providers exported by default, unless they
2756 // specify otherwise.
2757 providerExportedDefault = true;
2758 }
2759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002761 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2762 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002764 String cpname = sa.getNonConfigurationString(
2765 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766
2767 p.info.isSyncable = sa.getBoolean(
2768 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2769 false);
2770
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002771 String permission = sa.getNonConfigurationString(
2772 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2773 String str = sa.getNonConfigurationString(
2774 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 if (str == null) {
2776 str = permission;
2777 }
2778 if (str == null) {
2779 p.info.readPermission = owner.applicationInfo.permission;
2780 } else {
2781 p.info.readPermission =
2782 str.length() > 0 ? str.toString().intern() : null;
2783 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002784 str = sa.getNonConfigurationString(
2785 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 if (str == null) {
2787 str = permission;
2788 }
2789 if (str == null) {
2790 p.info.writePermission = owner.applicationInfo.permission;
2791 } else {
2792 p.info.writePermission =
2793 str.length() > 0 ? str.toString().intern() : null;
2794 }
2795
2796 p.info.grantUriPermissions = sa.getBoolean(
2797 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2798 false);
2799
2800 p.info.multiprocess = sa.getBoolean(
2801 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2802 false);
2803
2804 p.info.initOrder = sa.getInt(
2805 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2806 0);
2807
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002808 p.info.flags = 0;
2809
2810 if (sa.getBoolean(
2811 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2812 false)) {
2813 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2814 if (p.info.exported) {
2815 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2816 + p.className + " at " + mArchiveSourcePath + " "
2817 + parser.getPositionDescription());
2818 p.info.exported = false;
2819 }
2820 }
2821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 sa.recycle();
2823
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002824 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002825 // A heavy-weight application can not have providers in its main process
2826 // We can do direct compare because we intern all strings.
2827 if (p.info.processName == owner.packageName) {
2828 outError[0] = "Heavy-weight applications can not have providers in main process";
2829 return null;
2830 }
2831 }
2832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002834 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 return null;
2836 }
2837 p.info.authority = cpname.intern();
2838
2839 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2840 return null;
2841 }
2842
2843 return p;
2844 }
2845
2846 private boolean parseProviderTags(Resources res,
2847 XmlPullParser parser, AttributeSet attrs,
2848 Provider outInfo, String[] outError)
2849 throws XmlPullParserException, IOException {
2850 int outerDepth = parser.getDepth();
2851 int type;
2852 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2853 && (type != XmlPullParser.END_TAG
2854 || parser.getDepth() > outerDepth)) {
2855 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2856 continue;
2857 }
2858
Jeff Sharkey85f5f812013-10-07 10:16:12 -07002859 if (parser.getName().equals("intent-filter")) {
2860 ProviderIntentInfo intent = new ProviderIntentInfo(outInfo);
2861 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
2862 return false;
2863 }
2864 outInfo.intents.add(intent);
2865
2866 } else if (parser.getName().equals("meta-data")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2868 outInfo.metaData, outError)) == null) {
2869 return false;
2870 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 } else if (parser.getName().equals("grant-uri-permission")) {
2873 TypedArray sa = res.obtainAttributes(attrs,
2874 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2875
2876 PatternMatcher pa = null;
2877
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002878 String str = sa.getNonConfigurationString(
2879 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 if (str != null) {
2881 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2882 }
2883
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002884 str = sa.getNonConfigurationString(
2885 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 if (str != null) {
2887 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2888 }
2889
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002890 str = sa.getNonConfigurationString(
2891 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 if (str != null) {
2893 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2894 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 sa.recycle();
2897
2898 if (pa != null) {
2899 if (outInfo.info.uriPermissionPatterns == null) {
2900 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2901 outInfo.info.uriPermissionPatterns[0] = pa;
2902 } else {
2903 final int N = outInfo.info.uriPermissionPatterns.length;
2904 PatternMatcher[] newp = new PatternMatcher[N+1];
2905 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2906 newp[N] = pa;
2907 outInfo.info.uriPermissionPatterns = newp;
2908 }
2909 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002910 } else {
2911 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002912 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002913 + parser.getName() + " at " + mArchiveSourcePath + " "
2914 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002915 XmlUtils.skipCurrentTag(parser);
2916 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002917 } else {
2918 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2919 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002920 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002921 }
2922 XmlUtils.skipCurrentTag(parser);
2923
2924 } else if (parser.getName().equals("path-permission")) {
2925 TypedArray sa = res.obtainAttributes(attrs,
2926 com.android.internal.R.styleable.AndroidManifestPathPermission);
2927
2928 PathPermission pa = null;
2929
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002930 String permission = sa.getNonConfigurationString(
2931 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2932 String readPermission = sa.getNonConfigurationString(
2933 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002934 if (readPermission == null) {
2935 readPermission = permission;
2936 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002937 String writePermission = sa.getNonConfigurationString(
2938 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002939 if (writePermission == null) {
2940 writePermission = permission;
2941 }
2942
2943 boolean havePerm = false;
2944 if (readPermission != null) {
2945 readPermission = readPermission.intern();
2946 havePerm = true;
2947 }
2948 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002949 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002950 havePerm = true;
2951 }
2952
2953 if (!havePerm) {
2954 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002955 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002956 + parser.getName() + " at " + mArchiveSourcePath + " "
2957 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002958 XmlUtils.skipCurrentTag(parser);
2959 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002960 } else {
2961 outError[0] = "No readPermission or writePermssion for <path-permission>";
2962 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002963 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002964 }
2965
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002966 String path = sa.getNonConfigurationString(
2967 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002968 if (path != null) {
2969 pa = new PathPermission(path,
2970 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2971 }
2972
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002973 path = sa.getNonConfigurationString(
2974 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002975 if (path != null) {
2976 pa = new PathPermission(path,
2977 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2978 }
2979
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002980 path = sa.getNonConfigurationString(
2981 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002982 if (path != null) {
2983 pa = new PathPermission(path,
2984 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2985 }
2986
2987 sa.recycle();
2988
2989 if (pa != null) {
2990 if (outInfo.info.pathPermissions == null) {
2991 outInfo.info.pathPermissions = new PathPermission[1];
2992 outInfo.info.pathPermissions[0] = pa;
2993 } else {
2994 final int N = outInfo.info.pathPermissions.length;
2995 PathPermission[] newp = new PathPermission[N+1];
2996 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2997 newp[N] = pa;
2998 outInfo.info.pathPermissions = newp;
2999 }
3000 } else {
3001 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003002 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003003 + parser.getName() + " at " + mArchiveSourcePath + " "
3004 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07003005 XmlUtils.skipCurrentTag(parser);
3006 continue;
3007 }
3008 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
3009 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011 XmlUtils.skipCurrentTag(parser);
3012
3013 } else {
3014 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003015 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003016 + parser.getName() + " at " + mArchiveSourcePath + " "
3017 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 XmlUtils.skipCurrentTag(parser);
3019 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003020 } else {
3021 outError[0] = "Bad element under <provider>: " + parser.getName();
3022 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 }
3025 }
3026 return true;
3027 }
3028
3029 private Service parseService(Package owner, Resources res,
3030 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
3031 throws XmlPullParserException, IOException {
3032 TypedArray sa = res.obtainAttributes(attrs,
3033 com.android.internal.R.styleable.AndroidManifestService);
3034
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003035 if (mParseServiceArgs == null) {
3036 mParseServiceArgs = new ParseComponentArgs(owner, outError,
3037 com.android.internal.R.styleable.AndroidManifestService_name,
3038 com.android.internal.R.styleable.AndroidManifestService_label,
3039 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07003040 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003041 mSeparateProcesses,
3042 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003043 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003044 com.android.internal.R.styleable.AndroidManifestService_enabled);
3045 mParseServiceArgs.tag = "<service>";
3046 }
3047
3048 mParseServiceArgs.sa = sa;
3049 mParseServiceArgs.flags = flags;
3050
3051 Service s = new Service(mParseServiceArgs, new ServiceInfo());
3052 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 sa.recycle();
3054 return null;
3055 }
3056
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003057 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 com.android.internal.R.styleable.AndroidManifestService_exported);
3059 if (setExported) {
3060 s.info.exported = sa.getBoolean(
3061 com.android.internal.R.styleable.AndroidManifestService_exported, false);
3062 }
3063
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003064 String str = sa.getNonConfigurationString(
3065 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 if (str == null) {
3067 s.info.permission = owner.applicationInfo.permission;
3068 } else {
3069 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
3070 }
3071
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003072 s.info.flags = 0;
3073 if (sa.getBoolean(
3074 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
3075 false)) {
3076 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
3077 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08003078 if (sa.getBoolean(
3079 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
3080 false)) {
3081 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
3082 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003083 if (sa.getBoolean(
3084 com.android.internal.R.styleable.AndroidManifestService_singleUser,
3085 false)) {
3086 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
3087 if (s.info.exported) {
3088 Slog.w(TAG, "Service exported request ignored due to singleUser: "
3089 + s.className + " at " + mArchiveSourcePath + " "
3090 + parser.getPositionDescription());
3091 s.info.exported = false;
3092 }
3093 setExported = true;
3094 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096 sa.recycle();
3097
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003098 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003099 // A heavy-weight application can not have services in its main process
3100 // We can do direct compare because we intern all strings.
3101 if (s.info.processName == owner.packageName) {
3102 outError[0] = "Heavy-weight applications can not have services in main process";
3103 return null;
3104 }
3105 }
3106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 int outerDepth = parser.getDepth();
3108 int type;
3109 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3110 && (type != XmlPullParser.END_TAG
3111 || parser.getDepth() > outerDepth)) {
3112 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3113 continue;
3114 }
3115
3116 if (parser.getName().equals("intent-filter")) {
3117 ServiceIntentInfo intent = new ServiceIntentInfo(s);
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003118 if (!parseIntent(res, parser, attrs, true, intent, outError)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 return null;
3120 }
3121
3122 s.intents.add(intent);
3123 } else if (parser.getName().equals("meta-data")) {
3124 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3125 outError)) == null) {
3126 return null;
3127 }
3128 } else {
3129 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003130 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003131 + parser.getName() + " at " + mArchiveSourcePath + " "
3132 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 XmlUtils.skipCurrentTag(parser);
3134 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003135 } else {
3136 outError[0] = "Bad element under <service>: " + parser.getName();
3137 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 }
3140 }
3141
3142 if (!setExported) {
3143 s.info.exported = s.intents.size() > 0;
3144 }
3145
3146 return s;
3147 }
3148
3149 private boolean parseAllMetaData(Resources res,
3150 XmlPullParser parser, AttributeSet attrs, String tag,
3151 Component outInfo, String[] outError)
3152 throws XmlPullParserException, IOException {
3153 int outerDepth = parser.getDepth();
3154 int type;
3155 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3156 && (type != XmlPullParser.END_TAG
3157 || parser.getDepth() > outerDepth)) {
3158 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3159 continue;
3160 }
3161
3162 if (parser.getName().equals("meta-data")) {
3163 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3164 outInfo.metaData, outError)) == null) {
3165 return false;
3166 }
3167 } else {
3168 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003169 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003170 + parser.getName() + " at " + mArchiveSourcePath + " "
3171 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 XmlUtils.skipCurrentTag(parser);
3173 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003174 } else {
3175 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3176 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 }
3179 }
3180 return true;
3181 }
3182
3183 private Bundle parseMetaData(Resources res,
3184 XmlPullParser parser, AttributeSet attrs,
3185 Bundle data, String[] outError)
3186 throws XmlPullParserException, IOException {
3187
3188 TypedArray sa = res.obtainAttributes(attrs,
3189 com.android.internal.R.styleable.AndroidManifestMetaData);
3190
3191 if (data == null) {
3192 data = new Bundle();
3193 }
3194
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003195 String name = sa.getNonConfigurationString(
3196 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 if (name == null) {
3198 outError[0] = "<meta-data> requires an android:name attribute";
3199 sa.recycle();
3200 return null;
3201 }
3202
Dianne Hackborn854060a2009-07-09 18:14:31 -07003203 name = name.intern();
3204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 TypedValue v = sa.peekValue(
3206 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3207 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003208 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 data.putInt(name, v.resourceId);
3210 } else {
3211 v = sa.peekValue(
3212 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003213 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 if (v != null) {
3215 if (v.type == TypedValue.TYPE_STRING) {
3216 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003217 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3219 data.putBoolean(name, v.data != 0);
3220 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3221 && v.type <= TypedValue.TYPE_LAST_INT) {
3222 data.putInt(name, v.data);
3223 } else if (v.type == TypedValue.TYPE_FLOAT) {
3224 data.putFloat(name, v.getFloat());
3225 } else {
3226 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003227 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003228 + parser.getName() + " at " + mArchiveSourcePath + " "
3229 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 } else {
3231 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3232 data = null;
3233 }
3234 }
3235 } else {
3236 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3237 data = null;
3238 }
3239 }
3240
3241 sa.recycle();
3242
3243 XmlUtils.skipCurrentTag(parser);
3244
3245 return data;
3246 }
3247
Kenny Root05ca4c92011-09-15 10:36:25 -07003248 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3249 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3250 IOException {
3251 final TypedArray sa = res.obtainAttributes(attrs,
3252 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3253
3254 final String packageName = sa.getNonResourceString(
3255 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3256
3257 final String encodedPublicKey = sa.getNonResourceString(
3258 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3259
3260 sa.recycle();
3261
3262 if (packageName == null || packageName.length() == 0) {
3263 Slog.i(TAG, "verifier package name was null; skipping");
3264 return null;
3265 } else if (encodedPublicKey == null) {
3266 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3267 }
3268
Geremy Condraf1bcca82013-01-07 22:35:24 -08003269 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3270 if (publicKey != null) {
3271 return new VerifierInfo(packageName, publicKey);
3272 }
3273
3274 return null;
3275 }
3276
3277 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003278 EncodedKeySpec keySpec;
3279 try {
3280 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3281 keySpec = new X509EncodedKeySpec(encoded);
3282 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003283 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003284 return null;
3285 }
3286
3287 /* First try the key as an RSA key. */
3288 try {
3289 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003290 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003291 } catch (NoSuchAlgorithmException e) {
3292 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3293 return null;
3294 } catch (InvalidKeySpecException e) {
3295 // Not a RSA public key.
3296 }
3297
3298 /* Now try it as a DSA key. */
3299 try {
3300 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003301 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003302 } catch (NoSuchAlgorithmException e) {
3303 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3304 return null;
3305 } catch (InvalidKeySpecException e) {
3306 // Not a DSA public key.
3307 }
3308
3309 return null;
3310 }
3311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 private static final String ANDROID_RESOURCES
3313 = "http://schemas.android.com/apk/res/android";
3314
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003315 private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs,
3316 boolean allowGlobs, IntentInfo outInfo, String[] outError)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 throws XmlPullParserException, IOException {
3318
3319 TypedArray sa = res.obtainAttributes(attrs,
3320 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3321
3322 int priority = sa.getInt(
3323 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 TypedValue v = sa.peekValue(
3327 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3328 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3329 outInfo.nonLocalizedLabel = v.coerceToString();
3330 }
3331
3332 outInfo.icon = sa.getResourceId(
3333 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003334
3335 outInfo.logo = sa.getResourceId(
3336 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337
3338 sa.recycle();
3339
3340 int outerDepth = parser.getDepth();
3341 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003342 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3343 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3344 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 continue;
3346 }
3347
3348 String nodeName = parser.getName();
3349 if (nodeName.equals("action")) {
3350 String value = attrs.getAttributeValue(
3351 ANDROID_RESOURCES, "name");
3352 if (value == null || value == "") {
3353 outError[0] = "No value supplied for <android:name>";
3354 return false;
3355 }
3356 XmlUtils.skipCurrentTag(parser);
3357
3358 outInfo.addAction(value);
3359 } else if (nodeName.equals("category")) {
3360 String value = attrs.getAttributeValue(
3361 ANDROID_RESOURCES, "name");
3362 if (value == null || value == "") {
3363 outError[0] = "No value supplied for <android:name>";
3364 return false;
3365 }
3366 XmlUtils.skipCurrentTag(parser);
3367
3368 outInfo.addCategory(value);
3369
3370 } else if (nodeName.equals("data")) {
3371 sa = res.obtainAttributes(attrs,
3372 com.android.internal.R.styleable.AndroidManifestData);
3373
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003374 String str = sa.getNonConfigurationString(
3375 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 if (str != null) {
3377 try {
3378 outInfo.addDataType(str);
3379 } catch (IntentFilter.MalformedMimeTypeException e) {
3380 outError[0] = e.toString();
3381 sa.recycle();
3382 return false;
3383 }
3384 }
3385
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003386 str = sa.getNonConfigurationString(
3387 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 if (str != null) {
3389 outInfo.addDataScheme(str);
3390 }
3391
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003392 str = sa.getNonConfigurationString(
3393 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3394 if (str != null) {
3395 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3396 }
3397
3398 str = sa.getNonConfigurationString(
3399 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3400 if (str != null) {
3401 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3402 }
3403
3404 str = sa.getNonConfigurationString(
3405 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3406 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003407 if (!allowGlobs) {
3408 outError[0] = "sspPattern not allowed here; ssp must be literal";
3409 return false;
3410 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003411 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3412 }
3413
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003414 String host = sa.getNonConfigurationString(
3415 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3416 String port = sa.getNonConfigurationString(
3417 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 if (host != null) {
3419 outInfo.addDataAuthority(host, port);
3420 }
3421
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003422 str = sa.getNonConfigurationString(
3423 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 if (str != null) {
3425 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3426 }
3427
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003428 str = sa.getNonConfigurationString(
3429 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 if (str != null) {
3431 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3432 }
3433
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003434 str = sa.getNonConfigurationString(
3435 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 if (str != null) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003437 if (!allowGlobs) {
3438 outError[0] = "pathPattern not allowed here; path must be literal";
3439 return false;
3440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3442 }
3443
3444 sa.recycle();
3445 XmlUtils.skipCurrentTag(parser);
3446 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003447 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003448 + parser.getName() + " at " + mArchiveSourcePath + " "
3449 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 XmlUtils.skipCurrentTag(parser);
3451 } else {
3452 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3453 return false;
3454 }
3455 }
3456
3457 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003458
3459 if (DEBUG_PARSER) {
3460 final StringBuilder cats = new StringBuilder("Intent d=");
3461 cats.append(outInfo.hasDefault);
3462 cats.append(", cat=");
3463
3464 final Iterator<String> it = outInfo.categoriesIterator();
3465 if (it != null) {
3466 while (it.hasNext()) {
3467 cats.append(' ');
3468 cats.append(it.next());
3469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003471 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 }
3473
3474 return true;
3475 }
3476
3477 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003478
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003479 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480
3481 // For now we only support one application per package.
3482 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3483
3484 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3485 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3486 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3487 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3488 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3489 public final ArrayList<Service> services = new ArrayList<Service>(0);
3490 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3491
3492 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003493 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494
Dianne Hackborn854060a2009-07-09 18:14:31 -07003495 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003496
3497 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003498 public ArrayList<String> usesLibraries = null;
3499 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 public String[] usesLibraryFiles = null;
3501
Dianne Hackbornb09491f2013-07-22 15:30:11 -07003502 public ArrayList<ActivityIntentInfo> preferredActivityFilters = null;
3503
Dianne Hackbornc1552392010-03-03 16:19:01 -08003504 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003505 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003506 public ArrayList<String> mAdoptPermissions = null;
3507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 // We store the application meta-data independently to avoid multiple unwanted references
3509 public Bundle mAppMetaData = null;
3510
3511 // If this is a 3rd party app, this is the path of the zip file.
3512 public String mPath;
3513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 // The version code declared for this package.
3515 public int mVersionCode;
3516
3517 // The version name declared for this package.
3518 public String mVersionName;
3519
3520 // The shared user id that this package wants to use.
3521 public String mSharedUserId;
3522
3523 // The shared user label that this package wants to use.
3524 public int mSharedUserLabel;
3525
3526 // Signatures that were read from the package.
3527 public Signature mSignatures[];
3528
3529 // For use by package manager service for quick lookup of
3530 // preferred up order.
3531 public int mPreferredOrder = 0;
3532
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003533 // For use by the package manager to keep track of the path to the
3534 // file an app came from.
3535 public String mScanPath;
3536
3537 // For use by package manager to keep track of where it has done dexopt.
3538 public boolean mDidDexOpt;
3539
Amith Yamasani13593602012-03-22 16:16:17 -07003540 // // User set enabled state.
3541 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3542 //
3543 // // Whether the package has been stopped.
3544 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 // Additional data supplied by callers.
3547 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003548
3549 // Whether an operation is currently pending on this package
3550 public boolean mOperationPending;
3551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 /*
3553 * Applications hardware preferences
3554 */
3555 public final ArrayList<ConfigurationInfo> configPreferences =
3556 new ArrayList<ConfigurationInfo>();
3557
Dianne Hackborn49237342009-08-27 20:08:01 -07003558 /*
3559 * Applications requested features
3560 */
3561 public ArrayList<FeatureInfo> reqFeatures = null;
3562
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003563 public int installLocation;
3564
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003565 /* An app that's required for all users and cannot be uninstalled for a user */
3566 public boolean mRequiredForAllUsers;
3567
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003568 /* The restricted account authenticator type that is used by this application */
3569 public String mRestrictedAccountType;
3570
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003571 /* The required account type without which this application will not function */
3572 public String mRequiredAccountType;
3573
Kenny Rootbcc954d2011-08-08 16:19:08 -07003574 /**
3575 * Digest suitable for comparing whether this package's manifest is the
3576 * same as another.
3577 */
3578 public ManifestDigest manifestDigest;
3579
MÃ¥rten Kongstad48d22322014-01-31 14:43:27 +01003580 public String mOverlayTarget;
3581 public int mOverlayPriority;
3582 public boolean mTrustedOverlay;
3583
Geremy Condraf1bcca82013-01-07 22:35:24 -08003584 /**
3585 * Data used to feed the KeySetManager
3586 */
3587 public Set<PublicKey> mSigningKeys;
3588 public Map<String, Set<PublicKey>> mKeySetMapping;
3589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 public Package(String _name) {
3591 packageName = _name;
3592 applicationInfo.packageName = _name;
3593 applicationInfo.uid = -1;
3594 }
3595
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003596 public void setPackageName(String newName) {
3597 packageName = newName;
3598 applicationInfo.packageName = newName;
3599 for (int i=permissions.size()-1; i>=0; i--) {
3600 permissions.get(i).setPackageName(newName);
3601 }
3602 for (int i=permissionGroups.size()-1; i>=0; i--) {
3603 permissionGroups.get(i).setPackageName(newName);
3604 }
3605 for (int i=activities.size()-1; i>=0; i--) {
3606 activities.get(i).setPackageName(newName);
3607 }
3608 for (int i=receivers.size()-1; i>=0; i--) {
3609 receivers.get(i).setPackageName(newName);
3610 }
3611 for (int i=providers.size()-1; i>=0; i--) {
3612 providers.get(i).setPackageName(newName);
3613 }
3614 for (int i=services.size()-1; i>=0; i--) {
3615 services.get(i).setPackageName(newName);
3616 }
3617 for (int i=instrumentation.size()-1; i>=0; i--) {
3618 instrumentation.get(i).setPackageName(newName);
3619 }
3620 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003621
3622 public boolean hasComponentClassName(String name) {
3623 for (int i=activities.size()-1; i>=0; i--) {
3624 if (name.equals(activities.get(i).className)) {
3625 return true;
3626 }
3627 }
3628 for (int i=receivers.size()-1; i>=0; i--) {
3629 if (name.equals(receivers.get(i).className)) {
3630 return true;
3631 }
3632 }
3633 for (int i=providers.size()-1; i>=0; i--) {
3634 if (name.equals(providers.get(i).className)) {
3635 return true;
3636 }
3637 }
3638 for (int i=services.size()-1; i>=0; i--) {
3639 if (name.equals(services.get(i).className)) {
3640 return true;
3641 }
3642 }
3643 for (int i=instrumentation.size()-1; i>=0; i--) {
3644 if (name.equals(instrumentation.get(i).className)) {
3645 return true;
3646 }
3647 }
3648 return false;
3649 }
3650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 public String toString() {
3652 return "Package{"
3653 + Integer.toHexString(System.identityHashCode(this))
3654 + " " + packageName + "}";
3655 }
3656 }
3657
3658 public static class Component<II extends IntentInfo> {
3659 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003660 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003661 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 public Bundle metaData;
3663
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003664 ComponentName componentName;
3665 String componentShortName;
3666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 public Component(Package _owner) {
3668 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003669 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003670 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003671 }
3672
3673 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3674 owner = args.owner;
3675 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003676 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003677 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003678 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003679 args.outError[0] = args.tag + " does not specify android:name";
3680 return;
3681 }
3682
3683 outInfo.name
3684 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3685 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003686 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003687 args.outError[0] = args.tag + " does not have valid android:name";
3688 return;
3689 }
3690
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003691 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003692
3693 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3694 if (iconVal != 0) {
3695 outInfo.icon = iconVal;
3696 outInfo.nonLocalizedLabel = null;
3697 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003698
3699 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3700 if (logoVal != 0) {
3701 outInfo.logo = logoVal;
3702 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003703
3704 TypedValue v = args.sa.peekValue(args.labelRes);
3705 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3706 outInfo.nonLocalizedLabel = v.coerceToString();
3707 }
3708
3709 outInfo.packageName = owner.packageName;
3710 }
3711
3712 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3713 this(args, (PackageItemInfo)outInfo);
3714 if (args.outError[0] != null) {
3715 return;
3716 }
3717
3718 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003719 CharSequence pname;
3720 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
Dianne Hackborn1d0b1772013-09-06 14:02:54 -07003721 pname = args.sa.getNonConfigurationString(args.processRes,
3722 Configuration.NATIVE_CONFIG_VERSION);
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003723 } else {
3724 // Some older apps have been seen to use a resource reference
3725 // here that on older builds was ignored (with a warning). We
3726 // need to continue to do this for them so they don't break.
3727 pname = args.sa.getNonResourceString(args.processRes);
3728 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003729 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003730 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003731 args.flags, args.sepProcesses, args.outError);
3732 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003733
3734 if (args.descriptionRes != 0) {
3735 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3736 }
3737
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003738 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 }
3740
3741 public Component(Component<II> clone) {
3742 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003743 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003744 className = clone.className;
3745 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003746 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003747 }
3748
3749 public ComponentName getComponentName() {
3750 if (componentName != null) {
3751 return componentName;
3752 }
3753 if (className != null) {
3754 componentName = new ComponentName(owner.applicationInfo.packageName,
3755 className);
3756 }
3757 return componentName;
3758 }
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003759
3760 public void appendComponentShortName(StringBuilder sb) {
3761 ComponentName.appendShortString(sb, owner.applicationInfo.packageName, className);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003762 }
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003763
3764 public void printComponentShortName(PrintWriter pw) {
3765 ComponentName.printShortString(pw, owner.applicationInfo.packageName, className);
3766 }
3767
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003768 public void setPackageName(String packageName) {
3769 componentName = null;
3770 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 }
3772 }
3773
3774 public final static class Permission extends Component<IntentInfo> {
3775 public final PermissionInfo info;
3776 public boolean tree;
3777 public PermissionGroup group;
3778
3779 public Permission(Package _owner) {
3780 super(_owner);
3781 info = new PermissionInfo();
3782 }
3783
3784 public Permission(Package _owner, PermissionInfo _info) {
3785 super(_owner);
3786 info = _info;
3787 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003788
3789 public void setPackageName(String packageName) {
3790 super.setPackageName(packageName);
3791 info.packageName = packageName;
3792 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793
3794 public String toString() {
3795 return "Permission{"
3796 + Integer.toHexString(System.identityHashCode(this))
3797 + " " + info.name + "}";
3798 }
3799 }
3800
3801 public final static class PermissionGroup extends Component<IntentInfo> {
3802 public final PermissionGroupInfo info;
3803
3804 public PermissionGroup(Package _owner) {
3805 super(_owner);
3806 info = new PermissionGroupInfo();
3807 }
3808
3809 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3810 super(_owner);
3811 info = _info;
3812 }
3813
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003814 public void setPackageName(String packageName) {
3815 super.setPackageName(packageName);
3816 info.packageName = packageName;
3817 }
3818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 public String toString() {
3820 return "PermissionGroup{"
3821 + Integer.toHexString(System.identityHashCode(this))
3822 + " " + info.name + "}";
3823 }
3824 }
3825
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003826 private static boolean copyNeeded(int flags, Package p,
3827 PackageUserState state, Bundle metaData, int userId) {
3828 if (userId != 0) {
3829 // We always need to copy for other users, since we need
3830 // to fix up the uid.
3831 return true;
3832 }
3833 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3834 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003835 if (p.applicationInfo.enabled != enabled) {
3836 return true;
3837 }
3838 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003839 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003840 return true;
3841 }
3842 if (state.stopped) {
3843 return true;
3844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 if ((flags & PackageManager.GET_META_DATA) != 0
3846 && (metaData != null || p.mAppMetaData != null)) {
3847 return true;
3848 }
3849 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3850 && p.usesLibraryFiles != null) {
3851 return true;
3852 }
3853 return false;
3854 }
3855
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003856 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3857 PackageUserState state) {
3858 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003859 }
3860
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003861 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3862 PackageUserState state) {
3863 // CompatibilityMode is global state.
3864 if (!sCompatibilityModeEnabled) {
3865 ai.disableCompatibilityMode();
3866 }
3867 if (state.installed) {
3868 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3869 } else {
3870 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3871 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003872 if (state.blocked) {
3873 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3874 } else {
3875 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3876 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003877 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3878 ai.enabled = true;
3879 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3880 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3881 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3882 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3883 ai.enabled = false;
3884 }
3885 ai.enabledSetting = state.enabled;
3886 }
3887
Amith Yamasani13593602012-03-22 16:16:17 -07003888 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003889 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003891 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003892 return null;
3893 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003894 if (!copyNeeded(flags, p, state, null, userId)
3895 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3896 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3897 // In this case it is safe to directly modify the internal ApplicationInfo state:
3898 // - CompatibilityMode is global state, so will be the same for every call.
3899 // - We only come in to here if the app should reported as installed; this is the
3900 // default state, and we will do a copy otherwise.
3901 // - The enable state will always be reported the same for the application across
3902 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3903 // be doing a copy.
3904 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 return p.applicationInfo;
3906 }
3907
3908 // Make shallow copy so we can store the metadata/libraries safely
3909 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003910 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003911 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003912 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 if ((flags & PackageManager.GET_META_DATA) != 0) {
3915 ai.metaData = p.mAppMetaData;
3916 }
3917 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3918 ai.sharedLibraryFiles = p.usesLibraryFiles;
3919 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003920 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003921 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003922 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003923 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003924 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003925 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926 return ai;
3927 }
3928
3929 public static final PermissionInfo generatePermissionInfo(
3930 Permission p, int flags) {
3931 if (p == null) return null;
3932 if ((flags&PackageManager.GET_META_DATA) == 0) {
3933 return p.info;
3934 }
3935 PermissionInfo pi = new PermissionInfo(p.info);
3936 pi.metaData = p.metaData;
3937 return pi;
3938 }
3939
3940 public static final PermissionGroupInfo generatePermissionGroupInfo(
3941 PermissionGroup pg, int flags) {
3942 if (pg == null) return null;
3943 if ((flags&PackageManager.GET_META_DATA) == 0) {
3944 return pg.info;
3945 }
3946 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3947 pgi.metaData = pg.metaData;
3948 return pgi;
3949 }
3950
3951 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003952 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003953
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003954 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3955 super(args, _info);
3956 info = _info;
3957 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003959
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003960 public void setPackageName(String packageName) {
3961 super.setPackageName(packageName);
3962 info.packageName = packageName;
3963 }
3964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07003966 StringBuilder sb = new StringBuilder(128);
3967 sb.append("Activity{");
3968 sb.append(Integer.toHexString(System.identityHashCode(this)));
3969 sb.append(' ');
3970 appendComponentShortName(sb);
3971 sb.append('}');
3972 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 }
3974 }
3975
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003976 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3977 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003979 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003980 return null;
3981 }
3982 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 return a.info;
3984 }
3985 // Make shallow copies so we can store the metadata safely
3986 ActivityInfo ai = new ActivityInfo(a.info);
3987 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003988 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 return ai;
3990 }
3991
3992 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003993 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003994
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003995 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3996 super(args, _info);
3997 info = _info;
3998 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004000
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004001 public void setPackageName(String packageName) {
4002 super.setPackageName(packageName);
4003 info.packageName = packageName;
4004 }
4005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004007 StringBuilder sb = new StringBuilder(128);
4008 sb.append("Service{");
4009 sb.append(Integer.toHexString(System.identityHashCode(this)));
4010 sb.append(' ');
4011 appendComponentShortName(sb);
4012 sb.append('}');
4013 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 }
4015 }
4016
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004017 public static final ServiceInfo generateServiceInfo(Service s, int flags,
4018 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07004020 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004021 return null;
4022 }
4023 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 return s.info;
4025 }
4026 // Make shallow copies so we can store the metadata safely
4027 ServiceInfo si = new ServiceInfo(s.info);
4028 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004029 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 return si;
4031 }
4032
Jeff Sharkey85f5f812013-10-07 10:16:12 -07004033 public final static class Provider extends Component<ProviderIntentInfo> {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 public final ProviderInfo info;
4035 public boolean syncable;
4036
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004037 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
4038 super(args, _info);
4039 info = _info;
4040 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004041 syncable = false;
4042 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004044 public Provider(Provider existingProvider) {
4045 super(existingProvider);
4046 this.info = existingProvider.info;
4047 this.syncable = existingProvider.syncable;
4048 }
4049
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004050 public void setPackageName(String packageName) {
4051 super.setPackageName(packageName);
4052 info.packageName = packageName;
4053 }
4054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004056 StringBuilder sb = new StringBuilder(128);
4057 sb.append("Provider{");
4058 sb.append(Integer.toHexString(System.identityHashCode(this)));
4059 sb.append(' ');
4060 appendComponentShortName(sb);
4061 sb.append('}');
4062 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004063 }
4064 }
4065
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004066 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
4067 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07004069 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004070 return null;
4071 }
4072 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004073 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004074 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 return p.info;
4076 }
4077 // Make shallow copies so we can store the metadata safely
4078 ProviderInfo pi = new ProviderInfo(p.info);
4079 pi.metaData = p.metaData;
4080 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
4081 pi.uriPermissionPatterns = null;
4082 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07004083 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 return pi;
4085 }
4086
4087 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004088 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004089
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004090 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
4091 super(args, _info);
4092 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004094
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004095 public void setPackageName(String packageName) {
4096 super.setPackageName(packageName);
4097 info.packageName = packageName;
4098 }
4099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004101 StringBuilder sb = new StringBuilder(128);
4102 sb.append("Instrumentation{");
4103 sb.append(Integer.toHexString(System.identityHashCode(this)));
4104 sb.append(' ');
4105 appendComponentShortName(sb);
4106 sb.append('}');
4107 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 }
4109 }
4110
4111 public static final InstrumentationInfo generateInstrumentationInfo(
4112 Instrumentation i, int flags) {
4113 if (i == null) return null;
4114 if ((flags&PackageManager.GET_META_DATA) == 0) {
4115 return i.info;
4116 }
4117 InstrumentationInfo ii = new InstrumentationInfo(i.info);
4118 ii.metaData = i.metaData;
4119 return ii;
4120 }
4121
4122 public static class IntentInfo extends IntentFilter {
4123 public boolean hasDefault;
4124 public int labelRes;
4125 public CharSequence nonLocalizedLabel;
4126 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004127 public int logo;
Dianne Hackbornb09491f2013-07-22 15:30:11 -07004128 public int preferred;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 }
4130
4131 public final static class ActivityIntentInfo extends IntentInfo {
4132 public final Activity activity;
4133
4134 public ActivityIntentInfo(Activity _activity) {
4135 activity = _activity;
4136 }
4137
4138 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004139 StringBuilder sb = new StringBuilder(128);
4140 sb.append("ActivityIntentInfo{");
4141 sb.append(Integer.toHexString(System.identityHashCode(this)));
4142 sb.append(' ');
4143 activity.appendComponentShortName(sb);
4144 sb.append('}');
4145 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 }
4147 }
4148
4149 public final static class ServiceIntentInfo extends IntentInfo {
4150 public final Service service;
4151
4152 public ServiceIntentInfo(Service _service) {
4153 service = _service;
4154 }
4155
4156 public String toString() {
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -07004157 StringBuilder sb = new StringBuilder(128);
4158 sb.append("ServiceIntentInfo{");
4159 sb.append(Integer.toHexString(System.identityHashCode(this)));
4160 sb.append(' ');
4161 service.appendComponentShortName(sb);
4162 sb.append('}');
4163 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 }
4165 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004166
Jeff Sharkey85f5f812013-10-07 10:16:12 -07004167 public static final class ProviderIntentInfo extends IntentInfo {
4168 public final Provider provider;
4169
4170 public ProviderIntentInfo(Provider provider) {
4171 this.provider = provider;
4172 }
4173
4174 public String toString() {
4175 StringBuilder sb = new StringBuilder(128);
4176 sb.append("ProviderIntentInfo{");
4177 sb.append(Integer.toHexString(System.identityHashCode(this)));
4178 sb.append(' ');
4179 provider.appendComponentShortName(sb);
4180 sb.append('}');
4181 return sb.toString();
4182 }
4183 }
4184
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004185 /**
4186 * @hide
4187 */
4188 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4189 sCompatibilityModeEnabled = compatibilityModeEnabled;
4190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191}