1 /*
2 * Copyright (c) 2022 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 "enabled_notification_callback_data.h"
17
18 #include <string> // for operator+, basic_string
19
20 #include "ans_log_wrapper.h"
21 #include "string_ex.h"
22 #include "parcel.h" // for Parcel
23
24 namespace OHOS {
25 namespace Notification {
EnabledNotificationCallbackData(std::string bundle,uid_t uid,bool enable)26 EnabledNotificationCallbackData::EnabledNotificationCallbackData(std::string bundle, uid_t uid, bool enable)
27 : bundle_(bundle), uid_(uid), enable_(enable)
28 {}
29
SetBundle(const std::string bundle)30 void EnabledNotificationCallbackData::SetBundle(const std::string bundle)
31 {
32 bundle_ = bundle;
33 }
34
GetBundle() const35 std::string EnabledNotificationCallbackData::GetBundle() const
36 {
37 return bundle_;
38 }
39
SetUid(const uid_t uid)40 void EnabledNotificationCallbackData::SetUid(const uid_t uid)
41 {
42 uid_ = uid;
43 }
44
GetUid() const45 uid_t EnabledNotificationCallbackData::GetUid() const
46 {
47 return uid_;
48 }
49
SetEnable(const bool enable)50 void EnabledNotificationCallbackData::SetEnable(const bool enable)
51 {
52 enable_ = enable;
53 }
54
GetEnable() const55 bool EnabledNotificationCallbackData::GetEnable() const
56 {
57 return enable_;
58 }
59
Dump()60 std::string EnabledNotificationCallbackData::Dump()
61 {
62 return "EnabledNotificationCallbackData{ "
63 "bundle = " + bundle_ +
64 ", uid = " + std::to_string(uid_) +
65 ", enable = " + std::to_string(enable_) +
66 " }";
67 }
68
Marshalling(Parcel & parcel) const69 bool EnabledNotificationCallbackData::Marshalling(Parcel &parcel) const
70 {
71 if (!parcel.WriteString16(Str8ToStr16(bundle_))) {
72 ANS_LOGE("Failed to write bundle name");
73 return false;
74 }
75
76 if (!parcel.WriteInt32(uid_)) {
77 ANS_LOGE("Failed to write uid");
78 return false;
79 }
80
81 if (!parcel.WriteBool(enable_)) {
82 ANS_LOGE("Failed to write enable");
83 return false;
84 }
85
86 return true;
87 }
88
Unmarshalling(Parcel & parcel)89 EnabledNotificationCallbackData *EnabledNotificationCallbackData::Unmarshalling(Parcel &parcel)
90 {
91 auto objptr = new (std::nothrow) EnabledNotificationCallbackData();
92 if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
93 delete objptr;
94 objptr = nullptr;
95 }
96
97 return objptr;
98 }
99
ReadFromParcel(Parcel & parcel)100 bool EnabledNotificationCallbackData::ReadFromParcel(Parcel &parcel)
101 {
102 bundle_ = Str16ToStr8(parcel.ReadString16());
103 uid_ = static_cast<uid_t>(parcel.ReadInt32());
104 enable_ = parcel.ReadBool();
105
106 return true;
107 }
108 } // namespace Notification
109 } // namespace OHOS