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 #include "keep_alive_info.h"
16
17 #include "hilog_tag_wrapper.h"
18 #include "string_ex.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
ReadFromParcel(Parcel & parcel)22 bool KeepAliveInfo::ReadFromParcel(Parcel &parcel)
23 {
24 bundleName = Str16ToStr8(parcel.ReadString16());
25 userId = parcel.ReadInt32();
26 appType = KeepAliveAppType(parcel.ReadInt32());
27 setter = KeepAliveSetter(parcel.ReadInt32());
28 return true;
29 }
30
Unmarshalling(Parcel & parcel)31 KeepAliveInfo *KeepAliveInfo::Unmarshalling(Parcel &parcel)
32 {
33 KeepAliveInfo *info = new (std::nothrow) KeepAliveInfo();
34 if (info == nullptr) {
35 TAG_LOGE(AAFwkTag::KEEP_ALIVE, "info null");
36 return nullptr;
37 }
38
39 if (!info->ReadFromParcel(parcel)) {
40 delete info;
41 info = nullptr;
42 }
43 return info;
44 }
45
Marshalling(Parcel & parcel) const46 bool KeepAliveInfo::Marshalling(Parcel &parcel) const
47 {
48 if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
49 TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write bundleName");
50 return false;
51 }
52 if (!parcel.WriteInt32(userId)) {
53 TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write userId");
54 return false;
55 }
56 if (!parcel.WriteInt32(static_cast<int32_t>(appType))) {
57 TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write appType");
58 return false;
59 }
60 if (!parcel.WriteInt32(static_cast<int32_t>(setter))) {
61 TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write setter");
62 return false;
63 }
64 return true;
65 }
66 } // namespace AbilityRuntime
67 } // namespace OHOS
68