• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "config_subscriber.h"
17 
18 #include <fstream>
19 #include <mutex>
20 
21 #include "directory_ex.h"
22 #include "string_ex.h"
23 
24 #include "bigdata.h"
25 #include "event_config.h"
26 #include "config_define.h"
27 #include "config_manager.h"
28 #include "model_config.h"
29 #include "security_guard_log.h"
30 #include "security_guard_utils.h"
31 #include "i_model_info.h"
32 
33 namespace OHOS::Security::SecurityGuard {
34 
UpdateConfig(const std::string & file)35 bool ConfigSubscriber::UpdateConfig(const std::string &file)
36 {
37     ConfigUpdateEvent event{};
38     bool isSuccess = false;
39     if (file == CONFIG_CACHE_FILES[EVENT_CFG_INDEX]) {
40         isSuccess = ConfigManager::UpdateConfig<EventConfig>();
41     } else if (file == CONFIG_CACHE_FILES[MODEL_CFG_INDEX]) {
42         isSuccess = ConfigManager::UpdateConfig<ModelConfig>();
43     }
44     event.path = file;
45     event.time = SecurityGuardUtils::GetDate();
46     event.ret = isSuccess ? SUCCESS : FAILED;
47     SGLOGD("file path=%{public}s, TIME=%{public}s, ret=%{public}d", event.path.c_str(), event.time.c_str(),
48         event.ret);
49     BigData::ReportConfigUpdateEvent(event);
50 
51     if (file != CONFIG_CACHE_FILES[EVENT_CFG_INDEX] && file != CONFIG_CACHE_FILES[MODEL_CFG_INDEX]) {
52         return true;
53     }
54     if (!RemoveFile(file)) {
55         SGLOGE("remove file error, %{public}s", strerror(errno));
56     }
57     return isSuccess;
58 }
59 } // OHOS::Security::SecurityGuard
60