• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include <cstdint>
14 #include <cstdio>
15 #include <ctime>
16 #include <securec.h>
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include "tee_client_type.h"
21 #include "tee_log.h"
22 #include "tc_ns_client.h"
23 #include "tui_event.h"
24 
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28 #define LOG_TAG "tee_tui_daemon"
29 
30 using namespace std;
31 
32 static TUIEvent *g_tuiEventInstance = nullptr;
33 static TUIDaemon *g_tuiDaemon = nullptr;
34 static bool g_tuiDaemonInit = false;
35 static bool g_tuiFoldable = false;
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 static const uint32_t TUI_POLL_FOLD   = 26;
42 
43 static void TuiDaemonClear();
44 
TuiDaemonInit(bool onlyConfigRes)45 static bool TuiDaemonInit(bool onlyConfigRes)
46 {
47     if (g_tuiDaemonInit) {
48         return true;
49     }
50 
51     g_tuiDaemon = new TUIDaemon();
52     if (g_tuiDaemon == nullptr) {
53         return false;
54     }
55 
56     g_tuiDaemon->TuiDaemonInit(onlyConfigRes);
57     g_tuiEventInstance = TUIEvent::GetInstance();
58     if (!g_tuiEventInstance->TUIGetPannelInfo()) {
59         TuiDaemonClear();
60         return false;
61     }
62 
63     g_tuiFoldable = g_tuiEventInstance->TUIGetFoldableStatus();
64     tlogi("TuiDaemonInit g_tuiFoldable %" PUBLIC "d\n", g_tuiFoldable);
65     if (!g_tuiEventInstance->TUISendCmd(TUI_POLL_FOLD)) {
66         TuiDaemonClear();
67         return false;
68     }
69 
70     g_tuiDaemonInit = true;
71     return g_tuiDaemonInit;
72 }
73 
TuiDaemonClear()74 static void TuiDaemonClear()
75 {
76     if (g_tuiDaemon != nullptr) {
77         delete g_tuiDaemon;
78         g_tuiDaemon = nullptr;
79     }
80 
81     g_tuiDaemonInit = false;
82 }
83 
TeeTuiDaemonWork(int tuiState)84 bool TeeTuiDaemonWork(int tuiState)
85 {
86     if (tuiState <= TUI_STATE_INVALID || tuiState >= TUI_STATE_MAX) {
87         tlogi("invalid tui cmd\n");
88         return false;
89     }
90 
91     bool onlyConfigRes = false;
92     if (tuiState == TUI_STATE_INIT) {
93         onlyConfigRes = true;
94     }
95 
96     if (!TuiDaemonInit(onlyConfigRes)) {
97         return false;
98     }
99 
100     if (tuiState == TUI_STATE_TUI_START) {
101         tlogi("send true state to frame 2\n");
102         g_tuiEventInstance->TUIDealWithEvent(true);
103     } else if (tuiState == TUI_STATE_TUI_END) {
104         tlogi("send false state to frame 2\n");
105         g_tuiEventInstance->TUIDealWithEvent(false);
106         TuiDaemonClear();
107     }
108 
109     return true;
110 }
111 
TeeTuiIsFoldable(void)112 bool TeeTuiIsFoldable(void)
113 {
114     return g_tuiFoldable;
115 }
116 
117 #ifdef __cplusplus
118 }
119 #endif
120