• 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_template.h"
17 #include "ans_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace Notification {
SetTemplateName(const std::string & name)21 void NotificationTemplate::SetTemplateName(const std::string &name)
22 {
23     templateName_ = name;
24 }
25 
GetTemplateName() const26 std::string NotificationTemplate::GetTemplateName() const
27 {
28     return templateName_;
29 }
30 
SetTemplateData(const std::shared_ptr<AAFwk::WantParams> & data)31 void NotificationTemplate::SetTemplateData(const std::shared_ptr<AAFwk::WantParams> &data)
32 {
33     templateData_ = data;
34 }
35 
GetTemplateData() const36 std::shared_ptr<AAFwk::WantParams> NotificationTemplate::GetTemplateData() const
37 {
38     return templateData_;
39 }
40 
Dump()41 std::string NotificationTemplate::Dump()
42 {
43     return "templateName = " + templateName_ +
44         ", templateData = " + (templateData_ ? "not null" : "null");
45 }
46 
Marshalling(Parcel & parcel) const47 bool NotificationTemplate::Marshalling(Parcel &parcel) const
48 {
49     if (!parcel.WriteString(templateName_)) {
50         ANS_LOGE("Failed to write text");
51         return false;
52     }
53 
54     bool valid = templateData_ ? true : false;
55     if (!parcel.WriteBool(valid)) {
56         ANS_LOGE("Failed to write the flag which indicate whether templateData is null");
57         return false;
58     }
59 
60     if (valid) {
61         if (!parcel.WriteParcelable(templateData_.get())) {
62             ANS_LOGE("Failed to write templateData");
63             return false;
64         }
65     }
66 
67     return true;
68 }
69 
Unmarshalling(Parcel & parcel)70 NotificationTemplate *NotificationTemplate::Unmarshalling(Parcel &parcel)
71 {
72     auto templ = new NotificationTemplate();
73     if ((templ != nullptr) && !templ->ReadFromParcel(parcel)) {
74         delete templ;
75         templ = nullptr;
76     }
77 
78     return templ;
79 }
80 
ReadFromParcel(Parcel & parcel)81 bool NotificationTemplate::ReadFromParcel(Parcel &parcel)
82 {
83     if (!parcel.ReadString(templateName_)) {
84         ANS_LOGE("Failed to read template name");
85         return false;
86     }
87 
88     bool valid = parcel.ReadBool();
89     if (valid) {
90         templateData_ = std::shared_ptr<AAFwk::WantParams>(parcel.ReadParcelable<AAFwk::WantParams>());
91         if (!templateData_) {
92             ANS_LOGE("Failed to read template data");
93             return false;
94         }
95     }
96 
97     return true;
98 }
99 }  // namespace Notification
100 }  // namespace OHOS
101