• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 "bluetooth_pbap_pce_observer_stub.h"
17 #include "bluetooth_log.h"
18 #include "ipc_types.h"
19 #include "string_ex.h"
20 namespace OHOS {
21 namespace Bluetooth {
BluetoothPbapPceObserverStub()22 BluetoothPbapPceObserverStub::BluetoothPbapPceObserverStub()
23 {
24     HILOGD("%{public}s start.", __func__);
25     memberFuncMap_[static_cast<uint32_t>(BluetoothPbapPceObserverStub::Code::PBAP_PCE_ON_SERVICE_CONNECTION_STATE_CHANGED)] =
26         &BluetoothPbapPceObserverStub::OnServiceConnectionStateChangedInner;
27     memberFuncMap_[static_cast<uint32_t>(BluetoothPbapPceObserverStub::Code::PBAP_PCE_ON_SERVICE_PASSWORD_REQUIRED)] =
28         &BluetoothPbapPceObserverStub::OnServicePasswordRequiredInner;
29     memberFuncMap_[static_cast<uint32_t>(BluetoothPbapPceObserverStub::Code::PBAP_PCE_ON_ACTION_COMPLETED)] =
30         &BluetoothPbapPceObserverStub::OnActionCompletedInner;
31 }
32 
~BluetoothPbapPceObserverStub()33 BluetoothPbapPceObserverStub::~BluetoothPbapPceObserverStub()
34 {
35     HILOGD("%{public}s start.", __func__);
36     memberFuncMap_.clear();
37 }
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int BluetoothPbapPceObserverStub::OnRemoteRequest(
39     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
40 {
41     HILOGD("BluetoothPbapPceObserverStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
42     std::u16string descriptor = BluetoothPbapPceObserverStub::GetDescriptor();
43     std::u16string remoteDescriptor = data.ReadInterfaceToken();
44     if (descriptor != remoteDescriptor) {
45         HILOGI("local descriptor is not equal to remote");
46         return ERR_INVALID_STATE;
47     }
48 
49     auto itFunc = memberFuncMap_.find(code);
50     if (itFunc != memberFuncMap_.end()) {
51         auto memberFunc = itFunc->second;
52         if (memberFunc != nullptr) {
53             return (this->*memberFunc)(data, reply);
54         }
55     }
56     HILOGW("BluetoothPbapPceObserverStub::OnRemoteRequest, default case, need check.");
57     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 };
59 
OnServiceConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)60 ErrCode BluetoothPbapPceObserverStub::OnServiceConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
61 {
62     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
63     std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
64     if (!device) {
65         return TRANSACTION_ERR;
66     }
67     int state = data.ReadInt32();
68 
69     OnServiceConnectionStateChanged(*device, state);
70 
71     return NO_ERROR;
72 }
73 
OnServicePasswordRequiredInner(MessageParcel & data,MessageParcel & reply)74 ErrCode BluetoothPbapPceObserverStub::OnServicePasswordRequiredInner(MessageParcel &data, MessageParcel &reply)
75 {
76     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
77     std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
78     if (!device) {
79         return TRANSACTION_ERR;
80     }
81     std::vector<uint8_t>* des = nullptr;
82     if (!data.ReadUInt8Vector(des) || des == nullptr) {
83         HILOGW("BluetoothPbapPceObserverStub::OnServicePasswordRequiredInner: get description failed.");
84         return INVALID_DATA;
85     }
86     const ::std::vector<uint8_t> description = *des;
87     int8_t charset = data.ReadInt8();
88     bool fullAccess = data.ReadBool();
89 
90     OnServicePasswordRequired(*device, description, charset, fullAccess);
91 
92     return NO_ERROR;
93 }
94 
OnActionCompletedInner(MessageParcel & data,MessageParcel & reply)95 ErrCode BluetoothPbapPceObserverStub::OnActionCompletedInner(MessageParcel &data, MessageParcel &reply)
96 {
97     HILOGD("[%{public}s]: %{public}s(): Enter!", __FILE__, __FUNCTION__);
98     std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
99     if (!device) {
100         return TRANSACTION_ERR;
101     }
102     int respCode = data.ReadInt32();
103     int actionType = data.ReadInt32();
104     std::shared_ptr<BluetoothIPbapPhoneBookData> result(data.ReadParcelable<BluetoothIPbapPhoneBookData>());
105     if (!result) {
106         return TRANSACTION_ERR;
107     }
108 
109     OnActionCompleted(*device, respCode, actionType, *result);
110 
111     return NO_ERROR;
112 }
113 }  // namespace Bluetooth
114 }  // namespace OHOS