1 /*
2 * Copyright (C) 2024 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 "spam_call_proxy.h"
17
18 #include "message_option.h"
19 #include "message_parcel.h"
20
21 #include "call_manager_errors.h"
22 #include "telephony_log_wrapper.h"
23 #include "callback_stub_helper.h"
24 #include "callback_stub_helper.h"
25 #include <string_ex.h>
26
27 namespace OHOS {
28 namespace Telephony {
SpamCallProxy(const sptr<IRemoteObject> & impl)29 SpamCallProxy::SpamCallProxy(const sptr<IRemoteObject> &impl)
30 : IRemoteProxy<ISpamCall>(impl)
31 {}
32
DetectSpamCall(const std::string & phoneNumber,const int32_t & slotId,std::shared_ptr<SpamCallAdapter> spamCallAdapter)33 int32_t SpamCallProxy::DetectSpamCall(const std::string &phoneNumber, const int32_t &slotId,
34 std::shared_ptr<SpamCallAdapter> spamCallAdapter)
35 {
36 MessageParcel dataParcel;
37 std::u16string myDescriptor = SpamCallProxy::GetDescriptor();
38 if (!dataParcel.WriteInterfaceToken(myDescriptor)) {
39 TELEPHONY_LOGE("Write descriptor fail");
40 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
41 }
42 auto instance = new (std::nothrow) CallbackStubHelper(spamCallAdapter);
43 if (instance == nullptr) {
44 TELEPHONY_LOGE("CallbackStubHelper is null!");
45 return TELEPHONY_ERR_LOCAL_PTR_NULL;
46 }
47 if (!dataParcel.WriteString16(Str8ToStr16(phoneNumber))) {
48 TELEPHONY_LOGE("WriteString16 failed");
49 }
50 if (!dataParcel.WriteInt32(slotId)) {
51 TELEPHONY_LOGE("WriteInt32 failed");
52 }
53 if (!dataParcel.WriteRemoteObject(instance)) {
54 TELEPHONY_LOGE("WriteRemoteObject failed");
55 }
56 MessageParcel replyParcel;
57 auto remote = Remote();
58 if (remote == nullptr) {
59 TELEPHONY_LOGE("Remote() return nullptr!");
60 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
61 }
62 MessageOption option;
63 int32_t ret = remote->SendRequest(COMMAND_DETECT_SPAM_CALL, dataParcel, replyParcel, option);
64 if (ret != TELEPHONY_SUCCESS) {
65 TELEPHONY_LOGE("DetectSpamCall:%{public}d errCode:%{public}d", COMMAND_DETECT_SPAM_CALL, ret);
66 return ret;
67 }
68 return replyParcel.ReadInt32();
69 }
70 } // namespace Telephony
71 } // namespace OHOS
72