Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f33eb013 authored by Vincent Wang's avatar Vincent Wang Committed by Automerger Merge Worker
Browse files

Merge "Skip reset wallpaper operation if users have changed wallpaper" into...

Merge "Skip reset wallpaper operation if users have changed wallpaper" into tm-dev am: 2f48d97c am: 63c36fc6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17369584



Change-Id: I9b5225ff23d7a2a02870aa116a55dc66d2540d8e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6a718af8 63c36fc6
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -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;
    }
}