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_MAX 57 } AppSpawnClientType; 58 59 typedef struct { 60 struct ListNode node; 61 uint32_t blockSize; // block 的大小 62 uint32_t currentIndex; // 当前已经填充的位置 63 uint8_t buffer[0]; 64 } AppSpawnMsgBlock; 65 66 typedef struct TagAppSpawnReqMsgMgr { 67 AppSpawnClientType type; 68 uint32_t maxRetryCount; 69 uint32_t timeout; 70 uint32_t msgNextId; 71 int socketId; 72 pthread_mutex_t mutex; 73 AppSpawnMsgBlock recvBlock; // 消息接收缓存 74 } AppSpawnReqMsgMgr; 75 76 typedef struct TagAppSpawnReqMsgNode { 77 struct ListNode node; 78 uint32_t reqId; 79 uint32_t retryCount; 80 int fdCount; 81 int fds[APP_MAX_FD_COUNT]; 82 int isAsan; 83 AppSpawnMsgFlags *msgFlags; 84 AppSpawnMsgFlags *permissionFlags; 85 AppSpawnMsg *msg; 86 struct ListNode msgBlocks; // 保存实际的消息数据 87 } AppSpawnReqMsgNode; 88 89 typedef struct { 90 uint8_t *data; 91 uint16_t dataLen; 92 uint16_t dataType; 93 } AppSpawnAppData; 94 95 int32_t GetPermissionMaxCount(); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 #endif 101