• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_SERVICE_H
17 #define APPSPAWN_SERVICE_H
18 
19 #include <unistd.h>
20 #include <stdbool.h>
21 #include "appspawn_msg.h"
22 #include "appspawn_server.h"
23 #include "init_hashmap.h"
24 #include "loop_event.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifdef APPSPAWN_TEST
31 #define APPSPAWN_STATIC
32 #else
33 #define APPSPAWN_STATIC static
34 #endif
35 
36 #define APP_HASH_BUTT 32
37 #define FLAGS_ON_DEMAND 0x1
38 #define FLAGS_MODE_COLD 0x2
39 #define FLAGS_SANDBOX_PRIVATE 0x10
40 #define FLAGS_SANDBOX_APP 0x20
41 
42 #define START_INDEX 1
43 #define FD_INDEX 2
44 #define PARAM_INDEX 3
45 #define HSP_LIST_LEN_INDEX 4
46 #define HSP_LIST_INDEX 5
47 #define OVERLAY_LEN_INDEX 6
48 #define OVERLAY_INDEX 7
49 #define DIR_LIST_LEN_INDEX 8
50 #define DIR_LIST_INDEX 9
51 #define NULL_INDEX 10
52 #define PARAM_BUFFER_LEN 128
53 typedef struct {
54     AppSpawnClient client;
55     TaskHandle stream;
56     int32_t fd[2];  // 2 fd count
57     AppParameter property;
58     pid_t pid;
59 } AppSpawnClientExt;
60 
61 typedef struct {
62     HashNode node;
63     pid_t pid;
64     char name[0];
65 } AppInfo;
66 
67 typedef struct {
68     AppSpawnContent content;
69     uint32_t flags;
70     TaskHandle server;
71     SignalHandle sigHandler;
72     TimerHandle timer;
73     HashMapHandle appMap;  // save app pid and name
74 } AppSpawnContentExt;
75 
76 void SetContentFunction(AppSpawnContent *content);
77 void AppSpawnColdRun(AppSpawnContent *content, int argc, char *const argv[]);
78 void AddNwebInfo(pid_t pid, const char *processName);
79 int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *client);
80 #define SHOW_CLIENT(info, clientExt) \
81 do { \
82     APPSPAWN_LOGI("Info %{public}s id %{public}d code %{public}d ",                                 \
83         info, (clientExt)->client.id, (clientExt)->property.code);                                  \
84     APPSPAWN_LOGI("processname %{public}s flags 0x%{public}x",                                      \
85         (clientExt)->property.processName, (clientExt)->property.flags);                            \
86     APPSPAWN_LOGI("flags 0x%{public}x cloneFlags 0x%{public}x hapFlags 0x%{public}x",               \
87         (clientExt)->client.flags, (clientExt)->client.cloneFlags, (clientExt)->property.hapFlags); \
88     APPSPAWN_LOGI("bundleName %{public}s soPath %{public}s",                                        \
89         (clientExt)->property.bundleName, (clientExt)->property.soPath);                            \
90     APPSPAWN_LOGI("Access token apl %{public}s renderCmd %{public}s",                               \
91         (clientExt)->property.apl, (clientExt)->property.renderCmd);                                \
92     APPSPAWN_LOGI("uid %{public}u %{public}u gid count %{public}u",                                 \
93         (clientExt)->property.uid, (clientExt)->property.gid, (clientExt)->property.gidCount);      \
94     APPSPAWN_LOGI("setAllowInternet %{public}d allowInternet %{public}d ",                          \
95         (clientExt)->property.setAllowInternet, (clientExt)->property.allowInternet);               \
96 } while (0)
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 #endif  // APPSPAWN_SERVICE_H
102