blob: 5ebca9eba1a901fd4fb8e0f543cab5204e8336a5 [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;
Amith Yamasani742a6712011-05-04 14:49:28 -070027import android.os.Binder;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -070028import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Bundle;
30import android.os.PatternMatcher;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070031import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.AttributeSet;
Kenny Root05ca4c92011-09-15 10:36:25 -070033import android.util.Base64;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.DisplayMetrics;
Kenny Root05ca4c92011-09-15 10:36:25 -070035import android.util.Log;
Kenny Rootd2d29252011-08-08 11:27:57 -070036import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Kenny Rootd63f7db2010-09-27 08:07:48 -070039import java.io.BufferedInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import java.io.File;
41import java.io.IOException;
42import java.io.InputStream;
43import java.lang.ref.WeakReference;
Kenny Root05ca4c92011-09-15 10:36:25 -070044import java.security.KeyFactory;
45import java.security.NoSuchAlgorithmException;
46import java.security.PublicKey;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import java.security.cert.Certificate;
48import java.security.cert.CertificateEncodingException;
Kenny Root05ca4c92011-09-15 10:36:25 -070049import java.security.spec.EncodedKeySpec;
50import java.security.spec.InvalidKeySpecException;
51import java.security.spec.X509EncodedKeySpec;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.util.ArrayList;
53import java.util.Enumeration;
Dianne Hackborne639da72012-02-21 15:11:13 -080054import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import java.util.Iterator;
Kenny Root05ca4c92011-09-15 10:36:25 -070056import java.util.List;
Kenny Rootbcc954d2011-08-08 16:19:08 -070057import java.util.jar.Attributes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.util.jar.JarEntry;
59import java.util.jar.JarFile;
Kenny Rootd2d29252011-08-08 11:27:57 -070060import java.util.jar.Manifest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Amith Yamasani742a6712011-05-04 14:49:28 -070062import com.android.internal.util.XmlUtils;
63
64import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
68 * Package archive parsing
69 *
70 * {@hide}
71 */
72public class PackageParser {
Kenny Rootd2d29252011-08-08 11:27:57 -070073 private static final boolean DEBUG_JAR = false;
74 private static final boolean DEBUG_PARSER = false;
75 private static final boolean DEBUG_BACKUP = false;
76
Kenny Rootbcc954d2011-08-08 16:19:08 -070077 /** File name in an APK for the Android manifest. */
78 private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
79
Dianne Hackborna96cbb42009-05-13 15:06:13 -070080 /** @hide */
81 public static class NewPermissionInfo {
82 public final String name;
83 public final int sdkVersion;
84 public final int fileVersion;
85
86 public NewPermissionInfo(String name, int sdkVersion, int fileVersion) {
87 this.name = name;
88 this.sdkVersion = sdkVersion;
89 this.fileVersion = fileVersion;
90 }
91 }
Dianne Hackborn79245122012-03-12 10:51:26 -070092
93 /** @hide */
94 public static class SplitPermissionInfo {
95 public final String rootPerm;
96 public final String[] newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070097 public final int targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -070098
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -070099 public SplitPermissionInfo(String rootPerm, String[] newPerms, int targetSdk) {
Dianne Hackborn79245122012-03-12 10:51:26 -0700100 this.rootPerm = rootPerm;
101 this.newPerms = newPerms;
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700102 this.targetSdk = targetSdk;
Dianne Hackborn79245122012-03-12 10:51:26 -0700103 }
104 }
105
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700106 /**
107 * List of new permissions that have been added since 1.0.
108 * NOTE: These must be declared in SDK version order, with permissions
109 * added to older SDKs appearing before those added to newer SDKs.
Dianne Hackborn79245122012-03-12 10:51:26 -0700110 * If sdkVersion is 0, then this is not a permission that we want to
111 * automatically add to older apps, but we do want to allow it to be
112 * granted during a platform update.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700113 * @hide
114 */
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700115 public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] =
116 new PackageParser.NewPermissionInfo[] {
San Mehat5a3a77d2009-06-01 09:25:28 -0700117 new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700118 android.os.Build.VERSION_CODES.DONUT, 0),
119 new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE,
120 android.os.Build.VERSION_CODES.DONUT, 0)
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700121 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Dianne Hackborn79245122012-03-12 10:51:26 -0700123 /**
124 * List of permissions that have been split into more granular or dependent
125 * permissions.
126 * @hide
127 */
128 public static final PackageParser.SplitPermissionInfo SPLIT_PERMISSIONS[] =
129 new PackageParser.SplitPermissionInfo[] {
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700130 // READ_EXTERNAL_STORAGE is always required when an app requests
131 // WRITE_EXTERNAL_STORAGE, because we can't have an app that has
132 // write access without read access. The hack here with the target
133 // target SDK version ensures that this grant is always done.
Dianne Hackborn79245122012-03-12 10:51:26 -0700134 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700135 new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE },
Dianne Hackborn2bd8d042012-06-11 12:27:05 -0700136 android.os.Build.VERSION_CODES.CUR_DEVELOPMENT+1),
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -0700137 new PackageParser.SplitPermissionInfo(android.Manifest.permission.READ_CONTACTS,
138 new String[] { android.Manifest.permission.READ_CALL_LOG },
139 android.os.Build.VERSION_CODES.JELLY_BEAN),
140 new PackageParser.SplitPermissionInfo(android.Manifest.permission.WRITE_CONTACTS,
141 new String[] { android.Manifest.permission.WRITE_CALL_LOG },
142 android.os.Build.VERSION_CODES.JELLY_BEAN)
Dianne Hackborn79245122012-03-12 10:51:26 -0700143 };
144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 private String mArchiveSourcePath;
146 private String[] mSeparateProcesses;
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700147 private boolean mOnlyCoreApps;
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -0700148 private static final int SDK_VERSION = Build.VERSION.SDK_INT;
149 private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME)
150 ? null : Build.VERSION.CODENAME;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151
152 private int mParseError = PackageManager.INSTALL_SUCCEEDED;
153
154 private static final Object mSync = new Object();
155 private static WeakReference<byte[]> mReadBuffer;
156
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700157 private static boolean sCompatibilityModeEnabled = true;
158 private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700159
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700160 static class ParsePackageItemArgs {
161 final Package owner;
162 final String[] outError;
163 final int nameRes;
164 final int labelRes;
165 final int iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700166 final int logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700167
168 String tag;
169 TypedArray sa;
170
171 ParsePackageItemArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700172 int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700173 owner = _owner;
174 outError = _outError;
175 nameRes = _nameRes;
176 labelRes = _labelRes;
177 iconRes = _iconRes;
Adam Powell81cd2e92010-04-21 16:35:18 -0700178 logoRes = _logoRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700179 }
180 }
181
182 static class ParseComponentArgs extends ParsePackageItemArgs {
183 final String[] sepProcesses;
184 final int processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800185 final int descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700186 final int enabledRes;
187 int flags;
188
189 ParseComponentArgs(Package _owner, String[] _outError,
Adam Powell81cd2e92010-04-21 16:35:18 -0700190 int _nameRes, int _labelRes, int _iconRes, int _logoRes,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800191 String[] _sepProcesses, int _processRes,
192 int _descriptionRes, int _enabledRes) {
Adam Powell81cd2e92010-04-21 16:35:18 -0700193 super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700194 sepProcesses = _sepProcesses;
195 processRes = _processRes;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -0800196 descriptionRes = _descriptionRes;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700197 enabledRes = _enabledRes;
198 }
199 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800200
201 /* Light weight package info.
202 * @hide
203 */
204 public static class PackageLite {
Kenny Root05ca4c92011-09-15 10:36:25 -0700205 public final String packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700206 public final int versionCode;
Kenny Root05ca4c92011-09-15 10:36:25 -0700207 public final int installLocation;
208 public final VerifierInfo[] verifiers;
209
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700210 public PackageLite(String packageName, int versionCode,
211 int installLocation, List<VerifierInfo> verifiers) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800212 this.packageName = packageName;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700213 this.versionCode = versionCode;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800214 this.installLocation = installLocation;
Kenny Root05ca4c92011-09-15 10:36:25 -0700215 this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800216 }
217 }
218
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700219 private ParsePackageItemArgs mParseInstrumentationArgs;
220 private ParseComponentArgs mParseActivityArgs;
221 private ParseComponentArgs mParseActivityAliasArgs;
222 private ParseComponentArgs mParseServiceArgs;
223 private ParseComponentArgs mParseProviderArgs;
224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 /** If set to true, we will only allow package files that exactly match
226 * the DTD. Otherwise, we try to get as much from the package as we
227 * can without failing. This should normally be set to false, to
228 * support extensions to the DTD in future versions. */
229 private static final boolean RIGID_PARSER = false;
230
231 private static final String TAG = "PackageParser";
232
233 public PackageParser(String archiveSourcePath) {
234 mArchiveSourcePath = archiveSourcePath;
235 }
236
237 public void setSeparateProcesses(String[] procs) {
238 mSeparateProcesses = procs;
239 }
240
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700241 public void setOnlyCoreApps(boolean onlyCoreApps) {
242 mOnlyCoreApps = onlyCoreApps;
243 }
244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 private static final boolean isPackageFilename(String name) {
246 return name.endsWith(".apk");
247 }
248
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700249 /*
Amith Yamasani13593602012-03-22 16:16:17 -0700250 public static PackageInfo generatePackageInfo(PackageParser.Package p,
251 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
252 HashSet<String> grantedPermissions) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700253 PackageUserState state = new PackageUserState();
Amith Yamasani13593602012-03-22 16:16:17 -0700254 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700255 grantedPermissions, state, UserHandle.getCallingUserId());
Amith Yamasani13593602012-03-22 16:16:17 -0700256 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700257 */
Amith Yamasani13593602012-03-22 16:16:17 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * Generate and return the {@link PackageInfo} for a parsed package.
261 *
262 * @param p the parsed package.
263 * @param flags indicating which optional information is included.
264 */
265 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Dianne Hackborne639da72012-02-21 15:11:13 -0800266 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700267 HashSet<String> grantedPermissions, PackageUserState state) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268
Amith Yamasani483f3b02012-03-13 16:08:00 -0700269 return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700270 grantedPermissions, state, UserHandle.getCallingUserId());
271 }
272
273 private static boolean checkUseInstalled(int flags, PackageUserState state) {
274 return state.installed || ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0);
Amith Yamasani483f3b02012-03-13 16:08:00 -0700275 }
276
Amith Yamasani13593602012-03-22 16:16:17 -0700277 public static PackageInfo generatePackageInfo(PackageParser.Package p,
Amith Yamasani483f3b02012-03-13 16:08:00 -0700278 int gids[], int flags, long firstInstallTime, long lastUpdateTime,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700279 HashSet<String> grantedPermissions, PackageUserState state, int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700280
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700281 if (!checkUseInstalled(flags, state)) {
282 return null;
283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 PackageInfo pi = new PackageInfo();
285 pi.packageName = p.packageName;
286 pi.versionCode = p.mVersionCode;
287 pi.versionName = p.mVersionName;
288 pi.sharedUserId = p.mSharedUserId;
289 pi.sharedUserLabel = p.mSharedUserLabel;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700290 pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800291 pi.installLocation = p.installLocation;
Dianne Hackborn78d68832010-10-07 01:12:46 -0700292 pi.firstInstallTime = firstInstallTime;
293 pi.lastUpdateTime = lastUpdateTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 if ((flags&PackageManager.GET_GIDS) != 0) {
295 pi.gids = gids;
296 }
297 if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) {
298 int N = p.configPreferences.size();
299 if (N > 0) {
300 pi.configPreferences = new ConfigurationInfo[N];
Dianne Hackborn49237342009-08-27 20:08:01 -0700301 p.configPreferences.toArray(pi.configPreferences);
302 }
303 N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
304 if (N > 0) {
305 pi.reqFeatures = new FeatureInfo[N];
306 p.reqFeatures.toArray(pi.reqFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308 }
309 if ((flags&PackageManager.GET_ACTIVITIES) != 0) {
310 int N = p.activities.size();
311 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700312 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
313 pi.activities = new ActivityInfo[N];
314 } else {
315 int num = 0;
316 for (int i=0; i<N; i++) {
317 if (p.activities.get(i).info.enabled) num++;
318 }
319 pi.activities = new ActivityInfo[num];
320 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700321 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 final Activity activity = p.activities.get(i);
323 if (activity.info.enabled
324 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700325 pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700326 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 }
328 }
329 }
330 }
331 if ((flags&PackageManager.GET_RECEIVERS) != 0) {
332 int N = p.receivers.size();
333 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700334 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
335 pi.receivers = new ActivityInfo[N];
336 } else {
337 int num = 0;
338 for (int i=0; i<N; i++) {
339 if (p.receivers.get(i).info.enabled) num++;
340 }
341 pi.receivers = new ActivityInfo[num];
342 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700343 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 final Activity activity = p.receivers.get(i);
345 if (activity.info.enabled
346 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Amith Yamasani13593602012-03-22 16:16:17 -0700347 pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700348 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 }
350 }
351 }
352 }
353 if ((flags&PackageManager.GET_SERVICES) != 0) {
354 int N = p.services.size();
355 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700356 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
357 pi.services = new ServiceInfo[N];
358 } else {
359 int num = 0;
360 for (int i=0; i<N; i++) {
361 if (p.services.get(i).info.enabled) num++;
362 }
363 pi.services = new ServiceInfo[num];
364 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700365 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 final Service service = p.services.get(i);
367 if (service.info.enabled
368 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700369 pi.services[j++] = generateServiceInfo(p.services.get(i), flags,
370 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372 }
373 }
374 }
375 if ((flags&PackageManager.GET_PROVIDERS) != 0) {
376 int N = p.providers.size();
377 if (N > 0) {
Dianne Hackborn7eca6872009-09-28 23:57:05 -0700378 if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
379 pi.providers = new ProviderInfo[N];
380 } else {
381 int num = 0;
382 for (int i=0; i<N; i++) {
383 if (p.providers.get(i).info.enabled) num++;
384 }
385 pi.providers = new ProviderInfo[num];
386 }
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700387 for (int i=0, j=0; i<N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 final Provider provider = p.providers.get(i);
389 if (provider.info.enabled
390 || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700391 pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags,
392 state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 }
394 }
395 }
396 }
397 if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) {
398 int N = p.instrumentation.size();
399 if (N > 0) {
400 pi.instrumentation = new InstrumentationInfo[N];
401 for (int i=0; i<N; i++) {
402 pi.instrumentation[i] = generateInstrumentationInfo(
403 p.instrumentation.get(i), flags);
404 }
405 }
406 }
407 if ((flags&PackageManager.GET_PERMISSIONS) != 0) {
408 int N = p.permissions.size();
409 if (N > 0) {
410 pi.permissions = new PermissionInfo[N];
411 for (int i=0; i<N; i++) {
412 pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
413 }
414 }
415 N = p.requestedPermissions.size();
416 if (N > 0) {
417 pi.requestedPermissions = new String[N];
Dianne Hackborne639da72012-02-21 15:11:13 -0800418 pi.requestedPermissionsFlags = new int[N];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 for (int i=0; i<N; i++) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800420 final String perm = p.requestedPermissions.get(i);
421 pi.requestedPermissions[i] = perm;
422 if (p.requestedPermissionsRequired.get(i)) {
423 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
424 }
425 if (grantedPermissions != null && grantedPermissions.contains(perm)) {
426 pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 }
429 }
430 }
431 if ((flags&PackageManager.GET_SIGNATURES) != 0) {
Suchi Amalapurapud83006c2009-10-28 23:39:46 -0700432 int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
433 if (N > 0) {
434 pi.signatures = new Signature[N];
435 System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437 }
438 return pi;
439 }
440
441 private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
442 byte[] readBuffer) {
443 try {
444 // We must read the stream for the JarEntry to retrieve
445 // its certificates.
Kenny Rootd63f7db2010-09-27 08:07:48 -0700446 InputStream is = new BufferedInputStream(jarFile.getInputStream(je));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 while (is.read(readBuffer, 0, readBuffer.length) != -1) {
448 // not using
449 }
450 is.close();
451 return je != null ? je.getCertificates() : null;
452 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700453 Slog.w(TAG, "Exception reading " + je.getName() + " in "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 + jarFile.getName(), e);
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700455 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700456 Slog.w(TAG, "Exception reading " + je.getName() + " in "
Dianne Hackborn6e52b5d2010-04-05 14:33:01 -0700457 + jarFile.getName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
459 return null;
460 }
461
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800462 public final static int PARSE_IS_SYSTEM = 1<<0;
463 public final static int PARSE_CHATTY = 1<<1;
464 public final static int PARSE_MUST_BE_APK = 1<<2;
465 public final static int PARSE_IGNORE_PROCESSES = 1<<3;
466 public final static int PARSE_FORWARD_LOCK = 1<<4;
467 public final static int PARSE_ON_SDCARD = 1<<5;
Dianne Hackborn806da1d2010-03-18 16:50:07 -0700468 public final static int PARSE_IS_SYSTEM_DIR = 1<<6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469
470 public int getParseError() {
471 return mParseError;
472 }
473
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800474 public Package parsePackage(File sourceFile, String destCodePath,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 DisplayMetrics metrics, int flags) {
476 mParseError = PackageManager.INSTALL_SUCCEEDED;
477
478 mArchiveSourcePath = sourceFile.getPath();
479 if (!sourceFile.isFile()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700480 Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
482 return null;
483 }
484 if (!isPackageFilename(sourceFile.getName())
485 && (flags&PARSE_MUST_BE_APK) != 0) {
486 if ((flags&PARSE_IS_SYSTEM) == 0) {
487 // We expect to have non-.apk files in the system dir,
488 // so don't warn about them.
Kenny Rootd2d29252011-08-08 11:27:57 -0700489 Slog.w(TAG, "Skipping non-package file: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491 mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;
492 return null;
493 }
494
Kenny Rootd2d29252011-08-08 11:27:57 -0700495 if (DEBUG_JAR)
496 Slog.d(TAG, "Scanning package: " + mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497
498 XmlResourceParser parser = null;
499 AssetManager assmgr = null;
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800500 Resources res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 boolean assetError = true;
502 try {
503 assmgr = new AssetManager();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700504 int cookie = assmgr.addAssetPath(mArchiveSourcePath);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800505 if (cookie != 0) {
506 res = new Resources(assmgr, metrics, null);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700507 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 -0800508 Build.VERSION.RESOURCES_SDK_INT);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700509 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 assetError = false;
511 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700512 Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514 } catch (Exception e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700515 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 + mArchiveSourcePath, e);
517 }
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800518 if (assetError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 if (assmgr != null) assmgr.close();
520 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
521 return null;
522 }
523 String[] errorText = new String[1];
524 Package pkg = null;
525 Exception errorException = null;
526 try {
527 // XXXX todo: need to figure out correct configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 pkg = parsePackage(res, parser, flags, errorText);
529 } catch (Exception e) {
530 errorException = e;
531 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
532 }
533
534
535 if (pkg == null) {
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700536 // If we are only parsing core apps, then a null with INSTALL_SUCCEEDED
537 // just means to skip this app so don't make a fuss about it.
538 if (!mOnlyCoreApps || mParseError != PackageManager.INSTALL_SUCCEEDED) {
539 if (errorException != null) {
540 Slog.w(TAG, mArchiveSourcePath, errorException);
541 } else {
542 Slog.w(TAG, mArchiveSourcePath + " (at "
543 + parser.getPositionDescription()
544 + "): " + errorText[0]);
545 }
546 if (mParseError == PackageManager.INSTALL_SUCCEEDED) {
547 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 parser.close();
551 assmgr.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 return null;
553 }
554
555 parser.close();
556 assmgr.close();
557
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800558 // Set code and resource paths
559 pkg.mPath = destCodePath;
560 pkg.mScanPath = mArchiveSourcePath;
561 //pkg.applicationInfo.sourceDir = destCodePath;
562 //pkg.applicationInfo.publicSourceDir = destRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 pkg.mSignatures = null;
564
565 return pkg;
566 }
567
568 public boolean collectCertificates(Package pkg, int flags) {
569 pkg.mSignatures = null;
570
571 WeakReference<byte[]> readBufferRef;
572 byte[] readBuffer = null;
573 synchronized (mSync) {
574 readBufferRef = mReadBuffer;
575 if (readBufferRef != null) {
576 mReadBuffer = null;
577 readBuffer = readBufferRef.get();
578 }
579 if (readBuffer == null) {
580 readBuffer = new byte[8192];
581 readBufferRef = new WeakReference<byte[]>(readBuffer);
582 }
583 }
584
585 try {
586 JarFile jarFile = new JarFile(mArchiveSourcePath);
587
588 Certificate[] certs = null;
589
590 if ((flags&PARSE_IS_SYSTEM) != 0) {
591 // If this package comes from the system image, then we
592 // can trust it... we'll just use the AndroidManifest.xml
593 // to retrieve its signatures, not validating all of the
594 // files.
Kenny Rootbcc954d2011-08-08 16:19:08 -0700595 JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 certs = loadCertificates(jarFile, jarEntry, readBuffer);
597 if (certs == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700598 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 + " has no certificates at entry "
600 + jarEntry.getName() + "; ignoring!");
601 jarFile.close();
602 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
603 return false;
604 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700605 if (DEBUG_JAR) {
606 Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 + " certs=" + (certs != null ? certs.length : 0));
608 if (certs != null) {
609 final int N = certs.length;
610 for (int i=0; i<N; i++) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700611 Slog.i(TAG, " Public key: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 + certs[i].getPublicKey().getEncoded()
613 + " " + certs[i].getPublicKey());
614 }
615 }
616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700618 Enumeration<JarEntry> entries = jarFile.entries();
Kenny Rootbcc954d2011-08-08 16:19:08 -0700619 final Manifest manifest = jarFile.getManifest();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 while (entries.hasMoreElements()) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700621 final JarEntry je = entries.nextElement();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 if (je.isDirectory()) continue;
Kenny Rootd2d29252011-08-08 11:27:57 -0700623
Kenny Rootbcc954d2011-08-08 16:19:08 -0700624 final String name = je.getName();
625
626 if (name.startsWith("META-INF/"))
627 continue;
628
629 if (ANDROID_MANIFEST_FILENAME.equals(name)) {
630 final Attributes attributes = manifest.getAttributes(name);
631 pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
632 }
633
634 final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
Kenny Rootd2d29252011-08-08 11:27:57 -0700635 if (DEBUG_JAR) {
636 Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 + ": certs=" + certs + " ("
638 + (certs != null ? certs.length : 0) + ")");
639 }
Kenny Rootbcc954d2011-08-08 16:19:08 -0700640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 if (localCerts == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700642 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 + " has no certificates at entry "
644 + je.getName() + "; ignoring!");
645 jarFile.close();
646 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
647 return false;
648 } else if (certs == null) {
649 certs = localCerts;
650 } else {
651 // Ensure all certificates match.
652 for (int i=0; i<certs.length; i++) {
653 boolean found = false;
654 for (int j=0; j<localCerts.length; j++) {
655 if (certs[i] != null &&
656 certs[i].equals(localCerts[j])) {
657 found = true;
658 break;
659 }
660 }
661 if (!found || certs.length != localCerts.length) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700662 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 + " has mismatched certificates at entry "
664 + je.getName() + "; ignoring!");
665 jarFile.close();
666 mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
667 return false;
668 }
669 }
670 }
671 }
672 }
673 jarFile.close();
674
675 synchronized (mSync) {
676 mReadBuffer = readBufferRef;
677 }
678
679 if (certs != null && certs.length > 0) {
680 final int N = certs.length;
681 pkg.mSignatures = new Signature[certs.length];
682 for (int i=0; i<N; i++) {
683 pkg.mSignatures[i] = new Signature(
684 certs[i].getEncoded());
685 }
686 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700687 Slog.e(TAG, "Package " + pkg.packageName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 + " has no certificates; ignoring!");
689 mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
690 return false;
691 }
692 } catch (CertificateEncodingException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700693 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
695 return false;
696 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700697 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
699 return false;
700 } catch (RuntimeException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700701 Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
703 return false;
704 }
705
706 return true;
707 }
708
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800709 /*
710 * Utility method that retrieves just the package name and install
711 * location from the apk location at the given file path.
712 * @param packageFilePath file location of the apk
713 * @param flags Special parse flags
Kenny Root930d3af2010-07-30 16:52:29 -0700714 * @return PackageLite object with package information or null on failure.
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800715 */
716 public static PackageLite parsePackageLite(String packageFilePath, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 AssetManager assmgr = null;
Kenny Root05ca4c92011-09-15 10:36:25 -0700718 final XmlResourceParser parser;
719 final Resources res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 try {
721 assmgr = new AssetManager();
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700722 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 -0800723 Build.VERSION.RESOURCES_SDK_INT);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 int cookie = assmgr.addAssetPath(packageFilePath);
Kenny Root1ebd74a2011-08-03 15:09:44 -0700726 if (cookie == 0) {
727 return null;
728 }
729
Kenny Root05ca4c92011-09-15 10:36:25 -0700730 final DisplayMetrics metrics = new DisplayMetrics();
731 metrics.setToDefaults();
732 res = new Resources(assmgr, metrics, null);
Kenny Rootbcc954d2011-08-08 16:19:08 -0700733 parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 } catch (Exception e) {
735 if (assmgr != null) assmgr.close();
Kenny Rootd2d29252011-08-08 11:27:57 -0700736 Slog.w(TAG, "Unable to read AndroidManifest.xml of "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 + packageFilePath, e);
738 return null;
739 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700740
741 final AttributeSet attrs = parser;
742 final String errors[] = new String[1];
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800743 PackageLite packageLite = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 try {
Kenny Root05ca4c92011-09-15 10:36:25 -0700745 packageLite = parsePackageLite(res, parser, attrs, flags, errors);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 } catch (IOException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700747 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 } catch (XmlPullParserException e) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700749 Slog.w(TAG, packageFilePath, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 } finally {
751 if (parser != null) parser.close();
752 if (assmgr != null) assmgr.close();
753 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800754 if (packageLite == null) {
Kenny Rootd2d29252011-08-08 11:27:57 -0700755 Slog.e(TAG, "parsePackageLite error: " + errors[0]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 return null;
757 }
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800758 return packageLite;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 }
760
761 private static String validateName(String name, boolean requiresSeparator) {
762 final int N = name.length();
763 boolean hasSep = false;
764 boolean front = true;
765 for (int i=0; i<N; i++) {
766 final char c = name.charAt(i);
767 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
768 front = false;
769 continue;
770 }
771 if (!front) {
772 if ((c >= '0' && c <= '9') || c == '_') {
773 continue;
774 }
775 }
776 if (c == '.') {
777 hasSep = true;
778 front = true;
779 continue;
780 }
781 return "bad character '" + c + "'";
782 }
783 return hasSep || !requiresSeparator
784 ? null : "must have at least one '.' separator";
785 }
786
787 private static String parsePackageName(XmlPullParser parser,
788 AttributeSet attrs, int flags, String[] outError)
789 throws IOException, XmlPullParserException {
790
791 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700792 while ((type = parser.next()) != XmlPullParser.START_TAG
793 && type != XmlPullParser.END_DOCUMENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 ;
795 }
796
Kenny Rootd2d29252011-08-08 11:27:57 -0700797 if (type != XmlPullParser.START_TAG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 outError[0] = "No start tag found";
799 return null;
800 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700801 if (DEBUG_PARSER)
802 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 if (!parser.getName().equals("manifest")) {
804 outError[0] = "No <manifest> tag";
805 return null;
806 }
807 String pkgName = attrs.getAttributeValue(null, "package");
808 if (pkgName == null || pkgName.length() == 0) {
809 outError[0] = "<manifest> does not specify package";
810 return null;
811 }
812 String nameError = validateName(pkgName, true);
813 if (nameError != null && !"android".equals(pkgName)) {
814 outError[0] = "<manifest> specifies bad package name \""
815 + pkgName + "\": " + nameError;
816 return null;
817 }
818
819 return pkgName.intern();
820 }
821
Kenny Root05ca4c92011-09-15 10:36:25 -0700822 private static PackageLite parsePackageLite(Resources res, XmlPullParser parser,
823 AttributeSet attrs, int flags, String[] outError) throws IOException,
824 XmlPullParserException {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800825
826 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -0700827 while ((type = parser.next()) != XmlPullParser.START_TAG
828 && type != XmlPullParser.END_DOCUMENT) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800829 ;
830 }
831
Kenny Rootd2d29252011-08-08 11:27:57 -0700832 if (type != XmlPullParser.START_TAG) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800833 outError[0] = "No start tag found";
834 return null;
835 }
Kenny Rootd2d29252011-08-08 11:27:57 -0700836 if (DEBUG_PARSER)
837 Slog.v(TAG, "Root element name: '" + parser.getName() + "'");
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800838 if (!parser.getName().equals("manifest")) {
839 outError[0] = "No <manifest> tag";
840 return null;
841 }
842 String pkgName = attrs.getAttributeValue(null, "package");
843 if (pkgName == null || pkgName.length() == 0) {
844 outError[0] = "<manifest> does not specify package";
845 return null;
846 }
847 String nameError = validateName(pkgName, true);
848 if (nameError != null && !"android".equals(pkgName)) {
849 outError[0] = "<manifest> specifies bad package name \""
850 + pkgName + "\": " + nameError;
851 return null;
852 }
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700853 int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700854 int versionCode = 0;
855 int numFound = 0;
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800856 for (int i = 0; i < attrs.getAttributeCount(); i++) {
857 String attr = attrs.getAttributeName(i);
858 if (attr.equals("installLocation")) {
859 installLocation = attrs.getAttributeIntValue(i,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700860 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700861 numFound++;
862 } else if (attr.equals("versionCode")) {
863 versionCode = attrs.getAttributeIntValue(i, 0);
864 numFound++;
865 }
866 if (numFound >= 2) {
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800867 break;
868 }
869 }
Kenny Root05ca4c92011-09-15 10:36:25 -0700870
871 // Only search the tree when the tag is directly below <manifest>
872 final int searchDepth = parser.getDepth() + 1;
873
874 final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
875 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
876 && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
877 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
878 continue;
879 }
880
881 if (parser.getDepth() == searchDepth && "package-verifier".equals(parser.getName())) {
882 final VerifierInfo verifier = parseVerifier(res, parser, attrs, flags, outError);
883 if (verifier != null) {
884 verifiers.add(verifier);
885 }
886 }
887 }
888
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700889 return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
Suchi Amalapurapua2b6c372010-03-05 17:40:11 -0800890 }
891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 /**
893 * Temporary.
894 */
895 static public Signature stringToSignature(String str) {
896 final int N = str.length();
897 byte[] sig = new byte[N];
898 for (int i=0; i<N; i++) {
899 sig[i] = (byte)str.charAt(i);
900 }
901 return new Signature(sig);
902 }
903
904 private Package parsePackage(
905 Resources res, XmlResourceParser parser, int flags, String[] outError)
906 throws XmlPullParserException, IOException {
907 AttributeSet attrs = parser;
908
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700909 mParseInstrumentationArgs = null;
910 mParseActivityArgs = null;
911 mParseServiceArgs = null;
912 mParseProviderArgs = null;
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 String pkgName = parsePackageName(parser, attrs, flags, outError);
915 if (pkgName == null) {
916 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
917 return null;
918 }
919 int type;
920
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700921 if (mOnlyCoreApps) {
922 boolean core = attrs.getAttributeBooleanValue(null, "coreApp", false);
923 if (!core) {
924 mParseError = PackageManager.INSTALL_SUCCEEDED;
925 return null;
926 }
927 }
928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 final Package pkg = new Package(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 boolean foundApp = false;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 TypedArray sa = res.obtainAttributes(attrs,
933 com.android.internal.R.styleable.AndroidManifest);
934 pkg.mVersionCode = sa.getInteger(
935 com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800936 pkg.mVersionName = sa.getNonConfigurationString(
937 com.android.internal.R.styleable.AndroidManifest_versionName, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 if (pkg.mVersionName != null) {
939 pkg.mVersionName = pkg.mVersionName.intern();
940 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -0800941 String str = sa.getNonConfigurationString(
942 com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
943 if (str != null && str.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 String nameError = validateName(str, true);
945 if (nameError != null && !"android".equals(pkgName)) {
946 outError[0] = "<manifest> specifies bad sharedUserId name \""
947 + str + "\": " + nameError;
948 mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
949 return null;
950 }
951 pkg.mSharedUserId = str.intern();
952 pkg.mSharedUserLabel = sa.getResourceId(
953 com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
954 }
955 sa.recycle();
Suchi Amalapurapuaaec7792010-02-25 11:49:43 -0800956
Suchi Amalapurapu117818e2010-02-09 03:45:40 -0800957 pkg.installLocation = sa.getInteger(
958 com.android.internal.R.styleable.AndroidManifest_installLocation,
Suchi Amalapurapu90d8ee62010-03-18 11:38:35 -0700959 PARSE_DEFAULT_INSTALL_LOCATION);
Dianne Hackborn54e570f2010-10-04 18:32:32 -0700960 pkg.applicationInfo.installLocation = pkg.installLocation;
Kenny Root7cb9be22012-05-30 15:30:37 -0700961
962 /* Set the global "forward lock" flag */
963 if ((flags & PARSE_FORWARD_LOCK) != 0) {
964 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FORWARD_LOCK;
965 }
966
967 /* Set the global "on SD card" flag */
968 if ((flags & PARSE_ON_SDCARD) != 0) {
969 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
970 }
971
Dianne Hackborn723738c2009-06-25 19:48:04 -0700972 // Resource boolean are -1, so 1 means we don't know the value.
973 int supportsSmallScreens = 1;
974 int supportsNormalScreens = 1;
975 int supportsLargeScreens = 1;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700976 int supportsXLargeScreens = 1;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700977 int resizeable = 1;
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700978 int anyDensity = 1;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 int outerDepth = parser.getDepth();
Kenny Rootd2d29252011-08-08 11:27:57 -0700981 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
982 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
983 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 continue;
985 }
986
987 String tagName = parser.getName();
988 if (tagName.equals("application")) {
989 if (foundApp) {
990 if (RIGID_PARSER) {
991 outError[0] = "<manifest> has more than one <application>";
992 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
993 return null;
994 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -0700995 Slog.w(TAG, "<manifest> has more than one <application>");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 XmlUtils.skipCurrentTag(parser);
997 continue;
998 }
999 }
1000
1001 foundApp = true;
1002 if (!parseApplication(pkg, res, parser, attrs, flags, outError)) {
1003 return null;
1004 }
1005 } else if (tagName.equals("permission-group")) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001006 if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 return null;
1008 }
1009 } else if (tagName.equals("permission")) {
1010 if (parsePermission(pkg, res, parser, attrs, outError) == null) {
1011 return null;
1012 }
1013 } else if (tagName.equals("permission-tree")) {
1014 if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
1015 return null;
1016 }
1017 } else if (tagName.equals("uses-permission")) {
1018 sa = res.obtainAttributes(attrs,
1019 com.android.internal.R.styleable.AndroidManifestUsesPermission);
1020
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001021 // Note: don't allow this value to be a reference to a resource
1022 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 String name = sa.getNonResourceString(
1024 com.android.internal.R.styleable.AndroidManifestUsesPermission_name);
Dianne Hackborne8241202012-04-06 13:39:09 -07001025 /* Not supporting optional permissions yet.
Dianne Hackborne639da72012-02-21 15:11:13 -08001026 boolean required = sa.getBoolean(
1027 com.android.internal.R.styleable.AndroidManifestUsesPermission_required, true);
Dianne Hackborne8241202012-04-06 13:39:09 -07001028 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029
1030 sa.recycle();
1031
1032 if (name != null && !pkg.requestedPermissions.contains(name)) {
Dianne Hackborn854060a2009-07-09 18:14:31 -07001033 pkg.requestedPermissions.add(name.intern());
Dianne Hackborne8241202012-04-06 13:39:09 -07001034 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 }
1036
1037 XmlUtils.skipCurrentTag(parser);
1038
1039 } else if (tagName.equals("uses-configuration")) {
1040 ConfigurationInfo cPref = new ConfigurationInfo();
1041 sa = res.obtainAttributes(attrs,
1042 com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
1043 cPref.reqTouchScreen = sa.getInt(
1044 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
1045 Configuration.TOUCHSCREEN_UNDEFINED);
1046 cPref.reqKeyboardType = sa.getInt(
1047 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
1048 Configuration.KEYBOARD_UNDEFINED);
1049 if (sa.getBoolean(
1050 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
1051 false)) {
1052 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
1053 }
1054 cPref.reqNavigation = sa.getInt(
1055 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
1056 Configuration.NAVIGATION_UNDEFINED);
1057 if (sa.getBoolean(
1058 com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
1059 false)) {
1060 cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
1061 }
1062 sa.recycle();
1063 pkg.configPreferences.add(cPref);
1064
1065 XmlUtils.skipCurrentTag(parser);
1066
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001067 } else if (tagName.equals("uses-feature")) {
Dianne Hackborn49237342009-08-27 20:08:01 -07001068 FeatureInfo fi = new FeatureInfo();
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001069 sa = res.obtainAttributes(attrs,
1070 com.android.internal.R.styleable.AndroidManifestUsesFeature);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001071 // Note: don't allow this value to be a reference to a resource
1072 // that may change.
Dianne Hackborn49237342009-08-27 20:08:01 -07001073 fi.name = sa.getNonResourceString(
1074 com.android.internal.R.styleable.AndroidManifestUsesFeature_name);
1075 if (fi.name == null) {
1076 fi.reqGlEsVersion = sa.getInt(
1077 com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion,
1078 FeatureInfo.GL_ES_VERSION_UNDEFINED);
1079 }
1080 if (sa.getBoolean(
1081 com.android.internal.R.styleable.AndroidManifestUsesFeature_required,
1082 true)) {
1083 fi.flags |= FeatureInfo.FLAG_REQUIRED;
1084 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001085 sa.recycle();
Dianne Hackborn49237342009-08-27 20:08:01 -07001086 if (pkg.reqFeatures == null) {
1087 pkg.reqFeatures = new ArrayList<FeatureInfo>();
1088 }
1089 pkg.reqFeatures.add(fi);
1090
1091 if (fi.name == null) {
1092 ConfigurationInfo cPref = new ConfigurationInfo();
1093 cPref.reqGlEsVersion = fi.reqGlEsVersion;
1094 pkg.configPreferences.add(cPref);
1095 }
Suchi Amalapurapud299b812009-06-05 10:26:19 -07001096
1097 XmlUtils.skipCurrentTag(parser);
1098
Dianne Hackborn851a5412009-05-08 12:06:44 -07001099 } else if (tagName.equals("uses-sdk")) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001100 if (SDK_VERSION > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 sa = res.obtainAttributes(attrs,
1102 com.android.internal.R.styleable.AndroidManifestUsesSdk);
1103
Dianne Hackborn851a5412009-05-08 12:06:44 -07001104 int minVers = 0;
1105 String minCode = null;
1106 int targetVers = 0;
1107 String targetCode = null;
1108
1109 TypedValue val = sa.peekValue(
1110 com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
1111 if (val != null) {
1112 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1113 targetCode = minCode = val.string.toString();
1114 } else {
1115 // If it's not a string, it's an integer.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001116 targetVers = minVers = val.data;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001117 }
1118 }
1119
1120 val = sa.peekValue(
1121 com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
1122 if (val != null) {
1123 if (val.type == TypedValue.TYPE_STRING && val.string != null) {
1124 targetCode = minCode = val.string.toString();
1125 } else {
1126 // If it's not a string, it's an integer.
1127 targetVers = val.data;
1128 }
1129 }
1130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 sa.recycle();
1132
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001133 if (minCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001134 if (!minCode.equals(SDK_CODENAME)) {
1135 if (SDK_CODENAME != null) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001136 outError[0] = "Requires development platform " + minCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001137 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001138 } else {
1139 outError[0] = "Requires development platform " + minCode
1140 + " but this is a release platform.";
1141 }
1142 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1143 return null;
1144 }
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001145 } else if (minVers > SDK_VERSION) {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001146 outError[0] = "Requires newer sdk version #" + minVers
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001147 + " (current version is #" + SDK_VERSION + ")";
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07001148 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1149 return null;
1150 }
1151
Dianne Hackborn851a5412009-05-08 12:06:44 -07001152 if (targetCode != null) {
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001153 if (!targetCode.equals(SDK_CODENAME)) {
1154 if (SDK_CODENAME != null) {
Dianne Hackborn851a5412009-05-08 12:06:44 -07001155 outError[0] = "Requires development platform " + targetCode
Suchi Amalapurapu8d5ae982009-10-06 09:26:09 -07001156 + " (current platform is " + SDK_CODENAME + ")";
Dianne Hackborn851a5412009-05-08 12:06:44 -07001157 } else {
1158 outError[0] = "Requires development platform " + targetCode
1159 + " but this is a release platform.";
1160 }
1161 mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
1162 return null;
1163 }
1164 // If the code matches, it definitely targets this SDK.
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001165 pkg.applicationInfo.targetSdkVersion
1166 = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
1167 } else {
1168 pkg.applicationInfo.targetSdkVersion = targetVers;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171
1172 XmlUtils.skipCurrentTag(parser);
1173
Dianne Hackborn723738c2009-06-25 19:48:04 -07001174 } else if (tagName.equals("supports-screens")) {
1175 sa = res.obtainAttributes(attrs,
1176 com.android.internal.R.styleable.AndroidManifestSupportsScreens);
1177
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001178 pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
1179 com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp,
1180 0);
1181 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
1182 com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
1183 0);
Dianne Hackborn2762ff32011-06-01 21:27:05 -07001184 pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
1185 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
1186 0);
Dianne Hackborndf6e9802011-05-26 14:20:23 -07001187
Dianne Hackborn723738c2009-06-25 19:48:04 -07001188 // This is a trick to get a boolean and still able to detect
1189 // if a value was actually set.
1190 supportsSmallScreens = sa.getInteger(
1191 com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
1192 supportsSmallScreens);
1193 supportsNormalScreens = sa.getInteger(
1194 com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
1195 supportsNormalScreens);
1196 supportsLargeScreens = sa.getInteger(
1197 com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
1198 supportsLargeScreens);
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001199 supportsXLargeScreens = sa.getInteger(
1200 com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
1201 supportsXLargeScreens);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001202 resizeable = sa.getInteger(
1203 com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001204 resizeable);
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001205 anyDensity = sa.getInteger(
1206 com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
1207 anyDensity);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001208
1209 sa.recycle();
1210
Mitsuru Oshima9189cab2009-06-03 11:19:12 -07001211 XmlUtils.skipCurrentTag(parser);
Dianne Hackborn854060a2009-07-09 18:14:31 -07001212
1213 } else if (tagName.equals("protected-broadcast")) {
1214 sa = res.obtainAttributes(attrs,
1215 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
1216
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001217 // Note: don't allow this value to be a reference to a resource
1218 // that may change.
Dianne Hackborn854060a2009-07-09 18:14:31 -07001219 String name = sa.getNonResourceString(
1220 com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
1221
1222 sa.recycle();
1223
1224 if (name != null && (flags&PARSE_IS_SYSTEM) != 0) {
1225 if (pkg.protectedBroadcasts == null) {
1226 pkg.protectedBroadcasts = new ArrayList<String>();
1227 }
1228 if (!pkg.protectedBroadcasts.contains(name)) {
1229 pkg.protectedBroadcasts.add(name.intern());
1230 }
1231 }
1232
1233 XmlUtils.skipCurrentTag(parser);
1234
1235 } else if (tagName.equals("instrumentation")) {
1236 if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
1237 return null;
1238 }
1239
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001240 } else if (tagName.equals("original-package")) {
1241 sa = res.obtainAttributes(attrs,
1242 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1243
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001244 String orig =sa.getNonConfigurationString(
1245 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001246 if (!pkg.packageName.equals(orig)) {
Dianne Hackbornc1552392010-03-03 16:19:01 -08001247 if (pkg.mOriginalPackages == null) {
1248 pkg.mOriginalPackages = new ArrayList<String>();
1249 pkg.mRealPackage = pkg.packageName;
1250 }
1251 pkg.mOriginalPackages.add(orig);
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001252 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001253
1254 sa.recycle();
1255
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001256 XmlUtils.skipCurrentTag(parser);
1257
1258 } else if (tagName.equals("adopt-permissions")) {
1259 sa = res.obtainAttributes(attrs,
1260 com.android.internal.R.styleable.AndroidManifestOriginalPackage);
1261
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001262 String name = sa.getNonConfigurationString(
1263 com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001264
1265 sa.recycle();
1266
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08001267 if (name != null) {
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08001268 if (pkg.mAdoptPermissions == null) {
1269 pkg.mAdoptPermissions = new ArrayList<String>();
1270 }
1271 pkg.mAdoptPermissions.add(name);
1272 }
1273
1274 XmlUtils.skipCurrentTag(parser);
1275
Dianne Hackborna0b46c92010-10-21 15:32:06 -07001276 } else if (tagName.equals("uses-gl-texture")) {
1277 // Just skip this tag
1278 XmlUtils.skipCurrentTag(parser);
1279 continue;
1280
1281 } else if (tagName.equals("compatible-screens")) {
1282 // Just skip this tag
1283 XmlUtils.skipCurrentTag(parser);
1284 continue;
1285
Dianne Hackborn854060a2009-07-09 18:14:31 -07001286 } else if (tagName.equals("eat-comment")) {
1287 // Just skip this tag
1288 XmlUtils.skipCurrentTag(parser);
1289 continue;
1290
1291 } else if (RIGID_PARSER) {
1292 outError[0] = "Bad element under <manifest>: "
1293 + parser.getName();
1294 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1295 return null;
1296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07001298 Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName()
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07001299 + " at " + mArchiveSourcePath + " "
1300 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 XmlUtils.skipCurrentTag(parser);
1302 continue;
1303 }
1304 }
1305
1306 if (!foundApp && pkg.instrumentation.size() == 0) {
1307 outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
1308 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
1309 }
1310
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001311 final int NP = PackageParser.NEW_PERMISSIONS.length;
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001312 StringBuilder implicitPerms = null;
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001313 for (int ip=0; ip<NP; ip++) {
1314 final PackageParser.NewPermissionInfo npi
1315 = PackageParser.NEW_PERMISSIONS[ip];
1316 if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
1317 break;
1318 }
1319 if (!pkg.requestedPermissions.contains(npi.name)) {
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001320 if (implicitPerms == null) {
1321 implicitPerms = new StringBuilder(128);
1322 implicitPerms.append(pkg.packageName);
1323 implicitPerms.append(": compat added ");
1324 } else {
1325 implicitPerms.append(' ');
1326 }
1327 implicitPerms.append(npi.name);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001328 pkg.requestedPermissions.add(npi.name);
Dianne Hackborn65696252012-03-05 18:49:21 -08001329 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
Dianne Hackborna96cbb42009-05-13 15:06:13 -07001330 }
Dianne Hackborn851a5412009-05-08 12:06:44 -07001331 }
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001332 if (implicitPerms != null) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001333 Slog.i(TAG, implicitPerms.toString());
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001334 }
Dianne Hackborn79245122012-03-12 10:51:26 -07001335
1336 final int NS = PackageParser.SPLIT_PERMISSIONS.length;
1337 for (int is=0; is<NS; is++) {
1338 final PackageParser.SplitPermissionInfo spi
1339 = PackageParser.SPLIT_PERMISSIONS[is];
Dianne Hackborn31b0e0e2012-04-05 19:33:30 -07001340 if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
1341 || !pkg.requestedPermissions.contains(spi.rootPerm)) {
Dianne Hackborn5e4705a2012-04-06 12:55:53 -07001342 continue;
Dianne Hackborn79245122012-03-12 10:51:26 -07001343 }
1344 for (int in=0; in<spi.newPerms.length; in++) {
1345 final String perm = spi.newPerms[in];
1346 if (!pkg.requestedPermissions.contains(perm)) {
1347 pkg.requestedPermissions.add(perm);
1348 pkg.requestedPermissionsRequired.add(Boolean.TRUE);
1349 }
1350 }
1351 }
1352
Dianne Hackborn723738c2009-06-25 19:48:04 -07001353 if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
1354 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001355 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001356 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
1357 }
1358 if (supportsNormalScreens != 0) {
1359 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
1360 }
1361 if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
1362 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001363 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001364 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
1365 }
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07001366 if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
1367 && pkg.applicationInfo.targetSdkVersion
1368 >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
1369 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
1370 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001371 if (resizeable < 0 || (resizeable > 0
1372 && pkg.applicationInfo.targetSdkVersion
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001373 >= android.os.Build.VERSION_CODES.DONUT)) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001374 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
1375 }
Dianne Hackborn11b822d2009-07-21 20:03:02 -07001376 if (anyDensity < 0 || (anyDensity > 0
1377 && pkg.applicationInfo.targetSdkVersion
1378 >= android.os.Build.VERSION_CODES.DONUT)) {
1379 pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001380 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07001381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 return pkg;
1383 }
1384
1385 private static String buildClassName(String pkg, CharSequence clsSeq,
1386 String[] outError) {
1387 if (clsSeq == null || clsSeq.length() <= 0) {
1388 outError[0] = "Empty class name in package " + pkg;
1389 return null;
1390 }
1391 String cls = clsSeq.toString();
1392 char c = cls.charAt(0);
1393 if (c == '.') {
1394 return (pkg + cls).intern();
1395 }
1396 if (cls.indexOf('.') < 0) {
1397 StringBuilder b = new StringBuilder(pkg);
1398 b.append('.');
1399 b.append(cls);
1400 return b.toString().intern();
1401 }
1402 if (c >= 'a' && c <= 'z') {
1403 return cls.intern();
1404 }
1405 outError[0] = "Bad class name " + cls + " in package " + pkg;
1406 return null;
1407 }
1408
1409 private static String buildCompoundName(String pkg,
1410 CharSequence procSeq, String type, String[] outError) {
1411 String proc = procSeq.toString();
1412 char c = proc.charAt(0);
1413 if (pkg != null && c == ':') {
1414 if (proc.length() < 2) {
1415 outError[0] = "Bad " + type + " name " + proc + " in package " + pkg
1416 + ": must be at least two characters";
1417 return null;
1418 }
1419 String subName = proc.substring(1);
1420 String nameError = validateName(subName, false);
1421 if (nameError != null) {
1422 outError[0] = "Invalid " + type + " name " + proc + " in package "
1423 + pkg + ": " + nameError;
1424 return null;
1425 }
1426 return (pkg + proc).intern();
1427 }
1428 String nameError = validateName(proc, true);
1429 if (nameError != null && !"system".equals(proc)) {
1430 outError[0] = "Invalid " + type + " name " + proc + " in package "
1431 + pkg + ": " + nameError;
1432 return null;
1433 }
1434 return proc.intern();
1435 }
1436
1437 private static String buildProcessName(String pkg, String defProc,
1438 CharSequence procSeq, int flags, String[] separateProcesses,
1439 String[] outError) {
1440 if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) {
1441 return defProc != null ? defProc : pkg;
1442 }
1443 if (separateProcesses != null) {
1444 for (int i=separateProcesses.length-1; i>=0; i--) {
1445 String sp = separateProcesses[i];
1446 if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) {
1447 return pkg;
1448 }
1449 }
1450 }
1451 if (procSeq == null || procSeq.length() <= 0) {
1452 return defProc;
1453 }
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001454 return buildCompoundName(pkg, procSeq, "process", outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 }
1456
1457 private static String buildTaskAffinityName(String pkg, String defProc,
1458 CharSequence procSeq, String[] outError) {
1459 if (procSeq == null) {
1460 return defProc;
1461 }
1462 if (procSeq.length() <= 0) {
1463 return null;
1464 }
1465 return buildCompoundName(pkg, procSeq, "taskAffinity", outError);
1466 }
1467
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001468 private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 XmlPullParser parser, AttributeSet attrs, String[] outError)
1470 throws XmlPullParserException, IOException {
1471 PermissionGroup perm = new PermissionGroup(owner);
1472
1473 TypedArray sa = res.obtainAttributes(attrs,
1474 com.android.internal.R.styleable.AndroidManifestPermissionGroup);
1475
1476 if (!parsePackageItemInfo(owner, perm.info, outError,
1477 "<permission-group>", sa,
1478 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
1479 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001480 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
1481 com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 sa.recycle();
1483 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1484 return null;
1485 }
1486
1487 perm.info.descriptionRes = sa.getResourceId(
1488 com.android.internal.R.styleable.AndroidManifestPermissionGroup_description,
1489 0);
Dianne Hackborn7454d3b2012-09-12 17:22:00 -07001490 perm.info.flags = sa.getInt(
1491 com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001492 perm.info.priority = sa.getInt(
1493 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001494 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001495 perm.info.priority = 0;
1496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497
1498 sa.recycle();
1499
1500 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1501 outError)) {
1502 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1503 return null;
1504 }
1505
1506 owner.permissionGroups.add(perm);
1507
1508 return perm;
1509 }
1510
1511 private Permission parsePermission(Package owner, Resources res,
1512 XmlPullParser parser, AttributeSet attrs, String[] outError)
1513 throws XmlPullParserException, IOException {
1514 Permission perm = new Permission(owner);
1515
1516 TypedArray sa = res.obtainAttributes(attrs,
1517 com.android.internal.R.styleable.AndroidManifestPermission);
1518
1519 if (!parsePackageItemInfo(owner, perm.info, outError,
1520 "<permission>", sa,
1521 com.android.internal.R.styleable.AndroidManifestPermission_name,
1522 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001523 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1524 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 sa.recycle();
1526 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1527 return null;
1528 }
1529
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001530 // Note: don't allow this value to be a reference to a resource
1531 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 perm.info.group = sa.getNonResourceString(
1533 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1534 if (perm.info.group != null) {
1535 perm.info.group = perm.info.group.intern();
1536 }
1537
1538 perm.info.descriptionRes = sa.getResourceId(
1539 com.android.internal.R.styleable.AndroidManifestPermission_description,
1540 0);
1541
1542 perm.info.protectionLevel = sa.getInt(
1543 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1544 PermissionInfo.PROTECTION_NORMAL);
1545
1546 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 if (perm.info.protectionLevel == -1) {
1549 outError[0] = "<permission> does not specify protectionLevel";
1550 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1551 return null;
1552 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001553
1554 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1555
1556 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1557 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1558 PermissionInfo.PROTECTION_SIGNATURE) {
1559 outError[0] = "<permission> protectionLevel specifies a flag but is "
1560 + "not based on signature type";
1561 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1562 return null;
1563 }
1564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565
1566 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1567 outError)) {
1568 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1569 return null;
1570 }
1571
1572 owner.permissions.add(perm);
1573
1574 return perm;
1575 }
1576
1577 private Permission parsePermissionTree(Package owner, Resources res,
1578 XmlPullParser parser, AttributeSet attrs, String[] outError)
1579 throws XmlPullParserException, IOException {
1580 Permission perm = new Permission(owner);
1581
1582 TypedArray sa = res.obtainAttributes(attrs,
1583 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1584
1585 if (!parsePackageItemInfo(owner, perm.info, outError,
1586 "<permission-tree>", sa,
1587 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1588 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001589 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1590 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 sa.recycle();
1592 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1593 return null;
1594 }
1595
1596 sa.recycle();
1597
1598 int index = perm.info.name.indexOf('.');
1599 if (index > 0) {
1600 index = perm.info.name.indexOf('.', index+1);
1601 }
1602 if (index < 0) {
1603 outError[0] = "<permission-tree> name has less than three segments: "
1604 + perm.info.name;
1605 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1606 return null;
1607 }
1608
1609 perm.info.descriptionRes = 0;
1610 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1611 perm.tree = true;
1612
1613 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1614 outError)) {
1615 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1616 return null;
1617 }
1618
1619 owner.permissions.add(perm);
1620
1621 return perm;
1622 }
1623
1624 private Instrumentation parseInstrumentation(Package owner, Resources res,
1625 XmlPullParser parser, AttributeSet attrs, String[] outError)
1626 throws XmlPullParserException, IOException {
1627 TypedArray sa = res.obtainAttributes(attrs,
1628 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1629
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001630 if (mParseInstrumentationArgs == null) {
1631 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1632 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1633 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001634 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1635 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001636 mParseInstrumentationArgs.tag = "<instrumentation>";
1637 }
1638
1639 mParseInstrumentationArgs.sa = sa;
1640
1641 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1642 new InstrumentationInfo());
1643 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 sa.recycle();
1645 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1646 return null;
1647 }
1648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001650 // Note: don't allow this value to be a reference to a resource
1651 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 str = sa.getNonResourceString(
1653 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1654 a.info.targetPackage = str != null ? str.intern() : null;
1655
1656 a.info.handleProfiling = sa.getBoolean(
1657 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1658 false);
1659
1660 a.info.functionalTest = sa.getBoolean(
1661 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1662 false);
1663
1664 sa.recycle();
1665
1666 if (a.info.targetPackage == null) {
1667 outError[0] = "<instrumentation> does not specify targetPackage";
1668 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1669 return null;
1670 }
1671
1672 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1673 outError)) {
1674 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1675 return null;
1676 }
1677
1678 owner.instrumentation.add(a);
1679
1680 return a;
1681 }
1682
1683 private boolean parseApplication(Package owner, Resources res,
1684 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1685 throws XmlPullParserException, IOException {
1686 final ApplicationInfo ai = owner.applicationInfo;
1687 final String pkgName = owner.applicationInfo.packageName;
1688
1689 TypedArray sa = res.obtainAttributes(attrs,
1690 com.android.internal.R.styleable.AndroidManifestApplication);
1691
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001692 String name = sa.getNonConfigurationString(
1693 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 if (name != null) {
1695 ai.className = buildClassName(pkgName, name, outError);
1696 if (ai.className == null) {
1697 sa.recycle();
1698 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1699 return false;
1700 }
1701 }
1702
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001703 String manageSpaceActivity = sa.getNonConfigurationString(
1704 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 if (manageSpaceActivity != null) {
1706 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1707 outError);
1708 }
1709
Christopher Tate181fafa2009-05-14 11:12:14 -07001710 boolean allowBackup = sa.getBoolean(
1711 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1712 if (allowBackup) {
1713 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001714
Christopher Tate3de55bc2010-03-12 17:28:08 -08001715 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1716 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001717 String backupAgent = sa.getNonConfigurationString(
1718 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001719 if (backupAgent != null) {
1720 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001721 if (DEBUG_BACKUP) {
1722 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001723 + " from " + pkgName + "+" + backupAgent);
1724 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001725
1726 if (sa.getBoolean(
1727 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1728 true)) {
1729 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1730 }
1731 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001732 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1733 false)) {
1734 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1735 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001736 }
1737 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 TypedValue v = sa.peekValue(
1740 com.android.internal.R.styleable.AndroidManifestApplication_label);
1741 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1742 ai.nonLocalizedLabel = v.coerceToString();
1743 }
1744
1745 ai.icon = sa.getResourceId(
1746 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001747 ai.logo = sa.getResourceId(
1748 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001750 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 ai.descriptionRes = sa.getResourceId(
1752 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1753
1754 if ((flags&PARSE_IS_SYSTEM) != 0) {
1755 if (sa.getBoolean(
1756 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1757 false)) {
1758 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1759 }
1760 }
1761
1762 if (sa.getBoolean(
1763 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1764 false)) {
1765 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1766 }
1767
1768 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001769 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001770 false)) {
1771 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1772 }
1773
Romain Guy529b60a2010-08-03 18:05:47 -07001774 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001775 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001776 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001777
1778 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1780 true)) {
1781 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1782 }
1783
1784 if (sa.getBoolean(
1785 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1786 false)) {
1787 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1788 }
1789
1790 if (sa.getBoolean(
1791 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1792 true)) {
1793 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1794 }
1795
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001796 if (sa.getBoolean(
1797 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001798 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001799 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1800 }
1801
Jason parksa3cdaa52011-01-13 14:15:43 -06001802 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001803 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001804 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001805 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001806 }
1807
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001808 if (sa.getBoolean(
1809 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1810 false /* default is no RTL support*/)) {
1811 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1812 }
1813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001815 str = sa.getNonConfigurationString(
1816 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1818
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001819 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1820 str = sa.getNonConfigurationString(
1821 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1822 } else {
1823 // Some older apps have been seen to use a resource reference
1824 // here that on older builds was ignored (with a warning). We
1825 // need to continue to do this for them so they don't break.
1826 str = sa.getNonResourceString(
1827 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1828 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1830 str, outError);
1831
1832 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001833 CharSequence pname;
1834 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1835 pname = sa.getNonConfigurationString(
1836 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1837 } else {
1838 // Some older apps have been seen to use a resource reference
1839 // here that on older builds was ignored (with a warning). We
1840 // need to continue to do this for them so they don't break.
1841 pname = sa.getNonResourceString(
1842 com.android.internal.R.styleable.AndroidManifestApplication_process);
1843 }
1844 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 flags, mSeparateProcesses, outError);
1846
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001847 ai.enabled = sa.getBoolean(
1848 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001849
Dianne Hackborn02486b12010-08-26 14:18:37 -07001850 if (false) {
1851 if (sa.getBoolean(
1852 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1853 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001854 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001855
1856 // A heavy-weight application can not be in a custom process.
1857 // We can do direct compare because we intern all strings.
1858 if (ai.processName != null && ai.processName != ai.packageName) {
1859 outError[0] = "cantSaveState applications can not use custom processes";
1860 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001861 }
1862 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 }
1864
Adam Powell269248d2011-08-02 10:26:54 -07001865 ai.uiOptions = sa.getInt(
1866 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001868 sa.recycle();
1869
1870 if (outError[0] != null) {
1871 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1872 return false;
1873 }
1874
1875 final int innerDepth = parser.getDepth();
1876
1877 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001878 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1879 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1880 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 continue;
1882 }
1883
1884 String tagName = parser.getName();
1885 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001886 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1887 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 if (a == null) {
1889 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1890 return false;
1891 }
1892
1893 owner.activities.add(a);
1894
1895 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001896 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 if (a == null) {
1898 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1899 return false;
1900 }
1901
1902 owner.receivers.add(a);
1903
1904 } else if (tagName.equals("service")) {
1905 Service s = parseService(owner, res, parser, attrs, flags, outError);
1906 if (s == null) {
1907 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1908 return false;
1909 }
1910
1911 owner.services.add(s);
1912
1913 } else if (tagName.equals("provider")) {
1914 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1915 if (p == null) {
1916 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1917 return false;
1918 }
1919
1920 owner.providers.add(p);
1921
1922 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001923 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 if (a == null) {
1925 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1926 return false;
1927 }
1928
1929 owner.activities.add(a);
1930
1931 } else if (parser.getName().equals("meta-data")) {
1932 // note: application meta-data is stored off to the side, so it can
1933 // remain null in the primary copy (we like to avoid extra copies because
1934 // it can be large)
1935 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1936 outError)) == null) {
1937 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1938 return false;
1939 }
1940
1941 } else if (tagName.equals("uses-library")) {
1942 sa = res.obtainAttributes(attrs,
1943 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1944
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001945 // Note: don't allow this value to be a reference to a resource
1946 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 String lname = sa.getNonResourceString(
1948 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001949 boolean req = sa.getBoolean(
1950 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1951 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952
1953 sa.recycle();
1954
Dianne Hackborn49237342009-08-27 20:08:01 -07001955 if (lname != null) {
1956 if (req) {
1957 if (owner.usesLibraries == null) {
1958 owner.usesLibraries = new ArrayList<String>();
1959 }
1960 if (!owner.usesLibraries.contains(lname)) {
1961 owner.usesLibraries.add(lname.intern());
1962 }
1963 } else {
1964 if (owner.usesOptionalLibraries == null) {
1965 owner.usesOptionalLibraries = new ArrayList<String>();
1966 }
1967 if (!owner.usesOptionalLibraries.contains(lname)) {
1968 owner.usesOptionalLibraries.add(lname.intern());
1969 }
1970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 }
1972
1973 XmlUtils.skipCurrentTag(parser);
1974
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001975 } else if (tagName.equals("uses-package")) {
1976 // Dependencies for app installers; we don't currently try to
1977 // enforce this.
1978 XmlUtils.skipCurrentTag(parser);
1979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 } else {
1981 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001982 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001983 + " at " + mArchiveSourcePath + " "
1984 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 XmlUtils.skipCurrentTag(parser);
1986 continue;
1987 } else {
1988 outError[0] = "Bad element under <application>: " + tagName;
1989 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1990 return false;
1991 }
1992 }
1993 }
1994
1995 return true;
1996 }
1997
1998 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1999 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07002000 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002001 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 if (name == null) {
2003 outError[0] = tag + " does not specify android:name";
2004 return false;
2005 }
2006
2007 outInfo.name
2008 = buildClassName(owner.applicationInfo.packageName, name, outError);
2009 if (outInfo.name == null) {
2010 return false;
2011 }
2012
2013 int iconVal = sa.getResourceId(iconRes, 0);
2014 if (iconVal != 0) {
2015 outInfo.icon = iconVal;
2016 outInfo.nonLocalizedLabel = null;
2017 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002018
2019 int logoVal = sa.getResourceId(logoRes, 0);
2020 if (logoVal != 0) {
2021 outInfo.logo = logoVal;
2022 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023
2024 TypedValue v = sa.peekValue(labelRes);
2025 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2026 outInfo.nonLocalizedLabel = v.coerceToString();
2027 }
2028
2029 outInfo.packageName = owner.packageName;
2030
2031 return true;
2032 }
2033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 private Activity parseActivity(Package owner, Resources res,
2035 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002036 boolean receiver, boolean hardwareAccelerated)
2037 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 TypedArray sa = res.obtainAttributes(attrs,
2039 com.android.internal.R.styleable.AndroidManifestActivity);
2040
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002041 if (mParseActivityArgs == null) {
2042 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2043 com.android.internal.R.styleable.AndroidManifestActivity_name,
2044 com.android.internal.R.styleable.AndroidManifestActivity_label,
2045 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002046 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002047 mSeparateProcesses,
2048 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002049 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002050 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2051 }
2052
2053 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2054 mParseActivityArgs.sa = sa;
2055 mParseActivityArgs.flags = flags;
2056
2057 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2058 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 sa.recycle();
2060 return null;
2061 }
2062
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002063 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002064 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2065 if (setExported) {
2066 a.info.exported = sa.getBoolean(
2067 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2068 }
2069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 a.info.theme = sa.getResourceId(
2071 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2072
Adam Powell269248d2011-08-02 10:26:54 -07002073 a.info.uiOptions = sa.getInt(
2074 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2075 a.info.applicationInfo.uiOptions);
2076
Adam Powelldd8fab22012-03-22 17:47:27 -07002077 String parentName = sa.getNonConfigurationString(
2078 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2079 if (parentName != null) {
2080 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2081 if (outError[0] == null) {
2082 a.info.parentActivityName = parentClassName;
2083 } else {
2084 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2085 parentName);
2086 outError[0] = null;
2087 }
2088 }
2089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002091 str = sa.getNonConfigurationString(
2092 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002093 if (str == null) {
2094 a.info.permission = owner.applicationInfo.permission;
2095 } else {
2096 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2097 }
2098
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002099 str = sa.getNonConfigurationString(
2100 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2102 owner.applicationInfo.taskAffinity, str, outError);
2103
2104 a.info.flags = 0;
2105 if (sa.getBoolean(
2106 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2107 false)) {
2108 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2109 }
2110
2111 if (sa.getBoolean(
2112 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2113 false)) {
2114 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2115 }
2116
2117 if (sa.getBoolean(
2118 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2119 false)) {
2120 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2121 }
2122
2123 if (sa.getBoolean(
2124 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2125 false)) {
2126 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2127 }
2128
2129 if (sa.getBoolean(
2130 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2131 false)) {
2132 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2133 }
2134
2135 if (sa.getBoolean(
2136 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2137 false)) {
2138 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2139 }
2140
2141 if (sa.getBoolean(
2142 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2143 false)) {
2144 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2145 }
2146
2147 if (sa.getBoolean(
2148 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2149 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2150 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2151 }
2152
Dianne Hackbornffa42482009-09-23 22:20:11 -07002153 if (sa.getBoolean(
2154 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2155 false)) {
2156 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2157 }
2158
Daniel Sandler613dde42010-06-21 13:46:39 -04002159 if (sa.getBoolean(
2160 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2161 false)) {
2162 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2163 }
Romain Guy529b60a2010-08-03 18:05:47 -07002164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002166 if (sa.getBoolean(
2167 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2168 hardwareAccelerated)) {
2169 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2170 }
2171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 a.info.launchMode = sa.getInt(
2173 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2174 ActivityInfo.LAUNCH_MULTIPLE);
2175 a.info.screenOrientation = sa.getInt(
2176 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2177 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2178 a.info.configChanges = sa.getInt(
2179 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2180 0);
2181 a.info.softInputMode = sa.getInt(
2182 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2183 0);
2184 } else {
2185 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2186 a.info.configChanges = 0;
2187 }
2188
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002189 if (receiver) {
2190 if (sa.getBoolean(
2191 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2192 false)) {
2193 a.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2194 if (a.info.exported) {
2195 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2196 + a.className + " at " + mArchiveSourcePath + " "
2197 + parser.getPositionDescription());
2198 a.info.exported = false;
2199 }
2200 setExported = true;
2201 }
2202 }
2203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 sa.recycle();
2205
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002206 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002207 // A heavy-weight application can not have receives in its main process
2208 // We can do direct compare because we intern all strings.
2209 if (a.info.processName == owner.packageName) {
2210 outError[0] = "Heavy-weight applications can not have receivers in main process";
2211 }
2212 }
2213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 if (outError[0] != null) {
2215 return null;
2216 }
2217
2218 int outerDepth = parser.getDepth();
2219 int type;
2220 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2221 && (type != XmlPullParser.END_TAG
2222 || parser.getDepth() > outerDepth)) {
2223 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2224 continue;
2225 }
2226
2227 if (parser.getName().equals("intent-filter")) {
2228 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2229 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2230 return null;
2231 }
2232 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002233 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002234 + mArchiveSourcePath + " "
2235 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 } else {
2237 a.intents.add(intent);
2238 }
2239 } else if (parser.getName().equals("meta-data")) {
2240 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2241 outError)) == null) {
2242 return null;
2243 }
2244 } else {
2245 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002246 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002248 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002249 + " at " + mArchiveSourcePath + " "
2250 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002252 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002253 + " at " + mArchiveSourcePath + " "
2254 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 }
2256 XmlUtils.skipCurrentTag(parser);
2257 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002259 if (receiver) {
2260 outError[0] = "Bad element under <receiver>: " + parser.getName();
2261 } else {
2262 outError[0] = "Bad element under <activity>: " + parser.getName();
2263 }
2264 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 }
2267 }
2268
2269 if (!setExported) {
2270 a.info.exported = a.intents.size() > 0;
2271 }
2272
2273 return a;
2274 }
2275
2276 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002277 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2278 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 TypedArray sa = res.obtainAttributes(attrs,
2280 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2281
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002282 String targetActivity = sa.getNonConfigurationString(
2283 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 if (targetActivity == null) {
2285 outError[0] = "<activity-alias> does not specify android:targetActivity";
2286 sa.recycle();
2287 return null;
2288 }
2289
2290 targetActivity = buildClassName(owner.applicationInfo.packageName,
2291 targetActivity, outError);
2292 if (targetActivity == null) {
2293 sa.recycle();
2294 return null;
2295 }
2296
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002297 if (mParseActivityAliasArgs == null) {
2298 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2299 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2300 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2301 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002302 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002303 mSeparateProcesses,
2304 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002305 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002306 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2307 mParseActivityAliasArgs.tag = "<activity-alias>";
2308 }
2309
2310 mParseActivityAliasArgs.sa = sa;
2311 mParseActivityAliasArgs.flags = flags;
2312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 Activity target = null;
2314
2315 final int NA = owner.activities.size();
2316 for (int i=0; i<NA; i++) {
2317 Activity t = owner.activities.get(i);
2318 if (targetActivity.equals(t.info.name)) {
2319 target = t;
2320 break;
2321 }
2322 }
2323
2324 if (target == null) {
2325 outError[0] = "<activity-alias> target activity " + targetActivity
2326 + " not found in manifest";
2327 sa.recycle();
2328 return null;
2329 }
2330
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002331 ActivityInfo info = new ActivityInfo();
2332 info.targetActivity = targetActivity;
2333 info.configChanges = target.info.configChanges;
2334 info.flags = target.info.flags;
2335 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002336 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002337 info.labelRes = target.info.labelRes;
2338 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2339 info.launchMode = target.info.launchMode;
2340 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002341 if (info.descriptionRes == 0) {
2342 info.descriptionRes = target.info.descriptionRes;
2343 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002344 info.screenOrientation = target.info.screenOrientation;
2345 info.taskAffinity = target.info.taskAffinity;
2346 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002347 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002348 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002349 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002350
2351 Activity a = new Activity(mParseActivityAliasArgs, info);
2352 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 sa.recycle();
2354 return null;
2355 }
2356
2357 final boolean setExported = sa.hasValue(
2358 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2359 if (setExported) {
2360 a.info.exported = sa.getBoolean(
2361 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2362 }
2363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002365 str = sa.getNonConfigurationString(
2366 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 if (str != null) {
2368 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2369 }
2370
Adam Powelldd8fab22012-03-22 17:47:27 -07002371 String parentName = sa.getNonConfigurationString(
2372 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2373 0);
2374 if (parentName != null) {
2375 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2376 if (outError[0] == null) {
2377 a.info.parentActivityName = parentClassName;
2378 } else {
2379 Log.e(TAG, "Activity alias " + a.info.name +
2380 " specified invalid parentActivityName " + parentName);
2381 outError[0] = null;
2382 }
2383 }
2384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 sa.recycle();
2386
2387 if (outError[0] != null) {
2388 return null;
2389 }
2390
2391 int outerDepth = parser.getDepth();
2392 int type;
2393 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2394 && (type != XmlPullParser.END_TAG
2395 || parser.getDepth() > outerDepth)) {
2396 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2397 continue;
2398 }
2399
2400 if (parser.getName().equals("intent-filter")) {
2401 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2402 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2403 return null;
2404 }
2405 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002406 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002407 + mArchiveSourcePath + " "
2408 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 } else {
2410 a.intents.add(intent);
2411 }
2412 } else if (parser.getName().equals("meta-data")) {
2413 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2414 outError)) == null) {
2415 return null;
2416 }
2417 } else {
2418 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002419 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002420 + " at " + mArchiveSourcePath + " "
2421 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 XmlUtils.skipCurrentTag(parser);
2423 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002424 } else {
2425 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2426 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
2429 }
2430
2431 if (!setExported) {
2432 a.info.exported = a.intents.size() > 0;
2433 }
2434
2435 return a;
2436 }
2437
2438 private Provider parseProvider(Package owner, Resources res,
2439 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2440 throws XmlPullParserException, IOException {
2441 TypedArray sa = res.obtainAttributes(attrs,
2442 com.android.internal.R.styleable.AndroidManifestProvider);
2443
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002444 if (mParseProviderArgs == null) {
2445 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2446 com.android.internal.R.styleable.AndroidManifestProvider_name,
2447 com.android.internal.R.styleable.AndroidManifestProvider_label,
2448 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002449 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002450 mSeparateProcesses,
2451 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002452 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002453 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2454 mParseProviderArgs.tag = "<provider>";
2455 }
2456
2457 mParseProviderArgs.sa = sa;
2458 mParseProviderArgs.flags = flags;
2459
2460 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2461 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 sa.recycle();
2463 return null;
2464 }
2465
Nick Kralevichf097b162012-07-28 12:43:48 -07002466 boolean providerExportedDefault = false;
2467
2468 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2469 // For compatibility, applications targeting API level 16 or lower
2470 // should have their content providers exported by default, unless they
2471 // specify otherwise.
2472 providerExportedDefault = true;
2473 }
2474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002476 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2477 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002479 String cpname = sa.getNonConfigurationString(
2480 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481
2482 p.info.isSyncable = sa.getBoolean(
2483 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2484 false);
2485
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002486 String permission = sa.getNonConfigurationString(
2487 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2488 String str = sa.getNonConfigurationString(
2489 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (str == null) {
2491 str = permission;
2492 }
2493 if (str == null) {
2494 p.info.readPermission = owner.applicationInfo.permission;
2495 } else {
2496 p.info.readPermission =
2497 str.length() > 0 ? str.toString().intern() : null;
2498 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002499 str = sa.getNonConfigurationString(
2500 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 if (str == null) {
2502 str = permission;
2503 }
2504 if (str == null) {
2505 p.info.writePermission = owner.applicationInfo.permission;
2506 } else {
2507 p.info.writePermission =
2508 str.length() > 0 ? str.toString().intern() : null;
2509 }
2510
2511 p.info.grantUriPermissions = sa.getBoolean(
2512 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2513 false);
2514
2515 p.info.multiprocess = sa.getBoolean(
2516 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2517 false);
2518
2519 p.info.initOrder = sa.getInt(
2520 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2521 0);
2522
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002523 p.info.flags = 0;
2524
2525 if (sa.getBoolean(
2526 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2527 false)) {
2528 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2529 if (p.info.exported) {
2530 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2531 + p.className + " at " + mArchiveSourcePath + " "
2532 + parser.getPositionDescription());
2533 p.info.exported = false;
2534 }
2535 }
2536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 sa.recycle();
2538
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002539 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002540 // A heavy-weight application can not have providers in its main process
2541 // We can do direct compare because we intern all strings.
2542 if (p.info.processName == owner.packageName) {
2543 outError[0] = "Heavy-weight applications can not have providers in main process";
2544 return null;
2545 }
2546 }
2547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002549 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 return null;
2551 }
2552 p.info.authority = cpname.intern();
2553
2554 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2555 return null;
2556 }
2557
2558 return p;
2559 }
2560
2561 private boolean parseProviderTags(Resources res,
2562 XmlPullParser parser, AttributeSet attrs,
2563 Provider outInfo, String[] outError)
2564 throws XmlPullParserException, IOException {
2565 int outerDepth = parser.getDepth();
2566 int type;
2567 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2568 && (type != XmlPullParser.END_TAG
2569 || parser.getDepth() > outerDepth)) {
2570 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2571 continue;
2572 }
2573
2574 if (parser.getName().equals("meta-data")) {
2575 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2576 outInfo.metaData, outError)) == null) {
2577 return false;
2578 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 } else if (parser.getName().equals("grant-uri-permission")) {
2581 TypedArray sa = res.obtainAttributes(attrs,
2582 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2583
2584 PatternMatcher pa = null;
2585
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002586 String str = sa.getNonConfigurationString(
2587 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 if (str != null) {
2589 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2590 }
2591
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002592 str = sa.getNonConfigurationString(
2593 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 if (str != null) {
2595 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2596 }
2597
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002598 str = sa.getNonConfigurationString(
2599 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 if (str != null) {
2601 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2602 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 sa.recycle();
2605
2606 if (pa != null) {
2607 if (outInfo.info.uriPermissionPatterns == null) {
2608 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2609 outInfo.info.uriPermissionPatterns[0] = pa;
2610 } else {
2611 final int N = outInfo.info.uriPermissionPatterns.length;
2612 PatternMatcher[] newp = new PatternMatcher[N+1];
2613 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2614 newp[N] = pa;
2615 outInfo.info.uriPermissionPatterns = newp;
2616 }
2617 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002618 } else {
2619 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002620 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002621 + parser.getName() + " at " + mArchiveSourcePath + " "
2622 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002623 XmlUtils.skipCurrentTag(parser);
2624 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002625 } else {
2626 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2627 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002628 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002629 }
2630 XmlUtils.skipCurrentTag(parser);
2631
2632 } else if (parser.getName().equals("path-permission")) {
2633 TypedArray sa = res.obtainAttributes(attrs,
2634 com.android.internal.R.styleable.AndroidManifestPathPermission);
2635
2636 PathPermission pa = null;
2637
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002638 String permission = sa.getNonConfigurationString(
2639 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2640 String readPermission = sa.getNonConfigurationString(
2641 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002642 if (readPermission == null) {
2643 readPermission = permission;
2644 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002645 String writePermission = sa.getNonConfigurationString(
2646 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002647 if (writePermission == null) {
2648 writePermission = permission;
2649 }
2650
2651 boolean havePerm = false;
2652 if (readPermission != null) {
2653 readPermission = readPermission.intern();
2654 havePerm = true;
2655 }
2656 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002657 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002658 havePerm = true;
2659 }
2660
2661 if (!havePerm) {
2662 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002663 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002664 + parser.getName() + " at " + mArchiveSourcePath + " "
2665 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002666 XmlUtils.skipCurrentTag(parser);
2667 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002668 } else {
2669 outError[0] = "No readPermission or writePermssion for <path-permission>";
2670 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002671 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002672 }
2673
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002674 String path = sa.getNonConfigurationString(
2675 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002676 if (path != null) {
2677 pa = new PathPermission(path,
2678 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2679 }
2680
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002681 path = sa.getNonConfigurationString(
2682 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002683 if (path != null) {
2684 pa = new PathPermission(path,
2685 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2686 }
2687
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002688 path = sa.getNonConfigurationString(
2689 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002690 if (path != null) {
2691 pa = new PathPermission(path,
2692 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2693 }
2694
2695 sa.recycle();
2696
2697 if (pa != null) {
2698 if (outInfo.info.pathPermissions == null) {
2699 outInfo.info.pathPermissions = new PathPermission[1];
2700 outInfo.info.pathPermissions[0] = pa;
2701 } else {
2702 final int N = outInfo.info.pathPermissions.length;
2703 PathPermission[] newp = new PathPermission[N+1];
2704 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2705 newp[N] = pa;
2706 outInfo.info.pathPermissions = newp;
2707 }
2708 } else {
2709 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002710 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002711 + parser.getName() + " at " + mArchiveSourcePath + " "
2712 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002713 XmlUtils.skipCurrentTag(parser);
2714 continue;
2715 }
2716 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2717 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 }
2719 XmlUtils.skipCurrentTag(parser);
2720
2721 } else {
2722 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002723 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002724 + parser.getName() + " at " + mArchiveSourcePath + " "
2725 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 XmlUtils.skipCurrentTag(parser);
2727 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002728 } else {
2729 outError[0] = "Bad element under <provider>: " + parser.getName();
2730 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 }
2733 }
2734 return true;
2735 }
2736
2737 private Service parseService(Package owner, Resources res,
2738 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2739 throws XmlPullParserException, IOException {
2740 TypedArray sa = res.obtainAttributes(attrs,
2741 com.android.internal.R.styleable.AndroidManifestService);
2742
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002743 if (mParseServiceArgs == null) {
2744 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2745 com.android.internal.R.styleable.AndroidManifestService_name,
2746 com.android.internal.R.styleable.AndroidManifestService_label,
2747 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002748 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002749 mSeparateProcesses,
2750 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002751 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002752 com.android.internal.R.styleable.AndroidManifestService_enabled);
2753 mParseServiceArgs.tag = "<service>";
2754 }
2755
2756 mParseServiceArgs.sa = sa;
2757 mParseServiceArgs.flags = flags;
2758
2759 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2760 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 sa.recycle();
2762 return null;
2763 }
2764
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002765 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 com.android.internal.R.styleable.AndroidManifestService_exported);
2767 if (setExported) {
2768 s.info.exported = sa.getBoolean(
2769 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2770 }
2771
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002772 String str = sa.getNonConfigurationString(
2773 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 if (str == null) {
2775 s.info.permission = owner.applicationInfo.permission;
2776 } else {
2777 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2778 }
2779
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002780 s.info.flags = 0;
2781 if (sa.getBoolean(
2782 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2783 false)) {
2784 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2785 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002786 if (sa.getBoolean(
2787 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2788 false)) {
2789 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2790 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002791 if (sa.getBoolean(
2792 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2793 false)) {
2794 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2795 if (s.info.exported) {
2796 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2797 + s.className + " at " + mArchiveSourcePath + " "
2798 + parser.getPositionDescription());
2799 s.info.exported = false;
2800 }
2801 setExported = true;
2802 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 sa.recycle();
2805
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002806 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002807 // A heavy-weight application can not have services in its main process
2808 // We can do direct compare because we intern all strings.
2809 if (s.info.processName == owner.packageName) {
2810 outError[0] = "Heavy-weight applications can not have services in main process";
2811 return null;
2812 }
2813 }
2814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 int outerDepth = parser.getDepth();
2816 int type;
2817 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2818 && (type != XmlPullParser.END_TAG
2819 || parser.getDepth() > outerDepth)) {
2820 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2821 continue;
2822 }
2823
2824 if (parser.getName().equals("intent-filter")) {
2825 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2826 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2827 return null;
2828 }
2829
2830 s.intents.add(intent);
2831 } else if (parser.getName().equals("meta-data")) {
2832 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2833 outError)) == null) {
2834 return null;
2835 }
2836 } else {
2837 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002838 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002839 + parser.getName() + " at " + mArchiveSourcePath + " "
2840 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 XmlUtils.skipCurrentTag(parser);
2842 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002843 } else {
2844 outError[0] = "Bad element under <service>: " + parser.getName();
2845 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 }
2848 }
2849
2850 if (!setExported) {
2851 s.info.exported = s.intents.size() > 0;
2852 }
2853
2854 return s;
2855 }
2856
2857 private boolean parseAllMetaData(Resources res,
2858 XmlPullParser parser, AttributeSet attrs, String tag,
2859 Component outInfo, String[] outError)
2860 throws XmlPullParserException, IOException {
2861 int outerDepth = parser.getDepth();
2862 int type;
2863 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2864 && (type != XmlPullParser.END_TAG
2865 || parser.getDepth() > outerDepth)) {
2866 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2867 continue;
2868 }
2869
2870 if (parser.getName().equals("meta-data")) {
2871 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2872 outInfo.metaData, outError)) == null) {
2873 return false;
2874 }
2875 } else {
2876 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002877 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002878 + parser.getName() + " at " + mArchiveSourcePath + " "
2879 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 XmlUtils.skipCurrentTag(parser);
2881 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002882 } else {
2883 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2884 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
2887 }
2888 return true;
2889 }
2890
2891 private Bundle parseMetaData(Resources res,
2892 XmlPullParser parser, AttributeSet attrs,
2893 Bundle data, String[] outError)
2894 throws XmlPullParserException, IOException {
2895
2896 TypedArray sa = res.obtainAttributes(attrs,
2897 com.android.internal.R.styleable.AndroidManifestMetaData);
2898
2899 if (data == null) {
2900 data = new Bundle();
2901 }
2902
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002903 String name = sa.getNonConfigurationString(
2904 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 if (name == null) {
2906 outError[0] = "<meta-data> requires an android:name attribute";
2907 sa.recycle();
2908 return null;
2909 }
2910
Dianne Hackborn854060a2009-07-09 18:14:31 -07002911 name = name.intern();
2912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 TypedValue v = sa.peekValue(
2914 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2915 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002916 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 data.putInt(name, v.resourceId);
2918 } else {
2919 v = sa.peekValue(
2920 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002921 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 if (v != null) {
2923 if (v.type == TypedValue.TYPE_STRING) {
2924 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002925 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2927 data.putBoolean(name, v.data != 0);
2928 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2929 && v.type <= TypedValue.TYPE_LAST_INT) {
2930 data.putInt(name, v.data);
2931 } else if (v.type == TypedValue.TYPE_FLOAT) {
2932 data.putFloat(name, v.getFloat());
2933 } else {
2934 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002935 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002936 + parser.getName() + " at " + mArchiveSourcePath + " "
2937 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 } else {
2939 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2940 data = null;
2941 }
2942 }
2943 } else {
2944 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2945 data = null;
2946 }
2947 }
2948
2949 sa.recycle();
2950
2951 XmlUtils.skipCurrentTag(parser);
2952
2953 return data;
2954 }
2955
Kenny Root05ca4c92011-09-15 10:36:25 -07002956 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2957 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2958 IOException {
2959 final TypedArray sa = res.obtainAttributes(attrs,
2960 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2961
2962 final String packageName = sa.getNonResourceString(
2963 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2964
2965 final String encodedPublicKey = sa.getNonResourceString(
2966 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2967
2968 sa.recycle();
2969
2970 if (packageName == null || packageName.length() == 0) {
2971 Slog.i(TAG, "verifier package name was null; skipping");
2972 return null;
2973 } else if (encodedPublicKey == null) {
2974 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2975 }
2976
2977 EncodedKeySpec keySpec;
2978 try {
2979 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2980 keySpec = new X509EncodedKeySpec(encoded);
2981 } catch (IllegalArgumentException e) {
2982 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2983 return null;
2984 }
2985
2986 /* First try the key as an RSA key. */
2987 try {
2988 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2989 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2990 return new VerifierInfo(packageName, publicKey);
2991 } catch (NoSuchAlgorithmException e) {
2992 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2993 return null;
2994 } catch (InvalidKeySpecException e) {
2995 // Not a RSA public key.
2996 }
2997
2998 /* Now try it as a DSA key. */
2999 try {
3000 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3001 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3002 return new VerifierInfo(packageName, publicKey);
3003 } catch (NoSuchAlgorithmException e) {
3004 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3005 return null;
3006 } catch (InvalidKeySpecException e) {
3007 // Not a DSA public key.
3008 }
3009
3010 return null;
3011 }
3012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 private static final String ANDROID_RESOURCES
3014 = "http://schemas.android.com/apk/res/android";
3015
3016 private boolean parseIntent(Resources res,
3017 XmlPullParser parser, AttributeSet attrs, int flags,
3018 IntentInfo outInfo, String[] outError, boolean isActivity)
3019 throws XmlPullParserException, IOException {
3020
3021 TypedArray sa = res.obtainAttributes(attrs,
3022 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3023
3024 int priority = sa.getInt(
3025 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 TypedValue v = sa.peekValue(
3029 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3030 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3031 outInfo.nonLocalizedLabel = v.coerceToString();
3032 }
3033
3034 outInfo.icon = sa.getResourceId(
3035 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003036
3037 outInfo.logo = sa.getResourceId(
3038 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039
3040 sa.recycle();
3041
3042 int outerDepth = parser.getDepth();
3043 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003044 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3045 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3046 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 continue;
3048 }
3049
3050 String nodeName = parser.getName();
3051 if (nodeName.equals("action")) {
3052 String value = attrs.getAttributeValue(
3053 ANDROID_RESOURCES, "name");
3054 if (value == null || value == "") {
3055 outError[0] = "No value supplied for <android:name>";
3056 return false;
3057 }
3058 XmlUtils.skipCurrentTag(parser);
3059
3060 outInfo.addAction(value);
3061 } else if (nodeName.equals("category")) {
3062 String value = attrs.getAttributeValue(
3063 ANDROID_RESOURCES, "name");
3064 if (value == null || value == "") {
3065 outError[0] = "No value supplied for <android:name>";
3066 return false;
3067 }
3068 XmlUtils.skipCurrentTag(parser);
3069
3070 outInfo.addCategory(value);
3071
3072 } else if (nodeName.equals("data")) {
3073 sa = res.obtainAttributes(attrs,
3074 com.android.internal.R.styleable.AndroidManifestData);
3075
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003076 String str = sa.getNonConfigurationString(
3077 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 if (str != null) {
3079 try {
3080 outInfo.addDataType(str);
3081 } catch (IntentFilter.MalformedMimeTypeException e) {
3082 outError[0] = e.toString();
3083 sa.recycle();
3084 return false;
3085 }
3086 }
3087
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003088 str = sa.getNonConfigurationString(
3089 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 if (str != null) {
3091 outInfo.addDataScheme(str);
3092 }
3093
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003094 String host = sa.getNonConfigurationString(
3095 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3096 String port = sa.getNonConfigurationString(
3097 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098 if (host != null) {
3099 outInfo.addDataAuthority(host, port);
3100 }
3101
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003102 str = sa.getNonConfigurationString(
3103 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 if (str != null) {
3105 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3106 }
3107
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003108 str = sa.getNonConfigurationString(
3109 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 if (str != null) {
3111 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3112 }
3113
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003114 str = sa.getNonConfigurationString(
3115 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116 if (str != null) {
3117 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3118 }
3119
3120 sa.recycle();
3121 XmlUtils.skipCurrentTag(parser);
3122 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003123 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003124 + parser.getName() + " at " + mArchiveSourcePath + " "
3125 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 XmlUtils.skipCurrentTag(parser);
3127 } else {
3128 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3129 return false;
3130 }
3131 }
3132
3133 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003134
3135 if (DEBUG_PARSER) {
3136 final StringBuilder cats = new StringBuilder("Intent d=");
3137 cats.append(outInfo.hasDefault);
3138 cats.append(", cat=");
3139
3140 final Iterator<String> it = outInfo.categoriesIterator();
3141 if (it != null) {
3142 while (it.hasNext()) {
3143 cats.append(' ');
3144 cats.append(it.next());
3145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003147 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 }
3149
3150 return true;
3151 }
3152
3153 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003154 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155
3156 // For now we only support one application per package.
3157 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3158
3159 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3160 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3161 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3162 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3163 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3164 public final ArrayList<Service> services = new ArrayList<Service>(0);
3165 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3166
3167 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003168 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169
Dianne Hackborn854060a2009-07-09 18:14:31 -07003170 public ArrayList<String> protectedBroadcasts;
3171
Dianne Hackborn49237342009-08-27 20:08:01 -07003172 public ArrayList<String> usesLibraries = null;
3173 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 public String[] usesLibraryFiles = null;
3175
Dianne Hackbornc1552392010-03-03 16:19:01 -08003176 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003177 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003178 public ArrayList<String> mAdoptPermissions = null;
3179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 // We store the application meta-data independently to avoid multiple unwanted references
3181 public Bundle mAppMetaData = null;
3182
3183 // If this is a 3rd party app, this is the path of the zip file.
3184 public String mPath;
3185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 // The version code declared for this package.
3187 public int mVersionCode;
3188
3189 // The version name declared for this package.
3190 public String mVersionName;
3191
3192 // The shared user id that this package wants to use.
3193 public String mSharedUserId;
3194
3195 // The shared user label that this package wants to use.
3196 public int mSharedUserLabel;
3197
3198 // Signatures that were read from the package.
3199 public Signature mSignatures[];
3200
3201 // For use by package manager service for quick lookup of
3202 // preferred up order.
3203 public int mPreferredOrder = 0;
3204
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003205 // For use by the package manager to keep track of the path to the
3206 // file an app came from.
3207 public String mScanPath;
3208
3209 // For use by package manager to keep track of where it has done dexopt.
3210 public boolean mDidDexOpt;
3211
Amith Yamasani13593602012-03-22 16:16:17 -07003212 // // User set enabled state.
3213 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3214 //
3215 // // Whether the package has been stopped.
3216 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 // Additional data supplied by callers.
3219 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003220
3221 // Whether an operation is currently pending on this package
3222 public boolean mOperationPending;
3223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 /*
3225 * Applications hardware preferences
3226 */
3227 public final ArrayList<ConfigurationInfo> configPreferences =
3228 new ArrayList<ConfigurationInfo>();
3229
Dianne Hackborn49237342009-08-27 20:08:01 -07003230 /*
3231 * Applications requested features
3232 */
3233 public ArrayList<FeatureInfo> reqFeatures = null;
3234
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003235 public int installLocation;
3236
Kenny Rootbcc954d2011-08-08 16:19:08 -07003237 /**
3238 * Digest suitable for comparing whether this package's manifest is the
3239 * same as another.
3240 */
3241 public ManifestDigest manifestDigest;
3242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 public Package(String _name) {
3244 packageName = _name;
3245 applicationInfo.packageName = _name;
3246 applicationInfo.uid = -1;
3247 }
3248
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003249 public void setPackageName(String newName) {
3250 packageName = newName;
3251 applicationInfo.packageName = newName;
3252 for (int i=permissions.size()-1; i>=0; i--) {
3253 permissions.get(i).setPackageName(newName);
3254 }
3255 for (int i=permissionGroups.size()-1; i>=0; i--) {
3256 permissionGroups.get(i).setPackageName(newName);
3257 }
3258 for (int i=activities.size()-1; i>=0; i--) {
3259 activities.get(i).setPackageName(newName);
3260 }
3261 for (int i=receivers.size()-1; i>=0; i--) {
3262 receivers.get(i).setPackageName(newName);
3263 }
3264 for (int i=providers.size()-1; i>=0; i--) {
3265 providers.get(i).setPackageName(newName);
3266 }
3267 for (int i=services.size()-1; i>=0; i--) {
3268 services.get(i).setPackageName(newName);
3269 }
3270 for (int i=instrumentation.size()-1; i>=0; i--) {
3271 instrumentation.get(i).setPackageName(newName);
3272 }
3273 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003274
3275 public boolean hasComponentClassName(String name) {
3276 for (int i=activities.size()-1; i>=0; i--) {
3277 if (name.equals(activities.get(i).className)) {
3278 return true;
3279 }
3280 }
3281 for (int i=receivers.size()-1; i>=0; i--) {
3282 if (name.equals(receivers.get(i).className)) {
3283 return true;
3284 }
3285 }
3286 for (int i=providers.size()-1; i>=0; i--) {
3287 if (name.equals(providers.get(i).className)) {
3288 return true;
3289 }
3290 }
3291 for (int i=services.size()-1; i>=0; i--) {
3292 if (name.equals(services.get(i).className)) {
3293 return true;
3294 }
3295 }
3296 for (int i=instrumentation.size()-1; i>=0; i--) {
3297 if (name.equals(instrumentation.get(i).className)) {
3298 return true;
3299 }
3300 }
3301 return false;
3302 }
3303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 public String toString() {
3305 return "Package{"
3306 + Integer.toHexString(System.identityHashCode(this))
3307 + " " + packageName + "}";
3308 }
3309 }
3310
3311 public static class Component<II extends IntentInfo> {
3312 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003313 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003314 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 public Bundle metaData;
3316
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003317 ComponentName componentName;
3318 String componentShortName;
3319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 public Component(Package _owner) {
3321 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003322 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003323 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003324 }
3325
3326 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3327 owner = args.owner;
3328 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003329 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003330 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003331 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003332 args.outError[0] = args.tag + " does not specify android:name";
3333 return;
3334 }
3335
3336 outInfo.name
3337 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3338 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003339 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003340 args.outError[0] = args.tag + " does not have valid android:name";
3341 return;
3342 }
3343
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003344 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003345
3346 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3347 if (iconVal != 0) {
3348 outInfo.icon = iconVal;
3349 outInfo.nonLocalizedLabel = null;
3350 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003351
3352 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3353 if (logoVal != 0) {
3354 outInfo.logo = logoVal;
3355 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003356
3357 TypedValue v = args.sa.peekValue(args.labelRes);
3358 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3359 outInfo.nonLocalizedLabel = v.coerceToString();
3360 }
3361
3362 outInfo.packageName = owner.packageName;
3363 }
3364
3365 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3366 this(args, (PackageItemInfo)outInfo);
3367 if (args.outError[0] != null) {
3368 return;
3369 }
3370
3371 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003372 CharSequence pname;
3373 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3374 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3375 } else {
3376 // Some older apps have been seen to use a resource reference
3377 // here that on older builds was ignored (with a warning). We
3378 // need to continue to do this for them so they don't break.
3379 pname = args.sa.getNonResourceString(args.processRes);
3380 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003381 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003382 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003383 args.flags, args.sepProcesses, args.outError);
3384 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003385
3386 if (args.descriptionRes != 0) {
3387 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3388 }
3389
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003390 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 }
3392
3393 public Component(Component<II> clone) {
3394 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003395 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003396 className = clone.className;
3397 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003398 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003399 }
3400
3401 public ComponentName getComponentName() {
3402 if (componentName != null) {
3403 return componentName;
3404 }
3405 if (className != null) {
3406 componentName = new ComponentName(owner.applicationInfo.packageName,
3407 className);
3408 }
3409 return componentName;
3410 }
3411
3412 public String getComponentShortName() {
3413 if (componentShortName != null) {
3414 return componentShortName;
3415 }
3416 ComponentName component = getComponentName();
3417 if (component != null) {
3418 componentShortName = component.flattenToShortString();
3419 }
3420 return componentShortName;
3421 }
3422
3423 public void setPackageName(String packageName) {
3424 componentName = null;
3425 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 }
3427 }
3428
3429 public final static class Permission extends Component<IntentInfo> {
3430 public final PermissionInfo info;
3431 public boolean tree;
3432 public PermissionGroup group;
3433
3434 public Permission(Package _owner) {
3435 super(_owner);
3436 info = new PermissionInfo();
3437 }
3438
3439 public Permission(Package _owner, PermissionInfo _info) {
3440 super(_owner);
3441 info = _info;
3442 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003443
3444 public void setPackageName(String packageName) {
3445 super.setPackageName(packageName);
3446 info.packageName = packageName;
3447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448
3449 public String toString() {
3450 return "Permission{"
3451 + Integer.toHexString(System.identityHashCode(this))
3452 + " " + info.name + "}";
3453 }
3454 }
3455
3456 public final static class PermissionGroup extends Component<IntentInfo> {
3457 public final PermissionGroupInfo info;
3458
3459 public PermissionGroup(Package _owner) {
3460 super(_owner);
3461 info = new PermissionGroupInfo();
3462 }
3463
3464 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3465 super(_owner);
3466 info = _info;
3467 }
3468
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003469 public void setPackageName(String packageName) {
3470 super.setPackageName(packageName);
3471 info.packageName = packageName;
3472 }
3473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 public String toString() {
3475 return "PermissionGroup{"
3476 + Integer.toHexString(System.identityHashCode(this))
3477 + " " + info.name + "}";
3478 }
3479 }
3480
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003481 private static boolean copyNeeded(int flags, Package p,
3482 PackageUserState state, Bundle metaData, int userId) {
3483 if (userId != 0) {
3484 // We always need to copy for other users, since we need
3485 // to fix up the uid.
3486 return true;
3487 }
3488 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3489 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003490 if (p.applicationInfo.enabled != enabled) {
3491 return true;
3492 }
3493 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003494 if (!state.installed) {
3495 return true;
3496 }
3497 if (state.stopped) {
3498 return true;
3499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 if ((flags & PackageManager.GET_META_DATA) != 0
3501 && (metaData != null || p.mAppMetaData != null)) {
3502 return true;
3503 }
3504 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3505 && p.usesLibraryFiles != null) {
3506 return true;
3507 }
3508 return false;
3509 }
3510
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003511 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3512 PackageUserState state) {
3513 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003514 }
3515
Amith Yamasani13593602012-03-22 16:16:17 -07003516 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003517 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003519 if (!checkUseInstalled(flags, state)) {
3520 return null;
3521 }
3522 if (!copyNeeded(flags, p, state, null, userId)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003523 // CompatibilityMode is global state. It's safe to modify the instance
3524 // of the package.
3525 if (!sCompatibilityModeEnabled) {
3526 p.applicationInfo.disableCompatibilityMode();
3527 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003528 // Make sure we report as installed. Also safe to do, since the
3529 // default state should be installed (we will always copy if we
3530 // need to report it is not installed).
3531 p.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
3532 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003533 p.applicationInfo.enabled = true;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003534 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3535 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003536 p.applicationInfo.enabled = false;
3537 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003538 p.applicationInfo.enabledSetting = state.enabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 return p.applicationInfo;
3540 }
3541
3542 // Make shallow copy so we can store the metadata/libraries safely
3543 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003544 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003545 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003546 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 if ((flags & PackageManager.GET_META_DATA) != 0) {
3549 ai.metaData = p.mAppMetaData;
3550 }
3551 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3552 ai.sharedLibraryFiles = p.usesLibraryFiles;
3553 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003554 if (!sCompatibilityModeEnabled) {
3555 ai.disableCompatibilityMode();
3556 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003557 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003558 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003559 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003560 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003561 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003562 if (state.installed) {
3563 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3564 } else {
3565 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3566 }
3567 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003568 ai.enabled = true;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003569 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3570 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003571 ai.enabled = false;
3572 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003573 ai.enabledSetting = state.enabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 return ai;
3575 }
3576
3577 public static final PermissionInfo generatePermissionInfo(
3578 Permission p, int flags) {
3579 if (p == null) return null;
3580 if ((flags&PackageManager.GET_META_DATA) == 0) {
3581 return p.info;
3582 }
3583 PermissionInfo pi = new PermissionInfo(p.info);
3584 pi.metaData = p.metaData;
3585 return pi;
3586 }
3587
3588 public static final PermissionGroupInfo generatePermissionGroupInfo(
3589 PermissionGroup pg, int flags) {
3590 if (pg == null) return null;
3591 if ((flags&PackageManager.GET_META_DATA) == 0) {
3592 return pg.info;
3593 }
3594 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3595 pgi.metaData = pg.metaData;
3596 return pgi;
3597 }
3598
3599 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003600 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003602 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3603 super(args, _info);
3604 info = _info;
3605 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003607
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003608 public void setPackageName(String packageName) {
3609 super.setPackageName(packageName);
3610 info.packageName = packageName;
3611 }
3612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 public String toString() {
3614 return "Activity{"
3615 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003616 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 }
3618 }
3619
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003620 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3621 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003623 if (!checkUseInstalled(flags, state)) {
3624 return null;
3625 }
3626 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 return a.info;
3628 }
3629 // Make shallow copies so we can store the metadata safely
3630 ActivityInfo ai = new ActivityInfo(a.info);
3631 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003632 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 return ai;
3634 }
3635
3636 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003637 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003639 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3640 super(args, _info);
3641 info = _info;
3642 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003644
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003645 public void setPackageName(String packageName) {
3646 super.setPackageName(packageName);
3647 info.packageName = packageName;
3648 }
3649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 public String toString() {
3651 return "Service{"
3652 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003653 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 }
3655 }
3656
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003657 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3658 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003660 if (!checkUseInstalled(flags, state)) {
3661 return null;
3662 }
3663 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 return s.info;
3665 }
3666 // Make shallow copies so we can store the metadata safely
3667 ServiceInfo si = new ServiceInfo(s.info);
3668 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003669 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 return si;
3671 }
3672
3673 public final static class Provider extends Component {
3674 public final ProviderInfo info;
3675 public boolean syncable;
3676
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003677 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3678 super(args, _info);
3679 info = _info;
3680 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 syncable = false;
3682 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 public Provider(Provider existingProvider) {
3685 super(existingProvider);
3686 this.info = existingProvider.info;
3687 this.syncable = existingProvider.syncable;
3688 }
3689
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003690 public void setPackageName(String packageName) {
3691 super.setPackageName(packageName);
3692 info.packageName = packageName;
3693 }
3694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 public String toString() {
3696 return "Provider{"
3697 + Integer.toHexString(System.identityHashCode(this))
3698 + " " + info.name + "}";
3699 }
3700 }
3701
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003702 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3703 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003705 if (!checkUseInstalled(flags, state)) {
3706 return null;
3707 }
3708 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003710 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 return p.info;
3712 }
3713 // Make shallow copies so we can store the metadata safely
3714 ProviderInfo pi = new ProviderInfo(p.info);
3715 pi.metaData = p.metaData;
3716 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3717 pi.uriPermissionPatterns = null;
3718 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003719 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 return pi;
3721 }
3722
3723 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003724 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003726 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3727 super(args, _info);
3728 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003730
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003731 public void setPackageName(String packageName) {
3732 super.setPackageName(packageName);
3733 info.packageName = packageName;
3734 }
3735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 public String toString() {
3737 return "Instrumentation{"
3738 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003739 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 }
3741 }
3742
3743 public static final InstrumentationInfo generateInstrumentationInfo(
3744 Instrumentation i, int flags) {
3745 if (i == null) return null;
3746 if ((flags&PackageManager.GET_META_DATA) == 0) {
3747 return i.info;
3748 }
3749 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3750 ii.metaData = i.metaData;
3751 return ii;
3752 }
3753
3754 public static class IntentInfo extends IntentFilter {
3755 public boolean hasDefault;
3756 public int labelRes;
3757 public CharSequence nonLocalizedLabel;
3758 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003759 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 }
3761
3762 public final static class ActivityIntentInfo extends IntentInfo {
3763 public final Activity activity;
3764
3765 public ActivityIntentInfo(Activity _activity) {
3766 activity = _activity;
3767 }
3768
3769 public String toString() {
3770 return "ActivityIntentInfo{"
3771 + Integer.toHexString(System.identityHashCode(this))
3772 + " " + activity.info.name + "}";
3773 }
3774 }
3775
3776 public final static class ServiceIntentInfo extends IntentInfo {
3777 public final Service service;
3778
3779 public ServiceIntentInfo(Service _service) {
3780 service = _service;
3781 }
3782
3783 public String toString() {
3784 return "ServiceIntentInfo{"
3785 + Integer.toHexString(System.identityHashCode(this))
3786 + " " + service.info.name + "}";
3787 }
3788 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003789
3790 /**
3791 * @hide
3792 */
3793 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3794 sCompatibilityModeEnabled = compatibilityModeEnabled;
3795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796}