blob: ce7addcc212a5b00141441b11a5e7e96cee9758f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.ComponentName;
20import android.content.Intent;
21import android.content.IntentFilter;
22import android.content.res.AssetManager;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.content.res.XmlResourceParser;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Bundle;
29import android.os.PatternMatcher;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070030import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070032import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070034import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070035import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Kenny Rootd63f7db2010-09-27 08:07:48 -070038import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.File;
40import java.io.IOException;
41import java.io.InputStream;
42import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070043import java.security.KeyFactory;
44import java.security.NoSuchAlgorithmException;
45import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import java.security.cert.Certificate;
47import java.security.cert.CertificateEncodingException;
Geremy Condraf1bcca82013-01-07 22:35:24 -080048import java.security.cert.CertificateFactory;
49import java.security.cert.CertPath;
50import java.security.cert.X509Certificate;
Kenny Root05ca4c92011-09-15 10:36:25 -070051import java.security.spec.EncodedKeySpec;
52import java.security.spec.InvalidKeySpecException;
53import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.util.ArrayList;
55import java.util.Enumeration;
Geremy Condraf1bcca82013-01-07 22:35:24 -080056import java.util.HashMap;
Dianne Hackborne639da72012-02-21 15:11:13 -080057import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070059import java.util.List;
Geremy Condraf1bcca82013-01-07 22:35:24 -080060import java.util.Map;
61import java.util.Set;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import java.util.jar.JarEntry;
63import java.util.jar.JarFile;
Kenny Root6c918ce2013-04-02 14:04:24 -070064import java.util.zip.ZipEntry;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
Amith Yamasani742a6712011-05-04 14:49:28 -070066import com.android.internal.util.XmlUtils;
67
68import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
72 * Package archive parsing
73 *
74 * {@hide}
75 */
76public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070077 private static final boolean DEBUG_JAR = false;
78 private static final boolean DEBUG_PARSER = false;
79 private static final boolean DEBUG_BACKUP = false;
80
Kenny Rootbcc954d2011-08-08 16:19:08 -070081 /** File name in an APK for the Android manifest. */
82 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
83
Dianne Hackborna96cbb42009-05-13 15:06:13 -070084 /** @hide */
85 public static class NewPermissionInfo {
86 public final String name;
87 public final int sdkVersion;
88 public final int fileVersion;
89
90 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
91 this.name = name;
92 this.sdkVersion = sdkVersion;
93 this.fileVersion = fileVersion;
94 }
95 }
Dianne Hackborn79245122012-03-12 10:51:26 -070096
97 /** @hide */
98 public static class SplitPermissionInfo {
99 public final String rootPerm;
100 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700101 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700102
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700103 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700104 this.rootPerm = rootPerm;
105 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700106 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700107 }
108 }
109
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700110 /**
111 * List of new permissions that have been added since 1.0.
112 * NOTE: These must be declared in SDK version order, with permissions
113 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700114 * If sdkVersion is 0, then this is not a permission that we want to
115 * automatically add to older apps, but we do want to allow it to be
116 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700117 * @hide
118 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700119 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
120 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700121 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700122 android.os.Build.VERSION_CODES.DONUT, 0),
123 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
124 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700125 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126
Dianne Hackborn79245122012-03-12 10:51:26 -0700127 /**
128 * List of permissions that have been split into more granular or dependent
129 * permissions.
130 * @hide
131 */
132 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
133 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700134 // READ_EXTERNAL_STORAGE is always required when an app requests
135 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
136 // write access without read access. The hack here with the target
137 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700138 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700139 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700140 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700141 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
142 new String[] { android.Manifest.permission.READ_CALL_LOG },
143 android.os.Build.VERSION_CODES.JELLY_BEAN),
144 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
145 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
146 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700147 };
148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 private String mArchiveSourcePath;
150 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700151 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700152 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
153 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
154 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155
156 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
157
158 private static final Object mSync = new Object();
159 private static WeakReference<byte[]> mReadBuffer;
160
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700161 private static boolean sCompatibilityModeEnabled = true;
Amith Yamasani655d0e22013-06-12 14:19:10 -0700162 private static final int PARSE_DEFAULT_INSTALL_LOCATION =
163 PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700164
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700165 static class ParsePackageItemArgs {
166 final Package owner;
167 final String[] outError;
168 final int nameRes;
169 final int labelRes;
170 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700171 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700172
173 String tag;
174 TypedArray sa;
175
176 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700177 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700178 owner = _owner;
179 outError = _outError;
180 nameRes = _nameRes;
181 labelRes = _labelRes;
182 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700183 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 }
185 }
186
187 static class ParseComponentArgs extends ParsePackageItemArgs {
188 final String[] sepProcesses;
189 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800190 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700191 final int enabledRes;
192 int flags;
193
194 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700195 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800196 String[] _sepProcesses, int _processRes,
197 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700198 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700199 sepProcesses = _sepProcesses;
200 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800201 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700202 enabledRes = _enabledRes;
203 }
204 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800205
206 /* Light weight package info.
207 * @hide
208 */
209 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700210 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700211 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700212 public final int installLocation;
213 public final VerifierInfo[] verifiers;
214
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700215 public PackageLite(String packageName, int versionCode,
216 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800217 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700218 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800219 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700220 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800221 }
222 }
223
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700224 private ParsePackageItemArgs mParseInstrumentationArgs;
225 private ParseComponentArgs mParseActivityArgs;
226 private ParseComponentArgs mParseActivityAliasArgs;
227 private ParseComponentArgs mParseServiceArgs;
228 private ParseComponentArgs mParseProviderArgs;
229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 /** If set to true, we will only allow package files that exactly match
231 * the DTD. Otherwise, we try to get as much from the package as we
232 * can without failing. This should normally be set to false, to
233 * support extensions to the DTD in future versions. */
234 private static final boolean RIGID_PARSER = false;
235
236 private static final String TAG = "PackageParser";
237
238 public PackageParser(String archiveSourcePath) {
239 mArchiveSourcePath = archiveSourcePath;
240 }
241
242 public void setSeparateProcesses(String[] procs) {
243 mSeparateProcesses = procs;
244 }
245
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700246 public void setOnlyCoreApps(boolean onlyCoreApps) {
247 mOnlyCoreApps = onlyCoreApps;
248 }
249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 private static final boolean isPackageFilename(String name) {
251 return name.endsWith(".apk");
252 }
253
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700254 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700255 public static PackageInfo generatePackageInfo(PackageParser.Package p,
256 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
257 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700258 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700259 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700260 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700261 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700262 */
Amith Yamasani13593602012-03-22 16:16:17 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 /**
265 * Generate and return the {@link PackageInfo} for a parsed package.
266 *
267 * @param p the parsed package.
268 * @param flags indicating which optional information is included.
269 */
270 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800271 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700272 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
Amith Yamasani483f3b02012-03-13 16:08:00 -0700274 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700275 grantedPermissions, state, UserHandle.getCallingUserId());
276 }
277
Amith Yamasani655d0e22013-06-12 14:19:10 -0700278 /**
279 * Returns true if the package is installed and not blocked, or if the caller
280 * explicitly wanted all uninstalled and blocked packages as well.
281 */
282 private static boolean checkUseInstalledOrBlocked(int flags, PackageUserState state) {
283 return (state.installed && !state.blocked)
284 || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
Amith Yamasani483f3b02012-03-13 16:08:00 -0700285 }
286
Amith Yamasani13593602012-03-22 16:16:17 -0700287 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700288 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700289 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700290
Amith Yamasani655d0e22013-06-12 14:19:10 -0700291 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700292 return null;
293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 PackageInfo pi = new PackageInfo();
295 pi.packageName = p.packageName;
296 pi.versionCode = p.mVersionCode;
297 pi.versionName = p.mVersionName;
298 pi.sharedUserId = p.mSharedUserId;
299 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700300 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800301 pi.installLocation = p.installLocation;
Amith Yamasani0d8750d2013-05-01 15:25:28 -0700302 if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0
303 || (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
304 pi.requiredForAllUsers = p.mRequiredForAllUsers;
305 }
Amith Yamasani0ac1fc92013-03-27 18:56:08 -0700306 pi.restrictedAccountType = p.mRestrictedAccountType;
Amith Yamasaniccbe3892013-04-12 17:52:42 -0700307 pi.requiredAccountType = p.mRequiredAccountType;
Dianne Hackborn78d6883692010-10-07 01:12:46 -0700308 pi.firstInstallTime = firstInstallTime;
309 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 if ((flags&PackageManager.GET_GIDS) != 0) {
311 pi.gids = gids;
312 }
313 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
314 int N = p.configPreferences.size();
315 if (N > 0) {
316 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700317 p.configPreferences.toArray(pi.configPreferences);
318 }
319 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
320 if (N > 0) {
321 pi.reqFeatures = new FeatureInfo[N];
322 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 }
324 }
325 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
326 int N = p.activities.size();
327 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700328 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
329 pi.activities = new ActivityInfo[N];
330 } else {
331 int num = 0;
332 for (int i=0; i<N; i++) {
333 if (p.activities.get(i).info.enabled) num++;
334 }
335 pi.activities = new ActivityInfo[num];
336 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700337 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 final Activity activity = p.activities.get(i);
339 if (activity.info.enabled
340 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700341 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700342 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344 }
345 }
346 }
347 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
348 int N = p.receivers.size();
349 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700350 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
351 pi.receivers = new ActivityInfo[N];
352 } else {
353 int num = 0;
354 for (int i=0; i<N; i++) {
355 if (p.receivers.get(i).info.enabled) num++;
356 }
357 pi.receivers = new ActivityInfo[num];
358 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700359 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 final Activity activity = p.receivers.get(i);
361 if (activity.info.enabled
362 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700363 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700364 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 }
366 }
367 }
368 }
369 if ((flags&PackageManager.GET_SERVICES) != 0) {
370 int N = p.services.size();
371 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700372 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
373 pi.services = new ServiceInfo[N];
374 } else {
375 int num = 0;
376 for (int i=0; i<N; i++) {
377 if (p.services.get(i).info.enabled) num++;
378 }
379 pi.services = new ServiceInfo[num];
380 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700381 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 final Service service = p.services.get(i);
383 if (service.info.enabled
384 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700385 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
386 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 }
388 }
389 }
390 }
391 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
392 int N = p.providers.size();
393 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700394 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
395 pi.providers = new ProviderInfo[N];
396 } else {
397 int num = 0;
398 for (int i=0; i<N; i++) {
399 if (p.providers.get(i).info.enabled) num++;
400 }
401 pi.providers = new ProviderInfo[num];
402 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700403 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 final Provider provider = p.providers.get(i);
405 if (provider.info.enabled
406 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700407 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
408 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 }
410 }
411 }
412 }
413 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
414 int N = p.instrumentation.size();
415 if (N > 0) {
416 pi.instrumentation = new InstrumentationInfo[N];
417 for (int i=0; i<N; i++) {
418 pi.instrumentation[i] = generateInstrumentationInfo(
419 p.instrumentation.get(i), flags);
420 }
421 }
422 }
423 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
424 int N = p.permissions.size();
425 if (N > 0) {
426 pi.permissions = new PermissionInfo[N];
427 for (int i=0; i<N; i++) {
428 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
429 }
430 }
431 N = p.requestedPermissions.size();
432 if (N > 0) {
433 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800434 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800436 final String perm = p.requestedPermissions.get(i);
437 pi.requestedPermissions[i] = perm;
438 if (p.requestedPermissionsRequired.get(i)) {
439 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
440 }
441 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
442 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445 }
446 }
447 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700448 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
449 if (N > 0) {
450 pi.signatures = new Signature[N];
451 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 }
453 }
454 return pi;
455 }
456
457 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
458 byte[] readBuffer) {
459 try {
460 // We must read the stream for the JarEntry to retrieve
461 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700462 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
464 // not using
465 }
466 is.close();
467 return je != null ? je.getCertificates() : null;
468 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700469 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700471 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700472 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700473 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 }
475 return null;
476 }
477
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800478 public final static int PARSE_IS_SYSTEM = 1<<0;
479 public final static int PARSE_CHATTY = 1<<1;
480 public final static int PARSE_MUST_BE_APK = 1<<2;
481 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
482 public final static int PARSE_FORWARD_LOCK = 1<<4;
483 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700484 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
Christopher Tateccbf84f2013-05-08 15:25:41 -0700485 public final static int PARSE_IS_PRIVILEGED = 1<<7;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486
487 public int getParseError() {
488 return mParseError;
489 }
490
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800491 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 DisplayMetrics metrics, int flags) {
493 mParseError = PackageManager.INSTALL_SUCCEEDED;
494
495 mArchiveSourcePath = sourceFile.getPath();
496 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700497 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
499 return null;
500 }
501 if (!isPackageFilename(sourceFile.getName())
502 && (flags&PARSE_MUST_BE_APK) != 0) {
503 if ((flags&PARSE_IS_SYSTEM) == 0) {
504 // We expect to have non-.apk files in the system dir,
505 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700506 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
509 return null;
510 }
511
Kenny Rootd2d29252011-08-08 11:27:57 -0700512 if (DEBUG_JAR)
513 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514
515 XmlResourceParser parser = null;
516 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800517 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 boolean assetError = true;
519 try {
520 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700521 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800522 if (cookie != 0) {
523 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700524 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 -0800525 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700526 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 assetError = false;
528 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700529 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 }
531 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700532 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 + mArchiveSourcePath, e);
534 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800535 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 if (assmgr != null) assmgr.close();
537 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
538 return null;
539 }
540 String[] errorText = new String[1];
541 Package pkg = null;
542 Exception errorException = null;
543 try {
544 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 pkg = parsePackage(res, parser, flags, errorText);
546 } catch (Exception e) {
547 errorException = e;
548 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
549 }
550
551
552 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700553 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
554 // just means to skip this app so don't make a fuss about it.
555 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
556 if (errorException != null) {
557 Slog.w(TAG, mArchiveSourcePath, errorException);
558 } else {
559 Slog.w(TAG, mArchiveSourcePath + " (at "
560 + parser.getPositionDescription()
561 + "): " + errorText[0]);
562 }
563 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
564 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 }
567 parser.close();
568 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 return null;
570 }
571
572 parser.close();
573 assmgr.close();
574
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800575 // Set code and resource paths
576 pkg.mPath = destCodePath;
577 pkg.mScanPath = mArchiveSourcePath;
578 //pkg.applicationInfo.sourceDir = destCodePath;
579 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 pkg.mSignatures = null;
581
582 return pkg;
583 }
584
Kenny Root6c918ce2013-04-02 14:04:24 -0700585 /**
586 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
587 * APK. If it successfully scanned the package and found the
588 * {@code AndroidManifest.xml}, {@code true} is returned.
589 */
590 public boolean collectManifestDigest(Package pkg) {
591 try {
592 final JarFile jarFile = new JarFile(mArchiveSourcePath);
593 try {
594 final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
595 if (je != null) {
596 pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
597 }
598 } finally {
599 jarFile.close();
600 }
601 return true;
602 } catch (IOException e) {
603 return false;
604 }
605 }
606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 public boolean collectCertificates(Package pkg, int flags) {
608 pkg.mSignatures = null;
609
610 WeakReference<byte[]> readBufferRef;
611 byte[] readBuffer = null;
612 synchronized (mSync) {
613 readBufferRef = mReadBuffer;
614 if (readBufferRef != null) {
615 mReadBuffer = null;
616 readBuffer = readBufferRef.get();
617 }
618 if (readBuffer == null) {
619 readBuffer = new byte[8192];
620 readBufferRef = new WeakReference<byte[]>(readBuffer);
621 }
622 }
623
624 try {
625 JarFile jarFile = new JarFile(mArchiveSourcePath);
626
627 Certificate[] certs = null;
628
629 if ((flags&PARSE_IS_SYSTEM) != 0) {
630 // If this package comes from the system image, then we
631 // can trust it... we'll just use the AndroidManifest.xml
632 // to retrieve its signatures, not validating all of the
633 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700634 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 certs = loadCertificates(jarFile, jarEntry, readBuffer);
636 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700637 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 + " has no certificates at entry "
639 + jarEntry.getName() + "; ignoring!");
640 jarFile.close();
641 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
642 return false;
643 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700644 if (DEBUG_JAR) {
645 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 + " certs=" + (certs != null ? certs.length : 0));
647 if (certs != null) {
648 final int N = certs.length;
649 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700650 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 + certs[i].getPublicKey().getEncoded()
652 + " " + certs[i].getPublicKey());
653 }
654 }
655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700657 Enumeration<JarEntry> entries = jarFile.entries();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700659 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700661
Kenny Rootbcc954d2011-08-08 16:19:08 -0700662 final String name = je.getName();
663
664 if (name.startsWith("META-INF/"))
665 continue;
666
667 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
Kenny Root6c918ce2013-04-02 14:04:24 -0700668 pkg.manifestDigest =
669 ManifestDigest.fromInputStream(jarFile.getInputStream(je));
Kenny Rootbcc954d2011-08-08 16:19:08 -0700670 }
671
672 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700673 if (DEBUG_JAR) {
674 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 + ": certs=" + certs + " ("
676 + (certs != null ? certs.length : 0) + ")");
677 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700680 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 + " has no certificates at entry "
682 + je.getName() + "; ignoring!");
683 jarFile.close();
684 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
685 return false;
686 } else if (certs == null) {
687 certs = localCerts;
688 } else {
689 // Ensure all certificates match.
690 for (int i=0; i<certs.length; i++) {
691 boolean found = false;
692 for (int j=0; j<localCerts.length; j++) {
693 if (certs[i] != null &&
694 certs[i].equals(localCerts[j])) {
695 found = true;
696 break;
697 }
698 }
699 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700700 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 + " has mismatched certificates at entry "
702 + je.getName() + "; ignoring!");
703 jarFile.close();
704 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
705 return false;
706 }
707 }
708 }
709 }
710 }
711 jarFile.close();
712
713 synchronized (mSync) {
714 mReadBuffer = readBufferRef;
715 }
716
717 if (certs != null && certs.length > 0) {
718 final int N = certs.length;
719 pkg.mSignatures = new Signature[certs.length];
720 for (int i=0; i<N; i++) {
721 pkg.mSignatures[i] = new Signature(
722 certs[i].getEncoded());
723 }
724 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700725 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 + " has no certificates; ignoring!");
727 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
728 return false;
729 }
Geremy Condraf1bcca82013-01-07 22:35:24 -0800730
731 // Add the signing KeySet to the system
732 pkg.mSigningKeys = new HashSet<PublicKey>();
733 for (int i=0; i < certs.length; i++) {
734 pkg.mSigningKeys.add(certs[i].getPublicKey());
735 }
736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700738 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
740 return false;
741 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700742 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
744 return false;
745 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700746 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
748 return false;
749 }
750
751 return true;
752 }
753
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800754 /*
755 * Utility method that retrieves just the package name and install
756 * location from the apk location at the given file path.
757 * @param packageFilePath file location of the apk
758 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700759 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800760 */
761 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700763 final XmlResourceParser parser;
764 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 try {
766 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700767 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 -0800768 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700771 if (cookie == 0) {
772 return null;
773 }
774
Kenny Root05ca4c92011-09-15 10:36:25 -0700775 final DisplayMetrics metrics = new DisplayMetrics();
776 metrics.setToDefaults();
777 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700778 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 } catch (Exception e) {
780 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700781 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 + packageFilePath, e);
783 return null;
784 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700785
786 final AttributeSet attrs = parser;
787 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800788 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700790 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700792 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700794 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 } finally {
796 if (parser != null) parser.close();
797 if (assmgr != null) assmgr.close();
798 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800799 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700800 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 return null;
802 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800803 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
805
806 private static String validateName(String name, boolean requiresSeparator) {
807 final int N = name.length();
808 boolean hasSep = false;
809 boolean front = true;
810 for (int i=0; i<N; i++) {
811 final char c = name.charAt(i);
812 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
813 front = false;
814 continue;
815 }
816 if (!front) {
817 if ((c >= '0' && c <= '9') || c == '_') {
818 continue;
819 }
820 }
821 if (c == '.') {
822 hasSep = true;
823 front = true;
824 continue;
825 }
826 return "bad character '" + c + "'";
827 }
828 return hasSep || !requiresSeparator
829 ? null : "must have at least one '.' separator";
830 }
831
832 private static String parsePackageName(XmlPullParser parser,
833 AttributeSet attrs, int flags, String[] outError)
834 throws IOException, XmlPullParserException {
835
836 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700837 while ((type = parser.next()) != XmlPullParser.START_TAG
838 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 ;
840 }
841
Kenny Rootd2d29252011-08-08 11:27:57 -0700842 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 outError[0] = "No start tag found";
844 return null;
845 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700846 if (DEBUG_PARSER)
847 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 if (!parser.getName().equals("manifest")) {
849 outError[0] = "No <manifest> tag";
850 return null;
851 }
852 String pkgName = attrs.getAttributeValue(null, "package");
853 if (pkgName == null || pkgName.length() == 0) {
854 outError[0] = "<manifest> does not specify package";
855 return null;
856 }
857 String nameError = validateName(pkgName, true);
858 if (nameError != null && !"android".equals(pkgName)) {
859 outError[0] = "<manifest> specifies bad package name \""
860 + pkgName + "\": " + nameError;
861 return null;
862 }
863
864 return pkgName.intern();
865 }
866
Kenny Root05ca4c92011-09-15 10:36:25 -0700867 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
868 AttributeSet attrs, int flags, String[] outError) throws IOException,
869 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800870
871 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700872 while ((type = parser.next()) != XmlPullParser.START_TAG
873 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800874 ;
875 }
876
Kenny Rootd2d29252011-08-08 11:27:57 -0700877 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800878 outError[0] = "No start tag found";
879 return null;
880 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700881 if (DEBUG_PARSER)
882 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800883 if (!parser.getName().equals("manifest")) {
884 outError[0] = "No <manifest> tag";
885 return null;
886 }
887 String pkgName = attrs.getAttributeValue(null, "package");
888 if (pkgName == null || pkgName.length() == 0) {
889 outError[0] = "<manifest> does not specify package";
890 return null;
891 }
892 String nameError = validateName(pkgName, true);
893 if (nameError != null && !"android".equals(pkgName)) {
894 outError[0] = "<manifest> specifies bad package name \""
895 + pkgName + "\": " + nameError;
896 return null;
897 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700898 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700899 int versionCode = 0;
900 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800901 for (int i = 0; i < attrs.getAttributeCount(); i++) {
902 String attr = attrs.getAttributeName(i);
903 if (attr.equals("installLocation")) {
904 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700905 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700906 numFound++;
907 } else if (attr.equals("versionCode")) {
908 versionCode = attrs.getAttributeIntValue(i, 0);
909 numFound++;
910 }
911 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800912 break;
913 }
914 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700915
916 // Only search the tree when the tag is directly below <manifest>
917 final int searchDepth = parser.getDepth() + 1;
918
919 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
920 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
921 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
922 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
923 continue;
924 }
925
926 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
927 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
928 if (verifier != null) {
929 verifiers.add(verifier);
930 }
931 }
932 }
933
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700934 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800935 }
936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 /**
938 * Temporary.
939 */
940 static public Signature stringToSignature(String str) {
941 final int N = str.length();
942 byte[] sig = new byte[N];
943 for (int i=0; i<N; i++) {
944 sig[i] = (byte)str.charAt(i);
945 }
946 return new Signature(sig);
947 }
948
949 private Package parsePackage(
950 Resources res, XmlResourceParser parser, int flags, String[] outError)
951 throws XmlPullParserException, IOException {
952 AttributeSet attrs = parser;
953
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700954 mParseInstrumentationArgs = null;
955 mParseActivityArgs = null;
956 mParseServiceArgs = null;
957 mParseProviderArgs = null;
958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 String pkgName = parsePackageName(parser, attrs, flags, outError);
960 if (pkgName == null) {
961 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
962 return null;
963 }
964 int type;
965
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700966 if (mOnlyCoreApps) {
967 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
968 if (!core) {
969 mParseError = PackageManager.INSTALL_SUCCEEDED;
970 return null;
971 }
972 }
973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 TypedArray sa = res.obtainAttributes(attrs,
978 com.android.internal.R.styleable.AndroidManifest);
979 pkg.mVersionCode = sa.getInteger(
980 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800981 pkg.mVersionName = sa.getNonConfigurationString(
982 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 if (pkg.mVersionName != null) {
984 pkg.mVersionName = pkg.mVersionName.intern();
985 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800986 String str = sa.getNonConfigurationString(
987 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
988 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 String nameError = validateName(str, true);
990 if (nameError != null && !"android".equals(pkgName)) {
991 outError[0] = "<manifest> specifies bad sharedUserId name \""
992 + str + "\": " + nameError;
993 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
994 return null;
995 }
996 pkg.mSharedUserId = str.intern();
997 pkg.mSharedUserLabel = sa.getResourceId(
998 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
999 }
1000 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -08001001
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08001002 pkg.installLocation = sa.getInteger(
1003 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -07001004 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001005 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -07001006
1007 /* Set the global "forward lock" flag */
1008 if ((flags & PARSE_FORWARD_LOCK) != 0) {
1009 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
1010 }
1011
1012 /* Set the global "on SD card" flag */
1013 if ((flags & PARSE_ON_SDCARD) != 0) {
1014 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
1015 }
1016
Dianne Hackborn723738c2009-06-25 19:48:04 -07001017 // Resource boolean are -1, so 1 means we don't know the value.
1018 int supportsSmallScreens = 1;
1019 int supportsNormalScreens = 1;
1020 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001021 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001022 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001023 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -07001026 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1027 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1028 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 continue;
1030 }
1031
1032 String tagName = parser.getName();
1033 if (tagName.equals("application")) {
1034 if (foundApp) {
1035 if (RIGID_PARSER) {
1036 outError[0] = "<manifest> has more than one <application>";
1037 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1038 return null;
1039 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001040 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 XmlUtils.skipCurrentTag(parser);
1042 continue;
1043 }
1044 }
1045
1046 foundApp = true;
1047 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1048 return null;
1049 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001050 } else if (tagName.equals("keys")) {
1051 if (!parseKeys(pkg, res, parser, attrs, outError)) {
1052 return null;
1053 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001055 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 return null;
1057 }
1058 } else if (tagName.equals("permission")) {
1059 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1060 return null;
1061 }
1062 } else if (tagName.equals("permission-tree")) {
1063 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1064 return null;
1065 }
1066 } else if (tagName.equals("uses-permission")) {
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001067 if (!parseUsesPermission(pkg, res, parser, attrs, outError)) {
1068 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 }
1070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 } else if (tagName.equals("uses-configuration")) {
1072 ConfigurationInfo cPref = new ConfigurationInfo();
1073 sa = res.obtainAttributes(attrs,
1074 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1075 cPref.reqTouchScreen = sa.getInt(
1076 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1077 Configuration.TOUCHSCREEN_UNDEFINED);
1078 cPref.reqKeyboardType = sa.getInt(
1079 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1080 Configuration.KEYBOARD_UNDEFINED);
1081 if (sa.getBoolean(
1082 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1083 false)) {
1084 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1085 }
1086 cPref.reqNavigation = sa.getInt(
1087 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1088 Configuration.NAVIGATION_UNDEFINED);
1089 if (sa.getBoolean(
1090 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1091 false)) {
1092 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1093 }
1094 sa.recycle();
1095 pkg.configPreferences.add(cPref);
1096
1097 XmlUtils.skipCurrentTag(parser);
1098
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001099 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001100 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001101 sa = res.obtainAttributes(attrs,
1102 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001103 // Note: don't allow this value to be a reference to a resource
1104 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001105 fi.name = sa.getNonResourceString(
1106 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1107 if (fi.name == null) {
1108 fi.reqGlEsVersion = sa.getInt(
1109 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1110 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1111 }
1112 if (sa.getBoolean(
1113 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1114 true)) {
1115 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1116 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001117 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001118 if (pkg.reqFeatures == null) {
1119 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1120 }
1121 pkg.reqFeatures.add(fi);
1122
1123 if (fi.name == null) {
1124 ConfigurationInfo cPref = new ConfigurationInfo();
1125 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1126 pkg.configPreferences.add(cPref);
1127 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001128
1129 XmlUtils.skipCurrentTag(parser);
1130
Dianne Hackborn851a5412009-05-08 12:06:44 -07001131 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001132 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 sa = res.obtainAttributes(attrs,
1134 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1135
Dianne Hackborn851a5412009-05-08 12:06:44 -07001136 int minVers = 0;
1137 String minCode = null;
1138 int targetVers = 0;
1139 String targetCode = null;
1140
1141 TypedValue val = sa.peekValue(
1142 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1143 if (val != null) {
1144 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1145 targetCode = minCode = val.string.toString();
1146 } else {
1147 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001148 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001149 }
1150 }
1151
1152 val = sa.peekValue(
1153 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1154 if (val != null) {
1155 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1156 targetCode = minCode = val.string.toString();
1157 } else {
1158 // If it's not a string, it's an integer.
1159 targetVers = val.data;
1160 }
1161 }
1162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 sa.recycle();
1164
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001165 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001166 if (!minCode.equals(SDK_CODENAME)) {
1167 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001168 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001169 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001170 } else {
1171 outError[0] = "Requires development platform " + minCode
1172 + " but this is a release platform.";
1173 }
1174 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1175 return null;
1176 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001177 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001178 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001179 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001180 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1181 return null;
1182 }
1183
Dianne Hackborn851a5412009-05-08 12:06:44 -07001184 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001185 if (!targetCode.equals(SDK_CODENAME)) {
1186 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001187 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001188 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001189 } else {
1190 outError[0] = "Requires development platform " + targetCode
1191 + " but this is a release platform.";
1192 }
1193 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1194 return null;
1195 }
1196 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001197 pkg.applicationInfo.targetSdkVersion
1198 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1199 } else {
1200 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 }
1203
1204 XmlUtils.skipCurrentTag(parser);
1205
Dianne Hackborn723738c2009-06-25 19:48:04 -07001206 } else if (tagName.equals("supports-screens")) {
1207 sa = res.obtainAttributes(attrs,
1208 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1209
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001210 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1211 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1212 0);
1213 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1214 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1215 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001216 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1217 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1218 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001219
Dianne Hackborn723738c2009-06-25 19:48:04 -07001220 // This is a trick to get a boolean and still able to detect
1221 // if a value was actually set.
1222 supportsSmallScreens = sa.getInteger(
1223 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1224 supportsSmallScreens);
1225 supportsNormalScreens = sa.getInteger(
1226 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1227 supportsNormalScreens);
1228 supportsLargeScreens = sa.getInteger(
1229 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1230 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001231 supportsXLargeScreens = sa.getInteger(
1232 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1233 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001234 resizeable = sa.getInteger(
1235 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001236 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001237 anyDensity = sa.getInteger(
1238 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1239 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001240
1241 sa.recycle();
1242
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001243 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060af2009-07-09 18:14:31 -07001244
1245 } else if (tagName.equals("protected-broadcast")) {
1246 sa = res.obtainAttributes(attrs,
1247 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1248
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001249 // Note: don't allow this value to be a reference to a resource
1250 // that may change.
Dianne Hackborn854060af2009-07-09 18:14:31 -07001251 String name = sa.getNonResourceString(
1252 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1253
1254 sa.recycle();
1255
1256 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1257 if (pkg.protectedBroadcasts == null) {
1258 pkg.protectedBroadcasts = new ArrayList<String>();
1259 }
1260 if (!pkg.protectedBroadcasts.contains(name)) {
1261 pkg.protectedBroadcasts.add(name.intern());
1262 }
1263 }
1264
1265 XmlUtils.skipCurrentTag(parser);
1266
1267 } else if (tagName.equals("instrumentation")) {
1268 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1269 return null;
1270 }
1271
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001272 } else if (tagName.equals("original-package")) {
1273 sa = res.obtainAttributes(attrs,
1274 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1275
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001276 String orig =sa.getNonConfigurationString(
1277 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001278 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001279 if (pkg.mOriginalPackages == null) {
1280 pkg.mOriginalPackages = new ArrayList<String>();
1281 pkg.mRealPackage = pkg.packageName;
1282 }
1283 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001284 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001285
1286 sa.recycle();
1287
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001288 XmlUtils.skipCurrentTag(parser);
1289
1290 } else if (tagName.equals("adopt-permissions")) {
1291 sa = res.obtainAttributes(attrs,
1292 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1293
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001294 String name = sa.getNonConfigurationString(
1295 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001296
1297 sa.recycle();
1298
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001299 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001300 if (pkg.mAdoptPermissions == null) {
1301 pkg.mAdoptPermissions = new ArrayList<String>();
1302 }
1303 pkg.mAdoptPermissions.add(name);
1304 }
1305
1306 XmlUtils.skipCurrentTag(parser);
1307
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001308 } else if (tagName.equals("uses-gl-texture")) {
1309 // Just skip this tag
1310 XmlUtils.skipCurrentTag(parser);
1311 continue;
1312
1313 } else if (tagName.equals("compatible-screens")) {
1314 // Just skip this tag
1315 XmlUtils.skipCurrentTag(parser);
1316 continue;
1317
Dianne Hackborn854060af2009-07-09 18:14:31 -07001318 } else if (tagName.equals("eat-comment")) {
1319 // Just skip this tag
1320 XmlUtils.skipCurrentTag(parser);
1321 continue;
1322
1323 } else if (RIGID_PARSER) {
1324 outError[0] = "Bad element under <manifest>: "
1325 + parser.getName();
1326 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1327 return null;
1328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001330 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001331 + " at " + mArchiveSourcePath + " "
1332 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 XmlUtils.skipCurrentTag(parser);
1334 continue;
1335 }
1336 }
1337
1338 if (!foundApp && pkg.instrumentation.size() == 0) {
1339 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1340 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1341 }
1342
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001343 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001344 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001345 for (int ip=0; ip<NP; ip++) {
1346 final PackageParser.NewPermissionInfo npi
1347 = PackageParser.NEW_PERMISSIONS[ip];
1348 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1349 break;
1350 }
1351 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001352 if (implicitPerms == null) {
1353 implicitPerms = new StringBuilder(128);
1354 implicitPerms.append(pkg.packageName);
1355 implicitPerms.append(": compat added ");
1356 } else {
1357 implicitPerms.append(' ');
1358 }
1359 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001360 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001361 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001362 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001363 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001364 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001365 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001366 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001367
1368 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1369 for (int is=0; is<NS; is++) {
1370 final PackageParser.SplitPermissionInfo spi
1371 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001372 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1373 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001374 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001375 }
1376 for (int in=0; in<spi.newPerms.length; in++) {
1377 final String perm = spi.newPerms[in];
1378 if (!pkg.requestedPermissions.contains(perm)) {
1379 pkg.requestedPermissions.add(perm);
1380 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1381 }
1382 }
1383 }
1384
Dianne Hackborn723738c2009-06-25 19:48:04 -07001385 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1386 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001387 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001388 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1389 }
1390 if (supportsNormalScreens != 0) {
1391 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1392 }
1393 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1394 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001395 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001396 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1397 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001398 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1399 && pkg.applicationInfo.targetSdkVersion
1400 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1401 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1402 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001403 if (resizeable < 0 || (resizeable > 0
1404 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001405 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001406 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1407 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001408 if (anyDensity < 0 || (anyDensity > 0
1409 && pkg.applicationInfo.targetSdkVersion
1410 >= android.os.Build.VERSION_CODES.DONUT)) {
1411 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001412 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001413
Nick Kralevich38f130e2013-04-04 13:19:10 -07001414 /*
1415 * b/8528162: Ignore the <uses-permission android:required> attribute if
1416 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1417 * which are improperly using this attribute, even though it never worked.
1418 */
1419 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1420 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1421 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1422 }
1423 }
1424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 return pkg;
1426 }
1427
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001428 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1429 AttributeSet attrs, String[] outError)
1430 throws XmlPullParserException, IOException {
1431 TypedArray sa = res.obtainAttributes(attrs,
1432 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1433
1434 // Note: don't allow this value to be a reference to a resource
1435 // that may change.
1436 String name = sa.getNonResourceString(
1437 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b182013-04-11 10:20:09 -07001438/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001439 boolean required = sa.getBoolean(
1440 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b182013-04-11 10:20:09 -07001441*/
1442 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001443
1444 sa.recycle();
1445
1446 if (name != null) {
1447 int index = pkg.requestedPermissions.indexOf(name);
1448 if (index == -1) {
1449 pkg.requestedPermissions.add(name.intern());
1450 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1451 } else {
1452 if (pkg.requestedPermissionsRequired.get(index) != required) {
1453 outError[0] = "conflicting <uses-permission> entries";
1454 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1455 return false;
1456 }
1457 }
1458 }
1459
1460 XmlUtils.skipCurrentTag(parser);
1461 return true;
1462 }
1463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 private static String buildClassName(String pkg, CharSequence clsSeq,
1465 String[] outError) {
1466 if (clsSeq == null || clsSeq.length() <= 0) {
1467 outError[0] = "Empty class name in package " + pkg;
1468 return null;
1469 }
1470 String cls = clsSeq.toString();
1471 char c = cls.charAt(0);
1472 if (c == '.') {
1473 return (pkg + cls).intern();
1474 }
1475 if (cls.indexOf('.') < 0) {
1476 StringBuilder b = new StringBuilder(pkg);
1477 b.append('.');
1478 b.append(cls);
1479 return b.toString().intern();
1480 }
1481 if (c >= 'a' && c <= 'z') {
1482 return cls.intern();
1483 }
1484 outError[0] = "Bad class name " + cls + " in package " + pkg;
1485 return null;
1486 }
1487
1488 private static String buildCompoundName(String pkg,
1489 CharSequence procSeq, String type, String[] outError) {
1490 String proc = procSeq.toString();
1491 char c = proc.charAt(0);
1492 if (pkg != null && c == ':') {
1493 if (proc.length() < 2) {
1494 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1495 + ": must be at least two characters";
1496 return null;
1497 }
1498 String subName = proc.substring(1);
1499 String nameError = validateName(subName, false);
1500 if (nameError != null) {
1501 outError[0] = "Invalid " + type + " name " + proc + " in package "
1502 + pkg + ": " + nameError;
1503 return null;
1504 }
1505 return (pkg + proc).intern();
1506 }
1507 String nameError = validateName(proc, true);
1508 if (nameError != null && !"system".equals(proc)) {
1509 outError[0] = "Invalid " + type + " name " + proc + " in package "
1510 + pkg + ": " + nameError;
1511 return null;
1512 }
1513 return proc.intern();
1514 }
1515
1516 private static String buildProcessName(String pkg, String defProc,
1517 CharSequence procSeq, int flags, String[] separateProcesses,
1518 String[] outError) {
1519 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1520 return defProc != null ? defProc : pkg;
1521 }
1522 if (separateProcesses != null) {
1523 for (int i=separateProcesses.length-1; i>=0; i--) {
1524 String sp = separateProcesses[i];
1525 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1526 return pkg;
1527 }
1528 }
1529 }
1530 if (procSeq == null || procSeq.length() <= 0) {
1531 return defProc;
1532 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001533 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 }
1535
1536 private static String buildTaskAffinityName(String pkg, String defProc,
1537 CharSequence procSeq, String[] outError) {
1538 if (procSeq == null) {
1539 return defProc;
1540 }
1541 if (procSeq.length() <= 0) {
1542 return null;
1543 }
1544 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1545 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001546
1547 private boolean parseKeys(Package owner, Resources res,
1548 XmlPullParser parser, AttributeSet attrs, String[] outError)
1549 throws XmlPullParserException, IOException {
1550 // we've encountered the 'keys' tag
1551 // all the keys and keysets that we want must be defined here
1552 // so we're going to iterate over the parser and pull out the things we want
1553 int outerDepth = parser.getDepth();
1554
1555 int type;
1556 PublicKey currentKey = null;
Kenny Root37dca152013-07-10 14:01:49 -07001557 int currentKeyDepth = -1;
Geremy Condraf1bcca82013-01-07 22:35:24 -08001558 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1559 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1560 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1561 if (type == XmlPullParser.END_TAG) {
Kenny Root37dca152013-07-10 14:01:49 -07001562 if (parser.getDepth() == currentKeyDepth) {
1563 currentKey = null;
1564 currentKeyDepth = -1;
1565 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001566 continue;
1567 }
1568 String tagname = parser.getName();
1569 if (tagname.equals("publicKey")) {
1570 final TypedArray sa = res.obtainAttributes(attrs,
1571 com.android.internal.R.styleable.PublicKey);
1572 final String encodedKey = sa.getNonResourceString(
1573 com.android.internal.R.styleable.PublicKey_value);
1574 currentKey = parsePublicKey(encodedKey);
Kenny Root37dca152013-07-10 14:01:49 -07001575 if (currentKey == null) {
1576 Slog.w(TAG, "No valid key in 'publicKey' tag at "
1577 + parser.getPositionDescription());
1578 sa.recycle();
1579 continue;
1580 }
1581 currentKeyDepth = parser.getDepth();
Geremy Condraf1bcca82013-01-07 22:35:24 -08001582 definedKeySets.put(currentKey, new HashSet<String>());
1583 sa.recycle();
Kenny Root2758e292013-07-08 09:32:59 -07001584 } else if (tagname.equals("keyset")) {
Kenny Root37dca152013-07-10 14:01:49 -07001585 if (currentKey == null) {
1586 Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
1587 + parser.getPositionDescription());
1588 continue;
1589 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001590 final TypedArray sa = res.obtainAttributes(attrs,
1591 com.android.internal.R.styleable.KeySet);
1592 final String name = sa.getNonResourceString(
1593 com.android.internal.R.styleable.KeySet_name);
1594 definedKeySets.get(currentKey).add(name);
1595 sa.recycle();
1596 } else if (RIGID_PARSER) {
1597 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1598 + " at " + mArchiveSourcePath + " "
1599 + parser.getPositionDescription());
1600 return false;
1601 } else {
1602 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1603 + " at " + mArchiveSourcePath + " "
1604 + parser.getPositionDescription());
1605 XmlUtils.skipCurrentTag(parser);
1606 continue;
1607 }
1608 }
1609
1610 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1611 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1612 PublicKey key = e.getKey();
1613 Set<String> keySetNames = e.getValue();
1614 for (String alias : keySetNames) {
1615 if (owner.mKeySetMapping.containsKey(alias)) {
1616 owner.mKeySetMapping.get(alias).add(key);
1617 } else {
1618 Set<PublicKey> keys = new HashSet<PublicKey>();
1619 keys.add(key);
1620 owner.mKeySetMapping.put(alias, keys);
1621 }
1622 }
1623 }
1624
1625 return true;
1626 }
1627
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001628 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 XmlPullParser parser, AttributeSet attrs, String[] outError)
1630 throws XmlPullParserException, IOException {
1631 PermissionGroup perm = new PermissionGroup(owner);
1632
1633 TypedArray sa = res.obtainAttributes(attrs,
1634 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1635
1636 if (!parsePackageItemInfo(owner, perm.info, outError,
1637 "<permission-group>", sa,
1638 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1639 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001640 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1641 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 sa.recycle();
1643 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1644 return null;
1645 }
1646
1647 perm.info.descriptionRes = sa.getResourceId(
1648 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1649 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001650 perm.info.flags = sa.getInt(
1651 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001652 perm.info.priority = sa.getInt(
1653 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001654 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001655 perm.info.priority = 0;
1656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657
1658 sa.recycle();
1659
1660 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1661 outError)) {
1662 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1663 return null;
1664 }
1665
1666 owner.permissionGroups.add(perm);
1667
1668 return perm;
1669 }
1670
1671 private Permission parsePermission(Package owner, Resources res,
1672 XmlPullParser parser, AttributeSet attrs, String[] outError)
1673 throws XmlPullParserException, IOException {
1674 Permission perm = new Permission(owner);
1675
1676 TypedArray sa = res.obtainAttributes(attrs,
1677 com.android.internal.R.styleable.AndroidManifestPermission);
1678
1679 if (!parsePackageItemInfo(owner, perm.info, outError,
1680 "<permission>", sa,
1681 com.android.internal.R.styleable.AndroidManifestPermission_name,
1682 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001683 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1684 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 sa.recycle();
1686 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1687 return null;
1688 }
1689
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001690 // Note: don't allow this value to be a reference to a resource
1691 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 perm.info.group = sa.getNonResourceString(
1693 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1694 if (perm.info.group != null) {
1695 perm.info.group = perm.info.group.intern();
1696 }
1697
1698 perm.info.descriptionRes = sa.getResourceId(
1699 com.android.internal.R.styleable.AndroidManifestPermission_description,
1700 0);
1701
1702 perm.info.protectionLevel = sa.getInt(
1703 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1704 PermissionInfo.PROTECTION_NORMAL);
1705
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001706 perm.info.flags = sa.getInt(
1707 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 if (perm.info.protectionLevel == -1) {
1712 outError[0] = "<permission> does not specify protectionLevel";
1713 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1714 return null;
1715 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001716
1717 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1718
1719 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1720 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1721 PermissionInfo.PROTECTION_SIGNATURE) {
1722 outError[0] = "<permission> protectionLevel specifies a flag but is "
1723 + "not based on signature type";
1724 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1725 return null;
1726 }
1727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728
1729 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1730 outError)) {
1731 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1732 return null;
1733 }
1734
1735 owner.permissions.add(perm);
1736
1737 return perm;
1738 }
1739
1740 private Permission parsePermissionTree(Package owner, Resources res,
1741 XmlPullParser parser, AttributeSet attrs, String[] outError)
1742 throws XmlPullParserException, IOException {
1743 Permission perm = new Permission(owner);
1744
1745 TypedArray sa = res.obtainAttributes(attrs,
1746 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1747
1748 if (!parsePackageItemInfo(owner, perm.info, outError,
1749 "<permission-tree>", sa,
1750 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1751 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001752 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1753 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 sa.recycle();
1755 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1756 return null;
1757 }
1758
1759 sa.recycle();
1760
1761 int index = perm.info.name.indexOf('.');
1762 if (index > 0) {
1763 index = perm.info.name.indexOf('.', index+1);
1764 }
1765 if (index < 0) {
1766 outError[0] = "<permission-tree> name has less than three segments: "
1767 + perm.info.name;
1768 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1769 return null;
1770 }
1771
1772 perm.info.descriptionRes = 0;
1773 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1774 perm.tree = true;
1775
1776 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1777 outError)) {
1778 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1779 return null;
1780 }
1781
1782 owner.permissions.add(perm);
1783
1784 return perm;
1785 }
1786
1787 private Instrumentation parseInstrumentation(Package owner, Resources res,
1788 XmlPullParser parser, AttributeSet attrs, String[] outError)
1789 throws XmlPullParserException, IOException {
1790 TypedArray sa = res.obtainAttributes(attrs,
1791 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1792
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001793 if (mParseInstrumentationArgs == null) {
1794 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1795 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1796 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001797 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1798 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001799 mParseInstrumentationArgs.tag = "<instrumentation>";
1800 }
1801
1802 mParseInstrumentationArgs.sa = sa;
1803
1804 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1805 new InstrumentationInfo());
1806 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 sa.recycle();
1808 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1809 return null;
1810 }
1811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001813 // Note: don't allow this value to be a reference to a resource
1814 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 str = sa.getNonResourceString(
1816 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1817 a.info.targetPackage = str != null ? str.intern() : null;
1818
1819 a.info.handleProfiling = sa.getBoolean(
1820 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1821 false);
1822
1823 a.info.functionalTest = sa.getBoolean(
1824 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1825 false);
1826
1827 sa.recycle();
1828
1829 if (a.info.targetPackage == null) {
1830 outError[0] = "<instrumentation> does not specify targetPackage";
1831 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1832 return null;
1833 }
1834
1835 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1836 outError)) {
1837 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1838 return null;
1839 }
1840
1841 owner.instrumentation.add(a);
1842
1843 return a;
1844 }
1845
1846 private boolean parseApplication(Package owner, Resources res,
1847 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1848 throws XmlPullParserException, IOException {
1849 final ApplicationInfo ai = owner.applicationInfo;
1850 final String pkgName = owner.applicationInfo.packageName;
1851
1852 TypedArray sa = res.obtainAttributes(attrs,
1853 com.android.internal.R.styleable.AndroidManifestApplication);
1854
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001855 String name = sa.getNonConfigurationString(
1856 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 if (name != null) {
1858 ai.className = buildClassName(pkgName, name, outError);
1859 if (ai.className == null) {
1860 sa.recycle();
1861 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1862 return false;
1863 }
1864 }
1865
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001866 String manageSpaceActivity = sa.getNonConfigurationString(
1867 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 if (manageSpaceActivity != null) {
1869 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1870 outError);
1871 }
1872
Christopher Tate181fafa2009-05-14 11:12:14 -07001873 boolean allowBackup = sa.getBoolean(
1874 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1875 if (allowBackup) {
1876 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001877
Christopher Tate3de55bc2010-03-12 17:28:08 -08001878 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1879 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001880 String backupAgent = sa.getNonConfigurationString(
1881 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001882 if (backupAgent != null) {
1883 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001884 if (DEBUG_BACKUP) {
1885 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001886 + " from " + pkgName + "+" + backupAgent);
1887 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001888
1889 if (sa.getBoolean(
1890 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1891 true)) {
1892 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1893 }
1894 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001895 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1896 false)) {
1897 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1898 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001899 }
1900 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001902 TypedValue v = sa.peekValue(
1903 com.android.internal.R.styleable.AndroidManifestApplication_label);
1904 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1905 ai.nonLocalizedLabel = v.coerceToString();
1906 }
1907
1908 ai.icon = sa.getResourceId(
1909 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001910 ai.logo = sa.getResourceId(
1911 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001913 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001914 ai.descriptionRes = sa.getResourceId(
1915 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1916
1917 if ((flags&PARSE_IS_SYSTEM) != 0) {
1918 if (sa.getBoolean(
1919 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1920 false)) {
1921 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1922 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001923 }
1924
1925 if (sa.getBoolean(
1926 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1927 false)) {
1928 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001929 }
1930
1931 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1932 .AndroidManifestApplication_restrictedAccountType);
1933 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1934 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 }
1936
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001937 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1938 .AndroidManifestApplication_requiredAccountType);
1939 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1940 owner.mRequiredAccountType = requiredAccountType;
1941 }
1942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 if (sa.getBoolean(
1944 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1945 false)) {
1946 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1947 }
1948
1949 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001950 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001951 false)) {
1952 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1953 }
1954
Romain Guy529b60a2010-08-03 18:05:47 -07001955 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001956 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001957 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001958
1959 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1961 true)) {
1962 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1963 }
1964
1965 if (sa.getBoolean(
1966 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1967 false)) {
1968 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1969 }
1970
1971 if (sa.getBoolean(
1972 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1973 true)) {
1974 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1975 }
1976
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001977 if (sa.getBoolean(
1978 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001979 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001980 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1981 }
1982
Jason parksa3cdaa52011-01-13 14:15:43 -06001983 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001984 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001985 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001986 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001987 }
1988
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001989 if (sa.getBoolean(
1990 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1991 false /* default is no RTL support*/)) {
1992 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1993 }
1994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001996 str = sa.getNonConfigurationString(
1997 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1999
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002000 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2001 str = sa.getNonConfigurationString(
2002 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
2003 } else {
2004 // Some older apps have been seen to use a resource reference
2005 // here that on older builds was ignored (with a warning). We
2006 // need to continue to do this for them so they don't break.
2007 str = sa.getNonResourceString(
2008 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
2009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
2011 str, outError);
2012
2013 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07002014 CharSequence pname;
2015 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
2016 pname = sa.getNonConfigurationString(
2017 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
2018 } else {
2019 // Some older apps have been seen to use a resource reference
2020 // here that on older builds was ignored (with a warning). We
2021 // need to continue to do this for them so they don't break.
2022 pname = sa.getNonResourceString(
2023 com.android.internal.R.styleable.AndroidManifestApplication_process);
2024 }
2025 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 flags, mSeparateProcesses, outError);
2027
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002028 ai.enabled = sa.getBoolean(
2029 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002030
Dianne Hackborn02486b12010-08-26 14:18:37 -07002031 if (false) {
2032 if (sa.getBoolean(
2033 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2034 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002035 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002036
2037 // A heavy-weight application can not be in a custom process.
2038 // We can do direct compare because we intern all strings.
2039 if (ai.processName != null && ai.processName != ai.packageName) {
2040 outError[0] = "cantSaveState applications can not use custom processes";
2041 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002042 }
2043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 }
2045
Adam Powell269248d2011-08-02 10:26:54 -07002046 ai.uiOptions = sa.getInt(
2047 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002049 sa.recycle();
2050
2051 if (outError[0] != null) {
2052 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2053 return false;
2054 }
2055
2056 final int innerDepth = parser.getDepth();
2057
2058 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002059 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2060 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2061 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 continue;
2063 }
2064
2065 String tagName = parser.getName();
2066 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002067 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2068 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 if (a == null) {
2070 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2071 return false;
2072 }
2073
2074 owner.activities.add(a);
2075
2076 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002077 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 if (a == null) {
2079 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2080 return false;
2081 }
2082
2083 owner.receivers.add(a);
2084
2085 } else if (tagName.equals("service")) {
2086 Service s = parseService(owner, res, parser, attrs, flags, outError);
2087 if (s == null) {
2088 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2089 return false;
2090 }
2091
2092 owner.services.add(s);
2093
2094 } else if (tagName.equals("provider")) {
2095 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2096 if (p == null) {
2097 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2098 return false;
2099 }
2100
2101 owner.providers.add(p);
2102
2103 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002104 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002105 if (a == null) {
2106 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2107 return false;
2108 }
2109
2110 owner.activities.add(a);
2111
2112 } else if (parser.getName().equals("meta-data")) {
2113 // note: application meta-data is stored off to the side, so it can
2114 // remain null in the primary copy (we like to avoid extra copies because
2115 // it can be large)
2116 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2117 outError)) == null) {
2118 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2119 return false;
2120 }
2121
Dianne Hackbornc895be72013-03-11 17:48:43 -07002122 } else if (tagName.equals("library")) {
2123 sa = res.obtainAttributes(attrs,
2124 com.android.internal.R.styleable.AndroidManifestLibrary);
2125
2126 // Note: don't allow this value to be a reference to a resource
2127 // that may change.
2128 String lname = sa.getNonResourceString(
2129 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2130
2131 sa.recycle();
2132
2133 if (lname != null) {
2134 if (owner.libraryNames == null) {
2135 owner.libraryNames = new ArrayList<String>();
2136 }
2137 if (!owner.libraryNames.contains(lname)) {
2138 owner.libraryNames.add(lname.intern());
2139 }
2140 }
2141
2142 XmlUtils.skipCurrentTag(parser);
2143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 } else if (tagName.equals("uses-library")) {
2145 sa = res.obtainAttributes(attrs,
2146 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2147
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002148 // Note: don't allow this value to be a reference to a resource
2149 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 String lname = sa.getNonResourceString(
2151 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002152 boolean req = sa.getBoolean(
2153 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2154 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155
2156 sa.recycle();
2157
Dianne Hackborn49237342009-08-27 20:08:01 -07002158 if (lname != null) {
2159 if (req) {
2160 if (owner.usesLibraries == null) {
2161 owner.usesLibraries = new ArrayList<String>();
2162 }
2163 if (!owner.usesLibraries.contains(lname)) {
2164 owner.usesLibraries.add(lname.intern());
2165 }
2166 } else {
2167 if (owner.usesOptionalLibraries == null) {
2168 owner.usesOptionalLibraries = new ArrayList<String>();
2169 }
2170 if (!owner.usesOptionalLibraries.contains(lname)) {
2171 owner.usesOptionalLibraries.add(lname.intern());
2172 }
2173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 }
2175
2176 XmlUtils.skipCurrentTag(parser);
2177
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002178 } else if (tagName.equals("uses-package")) {
2179 // Dependencies for app installers; we don't currently try to
2180 // enforce this.
2181 XmlUtils.skipCurrentTag(parser);
2182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 } else {
2184 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002185 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002186 + " at " + mArchiveSourcePath + " "
2187 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 XmlUtils.skipCurrentTag(parser);
2189 continue;
2190 } else {
2191 outError[0] = "Bad element under <application>: " + tagName;
2192 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2193 return false;
2194 }
2195 }
2196 }
2197
2198 return true;
2199 }
2200
2201 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2202 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002203 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002204 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 if (name == null) {
2206 outError[0] = tag + " does not specify android:name";
2207 return false;
2208 }
2209
2210 outInfo.name
2211 = buildClassName(owner.applicationInfo.packageName, name, outError);
2212 if (outInfo.name == null) {
2213 return false;
2214 }
2215
2216 int iconVal = sa.getResourceId(iconRes, 0);
2217 if (iconVal != 0) {
2218 outInfo.icon = iconVal;
2219 outInfo.nonLocalizedLabel = null;
2220 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002221
2222 int logoVal = sa.getResourceId(logoRes, 0);
2223 if (logoVal != 0) {
2224 outInfo.logo = logoVal;
2225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226
2227 TypedValue v = sa.peekValue(labelRes);
2228 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2229 outInfo.nonLocalizedLabel = v.coerceToString();
2230 }
2231
2232 outInfo.packageName = owner.packageName;
2233
2234 return true;
2235 }
2236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 private Activity parseActivity(Package owner, Resources res,
2238 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002239 boolean receiver, boolean hardwareAccelerated)
2240 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 TypedArray sa = res.obtainAttributes(attrs,
2242 com.android.internal.R.styleable.AndroidManifestActivity);
2243
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002244 if (mParseActivityArgs == null) {
2245 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2246 com.android.internal.R.styleable.AndroidManifestActivity_name,
2247 com.android.internal.R.styleable.AndroidManifestActivity_label,
2248 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002249 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002250 mSeparateProcesses,
2251 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002252 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002253 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2254 }
2255
2256 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2257 mParseActivityArgs.sa = sa;
2258 mParseActivityArgs.flags = flags;
2259
2260 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2261 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 sa.recycle();
2263 return null;
2264 }
2265
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002266 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2268 if (setExported) {
2269 a.info.exported = sa.getBoolean(
2270 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2271 }
2272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 a.info.theme = sa.getResourceId(
2274 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2275
Adam Powell269248d2011-08-02 10:26:54 -07002276 a.info.uiOptions = sa.getInt(
2277 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2278 a.info.applicationInfo.uiOptions);
2279
Adam Powelldd8fab22012-03-22 17:47:27 -07002280 String parentName = sa.getNonConfigurationString(
2281 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2282 if (parentName != null) {
2283 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2284 if (outError[0] == null) {
2285 a.info.parentActivityName = parentClassName;
2286 } else {
2287 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2288 parentName);
2289 outError[0] = null;
2290 }
2291 }
2292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002294 str = sa.getNonConfigurationString(
2295 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 if (str == null) {
2297 a.info.permission = owner.applicationInfo.permission;
2298 } else {
2299 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2300 }
2301
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002302 str = sa.getNonConfigurationString(
2303 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2305 owner.applicationInfo.taskAffinity, str, outError);
2306
2307 a.info.flags = 0;
2308 if (sa.getBoolean(
2309 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2310 false)) {
2311 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2312 }
2313
2314 if (sa.getBoolean(
2315 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2316 false)) {
2317 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2318 }
2319
2320 if (sa.getBoolean(
2321 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2322 false)) {
2323 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2324 }
2325
2326 if (sa.getBoolean(
2327 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2328 false)) {
2329 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2330 }
2331
2332 if (sa.getBoolean(
2333 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2334 false)) {
2335 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2336 }
2337
2338 if (sa.getBoolean(
2339 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2340 false)) {
2341 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2342 }
2343
2344 if (sa.getBoolean(
2345 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2346 false)) {
2347 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2348 }
2349
2350 if (sa.getBoolean(
2351 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2352 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2353 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2354 }
2355
Dianne Hackbornffa42482009-09-23 22:20:11 -07002356 if (sa.getBoolean(
2357 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2358 false)) {
2359 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2360 }
2361
Daniel Sandler613dde42010-06-21 13:46:39 -04002362 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002363 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2364 false)) {
2365 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2366 }
2367
2368 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002369 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2370 false)) {
2371 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2372 }
Craig Mautner5962b122012-10-05 14:45:52 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002375 if (sa.getBoolean(
2376 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2377 hardwareAccelerated)) {
2378 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2379 }
2380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 a.info.launchMode = sa.getInt(
2382 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2383 ActivityInfo.LAUNCH_MULTIPLE);
2384 a.info.screenOrientation = sa.getInt(
2385 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2386 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2387 a.info.configChanges = sa.getInt(
2388 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2389 0);
2390 a.info.softInputMode = sa.getInt(
2391 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2392 0);
2393 } else {
2394 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2395 a.info.configChanges = 0;
2396 }
2397
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002398 if (receiver) {
2399 if (sa.getBoolean(
2400 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2401 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002402 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002403 if (a.info.exported) {
2404 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2405 + a.className + " at " + mArchiveSourcePath + " "
2406 + parser.getPositionDescription());
2407 a.info.exported = false;
2408 }
2409 setExported = true;
2410 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002411 if (sa.getBoolean(
2412 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2413 false)) {
2414 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2415 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002416 }
2417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 sa.recycle();
2419
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002420 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002421 // A heavy-weight application can not have receives in its main process
2422 // We can do direct compare because we intern all strings.
2423 if (a.info.processName == owner.packageName) {
2424 outError[0] = "Heavy-weight applications can not have receivers in main process";
2425 }
2426 }
2427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 if (outError[0] != null) {
2429 return null;
2430 }
2431
2432 int outerDepth = parser.getDepth();
2433 int type;
2434 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2435 && (type != XmlPullParser.END_TAG
2436 || parser.getDepth() > outerDepth)) {
2437 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2438 continue;
2439 }
2440
2441 if (parser.getName().equals("intent-filter")) {
2442 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2443 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2444 return null;
2445 }
2446 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002447 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002448 + mArchiveSourcePath + " "
2449 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 } else {
2451 a.intents.add(intent);
2452 }
2453 } else if (parser.getName().equals("meta-data")) {
2454 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2455 outError)) == null) {
2456 return null;
2457 }
2458 } else {
2459 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002460 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002462 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002463 + " at " + mArchiveSourcePath + " "
2464 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002466 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002467 + " at " + mArchiveSourcePath + " "
2468 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 }
2470 XmlUtils.skipCurrentTag(parser);
2471 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002473 if (receiver) {
2474 outError[0] = "Bad element under <receiver>: " + parser.getName();
2475 } else {
2476 outError[0] = "Bad element under <activity>: " + parser.getName();
2477 }
2478 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 }
2481 }
2482
2483 if (!setExported) {
2484 a.info.exported = a.intents.size() > 0;
2485 }
2486
2487 return a;
2488 }
2489
2490 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002491 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2492 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 TypedArray sa = res.obtainAttributes(attrs,
2494 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2495
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002496 String targetActivity = sa.getNonConfigurationString(
2497 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 if (targetActivity == null) {
2499 outError[0] = "<activity-alias> does not specify android:targetActivity";
2500 sa.recycle();
2501 return null;
2502 }
2503
2504 targetActivity = buildClassName(owner.applicationInfo.packageName,
2505 targetActivity, outError);
2506 if (targetActivity == null) {
2507 sa.recycle();
2508 return null;
2509 }
2510
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002511 if (mParseActivityAliasArgs == null) {
2512 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2513 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2514 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2515 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002516 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002517 mSeparateProcesses,
2518 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002519 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002520 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2521 mParseActivityAliasArgs.tag = "<activity-alias>";
2522 }
2523
2524 mParseActivityAliasArgs.sa = sa;
2525 mParseActivityAliasArgs.flags = flags;
2526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 Activity target = null;
2528
2529 final int NA = owner.activities.size();
2530 for (int i=0; i<NA; i++) {
2531 Activity t = owner.activities.get(i);
2532 if (targetActivity.equals(t.info.name)) {
2533 target = t;
2534 break;
2535 }
2536 }
2537
2538 if (target == null) {
2539 outError[0] = "<activity-alias> target activity " + targetActivity
2540 + " not found in manifest";
2541 sa.recycle();
2542 return null;
2543 }
2544
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002545 ActivityInfo info = new ActivityInfo();
2546 info.targetActivity = targetActivity;
2547 info.configChanges = target.info.configChanges;
2548 info.flags = target.info.flags;
2549 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002550 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002551 info.labelRes = target.info.labelRes;
2552 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2553 info.launchMode = target.info.launchMode;
2554 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002555 if (info.descriptionRes == 0) {
2556 info.descriptionRes = target.info.descriptionRes;
2557 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002558 info.screenOrientation = target.info.screenOrientation;
2559 info.taskAffinity = target.info.taskAffinity;
2560 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002561 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002562 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002563 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002564
2565 Activity a = new Activity(mParseActivityAliasArgs, info);
2566 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 sa.recycle();
2568 return null;
2569 }
2570
2571 final boolean setExported = sa.hasValue(
2572 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2573 if (setExported) {
2574 a.info.exported = sa.getBoolean(
2575 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2576 }
2577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002579 str = sa.getNonConfigurationString(
2580 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 if (str != null) {
2582 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2583 }
2584
Adam Powelldd8fab22012-03-22 17:47:27 -07002585 String parentName = sa.getNonConfigurationString(
2586 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2587 0);
2588 if (parentName != null) {
2589 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2590 if (outError[0] == null) {
2591 a.info.parentActivityName = parentClassName;
2592 } else {
2593 Log.e(TAG, "Activity alias " + a.info.name +
2594 " specified invalid parentActivityName " + parentName);
2595 outError[0] = null;
2596 }
2597 }
2598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 sa.recycle();
2600
2601 if (outError[0] != null) {
2602 return null;
2603 }
2604
2605 int outerDepth = parser.getDepth();
2606 int type;
2607 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2608 && (type != XmlPullParser.END_TAG
2609 || parser.getDepth() > outerDepth)) {
2610 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2611 continue;
2612 }
2613
2614 if (parser.getName().equals("intent-filter")) {
2615 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2616 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2617 return null;
2618 }
2619 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002620 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002621 + mArchiveSourcePath + " "
2622 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 } else {
2624 a.intents.add(intent);
2625 }
2626 } else if (parser.getName().equals("meta-data")) {
2627 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2628 outError)) == null) {
2629 return null;
2630 }
2631 } else {
2632 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002633 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002634 + " at " + mArchiveSourcePath + " "
2635 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 XmlUtils.skipCurrentTag(parser);
2637 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002638 } else {
2639 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2640 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 }
2643 }
2644
2645 if (!setExported) {
2646 a.info.exported = a.intents.size() > 0;
2647 }
2648
2649 return a;
2650 }
2651
2652 private Provider parseProvider(Package owner, Resources res,
2653 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2654 throws XmlPullParserException, IOException {
2655 TypedArray sa = res.obtainAttributes(attrs,
2656 com.android.internal.R.styleable.AndroidManifestProvider);
2657
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002658 if (mParseProviderArgs == null) {
2659 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2660 com.android.internal.R.styleable.AndroidManifestProvider_name,
2661 com.android.internal.R.styleable.AndroidManifestProvider_label,
2662 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002663 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002664 mSeparateProcesses,
2665 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002666 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002667 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2668 mParseProviderArgs.tag = "<provider>";
2669 }
2670
2671 mParseProviderArgs.sa = sa;
2672 mParseProviderArgs.flags = flags;
2673
2674 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2675 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 sa.recycle();
2677 return null;
2678 }
2679
Nick Kralevichf097b162012-07-28 12:43:48 -07002680 boolean providerExportedDefault = false;
2681
2682 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2683 // For compatibility, applications targeting API level 16 or lower
2684 // should have their content providers exported by default, unless they
2685 // specify otherwise.
2686 providerExportedDefault = true;
2687 }
2688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002690 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2691 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002693 String cpname = sa.getNonConfigurationString(
2694 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695
2696 p.info.isSyncable = sa.getBoolean(
2697 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2698 false);
2699
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002700 String permission = sa.getNonConfigurationString(
2701 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2702 String str = sa.getNonConfigurationString(
2703 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 if (str == null) {
2705 str = permission;
2706 }
2707 if (str == null) {
2708 p.info.readPermission = owner.applicationInfo.permission;
2709 } else {
2710 p.info.readPermission =
2711 str.length() > 0 ? str.toString().intern() : null;
2712 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002713 str = sa.getNonConfigurationString(
2714 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 if (str == null) {
2716 str = permission;
2717 }
2718 if (str == null) {
2719 p.info.writePermission = owner.applicationInfo.permission;
2720 } else {
2721 p.info.writePermission =
2722 str.length() > 0 ? str.toString().intern() : null;
2723 }
2724
2725 p.info.grantUriPermissions = sa.getBoolean(
2726 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2727 false);
2728
2729 p.info.multiprocess = sa.getBoolean(
2730 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2731 false);
2732
2733 p.info.initOrder = sa.getInt(
2734 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2735 0);
2736
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002737 p.info.flags = 0;
2738
2739 if (sa.getBoolean(
2740 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2741 false)) {
2742 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2743 if (p.info.exported) {
2744 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2745 + p.className + " at " + mArchiveSourcePath + " "
2746 + parser.getPositionDescription());
2747 p.info.exported = false;
2748 }
2749 }
2750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 sa.recycle();
2752
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002753 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002754 // A heavy-weight application can not have providers in its main process
2755 // We can do direct compare because we intern all strings.
2756 if (p.info.processName == owner.packageName) {
2757 outError[0] = "Heavy-weight applications can not have providers in main process";
2758 return null;
2759 }
2760 }
2761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002763 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002764 return null;
2765 }
2766 p.info.authority = cpname.intern();
2767
2768 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2769 return null;
2770 }
2771
2772 return p;
2773 }
2774
2775 private boolean parseProviderTags(Resources res,
2776 XmlPullParser parser, AttributeSet attrs,
2777 Provider outInfo, String[] outError)
2778 throws XmlPullParserException, IOException {
2779 int outerDepth = parser.getDepth();
2780 int type;
2781 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2782 && (type != XmlPullParser.END_TAG
2783 || parser.getDepth() > outerDepth)) {
2784 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2785 continue;
2786 }
2787
2788 if (parser.getName().equals("meta-data")) {
2789 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2790 outInfo.metaData, outError)) == null) {
2791 return false;
2792 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 } else if (parser.getName().equals("grant-uri-permission")) {
2795 TypedArray sa = res.obtainAttributes(attrs,
2796 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2797
2798 PatternMatcher pa = null;
2799
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002800 String str = sa.getNonConfigurationString(
2801 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 if (str != null) {
2803 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2804 }
2805
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002806 str = sa.getNonConfigurationString(
2807 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 if (str != null) {
2809 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2810 }
2811
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002812 str = sa.getNonConfigurationString(
2813 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 if (str != null) {
2815 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2816 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 sa.recycle();
2819
2820 if (pa != null) {
2821 if (outInfo.info.uriPermissionPatterns == null) {
2822 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2823 outInfo.info.uriPermissionPatterns[0] = pa;
2824 } else {
2825 final int N = outInfo.info.uriPermissionPatterns.length;
2826 PatternMatcher[] newp = new PatternMatcher[N+1];
2827 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2828 newp[N] = pa;
2829 outInfo.info.uriPermissionPatterns = newp;
2830 }
2831 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002832 } else {
2833 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002834 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002835 + parser.getName() + " at " + mArchiveSourcePath + " "
2836 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002837 XmlUtils.skipCurrentTag(parser);
2838 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002839 } else {
2840 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2841 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002842 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002843 }
2844 XmlUtils.skipCurrentTag(parser);
2845
2846 } else if (parser.getName().equals("path-permission")) {
2847 TypedArray sa = res.obtainAttributes(attrs,
2848 com.android.internal.R.styleable.AndroidManifestPathPermission);
2849
2850 PathPermission pa = null;
2851
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002852 String permission = sa.getNonConfigurationString(
2853 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2854 String readPermission = sa.getNonConfigurationString(
2855 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002856 if (readPermission == null) {
2857 readPermission = permission;
2858 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002859 String writePermission = sa.getNonConfigurationString(
2860 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002861 if (writePermission == null) {
2862 writePermission = permission;
2863 }
2864
2865 boolean havePerm = false;
2866 if (readPermission != null) {
2867 readPermission = readPermission.intern();
2868 havePerm = true;
2869 }
2870 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002871 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002872 havePerm = true;
2873 }
2874
2875 if (!havePerm) {
2876 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002877 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002878 + parser.getName() + " at " + mArchiveSourcePath + " "
2879 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002880 XmlUtils.skipCurrentTag(parser);
2881 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002882 } else {
2883 outError[0] = "No readPermission or writePermssion for <path-permission>";
2884 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002885 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002886 }
2887
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002888 String path = sa.getNonConfigurationString(
2889 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002890 if (path != null) {
2891 pa = new PathPermission(path,
2892 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2893 }
2894
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002895 path = sa.getNonConfigurationString(
2896 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002897 if (path != null) {
2898 pa = new PathPermission(path,
2899 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2900 }
2901
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002902 path = sa.getNonConfigurationString(
2903 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002904 if (path != null) {
2905 pa = new PathPermission(path,
2906 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2907 }
2908
2909 sa.recycle();
2910
2911 if (pa != null) {
2912 if (outInfo.info.pathPermissions == null) {
2913 outInfo.info.pathPermissions = new PathPermission[1];
2914 outInfo.info.pathPermissions[0] = pa;
2915 } else {
2916 final int N = outInfo.info.pathPermissions.length;
2917 PathPermission[] newp = new PathPermission[N+1];
2918 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2919 newp[N] = pa;
2920 outInfo.info.pathPermissions = newp;
2921 }
2922 } else {
2923 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002924 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002925 + parser.getName() + " at " + mArchiveSourcePath + " "
2926 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002927 XmlUtils.skipCurrentTag(parser);
2928 continue;
2929 }
2930 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2931 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
2933 XmlUtils.skipCurrentTag(parser);
2934
2935 } else {
2936 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002937 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002938 + parser.getName() + " at " + mArchiveSourcePath + " "
2939 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 XmlUtils.skipCurrentTag(parser);
2941 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002942 } else {
2943 outError[0] = "Bad element under <provider>: " + parser.getName();
2944 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 }
2947 }
2948 return true;
2949 }
2950
2951 private Service parseService(Package owner, Resources res,
2952 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2953 throws XmlPullParserException, IOException {
2954 TypedArray sa = res.obtainAttributes(attrs,
2955 com.android.internal.R.styleable.AndroidManifestService);
2956
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002957 if (mParseServiceArgs == null) {
2958 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2959 com.android.internal.R.styleable.AndroidManifestService_name,
2960 com.android.internal.R.styleable.AndroidManifestService_label,
2961 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002962 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002963 mSeparateProcesses,
2964 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002965 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002966 com.android.internal.R.styleable.AndroidManifestService_enabled);
2967 mParseServiceArgs.tag = "<service>";
2968 }
2969
2970 mParseServiceArgs.sa = sa;
2971 mParseServiceArgs.flags = flags;
2972
2973 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2974 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 sa.recycle();
2976 return null;
2977 }
2978
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002979 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 com.android.internal.R.styleable.AndroidManifestService_exported);
2981 if (setExported) {
2982 s.info.exported = sa.getBoolean(
2983 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2984 }
2985
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002986 String str = sa.getNonConfigurationString(
2987 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 if (str == null) {
2989 s.info.permission = owner.applicationInfo.permission;
2990 } else {
2991 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2992 }
2993
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002994 s.info.flags = 0;
2995 if (sa.getBoolean(
2996 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2997 false)) {
2998 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2999 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08003000 if (sa.getBoolean(
3001 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
3002 false)) {
3003 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
3004 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07003005 if (sa.getBoolean(
3006 com.android.internal.R.styleable.AndroidManifestService_singleUser,
3007 false)) {
3008 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
3009 if (s.info.exported) {
3010 Slog.w(TAG, "Service exported request ignored due to singleUser: "
3011 + s.className + " at " + mArchiveSourcePath + " "
3012 + parser.getPositionDescription());
3013 s.info.exported = false;
3014 }
3015 setExported = true;
3016 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 sa.recycle();
3019
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003020 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003021 // A heavy-weight application can not have services in its main process
3022 // We can do direct compare because we intern all strings.
3023 if (s.info.processName == owner.packageName) {
3024 outError[0] = "Heavy-weight applications can not have services in main process";
3025 return null;
3026 }
3027 }
3028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 int outerDepth = parser.getDepth();
3030 int type;
3031 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3032 && (type != XmlPullParser.END_TAG
3033 || parser.getDepth() > outerDepth)) {
3034 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3035 continue;
3036 }
3037
3038 if (parser.getName().equals("intent-filter")) {
3039 ServiceIntentInfo intent = new ServiceIntentInfo(s);
3040 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
3041 return null;
3042 }
3043
3044 s.intents.add(intent);
3045 } else if (parser.getName().equals("meta-data")) {
3046 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3047 outError)) == null) {
3048 return null;
3049 }
3050 } else {
3051 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003052 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003053 + parser.getName() + " at " + mArchiveSourcePath + " "
3054 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 XmlUtils.skipCurrentTag(parser);
3056 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003057 } else {
3058 outError[0] = "Bad element under <service>: " + parser.getName();
3059 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 }
3062 }
3063
3064 if (!setExported) {
3065 s.info.exported = s.intents.size() > 0;
3066 }
3067
3068 return s;
3069 }
3070
3071 private boolean parseAllMetaData(Resources res,
3072 XmlPullParser parser, AttributeSet attrs, String tag,
3073 Component outInfo, String[] outError)
3074 throws XmlPullParserException, IOException {
3075 int outerDepth = parser.getDepth();
3076 int type;
3077 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3078 && (type != XmlPullParser.END_TAG
3079 || parser.getDepth() > outerDepth)) {
3080 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3081 continue;
3082 }
3083
3084 if (parser.getName().equals("meta-data")) {
3085 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3086 outInfo.metaData, outError)) == null) {
3087 return false;
3088 }
3089 } else {
3090 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003091 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003092 + parser.getName() + " at " + mArchiveSourcePath + " "
3093 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 XmlUtils.skipCurrentTag(parser);
3095 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003096 } else {
3097 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3098 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 }
3101 }
3102 return true;
3103 }
3104
3105 private Bundle parseMetaData(Resources res,
3106 XmlPullParser parser, AttributeSet attrs,
3107 Bundle data, String[] outError)
3108 throws XmlPullParserException, IOException {
3109
3110 TypedArray sa = res.obtainAttributes(attrs,
3111 com.android.internal.R.styleable.AndroidManifestMetaData);
3112
3113 if (data == null) {
3114 data = new Bundle();
3115 }
3116
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003117 String name = sa.getNonConfigurationString(
3118 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 if (name == null) {
3120 outError[0] = "<meta-data> requires an android:name attribute";
3121 sa.recycle();
3122 return null;
3123 }
3124
Dianne Hackborn854060af2009-07-09 18:14:31 -07003125 name = name.intern();
3126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 TypedValue v = sa.peekValue(
3128 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3129 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003130 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 data.putInt(name, v.resourceId);
3132 } else {
3133 v = sa.peekValue(
3134 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003135 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 if (v != null) {
3137 if (v.type == TypedValue.TYPE_STRING) {
3138 CharSequence cs = v.coerceToString();
Dianne Hackborn854060af2009-07-09 18:14:31 -07003139 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3141 data.putBoolean(name, v.data != 0);
3142 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3143 && v.type <= TypedValue.TYPE_LAST_INT) {
3144 data.putInt(name, v.data);
3145 } else if (v.type == TypedValue.TYPE_FLOAT) {
3146 data.putFloat(name, v.getFloat());
3147 } else {
3148 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003149 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003150 + parser.getName() + " at " + mArchiveSourcePath + " "
3151 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 } else {
3153 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3154 data = null;
3155 }
3156 }
3157 } else {
3158 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3159 data = null;
3160 }
3161 }
3162
3163 sa.recycle();
3164
3165 XmlUtils.skipCurrentTag(parser);
3166
3167 return data;
3168 }
3169
Kenny Root05ca4c92011-09-15 10:36:25 -07003170 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3171 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3172 IOException {
3173 final TypedArray sa = res.obtainAttributes(attrs,
3174 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3175
3176 final String packageName = sa.getNonResourceString(
3177 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3178
3179 final String encodedPublicKey = sa.getNonResourceString(
3180 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3181
3182 sa.recycle();
3183
3184 if (packageName == null || packageName.length() == 0) {
3185 Slog.i(TAG, "verifier package name was null; skipping");
3186 return null;
3187 } else if (encodedPublicKey == null) {
3188 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3189 }
3190
Geremy Condraf1bcca82013-01-07 22:35:24 -08003191 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3192 if (publicKey != null) {
3193 return new VerifierInfo(packageName, publicKey);
3194 }
3195
3196 return null;
3197 }
3198
3199 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003200 EncodedKeySpec keySpec;
3201 try {
3202 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3203 keySpec = new X509EncodedKeySpec(encoded);
3204 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003205 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003206 return null;
3207 }
3208
3209 /* First try the key as an RSA key. */
3210 try {
3211 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003212 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003213 } catch (NoSuchAlgorithmException e) {
3214 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3215 return null;
3216 } catch (InvalidKeySpecException e) {
3217 // Not a RSA public key.
3218 }
3219
3220 /* Now try it as a DSA key. */
3221 try {
3222 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003223 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003224 } catch (NoSuchAlgorithmException e) {
3225 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3226 return null;
3227 } catch (InvalidKeySpecException e) {
3228 // Not a DSA public key.
3229 }
3230
3231 return null;
3232 }
3233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234 private static final String ANDROID_RESOURCES
3235 = "http://schemas.android.com/apk/res/android";
3236
3237 private boolean parseIntent(Resources res,
3238 XmlPullParser parser, AttributeSet attrs, int flags,
3239 IntentInfo outInfo, String[] outError, boolean isActivity)
3240 throws XmlPullParserException, IOException {
3241
3242 TypedArray sa = res.obtainAttributes(attrs,
3243 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3244
3245 int priority = sa.getInt(
3246 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 TypedValue v = sa.peekValue(
3250 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3251 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3252 outInfo.nonLocalizedLabel = v.coerceToString();
3253 }
3254
3255 outInfo.icon = sa.getResourceId(
3256 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003257
3258 outInfo.logo = sa.getResourceId(
3259 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260
3261 sa.recycle();
3262
3263 int outerDepth = parser.getDepth();
3264 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003265 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3266 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3267 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 continue;
3269 }
3270
3271 String nodeName = parser.getName();
3272 if (nodeName.equals("action")) {
3273 String value = attrs.getAttributeValue(
3274 ANDROID_RESOURCES, "name");
3275 if (value == null || value == "") {
3276 outError[0] = "No value supplied for <android:name>";
3277 return false;
3278 }
3279 XmlUtils.skipCurrentTag(parser);
3280
3281 outInfo.addAction(value);
3282 } else if (nodeName.equals("category")) {
3283 String value = attrs.getAttributeValue(
3284 ANDROID_RESOURCES, "name");
3285 if (value == null || value == "") {
3286 outError[0] = "No value supplied for <android:name>";
3287 return false;
3288 }
3289 XmlUtils.skipCurrentTag(parser);
3290
3291 outInfo.addCategory(value);
3292
3293 } else if (nodeName.equals("data")) {
3294 sa = res.obtainAttributes(attrs,
3295 com.android.internal.R.styleable.AndroidManifestData);
3296
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003297 String str = sa.getNonConfigurationString(
3298 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 if (str != null) {
3300 try {
3301 outInfo.addDataType(str);
3302 } catch (IntentFilter.MalformedMimeTypeException e) {
3303 outError[0] = e.toString();
3304 sa.recycle();
3305 return false;
3306 }
3307 }
3308
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003309 str = sa.getNonConfigurationString(
3310 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 if (str != null) {
3312 outInfo.addDataScheme(str);
3313 }
3314
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003315 str = sa.getNonConfigurationString(
3316 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3317 if (str != null) {
3318 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3319 }
3320
3321 str = sa.getNonConfigurationString(
3322 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3323 if (str != null) {
3324 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3325 }
3326
3327 str = sa.getNonConfigurationString(
3328 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3329 if (str != null) {
3330 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3331 }
3332
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003333 String host = sa.getNonConfigurationString(
3334 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3335 String port = sa.getNonConfigurationString(
3336 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 if (host != null) {
3338 outInfo.addDataAuthority(host, port);
3339 }
3340
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003341 str = sa.getNonConfigurationString(
3342 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 if (str != null) {
3344 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3345 }
3346
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003347 str = sa.getNonConfigurationString(
3348 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 if (str != null) {
3350 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3351 }
3352
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003353 str = sa.getNonConfigurationString(
3354 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 if (str != null) {
3356 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3357 }
3358
3359 sa.recycle();
3360 XmlUtils.skipCurrentTag(parser);
3361 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003362 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003363 + parser.getName() + " at " + mArchiveSourcePath + " "
3364 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 XmlUtils.skipCurrentTag(parser);
3366 } else {
3367 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3368 return false;
3369 }
3370 }
3371
3372 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003373
3374 if (DEBUG_PARSER) {
3375 final StringBuilder cats = new StringBuilder("Intent d=");
3376 cats.append(outInfo.hasDefault);
3377 cats.append(", cat=");
3378
3379 final Iterator<String> it = outInfo.categoriesIterator();
3380 if (it != null) {
3381 while (it.hasNext()) {
3382 cats.append(' ');
3383 cats.append(it.next());
3384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003386 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 }
3388
3389 return true;
3390 }
3391
3392 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003393
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003394 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395
3396 // For now we only support one application per package.
3397 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3398
3399 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3400 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3401 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3402 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3403 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3404 public final ArrayList<Service> services = new ArrayList<Service>(0);
3405 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3406
3407 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003408 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409
Dianne Hackborn854060af2009-07-09 18:14:31 -07003410 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003411
3412 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003413 public ArrayList<String> usesLibraries = null;
3414 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 public String[] usesLibraryFiles = null;
3416
Dianne Hackbornc1552392010-03-03 16:19:01 -08003417 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003418 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003419 public ArrayList<String> mAdoptPermissions = null;
3420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 // We store the application meta-data independently to avoid multiple unwanted references
3422 public Bundle mAppMetaData = null;
3423
3424 // If this is a 3rd party app, this is the path of the zip file.
3425 public String mPath;
3426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 // The version code declared for this package.
3428 public int mVersionCode;
3429
3430 // The version name declared for this package.
3431 public String mVersionName;
3432
3433 // The shared user id that this package wants to use.
3434 public String mSharedUserId;
3435
3436 // The shared user label that this package wants to use.
3437 public int mSharedUserLabel;
3438
3439 // Signatures that were read from the package.
3440 public Signature mSignatures[];
3441
3442 // For use by package manager service for quick lookup of
3443 // preferred up order.
3444 public int mPreferredOrder = 0;
3445
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003446 // For use by the package manager to keep track of the path to the
3447 // file an app came from.
3448 public String mScanPath;
3449
3450 // For use by package manager to keep track of where it has done dexopt.
3451 public boolean mDidDexOpt;
3452
Amith Yamasani13593602012-03-22 16:16:17 -07003453 // // User set enabled state.
3454 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3455 //
3456 // // Whether the package has been stopped.
3457 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 // Additional data supplied by callers.
3460 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003461
3462 // Whether an operation is currently pending on this package
3463 public boolean mOperationPending;
3464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003465 /*
3466 * Applications hardware preferences
3467 */
3468 public final ArrayList<ConfigurationInfo> configPreferences =
3469 new ArrayList<ConfigurationInfo>();
3470
Dianne Hackborn49237342009-08-27 20:08:01 -07003471 /*
3472 * Applications requested features
3473 */
3474 public ArrayList<FeatureInfo> reqFeatures = null;
3475
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003476 public int installLocation;
3477
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003478 /* An app that's required for all users and cannot be uninstalled for a user */
3479 public boolean mRequiredForAllUsers;
3480
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003481 /* The restricted account authenticator type that is used by this application */
3482 public String mRestrictedAccountType;
3483
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003484 /* The required account type without which this application will not function */
3485 public String mRequiredAccountType;
3486
Kenny Rootbcc954d2011-08-08 16:19:08 -07003487 /**
3488 * Digest suitable for comparing whether this package's manifest is the
3489 * same as another.
3490 */
3491 public ManifestDigest manifestDigest;
3492
Geremy Condraf1bcca82013-01-07 22:35:24 -08003493 /**
3494 * Data used to feed the KeySetManager
3495 */
3496 public Set<PublicKey> mSigningKeys;
3497 public Map<String, Set<PublicKey>> mKeySetMapping;
3498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 public Package(String _name) {
3500 packageName = _name;
3501 applicationInfo.packageName = _name;
3502 applicationInfo.uid = -1;
3503 }
3504
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003505 public void setPackageName(String newName) {
3506 packageName = newName;
3507 applicationInfo.packageName = newName;
3508 for (int i=permissions.size()-1; i>=0; i--) {
3509 permissions.get(i).setPackageName(newName);
3510 }
3511 for (int i=permissionGroups.size()-1; i>=0; i--) {
3512 permissionGroups.get(i).setPackageName(newName);
3513 }
3514 for (int i=activities.size()-1; i>=0; i--) {
3515 activities.get(i).setPackageName(newName);
3516 }
3517 for (int i=receivers.size()-1; i>=0; i--) {
3518 receivers.get(i).setPackageName(newName);
3519 }
3520 for (int i=providers.size()-1; i>=0; i--) {
3521 providers.get(i).setPackageName(newName);
3522 }
3523 for (int i=services.size()-1; i>=0; i--) {
3524 services.get(i).setPackageName(newName);
3525 }
3526 for (int i=instrumentation.size()-1; i>=0; i--) {
3527 instrumentation.get(i).setPackageName(newName);
3528 }
3529 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003530
3531 public boolean hasComponentClassName(String name) {
3532 for (int i=activities.size()-1; i>=0; i--) {
3533 if (name.equals(activities.get(i).className)) {
3534 return true;
3535 }
3536 }
3537 for (int i=receivers.size()-1; i>=0; i--) {
3538 if (name.equals(receivers.get(i).className)) {
3539 return true;
3540 }
3541 }
3542 for (int i=providers.size()-1; i>=0; i--) {
3543 if (name.equals(providers.get(i).className)) {
3544 return true;
3545 }
3546 }
3547 for (int i=services.size()-1; i>=0; i--) {
3548 if (name.equals(services.get(i).className)) {
3549 return true;
3550 }
3551 }
3552 for (int i=instrumentation.size()-1; i>=0; i--) {
3553 if (name.equals(instrumentation.get(i).className)) {
3554 return true;
3555 }
3556 }
3557 return false;
3558 }
3559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 public String toString() {
3561 return "Package{"
3562 + Integer.toHexString(System.identityHashCode(this))
3563 + " " + packageName + "}";
3564 }
3565 }
3566
3567 public static class Component<II extends IntentInfo> {
3568 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003569 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003570 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 public Bundle metaData;
3572
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003573 ComponentName componentName;
3574 String componentShortName;
3575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 public Component(Package _owner) {
3577 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003578 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003579 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003580 }
3581
3582 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3583 owner = args.owner;
3584 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003585 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003586 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003587 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003588 args.outError[0] = args.tag + " does not specify android:name";
3589 return;
3590 }
3591
3592 outInfo.name
3593 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3594 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003595 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003596 args.outError[0] = args.tag + " does not have valid android:name";
3597 return;
3598 }
3599
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003600 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003601
3602 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3603 if (iconVal != 0) {
3604 outInfo.icon = iconVal;
3605 outInfo.nonLocalizedLabel = null;
3606 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003607
3608 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3609 if (logoVal != 0) {
3610 outInfo.logo = logoVal;
3611 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003612
3613 TypedValue v = args.sa.peekValue(args.labelRes);
3614 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3615 outInfo.nonLocalizedLabel = v.coerceToString();
3616 }
3617
3618 outInfo.packageName = owner.packageName;
3619 }
3620
3621 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3622 this(args, (PackageItemInfo)outInfo);
3623 if (args.outError[0] != null) {
3624 return;
3625 }
3626
3627 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003628 CharSequence pname;
3629 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3630 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3631 } else {
3632 // Some older apps have been seen to use a resource reference
3633 // here that on older builds was ignored (with a warning). We
3634 // need to continue to do this for them so they don't break.
3635 pname = args.sa.getNonResourceString(args.processRes);
3636 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003637 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003638 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003639 args.flags, args.sepProcesses, args.outError);
3640 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003641
3642 if (args.descriptionRes != 0) {
3643 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3644 }
3645
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003646 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 }
3648
3649 public Component(Component<II> clone) {
3650 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003651 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003652 className = clone.className;
3653 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003654 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003655 }
3656
3657 public ComponentName getComponentName() {
3658 if (componentName != null) {
3659 return componentName;
3660 }
3661 if (className != null) {
3662 componentName = new ComponentName(owner.applicationInfo.packageName,
3663 className);
3664 }
3665 return componentName;
3666 }
3667
3668 public String getComponentShortName() {
3669 if (componentShortName != null) {
3670 return componentShortName;
3671 }
3672 ComponentName component = getComponentName();
3673 if (component != null) {
3674 componentShortName = component.flattenToShortString();
3675 }
3676 return componentShortName;
3677 }
3678
3679 public void setPackageName(String packageName) {
3680 componentName = null;
3681 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 }
3683 }
3684
3685 public final static class Permission extends Component<IntentInfo> {
3686 public final PermissionInfo info;
3687 public boolean tree;
3688 public PermissionGroup group;
3689
3690 public Permission(Package _owner) {
3691 super(_owner);
3692 info = new PermissionInfo();
3693 }
3694
3695 public Permission(Package _owner, PermissionInfo _info) {
3696 super(_owner);
3697 info = _info;
3698 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003699
3700 public void setPackageName(String packageName) {
3701 super.setPackageName(packageName);
3702 info.packageName = packageName;
3703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704
3705 public String toString() {
3706 return "Permission{"
3707 + Integer.toHexString(System.identityHashCode(this))
3708 + " " + info.name + "}";
3709 }
3710 }
3711
3712 public final static class PermissionGroup extends Component<IntentInfo> {
3713 public final PermissionGroupInfo info;
3714
3715 public PermissionGroup(Package _owner) {
3716 super(_owner);
3717 info = new PermissionGroupInfo();
3718 }
3719
3720 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3721 super(_owner);
3722 info = _info;
3723 }
3724
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003725 public void setPackageName(String packageName) {
3726 super.setPackageName(packageName);
3727 info.packageName = packageName;
3728 }
3729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 public String toString() {
3731 return "PermissionGroup{"
3732 + Integer.toHexString(System.identityHashCode(this))
3733 + " " + info.name + "}";
3734 }
3735 }
3736
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003737 private static boolean copyNeeded(int flags, Package p,
3738 PackageUserState state, Bundle metaData, int userId) {
3739 if (userId != 0) {
3740 // We always need to copy for other users, since we need
3741 // to fix up the uid.
3742 return true;
3743 }
3744 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3745 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003746 if (p.applicationInfo.enabled != enabled) {
3747 return true;
3748 }
3749 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003750 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003751 return true;
3752 }
3753 if (state.stopped) {
3754 return true;
3755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 if ((flags & PackageManager.GET_META_DATA) != 0
3757 && (metaData != null || p.mAppMetaData != null)) {
3758 return true;
3759 }
3760 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3761 && p.usesLibraryFiles != null) {
3762 return true;
3763 }
3764 return false;
3765 }
3766
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003767 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3768 PackageUserState state) {
3769 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003770 }
3771
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003772 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3773 PackageUserState state) {
3774 // CompatibilityMode is global state.
3775 if (!sCompatibilityModeEnabled) {
3776 ai.disableCompatibilityMode();
3777 }
3778 if (state.installed) {
3779 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3780 } else {
3781 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3782 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003783 if (state.blocked) {
3784 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3785 } else {
3786 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3787 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003788 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3789 ai.enabled = true;
3790 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3791 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3792 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3793 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3794 ai.enabled = false;
3795 }
3796 ai.enabledSetting = state.enabled;
3797 }
3798
Amith Yamasani13593602012-03-22 16:16:17 -07003799 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003800 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003802 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003803 return null;
3804 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003805 if (!copyNeeded(flags, p, state, null, userId)
3806 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3807 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3808 // In this case it is safe to directly modify the internal ApplicationInfo state:
3809 // - CompatibilityMode is global state, so will be the same for every call.
3810 // - We only come in to here if the app should reported as installed; this is the
3811 // default state, and we will do a copy otherwise.
3812 // - The enable state will always be reported the same for the application across
3813 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3814 // be doing a copy.
3815 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 return p.applicationInfo;
3817 }
3818
3819 // Make shallow copy so we can store the metadata/libraries safely
3820 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003821 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003822 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003823 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3824 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 if ((flags & PackageManager.GET_META_DATA) != 0) {
3826 ai.metaData = p.mAppMetaData;
3827 }
3828 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3829 ai.sharedLibraryFiles = p.usesLibraryFiles;
3830 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003831 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003832 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003833 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003834 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003835 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003836 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 return ai;
3838 }
3839
3840 public static final PermissionInfo generatePermissionInfo(
3841 Permission p, int flags) {
3842 if (p == null) return null;
3843 if ((flags&PackageManager.GET_META_DATA) == 0) {
3844 return p.info;
3845 }
3846 PermissionInfo pi = new PermissionInfo(p.info);
3847 pi.metaData = p.metaData;
3848 return pi;
3849 }
3850
3851 public static final PermissionGroupInfo generatePermissionGroupInfo(
3852 PermissionGroup pg, int flags) {
3853 if (pg == null) return null;
3854 if ((flags&PackageManager.GET_META_DATA) == 0) {
3855 return pg.info;
3856 }
3857 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3858 pgi.metaData = pg.metaData;
3859 return pgi;
3860 }
3861
3862 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003863 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003865 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3866 super(args, _info);
3867 info = _info;
3868 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003870
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003871 public void setPackageName(String packageName) {
3872 super.setPackageName(packageName);
3873 info.packageName = packageName;
3874 }
3875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 public String toString() {
3877 return "Activity{"
3878 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003879 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 }
3881 }
3882
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003883 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3884 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003886 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003887 return null;
3888 }
3889 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 return a.info;
3891 }
3892 // Make shallow copies so we can store the metadata safely
3893 ActivityInfo ai = new ActivityInfo(a.info);
3894 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003895 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 return ai;
3897 }
3898
3899 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003900 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003902 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3903 super(args, _info);
3904 info = _info;
3905 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003907
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003908 public void setPackageName(String packageName) {
3909 super.setPackageName(packageName);
3910 info.packageName = packageName;
3911 }
3912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003913 public String toString() {
3914 return "Service{"
3915 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003916 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 }
3918 }
3919
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003920 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3921 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003923 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003924 return null;
3925 }
3926 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 return s.info;
3928 }
3929 // Make shallow copies so we can store the metadata safely
3930 ServiceInfo si = new ServiceInfo(s.info);
3931 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003932 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 return si;
3934 }
3935
3936 public final static class Provider extends Component {
3937 public final ProviderInfo info;
3938 public boolean syncable;
3939
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003940 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3941 super(args, _info);
3942 info = _info;
3943 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 syncable = false;
3945 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 public Provider(Provider existingProvider) {
3948 super(existingProvider);
3949 this.info = existingProvider.info;
3950 this.syncable = existingProvider.syncable;
3951 }
3952
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003953 public void setPackageName(String packageName) {
3954 super.setPackageName(packageName);
3955 info.packageName = packageName;
3956 }
3957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 public String toString() {
3959 return "Provider{"
3960 + Integer.toHexString(System.identityHashCode(this))
3961 + " " + info.name + "}";
3962 }
3963 }
3964
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003965 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3966 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003968 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003969 return null;
3970 }
3971 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003973 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 return p.info;
3975 }
3976 // Make shallow copies so we can store the metadata safely
3977 ProviderInfo pi = new ProviderInfo(p.info);
3978 pi.metaData = p.metaData;
3979 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3980 pi.uriPermissionPatterns = null;
3981 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003982 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 return pi;
3984 }
3985
3986 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003987 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003989 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3990 super(args, _info);
3991 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003993
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003994 public void setPackageName(String packageName) {
3995 super.setPackageName(packageName);
3996 info.packageName = packageName;
3997 }
3998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 public String toString() {
4000 return "Instrumentation{"
4001 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08004002 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 }
4004 }
4005
4006 public static final InstrumentationInfo generateInstrumentationInfo(
4007 Instrumentation i, int flags) {
4008 if (i == null) return null;
4009 if ((flags&PackageManager.GET_META_DATA) == 0) {
4010 return i.info;
4011 }
4012 InstrumentationInfo ii = new InstrumentationInfo(i.info);
4013 ii.metaData = i.metaData;
4014 return ii;
4015 }
4016
4017 public static class IntentInfo extends IntentFilter {
4018 public boolean hasDefault;
4019 public int labelRes;
4020 public CharSequence nonLocalizedLabel;
4021 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004022 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 }
4024
4025 public final static class ActivityIntentInfo extends IntentInfo {
4026 public final Activity activity;
4027
4028 public ActivityIntentInfo(Activity _activity) {
4029 activity = _activity;
4030 }
4031
4032 public String toString() {
4033 return "ActivityIntentInfo{"
4034 + Integer.toHexString(System.identityHashCode(this))
4035 + " " + activity.info.name + "}";
4036 }
4037 }
4038
4039 public final static class ServiceIntentInfo extends IntentInfo {
4040 public final Service service;
4041
4042 public ServiceIntentInfo(Service _service) {
4043 service = _service;
4044 }
4045
4046 public String toString() {
4047 return "ServiceIntentInfo{"
4048 + Integer.toHexString(System.identityHashCode(this))
4049 + " " + service.info.name + "}";
4050 }
4051 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004052
4053 /**
4054 * @hide
4055 */
4056 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4057 sCompatibilityModeEnabled = compatibilityModeEnabled;
4058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059}