1 /*
2 * Copyright (c) 2023 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 "module_ipc_helper.h"
17
18 #include "string_ex.h"
19
20 namespace OHOS {
21 namespace SysInstaller {
ReadSaVersion(MessageParcel & reply,SaVersion & version)22 void ReadSaVersion(MessageParcel &reply, SaVersion &version)
23 {
24 version.apiVersion = reply.ReadUint32();
25 version.versionCode = reply.ReadUint32();
26 version.patchVersion = reply.ReadUint32();
27 }
28
WriteSaVersion(MessageParcel & data,const SaVersion & version)29 void WriteSaVersion(MessageParcel &data, const SaVersion &version)
30 {
31 data.WriteUint32(version.apiVersion);
32 data.WriteUint32(version.versionCode);
33 data.WriteUint32(version.patchVersion);
34 }
35
ReadSaInfo(MessageParcel & reply,SaInfo & info)36 void ReadSaInfo(MessageParcel &reply, SaInfo &info)
37 {
38 info.saName = Str16ToStr8(reply.ReadString16());
39 info.saId = reply.ReadInt32();
40 ReadSaVersion(reply, info.version);
41 }
42
WriteSaInfo(MessageParcel & data,const SaInfo & info)43 void WriteSaInfo(MessageParcel &data, const SaInfo &info)
44 {
45 data.WriteString16(Str8ToStr16(info.saName));
46 data.WriteInt32(info.saId);
47 WriteSaVersion(data, info.version);
48 }
49
ReadBundleInfo(MessageParcel & reply,BundleInfo & info)50 void ReadBundleInfo(MessageParcel &reply, BundleInfo &info)
51 {
52 info.bundleName = Str16ToStr8(reply.ReadString16());
53 info.bundleVersion = Str16ToStr8(reply.ReadString16());
54 }
55
WriteBundleInfo(MessageParcel & data,const BundleInfo & info)56 void WriteBundleInfo(MessageParcel &data, const BundleInfo &info)
57 {
58 data.WriteString16(Str8ToStr16(info.bundleName));
59 data.WriteString16(Str8ToStr16(info.bundleVersion));
60 }
61
ReadModulePackageInfo(MessageParcel & reply,ModulePackageInfo & info)62 void ReadModulePackageInfo(MessageParcel &reply, ModulePackageInfo &info)
63 {
64 info.hmpName = Str16ToStr8(reply.ReadString16());
65 info.version = Str16ToStr8(reply.ReadString16());
66 info.saSdkVersion = Str16ToStr8(reply.ReadString16());
67 info.type = Str16ToStr8(reply.ReadString16());
68 info.apiVersion = reply.ReadInt32();
69 info.hotApply = reply.ReadInt32();
70
71 ModuleIpcHelper::ReadList<SaInfo>(reply, info.saInfoList, ReadSaInfo);
72 ModuleIpcHelper::ReadList<BundleInfo>(reply, info.bundleInfoList, ReadBundleInfo);
73 }
74
WriteModulePackageInfo(MessageParcel & data,const ModulePackageInfo & info)75 void WriteModulePackageInfo(MessageParcel &data, const ModulePackageInfo &info)
76 {
77 data.WriteString16(Str8ToStr16(info.hmpName));
78 data.WriteString16(Str8ToStr16(info.version));
79 data.WriteString16(Str8ToStr16(info.saSdkVersion));
80 data.WriteString16(Str8ToStr16(info.type));
81 data.WriteInt32(info.apiVersion);
82 data.WriteInt32(info.hotApply);
83
84 ModuleIpcHelper::WriteList<SaInfo>(data, info.saInfoList, WriteSaInfo);
85 ModuleIpcHelper::WriteList<BundleInfo>(data, info.bundleInfoList, WriteBundleInfo);
86 }
87
ReadModulePackageInfos(MessageParcel & reply,std::list<ModulePackageInfo> & infos)88 int32_t ModuleIpcHelper::ReadModulePackageInfos(MessageParcel &reply, std::list<ModulePackageInfo> &infos)
89 {
90 ReadList<ModulePackageInfo>(reply, infos, ReadModulePackageInfo);
91 return 0;
92 }
93
WriteModulePackageInfos(MessageParcel & data,const std::list<ModulePackageInfo> & infos)94 int32_t ModuleIpcHelper::WriteModulePackageInfos(MessageParcel &data, const std::list<ModulePackageInfo> &infos)
95 {
96 WriteList<ModulePackageInfo>(data, infos, WriteModulePackageInfo);
97 return 0;
98 }
99
ReadModuleUpdateStatus(MessageParcel & reply,ModuleUpdateStatus & status)100 int32_t ModuleIpcHelper::ReadModuleUpdateStatus(MessageParcel &reply, ModuleUpdateStatus &status)
101 {
102 status.hmpName = Str16ToStr8(reply.ReadString16());
103 status.isPreInstalled = reply.ReadBool();
104 status.isAllMountSuccess = reply.ReadBool();
105 status.isHotInstall = reply.ReadBool();
106 status.type = static_cast<HmpInstallType>(reply.ReadInt32());
107 return 0;
108 }
109
WriteModuleUpdateStatus(MessageParcel & data,const ModuleUpdateStatus & status)110 int32_t ModuleIpcHelper::WriteModuleUpdateStatus(MessageParcel &data, const ModuleUpdateStatus &status)
111 {
112 data.WriteString16(Str8ToStr16(status.hmpName));
113 data.WriteBool(status.isPreInstalled);
114 data.WriteBool(status.isAllMountSuccess);
115 data.WriteBool(status.isHotInstall);
116 data.WriteInt32(static_cast<int32_t>(status.type));
117 return 0;
118 }
119 } // namespace SysInstaller
120 } // namespace OHOS