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

Commit 89e4d54d authored by Roman Birg's avatar Roman Birg Committed by Abhisek Devkota
Browse files

frameworks: move keyguard wallpaper to system (1/2)



Change-Id: I0eb1b5578b705c2ade4c0772fa86e09478b9f73e
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 71aed47c
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -30,6 +30,12 @@ interface IWallpaperManager {
     */
    ParcelFileDescriptor setWallpaper(String name);

    /**
     * Set the keyguard wallpaper.
     * @hide
     */
    ParcelFileDescriptor setKeyguardWallpaper(String name);
    
    /**
     * Set the live wallpaper.
     */
@@ -41,6 +47,13 @@ interface IWallpaperManager {
    ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
            out Bundle outParams);

    /**
     * Get the keyguard wallpaper.
     * @hide
     */
    ParcelFileDescriptor getKeyguardWallpaper(IWallpaperManagerCallback cb,
            out Bundle outParams);
    
    /**
     * Get information about a live wallpaper.
     */
@@ -51,6 +64,12 @@ interface IWallpaperManager {
     */
    void clearWallpaper();

    /*
     * Clear the keyguard wallpaper.
     * @hide
     */
    void clearKeyguardWallpaper();

    /**
     * Return whether there is a wallpaper set with the given name.
     */
+5 −0
Original line number Diff line number Diff line
@@ -28,4 +28,9 @@ oneway interface IWallpaperManagerCallback {
     * Called when the wallpaper has changed
     */
    void onWallpaperChanged();

    /**
     * Called when the keygaurd wallpaper has changed
     */
     void onKeyguardWallpaperChanged();
}
+147 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
@@ -220,8 +221,10 @@ public class WallpaperManager {
        private IWallpaperManager mService;
        private Bitmap mWallpaper;
        private Bitmap mDefaultWallpaper;
        private Bitmap mKeyguardwallpaper;
        
        private static final int MSG_CLEAR_WALLPAPER = 1;
        private static final int MSG_CLEAR_KEYGUARD_WALLPAPER = 2;
        
        private final Handler mHandler;
        
@@ -238,6 +241,11 @@ public class WallpaperManager {
                                mDefaultWallpaper = null;
                            }
                            break;
                        case MSG_CLEAR_KEYGUARD_WALLPAPER:
                            synchronized (this) {
                                mKeyguardwallpaper = null;
                            }
                            break;
                    }
                }
            };
