blob: 8f0c62d54af33cda7e0d443a93438e38aa40ba97 [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 Hackborn78d68832010-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 Hackborn854060a2009-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 Hackborn854060a2009-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 Hackborn854060a2009-07-09 18:14:31 -07001318 } else if (tagName.equals("eat-comment")) {
1319 // Just skip this tag
1320 XmlUtils.skipCurrentTag(parser);
1321 continue;
1322
1323 } else if (RIGID_PARSER) {
1324 outError[0] = "Bad element under <manifest>: "
1325 + parser.getName();
1326 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1327 return null;
1328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001330 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001331 + " at " + mArchiveSourcePath + " "
1332 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 XmlUtils.skipCurrentTag(parser);
1334 continue;
1335 }
1336 }
1337
1338 if (!foundApp && pkg.instrumentation.size() == 0) {
1339 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1340 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1341 }
1342
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001343 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001344 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001345 for (int ip=0; ip<NP; ip++) {
1346 final PackageParser.NewPermissionInfo npi
1347 = PackageParser.NEW_PERMISSIONS[ip];
1348 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1349 break;
1350 }
1351 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001352 if (implicitPerms == null) {
1353 implicitPerms = new StringBuilder(128);
1354 implicitPerms.append(pkg.packageName);
1355 implicitPerms.append(": compat added ");
1356 } else {
1357 implicitPerms.append(' ');
1358 }
1359 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001360 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001361 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001362 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001363 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001364 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001365 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001366 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001367
1368 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1369 for (int is=0; is<NS; is++) {
1370 final PackageParser.SplitPermissionInfo spi
1371 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001372 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1373 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001374 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001375 }
1376 for (int in=0; in<spi.newPerms.length; in++) {
1377 final String perm = spi.newPerms[in];
1378 if (!pkg.requestedPermissions.contains(perm)) {
1379 pkg.requestedPermissions.add(perm);
1380 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1381 }
1382 }
1383 }
1384
Dianne Hackborn723738c2009-06-25 19:48:04 -07001385 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1386 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001387 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001388 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1389 }
1390 if (supportsNormalScreens != 0) {
1391 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1392 }
1393 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1394 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001395 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001396 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1397 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001398 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1399 && pkg.applicationInfo.targetSdkVersion
1400 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1401 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1402 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001403 if (resizeable < 0 || (resizeable > 0
1404 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001405 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001406 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1407 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001408 if (anyDensity < 0 || (anyDensity > 0
1409 && pkg.applicationInfo.targetSdkVersion
1410 >= android.os.Build.VERSION_CODES.DONUT)) {
1411 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001412 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001413
Nick Kralevich38f130e2013-04-04 13:19:10 -07001414 /*
1415 * b/8528162: Ignore the <uses-permission android:required> attribute if
1416 * targetSdkVersion < JELLY_BEAN_MR2. There are lots of apps in the wild
1417 * which are improperly using this attribute, even though it never worked.
1418 */
1419 if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2) {
1420 for (int i = 0; i < pkg.requestedPermissionsRequired.size(); i++) {
1421 pkg.requestedPermissionsRequired.set(i, Boolean.TRUE);
1422 }
1423 }
1424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 return pkg;
1426 }
1427
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001428 private boolean parseUsesPermission(Package pkg, Resources res, XmlResourceParser parser,
1429 AttributeSet attrs, String[] outError)
1430 throws XmlPullParserException, IOException {
1431 TypedArray sa = res.obtainAttributes(attrs,
1432 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1433
1434 // Note: don't allow this value to be a reference to a resource
1435 // that may change.
1436 String name = sa.getNonResourceString(
1437 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001438/*
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001439 boolean required = sa.getBoolean(
1440 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Nick Kralevich32eb5b12013-04-11 10:20:09 -07001441*/
1442 boolean required = true; // Optional <uses-permission> not supported
Nick Kralevich73f2d3c2013-04-04 14:38:13 -07001443
1444 sa.recycle();
1445
1446 if (name != null) {
1447 int index = pkg.requestedPermissions.indexOf(name);
1448 if (index == -1) {
1449 pkg.requestedPermissions.add(name.intern());
1450 pkg.requestedPermissionsRequired.add(required ? Boolean.TRUE : Boolean.FALSE);
1451 } else {
1452 if (pkg.requestedPermissionsRequired.get(index) != required) {
1453 outError[0] = "conflicting <uses-permission> entries";
1454 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1455 return false;
1456 }
1457 }
1458 }
1459
1460 XmlUtils.skipCurrentTag(parser);
1461 return true;
1462 }
1463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 private static String buildClassName(String pkg, CharSequence clsSeq,
1465 String[] outError) {
1466 if (clsSeq == null || clsSeq.length() <= 0) {
1467 outError[0] = "Empty class name in package " + pkg;
1468 return null;
1469 }
1470 String cls = clsSeq.toString();
1471 char c = cls.charAt(0);
1472 if (c == '.') {
1473 return (pkg + cls).intern();
1474 }
1475 if (cls.indexOf('.') < 0) {
1476 StringBuilder b = new StringBuilder(pkg);
1477 b.append('.');
1478 b.append(cls);
1479 return b.toString().intern();
1480 }
1481 if (c >= 'a' && c <= 'z') {
1482 return cls.intern();
1483 }
1484 outError[0] = "Bad class name " + cls + " in package " + pkg;
1485 return null;
1486 }
1487
1488 private static String buildCompoundName(String pkg,
1489 CharSequence procSeq, String type, String[] outError) {
1490 String proc = procSeq.toString();
1491 char c = proc.charAt(0);
1492 if (pkg != null && c == ':') {
1493 if (proc.length() < 2) {
1494 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1495 + ": must be at least two characters";
1496 return null;
1497 }
1498 String subName = proc.substring(1);
1499 String nameError = validateName(subName, false);
1500 if (nameError != null) {
1501 outError[0] = "Invalid " + type + " name " + proc + " in package "
1502 + pkg + ": " + nameError;
1503 return null;
1504 }
1505 return (pkg + proc).intern();
1506 }
1507 String nameError = validateName(proc, true);
1508 if (nameError != null && !"system".equals(proc)) {
1509 outError[0] = "Invalid " + type + " name " + proc + " in package "
1510 + pkg + ": " + nameError;
1511 return null;
1512 }
1513 return proc.intern();
1514 }
1515
1516 private static String buildProcessName(String pkg, String defProc,
1517 CharSequence procSeq, int flags, String[] separateProcesses,
1518 String[] outError) {
1519 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1520 return defProc != null ? defProc : pkg;
1521 }
1522 if (separateProcesses != null) {
1523 for (int i=separateProcesses.length-1; i>=0; i--) {
1524 String sp = separateProcesses[i];
1525 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1526 return pkg;
1527 }
1528 }
1529 }
1530 if (procSeq == null || procSeq.length() <= 0) {
1531 return defProc;
1532 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001533 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 }
1535
1536 private static String buildTaskAffinityName(String pkg, String defProc,
1537 CharSequence procSeq, String[] outError) {
1538 if (procSeq == null) {
1539 return defProc;
1540 }
1541 if (procSeq.length() <= 0) {
1542 return null;
1543 }
1544 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1545 }
Geremy Condraf1bcca82013-01-07 22:35:24 -08001546
1547 private boolean parseKeys(Package owner, Resources res,
1548 XmlPullParser parser, AttributeSet attrs, String[] outError)
1549 throws XmlPullParserException, IOException {
1550 // we've encountered the 'keys' tag
1551 // all the keys and keysets that we want must be defined here
1552 // so we're going to iterate over the parser and pull out the things we want
1553 int outerDepth = parser.getDepth();
1554
1555 int type;
1556 PublicKey currentKey = null;
1557 Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
1558 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1559 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1560 if (type == XmlPullParser.END_TAG) {
1561 continue;
1562 }
1563 String tagname = parser.getName();
1564 if (tagname.equals("publicKey")) {
1565 final TypedArray sa = res.obtainAttributes(attrs,
1566 com.android.internal.R.styleable.PublicKey);
1567 final String encodedKey = sa.getNonResourceString(
1568 com.android.internal.R.styleable.PublicKey_value);
1569 currentKey = parsePublicKey(encodedKey);
1570 definedKeySets.put(currentKey, new HashSet<String>());
1571 sa.recycle();
1572 } else if (tagname.equals("keyset")) {
1573 final TypedArray sa = res.obtainAttributes(attrs,
1574 com.android.internal.R.styleable.KeySet);
1575 final String name = sa.getNonResourceString(
1576 com.android.internal.R.styleable.KeySet_name);
1577 definedKeySets.get(currentKey).add(name);
1578 sa.recycle();
1579 } else if (RIGID_PARSER) {
1580 Slog.w(TAG, "Bad element under <keys>: " + parser.getName()
1581 + " at " + mArchiveSourcePath + " "
1582 + parser.getPositionDescription());
1583 return false;
1584 } else {
1585 Slog.w(TAG, "Unknown element under <keys>: " + parser.getName()
1586 + " at " + mArchiveSourcePath + " "
1587 + parser.getPositionDescription());
1588 XmlUtils.skipCurrentTag(parser);
1589 continue;
1590 }
1591 }
1592
1593 owner.mKeySetMapping = new HashMap<String, Set<PublicKey>>();
1594 for (Map.Entry<PublicKey, Set<String>> e : definedKeySets.entrySet()) {
1595 PublicKey key = e.getKey();
1596 Set<String> keySetNames = e.getValue();
1597 for (String alias : keySetNames) {
1598 if (owner.mKeySetMapping.containsKey(alias)) {
1599 owner.mKeySetMapping.get(alias).add(key);
1600 } else {
1601 Set<PublicKey> keys = new HashSet<PublicKey>();
1602 keys.add(key);
1603 owner.mKeySetMapping.put(alias, keys);
1604 }
1605 }
1606 }
1607
1608 return true;
1609 }
1610
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001611 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 XmlPullParser parser, AttributeSet attrs, String[] outError)
1613 throws XmlPullParserException, IOException {
1614 PermissionGroup perm = new PermissionGroup(owner);
1615
1616 TypedArray sa = res.obtainAttributes(attrs,
1617 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1618
1619 if (!parsePackageItemInfo(owner, perm.info, outError,
1620 "<permission-group>", sa,
1621 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1622 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001623 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1624 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 sa.recycle();
1626 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1627 return null;
1628 }
1629
1630 perm.info.descriptionRes = sa.getResourceId(
1631 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1632 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001633 perm.info.flags = sa.getInt(
1634 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001635 perm.info.priority = sa.getInt(
1636 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001637 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001638 perm.info.priority = 0;
1639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640
1641 sa.recycle();
1642
1643 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1644 outError)) {
1645 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1646 return null;
1647 }
1648
1649 owner.permissionGroups.add(perm);
1650
1651 return perm;
1652 }
1653
1654 private Permission parsePermission(Package owner, Resources res,
1655 XmlPullParser parser, AttributeSet attrs, String[] outError)
1656 throws XmlPullParserException, IOException {
1657 Permission perm = new Permission(owner);
1658
1659 TypedArray sa = res.obtainAttributes(attrs,
1660 com.android.internal.R.styleable.AndroidManifestPermission);
1661
1662 if (!parsePackageItemInfo(owner, perm.info, outError,
1663 "<permission>", sa,
1664 com.android.internal.R.styleable.AndroidManifestPermission_name,
1665 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001666 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1667 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 sa.recycle();
1669 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1670 return null;
1671 }
1672
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001673 // Note: don't allow this value to be a reference to a resource
1674 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 perm.info.group = sa.getNonResourceString(
1676 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1677 if (perm.info.group != null) {
1678 perm.info.group = perm.info.group.intern();
1679 }
1680
1681 perm.info.descriptionRes = sa.getResourceId(
1682 com.android.internal.R.styleable.AndroidManifestPermission_description,
1683 0);
1684
1685 perm.info.protectionLevel = sa.getInt(
1686 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1687 PermissionInfo.PROTECTION_NORMAL);
1688
Dianne Hackborn2ca2c872012-09-16 16:03:36 -07001689 perm.info.flags = sa.getInt(
1690 com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);
1691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 if (perm.info.protectionLevel == -1) {
1695 outError[0] = "<permission> does not specify protectionLevel";
1696 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1697 return null;
1698 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001699
1700 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1701
1702 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1703 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1704 PermissionInfo.PROTECTION_SIGNATURE) {
1705 outError[0] = "<permission> protectionLevel specifies a flag but is "
1706 + "not based on signature type";
1707 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1708 return null;
1709 }
1710 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711
1712 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1713 outError)) {
1714 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1715 return null;
1716 }
1717
1718 owner.permissions.add(perm);
1719
1720 return perm;
1721 }
1722
1723 private Permission parsePermissionTree(Package owner, Resources res,
1724 XmlPullParser parser, AttributeSet attrs, String[] outError)
1725 throws XmlPullParserException, IOException {
1726 Permission perm = new Permission(owner);
1727
1728 TypedArray sa = res.obtainAttributes(attrs,
1729 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1730
1731 if (!parsePackageItemInfo(owner, perm.info, outError,
1732 "<permission-tree>", sa,
1733 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1734 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001735 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1736 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 sa.recycle();
1738 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1739 return null;
1740 }
1741
1742 sa.recycle();
1743
1744 int index = perm.info.name.indexOf('.');
1745 if (index > 0) {
1746 index = perm.info.name.indexOf('.', index+1);
1747 }
1748 if (index < 0) {
1749 outError[0] = "<permission-tree> name has less than three segments: "
1750 + perm.info.name;
1751 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1752 return null;
1753 }
1754
1755 perm.info.descriptionRes = 0;
1756 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1757 perm.tree = true;
1758
1759 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1760 outError)) {
1761 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1762 return null;
1763 }
1764
1765 owner.permissions.add(perm);
1766
1767 return perm;
1768 }
1769
1770 private Instrumentation parseInstrumentation(Package owner, Resources res,
1771 XmlPullParser parser, AttributeSet attrs, String[] outError)
1772 throws XmlPullParserException, IOException {
1773 TypedArray sa = res.obtainAttributes(attrs,
1774 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1775
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001776 if (mParseInstrumentationArgs == null) {
1777 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1778 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1779 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001780 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1781 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001782 mParseInstrumentationArgs.tag = "<instrumentation>";
1783 }
1784
1785 mParseInstrumentationArgs.sa = sa;
1786
1787 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1788 new InstrumentationInfo());
1789 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 sa.recycle();
1791 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1792 return null;
1793 }
1794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001796 // Note: don't allow this value to be a reference to a resource
1797 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 str = sa.getNonResourceString(
1799 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1800 a.info.targetPackage = str != null ? str.intern() : null;
1801
1802 a.info.handleProfiling = sa.getBoolean(
1803 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1804 false);
1805
1806 a.info.functionalTest = sa.getBoolean(
1807 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1808 false);
1809
1810 sa.recycle();
1811
1812 if (a.info.targetPackage == null) {
1813 outError[0] = "<instrumentation> does not specify targetPackage";
1814 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1815 return null;
1816 }
1817
1818 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1819 outError)) {
1820 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1821 return null;
1822 }
1823
1824 owner.instrumentation.add(a);
1825
1826 return a;
1827 }
1828
1829 private boolean parseApplication(Package owner, Resources res,
1830 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1831 throws XmlPullParserException, IOException {
1832 final ApplicationInfo ai = owner.applicationInfo;
1833 final String pkgName = owner.applicationInfo.packageName;
1834
1835 TypedArray sa = res.obtainAttributes(attrs,
1836 com.android.internal.R.styleable.AndroidManifestApplication);
1837
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001838 String name = sa.getNonConfigurationString(
1839 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 if (name != null) {
1841 ai.className = buildClassName(pkgName, name, outError);
1842 if (ai.className == null) {
1843 sa.recycle();
1844 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1845 return false;
1846 }
1847 }
1848
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001849 String manageSpaceActivity = sa.getNonConfigurationString(
1850 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 if (manageSpaceActivity != null) {
1852 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1853 outError);
1854 }
1855
Christopher Tate181fafa2009-05-14 11:12:14 -07001856 boolean allowBackup = sa.getBoolean(
1857 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1858 if (allowBackup) {
1859 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001860
Christopher Tate3de55bc2010-03-12 17:28:08 -08001861 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1862 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001863 String backupAgent = sa.getNonConfigurationString(
1864 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001865 if (backupAgent != null) {
1866 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001867 if (DEBUG_BACKUP) {
1868 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001869 + " from " + pkgName + "+" + backupAgent);
1870 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001871
1872 if (sa.getBoolean(
1873 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1874 true)) {
1875 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1876 }
1877 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001878 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1879 false)) {
1880 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1881 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001882 }
1883 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 TypedValue v = sa.peekValue(
1886 com.android.internal.R.styleable.AndroidManifestApplication_label);
1887 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1888 ai.nonLocalizedLabel = v.coerceToString();
1889 }
1890
1891 ai.icon = sa.getResourceId(
1892 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001893 ai.logo = sa.getResourceId(
1894 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001896 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 ai.descriptionRes = sa.getResourceId(
1898 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1899
1900 if ((flags&PARSE_IS_SYSTEM) != 0) {
1901 if (sa.getBoolean(
1902 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1903 false)) {
1904 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1905 }
Amith Yamasani0d8750d2013-05-01 15:25:28 -07001906 }
1907
1908 if (sa.getBoolean(
1909 com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers,
1910 false)) {
1911 owner.mRequiredForAllUsers = true;
Amith Yamasanie993ae12013-04-15 13:42:57 -07001912 }
1913
1914 String restrictedAccountType = sa.getString(com.android.internal.R.styleable
1915 .AndroidManifestApplication_restrictedAccountType);
1916 if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
1917 owner.mRestrictedAccountType = restrictedAccountType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 }
1919
Amith Yamasaniccbe3892013-04-12 17:52:42 -07001920 String requiredAccountType = sa.getString(com.android.internal.R.styleable
1921 .AndroidManifestApplication_requiredAccountType);
1922 if (requiredAccountType != null && requiredAccountType.length() > 0) {
1923 owner.mRequiredAccountType = requiredAccountType;
1924 }
1925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 if (sa.getBoolean(
1927 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1928 false)) {
1929 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1930 }
1931
1932 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001933 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001934 false)) {
1935 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1936 }
1937
Romain Guy529b60a2010-08-03 18:05:47 -07001938 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001939 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001940 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001941
1942 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1944 true)) {
1945 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1946 }
1947
1948 if (sa.getBoolean(
1949 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1950 false)) {
1951 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1952 }
1953
1954 if (sa.getBoolean(
1955 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1956 true)) {
1957 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1958 }
1959
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001960 if (sa.getBoolean(
1961 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001962 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001963 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1964 }
1965
Jason parksa3cdaa52011-01-13 14:15:43 -06001966 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001967 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001968 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001969 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001970 }
1971
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001972 if (sa.getBoolean(
1973 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1974 false /* default is no RTL support*/)) {
1975 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1976 }
1977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001979 str = sa.getNonConfigurationString(
1980 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1982
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001983 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1984 str = sa.getNonConfigurationString(
1985 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1986 } else {
1987 // Some older apps have been seen to use a resource reference
1988 // here that on older builds was ignored (with a warning). We
1989 // need to continue to do this for them so they don't break.
1990 str = sa.getNonResourceString(
1991 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1994 str, outError);
1995
1996 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001997 CharSequence pname;
1998 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1999 pname = sa.getNonConfigurationString(
2000 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
2001 } else {
2002 // Some older apps have been seen to use a resource reference
2003 // here that on older builds was ignored (with a warning). We
2004 // need to continue to do this for them so they don't break.
2005 pname = sa.getNonResourceString(
2006 com.android.internal.R.styleable.AndroidManifestApplication_process);
2007 }
2008 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 flags, mSeparateProcesses, outError);
2010
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002011 ai.enabled = sa.getBoolean(
2012 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07002013
Dianne Hackborn02486b12010-08-26 14:18:37 -07002014 if (false) {
2015 if (sa.getBoolean(
2016 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
2017 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002018 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07002019
2020 // A heavy-weight application can not be in a custom process.
2021 // We can do direct compare because we intern all strings.
2022 if (ai.processName != null && ai.processName != ai.packageName) {
2023 outError[0] = "cantSaveState applications can not use custom processes";
2024 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07002025 }
2026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 }
2028
Adam Powell269248d2011-08-02 10:26:54 -07002029 ai.uiOptions = sa.getInt(
2030 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
2031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 sa.recycle();
2033
2034 if (outError[0] != null) {
2035 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2036 return false;
2037 }
2038
2039 final int innerDepth = parser.getDepth();
2040
2041 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07002042 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
2043 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
2044 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 continue;
2046 }
2047
2048 String tagName = parser.getName();
2049 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002050 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
2051 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 if (a == null) {
2053 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2054 return false;
2055 }
2056
2057 owner.activities.add(a);
2058
2059 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07002060 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 if (a == null) {
2062 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2063 return false;
2064 }
2065
2066 owner.receivers.add(a);
2067
2068 } else if (tagName.equals("service")) {
2069 Service s = parseService(owner, res, parser, attrs, flags, outError);
2070 if (s == null) {
2071 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2072 return false;
2073 }
2074
2075 owner.services.add(s);
2076
2077 } else if (tagName.equals("provider")) {
2078 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
2079 if (p == null) {
2080 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2081 return false;
2082 }
2083
2084 owner.providers.add(p);
2085
2086 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002087 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 if (a == null) {
2089 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2090 return false;
2091 }
2092
2093 owner.activities.add(a);
2094
2095 } else if (parser.getName().equals("meta-data")) {
2096 // note: application meta-data is stored off to the side, so it can
2097 // remain null in the primary copy (we like to avoid extra copies because
2098 // it can be large)
2099 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
2100 outError)) == null) {
2101 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2102 return false;
2103 }
2104
Dianne Hackbornc895be72013-03-11 17:48:43 -07002105 } else if (tagName.equals("library")) {
2106 sa = res.obtainAttributes(attrs,
2107 com.android.internal.R.styleable.AndroidManifestLibrary);
2108
2109 // Note: don't allow this value to be a reference to a resource
2110 // that may change.
2111 String lname = sa.getNonResourceString(
2112 com.android.internal.R.styleable.AndroidManifestLibrary_name);
2113
2114 sa.recycle();
2115
2116 if (lname != null) {
2117 if (owner.libraryNames == null) {
2118 owner.libraryNames = new ArrayList<String>();
2119 }
2120 if (!owner.libraryNames.contains(lname)) {
2121 owner.libraryNames.add(lname.intern());
2122 }
2123 }
2124
2125 XmlUtils.skipCurrentTag(parser);
2126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 } else if (tagName.equals("uses-library")) {
2128 sa = res.obtainAttributes(attrs,
2129 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
2130
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002131 // Note: don't allow this value to be a reference to a resource
2132 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 String lname = sa.getNonResourceString(
2134 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07002135 boolean req = sa.getBoolean(
2136 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
2137 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138
2139 sa.recycle();
2140
Dianne Hackborn49237342009-08-27 20:08:01 -07002141 if (lname != null) {
2142 if (req) {
2143 if (owner.usesLibraries == null) {
2144 owner.usesLibraries = new ArrayList<String>();
2145 }
2146 if (!owner.usesLibraries.contains(lname)) {
2147 owner.usesLibraries.add(lname.intern());
2148 }
2149 } else {
2150 if (owner.usesOptionalLibraries == null) {
2151 owner.usesOptionalLibraries = new ArrayList<String>();
2152 }
2153 if (!owner.usesOptionalLibraries.contains(lname)) {
2154 owner.usesOptionalLibraries.add(lname.intern());
2155 }
2156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 }
2158
2159 XmlUtils.skipCurrentTag(parser);
2160
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002161 } else if (tagName.equals("uses-package")) {
2162 // Dependencies for app installers; we don't currently try to
2163 // enforce this.
2164 XmlUtils.skipCurrentTag(parser);
2165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 } else {
2167 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002168 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002169 + " at " + mArchiveSourcePath + " "
2170 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 XmlUtils.skipCurrentTag(parser);
2172 continue;
2173 } else {
2174 outError[0] = "Bad element under <application>: " + tagName;
2175 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
2176 return false;
2177 }
2178 }
2179 }
2180
2181 return true;
2182 }
2183
2184 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
2185 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002186 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002187 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 if (name == null) {
2189 outError[0] = tag + " does not specify android:name";
2190 return false;
2191 }
2192
2193 outInfo.name
2194 = buildClassName(owner.applicationInfo.packageName, name, outError);
2195 if (outInfo.name == null) {
2196 return false;
2197 }
2198
2199 int iconVal = sa.getResourceId(iconRes, 0);
2200 if (iconVal != 0) {
2201 outInfo.icon = iconVal;
2202 outInfo.nonLocalizedLabel = null;
2203 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002204
2205 int logoVal = sa.getResourceId(logoRes, 0);
2206 if (logoVal != 0) {
2207 outInfo.logo = logoVal;
2208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209
2210 TypedValue v = sa.peekValue(labelRes);
2211 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2212 outInfo.nonLocalizedLabel = v.coerceToString();
2213 }
2214
2215 outInfo.packageName = owner.packageName;
2216
2217 return true;
2218 }
2219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 private Activity parseActivity(Package owner, Resources res,
2221 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002222 boolean receiver, boolean hardwareAccelerated)
2223 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002224 TypedArray sa = res.obtainAttributes(attrs,
2225 com.android.internal.R.styleable.AndroidManifestActivity);
2226
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002227 if (mParseActivityArgs == null) {
2228 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2229 com.android.internal.R.styleable.AndroidManifestActivity_name,
2230 com.android.internal.R.styleable.AndroidManifestActivity_label,
2231 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002232 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002233 mSeparateProcesses,
2234 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002235 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002236 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2237 }
2238
2239 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2240 mParseActivityArgs.sa = sa;
2241 mParseActivityArgs.flags = flags;
2242
2243 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2244 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 sa.recycle();
2246 return null;
2247 }
2248
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002249 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2251 if (setExported) {
2252 a.info.exported = sa.getBoolean(
2253 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2254 }
2255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 a.info.theme = sa.getResourceId(
2257 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2258
Adam Powell269248d2011-08-02 10:26:54 -07002259 a.info.uiOptions = sa.getInt(
2260 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2261 a.info.applicationInfo.uiOptions);
2262
Adam Powelldd8fab22012-03-22 17:47:27 -07002263 String parentName = sa.getNonConfigurationString(
2264 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2265 if (parentName != null) {
2266 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2267 if (outError[0] == null) {
2268 a.info.parentActivityName = parentClassName;
2269 } else {
2270 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2271 parentName);
2272 outError[0] = null;
2273 }
2274 }
2275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002277 str = sa.getNonConfigurationString(
2278 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 if (str == null) {
2280 a.info.permission = owner.applicationInfo.permission;
2281 } else {
2282 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2283 }
2284
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002285 str = sa.getNonConfigurationString(
2286 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2288 owner.applicationInfo.taskAffinity, str, outError);
2289
2290 a.info.flags = 0;
2291 if (sa.getBoolean(
2292 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2293 false)) {
2294 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2295 }
2296
2297 if (sa.getBoolean(
2298 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2299 false)) {
2300 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2301 }
2302
2303 if (sa.getBoolean(
2304 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2305 false)) {
2306 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2307 }
2308
2309 if (sa.getBoolean(
2310 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2311 false)) {
2312 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2313 }
2314
2315 if (sa.getBoolean(
2316 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2317 false)) {
2318 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2319 }
2320
2321 if (sa.getBoolean(
2322 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2323 false)) {
2324 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2325 }
2326
2327 if (sa.getBoolean(
2328 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2329 false)) {
2330 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2331 }
2332
2333 if (sa.getBoolean(
2334 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2335 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2336 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2337 }
2338
Dianne Hackbornffa42482009-09-23 22:20:11 -07002339 if (sa.getBoolean(
2340 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2341 false)) {
2342 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2343 }
2344
Daniel Sandler613dde42010-06-21 13:46:39 -04002345 if (sa.getBoolean(
Craig Mautner5962b122012-10-05 14:45:52 -07002346 com.android.internal.R.styleable.AndroidManifestActivity_showOnLockScreen,
2347 false)) {
2348 a.info.flags |= ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN;
2349 }
2350
2351 if (sa.getBoolean(
Daniel Sandler613dde42010-06-21 13:46:39 -04002352 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2353 false)) {
2354 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2355 }
Craig Mautner5962b122012-10-05 14:45:52 -07002356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002358 if (sa.getBoolean(
2359 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2360 hardwareAccelerated)) {
2361 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2362 }
2363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 a.info.launchMode = sa.getInt(
2365 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2366 ActivityInfo.LAUNCH_MULTIPLE);
2367 a.info.screenOrientation = sa.getInt(
2368 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2369 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2370 a.info.configChanges = sa.getInt(
2371 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2372 0);
2373 a.info.softInputMode = sa.getInt(
2374 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2375 0);
2376 } else {
2377 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2378 a.info.configChanges = 0;
2379 }
2380
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002381 if (receiver) {
2382 if (sa.getBoolean(
2383 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2384 false)) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002385 a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002386 if (a.info.exported) {
2387 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2388 + a.className + " at " + mArchiveSourcePath + " "
2389 + parser.getPositionDescription());
2390 a.info.exported = false;
2391 }
2392 setExported = true;
2393 }
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -07002394 if (sa.getBoolean(
2395 com.android.internal.R.styleable.AndroidManifestActivity_primaryUserOnly,
2396 false)) {
2397 a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
2398 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002399 }
2400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 sa.recycle();
2402
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002403 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002404 // A heavy-weight application can not have receives in its main process
2405 // We can do direct compare because we intern all strings.
2406 if (a.info.processName == owner.packageName) {
2407 outError[0] = "Heavy-weight applications can not have receivers in main process";
2408 }
2409 }
2410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 if (outError[0] != null) {
2412 return null;
2413 }
2414
2415 int outerDepth = parser.getDepth();
2416 int type;
2417 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2418 && (type != XmlPullParser.END_TAG
2419 || parser.getDepth() > outerDepth)) {
2420 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2421 continue;
2422 }
2423
2424 if (parser.getName().equals("intent-filter")) {
2425 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2426 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2427 return null;
2428 }
2429 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002430 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002431 + mArchiveSourcePath + " "
2432 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 } else {
2434 a.intents.add(intent);
2435 }
2436 } else if (parser.getName().equals("meta-data")) {
2437 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2438 outError)) == null) {
2439 return null;
2440 }
2441 } else {
2442 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002443 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002445 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002446 + " at " + mArchiveSourcePath + " "
2447 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002449 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002450 + " at " + mArchiveSourcePath + " "
2451 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 }
2453 XmlUtils.skipCurrentTag(parser);
2454 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002456 if (receiver) {
2457 outError[0] = "Bad element under <receiver>: " + parser.getName();
2458 } else {
2459 outError[0] = "Bad element under <activity>: " + parser.getName();
2460 }
2461 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 }
2464 }
2465
2466 if (!setExported) {
2467 a.info.exported = a.intents.size() > 0;
2468 }
2469
2470 return a;
2471 }
2472
2473 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002474 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2475 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 TypedArray sa = res.obtainAttributes(attrs,
2477 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2478
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002479 String targetActivity = sa.getNonConfigurationString(
2480 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 if (targetActivity == null) {
2482 outError[0] = "<activity-alias> does not specify android:targetActivity";
2483 sa.recycle();
2484 return null;
2485 }
2486
2487 targetActivity = buildClassName(owner.applicationInfo.packageName,
2488 targetActivity, outError);
2489 if (targetActivity == null) {
2490 sa.recycle();
2491 return null;
2492 }
2493
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002494 if (mParseActivityAliasArgs == null) {
2495 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2496 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2497 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2498 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002499 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002500 mSeparateProcesses,
2501 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002502 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002503 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2504 mParseActivityAliasArgs.tag = "<activity-alias>";
2505 }
2506
2507 mParseActivityAliasArgs.sa = sa;
2508 mParseActivityAliasArgs.flags = flags;
2509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 Activity target = null;
2511
2512 final int NA = owner.activities.size();
2513 for (int i=0; i<NA; i++) {
2514 Activity t = owner.activities.get(i);
2515 if (targetActivity.equals(t.info.name)) {
2516 target = t;
2517 break;
2518 }
2519 }
2520
2521 if (target == null) {
2522 outError[0] = "<activity-alias> target activity " + targetActivity
2523 + " not found in manifest";
2524 sa.recycle();
2525 return null;
2526 }
2527
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002528 ActivityInfo info = new ActivityInfo();
2529 info.targetActivity = targetActivity;
2530 info.configChanges = target.info.configChanges;
2531 info.flags = target.info.flags;
2532 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002533 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002534 info.labelRes = target.info.labelRes;
2535 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2536 info.launchMode = target.info.launchMode;
2537 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002538 if (info.descriptionRes == 0) {
2539 info.descriptionRes = target.info.descriptionRes;
2540 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002541 info.screenOrientation = target.info.screenOrientation;
2542 info.taskAffinity = target.info.taskAffinity;
2543 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002544 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002545 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002546 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002547
2548 Activity a = new Activity(mParseActivityAliasArgs, info);
2549 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 sa.recycle();
2551 return null;
2552 }
2553
2554 final boolean setExported = sa.hasValue(
2555 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2556 if (setExported) {
2557 a.info.exported = sa.getBoolean(
2558 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2559 }
2560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002562 str = sa.getNonConfigurationString(
2563 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 if (str != null) {
2565 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2566 }
2567
Adam Powelldd8fab22012-03-22 17:47:27 -07002568 String parentName = sa.getNonConfigurationString(
2569 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2570 0);
2571 if (parentName != null) {
2572 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2573 if (outError[0] == null) {
2574 a.info.parentActivityName = parentClassName;
2575 } else {
2576 Log.e(TAG, "Activity alias " + a.info.name +
2577 " specified invalid parentActivityName " + parentName);
2578 outError[0] = null;
2579 }
2580 }
2581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 sa.recycle();
2583
2584 if (outError[0] != null) {
2585 return null;
2586 }
2587
2588 int outerDepth = parser.getDepth();
2589 int type;
2590 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2591 && (type != XmlPullParser.END_TAG
2592 || parser.getDepth() > outerDepth)) {
2593 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2594 continue;
2595 }
2596
2597 if (parser.getName().equals("intent-filter")) {
2598 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2599 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2600 return null;
2601 }
2602 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002603 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002604 + mArchiveSourcePath + " "
2605 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 } else {
2607 a.intents.add(intent);
2608 }
2609 } else if (parser.getName().equals("meta-data")) {
2610 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2611 outError)) == null) {
2612 return null;
2613 }
2614 } else {
2615 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002616 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002617 + " at " + mArchiveSourcePath + " "
2618 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 XmlUtils.skipCurrentTag(parser);
2620 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002621 } else {
2622 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2623 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 }
2626 }
2627
2628 if (!setExported) {
2629 a.info.exported = a.intents.size() > 0;
2630 }
2631
2632 return a;
2633 }
2634
2635 private Provider parseProvider(Package owner, Resources res,
2636 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2637 throws XmlPullParserException, IOException {
2638 TypedArray sa = res.obtainAttributes(attrs,
2639 com.android.internal.R.styleable.AndroidManifestProvider);
2640
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002641 if (mParseProviderArgs == null) {
2642 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2643 com.android.internal.R.styleable.AndroidManifestProvider_name,
2644 com.android.internal.R.styleable.AndroidManifestProvider_label,
2645 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002646 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002647 mSeparateProcesses,
2648 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002649 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002650 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2651 mParseProviderArgs.tag = "<provider>";
2652 }
2653
2654 mParseProviderArgs.sa = sa;
2655 mParseProviderArgs.flags = flags;
2656
2657 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2658 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 sa.recycle();
2660 return null;
2661 }
2662
Nick Kralevichf097b162012-07-28 12:43:48 -07002663 boolean providerExportedDefault = false;
2664
2665 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2666 // For compatibility, applications targeting API level 16 or lower
2667 // should have their content providers exported by default, unless they
2668 // specify otherwise.
2669 providerExportedDefault = true;
2670 }
2671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002673 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2674 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002676 String cpname = sa.getNonConfigurationString(
2677 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678
2679 p.info.isSyncable = sa.getBoolean(
2680 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2681 false);
2682
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002683 String permission = sa.getNonConfigurationString(
2684 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2685 String str = sa.getNonConfigurationString(
2686 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 if (str == null) {
2688 str = permission;
2689 }
2690 if (str == null) {
2691 p.info.readPermission = owner.applicationInfo.permission;
2692 } else {
2693 p.info.readPermission =
2694 str.length() > 0 ? str.toString().intern() : null;
2695 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002696 str = sa.getNonConfigurationString(
2697 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 if (str == null) {
2699 str = permission;
2700 }
2701 if (str == null) {
2702 p.info.writePermission = owner.applicationInfo.permission;
2703 } else {
2704 p.info.writePermission =
2705 str.length() > 0 ? str.toString().intern() : null;
2706 }
2707
2708 p.info.grantUriPermissions = sa.getBoolean(
2709 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2710 false);
2711
2712 p.info.multiprocess = sa.getBoolean(
2713 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2714 false);
2715
2716 p.info.initOrder = sa.getInt(
2717 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2718 0);
2719
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002720 p.info.flags = 0;
2721
2722 if (sa.getBoolean(
2723 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2724 false)) {
2725 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2726 if (p.info.exported) {
2727 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2728 + p.className + " at " + mArchiveSourcePath + " "
2729 + parser.getPositionDescription());
2730 p.info.exported = false;
2731 }
2732 }
2733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 sa.recycle();
2735
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002736 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002737 // A heavy-weight application can not have providers in its main process
2738 // We can do direct compare because we intern all strings.
2739 if (p.info.processName == owner.packageName) {
2740 outError[0] = "Heavy-weight applications can not have providers in main process";
2741 return null;
2742 }
2743 }
2744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002746 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 return null;
2748 }
2749 p.info.authority = cpname.intern();
2750
2751 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2752 return null;
2753 }
2754
2755 return p;
2756 }
2757
2758 private boolean parseProviderTags(Resources res,
2759 XmlPullParser parser, AttributeSet attrs,
2760 Provider outInfo, String[] outError)
2761 throws XmlPullParserException, IOException {
2762 int outerDepth = parser.getDepth();
2763 int type;
2764 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2765 && (type != XmlPullParser.END_TAG
2766 || parser.getDepth() > outerDepth)) {
2767 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2768 continue;
2769 }
2770
2771 if (parser.getName().equals("meta-data")) {
2772 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2773 outInfo.metaData, outError)) == null) {
2774 return false;
2775 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 } else if (parser.getName().equals("grant-uri-permission")) {
2778 TypedArray sa = res.obtainAttributes(attrs,
2779 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2780
2781 PatternMatcher pa = null;
2782
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002783 String str = sa.getNonConfigurationString(
2784 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 if (str != null) {
2786 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2787 }
2788
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002789 str = sa.getNonConfigurationString(
2790 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 if (str != null) {
2792 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2793 }
2794
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002795 str = sa.getNonConfigurationString(
2796 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 if (str != null) {
2798 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2799 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 sa.recycle();
2802
2803 if (pa != null) {
2804 if (outInfo.info.uriPermissionPatterns == null) {
2805 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2806 outInfo.info.uriPermissionPatterns[0] = pa;
2807 } else {
2808 final int N = outInfo.info.uriPermissionPatterns.length;
2809 PatternMatcher[] newp = new PatternMatcher[N+1];
2810 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2811 newp[N] = pa;
2812 outInfo.info.uriPermissionPatterns = newp;
2813 }
2814 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002815 } else {
2816 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002817 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002818 + parser.getName() + " at " + mArchiveSourcePath + " "
2819 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002820 XmlUtils.skipCurrentTag(parser);
2821 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002822 } else {
2823 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2824 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002825 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002826 }
2827 XmlUtils.skipCurrentTag(parser);
2828
2829 } else if (parser.getName().equals("path-permission")) {
2830 TypedArray sa = res.obtainAttributes(attrs,
2831 com.android.internal.R.styleable.AndroidManifestPathPermission);
2832
2833 PathPermission pa = null;
2834
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002835 String permission = sa.getNonConfigurationString(
2836 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2837 String readPermission = sa.getNonConfigurationString(
2838 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002839 if (readPermission == null) {
2840 readPermission = permission;
2841 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002842 String writePermission = sa.getNonConfigurationString(
2843 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002844 if (writePermission == null) {
2845 writePermission = permission;
2846 }
2847
2848 boolean havePerm = false;
2849 if (readPermission != null) {
2850 readPermission = readPermission.intern();
2851 havePerm = true;
2852 }
2853 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002854 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002855 havePerm = true;
2856 }
2857
2858 if (!havePerm) {
2859 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002860 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002861 + parser.getName() + " at " + mArchiveSourcePath + " "
2862 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002863 XmlUtils.skipCurrentTag(parser);
2864 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002865 } else {
2866 outError[0] = "No readPermission or writePermssion for <path-permission>";
2867 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002868 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002869 }
2870
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002871 String path = sa.getNonConfigurationString(
2872 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002873 if (path != null) {
2874 pa = new PathPermission(path,
2875 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2876 }
2877
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002878 path = sa.getNonConfigurationString(
2879 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002880 if (path != null) {
2881 pa = new PathPermission(path,
2882 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2883 }
2884
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002885 path = sa.getNonConfigurationString(
2886 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002887 if (path != null) {
2888 pa = new PathPermission(path,
2889 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2890 }
2891
2892 sa.recycle();
2893
2894 if (pa != null) {
2895 if (outInfo.info.pathPermissions == null) {
2896 outInfo.info.pathPermissions = new PathPermission[1];
2897 outInfo.info.pathPermissions[0] = pa;
2898 } else {
2899 final int N = outInfo.info.pathPermissions.length;
2900 PathPermission[] newp = new PathPermission[N+1];
2901 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2902 newp[N] = pa;
2903 outInfo.info.pathPermissions = newp;
2904 }
2905 } else {
2906 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002907 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002908 + parser.getName() + " at " + mArchiveSourcePath + " "
2909 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002910 XmlUtils.skipCurrentTag(parser);
2911 continue;
2912 }
2913 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2914 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 }
2916 XmlUtils.skipCurrentTag(parser);
2917
2918 } else {
2919 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002920 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002921 + parser.getName() + " at " + mArchiveSourcePath + " "
2922 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 XmlUtils.skipCurrentTag(parser);
2924 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002925 } else {
2926 outError[0] = "Bad element under <provider>: " + parser.getName();
2927 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 }
2930 }
2931 return true;
2932 }
2933
2934 private Service parseService(Package owner, Resources res,
2935 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2936 throws XmlPullParserException, IOException {
2937 TypedArray sa = res.obtainAttributes(attrs,
2938 com.android.internal.R.styleable.AndroidManifestService);
2939
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002940 if (mParseServiceArgs == null) {
2941 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2942 com.android.internal.R.styleable.AndroidManifestService_name,
2943 com.android.internal.R.styleable.AndroidManifestService_label,
2944 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002945 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002946 mSeparateProcesses,
2947 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002948 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002949 com.android.internal.R.styleable.AndroidManifestService_enabled);
2950 mParseServiceArgs.tag = "<service>";
2951 }
2952
2953 mParseServiceArgs.sa = sa;
2954 mParseServiceArgs.flags = flags;
2955
2956 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2957 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 sa.recycle();
2959 return null;
2960 }
2961
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002962 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 com.android.internal.R.styleable.AndroidManifestService_exported);
2964 if (setExported) {
2965 s.info.exported = sa.getBoolean(
2966 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2967 }
2968
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002969 String str = sa.getNonConfigurationString(
2970 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 if (str == null) {
2972 s.info.permission = owner.applicationInfo.permission;
2973 } else {
2974 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2975 }
2976
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002977 s.info.flags = 0;
2978 if (sa.getBoolean(
2979 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2980 false)) {
2981 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2982 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002983 if (sa.getBoolean(
2984 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2985 false)) {
2986 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2987 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002988 if (sa.getBoolean(
2989 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2990 false)) {
2991 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2992 if (s.info.exported) {
2993 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2994 + s.className + " at " + mArchiveSourcePath + " "
2995 + parser.getPositionDescription());
2996 s.info.exported = false;
2997 }
2998 setExported = true;
2999 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 sa.recycle();
3002
Dianne Hackborn54e570f2010-10-04 18:32:32 -07003003 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07003004 // A heavy-weight application can not have services in its main process
3005 // We can do direct compare because we intern all strings.
3006 if (s.info.processName == owner.packageName) {
3007 outError[0] = "Heavy-weight applications can not have services in main process";
3008 return null;
3009 }
3010 }
3011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 int outerDepth = parser.getDepth();
3013 int type;
3014 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3015 && (type != XmlPullParser.END_TAG
3016 || parser.getDepth() > outerDepth)) {
3017 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3018 continue;
3019 }
3020
3021 if (parser.getName().equals("intent-filter")) {
3022 ServiceIntentInfo intent = new ServiceIntentInfo(s);
3023 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
3024 return null;
3025 }
3026
3027 s.intents.add(intent);
3028 } else if (parser.getName().equals("meta-data")) {
3029 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
3030 outError)) == null) {
3031 return null;
3032 }
3033 } else {
3034 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003035 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003036 + parser.getName() + " at " + mArchiveSourcePath + " "
3037 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 XmlUtils.skipCurrentTag(parser);
3039 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003040 } else {
3041 outError[0] = "Bad element under <service>: " + parser.getName();
3042 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 }
3045 }
3046
3047 if (!setExported) {
3048 s.info.exported = s.intents.size() > 0;
3049 }
3050
3051 return s;
3052 }
3053
3054 private boolean parseAllMetaData(Resources res,
3055 XmlPullParser parser, AttributeSet attrs, String tag,
3056 Component outInfo, String[] outError)
3057 throws XmlPullParserException, IOException {
3058 int outerDepth = parser.getDepth();
3059 int type;
3060 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
3061 && (type != XmlPullParser.END_TAG
3062 || parser.getDepth() > outerDepth)) {
3063 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
3064 continue;
3065 }
3066
3067 if (parser.getName().equals("meta-data")) {
3068 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
3069 outInfo.metaData, outError)) == null) {
3070 return false;
3071 }
3072 } else {
3073 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003074 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003075 + parser.getName() + " at " + mArchiveSourcePath + " "
3076 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 XmlUtils.skipCurrentTag(parser);
3078 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07003079 } else {
3080 outError[0] = "Bad element under " + tag + ": " + parser.getName();
3081 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 }
3084 }
3085 return true;
3086 }
3087
3088 private Bundle parseMetaData(Resources res,
3089 XmlPullParser parser, AttributeSet attrs,
3090 Bundle data, String[] outError)
3091 throws XmlPullParserException, IOException {
3092
3093 TypedArray sa = res.obtainAttributes(attrs,
3094 com.android.internal.R.styleable.AndroidManifestMetaData);
3095
3096 if (data == null) {
3097 data = new Bundle();
3098 }
3099
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003100 String name = sa.getNonConfigurationString(
3101 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003102 if (name == null) {
3103 outError[0] = "<meta-data> requires an android:name attribute";
3104 sa.recycle();
3105 return null;
3106 }
3107
Dianne Hackborn854060a2009-07-09 18:14:31 -07003108 name = name.intern();
3109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 TypedValue v = sa.peekValue(
3111 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
3112 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003113 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 data.putInt(name, v.resourceId);
3115 } else {
3116 v = sa.peekValue(
3117 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07003118 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 if (v != null) {
3120 if (v.type == TypedValue.TYPE_STRING) {
3121 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07003122 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
3124 data.putBoolean(name, v.data != 0);
3125 } else if (v.type >= TypedValue.TYPE_FIRST_INT
3126 && v.type <= TypedValue.TYPE_LAST_INT) {
3127 data.putInt(name, v.data);
3128 } else if (v.type == TypedValue.TYPE_FLOAT) {
3129 data.putFloat(name, v.getFloat());
3130 } else {
3131 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003132 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003133 + parser.getName() + " at " + mArchiveSourcePath + " "
3134 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 } else {
3136 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
3137 data = null;
3138 }
3139 }
3140 } else {
3141 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
3142 data = null;
3143 }
3144 }
3145
3146 sa.recycle();
3147
3148 XmlUtils.skipCurrentTag(parser);
3149
3150 return data;
3151 }
3152
Kenny Root05ca4c92011-09-15 10:36:25 -07003153 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
3154 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
3155 IOException {
3156 final TypedArray sa = res.obtainAttributes(attrs,
3157 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
3158
3159 final String packageName = sa.getNonResourceString(
3160 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
3161
3162 final String encodedPublicKey = sa.getNonResourceString(
3163 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
3164
3165 sa.recycle();
3166
3167 if (packageName == null || packageName.length() == 0) {
3168 Slog.i(TAG, "verifier package name was null; skipping");
3169 return null;
3170 } else if (encodedPublicKey == null) {
3171 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
3172 }
3173
Geremy Condraf1bcca82013-01-07 22:35:24 -08003174 PublicKey publicKey = parsePublicKey(encodedPublicKey);
3175 if (publicKey != null) {
3176 return new VerifierInfo(packageName, publicKey);
3177 }
3178
3179 return null;
3180 }
3181
3182 public static final PublicKey parsePublicKey(String encodedPublicKey) {
Kenny Root05ca4c92011-09-15 10:36:25 -07003183 EncodedKeySpec keySpec;
3184 try {
3185 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
3186 keySpec = new X509EncodedKeySpec(encoded);
3187 } catch (IllegalArgumentException e) {
Geremy Condraf1bcca82013-01-07 22:35:24 -08003188 Slog.i(TAG, "Could not parse verifier public key; invalid Base64");
Kenny Root05ca4c92011-09-15 10:36:25 -07003189 return null;
3190 }
3191
3192 /* First try the key as an RSA key. */
3193 try {
3194 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003195 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003196 } catch (NoSuchAlgorithmException e) {
3197 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
3198 return null;
3199 } catch (InvalidKeySpecException e) {
3200 // Not a RSA public key.
3201 }
3202
3203 /* Now try it as a DSA key. */
3204 try {
3205 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
Geremy Condraf1bcca82013-01-07 22:35:24 -08003206 return keyFactory.generatePublic(keySpec);
Kenny Root05ca4c92011-09-15 10:36:25 -07003207 } catch (NoSuchAlgorithmException e) {
3208 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3209 return null;
3210 } catch (InvalidKeySpecException e) {
3211 // Not a DSA public key.
3212 }
3213
3214 return null;
3215 }
3216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 private static final String ANDROID_RESOURCES
3218 = "http://schemas.android.com/apk/res/android";
3219
3220 private boolean parseIntent(Resources res,
3221 XmlPullParser parser, AttributeSet attrs, int flags,
3222 IntentInfo outInfo, String[] outError, boolean isActivity)
3223 throws XmlPullParserException, IOException {
3224
3225 TypedArray sa = res.obtainAttributes(attrs,
3226 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3227
3228 int priority = sa.getInt(
3229 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 TypedValue v = sa.peekValue(
3233 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3234 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3235 outInfo.nonLocalizedLabel = v.coerceToString();
3236 }
3237
3238 outInfo.icon = sa.getResourceId(
3239 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003240
3241 outInfo.logo = sa.getResourceId(
3242 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243
3244 sa.recycle();
3245
3246 int outerDepth = parser.getDepth();
3247 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003248 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3249 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3250 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 continue;
3252 }
3253
3254 String nodeName = parser.getName();
3255 if (nodeName.equals("action")) {
3256 String value = attrs.getAttributeValue(
3257 ANDROID_RESOURCES, "name");
3258 if (value == null || value == "") {
3259 outError[0] = "No value supplied for <android:name>";
3260 return false;
3261 }
3262 XmlUtils.skipCurrentTag(parser);
3263
3264 outInfo.addAction(value);
3265 } else if (nodeName.equals("category")) {
3266 String value = attrs.getAttributeValue(
3267 ANDROID_RESOURCES, "name");
3268 if (value == null || value == "") {
3269 outError[0] = "No value supplied for <android:name>";
3270 return false;
3271 }
3272 XmlUtils.skipCurrentTag(parser);
3273
3274 outInfo.addCategory(value);
3275
3276 } else if (nodeName.equals("data")) {
3277 sa = res.obtainAttributes(attrs,
3278 com.android.internal.R.styleable.AndroidManifestData);
3279
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003280 String str = sa.getNonConfigurationString(
3281 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 if (str != null) {
3283 try {
3284 outInfo.addDataType(str);
3285 } catch (IntentFilter.MalformedMimeTypeException e) {
3286 outError[0] = e.toString();
3287 sa.recycle();
3288 return false;
3289 }
3290 }
3291
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003292 str = sa.getNonConfigurationString(
3293 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 if (str != null) {
3295 outInfo.addDataScheme(str);
3296 }
3297
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07003298 str = sa.getNonConfigurationString(
3299 com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
3300 if (str != null) {
3301 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
3302 }
3303
3304 str = sa.getNonConfigurationString(
3305 com.android.internal.R.styleable.AndroidManifestData_sspPrefix, 0);
3306 if (str != null) {
3307 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
3308 }
3309
3310 str = sa.getNonConfigurationString(
3311 com.android.internal.R.styleable.AndroidManifestData_sspPattern, 0);
3312 if (str != null) {
3313 outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3314 }
3315
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003316 String host = sa.getNonConfigurationString(
3317 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3318 String port = sa.getNonConfigurationString(
3319 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 if (host != null) {
3321 outInfo.addDataAuthority(host, port);
3322 }
3323
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003324 str = sa.getNonConfigurationString(
3325 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 if (str != null) {
3327 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3328 }
3329
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003330 str = sa.getNonConfigurationString(
3331 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 if (str != null) {
3333 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3334 }
3335
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003336 str = sa.getNonConfigurationString(
3337 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 if (str != null) {
3339 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3340 }
3341
3342 sa.recycle();
3343 XmlUtils.skipCurrentTag(parser);
3344 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003345 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003346 + parser.getName() + " at " + mArchiveSourcePath + " "
3347 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 XmlUtils.skipCurrentTag(parser);
3349 } else {
3350 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3351 return false;
3352 }
3353 }
3354
3355 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003356
3357 if (DEBUG_PARSER) {
3358 final StringBuilder cats = new StringBuilder("Intent d=");
3359 cats.append(outInfo.hasDefault);
3360 cats.append(", cat=");
3361
3362 final Iterator<String> it = outInfo.categoriesIterator();
3363 if (it != null) {
3364 while (it.hasNext()) {
3365 cats.append(' ');
3366 cats.append(it.next());
3367 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003369 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 }
3371
3372 return true;
3373 }
3374
3375 public final static class Package {
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003376
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003377 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378
3379 // For now we only support one application per package.
3380 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3381
3382 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3383 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3384 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3385 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3386 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3387 public final ArrayList<Service> services = new ArrayList<Service>(0);
3388 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3389
3390 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003391 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392
Dianne Hackborn854060a2009-07-09 18:14:31 -07003393 public ArrayList<String> protectedBroadcasts;
Dianne Hackbornc895be72013-03-11 17:48:43 -07003394
3395 public ArrayList<String> libraryNames = null;
Dianne Hackborn49237342009-08-27 20:08:01 -07003396 public ArrayList<String> usesLibraries = null;
3397 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 public String[] usesLibraryFiles = null;
3399
Dianne Hackbornc1552392010-03-03 16:19:01 -08003400 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003401 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003402 public ArrayList<String> mAdoptPermissions = null;
3403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 // We store the application meta-data independently to avoid multiple unwanted references
3405 public Bundle mAppMetaData = null;
3406
3407 // If this is a 3rd party app, this is the path of the zip file.
3408 public String mPath;
3409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 // The version code declared for this package.
3411 public int mVersionCode;
3412
3413 // The version name declared for this package.
3414 public String mVersionName;
3415
3416 // The shared user id that this package wants to use.
3417 public String mSharedUserId;
3418
3419 // The shared user label that this package wants to use.
3420 public int mSharedUserLabel;
3421
3422 // Signatures that were read from the package.
3423 public Signature mSignatures[];
3424
3425 // For use by package manager service for quick lookup of
3426 // preferred up order.
3427 public int mPreferredOrder = 0;
3428
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003429 // For use by the package manager to keep track of the path to the
3430 // file an app came from.
3431 public String mScanPath;
3432
3433 // For use by package manager to keep track of where it has done dexopt.
3434 public boolean mDidDexOpt;
3435
Amith Yamasani13593602012-03-22 16:16:17 -07003436 // // User set enabled state.
3437 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3438 //
3439 // // Whether the package has been stopped.
3440 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 // Additional data supplied by callers.
3443 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003444
3445 // Whether an operation is currently pending on this package
3446 public boolean mOperationPending;
3447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 /*
3449 * Applications hardware preferences
3450 */
3451 public final ArrayList<ConfigurationInfo> configPreferences =
3452 new ArrayList<ConfigurationInfo>();
3453
Dianne Hackborn49237342009-08-27 20:08:01 -07003454 /*
3455 * Applications requested features
3456 */
3457 public ArrayList<FeatureInfo> reqFeatures = null;
3458
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003459 public int installLocation;
3460
Amith Yamasanidf2e92a2013-03-01 17:04:38 -08003461 /* An app that's required for all users and cannot be uninstalled for a user */
3462 public boolean mRequiredForAllUsers;
3463
Amith Yamasani0ac1fc92013-03-27 18:56:08 -07003464 /* The restricted account authenticator type that is used by this application */
3465 public String mRestrictedAccountType;
3466
Amith Yamasaniccbe3892013-04-12 17:52:42 -07003467 /* The required account type without which this application will not function */
3468 public String mRequiredAccountType;
3469
Kenny Rootbcc954d2011-08-08 16:19:08 -07003470 /**
3471 * Digest suitable for comparing whether this package's manifest is the
3472 * same as another.
3473 */
3474 public ManifestDigest manifestDigest;
3475
Geremy Condraf1bcca82013-01-07 22:35:24 -08003476 /**
3477 * Data used to feed the KeySetManager
3478 */
3479 public Set<PublicKey> mSigningKeys;
3480 public Map<String, Set<PublicKey>> mKeySetMapping;
3481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 public Package(String _name) {
3483 packageName = _name;
3484 applicationInfo.packageName = _name;
3485 applicationInfo.uid = -1;
3486 }
3487
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003488 public void setPackageName(String newName) {
3489 packageName = newName;
3490 applicationInfo.packageName = newName;
3491 for (int i=permissions.size()-1; i>=0; i--) {
3492 permissions.get(i).setPackageName(newName);
3493 }
3494 for (int i=permissionGroups.size()-1; i>=0; i--) {
3495 permissionGroups.get(i).setPackageName(newName);
3496 }
3497 for (int i=activities.size()-1; i>=0; i--) {
3498 activities.get(i).setPackageName(newName);
3499 }
3500 for (int i=receivers.size()-1; i>=0; i--) {
3501 receivers.get(i).setPackageName(newName);
3502 }
3503 for (int i=providers.size()-1; i>=0; i--) {
3504 providers.get(i).setPackageName(newName);
3505 }
3506 for (int i=services.size()-1; i>=0; i--) {
3507 services.get(i).setPackageName(newName);
3508 }
3509 for (int i=instrumentation.size()-1; i>=0; i--) {
3510 instrumentation.get(i).setPackageName(newName);
3511 }
3512 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003513
3514 public boolean hasComponentClassName(String name) {
3515 for (int i=activities.size()-1; i>=0; i--) {
3516 if (name.equals(activities.get(i).className)) {
3517 return true;
3518 }
3519 }
3520 for (int i=receivers.size()-1; i>=0; i--) {
3521 if (name.equals(receivers.get(i).className)) {
3522 return true;
3523 }
3524 }
3525 for (int i=providers.size()-1; i>=0; i--) {
3526 if (name.equals(providers.get(i).className)) {
3527 return true;
3528 }
3529 }
3530 for (int i=services.size()-1; i>=0; i--) {
3531 if (name.equals(services.get(i).className)) {
3532 return true;
3533 }
3534 }
3535 for (int i=instrumentation.size()-1; i>=0; i--) {
3536 if (name.equals(instrumentation.get(i).className)) {
3537 return true;
3538 }
3539 }
3540 return false;
3541 }
3542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 public String toString() {
3544 return "Package{"
3545 + Integer.toHexString(System.identityHashCode(this))
3546 + " " + packageName + "}";
3547 }
3548 }
3549
3550 public static class Component<II extends IntentInfo> {
3551 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003552 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003553 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 public Bundle metaData;
3555
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003556 ComponentName componentName;
3557 String componentShortName;
3558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 public Component(Package _owner) {
3560 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003561 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003562 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003563 }
3564
3565 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3566 owner = args.owner;
3567 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003568 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003569 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003570 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003571 args.outError[0] = args.tag + " does not specify android:name";
3572 return;
3573 }
3574
3575 outInfo.name
3576 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3577 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003578 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003579 args.outError[0] = args.tag + " does not have valid android:name";
3580 return;
3581 }
3582
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003583 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003584
3585 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3586 if (iconVal != 0) {
3587 outInfo.icon = iconVal;
3588 outInfo.nonLocalizedLabel = null;
3589 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003590
3591 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3592 if (logoVal != 0) {
3593 outInfo.logo = logoVal;
3594 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003595
3596 TypedValue v = args.sa.peekValue(args.labelRes);
3597 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3598 outInfo.nonLocalizedLabel = v.coerceToString();
3599 }
3600
3601 outInfo.packageName = owner.packageName;
3602 }
3603
3604 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3605 this(args, (PackageItemInfo)outInfo);
3606 if (args.outError[0] != null) {
3607 return;
3608 }
3609
3610 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003611 CharSequence pname;
3612 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3613 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3614 } else {
3615 // Some older apps have been seen to use a resource reference
3616 // here that on older builds was ignored (with a warning). We
3617 // need to continue to do this for them so they don't break.
3618 pname = args.sa.getNonResourceString(args.processRes);
3619 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003620 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003621 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003622 args.flags, args.sepProcesses, args.outError);
3623 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003624
3625 if (args.descriptionRes != 0) {
3626 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3627 }
3628
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003629 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 }
3631
3632 public Component(Component<II> clone) {
3633 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003634 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003635 className = clone.className;
3636 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003637 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003638 }
3639
3640 public ComponentName getComponentName() {
3641 if (componentName != null) {
3642 return componentName;
3643 }
3644 if (className != null) {
3645 componentName = new ComponentName(owner.applicationInfo.packageName,
3646 className);
3647 }
3648 return componentName;
3649 }
3650
3651 public String getComponentShortName() {
3652 if (componentShortName != null) {
3653 return componentShortName;
3654 }
3655 ComponentName component = getComponentName();
3656 if (component != null) {
3657 componentShortName = component.flattenToShortString();
3658 }
3659 return componentShortName;
3660 }
3661
3662 public void setPackageName(String packageName) {
3663 componentName = null;
3664 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 }
3666 }
3667
3668 public final static class Permission extends Component<IntentInfo> {
3669 public final PermissionInfo info;
3670 public boolean tree;
3671 public PermissionGroup group;
3672
3673 public Permission(Package _owner) {
3674 super(_owner);
3675 info = new PermissionInfo();
3676 }
3677
3678 public Permission(Package _owner, PermissionInfo _info) {
3679 super(_owner);
3680 info = _info;
3681 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003682
3683 public void setPackageName(String packageName) {
3684 super.setPackageName(packageName);
3685 info.packageName = packageName;
3686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687
3688 public String toString() {
3689 return "Permission{"
3690 + Integer.toHexString(System.identityHashCode(this))
3691 + " " + info.name + "}";
3692 }
3693 }
3694
3695 public final static class PermissionGroup extends Component<IntentInfo> {
3696 public final PermissionGroupInfo info;
3697
3698 public PermissionGroup(Package _owner) {
3699 super(_owner);
3700 info = new PermissionGroupInfo();
3701 }
3702
3703 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3704 super(_owner);
3705 info = _info;
3706 }
3707
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003708 public void setPackageName(String packageName) {
3709 super.setPackageName(packageName);
3710 info.packageName = packageName;
3711 }
3712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 public String toString() {
3714 return "PermissionGroup{"
3715 + Integer.toHexString(System.identityHashCode(this))
3716 + " " + info.name + "}";
3717 }
3718 }
3719
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003720 private static boolean copyNeeded(int flags, Package p,
3721 PackageUserState state, Bundle metaData, int userId) {
3722 if (userId != 0) {
3723 // We always need to copy for other users, since we need
3724 // to fix up the uid.
3725 return true;
3726 }
3727 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3728 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003729 if (p.applicationInfo.enabled != enabled) {
3730 return true;
3731 }
3732 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003733 if (!state.installed || state.blocked) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003734 return true;
3735 }
3736 if (state.stopped) {
3737 return true;
3738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 if ((flags & PackageManager.GET_META_DATA) != 0
3740 && (metaData != null || p.mAppMetaData != null)) {
3741 return true;
3742 }
3743 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3744 && p.usesLibraryFiles != null) {
3745 return true;
3746 }
3747 return false;
3748 }
3749
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003750 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3751 PackageUserState state) {
3752 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003753 }
3754
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003755 private static void updateApplicationInfo(ApplicationInfo ai, int flags,
3756 PackageUserState state) {
3757 // CompatibilityMode is global state.
3758 if (!sCompatibilityModeEnabled) {
3759 ai.disableCompatibilityMode();
3760 }
3761 if (state.installed) {
3762 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3763 } else {
3764 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3765 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07003766 if (state.blocked) {
3767 ai.flags |= ApplicationInfo.FLAG_BLOCKED;
3768 } else {
3769 ai.flags &= ~ApplicationInfo.FLAG_BLOCKED;
3770 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003771 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
3772 ai.enabled = true;
3773 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
3774 ai.enabled = (flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0;
3775 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3776 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
3777 ai.enabled = false;
3778 }
3779 ai.enabledSetting = state.enabled;
3780 }
3781
Amith Yamasani13593602012-03-22 16:16:17 -07003782 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003783 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003785 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003786 return null;
3787 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003788 if (!copyNeeded(flags, p, state, null, userId)
3789 && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
3790 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
3791 // In this case it is safe to directly modify the internal ApplicationInfo state:
3792 // - CompatibilityMode is global state, so will be the same for every call.
3793 // - We only come in to here if the app should reported as installed; this is the
3794 // default state, and we will do a copy otherwise.
3795 // - The enable state will always be reported the same for the application across
3796 // calls; the only exception is for the UNTIL_USED mode, and in that case we will
3797 // be doing a copy.
3798 updateApplicationInfo(p.applicationInfo, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 return p.applicationInfo;
3800 }
3801
3802 // Make shallow copy so we can store the metadata/libraries safely
3803 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003804 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003805 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003806 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 if ((flags & PackageManager.GET_META_DATA) != 0) {
3809 ai.metaData = p.mAppMetaData;
3810 }
3811 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3812 ai.sharedLibraryFiles = p.usesLibraryFiles;
3813 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003814 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003815 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003816 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003817 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003818 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003819 updateApplicationInfo(ai, flags, state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 return ai;
3821 }
3822
3823 public static final PermissionInfo generatePermissionInfo(
3824 Permission p, int flags) {
3825 if (p == null) return null;
3826 if ((flags&PackageManager.GET_META_DATA) == 0) {
3827 return p.info;
3828 }
3829 PermissionInfo pi = new PermissionInfo(p.info);
3830 pi.metaData = p.metaData;
3831 return pi;
3832 }
3833
3834 public static final PermissionGroupInfo generatePermissionGroupInfo(
3835 PermissionGroup pg, int flags) {
3836 if (pg == null) return null;
3837 if ((flags&PackageManager.GET_META_DATA) == 0) {
3838 return pg.info;
3839 }
3840 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3841 pgi.metaData = pg.metaData;
3842 return pgi;
3843 }
3844
3845 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003846 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003848 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3849 super(args, _info);
3850 info = _info;
3851 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003853
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003854 public void setPackageName(String packageName) {
3855 super.setPackageName(packageName);
3856 info.packageName = packageName;
3857 }
3858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 public String toString() {
3860 return "Activity{"
3861 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003862 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 }
3864 }
3865
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003866 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3867 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 if (a == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003869 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003870 return null;
3871 }
3872 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 return a.info;
3874 }
3875 // Make shallow copies so we can store the metadata safely
3876 ActivityInfo ai = new ActivityInfo(a.info);
3877 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003878 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 return ai;
3880 }
3881
3882 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003883 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003885 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3886 super(args, _info);
3887 info = _info;
3888 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003890
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003891 public void setPackageName(String packageName) {
3892 super.setPackageName(packageName);
3893 info.packageName = packageName;
3894 }
3895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 public String toString() {
3897 return "Service{"
3898 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003899 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 }
3901 }
3902
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003903 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3904 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 if (s == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003906 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003907 return null;
3908 }
3909 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 return s.info;
3911 }
3912 // Make shallow copies so we can store the metadata safely
3913 ServiceInfo si = new ServiceInfo(s.info);
3914 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003915 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 return si;
3917 }
3918
3919 public final static class Provider extends Component {
3920 public final ProviderInfo info;
3921 public boolean syncable;
3922
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003923 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3924 super(args, _info);
3925 info = _info;
3926 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 syncable = false;
3928 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 public Provider(Provider existingProvider) {
3931 super(existingProvider);
3932 this.info = existingProvider.info;
3933 this.syncable = existingProvider.syncable;
3934 }
3935
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003936 public void setPackageName(String packageName) {
3937 super.setPackageName(packageName);
3938 info.packageName = packageName;
3939 }
3940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 public String toString() {
3942 return "Provider{"
3943 + Integer.toHexString(System.identityHashCode(this))
3944 + " " + info.name + "}";
3945 }
3946 }
3947
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003948 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3949 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 if (p == null) return null;
Amith Yamasani655d0e22013-06-12 14:19:10 -07003951 if (!checkUseInstalledOrBlocked(flags, state)) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003952 return null;
3953 }
3954 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003956 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 return p.info;
3958 }
3959 // Make shallow copies so we can store the metadata safely
3960 ProviderInfo pi = new ProviderInfo(p.info);
3961 pi.metaData = p.metaData;
3962 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3963 pi.uriPermissionPatterns = null;
3964 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003965 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 return pi;
3967 }
3968
3969 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003970 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003972 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3973 super(args, _info);
3974 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003976
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003977 public void setPackageName(String packageName) {
3978 super.setPackageName(packageName);
3979 info.packageName = packageName;
3980 }
3981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 public String toString() {
3983 return "Instrumentation{"
3984 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003985 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 }
3987 }
3988
3989 public static final InstrumentationInfo generateInstrumentationInfo(
3990 Instrumentation i, int flags) {
3991 if (i == null) return null;
3992 if ((flags&PackageManager.GET_META_DATA) == 0) {
3993 return i.info;
3994 }
3995 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3996 ii.metaData = i.metaData;
3997 return ii;
3998 }
3999
4000 public static class IntentInfo extends IntentFilter {
4001 public boolean hasDefault;
4002 public int labelRes;
4003 public CharSequence nonLocalizedLabel;
4004 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07004005 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
4008 public final static class ActivityIntentInfo extends IntentInfo {
4009 public final Activity activity;
4010
4011 public ActivityIntentInfo(Activity _activity) {
4012 activity = _activity;
4013 }
4014
4015 public String toString() {
4016 return "ActivityIntentInfo{"
4017 + Integer.toHexString(System.identityHashCode(this))
4018 + " " + activity.info.name + "}";
4019 }
4020 }
4021
4022 public final static class ServiceIntentInfo extends IntentInfo {
4023 public final Service service;
4024
4025 public ServiceIntentInfo(Service _service) {
4026 service = _service;
4027 }
4028
4029 public String toString() {
4030 return "ServiceIntentInfo{"
4031 + Integer.toHexString(System.identityHashCode(this))
4032 + " " + service.info.name + "}";
4033 }
4034 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07004035
4036 /**
4037 * @hide
4038 */
4039 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
4040 sCompatibilityModeEnabled = compatibilityModeEnabled;
4041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004042}