• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "extension_running_info.h"
17 #include "hilog_wrapper.h"
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
ReadFromParcel(Parcel & parcel)23 bool ExtensionRunningInfo::ReadFromParcel(Parcel &parcel)
24 {
25     std::unique_ptr<AppExecFwk::ElementName> readExtension(parcel.ReadParcelable<AppExecFwk::ElementName>());
26     if (readExtension == nullptr) {
27         return false;
28     }
29     extension = *readExtension;
30     pid = parcel.ReadInt32();
31     uid = parcel.ReadInt32();
32     type = static_cast<AppExecFwk::ExtensionAbilityType>(parcel.ReadInt32());
33     processName = Str16ToStr8(parcel.ReadString16());
34     startTime = parcel.ReadInt32();
35     int32_t clientPackageSize = parcel.ReadInt32();
36     for (int32_t i = 0; i < clientPackageSize; i++) {
37         clientPackage.emplace_back(Str16ToStr8(parcel.ReadString16()));
38     }
39     return true;
40 }
41 
Unmarshalling(Parcel & parcel)42 ExtensionRunningInfo *ExtensionRunningInfo::Unmarshalling(Parcel &parcel)
43 {
44     ExtensionRunningInfo *info = new (std::nothrow) ExtensionRunningInfo();
45     if (info == nullptr) {
46         return nullptr;
47     }
48 
49     if (!info->ReadFromParcel(parcel)) {
50         delete info;
51         info = nullptr;
52     }
53     return info;
54 }
55 
Marshalling(Parcel & parcel) const56 bool ExtensionRunningInfo::Marshalling(Parcel &parcel) const
57 {
58     if (!parcel.WriteParcelable(&extension)) {
59         return false;
60     }
61     if (!parcel.WriteInt32(pid)) {
62         return false;
63     }
64     if (!parcel.WriteInt32(uid)) {
65         return false;
66     }
67     if (!parcel.WriteInt32(static_cast<int32_t>(type))) {
68         return false;
69     }
70     if (!parcel.WriteString16(Str8ToStr16(processName))) {
71         return false;
72     }
73     if (!parcel.WriteInt32(startTime)) {
74         return false;
75     }
76     int32_t clientPackageSize = static_cast<int32_t>(clientPackage.size());
77     if (!parcel.WriteInt32(clientPackageSize)) {
78         return false;
79     }
80     for (std::string package : clientPackage) {
81         if (!parcel.WriteString16(Str8ToStr16(package))) {
82             return false;
83         }
84     }
85     return true;
86 }
87 }  // namespace AAFwk
88 }  // namespace OHOS
89