| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.annotation.SystemApi; |
| 21 |
import android.app.slice.Slice; |
| 22 |
import android.content.ComponentName; |
| 23 |
import android.content.Context; |
| 24 |
import android.content.pm.ApplicationInfo; |
| 25 |
import android.content.pm.PackageManager; |
| 26 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 27 |
import android.content.pm.ResolveInfo; |
| 28 |
import android.content.pm.ServiceInfo; |
| 29 |
import android.content.res.Resources; |
| 30 |
import android.content.res.Resources.NotFoundException; |
| 31 |
import android.content.res.TypedArray; |
| 32 |
import android.content.res.XmlResourceParser; |
| 33 |
import android.graphics.drawable.Drawable; |
| 34 |
import android.net.Uri; |
| 35 |
import android.os.Parcel; |
| 36 |
import android.os.Parcelable; |
| 37 |
import android.service.wallpaper.WallpaperService; |
| 38 |
import android.util.AttributeSet; |
| 39 |
import android.util.Printer; |
| 40 |
import android.util.Xml; |
| 41 |
import android.view.SurfaceHolder; |
| 42 |
|
| 43 |
import org.xmlpull.v1.XmlPullParser; |
| 44 |
import org.xmlpull.v1.XmlPullParserException; |
| 45 |
|
| 46 |
import java.io.IOException; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public final class WallpaperInfo implements Parcelable { |
| 52 |
static final String TAG = "WallpaperInfo"; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
final ResolveInfo mService; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
final String mSettingsActivityName; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
final int mThumbnailResource; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
final int mAuthorResource; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
final int mDescriptionResource; |
| 79 |
|
| 80 |
final int mContextUriResource; |
| 81 |
final int mContextDescriptionResource; |
| 82 |
final boolean mShowMetadataInPreview; |
| 83 |
final boolean mSupportsAmbientMode; |
| 84 |
final boolean mShouldUseDefaultUnfoldTransition; |
| 85 |
final String mSettingsSliceUri; |
| 86 |
final boolean mSupportMultipleDisplays; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public WallpaperInfo(Context context, ResolveInfo service) |
| 96 |
throws XmlPullParserException, IOException { |
| 97 |
mService = service; |
| 98 |
ServiceInfo si = service.serviceInfo; |
| 99 |
|
| 100 |
final PackageManager pm = context.getPackageManager(); |
| 101 |
XmlResourceParser parser = null; |
| 102 |
try { |
| 103 |
parser = si.loadXmlMetaData(pm, WallpaperService.SERVICE_META_DATA); |
| 104 |
if (parser == null) { |
| 105 |
throw new XmlPullParserException("No " |
| 106 |
+ WallpaperService.SERVICE_META_DATA + " meta-data"); |
| 107 |
} |
| 108 |
|
| 109 |
Resources res = pm.getResourcesForApplication(si.applicationInfo); |
| 110 |
|
| 111 |
AttributeSet attrs = Xml.asAttributeSet(parser); |
| 112 |
|
| 113 |
int type; |
| 114 |
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 115 |
&& type != XmlPullParser.START_TAG) { |
| 116 |
} |
| 117 |
|
| 118 |
String nodeName = parser.getName(); |
| 119 |
if (!"wallpaper".equals(nodeName)) { |
| 120 |
throw new XmlPullParserException( |
| 121 |
"Meta-data does not start with wallpaper tag"); |
| 122 |
} |
| 123 |
|
| 124 |
TypedArray sa = res.obtainAttributes(attrs, |
| 125 |
com.android.internal.R.styleable.Wallpaper); |
| 126 |
mSettingsActivityName = sa.getString( |
| 127 |
com.android.internal.R.styleable.Wallpaper_settingsActivity); |
| 128 |
mThumbnailResource = sa.getResourceId( |
| 129 |
com.android.internal.R.styleable.Wallpaper_thumbnail, |
| 130 |
-1); |
| 131 |
mAuthorResource = sa.getResourceId( |
| 132 |
com.android.internal.R.styleable.Wallpaper_author, |
| 133 |
-1); |
| 134 |
mDescriptionResource = sa.getResourceId( |
| 135 |
com.android.internal.R.styleable.Wallpaper_description, |
| 136 |
-1); |
| 137 |
mContextUriResource = sa.getResourceId( |
| 138 |
com.android.internal.R.styleable.Wallpaper_contextUri, |
| 139 |
-1); |
| 140 |
mContextDescriptionResource = sa.getResourceId( |
| 141 |
com.android.internal.R.styleable.Wallpaper_contextDescription, |
| 142 |
-1); |
| 143 |
mShowMetadataInPreview = sa.getBoolean( |
| 144 |
com.android.internal.R.styleable.Wallpaper_showMetadataInPreview, |
| 145 |
false); |
| 146 |
mSupportsAmbientMode = sa.getBoolean( |
| 147 |
com.android.internal.R.styleable.Wallpaper_supportsAmbientMode, |
| 148 |
false); |
| 149 |
mShouldUseDefaultUnfoldTransition = sa.getBoolean( |
| 150 |
com.android.internal.R.styleable |
| 151 |
.Wallpaper_shouldUseDefaultUnfoldTransition, true); |
| 152 |
mSettingsSliceUri = sa.getString( |
| 153 |
com.android.internal.R.styleable.Wallpaper_settingsSliceUri); |
| 154 |
mSupportMultipleDisplays = sa.getBoolean( |
| 155 |
com.android.internal.R.styleable.Wallpaper_supportsMultipleDisplays, |
| 156 |
false); |
| 157 |
|
| 158 |
sa.recycle(); |
| 159 |
} catch (NameNotFoundException e) { |
| 160 |
throw new XmlPullParserException( |
| 161 |
"Unable to create context for: " + si.packageName); |
| 162 |
} finally { |
| 163 |
if (parser != null) parser.close(); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
WallpaperInfo(Parcel source) { |
| 168 |
mSettingsActivityName = source.readString(); |
| 169 |
mThumbnailResource = source.readInt(); |
| 170 |
mAuthorResource = source.readInt(); |
| 171 |
mDescriptionResource = source.readInt(); |
| 172 |
mContextUriResource = source.readInt(); |
| 173 |
mContextDescriptionResource = source.readInt(); |
| 174 |
mShowMetadataInPreview = source.readInt() != 0; |
| 175 |
mSupportsAmbientMode = source.readInt() != 0; |
| 176 |
mSettingsSliceUri = source.readString(); |
| 177 |
mSupportMultipleDisplays = source.readInt() != 0; |
| 178 |
mShouldUseDefaultUnfoldTransition = source.readInt() != 0; |
| 179 |
mService = ResolveInfo.CREATOR.createFromParcel(source); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public String getPackageName() { |
| 186 |
return mService.serviceInfo.packageName; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
public String getServiceName() { |
| 194 |
return mService.serviceInfo.name; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public ServiceInfo getServiceInfo() { |
| 202 |
return mService.serviceInfo; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public ComponentName getComponent() { |
| 209 |
return new ComponentName(mService.serviceInfo.packageName, |
| 210 |
mService.serviceInfo.name); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public CharSequence loadLabel(PackageManager pm) { |
| 220 |
return mService.loadLabel(pm); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public Drawable loadIcon(PackageManager pm) { |
| 230 |
return mService.loadIcon(pm); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public Drawable loadThumbnail(PackageManager pm) { |
| 240 |
if (mThumbnailResource < 0) return null; |
| 241 |
|
| 242 |
return pm.getDrawable(mService.serviceInfo.packageName, |
| 243 |
mThumbnailResource, |
| 244 |
mService.serviceInfo.applicationInfo); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public CharSequence loadAuthor(PackageManager pm) throws NotFoundException { |
| 251 |
if (mAuthorResource <= 0) throw new NotFoundException(); |
| 252 |
String packageName = mService.resolvePackageName; |
| 253 |
ApplicationInfo applicationInfo = null; |
| 254 |
if (packageName == null) { |
| 255 |
packageName = mService.serviceInfo.packageName; |
| 256 |
applicationInfo = mService.serviceInfo.applicationInfo; |
| 257 |
} |
| 258 |
return pm.getText(packageName, mAuthorResource, applicationInfo); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public CharSequence loadDescription(PackageManager pm) throws NotFoundException { |
| 265 |
String packageName = mService.resolvePackageName; |
| 266 |
ApplicationInfo applicationInfo = null; |
| 267 |
if (packageName == null) { |
| 268 |
packageName = mService.serviceInfo.packageName; |
| 269 |
applicationInfo = mService.serviceInfo.applicationInfo; |
| 270 |
} |
| 271 |
if (mService.serviceInfo.descriptionRes != 0) { |
| 272 |
return pm.getText(packageName, mService.serviceInfo.descriptionRes, |
| 273 |
applicationInfo); |
| 274 |
|
| 275 |
} |
| 276 |
if (mDescriptionResource <= 0) throw new NotFoundException(); |
| 277 |
return pm.getText(packageName, mDescriptionResource, |
| 278 |
mService.serviceInfo.applicationInfo); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
public Uri loadContextUri(PackageManager pm) throws NotFoundException { |
| 288 |
if (mContextUriResource <= 0) throw new NotFoundException(); |
| 289 |
String packageName = mService.resolvePackageName; |
| 290 |
ApplicationInfo applicationInfo = null; |
| 291 |
if (packageName == null) { |
| 292 |
packageName = mService.serviceInfo.packageName; |
| 293 |
applicationInfo = mService.serviceInfo.applicationInfo; |
| 294 |
} |
| 295 |
String contextUriString = pm.getText( |
| 296 |
packageName, mContextUriResource, applicationInfo).toString(); |
| 297 |
if (contextUriString == null) { |
| 298 |
return null; |
| 299 |
} |
| 300 |
return Uri.parse(contextUriString); |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public CharSequence loadContextDescription(PackageManager pm) throws NotFoundException { |
| 310 |
if (mContextDescriptionResource <= 0) throw new NotFoundException(); |
| 311 |
String packageName = mService.resolvePackageName; |
| 312 |
ApplicationInfo applicationInfo = null; |
| 313 |
if (packageName == null) { |
| 314 |
packageName = mService.serviceInfo.packageName; |
| 315 |
applicationInfo = mService.serviceInfo.applicationInfo; |
| 316 |
} |
| 317 |
return pm.getText(packageName, mContextDescriptionResource, applicationInfo).toString(); |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
public boolean getShowMetadataInPreview() { |
| 331 |
return mShowMetadataInPreview; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
@SystemApi |
| 343 |
public boolean supportsAmbientMode() { |
| 344 |
return mSupportsAmbientMode; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
public String getSettingsActivity() { |
| 358 |
return mSettingsActivityName; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
@Nullable |
| 374 |
public Uri getSettingsSliceUri() { |
| 375 |
if (mSettingsSliceUri == null) { |
| 376 |
return null; |
| 377 |
} |
| 378 |
return Uri.parse(mSettingsSliceUri); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
public boolean supportsMultipleDisplays() { |
| 398 |
return mSupportMultipleDisplays; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public boolean shouldUseDefaultUnfoldTransition() { |
| 420 |
return mShouldUseDefaultUnfoldTransition; |
| 421 |
} |
| 422 |
|
| 423 |
public void dump(Printer pw, String prefix) { |
| 424 |
pw.println(prefix + "Service:"); |
| 425 |
mService.dump(pw, prefix + " "); |
| 426 |
pw.println(prefix + "mSettingsActivityName=" + mSettingsActivityName); |
| 427 |
} |
| 428 |
|
| 429 |
@Override |
| 430 |
public String toString() { |
| 431 |
return "WallpaperInfo{" + mService.serviceInfo.name |
| 432 |
+ ", settings: " |
| 433 |
+ mSettingsActivityName + "}"; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public void writeToParcel(Parcel dest, int flags) { |
| 443 |
dest.writeString(mSettingsActivityName); |
| 444 |
dest.writeInt(mThumbnailResource); |
| 445 |
dest.writeInt(mAuthorResource); |
| 446 |
dest.writeInt(mDescriptionResource); |
| 447 |
dest.writeInt(mContextUriResource); |
| 448 |
dest.writeInt(mContextDescriptionResource); |
| 449 |
dest.writeInt(mShowMetadataInPreview ? 1 : 0); |
| 450 |
dest.writeInt(mSupportsAmbientMode ? 1 : 0); |
| 451 |
dest.writeString(mSettingsSliceUri); |
| 452 |
dest.writeInt(mSupportMultipleDisplays ? 1 : 0); |
| 453 |
dest.writeInt(mShouldUseDefaultUnfoldTransition ? 1 : 0); |
| 454 |
mService.writeToParcel(dest, flags); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public static final @android.annotation.NonNull Parcelable.Creator<WallpaperInfo> CREATOR = new Parcelable.Creator<WallpaperInfo>() { |
| 461 |
public WallpaperInfo createFromParcel(Parcel source) { |
| 462 |
return new WallpaperInfo(source); |
| 463 |
} |
| 464 |
|
| 465 |
public WallpaperInfo[] newArray(int size) { |
| 466 |
return new WallpaperInfo[size]; |
| 467 |
} |
| 468 |
}; |
| 469 |
|
| 470 |
public int describeContents() { |
| 471 |
return 0; |
| 472 |
} |
| 473 |
} |