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

Commit b1a7ffef authored by Joe Onorato's avatar Joe Onorato
Browse files

More backup tests

parent fedf566b
Loading
Loading
Loading
Loading
+178 −0
Original line number Diff line number Diff line
@@ -21795,6 +21795,184 @@
</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="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="write"
 return="void"
 abstract="false"
 native="false"
 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="false"
 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="false"
 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="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="key" type="java.lang.String">
</parameter>
</method>
</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"
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.backup;

import android.content.Context;

import java.io.FileDescriptor;

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

    public static final int OP_UPDATE = 1;
    public static final int OP_DELETE = 2;

    public BackupDataOutput(Context context, FileDescriptor fd) {
        this.fd = fd;
    }

    public void close() {
        // do we close the fd?
    }
    public native void flush();
    public native void write(byte[] buffer);
    public native void write(int oneByte);
    public native void write(byte[] buffer, int offset, int count);

    public native void writeOperation(int op);
    public native void writeKey(String key);
}
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.backup;

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

import java.io.FileDescriptor;

public class 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
     * state as it exists now.
     */
    public static void performBackup(Context context,
            ParcelFileDescriptor oldSnapshot, ParcelFileDescriptor newSnapshot,
            BackupDataOutput data, String[] files) {
        String basePath = context.getFilesDir().getAbsolutePath();
        performBackup_checked(basePath, oldSnapshot, newSnapshot, data, files);
    }

    /**
     * Check the parameters so the native code doens't have to throw all the exceptions
     * 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");
        }
        if (data == null) {
            throw new NullPointerException("data==null");
        }
        if (data.fd == null) {
            throw new NullPointerException("data.fd==null");
        }
        if (files == null) {
            throw new NullPointerException("files==null");
        }

        int err = performBackup_native(basePath, oldSnapshot.getFileDescriptor(),
                newSnapshot.getFileDescriptor(), data.fd, 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);
}
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.backup;

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

import java.io.FileDescriptor;

public class SharedPreferencesBackupHelper {
    public static void performBackup(Context context,
            ParcelFileDescriptor oldSnapshot, ParcelFileDescriptor newSnapshot,
            BackupDataOutput data, String[] prefGroups) {
        String basePath = "/xxx"; //context.getPreferencesDir();

        // make filenames for the prefGroups
        final int N = prefGroups.length;
        String[] files = new String[N];
        for (int i=0; i<N; i++) {
            files[i] = prefGroups[i] + ".xml";
        }

        FileBackupHelper.performBackup_checked(basePath, oldSnapshot, newSnapshot, data, files);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -116,7 +116,8 @@ LOCAL_SRC_FILES:= \
	android_ddm_DdmHandleNativeHeap.cpp \
	android_location_GpsLocationProvider.cpp \
	com_android_internal_os_ZygoteInit.cpp \
	com_android_internal_graphics_NativeUtils.cpp
	com_android_internal_graphics_NativeUtils.cpp \
	android_backup_FileBackupHelper.cpp

LOCAL_C_INCLUDES += \
	$(JNI_H_INCLUDE) \
Loading