1 /*
2 * Copyright (C) 2021-2022 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 "reject_call_sms.h"
17
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
RejectCallSms()23 RejectCallSms::RejectCallSms() {}
24
IncomingCallHungUp(sptr<CallBase> & callObjectPtr,bool isSendSms,std::string content)25 void RejectCallSms::IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content)
26 {
27 if (callObjectPtr == nullptr || !isSendSms || content.empty() || callObjectPtr->GetAccountNumber().empty()) {
28 TELEPHONY_LOGE("no need to send reject call message");
29 return;
30 }
31 std::string number = callObjectPtr->GetAccountNumber();
32 SendMessage(callObjectPtr->GetSlotId(), ConvertToUtf16(number), ConvertToUtf16(content));
33 }
34
SendMessage(int32_t slotId,const std::u16string & desAddr,const std::u16string & text)35 void RejectCallSms::SendMessage(int32_t slotId, const std::u16string &desAddr, const std::u16string &text)
36 {
37 #ifdef ABILITY_SMS_SUPPORT
38 Singleton<SmsServiceManagerClient>::GetInstance()
39 .SendMessage(slotId, desAddr, ConvertToUtf16(""), text, nullptr, nullptr);
40 TELEPHONY_LOGI("reject call message sended");
41 #endif
42 }
43
ConvertToUtf16(const std::string & str)44 std::u16string RejectCallSms::ConvertToUtf16(const std::string &str)
45 {
46 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
47 return converter.from_bytes(str);
48 }
49
NewCallCreated(sptr<CallBase> & callObjectPtr)50 void RejectCallSms::NewCallCreated(sptr<CallBase> &callObjectPtr) {}
51
CallDestroyed(const DisconnectedDetails & details)52 void RejectCallSms::CallDestroyed(const DisconnectedDetails &details) {}
53
IncomingCallActivated(sptr<CallBase> & callObjectPtr)54 void RejectCallSms::IncomingCallActivated(sptr<CallBase> &callObjectPtr) {}
55
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)56 void RejectCallSms::CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
57 {}
58 } // namespace Telephony
59 } // namespace OHOS