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 #ifndef ANDROID_INCREMENTAL_FILE_SYSTEM_DATA_LOADER_NDK_H 18 #define ANDROID_INCREMENTAL_FILE_SYSTEM_DATA_LOADER_NDK_H 19 20 #include <incfs_ndk.h> 21 #include <jni.h> 22 23 __BEGIN_DECLS 24 25 #define DATALOADER_LIBRARY_NAME "libdataloader.so" 26 27 typedef enum { 28 DATA_LOADER_UNAVAILABLE = 7, 29 DATA_LOADER_UNRECOVERABLE = 8, 30 } DataLoaderStatus; 31 32 typedef enum { 33 DATA_LOADER_TYPE_NONE = 0, 34 DATA_LOADER_TYPE_STREAMING = 1, 35 DATA_LOADER_TYPE_INCREMENTAL = 2, 36 } DataLoaderType; 37 38 typedef enum { 39 DATA_LOADER_LOCATION_DATA_APP = 0, 40 DATA_LOADER_LOCATION_MEDIA_OBB = 1, 41 DATA_LOADER_LOCATION_MEDIA_DATA = 2, 42 } DataLoaderLocation; 43 44 typedef enum { 45 DATA_LOADER_FEATURE_NONE = 0, 46 DATA_LOADER_FEATURE_UID = 1 << 0, 47 } DataLoaderFeatures; 48 49 struct DataLoaderParams { 50 int type; 51 const char* packageName; 52 const char* className; 53 const char* arguments; 54 }; 55 56 typedef struct { 57 int location; 58 const char* name; 59 IncFsSize size; 60 IncFsSpan metadata; 61 } DataLoaderInstallationFile; 62 63 typedef struct { 64 bool readLogsEnabled; 65 } DataLoaderFilesystemParams; 66 67 #ifdef __cplusplus 68 69 typedef class DataLoaderFilesystemConnector { 70 } * DataLoaderFilesystemConnectorPtr; 71 typedef class DataLoaderStatusListener { 72 } * DataLoaderStatusListenerPtr; 73 74 #else /* not __cplusplus */ 75 76 typedef void* DataLoaderFilesystemConnectorPtr; 77 typedef void* DataLoaderStatusListenerPtr; 78 79 #endif /* not __cplusplus */ 80 81 typedef JavaVM* DataLoaderServiceVmPtr; 82 typedef jobject DataLoaderServiceConnectorPtr; 83 typedef jobject DataLoaderServiceParamsPtr; 84 85 struct DataLoader { 86 // DataLoader v1. 87 bool (*onStart)(struct DataLoader* self); 88 void (*onStop)(struct DataLoader* self); 89 void (*onDestroy)(struct DataLoader* self); 90 91 bool (*onPrepareImage)(struct DataLoader* self, const DataLoaderInstallationFile addedFiles[], 92 int addedFilesCount); 93 94 void (*onPendingReads)(struct DataLoader* self, const IncFsReadInfo pendingReads[], 95 int pendingReadsCount); 96 void (*onPageReads)(struct DataLoader* self, const IncFsReadInfo pageReads[], 97 int pageReadsCount); 98 99 // DataLoader v2, with features. 100 // Use DataLoader_Initialize_WithFeatures to set a factory for v2 DataLoader. 101 DataLoaderFeatures (*getFeatures)(struct DataLoader* self); 102 103 void (*onPendingReadsWithUid)(struct DataLoader* self, 104 const IncFsReadInfoWithUid pendingReads[], int pendingReadsCount); 105 void (*onPageReadsWithUid)(struct DataLoader* self, const IncFsReadInfoWithUid pageReads[], 106 int pageReadsCount); 107 }; 108 109 struct DataLoaderFactory { 110 struct DataLoader* (*onCreate)(struct DataLoaderFactory* self, const struct DataLoaderParams*, 111 DataLoaderFilesystemConnectorPtr, DataLoaderStatusListenerPtr, 112 DataLoaderServiceVmPtr, DataLoaderServiceConnectorPtr, 113 DataLoaderServiceParamsPtr); 114 }; 115 void DataLoader_Initialize(struct DataLoaderFactory*); 116 void DataLoader_Initialize_WithFeatures(struct DataLoaderFactory*); 117 118 void DataLoader_FilesystemConnector_writeData(DataLoaderFilesystemConnectorPtr, jstring name, 119 jlong offsetBytes, jlong lengthBytes, 120 jobject incomingFd); 121 122 // Returns a newly opened file descriptor and gives the ownership to the caller. 123 int DataLoader_FilesystemConnector_openForSpecialOps(DataLoaderFilesystemConnectorPtr, 124 IncFsFileId fid); 125 126 int DataLoader_FilesystemConnector_writeBlocks(DataLoaderFilesystemConnectorPtr, 127 const IncFsDataBlock blocks[], int blocksCount); 128 // INCFS_MAX_FILE_ATTR_SIZE 129 int DataLoader_FilesystemConnector_getRawMetadata(DataLoaderFilesystemConnectorPtr, IncFsFileId fid, 130 char buffer[], size_t* bufferSize); 131 132 bool DataLoader_FilesystemConnector_setParams(DataLoaderFilesystemConnectorPtr, 133 DataLoaderFilesystemParams params); 134 135 int DataLoader_StatusListener_reportStatus(DataLoaderStatusListenerPtr listener, 136 DataLoaderStatus status); 137 138 // DataLoaderService JNI 139 bool DataLoaderService_OnCreate(JNIEnv* env, jobject service, jint storageId, jobject control, 140 jobject params, jobject listener); 141 bool DataLoaderService_OnStart(JNIEnv* env, jint storageId); 142 bool DataLoaderService_OnStop(JNIEnv* env, jint storageId); 143 bool DataLoaderService_OnDestroy(JNIEnv* env, jint storageId); 144 145 bool DataLoaderService_OnPrepareImage(JNIEnv* env, jint storageId, jobjectArray addedFiles, 146 jobjectArray removedFiles); 147 148 __END_DECLS 149 150 #endif // ANDROID_INCREMENTAL_FILE_SYSTEM_DATA_LOADER_NDK_H 151