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

Commit 0cd48879 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

A little more wallpaper robustness.

- Recover if a live wallpaper is crashing repeatedly.
- Don't crash when someone tries to set a static wallpaper.
- Make the static wallpaper update correctly when the image changes.
parent 1d47a514
Loading
Loading
Loading
Loading
+9 −8
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ public class ImageWallpaper extends WallpaperService {
    class WallpaperObserver extends BroadcastReceiver {
    class WallpaperObserver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            mEngine.updateWallpaper();
            mEngine.updateWallpaper();
            mEngine.drawFrame();
        }
        }
    }
    }


@@ -72,14 +73,7 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            super.onCreate(surfaceHolder);
            mBackground = mWallpaperManager.getDrawable();
            updateWallpaper();
            mBounds.left = mBounds.top = 0;
            mBounds.right = mBackground.getIntrinsicWidth();
            mBounds.bottom = mBackground.getIntrinsicHeight();
            int offx = (getDesiredMinimumWidth() - mBounds.right) / 2;
            int offy = (getDesiredMinimumHeight() - mBounds.bottom) / 2;
            mBounds.offset(offx, offy);
            mBackground.setBounds(mBounds);
            surfaceHolder.setSizeFromLayout();
            surfaceHolder.setSizeFromLayout();
        }
        }


@@ -131,6 +125,13 @@ public class ImageWallpaper extends WallpaperService {
        void updateWallpaper() {
        void updateWallpaper() {
            synchronized (mLock) {
            synchronized (mLock) {
                mBackground = mWallpaperManager.getDrawable();
                mBackground = mWallpaperManager.getDrawable();
                mBounds.left = mBounds.top = 0;
                mBounds.right = mBackground.getIntrinsicWidth();
                mBounds.bottom = mBackground.getIntrinsicHeight();
                int offx = (getDesiredMinimumWidth() - mBounds.right) / 2;
                int offy = (getDesiredMinimumHeight() - mBounds.bottom) / 2;
                mBounds.offset(offx, offy);
                mBackground.setBounds(mBounds);
            }
            }
        }
        }
    }
    }
