1 /*
2 * Copyright (c) 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 "continuous_task_info.h"
17 #include "ipc_util.h"
18 #include "continuous_task_log.h"
19
20 namespace OHOS {
21 namespace BackgroundTaskMgr {
GetAbilityName() const22 std::string ContinuousTaskInfo::GetAbilityName() const
23 {
24 return abilityName_;
25 }
26
GetWantAgentBundleName() const27 std::string ContinuousTaskInfo::GetWantAgentBundleName() const
28 {
29 return wantAgentBundleName_;
30 }
31
GetWantAgentAbilityName() const32 std::string ContinuousTaskInfo::GetWantAgentAbilityName() const
33 {
34 return wantAgentAbilityName_;
35 }
36
GetUid() const37 int32_t ContinuousTaskInfo::GetUid() const
38 {
39 return uid_;
40 }
41
GetPid() const42 int32_t ContinuousTaskInfo::GetPid() const
43 {
44 return pid_;
45 }
46
GetNotificationId() const47 int32_t ContinuousTaskInfo::GetNotificationId() const
48 {
49 return notificationId_;
50 }
51
GetContinuousTaskId() const52 int32_t ContinuousTaskInfo::GetContinuousTaskId() const
53 {
54 return continuousTaskId_;
55 }
56
GetAbilityId() const57 int32_t ContinuousTaskInfo::GetAbilityId() const
58 {
59 return abilityId_;
60 }
61
GetBackgroundModes() const62 std::vector<uint32_t> ContinuousTaskInfo::GetBackgroundModes() const
63 {
64 return backgroundModes_;
65 }
66
GetBackgroundSubModes() const67 std::vector<uint32_t> ContinuousTaskInfo::GetBackgroundSubModes() const
68 {
69 return backgroundSubModes_;
70 }
71
IsFromWebView() const72 bool ContinuousTaskInfo::IsFromWebView() const
73 {
74 return isFromWebView_;
75 }
76
GetSuspendState() const77 bool ContinuousTaskInfo::GetSuspendState() const
78 {
79 return suspendState_;
80 }
81
ToString(const std::vector<uint32_t> & modes) const82 std::string ContinuousTaskInfo::ToString(const std::vector<uint32_t> &modes) const
83 {
84 std::string result;
85 for (auto it : modes) {
86 result += std::to_string(it);
87 result += ",";
88 }
89 return result;
90 }
91
Marshalling(Parcel & out) const92 bool ContinuousTaskInfo::Marshalling(Parcel& out) const
93 {
94 WRITE_PARCEL_WITH_RET(out, String, abilityName_, false);
95 WRITE_PARCEL_WITH_RET(out, Int32, uid_, false);
96 WRITE_PARCEL_WITH_RET(out, Int32, pid_, false);
97 WRITE_PARCEL_WITH_RET(out, Bool, isFromWebView_, false);
98 if (!out.WriteUInt32Vector(backgroundModes_)) {
99 BGTASK_LOGE("Failed to write backgroundModes");
100 return false;
101 }
102 if (!out.WriteUInt32Vector(backgroundSubModes_)) {
103 BGTASK_LOGE("Failed to write backgroundSubModes");
104 return false;
105 }
106 WRITE_PARCEL_WITH_RET(out, Int32, notificationId_, false);
107 WRITE_PARCEL_WITH_RET(out, Int32, continuousTaskId_, false);
108 WRITE_PARCEL_WITH_RET(out, Int32, abilityId_, false);
109 WRITE_PARCEL_WITH_RET(out, String, wantAgentBundleName_, false);
110 WRITE_PARCEL_WITH_RET(out, String, wantAgentAbilityName_, false);
111 WRITE_PARCEL_WITH_RET(out, Bool, suspendState_, false);
112 return true;
113 }
114
Unmarshalling(Parcel & in)115 ContinuousTaskInfo* ContinuousTaskInfo::Unmarshalling(Parcel &in)
116 {
117 ContinuousTaskInfo* info = new (std::nothrow) ContinuousTaskInfo();
118 if (info && !info->ReadFromParcel(in)) {
119 BGTASK_LOGE("read from parcel failed");
120 delete info;
121 info = nullptr;
122 }
123 return info;
124 }
125
ReadFromParcel(Parcel & in)126 bool ContinuousTaskInfo::ReadFromParcel(Parcel& in)
127 {
128 READ_PARCEL_WITH_RET(in, String, abilityName_, false);
129 READ_PARCEL_WITH_RET(in, Int32, uid_, false);
130 READ_PARCEL_WITH_RET(in, Int32, pid_, false);
131 READ_PARCEL_WITH_RET(in, Bool, isFromWebView_, false);
132 if (!in.ReadUInt32Vector(&backgroundModes_)) {
133 BGTASK_LOGE("read parce backgroundModes error");
134 return false;
135 }
136 if (!in.ReadUInt32Vector(&backgroundSubModes_)) {
137 BGTASK_LOGE("read parce backgroundSubModes error");
138 return false;
139 }
140 READ_PARCEL_WITH_RET(in, Int32, notificationId_, false);
141 READ_PARCEL_WITH_RET(in, Int32, continuousTaskId_, false);
142 READ_PARCEL_WITH_RET(in, Int32, abilityId_, false);
143 READ_PARCEL_WITH_RET(in, String, wantAgentBundleName_, false);
144 READ_PARCEL_WITH_RET(in, String, wantAgentAbilityName_, false);
145 READ_PARCEL_WITH_RET(in, Bool, suspendState_, false);
146 return true;
147 }
148 } // namespace BackgroundTaskMgr
149 } // namespace OHOS