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_receive_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;
MmsReceiveManager(int32_t slotId)24 MmsReceiveManager::MmsReceiveManager(int32_t slotId) : TelEventHandler("MmsReceiveManager"), slotId_(slotId) {}
25
~MmsReceiveManager()26 MmsReceiveManager::~MmsReceiveManager() {}
27
Init()28 void MmsReceiveManager::Init()
29 {
30 mmsReceiver_ = std::make_shared<MmsReceive>(slotId_);
31 if (mmsReceiver_ == nullptr) {
32 TELEPHONY_LOGE("failed to create mmsReceiver");
33 return;
34 }
35 }
36
DownloadMms(const std::u16string & mmsc,std::u16string & data,const std::u16string & ua,const std::u16string & uaprof)37 int32_t MmsReceiveManager::DownloadMms(
38 const std::u16string &mmsc, std::u16string &data, const std::u16string &ua, const std::u16string &uaprof)
39 {
40 if (mmsReceiver_ == nullptr) {
41 TELEPHONY_LOGE("mmsReceiver_ is nullptr");
42 return TELEPHONY_ERR_LOCAL_PTR_NULL;
43 }
44 std::string dataPdu;
45 int32_t downloadResult = mmsReceiver_->ExecuteDownloadMms(
46 StringUtils::ToUtf8(mmsc), dataPdu, StringUtils::ToUtf8(ua), StringUtils::ToUtf8(uaprof));
47 if (downloadResult == TELEPHONY_ERR_SUCCESS) {
48 data = StringUtils::ToUtf16(dataPdu);
49 TELEPHONY_LOGI("download mms successed");
50 return TELEPHONY_ERR_SUCCESS;
51 } else {
52 TELEPHONY_LOGI("download mms failed");
53 return downloadResult;
54 }
55 }
56 } // namespace Telephony
57 } // namespace OHOS