+36 −9
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.FileObserver;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.RemoteCallbackList;
import android.os.RemoteCallbackList;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperEngine;
import android.service.wallpaper.IWallpaperEngine;
import android.service.wallpaper.IWallpaperService;
import android.service.wallpaper.IWallpaperService;
@@ -68,10 +69,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub {


    Object mLock = new Object();
    Object mLock = new Object();


    private static final File WALLPAPER_DIR = new File(
    /**
     * Minimum time between crashes of a wallpaper service for us to consider
     * restarting it vs. just reverting to the static wallpaper.
     */
    static final long MIN_WALLPAPER_CRASH_TIME = 10000;
    
    static final File WALLPAPER_DIR = new File(
            "/data/data/com.android.settings/files");
            "/data/data/com.android.settings/files");
    private static final String WALLPAPER = "wallpaper";
    static final String WALLPAPER = "wallpaper";
    private static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER);
    static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER);


    /**
    /**
     * List of callbacks registered they should each be notified
     * List of callbacks registered they should each be notified
@@ -116,6 +123,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
    String mName = "";
    String mName = "";
    ComponentName mWallpaperComponent;
    ComponentName mWallpaperComponent;
    WallpaperConnection mWallpaperConnection;
    WallpaperConnection mWallpaperConnection;
    long mLastDiedTime;
    
    
    class WallpaperConnection extends IWallpaperConnection.Stub
    class WallpaperConnection extends IWallpaperConnection.Stub
            implements ServiceConnection {
            implements ServiceConnection {
@@ -136,6 +144,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
            synchronized (mLock) {
            synchronized (mLock) {
                mService = null;
                mService = null;
                mEngine = null;
                mEngine = null;
                if (mWallpaperConnection == this) {
                    Log.w(TAG, "Wallpaper service gone: " + mWallpaperComponent);
                    if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
                            < SystemClock.uptimeMillis()) {
                        Log.w(TAG, "Reverting to built-in wallpaper!");
                        bindWallpaperComponentLocked(null);
                    }
                }
            }
            }
        }
        }
        
        
@@ -195,7 +211,12 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
            if (f.exists()) {
            if (f.exists()) {
                f.delete();
                f.delete();
            }
            }
            final long ident = Binder.clearCallingIdentity();
            try {
                bindWallpaperComponentLocked(null);
                bindWallpaperComponentLocked(null);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
        }
    }
    }


@@ -247,12 +268,17 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
    public ParcelFileDescriptor setWallpaper(String name) {
    public ParcelFileDescriptor setWallpaper(String name) {
        checkPermission(android.Manifest.permission.SET_WALLPAPER);
        checkPermission(android.Manifest.permission.SET_WALLPAPER);
        synchronized (mLock) {
        synchronized (mLock) {
            final long ident = Binder.clearCallingIdentity();
            try {
                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
                if (pfd != null) {
                if (pfd != null) {
                    bindWallpaperComponentLocked(null);
                    bindWallpaperComponentLocked(null);
                    saveSettingsLocked();
                    saveSettingsLocked();
                }
                }
                return pfd;
                return pfd;
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
        }
    }
    }


@@ -341,6 +367,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
            clearWallpaperComponentLocked();
            clearWallpaperComponentLocked();
            mWallpaperComponent = name;
            mWallpaperComponent = name;
            mWallpaperConnection = newConn;
            mWallpaperConnection = newConn;
            mLastDiedTime = SystemClock.uptimeMillis();
            try {
            try {
                if (DEBUG) Log.v(TAG, "Adding window token: " + newConn.mToken);
                if (DEBUG) Log.v(TAG, "Adding window token: " + newConn.mToken);
                mIWindowManager.addWindowToken(newConn.mToken,
                mIWindowManager.addWindowToken(newConn.mToken,
+8 −4
Original line number Original line Diff line number Diff line
@@ -1194,6 +1194,9 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }


        if (!visible) w = null;
        if (!visible) w = null;
        //if (mWallpaperTarget != w) {
        //    Log.v(TAG, "New wallpaper target: " + w);
        //}
        mWallpaperTarget = w;
        mWallpaperTarget = w;
        
        
        if (visible) {
        if (visible) {
@@ -6900,10 +6903,10 @@ public class WindowManagerService extends IWindowManager.Stub
            if (atoken != null) {
            if (atoken != null) {
                return mSurface != null && mPolicyVisibility && !mDestroying
                return mSurface != null && mPolicyVisibility && !mDestroying
                        && ((!mAttachedHidden && !atoken.hiddenRequested)
                        && ((!mAttachedHidden && !atoken.hiddenRequested)
                                || mAnimating || atoken.animating);
                                || mAnimation != null || atoken.animation != null);
            } else {
            } else {
                return mSurface != null && mPolicyVisibility && !mDestroying
                return mSurface != null && mPolicyVisibility && !mDestroying
                        && (!mAttachedHidden || mAnimating);
                        && (!mAttachedHidden || mAnimation != null);
            }
            }
        }
        }


@@ -6913,10 +6916,11 @@ public class WindowManagerService extends IWindowManager.Stub
         */
         */
        boolean isReadyForDisplay() {
        boolean isReadyForDisplay() {
            final AppWindowToken atoken = mAppToken;
            final AppWindowToken atoken = mAppToken;
            final boolean animating = atoken != null ? atoken.animating : false;
            final boolean animating = atoken != null
                    ? (atoken.animation != null) : false;
            return mSurface != null && mPolicyVisibility && !mDestroying
            return mSurface != null && mPolicyVisibility && !mDestroying
                    && ((!mAttachedHidden && !mRootToken.hidden)
                    && ((!mAttachedHidden && !mRootToken.hidden)
                            || mAnimating || animating);
                            || mAnimation != null || animating);
        }
        }


        /** Is the window or its container currently animating? */
        /** Is the window or its container currently animating? */