| 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.FloatRange; |
| 20 |
import android.annotation.IntDef; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.annotation.RawRes; |
| 24 |
import android.annotation.RequiresPermission; |
| 25 |
import android.annotation.SdkConstant; |
| 26 |
import android.annotation.SdkConstant.SdkConstantType; |
| 27 |
import android.annotation.SystemApi; |
| 28 |
import android.annotation.SystemService; |
| 29 |
import android.annotation.TestApi; |
| 30 |
import android.annotation.UiContext; |
| 31 |
import android.compat.annotation.UnsupportedAppUsage; |
| 32 |
import android.content.ComponentName; |
| 33 |
import android.content.ContentResolver; |
| 34 |
import android.content.Context; |
| 35 |
import android.content.Intent; |
| 36 |
import android.content.pm.PackageManager; |
| 37 |
import android.content.pm.ResolveInfo; |
| 38 |
import android.content.res.Configuration; |
| 39 |
import android.content.res.Resources; |
| 40 |
import android.content.res.Resources.NotFoundException; |
| 41 |
import android.graphics.Bitmap; |
| 42 |
import android.graphics.BitmapFactory; |
| 43 |
import android.graphics.BitmapRegionDecoder; |
| 44 |
import android.graphics.Canvas; |
| 45 |
import android.graphics.ColorFilter; |
| 46 |
import android.graphics.ColorSpace; |
| 47 |
import android.graphics.ImageDecoder; |
| 48 |
import android.graphics.Matrix; |
| 49 |
import android.graphics.Paint; |
| 50 |
import android.graphics.PixelFormat; |
| 51 |
import android.graphics.PorterDuff; |
| 52 |
import android.graphics.PorterDuffXfermode; |
| 53 |
import android.graphics.Rect; |
| 54 |
import android.graphics.RectF; |
| 55 |
import android.graphics.drawable.BitmapDrawable; |
| 56 |
import android.graphics.drawable.Drawable; |
| 57 |
import android.net.Uri; |
| 58 |
import android.os.Build; |
| 59 |
import android.os.Bundle; |
| 60 |
import android.os.DeadSystemException; |
| 61 |
import android.os.Environment; |
| 62 |
import android.os.FileUtils; |
| 63 |
import android.os.Handler; |
| 64 |
import android.os.IBinder; |
| 65 |
import android.os.Looper; |
| 66 |
import android.os.ParcelFileDescriptor; |
| 67 |
import android.os.RemoteException; |
| 68 |
import android.os.StrictMode; |
| 69 |
import android.os.SystemProperties; |
| 70 |
import android.text.TextUtils; |
| 71 |
import android.util.ArrayMap; |
| 72 |
import android.util.ArraySet; |
| 73 |
import android.util.Log; |
| 74 |
import android.util.MathUtils; |
| 75 |
import android.util.Pair; |
| 76 |
import android.view.Display; |
| 77 |
import android.view.WindowManagerGlobal; |
| 78 |
|
| 79 |
import com.android.internal.R; |
| 80 |
|
| 81 |
import libcore.io.IoUtils; |
| 82 |
|
| 83 |
import java.io.BufferedInputStream; |
| 84 |
import java.io.ByteArrayOutputStream; |
| 85 |
import java.io.File; |
| 86 |
import java.io.FileInputStream; |
| 87 |
import java.io.FileOutputStream; |
| 88 |
import java.io.IOException; |
| 89 |
import java.io.InputStream; |
| 90 |
import java.lang.annotation.Retention; |
| 91 |
import java.lang.annotation.RetentionPolicy; |
| 92 |
import java.util.ArrayList; |
| 93 |
import java.util.Arrays; |
| 94 |
import java.util.HashSet; |
| 95 |
import java.util.List; |
| 96 |
import java.util.Set; |
| 97 |
import java.util.concurrent.CountDownLatch; |
| 98 |
import java.util.concurrent.TimeUnit; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
@SystemService(Context.WALLPAPER_SERVICE) |
| 110 |
public class WallpaperManager { |
| 111 |
private static String TAG = "WallpaperManager"; |
| 112 |
private static final boolean DEBUG = false; |
| 113 |
private float mWallpaperXStep = -1; |
| 114 |
private float mWallpaperYStep = -1; |
| 115 |
private static final @NonNull RectF LOCAL_COLOR_BOUNDS = |
| 116 |
new RectF(0, 0, 1, 1); |
| 117 |
|
| 118 |
|
| 119 |
private static final String PROP_WALLPAPER = "ro.config.wallpaper"; |
| 120 |
|
| 121 |
private static final String PROP_LOCK_WALLPAPER = "ro.config.lock_wallpaper"; |
| 122 |
|
| 123 |
private static final String PROP_WALLPAPER_COMPONENT = "ro.config.wallpaper_component"; |
| 124 |
|
| 125 |
private static final String VALUE_CMF_COLOR = |
| 126 |
android.os.SystemProperties.get("ro.boot.hardware.color"); |
| 127 |
|
| 128 |
private static final String WALLPAPER_CMF_PATH = "/wallpaper/image/"; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 138 |
public static final String ACTION_CROP_AND_SET_WALLPAPER = |
| 139 |
"android.service.wallpaper.CROP_AND_SET_WALLPAPER"; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public static final String ACTION_LIVE_WALLPAPER_CHOOSER |
| 146 |
= "android.service.wallpaper.LIVE_WALLPAPER_CHOOSER"; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public static final String ACTION_CHANGE_LIVE_WALLPAPER |
| 155 |
= "android.service.wallpaper.CHANGE_LIVE_WALLPAPER"; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public static final String EXTRA_LIVE_WALLPAPER_COMPONENT |
| 163 |
= "android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT"; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public static final String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview"; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public static final String COMMAND_TAP = "android.wallpaper.tap"; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public static final String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap"; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public static final String COMMAND_DROP = "android.home.drop"; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public static final String COMMAND_WAKING_UP = "android.wallpaper.wakingup"; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public static final String COMMAND_GOING_TO_SLEEP = "android.wallpaper.goingtosleep"; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public static final String COMMAND_REAPPLY = "android.wallpaper.reapply"; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public static final String COMMAND_FREEZE = "android.wallpaper.freeze"; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public static final String COMMAND_UNFREEZE = "android.wallpaper.unfreeze"; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
public static final String EXTRA_NEW_WALLPAPER_ID = "android.service.wallpaper.extra.ID"; |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public static final String EXTRA_FROM_FOREGROUND_APP = |
| 251 |
"android.service.wallpaper.extra.FROM_FOREGROUND_APP"; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 257 |
FLAG_SYSTEM, |
| 258 |
FLAG_LOCK |
| 259 |
}) |
| 260 |
@Retention(RetentionPolicy.SOURCE) |
| 261 |
public @interface SetWallpaperFlags {} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
public static final int FLAG_SYSTEM = 1 << 0; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public static final int FLAG_LOCK = 1 << 1; |
| 272 |
|
| 273 |
private static final Object sSync = new Object[0]; |
| 274 |
@UnsupportedAppUsage |
| 275 |
private static Globals sGlobals; |
| 276 |
private final Context mContext; |
| 277 |
private final boolean mWcgEnabled; |
| 278 |
private final ColorManagementProxy mCmProxy; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
static class FastBitmapDrawable extends Drawable { |
| 286 |
private final Bitmap mBitmap; |
| 287 |
private final int mWidth; |
| 288 |
private final int mHeight; |
| 289 |
private int mDrawLeft; |
| 290 |
private int mDrawTop; |
| 291 |
private final Paint mPaint; |
| 292 |
|
| 293 |
private FastBitmapDrawable(Bitmap bitmap) { |
| 294 |
mBitmap = bitmap; |
| 295 |
mWidth = bitmap.getWidth(); |
| 296 |
mHeight = bitmap.getHeight(); |
| 297 |
|
| 298 |
setBounds(0, 0, mWidth, mHeight); |
| 299 |
|
| 300 |
mPaint = new Paint(); |
| 301 |
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); |
| 302 |
} |
| 303 |
|
| 304 |
@Override |
| 305 |
public void draw(Canvas canvas) { |
| 306 |
canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, mPaint); |
| 307 |
} |
| 308 |
|
| 309 |
@Override |
| 310 |
public int getOpacity() { |
| 311 |
return PixelFormat.OPAQUE; |
| 312 |
} |
| 313 |
|
| 314 |
@Override |
| 315 |
public void setBounds(int left, int top, int right, int bottom) { |
| 316 |
mDrawLeft = left + (right-left - mWidth) / 2; |
| 317 |
mDrawTop = top + (bottom-top - mHeight) / 2; |
| 318 |
} |
| 319 |
|
| 320 |
@Override |
| 321 |
public void setAlpha(int alpha) { |
| 322 |
throw new UnsupportedOperationException("Not supported with this drawable"); |
| 323 |
} |
| 324 |
|
| 325 |
@Override |
| 326 |
public void setColorFilter(ColorFilter colorFilter) { |
| 327 |
throw new UnsupportedOperationException("Not supported with this drawable"); |
| 328 |
} |
| 329 |
|
| 330 |
@Override |
| 331 |
public void setDither(boolean dither) { |
| 332 |
throw new UnsupportedOperationException("Not supported with this drawable"); |
| 333 |
} |
| 334 |
|
| 335 |
@Override |
| 336 |
public void setFilterBitmap(boolean filter) { |
| 337 |
throw new UnsupportedOperationException("Not supported with this drawable"); |
| 338 |
} |
| 339 |
|
| 340 |
@Override |
| 341 |
public int getIntrinsicWidth() { |
| 342 |
return mWidth; |
| 343 |
} |
| 344 |
|
| 345 |
@Override |
| 346 |
public int getIntrinsicHeight() { |
| 347 |
return mHeight; |
| 348 |
} |
| 349 |
|
| 350 |
@Override |
| 351 |
public int getMinimumWidth() { |
| 352 |
return mWidth; |
| 353 |
} |
| 354 |
|
| 355 |
@Override |
| 356 |
public int getMinimumHeight() { |
| 357 |
return mHeight; |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
private static class Globals extends IWallpaperManagerCallback.Stub { |
| 362 |
private final IWallpaperManager mService; |
| 363 |
private boolean mColorCallbackRegistered; |
| 364 |
private final ArrayList<Pair<OnColorsChangedListener, Handler>> mColorListeners = |
| 365 |
new ArrayList<>(); |
| 366 |
private Bitmap mCachedWallpaper; |
| 367 |
private int mCachedWallpaperUserId; |
| 368 |
private Bitmap mDefaultWallpaper; |
| 369 |
private Handler mMainLooperHandler; |
| 370 |
private ArrayMap<LocalWallpaperColorConsumer, ArraySet<RectF>> mLocalColorCallbackAreas = |
| 371 |
new ArrayMap<>(); |
| 372 |
private ILocalWallpaperColorConsumer mLocalColorCallback = |
| 373 |
new ILocalWallpaperColorConsumer.Stub() { |
| 374 |
@Override |
| 375 |
public void onColorsChanged(RectF area, WallpaperColors colors) { |
| 376 |
for (LocalWallpaperColorConsumer callback : |
| 377 |
mLocalColorCallbackAreas.keySet()) { |
| 378 |
ArraySet<RectF> areas = mLocalColorCallbackAreas.get(callback); |
| 379 |
if (areas != null && areas.contains(area)) { |
| 380 |
callback.onColorsChanged(area, colors); |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
}; |
| 385 |
|
| 386 |
Globals(IWallpaperManager service, Looper looper) { |
| 387 |
mService = service; |
| 388 |
mMainLooperHandler = new Handler(looper); |
| 389 |
forgetLoadedWallpaper(); |
| 390 |
} |
| 391 |
|
| 392 |
public void onWallpaperChanged() { |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
forgetLoadedWallpaper(); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
public void addOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
| 411 |
@Nullable Handler handler, int userId, int displayId) { |
| 412 |
synchronized (this) { |
| 413 |
if (!mColorCallbackRegistered) { |
| 414 |
try { |
| 415 |
mService.registerWallpaperColorsCallback(this, userId, displayId); |
| 416 |
mColorCallbackRegistered = true; |
| 417 |
} catch (RemoteException e) { |
| 418 |
|
| 419 |
Log.w(TAG, "Can't register for color updates", e); |
| 420 |
} |
| 421 |
} |
| 422 |
mColorListeners.add(new Pair<>(callback, handler)); |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
public void addOnColorsChangedListener( |
| 427 |
@NonNull LocalWallpaperColorConsumer callback, |
| 428 |
@NonNull List<RectF> regions, int which, int userId, int displayId) { |
| 429 |
synchronized (this) { |
| 430 |
for (RectF area : regions) { |
| 431 |
ArraySet<RectF> areas = mLocalColorCallbackAreas.get(callback); |
| 432 |
if (areas == null) { |
| 433 |
areas = new ArraySet<>(); |
| 434 |
mLocalColorCallbackAreas.put(callback, areas); |
| 435 |
} |
| 436 |
areas.add(area); |
| 437 |
} |
| 438 |
try { |
| 439 |
|
| 440 |
mService.addOnLocalColorsChangedListener(mLocalColorCallback, regions, which, |
| 441 |
userId, displayId); |
| 442 |
} catch (RemoteException e) { |
| 443 |
|
| 444 |
Log.e(TAG, "Can't register for local color updates", e); |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
public void removeOnColorsChangedListener( |
| 450 |
@NonNull LocalWallpaperColorConsumer callback, int which, int userId, |
| 451 |
int displayId) { |
| 452 |
synchronized (this) { |
| 453 |
final ArraySet<RectF> removeAreas = mLocalColorCallbackAreas.remove(callback); |
| 454 |
if (removeAreas == null || removeAreas.size() == 0) { |
| 455 |
return; |
| 456 |
} |
| 457 |
for (LocalWallpaperColorConsumer cb : mLocalColorCallbackAreas.keySet()) { |
| 458 |
ArraySet<RectF> areas = mLocalColorCallbackAreas.get(cb); |
| 459 |
if (areas != null && cb != callback) removeAreas.removeAll(areas); |
| 460 |
} |
| 461 |
try { |
| 462 |
if (removeAreas.size() > 0) { |
| 463 |
|
| 464 |
mService.removeOnLocalColorsChangedListener( |
| 465 |
mLocalColorCallback, new ArrayList(removeAreas), which, userId, |
| 466 |
displayId); |
| 467 |
} |
| 468 |
} catch (RemoteException e) { |
| 469 |
|
| 470 |
Log.e(TAG, "Can't unregister for local color updates", e); |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
| 483 |
int userId, int displayId) { |
| 484 |
synchronized (this) { |
| 485 |
mColorListeners.removeIf(pair -> pair.first == callback); |
| 486 |
|
| 487 |
if (mColorListeners.size() == 0 && mColorCallbackRegistered) { |
| 488 |
mColorCallbackRegistered = false; |
| 489 |
try { |
| 490 |
mService.unregisterWallpaperColorsCallback(this, userId, displayId); |
| 491 |
} catch (RemoteException e) { |
| 492 |
|
| 493 |
Log.w(TAG, "Can't unregister color updates", e); |
| 494 |
} |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
@Override |
| 500 |
public void onWallpaperColorsChanged(WallpaperColors colors, int which, int userId) { |
| 501 |
synchronized (this) { |
| 502 |
for (Pair<OnColorsChangedListener, Handler> listener : mColorListeners) { |
| 503 |
Handler handler = listener.second; |
| 504 |
if (listener.second == null) { |
| 505 |
handler = mMainLooperHandler; |
| 506 |
} |
| 507 |
handler.post(() -> { |
| 508 |
|
| 509 |
|
| 510 |
boolean stillExists; |
| 511 |
synchronized (sGlobals) { |
| 512 |
stillExists = mColorListeners.contains(listener); |
| 513 |
} |
| 514 |
if (stillExists) { |
| 515 |
listener.first.onColorsChanged(colors, which, userId); |
| 516 |
} |
| 517 |
}); |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
WallpaperColors getWallpaperColors(int which, int userId, int displayId) { |
| 523 |
if (which != FLAG_LOCK && which != FLAG_SYSTEM) { |
| 524 |
throw new IllegalArgumentException( |
| 525 |
"Must request colors for exactly one kind of wallpaper"); |
| 526 |
} |
| 527 |
|
| 528 |
try { |
| 529 |
return mService.getWallpaperColors(which, userId, displayId); |
| 530 |
} catch (RemoteException e) { |
| 531 |
|
| 532 |
} |
| 533 |
return null; |
| 534 |
} |
| 535 |
|
| 536 |
public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault, |
| 537 |
@SetWallpaperFlags int which, ColorManagementProxy cmProxy) { |
| 538 |
return peekWallpaperBitmap(context, returnDefault, which, context.getUserId(), |
| 539 |
false , cmProxy); |
| 540 |
} |
| 541 |
|
| 542 |
public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault, |
| 543 |
@SetWallpaperFlags int which, int userId, boolean hardware, |
| 544 |
ColorManagementProxy cmProxy) { |
| 545 |
if (mService != null) { |
| 546 |
try { |
| 547 |
if (!mService.isWallpaperSupported(context.getOpPackageName())) { |
| 548 |
return null; |
| 549 |
} |
| 550 |
} catch (RemoteException e) { |
| 551 |
throw e.rethrowFromSystemServer(); |
| 552 |
} |
| 553 |
} |
| 554 |
synchronized (this) { |
| 555 |
if (mCachedWallpaper != null && mCachedWallpaperUserId == userId |
| 556 |
&& !mCachedWallpaper.isRecycled()) { |
| 557 |
return mCachedWallpaper; |
| 558 |
} |
| 559 |
mCachedWallpaper = null; |
| 560 |
mCachedWallpaperUserId = 0; |
| 561 |
} |
| 562 |
try { |
| 563 |
Bitmap currentWallpaper = getCurrentWallpaperLocked( |
| 564 |
context, userId, hardware, cmProxy); |
| 565 |
if (currentWallpaper != null) { |
| 566 |
synchronized (this) { |
| 567 |
mCachedWallpaper = currentWallpaper; |
| 568 |
mCachedWallpaperUserId = userId; |
| 569 |
return mCachedWallpaper; |
| 570 |
} |
| 571 |
} |
| 572 |
} catch (OutOfMemoryError e) { |
| 573 |
Log.w(TAG, "Out of memory loading the current wallpaper: " + e); |
| 574 |
} catch (SecurityException e) { |
| 575 |
if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) { |
| 576 |
Log.w(TAG, "No permission to access wallpaper, suppressing" |
| 577 |
+ " exception to avoid crashing legacy app."); |
| 578 |
} else { |
| 579 |
|
| 580 |
throw e; |
| 581 |
} |
| 582 |
} |
| 583 |
if (returnDefault) { |
| 584 |
Bitmap defaultWallpaper = mDefaultWallpaper; |
| 585 |
if (defaultWallpaper == null || defaultWallpaper.isRecycled()) { |
| 586 |
defaultWallpaper = getDefaultWallpaper(context, which); |
| 587 |
synchronized (this) { |
| 588 |
mDefaultWallpaper = defaultWallpaper; |
| 589 |
} |
| 590 |
} |
| 591 |
return defaultWallpaper; |
| 592 |
} |
| 593 |
return null; |
| 594 |
} |
| 595 |
|
| 596 |
public Rect peekWallpaperDimensions(Context context, boolean returnDefault, int userId) { |
| 597 |
if (mService != null) { |
| 598 |
try { |
| 599 |
if (!mService.isWallpaperSupported(context.getOpPackageName())) { |
| 600 |
return new Rect(); |
| 601 |
} |
| 602 |
} catch (RemoteException e) { |
| 603 |
throw e.rethrowFromSystemServer(); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
Rect dimensions = null; |
| 608 |
synchronized (this) { |
| 609 |
ParcelFileDescriptor pfd = null; |
| 610 |
try { |
| 611 |
Bundle params = new Bundle(); |
| 612 |
pfd = mService.getWallpaperWithFeature(context.getOpPackageName(), |
| 613 |
context.getAttributionTag(), this, FLAG_SYSTEM, params, userId); |
| 614 |
|
| 615 |
if (pfd != null) { |
| 616 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 617 |
options.inJustDecodeBounds = true; |
| 618 |
BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor(), null, options); |
| 619 |
dimensions = new Rect(0, 0, options.outWidth, options.outHeight); |
| 620 |
} |
| 621 |
} catch (RemoteException ex) { |
| 622 |
Log.w(TAG, "peek wallpaper dimensions failed", ex); |
| 623 |
} finally { |
| 624 |
if (pfd != null) { |
| 625 |
try { |
| 626 |
pfd.close(); |
| 627 |
} catch (IOException ignored) { |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
if ((dimensions == null || dimensions.width() == 0 || dimensions.height() == 0) |
| 634 |
&& returnDefault) { |
| 635 |
InputStream is = openDefaultWallpaper(context, FLAG_SYSTEM); |
| 636 |
if (is != null) { |
| 637 |
try { |
| 638 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 639 |
options.inJustDecodeBounds = true; |
| 640 |
BitmapFactory.decodeStream(is, null, options); |
| 641 |
dimensions = new Rect(0, 0, options.outWidth, options.outHeight); |
| 642 |
} finally { |
| 643 |
IoUtils.closeQuietly(is); |
| 644 |
} |
| 645 |
} |
| 646 |
} |
| 647 |
return dimensions; |
| 648 |
} |
| 649 |
|
| 650 |
void forgetLoadedWallpaper() { |
| 651 |
synchronized (this) { |
| 652 |
mCachedWallpaper = null; |
| 653 |
mCachedWallpaperUserId = 0; |
| 654 |
mDefaultWallpaper = null; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
private Bitmap getCurrentWallpaperLocked(Context context, int userId, boolean hardware, |
| 659 |
ColorManagementProxy cmProxy) { |
| 660 |
if (mService == null) { |
| 661 |
Log.w(TAG, "WallpaperService not running"); |
| 662 |
return null; |
| 663 |
} |
| 664 |
|
| 665 |
try { |
| 666 |
Bundle params = new Bundle(); |
| 667 |
ParcelFileDescriptor pfd = mService.getWallpaperWithFeature( |
| 668 |
context.getOpPackageName(), context.getAttributionTag(), this, FLAG_SYSTEM, |
| 669 |
params, userId); |
| 670 |
|
| 671 |
if (pfd != null) { |
| 672 |
try (BufferedInputStream bis = new BufferedInputStream( |
| 673 |
new ParcelFileDescriptor.AutoCloseInputStream(pfd))) { |
| 674 |
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 675 |
int data; |
| 676 |
while ((data = bis.read()) != -1) { |
| 677 |
baos.write(data); |
| 678 |
} |
| 679 |
ImageDecoder.Source src = ImageDecoder.createSource(baos.toByteArray()); |
| 680 |
return ImageDecoder.decodeBitmap(src, ((decoder, info, source) -> { |
| 681 |
|
| 682 |
decoder.setMutableRequired(!hardware); |
| 683 |
|
| 684 |
if (cmProxy != null) { |
| 685 |
cmProxy.doColorManagement(decoder, info); |
| 686 |
} |
| 687 |
})); |
| 688 |
} catch (OutOfMemoryError | IOException e) { |
| 689 |
Log.w(TAG, "Can't decode file", e); |
| 690 |
} |
| 691 |
} |
| 692 |
} catch (RemoteException e) { |
| 693 |
throw e.rethrowFromSystemServer(); |
| 694 |
} |
| 695 |
return null; |
| 696 |
} |
| 697 |
|
| 698 |
private Bitmap getDefaultWallpaper(Context context, @SetWallpaperFlags int which) { |
| 699 |
InputStream is = openDefaultWallpaper(context, which); |
| 700 |
if (is != null) { |
| 701 |
try { |
| 702 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 703 |
return BitmapFactory.decodeStream(is, null, options); |
| 704 |
} catch (OutOfMemoryError e) { |
| 705 |
Log.w(TAG, "Can't decode stream", e); |
| 706 |
} finally { |
| 707 |
IoUtils.closeQuietly(is); |
| 708 |
} |
| 709 |
} |
| 710 |
return null; |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
static void initGlobals(IWallpaperManager service, Looper looper) { |
| 715 |
synchronized (sSync) { |
| 716 |
if (sGlobals == null) { |
| 717 |
sGlobals = new Globals(service, looper); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
WallpaperManager(IWallpaperManager service, @UiContext Context context, |
| 723 |
Handler handler) { |
| 724 |
mContext = context; |
| 725 |
if (service != null) { |
| 726 |
initGlobals(service, context.getMainLooper()); |
| 727 |
} |
| 728 |
|
| 729 |
mWcgEnabled = context.getResources().getConfiguration().isScreenWideColorGamut() |
| 730 |
&& context.getResources().getBoolean(R.bool.config_enableWcgMode); |
| 731 |
mCmProxy = new ColorManagementProxy(context); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
WallpaperManager() { |
| 736 |
mContext = null; |
| 737 |
mCmProxy = null; |
| 738 |
mWcgEnabled = false; |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
public static WallpaperManager getInstance(Context context) { |
| 745 |
return (WallpaperManager)context.getSystemService( |
| 746 |
Context.WALLPAPER_SERVICE); |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
@UnsupportedAppUsage |
| 751 |
public IWallpaperManager getIWallpaperManager() { |
| 752 |
return sGlobals.mService; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
public boolean isLockscreenLiveWallpaperEnabled() { |
| 765 |
return false; |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
@TestApi |
| 782 |
public boolean shouldEnableWideColorGamut() { |
| 783 |
return mWcgEnabled; |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 802 |
@Nullable |
| 803 |
public Drawable getDrawable() { |
| 804 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 805 |
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, cmProxy); |
| 806 |
if (bm != null) { |
| 807 |
Drawable dr = new BitmapDrawable(mContext.getResources(), bm); |
| 808 |
dr.setDither(false); |
| 809 |
return dr; |
| 810 |
} |
| 811 |
return null; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 833 |
@Nullable |
| 834 |
public Drawable getDrawable(@SetWallpaperFlags int which) { |
| 835 |
return getDrawable(); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
public Drawable getBuiltInDrawable() { |
| 841 |
return getBuiltInDrawable(0, 0, false, 0, 0, FLAG_SYSTEM); |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public Drawable getBuiltInDrawable(@SetWallpaperFlags int which) { |
| 853 |
return getBuiltInDrawable(0, 0, false, 0, 0, which); |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
public Drawable getBuiltInDrawable(int outWidth, int outHeight, |
| 871 |
boolean scaleToFit, float horizontalAlignment, float verticalAlignment) { |
| 872 |
return getBuiltInDrawable(outWidth, outHeight, scaleToFit, |
| 873 |
horizontalAlignment, verticalAlignment, FLAG_SYSTEM); |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
public Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, |
| 893 |
float horizontalAlignment, float verticalAlignment, @SetWallpaperFlags int which) { |
| 894 |
if (sGlobals.mService == null) { |
| 895 |
Log.w(TAG, "WallpaperService not running"); |
| 896 |
throw new RuntimeException(new DeadSystemException()); |
| 897 |
} |
| 898 |
|
| 899 |
if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
| 900 |
throw new IllegalArgumentException("Must request exactly one kind of wallpaper"); |
| 901 |
} |
| 902 |
|
| 903 |
Resources resources = mContext.getResources(); |
| 904 |
horizontalAlignment = Math.max(0, Math.min(1, horizontalAlignment)); |
| 905 |
verticalAlignment = Math.max(0, Math.min(1, verticalAlignment)); |
| 906 |
|
| 907 |
InputStream wpStream = openDefaultWallpaper(mContext, which); |
| 908 |
if (wpStream == null) { |
| 909 |
if (DEBUG) { |
| 910 |
Log.w(TAG, "default wallpaper stream " + which + " is null"); |
| 911 |
} |
| 912 |
return null; |
| 913 |
} else { |
| 914 |
InputStream is = new BufferedInputStream(wpStream); |
| 915 |
if (outWidth <= 0 || outHeight <= 0) { |
| 916 |
Bitmap fullSize = BitmapFactory.decodeStream(is, null, null); |
| 917 |
return new BitmapDrawable(resources, fullSize); |
| 918 |
} else { |
| 919 |
int inWidth; |
| 920 |
int inHeight; |
| 921 |
|
| 922 |
{ |
| 923 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 924 |
options.inJustDecodeBounds = true; |
| 925 |
BitmapFactory.decodeStream(is, null, options); |
| 926 |
if (options.outWidth != 0 && options.outHeight != 0) { |
| 927 |
inWidth = options.outWidth; |
| 928 |
inHeight = options.outHeight; |
| 929 |
} else { |
| 930 |
Log.e(TAG, "default wallpaper dimensions are 0"); |
| 931 |
return null; |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
is = new BufferedInputStream(openDefaultWallpaper(mContext, which)); |
| 938 |
|
| 939 |
RectF cropRectF; |
| 940 |
|
| 941 |
outWidth = Math.min(inWidth, outWidth); |
| 942 |
outHeight = Math.min(inHeight, outHeight); |
| 943 |
if (scaleToFit) { |
| 944 |
cropRectF = getMaxCropRect(inWidth, inHeight, outWidth, outHeight, |
| 945 |
horizontalAlignment, verticalAlignment); |
| 946 |
} else { |
| 947 |
float left = (inWidth - outWidth) * horizontalAlignment; |
| 948 |
float right = left + outWidth; |
| 949 |
float top = (inHeight - outHeight) * verticalAlignment; |
| 950 |
float bottom = top + outHeight; |
| 951 |
cropRectF = new RectF(left, top, right, bottom); |
| 952 |
} |
| 953 |
Rect roundedTrueCrop = new Rect(); |
| 954 |
cropRectF.roundOut(roundedTrueCrop); |
| 955 |
|
| 956 |
if (roundedTrueCrop.width() <= 0 || roundedTrueCrop.height() <= 0) { |
| 957 |
Log.w(TAG, "crop has bad values for full size image"); |
| 958 |
return null; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
int scaleDownSampleSize = Math.min(roundedTrueCrop.width() / outWidth, |
| 963 |
roundedTrueCrop.height() / outHeight); |
| 964 |
|
| 965 |
|
| 966 |
BitmapRegionDecoder decoder = null; |
| 967 |
try { |
| 968 |
decoder = BitmapRegionDecoder.newInstance(is, true); |
| 969 |
} catch (IOException e) { |
| 970 |
Log.w(TAG, "cannot open region decoder for default wallpaper"); |
| 971 |
} |
| 972 |
|
| 973 |
Bitmap crop = null; |
| 974 |
if (decoder != null) { |
| 975 |
|
| 976 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 977 |
if (scaleDownSampleSize > 1) { |
| 978 |
options.inSampleSize = scaleDownSampleSize; |
| 979 |
} |
| 980 |
crop = decoder.decodeRegion(roundedTrueCrop, options); |
| 981 |
decoder.recycle(); |
| 982 |
} |
| 983 |
|
| 984 |
if (crop == null) { |
| 985 |
|
| 986 |
|
| 987 |
is = new BufferedInputStream(openDefaultWallpaper(mContext, which)); |
| 988 |
Bitmap fullSize = null; |
| 989 |
BitmapFactory.Options options = new BitmapFactory.Options(); |
| 990 |
if (scaleDownSampleSize > 1) { |
| 991 |
options.inSampleSize = scaleDownSampleSize; |
| 992 |
} |
| 993 |
fullSize = BitmapFactory.decodeStream(is, null, options); |
| 994 |
if (fullSize != null) { |
| 995 |
crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, |
| 996 |
roundedTrueCrop.top, roundedTrueCrop.width(), |
| 997 |
roundedTrueCrop.height()); |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
if (crop == null) { |
| 1002 |
Log.w(TAG, "cannot decode default wallpaper"); |
| 1003 |
return null; |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
if (outWidth > 0 && outHeight > 0 && |
| 1008 |
(crop.getWidth() != outWidth || crop.getHeight() != outHeight)) { |
| 1009 |
Matrix m = new Matrix(); |
| 1010 |
RectF cropRect = new RectF(0, 0, crop.getWidth(), crop.getHeight()); |
| 1011 |
RectF returnRect = new RectF(0, 0, outWidth, outHeight); |
| 1012 |
m.setRectToRect(cropRect, returnRect, Matrix.ScaleToFit.FILL); |
| 1013 |
Bitmap tmp = Bitmap.createBitmap((int) returnRect.width(), |
| 1014 |
(int) returnRect.height(), Bitmap.Config.ARGB_8888); |
| 1015 |
if (tmp != null) { |
| 1016 |
Canvas c = new Canvas(tmp); |
| 1017 |
Paint p = new Paint(); |
| 1018 |
p.setFilterBitmap(true); |
| 1019 |
c.drawBitmap(crop, m, p); |
| 1020 |
crop = tmp; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
return new BitmapDrawable(resources, crop); |
| 1025 |
} |
| 1026 |
} |
| 1027 |
} |
| 1028 |
|
| 1029 |
private static RectF getMaxCropRect(int inWidth, int inHeight, int outWidth, int outHeight, |
| 1030 |
float horizontalAlignment, float verticalAlignment) { |
| 1031 |
RectF cropRect = new RectF(); |
| 1032 |
|
| 1033 |
if (inWidth / (float) inHeight > outWidth / (float) outHeight) { |
| 1034 |
cropRect.top = 0; |
| 1035 |
cropRect.bottom = inHeight; |
| 1036 |
float cropWidth = outWidth * (inHeight / (float) outHeight); |
| 1037 |
cropRect.left = (inWidth - cropWidth) * horizontalAlignment; |
| 1038 |
cropRect.right = cropRect.left + cropWidth; |
| 1039 |
} else { |
| 1040 |
cropRect.left = 0; |
| 1041 |
cropRect.right = inWidth; |
| 1042 |
float cropHeight = outHeight * (inWidth / (float) outWidth); |
| 1043 |
cropRect.top = (inHeight - cropHeight) * verticalAlignment; |
| 1044 |
cropRect.bottom = cropRect.top + cropHeight; |
| 1045 |
} |
| 1046 |
return cropRect; |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
@Nullable |
| 1059 |
public Drawable peekDrawable() { |
| 1060 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 1061 |
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM, cmProxy); |
| 1062 |
if (bm != null) { |
| 1063 |
Drawable dr = new BitmapDrawable(mContext.getResources(), bm); |
| 1064 |
dr.setDither(false); |
| 1065 |
return dr; |
| 1066 |
} |
| 1067 |
return null; |
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
@Nullable |
| 1083 |
public Drawable peekDrawable(@SetWallpaperFlags int which) { |
| 1084 |
return peekDrawable(); |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1101 |
@Nullable |
| 1102 |
public Drawable getFastDrawable() { |
| 1103 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 1104 |
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, cmProxy); |
| 1105 |
if (bm != null) { |
| 1106 |
return new FastBitmapDrawable(bm); |
| 1107 |
} |
| 1108 |
return null; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1128 |
@Nullable |
| 1129 |
public Drawable getFastDrawable(@SetWallpaperFlags int which) { |
| 1130 |
return getFastDrawable(); |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1141 |
@Nullable |
| 1142 |
public Drawable peekFastDrawable() { |
| 1143 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 1144 |
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM, cmProxy); |
| 1145 |
if (bm != null) { |
| 1146 |
return new FastBitmapDrawable(bm); |
| 1147 |
} |
| 1148 |
return null; |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1162 |
@Nullable |
| 1163 |
public Drawable peekFastDrawable(@SetWallpaperFlags int which) { |
| 1164 |
return peekFastDrawable(); |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
@TestApi |
| 1178 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1179 |
public boolean wallpaperSupportsWcg(int which) { |
| 1180 |
if (!shouldEnableWideColorGamut()) { |
| 1181 |
return false; |
| 1182 |
} |
| 1183 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 1184 |
Bitmap bitmap = sGlobals.peekWallpaperBitmap(mContext, false, which, cmProxy); |
| 1185 |
return bitmap != null && bitmap.getColorSpace() != null |
| 1186 |
&& bitmap.getColorSpace() != ColorSpace.get(ColorSpace.Named.SRGB) |
| 1187 |
&& cmProxy.isSupportedColorSpace(bitmap.getColorSpace()); |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
@TestApi |
| 1196 |
@Nullable |
| 1197 |
@UnsupportedAppUsage |
| 1198 |
public Bitmap getBitmap() { |
| 1199 |
return getBitmap(false); |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
@UnsupportedAppUsage |
| 1210 |
public Bitmap getBitmap(boolean hardware) { |
| 1211 |
return getBitmapAsUser(mContext.getUserId(), hardware); |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
public Bitmap getBitmapAsUser(int userId, boolean hardware) { |
| 1220 |
final ColorManagementProxy cmProxy = getColorManagementProxy(); |
| 1221 |
return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId, hardware, cmProxy); |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
@Nullable |
| 1231 |
public Rect peekBitmapDimensions() { |
| 1232 |
return sGlobals.peekWallpaperDimensions( |
| 1233 |
mContext, true , mContext.getUserId()); |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
@Nullable |
| 1245 |
public Rect peekBitmapDimensions(@SetWallpaperFlags int which) { |
| 1246 |
return peekBitmapDimensions(); |
| 1247 |
} |
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
| 1268 |
public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which) { |
| 1269 |
return getWallpaperFile(which, mContext.getUserId()); |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener, |
| 1279 |
@NonNull Handler handler) { |
| 1280 |
addOnColorsChangedListener(listener, handler, mContext.getUserId()); |
| 1281 |
} |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
@UnsupportedAppUsage |
| 1292 |
public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener, |
| 1293 |
@NonNull Handler handler, int userId) { |
| 1294 |
sGlobals.addOnColorsChangedListener(listener, handler, userId, mContext.getDisplayId()); |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback) { |
| 1302 |
removeOnColorsChangedListener(callback, mContext.getUserId()); |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
| 1312 |
int userId) { |
| 1313 |
sGlobals.removeOnColorsChangedListener(callback, userId, mContext.getDisplayId()); |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
public @Nullable WallpaperColors getWallpaperColors(int which) { |
| 1337 |
return getWallpaperColors(which, mContext.getUserId()); |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
@UnsupportedAppUsage |
| 1350 |
public @Nullable WallpaperColors getWallpaperColors(int which, int userId) { |
| 1351 |
StrictMode.assertUiContext(mContext, "getWallpaperColors"); |
| 1352 |
return sGlobals.getWallpaperColors(which, userId, mContext.getDisplayId()); |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
public void addOnColorsChangedListener(@NonNull LocalWallpaperColorConsumer callback, |
| 1359 |
List<RectF> regions) throws IllegalArgumentException { |
| 1360 |
for (RectF region : regions) { |
| 1361 |
if (!LOCAL_COLOR_BOUNDS.contains(region)) { |
| 1362 |
throw new IllegalArgumentException("Regions must be within bounds " |
| 1363 |
+ LOCAL_COLOR_BOUNDS); |
| 1364 |
} |
| 1365 |
} |
| 1366 |
sGlobals.addOnColorsChangedListener(callback, regions, FLAG_SYSTEM, |
| 1367 |
mContext.getUserId(), mContext.getDisplayId()); |
| 1368 |
} |
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
public void removeOnColorsChangedListener(@NonNull LocalWallpaperColorConsumer callback) { |
| 1374 |
sGlobals.removeOnColorsChangedListener(callback, FLAG_SYSTEM, mContext.getUserId(), |
| 1375 |
mContext.getDisplayId()); |
| 1376 |
} |
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
@UnsupportedAppUsage |
| 1394 |
public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, int userId) { |
| 1395 |
if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
| 1396 |
throw new IllegalArgumentException("Must request exactly one kind of wallpaper"); |
| 1397 |
} |
| 1398 |
|
| 1399 |
if (sGlobals.mService == null) { |
| 1400 |
Log.w(TAG, "WallpaperService not running"); |
| 1401 |
throw new RuntimeException(new DeadSystemException()); |
| 1402 |
} else { |
| 1403 |
try { |
| 1404 |
Bundle outParams = new Bundle(); |
| 1405 |
return sGlobals.mService.getWallpaperWithFeature(mContext.getOpPackageName(), |
| 1406 |
mContext.getAttributionTag(), null, which, outParams, userId); |
| 1407 |
} catch (RemoteException e) { |
| 1408 |
throw e.rethrowFromSystemServer(); |
| 1409 |
} catch (SecurityException e) { |
| 1410 |
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) { |
| 1411 |
Log.w(TAG, "No permission to access wallpaper, suppressing" |
| 1412 |
+ " exception to avoid crashing legacy app."); |
| 1413 |
return null; |
| 1414 |
} else { |
| 1415 |
throw e; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
public void forgetLoadedWallpaper() { |
| 1428 |
sGlobals.forgetLoadedWallpaper(); |
| 1429 |
} |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
public WallpaperInfo getWallpaperInfo() { |
| 1436 |
return getWallpaperInfoForUser(mContext.getUserId()); |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
public WallpaperInfo getWallpaperInfoForUser(int userId) { |
| 1447 |
try { |
| 1448 |
if (sGlobals.mService == null) { |
| 1449 |
Log.w(TAG, "WallpaperService not running"); |
| 1450 |
throw new RuntimeException(new DeadSystemException()); |
| 1451 |
} else { |
| 1452 |
return sGlobals.mService.getWallpaperInfo(userId); |
| 1453 |
} |
| 1454 |
} catch (RemoteException e) { |
| 1455 |
throw e.rethrowFromSystemServer(); |
| 1456 |
} |
| 1457 |
} |
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which) { |
| 1470 |
return getWallpaperInfo(); |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which, int userId) { |
| 1485 |
return getWallpaperInfoForUser(userId); |
| 1486 |
} |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
public int getWallpaperId(@SetWallpaperFlags int which) { |
| 1503 |
return getWallpaperIdForUser(which, mContext.getUserId()); |
| 1504 |
} |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
public int getWallpaperIdForUser(@SetWallpaperFlags int which, int userId) { |
| 1512 |
try { |
| 1513 |
if (sGlobals.mService == null) { |
| 1514 |
Log.w(TAG, "WallpaperService not running"); |
| 1515 |
throw new RuntimeException(new DeadSystemException()); |
| 1516 |
} else { |
| 1517 |
return sGlobals.mService.getWallpaperIdForUser(which, userId); |
| 1518 |
} |
| 1519 |
} catch (RemoteException e) { |
| 1520 |
throw e.rethrowFromSystemServer(); |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
public Intent getCropAndSetWallpaperIntent(Uri imageUri) { |
| 1538 |
if (imageUri == null) { |
| 1539 |
throw new IllegalArgumentException("Image URI must not be null"); |
| 1540 |
} |
| 1541 |
|
| 1542 |
if (!ContentResolver.SCHEME_CONTENT.equals(imageUri.getScheme())) { |
| 1543 |
throw new IllegalArgumentException("Image URI must be of the " |
| 1544 |
+ ContentResolver.SCHEME_CONTENT + " scheme type"); |
| 1545 |
} |
| 1546 |
|
| 1547 |
final PackageManager packageManager = mContext.getPackageManager(); |
| 1548 |
Intent cropAndSetWallpaperIntent = |
| 1549 |
new Intent(ACTION_CROP_AND_SET_WALLPAPER, imageUri); |
| 1550 |
cropAndSetWallpaperIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 1551 |
|
| 1552 |
|
| 1553 |
Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); |
| 1554 |
ResolveInfo resolvedHome = packageManager.resolveActivity(homeIntent, |
| 1555 |
PackageManager.MATCH_DEFAULT_ONLY); |
| 1556 |
if (resolvedHome != null) { |
| 1557 |
cropAndSetWallpaperIntent.setPackage(resolvedHome.activityInfo.packageName); |
| 1558 |
|
| 1559 |
List<ResolveInfo> cropAppList = packageManager.queryIntentActivities( |
| 1560 |
cropAndSetWallpaperIntent, 0); |
| 1561 |
if (cropAppList.size() > 0) { |
| 1562 |
return cropAndSetWallpaperIntent; |
| 1563 |
} |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
final String cropperPackage = mContext.getString( |
| 1568 |
com.android.internal.R.string.config_wallpaperCropperPackage); |
| 1569 |
cropAndSetWallpaperIntent.setPackage(cropperPackage); |
| 1570 |
List<ResolveInfo> cropAppList = packageManager.queryIntentActivities( |
| 1571 |
cropAndSetWallpaperIntent, 0); |
| 1572 |
if (cropAppList.size() > 0) { |
| 1573 |
return cropAndSetWallpaperIntent; |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
throw new IllegalArgumentException("Cannot use passed URI to set wallpaper; " + |
| 1578 |
"check that the type returned by ContentProvider matches image/*"); |
| 1579 |
} |
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1596 |
public void setResource(@RawRes int resid) throws IOException { |
| 1597 |
setResource(resid, FLAG_SYSTEM | FLAG_LOCK); |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1615 |
public int setResource(@RawRes int resid, @SetWallpaperFlags int which) |
| 1616 |
throws IOException { |
| 1617 |
if (sGlobals.mService == null) { |
| 1618 |
Log.w(TAG, "WallpaperService not running"); |
| 1619 |
throw new RuntimeException(new DeadSystemException()); |
| 1620 |
} |
| 1621 |
final Bundle result = new Bundle(); |
| 1622 |
final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
| 1623 |
try { |
| 1624 |
Resources resources = mContext.getResources(); |
| 1625 |
|
| 1626 |
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper( |
| 1627 |
"res:" + resources.getResourceName(resid), |
| 1628 |
mContext.getOpPackageName(), null, false, result, which, completion, |
| 1629 |
mContext.getUserId()); |
| 1630 |
if (fd != null) { |
| 1631 |
FileOutputStream fos = null; |
| 1632 |
boolean ok = false; |
| 1633 |
try { |
| 1634 |
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
| 1635 |
copyStreamToWallpaperFile(resources.openRawResource(resid), fos); |
| 1636 |
|
| 1637 |
|
| 1638 |
fos.close(); |
| 1639 |
completion.waitForCompletion(); |
| 1640 |
} finally { |
| 1641 |
|
| 1642 |
|
| 1643 |
IoUtils.closeQuietly(fos); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
} catch (RemoteException e) { |
| 1647 |
throw e.rethrowFromSystemServer(); |
| 1648 |
} |
| 1649 |
return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1671 |
public void setBitmap(Bitmap bitmap) throws IOException { |
| 1672 |
setBitmap(bitmap, null, true); |
| 1673 |
} |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1704 |
public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup) |
| 1705 |
throws IOException { |
| 1706 |
return setBitmap(fullImage, visibleCropHint, allowBackup, FLAG_SYSTEM | FLAG_LOCK); |
| 1707 |
} |
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1730 |
public int setBitmap(Bitmap fullImage, Rect visibleCropHint, |
| 1731 |
boolean allowBackup, @SetWallpaperFlags int which) |
| 1732 |
throws IOException { |
| 1733 |
return setBitmap(fullImage, visibleCropHint, allowBackup, which, |
| 1734 |
mContext.getUserId()); |
| 1735 |
} |
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1744 |
public int setBitmap(Bitmap fullImage, Rect visibleCropHint, |
| 1745 |
boolean allowBackup, @SetWallpaperFlags int which, int userId) |
| 1746 |
throws IOException { |
| 1747 |
validateRect(visibleCropHint); |
| 1748 |
if (sGlobals.mService == null) { |
| 1749 |
Log.w(TAG, "WallpaperService not running"); |
| 1750 |
throw new RuntimeException(new DeadSystemException()); |
| 1751 |
} |
| 1752 |
final Bundle result = new Bundle(); |
| 1753 |
final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
| 1754 |
try { |
| 1755 |
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null, |
| 1756 |
mContext.getOpPackageName(), visibleCropHint, allowBackup, |
| 1757 |
result, which, completion, userId); |
| 1758 |
if (fd != null) { |
| 1759 |
FileOutputStream fos = null; |
| 1760 |
try { |
| 1761 |
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
| 1762 |
fullImage.compress(Bitmap.CompressFormat.PNG, 90, fos); |
| 1763 |
fos.close(); |
| 1764 |
completion.waitForCompletion(); |
| 1765 |
} finally { |
| 1766 |
IoUtils.closeQuietly(fos); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
} catch (RemoteException e) { |
| 1770 |
throw e.rethrowFromSystemServer(); |
| 1771 |
} |
| 1772 |
return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
| 1773 |
} |
| 1774 |
|
| 1775 |
private final void validateRect(Rect rect) { |
| 1776 |
if (rect != null && rect.isEmpty()) { |
| 1777 |
throw new IllegalArgumentException("visibleCrop rectangle must be valid and non-empty"); |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1803 |
public void setStream(InputStream bitmapData) throws IOException { |
| 1804 |
setStream(bitmapData, null, true); |
| 1805 |
} |
| 1806 |
|
| 1807 |
private void copyStreamToWallpaperFile(InputStream data, FileOutputStream fos) |
| 1808 |
throws IOException { |
| 1809 |
FileUtils.copy(data, fos); |
| 1810 |
} |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1842 |
public int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup) |
| 1843 |
throws IOException { |
| 1844 |
return setStream(bitmapData, visibleCropHint, allowBackup, FLAG_SYSTEM | FLAG_LOCK); |
| 1845 |
} |
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 1869 |
public int setStream(InputStream bitmapData, Rect visibleCropHint, |
| 1870 |
boolean allowBackup, @SetWallpaperFlags int which) |
| 1871 |
throws IOException { |
| 1872 |
validateRect(visibleCropHint); |
| 1873 |
if (sGlobals.mService == null) { |
| 1874 |
Log.w(TAG, "WallpaperService not running"); |
| 1875 |
throw new RuntimeException(new DeadSystemException()); |
| 1876 |
} |
| 1877 |
final Bundle result = new Bundle(); |
| 1878 |
final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
| 1879 |
try { |
| 1880 |
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null, |
| 1881 |
mContext.getOpPackageName(), visibleCropHint, allowBackup, |
| 1882 |
result, which, completion, mContext.getUserId()); |
| 1883 |
if (fd != null) { |
| 1884 |
FileOutputStream fos = null; |
| 1885 |
try { |
| 1886 |
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
| 1887 |
copyStreamToWallpaperFile(bitmapData, fos); |
| 1888 |
fos.close(); |
| 1889 |
completion.waitForCompletion(); |
| 1890 |
} finally { |
| 1891 |
IoUtils.closeQuietly(fos); |
| 1892 |
} |
| 1893 |
} |
| 1894 |
} catch (RemoteException e) { |
| 1895 |
throw e.rethrowFromSystemServer(); |
| 1896 |
} |
| 1897 |
|
| 1898 |
return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
| 1899 |
} |
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
public boolean hasResourceWallpaper(@RawRes int resid) { |
| 1907 |
if (sGlobals.mService == null) { |
| 1908 |
Log.w(TAG, "WallpaperService not running"); |
| 1909 |
throw new RuntimeException(new DeadSystemException()); |
| 1910 |
} |
| 1911 |
try { |
| 1912 |
Resources resources = mContext.getResources(); |
| 1913 |
String name = "res:" + resources.getResourceName(resid); |
| 1914 |
return sGlobals.mService.hasNamedWallpaper(name); |
| 1915 |
} catch (RemoteException e) { |
| 1916 |
throw e.rethrowFromSystemServer(); |
| 1917 |
} |
| 1918 |
} |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
public int getDesiredMinimumWidth() { |
| 1938 |
StrictMode.assertUiContext(mContext, "getDesiredMinimumWidth"); |
| 1939 |
if (sGlobals.mService == null) { |
| 1940 |
Log.w(TAG, "WallpaperService not running"); |
| 1941 |
throw new RuntimeException(new DeadSystemException()); |
| 1942 |
} |
| 1943 |
try { |
| 1944 |
return sGlobals.mService.getWidthHint(mContext.getDisplayId()); |
| 1945 |
} catch (RemoteException e) { |
| 1946 |
throw e.rethrowFromSystemServer(); |
| 1947 |
} |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
public int getDesiredMinimumHeight() { |
| 1968 |
StrictMode.assertUiContext(mContext, "getDesiredMinimumHeight"); |
| 1969 |
if (sGlobals.mService == null) { |
| 1970 |
Log.w(TAG, "WallpaperService not running"); |
| 1971 |
throw new RuntimeException(new DeadSystemException()); |
| 1972 |
} |
| 1973 |
try { |
| 1974 |
return sGlobals.mService.getHeightHint(mContext.getDisplayId()); |
| 1975 |
} catch (RemoteException e) { |
| 1976 |
throw e.rethrowFromSystemServer(); |
| 1977 |
} |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) { |
| 2000 |
StrictMode.assertUiContext(mContext, "suggestDesiredDimensions"); |
| 2001 |
try { |
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
int maximumTextureSize; |
| 2011 |
try { |
| 2012 |
maximumTextureSize = SystemProperties.getInt("sys.max_texture_size", 0); |
| 2013 |
} catch (Exception e) { |
| 2014 |
maximumTextureSize = 0; |
| 2015 |
} |
| 2016 |
|
| 2017 |
if (maximumTextureSize > 0) { |
| 2018 |
if ((minimumWidth > maximumTextureSize) || |
| 2019 |
(minimumHeight > maximumTextureSize)) { |
| 2020 |
float aspect = (float)minimumHeight / (float)minimumWidth; |
| 2021 |
if (minimumWidth > minimumHeight) { |
| 2022 |
minimumWidth = maximumTextureSize; |
| 2023 |
minimumHeight = (int)((minimumWidth * aspect) + 0.5); |
| 2024 |
} else { |
| 2025 |
minimumHeight = maximumTextureSize; |
| 2026 |
minimumWidth = (int)((minimumHeight / aspect) + 0.5); |
| 2027 |
} |
| 2028 |
} |
| 2029 |
} |
| 2030 |
|
| 2031 |
if (sGlobals.mService == null) { |
| 2032 |
Log.w(TAG, "WallpaperService not running"); |
| 2033 |
throw new RuntimeException(new DeadSystemException()); |
| 2034 |
} else { |
| 2035 |
sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight, |
| 2036 |
mContext.getOpPackageName(), mContext.getDisplayId()); |
| 2037 |
} |
| 2038 |
} catch (RemoteException e) { |
| 2039 |
throw e.rethrowFromSystemServer(); |
| 2040 |
} |
| 2041 |
} |
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_HINTS) |
| 2056 |
public void setDisplayPadding(Rect padding) { |
| 2057 |
StrictMode.assertUiContext(mContext, "setDisplayPadding"); |
| 2058 |
try { |
| 2059 |
if (sGlobals.mService == null) { |
| 2060 |
Log.w(TAG, "WallpaperService not running"); |
| 2061 |
throw new RuntimeException(new DeadSystemException()); |
| 2062 |
} else { |
| 2063 |
sGlobals.mService.setDisplayPadding(padding, mContext.getOpPackageName(), |
| 2064 |
mContext.getDisplayId()); |
| 2065 |
} |
| 2066 |
} catch (RemoteException e) { |
| 2067 |
throw e.rethrowFromSystemServer(); |
| 2068 |
} |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
@SystemApi |
| 2081 |
public void setDisplayOffset(IBinder windowToken, int x, int y) { |
| 2082 |
try { |
| 2083 |
|
| 2084 |
WindowManagerGlobal.getWindowSession().setWallpaperDisplayOffset( |
| 2085 |
windowToken, x, y); |
| 2086 |
|
| 2087 |
} catch (RemoteException e) { |
| 2088 |
throw e.rethrowFromSystemServer(); |
| 2089 |
} |
| 2090 |
} |
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 2099 |
public void clearWallpaper() { |
| 2100 |
clearWallpaper(FLAG_LOCK, mContext.getUserId()); |
| 2101 |
clearWallpaper(FLAG_SYSTEM, mContext.getUserId()); |
| 2102 |
} |
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
@SystemApi |
| 2112 |
@RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 2113 |
public void clearWallpaper(@SetWallpaperFlags int which, int userId) { |
| 2114 |
if (sGlobals.mService == null) { |
| 2115 |
Log.w(TAG, "WallpaperService not running"); |
| 2116 |
throw new RuntimeException(new DeadSystemException()); |
| 2117 |
} |
| 2118 |
try { |
| 2119 |
sGlobals.mService.clearWallpaper(mContext.getOpPackageName(), which, userId); |
| 2120 |
} catch (RemoteException e) { |
| 2121 |
throw e.rethrowFromSystemServer(); |
| 2122 |
} |
| 2123 |
} |
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
@SystemApi |
| 2131 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) |
| 2132 |
public boolean setWallpaperComponent(ComponentName name) { |
| 2133 |
return setWallpaperComponent(name, mContext.getUserId()); |
| 2134 |
} |
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
@SystemApi |
| 2143 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) |
| 2144 |
public void setWallpaperDimAmount(@FloatRange (from = 0f, to = 1f) float dimAmount) { |
| 2145 |
if (sGlobals.mService == null) { |
| 2146 |
Log.w(TAG, "WallpaperService not running"); |
| 2147 |
throw new RuntimeException(new DeadSystemException()); |
| 2148 |
} |
| 2149 |
try { |
| 2150 |
sGlobals.mService.setWallpaperDimAmount(MathUtils.saturate(dimAmount)); |
| 2151 |
} catch (RemoteException e) { |
| 2152 |
throw e.rethrowFromSystemServer(); |
| 2153 |
} |
| 2154 |
} |
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
@SystemApi |
| 2163 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) |
| 2164 |
public float getWallpaperDimAmount() { |
| 2165 |
if (sGlobals.mService == null) { |
| 2166 |
Log.w(TAG, "WallpaperService not running"); |
| 2167 |
throw new RuntimeException(new DeadSystemException()); |
| 2168 |
} |
| 2169 |
try { |
| 2170 |
return sGlobals.mService.getWallpaperDimAmount(); |
| 2171 |
} catch (RemoteException e) { |
| 2172 |
throw e.rethrowFromSystemServer(); |
| 2173 |
} |
| 2174 |
} |
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
public boolean lockScreenWallpaperExists() { |
| 2182 |
if (sGlobals.mService == null) { |
| 2183 |
Log.w(TAG, "WallpaperService not running"); |
| 2184 |
throw new RuntimeException(new DeadSystemException()); |
| 2185 |
} |
| 2186 |
try { |
| 2187 |
return sGlobals.mService.lockScreenWallpaperExists(); |
| 2188 |
} catch (RemoteException e) { |
| 2189 |
throw e.rethrowFromSystemServer(); |
| 2190 |
} |
| 2191 |
} |
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) |
| 2203 |
@UnsupportedAppUsage |
| 2204 |
public boolean setWallpaperComponent(ComponentName name, int userId) { |
| 2205 |
if (sGlobals.mService == null) { |
| 2206 |
Log.w(TAG, "WallpaperService not running"); |
| 2207 |
throw new RuntimeException(new DeadSystemException()); |
| 2208 |
} |
| 2209 |
try { |
| 2210 |
sGlobals.mService.setWallpaperComponentChecked(name, mContext.getOpPackageName(), |
| 2211 |
userId); |
| 2212 |
return true; |
| 2213 |
} catch (RemoteException e) { |
| 2214 |
throw e.rethrowFromSystemServer(); |
| 2215 |
} |
| 2216 |
} |
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) |
| 2228 |
public boolean setWallpaperComponentWithFlags(@NonNull ComponentName name, |
| 2229 |
@SetWallpaperFlags int which) { |
| 2230 |
return setWallpaperComponent(name); |
| 2231 |
} |
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
public void setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset) { |
| 2247 |
try { |
| 2248 |
|
| 2249 |
WindowManagerGlobal.getWindowSession().setWallpaperPosition( |
| 2250 |
windowToken, xOffset, yOffset, mWallpaperXStep, mWallpaperYStep); |
| 2251 |
|
| 2252 |
} catch (RemoteException e) { |
| 2253 |
throw e.rethrowFromSystemServer(); |
| 2254 |
} |
| 2255 |
} |
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
public void setWallpaperOffsetSteps(float xStep, float yStep) { |
| 2266 |
mWallpaperXStep = xStep; |
| 2267 |
mWallpaperYStep = yStep; |
| 2268 |
} |
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
public void sendWallpaperCommand(IBinder windowToken, String action, |
| 2284 |
int x, int y, int z, Bundle extras) { |
| 2285 |
try { |
| 2286 |
|
| 2287 |
WindowManagerGlobal.getWindowSession().sendWallpaperCommand( |
| 2288 |
windowToken, action, x, y, z, extras, false); |
| 2289 |
|
| 2290 |
} catch (RemoteException e) { |
| 2291 |
throw e.rethrowFromSystemServer(); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
public void setWallpaperZoomOut(@NonNull IBinder windowToken, float zoom) { |
| 2305 |
if (zoom < 0 || zoom > 1f) { |
| 2306 |
throw new IllegalArgumentException("zoom must be between 0 and 1: " + zoom); |
| 2307 |
} |
| 2308 |
if (windowToken == null) { |
| 2309 |
throw new IllegalArgumentException("windowToken must not be null"); |
| 2310 |
} |
| 2311 |
try { |
| 2312 |
WindowManagerGlobal.getWindowSession().setWallpaperZoomOut(windowToken, zoom); |
| 2313 |
} catch (RemoteException e) { |
| 2314 |
throw e.rethrowFromSystemServer(); |
| 2315 |
} |
| 2316 |
} |
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
public boolean isWallpaperSupported() { |
| 2324 |
if (sGlobals.mService == null) { |
| 2325 |
Log.w(TAG, "WallpaperService not running"); |
| 2326 |
throw new RuntimeException(new DeadSystemException()); |
| 2327 |
} else { |
| 2328 |
try { |
| 2329 |
return sGlobals.mService.isWallpaperSupported(mContext.getOpPackageName()); |
| 2330 |
} catch (RemoteException e) { |
| 2331 |
throw e.rethrowFromSystemServer(); |
| 2332 |
} |
| 2333 |
} |
| 2334 |
} |
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
public boolean isSetWallpaperAllowed() { |
| 2344 |
if (sGlobals.mService == null) { |
| 2345 |
Log.w(TAG, "WallpaperService not running"); |
| 2346 |
throw new RuntimeException(new DeadSystemException()); |
| 2347 |
} else { |
| 2348 |
try { |
| 2349 |
return sGlobals.mService.isSetWallpaperAllowed(mContext.getOpPackageName()); |
| 2350 |
} catch (RemoteException e) { |
| 2351 |
throw e.rethrowFromSystemServer(); |
| 2352 |
} |
| 2353 |
} |
| 2354 |
} |
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
public void clearWallpaperOffsets(IBinder windowToken) { |
| 2367 |
try { |
| 2368 |
WindowManagerGlobal.getWindowSession().setWallpaperPosition( |
| 2369 |
windowToken, -1, -1, -1, -1); |
| 2370 |
} catch (RemoteException e) { |
| 2371 |
throw e.rethrowFromSystemServer(); |
| 2372 |
} |
| 2373 |
} |
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 2387 |
public void clear() throws IOException { |
| 2388 |
setStream(openDefaultWallpaper(mContext, FLAG_SYSTEM), null, false); |
| 2389 |
} |
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
@RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
| 2402 |
public void clear(@SetWallpaperFlags int which) throws IOException { |
| 2403 |
if ((which & FLAG_SYSTEM) != 0) { |
| 2404 |
clear(); |
| 2405 |
} |
| 2406 |
if ((which & FLAG_LOCK) != 0) { |
| 2407 |
clearWallpaper(FLAG_LOCK, mContext.getUserId()); |
| 2408 |
} |
| 2409 |
} |
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2420 |
public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) { |
| 2421 |
final String whichProp; |
| 2422 |
final int defaultResId; |
| 2423 |
if (which == FLAG_LOCK) { |
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
return null; |
| 2429 |
} else { |
| 2430 |
whichProp = PROP_WALLPAPER; |
| 2431 |
defaultResId = com.android.internal.R.drawable.default_wallpaper; |
| 2432 |
} |
| 2433 |
final String path = SystemProperties.get(whichProp); |
| 2434 |
final InputStream wallpaperInputStream = getWallpaperInputStream(path); |
| 2435 |
if (wallpaperInputStream != null) { |
| 2436 |
return wallpaperInputStream; |
| 2437 |
} |
| 2438 |
final String cmfPath = getCmfWallpaperPath(); |
| 2439 |
final InputStream cmfWallpaperInputStream = getWallpaperInputStream(cmfPath); |
| 2440 |
if (cmfWallpaperInputStream != null) { |
| 2441 |
return cmfWallpaperInputStream; |
| 2442 |
} |
| 2443 |
try { |
| 2444 |
return context.getResources().openRawResource(defaultResId); |
| 2445 |
} catch (NotFoundException e) { |
| 2446 |
|
| 2447 |
} |
| 2448 |
return null; |
| 2449 |
} |
| 2450 |
|
| 2451 |
private static InputStream getWallpaperInputStream(String path) { |
| 2452 |
if (!TextUtils.isEmpty(path)) { |
| 2453 |
final File file = new File(path); |
| 2454 |
if (file.exists()) { |
| 2455 |
try { |
| 2456 |
return new FileInputStream(file); |
| 2457 |
} catch (IOException e) { |
| 2458 |
|
| 2459 |
} |
| 2460 |
} |
| 2461 |
} |
| 2462 |
return null; |
| 2463 |
} |
| 2464 |
|
| 2465 |
private static String getCmfWallpaperPath() { |
| 2466 |
return Environment.getProductDirectory() + WALLPAPER_CMF_PATH + "default_wallpaper_" |
| 2467 |
+ VALUE_CMF_COLOR; |
| 2468 |
} |
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
public static ComponentName getDefaultWallpaperComponent(Context context) { |
| 2477 |
ComponentName cn = null; |
| 2478 |
|
| 2479 |
String flat = SystemProperties.get(PROP_WALLPAPER_COMPONENT); |
| 2480 |
if (!TextUtils.isEmpty(flat)) { |
| 2481 |
cn = ComponentName.unflattenFromString(flat); |
| 2482 |
} |
| 2483 |
|
| 2484 |
if (cn == null) { |
| 2485 |
flat = context.getString(com.android.internal.R.string.default_wallpaper_component); |
| 2486 |
if (!TextUtils.isEmpty(flat)) { |
| 2487 |
cn = ComponentName.unflattenFromString(flat); |
| 2488 |
} |
| 2489 |
} |
| 2490 |
|
| 2491 |
|
| 2492 |
if (cn != null) { |
| 2493 |
try { |
| 2494 |
final PackageManager packageManager = context.getPackageManager(); |
| 2495 |
packageManager.getPackageInfo(cn.getPackageName(), |
| 2496 |
PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 2497 |
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE); |
| 2498 |
} catch (PackageManager.NameNotFoundException e) { |
| 2499 |
cn = null; |
| 2500 |
} |
| 2501 |
} |
| 2502 |
|
| 2503 |
return cn; |
| 2504 |
} |
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
public boolean setLockWallpaperCallback(IWallpaperManagerCallback callback) { |
| 2513 |
if (sGlobals.mService == null) { |
| 2514 |
Log.w(TAG, "WallpaperService not running"); |
| 2515 |
throw new RuntimeException(new DeadSystemException()); |
| 2516 |
} |
| 2517 |
|
| 2518 |
try { |
| 2519 |
return sGlobals.mService.setLockWallpaperCallback(callback); |
| 2520 |
} catch (RemoteException e) { |
| 2521 |
throw e.rethrowFromSystemServer(); |
| 2522 |
} |
| 2523 |
} |
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
public boolean isWallpaperBackupEligible(int which) { |
| 2532 |
if (sGlobals.mService == null) { |
| 2533 |
Log.w(TAG, "WallpaperService not running"); |
| 2534 |
throw new RuntimeException(new DeadSystemException()); |
| 2535 |
} |
| 2536 |
try { |
| 2537 |
return sGlobals.mService.isWallpaperBackupEligible(which, mContext.getUserId()); |
| 2538 |
} catch (RemoteException e) { |
| 2539 |
Log.e(TAG, "Exception querying wallpaper backup eligibility: " + e.getMessage()); |
| 2540 |
} |
| 2541 |
return false; |
| 2542 |
} |
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
public ColorManagementProxy getColorManagementProxy() { |
| 2551 |
return mCmProxy; |
| 2552 |
} |
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
public static class ColorManagementProxy { |
| 2559 |
private final Set<ColorSpace> mSupportedColorSpaces = new HashSet<>(); |
| 2560 |
|
| 2561 |
public ColorManagementProxy(@NonNull Context context) { |
| 2562 |
|
| 2563 |
Display display = context.getDisplayNoVerify(); |
| 2564 |
if (display != null) { |
| 2565 |
mSupportedColorSpaces.addAll(Arrays.asList(display.getSupportedWideColorGamut())); |
| 2566 |
} |
| 2567 |
} |
| 2568 |
|
| 2569 |
@NonNull |
| 2570 |
public Set<ColorSpace> getSupportedColorSpaces() { |
| 2571 |
return mSupportedColorSpaces; |
| 2572 |
} |
| 2573 |
|
| 2574 |
boolean isSupportedColorSpace(ColorSpace colorSpace) { |
| 2575 |
return colorSpace != null && (colorSpace == ColorSpace.get(ColorSpace.Named.SRGB) |
| 2576 |
|| getSupportedColorSpaces().contains(colorSpace)); |
| 2577 |
} |
| 2578 |
|
| 2579 |
void doColorManagement(ImageDecoder decoder, ImageDecoder.ImageInfo info) { |
| 2580 |
if (!isSupportedColorSpace(info.getColorSpace())) { |
| 2581 |
decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB)); |
| 2582 |
Log.w(TAG, "Not supported color space: " + info.getColorSpace()); |
| 2583 |
} |
| 2584 |
} |
| 2585 |
} |
| 2586 |
|
| 2587 |
|
| 2588 |
private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub { |
| 2589 |
final CountDownLatch mLatch; |
| 2590 |
|
| 2591 |
public WallpaperSetCompletion() { |
| 2592 |
mLatch = new CountDownLatch(1); |
| 2593 |
} |
| 2594 |
|
| 2595 |
public void waitForCompletion() { |
| 2596 |
try { |
| 2597 |
final boolean completed = mLatch.await(30, TimeUnit.SECONDS); |
| 2598 |
if (completed) { |
| 2599 |
Log.d(TAG, "Wallpaper set completion."); |
| 2600 |
} else { |
| 2601 |
Log.d(TAG, "Timeout waiting for wallpaper set completion!"); |
| 2602 |
} |
| 2603 |
} catch (InterruptedException e) { |
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
} |
| 2608 |
} |
| 2609 |
|
| 2610 |
@Override |
| 2611 |
public void onWallpaperChanged() throws RemoteException { |
| 2612 |
mLatch.countDown(); |
| 2613 |
} |
| 2614 |
|
| 2615 |
@Override |
| 2616 |
public void onWallpaperColorsChanged(WallpaperColors colors, int which, int userId) |
| 2617 |
throws RemoteException { |
| 2618 |
sGlobals.onWallpaperColorsChanged(colors, which, userId); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
public interface OnColorsChangedListener { |
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
void onColorsChanged(@Nullable WallpaperColors colors, int which); |
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
default void onColorsChanged(@Nullable WallpaperColors colors, int which, int userId) { |
| 2649 |
onColorsChanged(colors, which); |
| 2650 |
} |
| 2651 |
} |
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
public interface LocalWallpaperColorConsumer { |
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
void onColorsChanged(RectF area, WallpaperColors colors); |
| 2665 |
} |
| 2666 |
} |