Merge "Unload wallpaper bitmap and release HwuiContext" into pi-dev

am: 3844e1d83c

Change-Id: I845b4ec476ea1c7e9bfa44a224818dea85c06577
This commit is contained in:
Lucas Dupin
2018-03-28 02:09:56 +00:00
committed by android-build-merger
3 changed files with 32 additions and 0 deletions

View File

@@ -441,6 +441,9 @@ public class WallpaperManager {
synchronized (this) {
mCachedWallpaper = null;
mCachedWallpaperUserId = 0;
if (mDefaultWallpaper != null) {
mDefaultWallpaper.recycle();
}
mDefaultWallpaper = null;
}
}

View File

@@ -249,6 +249,18 @@ public class Surface implements Parcelable {
release();
}
/**
* Destroys the HwuiContext without completely
* releasing the Surface.
* @hide
*/
public void hwuiDestroy() {
if (mHwuiContext != null) {
mHwuiContext.destroy();
mHwuiContext = null;
}
}
/**
* Returns true if this object holds a valid surface.
*

View File

@@ -24,11 +24,13 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region.Op;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Trace;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.WindowManager;
@@ -45,6 +47,7 @@ public class ImageWallpaper extends WallpaperService {
private static final String GL_LOG_TAG = "ImageWallpaperGL";
private static final boolean DEBUG = false;
private static final String PROPERTY_KERNEL_QEMU = "ro.kernel.qemu";
private static final long DELAY_FORGET_WALLPAPER = 5000;
private WallpaperManager mWallpaperManager;
private DrawableEngine mEngine;
@@ -69,6 +72,10 @@ public class ImageWallpaper extends WallpaperService {
}
class DrawableEngine extends Engine {
private final Runnable mUnloadWallpaperCallback = () -> {
unloadWallpaper(false /* forgetSize */);
};
Bitmap mBackground;
int mBackgroundWidth = -1, mBackgroundHeight = -1;
int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
@@ -331,6 +338,7 @@ public class ImageWallpaper extends WallpaperService {
}
drawWallpaperWithCanvas(sh, availw, availh, xPixels, yPixels);
scheduleUnloadWallpaper();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
@@ -433,6 +441,9 @@ public class ImageWallpaper extends WallpaperService {
mBackgroundHeight = -1;
}
final Surface surface = getSurfaceHolder().getSurface();
surface.hwuiDestroy();
mLoader = new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
@@ -442,6 +453,12 @@ public class ImageWallpaper extends WallpaperService {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void scheduleUnloadWallpaper() {
Handler handler = getMainThreadHandler();
handler.removeCallbacks(mUnloadWallpaperCallback);
handler.postDelayed(mUnloadWallpaperCallback, DELAY_FORGET_WALLPAPER);
}
@Override
protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
super.dump(prefix, fd, out, args);