summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h
blob: 78366ea96ae98bfe50df40705acef5e5d31ab347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * Copyright (c) 2016, Ford Motor Company
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of the Ford Motor Company nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUME_CTRL_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUME_CTRL_H_

#include <stdint.h>
#include <time.h>
#include "application_manager/resumption/resumption_data.h"

namespace application_manager {
class ApplicationManager;
class Application;
typedef std::shared_ptr<Application> ApplicationSharedPtr;
typedef std::shared_ptr<const Application> ApplicationConstSharedPtr;
}  // namespace application_manager
namespace app_mngr = application_manager;

namespace resumption {

class LastState;

/**
 * @brief Contains logic for storage/restore data of applications.
 */

class ResumeCtrl {
 public:
  /**
   * @brief allows to destroy ResumeCtrl object
   */
  virtual ~ResumeCtrl() {}

  /**
   * @brief Save all applications info to the file system
   */
  virtual void SaveAllApplications() = 0;

  /**
   * @brief Save application persistent info for future resuming
   * @param application is application witch need to be saved
   */
  virtual void SaveApplication(
      application_manager::ApplicationSharedPtr application) = 0;

  /**
   * @brief Set application HMI Level and ausio_state as saved
   * @param application is application witch HMI Level is need to restore
   * @return true if success, otherwise return false
   */
  virtual bool RestoreAppHMIState(
      application_manager::ApplicationSharedPtr application) = 0;

  /**
   * @brief Restore widgets HMI level on the resumption response from HMI
   * @param response_message smart_object with HMI message
   */
  virtual void RestoreWidgetsHMIState(
      const smart_objects::SmartObject& response_message) = 0;

  /**
   * @brief Set application HMI Level as stored in policy
   * @param application is application witch HMI Level is need to setup
   * @return true if success, otherwise return false
   */
  virtual bool SetupDefaultHMILevel(
      application_manager::ApplicationSharedPtr application) = 0;

  /**
   * @brief Setup HmiLevel for application
   * Do routine of setting up hmi_level
   * @param application is application witch HMI Level is need to setup
   * @param hmi_level HMI Level is needed to setup
   * @param hmi_level AudioStreamingState is needed to setup
   * @param check_policy indicate if policy data consent must be verified
   * @return true if success, otherwise return false
   */
  virtual bool SetAppHMIState(
      application_manager::ApplicationSharedPtr application,
      const mobile_apis::HMILevel::eType hmi_level,
      bool check_policy = true) = 0;

  /**
   * @brief RestoreAppWidgets add widgets for the application
   * @param application application which will be resumed
   * @param saved_app application specific section from backup file
   * @return the number of widget windows to be resumed
   */
  virtual size_t RestoreAppWidgets(
      application_manager::ApplicationSharedPtr application,
      const smart_objects::SmartObject& saved_app) = 0;

  /**
   * @brief Remove application from list of saved applications
   * @param application is application which need to be removed
   * @return return true, if success, otherwise return false
   */
  virtual bool RemoveApplicationFromSaved(
      app_mngr::ApplicationConstSharedPtr application) = 0;
  /**
   * @brief Processes resumption data after receiving signal "Suspend"
   */
  virtual void OnSuspend() = 0;

  /**
   * @brief Processes resumption data after receiving signal "Ignition Off"
   */
  virtual void OnIgnitionOff() = 0;

  /**
   * @brief Processes resumption data after receiving signal "Awake"
   */
  virtual void OnAwake() = 0;

  /**
   * @brief Saves Low Voltage signal timestamp
   */
  virtual void SaveLowVoltageTime() = 0;

  /**
   * @brief Saves Wake Up signal timestamp
   */
  virtual void SaveWakeUpTime() = 0;

  /**
   * @brief Checks if SDL has already received OnExitAllApplication notification
   * with "SUSPEND" reason
   *
   * @return Returns TRUE if SDL has received OnExitAllApplication notification
   * with reason "SUSPEND" otherwise returns FALSE
   */
  virtual bool is_suspended() const = 0;

  /**
   * @brief Method stops timer "RsmCtrlPersist" when SDL
   * receives OnExitAllApplication notification
   * with reason "SUSPEND"
   */
  virtual void StopSavePersistentDataTimer() = 0;

  /**
   * @brief Method starts timer "RsmCtrlPersist" when
   * SDL receives onAwakeSDL notification
   */
  virtual void StartSavePersistentDataTimer() = 0;

