Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "incremental_manager-jni" |
| 18 | |
| 19 | #include "core_jni_helpers.h" |
| 20 | #include "incfs_ndk.h" |
| 21 | #include "jni.h" |
| 22 | #include "nativehelper/JNIHelp.h" |
| 23 | |
| 24 | #include <iterator> |
| 25 | #include <memory> |
| 26 | |
| 27 | namespace android { |
| 28 | |
Alex Buynytskyy | d8b25b8 | 2020-02-04 11:44:20 -0800 | [diff] [blame] | 29 | static jboolean nativeIsEnabled(JNIEnv* env, jobject clazz) { |
| 30 | return IncFs_IsEnabled(); |
| 31 | } |
| 32 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 33 | static jboolean nativeIsIncrementalPath(JNIEnv* env, |
| 34 | jobject clazz, |
| 35 | jstring javaPath) { |
| 36 | ScopedUtfChars path(env, javaPath); |
| 37 | return (jboolean)IncFs_IsIncFsPath(path.c_str()); |
| 38 | } |
| 39 | |
Alex Buynytskyy | cd4d387 | 2020-02-08 17:50:50 -0800 | [diff] [blame] | 40 | static jbyteArray nativeUnsafeGetFileSignature(JNIEnv* env, jobject clazz, jstring javaPath) { |
| 41 | ScopedUtfChars path(env, javaPath); |
| 42 | |
| 43 | char signature[INCFS_MAX_SIGNATURE_SIZE]; |
| 44 | size_t size = sizeof(signature); |
| 45 | if (IncFs_UnsafeGetSignatureByPath(path.c_str(), signature, &size) < 0) { |
| 46 | return nullptr; |
| 47 | } |
| 48 | |
| 49 | jbyteArray result = env->NewByteArray(size); |
| 50 | if (result != nullptr) { |
| 51 | env->SetByteArrayRegion(result, 0, size, (const jbyte*)signature); |
| 52 | } |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | static const JNINativeMethod method_table[] = {{"nativeIsEnabled", "()Z", (void*)nativeIsEnabled}, |
| 57 | {"nativeIsIncrementalPath", "(Ljava/lang/String;)Z", |
| 58 | (void*)nativeIsIncrementalPath}, |
| 59 | {"nativeUnsafeGetFileSignature", |
| 60 | "(Ljava/lang/String;)[B", |
| 61 | (void*)nativeUnsafeGetFileSignature}}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 62 | |
| 63 | int register_android_os_incremental_IncrementalManager(JNIEnv* env) { |
| 64 | return jniRegisterNativeMethods(env, "android/os/incremental/IncrementalManager", |
| 65 | method_table, std::size(method_table)); |
| 66 | } |
| 67 | |
| 68 | } // namespace android |