• 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 EXTRA_INFO_LEN_INDEX 4
46 #define EXTRA_INFO_INDEX 5
47 #define NULL_INDEX 6
48 #define PARAM_BUFFER_LEN 128
49 typedef struct {
50     AppSpawnClient client;
51     TaskHandle stream;
52     int32_t fd[2];  // 2 fd count
53     AppParameter property;
54     pid_t pid;
55 } AppSpawnClientExt;
56 
57 typedef struct {
58     HashNode node;
59     pid_t pid;
60     char name[0];
61 } AppInfo;
62 
63 typedef struct {
64     AppSpawnContent content;
65     uint32_t flags;
66     TaskHandle server;
67     SignalHandle sigHandler;
68     TimerHandle timer;
69     HashMapHandle appMap;  // save app pid and name
70 } AppSpawnContentExt;
71 
72 void SetContentFunction(AppSpawnContent *content);
73 void AppSpawnColdRun(AppSpawnContent *content, int argc, char *const argv[]);
74 void AddNwebInfo(pid_t pid, const char *processName);
75 int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *client);
76 #define SHOW_CLIENT(info, clientExt) \
77 do { \
78     APPSPAWN_LOGI("Info %{public}s id %{public}d code %{public}d ",                                 \
79         info, (clientExt)->client.id, (clientExt)->property.code);                                  \
80     APPSPAWN_LOGI("processname %{public}s flags 0x%{public}x",                                      \
81         (clientExt)->property.processName, (clientExt)->property.flags);                            \
82     APPSPAWN_LOGI("flags 0x%{public}x cloneFlags 0x%{public}x hapFlags 0x%{public}x",               \
83         (clientExt)->client.flags, (clientExt)->client.cloneFlags, (clientExt)->property.hapFlags); \
84     APPSPAWN_LOGI("bundleName %{public}s soPath %{public}s",                                        \
85         (clientExt)->property.bundleName, (clientExt)->property.soPath);                            \
86     APPSPAWN_LOGI("Access token apl %{public}s renderCmd %{public}s ownerId %{public}s",            \
87         (clientExt)->property.apl, (clientExt)->property.renderCmd, (clientExt)->property.ownerId); \
88     APPSPAWN_LOGI("uid %{public}u %{public}u gid count %{public}u",                                 \
89         (clientExt)->property.uid, (clientExt)->property.gid, (clientExt)->property.gidCount);      \
90     APPSPAWN_LOGI("setAllowInternet %{public}d allowInternet %{public}d ",                          \
91         (clientExt)->property.setAllowInternet, (clientExt)->property.allowInternet);               \
92 } while (0)
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 #endif  // APPSPAWN_SERVICE_H
98