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 10 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 #define NORMAL_READ_RETRY_TIME (3 * 1000 * 1000 + 500 * 1000) // 3.5s, Exceed WAIT_CHILD_RESPONSE_TIMEOUT by 0.5s 41 // Exceed COLD_CHILD_RESPONSE_TIMEOUT by 0.5s 42 #define COLDRUN_READ_RETRY_TIME (ASAN_TIMEOUT * 1000 * 1000 + 500 * 1000) 43 44 // only used for ExternalFileManager.hap 45 #define GID_FILE_ACCESS 1006 46 #define GID_USER_DATA_RW 1008 47 48 #define MAX_DATA_IN_TLV 2 49 50 struct TagAppSpawnReqMsgNode; 51 typedef enum { 52 CLIENT_FOR_APPSPAWN, 53 CLIENT_FOR_NWEBSPAWN, 54 CLIENT_FOR_CJAPPSPAWN, 55 CLIENT_FOR_NATIVESPAWN, 56 CLIENT_FOR_HYBRIDSPAWN, 57 CLIENT_MAX 58 } AppSpawnClientType; 59 60 typedef struct { 61 struct ListNode node; 62 uint32_t blockSize; // block 的大小 63 uint32_t currentIndex; // 当前已经填充的位置 64 uint8_t buffer[0]; 65 } AppSpawnMsgBlock; 66 67 typedef struct TagAppSpawnReqMsgMgr { 68 AppSpawnClientType type; 69 uint32_t maxRetryCount; 70 uint32_t timeout; 71 uint32_t msgNextId; 72 int socketId; 73 pthread_mutex_t mutex; 74 AppSpawnMsgBlock recvBlock; // 消息接收缓存 75 } AppSpawnReqMsgMgr; 76 77 typedef struct TagAppSpawnReqMsgNode { 78 struct ListNode node; 79 uint32_t reqId; 80 uint32_t retryCount; 81 int fdCount; 82 int fds[APP_MAX_FD_COUNT]; 83 int isAsan; 84 AppSpawnMsgFlags *msgFlags; 85 AppSpawnMsgFlags *permissionFlags; 86 AppSpawnMsg *msg; 87 struct ListNode msgBlocks; // 保存实际的消息数据 88 } AppSpawnReqMsgNode; 89 90 typedef struct { 91 uint8_t *data; 92 uint16_t dataLen; 93 uint16_t dataType; 94 } AppSpawnAppData; 95 96 int32_t GetPermissionMaxCount(); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 #endif 102