• 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 {
23 namespace {
24 constexpr int CYCLE_LIMIT = 1000;
25 }
ReadFromParcel(Parcel & parcel)26 bool ExtensionRunningInfo::ReadFromParcel(Parcel &parcel)
27 {
28     std::unique_ptr<AppExecFwk::ElementName> readExtension(parcel.ReadParcelable<AppExecFwk::ElementName>());
29     if (readExtension == nullptr) {
30         return false;
31     }
32     extension = *readExtension;
33     pid = parcel.ReadInt32();
34     uid = parcel.ReadInt32();
35     type = static_cast<AppExecFwk::ExtensionAbilityType>(parcel.ReadInt32());
36     processName = Str16ToStr8(parcel.ReadString16());
37     startTime = parcel.ReadInt32();
38     int32_t clientPackageSize = parcel.ReadInt32();
39     if (clientPackageSize > CYCLE_LIMIT) {
40         HILOG_ERROR("clientPackageSize is too large.");
41         return false;
42     }
43     for (int32_t i = 0; i < clientPackageSize; i++) {
44         clientPackage.emplace_back(Str16ToStr8(parcel.ReadString16()));
45     }
46     return true;
47 }
48 
Unmarshalling(Parcel & parcel)49 ExtensionRunningInfo *ExtensionRunningInfo::Unmarshalling(Parcel &parcel)
50 {
51     ExtensionRunningInfo *info = new (std::nothrow) ExtensionRunningInfo();
52     if (info == nullptr) {
53         return nullptr;
54     }
55 
56     if (!info->ReadFromParcel(parcel)) {
57         delete info;
58         info = nullptr;
59     }
60     return info;
61 }
62 
Marshalling(Parcel & parcel) const63 bool ExtensionRunningInfo::Marshalling(Parcel &parcel) const
64 {
65     if (!parcel.WriteParcelable(&extension)) {
66         return false;
67     }
68     if (!parcel.WriteInt32(pid)) {
69         return false;
70     }
71     if (!parcel.WriteInt32(uid)) {
72         return false;
73     }
74     if (!parcel.WriteInt32(static_cast<int32_t>(type))) {
75         return false;
76     }
77     if (!parcel.WriteString16(Str8ToStr16(processName))) {
78         return false;
79     }
80     if (!parcel.WriteInt32(startTime)) {
81         return false;
82     }
83     int32_t clientPackageSize = static_cast<int32_t>(clientPackage.size());
84     if (!parcel.WriteInt32(clientPackageSize)) {
85         return false;
86     }
87     for (std::string package : clientPackage) {
88         if (!parcel.WriteString16(Str8ToStr16(package))) {
89             return false;
90         }
91     }
92     return true;
93 }
94 }  // namespace AAFwk
95 }  // namespace OHOS
96