• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "application_data_manager.h"
17 
18 #include "app_recovery.h"
19 #include "hilog_wrapper.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
ApplicationDataManager()23 ApplicationDataManager::ApplicationDataManager() {}
24 
~ApplicationDataManager()25 ApplicationDataManager::~ApplicationDataManager() {}
26 
GetInstance()27 ApplicationDataManager &ApplicationDataManager::GetInstance()
28 {
29     static ApplicationDataManager manager;
30     return manager;
31 }
32 
AddErrorObserver(const std::shared_ptr<IErrorObserver> & observer)33 void ApplicationDataManager::AddErrorObserver(const std::shared_ptr<IErrorObserver> &observer)
34 {
35     HILOG_DEBUG("Add error observer come.");
36     errorObserver_ = observer;
37 }
38 
NotifyUnhandledException(const std::string & errMsg)39 bool ApplicationDataManager::NotifyUnhandledException(const std::string &errMsg)
40 {
41     HILOG_DEBUG("Notify error observer come.");
42     if (errorObserver_) {
43         errorObserver_->OnUnhandledException(errMsg);
44         return true;
45     }
46 
47     // if apprecovery is enabled, we could callback to save current state
48     // and restart as developer wants
49     return AppRecovery::GetInstance().TryRecoverApp(StateReason::JS_ERROR);
50 }
51 
RemoveErrorObserver()52 void ApplicationDataManager::RemoveErrorObserver()
53 {
54     HILOG_DEBUG("Remove error observer come.");
55     errorObserver_ = nullptr;
56 }
57 }  // namespace AppExecFwk
58 }  // namespace OHOS
59