• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "notification_bundle_option.h"
17 #include "ans_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace Notification {
NotificationBundleOption(const std::string & bundleName,const int32_t uid)21 NotificationBundleOption::NotificationBundleOption(const std::string &bundleName, const int32_t uid)
22     : bundleName_(bundleName), uid_(uid)
23 {}
24 
~NotificationBundleOption()25 NotificationBundleOption::~NotificationBundleOption()
26 {}
27 
SetBundleName(const std::string & bundleName)28 void NotificationBundleOption::SetBundleName(const std::string &bundleName)
29 {
30     bundleName_ = bundleName;
31 }
32 
GetBundleName() const33 std::string NotificationBundleOption::GetBundleName() const
34 {
35     return bundleName_;
36 }
37 
SetUid(const int32_t uid)38 void NotificationBundleOption::SetUid(const int32_t uid)
39 {
40     uid_ = uid;
41 }
42 
GetUid() const43 int32_t NotificationBundleOption::GetUid() const
44 {
45     return uid_;
46 }
47 
Dump()48 std::string NotificationBundleOption::Dump()
49 {
50     return "NotificationBundleOption{ "
51             "bundleName = " + bundleName_ +
52             ", uid = " + std::to_string(uid_) +
53             " }";
54 }
55 
Marshalling(Parcel & parcel) const56 bool NotificationBundleOption::Marshalling(Parcel &parcel) const
57 {
58     if (!parcel.WriteString(bundleName_)) {
59         ANS_LOGE("Failed to write bundle name");
60         return false;
61     }
62 
63     if (!parcel.WriteInt32(uid_)) {
64         ANS_LOGE("Failed to write uid");
65         return false;
66     }
67 
68     return true;
69 }
70 
Unmarshalling(Parcel & parcel)71 NotificationBundleOption *NotificationBundleOption::Unmarshalling(Parcel &parcel)
72 {
73     auto pbundleOption = new (std::nothrow) NotificationBundleOption();
74     if (pbundleOption && !pbundleOption->ReadFromParcel(parcel)) {
75         delete pbundleOption;
76         pbundleOption = nullptr;
77     }
78 
79     return pbundleOption;
80 }
81 
ReadFromParcel(Parcel & parcel)82 bool NotificationBundleOption::ReadFromParcel(Parcel &parcel)
83 {
84     if (!parcel.ReadString(bundleName_)) {
85         ANS_LOGE("Failed to read bundle name");
86         return false;
87     }
88 
89     uid_ = parcel.ReadInt32();
90 
91     return true;
92 }
93 }  // namespace Notification
94 }  // namespace OHOS
95