The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content.pm; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.content.ComponentName; |
| 20 | import android.content.Intent; |
| 21 | import android.content.IntentFilter; |
| 22 | import android.content.res.AssetManager; |
| 23 | import android.content.res.Configuration; |
| 24 | import android.content.res.Resources; |
| 25 | import android.content.res.TypedArray; |
| 26 | import android.content.res.XmlResourceParser; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 27 | import android.os.Binder; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 28 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.Bundle; |
| 30 | import android.os.PatternMatcher; |
| 31 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.util.DisplayMetrics; |
| 33 | import android.util.Log; |
| 34 | import android.util.TypedValue; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 35 | import com.android.internal.util.XmlUtils; |
| 36 | import org.xmlpull.v1.XmlPullParser; |
| 37 | import org.xmlpull.v1.XmlPullParserException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Kenny Root | d63f7db | 2010-09-27 08:07:48 -0700 | [diff] [blame] | 39 | import java.io.BufferedInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import java.io.File; |
| 41 | import java.io.IOException; |
| 42 | import java.io.InputStream; |
| 43 | import java.lang.ref.WeakReference; |
| 44 | import java.security.cert.Certificate; |
| 45 | import java.security.cert.CertificateEncodingException; |
| 46 | import java.util.ArrayList; |
| 47 | import java.util.Enumeration; |
| 48 | import java.util.Iterator; |
| 49 | import java.util.jar.JarEntry; |
| 50 | import java.util.jar.JarFile; |
| 51 | |
| 52 | /** |
| 53 | * Package archive parsing |
| 54 | * |
| 55 | * {@hide} |
| 56 | */ |
| 57 | public class PackageParser { |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 58 | /** @hide */ |
| 59 | public static class NewPermissionInfo { |
| 60 | public final String name; |
| 61 | public final int sdkVersion; |
| 62 | public final int fileVersion; |
| 63 | |
| 64 | public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { |
| 65 | this.name = name; |
| 66 | this.sdkVersion = sdkVersion; |
| 67 | this.fileVersion = fileVersion; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * List of new permissions that have been added since 1.0. |
| 73 | * NOTE: These must be declared in SDK version order, with permissions |
| 74 | * added to older SDKs appearing before those added to newer SDKs. |
| 75 | * @hide |
| 76 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 77 | public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = |
| 78 | new PackageParser.NewPermissionInfo[] { |
San Mehat | 5a3a77d | 2009-06-01 09:25:28 -0700 | [diff] [blame] | 79 | new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 80 | android.os.Build.VERSION_CODES.DONUT, 0), |
| 81 | new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, |
| 82 | android.os.Build.VERSION_CODES.DONUT, 0) |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 83 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
| 85 | private String mArchiveSourcePath; |
| 86 | private String[] mSeparateProcesses; |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 87 | private static final int SDK_VERSION = Build.VERSION.SDK_INT; |
| 88 | private static final String SDK_CODENAME = "REL".equals(Build.VERSION.CODENAME) |
| 89 | ? null : Build.VERSION.CODENAME; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | private int mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 92 | |
| 93 | private static final Object mSync = new Object(); |
| 94 | private static WeakReference<byte[]> mReadBuffer; |
| 95 | |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 96 | private static boolean sCompatibilityModeEnabled = true; |
| 97 | private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 99 | static class ParsePackageItemArgs { |
| 100 | final Package owner; |
| 101 | final String[] outError; |
| 102 | final int nameRes; |
| 103 | final int labelRes; |
| 104 | final int iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 105 | final int logoRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 106 | |
| 107 | String tag; |
| 108 | TypedArray sa; |
| 109 | |
| 110 | ParsePackageItemArgs(Package _owner, String[] _outError, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 111 | int _nameRes, int _labelRes, int _iconRes, int _logoRes) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 112 | owner = _owner; |
| 113 | outError = _outError; |
| 114 | nameRes = _nameRes; |
| 115 | labelRes = _labelRes; |
| 116 | iconRes = _iconRes; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 117 | logoRes = _logoRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | static class ParseComponentArgs extends ParsePackageItemArgs { |
| 122 | final String[] sepProcesses; |
| 123 | final int processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 124 | final int descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 125 | final int enabledRes; |
| 126 | int flags; |
| 127 | |
| 128 | ParseComponentArgs(Package _owner, String[] _outError, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 129 | int _nameRes, int _labelRes, int _iconRes, int _logoRes, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 130 | String[] _sepProcesses, int _processRes, |
| 131 | int _descriptionRes, int _enabledRes) { |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 132 | super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 133 | sepProcesses = _sepProcesses; |
| 134 | processRes = _processRes; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 135 | descriptionRes = _descriptionRes; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 136 | enabledRes = _enabledRes; |
| 137 | } |
| 138 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 139 | |
| 140 | /* Light weight package info. |
| 141 | * @hide |
| 142 | */ |
| 143 | public static class PackageLite { |
| 144 | public String packageName; |
| 145 | public int installLocation; |
| 146 | public String mScanPath; |
| 147 | public PackageLite(String packageName, int installLocation) { |
| 148 | this.packageName = packageName; |
| 149 | this.installLocation = installLocation; |
| 150 | } |
| 151 | } |
| 152 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 153 | private ParsePackageItemArgs mParseInstrumentationArgs; |
| 154 | private ParseComponentArgs mParseActivityArgs; |
| 155 | private ParseComponentArgs mParseActivityAliasArgs; |
| 156 | private ParseComponentArgs mParseServiceArgs; |
| 157 | private ParseComponentArgs mParseProviderArgs; |
| 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** If set to true, we will only allow package files that exactly match |
| 160 | * the DTD. Otherwise, we try to get as much from the package as we |
| 161 | * can without failing. This should normally be set to false, to |
| 162 | * support extensions to the DTD in future versions. */ |
| 163 | private static final boolean RIGID_PARSER = false; |
| 164 | |
| 165 | private static final String TAG = "PackageParser"; |
| 166 | |
| 167 | public PackageParser(String archiveSourcePath) { |
| 168 | mArchiveSourcePath = archiveSourcePath; |
| 169 | } |
| 170 | |
| 171 | public void setSeparateProcesses(String[] procs) { |
| 172 | mSeparateProcesses = procs; |
| 173 | } |
| 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | private static final boolean isPackageFilename(String name) { |
| 176 | return name.endsWith(".apk"); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Generate and return the {@link PackageInfo} for a parsed package. |
| 181 | * |
| 182 | * @param p the parsed package. |
| 183 | * @param flags indicating which optional information is included. |
| 184 | */ |
| 185 | public static PackageInfo generatePackageInfo(PackageParser.Package p, |
Dianne Hackborn | 78d6883 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 186 | int gids[], int flags, long firstInstallTime, long lastUpdateTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | |
| 188 | PackageInfo pi = new PackageInfo(); |
| 189 | pi.packageName = p.packageName; |
| 190 | pi.versionCode = p.mVersionCode; |
| 191 | pi.versionName = p.mVersionName; |
| 192 | pi.sharedUserId = p.mSharedUserId; |
| 193 | pi.sharedUserLabel = p.mSharedUserLabel; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 194 | pi.applicationInfo = generateApplicationInfo(p, flags); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 195 | pi.installLocation = p.installLocation; |
Dianne Hackborn | 78d6883 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 196 | pi.firstInstallTime = firstInstallTime; |
| 197 | pi.lastUpdateTime = lastUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | if ((flags&PackageManager.GET_GIDS) != 0) { |
| 199 | pi.gids = gids; |
| 200 | } |
| 201 | if ((flags&PackageManager.GET_CONFIGURATIONS) != 0) { |
| 202 | int N = p.configPreferences.size(); |
| 203 | if (N > 0) { |
| 204 | pi.configPreferences = new ConfigurationInfo[N]; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 205 | p.configPreferences.toArray(pi.configPreferences); |
| 206 | } |
| 207 | N = p.reqFeatures != null ? p.reqFeatures.size() : 0; |
| 208 | if (N > 0) { |
| 209 | pi.reqFeatures = new FeatureInfo[N]; |
| 210 | p.reqFeatures.toArray(pi.reqFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | if ((flags&PackageManager.GET_ACTIVITIES) != 0) { |
| 214 | int N = p.activities.size(); |
| 215 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 216 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 217 | pi.activities = new ActivityInfo[N]; |
| 218 | } else { |
| 219 | int num = 0; |
| 220 | for (int i=0; i<N; i++) { |
| 221 | if (p.activities.get(i).info.enabled) num++; |
| 222 | } |
| 223 | pi.activities = new ActivityInfo[num]; |
| 224 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 225 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | final Activity activity = p.activities.get(i); |
| 227 | if (activity.info.enabled |
| 228 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 229 | pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | if ((flags&PackageManager.GET_RECEIVERS) != 0) { |
| 235 | int N = p.receivers.size(); |
| 236 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 237 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 238 | pi.receivers = new ActivityInfo[N]; |
| 239 | } else { |
| 240 | int num = 0; |
| 241 | for (int i=0; i<N; i++) { |
| 242 | if (p.receivers.get(i).info.enabled) num++; |
| 243 | } |
| 244 | pi.receivers = new ActivityInfo[num]; |
| 245 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 246 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | final Activity activity = p.receivers.get(i); |
| 248 | if (activity.info.enabled |
| 249 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 250 | pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | if ((flags&PackageManager.GET_SERVICES) != 0) { |
| 256 | int N = p.services.size(); |
| 257 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 258 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 259 | pi.services = new ServiceInfo[N]; |
| 260 | } else { |
| 261 | int num = 0; |
| 262 | for (int i=0; i<N; i++) { |
| 263 | if (p.services.get(i).info.enabled) num++; |
| 264 | } |
| 265 | pi.services = new ServiceInfo[num]; |
| 266 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 267 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | final Service service = p.services.get(i); |
| 269 | if (service.info.enabled |
| 270 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 271 | pi.services[j++] = generateServiceInfo(p.services.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | if ((flags&PackageManager.GET_PROVIDERS) != 0) { |
| 277 | int N = p.providers.size(); |
| 278 | if (N > 0) { |
Dianne Hackborn | 7eca687 | 2009-09-28 23:57:05 -0700 | [diff] [blame] | 279 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 280 | pi.providers = new ProviderInfo[N]; |
| 281 | } else { |
| 282 | int num = 0; |
| 283 | for (int i=0; i<N; i++) { |
| 284 | if (p.providers.get(i).info.enabled) num++; |
| 285 | } |
| 286 | pi.providers = new ProviderInfo[num]; |
| 287 | } |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 288 | for (int i=0, j=0; i<N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | final Provider provider = p.providers.get(i); |
| 290 | if (provider.info.enabled |
| 291 | || (flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 292 | pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | if ((flags&PackageManager.GET_INSTRUMENTATION) != 0) { |
| 298 | int N = p.instrumentation.size(); |
| 299 | if (N > 0) { |
| 300 | pi.instrumentation = new InstrumentationInfo[N]; |
| 301 | for (int i=0; i<N; i++) { |
| 302 | pi.instrumentation[i] = generateInstrumentationInfo( |
| 303 | p.instrumentation.get(i), flags); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | if ((flags&PackageManager.GET_PERMISSIONS) != 0) { |
| 308 | int N = p.permissions.size(); |
| 309 | if (N > 0) { |
| 310 | pi.permissions = new PermissionInfo[N]; |
| 311 | for (int i=0; i<N; i++) { |
| 312 | pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); |
| 313 | } |
| 314 | } |
| 315 | N = p.requestedPermissions.size(); |
| 316 | if (N > 0) { |
| 317 | pi.requestedPermissions = new String[N]; |
| 318 | for (int i=0; i<N; i++) { |
| 319 | pi.requestedPermissions[i] = p.requestedPermissions.get(i); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | if ((flags&PackageManager.GET_SIGNATURES) != 0) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 324 | int N = (p.mSignatures != null) ? p.mSignatures.length : 0; |
| 325 | if (N > 0) { |
| 326 | pi.signatures = new Signature[N]; |
| 327 | System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | return pi; |
| 331 | } |
| 332 | |
| 333 | private Certificate[] loadCertificates(JarFile jarFile, JarEntry je, |
| 334 | byte[] readBuffer) { |
| 335 | try { |
| 336 | // We must read the stream for the JarEntry to retrieve |
| 337 | // its certificates. |
Kenny Root | d63f7db | 2010-09-27 08:07:48 -0700 | [diff] [blame] | 338 | InputStream is = new BufferedInputStream(jarFile.getInputStream(je)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | while (is.read(readBuffer, 0, readBuffer.length) != -1) { |
| 340 | // not using |
| 341 | } |
| 342 | is.close(); |
| 343 | return je != null ? je.getCertificates() : null; |
| 344 | } catch (IOException e) { |
| 345 | Log.w(TAG, "Exception reading " + je.getName() + " in " |
| 346 | + jarFile.getName(), e); |
Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 347 | } catch (RuntimeException e) { |
| 348 | Log.w(TAG, "Exception reading " + je.getName() + " in " |
| 349 | + jarFile.getName(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | } |
| 351 | return null; |
| 352 | } |
| 353 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 354 | public final static int PARSE_IS_SYSTEM = 1<<0; |
| 355 | public final static int PARSE_CHATTY = 1<<1; |
| 356 | public final static int PARSE_MUST_BE_APK = 1<<2; |
| 357 | public final static int PARSE_IGNORE_PROCESSES = 1<<3; |
| 358 | public final static int PARSE_FORWARD_LOCK = 1<<4; |
| 359 | public final static int PARSE_ON_SDCARD = 1<<5; |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 360 | public final static int PARSE_IS_SYSTEM_DIR = 1<<6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | |
| 362 | public int getParseError() { |
| 363 | return mParseError; |
| 364 | } |
| 365 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 366 | public Package parsePackage(File sourceFile, String destCodePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | DisplayMetrics metrics, int flags) { |
| 368 | mParseError = PackageManager.INSTALL_SUCCEEDED; |
| 369 | |
| 370 | mArchiveSourcePath = sourceFile.getPath(); |
| 371 | if (!sourceFile.isFile()) { |
| 372 | Log.w(TAG, "Skipping dir: " + mArchiveSourcePath); |
| 373 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
| 374 | return null; |
| 375 | } |
| 376 | if (!isPackageFilename(sourceFile.getName()) |
| 377 | && (flags&PARSE_MUST_BE_APK) != 0) { |
| 378 | if ((flags&PARSE_IS_SYSTEM) == 0) { |
| 379 | // We expect to have non-.apk files in the system dir, |
| 380 | // so don't warn about them. |
| 381 | Log.w(TAG, "Skipping non-package file: " + mArchiveSourcePath); |
| 382 | } |
| 383 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; |
| 384 | return null; |
| 385 | } |
| 386 | |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 387 | if ((flags&PARSE_CHATTY) != 0 && false) Log.d( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | TAG, "Scanning package: " + mArchiveSourcePath); |
| 389 | |
| 390 | XmlResourceParser parser = null; |
| 391 | AssetManager assmgr = null; |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 392 | Resources res = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | boolean assetError = true; |
| 394 | try { |
| 395 | assmgr = new AssetManager(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 396 | int cookie = assmgr.addAssetPath(mArchiveSourcePath); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 397 | if (cookie != 0) { |
| 398 | res = new Resources(assmgr, metrics, null); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 399 | assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 400 | Build.VERSION.RESOURCES_SDK_INT); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 401 | parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | assetError = false; |
| 403 | } else { |
| 404 | Log.w(TAG, "Failed adding asset path:"+mArchiveSourcePath); |
| 405 | } |
| 406 | } catch (Exception e) { |
| 407 | Log.w(TAG, "Unable to read AndroidManifest.xml of " |
| 408 | + mArchiveSourcePath, e); |
| 409 | } |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 410 | if (assetError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | if (assmgr != null) assmgr.close(); |
| 412 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST; |
| 413 | return null; |
| 414 | } |
| 415 | String[] errorText = new String[1]; |
| 416 | Package pkg = null; |
| 417 | Exception errorException = null; |
| 418 | try { |
| 419 | // XXXX todo: need to figure out correct configuration. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | pkg = parsePackage(res, parser, flags, errorText); |
| 421 | } catch (Exception e) { |
| 422 | errorException = e; |
| 423 | mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | if (pkg == null) { |
| 428 | if (errorException != null) { |
| 429 | Log.w(TAG, mArchiveSourcePath, errorException); |
| 430 | } else { |
| 431 | Log.w(TAG, mArchiveSourcePath + " (at " |
| 432 | + parser.getPositionDescription() |
| 433 | + "): " + errorText[0]); |
| 434 | } |
| 435 | parser.close(); |
| 436 | assmgr.close(); |
| 437 | if (mParseError == PackageManager.INSTALL_SUCCEEDED) { |
| 438 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 439 | } |
| 440 | return null; |
| 441 | } |
| 442 | |
| 443 | parser.close(); |
| 444 | assmgr.close(); |
| 445 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 446 | // Set code and resource paths |
| 447 | pkg.mPath = destCodePath; |
| 448 | pkg.mScanPath = mArchiveSourcePath; |
| 449 | //pkg.applicationInfo.sourceDir = destCodePath; |
| 450 | //pkg.applicationInfo.publicSourceDir = destRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | pkg.mSignatures = null; |
| 452 | |
| 453 | return pkg; |
| 454 | } |
| 455 | |
| 456 | public boolean collectCertificates(Package pkg, int flags) { |
| 457 | pkg.mSignatures = null; |
| 458 | |
| 459 | WeakReference<byte[]> readBufferRef; |
| 460 | byte[] readBuffer = null; |
| 461 | synchronized (mSync) { |
| 462 | readBufferRef = mReadBuffer; |
| 463 | if (readBufferRef != null) { |
| 464 | mReadBuffer = null; |
| 465 | readBuffer = readBufferRef.get(); |
| 466 | } |
| 467 | if (readBuffer == null) { |
| 468 | readBuffer = new byte[8192]; |
| 469 | readBufferRef = new WeakReference<byte[]>(readBuffer); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | try { |
| 474 | JarFile jarFile = new JarFile(mArchiveSourcePath); |
| 475 | |
| 476 | Certificate[] certs = null; |
| 477 | |
| 478 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 479 | // If this package comes from the system image, then we |
| 480 | // can trust it... we'll just use the AndroidManifest.xml |
| 481 | // to retrieve its signatures, not validating all of the |
| 482 | // files. |
| 483 | JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml"); |
| 484 | certs = loadCertificates(jarFile, jarEntry, readBuffer); |
| 485 | if (certs == null) { |
| 486 | Log.e(TAG, "Package " + pkg.packageName |
| 487 | + " has no certificates at entry " |
| 488 | + jarEntry.getName() + "; ignoring!"); |
| 489 | jarFile.close(); |
| 490 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 491 | return false; |
| 492 | } |
| 493 | if (false) { |
| 494 | Log.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry |
| 495 | + " certs=" + (certs != null ? certs.length : 0)); |
| 496 | if (certs != null) { |
| 497 | final int N = certs.length; |
| 498 | for (int i=0; i<N; i++) { |
| 499 | Log.i(TAG, " Public key: " |
| 500 | + certs[i].getPublicKey().getEncoded() |
| 501 | + " " + certs[i].getPublicKey()); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | } else { |
| 507 | Enumeration entries = jarFile.entries(); |
| 508 | while (entries.hasMoreElements()) { |
| 509 | JarEntry je = (JarEntry)entries.nextElement(); |
| 510 | if (je.isDirectory()) continue; |
| 511 | if (je.getName().startsWith("META-INF/")) continue; |
| 512 | Certificate[] localCerts = loadCertificates(jarFile, je, |
| 513 | readBuffer); |
| 514 | if (false) { |
| 515 | Log.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName() |
| 516 | + ": certs=" + certs + " (" |
| 517 | + (certs != null ? certs.length : 0) + ")"); |
| 518 | } |
| 519 | if (localCerts == null) { |
| 520 | Log.e(TAG, "Package " + pkg.packageName |
| 521 | + " has no certificates at entry " |
| 522 | + je.getName() + "; ignoring!"); |
| 523 | jarFile.close(); |
| 524 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 525 | return false; |
| 526 | } else if (certs == null) { |
| 527 | certs = localCerts; |
| 528 | } else { |
| 529 | // Ensure all certificates match. |
| 530 | for (int i=0; i<certs.length; i++) { |
| 531 | boolean found = false; |
| 532 | for (int j=0; j<localCerts.length; j++) { |
| 533 | if (certs[i] != null && |
| 534 | certs[i].equals(localCerts[j])) { |
| 535 | found = true; |
| 536 | break; |
| 537 | } |
| 538 | } |
| 539 | if (!found || certs.length != localCerts.length) { |
| 540 | Log.e(TAG, "Package " + pkg.packageName |
| 541 | + " has mismatched certificates at entry " |
| 542 | + je.getName() + "; ignoring!"); |
| 543 | jarFile.close(); |
| 544 | mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 545 | return false; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | jarFile.close(); |
| 552 | |
| 553 | synchronized (mSync) { |
| 554 | mReadBuffer = readBufferRef; |
| 555 | } |
| 556 | |
| 557 | if (certs != null && certs.length > 0) { |
| 558 | final int N = certs.length; |
| 559 | pkg.mSignatures = new Signature[certs.length]; |
| 560 | for (int i=0; i<N; i++) { |
| 561 | pkg.mSignatures[i] = new Signature( |
| 562 | certs[i].getEncoded()); |
| 563 | } |
| 564 | } else { |
| 565 | Log.e(TAG, "Package " + pkg.packageName |
| 566 | + " has no certificates; ignoring!"); |
| 567 | mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES; |
| 568 | return false; |
| 569 | } |
| 570 | } catch (CertificateEncodingException e) { |
| 571 | Log.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
| 572 | mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; |
| 573 | return false; |
| 574 | } catch (IOException e) { |
| 575 | Log.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
| 576 | mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; |
| 577 | return false; |
| 578 | } catch (RuntimeException e) { |
| 579 | Log.w(TAG, "Exception reading " + mArchiveSourcePath, e); |
| 580 | mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | return true; |
| 585 | } |
| 586 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 587 | /* |
| 588 | * Utility method that retrieves just the package name and install |
| 589 | * location from the apk location at the given file path. |
| 590 | * @param packageFilePath file location of the apk |
| 591 | * @param flags Special parse flags |
Kenny Root | 930d3af | 2010-07-30 16:52:29 -0700 | [diff] [blame] | 592 | * @return PackageLite object with package information or null on failure. |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 593 | */ |
| 594 | public static PackageLite parsePackageLite(String packageFilePath, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | XmlResourceParser parser = null; |
| 596 | AssetManager assmgr = null; |
| 597 | try { |
| 598 | assmgr = new AssetManager(); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 599 | assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 600 | Build.VERSION.RESOURCES_SDK_INT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | int cookie = assmgr.addAssetPath(packageFilePath); |
| 602 | parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml"); |
| 603 | } catch (Exception e) { |
| 604 | if (assmgr != null) assmgr.close(); |
| 605 | Log.w(TAG, "Unable to read AndroidManifest.xml of " |
| 606 | + packageFilePath, e); |
| 607 | return null; |
| 608 | } |
| 609 | AttributeSet attrs = parser; |
| 610 | String errors[] = new String[1]; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 611 | PackageLite packageLite = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | try { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 613 | packageLite = parsePackageLite(parser, attrs, flags, errors); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | } catch (IOException e) { |
| 615 | Log.w(TAG, packageFilePath, e); |
| 616 | } catch (XmlPullParserException e) { |
| 617 | Log.w(TAG, packageFilePath, e); |
| 618 | } finally { |
| 619 | if (parser != null) parser.close(); |
| 620 | if (assmgr != null) assmgr.close(); |
| 621 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 622 | if (packageLite == null) { |
| 623 | Log.e(TAG, "parsePackageLite error: " + errors[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | return null; |
| 625 | } |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 626 | return packageLite; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | private static String validateName(String name, boolean requiresSeparator) { |
| 630 | final int N = name.length(); |
| 631 | boolean hasSep = false; |
| 632 | boolean front = true; |
| 633 | for (int i=0; i<N; i++) { |
| 634 | final char c = name.charAt(i); |
| 635 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 636 | front = false; |
| 637 | continue; |
| 638 | } |
| 639 | if (!front) { |
| 640 | if ((c >= '0' && c <= '9') || c == '_') { |
| 641 | continue; |
| 642 | } |
| 643 | } |
| 644 | if (c == '.') { |
| 645 | hasSep = true; |
| 646 | front = true; |
| 647 | continue; |
| 648 | } |
| 649 | return "bad character '" + c + "'"; |
| 650 | } |
| 651 | return hasSep || !requiresSeparator |
| 652 | ? null : "must have at least one '.' separator"; |
| 653 | } |
| 654 | |
| 655 | private static String parsePackageName(XmlPullParser parser, |
| 656 | AttributeSet attrs, int flags, String[] outError) |
| 657 | throws IOException, XmlPullParserException { |
| 658 | |
| 659 | int type; |
| 660 | while ((type=parser.next()) != parser.START_TAG |
| 661 | && type != parser.END_DOCUMENT) { |
| 662 | ; |
| 663 | } |
| 664 | |
| 665 | if (type != parser.START_TAG) { |
| 666 | outError[0] = "No start tag found"; |
| 667 | return null; |
| 668 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 669 | if ((flags&PARSE_CHATTY) != 0 && false) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | TAG, "Root element name: '" + parser.getName() + "'"); |
| 671 | if (!parser.getName().equals("manifest")) { |
| 672 | outError[0] = "No <manifest> tag"; |
| 673 | return null; |
| 674 | } |
| 675 | String pkgName = attrs.getAttributeValue(null, "package"); |
| 676 | if (pkgName == null || pkgName.length() == 0) { |
| 677 | outError[0] = "<manifest> does not specify package"; |
| 678 | return null; |
| 679 | } |
| 680 | String nameError = validateName(pkgName, true); |
| 681 | if (nameError != null && !"android".equals(pkgName)) { |
| 682 | outError[0] = "<manifest> specifies bad package name \"" |
| 683 | + pkgName + "\": " + nameError; |
| 684 | return null; |
| 685 | } |
| 686 | |
| 687 | return pkgName.intern(); |
| 688 | } |
| 689 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 690 | private static PackageLite parsePackageLite(XmlPullParser parser, |
| 691 | AttributeSet attrs, int flags, String[] outError) |
| 692 | throws IOException, XmlPullParserException { |
| 693 | |
| 694 | int type; |
| 695 | while ((type=parser.next()) != parser.START_TAG |
| 696 | && type != parser.END_DOCUMENT) { |
| 697 | ; |
| 698 | } |
| 699 | |
| 700 | if (type != parser.START_TAG) { |
| 701 | outError[0] = "No start tag found"; |
| 702 | return null; |
| 703 | } |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 704 | if ((flags&PARSE_CHATTY) != 0 && false) Log.v( |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 705 | TAG, "Root element name: '" + parser.getName() + "'"); |
| 706 | if (!parser.getName().equals("manifest")) { |
| 707 | outError[0] = "No <manifest> tag"; |
| 708 | return null; |
| 709 | } |
| 710 | String pkgName = attrs.getAttributeValue(null, "package"); |
| 711 | if (pkgName == null || pkgName.length() == 0) { |
| 712 | outError[0] = "<manifest> does not specify package"; |
| 713 | return null; |
| 714 | } |
| 715 | String nameError = validateName(pkgName, true); |
| 716 | if (nameError != null && !"android".equals(pkgName)) { |
| 717 | outError[0] = "<manifest> specifies bad package name \"" |
| 718 | + pkgName + "\": " + nameError; |
| 719 | return null; |
| 720 | } |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 721 | int installLocation = PARSE_DEFAULT_INSTALL_LOCATION; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 722 | for (int i = 0; i < attrs.getAttributeCount(); i++) { |
| 723 | String attr = attrs.getAttributeName(i); |
| 724 | if (attr.equals("installLocation")) { |
| 725 | installLocation = attrs.getAttributeIntValue(i, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 726 | PARSE_DEFAULT_INSTALL_LOCATION); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 727 | break; |
| 728 | } |
| 729 | } |
| 730 | return new PackageLite(pkgName.intern(), installLocation); |
| 731 | } |
| 732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | /** |
| 734 | * Temporary. |
| 735 | */ |
| 736 | static public Signature stringToSignature(String str) { |
| 737 | final int N = str.length(); |
| 738 | byte[] sig = new byte[N]; |
| 739 | for (int i=0; i<N; i++) { |
| 740 | sig[i] = (byte)str.charAt(i); |
| 741 | } |
| 742 | return new Signature(sig); |
| 743 | } |
| 744 | |
| 745 | private Package parsePackage( |
| 746 | Resources res, XmlResourceParser parser, int flags, String[] outError) |
| 747 | throws XmlPullParserException, IOException { |
| 748 | AttributeSet attrs = parser; |
| 749 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 750 | mParseInstrumentationArgs = null; |
| 751 | mParseActivityArgs = null; |
| 752 | mParseServiceArgs = null; |
| 753 | mParseProviderArgs = null; |
| 754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | String pkgName = parsePackageName(parser, attrs, flags, outError); |
| 756 | if (pkgName == null) { |
| 757 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 758 | return null; |
| 759 | } |
| 760 | int type; |
| 761 | |
| 762 | final Package pkg = new Package(pkgName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | boolean foundApp = false; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | TypedArray sa = res.obtainAttributes(attrs, |
| 766 | com.android.internal.R.styleable.AndroidManifest); |
| 767 | pkg.mVersionCode = sa.getInteger( |
| 768 | com.android.internal.R.styleable.AndroidManifest_versionCode, 0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 769 | pkg.mVersionName = sa.getNonConfigurationString( |
| 770 | com.android.internal.R.styleable.AndroidManifest_versionName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | if (pkg.mVersionName != null) { |
| 772 | pkg.mVersionName = pkg.mVersionName.intern(); |
| 773 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 774 | String str = sa.getNonConfigurationString( |
| 775 | com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0); |
| 776 | if (str != null && str.length() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | String nameError = validateName(str, true); |
| 778 | if (nameError != null && !"android".equals(pkgName)) { |
| 779 | outError[0] = "<manifest> specifies bad sharedUserId name \"" |
| 780 | + str + "\": " + nameError; |
| 781 | mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID; |
| 782 | return null; |
| 783 | } |
| 784 | pkg.mSharedUserId = str.intern(); |
| 785 | pkg.mSharedUserLabel = sa.getResourceId( |
| 786 | com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0); |
| 787 | } |
| 788 | sa.recycle(); |
Suchi Amalapurapu | aaec779 | 2010-02-25 11:49:43 -0800 | [diff] [blame] | 789 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 790 | pkg.installLocation = sa.getInteger( |
| 791 | com.android.internal.R.styleable.AndroidManifest_installLocation, |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 792 | PARSE_DEFAULT_INSTALL_LOCATION); |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 793 | pkg.applicationInfo.installLocation = pkg.installLocation; |
| 794 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 795 | // Resource boolean are -1, so 1 means we don't know the value. |
| 796 | int supportsSmallScreens = 1; |
| 797 | int supportsNormalScreens = 1; |
| 798 | int supportsLargeScreens = 1; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 799 | int supportsXLargeScreens = 1; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 800 | int resizeable = 1; |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 801 | int anyDensity = 1; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | int outerDepth = parser.getDepth(); |
| 804 | while ((type=parser.next()) != parser.END_DOCUMENT |
| 805 | && (type != parser.END_TAG || parser.getDepth() > outerDepth)) { |
| 806 | if (type == parser.END_TAG || type == parser.TEXT) { |
| 807 | continue; |
| 808 | } |
| 809 | |
| 810 | String tagName = parser.getName(); |
| 811 | if (tagName.equals("application")) { |
| 812 | if (foundApp) { |
| 813 | if (RIGID_PARSER) { |
| 814 | outError[0] = "<manifest> has more than one <application>"; |
| 815 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 816 | return null; |
| 817 | } else { |
| 818 | Log.w(TAG, "<manifest> has more than one <application>"); |
| 819 | XmlUtils.skipCurrentTag(parser); |
| 820 | continue; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | foundApp = true; |
| 825 | if (!parseApplication(pkg, res, parser, attrs, flags, outError)) { |
| 826 | return null; |
| 827 | } |
| 828 | } else if (tagName.equals("permission-group")) { |
| 829 | if (parsePermissionGroup(pkg, res, parser, attrs, outError) == null) { |
| 830 | return null; |
| 831 | } |
| 832 | } else if (tagName.equals("permission")) { |
| 833 | if (parsePermission(pkg, res, parser, attrs, outError) == null) { |
| 834 | return null; |
| 835 | } |
| 836 | } else if (tagName.equals("permission-tree")) { |
| 837 | if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) { |
| 838 | return null; |
| 839 | } |
| 840 | } else if (tagName.equals("uses-permission")) { |
| 841 | sa = res.obtainAttributes(attrs, |
| 842 | com.android.internal.R.styleable.AndroidManifestUsesPermission); |
| 843 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 844 | // Note: don't allow this value to be a reference to a resource |
| 845 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | String name = sa.getNonResourceString( |
| 847 | com.android.internal.R.styleable.AndroidManifestUsesPermission_name); |
| 848 | |
| 849 | sa.recycle(); |
| 850 | |
| 851 | if (name != null && !pkg.requestedPermissions.contains(name)) { |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 852 | pkg.requestedPermissions.add(name.intern()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | XmlUtils.skipCurrentTag(parser); |
| 856 | |
| 857 | } else if (tagName.equals("uses-configuration")) { |
| 858 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 859 | sa = res.obtainAttributes(attrs, |
| 860 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration); |
| 861 | cPref.reqTouchScreen = sa.getInt( |
| 862 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, |
| 863 | Configuration.TOUCHSCREEN_UNDEFINED); |
| 864 | cPref.reqKeyboardType = sa.getInt( |
| 865 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, |
| 866 | Configuration.KEYBOARD_UNDEFINED); |
| 867 | if (sa.getBoolean( |
| 868 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, |
| 869 | false)) { |
| 870 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 871 | } |
| 872 | cPref.reqNavigation = sa.getInt( |
| 873 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, |
| 874 | Configuration.NAVIGATION_UNDEFINED); |
| 875 | if (sa.getBoolean( |
| 876 | com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, |
| 877 | false)) { |
| 878 | cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 879 | } |
| 880 | sa.recycle(); |
| 881 | pkg.configPreferences.add(cPref); |
| 882 | |
| 883 | XmlUtils.skipCurrentTag(parser); |
| 884 | |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 885 | } else if (tagName.equals("uses-feature")) { |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 886 | FeatureInfo fi = new FeatureInfo(); |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 887 | sa = res.obtainAttributes(attrs, |
| 888 | com.android.internal.R.styleable.AndroidManifestUsesFeature); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 889 | // Note: don't allow this value to be a reference to a resource |
| 890 | // that may change. |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 891 | fi.name = sa.getNonResourceString( |
| 892 | com.android.internal.R.styleable.AndroidManifestUsesFeature_name); |
| 893 | if (fi.name == null) { |
| 894 | fi.reqGlEsVersion = sa.getInt( |
| 895 | com.android.internal.R.styleable.AndroidManifestUsesFeature_glEsVersion, |
| 896 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 897 | } |
| 898 | if (sa.getBoolean( |
| 899 | com.android.internal.R.styleable.AndroidManifestUsesFeature_required, |
| 900 | true)) { |
| 901 | fi.flags |= FeatureInfo.FLAG_REQUIRED; |
| 902 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 903 | sa.recycle(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 904 | if (pkg.reqFeatures == null) { |
| 905 | pkg.reqFeatures = new ArrayList<FeatureInfo>(); |
| 906 | } |
| 907 | pkg.reqFeatures.add(fi); |
| 908 | |
| 909 | if (fi.name == null) { |
| 910 | ConfigurationInfo cPref = new ConfigurationInfo(); |
| 911 | cPref.reqGlEsVersion = fi.reqGlEsVersion; |
| 912 | pkg.configPreferences.add(cPref); |
| 913 | } |
Suchi Amalapurapu | d299b81 | 2009-06-05 10:26:19 -0700 | [diff] [blame] | 914 | |
| 915 | XmlUtils.skipCurrentTag(parser); |
| 916 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 917 | } else if (tagName.equals("uses-sdk")) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 918 | if (SDK_VERSION > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | sa = res.obtainAttributes(attrs, |
| 920 | com.android.internal.R.styleable.AndroidManifestUsesSdk); |
| 921 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 922 | int minVers = 0; |
| 923 | String minCode = null; |
| 924 | int targetVers = 0; |
| 925 | String targetCode = null; |
| 926 | |
| 927 | TypedValue val = sa.peekValue( |
| 928 | com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion); |
| 929 | if (val != null) { |
| 930 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 931 | targetCode = minCode = val.string.toString(); |
| 932 | } else { |
| 933 | // If it's not a string, it's an integer. |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 934 | targetVers = minVers = val.data; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
| 938 | val = sa.peekValue( |
| 939 | com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion); |
| 940 | if (val != null) { |
| 941 | if (val.type == TypedValue.TYPE_STRING && val.string != null) { |
| 942 | targetCode = minCode = val.string.toString(); |
| 943 | } else { |
| 944 | // If it's not a string, it's an integer. |
| 945 | targetVers = val.data; |
| 946 | } |
| 947 | } |
| 948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | sa.recycle(); |
| 950 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 951 | if (minCode != null) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 952 | if (!minCode.equals(SDK_CODENAME)) { |
| 953 | if (SDK_CODENAME != null) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 954 | outError[0] = "Requires development platform " + minCode |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 955 | + " (current platform is " + SDK_CODENAME + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 956 | } else { |
| 957 | outError[0] = "Requires development platform " + minCode |
| 958 | + " but this is a release platform."; |
| 959 | } |
| 960 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 961 | return null; |
| 962 | } |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 963 | } else if (minVers > SDK_VERSION) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 964 | outError[0] = "Requires newer sdk version #" + minVers |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 965 | + " (current version is #" + SDK_VERSION + ")"; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 966 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 967 | return null; |
| 968 | } |
| 969 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 970 | if (targetCode != null) { |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 971 | if (!targetCode.equals(SDK_CODENAME)) { |
| 972 | if (SDK_CODENAME != null) { |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 973 | outError[0] = "Requires development platform " + targetCode |
Suchi Amalapurapu | 8d5ae98 | 2009-10-06 09:26:09 -0700 | [diff] [blame] | 974 | + " (current platform is " + SDK_CODENAME + ")"; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 975 | } else { |
| 976 | outError[0] = "Requires development platform " + targetCode |
| 977 | + " but this is a release platform."; |
| 978 | } |
| 979 | mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK; |
| 980 | return null; |
| 981 | } |
| 982 | // If the code matches, it definitely targets this SDK. |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 983 | pkg.applicationInfo.targetSdkVersion |
| 984 | = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 985 | } else { |
| 986 | pkg.applicationInfo.targetSdkVersion = targetVers; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | XmlUtils.skipCurrentTag(parser); |
| 991 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 992 | } else if (tagName.equals("supports-screens")) { |
| 993 | sa = res.obtainAttributes(attrs, |
| 994 | com.android.internal.R.styleable.AndroidManifestSupportsScreens); |
| 995 | |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 996 | pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger( |
| 997 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, |
| 998 | 0); |
| 999 | pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger( |
| 1000 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, |
| 1001 | 0); |
Dianne Hackborn | 2762ff3 | 2011-06-01 21:27:05 -0700 | [diff] [blame] | 1002 | pkg.applicationInfo.largestWidthLimitDp = sa.getInteger( |
| 1003 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, |
| 1004 | 0); |
Dianne Hackborn | df6e980 | 2011-05-26 14:20:23 -0700 | [diff] [blame] | 1005 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1006 | // This is a trick to get a boolean and still able to detect |
| 1007 | // if a value was actually set. |
| 1008 | supportsSmallScreens = sa.getInteger( |
| 1009 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, |
| 1010 | supportsSmallScreens); |
| 1011 | supportsNormalScreens = sa.getInteger( |
| 1012 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, |
| 1013 | supportsNormalScreens); |
| 1014 | supportsLargeScreens = sa.getInteger( |
| 1015 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, |
| 1016 | supportsLargeScreens); |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1017 | supportsXLargeScreens = sa.getInteger( |
| 1018 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, |
| 1019 | supportsXLargeScreens); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1020 | resizeable = sa.getInteger( |
| 1021 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1022 | resizeable); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1023 | anyDensity = sa.getInteger( |
| 1024 | com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, |
| 1025 | anyDensity); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1026 | |
| 1027 | sa.recycle(); |
| 1028 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 1029 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1030 | |
| 1031 | } else if (tagName.equals("protected-broadcast")) { |
| 1032 | sa = res.obtainAttributes(attrs, |
| 1033 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast); |
| 1034 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1035 | // Note: don't allow this value to be a reference to a resource |
| 1036 | // that may change. |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1037 | String name = sa.getNonResourceString( |
| 1038 | com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name); |
| 1039 | |
| 1040 | sa.recycle(); |
| 1041 | |
| 1042 | if (name != null && (flags&PARSE_IS_SYSTEM) != 0) { |
| 1043 | if (pkg.protectedBroadcasts == null) { |
| 1044 | pkg.protectedBroadcasts = new ArrayList<String>(); |
| 1045 | } |
| 1046 | if (!pkg.protectedBroadcasts.contains(name)) { |
| 1047 | pkg.protectedBroadcasts.add(name.intern()); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | XmlUtils.skipCurrentTag(parser); |
| 1052 | |
| 1053 | } else if (tagName.equals("instrumentation")) { |
| 1054 | if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) { |
| 1055 | return null; |
| 1056 | } |
| 1057 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1058 | } else if (tagName.equals("original-package")) { |
| 1059 | sa = res.obtainAttributes(attrs, |
| 1060 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 1061 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1062 | String orig =sa.getNonConfigurationString( |
| 1063 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1064 | if (!pkg.packageName.equals(orig)) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 1065 | if (pkg.mOriginalPackages == null) { |
| 1066 | pkg.mOriginalPackages = new ArrayList<String>(); |
| 1067 | pkg.mRealPackage = pkg.packageName; |
| 1068 | } |
| 1069 | pkg.mOriginalPackages.add(orig); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1070 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1071 | |
| 1072 | sa.recycle(); |
| 1073 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1074 | XmlUtils.skipCurrentTag(parser); |
| 1075 | |
| 1076 | } else if (tagName.equals("adopt-permissions")) { |
| 1077 | sa = res.obtainAttributes(attrs, |
| 1078 | com.android.internal.R.styleable.AndroidManifestOriginalPackage); |
| 1079 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1080 | String name = sa.getNonConfigurationString( |
| 1081 | com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1082 | |
| 1083 | sa.recycle(); |
| 1084 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 1085 | if (name != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 1086 | if (pkg.mAdoptPermissions == null) { |
| 1087 | pkg.mAdoptPermissions = new ArrayList<String>(); |
| 1088 | } |
| 1089 | pkg.mAdoptPermissions.add(name); |
| 1090 | } |
| 1091 | |
| 1092 | XmlUtils.skipCurrentTag(parser); |
| 1093 | |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1094 | } else if (tagName.equals("uses-gl-texture")) { |
| 1095 | // Just skip this tag |
| 1096 | XmlUtils.skipCurrentTag(parser); |
| 1097 | continue; |
| 1098 | |
| 1099 | } else if (tagName.equals("compatible-screens")) { |
| 1100 | // Just skip this tag |
| 1101 | XmlUtils.skipCurrentTag(parser); |
| 1102 | continue; |
| 1103 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1104 | } else if (tagName.equals("eat-comment")) { |
| 1105 | // Just skip this tag |
| 1106 | XmlUtils.skipCurrentTag(parser); |
| 1107 | continue; |
| 1108 | |
| 1109 | } else if (RIGID_PARSER) { |
| 1110 | outError[0] = "Bad element under <manifest>: " |
| 1111 | + parser.getName(); |
| 1112 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1113 | return null; |
| 1114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | } else { |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1116 | Log.w(TAG, "Unknown element under <manifest>: " + parser.getName() |
| 1117 | + " at " + mArchiveSourcePath + " " |
| 1118 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | XmlUtils.skipCurrentTag(parser); |
| 1120 | continue; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | if (!foundApp && pkg.instrumentation.size() == 0) { |
| 1125 | outError[0] = "<manifest> does not contain an <application> or <instrumentation>"; |
| 1126 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; |
| 1127 | } |
| 1128 | |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1129 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1130 | StringBuilder implicitPerms = null; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1131 | for (int ip=0; ip<NP; ip++) { |
| 1132 | final PackageParser.NewPermissionInfo npi |
| 1133 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 1134 | if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { |
| 1135 | break; |
| 1136 | } |
| 1137 | if (!pkg.requestedPermissions.contains(npi.name)) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1138 | if (implicitPerms == null) { |
| 1139 | implicitPerms = new StringBuilder(128); |
| 1140 | implicitPerms.append(pkg.packageName); |
| 1141 | implicitPerms.append(": compat added "); |
| 1142 | } else { |
| 1143 | implicitPerms.append(' '); |
| 1144 | } |
| 1145 | implicitPerms.append(npi.name); |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 1146 | pkg.requestedPermissions.add(npi.name); |
| 1147 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1148 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1149 | if (implicitPerms != null) { |
| 1150 | Log.i(TAG, implicitPerms.toString()); |
| 1151 | } |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 1152 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1153 | if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 |
| 1154 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1155 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1156 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; |
| 1157 | } |
| 1158 | if (supportsNormalScreens != 0) { |
| 1159 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; |
| 1160 | } |
| 1161 | if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 |
| 1162 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1163 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1164 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; |
| 1165 | } |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 1166 | if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 |
| 1167 | && pkg.applicationInfo.targetSdkVersion |
| 1168 | >= android.os.Build.VERSION_CODES.GINGERBREAD)) { |
| 1169 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; |
| 1170 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1171 | if (resizeable < 0 || (resizeable > 0 |
| 1172 | && pkg.applicationInfo.targetSdkVersion |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1173 | >= android.os.Build.VERSION_CODES.DONUT)) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 1174 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; |
| 1175 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 1176 | if (anyDensity < 0 || (anyDensity > 0 |
| 1177 | && pkg.applicationInfo.targetSdkVersion |
| 1178 | >= android.os.Build.VERSION_CODES.DONUT)) { |
| 1179 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; |
Mitsuru Oshima | 8d11267 | 2009-04-27 12:01:23 -0700 | [diff] [blame] | 1180 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 1181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | return pkg; |
| 1183 | } |
| 1184 | |
| 1185 | private static String buildClassName(String pkg, CharSequence clsSeq, |
| 1186 | String[] outError) { |
| 1187 | if (clsSeq == null || clsSeq.length() <= 0) { |
| 1188 | outError[0] = "Empty class name in package " + pkg; |
| 1189 | return null; |
| 1190 | } |
| 1191 | String cls = clsSeq.toString(); |
| 1192 | char c = cls.charAt(0); |
| 1193 | if (c == '.') { |
| 1194 | return (pkg + cls).intern(); |
| 1195 | } |
| 1196 | if (cls.indexOf('.') < 0) { |
| 1197 | StringBuilder b = new StringBuilder(pkg); |
| 1198 | b.append('.'); |
| 1199 | b.append(cls); |
| 1200 | return b.toString().intern(); |
| 1201 | } |
| 1202 | if (c >= 'a' && c <= 'z') { |
| 1203 | return cls.intern(); |
| 1204 | } |
| 1205 | outError[0] = "Bad class name " + cls + " in package " + pkg; |
| 1206 | return null; |
| 1207 | } |
| 1208 | |
| 1209 | private static String buildCompoundName(String pkg, |
| 1210 | CharSequence procSeq, String type, String[] outError) { |
| 1211 | String proc = procSeq.toString(); |
| 1212 | char c = proc.charAt(0); |
| 1213 | if (pkg != null && c == ':') { |
| 1214 | if (proc.length() < 2) { |
| 1215 | outError[0] = "Bad " + type + " name " + proc + " in package " + pkg |
| 1216 | + ": must be at least two characters"; |
| 1217 | return null; |
| 1218 | } |
| 1219 | String subName = proc.substring(1); |
| 1220 | String nameError = validateName(subName, false); |
| 1221 | if (nameError != null) { |
| 1222 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 1223 | + pkg + ": " + nameError; |
| 1224 | return null; |
| 1225 | } |
| 1226 | return (pkg + proc).intern(); |
| 1227 | } |
| 1228 | String nameError = validateName(proc, true); |
| 1229 | if (nameError != null && !"system".equals(proc)) { |
| 1230 | outError[0] = "Invalid " + type + " name " + proc + " in package " |
| 1231 | + pkg + ": " + nameError; |
| 1232 | return null; |
| 1233 | } |
| 1234 | return proc.intern(); |
| 1235 | } |
| 1236 | |
| 1237 | private static String buildProcessName(String pkg, String defProc, |
| 1238 | CharSequence procSeq, int flags, String[] separateProcesses, |
| 1239 | String[] outError) { |
| 1240 | if ((flags&PARSE_IGNORE_PROCESSES) != 0 && !"system".equals(procSeq)) { |
| 1241 | return defProc != null ? defProc : pkg; |
| 1242 | } |
| 1243 | if (separateProcesses != null) { |
| 1244 | for (int i=separateProcesses.length-1; i>=0; i--) { |
| 1245 | String sp = separateProcesses[i]; |
| 1246 | if (sp.equals(pkg) || sp.equals(defProc) || sp.equals(procSeq)) { |
| 1247 | return pkg; |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | if (procSeq == null || procSeq.length() <= 0) { |
| 1252 | return defProc; |
| 1253 | } |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1254 | return buildCompoundName(pkg, procSeq, "process", outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | private static String buildTaskAffinityName(String pkg, String defProc, |
| 1258 | CharSequence procSeq, String[] outError) { |
| 1259 | if (procSeq == null) { |
| 1260 | return defProc; |
| 1261 | } |
| 1262 | if (procSeq.length() <= 0) { |
| 1263 | return null; |
| 1264 | } |
| 1265 | return buildCompoundName(pkg, procSeq, "taskAffinity", outError); |
| 1266 | } |
| 1267 | |
| 1268 | private PermissionGroup parsePermissionGroup(Package owner, Resources res, |
| 1269 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1270 | throws XmlPullParserException, IOException { |
| 1271 | PermissionGroup perm = new PermissionGroup(owner); |
| 1272 | |
| 1273 | TypedArray sa = res.obtainAttributes(attrs, |
| 1274 | com.android.internal.R.styleable.AndroidManifestPermissionGroup); |
| 1275 | |
| 1276 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1277 | "<permission-group>", sa, |
| 1278 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, |
| 1279 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1280 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, |
| 1281 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | sa.recycle(); |
| 1283 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1284 | return null; |
| 1285 | } |
| 1286 | |
| 1287 | perm.info.descriptionRes = sa.getResourceId( |
| 1288 | com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, |
| 1289 | 0); |
| 1290 | |
| 1291 | sa.recycle(); |
| 1292 | |
| 1293 | if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm, |
| 1294 | outError)) { |
| 1295 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1296 | return null; |
| 1297 | } |
| 1298 | |
| 1299 | owner.permissionGroups.add(perm); |
| 1300 | |
| 1301 | return perm; |
| 1302 | } |
| 1303 | |
| 1304 | private Permission parsePermission(Package owner, Resources res, |
| 1305 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1306 | throws XmlPullParserException, IOException { |
| 1307 | Permission perm = new Permission(owner); |
| 1308 | |
| 1309 | TypedArray sa = res.obtainAttributes(attrs, |
| 1310 | com.android.internal.R.styleable.AndroidManifestPermission); |
| 1311 | |
| 1312 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1313 | "<permission>", sa, |
| 1314 | com.android.internal.R.styleable.AndroidManifestPermission_name, |
| 1315 | com.android.internal.R.styleable.AndroidManifestPermission_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1316 | com.android.internal.R.styleable.AndroidManifestPermission_icon, |
| 1317 | com.android.internal.R.styleable.AndroidManifestPermission_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | sa.recycle(); |
| 1319 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1320 | return null; |
| 1321 | } |
| 1322 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1323 | // Note: don't allow this value to be a reference to a resource |
| 1324 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | perm.info.group = sa.getNonResourceString( |
| 1326 | com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); |
| 1327 | if (perm.info.group != null) { |
| 1328 | perm.info.group = perm.info.group.intern(); |
| 1329 | } |
| 1330 | |
| 1331 | perm.info.descriptionRes = sa.getResourceId( |
| 1332 | com.android.internal.R.styleable.AndroidManifestPermission_description, |
| 1333 | 0); |
| 1334 | |
| 1335 | perm.info.protectionLevel = sa.getInt( |
| 1336 | com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, |
| 1337 | PermissionInfo.PROTECTION_NORMAL); |
| 1338 | |
| 1339 | sa.recycle(); |
| 1340 | |
| 1341 | if (perm.info.protectionLevel == -1) { |
| 1342 | outError[0] = "<permission> does not specify protectionLevel"; |
| 1343 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1344 | return null; |
| 1345 | } |
| 1346 | |
| 1347 | if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, |
| 1348 | outError)) { |
| 1349 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1350 | return null; |
| 1351 | } |
| 1352 | |
| 1353 | owner.permissions.add(perm); |
| 1354 | |
| 1355 | return perm; |
| 1356 | } |
| 1357 | |
| 1358 | private Permission parsePermissionTree(Package owner, Resources res, |
| 1359 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1360 | throws XmlPullParserException, IOException { |
| 1361 | Permission perm = new Permission(owner); |
| 1362 | |
| 1363 | TypedArray sa = res.obtainAttributes(attrs, |
| 1364 | com.android.internal.R.styleable.AndroidManifestPermissionTree); |
| 1365 | |
| 1366 | if (!parsePackageItemInfo(owner, perm.info, outError, |
| 1367 | "<permission-tree>", sa, |
| 1368 | com.android.internal.R.styleable.AndroidManifestPermissionTree_name, |
| 1369 | com.android.internal.R.styleable.AndroidManifestPermissionTree_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1370 | com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, |
| 1371 | com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | sa.recycle(); |
| 1373 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1374 | return null; |
| 1375 | } |
| 1376 | |
| 1377 | sa.recycle(); |
| 1378 | |
| 1379 | int index = perm.info.name.indexOf('.'); |
| 1380 | if (index > 0) { |
| 1381 | index = perm.info.name.indexOf('.', index+1); |
| 1382 | } |
| 1383 | if (index < 0) { |
| 1384 | outError[0] = "<permission-tree> name has less than three segments: " |
| 1385 | + perm.info.name; |
| 1386 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1387 | return null; |
| 1388 | } |
| 1389 | |
| 1390 | perm.info.descriptionRes = 0; |
| 1391 | perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; |
| 1392 | perm.tree = true; |
| 1393 | |
| 1394 | if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm, |
| 1395 | outError)) { |
| 1396 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1397 | return null; |
| 1398 | } |
| 1399 | |
| 1400 | owner.permissions.add(perm); |
| 1401 | |
| 1402 | return perm; |
| 1403 | } |
| 1404 | |
| 1405 | private Instrumentation parseInstrumentation(Package owner, Resources res, |
| 1406 | XmlPullParser parser, AttributeSet attrs, String[] outError) |
| 1407 | throws XmlPullParserException, IOException { |
| 1408 | TypedArray sa = res.obtainAttributes(attrs, |
| 1409 | com.android.internal.R.styleable.AndroidManifestInstrumentation); |
| 1410 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1411 | if (mParseInstrumentationArgs == null) { |
| 1412 | mParseInstrumentationArgs = new ParsePackageItemArgs(owner, outError, |
| 1413 | com.android.internal.R.styleable.AndroidManifestInstrumentation_name, |
| 1414 | com.android.internal.R.styleable.AndroidManifestInstrumentation_label, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1415 | com.android.internal.R.styleable.AndroidManifestInstrumentation_icon, |
| 1416 | com.android.internal.R.styleable.AndroidManifestInstrumentation_logo); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1417 | mParseInstrumentationArgs.tag = "<instrumentation>"; |
| 1418 | } |
| 1419 | |
| 1420 | mParseInstrumentationArgs.sa = sa; |
| 1421 | |
| 1422 | Instrumentation a = new Instrumentation(mParseInstrumentationArgs, |
| 1423 | new InstrumentationInfo()); |
| 1424 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | sa.recycle(); |
| 1426 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1427 | return null; |
| 1428 | } |
| 1429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1431 | // Note: don't allow this value to be a reference to a resource |
| 1432 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | str = sa.getNonResourceString( |
| 1434 | com.android.internal.R.styleable.AndroidManifestInstrumentation_targetPackage); |
| 1435 | a.info.targetPackage = str != null ? str.intern() : null; |
| 1436 | |
| 1437 | a.info.handleProfiling = sa.getBoolean( |
| 1438 | com.android.internal.R.styleable.AndroidManifestInstrumentation_handleProfiling, |
| 1439 | false); |
| 1440 | |
| 1441 | a.info.functionalTest = sa.getBoolean( |
| 1442 | com.android.internal.R.styleable.AndroidManifestInstrumentation_functionalTest, |
| 1443 | false); |
| 1444 | |
| 1445 | sa.recycle(); |
| 1446 | |
| 1447 | if (a.info.targetPackage == null) { |
| 1448 | outError[0] = "<instrumentation> does not specify targetPackage"; |
| 1449 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1450 | return null; |
| 1451 | } |
| 1452 | |
| 1453 | if (!parseAllMetaData(res, parser, attrs, "<instrumentation>", a, |
| 1454 | outError)) { |
| 1455 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1456 | return null; |
| 1457 | } |
| 1458 | |
| 1459 | owner.instrumentation.add(a); |
| 1460 | |
| 1461 | return a; |
| 1462 | } |
| 1463 | |
| 1464 | private boolean parseApplication(Package owner, Resources res, |
| 1465 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 1466 | throws XmlPullParserException, IOException { |
| 1467 | final ApplicationInfo ai = owner.applicationInfo; |
| 1468 | final String pkgName = owner.applicationInfo.packageName; |
| 1469 | |
| 1470 | TypedArray sa = res.obtainAttributes(attrs, |
| 1471 | com.android.internal.R.styleable.AndroidManifestApplication); |
| 1472 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1473 | String name = sa.getNonConfigurationString( |
| 1474 | com.android.internal.R.styleable.AndroidManifestApplication_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | if (name != null) { |
| 1476 | ai.className = buildClassName(pkgName, name, outError); |
| 1477 | if (ai.className == null) { |
| 1478 | sa.recycle(); |
| 1479 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1480 | return false; |
| 1481 | } |
| 1482 | } |
| 1483 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1484 | String manageSpaceActivity = sa.getNonConfigurationString( |
| 1485 | com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | if (manageSpaceActivity != null) { |
| 1487 | ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, |
| 1488 | outError); |
| 1489 | } |
| 1490 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1491 | boolean allowBackup = sa.getBoolean( |
| 1492 | com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); |
| 1493 | if (allowBackup) { |
| 1494 | ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1495 | |
Christopher Tate | 3de55bc | 2010-03-12 17:28:08 -0800 | [diff] [blame] | 1496 | // backupAgent, killAfterRestore, and restoreAnyVersion are only relevant |
| 1497 | // if backup is possible for the given application. |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1498 | String backupAgent = sa.getNonConfigurationString( |
| 1499 | com.android.internal.R.styleable.AndroidManifestApplication_backupAgent, 0); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1500 | if (backupAgent != null) { |
| 1501 | ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1502 | if (false) { |
| 1503 | Log.v(TAG, "android:backupAgent = " + ai.backupAgentName |
| 1504 | + " from " + pkgName + "+" + backupAgent); |
| 1505 | } |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1506 | |
| 1507 | if (sa.getBoolean( |
| 1508 | com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, |
| 1509 | true)) { |
| 1510 | ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; |
| 1511 | } |
| 1512 | if (sa.getBoolean( |
Christopher Tate | 3dda518 | 2010-02-24 16:06:18 -0800 | [diff] [blame] | 1513 | com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion, |
| 1514 | false)) { |
| 1515 | ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION; |
| 1516 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1519 | |
Christopher Tate | b0628bf | 2011-06-02 15:08:13 -0700 | [diff] [blame] | 1520 | // fullBackupAgent is explicitly handled even if allowBackup is false |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1521 | name = sa.getNonConfigurationString( |
| 1522 | com.android.internal.R.styleable.AndroidManifestApplication_fullBackupAgent, 0); |
| 1523 | if (name != null) { |
| 1524 | ai.fullBackupAgentName = buildClassName(pkgName, name, outError); |
Christopher Tate | b0628bf | 2011-06-02 15:08:13 -0700 | [diff] [blame] | 1525 | if (false) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 1526 | Log.v(TAG, "android:fullBackupAgent=" + ai.fullBackupAgentName |
| 1527 | + " from " + pkgName + "+" + name); |
| 1528 | } |
| 1529 | } |
| 1530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | TypedValue v = sa.peekValue( |
| 1532 | com.android.internal.R.styleable.AndroidManifestApplication_label); |
| 1533 | if (v != null && (ai.labelRes=v.resourceId) == 0) { |
| 1534 | ai.nonLocalizedLabel = v.coerceToString(); |
| 1535 | } |
| 1536 | |
| 1537 | ai.icon = sa.getResourceId( |
| 1538 | com.android.internal.R.styleable.AndroidManifestApplication_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1539 | ai.logo = sa.getResourceId( |
| 1540 | com.android.internal.R.styleable.AndroidManifestApplication_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | ai.theme = sa.getResourceId( |
Dianne Hackborn | b35cd54 | 2011-01-04 21:30:53 -0800 | [diff] [blame] | 1542 | com.android.internal.R.styleable.AndroidManifestApplication_theme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | ai.descriptionRes = sa.getResourceId( |
| 1544 | com.android.internal.R.styleable.AndroidManifestApplication_description, 0); |
| 1545 | |
| 1546 | if ((flags&PARSE_IS_SYSTEM) != 0) { |
| 1547 | if (sa.getBoolean( |
| 1548 | com.android.internal.R.styleable.AndroidManifestApplication_persistent, |
| 1549 | false)) { |
| 1550 | ai.flags |= ApplicationInfo.FLAG_PERSISTENT; |
| 1551 | } |
| 1552 | } |
| 1553 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 1554 | if ((flags & PARSE_FORWARD_LOCK) != 0) { |
| 1555 | ai.flags |= ApplicationInfo.FLAG_FORWARD_LOCK; |
| 1556 | } |
| 1557 | |
| 1558 | if ((flags & PARSE_ON_SDCARD) != 0) { |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 1559 | ai.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | if (sa.getBoolean( |
| 1563 | com.android.internal.R.styleable.AndroidManifestApplication_debuggable, |
| 1564 | false)) { |
| 1565 | ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE; |
| 1566 | } |
| 1567 | |
| 1568 | if (sa.getBoolean( |
Ben Cheng | ef3f5dd | 2010-03-29 15:47:26 -0700 | [diff] [blame] | 1569 | com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, |
Ben Cheng | 23085b7 | 2010-02-08 16:06:32 -0800 | [diff] [blame] | 1570 | false)) { |
| 1571 | ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE; |
| 1572 | } |
| 1573 | |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1574 | boolean hardwareAccelerated = sa.getBoolean( |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1575 | com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated, |
Dianne Hackborn | 2d6833b | 2011-06-24 16:04:19 -0700 | [diff] [blame^] | 1576 | owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1577 | |
| 1578 | if (sa.getBoolean( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | com.android.internal.R.styleable.AndroidManifestApplication_hasCode, |
| 1580 | true)) { |
| 1581 | ai.flags |= ApplicationInfo.FLAG_HAS_CODE; |
| 1582 | } |
| 1583 | |
| 1584 | if (sa.getBoolean( |
| 1585 | com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting, |
| 1586 | false)) { |
| 1587 | ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 1588 | } |
| 1589 | |
| 1590 | if (sa.getBoolean( |
| 1591 | com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, |
| 1592 | true)) { |
| 1593 | ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; |
| 1594 | } |
| 1595 | |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 1596 | if (sa.getBoolean( |
| 1597 | com.android.internal.R.styleable.AndroidManifestApplication_testOnly, |
Dianne Hackborn | e7fe35b | 2009-05-13 10:53:41 -0700 | [diff] [blame] | 1598 | false)) { |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 1599 | ai.flags |= ApplicationInfo.FLAG_TEST_ONLY; |
| 1600 | } |
| 1601 | |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1602 | if (sa.getBoolean( |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1603 | com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1604 | false)) { |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1605 | ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; |
Jason parks | a3cdaa5 | 2011-01-13 14:15:43 -0600 | [diff] [blame] | 1606 | } |
| 1607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1609 | str = sa.getNonConfigurationString( |
| 1610 | com.android.internal.R.styleable.AndroidManifestApplication_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | ai.permission = (str != null && str.length() > 0) ? str.intern() : null; |
| 1612 | |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1613 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 1614 | str = sa.getNonConfigurationString( |
| 1615 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity, 0); |
| 1616 | } else { |
| 1617 | // Some older apps have been seen to use a resource reference |
| 1618 | // here that on older builds was ignored (with a warning). We |
| 1619 | // need to continue to do this for them so they don't break. |
| 1620 | str = sa.getNonResourceString( |
| 1621 | com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity); |
| 1622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, |
| 1624 | str, outError); |
| 1625 | |
| 1626 | if (outError[0] == null) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 1627 | CharSequence pname; |
| 1628 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 1629 | pname = sa.getNonConfigurationString( |
| 1630 | com.android.internal.R.styleable.AndroidManifestApplication_process, 0); |
| 1631 | } else { |
| 1632 | // Some older apps have been seen to use a resource reference |
| 1633 | // here that on older builds was ignored (with a warning). We |
| 1634 | // need to continue to do this for them so they don't break. |
| 1635 | pname = sa.getNonResourceString( |
| 1636 | com.android.internal.R.styleable.AndroidManifestApplication_process); |
| 1637 | } |
| 1638 | ai.processName = buildProcessName(ai.packageName, null, pname, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | flags, mSeparateProcesses, outError); |
| 1640 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1641 | ai.enabled = sa.getBoolean( |
| 1642 | com.android.internal.R.styleable.AndroidManifestApplication_enabled, true); |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1643 | |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 1644 | if (false) { |
| 1645 | if (sa.getBoolean( |
| 1646 | com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState, |
| 1647 | false)) { |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1648 | ai.flags |= ApplicationInfo.FLAG_CANT_SAVE_STATE; |
Dianne Hackborn | 02486b1 | 2010-08-26 14:18:37 -0700 | [diff] [blame] | 1649 | |
| 1650 | // A heavy-weight application can not be in a custom process. |
| 1651 | // We can do direct compare because we intern all strings. |
| 1652 | if (ai.processName != null && ai.processName != ai.packageName) { |
| 1653 | outError[0] = "cantSaveState applications can not use custom processes"; |
| 1654 | } |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1655 | } |
| 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | sa.recycle(); |
| 1660 | |
| 1661 | if (outError[0] != null) { |
| 1662 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1663 | return false; |
| 1664 | } |
| 1665 | |
| 1666 | final int innerDepth = parser.getDepth(); |
| 1667 | |
| 1668 | int type; |
| 1669 | while ((type=parser.next()) != parser.END_DOCUMENT |
| 1670 | && (type != parser.END_TAG || parser.getDepth() > innerDepth)) { |
| 1671 | if (type == parser.END_TAG || type == parser.TEXT) { |
| 1672 | continue; |
| 1673 | } |
| 1674 | |
| 1675 | String tagName = parser.getName(); |
| 1676 | if (tagName.equals("activity")) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1677 | Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false, |
| 1678 | hardwareAccelerated); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | if (a == null) { |
| 1680 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | owner.activities.add(a); |
| 1685 | |
| 1686 | } else if (tagName.equals("receiver")) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1687 | Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | if (a == null) { |
| 1689 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1690 | return false; |
| 1691 | } |
| 1692 | |
| 1693 | owner.receivers.add(a); |
| 1694 | |
| 1695 | } else if (tagName.equals("service")) { |
| 1696 | Service s = parseService(owner, res, parser, attrs, flags, outError); |
| 1697 | if (s == null) { |
| 1698 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1699 | return false; |
| 1700 | } |
| 1701 | |
| 1702 | owner.services.add(s); |
| 1703 | |
| 1704 | } else if (tagName.equals("provider")) { |
| 1705 | Provider p = parseProvider(owner, res, parser, attrs, flags, outError); |
| 1706 | if (p == null) { |
| 1707 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1708 | return false; |
| 1709 | } |
| 1710 | |
| 1711 | owner.providers.add(p); |
| 1712 | |
| 1713 | } else if (tagName.equals("activity-alias")) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1714 | Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | if (a == null) { |
| 1716 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1717 | return false; |
| 1718 | } |
| 1719 | |
| 1720 | owner.activities.add(a); |
| 1721 | |
| 1722 | } else if (parser.getName().equals("meta-data")) { |
| 1723 | // note: application meta-data is stored off to the side, so it can |
| 1724 | // remain null in the primary copy (we like to avoid extra copies because |
| 1725 | // it can be large) |
| 1726 | if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData, |
| 1727 | outError)) == null) { |
| 1728 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
| 1732 | } else if (tagName.equals("uses-library")) { |
| 1733 | sa = res.obtainAttributes(attrs, |
| 1734 | com.android.internal.R.styleable.AndroidManifestUsesLibrary); |
| 1735 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1736 | // Note: don't allow this value to be a reference to a resource |
| 1737 | // that may change. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1738 | String lname = sa.getNonResourceString( |
| 1739 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_name); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1740 | boolean req = sa.getBoolean( |
| 1741 | com.android.internal.R.styleable.AndroidManifestUsesLibrary_required, |
| 1742 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | |
| 1744 | sa.recycle(); |
| 1745 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1746 | if (lname != null) { |
| 1747 | if (req) { |
| 1748 | if (owner.usesLibraries == null) { |
| 1749 | owner.usesLibraries = new ArrayList<String>(); |
| 1750 | } |
| 1751 | if (!owner.usesLibraries.contains(lname)) { |
| 1752 | owner.usesLibraries.add(lname.intern()); |
| 1753 | } |
| 1754 | } else { |
| 1755 | if (owner.usesOptionalLibraries == null) { |
| 1756 | owner.usesOptionalLibraries = new ArrayList<String>(); |
| 1757 | } |
| 1758 | if (!owner.usesOptionalLibraries.contains(lname)) { |
| 1759 | owner.usesOptionalLibraries.add(lname.intern()); |
| 1760 | } |
| 1761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | XmlUtils.skipCurrentTag(parser); |
| 1765 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1766 | } else if (tagName.equals("uses-package")) { |
| 1767 | // Dependencies for app installers; we don't currently try to |
| 1768 | // enforce this. |
| 1769 | XmlUtils.skipCurrentTag(parser); |
| 1770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | } else { |
| 1772 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1773 | Log.w(TAG, "Unknown element under <application>: " + tagName |
| 1774 | + " at " + mArchiveSourcePath + " " |
| 1775 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | XmlUtils.skipCurrentTag(parser); |
| 1777 | continue; |
| 1778 | } else { |
| 1779 | outError[0] = "Bad element under <application>: " + tagName; |
| 1780 | mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; |
| 1781 | return false; |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | return true; |
| 1787 | } |
| 1788 | |
| 1789 | private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, |
| 1790 | String[] outError, String tag, TypedArray sa, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1791 | int nameRes, int labelRes, int iconRes, int logoRes) { |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1792 | String name = sa.getNonConfigurationString(nameRes, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | if (name == null) { |
| 1794 | outError[0] = tag + " does not specify android:name"; |
| 1795 | return false; |
| 1796 | } |
| 1797 | |
| 1798 | outInfo.name |
| 1799 | = buildClassName(owner.applicationInfo.packageName, name, outError); |
| 1800 | if (outInfo.name == null) { |
| 1801 | return false; |
| 1802 | } |
| 1803 | |
| 1804 | int iconVal = sa.getResourceId(iconRes, 0); |
| 1805 | if (iconVal != 0) { |
| 1806 | outInfo.icon = iconVal; |
| 1807 | outInfo.nonLocalizedLabel = null; |
| 1808 | } |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1809 | |
| 1810 | int logoVal = sa.getResourceId(logoRes, 0); |
| 1811 | if (logoVal != 0) { |
| 1812 | outInfo.logo = logoVal; |
| 1813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | |
| 1815 | TypedValue v = sa.peekValue(labelRes); |
| 1816 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 1817 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 1818 | } |
| 1819 | |
| 1820 | outInfo.packageName = owner.packageName; |
| 1821 | |
| 1822 | return true; |
| 1823 | } |
| 1824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | private Activity parseActivity(Package owner, Resources res, |
| 1826 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError, |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1827 | boolean receiver, boolean hardwareAccelerated) |
| 1828 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | TypedArray sa = res.obtainAttributes(attrs, |
| 1830 | com.android.internal.R.styleable.AndroidManifestActivity); |
| 1831 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1832 | if (mParseActivityArgs == null) { |
| 1833 | mParseActivityArgs = new ParseComponentArgs(owner, outError, |
| 1834 | com.android.internal.R.styleable.AndroidManifestActivity_name, |
| 1835 | com.android.internal.R.styleable.AndroidManifestActivity_label, |
| 1836 | com.android.internal.R.styleable.AndroidManifestActivity_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1837 | com.android.internal.R.styleable.AndroidManifestActivity_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1838 | mSeparateProcesses, |
| 1839 | com.android.internal.R.styleable.AndroidManifestActivity_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1840 | com.android.internal.R.styleable.AndroidManifestActivity_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1841 | com.android.internal.R.styleable.AndroidManifestActivity_enabled); |
| 1842 | } |
| 1843 | |
| 1844 | mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>"; |
| 1845 | mParseActivityArgs.sa = sa; |
| 1846 | mParseActivityArgs.flags = flags; |
| 1847 | |
| 1848 | Activity a = new Activity(mParseActivityArgs, new ActivityInfo()); |
| 1849 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1850 | sa.recycle(); |
| 1851 | return null; |
| 1852 | } |
| 1853 | |
| 1854 | final boolean setExported = sa.hasValue( |
| 1855 | com.android.internal.R.styleable.AndroidManifestActivity_exported); |
| 1856 | if (setExported) { |
| 1857 | a.info.exported = sa.getBoolean( |
| 1858 | com.android.internal.R.styleable.AndroidManifestActivity_exported, false); |
| 1859 | } |
| 1860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | a.info.theme = sa.getResourceId( |
| 1862 | com.android.internal.R.styleable.AndroidManifestActivity_theme, 0); |
| 1863 | |
| 1864 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1865 | str = sa.getNonConfigurationString( |
| 1866 | com.android.internal.R.styleable.AndroidManifestActivity_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1867 | if (str == null) { |
| 1868 | a.info.permission = owner.applicationInfo.permission; |
| 1869 | } else { |
| 1870 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 1871 | } |
| 1872 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 1873 | str = sa.getNonConfigurationString( |
| 1874 | com.android.internal.R.styleable.AndroidManifestActivity_taskAffinity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName, |
| 1876 | owner.applicationInfo.taskAffinity, str, outError); |
| 1877 | |
| 1878 | a.info.flags = 0; |
| 1879 | if (sa.getBoolean( |
| 1880 | com.android.internal.R.styleable.AndroidManifestActivity_multiprocess, |
| 1881 | false)) { |
| 1882 | a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS; |
| 1883 | } |
| 1884 | |
| 1885 | if (sa.getBoolean( |
| 1886 | com.android.internal.R.styleable.AndroidManifestActivity_finishOnTaskLaunch, |
| 1887 | false)) { |
| 1888 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH; |
| 1889 | } |
| 1890 | |
| 1891 | if (sa.getBoolean( |
| 1892 | com.android.internal.R.styleable.AndroidManifestActivity_clearTaskOnLaunch, |
| 1893 | false)) { |
| 1894 | a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH; |
| 1895 | } |
| 1896 | |
| 1897 | if (sa.getBoolean( |
| 1898 | com.android.internal.R.styleable.AndroidManifestActivity_noHistory, |
| 1899 | false)) { |
| 1900 | a.info.flags |= ActivityInfo.FLAG_NO_HISTORY; |
| 1901 | } |
| 1902 | |
| 1903 | if (sa.getBoolean( |
| 1904 | com.android.internal.R.styleable.AndroidManifestActivity_alwaysRetainTaskState, |
| 1905 | false)) { |
| 1906 | a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE; |
| 1907 | } |
| 1908 | |
| 1909 | if (sa.getBoolean( |
| 1910 | com.android.internal.R.styleable.AndroidManifestActivity_stateNotNeeded, |
| 1911 | false)) { |
| 1912 | a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED; |
| 1913 | } |
| 1914 | |
| 1915 | if (sa.getBoolean( |
| 1916 | com.android.internal.R.styleable.AndroidManifestActivity_excludeFromRecents, |
| 1917 | false)) { |
| 1918 | a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 1919 | } |
| 1920 | |
| 1921 | if (sa.getBoolean( |
| 1922 | com.android.internal.R.styleable.AndroidManifestActivity_allowTaskReparenting, |
| 1923 | (owner.applicationInfo.flags&ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) { |
| 1924 | a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING; |
| 1925 | } |
| 1926 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 1927 | if (sa.getBoolean( |
| 1928 | com.android.internal.R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, |
| 1929 | false)) { |
| 1930 | a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS; |
| 1931 | } |
| 1932 | |
Daniel Sandler | 613dde4 | 2010-06-21 13:46:39 -0400 | [diff] [blame] | 1933 | if (sa.getBoolean( |
| 1934 | com.android.internal.R.styleable.AndroidManifestActivity_immersive, |
| 1935 | false)) { |
| 1936 | a.info.flags |= ActivityInfo.FLAG_IMMERSIVE; |
| 1937 | } |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | if (!receiver) { |
Romain Guy | 529b60a | 2010-08-03 18:05:47 -0700 | [diff] [blame] | 1940 | if (sa.getBoolean( |
| 1941 | com.android.internal.R.styleable.AndroidManifestActivity_hardwareAccelerated, |
| 1942 | hardwareAccelerated)) { |
| 1943 | a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED; |
| 1944 | } |
| 1945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | a.info.launchMode = sa.getInt( |
| 1947 | com.android.internal.R.styleable.AndroidManifestActivity_launchMode, |
| 1948 | ActivityInfo.LAUNCH_MULTIPLE); |
| 1949 | a.info.screenOrientation = sa.getInt( |
| 1950 | com.android.internal.R.styleable.AndroidManifestActivity_screenOrientation, |
| 1951 | ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 1952 | a.info.configChanges = sa.getInt( |
| 1953 | com.android.internal.R.styleable.AndroidManifestActivity_configChanges, |
| 1954 | 0); |
| 1955 | a.info.softInputMode = sa.getInt( |
| 1956 | com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode, |
| 1957 | 0); |
| 1958 | } else { |
| 1959 | a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 1960 | a.info.configChanges = 0; |
| 1961 | } |
| 1962 | |
| 1963 | sa.recycle(); |
| 1964 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 1965 | if (receiver && (owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 1966 | // A heavy-weight application can not have receives in its main process |
| 1967 | // We can do direct compare because we intern all strings. |
| 1968 | if (a.info.processName == owner.packageName) { |
| 1969 | outError[0] = "Heavy-weight applications can not have receivers in main process"; |
| 1970 | } |
| 1971 | } |
| 1972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | if (outError[0] != null) { |
| 1974 | return null; |
| 1975 | } |
| 1976 | |
| 1977 | int outerDepth = parser.getDepth(); |
| 1978 | int type; |
| 1979 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1980 | && (type != XmlPullParser.END_TAG |
| 1981 | || parser.getDepth() > outerDepth)) { |
| 1982 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1983 | continue; |
| 1984 | } |
| 1985 | |
| 1986 | if (parser.getName().equals("intent-filter")) { |
| 1987 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
| 1988 | if (!parseIntent(res, parser, attrs, flags, intent, outError, !receiver)) { |
| 1989 | return null; |
| 1990 | } |
| 1991 | if (intent.countActions() == 0) { |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1992 | Log.w(TAG, "No actions in intent filter at " |
| 1993 | + mArchiveSourcePath + " " |
| 1994 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | } else { |
| 1996 | a.intents.add(intent); |
| 1997 | } |
| 1998 | } else if (parser.getName().equals("meta-data")) { |
| 1999 | if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, |
| 2000 | outError)) == null) { |
| 2001 | return null; |
| 2002 | } |
| 2003 | } else { |
| 2004 | if (!RIGID_PARSER) { |
| 2005 | Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); |
| 2006 | if (receiver) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2007 | Log.w(TAG, "Unknown element under <receiver>: " + parser.getName() |
| 2008 | + " at " + mArchiveSourcePath + " " |
| 2009 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | } else { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2011 | Log.w(TAG, "Unknown element under <activity>: " + parser.getName() |
| 2012 | + " at " + mArchiveSourcePath + " " |
| 2013 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | } |
| 2015 | XmlUtils.skipCurrentTag(parser); |
| 2016 | continue; |
| 2017 | } |
| 2018 | if (receiver) { |
| 2019 | outError[0] = "Bad element under <receiver>: " + parser.getName(); |
| 2020 | } else { |
| 2021 | outError[0] = "Bad element under <activity>: " + parser.getName(); |
| 2022 | } |
| 2023 | return null; |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | if (!setExported) { |
| 2028 | a.info.exported = a.intents.size() > 0; |
| 2029 | } |
| 2030 | |
| 2031 | return a; |
| 2032 | } |
| 2033 | |
| 2034 | private Activity parseActivityAlias(Package owner, Resources res, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2035 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2036 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | TypedArray sa = res.obtainAttributes(attrs, |
| 2038 | com.android.internal.R.styleable.AndroidManifestActivityAlias); |
| 2039 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2040 | String targetActivity = sa.getNonConfigurationString( |
| 2041 | com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | if (targetActivity == null) { |
| 2043 | outError[0] = "<activity-alias> does not specify android:targetActivity"; |
| 2044 | sa.recycle(); |
| 2045 | return null; |
| 2046 | } |
| 2047 | |
| 2048 | targetActivity = buildClassName(owner.applicationInfo.packageName, |
| 2049 | targetActivity, outError); |
| 2050 | if (targetActivity == null) { |
| 2051 | sa.recycle(); |
| 2052 | return null; |
| 2053 | } |
| 2054 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2055 | if (mParseActivityAliasArgs == null) { |
| 2056 | mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, |
| 2057 | com.android.internal.R.styleable.AndroidManifestActivityAlias_name, |
| 2058 | com.android.internal.R.styleable.AndroidManifestActivityAlias_label, |
| 2059 | com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2060 | com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2061 | mSeparateProcesses, |
| 2062 | 0, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2063 | com.android.internal.R.styleable.AndroidManifestActivityAlias_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2064 | com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); |
| 2065 | mParseActivityAliasArgs.tag = "<activity-alias>"; |
| 2066 | } |
| 2067 | |
| 2068 | mParseActivityAliasArgs.sa = sa; |
| 2069 | mParseActivityAliasArgs.flags = flags; |
| 2070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | Activity target = null; |
| 2072 | |
| 2073 | final int NA = owner.activities.size(); |
| 2074 | for (int i=0; i<NA; i++) { |
| 2075 | Activity t = owner.activities.get(i); |
| 2076 | if (targetActivity.equals(t.info.name)) { |
| 2077 | target = t; |
| 2078 | break; |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | if (target == null) { |
| 2083 | outError[0] = "<activity-alias> target activity " + targetActivity |
| 2084 | + " not found in manifest"; |
| 2085 | sa.recycle(); |
| 2086 | return null; |
| 2087 | } |
| 2088 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2089 | ActivityInfo info = new ActivityInfo(); |
| 2090 | info.targetActivity = targetActivity; |
| 2091 | info.configChanges = target.info.configChanges; |
| 2092 | info.flags = target.info.flags; |
| 2093 | info.icon = target.info.icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2094 | info.logo = target.info.logo; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2095 | info.labelRes = target.info.labelRes; |
| 2096 | info.nonLocalizedLabel = target.info.nonLocalizedLabel; |
| 2097 | info.launchMode = target.info.launchMode; |
| 2098 | info.processName = target.info.processName; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2099 | if (info.descriptionRes == 0) { |
| 2100 | info.descriptionRes = target.info.descriptionRes; |
| 2101 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2102 | info.screenOrientation = target.info.screenOrientation; |
| 2103 | info.taskAffinity = target.info.taskAffinity; |
| 2104 | info.theme = target.info.theme; |
| 2105 | |
| 2106 | Activity a = new Activity(mParseActivityAliasArgs, info); |
| 2107 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | sa.recycle(); |
| 2109 | return null; |
| 2110 | } |
| 2111 | |
| 2112 | final boolean setExported = sa.hasValue( |
| 2113 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); |
| 2114 | if (setExported) { |
| 2115 | a.info.exported = sa.getBoolean( |
| 2116 | com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); |
| 2117 | } |
| 2118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | String str; |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2120 | str = sa.getNonConfigurationString( |
| 2121 | com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | if (str != null) { |
| 2123 | a.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 2124 | } |
| 2125 | |
| 2126 | sa.recycle(); |
| 2127 | |
| 2128 | if (outError[0] != null) { |
| 2129 | return null; |
| 2130 | } |
| 2131 | |
| 2132 | int outerDepth = parser.getDepth(); |
| 2133 | int type; |
| 2134 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2135 | && (type != XmlPullParser.END_TAG |
| 2136 | || parser.getDepth() > outerDepth)) { |
| 2137 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2138 | continue; |
| 2139 | } |
| 2140 | |
| 2141 | if (parser.getName().equals("intent-filter")) { |
| 2142 | ActivityIntentInfo intent = new ActivityIntentInfo(a); |
| 2143 | if (!parseIntent(res, parser, attrs, flags, intent, outError, true)) { |
| 2144 | return null; |
| 2145 | } |
| 2146 | if (intent.countActions() == 0) { |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 2147 | Log.w(TAG, "No actions in intent filter at " |
| 2148 | + mArchiveSourcePath + " " |
| 2149 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | } else { |
| 2151 | a.intents.add(intent); |
| 2152 | } |
| 2153 | } else if (parser.getName().equals("meta-data")) { |
| 2154 | if ((a.metaData=parseMetaData(res, parser, attrs, a.metaData, |
| 2155 | outError)) == null) { |
| 2156 | return null; |
| 2157 | } |
| 2158 | } else { |
| 2159 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2160 | Log.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() |
| 2161 | + " at " + mArchiveSourcePath + " " |
| 2162 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | XmlUtils.skipCurrentTag(parser); |
| 2164 | continue; |
| 2165 | } |
| 2166 | outError[0] = "Bad element under <activity-alias>: " + parser.getName(); |
| 2167 | return null; |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | if (!setExported) { |
| 2172 | a.info.exported = a.intents.size() > 0; |
| 2173 | } |
| 2174 | |
| 2175 | return a; |
| 2176 | } |
| 2177 | |
| 2178 | private Provider parseProvider(Package owner, Resources res, |
| 2179 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2180 | throws XmlPullParserException, IOException { |
| 2181 | TypedArray sa = res.obtainAttributes(attrs, |
| 2182 | com.android.internal.R.styleable.AndroidManifestProvider); |
| 2183 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2184 | if (mParseProviderArgs == null) { |
| 2185 | mParseProviderArgs = new ParseComponentArgs(owner, outError, |
| 2186 | com.android.internal.R.styleable.AndroidManifestProvider_name, |
| 2187 | com.android.internal.R.styleable.AndroidManifestProvider_label, |
| 2188 | com.android.internal.R.styleable.AndroidManifestProvider_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2189 | com.android.internal.R.styleable.AndroidManifestProvider_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2190 | mSeparateProcesses, |
| 2191 | com.android.internal.R.styleable.AndroidManifestProvider_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2192 | com.android.internal.R.styleable.AndroidManifestProvider_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2193 | com.android.internal.R.styleable.AndroidManifestProvider_enabled); |
| 2194 | mParseProviderArgs.tag = "<provider>"; |
| 2195 | } |
| 2196 | |
| 2197 | mParseProviderArgs.sa = sa; |
| 2198 | mParseProviderArgs.flags = flags; |
| 2199 | |
| 2200 | Provider p = new Provider(mParseProviderArgs, new ProviderInfo()); |
| 2201 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | sa.recycle(); |
| 2203 | return null; |
| 2204 | } |
| 2205 | |
| 2206 | p.info.exported = sa.getBoolean( |
| 2207 | com.android.internal.R.styleable.AndroidManifestProvider_exported, true); |
| 2208 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2209 | String cpname = sa.getNonConfigurationString( |
| 2210 | com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | |
| 2212 | p.info.isSyncable = sa.getBoolean( |
| 2213 | com.android.internal.R.styleable.AndroidManifestProvider_syncable, |
| 2214 | false); |
| 2215 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2216 | String permission = sa.getNonConfigurationString( |
| 2217 | com.android.internal.R.styleable.AndroidManifestProvider_permission, 0); |
| 2218 | String str = sa.getNonConfigurationString( |
| 2219 | com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | if (str == null) { |
| 2221 | str = permission; |
| 2222 | } |
| 2223 | if (str == null) { |
| 2224 | p.info.readPermission = owner.applicationInfo.permission; |
| 2225 | } else { |
| 2226 | p.info.readPermission = |
| 2227 | str.length() > 0 ? str.toString().intern() : null; |
| 2228 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2229 | str = sa.getNonConfigurationString( |
| 2230 | com.android.internal.R.styleable.AndroidManifestProvider_writePermission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | if (str == null) { |
| 2232 | str = permission; |
| 2233 | } |
| 2234 | if (str == null) { |
| 2235 | p.info.writePermission = owner.applicationInfo.permission; |
| 2236 | } else { |
| 2237 | p.info.writePermission = |
| 2238 | str.length() > 0 ? str.toString().intern() : null; |
| 2239 | } |
| 2240 | |
| 2241 | p.info.grantUriPermissions = sa.getBoolean( |
| 2242 | com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, |
| 2243 | false); |
| 2244 | |
| 2245 | p.info.multiprocess = sa.getBoolean( |
| 2246 | com.android.internal.R.styleable.AndroidManifestProvider_multiprocess, |
| 2247 | false); |
| 2248 | |
| 2249 | p.info.initOrder = sa.getInt( |
| 2250 | com.android.internal.R.styleable.AndroidManifestProvider_initOrder, |
| 2251 | 0); |
| 2252 | |
| 2253 | sa.recycle(); |
| 2254 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2255 | if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2256 | // A heavy-weight application can not have providers in its main process |
| 2257 | // We can do direct compare because we intern all strings. |
| 2258 | if (p.info.processName == owner.packageName) { |
| 2259 | outError[0] = "Heavy-weight applications can not have providers in main process"; |
| 2260 | return null; |
| 2261 | } |
| 2262 | } |
| 2263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | if (cpname == null) { |
| 2265 | outError[0] = "<provider> does not incude authorities attribute"; |
| 2266 | return null; |
| 2267 | } |
| 2268 | p.info.authority = cpname.intern(); |
| 2269 | |
| 2270 | if (!parseProviderTags(res, parser, attrs, p, outError)) { |
| 2271 | return null; |
| 2272 | } |
| 2273 | |
| 2274 | return p; |
| 2275 | } |
| 2276 | |
| 2277 | private boolean parseProviderTags(Resources res, |
| 2278 | XmlPullParser parser, AttributeSet attrs, |
| 2279 | Provider outInfo, String[] outError) |
| 2280 | throws XmlPullParserException, IOException { |
| 2281 | int outerDepth = parser.getDepth(); |
| 2282 | int type; |
| 2283 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2284 | && (type != XmlPullParser.END_TAG |
| 2285 | || parser.getDepth() > outerDepth)) { |
| 2286 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2287 | continue; |
| 2288 | } |
| 2289 | |
| 2290 | if (parser.getName().equals("meta-data")) { |
| 2291 | if ((outInfo.metaData=parseMetaData(res, parser, attrs, |
| 2292 | outInfo.metaData, outError)) == null) { |
| 2293 | return false; |
| 2294 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } else if (parser.getName().equals("grant-uri-permission")) { |
| 2297 | TypedArray sa = res.obtainAttributes(attrs, |
| 2298 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission); |
| 2299 | |
| 2300 | PatternMatcher pa = null; |
| 2301 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2302 | String str = sa.getNonConfigurationString( |
| 2303 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2304 | if (str != null) { |
| 2305 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL); |
| 2306 | } |
| 2307 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2308 | str = sa.getNonConfigurationString( |
| 2309 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | if (str != null) { |
| 2311 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX); |
| 2312 | } |
| 2313 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2314 | str = sa.getNonConfigurationString( |
| 2315 | com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | if (str != null) { |
| 2317 | pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 2318 | } |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | sa.recycle(); |
| 2321 | |
| 2322 | if (pa != null) { |
| 2323 | if (outInfo.info.uriPermissionPatterns == null) { |
| 2324 | outInfo.info.uriPermissionPatterns = new PatternMatcher[1]; |
| 2325 | outInfo.info.uriPermissionPatterns[0] = pa; |
| 2326 | } else { |
| 2327 | final int N = outInfo.info.uriPermissionPatterns.length; |
| 2328 | PatternMatcher[] newp = new PatternMatcher[N+1]; |
| 2329 | System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N); |
| 2330 | newp[N] = pa; |
| 2331 | outInfo.info.uriPermissionPatterns = newp; |
| 2332 | } |
| 2333 | outInfo.info.grantUriPermissions = true; |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2334 | } else { |
| 2335 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2336 | Log.w(TAG, "Unknown element under <path-permission>: " |
| 2337 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2338 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2339 | XmlUtils.skipCurrentTag(parser); |
| 2340 | continue; |
| 2341 | } |
| 2342 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 2343 | return false; |
| 2344 | } |
| 2345 | XmlUtils.skipCurrentTag(parser); |
| 2346 | |
| 2347 | } else if (parser.getName().equals("path-permission")) { |
| 2348 | TypedArray sa = res.obtainAttributes(attrs, |
| 2349 | com.android.internal.R.styleable.AndroidManifestPathPermission); |
| 2350 | |
| 2351 | PathPermission pa = null; |
| 2352 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2353 | String permission = sa.getNonConfigurationString( |
| 2354 | com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0); |
| 2355 | String readPermission = sa.getNonConfigurationString( |
| 2356 | com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2357 | if (readPermission == null) { |
| 2358 | readPermission = permission; |
| 2359 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2360 | String writePermission = sa.getNonConfigurationString( |
| 2361 | com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2362 | if (writePermission == null) { |
| 2363 | writePermission = permission; |
| 2364 | } |
| 2365 | |
| 2366 | boolean havePerm = false; |
| 2367 | if (readPermission != null) { |
| 2368 | readPermission = readPermission.intern(); |
| 2369 | havePerm = true; |
| 2370 | } |
| 2371 | if (writePermission != null) { |
Bjorn Bringert | e04b1ad | 2010-02-09 13:56:08 +0000 | [diff] [blame] | 2372 | writePermission = writePermission.intern(); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2373 | havePerm = true; |
| 2374 | } |
| 2375 | |
| 2376 | if (!havePerm) { |
| 2377 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2378 | Log.w(TAG, "No readPermission or writePermssion for <path-permission>: " |
| 2379 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2380 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2381 | XmlUtils.skipCurrentTag(parser); |
| 2382 | continue; |
| 2383 | } |
| 2384 | outError[0] = "No readPermission or writePermssion for <path-permission>"; |
| 2385 | return false; |
| 2386 | } |
| 2387 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2388 | String path = sa.getNonConfigurationString( |
| 2389 | com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2390 | if (path != null) { |
| 2391 | pa = new PathPermission(path, |
| 2392 | PatternMatcher.PATTERN_LITERAL, readPermission, writePermission); |
| 2393 | } |
| 2394 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2395 | path = sa.getNonConfigurationString( |
| 2396 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2397 | if (path != null) { |
| 2398 | pa = new PathPermission(path, |
| 2399 | PatternMatcher.PATTERN_PREFIX, readPermission, writePermission); |
| 2400 | } |
| 2401 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2402 | path = sa.getNonConfigurationString( |
| 2403 | com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2404 | if (path != null) { |
| 2405 | pa = new PathPermission(path, |
| 2406 | PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission); |
| 2407 | } |
| 2408 | |
| 2409 | sa.recycle(); |
| 2410 | |
| 2411 | if (pa != null) { |
| 2412 | if (outInfo.info.pathPermissions == null) { |
| 2413 | outInfo.info.pathPermissions = new PathPermission[1]; |
| 2414 | outInfo.info.pathPermissions[0] = pa; |
| 2415 | } else { |
| 2416 | final int N = outInfo.info.pathPermissions.length; |
| 2417 | PathPermission[] newp = new PathPermission[N+1]; |
| 2418 | System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N); |
| 2419 | newp[N] = pa; |
| 2420 | outInfo.info.pathPermissions = newp; |
| 2421 | } |
| 2422 | } else { |
| 2423 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2424 | Log.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " |
| 2425 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2426 | + parser.getPositionDescription()); |
Dianne Hackborn | 2af632f | 2009-07-08 14:56:37 -0700 | [diff] [blame] | 2427 | XmlUtils.skipCurrentTag(parser); |
| 2428 | continue; |
| 2429 | } |
| 2430 | outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>"; |
| 2431 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | } |
| 2433 | XmlUtils.skipCurrentTag(parser); |
| 2434 | |
| 2435 | } else { |
| 2436 | if (!RIGID_PARSER) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | Log.w(TAG, "Unknown element under <provider>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2438 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2439 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | XmlUtils.skipCurrentTag(parser); |
| 2441 | continue; |
| 2442 | } |
| 2443 | outError[0] = "Bad element under <provider>: " |
| 2444 | + parser.getName(); |
| 2445 | return false; |
| 2446 | } |
| 2447 | } |
| 2448 | return true; |
| 2449 | } |
| 2450 | |
| 2451 | private Service parseService(Package owner, Resources res, |
| 2452 | XmlPullParser parser, AttributeSet attrs, int flags, String[] outError) |
| 2453 | throws XmlPullParserException, IOException { |
| 2454 | TypedArray sa = res.obtainAttributes(attrs, |
| 2455 | com.android.internal.R.styleable.AndroidManifestService); |
| 2456 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2457 | if (mParseServiceArgs == null) { |
| 2458 | mParseServiceArgs = new ParseComponentArgs(owner, outError, |
| 2459 | com.android.internal.R.styleable.AndroidManifestService_name, |
| 2460 | com.android.internal.R.styleable.AndroidManifestService_label, |
| 2461 | com.android.internal.R.styleable.AndroidManifestService_icon, |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2462 | com.android.internal.R.styleable.AndroidManifestService_logo, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2463 | mSeparateProcesses, |
| 2464 | com.android.internal.R.styleable.AndroidManifestService_process, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2465 | com.android.internal.R.styleable.AndroidManifestService_description, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2466 | com.android.internal.R.styleable.AndroidManifestService_enabled); |
| 2467 | mParseServiceArgs.tag = "<service>"; |
| 2468 | } |
| 2469 | |
| 2470 | mParseServiceArgs.sa = sa; |
| 2471 | mParseServiceArgs.flags = flags; |
| 2472 | |
| 2473 | Service s = new Service(mParseServiceArgs, new ServiceInfo()); |
| 2474 | if (outError[0] != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | sa.recycle(); |
| 2476 | return null; |
| 2477 | } |
| 2478 | |
| 2479 | final boolean setExported = sa.hasValue( |
| 2480 | com.android.internal.R.styleable.AndroidManifestService_exported); |
| 2481 | if (setExported) { |
| 2482 | s.info.exported = sa.getBoolean( |
| 2483 | com.android.internal.R.styleable.AndroidManifestService_exported, false); |
| 2484 | } |
| 2485 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2486 | String str = sa.getNonConfigurationString( |
| 2487 | com.android.internal.R.styleable.AndroidManifestService_permission, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | if (str == null) { |
| 2489 | s.info.permission = owner.applicationInfo.permission; |
| 2490 | } else { |
| 2491 | s.info.permission = str.length() > 0 ? str.toString().intern() : null; |
| 2492 | } |
| 2493 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2494 | s.info.flags = 0; |
| 2495 | if (sa.getBoolean( |
| 2496 | com.android.internal.R.styleable.AndroidManifestService_stopWithTask, |
| 2497 | false)) { |
| 2498 | s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK; |
| 2499 | } |
| 2500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2501 | sa.recycle(); |
| 2502 | |
Dianne Hackborn | 54e570f | 2010-10-04 18:32:32 -0700 | [diff] [blame] | 2503 | if ((owner.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) { |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 2504 | // A heavy-weight application can not have services in its main process |
| 2505 | // We can do direct compare because we intern all strings. |
| 2506 | if (s.info.processName == owner.packageName) { |
| 2507 | outError[0] = "Heavy-weight applications can not have services in main process"; |
| 2508 | return null; |
| 2509 | } |
| 2510 | } |
| 2511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | int outerDepth = parser.getDepth(); |
| 2513 | int type; |
| 2514 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2515 | && (type != XmlPullParser.END_TAG |
| 2516 | || parser.getDepth() > outerDepth)) { |
| 2517 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2518 | continue; |
| 2519 | } |
| 2520 | |
| 2521 | if (parser.getName().equals("intent-filter")) { |
| 2522 | ServiceIntentInfo intent = new ServiceIntentInfo(s); |
| 2523 | if (!parseIntent(res, parser, attrs, flags, intent, outError, false)) { |
| 2524 | return null; |
| 2525 | } |
| 2526 | |
| 2527 | s.intents.add(intent); |
| 2528 | } else if (parser.getName().equals("meta-data")) { |
| 2529 | if ((s.metaData=parseMetaData(res, parser, attrs, s.metaData, |
| 2530 | outError)) == null) { |
| 2531 | return null; |
| 2532 | } |
| 2533 | } else { |
| 2534 | if (!RIGID_PARSER) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | Log.w(TAG, "Unknown element under <service>: " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2536 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2537 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | XmlUtils.skipCurrentTag(parser); |
| 2539 | continue; |
| 2540 | } |
| 2541 | outError[0] = "Bad element under <service>: " |
| 2542 | + parser.getName(); |
| 2543 | return null; |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | if (!setExported) { |
| 2548 | s.info.exported = s.intents.size() > 0; |
| 2549 | } |
| 2550 | |
| 2551 | return s; |
| 2552 | } |
| 2553 | |
| 2554 | private boolean parseAllMetaData(Resources res, |
| 2555 | XmlPullParser parser, AttributeSet attrs, String tag, |
| 2556 | Component outInfo, String[] outError) |
| 2557 | throws XmlPullParserException, IOException { |
| 2558 | int outerDepth = parser.getDepth(); |
| 2559 | int type; |
| 2560 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2561 | && (type != XmlPullParser.END_TAG |
| 2562 | || parser.getDepth() > outerDepth)) { |
| 2563 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2564 | continue; |
| 2565 | } |
| 2566 | |
| 2567 | if (parser.getName().equals("meta-data")) { |
| 2568 | if ((outInfo.metaData=parseMetaData(res, parser, attrs, |
| 2569 | outInfo.metaData, outError)) == null) { |
| 2570 | return false; |
| 2571 | } |
| 2572 | } else { |
| 2573 | if (!RIGID_PARSER) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | Log.w(TAG, "Unknown element under " + tag + ": " |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2575 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2576 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | XmlUtils.skipCurrentTag(parser); |
| 2578 | continue; |
| 2579 | } |
| 2580 | outError[0] = "Bad element under " + tag + ": " |
| 2581 | + parser.getName(); |
| 2582 | return false; |
| 2583 | } |
| 2584 | } |
| 2585 | return true; |
| 2586 | } |
| 2587 | |
| 2588 | private Bundle parseMetaData(Resources res, |
| 2589 | XmlPullParser parser, AttributeSet attrs, |
| 2590 | Bundle data, String[] outError) |
| 2591 | throws XmlPullParserException, IOException { |
| 2592 | |
| 2593 | TypedArray sa = res.obtainAttributes(attrs, |
| 2594 | com.android.internal.R.styleable.AndroidManifestMetaData); |
| 2595 | |
| 2596 | if (data == null) { |
| 2597 | data = new Bundle(); |
| 2598 | } |
| 2599 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2600 | String name = sa.getNonConfigurationString( |
| 2601 | com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | if (name == null) { |
| 2603 | outError[0] = "<meta-data> requires an android:name attribute"; |
| 2604 | sa.recycle(); |
| 2605 | return null; |
| 2606 | } |
| 2607 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2608 | name = name.intern(); |
| 2609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | TypedValue v = sa.peekValue( |
| 2611 | com.android.internal.R.styleable.AndroidManifestMetaData_resource); |
| 2612 | if (v != null && v.resourceId != 0) { |
| 2613 | //Log.i(TAG, "Meta data ref " + name + ": " + v); |
| 2614 | data.putInt(name, v.resourceId); |
| 2615 | } else { |
| 2616 | v = sa.peekValue( |
| 2617 | com.android.internal.R.styleable.AndroidManifestMetaData_value); |
| 2618 | //Log.i(TAG, "Meta data " + name + ": " + v); |
| 2619 | if (v != null) { |
| 2620 | if (v.type == TypedValue.TYPE_STRING) { |
| 2621 | CharSequence cs = v.coerceToString(); |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2622 | data.putString(name, cs != null ? cs.toString().intern() : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { |
| 2624 | data.putBoolean(name, v.data != 0); |
| 2625 | } else if (v.type >= TypedValue.TYPE_FIRST_INT |
| 2626 | && v.type <= TypedValue.TYPE_LAST_INT) { |
| 2627 | data.putInt(name, v.data); |
| 2628 | } else if (v.type == TypedValue.TYPE_FLOAT) { |
| 2629 | data.putFloat(name, v.getFloat()); |
| 2630 | } else { |
| 2631 | if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2632 | Log.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " |
| 2633 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2634 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | } else { |
| 2636 | outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; |
| 2637 | data = null; |
| 2638 | } |
| 2639 | } |
| 2640 | } else { |
| 2641 | outError[0] = "<meta-data> requires an android:value or android:resource attribute"; |
| 2642 | data = null; |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | sa.recycle(); |
| 2647 | |
| 2648 | XmlUtils.skipCurrentTag(parser); |
| 2649 | |
| 2650 | return data; |
| 2651 | } |
| 2652 | |
| 2653 | private static final String ANDROID_RESOURCES |
| 2654 | = "http://schemas.android.com/apk/res/android"; |
| 2655 | |
| 2656 | private boolean parseIntent(Resources res, |
| 2657 | XmlPullParser parser, AttributeSet attrs, int flags, |
| 2658 | IntentInfo outInfo, String[] outError, boolean isActivity) |
| 2659 | throws XmlPullParserException, IOException { |
| 2660 | |
| 2661 | TypedArray sa = res.obtainAttributes(attrs, |
| 2662 | com.android.internal.R.styleable.AndroidManifestIntentFilter); |
| 2663 | |
| 2664 | int priority = sa.getInt( |
| 2665 | com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2666 | outInfo.setPriority(priority); |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 2667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | TypedValue v = sa.peekValue( |
| 2669 | com.android.internal.R.styleable.AndroidManifestIntentFilter_label); |
| 2670 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 2671 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 2672 | } |
| 2673 | |
| 2674 | outInfo.icon = sa.getResourceId( |
| 2675 | com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0); |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2676 | |
| 2677 | outInfo.logo = sa.getResourceId( |
| 2678 | com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | |
| 2680 | sa.recycle(); |
| 2681 | |
| 2682 | int outerDepth = parser.getDepth(); |
| 2683 | int type; |
| 2684 | while ((type=parser.next()) != parser.END_DOCUMENT |
| 2685 | && (type != parser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2686 | if (type == parser.END_TAG || type == parser.TEXT) { |
| 2687 | continue; |
| 2688 | } |
| 2689 | |
| 2690 | String nodeName = parser.getName(); |
| 2691 | if (nodeName.equals("action")) { |
| 2692 | String value = attrs.getAttributeValue( |
| 2693 | ANDROID_RESOURCES, "name"); |
| 2694 | if (value == null || value == "") { |
| 2695 | outError[0] = "No value supplied for <android:name>"; |
| 2696 | return false; |
| 2697 | } |
| 2698 | XmlUtils.skipCurrentTag(parser); |
| 2699 | |
| 2700 | outInfo.addAction(value); |
| 2701 | } else if (nodeName.equals("category")) { |
| 2702 | String value = attrs.getAttributeValue( |
| 2703 | ANDROID_RESOURCES, "name"); |
| 2704 | if (value == null || value == "") { |
| 2705 | outError[0] = "No value supplied for <android:name>"; |
| 2706 | return false; |
| 2707 | } |
| 2708 | XmlUtils.skipCurrentTag(parser); |
| 2709 | |
| 2710 | outInfo.addCategory(value); |
| 2711 | |
| 2712 | } else if (nodeName.equals("data")) { |
| 2713 | sa = res.obtainAttributes(attrs, |
| 2714 | com.android.internal.R.styleable.AndroidManifestData); |
| 2715 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2716 | String str = sa.getNonConfigurationString( |
| 2717 | com.android.internal.R.styleable.AndroidManifestData_mimeType, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | if (str != null) { |
| 2719 | try { |
| 2720 | outInfo.addDataType(str); |
| 2721 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 2722 | outError[0] = e.toString(); |
| 2723 | sa.recycle(); |
| 2724 | return false; |
| 2725 | } |
| 2726 | } |
| 2727 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2728 | str = sa.getNonConfigurationString( |
| 2729 | com.android.internal.R.styleable.AndroidManifestData_scheme, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | if (str != null) { |
| 2731 | outInfo.addDataScheme(str); |
| 2732 | } |
| 2733 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2734 | String host = sa.getNonConfigurationString( |
| 2735 | com.android.internal.R.styleable.AndroidManifestData_host, 0); |
| 2736 | String port = sa.getNonConfigurationString( |
| 2737 | com.android.internal.R.styleable.AndroidManifestData_port, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | if (host != null) { |
| 2739 | outInfo.addDataAuthority(host, port); |
| 2740 | } |
| 2741 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2742 | str = sa.getNonConfigurationString( |
| 2743 | com.android.internal.R.styleable.AndroidManifestData_path, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | if (str != null) { |
| 2745 | outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL); |
| 2746 | } |
| 2747 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2748 | str = sa.getNonConfigurationString( |
| 2749 | com.android.internal.R.styleable.AndroidManifestData_pathPrefix, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | if (str != null) { |
| 2751 | outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX); |
| 2752 | } |
| 2753 | |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2754 | str = sa.getNonConfigurationString( |
| 2755 | com.android.internal.R.styleable.AndroidManifestData_pathPattern, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | if (str != null) { |
| 2757 | outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB); |
| 2758 | } |
| 2759 | |
| 2760 | sa.recycle(); |
| 2761 | XmlUtils.skipCurrentTag(parser); |
| 2762 | } else if (!RIGID_PARSER) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2763 | Log.w(TAG, "Unknown element under <intent-filter>: " |
| 2764 | + parser.getName() + " at " + mArchiveSourcePath + " " |
| 2765 | + parser.getPositionDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2766 | XmlUtils.skipCurrentTag(parser); |
| 2767 | } else { |
| 2768 | outError[0] = "Bad element under <intent-filter>: " + parser.getName(); |
| 2769 | return false; |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT); |
| 2774 | if (false) { |
| 2775 | String cats = ""; |
| 2776 | Iterator<String> it = outInfo.categoriesIterator(); |
| 2777 | while (it != null && it.hasNext()) { |
| 2778 | cats += " " + it.next(); |
| 2779 | } |
| 2780 | System.out.println("Intent d=" + |
| 2781 | outInfo.hasDefault + ", cat=" + cats); |
| 2782 | } |
| 2783 | |
| 2784 | return true; |
| 2785 | } |
| 2786 | |
| 2787 | public final static class Package { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2788 | public String packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | |
| 2790 | // For now we only support one application per package. |
| 2791 | public final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 2792 | |
| 2793 | public final ArrayList<Permission> permissions = new ArrayList<Permission>(0); |
| 2794 | public final ArrayList<PermissionGroup> permissionGroups = new ArrayList<PermissionGroup>(0); |
| 2795 | public final ArrayList<Activity> activities = new ArrayList<Activity>(0); |
| 2796 | public final ArrayList<Activity> receivers = new ArrayList<Activity>(0); |
| 2797 | public final ArrayList<Provider> providers = new ArrayList<Provider>(0); |
| 2798 | public final ArrayList<Service> services = new ArrayList<Service>(0); |
| 2799 | public final ArrayList<Instrumentation> instrumentation = new ArrayList<Instrumentation>(0); |
| 2800 | |
| 2801 | public final ArrayList<String> requestedPermissions = new ArrayList<String>(); |
| 2802 | |
Dianne Hackborn | 854060a | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 2803 | public ArrayList<String> protectedBroadcasts; |
| 2804 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2805 | public ArrayList<String> usesLibraries = null; |
| 2806 | public ArrayList<String> usesOptionalLibraries = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | public String[] usesLibraryFiles = null; |
| 2808 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2809 | public ArrayList<String> mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2810 | public String mRealPackage = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2811 | public ArrayList<String> mAdoptPermissions = null; |
| 2812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | // We store the application meta-data independently to avoid multiple unwanted references |
| 2814 | public Bundle mAppMetaData = null; |
| 2815 | |
| 2816 | // If this is a 3rd party app, this is the path of the zip file. |
| 2817 | public String mPath; |
| 2818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | // The version code declared for this package. |
| 2820 | public int mVersionCode; |
| 2821 | |
| 2822 | // The version name declared for this package. |
| 2823 | public String mVersionName; |
| 2824 | |
| 2825 | // The shared user id that this package wants to use. |
| 2826 | public String mSharedUserId; |
| 2827 | |
| 2828 | // The shared user label that this package wants to use. |
| 2829 | public int mSharedUserLabel; |
| 2830 | |
| 2831 | // Signatures that were read from the package. |
| 2832 | public Signature mSignatures[]; |
| 2833 | |
| 2834 | // For use by package manager service for quick lookup of |
| 2835 | // preferred up order. |
| 2836 | public int mPreferredOrder = 0; |
| 2837 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2838 | // For use by the package manager to keep track of the path to the |
| 2839 | // file an app came from. |
| 2840 | public String mScanPath; |
| 2841 | |
| 2842 | // For use by package manager to keep track of where it has done dexopt. |
| 2843 | public boolean mDidDexOpt; |
| 2844 | |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 2845 | // User set enabled state. |
| 2846 | public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 2847 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2848 | // Whether the package has been stopped. |
| 2849 | public boolean mSetStopped = false; |
| 2850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | // Additional data supplied by callers. |
| 2852 | public Object mExtras; |
Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 2853 | |
| 2854 | // Whether an operation is currently pending on this package |
| 2855 | public boolean mOperationPending; |
| 2856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | /* |
| 2858 | * Applications hardware preferences |
| 2859 | */ |
| 2860 | public final ArrayList<ConfigurationInfo> configPreferences = |
| 2861 | new ArrayList<ConfigurationInfo>(); |
| 2862 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2863 | /* |
| 2864 | * Applications requested features |
| 2865 | */ |
| 2866 | public ArrayList<FeatureInfo> reqFeatures = null; |
| 2867 | |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 2868 | public int installLocation; |
| 2869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | public Package(String _name) { |
| 2871 | packageName = _name; |
| 2872 | applicationInfo.packageName = _name; |
| 2873 | applicationInfo.uid = -1; |
| 2874 | } |
| 2875 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2876 | public void setPackageName(String newName) { |
| 2877 | packageName = newName; |
| 2878 | applicationInfo.packageName = newName; |
| 2879 | for (int i=permissions.size()-1; i>=0; i--) { |
| 2880 | permissions.get(i).setPackageName(newName); |
| 2881 | } |
| 2882 | for (int i=permissionGroups.size()-1; i>=0; i--) { |
| 2883 | permissionGroups.get(i).setPackageName(newName); |
| 2884 | } |
| 2885 | for (int i=activities.size()-1; i>=0; i--) { |
| 2886 | activities.get(i).setPackageName(newName); |
| 2887 | } |
| 2888 | for (int i=receivers.size()-1; i>=0; i--) { |
| 2889 | receivers.get(i).setPackageName(newName); |
| 2890 | } |
| 2891 | for (int i=providers.size()-1; i>=0; i--) { |
| 2892 | providers.get(i).setPackageName(newName); |
| 2893 | } |
| 2894 | for (int i=services.size()-1; i>=0; i--) { |
| 2895 | services.get(i).setPackageName(newName); |
| 2896 | } |
| 2897 | for (int i=instrumentation.size()-1; i>=0; i--) { |
| 2898 | instrumentation.get(i).setPackageName(newName); |
| 2899 | } |
| 2900 | } |
| 2901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | public String toString() { |
| 2903 | return "Package{" |
| 2904 | + Integer.toHexString(System.identityHashCode(this)) |
| 2905 | + " " + packageName + "}"; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | public static class Component<II extends IntentInfo> { |
| 2910 | public final Package owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2911 | public final ArrayList<II> intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2912 | public final String className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | public Bundle metaData; |
| 2914 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2915 | ComponentName componentName; |
| 2916 | String componentShortName; |
| 2917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | public Component(Package _owner) { |
| 2919 | owner = _owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2920 | intents = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2921 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { |
| 2925 | owner = args.owner; |
| 2926 | intents = new ArrayList<II>(0); |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 2927 | String name = args.sa.getNonConfigurationString(args.nameRes, 0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2928 | if (name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2929 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2930 | args.outError[0] = args.tag + " does not specify android:name"; |
| 2931 | return; |
| 2932 | } |
| 2933 | |
| 2934 | outInfo.name |
| 2935 | = buildClassName(owner.applicationInfo.packageName, name, args.outError); |
| 2936 | if (outInfo.name == null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2937 | className = null; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2938 | args.outError[0] = args.tag + " does not have valid android:name"; |
| 2939 | return; |
| 2940 | } |
| 2941 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2942 | className = outInfo.name; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2943 | |
| 2944 | int iconVal = args.sa.getResourceId(args.iconRes, 0); |
| 2945 | if (iconVal != 0) { |
| 2946 | outInfo.icon = iconVal; |
| 2947 | outInfo.nonLocalizedLabel = null; |
| 2948 | } |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 2949 | |
| 2950 | int logoVal = args.sa.getResourceId(args.logoRes, 0); |
| 2951 | if (logoVal != 0) { |
| 2952 | outInfo.logo = logoVal; |
| 2953 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2954 | |
| 2955 | TypedValue v = args.sa.peekValue(args.labelRes); |
| 2956 | if (v != null && (outInfo.labelRes=v.resourceId) == 0) { |
| 2957 | outInfo.nonLocalizedLabel = v.coerceToString(); |
| 2958 | } |
| 2959 | |
| 2960 | outInfo.packageName = owner.packageName; |
| 2961 | } |
| 2962 | |
| 2963 | public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { |
| 2964 | this(args, (PackageItemInfo)outInfo); |
| 2965 | if (args.outError[0] != null) { |
| 2966 | return; |
| 2967 | } |
| 2968 | |
| 2969 | if (args.processRes != 0) { |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2970 | CharSequence pname; |
| 2971 | if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { |
| 2972 | pname = args.sa.getNonConfigurationString(args.processRes, 0); |
| 2973 | } else { |
| 2974 | // Some older apps have been seen to use a resource reference |
| 2975 | // here that on older builds was ignored (with a warning). We |
| 2976 | // need to continue to do this for them so they don't break. |
| 2977 | pname = args.sa.getNonResourceString(args.processRes); |
| 2978 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2979 | outInfo.processName = buildProcessName(owner.applicationInfo.packageName, |
Dianne Hackborn | d1cff1b | 2010-04-02 16:51:26 -0700 | [diff] [blame] | 2980 | owner.applicationInfo.processName, pname, |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2981 | args.flags, args.sepProcesses, args.outError); |
| 2982 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2983 | |
| 2984 | if (args.descriptionRes != 0) { |
| 2985 | outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); |
| 2986 | } |
| 2987 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2988 | outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | public Component(Component<II> clone) { |
| 2992 | owner = clone.owner; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2993 | intents = clone.intents; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2994 | className = clone.className; |
| 2995 | componentName = clone.componentName; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2996 | componentShortName = clone.componentShortName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | public ComponentName getComponentName() { |
| 3000 | if (componentName != null) { |
| 3001 | return componentName; |
| 3002 | } |
| 3003 | if (className != null) { |
| 3004 | componentName = new ComponentName(owner.applicationInfo.packageName, |
| 3005 | className); |
| 3006 | } |
| 3007 | return componentName; |
| 3008 | } |
| 3009 | |
| 3010 | public String getComponentShortName() { |
| 3011 | if (componentShortName != null) { |
| 3012 | return componentShortName; |
| 3013 | } |
| 3014 | ComponentName component = getComponentName(); |
| 3015 | if (component != null) { |
| 3016 | componentShortName = component.flattenToShortString(); |
| 3017 | } |
| 3018 | return componentShortName; |
| 3019 | } |
| 3020 | |
| 3021 | public void setPackageName(String packageName) { |
| 3022 | componentName = null; |
| 3023 | componentShortName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | public final static class Permission extends Component<IntentInfo> { |
| 3028 | public final PermissionInfo info; |
| 3029 | public boolean tree; |
| 3030 | public PermissionGroup group; |
| 3031 | |
| 3032 | public Permission(Package _owner) { |
| 3033 | super(_owner); |
| 3034 | info = new PermissionInfo(); |
| 3035 | } |
| 3036 | |
| 3037 | public Permission(Package _owner, PermissionInfo _info) { |
| 3038 | super(_owner); |
| 3039 | info = _info; |
| 3040 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3041 | |
| 3042 | public void setPackageName(String packageName) { |
| 3043 | super.setPackageName(packageName); |
| 3044 | info.packageName = packageName; |
| 3045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | |
| 3047 | public String toString() { |
| 3048 | return "Permission{" |
| 3049 | + Integer.toHexString(System.identityHashCode(this)) |
| 3050 | + " " + info.name + "}"; |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | public final static class PermissionGroup extends Component<IntentInfo> { |
| 3055 | public final PermissionGroupInfo info; |
| 3056 | |
| 3057 | public PermissionGroup(Package _owner) { |
| 3058 | super(_owner); |
| 3059 | info = new PermissionGroupInfo(); |
| 3060 | } |
| 3061 | |
| 3062 | public PermissionGroup(Package _owner, PermissionGroupInfo _info) { |
| 3063 | super(_owner); |
| 3064 | info = _info; |
| 3065 | } |
| 3066 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3067 | public void setPackageName(String packageName) { |
| 3068 | super.setPackageName(packageName); |
| 3069 | info.packageName = packageName; |
| 3070 | } |
| 3071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | public String toString() { |
| 3073 | return "PermissionGroup{" |
| 3074 | + Integer.toHexString(System.identityHashCode(this)) |
| 3075 | + " " + info.name + "}"; |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | private static boolean copyNeeded(int flags, Package p, Bundle metaData) { |
Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 3080 | if (p.mSetEnabled != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 3081 | boolean enabled = p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 3082 | if (p.applicationInfo.enabled != enabled) { |
| 3083 | return true; |
| 3084 | } |
| 3085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | if ((flags & PackageManager.GET_META_DATA) != 0 |
| 3087 | && (metaData != null || p.mAppMetaData != null)) { |
| 3088 | return true; |
| 3089 | } |
| 3090 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0 |
| 3091 | && p.usesLibraryFiles != null) { |
| 3092 | return true; |
| 3093 | } |
| 3094 | return false; |
| 3095 | } |
| 3096 | |
| 3097 | public static ApplicationInfo generateApplicationInfo(Package p, int flags) { |
| 3098 | if (p == null) return null; |
| 3099 | if (!copyNeeded(flags, p, null)) { |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3100 | // CompatibilityMode is global state. It's safe to modify the instance |
| 3101 | // of the package. |
| 3102 | if (!sCompatibilityModeEnabled) { |
| 3103 | p.applicationInfo.disableCompatibilityMode(); |
| 3104 | } |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 3105 | if (p.mSetStopped) { |
| 3106 | p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED; |
| 3107 | } else { |
| 3108 | p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 3109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | return p.applicationInfo; |
| 3111 | } |
| 3112 | |
| 3113 | // Make shallow copy so we can store the metadata/libraries safely |
| 3114 | ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); |
| 3115 | if ((flags & PackageManager.GET_META_DATA) != 0) { |
| 3116 | ai.metaData = p.mAppMetaData; |
| 3117 | } |
| 3118 | if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { |
| 3119 | ai.sharedLibraryFiles = p.usesLibraryFiles; |
| 3120 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3121 | if (!sCompatibilityModeEnabled) { |
| 3122 | ai.disableCompatibilityMode(); |
| 3123 | } |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 3124 | if (p.mSetStopped) { |
| 3125 | p.applicationInfo.flags |= ApplicationInfo.FLAG_STOPPED; |
| 3126 | } else { |
| 3127 | p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED; |
| 3128 | } |
John Reck | 4b7b7cc | 2011-02-02 11:57:44 -0800 | [diff] [blame] | 3129 | if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { |
| 3130 | ai.enabled = true; |
Dianne Hackborn | 0ac3031 | 2011-06-17 14:49:23 -0700 | [diff] [blame] | 3131 | } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED |
| 3132 | || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { |
John Reck | 4b7b7cc | 2011-02-02 11:57:44 -0800 | [diff] [blame] | 3133 | ai.enabled = false; |
| 3134 | } |
Dianne Hackborn | 0ac3031 | 2011-06-17 14:49:23 -0700 | [diff] [blame] | 3135 | ai.enabledSetting = p.mSetEnabled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | return ai; |
| 3137 | } |
| 3138 | |
| 3139 | public static final PermissionInfo generatePermissionInfo( |
| 3140 | Permission p, int flags) { |
| 3141 | if (p == null) return null; |
| 3142 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3143 | return p.info; |
| 3144 | } |
| 3145 | PermissionInfo pi = new PermissionInfo(p.info); |
| 3146 | pi.metaData = p.metaData; |
| 3147 | return pi; |
| 3148 | } |
| 3149 | |
| 3150 | public static final PermissionGroupInfo generatePermissionGroupInfo( |
| 3151 | PermissionGroup pg, int flags) { |
| 3152 | if (pg == null) return null; |
| 3153 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3154 | return pg.info; |
| 3155 | } |
| 3156 | PermissionGroupInfo pgi = new PermissionGroupInfo(pg.info); |
| 3157 | pgi.metaData = pg.metaData; |
| 3158 | return pgi; |
| 3159 | } |
| 3160 | |
| 3161 | public final static class Activity extends Component<ActivityIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3162 | public final ActivityInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3163 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3164 | public Activity(final ParseComponentArgs args, final ActivityInfo _info) { |
| 3165 | super(args, _info); |
| 3166 | info = _info; |
| 3167 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3168 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3169 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3170 | public void setPackageName(String packageName) { |
| 3171 | super.setPackageName(packageName); |
| 3172 | info.packageName = packageName; |
| 3173 | } |
| 3174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | public String toString() { |
| 3176 | return "Activity{" |
| 3177 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3178 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | public static final ActivityInfo generateActivityInfo(Activity a, |
| 3183 | int flags) { |
| 3184 | if (a == null) return null; |
| 3185 | if (!copyNeeded(flags, a.owner, a.metaData)) { |
| 3186 | return a.info; |
| 3187 | } |
| 3188 | // Make shallow copies so we can store the metadata safely |
| 3189 | ActivityInfo ai = new ActivityInfo(a.info); |
| 3190 | ai.metaData = a.metaData; |
| 3191 | ai.applicationInfo = generateApplicationInfo(a.owner, flags); |
| 3192 | return ai; |
| 3193 | } |
| 3194 | |
| 3195 | public final static class Service extends Component<ServiceIntentInfo> { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3196 | public final ServiceInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3198 | public Service(final ParseComponentArgs args, final ServiceInfo _info) { |
| 3199 | super(args, _info); |
| 3200 | info = _info; |
| 3201 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3203 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3204 | public void setPackageName(String packageName) { |
| 3205 | super.setPackageName(packageName); |
| 3206 | info.packageName = packageName; |
| 3207 | } |
| 3208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | public String toString() { |
| 3210 | return "Service{" |
| 3211 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3212 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | public static final ServiceInfo generateServiceInfo(Service s, int flags) { |
| 3217 | if (s == null) return null; |
| 3218 | if (!copyNeeded(flags, s.owner, s.metaData)) { |
| 3219 | return s.info; |
| 3220 | } |
| 3221 | // Make shallow copies so we can store the metadata safely |
| 3222 | ServiceInfo si = new ServiceInfo(s.info); |
| 3223 | si.metaData = s.metaData; |
| 3224 | si.applicationInfo = generateApplicationInfo(s.owner, flags); |
| 3225 | return si; |
| 3226 | } |
| 3227 | |
| 3228 | public final static class Provider extends Component { |
| 3229 | public final ProviderInfo info; |
| 3230 | public boolean syncable; |
| 3231 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3232 | public Provider(final ParseComponentArgs args, final ProviderInfo _info) { |
| 3233 | super(args, _info); |
| 3234 | info = _info; |
| 3235 | info.applicationInfo = args.owner.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | syncable = false; |
| 3237 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | public Provider(Provider existingProvider) { |
| 3240 | super(existingProvider); |
| 3241 | this.info = existingProvider.info; |
| 3242 | this.syncable = existingProvider.syncable; |
| 3243 | } |
| 3244 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3245 | public void setPackageName(String packageName) { |
| 3246 | super.setPackageName(packageName); |
| 3247 | info.packageName = packageName; |
| 3248 | } |
| 3249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | public String toString() { |
| 3251 | return "Provider{" |
| 3252 | + Integer.toHexString(System.identityHashCode(this)) |
| 3253 | + " " + info.name + "}"; |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | public static final ProviderInfo generateProviderInfo(Provider p, |
| 3258 | int flags) { |
| 3259 | if (p == null) return null; |
| 3260 | if (!copyNeeded(flags, p.owner, p.metaData) |
| 3261 | && ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) != 0 |
| 3262 | || p.info.uriPermissionPatterns == null)) { |
| 3263 | return p.info; |
| 3264 | } |
| 3265 | // Make shallow copies so we can store the metadata safely |
| 3266 | ProviderInfo pi = new ProviderInfo(p.info); |
| 3267 | pi.metaData = p.metaData; |
| 3268 | if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) { |
| 3269 | pi.uriPermissionPatterns = null; |
| 3270 | } |
| 3271 | pi.applicationInfo = generateApplicationInfo(p.owner, flags); |
| 3272 | return pi; |
| 3273 | } |
| 3274 | |
| 3275 | public final static class Instrumentation extends Component { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3276 | public final InstrumentationInfo info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3278 | public Instrumentation(final ParsePackageItemArgs args, final InstrumentationInfo _info) { |
| 3279 | super(args, _info); |
| 3280 | info = _info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3282 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3283 | public void setPackageName(String packageName) { |
| 3284 | super.setPackageName(packageName); |
| 3285 | info.packageName = packageName; |
| 3286 | } |
| 3287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | public String toString() { |
| 3289 | return "Instrumentation{" |
| 3290 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3291 | + " " + getComponentShortName() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | public static final InstrumentationInfo generateInstrumentationInfo( |
| 3296 | Instrumentation i, int flags) { |
| 3297 | if (i == null) return null; |
| 3298 | if ((flags&PackageManager.GET_META_DATA) == 0) { |
| 3299 | return i.info; |
| 3300 | } |
| 3301 | InstrumentationInfo ii = new InstrumentationInfo(i.info); |
| 3302 | ii.metaData = i.metaData; |
| 3303 | return ii; |
| 3304 | } |
| 3305 | |
| 3306 | public static class IntentInfo extends IntentFilter { |
| 3307 | public boolean hasDefault; |
| 3308 | public int labelRes; |
| 3309 | public CharSequence nonLocalizedLabel; |
| 3310 | public int icon; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 3311 | public int logo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | public final static class ActivityIntentInfo extends IntentInfo { |
| 3315 | public final Activity activity; |
| 3316 | |
| 3317 | public ActivityIntentInfo(Activity _activity) { |
| 3318 | activity = _activity; |
| 3319 | } |
| 3320 | |
| 3321 | public String toString() { |
| 3322 | return "ActivityIntentInfo{" |
| 3323 | + Integer.toHexString(System.identityHashCode(this)) |
| 3324 | + " " + activity.info.name + "}"; |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | public final static class ServiceIntentInfo extends IntentInfo { |
| 3329 | public final Service service; |
| 3330 | |
| 3331 | public ServiceIntentInfo(Service _service) { |
| 3332 | service = _service; |
| 3333 | } |
| 3334 | |
| 3335 | public String toString() { |
| 3336 | return "ServiceIntentInfo{" |
| 3337 | + Integer.toHexString(System.identityHashCode(this)) |
| 3338 | + " " + service.info.name + "}"; |
| 3339 | } |
| 3340 | } |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 3341 | |
| 3342 | /** |
| 3343 | * @hide |
| 3344 | */ |
| 3345 | public static void setCompatibilityModeEnabled(boolean compatibilityModeEnabled) { |
| 3346 | sCompatibilityModeEnabled = compatibilityModeEnabled; |
| 3347 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | } |