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