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

Commit 71144266 authored by Chris Wren's avatar Chris Wren
Browse files

skip backup if launcher is in a bad state

Bug: 13153542
Change-Id: I4312ebd200e8e652ef841f54301981c2a486b726
parent 3de6ea86
Loading
Loading
Loading
Loading
+32 −10
Original line number Diff line number Diff line
@@ -50,9 +50,7 @@ import android.util.Base64;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -188,6 +186,7 @@ public class LauncherBackupHelper implements BackupHelper {
        Log.v(TAG, "lastBackupTime = " + lastBackupTime);

        ArrayList<Key> keys = new ArrayList<Key>();
        if (launcherIsReady()) {
            try {
                backupFavorites(in, data, out, keys);
                backupScreens(in, data, out, keys);
@@ -196,8 +195,11 @@ public class LauncherBackupHelper implements BackupHelper {
            } catch (IOException e) {
                Log.e(TAG, "launcher backup has failed", e);
            }

            out.key = keys.toArray(new BackupProtos.Key[keys.size()]);
        } else {
            out = in;
        }

        writeJournal(newState, out);
        Log.v(TAG, "onBackup: wrote " + out.bytes + "b in " + out.rows + " rows.");
    }
@@ -1129,6 +1131,26 @@ public class LauncherBackupHelper implements BackupHelper {
        return mIconCache != null;
    }


   // check if the launcher is in a state to support backup
    private boolean launcherIsReady() {
        ContentResolver cr = mContext.getContentResolver();
        Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, null, null, null);
        if (cursor == null) {
            // launcher data has been wiped, do nothing
            return false;
        }
        cursor.close();

        if (!initializeIconCache()) {
            // launcher services are unavailable, try again later
            dataChanged();
            return false;
        }

        return true;
    }

    private class KeyParsingException extends Throwable {
        private KeyParsingException(Throwable cause) {
            super(cause);