bd1b319a0ddf53b86b5e200a4391c270912b249f
[apps/agl-service-windowmanager-2017.git] / policy_manager / stm / stub / stm_inner.c
1 /*
2  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <string.h>
18 #include "stm.h"
19 #include "stm_inner.h"
20
21 static StmState g_stm_crr_state;
22 static StmState g_stm_prv_state;
23
24 void stmInitializeInner() {
25     // Initialize previous state
26     memset(&g_stm_prv_state, 0, sizeof(g_stm_prv_state));
27
28     // Initialize current state
29     g_stm_crr_state = g_stm_prv_state;
30 }
31
32 int stmTransitionStateInner(int event, StmState* state) {
33     int event_no, category_no, area_no;
34
35     event_no    = STM_GET_EVENT_FROM_ID(event);
36     category_no = STM_GET_CATEGORY_FROM_ID(event);
37     area_no     = STM_GET_AREA_FROM_ID(event);
38
39     // Backup previous state
40     g_stm_prv_state = g_stm_crr_state;
41
42     // -------------------------------------------------------
43     // There is no policy table by default.
44     // Therefore update each layers
45     // to draw the applications in requested area
46     // in accordance with inputed activate/deactivate events.
47     // -------------------------------------------------------
48     if (StmEvtNoActivate == event_no)
49     {
50         if (StmCtgNoHomescreen == category_no)
51         {
52             g_stm_crr_state.layer[StmLayerNoHomescreen].state = StmLayoutNoHms;
53             g_stm_crr_state.layer[StmLayerNoHomescreen].changed = STM_TRUE;
54
55             // For AGL JIRA SPEC-1407
56             // Apps layer is invisibled only when Homescreen app is started already
57             if (StmLayoutNoHms == g_stm_prv_state.layer[StmLayerNoHomescreen].state)
58             {
59                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
60                 g_stm_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
61             }
62         }
63         else if (StmCtgNoDebug == category_no)
64         {
65             if (StmAreaNoNormal == area_no)
66             {
67                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoDbgNml;
68             }
69             else if (StmAreaNoSplitMain == area_no)
70             {
71                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoDbgSplMain;
72             }
73             else if (StmAreaNoSplitSub == area_no)
74             {
75                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoDbgSplSub;
76             }
77             else if (StmAreaNoFullscreen == area_no)
78             {
79                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoDbgFll;
80             }
81             g_stm_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
82         }
83         else if (StmCtgNoSoftwareKeyboard == category_no)
84         {
85             g_stm_crr_state.layer[StmLayerNoNearHomescreen].state = StmLayoutNoSftKbd;
86             g_stm_crr_state.layer[StmLayerNoNearHomescreen].changed = STM_TRUE;
87         }
88         else if (StmCtgNoPopUp == category_no)
89         {
90             g_stm_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoPopUp;
91             g_stm_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
92         }
93         else if (StmCtgNoSystemAlert == category_no)
94         {
95             g_stm_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoSysAlt;
96             g_stm_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
97         }
98     }
99     else if (StmEvtNoDeactivate == event_no)
100     {
101         if (StmCtgNoHomescreen == category_no)
102         {
103             g_stm_crr_state.layer[StmLayerNoHomescreen].state = StmLayoutNoNone;
104             g_stm_crr_state.layer[StmLayerNoHomescreen].changed = STM_TRUE;
105         }
106         else if (StmCtgNoDebug == category_no)
107         {
108             if ((StmLayoutNoDbgNml     == g_stm_prv_state.layer[StmLayerNoApps].state) ||
109                 (StmLayoutNoDbgSplMain == g_stm_prv_state.layer[StmLayerNoApps].state) ||
110                 (StmLayoutNoDbgSplSub  == g_stm_prv_state.layer[StmLayerNoApps].state) ||
111                 (StmLayoutNoDbgFll     == g_stm_prv_state.layer[StmLayerNoApps].state))
112             {
113                 g_stm_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
114                 g_stm_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
115             }
116         }
117         else if (StmCtgNoSoftwareKeyboard == category_no)
118         {
119             if (StmLayoutNoSftKbd == g_stm_prv_state.layer[StmLayerNoNearHomescreen].state )
120             {
121                 g_stm_crr_state.layer[StmLayerNoNearHomescreen].state = StmLayoutNoNone;
122                 g_stm_crr_state.layer[StmLayerNoNearHomescreen].changed = STM_TRUE;
123             }
124         }
125         else if (StmCtgNoPopUp == category_no)
126         {
127             if (StmLayoutNoPopUp == g_stm_prv_state.layer[StmLayerNoOnScreen].state )
128             {
129                 g_stm_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoNone;
130                 g_stm_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
131             }
132         }
133         else if (StmCtgNoSystemAlert == category_no)
134         {
135             if (StmLayoutNoSysAlt == g_stm_prv_state.layer[StmLayerNoOnScreen].state )
136             {
137                 g_stm_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoNone;
138                 g_stm_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
139             }
140         }
141     }
142
143     // Copy current state for return
144     memcpy(state, &g_stm_crr_state, sizeof(g_stm_crr_state));
145
146     return 0;
147 }
148
149 void stmUndoStateInner() {
150     g_stm_crr_state = g_stm_prv_state;
151 }