Merge "Fix Launcher preview crash" into main
diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
index 051fb6f..db27832 100644
--- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
+++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
@@ -87,6 +87,7 @@
private final int mHeight;
private String mGridName;
+ private final int mDisplayId;
private final Display mDisplay;
private final WallpaperColors mWallpaperColors;
private final RunnableList mOnDestroyCallbacks = new RunnableList();
@@ -110,8 +111,12 @@
mHostToken = bundle.getBinder(KEY_HOST_TOKEN);
mWidth = bundle.getInt(KEY_VIEW_WIDTH);
mHeight = bundle.getInt(KEY_VIEW_HEIGHT);
+ mDisplayId = bundle.getInt(KEY_DISPLAY_ID);
mDisplay = context.getSystemService(DisplayManager.class)
- .getDisplay(bundle.getInt(KEY_DISPLAY_ID));
+ .getDisplay(mDisplayId);
+ if (mDisplay == null) {
+ throw new IllegalArgumentException("Display ID does not match any displays.");
+ }
mSurfaceControlViewHost = MAIN_EXECUTOR.submit(() ->
new SurfaceControlViewHost(mContext, context.getSystemService(DisplayManager.class)
@@ -121,7 +126,7 @@
}
public int getDisplayId() {
- return mDisplay.getDisplayId();
+ return mDisplayId;
}
public IBinder getHostToken() {