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

Commit 9ea31639 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #5108980 Wallpaper is not restored after upgrade from IRK32B to IRK33B

Take care of updating from old component name, and don't let this happen
again.

Also tweak how we switch between static wallpapers to avoid introducing
a 4MB allocation in the system UI process when this happens -- we now
stop the current wallpaper service and start a new one, so we get a
brand new surface that we can draw only one time in to.

Change-Id: I6fc8a42b8a46bba79759bd68fb7d0684b5d897b7
parent 9c181ffb
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -93,9 +93,12 @@ public class ImageWallpaper extends WallpaperService {
            }
            }


            super.onCreate(surfaceHolder);
            super.onCreate(surfaceHolder);
            IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
            
            mReceiver = new WallpaperObserver();
            // Don't need this currently because the wallpaper service
            registerReceiver(mReceiver, filter, null, mHandler);
            // will restart the image wallpaper whenever the image changes.
            //IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
            //mReceiver = new WallpaperObserver();
            //registerReceiver(mReceiver, filter, null, mHandler);


            updateSurfaceSize(surfaceHolder);
            updateSurfaceSize(surfaceHolder);
        }
        }
@@ -103,8 +106,10 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void onDestroy() {
        public void onDestroy() {
            super.onDestroy();
            super.onDestroy();
            if (mReceiver != null) {
                unregisterReceiver(mReceiver);
                unregisterReceiver(mReceiver);
            }
            }
        }


        @Override
        @Override
        public void onDesiredSizeChanged(int desiredWidth, int desiredHeight) {
        public void onDesiredSizeChanged(int desiredWidth, int desiredHeight) {
+33 −22
Original line number Original line Diff line number Diff line
@@ -118,6 +118,10 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                        File changedFile = new File(WALLPAPER_DIR, path);
                        File changedFile = new File(WALLPAPER_DIR, path);
                        if (WALLPAPER_FILE.equals(changedFile)) {
                        if (WALLPAPER_FILE.equals(changedFile)) {
                            notifyCallbacksLocked();
                            notifyCallbacksLocked();
                            if (mWallpaperComponent == null ||
                                    mWallpaperComponent.equals(mImageWallpaperComponent)) {
                                bindWallpaperComponentLocked(mWallpaperComponent, true);
                            }
                        }
                        }
                    }
                    }
                }
                }
@@ -191,7 +195,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                    if (!mWallpaperUpdating && (mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
                    if (!mWallpaperUpdating && (mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
                                > SystemClock.uptimeMillis()) {
                                > SystemClock.uptimeMillis()) {
                        Slog.w(TAG, "Reverting to built-in wallpaper!");
                        Slog.w(TAG, "Reverting to built-in wallpaper!");
                        bindWallpaperComponentLocked(null);
                        bindWallpaperComponentLocked(null, true);
                    }
                    }
                }
                }
            }
            }
@@ -220,7 +224,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                    mWallpaperUpdating = false;
                    mWallpaperUpdating = false;
                    ComponentName comp = mWallpaperComponent;
                    ComponentName comp = mWallpaperComponent;
                    clearWallpaperComponentLocked();
                    clearWallpaperComponentLocked();
                    bindWallpaperComponentLocked(comp);
                    bindWallpaperComponentLocked(comp, false);
                }
                }
            }
            }
        }
        }
