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

Commit 42d7c9c0 authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

Merge "Full backup tweaks"

parents ae7bc652 dc92c82b
Loading
Loading
Loading
Loading
+20 −12
Original line number Original line Diff line number Diff line
@@ -468,6 +468,19 @@ static void calc_tar_checksum(char* buf) {
    sprintf(buf + 148, "%06o", sum); // the trailing space is already in place
    sprintf(buf + 148, "%06o", sum); // the trailing space is already in place
}
}


// Returns number of bytes written
static int write_pax_header_entry(char* buf, const char* key, const char* value) {
    // start with the size of "1 key=value\n"
    int len = strlen(key) + strlen(value) + 4;
    if (len > 9) len++;
    if (len > 99) len++;
    if (len > 999) len++;
    // since PATH_MAX is 4096 we don't expect to have to generate any single
    // header entry longer than 9999 characters

    return sprintf(buf, "%d %s=%s\n", len, key, value);
}

int write_tarfile(const String8& packageName, const String8& domain,
int write_tarfile(const String8& packageName, const String8& domain,
        const String8& rootpath, const String8& filepath, BackupDataWriter* writer)
        const String8& rootpath, const String8& filepath, BackupDataWriter* writer)
{
{
@@ -525,8 +538,7 @@ int write_tarfile(const String8& packageName, const String8& domain,
    }
    }


    // Good to go -- first construct the standard tar header at the start of the buffer
    // Good to go -- first construct the standard tar header at the start of the buffer
    memset(buf, 0, 512);    // tar header is 512 bytes
    memset(buf, 0, BUFSIZE);
    memset(paxHeader, 0, 512);


    // Magic fields for the ustar file format
    // Magic fields for the ustar file format
    strcat(buf + 257, "ustar");
    strcat(buf + 257, "ustar");
@@ -602,24 +614,20 @@ int write_tarfile(const String8& packageName, const String8& domain,
    // If we're using a pax extended header, build & write that here; lengths are
    // If we're using a pax extended header, build & write that here; lengths are
    // already preflighted
    // already preflighted
    if (needExtended) {
    if (needExtended) {
        char sizeStr[32];   // big enough for a 64-bit unsigned value in decimal
        char* p = paxData;

        // construct the pax extended header data block
        // construct the pax extended header data block
        memset(paxData, 0, BUFSIZE - (paxData - buf));
        memset(paxData, 0, BUFSIZE - (paxData - buf));
        char* p = paxData;
        int len;
        int len;


        // size header -- calc len in digits by actually rendering the number
        // size header -- calc len in digits by actually rendering the number
        // to a string - brute force but simple
        // to a string - brute force but simple
        len = sprintf(p, "%lld", s.st_size) + 8;  // 8 for "1 size=" and final LF
        snprintf(sizeStr, sizeof(sizeStr), "%lld", s.st_size);
        if (len >= 10) len++;
        p += write_pax_header_entry(p, "size", sizeStr);

        memset(p, 0, 512);
        p += sprintf(p, "%d size=%lld\n", len, s.st_size);


        // fullname was generated above with the ustar paths
        // fullname was generated above with the ustar paths
        len = fullname.length() + 8;        // 8 for "1 path=" and final LF
        p += write_pax_header_entry(p, "path", fullname.string());
        if (len >= 10) len++;
        if (len >= 100) len++;
        p += sprintf(p, "%d path=%s\n", len, fullname.string());


        // Now we know how big the pax data is
        // Now we know how big the pax data is
        int paxLen = p - paxData;
        int paxLen = p - paxData;
+7 −5
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
@@ -77,7 +76,7 @@ public class BackupRestoreConfirmation extends Activity {
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            switch (msg.what) {
                case MSG_START_BACKUP: {
                case MSG_START_BACKUP: {
                    Toast.makeText(mContext, "!!! Backup starting !!!", Toast.LENGTH_LONG);
                    Toast.makeText(mContext, "!!! Backup starting !!!", Toast.LENGTH_LONG).show();
                }
                }
                break;
                break;


@@ -88,12 +87,13 @@ public class BackupRestoreConfirmation extends Activity {
                break;
                break;


                case MSG_END_BACKUP: {
                case MSG_END_BACKUP: {
                    Toast.makeText(mContext, "!!! Backup ended !!!", Toast.LENGTH_SHORT);
                    Toast.makeText(mContext, "!!! Backup ended !!!", Toast.LENGTH_SHORT).show();
                    finish();
                }
                }
                break;
                break;


                case MSG_START_RESTORE: {
                case MSG_START_RESTORE: {
                    Toast.makeText(mContext, "!!! Restore starting !!!", Toast.LENGTH_LONG);
                    Toast.makeText(mContext, "!!! Restore starting !!!", Toast.LENGTH_LONG).show();
                }
                }
                break;
                break;


@@ -102,11 +102,13 @@ public class BackupRestoreConfirmation extends Activity {
                break;
                break;


                case MSG_END_RESTORE: {
                case MSG_END_RESTORE: {
                    Toast.makeText(mContext, "!!! Restore ended !!!", Toast.LENGTH_SHORT);
                    Toast.makeText(mContext, "!!! Restore ended !!!", Toast.LENGTH_SHORT).show();
                    finish();
                }
                }
                break;
                break;


                case MSG_TIMEOUT: {
                case MSG_TIMEOUT: {
                    Toast.makeText(mContext, "!!! TIMED OUT !!!", Toast.LENGTH_LONG).show();
                }
                }
                break;
                break;
            }
            }
+6 −7
Original line number Original line Diff line number Diff line
@@ -1710,8 +1710,7 @@ class BackupManagerService extends IBackupManager.Stub {
                            IApplicationThread.BACKUP_MODE_FULL);
                            IApplicationThread.BACKUP_MODE_FULL);
                    if (agent != null) {
                    if (agent != null) {
                        try {
                        try {
                            ApplicationInfo app = mPackageManager.getApplicationInfo(
                            ApplicationInfo app = pkg.applicationInfo;
                                    pkg.packageName, 0);
                            boolean sendApk = mIncludeApks
                            boolean sendApk = mIncludeApks
                                    && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
                                    && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
                                    && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
                                    && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
@@ -1742,9 +1741,6 @@ class BackupManagerService extends IBackupManager.Stub {
                            } else {
                            } else {
                                if (DEBUG) Slog.d(TAG, "Full backup success: " + pkg.packageName);
                                if (DEBUG) Slog.d(TAG, "Full backup success: " + pkg.packageName);
                            }
                            }
                        } catch (NameNotFoundException e) {
                            Slog.e(TAG, "Package exists but not app info; skipping: "
                                    + pkg.packageName);
                        } catch (IOException e) {
                        } catch (IOException e) {
                            Slog.e(TAG, "Error backing up " + pkg.packageName, e);
                            Slog.e(TAG, "Error backing up " + pkg.packageName, e);
                        }
                        }
@@ -1816,8 +1812,11 @@ class BackupManagerService extends IBackupManager.Stub {
                // unbind and tidy up even on timeout or failure, just in case
                // unbind and tidy up even on timeout or failure, just in case
                mActivityManager.unbindBackupAgent(app);
                mActivityManager.unbindBackupAgent(app);


                // The agent was running with a stub Application object, so shut it down
                // The agent was running with a stub Application object, so shut it down.
                if (app.uid != Process.SYSTEM_UID) {
                // !!! We hardcode the confirmation UI's package name here rather than use a
                //     manifest flag!  TODO something less direct.
                if (app.uid != Process.SYSTEM_UID
                        && !pkg.packageName.equals("com.android.backupconfirm")) {
                    if (DEBUG) Slog.d(TAG, "Backup complete, killing host process");
                    if (DEBUG) Slog.d(TAG, "Backup complete, killing host process");
                    mActivityManager.killApplicationProcess(app.processName, app.uid);
                    mActivityManager.killApplicationProcess(app.processName, app.uid);
                } else {
                } else {