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 "mms_send_manager.h"
17
18 #include "string_utils.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
23 using namespace std;
MmsSendManager(const std::shared_ptr<AppExecFwk::EventRunner> & runner,int32_t slotId)24 MmsSendManager::MmsSendManager(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId)
25 : AppExecFwk::EventHandler(runner), slotId_(slotId)
26 {}
27
~MmsSendManager()28 MmsSendManager::~MmsSendManager() {}
29
Init()30 void MmsSendManager::Init()
31 {
32 mmsSender_ = std::make_shared<MmsSender>(slotId_);
33 if (mmsSender_ == nullptr) {
34 TELEPHONY_LOGE("failed to create MmsSender");
35 return;
36 }
37 }
38
SendMms(const std::u16string & mmsc,const std::u16string & data,const std::u16string & ua,const std::u16string & uaprof)39 int32_t MmsSendManager::SendMms(
40 const std::u16string &mmsc, const std::u16string &data, const std::u16string &ua, const std::u16string &uaprof)
41 {
42 if (mmsSender_ == nullptr) {
43 TELEPHONY_LOGE("mmsSender_ is nullptr");
44 return TELEPHONY_ERR_LOCAL_PTR_NULL;
45 }
46
47 int32_t sendResult = mmsSender_->ExecuteSendMms(
48 StringUtils::ToUtf8(mmsc), StringUtils::ToUtf8(data), StringUtils::ToUtf8(ua), StringUtils::ToUtf8(uaprof));
49 if (sendResult == TELEPHONY_ERR_SUCCESS) {
50 TELEPHONY_LOGI("send mms successed");
51 return TELEPHONY_ERR_SUCCESS;
52 } else {
53 TELEPHONY_LOGI("send mms failed");
54 return sendResult;
55 }
56 }
57 } // namespace Telephony
58 } // namespace OHOS