• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dataloader-jni"
18 
19 #include "core_jni_helpers.h"
20 #include "dataloader_ndk.h"
21 
22 namespace android {
23 namespace {
24 
nativeCreateDataLoader(JNIEnv * env,jobject thiz,jint storageId,jobject control,jobject params,jobject callback)25 static jboolean nativeCreateDataLoader(JNIEnv* env,
26                                        jobject thiz,
27                                        jint storageId,
28                                        jobject control,
29                                        jobject params,
30                                        jobject callback) {
31     return DataLoaderService_OnCreate(env, thiz,
32                      storageId, control, params, callback);
33 }
34 
nativeStartDataLoader(JNIEnv * env,jobject thiz,jint storageId)35 static jboolean nativeStartDataLoader(JNIEnv* env,
36                                       jobject thiz,
37                                       jint storageId) {
38     return DataLoaderService_OnStart(env, storageId);
39 }
40 
nativeStopDataLoader(JNIEnv * env,jobject thiz,jint storageId)41 static jboolean nativeStopDataLoader(JNIEnv* env,
42                                      jobject thiz,
43                                      jint storageId) {
44     return DataLoaderService_OnStop(env, storageId);
45 }
46 
nativeDestroyDataLoader(JNIEnv * env,jobject thiz,jint storageId)47 static jboolean nativeDestroyDataLoader(JNIEnv* env,
48                                         jobject thiz,
49                                         jint storageId) {
50     return DataLoaderService_OnDestroy(env, storageId);
51 }
52 
nativePrepareImage(JNIEnv * env,jobject thiz,jint storageId,jobjectArray addedFiles,jobjectArray removedFiles)53 static jboolean nativePrepareImage(JNIEnv* env, jobject thiz, jint storageId,
54                                    jobjectArray addedFiles, jobjectArray removedFiles) {
55     return DataLoaderService_OnPrepareImage(env, storageId, addedFiles, removedFiles);
56 }
57 
nativeWriteData(JNIEnv * env,jobject clazz,jlong self,jstring name,jlong offsetBytes,jlong lengthBytes,jobject incomingFd)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);
67 }
68 
69 static const JNINativeMethod dlc_method_table[] = {
70         {"nativeCreateDataLoader",
71          "(ILandroid/content/pm/FileSystemControlParcel;"
72          "Landroid/content/pm/DataLoaderParamsParcel;"
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},
78         {"nativePrepareImage",
79          "(I[Landroid/content/pm/InstallationFileParcel;[Ljava/lang/String;)Z",
80          (void*)nativePrepareImage},
81         {"nativeWriteData", "(JLjava/lang/String;JJLandroid/os/ParcelFileDescriptor;)V",
82          (void*)nativeWriteData},
83 };
84 
85 }  // namespace
86 
register_android_service_DataLoaderService(JNIEnv * env)87 int register_android_service_DataLoaderService(JNIEnv* env) {
88     return jniRegisterNativeMethods(env,
89                                     "android/service/dataloader/DataLoaderService",
90                                     dlc_method_table, NELEM(dlc_method_table));
91 }
92 
93 }  // namespace android
94