Joe Onorato | d2110db | 2009-05-19 13:41:21 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "FileBackupHelper_native" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include "JNIHelp.h" |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | |
| 23 | #include <utils/backup_helpers.h> |
| 24 | |
| 25 | namespace android |
| 26 | { |
| 27 | |
| 28 | static jfieldID s_descriptorField = 0; |
| 29 | |
| 30 | static int |
| 31 | ctor_native(JNIEnv* env, jobject This, jobject fileDescriptor) |
| 32 | { |
| 33 | int err; |
| 34 | |
| 35 | int fd = env->GetIntField(fileDescriptor, s_descriptorField); |
| 36 | if (fd == -1) { |
| 37 | return NULL; |
| 38 | } |
| 39 | |
| 40 | return (int)new BackupDataWriter(fd); |
| 41 | } |
| 42 | |
| 43 | static void |
| 44 | dtor_native(JNIEnv* env, jobject This, int fd) |
| 45 | { |
| 46 | delete (BackupDataWriter*)fd; |
| 47 | } |
| 48 | |
| 49 | static const JNINativeMethod g_methods[] = { |
| 50 | { "ctor", "(Ljava/io/FileDescriptor;)I", (void*)ctor_native }, |
| 51 | { "dtor", "(I)V", (void*)dtor_native }, |
| 52 | }; |
| 53 | |
| 54 | int register_android_backup_BackupDataOutput(JNIEnv* env) |
| 55 | { |
| 56 | LOGD("register_android_backup_BackupDataOutput"); |
| 57 | |
| 58 | jclass clazz; |
| 59 | |
| 60 | clazz = env->FindClass("java/io/FileDescriptor"); |
| 61 | LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor"); |
| 62 | s_descriptorField = env->GetFieldID(clazz, "descriptor", "I"); |
| 63 | LOG_FATAL_IF(s_descriptorField == NULL, |
| 64 | "Unable to find descriptor field in java.io.FileDescriptor"); |
| 65 | |
| 66 | return AndroidRuntime::registerNativeMethods(env, "android/backup/BackupDataOutput", |
| 67 | g_methods, NELEM(g_methods)); |
| 68 | } |
| 69 | |
| 70 | } |