  /**
   * @brief Start timer for resumption applications
   *        Restore D1-D5 data
   * @param application that is need to be restored
   * @return true if it was saved, otherwise return false
   */
  virtual bool StartResumption(app_mngr::ApplicationSharedPtr application,
                               const std::string& hash) = 0;
  /**
   * @brief Start timer for resumption applications
   *        Does not restore D1-D5 data
   * @param application that is need to be restored
   * @return true if it was saved, otherwise return false
   */
  virtual bool StartResumptionOnlyHMILevel(
      app_mngr::ApplicationSharedPtr application) = 0;

  /**
   * @brief Retry resumption of an app if it has been disabled or limited
   *        due to absence of high-bandwidth transport.
   * @param app_id ID of the app to resume
   */
  virtual void RetryResumption(const uint32_t app_id) = 0;

  /**
   * @brief Check if there are all files need for resumption
   * @param application that is need to be restored
   * @return true if it all files exist, otherwise return false
   */
  virtual bool CheckPersistenceFilesForResumption(
      app_mngr::ApplicationSharedPtr application) = 0;

  /**
   * @brief Check application hash
   * @param application that is need to be restored
   * @return true if it was saved, otherwise return false
   */
  virtual bool CheckApplicationHash(app_mngr::ApplicationSharedPtr application,
                                    const std::string& hash) = 0;

  /**
   * @brief Checks if Resume controller have saved application with hmi app id
   * @param hmi_app_id - hmi application id
   * @return true if exist, false otherwise
   */
  virtual bool IsHMIApplicationIdExist(uint32_t hmi_app_id) = 0;

  /**
   * @brief Check if Resume controller have saved instance of application
   * @param policy_app_id - mobile application id
   * @param device_id - id of device where application is run
   * @return true if exist, false otherwise
   */
  virtual bool IsApplicationSaved(const std::string& policy_app_id,
                                  const std::string& device_id) = 0;

  /**
   * @brief Function is used for application resume. HMI app ID must be
   * the same(PASA VCA module use it for stored app info).
   * Retrieves HMI app ID for the given policy app ID from stored information.
   * @param policy_app_id - mobile application id
   * @param device_id - id of device where application is run
   * @return HMI app ID
   */
  virtual uint32_t GetHMIApplicationID(const std::string& policy_app_id,
                                       const std::string& device_id) const = 0;

  /**
   * @brief Updates flag for saving application data
   */
  virtual void ApplicationsDataUpdated() = 0;

  /**
   * @brief Resume HMI Level and audio streaming state if needed
   * @param application - application to restore hmi level
   * and audio streaming state
   */
  virtual bool StartAppHmiStateResumption(
      application_manager::ApplicationSharedPtr application) = 0;

  /**
   * @brief Update launch_time_ to current
   */
  virtual void ResetLaunchTime() = 0;

  /**
   * @brief Removes activated application from resumption list
   *
   * @param application application witch need to be removed from resumption
   */
  virtual void OnAppActivated(app_mngr::ApplicationSharedPtr application) = 0;

  /**
   * @brief Removes app from resumption list
   *
   * app_id Application to remove
   */
  virtual void RemoveFromResumption(uint32_t app_id) = 0;

  /**
   * @brief Initialization data for Resume controller
   * @return true if initialization is success otherwise
   * returns false
   */
  virtual bool Init(LastState& last_state) = 0;

  /**
   * @brief Notify resume controller about new application
   * @param policy_app_id - mobile application id
   * @param device_id - id of device where application is run
   */
  virtual void OnAppRegistrationStart(const std::string& policy_app_id,
                                      const std::string& device_id) = 0;

  /**
   * @brief Notify resume controller about delete new application
   */
  virtual void OnAppRegistrationEnd() = 0;

  /**
   * @brief GetSavedHMILevels get saved apps hmi levels
   * @return mapping of mobile application id and saved hmi_level
   */
  virtual int32_t GetSavedAppHmiLevel(const std::string& app_id,
                                      const std::string& device_id) const = 0;

  virtual void StartWaitingForDisplayCapabilitiesUpdate(
      app_mngr::ApplicationSharedPtr application) = 0;

  virtual time_t LaunchTime() const = 0;

#ifdef BUILD_TESTS
  virtual void set_resumption_storage(
      std::shared_ptr<ResumptionData> mock_storage) = 0;

  virtual bool get_resumption_active() const = 0;
#endif  // BUILD_TESTS
};

}  // namespace resumption
#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RESUMPTION_RESUME_CTRL_H_