16ea96550Sopenharmony_ci/* 26ea96550Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 36ea96550Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46ea96550Sopenharmony_ci * you may not use this file except in compliance with the License. 56ea96550Sopenharmony_ci * You may obtain a copy of the License at 66ea96550Sopenharmony_ci * 76ea96550Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86ea96550Sopenharmony_ci * 96ea96550Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106ea96550Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116ea96550Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126ea96550Sopenharmony_ci * See the License for the specific language governing permissions and 136ea96550Sopenharmony_ci * limitations under the License. 146ea96550Sopenharmony_ci */ 156ea96550Sopenharmony_ci 166ea96550Sopenharmony_ci#include "config_subscriber.h" 176ea96550Sopenharmony_ci 186ea96550Sopenharmony_ci#include <fstream> 196ea96550Sopenharmony_ci#include <mutex> 206ea96550Sopenharmony_ci 216ea96550Sopenharmony_ci#include "directory_ex.h" 226ea96550Sopenharmony_ci#include "string_ex.h" 236ea96550Sopenharmony_ci 246ea96550Sopenharmony_ci#include "bigdata.h" 256ea96550Sopenharmony_ci#include "event_config.h" 266ea96550Sopenharmony_ci#include "config_define.h" 276ea96550Sopenharmony_ci#include "config_manager.h" 286ea96550Sopenharmony_ci#include "model_config.h" 296ea96550Sopenharmony_ci#include "security_guard_log.h" 306ea96550Sopenharmony_ci#include "security_guard_utils.h" 316ea96550Sopenharmony_ci 326ea96550Sopenharmony_cinamespace OHOS::Security::SecurityGuard { 336ea96550Sopenharmony_ci 346ea96550Sopenharmony_cibool ConfigSubscriber::UpdateConfig(const std::string &file) 356ea96550Sopenharmony_ci{ 366ea96550Sopenharmony_ci ConfigUpdateEvent event{}; 376ea96550Sopenharmony_ci bool isSuccess = false; 386ea96550Sopenharmony_ci if (file == CONFIG_CACHE_FILES[EVENT_CFG_INDEX]) { 396ea96550Sopenharmony_ci isSuccess = ConfigManager::UpdataConfig<EventConfig>(); 406ea96550Sopenharmony_ci } else if (file == CONFIG_CACHE_FILES[MODEL_CFG_INDEX]) { 416ea96550Sopenharmony_ci isSuccess = ConfigManager::UpdataConfig<ModelConfig>(); 426ea96550Sopenharmony_ci } 436ea96550Sopenharmony_ci event.path = file; 446ea96550Sopenharmony_ci event.time = SecurityGuardUtils::GetDate(); 456ea96550Sopenharmony_ci event.ret = isSuccess ? SUCCESS : FAILED; 466ea96550Sopenharmony_ci SGLOGD("file path=%{public}s, TIME=%{public}s, ret=%{public}d", event.path.c_str(), event.time.c_str(), 476ea96550Sopenharmony_ci event.ret); 486ea96550Sopenharmony_ci BigData::ReportConfigUpdateEvent(event); 496ea96550Sopenharmony_ci 506ea96550Sopenharmony_ci if (file != CONFIG_CACHE_FILES[EVENT_CFG_INDEX] && file != CONFIG_CACHE_FILES[MODEL_CFG_INDEX]) { 516ea96550Sopenharmony_ci return true; 526ea96550Sopenharmony_ci } 536ea96550Sopenharmony_ci if (!RemoveFile(file)) { 546ea96550Sopenharmony_ci SGLOGE("remove file error, %{public}s", strerror(errno)); 556ea96550Sopenharmony_ci } 566ea96550Sopenharmony_ci return isSuccess; 576ea96550Sopenharmony_ci} 586ea96550Sopenharmony_ci} // OHOS::Security::SecurityGuard 59