wallpaper setting wallpaper picture is stretched

Time:
Before 2021/04/07, the company does not allow csdn, and the notes are written elsewhere. recently tidied up

Problem Description:

原生壁纸设置壁纸之后,图片被拉伸。导出/data/system/users/0/wallpaper_info.xml

The mobile phone resolution is 480 854 and the wallpaper is set to 2 480 * 854

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<wp id="10" width="960" height="854" cropLeft="0" cropTop="0" cropRight="0" cropBottom="0" colorsCount="3" colorValue0="-13485218" colorValue1="-801681" colorValue2="-2239870" colorHints="4" name="" />

Repair plan

1. Width and height calculation in wallpaper code
packages/apps/WallpaperPicker2/src/com/android/wallpaper/util/WallpaperCropUtils.java

public static Point getDefaultCropSurfaceSize(Resources resources, Display display, boolean scroll) {
    
    
    Point minDims = new Point();
    Point maxDims = new Point();
    display.getCurrentSizeRange(minDims, maxDims);

    int maxDim = Math.max(maxDims.x, maxDims.y);
    int minDim = Math.max(minDims.x, minDims.y);

    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
    
    
        Point realSize = new Point();
        display.getRealSize(realSize);
        maxDim = Math.max(realSize.x, realSize.y);
        minDim = Math.min(realSize.x, realSize.y);
    }

    final int defaultWidth, defaultHeight;
    if (resources.getConfiguration().smallestScreenWidthDp >= 720) {
    
    
        defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
        defaultHeight = maxDim;
    } else {
    
    
        //这个值默认是2 WALLPAPER_SCREENS_SPAN 双屏壁纸
        defaultWidth = minDim;//scroll ? Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim) : minDim;
        defaultHeight = maxDim;
    }


    return new Point(defaultWidth, defaultHeight);
}

2. Set the wallpaper width and height in packages/apps/Launcher3/src/com/android/launcher3/Workspace.java

protected void setWallpaperDimension() {
    
    
    Executors.THREAD_POOL_EXECUTOR.execute(new Runnable() {
    
    
        @Override
        public void run() {
    
    
            final Point size = LauncherAppState.getIDP(getContext()).defaultWallpaperSize;
            if (size.x != mWallpaperManager.getDesiredMinimumWidth()
                    || size.y != mWallpaperManager.getDesiredMinimumHeight()) {
    
    
                mWallpaperManager.suggestDesiredDimensions(size.x, size.y);
            }
        }
    });
}

3. Calculate the wallpaper width and height according to the display size in frameworks/base/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java

loadSettingsLocked中:

private void ensureSaneWallpaperDisplaySize(DisplayData wpdData, int displayId) {
    
    
    // We always want to have some reasonable width hint.
    final int baseSize = getMaximumSizeDimension(displayId);
    final int width = getMinimumSizeDimension(displayId);//我自己加的
    Slog.i(TAG, "baseSize:" + baseSize + " width: "+width);
    Slog.i(TAG, "wpdData.mWidth:" + wpdData.mWidth + " wpdData.mHeight: "+wpdData.mHeight);
    if (wpdData.mWidth < width) {
    
    
        wpdData.mWidth = width;
    }
    if (wpdData.mHeight < baseSize) {
    
    
        wpdData.mHeight = baseSize;
    }
    Slog.w(TAG, "wpdData.mWidth:" + wpdData.mWidth + " wpdData.mHeight: "+wpdData.mHeight);
}

The above modification is invalid on android11
​​4. frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java

@Override
public boolean shouldZoomOutWallpaper() {
    
    //修改这里的返回值,并且修改WallpaperCropUtils中的修改,可以解决缩放问题
    return !SPRD_STABLE_WALLPAPER;
}

//默认会放大1.1倍
<!-- The max scale for the wallpaper when it's zoomed in -->
<item name="config_wallpaperMaxScale" format="float" type="dimen">1.10</item>

Guess you like

Origin blog.csdn.net/a396604593/article/details/129797207