@@ -312,11 +316,11 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
        if (DEBUG) Slog.v(TAG, "systemReady");
        if (DEBUG) Slog.v(TAG, "systemReady");
        synchronized (mLock) {
        synchronized (mLock) {
            try {
            try {
                bindWallpaperComponentLocked(mNextWallpaperComponent);
                bindWallpaperComponentLocked(mNextWallpaperComponent, false);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                Slog.w(TAG, "Failure starting previous wallpaper", e);
                Slog.w(TAG, "Failure starting previous wallpaper", e);
                try {
                try {
                    bindWallpaperComponentLocked(null);
                    bindWallpaperComponentLocked(null, false);
                } catch (RuntimeException e2) {
                } catch (RuntimeException e2) {
                    Slog.w(TAG, "Failure starting default wallpaper", e2);
                    Slog.w(TAG, "Failure starting default wallpaper", e2);
                    clearWallpaperComponentLocked();
                    clearWallpaperComponentLocked();
@@ -339,7 +343,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
        }
        }
        final long ident = Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();
        try {
        try {
            bindWallpaperComponentLocked(null);
            bindWallpaperComponentLocked(null, false);
        } catch (IllegalArgumentException e) {
        } catch (IllegalArgumentException e) {
            // This can happen if the default wallpaper component doesn't
            // This can happen if the default wallpaper component doesn't
            // exist.  This should be a system configuration problem, but
            // exist.  This should be a system configuration problem, but
@@ -430,7 +434,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
                if (pfd != null) {
                if (pfd != null) {
                    // Bind the wallpaper to an ImageWallpaper
                    // Bind the wallpaper to an ImageWallpaper
                    bindWallpaperComponentLocked(mImageWallpaperComponent);
                    bindWallpaperComponentLocked(mImageWallpaperComponent, false);
                    saveSettingsLocked();
                    saveSettingsLocked();
                }
                }
                return pfd;
                return pfd;
@@ -459,17 +463,18 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
        synchronized (mLock) {
        synchronized (mLock) {
            final long ident = Binder.clearCallingIdentity();
            final long ident = Binder.clearCallingIdentity();
            try {
            try {
                bindWallpaperComponentLocked(name);
                bindWallpaperComponentLocked(name, false);
            } finally {
            } finally {
                Binder.restoreCallingIdentity(ident);
                Binder.restoreCallingIdentity(ident);
            }
            }
        }
        }
    }
    }
    
    
    void bindWallpaperComponentLocked(ComponentName componentName) {
    void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
        
        
        // Has the component changed?
        // Has the component changed?
        if (!force) {
            if (mWallpaperConnection != null) {
            if (mWallpaperConnection != null) {
                if (mWallpaperComponent == null) {
                if (mWallpaperComponent == null) {
                    if (componentName == null) {
                    if (componentName == null) {
@@ -483,6 +488,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                    return;
                    return;
                }
                }
            }
            }
        }
        
        
        try {
        try {
            if (componentName == null) {
            if (componentName == null) {
@@ -599,7 +605,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
            Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
            if (!mWallpaperUpdating) {
            if (!mWallpaperUpdating) {
                bindWallpaperComponentLocked(null);
                bindWallpaperComponentLocked(null, false);
            }
            }
        }
        }
    }
    }
@@ -645,7 +651,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
            out.attribute(null, "width", Integer.toString(mWidth));
            out.attribute(null, "width", Integer.toString(mWidth));
            out.attribute(null, "height", Integer.toString(mHeight));
            out.attribute(null, "height", Integer.toString(mHeight));
            out.attribute(null, "name", mName);
            out.attribute(null, "name", mName);
            if (mWallpaperComponent != null) {
            if (mWallpaperComponent != null &&
                    !mWallpaperComponent.equals(mImageWallpaperComponent)) {
                out.attribute(null, "component",
                out.attribute(null, "component",
                        mWallpaperComponent.flattenToShortString());
                        mWallpaperComponent.flattenToShortString());
            }
            }
@@ -691,6 +698,10 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                        mNextWallpaperComponent = comp != null
                        mNextWallpaperComponent = comp != null
                                ? ComponentName.unflattenFromString(comp)
                                ? ComponentName.unflattenFromString(comp)
                                : null;
                                : null;
                        if (mNextWallpaperComponent == null ||
                                "android".equals(mNextWallpaperComponent.getPackageName())) {
                            mNextWallpaperComponent = mImageWallpaperComponent;
                        }
                          
                          
                        if (DEBUG) {
                        if (DEBUG) {
                            Slog.v(TAG, "mWidth:" + mWidth);
                            Slog.v(TAG, "mWidth:" + mWidth);
@@ -749,12 +760,12 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
            if (mNextWallpaperComponent != null && 
            if (mNextWallpaperComponent != null && 
                    !mNextWallpaperComponent.equals(mImageWallpaperComponent)) {
                    !mNextWallpaperComponent.equals(mImageWallpaperComponent)) {
                try {
                try {
                    bindWallpaperComponentLocked(mNextWallpaperComponent);
                    bindWallpaperComponentLocked(mNextWallpaperComponent, false);
                } catch (IllegalArgumentException e) {
                } catch (IllegalArgumentException e) {
                    // No such live wallpaper or other failure; fall back to the default
                    // No such live wallpaper or other failure; fall back to the default
                    // live wallpaper (since the profile being restored indicated that the
                    // live wallpaper (since the profile being restored indicated that the
                    // user had selected a live rather than static one).
                    // user had selected a live rather than static one).
                    bindWallpaperComponentLocked(null);
                    bindWallpaperComponentLocked(null, false);
                }
                }
                success = true;
                success = true;
            } else {
            } else {
@@ -769,7 +780,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
                }
                }
                if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
                if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
                if (success) {
                if (success) {
                    bindWallpaperComponentLocked(mImageWallpaperComponent);
                    bindWallpaperComponentLocked(null, false);
                }
                }
            }
            }
        }
        }