blob: 237f5c545601fd555542f9106ec7f5cecdd0d289 [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 Hackborn4034bc42012-06-01 12:45:49 -07001490 perm.info.flags = 0;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001491 perm.info.priority = sa.getInt(
1492 com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
Dianne Hackborn99222d22012-05-06 16:30:15 -07001493 if (perm.info.priority > 0 && (flags&PARSE_IS_SYSTEM) == 0) {
Dianne Hackbornfd5015b2012-04-30 16:33:56 -07001494 perm.info.priority = 0;
1495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496
1497 sa.recycle();
1498
1499 if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm,
1500 outError)) {
1501 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1502 return null;
1503 }
1504
1505 owner.permissionGroups.add(perm);
1506
1507 return perm;
1508 }
1509
1510 private Permission parsePermission(Package owner, Resources res,
1511 XmlPullParser parser, AttributeSet attrs, String[] outError)
1512 throws XmlPullParserException, IOException {
1513 Permission perm = new Permission(owner);
1514
1515 TypedArray sa = res.obtainAttributes(attrs,
1516 com.android.internal.R.styleable.AndroidManifestPermission);
1517
1518 if (!parsePackageItemInfo(owner, perm.info, outError,
1519 "<permission>", sa,
1520 com.android.internal.R.styleable.AndroidManifestPermission_name,
1521 com.android.internal.R.styleable.AndroidManifestPermission_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001522 com.android.internal.R.styleable.AndroidManifestPermission_icon,
1523 com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 sa.recycle();
1525 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1526 return null;
1527 }
1528
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001529 // Note: don't allow this value to be a reference to a resource
1530 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 perm.info.group = sa.getNonResourceString(
1532 com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
1533 if (perm.info.group != null) {
1534 perm.info.group = perm.info.group.intern();
1535 }
1536
1537 perm.info.descriptionRes = sa.getResourceId(
1538 com.android.internal.R.styleable.AndroidManifestPermission_description,
1539 0);
1540
1541 perm.info.protectionLevel = sa.getInt(
1542 com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
1543 PermissionInfo.PROTECTION_NORMAL);
1544
1545 sa.recycle();
Dianne Hackborne639da72012-02-21 15:11:13 -08001546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 if (perm.info.protectionLevel == -1) {
1548 outError[0] = "<permission> does not specify protectionLevel";
1549 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1550 return null;
1551 }
Dianne Hackborne639da72012-02-21 15:11:13 -08001552
1553 perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);
1554
1555 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
1556 if ((perm.info.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE) !=
1557 PermissionInfo.PROTECTION_SIGNATURE) {
1558 outError[0] = "<permission> protectionLevel specifies a flag but is "
1559 + "not based on signature type";
1560 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1561 return null;
1562 }
1563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564
1565 if (!parseAllMetaData(res, parser, attrs, "<permission>", perm,
1566 outError)) {
1567 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1568 return null;
1569 }
1570
1571 owner.permissions.add(perm);
1572
1573 return perm;
1574 }
1575
1576 private Permission parsePermissionTree(Package owner, Resources res,
1577 XmlPullParser parser, AttributeSet attrs, String[] outError)
1578 throws XmlPullParserException, IOException {
1579 Permission perm = new Permission(owner);
1580
1581 TypedArray sa = res.obtainAttributes(attrs,
1582 com.android.internal.R.styleable.AndroidManifestPermissionTree);
1583
1584 if (!parsePackageItemInfo(owner, perm.info, outError,
1585 "<permission-tree>", sa,
1586 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
1587 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001588 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
1589 com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 sa.recycle();
1591 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1592 return null;
1593 }
1594
1595 sa.recycle();
1596
1597 int index = perm.info.name.indexOf('.');
1598 if (index > 0) {
1599 index = perm.info.name.indexOf('.', index+1);
1600 }
1601 if (index < 0) {
1602 outError[0] = "<permission-tree> name has less than three segments: "
1603 + perm.info.name;
1604 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1605 return null;
1606 }
1607
1608 perm.info.descriptionRes = 0;
1609 perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
1610 perm.tree = true;
1611
1612 if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm,
1613 outError)) {
1614 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1615 return null;
1616 }
1617
1618 owner.permissions.add(perm);
1619
1620 return perm;
1621 }
1622
1623 private Instrumentation parseInstrumentation(Package owner, Resources res,
1624 XmlPullParser parser, AttributeSet attrs, String[] outError)
1625 throws XmlPullParserException, IOException {
1626 TypedArray sa = res.obtainAttributes(attrs,
1627 com.android.internal.R.styleable.AndroidManifestInstrumentation);
1628
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001629 if (mParseInstrumentationArgs == null) {
1630 mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError,
1631 com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
1632 com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
Adam Powell81cd2e92010-04-21 16:35:18 -07001633 com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
1634 com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001635 mParseInstrumentationArgs.tag = "<instrumentation>";
1636 }
1637
1638 mParseInstrumentationArgs.sa = sa;
1639
1640 Instrumentation a = new Instrumentation(mParseInstrumentationArgs,
1641 new InstrumentationInfo());
1642 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 sa.recycle();
1644 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1645 return null;
1646 }
1647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001649 // Note: don't allow this value to be a reference to a resource
1650 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 str = sa.getNonResourceString(
1652 com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage);
1653 a.info.targetPackage = str != null ? str.intern() : null;
1654
1655 a.info.handleProfiling = sa.getBoolean(
1656 com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling,
1657 false);
1658
1659 a.info.functionalTest = sa.getBoolean(
1660 com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest,
1661 false);
1662
1663 sa.recycle();
1664
1665 if (a.info.targetPackage == null) {
1666 outError[0] = "<instrumentation> does not specify targetPackage";
1667 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1668 return null;
1669 }
1670
1671 if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a,
1672 outError)) {
1673 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1674 return null;
1675 }
1676
1677 owner.instrumentation.add(a);
1678
1679 return a;
1680 }
1681
1682 private boolean parseApplication(Package owner, Resources res,
1683 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
1684 throws XmlPullParserException, IOException {
1685 final ApplicationInfo ai = owner.applicationInfo;
1686 final String pkgName = owner.applicationInfo.packageName;
1687
1688 TypedArray sa = res.obtainAttributes(attrs,
1689 com.android.internal.R.styleable.AndroidManifestApplication);
1690
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001691 String name = sa.getNonConfigurationString(
1692 com.android.internal.R.styleable.AndroidManifestApplication_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 if (name != null) {
1694 ai.className = buildClassName(pkgName, name, outError);
1695 if (ai.className == null) {
1696 sa.recycle();
1697 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1698 return false;
1699 }
1700 }
1701
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001702 String manageSpaceActivity = sa.getNonConfigurationString(
1703 com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 if (manageSpaceActivity != null) {
1705 ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity,
1706 outError);
1707 }
1708
Christopher Tate181fafa2009-05-14 11:12:14 -07001709 boolean allowBackup = sa.getBoolean(
1710 com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true);
1711 if (allowBackup) {
1712 ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001713
Christopher Tate3de55bc2010-03-12 17:28:08 -08001714 // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant
1715 // if backup is possible for the given application.
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001716 String backupAgent = sa.getNonConfigurationString(
1717 com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0);
Christopher Tate181fafa2009-05-14 11:12:14 -07001718 if (backupAgent != null) {
1719 ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
Kenny Rootd2d29252011-08-08 11:27:57 -07001720 if (DEBUG_BACKUP) {
1721 Slog.v(TAG, "android:backupAgent = " + ai.backupAgentName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001722 + " from " + pkgName + "+" + backupAgent);
1723 }
Christopher Tate5e1ab332009-09-01 20:32:49 -07001724
1725 if (sa.getBoolean(
1726 com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
1727 true)) {
1728 ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
1729 }
1730 if (sa.getBoolean(
Christopher Tate3dda5182010-02-24 16:06:18 -08001731 com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
1732 false)) {
1733 ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
1734 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001735 }
1736 }
Christopher Tate4a627c72011-04-01 14:43:32 -07001737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 TypedValue v = sa.peekValue(
1739 com.android.internal.R.styleable.AndroidManifestApplication_label);
1740 if (v != null && (ai.labelRes=v.resourceId) == 0) {
1741 ai.nonLocalizedLabel = v.coerceToString();
1742 }
1743
1744 ai.icon = sa.getResourceId(
1745 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07001746 ai.logo = sa.getResourceId(
1747 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 ai.theme = sa.getResourceId(
Dianne Hackbornb35cd542011-01-04 21:30:53 -08001749 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 ai.descriptionRes = sa.getResourceId(
1751 com.android.internal.R.styleable.AndroidManifestApplication_description, 0);
1752
1753 if ((flags&PARSE_IS_SYSTEM) != 0) {
1754 if (sa.getBoolean(
1755 com.android.internal.R.styleable.AndroidManifestApplication_persistent,
1756 false)) {
1757 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
1758 }
1759 }
1760
1761 if (sa.getBoolean(
1762 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
1763 false)) {
1764 ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
1765 }
1766
1767 if (sa.getBoolean(
Ben Chengef3f5dd2010-03-29 15:47:26 -07001768 com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode,
Ben Cheng23085b72010-02-08 16:06:32 -08001769 false)) {
1770 ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
1771 }
1772
Romain Guy529b60a2010-08-03 18:05:47 -07001773 boolean hardwareAccelerated = sa.getBoolean(
Romain Guy812ccbe2010-06-01 14:07:24 -07001774 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
Dianne Hackborn2d6833b2011-06-24 16:04:19 -07001775 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Romain Guy812ccbe2010-06-01 14:07:24 -07001776
1777 if (sa.getBoolean(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
1779 true)) {
1780 ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
1781 }
1782
1783 if (sa.getBoolean(
1784 com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
1785 false)) {
1786 ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
1787 }
1788
1789 if (sa.getBoolean(
1790 com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData,
1791 true)) {
1792 ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
1793 }
1794
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001795 if (sa.getBoolean(
1796 com.android.internal.R.styleable.AndroidManifestApplication_testOnly,
Dianne Hackborne7fe35b2009-05-13 10:53:41 -07001797 false)) {
Dianne Hackbornade3eca2009-05-11 18:54:45 -07001798 ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
1799 }
1800
Jason parksa3cdaa52011-01-13 14:15:43 -06001801 if (sa.getBoolean(
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001802 com.android.internal.R.styleable.AndroidManifestApplication_largeHeap,
Jason parksa3cdaa52011-01-13 14:15:43 -06001803 false)) {
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001804 ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
Jason parksa3cdaa52011-01-13 14:15:43 -06001805 }
1806
Fabrice Di Meglio59dfce82012-04-02 16:17:20 -07001807 if (sa.getBoolean(
1808 com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
1809 false /* default is no RTL support*/)) {
1810 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
1811 }
1812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001814 str = sa.getNonConfigurationString(
1815 com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 ai.permission = (str != null && str.length() > 0) ? str.intern() : null;
1817
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001818 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1819 str = sa.getNonConfigurationString(
1820 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0);
1821 } else {
1822 // Some older apps have been seen to use a resource reference
1823 // here that on older builds was ignored (with a warning). We
1824 // need to continue to do this for them so they don't break.
1825 str = sa.getNonResourceString(
1826 com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
1827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName,
1829 str, outError);
1830
1831 if (outError[0] == null) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07001832 CharSequence pname;
1833 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
1834 pname = sa.getNonConfigurationString(
1835 com.android.internal.R.styleable.AndroidManifestApplication_process, 0);
1836 } else {
1837 // Some older apps have been seen to use a resource reference
1838 // here that on older builds was ignored (with a warning). We
1839 // need to continue to do this for them so they don't break.
1840 pname = sa.getNonResourceString(
1841 com.android.internal.R.styleable.AndroidManifestApplication_process);
1842 }
1843 ai.processName = buildProcessName(ai.packageName, null, pname,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 flags, mSeparateProcesses, outError);
1845
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001846 ai.enabled = sa.getBoolean(
1847 com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);
Dianne Hackborn860755f2010-06-03 18:47:52 -07001848
Dianne Hackborn02486b12010-08-26 14:18:37 -07001849 if (false) {
1850 if (sa.getBoolean(
1851 com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
1852 false)) {
Dianne Hackborn54e570f2010-10-04 18:32:32 -07001853 ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE;
Dianne Hackborn02486b12010-08-26 14:18:37 -07001854
1855 // A heavy-weight application can not be in a custom process.
1856 // We can do direct compare because we intern all strings.
1857 if (ai.processName != null && ai.processName != ai.packageName) {
1858 outError[0] = "cantSaveState applications can not use custom processes";
1859 }
Dianne Hackborn860755f2010-06-03 18:47:52 -07001860 }
1861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 }
1863
Adam Powell269248d2011-08-02 10:26:54 -07001864 ai.uiOptions = sa.getInt(
1865 com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);
1866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 sa.recycle();
1868
1869 if (outError[0] != null) {
1870 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1871 return false;
1872 }
1873
1874 final int innerDepth = parser.getDepth();
1875
1876 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07001877 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
1878 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1879 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 continue;
1881 }
1882
1883 String tagName = parser.getName();
1884 if (tagName.equals("activity")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001885 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
1886 hardwareAccelerated);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 if (a == null) {
1888 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1889 return false;
1890 }
1891
1892 owner.activities.add(a);
1893
1894 } else if (tagName.equals("receiver")) {
Romain Guy529b60a2010-08-03 18:05:47 -07001895 Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 if (a == null) {
1897 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1898 return false;
1899 }
1900
1901 owner.receivers.add(a);
1902
1903 } else if (tagName.equals("service")) {
1904 Service s = parseService(owner, res, parser, attrs, flags, outError);
1905 if (s == null) {
1906 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1907 return false;
1908 }
1909
1910 owner.services.add(s);
1911
1912 } else if (tagName.equals("provider")) {
1913 Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
1914 if (p == null) {
1915 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1916 return false;
1917 }
1918
1919 owner.providers.add(p);
1920
1921 } else if (tagName.equals("activity-alias")) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001922 Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 if (a == null) {
1924 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1925 return false;
1926 }
1927
1928 owner.activities.add(a);
1929
1930 } else if (parser.getName().equals("meta-data")) {
1931 // note: application meta-data is stored off to the side, so it can
1932 // remain null in the primary copy (we like to avoid extra copies because
1933 // it can be large)
1934 if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
1935 outError)) == null) {
1936 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1937 return false;
1938 }
1939
1940 } else if (tagName.equals("uses-library")) {
1941 sa = res.obtainAttributes(attrs,
1942 com.android.internal.R.styleable.AndroidManifestUsesLibrary);
1943
Dianne Hackborncf244ad2010-03-09 15:00:30 -08001944 // Note: don't allow this value to be a reference to a resource
1945 // that may change.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 String lname = sa.getNonResourceString(
1947 com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
Dianne Hackborn49237342009-08-27 20:08:01 -07001948 boolean req = sa.getBoolean(
1949 com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
1950 true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951
1952 sa.recycle();
1953
Dianne Hackborn49237342009-08-27 20:08:01 -07001954 if (lname != null) {
1955 if (req) {
1956 if (owner.usesLibraries == null) {
1957 owner.usesLibraries = new ArrayList<String>();
1958 }
1959 if (!owner.usesLibraries.contains(lname)) {
1960 owner.usesLibraries.add(lname.intern());
1961 }
1962 } else {
1963 if (owner.usesOptionalLibraries == null) {
1964 owner.usesOptionalLibraries = new ArrayList<String>();
1965 }
1966 if (!owner.usesOptionalLibraries.contains(lname)) {
1967 owner.usesOptionalLibraries.add(lname.intern());
1968 }
1969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 }
1971
1972 XmlUtils.skipCurrentTag(parser);
1973
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001974 } else if (tagName.equals("uses-package")) {
1975 // Dependencies for app installers; we don't currently try to
1976 // enforce this.
1977 XmlUtils.skipCurrentTag(parser);
1978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 } else {
1980 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07001981 Slog.w(TAG, "Unknown element under <application>: " + tagName
Dianne Hackborna33e3f72009-09-29 17:28:24 -07001982 + " at " + mArchiveSourcePath + " "
1983 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 XmlUtils.skipCurrentTag(parser);
1985 continue;
1986 } else {
1987 outError[0] = "Bad element under <application>: " + tagName;
1988 mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
1989 return false;
1990 }
1991 }
1992 }
1993
1994 return true;
1995 }
1996
1997 private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
1998 String[] outError, String tag, TypedArray sa,
Adam Powell81cd2e92010-04-21 16:35:18 -07001999 int nameRes, int labelRes, int iconRes, int logoRes) {
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002000 String name = sa.getNonConfigurationString(nameRes, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 if (name == null) {
2002 outError[0] = tag + " does not specify android:name";
2003 return false;
2004 }
2005
2006 outInfo.name
2007 = buildClassName(owner.applicationInfo.packageName, name, outError);
2008 if (outInfo.name == null) {
2009 return false;
2010 }
2011
2012 int iconVal = sa.getResourceId(iconRes, 0);
2013 if (iconVal != 0) {
2014 outInfo.icon = iconVal;
2015 outInfo.nonLocalizedLabel = null;
2016 }
Adam Powell81cd2e92010-04-21 16:35:18 -07002017
2018 int logoVal = sa.getResourceId(logoRes, 0);
2019 if (logoVal != 0) {
2020 outInfo.logo = logoVal;
2021 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022
2023 TypedValue v = sa.peekValue(labelRes);
2024 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
2025 outInfo.nonLocalizedLabel = v.coerceToString();
2026 }
2027
2028 outInfo.packageName = owner.packageName;
2029
2030 return true;
2031 }
2032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 private Activity parseActivity(Package owner, Resources res,
2034 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError,
Romain Guy529b60a2010-08-03 18:05:47 -07002035 boolean receiver, boolean hardwareAccelerated)
2036 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 TypedArray sa = res.obtainAttributes(attrs,
2038 com.android.internal.R.styleable.AndroidManifestActivity);
2039
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002040 if (mParseActivityArgs == null) {
2041 mParseActivityArgs = new ParseComponentArgs(owner, outError,
2042 com.android.internal.R.styleable.AndroidManifestActivity_name,
2043 com.android.internal.R.styleable.AndroidManifestActivity_label,
2044 com.android.internal.R.styleable.AndroidManifestActivity_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002045 com.android.internal.R.styleable.AndroidManifestActivity_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002046 mSeparateProcesses,
2047 com.android.internal.R.styleable.AndroidManifestActivity_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002048 com.android.internal.R.styleable.AndroidManifestActivity_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002049 com.android.internal.R.styleable.AndroidManifestActivity_enabled);
2050 }
2051
2052 mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
2053 mParseActivityArgs.sa = sa;
2054 mParseActivityArgs.flags = flags;
2055
2056 Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
2057 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002058 sa.recycle();
2059 return null;
2060 }
2061
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002062 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 com.android.internal.R.styleable.AndroidManifestActivity_exported);
2064 if (setExported) {
2065 a.info.exported = sa.getBoolean(
2066 com.android.internal.R.styleable.AndroidManifestActivity_exported, false);
2067 }
2068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 a.info.theme = sa.getResourceId(
2070 com.android.internal.R.styleable.AndroidManifestActivity_theme, 0);
2071
Adam Powell269248d2011-08-02 10:26:54 -07002072 a.info.uiOptions = sa.getInt(
2073 com.android.internal.R.styleable.AndroidManifestActivity_uiOptions,
2074 a.info.applicationInfo.uiOptions);
2075
Adam Powelldd8fab22012-03-22 17:47:27 -07002076 String parentName = sa.getNonConfigurationString(
2077 com.android.internal.R.styleable.AndroidManifestActivity_parentActivityName, 0);
2078 if (parentName != null) {
2079 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2080 if (outError[0] == null) {
2081 a.info.parentActivityName = parentClassName;
2082 } else {
2083 Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " +
2084 parentName);
2085 outError[0] = null;
2086 }
2087 }
2088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002090 str = sa.getNonConfigurationString(
2091 com.android.internal.R.styleable.AndroidManifestActivity_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 if (str == null) {
2093 a.info.permission = owner.applicationInfo.permission;
2094 } else {
2095 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2096 }
2097
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002098 str = sa.getNonConfigurationString(
2099 com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
2101 owner.applicationInfo.taskAffinity, str, outError);
2102
2103 a.info.flags = 0;
2104 if (sa.getBoolean(
2105 com.android.internal.R.styleable.AndroidManifestActivity_multiprocess,
2106 false)) {
2107 a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
2108 }
2109
2110 if (sa.getBoolean(
2111 com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch,
2112 false)) {
2113 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
2114 }
2115
2116 if (sa.getBoolean(
2117 com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch,
2118 false)) {
2119 a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
2120 }
2121
2122 if (sa.getBoolean(
2123 com.android.internal.R.styleable.AndroidManifestActivity_noHistory,
2124 false)) {
2125 a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
2126 }
2127
2128 if (sa.getBoolean(
2129 com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState,
2130 false)) {
2131 a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
2132 }
2133
2134 if (sa.getBoolean(
2135 com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded,
2136 false)) {
2137 a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
2138 }
2139
2140 if (sa.getBoolean(
2141 com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents,
2142 false)) {
2143 a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
2144 }
2145
2146 if (sa.getBoolean(
2147 com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting,
2148 (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
2149 a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
2150 }
2151
Dianne Hackbornffa42482009-09-23 22:20:11 -07002152 if (sa.getBoolean(
2153 com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs,
2154 false)) {
2155 a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
2156 }
2157
Daniel Sandler613dde42010-06-21 13:46:39 -04002158 if (sa.getBoolean(
2159 com.android.internal.R.styleable.AndroidManifestActivity_immersive,
2160 false)) {
2161 a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
2162 }
Romain Guy529b60a2010-08-03 18:05:47 -07002163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 if (!receiver) {
Romain Guy529b60a2010-08-03 18:05:47 -07002165 if (sa.getBoolean(
2166 com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated,
2167 hardwareAccelerated)) {
2168 a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
2169 }
2170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 a.info.launchMode = sa.getInt(
2172 com.android.internal.R.styleable.AndroidManifestActivity_launchMode,
2173 ActivityInfo.LAUNCH_MULTIPLE);
2174 a.info.screenOrientation = sa.getInt(
2175 com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation,
2176 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2177 a.info.configChanges = sa.getInt(
2178 com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
2179 0);
2180 a.info.softInputMode = sa.getInt(
2181 com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
2182 0);
2183 } else {
2184 a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
2185 a.info.configChanges = 0;
2186 }
2187
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002188 if (receiver) {
2189 if (sa.getBoolean(
2190 com.android.internal.R.styleable.AndroidManifestActivity_singleUser,
2191 false)) {
2192 a.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2193 if (a.info.exported) {
2194 Slog.w(TAG, "Activity exported request ignored due to singleUser: "
2195 + a.className + " at " + mArchiveSourcePath + " "
2196 + parser.getPositionDescription());
2197 a.info.exported = false;
2198 }
2199 setExported = true;
2200 }
2201 }
2202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 sa.recycle();
2204
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002205 if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002206 // A heavy-weight application can not have receives in its main process
2207 // We can do direct compare because we intern all strings.
2208 if (a.info.processName == owner.packageName) {
2209 outError[0] = "Heavy-weight applications can not have receivers in main process";
2210 }
2211 }
2212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 if (outError[0] != null) {
2214 return null;
2215 }
2216
2217 int outerDepth = parser.getDepth();
2218 int type;
2219 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2220 && (type != XmlPullParser.END_TAG
2221 || parser.getDepth() > outerDepth)) {
2222 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2223 continue;
2224 }
2225
2226 if (parser.getName().equals("intent-filter")) {
2227 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2228 if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) {
2229 return null;
2230 }
2231 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002232 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002233 + mArchiveSourcePath + " "
2234 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 } else {
2236 a.intents.add(intent);
2237 }
2238 } else if (parser.getName().equals("meta-data")) {
2239 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2240 outError)) == null) {
2241 return null;
2242 }
2243 } else {
2244 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002245 Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 if (receiver) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002247 Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002248 + " at " + mArchiveSourcePath + " "
2249 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002251 Slog.w(TAG, "Unknown element under <activity>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002252 + " at " + mArchiveSourcePath + " "
2253 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 }
2255 XmlUtils.skipCurrentTag(parser);
2256 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 } else {
Kenny Rootd2d29252011-08-08 11:27:57 -07002258 if (receiver) {
2259 outError[0] = "Bad element under <receiver>: " + parser.getName();
2260 } else {
2261 outError[0] = "Bad element under <activity>: " + parser.getName();
2262 }
2263 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 }
2266 }
2267
2268 if (!setExported) {
2269 a.info.exported = a.intents.size() > 0;
2270 }
2271
2272 return a;
2273 }
2274
2275 private Activity parseActivityAlias(Package owner, Resources res,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002276 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2277 throws XmlPullParserException, IOException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 TypedArray sa = res.obtainAttributes(attrs,
2279 com.android.internal.R.styleable.AndroidManifestActivityAlias);
2280
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002281 String targetActivity = sa.getNonConfigurationString(
2282 com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 if (targetActivity == null) {
2284 outError[0] = "<activity-alias> does not specify android:targetActivity";
2285 sa.recycle();
2286 return null;
2287 }
2288
2289 targetActivity = buildClassName(owner.applicationInfo.packageName,
2290 targetActivity, outError);
2291 if (targetActivity == null) {
2292 sa.recycle();
2293 return null;
2294 }
2295
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002296 if (mParseActivityAliasArgs == null) {
2297 mParseActivityAliasArgs = new ParseComponentArgs(owner, outError,
2298 com.android.internal.R.styleable.AndroidManifestActivityAlias_name,
2299 com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
2300 com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002301 com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002302 mSeparateProcesses,
2303 0,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002304 com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002305 com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled);
2306 mParseActivityAliasArgs.tag = "<activity-alias>";
2307 }
2308
2309 mParseActivityAliasArgs.sa = sa;
2310 mParseActivityAliasArgs.flags = flags;
2311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 Activity target = null;
2313
2314 final int NA = owner.activities.size();
2315 for (int i=0; i<NA; i++) {
2316 Activity t = owner.activities.get(i);
2317 if (targetActivity.equals(t.info.name)) {
2318 target = t;
2319 break;
2320 }
2321 }
2322
2323 if (target == null) {
2324 outError[0] = "<activity-alias> target activity " + targetActivity
2325 + " not found in manifest";
2326 sa.recycle();
2327 return null;
2328 }
2329
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002330 ActivityInfo info = new ActivityInfo();
2331 info.targetActivity = targetActivity;
2332 info.configChanges = target.info.configChanges;
2333 info.flags = target.info.flags;
2334 info.icon = target.info.icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07002335 info.logo = target.info.logo;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002336 info.labelRes = target.info.labelRes;
2337 info.nonLocalizedLabel = target.info.nonLocalizedLabel;
2338 info.launchMode = target.info.launchMode;
2339 info.processName = target.info.processName;
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002340 if (info.descriptionRes == 0) {
2341 info.descriptionRes = target.info.descriptionRes;
2342 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002343 info.screenOrientation = target.info.screenOrientation;
2344 info.taskAffinity = target.info.taskAffinity;
2345 info.theme = target.info.theme;
Dianne Hackborn0836c7c2011-10-20 18:40:23 -07002346 info.softInputMode = target.info.softInputMode;
Adam Powell269248d2011-08-02 10:26:54 -07002347 info.uiOptions = target.info.uiOptions;
Adam Powelldd8fab22012-03-22 17:47:27 -07002348 info.parentActivityName = target.info.parentActivityName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002349
2350 Activity a = new Activity(mParseActivityAliasArgs, info);
2351 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 sa.recycle();
2353 return null;
2354 }
2355
2356 final boolean setExported = sa.hasValue(
2357 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported);
2358 if (setExported) {
2359 a.info.exported = sa.getBoolean(
2360 com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false);
2361 }
2362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 String str;
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002364 str = sa.getNonConfigurationString(
2365 com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 if (str != null) {
2367 a.info.permission = str.length() > 0 ? str.toString().intern() : null;
2368 }
2369
Adam Powelldd8fab22012-03-22 17:47:27 -07002370 String parentName = sa.getNonConfigurationString(
2371 com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName,
2372 0);
2373 if (parentName != null) {
2374 String parentClassName = buildClassName(a.info.packageName, parentName, outError);
2375 if (outError[0] == null) {
2376 a.info.parentActivityName = parentClassName;
2377 } else {
2378 Log.e(TAG, "Activity alias " + a.info.name +
2379 " specified invalid parentActivityName " + parentName);
2380 outError[0] = null;
2381 }
2382 }
2383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 sa.recycle();
2385
2386 if (outError[0] != null) {
2387 return null;
2388 }
2389
2390 int outerDepth = parser.getDepth();
2391 int type;
2392 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2393 && (type != XmlPullParser.END_TAG
2394 || parser.getDepth() > outerDepth)) {
2395 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2396 continue;
2397 }
2398
2399 if (parser.getName().equals("intent-filter")) {
2400 ActivityIntentInfo intent = new ActivityIntentInfo(a);
2401 if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) {
2402 return null;
2403 }
2404 if (intent.countActions() == 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002405 Slog.w(TAG, "No actions in intent filter at "
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -07002406 + mArchiveSourcePath + " "
2407 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 } else {
2409 a.intents.add(intent);
2410 }
2411 } else if (parser.getName().equals("meta-data")) {
2412 if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData,
2413 outError)) == null) {
2414 return null;
2415 }
2416 } else {
2417 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002418 Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName()
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002419 + " at " + mArchiveSourcePath + " "
2420 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 XmlUtils.skipCurrentTag(parser);
2422 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002423 } else {
2424 outError[0] = "Bad element under <activity-alias>: " + parser.getName();
2425 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 }
2428 }
2429
2430 if (!setExported) {
2431 a.info.exported = a.intents.size() > 0;
2432 }
2433
2434 return a;
2435 }
2436
2437 private Provider parseProvider(Package owner, Resources res,
2438 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2439 throws XmlPullParserException, IOException {
2440 TypedArray sa = res.obtainAttributes(attrs,
2441 com.android.internal.R.styleable.AndroidManifestProvider);
2442
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002443 if (mParseProviderArgs == null) {
2444 mParseProviderArgs = new ParseComponentArgs(owner, outError,
2445 com.android.internal.R.styleable.AndroidManifestProvider_name,
2446 com.android.internal.R.styleable.AndroidManifestProvider_label,
2447 com.android.internal.R.styleable.AndroidManifestProvider_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002448 com.android.internal.R.styleable.AndroidManifestProvider_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002449 mSeparateProcesses,
2450 com.android.internal.R.styleable.AndroidManifestProvider_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002451 com.android.internal.R.styleable.AndroidManifestProvider_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002452 com.android.internal.R.styleable.AndroidManifestProvider_enabled);
2453 mParseProviderArgs.tag = "<provider>";
2454 }
2455
2456 mParseProviderArgs.sa = sa;
2457 mParseProviderArgs.flags = flags;
2458
2459 Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
2460 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 sa.recycle();
2462 return null;
2463 }
2464
Nick Kralevichf097b162012-07-28 12:43:48 -07002465 boolean providerExportedDefault = false;
2466
2467 if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2468 // For compatibility, applications targeting API level 16 or lower
2469 // should have their content providers exported by default, unless they
2470 // specify otherwise.
2471 providerExportedDefault = true;
2472 }
2473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 p.info.exported = sa.getBoolean(
Nick Kralevichf097b162012-07-28 12:43:48 -07002475 com.android.internal.R.styleable.AndroidManifestProvider_exported,
2476 providerExportedDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002478 String cpname = sa.getNonConfigurationString(
2479 com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480
2481 p.info.isSyncable = sa.getBoolean(
2482 com.android.internal.R.styleable.AndroidManifestProvider_syncable,
2483 false);
2484
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002485 String permission = sa.getNonConfigurationString(
2486 com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
2487 String str = sa.getNonConfigurationString(
2488 com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (str == null) {
2490 str = permission;
2491 }
2492 if (str == null) {
2493 p.info.readPermission = owner.applicationInfo.permission;
2494 } else {
2495 p.info.readPermission =
2496 str.length() > 0 ? str.toString().intern() : null;
2497 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002498 str = sa.getNonConfigurationString(
2499 com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 if (str == null) {
2501 str = permission;
2502 }
2503 if (str == null) {
2504 p.info.writePermission = owner.applicationInfo.permission;
2505 } else {
2506 p.info.writePermission =
2507 str.length() > 0 ? str.toString().intern() : null;
2508 }
2509
2510 p.info.grantUriPermissions = sa.getBoolean(
2511 com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions,
2512 false);
2513
2514 p.info.multiprocess = sa.getBoolean(
2515 com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
2516 false);
2517
2518 p.info.initOrder = sa.getInt(
2519 com.android.internal.R.styleable.AndroidManifestProvider_initOrder,
2520 0);
2521
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002522 p.info.flags = 0;
2523
2524 if (sa.getBoolean(
2525 com.android.internal.R.styleable.AndroidManifestProvider_singleUser,
2526 false)) {
2527 p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
2528 if (p.info.exported) {
2529 Slog.w(TAG, "Provider exported request ignored due to singleUser: "
2530 + p.className + " at " + mArchiveSourcePath + " "
2531 + parser.getPositionDescription());
2532 p.info.exported = false;
2533 }
2534 }
2535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 sa.recycle();
2537
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002538 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002539 // A heavy-weight application can not have providers in its main process
2540 // We can do direct compare because we intern all strings.
2541 if (p.info.processName == owner.packageName) {
2542 outError[0] = "Heavy-weight applications can not have providers in main process";
2543 return null;
2544 }
2545 }
2546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if (cpname == null) {
Nick Kralevichf097b162012-07-28 12:43:48 -07002548 outError[0] = "<provider> does not include authorities attribute";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 return null;
2550 }
2551 p.info.authority = cpname.intern();
2552
2553 if (!parseProviderTags(res, parser, attrs, p, outError)) {
2554 return null;
2555 }
2556
2557 return p;
2558 }
2559
2560 private boolean parseProviderTags(Resources res,
2561 XmlPullParser parser, AttributeSet attrs,
2562 Provider outInfo, String[] outError)
2563 throws XmlPullParserException, IOException {
2564 int outerDepth = parser.getDepth();
2565 int type;
2566 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2567 && (type != XmlPullParser.END_TAG
2568 || parser.getDepth() > outerDepth)) {
2569 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2570 continue;
2571 }
2572
2573 if (parser.getName().equals("meta-data")) {
2574 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2575 outInfo.metaData, outError)) == null) {
2576 return false;
2577 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 } else if (parser.getName().equals("grant-uri-permission")) {
2580 TypedArray sa = res.obtainAttributes(attrs,
2581 com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
2582
2583 PatternMatcher pa = null;
2584
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002585 String str = sa.getNonConfigurationString(
2586 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 if (str != null) {
2588 pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
2589 }
2590
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002591 str = sa.getNonConfigurationString(
2592 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 if (str != null) {
2594 pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
2595 }
2596
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002597 str = sa.getNonConfigurationString(
2598 com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 if (str != null) {
2600 pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
2601 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 sa.recycle();
2604
2605 if (pa != null) {
2606 if (outInfo.info.uriPermissionPatterns == null) {
2607 outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
2608 outInfo.info.uriPermissionPatterns[0] = pa;
2609 } else {
2610 final int N = outInfo.info.uriPermissionPatterns.length;
2611 PatternMatcher[] newp = new PatternMatcher[N+1];
2612 System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
2613 newp[N] = pa;
2614 outInfo.info.uriPermissionPatterns = newp;
2615 }
2616 outInfo.info.grantUriPermissions = true;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002617 } else {
2618 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002619 Slog.w(TAG, "Unknown element under <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002620 + parser.getName() + " at " + mArchiveSourcePath + " "
2621 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002622 XmlUtils.skipCurrentTag(parser);
2623 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002624 } else {
2625 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2626 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002627 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002628 }
2629 XmlUtils.skipCurrentTag(parser);
2630
2631 } else if (parser.getName().equals("path-permission")) {
2632 TypedArray sa = res.obtainAttributes(attrs,
2633 com.android.internal.R.styleable.AndroidManifestPathPermission);
2634
2635 PathPermission pa = null;
2636
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002637 String permission = sa.getNonConfigurationString(
2638 com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
2639 String readPermission = sa.getNonConfigurationString(
2640 com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002641 if (readPermission == null) {
2642 readPermission = permission;
2643 }
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002644 String writePermission = sa.getNonConfigurationString(
2645 com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002646 if (writePermission == null) {
2647 writePermission = permission;
2648 }
2649
2650 boolean havePerm = false;
2651 if (readPermission != null) {
2652 readPermission = readPermission.intern();
2653 havePerm = true;
2654 }
2655 if (writePermission != null) {
Bjorn Bringerte04b1ad2010-02-09 13:56:08 +00002656 writePermission = writePermission.intern();
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002657 havePerm = true;
2658 }
2659
2660 if (!havePerm) {
2661 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002662 Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002663 + parser.getName() + " at " + mArchiveSourcePath + " "
2664 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002665 XmlUtils.skipCurrentTag(parser);
2666 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002667 } else {
2668 outError[0] = "No readPermission or writePermssion for <path-permission>";
2669 return false;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002670 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002671 }
2672
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002673 String path = sa.getNonConfigurationString(
2674 com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002675 if (path != null) {
2676 pa = new PathPermission(path,
2677 PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
2678 }
2679
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002680 path = sa.getNonConfigurationString(
2681 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002682 if (path != null) {
2683 pa = new PathPermission(path,
2684 PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
2685 }
2686
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002687 path = sa.getNonConfigurationString(
2688 com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002689 if (path != null) {
2690 pa = new PathPermission(path,
2691 PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
2692 }
2693
2694 sa.recycle();
2695
2696 if (pa != null) {
2697 if (outInfo.info.pathPermissions == null) {
2698 outInfo.info.pathPermissions = new PathPermission[1];
2699 outInfo.info.pathPermissions[0] = pa;
2700 } else {
2701 final int N = outInfo.info.pathPermissions.length;
2702 PathPermission[] newp = new PathPermission[N+1];
2703 System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
2704 newp[N] = pa;
2705 outInfo.info.pathPermissions = newp;
2706 }
2707 } else {
2708 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002709 Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002710 + parser.getName() + " at " + mArchiveSourcePath + " "
2711 + parser.getPositionDescription());
Dianne Hackborn2af632f2009-07-08 14:56:37 -07002712 XmlUtils.skipCurrentTag(parser);
2713 continue;
2714 }
2715 outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
2716 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 }
2718 XmlUtils.skipCurrentTag(parser);
2719
2720 } else {
2721 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002722 Slog.w(TAG, "Unknown element under <provider>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002723 + parser.getName() + " at " + mArchiveSourcePath + " "
2724 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002725 XmlUtils.skipCurrentTag(parser);
2726 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002727 } else {
2728 outError[0] = "Bad element under <provider>: " + parser.getName();
2729 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 }
2732 }
2733 return true;
2734 }
2735
2736 private Service parseService(Package owner, Resources res,
2737 XmlPullParser parser, AttributeSet attrs, int flags, String[] outError)
2738 throws XmlPullParserException, IOException {
2739 TypedArray sa = res.obtainAttributes(attrs,
2740 com.android.internal.R.styleable.AndroidManifestService);
2741
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002742 if (mParseServiceArgs == null) {
2743 mParseServiceArgs = new ParseComponentArgs(owner, outError,
2744 com.android.internal.R.styleable.AndroidManifestService_name,
2745 com.android.internal.R.styleable.AndroidManifestService_label,
2746 com.android.internal.R.styleable.AndroidManifestService_icon,
Adam Powell81cd2e92010-04-21 16:35:18 -07002747 com.android.internal.R.styleable.AndroidManifestService_logo,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002748 mSeparateProcesses,
2749 com.android.internal.R.styleable.AndroidManifestService_process,
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002750 com.android.internal.R.styleable.AndroidManifestService_description,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002751 com.android.internal.R.styleable.AndroidManifestService_enabled);
2752 mParseServiceArgs.tag = "<service>";
2753 }
2754
2755 mParseServiceArgs.sa = sa;
2756 mParseServiceArgs.flags = flags;
2757
2758 Service s = new Service(mParseServiceArgs, new ServiceInfo());
2759 if (outError[0] != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 sa.recycle();
2761 return null;
2762 }
2763
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002764 boolean setExported = sa.hasValue(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 com.android.internal.R.styleable.AndroidManifestService_exported);
2766 if (setExported) {
2767 s.info.exported = sa.getBoolean(
2768 com.android.internal.R.styleable.AndroidManifestService_exported, false);
2769 }
2770
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002771 String str = sa.getNonConfigurationString(
2772 com.android.internal.R.styleable.AndroidManifestService_permission, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 if (str == null) {
2774 s.info.permission = owner.applicationInfo.permission;
2775 } else {
2776 s.info.permission = str.length() > 0 ? str.toString().intern() : null;
2777 }
2778
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002779 s.info.flags = 0;
2780 if (sa.getBoolean(
2781 com.android.internal.R.styleable.AndroidManifestService_stopWithTask,
2782 false)) {
2783 s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
2784 }
Dianne Hackborna0c283e2012-02-09 10:47:01 -08002785 if (sa.getBoolean(
2786 com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2787 false)) {
2788 s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2789 }
Dianne Hackbornb4163a62012-08-02 18:31:26 -07002790 if (sa.getBoolean(
2791 com.android.internal.R.styleable.AndroidManifestService_singleUser,
2792 false)) {
2793 s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
2794 if (s.info.exported) {
2795 Slog.w(TAG, "Service exported request ignored due to singleUser: "
2796 + s.className + " at " + mArchiveSourcePath + " "
2797 + parser.getPositionDescription());
2798 s.info.exported = false;
2799 }
2800 setExported = true;
2801 }
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 sa.recycle();
2804
Dianne Hackborn54e570f2010-10-04 18:32:32 -07002805 if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
Dianne Hackborn860755f2010-06-03 18:47:52 -07002806 // A heavy-weight application can not have services in its main process
2807 // We can do direct compare because we intern all strings.
2808 if (s.info.processName == owner.packageName) {
2809 outError[0] = "Heavy-weight applications can not have services in main process";
2810 return null;
2811 }
2812 }
2813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 int outerDepth = parser.getDepth();
2815 int type;
2816 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2817 && (type != XmlPullParser.END_TAG
2818 || parser.getDepth() > outerDepth)) {
2819 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2820 continue;
2821 }
2822
2823 if (parser.getName().equals("intent-filter")) {
2824 ServiceIntentInfo intent = new ServiceIntentInfo(s);
2825 if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) {
2826 return null;
2827 }
2828
2829 s.intents.add(intent);
2830 } else if (parser.getName().equals("meta-data")) {
2831 if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData,
2832 outError)) == null) {
2833 return null;
2834 }
2835 } else {
2836 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002837 Slog.w(TAG, "Unknown element under <service>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002838 + parser.getName() + " at " + mArchiveSourcePath + " "
2839 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 XmlUtils.skipCurrentTag(parser);
2841 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002842 } else {
2843 outError[0] = "Bad element under <service>: " + parser.getName();
2844 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 }
2847 }
2848
2849 if (!setExported) {
2850 s.info.exported = s.intents.size() > 0;
2851 }
2852
2853 return s;
2854 }
2855
2856 private boolean parseAllMetaData(Resources res,
2857 XmlPullParser parser, AttributeSet attrs, String tag,
2858 Component outInfo, String[] outError)
2859 throws XmlPullParserException, IOException {
2860 int outerDepth = parser.getDepth();
2861 int type;
2862 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
2863 && (type != XmlPullParser.END_TAG
2864 || parser.getDepth() > outerDepth)) {
2865 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
2866 continue;
2867 }
2868
2869 if (parser.getName().equals("meta-data")) {
2870 if ((outInfo.metaData=parseMetaData(res, parser, attrs,
2871 outInfo.metaData, outError)) == null) {
2872 return false;
2873 }
2874 } else {
2875 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002876 Slog.w(TAG, "Unknown element under " + tag + ": "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002877 + parser.getName() + " at " + mArchiveSourcePath + " "
2878 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 XmlUtils.skipCurrentTag(parser);
2880 continue;
Kenny Rootd2d29252011-08-08 11:27:57 -07002881 } else {
2882 outError[0] = "Bad element under " + tag + ": " + parser.getName();
2883 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
2886 }
2887 return true;
2888 }
2889
2890 private Bundle parseMetaData(Resources res,
2891 XmlPullParser parser, AttributeSet attrs,
2892 Bundle data, String[] outError)
2893 throws XmlPullParserException, IOException {
2894
2895 TypedArray sa = res.obtainAttributes(attrs,
2896 com.android.internal.R.styleable.AndroidManifestMetaData);
2897
2898 if (data == null) {
2899 data = new Bundle();
2900 }
2901
Dianne Hackborncf244ad2010-03-09 15:00:30 -08002902 String name = sa.getNonConfigurationString(
2903 com.android.internal.R.styleable.AndroidManifestMetaData_name, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 if (name == null) {
2905 outError[0] = "<meta-data> requires an android:name attribute";
2906 sa.recycle();
2907 return null;
2908 }
2909
Dianne Hackborn854060a2009-07-09 18:14:31 -07002910 name = name.intern();
2911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 TypedValue v = sa.peekValue(
2913 com.android.internal.R.styleable.AndroidManifestMetaData_resource);
2914 if (v != null && v.resourceId != 0) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002915 //Slog.i(TAG, "Meta data ref " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 data.putInt(name, v.resourceId);
2917 } else {
2918 v = sa.peekValue(
2919 com.android.internal.R.styleable.AndroidManifestMetaData_value);
Kenny Rootd2d29252011-08-08 11:27:57 -07002920 //Slog.i(TAG, "Meta data " + name + ": " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 if (v != null) {
2922 if (v.type == TypedValue.TYPE_STRING) {
2923 CharSequence cs = v.coerceToString();
Dianne Hackborn854060a2009-07-09 18:14:31 -07002924 data.putString(name, cs != null ? cs.toString().intern() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
2926 data.putBoolean(name, v.data != 0);
2927 } else if (v.type >= TypedValue.TYPE_FIRST_INT
2928 && v.type <= TypedValue.TYPE_LAST_INT) {
2929 data.putInt(name, v.data);
2930 } else if (v.type == TypedValue.TYPE_FLOAT) {
2931 data.putFloat(name, v.getFloat());
2932 } else {
2933 if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07002934 Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07002935 + parser.getName() + " at " + mArchiveSourcePath + " "
2936 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 } else {
2938 outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
2939 data = null;
2940 }
2941 }
2942 } else {
2943 outError[0] = "<meta-data> requires an android:value or android:resource attribute";
2944 data = null;
2945 }
2946 }
2947
2948 sa.recycle();
2949
2950 XmlUtils.skipCurrentTag(parser);
2951
2952 return data;
2953 }
2954
Kenny Root05ca4c92011-09-15 10:36:25 -07002955 private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser,
2956 AttributeSet attrs, int flags, String[] outError) throws XmlPullParserException,
2957 IOException {
2958 final TypedArray sa = res.obtainAttributes(attrs,
2959 com.android.internal.R.styleable.AndroidManifestPackageVerifier);
2960
2961 final String packageName = sa.getNonResourceString(
2962 com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);
2963
2964 final String encodedPublicKey = sa.getNonResourceString(
2965 com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);
2966
2967 sa.recycle();
2968
2969 if (packageName == null || packageName.length() == 0) {
2970 Slog.i(TAG, "verifier package name was null; skipping");
2971 return null;
2972 } else if (encodedPublicKey == null) {
2973 Slog.i(TAG, "verifier " + packageName + " public key was null; skipping");
2974 }
2975
2976 EncodedKeySpec keySpec;
2977 try {
2978 final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
2979 keySpec = new X509EncodedKeySpec(encoded);
2980 } catch (IllegalArgumentException e) {
2981 Slog.i(TAG, "Could not parse verifier " + packageName + " public key; invalid Base64");
2982 return null;
2983 }
2984
2985 /* First try the key as an RSA key. */
2986 try {
2987 final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
2988 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
2989 return new VerifierInfo(packageName, publicKey);
2990 } catch (NoSuchAlgorithmException e) {
2991 Log.wtf(TAG, "Could not parse public key because RSA isn't included in build");
2992 return null;
2993 } catch (InvalidKeySpecException e) {
2994 // Not a RSA public key.
2995 }
2996
2997 /* Now try it as a DSA key. */
2998 try {
2999 final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
3000 final PublicKey publicKey = keyFactory.generatePublic(keySpec);
3001 return new VerifierInfo(packageName, publicKey);
3002 } catch (NoSuchAlgorithmException e) {
3003 Log.wtf(TAG, "Could not parse public key because DSA isn't included in build");
3004 return null;
3005 } catch (InvalidKeySpecException e) {
3006 // Not a DSA public key.
3007 }
3008
3009 return null;
3010 }
3011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 private static final String ANDROID_RESOURCES
3013 = "http://schemas.android.com/apk/res/android";
3014
3015 private boolean parseIntent(Resources res,
3016 XmlPullParser parser, AttributeSet attrs, int flags,
3017 IntentInfo outInfo, String[] outError, boolean isActivity)
3018 throws XmlPullParserException, IOException {
3019
3020 TypedArray sa = res.obtainAttributes(attrs,
3021 com.android.internal.R.styleable.AndroidManifestIntentFilter);
3022
3023 int priority = sa.getInt(
3024 com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 outInfo.setPriority(priority);
Kenny Root502e9a42011-01-10 13:48:15 -08003026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 TypedValue v = sa.peekValue(
3028 com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
3029 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3030 outInfo.nonLocalizedLabel = v.coerceToString();
3031 }
3032
3033 outInfo.icon = sa.getResourceId(
3034 com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);
Adam Powell81cd2e92010-04-21 16:35:18 -07003035
3036 outInfo.logo = sa.getResourceId(
3037 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038
3039 sa.recycle();
3040
3041 int outerDepth = parser.getDepth();
3042 int type;
Kenny Rootd2d29252011-08-08 11:27:57 -07003043 while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
3044 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
3045 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 continue;
3047 }
3048
3049 String nodeName = parser.getName();
3050 if (nodeName.equals("action")) {
3051 String value = attrs.getAttributeValue(
3052 ANDROID_RESOURCES, "name");
3053 if (value == null || value == "") {
3054 outError[0] = "No value supplied for <android:name>";
3055 return false;
3056 }
3057 XmlUtils.skipCurrentTag(parser);
3058
3059 outInfo.addAction(value);
3060 } else if (nodeName.equals("category")) {
3061 String value = attrs.getAttributeValue(
3062 ANDROID_RESOURCES, "name");
3063 if (value == null || value == "") {
3064 outError[0] = "No value supplied for <android:name>";
3065 return false;
3066 }
3067 XmlUtils.skipCurrentTag(parser);
3068
3069 outInfo.addCategory(value);
3070
3071 } else if (nodeName.equals("data")) {
3072 sa = res.obtainAttributes(attrs,
3073 com.android.internal.R.styleable.AndroidManifestData);
3074
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003075 String str = sa.getNonConfigurationString(
3076 com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 if (str != null) {
3078 try {
3079 outInfo.addDataType(str);
3080 } catch (IntentFilter.MalformedMimeTypeException e) {
3081 outError[0] = e.toString();
3082 sa.recycle();
3083 return false;
3084 }
3085 }
3086
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003087 str = sa.getNonConfigurationString(
3088 com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 if (str != null) {
3090 outInfo.addDataScheme(str);
3091 }
3092
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003093 String host = sa.getNonConfigurationString(
3094 com.android.internal.R.styleable.AndroidManifestData_host, 0);
3095 String port = sa.getNonConfigurationString(
3096 com.android.internal.R.styleable.AndroidManifestData_port, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 if (host != null) {
3098 outInfo.addDataAuthority(host, port);
3099 }
3100
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003101 str = sa.getNonConfigurationString(
3102 com.android.internal.R.styleable.AndroidManifestData_path, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 if (str != null) {
3104 outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
3105 }
3106
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003107 str = sa.getNonConfigurationString(
3108 com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 if (str != null) {
3110 outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
3111 }
3112
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003113 str = sa.getNonConfigurationString(
3114 com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 if (str != null) {
3116 outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
3117 }
3118
3119 sa.recycle();
3120 XmlUtils.skipCurrentTag(parser);
3121 } else if (!RIGID_PARSER) {
Kenny Rootd2d29252011-08-08 11:27:57 -07003122 Slog.w(TAG, "Unknown element under <intent-filter>: "
Dianne Hackborna33e3f72009-09-29 17:28:24 -07003123 + parser.getName() + " at " + mArchiveSourcePath + " "
3124 + parser.getPositionDescription());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 XmlUtils.skipCurrentTag(parser);
3126 } else {
3127 outError[0] = "Bad element under <intent-filter>: " + parser.getName();
3128 return false;
3129 }
3130 }
3131
3132 outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);
Kenny Rootd2d29252011-08-08 11:27:57 -07003133
3134 if (DEBUG_PARSER) {
3135 final StringBuilder cats = new StringBuilder("Intent d=");
3136 cats.append(outInfo.hasDefault);
3137 cats.append(", cat=");
3138
3139 final Iterator<String> it = outInfo.categoriesIterator();
3140 if (it != null) {
3141 while (it.hasNext()) {
3142 cats.append(' ');
3143 cats.append(it.next());
3144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 }
Kenny Rootd2d29252011-08-08 11:27:57 -07003146 Slog.d(TAG, cats.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 }
3148
3149 return true;
3150 }
3151
3152 public final static class Package {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003153 public String packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154
3155 // For now we only support one application per package.
3156 public final ApplicationInfo applicationInfo = new ApplicationInfo();
3157
3158 public final ArrayList<Permission> permissions = new ArrayList<Permission>(0);
3159 public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0);
3160 public final ArrayList<Activity> activities = new ArrayList<Activity>(0);
3161 public final ArrayList<Activity> receivers = new ArrayList<Activity>(0);
3162 public final ArrayList<Provider> providers = new ArrayList<Provider>(0);
3163 public final ArrayList<Service> services = new ArrayList<Service>(0);
3164 public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0);
3165
3166 public final ArrayList<String> requestedPermissions = new ArrayList<String>();
Dianne Hackborne639da72012-02-21 15:11:13 -08003167 public final ArrayList<Boolean> requestedPermissionsRequired = new ArrayList<Boolean>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168
Dianne Hackborn854060a2009-07-09 18:14:31 -07003169 public ArrayList<String> protectedBroadcasts;
3170
Dianne Hackborn49237342009-08-27 20:08:01 -07003171 public ArrayList<String> usesLibraries = null;
3172 public ArrayList<String> usesOptionalLibraries = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 public String[] usesLibraryFiles = null;
3174
Dianne Hackbornc1552392010-03-03 16:19:01 -08003175 public ArrayList<String> mOriginalPackages = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003176 public String mRealPackage = null;
Dianne Hackbornb858dfd2010-02-02 10:49:14 -08003177 public ArrayList<String> mAdoptPermissions = null;
3178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 // We store the application meta-data independently to avoid multiple unwanted references
3180 public Bundle mAppMetaData = null;
3181
3182 // If this is a 3rd party app, this is the path of the zip file.
3183 public String mPath;
3184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 // The version code declared for this package.
3186 public int mVersionCode;
3187
3188 // The version name declared for this package.
3189 public String mVersionName;
3190
3191 // The shared user id that this package wants to use.
3192 public String mSharedUserId;
3193
3194 // The shared user label that this package wants to use.
3195 public int mSharedUserLabel;
3196
3197 // Signatures that were read from the package.
3198 public Signature mSignatures[];
3199
3200 // For use by package manager service for quick lookup of
3201 // preferred up order.
3202 public int mPreferredOrder = 0;
3203
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -07003204 // For use by the package manager to keep track of the path to the
3205 // file an app came from.
3206 public String mScanPath;
3207
3208 // For use by package manager to keep track of where it has done dexopt.
3209 public boolean mDidDexOpt;
3210
Amith Yamasani13593602012-03-22 16:16:17 -07003211 // // User set enabled state.
3212 // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
3213 //
3214 // // Whether the package has been stopped.
3215 // public boolean mSetStopped = false;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 // Additional data supplied by callers.
3218 public Object mExtras;
Kenny Rootdeb11262010-08-02 11:36:21 -07003219
3220 // Whether an operation is currently pending on this package
3221 public boolean mOperationPending;
3222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 /*
3224 * Applications hardware preferences
3225 */
3226 public final ArrayList<ConfigurationInfo> configPreferences =
3227 new ArrayList<ConfigurationInfo>();
3228
Dianne Hackborn49237342009-08-27 20:08:01 -07003229 /*
3230 * Applications requested features
3231 */
3232 public ArrayList<FeatureInfo> reqFeatures = null;
3233
Suchi Amalapurapu117818e2010-02-09 03:45:40 -08003234 public int installLocation;
3235
Kenny Rootbcc954d2011-08-08 16:19:08 -07003236 /**
3237 * Digest suitable for comparing whether this package's manifest is the
3238 * same as another.
3239 */
3240 public ManifestDigest manifestDigest;
3241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 public Package(String _name) {
3243 packageName = _name;
3244 applicationInfo.packageName = _name;
3245 applicationInfo.uid = -1;
3246 }
3247
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003248 public void setPackageName(String newName) {
3249 packageName = newName;
3250 applicationInfo.packageName = newName;
3251 for (int i=permissions.size()-1; i>=0; i--) {
3252 permissions.get(i).setPackageName(newName);
3253 }
3254 for (int i=permissionGroups.size()-1; i>=0; i--) {
3255 permissionGroups.get(i).setPackageName(newName);
3256 }
3257 for (int i=activities.size()-1; i>=0; i--) {
3258 activities.get(i).setPackageName(newName);
3259 }
3260 for (int i=receivers.size()-1; i>=0; i--) {
3261 receivers.get(i).setPackageName(newName);
3262 }
3263 for (int i=providers.size()-1; i>=0; i--) {
3264 providers.get(i).setPackageName(newName);
3265 }
3266 for (int i=services.size()-1; i>=0; i--) {
3267 services.get(i).setPackageName(newName);
3268 }
3269 for (int i=instrumentation.size()-1; i>=0; i--) {
3270 instrumentation.get(i).setPackageName(newName);
3271 }
3272 }
Dianne Hackborn65696252012-03-05 18:49:21 -08003273
3274 public boolean hasComponentClassName(String name) {
3275 for (int i=activities.size()-1; i>=0; i--) {
3276 if (name.equals(activities.get(i).className)) {
3277 return true;
3278 }
3279 }
3280 for (int i=receivers.size()-1; i>=0; i--) {
3281 if (name.equals(receivers.get(i).className)) {
3282 return true;
3283 }
3284 }
3285 for (int i=providers.size()-1; i>=0; i--) {
3286 if (name.equals(providers.get(i).className)) {
3287 return true;
3288 }
3289 }
3290 for (int i=services.size()-1; i>=0; i--) {
3291 if (name.equals(services.get(i).className)) {
3292 return true;
3293 }
3294 }
3295 for (int i=instrumentation.size()-1; i>=0; i--) {
3296 if (name.equals(instrumentation.get(i).className)) {
3297 return true;
3298 }
3299 }
3300 return false;
3301 }
3302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 public String toString() {
3304 return "Package{"
3305 + Integer.toHexString(System.identityHashCode(this))
3306 + " " + packageName + "}";
3307 }
3308 }
3309
3310 public static class Component<II extends IntentInfo> {
3311 public final Package owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003312 public final ArrayList<II> intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003313 public final String className;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 public Bundle metaData;
3315
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003316 ComponentName componentName;
3317 String componentShortName;
3318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 public Component(Package _owner) {
3320 owner = _owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003321 intents = null;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003322 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003323 }
3324
3325 public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) {
3326 owner = args.owner;
3327 intents = new ArrayList<II>(0);
Dianne Hackborncf244ad2010-03-09 15:00:30 -08003328 String name = args.sa.getNonConfigurationString(args.nameRes, 0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003329 if (name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003330 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003331 args.outError[0] = args.tag + " does not specify android:name";
3332 return;
3333 }
3334
3335 outInfo.name
3336 = buildClassName(owner.applicationInfo.packageName, name, args.outError);
3337 if (outInfo.name == null) {
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003338 className = null;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003339 args.outError[0] = args.tag + " does not have valid android:name";
3340 return;
3341 }
3342
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003343 className = outInfo.name;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003344
3345 int iconVal = args.sa.getResourceId(args.iconRes, 0);
3346 if (iconVal != 0) {
3347 outInfo.icon = iconVal;
3348 outInfo.nonLocalizedLabel = null;
3349 }
Adam Powell81cd2e92010-04-21 16:35:18 -07003350
3351 int logoVal = args.sa.getResourceId(args.logoRes, 0);
3352 if (logoVal != 0) {
3353 outInfo.logo = logoVal;
3354 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003355
3356 TypedValue v = args.sa.peekValue(args.labelRes);
3357 if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
3358 outInfo.nonLocalizedLabel = v.coerceToString();
3359 }
3360
3361 outInfo.packageName = owner.packageName;
3362 }
3363
3364 public Component(final ParseComponentArgs args, final ComponentInfo outInfo) {
3365 this(args, (PackageItemInfo)outInfo);
3366 if (args.outError[0] != null) {
3367 return;
3368 }
3369
3370 if (args.processRes != 0) {
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003371 CharSequence pname;
3372 if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
3373 pname = args.sa.getNonConfigurationString(args.processRes, 0);
3374 } else {
3375 // Some older apps have been seen to use a resource reference
3376 // here that on older builds was ignored (with a warning). We
3377 // need to continue to do this for them so they don't break.
3378 pname = args.sa.getNonResourceString(args.processRes);
3379 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003380 outInfo.processName = buildProcessName(owner.applicationInfo.packageName,
Dianne Hackbornd1cff1b2010-04-02 16:51:26 -07003381 owner.applicationInfo.processName, pname,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003382 args.flags, args.sepProcesses, args.outError);
3383 }
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08003384
3385 if (args.descriptionRes != 0) {
3386 outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0);
3387 }
3388
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003389 outInfo.enabled = args.sa.getBoolean(args.enabledRes, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 }
3391
3392 public Component(Component<II> clone) {
3393 owner = clone.owner;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003394 intents = clone.intents;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003395 className = clone.className;
3396 componentName = clone.componentName;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003397 componentShortName = clone.componentShortName;
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003398 }
3399
3400 public ComponentName getComponentName() {
3401 if (componentName != null) {
3402 return componentName;
3403 }
3404 if (className != null) {
3405 componentName = new ComponentName(owner.applicationInfo.packageName,
3406 className);
3407 }
3408 return componentName;
3409 }
3410
3411 public String getComponentShortName() {
3412 if (componentShortName != null) {
3413 return componentShortName;
3414 }
3415 ComponentName component = getComponentName();
3416 if (component != null) {
3417 componentShortName = component.flattenToShortString();
3418 }
3419 return componentShortName;
3420 }
3421
3422 public void setPackageName(String packageName) {
3423 componentName = null;
3424 componentShortName = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 }
3426 }
3427
3428 public final static class Permission extends Component<IntentInfo> {
3429 public final PermissionInfo info;
3430 public boolean tree;
3431 public PermissionGroup group;
3432
3433 public Permission(Package _owner) {
3434 super(_owner);
3435 info = new PermissionInfo();
3436 }
3437
3438 public Permission(Package _owner, PermissionInfo _info) {
3439 super(_owner);
3440 info = _info;
3441 }
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003442
3443 public void setPackageName(String packageName) {
3444 super.setPackageName(packageName);
3445 info.packageName = packageName;
3446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447
3448 public String toString() {
3449 return "Permission{"
3450 + Integer.toHexString(System.identityHashCode(this))
3451 + " " + info.name + "}";
3452 }
3453 }
3454
3455 public final static class PermissionGroup extends Component<IntentInfo> {
3456 public final PermissionGroupInfo info;
3457
3458 public PermissionGroup(Package _owner) {
3459 super(_owner);
3460 info = new PermissionGroupInfo();
3461 }
3462
3463 public PermissionGroup(Package _owner, PermissionGroupInfo _info) {
3464 super(_owner);
3465 info = _info;
3466 }
3467
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003468 public void setPackageName(String packageName) {
3469 super.setPackageName(packageName);
3470 info.packageName = packageName;
3471 }
3472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 public String toString() {
3474 return "PermissionGroup{"
3475 + Integer.toHexString(System.identityHashCode(this))
3476 + " " + info.name + "}";
3477 }
3478 }
3479
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003480 private static boolean copyNeeded(int flags, Package p,
3481 PackageUserState state, Bundle metaData, int userId) {
3482 if (userId != 0) {
3483 // We always need to copy for other users, since we need
3484 // to fix up the uid.
3485 return true;
3486 }
3487 if (state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
3488 boolean enabled = state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Dianne Hackborn46730fc2010-07-24 16:32:42 -07003489 if (p.applicationInfo.enabled != enabled) {
3490 return true;
3491 }
3492 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003493 if (!state.installed) {
3494 return true;
3495 }
3496 if (state.stopped) {
3497 return true;
3498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 if ((flags & PackageManager.GET_META_DATA) != 0
3500 && (metaData != null || p.mAppMetaData != null)) {
3501 return true;
3502 }
3503 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0
3504 && p.usesLibraryFiles != null) {
3505 return true;
3506 }
3507 return false;
3508 }
3509
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003510 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
3511 PackageUserState state) {
3512 return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
Amith Yamasani742a6712011-05-04 14:49:28 -07003513 }
3514
Amith Yamasani13593602012-03-22 16:16:17 -07003515 public static ApplicationInfo generateApplicationInfo(Package p, int flags,
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003516 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003518 if (!checkUseInstalled(flags, state)) {
3519 return null;
3520 }
3521 if (!copyNeeded(flags, p, state, null, userId)) {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003522 // CompatibilityMode is global state. It's safe to modify the instance
3523 // of the package.
3524 if (!sCompatibilityModeEnabled) {
3525 p.applicationInfo.disableCompatibilityMode();
3526 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003527 // Make sure we report as installed. Also safe to do, since the
3528 // default state should be installed (we will always copy if we
3529 // need to report it is not installed).
3530 p.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
3531 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003532 p.applicationInfo.enabled = true;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003533 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3534 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
Amith Yamasani483f3b02012-03-13 16:08:00 -07003535 p.applicationInfo.enabled = false;
3536 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003537 p.applicationInfo.enabledSetting = state.enabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 return p.applicationInfo;
3539 }
3540
3541 // Make shallow copy so we can store the metadata/libraries safely
3542 ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
Amith Yamasani742a6712011-05-04 14:49:28 -07003543 if (userId != 0) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003544 ai.uid = UserHandle.getUid(userId, ai.uid);
Amith Yamasani742a6712011-05-04 14:49:28 -07003545 ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName);
3546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 if ((flags & PackageManager.GET_META_DATA) != 0) {
3548 ai.metaData = p.mAppMetaData;
3549 }
3550 if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
3551 ai.sharedLibraryFiles = p.usesLibraryFiles;
3552 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003553 if (!sCompatibilityModeEnabled) {
3554 ai.disableCompatibilityMode();
3555 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003556 if (state.stopped) {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003557 ai.flags |= ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003558 } else {
Amith Yamasania4a54e22012-04-16 15:44:19 -07003559 ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
Dianne Hackborne7f97212011-02-24 14:40:20 -08003560 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003561 if (state.installed) {
3562 ai.flags |= ApplicationInfo.FLAG_INSTALLED;
3563 } else {
3564 ai.flags &= ~ApplicationInfo.FLAG_INSTALLED;
3565 }
3566 if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003567 ai.enabled = true;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003568 } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
3569 || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
John Reck4b7b7cc2011-02-02 11:57:44 -08003570 ai.enabled = false;
3571 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003572 ai.enabledSetting = state.enabled;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 return ai;
3574 }
3575
3576 public static final PermissionInfo generatePermissionInfo(
3577 Permission p, int flags) {
3578 if (p == null) return null;
3579 if ((flags&PackageManager.GET_META_DATA) == 0) {
3580 return p.info;
3581 }
3582 PermissionInfo pi = new PermissionInfo(p.info);
3583 pi.metaData = p.metaData;
3584 return pi;
3585 }
3586
3587 public static final PermissionGroupInfo generatePermissionGroupInfo(
3588 PermissionGroup pg, int flags) {
3589 if (pg == null) return null;
3590 if ((flags&PackageManager.GET_META_DATA) == 0) {
3591 return pg.info;
3592 }
3593 PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info);
3594 pgi.metaData = pg.metaData;
3595 return pgi;
3596 }
3597
3598 public final static class Activity extends Component<ActivityIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003599 public final ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003601 public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
3602 super(args, _info);
3603 info = _info;
3604 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003606
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003607 public void setPackageName(String packageName) {
3608 super.setPackageName(packageName);
3609 info.packageName = packageName;
3610 }
3611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 public String toString() {
3613 return "Activity{"
3614 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003615 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 }
3617 }
3618
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003619 public static final ActivityInfo generateActivityInfo(Activity a, int flags,
3620 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 if (a == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003622 if (!checkUseInstalled(flags, state)) {
3623 return null;
3624 }
3625 if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 return a.info;
3627 }
3628 // Make shallow copies so we can store the metadata safely
3629 ActivityInfo ai = new ActivityInfo(a.info);
3630 ai.metaData = a.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003631 ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 return ai;
3633 }
3634
3635 public final static class Service extends Component<ServiceIntentInfo> {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003636 public final ServiceInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003638 public Service(final ParseComponentArgs args, final ServiceInfo _info) {
3639 super(args, _info);
3640 info = _info;
3641 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003643
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003644 public void setPackageName(String packageName) {
3645 super.setPackageName(packageName);
3646 info.packageName = packageName;
3647 }
3648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 public String toString() {
3650 return "Service{"
3651 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003652 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 }
3654 }
3655
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003656 public static final ServiceInfo generateServiceInfo(Service s, int flags,
3657 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 if (s == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003659 if (!checkUseInstalled(flags, state)) {
3660 return null;
3661 }
3662 if (!copyNeeded(flags, s.owner, state, s.metaData, userId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 return s.info;
3664 }
3665 // Make shallow copies so we can store the metadata safely
3666 ServiceInfo si = new ServiceInfo(s.info);
3667 si.metaData = s.metaData;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003668 si.applicationInfo = generateApplicationInfo(s.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 return si;
3670 }
3671
3672 public final static class Provider extends Component {
3673 public final ProviderInfo info;
3674 public boolean syncable;
3675
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003676 public Provider(final ParseComponentArgs args, final ProviderInfo _info) {
3677 super(args, _info);
3678 info = _info;
3679 info.applicationInfo = args.owner.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 syncable = false;
3681 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 public Provider(Provider existingProvider) {
3684 super(existingProvider);
3685 this.info = existingProvider.info;
3686 this.syncable = existingProvider.syncable;
3687 }
3688
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003689 public void setPackageName(String packageName) {
3690 super.setPackageName(packageName);
3691 info.packageName = packageName;
3692 }
3693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 public String toString() {
3695 return "Provider{"
3696 + Integer.toHexString(System.identityHashCode(this))
3697 + " " + info.name + "}";
3698 }
3699 }
3700
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003701 public static final ProviderInfo generateProviderInfo(Provider p, int flags,
3702 PackageUserState state, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 if (p == null) return null;
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003704 if (!checkUseInstalled(flags, state)) {
3705 return null;
3706 }
3707 if (!copyNeeded(flags, p.owner, state, p.metaData, userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003709 || p.info.uriPermissionPatterns == null)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 return p.info;
3711 }
3712 // Make shallow copies so we can store the metadata safely
3713 ProviderInfo pi = new ProviderInfo(p.info);
3714 pi.metaData = p.metaData;
3715 if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
3716 pi.uriPermissionPatterns = null;
3717 }
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003718 pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 return pi;
3720 }
3721
3722 public final static class Instrumentation extends Component {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003723 public final InstrumentationInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003725 public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) {
3726 super(args, _info);
3727 info = _info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003729
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003730 public void setPackageName(String packageName) {
3731 super.setPackageName(packageName);
3732 info.packageName = packageName;
3733 }
3734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 public String toString() {
3736 return "Instrumentation{"
3737 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn6dee18c2010-02-09 23:59:16 -08003738 + " " + getComponentShortName() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 }
3740 }
3741
3742 public static final InstrumentationInfo generateInstrumentationInfo(
3743 Instrumentation i, int flags) {
3744 if (i == null) return null;
3745 if ((flags&PackageManager.GET_META_DATA) == 0) {
3746 return i.info;
3747 }
3748 InstrumentationInfo ii = new InstrumentationInfo(i.info);
3749 ii.metaData = i.metaData;
3750 return ii;
3751 }
3752
3753 public static class IntentInfo extends IntentFilter {
3754 public boolean hasDefault;
3755 public int labelRes;
3756 public CharSequence nonLocalizedLabel;
3757 public int icon;
Adam Powell81cd2e92010-04-21 16:35:18 -07003758 public int logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 }
3760
3761 public final static class ActivityIntentInfo extends IntentInfo {
3762 public final Activity activity;
3763
3764 public ActivityIntentInfo(Activity _activity) {
3765 activity = _activity;
3766 }
3767
3768 public String toString() {
3769 return "ActivityIntentInfo{"
3770 + Integer.toHexString(System.identityHashCode(this))
3771 + " " + activity.info.name + "}";
3772 }
3773 }
3774
3775 public final static class ServiceIntentInfo extends IntentInfo {
3776 public final Service service;
3777
3778 public ServiceIntentInfo(Service _service) {
3779 service = _service;
3780 }
3781
3782 public String toString() {
3783 return "ServiceIntentInfo{"
3784 + Integer.toHexString(System.identityHashCode(this))
3785 + " " + service.info.name + "}";
3786 }
3787 }
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -07003788
3789 /**
3790 * @hide
3791 */
3792 public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) {
3793 sCompatibilityModeEnabled = compatibilityModeEnabled;
3794 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003795}