最近编译Android 7.1,编译完后系统中设置的壁纸不能正常显示
修改位置:7.1SDK/packages/apps/WallpaperPicker/src/com/android/wallpaperpicker/WallpaperUtils.java
// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects
- final int defaultWidth, defaultHeight;
+ int defaultWidth, defaultHeight;
if (res.getConfiguration().smallestScreenWidthDp >= 720) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
@@ -145,6 +145,8 @@ public final class WallpaperUtils {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
+ defaultWidth = maxDim;
+ defaultHeight = minDim;
sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
}
return sDefaultWallpaperSize;
修改位置:7.1SDK/frameworks/base/core/java/android/app/WallpaperManager.java
@@ -55,6 +55,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
+import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import libcore.io.IoUtils;
@@ -310,7 +311,7 @@ public class WallpaperManager {
mCachedWallpaper = null;
mCachedWallpaperUserId = 0;
try {
- mCachedWallpaper = getCurrentWallpaperLocked(userId);
+ mCachedWallpaper = getCurrentWallpaperLocked(context, userId);
mCachedWallpaperUserId = userId;
} catch (OutOfMemoryError e) {
Log.w(TAG, "No memory load current wallpaper", e);
@@ -342,7 +343,7 @@ public class WallpaperManager {
}
}
- private Bitmap getCurrentWallpaperLocked(int userId) {
+ private Bitmap getCurrentWallpaperLocked(Context context, int userId) {
if (mService == null) {
Log.w(TAG, "WallpaperService not running");
return null;
@@ -354,7 +355,14 @@ public class WallpaperManager {
params, userId);
if (fd != null) {
try {
+ WindowManager mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
+ int wW = mWindowManager.getDefaultDisplay().getWidth();
+ int wH = mWindowManager.getDefaultDisplay().getHeight();
BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, options);
+ options.inSampleSize = calculateInSampleSize(options, wW, wH);
+ options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(
fd.getFileDescriptor(), null, options);
} catch (OutOfMemoryError e) {
@@ -368,6 +376,18 @@ public class WallpaperManager {
}
return null;
}
+
+ private int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight){
+ int width = options.outWidth;
+ int height = options.outHeight;
+ int inSampleSize = 1;
+ if (width > reqWidth && height > reqHeight) {
+ int widthRatio = Math.round((float) width / (float) reqWidth);
+ int heightRatio = Math.round((float) width / (float) reqWidth);
+ inSampleSize = Math.max(widthRatio, heightRatio);
+ }
+ return inSampleSize;
+ }
private Bitmap getDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
InputStream is = openDefaultWallpaper(context, which);
修改位置:7.1SDK/frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
@@ -229,7 +229,7 @@ public class ImageWallpaper extends WallpaperService {
surfaceHeight = Math.max(displayInfo.logicalHeight, mBackgroundHeight);
}
- if (FIXED_SIZED_SURFACE) {
+ if (false) {
// Used a fixed size surface, because we are special. We can do
// this because we know the current design of window animations doesn't
// cause this to break.
修改之后,系统默认设置的壁纸可以正常显示。剩下的问题还在探索中。