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

Commit 9dabc3de authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Log important events in WallpaperBackupAgent" into rvc-dev am: 4d39f7bb

Change-Id: Ib8025dca07c821ae8cdccffda60c0fb4a36efdfa
parents e3fd2ef5 4d39f7bb
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -164,6 +164,9 @@ public class WallpaperBackupAgent extends BackupAgent {
                }
                if (DEBUG) Slog.v(TAG, "Storing wallpaper metadata");
                backupFile(infoStage, data);
            } else {
                Slog.w(TAG, "Wallpaper metadata file doesn't exist: " +
                        mWallpaperFile.getPath());
            }
            if (sysEligible && mWallpaperFile.exists()) {
                if (sysChanged || !imageStage.exists()) {
@@ -173,6 +176,10 @@ public class WallpaperBackupAgent extends BackupAgent {
                if (DEBUG) Slog.v(TAG, "Storing system wallpaper image");
                backupFile(imageStage, data);
                prefs.edit().putInt(SYSTEM_GENERATION, sysGeneration).apply();
            } else {
                Slog.w(TAG, "Not backing up wallpaper as one of conditions is not "
                        + "met: sysEligible = " + sysEligible + " wallpaperFileExists = "
                        + mWallpaperFile.exists());
            }

            // If there's no lock wallpaper, then we have nothing to add to the backup.
@@ -181,7 +188,7 @@ public class WallpaperBackupAgent extends BackupAgent {
                    if (DEBUG) Slog.v(TAG, "Removed lock wallpaper; deleting");
                    lockImageStage.delete();
                }
                if (DEBUG) Slog.v(TAG, "No lock paper set, add nothing to backup");
                Slog.d(TAG, "No lockscreen wallpaper set, add nothing to backup");
                prefs.edit().putInt(LOCK_GENERATION, lockGeneration).apply();
                return;
            }
@@ -195,6 +202,12 @@ public class WallpaperBackupAgent extends BackupAgent {
                if (DEBUG) Slog.v(TAG, "Storing lock wallpaper image");
                backupFile(lockImageStage, data);
                prefs.edit().putInt(LOCK_GENERATION, lockGeneration).apply();
            } else {
                Slog.w(TAG, "Not backing up lockscreen wallpaper as one of conditions is not "
                        + "met: lockEligible = " + lockEligible + " hasLockWallpaper = "
                        + hasLockWallpaper + " lockWallpaperFileExists = "
                        + mLockWallpaperFile.exists() + " quotaExceeded (last time) = "
                        + mQuotaExceeded);
            }
        } catch (Exception e) {
            Slog.e(TAG, "Unable to back up wallpaper", e);
@@ -216,9 +229,7 @@ public class WallpaperBackupAgent extends BackupAgent {

    @Override
    public void onQuotaExceeded(long backupDataBytes, long quotaBytes) {
        if (DEBUG) {
        Slog.i(TAG, "Quota exceeded (" + backupDataBytes + " vs " + quotaBytes + ')');
        }
        try (FileOutputStream f = new FileOutputStream(mQuotaFile)) {
            f.write(0);
        } catch (Exception e) {
@@ -230,9 +241,7 @@ public class WallpaperBackupAgent extends BackupAgent {
    // then post-process in onRestoreFinished() to apply the new wallpaper.
    @Override
    public void onRestoreFinished() {
        if (DEBUG) {
        Slog.v(TAG, "onRestoreFinished()");
        }
        final File filesDir = getFilesDir();
        final File infoStage = new File(filesDir, INFO_STAGE);
        final File imageStage = new File (filesDir, IMAGE_STAGE);
@@ -253,9 +262,7 @@ public class WallpaperBackupAgent extends BackupAgent {
            // And reset to the wallpaper service we should be using
            ComponentName wpService = parseWallpaperComponent(infoStage, "wp");
            if (servicePackageExists(wpService)) {
                if (DEBUG) {
                Slog.i(TAG, "Using wallpaper service " + wpService);
                }
                mWm.setWallpaperComponent(wpService, UserHandle.USER_SYSTEM);
                if (!lockImageStage.exists()) {
                    // We have a live wallpaper and no static lock image,
@@ -273,9 +280,7 @@ public class WallpaperBackupAgent extends BackupAgent {
        } catch (Exception e) {
            Slog.e(TAG, "Unable to restore wallpaper: " + e.getMessage());
        } finally {
            if (DEBUG) {
            Slog.v(TAG, "Restore finished; clearing backup bookkeeping");
            }
            infoStage.delete();
            imageStage.delete();
            lockImageStage.delete();
@@ -295,14 +300,14 @@ public class WallpaperBackupAgent extends BackupAgent {
            // relies on a priori knowledge of the wallpaper info file schema.
            Rect cropHint = parseCropHint(info, hintTag);
            if (cropHint != null) {
                Slog.i(TAG, "Got restored wallpaper; applying which=" + which);
                if (DEBUG) {
                    Slog.v(TAG, "Restored crop hint " + cropHint);
                }
                Slog.i(TAG, "Got restored wallpaper; applying which=" + which
                        + "; cropHint = " + cropHint);
                try (FileInputStream in = new FileInputStream(stage)) {
                    mWm.setStream(in, cropHint.isEmpty() ? null : cropHint, true, which);
                } finally {} // auto-closes 'in'
            }
        } else {
            Slog.d(TAG, "Restore data doesn't exist for file " + stage.getPath());
        }
    }