Fix non-visual Context in ImageWallpaper

Before, it tried to access WindowManager from a non-visual context. Now,
it should use a window context.

Bug: 187644235
Test: manual
Change-Id: I3994d7b86fd28598d375c1c8033d72bbc9a9fdcf
This commit is contained in:
Chris Li
2021-05-09 14:34:46 -07:00
parent 7e7c76c8a8
commit 4cb2859e93

View File

@@ -21,6 +21,7 @@ import static android.graphics.Matrix.MSCALE_Y;
import static android.graphics.Matrix.MSKEW_X;
import static android.graphics.Matrix.MSKEW_Y;
import static android.view.View.SYSTEM_UI_FLAG_VISIBLE;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import android.annotation.FloatRange;
import android.annotation.NonNull;
@@ -1218,7 +1219,9 @@ public abstract class WallpaperService extends Service {
mIWallpaperEngine.mDisplayManager.registerDisplayListener(mDisplayListener,
mCaller.getHandler());
mDisplay = mIWallpaperEngine.mDisplay;
mDisplayContext = createDisplayContext(mDisplay);
// Use window context of TYPE_WALLPAPER so client can access UI resources correctly.
mDisplayContext = createDisplayContext(mDisplay)
.createWindowContext(TYPE_WALLPAPER, null /* options */);
mDisplayState = mDisplay.getState();
if (DEBUG) Log.v(TAG, "onCreate(): " + this);