Get rid of usesSurfaceView check for Grid preview

We use SurfaceView preview only
Vedio: https://drive.google.com/file/d/1KRHNbYIqIn-fllHOLh5JXRcj9LTWoxRW/view?usp=sharing

Test: Manually
Fixes: 158161379
Change-Id: Ifaa3ef2fad5499e1fda779e1acdb039318705ca4
diff --git a/src/com/android/customization/model/grid/GridOptionsManager.java b/src/com/android/customization/model/grid/GridOptionsManager.java
index 84f5373..a0ae04c 100644
--- a/src/com/android/customization/model/grid/GridOptionsManager.java
+++ b/src/com/android/customization/model/grid/GridOptionsManager.java
@@ -61,11 +61,6 @@
         new FetchTask(mProvider, callback, reload).execute();
     }
 
-    /** See if using surface view to render grid options */
-    public boolean usesSurfaceView() {
-        return mProvider.usesSurfaceView();
-    }
-
     /** Call through content provider API to render preview */
     public Bundle renderPreview(Bundle bundle, String gridName) {
         return mProvider.renderPreview(gridName, bundle);
diff --git a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java
index 6a47f95..175f71a 100644
--- a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java
+++ b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java
@@ -21,7 +21,6 @@
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.os.Bundle;
-import android.text.TextUtils;
 import android.util.Pair;
 import android.view.SurfaceView;
 
@@ -71,11 +70,6 @@
         return mPreviewUtils.supportsPreview();
     }
 
-    boolean usesSurfaceView() {
-        // If no version code is returned, fall back to V1.
-        return TextUtils.equals(mVersion, "V2");
-    }
-
     /**
      * Retrieve the available grids.
      * @param reload whether to reload grid options if they're cached.
diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java
index fa6ab78..29c6ca8 100644
--- a/src/com/android/customization/picker/grid/GridFragment.java
+++ b/src/com/android/customization/picker/grid/GridFragment.java
@@ -19,7 +19,6 @@
 
 import static com.android.customization.picker.ViewOnlyFullPreviewActivity.SECTION_GRID;
 import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_GRID_OPTION;
-import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_GRID_USES_SURFACE_VIEW;
 import static com.android.customization.picker.grid.GridFullPreviewFragment.EXTRA_WALLPAPER_INFO;
 import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;
 
@@ -151,8 +150,8 @@
             wallpaperPreviewer.setWallpaper(mHomeWallpaper);
         }, false);
 
-        mGridOptionPreviewer = new GridOptionPreviewer(
-                getContext(), mGridManager, view.findViewById(R.id.grid_preview_container));
+        mGridOptionPreviewer = new GridOptionPreviewer(mGridManager,
+                view.findViewById(R.id.grid_preview_container));
 
         view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
             @Override
@@ -206,10 +205,6 @@
         mGridManager.apply(gridOption, mApplyGridCallback);
     }
 
-    private void updatePreview() {
-        mGridOptionPreviewer.setGridOption(mSelectedOption, mGridManager.usesSurfaceView());
-    }
-
     private void setUpOptions(@Nullable Bundle savedInstanceState) {
         hideError();
         mLoading.show();
@@ -222,7 +217,7 @@
                     mSelectedOption = (GridOption) selected;
                     mBottomActionBar.show();
                     mEventLogger.logGridSelected(mSelectedOption);
-                    updatePreview();
+                    mGridOptionPreviewer.setGridOption(mSelectedOption);
                 });
                 mOptionsController.initOptions(mGridManager);
 
@@ -286,7 +281,6 @@
         Bundle bundle = new Bundle();
         bundle.putParcelable(EXTRA_WALLPAPER_INFO, mHomeWallpaper);
         bundle.putParcelable(EXTRA_GRID_OPTION, mSelectedOption);
-        bundle.putBoolean(EXTRA_GRID_USES_SURFACE_VIEW, mGridManager.usesSurfaceView());
         Intent intent = ViewOnlyFullPreviewActivity.newIntent(getContext(), SECTION_GRID, bundle);
         startActivityForResult(intent, FULL_PREVIEW_REQUEST_CODE);
     }
diff --git a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java
index 2be77d6..27293d6 100644
--- a/src/com/android/customization/picker/grid/GridFullPreviewFragment.java
+++ b/src/com/android/customization/picker/grid/GridFullPreviewFragment.java
@@ -51,11 +51,9 @@
 
     static final String EXTRA_WALLPAPER_INFO = "wallpaper_info";
     static final String EXTRA_GRID_OPTION = "grid_option";
-    static final String EXTRA_GRID_USES_SURFACE_VIEW = "uses_surface_view";
 
     private WallpaperInfo mWallpaper;
     private GridOption mGridOption;
-    private boolean mUsesSurfaceView;
 
     private WallpaperPreviewer mWallpaperPreviewer;
     private GridOptionPreviewer mGridOptionPreviewer;
@@ -78,7 +76,6 @@
         super.onCreate(savedInstanceState);
         mWallpaper = getArguments().getParcelable(EXTRA_WALLPAPER_INFO);
         mGridOption = getArguments().getParcelable(EXTRA_GRID_OPTION);
-        mUsesSurfaceView = getArguments().getBoolean(EXTRA_GRID_USES_SURFACE_VIEW);
     }
 
     @Nullable
@@ -105,9 +102,8 @@
                         getString(R.string.grid_control_metadata_name)),
                 eventLogger);
 
-        ViewGroup gridPreviewContainer = view.findViewById(R.id.grid_preview_container);
-        mGridOptionPreviewer = new GridOptionPreviewer(
-                getContext(), gridManager, gridPreviewContainer);
+        mGridOptionPreviewer = new GridOptionPreviewer(gridManager,
+                view.findViewById(R.id.grid_preview_container));
 
         view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
             @Override
@@ -124,7 +120,7 @@
     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
         mWallpaperPreviewer.setWallpaper(mWallpaper);
-        mGridOptionPreviewer.setGridOption(mGridOption, mUsesSurfaceView);
+        mGridOptionPreviewer.setGridOption(mGridOption);
     }
 
     @Override
diff --git a/src/com/android/customization/picker/grid/GridOptionPreviewer.java b/src/com/android/customization/picker/grid/GridOptionPreviewer.java
index 49f2a16..5f6ef20 100644
--- a/src/com/android/customization/picker/grid/GridOptionPreviewer.java
+++ b/src/com/android/customization/picker/grid/GridOptionPreviewer.java
@@ -15,51 +15,41 @@
  */
 package com.android.customization.picker.grid;
 
