1 /* 2 * Copyright (C) 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 #ifndef BLUETOOTH_LOAD_SYSTEM_ABILITY_H 17 #define BLUETOOTH_LOAD_SYSTEM_ABILITY_H 18 19 #include <string> 20 21 #include "iservice_registry.h" 22 #include "system_ability_definition.h" 23 #include "system_ability_status_change_stub.h" 24 25 namespace OHOS { 26 namespace Bluetooth { 27 28 enum SUBSCRIBED_SYSTEM_ABILITY_STATE { 29 STATE_NONE, 30 STATE_SUBSCRIBING, 31 STATE_SUBSCRIBED, 32 }; 33 34 enum NOTIFY_PROFILE_MSG { NOTIFY_MSG_INIT }; 35 36 class BluetootLoadSystemAbility : public SystemAbilityStatusChangeStub { 37 public: 38 /** 39 * @brief Get the Instance of the BluetootLoadSystemAbility. 40 * 41 * @return Returns the Instance of the BluetootLoadSystemAbility. 42 */ 43 static BluetootLoadSystemAbility &GetInstance(); 44 /** 45 * @brief When an external process accesses bluetooth profile, the profile has not yet obtained the proxy. At this 46 * time, it is necessary to subscribe to the status of the start and stop of the Bluetooth process, and then 47 * register the id of the profile, so that it can notify the profile initialization or uninitialization in time 48 * after receiving the start and stop of the Bluetooth. 49 * 50 * @param profileId profile identification. 51 */ 52 void RegisterNotifyMsg(const uint32_t &profileId); 53 /** 54 * @brief Used to query whether the process currently calling the profile interface has subscribed to the start and 55 * stop of the Bluetooth process. 56 * 57 * @return Returns true if has subscribed; 58 * Returns false If it is the first time to access the interface of this profile or is subscribing. 59 */ 60 bool HasSubscribedBluetoothSystemAbility(); 61 /** 62 * @brief If the process accesses the profile interface of the Bluetooth process for the first time, call this 63 * interface to subscribe to the start and stop of the Bluetooth process. 64 * 65 */ 66 void SubScribeBluetoothSystemAbility(); 67 68 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 69 70 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 71 72 private: 73 /** 74 * @brief After receiving the Bluetooth start and stop notification, notify each profile to initialize or 75 * uninitialize in time. 76 * 77 * @param profileId profile identification. 78 */ 79 void NotifyMsgToProfile(NOTIFY_PROFILE_MSG notifyMsg); 80 /** 81 * @brief Notify each registered profile. 82 * 83 * @param notifyMsg NOTIFY_MSG_INIT:the Bluetooth process wakes up and notifies profile initialization; 84 * NOTIFY_MSG_UNINIT:after the Bluetooth process is turned off, notify each profile to uninitialize. 85 * @param profileId profile identification. 86 */ 87 void NotifyProfile(NOTIFY_PROFILE_MSG notifyMsg, const uint32_t &profileId); 88 89 void NotifyA2dpSrcProfile(NOTIFY_PROFILE_MSG notifyMsg); 90 void NotifyA2dpSinkProfile(NOTIFY_PROFILE_MSG notifyMsg); 91 void NotifyHfpAgProfile(NOTIFY_PROFILE_MSG notifyMsg); 92 void NotifyHfpHfProfile(NOTIFY_PROFILE_MSG notifyMsg); 93 void NotifyAvrcpTgProfile(NOTIFY_PROFILE_MSG notifyMsg); 94 void NotifyAvrcpCtProfile(NOTIFY_PROFILE_MSG notifyMsg); 95 96 void NotifyMapClientProfile(NOTIFY_PROFILE_MSG notifyMsg); 97 void NotifyMapServerProfile(NOTIFY_PROFILE_MSG notifyMsg); 98 void NotifyPbapClientProfile(NOTIFY_PROFILE_MSG notifyMsg); 99 void NotifyPbapServerProfile(NOTIFY_PROFILE_MSG notifyMsg); 100 101 void NotifyOppProfile(NOTIFY_PROFILE_MSG notifyMsg); 102 void NotifyHidHostProfile(NOTIFY_PROFILE_MSG notifyMsg); 103 void NotifyPanProfile(NOTIFY_PROFILE_MSG notifyMsg); 104 105 void NotifyAudioProfile(NOTIFY_PROFILE_MSG notifyMsg, const uint32_t &profileId); 106 void NotifyMessageProfile(NOTIFY_PROFILE_MSG notifyMsg, const uint32_t &profileId); 107 void NotifyTransferProfile(NOTIFY_PROFILE_MSG notifyMsg, const uint32_t &profileId); 108 void NotifyHostInit(NOTIFY_PROFILE_MSG notifyMsg); 109 110 /** 111 * @brief Construct a new BluetootLoadSystemAbility object. 112 */ 113 BluetootLoadSystemAbility(); 114 115 /** 116 * @brief Destroy the BluetootLoadSystemAbility object. 117 */ 118 ~BluetootLoadSystemAbility(); 119 120 std::recursive_mutex mutex_{}; 121 std::vector<uint32_t> profileIdList_{}; 122 SUBSCRIBED_SYSTEM_ABILITY_STATE subscribeBluetoothSystemAbilityState = STATE_NONE; 123 }; 124 } // namespace Bluetooth 125 } // namespace OHOS 126 127 #endif // BLUETOOTH_HOST_LOAD_CALLBACK_H