1 /*
2 * Copyright (c) 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 #include "app_exit_reason_data_manager.h"
17
18 #include <algorithm>
19 #include <chrono>
20 #include <unistd.h>
21
22 #include "errors.h"
23 #include "hilog_wrapper.h"
24 #include "nlohmann/json.hpp"
25
26 namespace OHOS {
27 namespace AbilityRuntime {
28 namespace {
29 constexpr int32_t CHECK_INTERVAL = 100000; // 100ms
30 constexpr int32_t MAX_TIMES = 5; // 5 * 100ms = 500ms
31 constexpr const char *APP_EXIT_REASON_STORAGE_DIR = "/data/service/el1/public/database/app_exit_reason";
32 const std::string JSON_KEY_REASON = "reason";
33 const std::string JSON_KEY_TIME_STAMP = "time_stamp";
34 const std::string JSON_KEY_ABILITY_LIST = "ability_list";
35 const std::string KEY_RECOVER_INFO_PREFIX = "recover_info";
36 const std::string JSON_KEY_RECOVER_INFO_LIST = "recover_info_list";
37 const std::string JSON_KEY_SESSION_ID_LIST = "session_id_list";
38 } // namespace
AppExitReasonDataManager()39 AppExitReasonDataManager::AppExitReasonDataManager() {}
40
~AppExitReasonDataManager()41 AppExitReasonDataManager::~AppExitReasonDataManager()
42 {
43 if (kvStorePtr_ != nullptr) {
44 dataManager_.CloseKvStore(appId_, kvStorePtr_);
45 }
46 }
47
GetKvStore()48 DistributedKv::Status AppExitReasonDataManager::GetKvStore()
49 {
50 DistributedKv::Options options = { .createIfMissing = true,
51 .encrypt = false,
52 .autoSync = true,
53 .syncable = false,
54 .securityLevel = DistributedKv::SecurityLevel::S2,
55 .area = DistributedKv::EL1,
56 .kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION,
57 .baseDir = APP_EXIT_REASON_STORAGE_DIR };
58
59 DistributedKv::Status status = dataManager_.GetSingleKvStore(options, appId_, storeId_, kvStorePtr_);
60 if (status != DistributedKv::Status::SUCCESS) {
61 HILOG_ERROR("return error: %{public}d", status);
62 } else {
63 HILOG_INFO("get kvStore success");
64 }
65 return status;
66 }
67
CheckKvStore()68 bool AppExitReasonDataManager::CheckKvStore()
69 {
70 HILOG_DEBUG("AppExitReasonDataManager::CheckKvStore start");
71 if (kvStorePtr_ != nullptr) {
72 return true;
73 }
74 int32_t tryTimes = MAX_TIMES;
75 while (tryTimes > 0) {
76 DistributedKv::Status status = GetKvStore();
77 if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ != nullptr) {
78 return true;
79 }
80 HILOG_DEBUG("try times: %{public}d", tryTimes);
81 usleep(CHECK_INTERVAL);
82 tryTimes--;
83 }
84 return kvStorePtr_ != nullptr;
85 }
86
SetAppExitReason(const std::string & bundleName,const std::vector<std::string> & abilityList,const AAFwk::Reason & reason)87 int32_t AppExitReasonDataManager::SetAppExitReason(
88 const std::string &bundleName, const std::vector<std::string> &abilityList, const AAFwk::Reason &reason)
89 {
90 if (bundleName.empty()) {
91 HILOG_WARN("invalid value");
92 return ERR_INVALID_VALUE;
93 }
94
95 HILOG_DEBUG("bundleName: %{public}s", bundleName.c_str());
96 {
97 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
98 if (!CheckKvStore()) {
99 HILOG_ERROR("kvStore is nullptr");
100 return ERR_NO_INIT;
101 }
102 }
103
104 DistributedKv::Key key(bundleName);
105 DistributedKv::Value value = ConvertAppExitReasonInfoToValue(abilityList, reason);
106 DistributedKv::Status status;
107 {
108 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
109 status = kvStorePtr_->Put(key, value);
110 }
111
112 if (status != DistributedKv::Status::SUCCESS) {
113 HILOG_ERROR("insert data to kvStore error: %{public}d", status);
114 return ERR_INVALID_OPERATION;
115 }
116 return ERR_OK;
117 }
118
DeleteAppExitReason(const std::string & bundleName)119 int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleName)
120 {
121 if (bundleName.empty()) {
122 HILOG_WARN("invalid value.");
123 return ERR_INVALID_VALUE;
124 }
125
126 HILOG_DEBUG("bundleName: %{public}s.", bundleName.c_str());
127 {
128 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
129 if (!CheckKvStore()) {
130 HILOG_ERROR("kvStore is nullptr.");
131 return ERR_NO_INIT;
132 }
133 }
134
135 DistributedKv::Key key(bundleName);
136 DistributedKv::Status status;
137 {
138 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
139 status = kvStorePtr_->Delete(key);
140 }
141
142 if (status != DistributedKv::Status::SUCCESS) {
143 HILOG_ERROR("delete data from kvStore error: %{public}d", status);
144 return ERR_INVALID_OPERATION;
145 }
146 return ERR_OK;
147 }
148
GetAppExitReason(const std::string & bundleName,const std::string & abilityName,bool & isSetReason,AAFwk::Reason & reason)149 int32_t AppExitReasonDataManager::GetAppExitReason(
150 const std::string &bundleName, const std::string &abilityName, bool &isSetReason, AAFwk::Reason &reason)
151 {
152 if (bundleName.empty()) {
153 HILOG_WARN("invalid value!");
154 return ERR_INVALID_VALUE;
155 }
156
157 HILOG_DEBUG("bundleName: %{public}s!", bundleName.c_str());
158 {
159 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
160 if (!CheckKvStore()) {
161 HILOG_ERROR("kvStore is nullptr!");
162 return ERR_NO_INIT;
163 }
164 }
165
166 std::vector<DistributedKv::Entry> allEntries;
167 DistributedKv::Status status = kvStorePtr_->GetEntries(nullptr, allEntries);
168 if (status != DistributedKv::Status::SUCCESS) {
169 HILOG_ERROR("get entries error: %{public}d", status);
170 return ERR_INVALID_VALUE;
171 }
172
173 std::vector<std::string> abilityList;
174 int64_t time_stamp;
175 isSetReason = false;
176 for (const auto &item : allEntries) {
177 if (item.key.ToString() == bundleName) {
178 ConvertAppExitReasonInfoFromValue(item.value, reason, time_stamp, abilityList);
179 auto pos = std::find(abilityList.begin(), abilityList.end(), abilityName);
180 if (pos != abilityList.end()) {
181 isSetReason = true;
182 abilityList.erase(std::remove(abilityList.begin(), abilityList.end(), abilityName), abilityList.end());
183 UpdateAppExitReason(bundleName, abilityList, reason);
184 }
185 HILOG_INFO(
186 "current bundle name: %{public}s reason: %{public}d abilityName:%{public}s isSetReason:%{public}d",
187 item.key.ToString().c_str(), reason, abilityName.c_str(), isSetReason);
188 if (abilityList.empty()) {
189 InnerDeleteAppExitReason(bundleName);
190 }
191 break;
192 }
193 }
194
195 return ERR_OK;
196 }
197
UpdateAppExitReason(const std::string & bundleName,const std::vector<std::string> & abilityList,const AAFwk::Reason & reason)198 void AppExitReasonDataManager::UpdateAppExitReason(
199 const std::string &bundleName, const std::vector<std::string> &abilityList, const AAFwk::Reason &reason)
200 {
201 if (kvStorePtr_ == nullptr) {
202 HILOG_ERROR("kvStore is nullptr.");
203 return;
204 }
205
206 DistributedKv::Key key(bundleName);
207 DistributedKv::Status status;
208 {
209 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
210 status = kvStorePtr_->Delete(key);
211 }
212 if (status != DistributedKv::Status::SUCCESS) {
213 HILOG_ERROR("delete data from kvStore error: %{public}d.", status);
214 return;
215 }
216
217 DistributedKv::Value value = ConvertAppExitReasonInfoToValue(abilityList, reason);
218 {
219 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
220 status = kvStorePtr_->Put(key, value);
221 }
222 if (status != DistributedKv::Status::SUCCESS) {
223 HILOG_ERROR("insert data to kvStore error: %{public}d", status);
224 }
225 }
226
ConvertAppExitReasonInfoToValue(const std::vector<std::string> & abilityList,const AAFwk::Reason & reason)227 DistributedKv::Value AppExitReasonDataManager::ConvertAppExitReasonInfoToValue(
228 const std::vector<std::string> &abilityList, const AAFwk::Reason &reason)
229 {
230 std::chrono::milliseconds nowMs =
231 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
232 nlohmann::json jsonObject = nlohmann::json {
233 { JSON_KEY_REASON, reason },
234 { JSON_KEY_TIME_STAMP, nowMs.count() },
235 { JSON_KEY_ABILITY_LIST, abilityList },
236 };
237 DistributedKv::Value value(jsonObject.dump());
238 HILOG_INFO("value: %{public}s", value.ToString().c_str());
239 return value;
240 }
241
ConvertAppExitReasonInfoFromValue(const DistributedKv::Value & value,AAFwk::Reason & reason,int64_t & time_stamp,std::vector<std::string> & abilityList)242 void AppExitReasonDataManager::ConvertAppExitReasonInfoFromValue(const DistributedKv::Value &value,
243 AAFwk::Reason &reason, int64_t &time_stamp, std::vector<std::string> &abilityList)
244 {
245 nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false);
246 if (jsonObject.is_discarded()) {
247 HILOG_ERROR("failed to parse json sting.");
248 return;
249 }
250 if (jsonObject.contains(JSON_KEY_REASON) && jsonObject[JSON_KEY_REASON].is_number_integer()) {
251 reason = jsonObject.at(JSON_KEY_REASON).get<AAFwk::Reason>();
252 }
253 if (jsonObject.contains(JSON_KEY_TIME_STAMP) && jsonObject[JSON_KEY_TIME_STAMP].is_number_integer()) {
254 time_stamp = jsonObject.at(JSON_KEY_TIME_STAMP).get<int64_t>();
255 }
256 if (jsonObject.contains(JSON_KEY_ABILITY_LIST) && jsonObject[JSON_KEY_ABILITY_LIST].is_array()) {
257 abilityList.clear();
258 auto size = jsonObject[JSON_KEY_ABILITY_LIST].size();
259 for (size_t i = 0; i < size; i++) {
260 if (jsonObject[JSON_KEY_ABILITY_LIST][i].is_string()) {
261 abilityList.emplace_back(jsonObject[JSON_KEY_ABILITY_LIST][i]);
262 }
263 }
264 }
265 }
266
InnerDeleteAppExitReason(const std::string & bundleName)267 void AppExitReasonDataManager::InnerDeleteAppExitReason(const std::string &bundleName)
268 {
269 if (kvStorePtr_ == nullptr) {
270 HILOG_ERROR("kvStore is nullptr");
271 return;
272 }
273
274 DistributedKv::Key key(bundleName);
275 DistributedKv::Status status;
276 {
277 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
278 status = kvStorePtr_->Delete(key);
279 }
280
281 if (status != DistributedKv::Status::SUCCESS) {
282 HILOG_ERROR("delete data from kvStore error: %{public}d", status);
283 }
284 }
285
AddAbilityRecoverInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const int & sessionId)286 int32_t AppExitReasonDataManager::AddAbilityRecoverInfo(const std::string &bundleName,
287 const std::string &moduleName, const std::string &abilityName, const int &sessionId)
288 {
289 HILOG_INFO("AddAbilityRecoverInfo bundle %{public}s module %{public}s ability %{public}s id %{public}d ",
290 bundleName.c_str(), moduleName.c_str(), abilityName.c_str(), sessionId);
291 {
292 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
293 if (!CheckKvStore()) {
294 HILOG_ERROR("kvStore is nullptr");
295 return ERR_NO_INIT;
296 }
297 }
298
299 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
300 DistributedKv::Value value;
301 DistributedKv::Status status = kvStorePtr_->Get(key, value);
302 if (status != DistributedKv::Status::SUCCESS && status != DistributedKv::Status::KEY_NOT_FOUND) {
303 HILOG_ERROR("AddAbilityRecoverInfo get error: %{public}d", status);
304 return ERR_INVALID_VALUE;
305 }
306
307 std::vector<std::string> recoverInfoList;
308 std::vector<int> sessionIdList;
309 std::string recoverInfo = moduleName + abilityName;
310 if (status == DistributedKv::Status::SUCCESS) {
311 ConvertAbilityRecoverInfoFromValue(value, recoverInfoList, sessionIdList);
312 auto pos = std::find(recoverInfoList.begin(), recoverInfoList.end(), recoverInfo);
313 if (pos != recoverInfoList.end()) {
314 HILOG_WARN("AddAbilityRecoverInfo recoverInfo already record");
315 int index = std::distance(recoverInfoList.begin(), pos);
316 sessionIdList[index] = sessionId;
317 return ERR_OK;
318 }
319 }
320
321 recoverInfoList.emplace_back(recoverInfo);
322 sessionIdList.emplace_back(sessionId);
323 value = ConvertAbilityRecoverInfoToValue(recoverInfoList, sessionIdList);
324 {
325 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
326 status = kvStorePtr_->Put(key, value);
327 }
328
329 if (status != DistributedKv::Status::SUCCESS) {
330 HILOG_ERROR("insert data to kvStore error : %{public}d", status);
331 return ERR_INVALID_OPERATION;
332 }
333
334 HILOG_INFO("AddAbilityRecoverInfo finish");
335 return ERR_OK;
336 }
337
DeleteAbilityRecoverInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName)338 int32_t AppExitReasonDataManager::DeleteAbilityRecoverInfo(
339 const std::string &bundleName, const std::string &moduleName, const std::string &abilityName)
340 {
341 HILOG_INFO("DeleteAbilityRecoverInfo bundle %{public}s module %{public}s ability %{public}s ",
342 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
343 {
344 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
345 if (!CheckKvStore()) {
346 HILOG_ERROR("kvStore is nullptr.");
347 return ERR_NO_INIT;
348 }
349 }
350
351 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
352 DistributedKv::Value value;
353 DistributedKv::Status status = kvStorePtr_->Get(key, value);
354 if (status != DistributedKv::Status::SUCCESS) {
355 HILOG_ERROR("DeleteAbilityRecoverInfo get error: %{public}d", status);
356 return ERR_INVALID_VALUE;
357 }
358
359 std::vector<std::string> recoverInfoList;
360 std::vector<int> sessionIdList;
361 std::string recoverInfo = moduleName + abilityName;
362 ConvertAbilityRecoverInfoFromValue(value, recoverInfoList, sessionIdList);
363 auto pos = std::find(recoverInfoList.begin(), recoverInfoList.end(), recoverInfo);
364 if (pos != recoverInfoList.end()) {
365 recoverInfoList.erase(std::remove(recoverInfoList.begin(), recoverInfoList.end(), recoverInfo),
366 recoverInfoList.end());
367 int index = std::distance(recoverInfoList.begin(), pos);
368 sessionIdList.erase(std::remove(sessionIdList.begin(), sessionIdList.end(), sessionIdList[index]),
369 sessionIdList.end());
370 UpdateAbilityRecoverInfo(bundleName, recoverInfoList, sessionIdList);
371 HILOG_INFO("DeleteAbilityRecoverInfo remove recoverInfo succeed");
372 }
373 if (recoverInfoList.empty()) {
374 InnerDeleteAbilityRecoverInfo(bundleName);
375 }
376
377 HILOG_INFO("DeleteAbilityRecoverInfo finished");
378 return ERR_OK;
379 }
380
GetAbilityRecoverInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,bool & hasRecoverInfo)381 int32_t AppExitReasonDataManager::GetAbilityRecoverInfo(
382 const std::string &bundleName, const std::string &moduleName, const std::string &abilityName, bool &hasRecoverInfo)
383 {
384 HILOG_INFO("GetAbilityRecoverInfo bundle %{public}s module %{public}s abillity %{public}s ",
385 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
386 hasRecoverInfo = false;
387 {
388 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
389 if (!CheckKvStore()) {
390 HILOG_ERROR("kvStore is nullptr!");
391 return ERR_NO_INIT;
392 }
393 }
394
395 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
396 DistributedKv::Value value;
397 DistributedKv::Status status = kvStorePtr_->Get(key, value);
398 if (status != DistributedKv::Status::SUCCESS) {
399 if (status == DistributedKv::Status::KEY_NOT_FOUND) {
400 HILOG_WARN("GetAbilityRecoverInfo KEY_NOT_FOUND.");
401 } else {
402 HILOG_ERROR("GetAbilityRecoverInfo error: %{public}d.", status);
403 }
404 return ERR_INVALID_VALUE;
405 }
406
407 std::vector<std::string> recoverInfoList;
408 std::vector<int> sessionIdList;
409 std::string recoverInfo = moduleName + abilityName;
410 ConvertAbilityRecoverInfoFromValue(value, recoverInfoList, sessionIdList);
411 auto pos = std::find(recoverInfoList.begin(), recoverInfoList.end(), recoverInfo);
412 if (pos != recoverInfoList.end()) {
413 hasRecoverInfo = true;
414 HILOG_INFO("GetAbilityRecoverInfo hasRecoverInfo found info");
415 }
416 return ERR_OK;
417 }
418
GetAbilitySessionId(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,int & sessionId)419 int32_t AppExitReasonDataManager::GetAbilitySessionId(const std::string &bundleName,
420 const std::string &moduleName, const std::string &abilityName, int &sessionId)
421 {
422 HILOG_INFO("GetAbilityRecoverInfo bundle %{public}s bundle %{public}s bundle %{public}s ",
423 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
424 sessionId = 0;
425 {
426 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
427 if (!CheckKvStore()) {
428 HILOG_ERROR("the kvStore is nullptr.");
429 return ERR_NO_INIT;
430 }
431 }
432
433 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
434 DistributedKv::Value value;
435 DistributedKv::Status status = kvStorePtr_->Get(key, value);
436 if (status != DistributedKv::Status::SUCCESS) {
437 if (status == DistributedKv::Status::KEY_NOT_FOUND) {
438 HILOG_WARN("GetAbilityRecoverInfo KEY_NOT_FOUND");
439 } else {
440 HILOG_ERROR("GetAbilityRecoverInfo error: %{public}d", status);
441 }
442 return ERR_INVALID_VALUE;
443 }
444
445 std::vector<std::string> recoverInfoList;
446 std::vector<int> sessionIdList;
447 std::string recoverInfo = moduleName + abilityName;
448 ConvertAbilityRecoverInfoFromValue(value, recoverInfoList, sessionIdList);
449 auto pos = std::find(recoverInfoList.begin(), recoverInfoList.end(), recoverInfo);
450 if (pos != recoverInfoList.end()) {
451 int index = std::distance(recoverInfoList.begin(), pos);
452 sessionId = sessionIdList[index];
453 HILOG_INFO("GetAbilityRecoverInfo sessionId found info %{public}d ", sessionId);
454 }
455 return ERR_OK;
456 }
457
UpdateAbilityRecoverInfo(const std::string & bundleName,const std::vector<std::string> & recoverInfoList,const std::vector<int> & sessionIdList)458 void AppExitReasonDataManager::UpdateAbilityRecoverInfo(const std::string &bundleName,
459 const std::vector<std::string> &recoverInfoList, const std::vector<int> &sessionIdList)
460 {
461 if (kvStorePtr_ == nullptr) {
462 HILOG_ERROR("kvStore is nullptr.");
463 return;
464 }
465
466 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
467 DistributedKv::Status status;
468 {
469 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
470 status = kvStorePtr_->Delete(key);
471 }
472 if (status != DistributedKv::Status::SUCCESS) {
473 HILOG_ERROR("delete data from kvStore error: %{public}d", status);
474 return;
475 }
476
477 DistributedKv::Value value = ConvertAbilityRecoverInfoToValue(recoverInfoList, sessionIdList);
478 {
479 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
480 status = kvStorePtr_->Put(key, value);
481 }
482 if (status != DistributedKv::Status::SUCCESS) {
483 HILOG_ERROR("insert data to kvStore failed: %{public}d", status);
484 }
485 }
486
ConvertAbilityRecoverInfoToValue(const std::vector<std::string> & recoverInfoList,const std::vector<int> & sessionIdList)487 DistributedKv::Value AppExitReasonDataManager::ConvertAbilityRecoverInfoToValue(
488 const std::vector<std::string> &recoverInfoList, const std::vector<int> &sessionIdList)
489 {
490 nlohmann::json jsonObject = nlohmann::json {
491 { JSON_KEY_RECOVER_INFO_LIST, recoverInfoList },
492 { JSON_KEY_SESSION_ID_LIST, sessionIdList },
493 };
494 DistributedKv::Value value(jsonObject.dump());
495 HILOG_INFO("ConvertAbilityRecoverInfoToValue value: %{public}s", value.ToString().c_str());
496 return value;
497 }
498
ConvertAbilityRecoverInfoFromValue(const DistributedKv::Value & value,std::vector<std::string> & recoverInfoList,std::vector<int> & sessionIdList)499 void AppExitReasonDataManager::ConvertAbilityRecoverInfoFromValue(const DistributedKv::Value &value,
500 std::vector<std::string> &recoverInfoList, std::vector<int> &sessionIdList)
501 {
502 nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false);
503 if (jsonObject.is_discarded()) {
504 HILOG_ERROR("failed to parse json sting.");
505 return;
506 }
507 if (jsonObject.contains(JSON_KEY_RECOVER_INFO_LIST)
508 && jsonObject[JSON_KEY_RECOVER_INFO_LIST].is_array()) {
509 recoverInfoList.clear();
510 auto size = jsonObject[JSON_KEY_RECOVER_INFO_LIST].size();
511 for (size_t i = 0; i < size; i++) {
512 if (jsonObject[JSON_KEY_RECOVER_INFO_LIST][i].is_string()) {
513 recoverInfoList.emplace_back(jsonObject[JSON_KEY_RECOVER_INFO_LIST][i]);
514 }
515 }
516 }
517 if (jsonObject.contains(JSON_KEY_SESSION_ID_LIST)
518 && jsonObject[JSON_KEY_SESSION_ID_LIST].is_array()) {
519 sessionIdList.clear();
520 auto size = jsonObject[JSON_KEY_SESSION_ID_LIST].size();
521 for (size_t i = 0; i < size; i++) {
522 if (jsonObject[JSON_KEY_SESSION_ID_LIST][i].is_number_integer()) {
523 sessionIdList.emplace_back(jsonObject[JSON_KEY_SESSION_ID_LIST][i]);
524 }
525 }
526 }
527 }
528
InnerDeleteAbilityRecoverInfo(const std::string & bundleName)529 void AppExitReasonDataManager::InnerDeleteAbilityRecoverInfo(const std::string &bundleName)
530 {
531 if (kvStorePtr_ == nullptr) {
532 HILOG_ERROR("kvStore is nullptr");
533 return;
534 }
535
536 DistributedKv::Key key(KEY_RECOVER_INFO_PREFIX + bundleName);
537 DistributedKv::Status status;
538 {
539 std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
540 status = kvStorePtr_->Delete(key);
541 }
542
543 if (status != DistributedKv::Status::SUCCESS) {
544 HILOG_ERROR("delete data from kvStore error: %{public}d", status);
545 }
546 }
547 } // namespace AbilityRuntime
548 } // namespace OHOS
549