• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-2025 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 #ifndef INTEROPERABLE_DATA_CONTROLLER_H
17 #define INTEROPERABLE_DATA_CONTROLLER_H
18 
19 #include "cJSON.h"
20 #include "call_base.h"
21 #include "i_interoperable_device_state_callback.h"
22 #include "session_adapter.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 constexpr const char* DATA_TYPE = "dataType";
27 constexpr const char* INTEROPERABLE_ITEM_MUTE = "mute";
28 constexpr const char* INTEROPERABLE_ITEM_SLOT = "slotId";
29 constexpr const char* INTEROPERABLE_ITEM_PHONE_NUMBER = "phoneNumber";
30 constexpr const char* INTEROPERABLE_ITEM_CALL_TYPE = "callType";
31 constexpr uint32_t INTEROPERABLE_MAX_RECV_DATA_LEN = 2048;
32 constexpr int32_t DEFAULT_SLOT_ID = 0;
33 constexpr int32_t QOS_BW_BT = 4 * 64 * 1024;    // 小于384*1024才可选路蓝牙,优先wifi,可选蓝牙
34 
35 enum class InteroperableMsgType : int32_t {
36     DATA_TYPE_UNKNOWN = -1,
37     DATA_TYPE_REQUISITES = 0,
38     DATA_TYPE_MUTE_RINGER = 102,
39     DATA_TYPE_MUTE = 104,
40     DATA_TYPE_QUERY_REQUISITES_DATA = 105,
41 };
42 
43 class InteroperableDataController : public IInteroperableDeviceStateCallback, public ISessionCallback {
44 public:
45     InteroperableDataController() = default;
46     ~InteroperableDataController() override = default;
47     void OnReceiveMsg(const char* data, uint32_t dataLen) override;
48     void SetMuted(bool isMute);
49     void MuteRinger();
50     void SendRequisiteDataQueryToPeer(const std::string &phoneNum);
51     void SendRequisiteDataToPeer(int32_t slotId, const std::string &phoneNum);
52     void DeleteBtSlotIdByPhoneNumber(const std::string &phoneNum);
53     void WaitForBtSlotId(const std::string &phoneNum);
54     int32_t GetBtSlotIdByPhoneNumber(const std::string &phoneNum);
55 
56     virtual void OnCallCreated(const sptr<CallBase> &call, const std::string &networkId) = 0;
57     virtual void OnCallDestroyed() = 0;
58     virtual void HandleSpecificMsg(int32_t msgType, const cJSON *msg) = 0;
59     virtual void CallCreated(const sptr<CallBase> &call, const std::string &networkId) = 0;
60 
61 protected:
62     bool GetInt32Value(const cJSON *msg, const std::string &name, int32_t &value);
63     bool GetBoolValue(const cJSON *msg, const std::string &name, bool &value);
64     bool GetStringValue(const cJSON *msg, const std::string &name, std::string &value);
65     std::string CreateQueryRequisitesDataMsg(InteroperableMsgType msgType, const std::string &phoneNum);
66     void ClearBtSlotId();
67 
68     std::shared_ptr<SessionAdapter> session_{nullptr};
69 
70 private:
71     void HandleMuted(const cJSON *msg);
72     void HandleMuteRinger();
73     std::string CreateMuteMsg(InteroperableMsgType msgType, bool isMute);
74     std::string CreateMuteRingerMsg(InteroperableMsgType msgType);
75     void HandleRequisitesData(const cJSON *msg);
76     std::string CreateRequisitesDataMsg(InteroperableMsgType msgType, int32_t slotId,
77         const std::string &phoneNum);
78     void SaveBtSlotId(const std::string &phoneNum, int32_t slotId);
79 
80 private:
81     ffrt::mutex slotIdMutex_{};
82     ffrt::condition_variable slotIdCv_{};
83     std::map<std::string, int32_t> slotIdMap_{};
84 };
85 }
86 }
87 #endif // INTEROPERABLE_DATA_CONTROLLER_H