Snap for 6671412 from 6f6fb5127b5e38d191fda0a0fa187bbab9c1894b to rvc-d1-release

Change-Id: Ia27fd08bdc416e06d90a45e8539e28340eb64794
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index 184e1de..b1153bb 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -411,17 +411,15 @@
         int minCrop = Math.min(cropWidth, cropHeight);
         Point hostViewSize = new Point(cropWidth, cropHeight);
 
-        // Workaround for now to force wallpapers designed to fit one screen size to not adjust for
-        // parallax scrolling (with an extra 1 pixel to account for rounding)
-        // TODO (santie): implement a better solution
-        boolean shouldForceScreenSize = mRawWallpaperSize.x - mScreenSize.x <= 1;
         Resources res = context.getResources();
-        Point cropSurfaceSize = shouldForceScreenSize ? hostViewSize :
-                WallpaperCropUtils.calculateCropSurfaceSize(res, maxCrop, minCrop);
+        Point cropSurfaceSize = WallpaperCropUtils.calculateCropSurfaceSize(res, maxCrop, minCrop);
+        WallpaperCropUtils.scaleSize(context, hostViewSize);
+        WallpaperCropUtils.scaleSize(context, cropSurfaceSize);
+
+        WallpaperCropUtils.adjustCropRect(context, visibleFileRect, false);
 
         Rect cropRect = WallpaperCropUtils.calculateCropRect(context, hostViewSize,
                 cropSurfaceSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom);
-        WallpaperCropUtils.adjustCropRect(context, cropRect, false /* zoomIn */);
         return cropRect;
     }
 
diff --git a/src/com/android/wallpaper/picker/LivePreviewFragment.java b/src/com/android/wallpaper/picker/LivePreviewFragment.java
index c9f5e02..7af31ac 100644
--- a/src/com/android/wallpaper/picker/LivePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/LivePreviewFragment.java
@@ -123,7 +123,6 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         android.app.WallpaperInfo info = mWallpaper.getWallpaperComponent();
-        setUpExploreIntentAndLabel(null);
 
         String deleteAction = getDeleteAction(info);
         if (!TextUtils.isEmpty(deleteAction)) {
@@ -169,6 +168,12 @@
         mScreenSize = ScreenSizeCalculator.getInstance().getScreenSize(
                 activity.getWindowManager().getDefaultDisplay());
 
+        mWallpaperInfoView = (WallpaperInfoView) LayoutInflater.from(getContext())
+                .inflate(R.layout.wallpaper_info_view, /* root= */ null);
+        setUpExploreIntentAndLabel(
+                () -> mWallpaperInfoView.populateWallpaperInfo(mWallpaper, mActionLabel,
+                                mExploreIntent, this::onExploreClicked));
+
         mPreviewContainer = view.findViewById(R.id.live_wallpaper_preview);
         mTouchForwardingLayout = view.findViewById(R.id.touch_forwarding_layout);
         // Set aspect ratio on the preview card.
@@ -348,10 +353,6 @@
         super.onBottomActionBarReady(bottomActionBar);
         mBottomActionBar.showActionsOnly(INFORMATION, DELETE, CUSTOMIZE, APPLY);
         mBottomActionBar.setActionClickListener(APPLY, unused -> onSetWallpaperClicked(null));
-        mWallpaperInfoView = (WallpaperInfoView) LayoutInflater.from(getContext())
-                .inflate(R.layout.wallpaper_info_view, /* root= */ null);
-        mWallpaperInfoView.populateWallpaperInfo(mWallpaper, mActionLabel, mExploreIntent,
-                this::onExploreClicked);
         mBottomActionBar.attachViewToBottomSheetAndBindAction(mWallpaperInfoView, INFORMATION);
 
         // Update target view's accessibility param since it will be blocked by the bottom sheet
diff --git a/src/com/android/wallpaper/util/WallpaperConnection.java b/src/com/android/wallpaper/util/WallpaperConnection.java
index b4ddebc..1b5bdae 100644
--- a/src/com/android/wallpaper/util/WallpaperConnection.java
+++ b/src/com/android/wallpaper/util/WallpaperConnection.java
@@ -246,7 +246,7 @@
     private void setEngineVisibility(boolean visible) {
         if (mEngine != null && visible != mIsEngineVisible) {
             try {
-                mEngine.setVisibility(true);
+                mEngine.setVisibility(visible);
                 mIsEngineVisible = visible;
             } catch (RemoteException e) {
                 Log.w(TAG, "Failure setting wallpaper visibility ", e);
diff --git a/src/com/android/wallpaper/util/WallpaperCropUtils.java b/src/com/android/wallpaper/util/WallpaperCropUtils.java
index 920037b..a13ed55 100755
--- a/src/com/android/wallpaper/util/WallpaperCropUtils.java
+++ b/src/com/android/wallpaper/util/WallpaperCropUtils.java
@@ -263,7 +263,7 @@
         float centerY = cropRect.centerY();
         float width = cropRect.width();
         float height = cropRect.height();
-        float systemWallpaperMaxScale = WallpaperCropUtils.getSystemWallpaperMaximumScale(context);
+        float systemWallpaperMaxScale = getSystemWallpaperMaximumScale(context);
         float scale = zoomIn ? systemWallpaperMaxScale : 1.0f / systemWallpaperMaxScale;
 
         // Adjust the rect according to the system wallpaper's maximum scale.
@@ -274,6 +274,12 @@
         cropRect.set(left, top, right, bottom);
     }
 
+    /** Adjust the given Point, representing a size by  systemWallpaperMaxScale. */
+    public static void scaleSize(Context context, Point size) {
+        float systemWallpaperMaxScale = getSystemWallpaperMaximumScale(context);
+        size.set((int) (size.x * systemWallpaperMaxScale),
+                (int) (size.y * systemWallpaperMaxScale));
+    }
     /**
      * Calculates {@link Rect} of the wallpaper which we want to crop to in physical pixel terms
      * (i.e., scaled to current zoom) when the wallpaper is laid on a fullscreen view.