blob: b307a73ed05b89ec437aed7658b02c636b40ad5b [file] [log] [blame]
Songchun Fan1a52cf72019-12-05 13:00:47 -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
Alex Buynytskyy89247d22019-12-11 12:07:23 -080017#define LOG_TAG "dataloader-jni"
Songchun Fan1a52cf72019-12-05 13:00:47 -080018
Songchun Fan1a52cf72019-12-05 13:00:47 -080019#include "core_jni_helpers.h"
Alex Buynytskyy89247d22019-12-11 12:07:23 -080020#include "dataloader_ndk.h"
Songchun Fan1a52cf72019-12-05 13:00:47 -080021
22namespace android {
23namespace {
24
Songchun Fan1a52cf72019-12-05 13:00:47 -080025static jboolean nativeCreateDataLoader(JNIEnv* env,
26 jobject thiz,
27 jint storageId,
28 jobject control,
29 jobject params,
30 jobject callback) {
Alex Buynytskyy89247d22019-12-11 12:07:23 -080031 return DataLoaderService_OnCreate(env, thiz,
Songchun Fan1a52cf72019-12-05 13:00:47 -080032 storageId, control, params, callback);
33}
34
35static jboolean nativeStartDataLoader(JNIEnv* env,
36 jobject thiz,
37 jint storageId) {
Alex Buynytskyy7f3ff5b2020-01-22 07:54:38 -080038 return DataLoaderService_OnStart(env, storageId);
Songchun Fan1a52cf72019-12-05 13:00:47 -080039}
40
41static jboolean nativeStopDataLoader(JNIEnv* env,
42 jobject thiz,
43 jint storageId) {
Alex Buynytskyy7f3ff5b2020-01-22 07:54:38 -080044 return DataLoaderService_OnStop(env, storageId);
Songchun Fan1a52cf72019-12-05 13:00:47 -080045}
46
47static jboolean nativeDestroyDataLoader(JNIEnv* env,
48 jobject thiz,
49 jint storageId) {
Alex Buynytskyy7f3ff5b2020-01-22 07:54:38 -080050 return DataLoaderService_OnDestroy(env, storageId);
Songchun Fan1a52cf72019-12-05 13:00:47 -080051}
52
53
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080054static jboolean nativePrepareImage(JNIEnv* env, jobject thiz, jint storageId, jobject addedFiles, jobject removedFiles) {
Alex Buynytskyy7f3ff5b2020-01-22 07:54:38 -080055 return DataLoaderService_OnPrepareImage(env, storageId, addedFiles, removedFiles);
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -080056}
57
58static 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 Fan1a52cf72019-12-05 13:00:47 -080067}
68
69static const JNINativeMethod dlc_method_table[] = {
70 {"nativeCreateDataLoader",
Alex Buynytskyyea14d192019-12-13 15:42:18 -080071 "(ILandroid/content/pm/FileSystemControlParcel;"
72 "Landroid/content/pm/DataLoaderParamsParcel;"
Songchun Fan1a52cf72019-12-05 13:00:47 -080073 "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 Buynytskyy1ecfcec2019-12-17 12:10:41 -080078 {"nativePrepareImage", "(ILjava/util/Collection;Ljava/util/Collection;)Z", (void*)nativePrepareImage},
79 {"nativeWriteData", "(JLjava/lang/String;JJLandroid/os/ParcelFileDescriptor;)V", (void*)nativeWriteData},
Songchun Fan1a52cf72019-12-05 13:00:47 -080080};
81
82} // namespace
83
Alex Buynytskyy89247d22019-12-11 12:07:23 -080084int register_android_service_DataLoaderService(JNIEnv* env) {
Songchun Fan1a52cf72019-12-05 13:00:47 -080085 return jniRegisterNativeMethods(env,
Alex Buynytskyyea14d192019-12-13 15:42:18 -080086 "android/service/dataloader/DataLoaderService",
Songchun Fan1a52cf72019-12-05 13:00:47 -080087 dlc_method_table, NELEM(dlc_method_table));
88}
89
90} // namespace android