• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     auto msgManager = DelayedSingleton<SmsServiceManagerClient>::GetInstance();
39     if (msgManager == nullptr) {
40         TELEPHONY_LOGE("short message manager nullptr");
41         return;
42     }
43     msgManager->SendMessage(slotId, desAddr, ConvertToUtf16(""), text, nullptr, nullptr);
44     TELEPHONY_LOGI("reject call message sended");
45 #endif
46 }
47 
ConvertToUtf16(const std::string & str)48 std::u16string RejectCallSms::ConvertToUtf16(const std::string &str)
49 {
50     std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
51     return converter.from_bytes(str);
52 }
53 
NewCallCreated(sptr<CallBase> & callObjectPtr)54 void RejectCallSms::NewCallCreated(sptr<CallBase> &callObjectPtr) {}
55 
CallDestroyed(const DisconnectedDetails & details)56 void RejectCallSms::CallDestroyed(const DisconnectedDetails &details) {}
57 
IncomingCallActivated(sptr<CallBase> & callObjectPtr)58 void RejectCallSms::IncomingCallActivated(sptr<CallBase> &callObjectPtr) {}
59 
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)60 void RejectCallSms::CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
61 {}
62 } // namespace Telephony
63 } // namespace OHOS