Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | /** |
| 23 | * Overall information about the contents of a package. This corresponds |
| 24 | * to all of the information collected from AndroidManifest.xml. |
| 25 | */ |
| 26 | public class PackageInfo implements Parcelable { |
| 27 | /** |
| 28 | * The name of this package. From the <manifest> tag's "name" |
| 29 | * attribute. |
| 30 | */ |
| 31 | public String packageName; |
| 32 | |
| 33 | /** |
| 34 | * The version number of this package, as specified by the <manifest> |
| 35 | * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode} |
| 36 | * attribute. |
| 37 | */ |
| 38 | public int versionCode; |
| 39 | |
| 40 | /** |
| 41 | * The version name of this package, as specified by the <manifest> |
| 42 | * tag's {@link android.R.styleable#AndroidManifest_versionName versionName} |
| 43 | * attribute. |
| 44 | */ |
| 45 | public String versionName; |
| 46 | |
| 47 | /** |
| 48 | * The shared user ID name of this package, as specified by the <manifest> |
| 49 | * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId} |
| 50 | * attribute. |
| 51 | */ |
| 52 | public String sharedUserId; |
| 53 | |
| 54 | /** |
| 55 | * The shared user ID label of this package, as specified by the <manifest> |
| 56 | * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel} |
| 57 | * attribute. |
| 58 | */ |
| 59 | public int sharedUserLabel; |
| 60 | |
| 61 | /** |
| 62 | * Information collected from the <application> tag, or null if |
| 63 | * there was none. |
| 64 | */ |
| 65 | public ApplicationInfo applicationInfo; |
| 66 | |
| 67 | /** |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 68 | * The time at which the app was first installed. Units are as |
| 69 | * per {@link System#currentTimeMillis()}. |
| 70 | */ |
| 71 | public long firstInstallTime; |
| 72 | |
| 73 | /** |
| 74 | * The time at which the app was last updated. Units are as |
| 75 | * per {@link System#currentTimeMillis()}. |
| 76 | */ |
| 77 | public long lastUpdateTime; |
| 78 | |
| 79 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | * All kernel group-IDs that have been assigned to this package. |
| 81 | * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set. |
| 82 | */ |
| 83 | public int[] gids; |
| 84 | |
| 85 | /** |
| 86 | * Array of all {@link android.R.styleable#AndroidManifestActivity |
| 87 | * <activity>} tags included under <application>, |
| 88 | * or null if there were none. This is only filled in if the flag |
| 89 | * {@link PackageManager#GET_ACTIVITIES} was set. |
| 90 | */ |
| 91 | public ActivityInfo[] activities; |
| 92 | |
| 93 | /** |
| 94 | * Array of all {@link android.R.styleable#AndroidManifestReceiver |
| 95 | * <receiver>} tags included under <application>, |
| 96 | * or null if there were none. This is only filled in if the flag |
| 97 | * {@link PackageManager#GET_RECEIVERS} was set. |
| 98 | */ |
| 99 | public ActivityInfo[] receivers; |
| 100 | |
| 101 | /** |
| 102 | * Array of all {@link android.R.styleable#AndroidManifestService |
| 103 | * <service>} tags included under <application>, |
| 104 | * or null if there were none. This is only filled in if the flag |
| 105 | * {@link PackageManager#GET_SERVICES} was set. |
| 106 | */ |
| 107 | public ServiceInfo[] services; |
| 108 | |
| 109 | /** |
| 110 | * Array of all {@link android.R.styleable#AndroidManifestProvider |
| 111 | * <provider>} tags included under <application>, |
| 112 | * or null if there were none. This is only filled in if the flag |
| 113 | * {@link PackageManager#GET_PROVIDERS} was set. |
| 114 | */ |
| 115 | public ProviderInfo[] providers; |
| 116 | |
| 117 | /** |
| 118 | * Array of all {@link android.R.styleable#AndroidManifestInstrumentation |
| 119 | * <instrumentation>} tags included under <manifest>, |
| 120 | * or null if there were none. This is only filled in if the flag |
| 121 | * {@link PackageManager#GET_INSTRUMENTATION} was set. |
| 122 | */ |
| 123 | public InstrumentationInfo[] instrumentation; |
| 124 | |
| 125 | /** |
| 126 | * Array of all {@link android.R.styleable#AndroidManifestPermission |
| 127 | * <permission>} tags included under <manifest>, |
| 128 | * or null if there were none. This is only filled in if the flag |
| 129 | * {@link PackageManager#GET_PERMISSIONS} was set. |
| 130 | */ |
| 131 | public PermissionInfo[] permissions; |
| 132 | |
| 133 | /** |
| 134 | * Array of all {@link android.R.styleable#AndroidManifestUsesPermission |
| 135 | * <uses-permission>} tags included under <manifest>, |
| 136 | * or null if there were none. This is only filled in if the flag |
| 137 | * {@link PackageManager#GET_PERMISSIONS} was set. This list includes |
| 138 | * all permissions requested, even those that were not granted or known |
| 139 | * by the system at install time. |
| 140 | */ |
| 141 | public String[] requestedPermissions; |
| 142 | |
| 143 | /** |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 144 | * Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission |
| 145 | * <uses-permission>} tags included under <manifest>, |
| 146 | * or null if there were none. This is only filled in if the flag |
| 147 | * {@link PackageManager#GET_PERMISSIONS} was set. Each value matches |
| 148 | * the corresponding entry in {@link #requestedPermissions}, and will have |
| 149 | * the flags {@link #REQUESTED_PERMISSION_REQUIRED} and |
| 150 | * {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate. |
| 151 | */ |
| 152 | public int[] requestedPermissionsFlags; |
| 153 | |
| 154 | /** |
| 155 | * Flag for {@link #requestedPermissionsFlags}: the requested permission |
| 156 | * is required for the application to run; the user can not optionally |
Dianne Hackborn | e824120 | 2012-04-06 13:39:09 -0700 | [diff] [blame] | 157 | * disable it. Currently all permissions are required. |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 158 | */ |
| 159 | public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0; |
| 160 | |
| 161 | /** |
| 162 | * Flag for {@link #requestedPermissionsFlags}: the requested permission |
| 163 | * is currently granted to the application. |
| 164 | */ |
| 165 | public static final int REQUESTED_PERMISSION_GRANTED = 1<<1; |
| 166 | |
| 167 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | * Array of all signatures read from the package file. This is only filled |
| 169 | * in if the flag {@link PackageManager#GET_SIGNATURES} was set. |
| 170 | */ |
| 171 | public Signature[] signatures; |
| 172 | |
| 173 | /** |
| 174 | * Application specified preferred configuration |
| 175 | * {@link android.R.styleable#AndroidManifestUsesConfiguration |
| 176 | * <uses-configuration>} tags included under <manifest>, |
| 177 | * or null if there were none. This is only filled in if the flag |
| 178 | * {@link PackageManager#GET_CONFIGURATIONS} was set. |
| 179 | */ |
| 180 | public ConfigurationInfo[] configPreferences; |
| 181 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 182 | /** |
| 183 | * The features that this application has said it requires. |
| 184 | */ |
| 185 | public FeatureInfo[] reqFeatures; |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Constant corresponding to <code>auto</code> in |
| 189 | * the {@link android.R.attr#installLocation} attribute. |
| 190 | * @hide |
| 191 | */ |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 192 | public static final int INSTALL_LOCATION_UNSPECIFIED = -1; |
| 193 | /** |
| 194 | * Constant corresponding to <code>auto</code> in |
| 195 | * the {@link android.R.attr#installLocation} attribute. |
| 196 | * @hide |
| 197 | */ |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 198 | public static final int INSTALL_LOCATION_AUTO = 0; |
| 199 | /** |
| 200 | * Constant corresponding to <code>internalOnly</code> in |
| 201 | * the {@link android.R.attr#installLocation} attribute. |
| 202 | * @hide |
| 203 | */ |
| 204 | public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1; |
| 205 | /** |
| 206 | * Constant corresponding to <code>preferExternal</code> in |
| 207 | * the {@link android.R.attr#installLocation} attribute. |
| 208 | * @hide |
| 209 | */ |
| 210 | public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2; |
| 211 | /** |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 212 | * The install location requested by the activity. From the |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 213 | * {@link android.R.attr#installLocation} attribute, one of |
| 214 | * {@link #INSTALL_LOCATION_AUTO}, |
| 215 | * {@link #INSTALL_LOCATION_INTERNAL_ONLY}, |
| 216 | * {@link #INSTALL_LOCATION_PREFER_EXTERNAL} |
| 217 | * @hide |
| 218 | */ |
| 219 | public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 220 | |
| 221 | /** @hide */ |
| 222 | public boolean requiredForAllUsers; |
| 223 | |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame^] | 224 | /** @hide */ |
| 225 | public String restrictedAccountType; |
| 226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | public PackageInfo() { |
| 228 | } |
| 229 | |
| 230 | public String toString() { |
| 231 | return "PackageInfo{" |
| 232 | + Integer.toHexString(System.identityHashCode(this)) |
| 233 | + " " + packageName + "}"; |
| 234 | } |
| 235 | |
| 236 | public int describeContents() { |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 241 | dest.writeString(packageName); |
| 242 | dest.writeInt(versionCode); |
| 243 | dest.writeString(versionName); |
| 244 | dest.writeString(sharedUserId); |
| 245 | dest.writeInt(sharedUserLabel); |
| 246 | if (applicationInfo != null) { |
| 247 | dest.writeInt(1); |
| 248 | applicationInfo.writeToParcel(dest, parcelableFlags); |
| 249 | } else { |
| 250 | dest.writeInt(0); |
| 251 | } |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 252 | dest.writeLong(firstInstallTime); |
| 253 | dest.writeLong(lastUpdateTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | dest.writeIntArray(gids); |
| 255 | dest.writeTypedArray(activities, parcelableFlags); |
| 256 | dest.writeTypedArray(receivers, parcelableFlags); |
| 257 | dest.writeTypedArray(services, parcelableFlags); |
| 258 | dest.writeTypedArray(providers, parcelableFlags); |
| 259 | dest.writeTypedArray(instrumentation, parcelableFlags); |
| 260 | dest.writeTypedArray(permissions, parcelableFlags); |
| 261 | dest.writeStringArray(requestedPermissions); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 262 | dest.writeIntArray(requestedPermissionsFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | dest.writeTypedArray(signatures, parcelableFlags); |
| 264 | dest.writeTypedArray(configPreferences, parcelableFlags); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 265 | dest.writeTypedArray(reqFeatures, parcelableFlags); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 266 | dest.writeInt(installLocation); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 267 | dest.writeInt(requiredForAllUsers ? 1 : 0); |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame^] | 268 | dest.writeString(restrictedAccountType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | public static final Parcelable.Creator<PackageInfo> CREATOR |
| 272 | = new Parcelable.Creator<PackageInfo>() { |
| 273 | public PackageInfo createFromParcel(Parcel source) { |
| 274 | return new PackageInfo(source); |
| 275 | } |
| 276 | |
| 277 | public PackageInfo[] newArray(int size) { |
| 278 | return new PackageInfo[size]; |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | private PackageInfo(Parcel source) { |
| 283 | packageName = source.readString(); |
| 284 | versionCode = source.readInt(); |
| 285 | versionName = source.readString(); |
| 286 | sharedUserId = source.readString(); |
| 287 | sharedUserLabel = source.readInt(); |
| 288 | int hasApp = source.readInt(); |
| 289 | if (hasApp != 0) { |
| 290 | applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); |
| 291 | } |
Dianne Hackborn | 78d688369 | 2010-10-07 01:12:46 -0700 | [diff] [blame] | 292 | firstInstallTime = source.readLong(); |
| 293 | lastUpdateTime = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | gids = source.createIntArray(); |
| 295 | activities = source.createTypedArray(ActivityInfo.CREATOR); |
| 296 | receivers = source.createTypedArray(ActivityInfo.CREATOR); |
| 297 | services = source.createTypedArray(ServiceInfo.CREATOR); |
| 298 | providers = source.createTypedArray(ProviderInfo.CREATOR); |
| 299 | instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR); |
| 300 | permissions = source.createTypedArray(PermissionInfo.CREATOR); |
| 301 | requestedPermissions = source.createStringArray(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 302 | requestedPermissionsFlags = source.createIntArray(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | signatures = source.createTypedArray(Signature.CREATOR); |
| 304 | configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 305 | reqFeatures = source.createTypedArray(FeatureInfo.CREATOR); |
Suchi Amalapurapu | 117818e | 2010-02-09 03:45:40 -0800 | [diff] [blame] | 306 | installLocation = source.readInt(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 307 | requiredForAllUsers = source.readInt() != 0; |
Amith Yamasani | 0ac1fc9 | 2013-03-27 18:56:08 -0700 | [diff] [blame^] | 308 | restrictedAccountType = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
| 310 | } |