1 /*
2  * Copyright (c) 2023 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 "notification_check_request.h"
16 #include "ans_log_wrapper.h"
17 
18 namespace OHOS {
19 namespace Notification {
20 
21 
NotificationCheckRequest(NotificationContent::Type contentType,NotificationConstant::SlotType slotType,std::vector<std::string> extraKeys)22 NotificationCheckRequest::NotificationCheckRequest(NotificationContent::Type contentType,
23     NotificationConstant::SlotType slotType, std::vector<std::string> extraKeys)
24     : contentType_(contentType), slotType_(slotType), extraKeys_(extraKeys)
25 {}
26 
~NotificationCheckRequest()27 NotificationCheckRequest::~NotificationCheckRequest()
28 {}
29 
SetContentType(NotificationContent::Type contentType)30 void NotificationCheckRequest::SetContentType(NotificationContent::Type contentType)
31 {
32     contentType_ = contentType;
33 }
34 
GetContentType() const35 NotificationContent::Type NotificationCheckRequest::GetContentType() const
36 {
37     return contentType_;
38 }
39 
SetSlotType(NotificationConstant::SlotType slotType)40 void NotificationCheckRequest::SetSlotType(NotificationConstant::SlotType slotType)
41 {
42     slotType_ = slotType;
43 }
44 
GetSlotType() const45 NotificationConstant::SlotType NotificationCheckRequest::GetSlotType() const
46 {
47     return slotType_;
48 }
49 
SetExtraKeys(std::vector<std::string> extraKeys)50 void NotificationCheckRequest::SetExtraKeys(std::vector<std::string> extraKeys)
51 {
52     extraKeys_ = extraKeys;
53 }
54 
GetExtraKeys() const55 std::vector<std::string> NotificationCheckRequest::GetExtraKeys() const
56 {
57     return extraKeys_;
58 }
59 
SetUid(const int32_t uid)60 void NotificationCheckRequest::SetUid(const int32_t uid)
61 {
62     creatorUid_ = uid;
63 }
64 
GetUid() const65 int32_t NotificationCheckRequest::GetUid() const
66 {
67     return creatorUid_;
68 }
69 
Marshalling(Parcel & parcel) const70 bool NotificationCheckRequest::Marshalling(Parcel &parcel) const
71 {
72     if (!parcel.WriteInt32(static_cast<int32_t>(contentType_))) {
73         ANS_LOGE("Failed to write content type");
74         return false;
75     }
76     if (!parcel.WriteInt32(static_cast<int32_t>(slotType_))) {
77         ANS_LOGE("Failed to write slot type");
78         return false;
79     }
80     if (!parcel.WriteStringVector(extraKeys_)) {
81         ANS_LOGE("Failed to write extra info keys");
82         return false;
83     }
84 
85     return true;
86 }
87 
Unmarshalling(Parcel & parcel)88 NotificationCheckRequest *NotificationCheckRequest::Unmarshalling(Parcel &parcel)
89 {
90     auto objptr = new (std::nothrow) NotificationCheckRequest();
91     if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
92         delete objptr;
93         objptr = nullptr;
94     }
95 
96     return objptr;
97 }
98 
ReadFromParcel(Parcel & parcel)99 bool NotificationCheckRequest::ReadFromParcel(Parcel &parcel)
100 {
101     contentType_ = static_cast<NotificationContent::Type>(parcel.ReadInt32());
102     slotType_ = static_cast<NotificationConstant::SlotType>(parcel.ReadInt32());
103     if (!parcel.ReadStringVector(&extraKeys_)) {
104         ANS_LOGE("Failed to read extra info keys");
105         return false;
106     }
107     return true;
108 }
109 
110 }  // namespace Notification
111 }  // namespace OHOS
112