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

Commit 565a22d7 authored by Roman Birg's avatar Roman Birg Committed by Steve Kondik
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 46bb690e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2096,7 +2096,7 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM

        case KEYGUARD_GOING_AWAY_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            keyguardGoingAway(data.readInt() != 0, data.readInt() != 0);
            keyguardGoingAway(data.readInt() != 0, data.readInt() != 0, data.readInt() != 0);
            reply.writeNoException();
            return true;
        }
@@ -5263,12 +5263,14 @@ class ActivityManagerProxy implements IActivityManager
    }

    public void keyguardGoingAway(boolean disableWindowAnimations,
            boolean keyguardGoingToNotificationShade) throws RemoteException {
            boolean keyguardGoingToNotificationShade,
            boolean keyguardShowingMedia) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeInt(disableWindowAnimations ? 1 : 0);
        data.writeInt(keyguardGoingToNotificationShade ? 1 : 0);
        data.writeInt(keyguardShowingMedia ? 1 : 0);
        mRemote.transact(KEYGUARD_GOING_AWAY_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
+2 −1
Original line number Diff line number Diff line
@@ -411,7 +411,8 @@ public interface IActivityManager extends IInterface {
    public void keyguardWaitingForActivityDrawn() throws RemoteException;

    public void keyguardGoingAway(boolean disableWindowAnimations,
            boolean keyguardGoingToNotificationShade) throws RemoteException;
            boolean keyguardGoingToNotificationShade,
            boolean keyguardShowingMedia) throws RemoteException;

    public boolean shouldUpRecreateTask(IBinder token, String destAffinity)
            throws RemoteException;
+19 −0
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ interface IWallpaperManager {
     */
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage);

    /**
     * Set the keyguard wallpaper.
     * @hide
     */
    ParcelFileDescriptor setKeyguardWallpaper(String name, in String callingPackage);
    
    /**
     * Set the live wallpaper.
     */
@@ -47,6 +53,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.
     */
@@ -57,6 +70,12 @@ interface IWallpaperManager {
     */
    void clearWallpaper(in String callingPackage);

    /*
     * 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();
}
+146 −2
Original line number Diff line number Diff line
@@ -33,6 +33,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;
@@ -230,6 +231,7 @@ public class WallpaperManager {
        private IWallpaperManager mService;
        private Bitmap mWallpaper;
        private Bitmap mDefaultWallpaper;
        private Bitmap mKeyguardWallpaper;
        
        private static final int MSG_CLEAR_WALLPAPER = 1;

@@ -250,6 +252,12 @@ public class WallpaperManager {
            }
        }

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

        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) {
            synchronized (this) {
                if (mService != null) {
@@ -285,6 +293,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;
@@ -322,6 +347,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) {
@@ -340,6 +391,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];
@@ -599,6 +662,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.
@@ -623,6 +695,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
@@ -786,6 +865,36 @@ 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,
                    mContext.getOpPackageName());
            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
@@ -826,6 +935,34 @@ 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,
                    mContext.getOpPackageName());
            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];
@@ -1165,6 +1302,13 @@ public class WallpaperManager {
        setStream(openDefaultWallpaper(mContext));
    }

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

    /**
     * Open stream representing the default static image wallpaper.
     *
Loading