• 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_subscribe_info.h"
17 
18 #include "ans_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Notification {
NotificationSubscribeInfo()22 NotificationSubscribeInfo::NotificationSubscribeInfo()
23 {}
24 
~NotificationSubscribeInfo()25 NotificationSubscribeInfo::~NotificationSubscribeInfo()
26 {}
27 
NotificationSubscribeInfo(const NotificationSubscribeInfo & subscribeInfo)28 NotificationSubscribeInfo::NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo)
29 {
30     appNames_ = subscribeInfo.GetAppNames();
31 }
32 
AddAppName(const std::string appName)33 void NotificationSubscribeInfo::AddAppName(const std::string appName)
34 {
35     appNames_.push_back(appName);
36 }
37 
AddAppNames(const std::vector<std::string> & appNames)38 void NotificationSubscribeInfo::AddAppNames(const std::vector<std::string> &appNames)
39 {
40     appNames_.insert(appNames_.end(), appNames.begin(), appNames.end());
41 }
42 
GetAppNames() const43 std::vector<std::string> NotificationSubscribeInfo::GetAppNames() const
44 {
45     return appNames_;
46 }
47 
AddAppUserId(const int userId)48 void NotificationSubscribeInfo::AddAppUserId(const int userId)
49 {
50     userId_ = userId;
51 }
52 
GetAppUserId() const53 int32_t NotificationSubscribeInfo::GetAppUserId() const
54 {
55     return userId_;
56 }
57 
Marshalling(Parcel & parcel) const58 bool NotificationSubscribeInfo::Marshalling(Parcel &parcel) const
59 {
60     // write appNames_
61     if (!parcel.WriteStringVector(appNames_)) {
62         ANS_LOGE("Can't write appNames_");
63         return false;
64     }
65     return true;
66 }
67 
Unmarshalling(Parcel & parcel)68 NotificationSubscribeInfo *NotificationSubscribeInfo::Unmarshalling(Parcel &parcel)
69 {
70     NotificationSubscribeInfo *info = new (std::nothrow) NotificationSubscribeInfo();
71     if (info && !info->ReadFromParcel(parcel)) {
72         delete info;
73         info = nullptr;
74     }
75 
76     return info;
77 }
78 
ReadFromParcel(Parcel & parcel)79 bool NotificationSubscribeInfo::ReadFromParcel(Parcel &parcel)
80 {
81     parcel.ReadStringVector(&appNames_);
82     return true;
83 }
84 
Dump()85 std::string NotificationSubscribeInfo::Dump()
86 {
87     std::string appNames = "";
88     for (auto name : appNames_) {
89         appNames += name;
90         appNames += ", ";
91     }
92     return "NotificationSubscribeInfo{ "
93             "appNames = [" + appNames + "]" +
94             " }";
95 }
96 }  // namespace Notification
97 }  // namespace OHOS
98