Skip reset wallpaper operation if users have changed wallpaper
Test: 1. Change default wallpaper to live wallpaper or other images
2. adb root
3. adb shell am broadcast -a android.intent.action.DEVICE_CUSTOMIZATION_READY -f 0x01000000
4. Make sure wallpaper won't be reset
BUG: 159673283
Change-Id: Ic21b03df185b0e47ae9755b8bf9e27288c16c77a
This commit is contained in:
@@ -16,13 +16,17 @@
|
||||
|
||||
package com.android.server;
|
||||
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.WallpaperInfo;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Slog;
|
||||
|
||||
/**
|
||||
@@ -50,6 +54,10 @@ public class WallpaperUpdateReceiver extends BroadcastReceiver {
|
||||
ActivityThread currentActivityThread = ActivityThread.currentActivityThread();
|
||||
Context uiContext = currentActivityThread.getSystemUiContext();
|
||||
WallpaperManager wallpaperManager = WallpaperManager.getInstance(uiContext);
|
||||
if (isUserSetWallpaper(wallpaperManager, uiContext)) {
|
||||
Slog.i(TAG, "User has set wallpaper, skip to resetting");
|
||||
return;
|
||||
}
|
||||
if (DEBUG) Slog.d(TAG, "Set customized default_wallpaper.");
|
||||
Bitmap blank = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
|
||||
// set a blank wallpaper to force a redraw of default_wallpaper
|
||||
@@ -59,4 +67,32 @@ public class WallpaperUpdateReceiver extends BroadcastReceiver {
|
||||
Slog.w(TAG, "Failed to customize system wallpaper." + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to validate if users have set customized (live)wallpaper
|
||||
* <p>
|
||||
* return true if users have customized their wallpaper
|
||||
**/
|
||||
@RequiresPermission(android.Manifest.permission.READ_WALLPAPER_INTERNAL)
|
||||
private boolean isUserSetWallpaper(WallpaperManager wm, Context context) {
|
||||
WallpaperInfo info = wm.getWallpaperInfo();
|
||||
if (info == null) {
|
||||
//Image Wallpaper
|
||||
ParcelFileDescriptor sysWallpaper =
|
||||
wm.getWallpaperFile(WallpaperManager.FLAG_SYSTEM);
|
||||
ParcelFileDescriptor lockWallpaper =
|
||||
wm.getWallpaperFile(WallpaperManager.FLAG_LOCK);
|
||||
if (sysWallpaper != null || lockWallpaper != null) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
//live wallpaper
|
||||
ComponentName currCN = info.getComponent();
|
||||
ComponentName defaultCN = WallpaperManager.getDefaultWallpaperComponent(context);
|
||||
if (!currCN.equals(defaultCN)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user