• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "configuration_holder.h"
16 #include "hilog_wrapper.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
Init(const std::shared_ptr<DummyConfiguration> & config)20 void ConfigurationHolder::Init(const std::shared_ptr<DummyConfiguration> &config)
21 {
22     baseConfiguration_ = config;
23 }
24 
UpdateConfiguration(const std::shared_ptr<DummyConfiguration> config)25 void ConfigurationHolder::UpdateConfiguration(const std::shared_ptr<DummyConfiguration> config)
26 {
27     if (GetChildSize() == 0 && GetParent()) {
28         HILOG_INFO("%{public}s child update configuration at the time of activing.", __func__);
29         return;
30     }
31     auto configChanges = baseConfiguration_ ? baseConfiguration_->Differ(config) : CHANGE_CONFIG_ALL_CHANGED;
32 
33     if (configChanges > 0) {
34         // update base configuration immediately
35         baseConfiguration_ = config;
36     }
37 
38     DealUpdateConfiguration();
39 }
40 
GetConfiguration() const41 std::shared_ptr<DummyConfiguration> ConfigurationHolder::GetConfiguration() const
42 {
43     return baseConfiguration_;
44 }
45 
DealUpdateConfiguration()46 void ConfigurationHolder::DealUpdateConfiguration()
47 {
48     for (unsigned int index = 0; index < GetChildSize(); index++) {
49         auto child = FindChild(index);
50         if (child) {
51             child->UpdateConfiguration(baseConfiguration_);
52         }
53     }
54 }
55 
ProcessConfigurationChange()56 bool ConfigurationHolder::ProcessConfigurationChange()
57 {
58     HILOG_INFO("%{public}s", __func__);
59     auto parent = GetParent();
60     auto targetConfig = parent ? parent->GetConfiguration() : baseConfiguration_;
61     if (targetConfig == nullptr && baseConfiguration_ == nullptr) {
62         HILOG_DEBUG("targetConfig and baseConfiguration_ is nullptr, no change.");
63         return false;
64     }
65 
66     return ProcessConfigurationChangeInner(targetConfig);
67 }
68 
ForceProcessConfigurationChange(const std::shared_ptr<DummyConfiguration> & config)69 bool ConfigurationHolder::ForceProcessConfigurationChange(const std::shared_ptr<DummyConfiguration> &config)
70 {
71     return ProcessConfigurationChangeInner(config);
72 }
73 
ProcessConfigurationChangeInner(const std::shared_ptr<DummyConfiguration> & config)74 bool ConfigurationHolder::ProcessConfigurationChangeInner(const std::shared_ptr<DummyConfiguration> &config)
75 {
76     auto configChanges = baseConfiguration_ ? baseConfiguration_->Differ(config) : CHANGE_CONFIG_ALL_CHANGED;
77     if (configChanges > 0) {
78         if (baseConfiguration_) {
79             baseConfiguration_ = config;
80             return OnConfigurationChanged(*(baseConfiguration_.get()), configChanges);
81         }
82         // update base configuration immediately
83         baseConfiguration_ = config;
84         HILOG_DEBUG("have changes.");
85     }
86     HILOG_DEBUG("there is no change.");
87     return false;
88 }
89 
OnConfigurationChanged(const DummyConfiguration & config,unsigned int configChanges)90 bool ConfigurationHolder::OnConfigurationChanged(const DummyConfiguration &config, unsigned int configChanges)
91 {
92     return false;
93 }
94 }  // namespace AAFwk
95 }  // namespace OHOS