From f2a14ca2dd72e24052a300cfe3937b3f60c6a399 Mon Sep 17 00:00:00 2001 From: Vincent Wang Date: Thu, 24 Mar 2022 14:00:08 +0800 Subject: [PATCH] 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 --- .../server/WallpaperUpdateReceiver.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/services/core/java/com/android/server/WallpaperUpdateReceiver.java b/services/core/java/com/android/server/WallpaperUpdateReceiver.java index 629e88250a118..99178920cc528 100644 --- a/services/core/java/com/android/server/WallpaperUpdateReceiver.java +++ b/services/core/java/com/android/server/WallpaperUpdateReceiver.java @@ -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 + *

+ * 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; + } }