1e5d0e473Sopenharmony_ci/* 2e5d0e473Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 3e5d0e473Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e5d0e473Sopenharmony_ci * you may not use this file except in compliance with the License. 5e5d0e473Sopenharmony_ci * You may obtain a copy of the License at 6e5d0e473Sopenharmony_ci * 7e5d0e473Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e5d0e473Sopenharmony_ci * 9e5d0e473Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e5d0e473Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e5d0e473Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e5d0e473Sopenharmony_ci * See the License for the specific language governing permissions and 13e5d0e473Sopenharmony_ci * limitations under the License. 14e5d0e473Sopenharmony_ci */ 15e5d0e473Sopenharmony_ci 16e5d0e473Sopenharmony_ci#include "sms_broadcast_subscriber.h" 17e5d0e473Sopenharmony_ci 18e5d0e473Sopenharmony_ci#include "common_event_support.h" 19e5d0e473Sopenharmony_ci#include "short_message.h" 20e5d0e473Sopenharmony_ci#include "sms_cb_data.h" 21e5d0e473Sopenharmony_ci#include "string_utils.h" 22e5d0e473Sopenharmony_ci 23e5d0e473Sopenharmony_cinamespace OHOS { 24e5d0e473Sopenharmony_cinamespace Telephony { 25e5d0e473Sopenharmony_ciusing namespace OHOS::EventFwk; 26e5d0e473Sopenharmony_ciSmsBroadcastSubscriber::SmsBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo) 27e5d0e473Sopenharmony_ci : CommonEventSubscriber(subscriberInfo) 28e5d0e473Sopenharmony_ci{} 29e5d0e473Sopenharmony_ci 30e5d0e473Sopenharmony_civoid SmsBroadcastSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) 31e5d0e473Sopenharmony_ci{ 32e5d0e473Sopenharmony_ci std::cout << "CommonEventPublishOrderedEventTest::Subscriber OnReceiveEvent" << std::endl; 33e5d0e473Sopenharmony_ci OHOS::EventFwk::Want want = data.GetWant(); 34e5d0e473Sopenharmony_ci std::string action = data.GetWant().GetAction(); 35e5d0e473Sopenharmony_ci if (action == CommonEventSupport::COMMON_EVENT_SMS_RECEIVE_COMPLETED) { 36e5d0e473Sopenharmony_ci int msgcode = GetCode(); 37e5d0e473Sopenharmony_ci std::string msgdata = GetData(); 38e5d0e473Sopenharmony_ci bool isCdma = want.GetBoolParam("isCdma", false); 39e5d0e473Sopenharmony_ci std::cout << "Sms Receive::OnReceiveEvent msgcode" << msgcode << std::endl; 40e5d0e473Sopenharmony_ci std::cout << "Sms Receive::OnReceiveEvent data = " << msgdata.data() << std::endl; 41e5d0e473Sopenharmony_ci std::cout << "Sms Receive::OnReceiveEvent format Type = " << (isCdma ? "Cdma" : "Gsm") << std::endl; 42e5d0e473Sopenharmony_ci const std::vector<std::string> pdus = want.GetStringArrayParam("pdus"); 43e5d0e473Sopenharmony_ci for (unsigned int index = 0; index < pdus.size(); ++index) { 44e5d0e473Sopenharmony_ci std::vector<unsigned char> pdu = StringUtils::HexToByteVector(pdus[index]); 45e5d0e473Sopenharmony_ci auto message = new ShortMessage(); 46e5d0e473Sopenharmony_ci std::u16string netType = isCdma ? u"3gpp2" : u"3gpp"; 47e5d0e473Sopenharmony_ci ShortMessage::CreateMessage(pdu, netType, *message); 48e5d0e473Sopenharmony_ci if (message != nullptr) { 49e5d0e473Sopenharmony_ci std::string messageBody = StringUtils::ToUtf8(message->GetVisibleMessageBody()); 50e5d0e473Sopenharmony_ci std::cout << "receive new sms = " << messageBody.c_str() << std::endl; 51e5d0e473Sopenharmony_ci delete message; 52e5d0e473Sopenharmony_ci message = nullptr; 53e5d0e473Sopenharmony_ci } else { 54e5d0e473Sopenharmony_ci std::cout << "Sms Receive::OnReceiveEvent pdus = " << pdus[index] << std::endl; 55e5d0e473Sopenharmony_ci } 56e5d0e473Sopenharmony_ci } 57e5d0e473Sopenharmony_ci } else if (action == CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED || 58e5d0e473Sopenharmony_ci action == CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED) { 59e5d0e473Sopenharmony_ci CbMessageTest(want); 60e5d0e473Sopenharmony_ci } else if (action == CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED) { 61e5d0e473Sopenharmony_ci WapPushMessageTest(want); 62e5d0e473Sopenharmony_ci } else { 63e5d0e473Sopenharmony_ci std::cout << "CommonEventPublishOrderedEventTest::Subscriber OnReceiveEvent do nothing" << std::endl; 64e5d0e473Sopenharmony_ci } 65e5d0e473Sopenharmony_ci} 66e5d0e473Sopenharmony_ci 67e5d0e473Sopenharmony_civoid SmsBroadcastSubscriber::CbMessageTest(const OHOS::EventFwk::Want &want) const 68e5d0e473Sopenharmony_ci{ 69e5d0e473Sopenharmony_ci std::cout << SmsCbData::SLOT_ID << ":" << want.GetIntParam(SmsCbData::SLOT_ID, DEFAULT_VALUE) << std::endl; 70e5d0e473Sopenharmony_ci std::cout << SmsCbData::CB_MSG_TYPE << ":" 71e5d0e473Sopenharmony_ci << std::to_string(static_cast<uint8_t>(want.GetByteParam(SmsCbData::CB_MSG_TYPE, DEFAULT_VALUE))) 72e5d0e473Sopenharmony_ci << std::endl; 73e5d0e473Sopenharmony_ci std::cout << SmsCbData::LANG_TYPE << ":" 74e5d0e473Sopenharmony_ci << std::to_string(static_cast<uint8_t>(want.GetByteParam(SmsCbData::LANG_TYPE, DEFAULT_VALUE))) 75e5d0e473Sopenharmony_ci << std::endl; 76e5d0e473Sopenharmony_ci std::cout << SmsCbData::DCS << ":" 77e5d0e473Sopenharmony_ci << std::to_string(static_cast<uint8_t>(want.GetByteParam(SmsCbData::DCS, DEFAULT_VALUE))) 78e5d0e473Sopenharmony_ci << std::endl; 79e5d0e473Sopenharmony_ci std::cout << SmsCbData::PRIORITY << ":" 80e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::PRIORITY, DEFAULT_VALUE)) << std::endl; 81e5d0e473Sopenharmony_ci std::cout << SmsCbData::CMAS_CLASS << ":" 82e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::CMAS_CLASS, DEFAULT_VALUE)) << std::endl; 83e5d0e473Sopenharmony_ci std::cout << SmsCbData::CMAS_CATEGORY << ":" 84e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::CMAS_CATEGORY, DEFAULT_VALUE)) << std::endl; 85e5d0e473Sopenharmony_ci std::cout << SmsCbData::CMAS_RESPONSE << ":" 86e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::CMAS_RESPONSE, DEFAULT_VALUE)) << std::endl; 87e5d0e473Sopenharmony_ci std::cout << SmsCbData::SEVERITY << ":" 88e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::SEVERITY, DEFAULT_VALUE)) << std::endl; 89e5d0e473Sopenharmony_ci std::cout << SmsCbData::URGENCY << ":" << std::to_string(want.GetByteParam(SmsCbData::URGENCY, DEFAULT_VALUE)) 90e5d0e473Sopenharmony_ci << std::endl; 91e5d0e473Sopenharmony_ci std::cout << SmsCbData::CERTAINTY << ":" 92e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::CERTAINTY, DEFAULT_VALUE)) << std::endl; 93e5d0e473Sopenharmony_ci std::cout << SmsCbData::MSG_BODY << ":" << want.GetStringParam(SmsCbData::MSG_BODY) << std::endl; 94e5d0e473Sopenharmony_ci std::cout << SmsCbData::FORMAT << ":" << std::to_string(want.GetByteParam(SmsCbData::FORMAT, DEFAULT_VALUE)) 95e5d0e473Sopenharmony_ci << std::endl; 96e5d0e473Sopenharmony_ci std::cout << SmsCbData::SERIAL_NUM << ":" 97e5d0e473Sopenharmony_ci << want.GetIntParam(SmsCbData::SERIAL_NUM, DEFAULT_VALUE) << std::endl; 98e5d0e473Sopenharmony_ci std::cout << SmsCbData::RECV_TIME << ":" << want.GetStringParam(SmsCbData::RECV_TIME) << std::endl; 99e5d0e473Sopenharmony_ci std::cout << SmsCbData::MSG_ID << ":" 100e5d0e473Sopenharmony_ci << want.GetIntParam(SmsCbData::MSG_ID, DEFAULT_VALUE) << std::endl; 101e5d0e473Sopenharmony_ci std::cout << SmsCbData::SERVICE_CATEGORY << ":" 102e5d0e473Sopenharmony_ci << want.GetIntParam(SmsCbData::SERVICE_CATEGORY, DEFAULT_VALUE) << std::endl; 103e5d0e473Sopenharmony_ci std::cout << SmsCbData::IS_ETWS_PRIMARY << ":" << want.GetBoolParam(SmsCbData::IS_ETWS_PRIMARY, false) 104e5d0e473Sopenharmony_ci << std::endl; 105e5d0e473Sopenharmony_ci std::cout << SmsCbData::IS_CMAS_MESSAGE << ":" << want.GetBoolParam(SmsCbData::IS_CMAS_MESSAGE, false) 106e5d0e473Sopenharmony_ci << std::endl; 107e5d0e473Sopenharmony_ci std::cout << SmsCbData::IS_ETWS_MESSAGE << ":" << want.GetBoolParam(SmsCbData::IS_ETWS_MESSAGE, false) 108e5d0e473Sopenharmony_ci << std::endl; 109e5d0e473Sopenharmony_ci std::cout << SmsCbData::PLMN << ":" << want.GetStringParam(SmsCbData::PLMN) << std::endl; 110e5d0e473Sopenharmony_ci std::cout << SmsCbData::LAC << ":" << want.GetIntParam(SmsCbData::LAC, DEFAULT_VALUE) << std::endl; 111e5d0e473Sopenharmony_ci std::cout << SmsCbData::CID << ":" << want.GetIntParam(SmsCbData::CID, DEFAULT_VALUE) << std::endl; 112e5d0e473Sopenharmony_ci std::cout << SmsCbData::WARNING_TYPE << ":" 113e5d0e473Sopenharmony_ci << want.GetIntParam(SmsCbData::WARNING_TYPE, DEFAULT_VALUE) << std::endl; 114e5d0e473Sopenharmony_ci std::cout << SmsCbData::GEO_SCOPE << ":" 115e5d0e473Sopenharmony_ci << std::to_string(want.GetByteParam(SmsCbData::GEO_SCOPE, DEFAULT_VALUE)) << std::endl; 116e5d0e473Sopenharmony_ci} 117e5d0e473Sopenharmony_ci 118e5d0e473Sopenharmony_civoid SmsBroadcastSubscriber::WapPushMessageTest(const OHOS::EventFwk::Want &want) const 119e5d0e473Sopenharmony_ci{ 120e5d0e473Sopenharmony_ci std::cout << "wap push slotId:" << want.GetIntParam("slotId", 0) << std::endl; 121e5d0e473Sopenharmony_ci std::cout << "wap push pushType:" << want.GetIntParam("pushType", 0) << std::endl; 122e5d0e473Sopenharmony_ci std::cout << "wap push transactionId:" << want.GetIntParam("transactionId", 0) << std::endl; 123e5d0e473Sopenharmony_ci std::cout << "wap push strAppId:" << want.GetStringParam("strAppId") << std::endl; 124e5d0e473Sopenharmony_ci std::cout << "wap push contentType:" << want.GetStringParam("contentType") << std::endl; 125e5d0e473Sopenharmony_ci std::cout << "wap push header:" << want.GetStringParam("headerData") << std::endl; 126e5d0e473Sopenharmony_ci std::cout << "wap push data:" << want.GetStringParam("rawData") << std::endl; 127e5d0e473Sopenharmony_ci} 128e5d0e473Sopenharmony_ci} // namespace Telephony 129e5d0e473Sopenharmony_ci} // namespace OHOS 130