1 /*
2 * Copyright (c) 2024 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 "running_multi_info.h"
17
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20
21 #include "hilog_tag_wrapper.h"
22 #include "parcel_macro_base.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)26 bool RunningMultiAppInfo::ReadFromParcel(Parcel &parcel)
27 {
28 bundleName = Str16ToStr8(parcel.ReadString16());
29 mode = parcel.ReadInt32();
30 int32_t runningAppClonesSize;
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, runningAppClonesSize);
32 if (runningAppClonesSize > MAX_CLONE_APP_NUM) {
33 return false;
34 }
35 for (auto i = 0; i < runningAppClonesSize; i++) {
36 RunningAppClone clone;
37 clone.appCloneIndex = parcel.ReadInt32();
38 clone.uid = parcel.ReadInt32();
39 parcel.ReadInt32Vector(&clone.pids);
40 runningAppClones.emplace_back(clone);
41 }
42 return true;
43 }
44
Unmarshalling(Parcel & parcel)45 RunningMultiAppInfo *RunningMultiAppInfo::Unmarshalling(Parcel &parcel)
46 {
47 RunningMultiAppInfo *info = new (std::nothrow) RunningMultiAppInfo();
48 if (info && !info->ReadFromParcel(parcel)) {
49 TAG_LOGW(AAFwkTag::APPMGR, "read from parcel failed");
50 delete info;
51 info = nullptr;
52 }
53 return info;
54 }
55
Marshalling(Parcel & parcel) const56 bool RunningMultiAppInfo::Marshalling(Parcel &parcel) const
57 {
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, mode);
60 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, runningAppClones.size());
61 if (runningAppClones.size() > MAX_CLONE_APP_NUM) {
62 return false;
63 }
64 for (auto &clone : runningAppClones) {
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, clone.appCloneIndex);
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, clone.uid);
67 if (!parcel.WriteInt32Vector(clone.pids)) {
68 TAG_LOGE(AAFwkTag::APPMGR, "write runningAppClones failed.");
69 return false;
70 }
71 }
72 return true;
73 }
74 } // namespace AppExecFwk
75 } // namespace OHOS