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_stub.h"
17 
18 #include <string_ex.h>
19 
20 #include "call_manager_errors.h"
21 #include "telephony_log_wrapper.h"
22 
23 #include "message_option.h"
24 #include "message_parcel.h"
25 
26 namespace OHOS {
27 namespace Telephony {
SpamCallStub()28 SpamCallStub::SpamCallStub() {}
29 
~SpamCallStub()30 SpamCallStub::~SpamCallStub() {}
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t SpamCallStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
33     MessageOption &option)
34 {
35     std::u16string myDescriptor = SpamCallStub::GetDescriptor();
36     std::u16string remoteDescriptor = data.ReadInterfaceToken();
37     if (myDescriptor != remoteDescriptor) {
38         TELEPHONY_LOGE("descriptor checked fail !");
39         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
40     }
41     TELEPHONY_LOGI("OnReceived, cmd = %{public}u", code);
42     switch (code) {
43         case COMMAND_ON_RESULT:
44             do {
45                 int32_t errCodeVar = data.ReadInt32();
46                 std::string resultVar = Str16ToStr8(data.ReadString16());
47                 OnResult(errCodeVar, resultVar);
48             } while (false);
49             break;
50         default:
51             TELEPHONY_LOGE("callback failed, default = %d", code);
52             break;
53     }
54     return ERR_NONE;
55 }
56 } // namespace Telephony
57 } // namespace OHOS
58