-import android.content.Context;
 import android.os.Bundle;
 import android.os.Message;
 import android.os.RemoteException;
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
-import android.view.View;
 import android.view.ViewGroup;
-import android.widget.ImageView;
 
 import com.android.customization.model.grid.GridOption;
 import com.android.customization.model.grid.GridOptionsManager;
-import com.android.wallpaper.asset.Asset;
-import com.android.wallpaper.asset.ContentUriAsset;
 import com.android.wallpaper.util.SurfaceViewUtils;
 
-import com.bumptech.glide.request.RequestOptions;
-
 /** A class to load the {@link GridOption} preview to the view. */
 class GridOptionPreviewer {
 
-    private static final int PREVIEW_FADE_DURATION_MS = 100;
-
     private final WorkspaceSurfaceHolderCallback mSurfaceCallback =
             new WorkspaceSurfaceHolderCallback();
 
-    private final Context mContext;
     private final GridOptionsManager mGridManager;
     private final ViewGroup mPreviewContainer;
 
     private SurfaceView mGridOptionSurface;
     private GridOption mGridOption;
 
-    GridOptionPreviewer(Context context, GridOptionsManager gridManager,
-                        ViewGroup previewContainer) {
-        mContext = context;
+    GridOptionPreviewer(GridOptionsManager gridManager, ViewGroup previewContainer) {
         mGridManager = gridManager;
         mPreviewContainer = previewContainer;
     }
 
     /** Loads the Grid option into the container view. */
-    public void setGridOption(GridOption gridOption, boolean usesSurfaceView) {
+    public void setGridOption(GridOption gridOption) {
         mGridOption = gridOption;
-        updateWorkspacePreview(usesSurfaceView);
+        if (mGridOption != null) {
+            updateWorkspacePreview();
+        }
     }
 
     /** Releases the view resource. */
@@ -76,43 +66,21 @@
         mPreviewContainer.removeAllViews();
     }
 
-    private void updateWorkspacePreview(boolean usesSurfaceView) {
-        if (mGridOption == null) {
-            return;
-        }
+    private void updateWorkspacePreview() {
+        // Reattach SurfaceView to trigger #surfaceCreated to update preview for different option.
         mPreviewContainer.removeAllViews();
-
-        if (usesSurfaceView) {
-            mSurfaceCallback.mLastSurface = null;
-            if (mGridOptionSurface == null) {
-                mGridOptionSurface = new SurfaceView(mContext);
-                mGridOptionSurface.setZOrderMediaOverlay(true);
-                mGridOptionSurface.getHolder().addCallback(mSurfaceCallback);
-            }
-            addViewToContainer(mGridOptionSurface);
-        } else {
-            final ImageView previewImage = new ImageView(mContext);
-            addViewToContainer(previewImage);
-            final Asset previewAsset = new ContentUriAsset(
-                    mContext,
-                    mGridOption.previewImageUri,
-                    RequestOptions.fitCenterTransform());
-            previewAsset.loadDrawableWithTransition(mContext,
-                    previewImage /* imageView */,
-                    PREVIEW_FADE_DURATION_MS /* duration */,
-                    null /* drawableLoadedListener */,
-                    mContext.getResources().getColor(android.R.color.transparent,
-                            null) /* placeHolderColorJ */);
+        mSurfaceCallback.mLastSurface = null;
+        if (mGridOptionSurface == null) {
+            mGridOptionSurface = new SurfaceView(mPreviewContainer.getContext());
+            mGridOptionSurface.setLayoutParams(new ViewGroup.LayoutParams(
+                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+            mGridOptionSurface.setZOrderMediaOverlay(true);
+            mGridOptionSurface.getHolder().addCallback(mSurfaceCallback);
         }
+        mPreviewContainer.addView(mGridOptionSurface);
     }
 
-    private void addViewToContainer(View view) {
-        view.setLayoutParams(new ViewGroup.LayoutParams(
-                ViewGroup.LayoutParams.MATCH_PARENT,
-                ViewGroup.LayoutParams.MATCH_PARENT));
-        mPreviewContainer.addView(view);
-    }
-
+    // TODO(158163054): Refactor and use with WorkspaceSurfaceHolderCallback.
     private class WorkspaceSurfaceHolderCallback implements SurfaceHolder.Callback {
         private Surface mLastSurface;
         private Message mCallback;