114cf0368Sopenharmony_ci/* 214cf0368Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 314cf0368Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 414cf0368Sopenharmony_ci * you may not use this file except in compliance with the License. 514cf0368Sopenharmony_ci * You may obtain a copy of the License at 614cf0368Sopenharmony_ci * 714cf0368Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 814cf0368Sopenharmony_ci * 914cf0368Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1014cf0368Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1114cf0368Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1214cf0368Sopenharmony_ci * See the License for the specific language governing permissions and 1314cf0368Sopenharmony_ci * limitations under the License. 1414cf0368Sopenharmony_ci */ 1514cf0368Sopenharmony_ci 1614cf0368Sopenharmony_ci#include "system_defined_appitem.h" 1714cf0368Sopenharmony_ci 1814cf0368Sopenharmony_cinamespace OHOS { 1914cf0368Sopenharmony_cinamespace UDMF { 2014cf0368Sopenharmony_ciSystemDefinedAppItem::SystemDefinedAppItem() 2114cf0368Sopenharmony_ci{ 2214cf0368Sopenharmony_ci SetType(SYSTEM_DEFINED_APP_ITEM); 2314cf0368Sopenharmony_ci} 2414cf0368Sopenharmony_ci 2514cf0368Sopenharmony_ciSystemDefinedAppItem::SystemDefinedAppItem(UDType type, ValueType value) : SystemDefinedRecord(type, value) 2614cf0368Sopenharmony_ci{ 2714cf0368Sopenharmony_ci SetType(SYSTEM_DEFINED_APP_ITEM); 2814cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value)) { 2914cf0368Sopenharmony_ci auto object = std::get<std::shared_ptr<Object>>(value); 3014cf0368Sopenharmony_ci object->GetValue(APP_ID, appId_); 3114cf0368Sopenharmony_ci object->GetValue(APP_NAME, appName_); 3214cf0368Sopenharmony_ci object->GetValue(APP_ICON_ID, appIconId_); 3314cf0368Sopenharmony_ci object->GetValue(APP_LABEL_ID, appLabelId_); 3414cf0368Sopenharmony_ci object->GetValue(BUNDLE_NAME, bundleName_); 3514cf0368Sopenharmony_ci object->GetValue(ABILITY_NAME, abilityName_); 3614cf0368Sopenharmony_ci std::shared_ptr<Object> detailObj = nullptr; 3714cf0368Sopenharmony_ci if (object->GetValue(DETAILS, detailObj)) { 3814cf0368Sopenharmony_ci details_ = ObjectUtils::ConvertToUDDetails(detailObj); 3914cf0368Sopenharmony_ci } 4014cf0368Sopenharmony_ci hasObject_ = true; 4114cf0368Sopenharmony_ci } 4214cf0368Sopenharmony_ci} 4314cf0368Sopenharmony_ci 4414cf0368Sopenharmony_ciint64_t SystemDefinedAppItem::GetSize() 4514cf0368Sopenharmony_ci{ 4614cf0368Sopenharmony_ci return UnifiedDataUtils::GetDetailsSize(this->details_) + this->appId_.size() + this->appName_.size() 4714cf0368Sopenharmony_ci + this->appIconId_.size() + this->appLabelId_.size() + this->bundleName_.size() + this->abilityName_.size(); 4814cf0368Sopenharmony_ci} 4914cf0368Sopenharmony_ci 5014cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetAppId() const 5114cf0368Sopenharmony_ci{ 5214cf0368Sopenharmony_ci return this->appId_; 5314cf0368Sopenharmony_ci} 5414cf0368Sopenharmony_ci 5514cf0368Sopenharmony_civoid SystemDefinedAppItem::SetAppId(const std::string &appId) 5614cf0368Sopenharmony_ci{ 5714cf0368Sopenharmony_ci this->appId_ = appId; 5814cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 5914cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[APP_ID] = appId_; 6014cf0368Sopenharmony_ci } 6114cf0368Sopenharmony_ci} 6214cf0368Sopenharmony_ci 6314cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetAppName() const 6414cf0368Sopenharmony_ci{ 6514cf0368Sopenharmony_ci return this->appName_; 6614cf0368Sopenharmony_ci} 6714cf0368Sopenharmony_ci 6814cf0368Sopenharmony_civoid SystemDefinedAppItem::SetAppName(const std::string &appName) 6914cf0368Sopenharmony_ci{ 7014cf0368Sopenharmony_ci this->appName_ = appName; 7114cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 7214cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[APP_NAME] = appName_; 7314cf0368Sopenharmony_ci } 7414cf0368Sopenharmony_ci} 7514cf0368Sopenharmony_ci 7614cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetAppIconId() const 7714cf0368Sopenharmony_ci{ 7814cf0368Sopenharmony_ci return this->appIconId_; 7914cf0368Sopenharmony_ci} 8014cf0368Sopenharmony_ci 8114cf0368Sopenharmony_civoid SystemDefinedAppItem::SetAppIconId(const std::string &appIconId) 8214cf0368Sopenharmony_ci{ 8314cf0368Sopenharmony_ci this->appIconId_ = appIconId; 8414cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 8514cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[APP_ICON_ID] = appIconId_; 8614cf0368Sopenharmony_ci } 8714cf0368Sopenharmony_ci} 8814cf0368Sopenharmony_ci 8914cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetAppLabelId() const 9014cf0368Sopenharmony_ci{ 9114cf0368Sopenharmony_ci return this->appLabelId_; 9214cf0368Sopenharmony_ci} 9314cf0368Sopenharmony_ci 9414cf0368Sopenharmony_civoid SystemDefinedAppItem::SetAppLabelId(const std::string &appLabelId) 9514cf0368Sopenharmony_ci{ 9614cf0368Sopenharmony_ci this->appLabelId_ = appLabelId; 9714cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 9814cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[APP_LABEL_ID] = appLabelId_; 9914cf0368Sopenharmony_ci } 10014cf0368Sopenharmony_ci} 10114cf0368Sopenharmony_ci 10214cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetBundleName() const 10314cf0368Sopenharmony_ci{ 10414cf0368Sopenharmony_ci return this->bundleName_; 10514cf0368Sopenharmony_ci} 10614cf0368Sopenharmony_ci 10714cf0368Sopenharmony_civoid SystemDefinedAppItem::SetBundleName(const std::string &bundleName) 10814cf0368Sopenharmony_ci{ 10914cf0368Sopenharmony_ci this->bundleName_ = bundleName; 11014cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 11114cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[BUNDLE_NAME] = bundleName_; 11214cf0368Sopenharmony_ci } 11314cf0368Sopenharmony_ci} 11414cf0368Sopenharmony_ci 11514cf0368Sopenharmony_cistd::string SystemDefinedAppItem::GetAbilityName() const 11614cf0368Sopenharmony_ci{ 11714cf0368Sopenharmony_ci return this->abilityName_; 11814cf0368Sopenharmony_ci} 11914cf0368Sopenharmony_ci 12014cf0368Sopenharmony_civoid SystemDefinedAppItem::SetAbilityName(const std::string &abilityName) 12114cf0368Sopenharmony_ci{ 12214cf0368Sopenharmony_ci this->abilityName_ = abilityName; 12314cf0368Sopenharmony_ci if (std::holds_alternative<std::shared_ptr<Object>>(value_)) { 12414cf0368Sopenharmony_ci std::get<std::shared_ptr<Object>>(value_)->value_[ABILITY_NAME] = abilityName_; 12514cf0368Sopenharmony_ci } 12614cf0368Sopenharmony_ci} 12714cf0368Sopenharmony_ci 12814cf0368Sopenharmony_civoid SystemDefinedAppItem::SetItems(UDDetails &details) 12914cf0368Sopenharmony_ci{ 13014cf0368Sopenharmony_ci for (auto &item : details) { 13114cf0368Sopenharmony_ci auto* value = std::get_if<std::string>(&item.second); 13214cf0368Sopenharmony_ci if (value == nullptr) { 13314cf0368Sopenharmony_ci continue; 13414cf0368Sopenharmony_ci } 13514cf0368Sopenharmony_ci if (item.first == APP_ID) { 13614cf0368Sopenharmony_ci SetAppId(*value); 13714cf0368Sopenharmony_ci } 13814cf0368Sopenharmony_ci if (item.first == APP_NAME) { 13914cf0368Sopenharmony_ci SetAppName(*value); 14014cf0368Sopenharmony_ci } 14114cf0368Sopenharmony_ci if (item.first == APP_ICON_ID) { 14214cf0368Sopenharmony_ci SetAppIconId(*value); 14314cf0368Sopenharmony_ci } 14414cf0368Sopenharmony_ci if (item.first == APP_LABEL_ID) { 14514cf0368Sopenharmony_ci SetAppLabelId(*value); 14614cf0368Sopenharmony_ci } 14714cf0368Sopenharmony_ci if (item.first == BUNDLE_NAME) { 14814cf0368Sopenharmony_ci SetBundleName(*value); 14914cf0368Sopenharmony_ci } 15014cf0368Sopenharmony_ci if (item.first == ABILITY_NAME) { 15114cf0368Sopenharmony_ci SetAbilityName(*value); 15214cf0368Sopenharmony_ci } 15314cf0368Sopenharmony_ci } 15414cf0368Sopenharmony_ci} 15514cf0368Sopenharmony_ci 15614cf0368Sopenharmony_ciUDDetails SystemDefinedAppItem::GetItems() 15714cf0368Sopenharmony_ci{ 15814cf0368Sopenharmony_ci UDDetails items; 15914cf0368Sopenharmony_ci items[APP_ID] = GetAppId(); 16014cf0368Sopenharmony_ci items[APP_NAME] = GetAppName(); 16114cf0368Sopenharmony_ci items[APP_ICON_ID] = GetAppIconId(); 16214cf0368Sopenharmony_ci items[APP_LABEL_ID] = GetAppLabelId(); 16314cf0368Sopenharmony_ci items[BUNDLE_NAME] = GetBundleName(); 16414cf0368Sopenharmony_ci items[ABILITY_NAME] = GetAbilityName(); 16514cf0368Sopenharmony_ci return items; 16614cf0368Sopenharmony_ci} 16714cf0368Sopenharmony_ci 16814cf0368Sopenharmony_civoid SystemDefinedAppItem::InitObject() 16914cf0368Sopenharmony_ci{ 17014cf0368Sopenharmony_ci if (!std::holds_alternative<std::shared_ptr<Object>>(value_)) { 17114cf0368Sopenharmony_ci auto value = value_; 17214cf0368Sopenharmony_ci value_ = std::make_shared<Object>(); 17314cf0368Sopenharmony_ci auto object = std::get<std::shared_ptr<Object>>(value_); 17414cf0368Sopenharmony_ci object->value_[UNIFORM_DATA_TYPE] = UtdUtils::GetUtdIdFromUtdEnum(dataType_); 17514cf0368Sopenharmony_ci object->value_[APP_ID] = appId_; 17614cf0368Sopenharmony_ci object->value_[APP_NAME] = appName_; 17714cf0368Sopenharmony_ci object->value_[APP_ICON_ID] = appIconId_; 17814cf0368Sopenharmony_ci object->value_[APP_LABEL_ID] = appLabelId_; 17914cf0368Sopenharmony_ci object->value_[BUNDLE_NAME] = bundleName_; 18014cf0368Sopenharmony_ci object->value_[ABILITY_NAME] = abilityName_; 18114cf0368Sopenharmony_ci object->value_[DETAILS] = ObjectUtils::ConvertToObject(details_); 18214cf0368Sopenharmony_ci object->value_[VALUE_TYPE] = value; 18314cf0368Sopenharmony_ci } 18414cf0368Sopenharmony_ci} 18514cf0368Sopenharmony_ci} // namespace UDMF 18614cf0368Sopenharmony_ci} // namespace OHOS