@@ -252,6 +260,10 @@ public class WallpaperManager {
            mHandler.sendEmptyMessage(MSG_CLEAR_WALLPAPER);
        }

        public void onKeyguardWallpaperChanged() {
            mHandler.sendEmptyMessage(MSG_CLEAR_KEYGUARD_WALLPAPER);
        }

        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) {
            synchronized (this) {
                if (mWallpaper != null) {
@@ -278,6 +290,23 @@ public class WallpaperManager {
            }
        }

        /**
         * @hide
         */
        public Bitmap peekKeyguardWallpaperBitmap(Context context) {
            synchronized (this) {
                if (mKeyguardwallpaper != null) {
                    return mKeyguardwallpaper;
                }
                try {
                    mKeyguardwallpaper = getCurrentKeyguardWallpaperLocked(context);
                } catch (OutOfMemoryError e) {
                    Log.w(TAG, "No memory load current keyguard wallpaper", e);
                }
                return mKeyguardwallpaper;
            }
        }

        public void forgetLoadedWallpaper() {
            synchronized (this) {
                mWallpaper = null;
@@ -315,6 +344,32 @@ public class WallpaperManager {
            return null;
        }

        private Bitmap getCurrentKeyguardWallpaperLocked(Context context) {
            try {
                Bundle params = new Bundle();
                ParcelFileDescriptor fd = mService.getKeyguardWallpaper(this, params);
                if (fd != null) {
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        Bitmap bm = BitmapFactory.decodeFileDescriptor(
                                fd.getFileDescriptor(), null, options);
                        return bm;
                    } catch (OutOfMemoryError e) {
                        Log.w(TAG, "Can't decode file", e);
                    } finally {
                        try {
                            fd.close();
                        } catch (IOException e) {
                            // Ignore
                        }
                    }
                }
            } catch (RemoteException e) {
                // Ignore
            }
            return null;
        }

        private Bitmap getDefaultWallpaperLocked(Context context) {
            try {
                InputStream is = context.getResources().openRawResource(
@@ -342,6 +397,18 @@ public class WallpaperManager {
            }
            return null;
        }

        public void clearKeyguardWallpaper() {
            synchronized (this) {
                try {
                    mService.clearKeyguardWallpaper();
                } catch (RemoteException e) {
                    // ignore
                }
                mKeyguardwallpaper = null;
                mHandler.removeMessages(MSG_CLEAR_KEYGUARD_WALLPAPER);
            }
        }
    }
    
    private static final Object sSync = new Object[0];
@@ -604,6 +671,15 @@ public class WallpaperManager {
        return null;
    }

    /** @hide */
    public Drawable getFastKeyguardDrawable() {
        Bitmap bm = sGlobals.peekKeyguardWallpaperBitmap(mContext);
        if (bm != null) {
            return new FastBitmapDrawable(bm);
        }
        return null;
    }

    /**
     * Like {@link #getFastDrawable()}, but if there is no wallpaper set,
     * a null pointer is returned.
@@ -628,6 +704,13 @@ public class WallpaperManager {
        return sGlobals.peekWallpaperBitmap(mContext, true);
    }

    /**
     * @hide
     */
    public Bitmap getKeyguardBitmap() {
        return sGlobals.peekKeyguardWallpaperBitmap(mContext);
    }

    /**
     * Remove all internal references to the last loaded wallpaper.  Useful
     * for apps that want to reduce memory usage when they only temporarily
@@ -784,6 +867,35 @@ public class WallpaperManager {
        }
    }

    /**
     * @param bitmap
     * @throws IOException
     * @hide
     */
    public void setKeyguardBitmap(Bitmap bitmap) throws IOException {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
        }
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setKeyguardWallpaper(null);
            if (fd == null) {
                return;
            }
            FileOutputStream fos = null;
            try {
                fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
            } finally {
                if (fos != null) {
                    fos.close();
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }

    /**
     * Change the current system wallpaper to a specific byte stream.  The
     * give InputStream is copied into persistent storage and will now be
@@ -823,6 +935,33 @@ public class WallpaperManager {
        }
    }

    /**
     * @hide
     */
    public void setKeyguardStream(InputStream data) throws IOException {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
        }
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setKeyguardWallpaper(null);
            if (fd == null) {
                return;
            }
            FileOutputStream fos = null;
            try {
                fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                setWallpaper(data, fos);
            } finally {
                if (fos != null) {
                    fos.close();
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }

    private void setWallpaper(InputStream data, FileOutputStream fos)
            throws IOException {
        byte[] buffer = new byte[32768];
@@ -1067,6 +1206,13 @@ public class WallpaperManager {
        setResource(com.android.internal.R.drawable.default_wallpaper);
    }

    /**
     * @hide
     */
    public void clearKeyguardWallpaper() {
        sGlobals.clearKeyguardWallpaper();
    }
    
    static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
        if (bm == null) {
            return null;
+0 −9
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import android.text.TextUtils;
import android.util.AndroidException;
import android.util.Log;

import com.android.internal.util.cm.LockscreenBackgroundUtil;
import com.android.internal.widget.ILockSettings;

import java.net.URISyntaxException;
@@ -3253,14 +3252,6 @@ public final class Settings {
         */
        public static final String QUIET_HOURS_DIM = "quiet_hours_dim";

        /**
         * Sets the lockscreen background style. Integer.
         * @see LockscreenBackgroundUtil#LOCKSCREEN_STYLE_DEFAULT
         * @see LockscreenBackgroundUtil#LOCKSCREEN_STYLE_IMAGE
         * @hide
         */
        public static final String LOCKSCREEN_BACKGROUND_STYLE = "lockscreen_background_style";

         /**
         * Action for long-pressing back button on lock screen
         * @hide
+0 −39
Original line number Diff line number Diff line
package com.android.internal.util.cm;

import java.io.File;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.provider.Settings;

/**
 * @hide
 */
public class LockscreenBackgroundUtil {

    public static final int LOCKSCREEN_STYLE_IMAGE = 1;
    public static final int LOCKSCREEN_STYLE_DEFAULT = 0;

    private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
    private static final String LOCKSCREEN_WALLPAPER_FILE_NAME = "lockwallpaper";

    public static File getWallpaperFile(Context ctx) {
        Context settingsContext = null;
        if (ctx.getPackageName().equals(SETTINGS_PACKAGE_NAME)) {
            settingsContext = ctx;
        } else {
            try {
                settingsContext = ctx.createPackageContext(SETTINGS_PACKAGE_NAME, 0);
            } catch (NameNotFoundException e) {
                // Settings package doesn't exist.
                return null;
            }
        }
        return new File(settingsContext.getFilesDir(), LOCKSCREEN_WALLPAPER_FILE_NAME);
    }

    public static int getLockscreenStyle(Context ctx) {
        return Settings.System.getInt(ctx.getContentResolver(),
                Settings.System.LOCKSCREEN_BACKGROUND_STYLE, LOCKSCREEN_STYLE_DEFAULT);
    }
}
Loading