• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 "param.h"
17 
18 namespace OHOS::AbilityRuntime {
Marshalling(Parcel & parcel) const19 bool LoadParam::Marshalling(Parcel &parcel) const
20 {
21     if (!parcel.WriteInt32(abilityRecordId)) {
22         return false;
23     }
24     if (!parcel.WriteBool(isShellCall)) {
25         return false;
26     }
27     if (!parcel.WriteString(instanceKey)) {
28         return false;
29     }
30     if (token == nullptr) {
31         if (!parcel.WriteBool(false)) {
32             return false;
33         }
34     } else {
35         if (!parcel.WriteBool(true)) {
36             return false;
37         }
38         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
39             return false;
40         }
41     }
42     if (preToken == nullptr) {
43         if (!parcel.WriteBool(false)) {
44             return false;
45         }
46     } else {
47         if (!parcel.WriteBool(true)) {
48             return false;
49         }
50         if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(preToken)) {
51             return false;
52         }
53     }
54     if (!parcel.WriteBool(isKeepAlive)) {
55         return false;
56     }
57     if (!parcel.WriteBool(isKeepAliveAppService)) {
58         return false;
59     }
60     if (!parcel.WriteUint32(extensionProcessMode)) {
61         return false;
62     }
63     if (!parcel.WriteParcelable(&extensionLoadParam)) {
64         return false;
65     }
66     if (!parcel.WriteBool(isStartupHide)) {
67         return false;
68     }
69     return MarshallingTwo(parcel);
70 }
71 
MarshallingTwo(Parcel & parcel) const72 bool LoadParam::MarshallingTwo(Parcel &parcel) const
73 {
74     if (!parcel.WriteBool(isMainElementRunning)) {
75         return false;
76     }
77     return true;
78 }
79 
ReadFromParcel(Parcel & parcel)80 bool LoadParam::ReadFromParcel(Parcel &parcel)
81 {
82     abilityRecordId = parcel.ReadInt32();
83     isShellCall = parcel.ReadBool();
84     instanceKey = parcel.ReadString();
85     if (parcel.ReadBool()) {
86         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
87         if (token == nullptr) {
88             return false;
89         }
90     }
91     if (parcel.ReadBool()) {
92         preToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
93         if (preToken == nullptr) {
94             return false;
95         }
96     }
97     isKeepAlive = parcel.ReadBool();
98     isKeepAliveAppService = parcel.ReadBool();
99     extensionProcessMode = parcel.ReadUint32();
100     std::unique_ptr<ExtensionLoadParam> extensionParamRead(parcel.ReadParcelable<ExtensionLoadParam>());
101     if (!extensionParamRead) {
102         return false;
103     }
104     extensionLoadParam = *extensionParamRead;
105     isStartupHide = parcel.ReadBool();
106     isMainElementRunning = parcel.ReadBool();
107     return true;
108 }
109 
Unmarshalling(Parcel & parcel)110 LoadParam *LoadParam::Unmarshalling(Parcel &parcel)
111 {
112     LoadParam *loadParam = new (std::nothrow) LoadParam();
113     if (loadParam && !loadParam->ReadFromParcel(parcel)) {
114         delete loadParam;
115         loadParam = nullptr;
116     }
117     return loadParam;
118 }
119 }