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

Commit 290bb011 authored by Joe Onorato's avatar Joe Onorato
Browse files

Get the backup calling through to the file backup helper.

This includes some cleanup to make the parameters match
between BackupService.onBackup and FileBackupHelper.performBackup.
parent ec2d74d4
Loading
Loading
Loading
Loading
+0 −213
Original line number Diff line number Diff line
@@ -21839,219 +21839,6 @@
</field>
</class>
</package>
<package name="android.backup"
>
<class name="BackupDataOutput"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="BackupDataOutput"
 type="android.backup.BackupDataOutput"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="fd" type="java.io.FileDescriptor">
</parameter>
</constructor>
<method name="close"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="flush"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="write"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="buffer" type="byte[]">
</parameter>
</method>
<method name="write"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="oneByte" type="int">
</parameter>
</method>
<method name="write"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="buffer" type="byte[]">
</parameter>
<parameter name="offset" type="int">
</parameter>
<parameter name="count" type="int">
</parameter>
</method>
<method name="writeKey"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="key" type="java.lang.String">
</parameter>
</method>
<method name="writeOperation"
 return="void"
 abstract="false"
 native="true"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="op" type="int">
</parameter>
</method>
<field name="OP_DELETE"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="OP_UPDATE"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="FileBackupHelper"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="FileBackupHelper"
 type="android.backup.FileBackupHelper"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="performBackup"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="oldSnapshot" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="newSnapshot" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="data" type="android.backup.BackupDataOutput">
</parameter>
<parameter name="files" type="java.lang.String[]">
</parameter>
</method>
</class>
<class name="SharedPreferencesBackupHelper"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="SharedPreferencesBackupHelper"
 type="android.backup.SharedPreferencesBackupHelper"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="performBackup"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="oldSnapshot" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="newSnapshot" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="data" type="android.backup.BackupDataOutput">
</parameter>
<parameter name="prefGroups" type="java.lang.String[]">
</parameter>
</method>
</class>
</package>
<package name="android.content"
>
<class name="ActivityNotFoundException"
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;

import java.io.FileDescriptor;

/** @hide */
public class BackupDataOutput {
    /* package */ FileDescriptor fd;

+12 −5
Original line number Diff line number Diff line
@@ -75,8 +75,7 @@ public abstract class BackupService extends Service {
     *                 file.  The application should record the final backup state
     *                 here after writing the requested data to dataFd.
     */
    public abstract void onBackup(ParcelFileDescriptor oldState,
            ParcelFileDescriptor data,
    public abstract void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
             ParcelFileDescriptor newState);
    
    /**
@@ -92,7 +91,7 @@ public abstract class BackupService extends Service {
     *                 file.  The application should record the final backup state
     *                 here after restoring its data from dataFd.
     */
    public abstract void onRestore(ParcelFileDescriptor data, ParcelFileDescriptor newState);
    public abstract void onRestore(ParcelFileDescriptor /* TODO: BackupDataInput */ data, ParcelFileDescriptor newState);


    // ----- Core implementation -----
@@ -117,7 +116,15 @@ public abstract class BackupService extends Service {
                ParcelFileDescriptor newState) throws RemoteException {
            // !!! TODO - real implementation; for now just invoke the callbacks directly
            Log.v("BackupServiceBinder", "doBackup() invoked");
            BackupService.this.onBackup(oldState, data, newState);
            BackupDataOutput output = new BackupDataOutput(BackupService.this,
                    data.getFileDescriptor());
            try {
                BackupService.this.onBackup(oldState, output, newState);
            } catch (RuntimeException ex) {
                Log.d("BackupService", "onBackup ("
                        + BackupService.this.getClass().getName() + ") threw", ex);
                throw ex;
            }
        }

        public void doRestore(ParcelFileDescriptor data,
+26 −18
Original line number Diff line number Diff line
@@ -18,20 +18,24 @@ package android.backup;

import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.util.Log;

import java.io.FileDescriptor;

/** @hide */
public class FileBackupHelper {
    private static final String TAG = "FileBackupHelper";

    /**
     * Based on oldSnapshot, determine which of the files from the application's data directory
     * need to be backed up, write them to the data stream, and fill in newSnapshot with the
     * Based on oldState, determine which of the files from the application's data directory
     * need to be backed up, write them to the data stream, and fill in newState with the
     * state as it exists now.
     */
    public static void performBackup(Context context,
            ParcelFileDescriptor oldSnapshot, ParcelFileDescriptor newSnapshot,
            BackupDataOutput data, String[] files) {
            ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState, String[] files) {
        String basePath = context.getFilesDir().getAbsolutePath();
        performBackup_checked(basePath, oldSnapshot, newSnapshot, data, files);
        performBackup_checked(basePath, oldState, data, newState, files);
    }

    /**
@@ -39,30 +43,34 @@ public class FileBackupHelper {
     * since it's easier to do that from java.
     */
    static void performBackup_checked(String basePath,
            ParcelFileDescriptor oldSnapshot, ParcelFileDescriptor newSnapshot,
            BackupDataOutput data, String[] files) {
        if (newSnapshot == null) {
            throw new NullPointerException("newSnapshot==null");
            ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState, String[] files) {
        if (files.length == 0) {
            return;
        }
        if (data == null) {
            throw new NullPointerException("data==null");
        if (basePath == null) {
            throw new NullPointerException();
        }
        // oldStateFd can be null
        FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null;
        if (data.fd == null) {
            throw new NullPointerException("data.fd==null");
            throw new NullPointerException();
        }
        FileDescriptor newStateFd = newState.getFileDescriptor();
        if (newStateFd == null) {
            throw new NullPointerException();
        }
        if (files == null) {
            throw new NullPointerException("files==null");
            throw new NullPointerException();
        }

        int err = performBackup_native(basePath, oldSnapshot.getFileDescriptor(),
                newSnapshot.getFileDescriptor(), data.fd, files);
        int err = performBackup_native(basePath, oldStateFd, data.fd, newStateFd, files);

        if (err != 0) {
            throw new RuntimeException("Backup failed"); // TODO: more here
        }
    }

    native private static int performBackup_native(String basePath,
            FileDescriptor oldSnapshot, FileDescriptor newSnapshot,
            FileDescriptor data, String[] files);
    native private static int performBackup_native(String basePath, FileDescriptor oldState,
            FileDescriptor data, FileDescriptor newState, String[] files);
}
+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.ParcelFileDescriptor;

import java.io.FileDescriptor;

/** @hide */
public class SharedPreferencesBackupHelper {
    public static void performBackup(Context context,
            ParcelFileDescriptor oldSnapshot, ParcelFileDescriptor newSnapshot,
@@ -34,7 +35,7 @@ public class SharedPreferencesBackupHelper {
            files[i] = prefGroups[i] + ".xml";
        }

        FileBackupHelper.performBackup_checked(basePath, oldSnapshot, newSnapshot, data, files);
        FileBackupHelper.performBackup_checked(basePath, oldSnapshot, data, newSnapshot, files);
    }
}
Loading