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 16 #include "aafwk_dummy_configuration.h" 17 18 #include "string_ex.h" 19 20 #include "hilog_wrapper.h" 21 22 namespace OHOS { 23 namespace AAFwk { 24 DummyConfiguration(const std::string & name)25DummyConfiguration::DummyConfiguration(const std::string &name) : testInfostr_(name) 26 {} 27 ReadFromParcel(Parcel & parcel)28bool DummyConfiguration::ReadFromParcel(Parcel &parcel) 29 { 30 testInfostr_ = Str16ToStr8(parcel.ReadString16()); 31 return true; 32 } 33 Unmarshalling(Parcel & parcel)34DummyConfiguration *DummyConfiguration::Unmarshalling(Parcel &parcel) 35 { 36 DummyConfiguration *dummyConfiguration = new (std::nothrow) DummyConfiguration(); 37 if (dummyConfiguration && !dummyConfiguration->ReadFromParcel(parcel)) { 38 delete dummyConfiguration; 39 dummyConfiguration = nullptr; 40 } 41 return dummyConfiguration; 42 } 43 Marshalling(Parcel & parcel) const44bool DummyConfiguration::Marshalling(Parcel &parcel) const 45 { 46 if (!parcel.WriteString16(Str8ToStr16(testInfostr_))) { 47 return false; 48 } 49 return true; 50 } 51 Differ(const std::shared_ptr<DummyConfiguration> config) const52unsigned int DummyConfiguration::Differ(const std::shared_ptr<DummyConfiguration> config) const 53 { 54 // temp test code 55 if (config == nullptr || config->GetName() == "none") { 56 return 0x00000000; 57 } 58 59 std::vector<std::string> changes; 60 std::string name = config->GetName(); 61 std::string::size_type nbegin = 0; 62 std::string::size_type nend = 0; 63 while (true) { 64 nend = name.find_first_of("#", nbegin); 65 if (nend == std::string::npos) { 66 changes.push_back(name.substr(nbegin, name.length())); 67 break; 68 } 69 changes.push_back(name.substr(nbegin, nend - nbegin)); 70 nbegin = nend + 1; 71 } 72 73 HILOG_ERROR("fail to get AbilityEventHandler"); 74 75 unsigned int flag = 0x00000000; 76 for (auto item : changes) { 77 if (item == "locale") { 78 flag |= 0x00000001; 79 } else if (item == "layout") { 80 flag |= 0x00000002; 81 } else if (item == "fontSize") { 82 flag |= 0x00000004; 83 } else if (item == "orientation") { 84 flag |= 0x00000008; 85 } else if (item == "density") { 86 flag |= 0x00000010; 87 } else { 88 continue; 89 } 90 } 91 return flag; 92 } 93 94 } // namespace AAFwk 95 } // namespace OHOS