• 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 {
ReadModuleVersion(MessageParcel & reply,ModuleVersion & version)22 void ReadModuleVersion(MessageParcel &reply, ModuleVersion &version)
23 {
24     version.apiVersion = reply.ReadUint32();
25     version.versionCode = reply.ReadUint32();
26     version.patchVersion = reply.ReadUint32();
27 }
28 
WriteModuleVersion(MessageParcel & data,const ModuleVersion & version)29 void WriteModuleVersion(MessageParcel &data, const ModuleVersion &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     ReadModuleVersion(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     WriteModuleVersion(data, info.version);
48 }
49 
ReadModulePackageInfo(MessageParcel & reply,ModulePackageInfo & info)50 void ReadModulePackageInfo(MessageParcel &reply, ModulePackageInfo &info)
51 {
52     info.hmpName = Str16ToStr8(reply.ReadString16());
53     ModuleIpcHelper::ReadList<SaInfo>(reply, info.saInfoList, ReadSaInfo);
54 }
55 
WriteModulePackageInfo(MessageParcel & data,const ModulePackageInfo & info)56 void WriteModulePackageInfo(MessageParcel &data, const ModulePackageInfo &info)
57 {
58     data.WriteString16(Str8ToStr16(info.hmpName));
59     ModuleIpcHelper::WriteList<SaInfo>(data, info.saInfoList, WriteSaInfo);
60 }
61 
ReadSaStatus(MessageParcel & reply,SaStatus & status)62 void ReadSaStatus(MessageParcel &reply, SaStatus &status)
63 {
64     status.saId = reply.ReadInt32();
65     status.isPreInstalled = reply.ReadBool();
66     status.isMountSuccess = reply.ReadBool();
67 }
68 
WriteSaStatus(MessageParcel & data,const SaStatus & status)69 void WriteSaStatus(MessageParcel &data, const SaStatus &status)
70 {
71     data.WriteInt32(status.saId);
72     data.WriteBool(status.isPreInstalled);
73     data.WriteBool(status.isMountSuccess);
74 }
75 
ReadModulePackageInfos(MessageParcel & reply,std::list<ModulePackageInfo> & infos)76 int32_t ModuleIpcHelper::ReadModulePackageInfos(MessageParcel &reply, std::list<ModulePackageInfo> &infos)
77 {
78     ReadList<ModulePackageInfo>(reply, infos, ReadModulePackageInfo);
79     return 0;
80 }
81 
WriteModulePackageInfos(MessageParcel & data,const std::list<ModulePackageInfo> & infos)82 int32_t ModuleIpcHelper::WriteModulePackageInfos(MessageParcel &data, const std::list<ModulePackageInfo> &infos)
83 {
84     WriteList<ModulePackageInfo>(data, infos, WriteModulePackageInfo);
85     return 0;
86 }
87 
ReadModuleUpdateStatus(MessageParcel & reply,ModuleUpdateStatus & status)88 int32_t ModuleIpcHelper::ReadModuleUpdateStatus(MessageParcel &reply, ModuleUpdateStatus &status)
89 {
90     status.process = Str16ToStr8(reply.ReadString16());
91     ReadList<SaStatus>(reply, status.saStatusList, ReadSaStatus);
92     return 0;
93 }
94 
WriteModuleUpdateStatus(MessageParcel & data,const ModuleUpdateStatus & status)95 int32_t ModuleIpcHelper::WriteModuleUpdateStatus(MessageParcel &data, const ModuleUpdateStatus &status)
96 {
97     data.WriteString16(Str8ToStr16(status.process));
98     WriteList<SaStatus>(data, status.saStatusList, WriteSaStatus);
99     return 0;
100 }
101 } // namespace SysInstaller
102 } // namespace OHOS