Hook up the backup data writer, and add a utility to read the backup data files.
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 4839b6f..d46dd80 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -117,6 +117,7 @@
android_location_GpsLocationProvider.cpp \
com_android_internal_os_ZygoteInit.cpp \
com_android_internal_graphics_NativeUtils.cpp \
+ android_backup_BackupDataOutput.cpp \
android_backup_FileBackupHelper.cpp
LOCAL_C_INCLUDES += \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index aa6450d..302f39e 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -155,6 +155,7 @@
extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env);
extern int register_android_util_Base64(JNIEnv* env);
extern int register_android_location_GpsLocationProvider(JNIEnv* env);
+extern int register_android_backup_BackupDataOutput(JNIEnv *env);
extern int register_android_backup_FileBackupHelper(JNIEnv *env);
static AndroidRuntime* gCurRuntime = NULL;
@@ -1126,6 +1127,7 @@
REG_JNI(register_android_ddm_DdmHandleNativeHeap),
REG_JNI(register_android_util_Base64),
REG_JNI(register_android_location_GpsLocationProvider),
+ REG_JNI(register_android_backup_BackupDataOutput),
REG_JNI(register_android_backup_FileBackupHelper),
};
diff --git a/core/jni/android_backup_BackupDataOutput.cpp b/core/jni/android_backup_BackupDataOutput.cpp
new file mode 100644
index 0000000..8fce2a2
--- /dev/null
+++ b/core/jni/android_backup_BackupDataOutput.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "FileBackupHelper_native"
+#include <utils/Log.h>
+
+#include "JNIHelp.h"
+#include <android_runtime/AndroidRuntime.h>
+
+#include <utils/backup_helpers.h>
+
+namespace android
+{
+
+static jfieldID s_descriptorField = 0;
+
+static int
+ctor_native(JNIEnv* env, jobject This, jobject fileDescriptor)
+{
+ int err;
+
+ int fd = env->GetIntField(fileDescriptor, s_descriptorField);
+ if (fd == -1) {
+ return NULL;
+ }
+
+ return (int)new BackupDataWriter(fd);
+}
+
+static void
+dtor_native(JNIEnv* env, jobject This, int fd)
+{
+ delete (BackupDataWriter*)fd;
+}
+
+static const JNINativeMethod g_methods[] = {
+ { "ctor", "(Ljava/io/FileDescriptor;)I", (void*)ctor_native },
+ { "dtor", "(I)V", (void*)dtor_native },
+};
+
+int register_android_backup_BackupDataOutput(JNIEnv* env)
+{
+ LOGD("register_android_backup_BackupDataOutput");
+
+ jclass clazz;
+
+ clazz = env->FindClass("java/io/FileDescriptor");
+ LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
+ s_descriptorField = env->GetFieldID(clazz, "descriptor", "I");
+ LOG_FATAL_IF(s_descriptorField == NULL,
+ "Unable to find descriptor field in java.io.FileDescriptor");
+
+ return AndroidRuntime::registerNativeMethods(env, "android/backup/BackupDataOutput",
+ g_methods, NELEM(g_methods));
+}
+
+}
diff --git a/core/jni/android_backup_FileBackupHelper.cpp b/core/jni/android_backup_FileBackupHelper.cpp
index c6de3a5..a05d812 100644
--- a/core/jni/android_backup_FileBackupHelper.cpp
+++ b/core/jni/android_backup_FileBackupHelper.cpp
@@ -28,7 +28,7 @@
static jfieldID s_descriptorField = 0;
static int
-performBackup_native(JNIEnv* env, jobject clazz, jstring basePath, jobject oldState, jobject data,
+performBackup_native(JNIEnv* env, jobject clazz, jstring basePath, jobject oldState, int data,
jobject newState, jobjectArray files)
{
int err;
@@ -37,7 +37,7 @@
LOGD("oldState=%p newState=%p data=%p\n", oldState, newState, data);
int oldStateFD = oldState != NULL ? env->GetIntField(oldState, s_descriptorField) : -1;
int newStateFD = env->GetIntField(newState, s_descriptorField);
- int dataFD = env->GetIntField(data, s_descriptorField);
+ BackupDataWriter* dataStream = (BackupDataWriter*)data;
char const* basePathUTF = env->GetStringUTFChars(basePath, NULL);
LOGD("basePathUTF=\"%s\"\n", basePathUTF);
@@ -47,7 +47,7 @@
filesUTF[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(files, i), NULL);
}
- err = back_up_files(oldStateFD, dataFD, newStateFD, basePathUTF, filesUTF, fileCount);
+ err = back_up_files(oldStateFD, dataStream, newStateFD, basePathUTF, filesUTF, fileCount);
for (int i=0; i<fileCount; i++) {
env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(files, i), filesUTF[i]);
@@ -60,8 +60,7 @@
static const JNINativeMethod g_methods[] = {
{ "performBackup_native",
- "(Ljava/lang/String;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
- "Ljava/io/FileDescriptor;[Ljava/lang/String;)I",
+ "(Ljava/lang/String;Ljava/io/FileDescriptor;ILjava/io/FileDescriptor;[Ljava/lang/String;)I",
(void*)performBackup_native },
};