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

Commit be132e6e authored by Christopher Tate's avatar Christopher Tate
Browse files

Keyguard wallpaper

Clients can now set a lock-only wallpaper that Keyguard can
observe and choose to draw as appropriate.

Bug 25454162

Change-Id: I3fc30e02919e814b55dfded2a1a36ad9d2e55299
parent b4cbd54e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5721,6 +5721,7 @@ package android.app {
    method public android.graphics.drawable.Drawable getDrawable();
    method public android.graphics.drawable.Drawable getFastDrawable();
    method public static android.app.WallpaperManager getInstance(android.content.Context);
    method public android.os.ParcelFileDescriptor getWallpaperFile(int);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method public boolean hasResourceWallpaper(int);
    method public boolean isWallpaperSettingAllowed();
+2 −0
Original line number Diff line number Diff line
@@ -5844,6 +5844,7 @@ package android.app {
  public class WallpaperManager {
    method public void clear() throws java.io.IOException;
    method public void clearWallpaper();
    method public void clearWallpaper(int, int);
    method public void clearWallpaperOffsets(android.os.IBinder);
    method public void forgetLoadedWallpaper();
    method public android.graphics.drawable.Drawable getBuiltInDrawable();
@@ -5854,6 +5855,7 @@ package android.app {
    method public android.graphics.drawable.Drawable getDrawable();
    method public android.graphics.drawable.Drawable getFastDrawable();
    method public static android.app.WallpaperManager getInstance(android.content.Context);
    method public android.os.ParcelFileDescriptor getWallpaperFile(int);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method public boolean hasResourceWallpaper(int);
    method public boolean isWallpaperSettingAllowed();
+1 −0
Original line number Diff line number Diff line
@@ -5723,6 +5723,7 @@ package android.app {
    method public android.graphics.drawable.Drawable getDrawable();
    method public android.graphics.drawable.Drawable getFastDrawable();
    method public static android.app.WallpaperManager getInstance(android.content.Context);
    method public android.os.ParcelFileDescriptor getWallpaperFile(int);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method public boolean hasResourceWallpaper(int);
    method public boolean isWallpaperSettingAllowed();
+11 −5
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.content.ComponentName;
interface IWallpaperManager {

    /**
     * Set the wallpaper.
     * Set the wallpaper for the current user.
     *
     * If 'extras' is non-null, on successful return it will contain:
     *   EXTRA_SET_WALLPAPER_ID : integer ID that the new wallpaper will have
@@ -56,10 +56,10 @@ interface IWallpaperManager {
    void setWallpaperComponent(in ComponentName name);

    /**
     * Get the system wallpaper.
     * Get the wallpaper for a given user.
     */
    ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
            out Bundle outParams);
    ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb, int which,
            out Bundle outParams, int userId);

    /**
     * If the current system wallpaper is a live wallpaper component, return the
@@ -71,7 +71,7 @@ interface IWallpaperManager {
    /**
     * Clear the system wallpaper.
     */
    void clearWallpaper(in String callingPackage);
    void clearWallpaper(in String callingPackage, int which, int userId);

    /**
     * Return whether the current system wallpaper has the given name.
@@ -118,4 +118,10 @@ interface IWallpaperManager {
     * Check whether setting of wallpapers are allowed for the calling user.
     */
    boolean isWallpaperSettingAllowed(in String callingPackage);

    /*
     * Keyguard: register a callback for being notified that lock-state relevant
     * wallpaper content has changed.
     */
    boolean setLockWallpaperCallback(IWallpaperManagerCallback cb);
}
+77 −14
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
h * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManagerGlobal;
@@ -265,11 +266,10 @@ public class WallpaperManager {
        private Bitmap mWallpaper;
        private Bitmap mDefaultWallpaper;

        private static final int MSG_CLEAR_WALLPAPER = 1;

        Globals(Looper looper) {
            IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
            mService = IWallpaperManager.Stub.asInterface(b);
            forgetLoadedWallpaper();
        }

        public void onWallpaperChanged() {
@@ -278,10 +278,7 @@ public class WallpaperManager {
             * to null so if the user requests the wallpaper again then we'll
             * fetch it.
             */
            synchronized (this) {
                mWallpaper = null;
                mDefaultWallpaper = null;
            }
            forgetLoadedWallpaper();
        }

        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) {
@@ -334,7 +331,8 @@ public class WallpaperManager {

            try {
                Bundle params = new Bundle();
                ParcelFileDescriptor fd = mService.getWallpaper(this, params);
                ParcelFileDescriptor fd = mService.getWallpaper(this, FLAG_SET_SYSTEM,
                        params, context.getUserId());
                if (fd != null) {
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
@@ -649,6 +647,42 @@ public class WallpaperManager {
        return sGlobals.peekWallpaperBitmap(mContext, true);
    }

    /**
     * Get an open, readable file descriptor to the given wallpaper image file.
     * The callee is resopnsible for closing the fd when done ingesting the file.
     *
     * <p>If no lock-specific wallpaper has been configured for the given user, then
     * this method will return {@code null} when requesting {@link #FLAG_SET_LOCK} rather than
     * returning the system wallpaper's image file.
     */
    public ParcelFileDescriptor getWallpaperFile(int which) {
        return getWallpaperFile(which, mContext.getUserId());
    }

    /**
     * Version of {@link #getWallpaperFile(int)} that can access the wallpaper data
     * for a given user.  The caller must hold the INTERACT_ACROSS_USERS_FULL
     * permission to access another user's wallpaper data.
     * @hide
     */
    public ParcelFileDescriptor getWallpaperFile(int which, int userId) {
        if (which != FLAG_SET_SYSTEM && which != FLAG_SET_LOCK) {
            throw new IllegalArgumentException("Must request exactly one kind of wallpaper");
        }

        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return null;
        } else {
            try {
                Bundle outParams = new Bundle();
                return sGlobals.mService.getWallpaper(null, which, outParams, userId);
            } catch (RemoteException e) {
                return null;
            }
        }
    }

    /**
     * Remove all internal references to the last loaded wallpaper.  Useful
     * for apps that want to reduce memory usage when they only temporarily
@@ -656,10 +690,8 @@ public class WallpaperManager {
     * wallpaper will require reloading it again from disk.
     */
    public void forgetLoadedWallpaper() {
        if (isWallpaperSupported()) {
        sGlobals.forgetLoadedWallpaper();
    }
    }

    /**
     * If the current wallpaper is a live wallpaper component, return the
@@ -1209,12 +1241,23 @@ public class WallpaperManager {
     */
    @SystemApi
    public void clearWallpaper() {
        clearWallpaper(FLAG_SET_SYSTEM, mContext.getUserId());
    }

    /**
     * Clear the wallpaper for a specific user.  The caller must hold the
     * INTERACT_ACROSS_USERS_FULL permission to clear another user's
     * wallpaper.
     * @hide
     */
    @SystemApi
    public void clearWallpaper(int which, int userId) {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
        }
        try {
            sGlobals.mService.clearWallpaper(mContext.getOpPackageName());
            sGlobals.mService.clearWallpaper(mContext.getOpPackageName(), which, userId);
        } catch (RemoteException e) {
            // Ignore
        }
@@ -1363,7 +1406,7 @@ public class WallpaperManager {
    }

    /**
     * Remove any currently set wallpaper, reverting to the system's built-in
     * Remove any currently set system wallpaper, reverting to the system's built-in
     * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
     * is broadcast.
     *
@@ -1424,6 +1467,26 @@ public class WallpaperManager {
        return null;
    }

    /**
     * Register a callback for lock wallpaper observation. Only the OS may use this.
     *
     * @return true on success; false on error.
     * @hide
     */
    public boolean setLockWallpaperCallback(IWallpaperManagerCallback callback) {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return false;
        }

        try {
            return sGlobals.mService.setLockWallpaperCallback(callback);
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to contact wallpaper service");
        }
        return false;
    }

    // Private completion callback for setWallpaper() synchronization
    private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub {
        final CountDownLatch mLatch;
Loading