blob: 44bff018854462a6f85a44106c642a568a2db2db [file] [log] [blame]
Songchun Fan3c82a302019-11-29 14:23:45 -08001/*
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
27namespace android {
28
Alex Buynytskyyd8b25b82020-02-04 11:44:20 -080029static jboolean nativeIsEnabled(JNIEnv* env, jobject clazz) {
30 return IncFs_IsEnabled();
31}
32
Songchun Fan3c82a302019-11-29 14:23:45 -080033static 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 Buynytskyycd4d3872020-02-08 17:50:50 -080040static 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
56static 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 Fan3c82a302019-11-29 14:23:45 -080062
63int 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