1 /*
2  * Copyright (C) 2023 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 "common_event_support.h"
17 #include "sms_broadcast_subscriber_gtest.h"
18 #include "telephony_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 using namespace OHOS::EventFwk;
SmsBroadcastSubscriberGtest(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo,SmsMmsTestHelper & helper)23 SmsBroadcastSubscriberGtest::SmsBroadcastSubscriberGtest(
24     const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo, SmsMmsTestHelper &helper)
25     : CommonEventSubscriber(subscriberInfo)
26 {
27     helper_ = &helper;
28 }
29 
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & data)30 void SmsBroadcastSubscriberGtest::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
31 {
32     std::string action = data.GetWant().GetAction();
33     if (action == CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED ||
34         action == CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED) {
35         TELEPHONY_LOGI("receive a Cell Broadcast");
36         if (helper_ == nullptr) {
37             return;
38         }
39         helper_->SetBoolResult(true);
40         helper_->NotifyAll();
41         helper_ = nullptr;
42     } else if (action == CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED) {
43         TELEPHONY_LOGI("receive a Normal Sms");
44         if (helper_ == nullptr) {
45             return;
46         }
47         helper_->SetBoolResult(true);
48         helper_->NotifyAll();
49         helper_ = nullptr;
50     } else if (action == CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED) {
51         TELEPHONY_LOGI("receive a Wap Push");
52         if (helper_ == nullptr) {
53             return;
54         }
55         helper_->SetBoolResult(true);
56         helper_->NotifyAll();
57         helper_ = nullptr;
58     }
59 }
60 } // namespace Telephony
61 } // namespace OHOS
62