• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     setterId = parcel.ReadInt32();
29     policy = KeepAlivePolicy(parcel.ReadInt32());
30     return true;
31 }
32 
Unmarshalling(Parcel & parcel)33 KeepAliveInfo *KeepAliveInfo::Unmarshalling(Parcel &parcel)
34 {
35     KeepAliveInfo *info = new (std::nothrow) KeepAliveInfo();
36     if (info == nullptr) {
37         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "info null");
38         return nullptr;
39     }
40 
41     if (!info->ReadFromParcel(parcel)) {
42         delete info;
43         info = nullptr;
44     }
45     return info;
46 }
47 
Marshalling(Parcel & parcel) const48 bool KeepAliveInfo::Marshalling(Parcel &parcel) const
49 {
50     if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
51         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write bundleName");
52         return false;
53     }
54     if (!parcel.WriteInt32(userId)) {
55         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write userId");
56         return false;
57     }
58     if (!parcel.WriteInt32(static_cast<int32_t>(appType))) {
59         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write appType");
60         return false;
61     }
62     if (!parcel.WriteInt32(static_cast<int32_t>(setter))) {
63         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write setter");
64         return false;
65     }
66     if (!parcel.WriteInt32(setterId)) {
67         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write setterId");
68         return false;
69     }
70     if (!parcel.WriteInt32(static_cast<int32_t>(policy))) {
71         TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed to write policy");
72         return false;
73     }
74     return true;
75 }
76 } // namespace AbilityRuntime
77 } // namespace OHOS
78