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

Commit 13e8d210 authored by Chris Poultney's avatar Chris Poultney
Browse files

Adds debug information on how current wallpapers were set

Bug: b/301073479
Flag: NONE
Test: manually verified that setting wallpapers works
Test: manually verified that attribute save/load works
Change-Id: I0ae4f27dfb0e196db898f3335bfbc23161103344
parent ba2e8836
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -130,6 +130,28 @@ class WallpaperData {
     */
    final Rect cropHint = new Rect(0, 0, 0, 0);

    // Describes the context of a call to WallpaperManagerService#bindWallpaperComponentLocked
    enum BindSource {
        UNKNOWN,
        CONNECT_LOCKED,
        CONNECTION_TRY_TO_REBIND,
        INITIALIZE_FALLBACK,
        PACKAGE_UPDATE_FINISHED,
        RESTORE_SETTINGS_LIVE_FAILURE,
        RESTORE_SETTINGS_LIVE_SUCCESS,
        RESTORE_SETTINGS_STATIC,
        SET_LIVE,
        SET_LIVE_TO_CLEAR,
        SET_STATIC,
        SWITCH_WALLPAPER_FAILURE,
        SWITCH_WALLPAPER_SWITCH_USER,
        SWITCH_WALLPAPER_UNLOCK_USER,
    }

    // Context in which this wallpaper was bound. Intended for use in resolving b/301073479 but may
    // be useful after the issue is resolved as well.
    BindSource mBindSource = BindSource.UNKNOWN;

    // map of which -> File
    private final SparseArray<File> mWallpaperFiles = new SparseArray<>();
    private final SparseArray<File> mCropFiles = new SparseArray<>();
+15 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.JournaledFile;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.wallpaper.WallpaperData.BindSource;

import libcore.io.IoUtils;

@@ -314,6 +315,14 @@ class WallpaperDataParser {
        wpData.mPadding.right = getAttributeInt(parser, "paddingRight", 0);
        wpData.mPadding.bottom = getAttributeInt(parser, "paddingBottom", 0);
        wallpaper.mWallpaperDimAmount = getAttributeFloat(parser, "dimAmount", 0f);
        BindSource bindSource;
        try {
            bindSource = Enum.valueOf(BindSource.class,
                    getAttributeString(parser, "bindSource", BindSource.UNKNOWN.name()));
        } catch (IllegalArgumentException | NullPointerException e) {
            bindSource = BindSource.UNKNOWN;
        }
        wallpaper.mBindSource = bindSource;
        int dimAmountsCount = getAttributeInt(parser, "dimAmountsCount", 0);
        if (dimAmountsCount > 0) {
            SparseArray<Float> allDimAmounts = new SparseArray<>(dimAmountsCount);
@@ -364,6 +373,11 @@ class WallpaperDataParser {
        return parser.getAttributeFloat(null, name, defValue);
    }

    private String getAttributeString(XmlPullParser parser, String name, String defValue) {
        String s = parser.getAttributeValue(null, name);
        return (s != null) ? s : defValue;
    }

    void saveSettingsLocked(int userId, WallpaperData wallpaper, WallpaperData lockWallpaper) {
        JournaledFile journal = makeJournaledFile(userId);
        FileOutputStream fstream = null;
@@ -423,6 +437,7 @@ class WallpaperDataParser {
        }

        out.attributeFloat(null, "dimAmount", wallpaper.mWallpaperDimAmount);
        out.attribute(null, "bindSource", wallpaper.mBindSource.name());
        int dimAmountsCount = wallpaper.mUidToDimAmount.size();
        out.attributeInt(null, "dimAmountsCount", dimAmountsCount);
        if (dimAmountsCount > 0) {
+17 −1
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.pm.UserManagerInternal;
import com.android.server.utils.TimingsTraceAndSlog;
import com.android.server.wallpaper.WallpaperData.BindSource;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.WindowManagerInternal;

@@ -335,6 +336,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                    };

                    // If this was the system wallpaper, rebind...
                    wallpaper.mBindSource = BindSource.SET_STATIC;
                    bindWallpaperComponentLocked(mImageWallpaper, true, false, wallpaper,
                            callback);
                }
@@ -354,6 +356,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                        }
                    };

                    wallpaper.mBindSource = BindSource.SET_STATIC;
                    bindWallpaperComponentLocked(mImageWallpaper, true /* force */,
                            false /* fromUser */, wallpaper, callback);
                } else if (isAppliedToLock) {
@@ -811,6 +814,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                Slog.w(TAG, "Failed attaching wallpaper on display", e);
                if (wallpaper != null && !wallpaper.wallpaperUpdating
                        && connection.getConnectedEngineSize() == 0) {
                    wallpaper.mBindSource = BindSource.CONNECT_LOCKED;
                    bindWallpaperComponentLocked(null /* componentName */, false /* force */,
                            false /* fromUser */, wallpaper, null /* reply */);
                }
@@ -1035,6 +1039,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                final ComponentName wpService = mWallpaper.wallpaperComponent;
                // The broadcast of package update could be delayed after service disconnected. Try
                // to re-bind the service for 10 seconds.
                mWallpaper.mBindSource = BindSource.CONNECTION_TRY_TO_REBIND;
                if (bindWallpaperComponentLocked(
                        wpService, true, false, mWallpaper, null)) {
                    mWallpaper.connection.scheduleTimeoutLocked();
@@ -1321,6 +1326,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                        }
                        wallpaper.wallpaperUpdating = false;
                        clearWallpaperComponentLocked(wallpaper);
                        wallpaper.mBindSource = BindSource.PACKAGE_UPDATE_FINISHED;
                        if (!bindWallpaperComponentLocked(wpService, false, false,
                                wallpaper, null)) {
                            Slog.w(TAG, "Wallpaper " + wpService
@@ -1711,6 +1717,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                if (mHomeWallpaperWaitingForUnlock) {
                    final WallpaperData systemWallpaper =
                            getWallpaperSafeLocked(userId, FLAG_SYSTEM);
                    systemWallpaper.mBindSource = BindSource.SWITCH_WALLPAPER_UNLOCK_USER;
                    switchWallpaper(systemWallpaper, null);
                    // TODO(b/278261563): call notifyCallbacksLocked inside switchWallpaper
                    notifyCallbacksLocked(systemWallpaper);
@@ -1718,6 +1725,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                if (mLockWallpaperWaitingForUnlock) {
                    final WallpaperData lockWallpaper =
                            getWallpaperSafeLocked(userId, FLAG_LOCK);
                    lockWallpaper.mBindSource = BindSource.SWITCH_WALLPAPER_UNLOCK_USER;
                    switchWallpaper(lockWallpaper, null);
                    notifyCallbacksLocked(lockWallpaper);
                }
@@ -1838,6 +1846,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        // delete them in order to show the default wallpaper.
        clearWallpaperBitmaps(wallpaper);

        fallback.mBindSource = BindSource.SWITCH_WALLPAPER_FAILURE;
        bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply);
        if ((wallpaper.mWhich & FLAG_SYSTEM) != 0) mHomeWallpaperWaitingForUnlock = true;
        if ((wallpaper.mWhich & FLAG_LOCK) != 0) mLockWallpaperWaitingForUnlock = true;
@@ -2963,6 +2972,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                 */
                boolean forceRebind = force || (same && systemIsBoth && which == FLAG_SYSTEM);

                newWallpaper.mBindSource =
                        (name == null) ? BindSource.SET_LIVE_TO_CLEAR : BindSource.SET_LIVE;
                bindSuccess = bindWallpaperComponentLocked(name, /* force */
                        forceRebind, /* fromUser */ true, newWallpaper, reply);
                if (bindSuccess) {
@@ -3530,6 +3541,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            mFallbackWallpaper = new WallpaperData(systemUserId, FLAG_SYSTEM);
            mFallbackWallpaper.allowBackup = false;
            mFallbackWallpaper.wallpaperId = makeWallpaperIdLocked();
            mFallbackWallpaper.mBindSource = BindSource.INITIALIZE_FALLBACK;
            bindWallpaperComponentLocked(mDefaultWallpaperComponent, true, false,
                    mFallbackWallpaper, null);
        }
@@ -3553,11 +3565,13 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            wallpaper.allowBackup = true;   // by definition if it was restored
            if (wallpaper.nextWallpaperComponent != null
                    && !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) {
                wallpaper.mBindSource = BindSource.RESTORE_SETTINGS_LIVE_SUCCESS;
                if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
                        wallpaper, null)) {
                    // No such live wallpaper or other failure; fall back to the default
                    // live wallpaper (since the profile being restored indicated that the
                    // user had selected a live rather than static one).
                    wallpaper.mBindSource = BindSource.RESTORE_SETTINGS_LIVE_FAILURE;
                    bindWallpaperComponentLocked(null, false, false, wallpaper, null);
                }
                success = true;
@@ -3575,6 +3589,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                        + " id=" + wallpaper.wallpaperId);
                if (success) {
                    mWallpaperCropper.generateCrop(wallpaper); // based on the new image + metadata
                    wallpaper.mBindSource = BindSource.RESTORE_SETTINGS_STATIC;
                    bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, true, false,
                            wallpaper, null);
                }
@@ -3608,7 +3623,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        pw.print(" User "); pw.print(wallpaper.userId);
        pw.print(": id="); pw.print(wallpaper.wallpaperId);
        pw.print(": mWhich="); pw.print(wallpaper.mWhich);
        pw.print(": mSystemWasBoth="); pw.println(wallpaper.mSystemWasBoth);
        pw.print(": mSystemWasBoth="); pw.print(wallpaper.mSystemWasBoth);
        pw.print(": mBindSource="); pw.println(wallpaper.mBindSource.name());
        pw.println(" Display state:");
        mWallpaperDisplayHelper.forEachDisplayData(wpSize -> {
            pw.print("  displayId=");