1 /*
2 * Copyright (C) 2022-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 "sms_send_callback_gtest.h"
17
18 #include <iostream>
19
20 #include "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22
23 namespace OHOS {
24 namespace Telephony {
25 static constexpr int SMS_DEFAULT_RESULT = 0;
26 static constexpr int SMS_DEFAULT_ERROR = -1;
27
SmsSendCallbackGTest(SmsMmsTestHelper & helper)28 SmsSendCallbackGTest::SmsSendCallbackGTest(SmsMmsTestHelper &helper)
29 {
30 callbackHelper_ = &helper;
31 }
32
~SmsSendCallbackGTest()33 SmsSendCallbackGTest::~SmsSendCallbackGTest() {}
34
HasDeliveryCallBack(bool hasCallback)35 void SmsSendCallbackGTest::HasDeliveryCallBack(bool hasCallback)
36 {
37 hasDeliveryCallback_ = hasCallback;
38 }
39
OnSmsSendResult(const ISendShortMessageCallback::SmsSendResult result)40 void SmsSendCallbackGTest::OnSmsSendResult(const ISendShortMessageCallback::SmsSendResult result)
41 {
42 TELEPHONY_LOGI("SmsSendCallbackGTest OnSmsSendResult = %{public}d", result);
43 if (callbackHelper_ == nullptr) {
44 TELEPHONY_LOGE("SmsSendCallbackGTest callbackHelper_ is nullptr");
45 return;
46 }
47
48 callbackHelper_->SetSendSmsIntResult(result);
49 if (!hasDeliveryCallback_) {
50 callbackHelper_->NotifyAll();
51 }
52 callbackHelper_ = nullptr;
53 }
54
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)55 int SmsSendCallbackGTest::OnRemoteRequest(
56 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
57 {
58 if (data.ReadInterfaceToken() != GetDescriptor()) {
59 TELEPHONY_LOGE("descriptor checked fail");
60 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
61 }
62
63 switch (code) {
64 case static_cast<int>(SendShortMessageCallbackInterfaceCode::ON_SMS_SEND_RESULT): {
65 int32_t result = data.ReadInt32();
66 OnSmsSendResult(static_cast<ISendShortMessageCallback::SmsSendResult>(result));
67 return SMS_DEFAULT_RESULT;
68 }
69 default: {
70 return SMS_DEFAULT_ERROR;
71 }
72 }
73 }
74 } // namespace Telephony
75 } // namespace OHOS