Merge "Fix NPE in WallpaperDrawable" into nyc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
index c423b67..ef19d95 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.phone;
+import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.IWallpaperManager;
import android.app.IWallpaperManagerCallback;
@@ -26,6 +27,7 @@
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableWrapper;
import android.os.AsyncTask;
import android.os.Handler;
@@ -209,12 +211,16 @@
*/
public static class WallpaperDrawable extends DrawableWrapper {
- private Bitmap mBackground;
- private Rect mTmpRect = new Rect();
+ private final ConstantState mState;
+ private final Rect mTmpRect = new Rect();
public WallpaperDrawable(Resources r, Bitmap b) {
- super(new BitmapDrawable(r, b));
- mBackground = b;
+ this(r, new ConstantState(b));
+ }
+
+ private WallpaperDrawable(Resources r, ConstantState state) {
+ super(new BitmapDrawable(r, state.mBackground));
+ mState = state;
}
@Override
@@ -231,8 +237,8 @@
protected void onBoundsChange(Rect bounds) {
int vwidth = getBounds().width();
int vheight = getBounds().height();
- int dwidth = mBackground.getWidth();
- int dheight = mBackground.getHeight();
+ int dwidth = mState.mBackground.getWidth();
+ int dheight = mState.mBackground.getHeight();
float scale;
float dx = 0, dy = 0;
@@ -255,5 +261,35 @@
super.onBoundsChange(mTmpRect);
}
+
+ @Override
+ public ConstantState getConstantState() {
+ return mState;
+ }
+
+ static class ConstantState extends Drawable.ConstantState {
+
+ private final Bitmap mBackground;
+
+ ConstantState(Bitmap background) {
+ mBackground = background;
+ }
+
+ @Override
+ public Drawable newDrawable() {
+ return newDrawable(null);
+ }
+
+ @Override
+ public Drawable newDrawable(@Nullable Resources res) {
+ return new WallpaperDrawable(res, this);
+ }
+
+ @Override
+ public int getChangingConfigurations() {
+ // DrawableWrapper already handles this for us.
+ return 0;
+ }
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index d3f3b2d..712f814 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -2021,7 +2021,8 @@
if (metaDataChanged) {
if (mBackdropBack.getDrawable() != null) {
Drawable drawable =
- mBackdropBack.getDrawable().getConstantState().newDrawable().mutate();
+ mBackdropBack.getDrawable().getConstantState()
+ .newDrawable(mBackdropFront.getResources()).mutate();
mBackdropFront.setImageDrawable(drawable);
if (mScrimSrcModeEnabled) {
mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode);