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

Commit 1f77af99 authored by Roman Birg's avatar Roman Birg
Browse files

frameworks: add keyguard wallpaper functionality to WallpaperManager



Adapted for cm-12.

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

    /**
     * Set the keyguard wallpaper.
     * @hide
     */
    ParcelFileDescriptor setKeyguardWallpaper(String name);
    
    /**
     * Set the live wallpaper.
     */
@@ -42,6 +48,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.
     */
@@ -52,6 +65,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();
}
+144 −2
Original line number Diff line number Diff line
@@ -32,6 +32,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;
@@ -226,6 +227,7 @@ public class WallpaperManager {
        private IWallpaperManager mService;
        private Bitmap mWallpaper;
        private Bitmap mDefaultWallpaper;
        private Bitmap mKeyguardWallpaper;
        
        private static final int MSG_CLEAR_WALLPAPER = 1;

@@ -246,6 +248,12 @@ public class WallpaperManager {
            }
        }

        public void onKeyguardWallpaperChanged() {
            synchronized (this) {
                mKeyguardWallpaper = null;
            }
        }

        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) {
            synchronized (this) {
                if (mWallpaper != null) {
@@ -272,6 +280,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;
@@ -309,6 +334,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) {
            InputStream is = openDefaultWallpaper(context);
            if (is != null) {
@@ -327,6 +378,18 @@ public class WallpaperManager {
            }
            return null;
        }

        /** @hide */
        public void clearKeyguardWallpaper() {
            synchronized (this) {
                try {
                    mService.clearKeyguardWallpaper();
                } catch (RemoteException e) {
                    // ignore
                }
                mKeyguardWallpaper = null;
            }
        }
    }
    
    private static final Object sSync = new Object[0];
@@ -586,6 +649,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.
@@ -610,6 +682,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
@@ -770,6 +849,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
@@ -809,6 +917,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];
@@ -1089,6 +1224,13 @@ public class WallpaperManager {
        setStream(openDefaultWallpaper(mContext));
    }

    /**
     * @hide
     */
    public void clearKeyguardWallpaper() {
        sGlobals.clearKeyguardWallpaper();
    }

    /**
     * Open stream representing the default static image wallpaper.
     *
+9 −0
Original line number Diff line number Diff line
@@ -1847,6 +1847,15 @@ public class Intent implements Parcelable, Cloneable {
     */
    @Deprecated @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";

    /**
     * Broadcast Action: The current keyguard wallpaper configuration
     * has changed and should be re-read.
     * {@hide}
     */
    public static final String ACTION_KEYGUARD_WALLPAPER_CHANGED =
            "android.intent.action.KEYGUARD_WALLPAPER_CHANGED";

    /**
     * Broadcast Action: The current device {@link android.content.res.Configuration}
     * (orientation, locale, etc) has changed.  When such a change happens, the
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ interface IWindowManager
    boolean inKeyguardRestrictedInputMode();
    void dismissKeyguard();
    void keyguardGoingAway(boolean disableWindowAnimations,
            boolean keyguardGoingToNotificationShade);
            boolean keyguardGoingToNotificationShade, boolean keyguardShowingMedia);

    void closeSystemDialogs(String reason);

Loading