Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -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 | |
Alex Buynytskyy | 89247d2 | 2019-12-11 12:07:23 -0800 | [diff] [blame] | 17 | #define LOG_TAG "dataloader-jni" |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 18 | |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 19 | #include "core_jni_helpers.h" |
Alex Buynytskyy | 89247d2 | 2019-12-11 12:07:23 -0800 | [diff] [blame] | 20 | #include "dataloader_ndk.h" |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 21 | |
| 22 | namespace android { |
| 23 | namespace { |
| 24 | |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 25 | static jboolean nativeCreateDataLoader(JNIEnv* env, |
| 26 | jobject thiz, |
| 27 | jint storageId, |
| 28 | jobject control, |
| 29 | jobject params, |
| 30 | jobject callback) { |
Alex Buynytskyy | 89247d2 | 2019-12-11 12:07:23 -0800 | [diff] [blame] | 31 | return DataLoaderService_OnCreate(env, thiz, |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 32 | storageId, control, params, callback); |
| 33 | } |
| 34 | |
| 35 | static jboolean nativeStartDataLoader(JNIEnv* env, |
| 36 | jobject thiz, |
| 37 | jint storageId) { |
Alex Buynytskyy | 7f3ff5b | 2020-01-22 07:54:38 -0800 | [diff] [blame] | 38 | return DataLoaderService_OnStart(env, storageId); |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static jboolean nativeStopDataLoader(JNIEnv* env, |
| 42 | jobject thiz, |
| 43 | jint storageId) { |
Alex Buynytskyy | 7f3ff5b | 2020-01-22 07:54:38 -0800 | [diff] [blame] | 44 | return DataLoaderService_OnStop(env, storageId); |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static jboolean nativeDestroyDataLoader(JNIEnv* env, |
| 48 | jobject thiz, |
| 49 | jint storageId) { |
Alex Buynytskyy | 7f3ff5b | 2020-01-22 07:54:38 -0800 | [diff] [blame] | 50 | return DataLoaderService_OnDestroy(env, storageId); |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 54 | static jboolean nativePrepareImage(JNIEnv* env, jobject thiz, jint storageId, jobject addedFiles, jobject removedFiles) { |
Alex Buynytskyy | 7f3ff5b | 2020-01-22 07:54:38 -0800 | [diff] [blame] | 55 | return DataLoaderService_OnPrepareImage(env, storageId, addedFiles, removedFiles); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void nativeWriteData(JNIEnv* env, |
| 59 | jobject clazz, |
| 60 | jlong self, |
| 61 | jstring name, |
| 62 | jlong offsetBytes, |
| 63 | jlong lengthBytes, |
| 64 | jobject incomingFd) { |
| 65 | auto connector = (DataLoaderFilesystemConnectorPtr)self; |
| 66 | return DataLoader_FilesystemConnector_writeData(connector, name, offsetBytes, lengthBytes, incomingFd); |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static const JNINativeMethod dlc_method_table[] = { |
| 70 | {"nativeCreateDataLoader", |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 71 | "(ILandroid/content/pm/FileSystemControlParcel;" |
| 72 | "Landroid/content/pm/DataLoaderParamsParcel;" |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 73 | "Landroid/content/pm/IDataLoaderStatusListener;)Z", |
| 74 | (void*)nativeCreateDataLoader}, |
| 75 | {"nativeStartDataLoader", "(I)Z", (void*)nativeStartDataLoader}, |
| 76 | {"nativeStopDataLoader", "(I)Z", (void*)nativeStopDataLoader}, |
| 77 | {"nativeDestroyDataLoader", "(I)Z", (void*)nativeDestroyDataLoader}, |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 78 | {"nativePrepareImage", "(ILjava/util/Collection;Ljava/util/Collection;)Z", (void*)nativePrepareImage}, |
| 79 | {"nativeWriteData", "(JLjava/lang/String;JJLandroid/os/ParcelFileDescriptor;)V", (void*)nativeWriteData}, |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace |
| 83 | |
Alex Buynytskyy | 89247d2 | 2019-12-11 12:07:23 -0800 | [diff] [blame] | 84 | int register_android_service_DataLoaderService(JNIEnv* env) { |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 85 | return jniRegisterNativeMethods(env, |
Alex Buynytskyy | ea14d19 | 2019-12-13 15:42:18 -0800 | [diff] [blame] | 86 | "android/service/dataloader/DataLoaderService", |
Songchun Fan | 1a52cf7 | 2019-12-05 13:00:47 -0800 | [diff] [blame] | 87 | dlc_method_table, NELEM(dlc_method_table)); |
| 88 | } |
| 89 | |
| 90 | } // namespace android |