• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t moduleSize = reply.ReadInt32();
70     if (moduleSize > IPC_MAX_SIZE || moduleSize < IPC_MIN_SIZE) {
71         return;
72     }
73     for (int32_t i = 0; i < moduleSize; ++i) {
74         ModuleInfo infoTmp;
75         std::string moduleName = Str16ToStr8(reply.ReadString16());
76         ModuleIpcHelper::ReadList<SaInfo>(reply, infoTmp.saInfoList, ReadSaInfo);
77         ModuleIpcHelper::ReadList<BundleInfo>(reply, infoTmp.bundleInfoList, ReadBundleInfo);
78         info.moduleMap.emplace(moduleName, std::move(infoTmp));
79     }
80 }
81 
WriteModulePackageInfo(MessageParcel & data,const ModulePackageInfo & info)82 void WriteModulePackageInfo(MessageParcel &data, const ModulePackageInfo &info)
83 {
84     data.WriteString16(Str8ToStr16(info.hmpName));
85     data.WriteString16(Str8ToStr16(info.version));
86     data.WriteString16(Str8ToStr16(info.saSdkVersion));
87     data.WriteString16(Str8ToStr16(info.type));
88     data.WriteInt32(info.apiVersion);
89 
90     data.WriteInt32(static_cast<int32_t>(info.moduleMap.size()));
91     for (const auto &[key, value] : info.moduleMap) {
92         data.WriteString16(Str8ToStr16(key));
93         ModuleIpcHelper::WriteList<SaInfo>(data, value.saInfoList, WriteSaInfo);
94         ModuleIpcHelper::WriteList<BundleInfo>(data, value.bundleInfoList, WriteBundleInfo);
95     }
96 }
97 
ReadModulePackageInfos(MessageParcel & reply,std::list<ModulePackageInfo> & infos)98 int32_t ModuleIpcHelper::ReadModulePackageInfos(MessageParcel &reply, std::list<ModulePackageInfo> &infos)
99 {
100     ReadList<ModulePackageInfo>(reply, infos, ReadModulePackageInfo);
101     return 0;
102 }
103 
WriteModulePackageInfos(MessageParcel & data,const std::list<ModulePackageInfo> & infos)104 int32_t ModuleIpcHelper::WriteModulePackageInfos(MessageParcel &data, const std::list<ModulePackageInfo> &infos)
105 {
106     WriteList<ModulePackageInfo>(data, infos, WriteModulePackageInfo);
107     return 0;
108 }
109 
ReadModuleUpdateStatus(MessageParcel & reply,ModuleUpdateStatus & status)110 int32_t ModuleIpcHelper::ReadModuleUpdateStatus(MessageParcel &reply, ModuleUpdateStatus &status)
111 {
112     status.hmpName = Str16ToStr8(reply.ReadString16());
113     status.isPreInstalled = reply.ReadBool();
114     status.isAllMountSuccess = reply.ReadBool();
115     return 0;
116 }
117 
WriteModuleUpdateStatus(MessageParcel & data,const ModuleUpdateStatus & status)118 int32_t ModuleIpcHelper::WriteModuleUpdateStatus(MessageParcel &data, const ModuleUpdateStatus &status)
119 {
120     data.WriteString16(Str8ToStr16(status.hmpName));
121     data.WriteBool(status.isPreInstalled);
122     data.WriteBool(status.isAllMountSuccess);
123     return 0;
124 }
125 } // namespace SysInstaller
126 } // namespace OHOS