• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sms_broadcast_subscriber_receiver.h"
17 #include "sms_persist_helper.h"
18 #include "sms_receive_reliability_handler.h"
19 #include "telephony_log_wrapper.h"
20 #include "want.h"
21 #include "event_handler.h"
22 #include "event_runner.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 using namespace EventFwk;
27 
SmsBroadcastSubscriberReceiver(const CommonEventSubscribeInfo & subscriberInfo)28 SmsBroadcastSubscriberReceiver::SmsBroadcastSubscriberReceiver(
29     const CommonEventSubscribeInfo &subscriberInfo) : CommonEventSubscriber(subscriberInfo) {}
30 
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & data)31 void SmsBroadcastSubscriberReceiver::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
32 {
33     auto want = data.GetWant();
34     std::string action = want.GetAction();
35     bool isSms = action == CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED;
36     bool isWapPush = action == CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED;
37     if (isSms || isWapPush) {
38         int refId = want.GetIntParam(SMS_BROADCAST_MSG_REF_ID_KEY, 0);
39         int dataBaseId = want.GetIntParam(SMS_BROADCAST_DATABASE_ID_KEY, 0);
40         TELEPHONY_LOGI("OnReceiveEvent refId =%{public}d, dataBaseId =%{public}d", refId, dataBaseId);
41         std::string address = want.GetStringParam(SMS_BROADCAST_ADDRESS_KEY);
42         if (!address.empty() && isSms) {
43             DelayedSingleton<SmsPersistHelper>::GetInstance()->UpdateContact(address);
44         }
45         std::make_shared<SmsReceiveReliabilityHandler>(0)->DeleteMessageFormDb(refId, dataBaseId);
46     }
47 }
48 } // namespace Telephony
49 } // namespace OHOS