diff options
author | Joe Onorato <joeo@android.com> | 2009-06-18 20:10:37 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-06-22 13:02:24 -0700 |
commit | 06290a4bb9b280fa14a2bbeb2d3ceb09396a78c3 (patch) | |
tree | 15fccf5ce4e9c42bba3fc7581ac2ddc0d8363dc9 /core/jni | |
parent | eed76b2a8ddc41af01cd3ae87c4722f3784c975c (diff) | |
download | frameworks_base-06290a4bb9b280fa14a2bbeb2d3ceb09396a78c3.zip frameworks_base-06290a4bb9b280fa14a2bbeb2d3ceb09396a78c3.tar.gz frameworks_base-06290a4bb9b280fa14a2bbeb2d3ceb09396a78c3.tar.bz2 |
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.
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/Android.mk | 3 | ||||
-rw-r--r-- | core/jni/AndroidRuntime.cpp | 6 | ||||
-rw-r--r-- | core/jni/android_backup_BackupDataOutput.cpp | 15 | ||||
-rw-r--r-- | core/jni/android_backup_FileBackupHelperBase.cpp (renamed from core/jni/android_backup_FileBackupHelper.cpp) | 51 | ||||
-rw-r--r-- | core/jni/android_backup_RestoreHelperBase.cpp | 94 |
5 files changed, 67 insertions, 102 deletions
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 @@ LOCAL_SRC_FILES:= \ 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_util_Base64(JNIEnv* env); 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 @@ static const RegJNIRec gRegJNI[] = { 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 @@ writeEntityData_native(JNIEnv* env, jobject clazz, int w, jbyteArray data, int s 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 index 418db8a..8225a36 100644 --- a/core/jni/android_backup_FileBackupHelper.cpp +++ b/core/jni/android_backup_FileBackupHelperBase.cpp @@ -29,6 +29,18 @@ namespace android 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 @@ performBackup_native(JNIEnv* env, jobject clazz, jobject oldState, int data, 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 @@ int register_android_backup_FileBackupHelper(JNIEnv* env) 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)); -} - -} |