Helper API cleanup. Allows multiple helpers to function,
because they'll always go in the same order, and this lets
us not have to write headers to keep them paired.
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index faa04f7..80c2489 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -119,8 +119,7 @@
com_android_internal_graphics_NativeUtils.cpp \
android_backup_BackupDataInput.cpp \
android_backup_BackupDataOutput.cpp \
- android_backup_FileBackupHelper.cpp \
- android_backup_RestoreHelperBase.cpp
+ android_backup_FileBackupHelperBase.cpp
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 18f6d5f9..7350348 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -157,8 +157,7 @@
extern int register_android_location_GpsLocationProvider(JNIEnv* env);
extern int register_android_backup_BackupDataInput(JNIEnv *env);
extern int register_android_backup_BackupDataOutput(JNIEnv *env);
-extern int register_android_backup_FileBackupHelper(JNIEnv *env);
-extern int register_android_backup_RestoreHelperBase(JNIEnv *env);
+extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
static AndroidRuntime* gCurRuntime = NULL;
@@ -1131,8 +1130,7 @@
REG_JNI(register_android_location_GpsLocationProvider),
REG_JNI(register_android_backup_BackupDataInput),
REG_JNI(register_android_backup_BackupDataOutput),
- REG_JNI(register_android_backup_FileBackupHelper),
- REG_JNI(register_android_backup_RestoreHelperBase),
+ REG_JNI(register_android_backup_FileBackupHelperBase),
};
/*
diff --git a/core/jni/android_backup_BackupDataOutput.cpp b/core/jni/android_backup_BackupDataOutput.cpp
index 6362439..d02590e 100644
--- a/core/jni/android_backup_BackupDataOutput.cpp
+++ b/core/jni/android_backup_BackupDataOutput.cpp
@@ -87,11 +87,26 @@
return err;
}
+static void
+setKeyPrefix_native(JNIEnv* env, jobject clazz, int w, jstring keyPrefixObj)
+{
+ int err;
+ BackupDataWriter* writer = (BackupDataWriter*)w;
+
+ const char* keyPrefixUTF = env->GetStringUTFChars(keyPrefixObj, NULL);
+ String8 keyPrefix(keyPrefixUTF ? keyPrefixUTF : "");
+
+ writer->SetKeyPrefix(keyPrefix);
+
+ env->ReleaseStringUTFChars(keyPrefixObj, keyPrefixUTF);
+}
+
static const JNINativeMethod g_methods[] = {
{ "ctor", "(Ljava/io/FileDescriptor;)I", (void*)ctor_native },
{ "dtor", "(I)V", (void*)dtor_native },
{ "writeEntityHeader_native", "(ILjava/lang/String;I)I", (void*)writeEntityHeader_native },
{ "writeEntityData_native", "(I[BI)I", (void*)writeEntityData_native },
+ { "setKeyPrefix_native", "(ILjava/lang/String;)V", (void*)setKeyPrefix_native },
};
int register_android_backup_BackupDataOutput(JNIEnv* env)
diff --git a/core/jni/android_backup_FileBackupHelper.cpp b/core/jni/android_backup_FileBackupHelperBase.cpp
similarity index 69%
rename from core/jni/android_backup_FileBackupHelper.cpp
rename to core/jni/android_backup_FileBackupHelperBase.cpp
index 418db8a..8225a36 100644
--- a/core/jni/android_backup_FileBackupHelper.cpp
+++ b/core/jni/android_backup_FileBackupHelperBase.cpp
@@ -29,6 +29,18 @@
static jfieldID s_descriptorField = 0;
static int
+ctor(JNIEnv* env, jobject clazz)
+{
+ return (int)new RestoreHelperBase();
+}
+
+static void
+dtor(JNIEnv* env, jobject clazz, jint ptr)
+{
+ delete (RestoreHelperBase*)ptr;
+}
+
+static int
performBackup_native(JNIEnv* env, jobject clazz, jobject oldState, int data,
jobject newState, jobjectArray files, jobjectArray keys)
{
@@ -66,13 +78,48 @@
return err;
}
+
+static int
+writeFile_native(JNIEnv* env, jobject clazz, jint ptr, jstring filenameObj, int backupReaderPtr)
+{
+ int err;
+ RestoreHelperBase* restore = (RestoreHelperBase*)ptr;
+ BackupDataReader* reader = (BackupDataReader*)backupReaderPtr;
+ char const* filename;
+
+ filename = env->GetStringUTFChars(filenameObj, NULL);
+
+ err = restore->WriteFile(String8(filename), reader);
+
+ env->ReleaseStringUTFChars(filenameObj, filename);
+
+ return err;
+}
+
+static int
+writeSnapshot_native(JNIEnv* env, jobject clazz, jint ptr, jobject fileDescriptor)
+{
+ int err;
+
+ RestoreHelperBase* restore = (RestoreHelperBase*)ptr;
+ int fd = env->GetIntField(fileDescriptor, s_descriptorField);
+
+ err = restore->WriteSnapshot(fd);
+
+ return err;
+}
+
static const JNINativeMethod g_methods[] = {
+ { "ctor", "()I", (void*)ctor },
+ { "dtor", "(I)V", (void*)dtor },
{ "performBackup_native",
"(Ljava/io/FileDescriptor;ILjava/io/FileDescriptor;[Ljava/lang/String;[Ljava/lang/String;)I",
(void*)performBackup_native },
+ { "writeFile_native", "(ILjava/lang/String;I)I", (void*)writeFile_native },
+ { "writeSnapshot_native", "(ILjava/io/FileDescriptor;)I", (void*)writeSnapshot_native },
};
-int register_android_backup_FileBackupHelper(JNIEnv* env)
+int register_android_backup_FileBackupHelperBase(JNIEnv* env)
{
jclass clazz;
@@ -82,7 +129,7 @@
LOG_FATAL_IF(s_descriptorField == NULL,
"Unable to find descriptor field in java.io.FileDescriptor");
- return AndroidRuntime::registerNativeMethods(env, "android/backup/FileBackupHelper",
+ return AndroidRuntime::registerNativeMethods(env, "android/backup/FileBackupHelperBase",
g_methods, NELEM(g_methods));
}
diff --git a/core/jni/android_backup_RestoreHelperBase.cpp b/core/jni/android_backup_RestoreHelperBase.cpp
deleted file mode 100644
index 3173420..0000000
--- a/core/jni/android_backup_RestoreHelperBase.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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/BackupHelpers.h>
-
-namespace android
-{
-
-// java.io.FileDescriptor
-static jfieldID s_descriptorField = 0;
-
-static int
-ctor(JNIEnv* env, jobject clazz)
-{
- return (int)new RestoreHelperBase();
-}
-
-static void
-dtor(JNIEnv* env, jobject clazz, jint ptr)
-{
- delete (RestoreHelperBase*)ptr;
-}
-
-static int
-writeFile_native(JNIEnv* env, jobject clazz, jint ptr, jstring filenameObj, int backupReaderPtr)
-{
- int err;
- RestoreHelperBase* restore = (RestoreHelperBase*)ptr;
- BackupDataReader* reader = (BackupDataReader*)backupReaderPtr;
- char const* filename;
-
- filename = env->GetStringUTFChars(filenameObj, NULL);
-
- err = restore->WriteFile(String8(filename), reader);
-
- env->ReleaseStringUTFChars(filenameObj, filename);
-
- return err;
-}
-
-static int
-writeSnapshot_native(JNIEnv* env, jobject clazz, jint ptr, jobject fileDescriptor)
-{
- int err;
-
- RestoreHelperBase* restore = (RestoreHelperBase*)ptr;
- int fd = env->GetIntField(fileDescriptor, s_descriptorField);
-
- err = restore->WriteSnapshot(fd);
-
- return err;
-}
-
-static const JNINativeMethod g_methods[] = {
- { "ctor", "()I", (void*)ctor },
- { "dtor", "(I)V", (void*)dtor },
- { "writeFile_native", "(ILjava/lang/String;I)I", (void*)writeFile_native },
- { "writeSnapshot_native", "(ILjava/io/FileDescriptor;)I", (void*)writeSnapshot_native },
-};
-
-int register_android_backup_RestoreHelperBase(JNIEnv* env)
-{
- 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/RestoreHelperBase",
- g_methods, NELEM(g_methods));
-}
-
-}