1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef APPSPAWN_CLIENT_H 17 #define APPSPAWN_CLIENT_H 18 #include <pthread.h> 19 #include <stdint.h> 20 #include <stdlib.h> 21 22 #include "appspawn_msg.h" 23 #include "list.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #ifdef ASAN_DETECTOR 30 #define TIMEOUT_DEF 60 31 #define ASAN_TIMEOUT 60 32 #else 33 #define TIMEOUT_DEF 2 34 #define ASAN_TIMEOUT 5 35 #endif 36 37 #define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000 38 #define MAX_RETRY_SEND_COUNT 2 // 2 max retry count CONNECT_RETRY_MAX_TIMES = 2; 39 40 // only used for ExternalFileManager.hap 41 #define GID_FILE_ACCESS 1006 42 #define GID_USER_DATA_RW 1008 43 44 #define MAX_DATA_IN_TLV 2 45 46 struct TagAppSpawnReqMsgNode; 47 typedef enum { 48 CLIENT_FOR_APPSPAWN, 49 CLIENT_FOR_NWEBSPAWN, 50 CLIENT_FOR_CJAPPSPAWN, 51 CLIENT_FOR_NATIVESPAWN, 52 CLIENT_MAX 53 } AppSpawnClientType; 54 55 typedef struct { 56 struct ListNode node; 57 uint32_t blockSize; // block 的大小 58 uint32_t currentIndex; // 当前已经填充的位置 59 uint8_t buffer[0]; 60 } AppSpawnMsgBlock; 61 62 typedef struct TagAppSpawnReqMsgMgr { 63 AppSpawnClientType type; 64 uint32_t maxRetryCount; 65 uint32_t timeout; 66 uint32_t msgNextId; 67 int socketId; 68 pthread_mutex_t mutex; 69 AppSpawnMsgBlock recvBlock; // 消息接收缓存 70 } AppSpawnReqMsgMgr; 71 72 typedef struct TagAppSpawnReqMsgNode { 73 struct ListNode node; 74 uint32_t reqId; 75 uint32_t retryCount; 76 int fdCount; 77 int fds[APP_MAX_FD_COUNT]; 78 int isAsan; 79 AppSpawnMsgFlags *msgFlags; 80 AppSpawnMsgFlags *permissionFlags; 81 AppSpawnMsg *msg; 82 struct ListNode msgBlocks; // 保存实际的消息数据 83 } AppSpawnReqMsgNode; 84 85 typedef struct { 86 uint8_t *data; 87 uint16_t dataLen; 88 uint16_t dataType; 89 } AppSpawnAppData; 90 91 int32_t GetPermissionMaxCount(); 92 93 #ifdef __cplusplus 94 } 95 #endif 96 #endif 97