/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "hap_module_info.h" #include "nlohmann/json.hpp" #include "string_ex.h" #include "app_log_wrapper.h" #include "parcel_macro.h" namespace OHOS { namespace AppExecFwk { bool HapModuleInfo::ReadFromParcel(Parcel &parcel) { name = Str16ToStr8(parcel.ReadString16()); moduleName = Str16ToStr8(parcel.ReadString16()); description = Str16ToStr8(parcel.ReadString16()); iconPath = Str16ToStr8(parcel.ReadString16()); label = Str16ToStr8(parcel.ReadString16()); backgroundImg = Str16ToStr8(parcel.ReadString16()); mainAbility = Str16ToStr8(parcel.ReadString16()); supportedModes = parcel.ReadInt32(); int32_t reqCapabilitiesSize; READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqCapabilitiesSize); for (int32_t i = 0; i < reqCapabilitiesSize; i++) { reqCapabilities.emplace_back(Str16ToStr8(parcel.ReadString16())); } int32_t deviceTypesSize; READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypesSize); for (int32_t i = 0; i < deviceTypesSize; i++) { deviceTypes.emplace_back(Str16ToStr8(parcel.ReadString16())); } int32_t abilityInfosSize = parcel.ReadInt32(); for (int32_t i = 0; i < abilityInfosSize; i++) { std::unique_ptr abilityInfo(parcel.ReadParcelable()); if (!abilityInfo) { APP_LOGE("ReadParcelable failed"); return false; } abilityInfos.emplace_back(*abilityInfo); } int32_t colorModeData; READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, colorModeData); colorMode = static_cast(colorModeData); return true; } HapModuleInfo *HapModuleInfo::Unmarshalling(Parcel &parcel) { HapModuleInfo *info = new (std::nothrow) HapModuleInfo(); if (info && !info->ReadFromParcel(parcel)) { APP_LOGW("read from parcel failed"); delete info; info = nullptr; } return info; } bool HapModuleInfo::Marshalling(Parcel &parcel) const { WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(backgroundImg)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(mainAbility)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportedModes); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqCapabilities.size()); for (auto &reqCapability : reqCapabilities) { WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(reqCapability)); } WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypes.size()); for (auto &deviceType : deviceTypes) { WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceType)); } WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityInfos.size()); for (auto &abilityInfo : abilityInfos) { WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &abilityInfo); } WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(colorMode)); return true; } } // namespace AppExecFwk } // namespace OHOS