已合并
add permission #601
liuqian创建于 6月3日
add permission #601
已合并
liuqian创建于 6月3日
已删除 :OpenHarmony-6.1-Release合入到openharmony/communication_bluetooth_serviceOpenHarmony-6.1-Release
58 个文件变更+1987-2946
Mservices/bluetooth/ipc/include/bluetooth_a2dp_sink_stub.h+17-15
@@ -19,6 +19,7 @@
19#include <map>19#include <map>
20#include "iremote_stub.h"20#include "iremote_stub.h"
21#include "i_bluetooth_a2dp_sink.h"21#include "i_bluetooth_a2dp_sink.h"
22+#include "permission_item.h"
22 23 
23namespace OHOS {24namespace OHOS {
24namespace Bluetooth {25namespace Bluetooth {
@@ -27,24 +28,25 @@ public:
27 BluetoothA2dpSinkStub();28 BluetoothA2dpSinkStub();
28 virtual ~BluetoothA2dpSinkStub();29 virtual ~BluetoothA2dpSinkStub();
29 30 
30- virtual int OnRemoteRequest(31+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
31- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;32+ 
33+ using A2dpSinkStubFunc = std::function<int32_t(BluetoothA2dpSinkStub *, MessageParcel &, MessageParcel &)>;
34+ using A2dpSinkStubFuncPerm = std::pair<A2dpSinkStubFunc, std::shared_ptr<PermissionItem>>;
32 35 
33private:36private:
34- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);37+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
35- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);38+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);39+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);40+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);41+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetPlayingStateInner(MessageParcel &data, MessageParcel &reply);43+ int32_t GetPlayingStateInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);44+ int32_t SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);45+ int32_t GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode SendDelayInner(MessageParcel &data, MessageParcel &reply);46+ int32_t SendDelayInner(MessageParcel &data, MessageParcel &reply);
44- 
45- using BluetoothA2dpSinkServerFunc = ErrCode (BluetoothA2dpSinkStub::*)(MessageParcel &data, MessageParcel &reply);
46- std::map<uint32_t, BluetoothA2dpSinkServerFunc> memberFuncMap_;
47 47 
48+private:
49+ static const std::map<uint32_t, A2dpSinkStubFuncPerm> memberFuncMap_;
48 DISALLOW_COPY_AND_MOVE(BluetoothA2dpSinkStub);50 DISALLOW_COPY_AND_MOVE(BluetoothA2dpSinkStub);
49};51};
50} // namespace Bluetooth52} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_a2dp_src_stub.h+34-31
@@ -19,6 +19,7 @@
19#include <map>19#include <map>
20#include "iremote_stub.h"20#include "iremote_stub.h"
21#include "i_bluetooth_a2dp_src.h"21#include "i_bluetooth_a2dp_src.h"
22+#include "permission_item.h"
22 23 
23namespace OHOS {24namespace OHOS {
24namespace Bluetooth {25namespace Bluetooth {
@@ -27,42 +28,44 @@ public:
27 BluetoothA2dpSrcStub();28 BluetoothA2dpSrcStub();
28 virtual ~BluetoothA2dpSrcStub();29 virtual ~BluetoothA2dpSrcStub();
29 30 
30- virtual int OnRemoteRequest(31+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
31- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;32+ 
33+ using A2dpSrcStubFunc = std::function<int32_t(BluetoothA2dpSrcStub *, MessageParcel &, MessageParcel &)>;
34+ using A2dpSrcStubFuncPerm = std::pair<A2dpSrcStubFunc, std::shared_ptr<PermissionItem>>;
32 35 
33private:36private:
34- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);37+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
35- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);38+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);39+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);40+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);41+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetPlayingStateInner(MessageParcel &data, MessageParcel &reply);43+ int32_t GetPlayingStateInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);44+ int32_t SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);45+ int32_t GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode SetActiveSinkDeviceInner(MessageParcel &data, MessageParcel &reply);46+ int32_t SetActiveSinkDeviceInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode GetActiveSinkDeviceInner(MessageParcel &data, MessageParcel &reply);47+ int32_t GetActiveSinkDeviceInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode GetCodecStatusInner(MessageParcel &data, MessageParcel &reply);48+ int32_t GetCodecStatusInner(MessageParcel &data, MessageParcel &reply);
46 ErrCode GetCodecPreferenceInner(MessageParcel &data, MessageParcel &reply);49 ErrCode GetCodecPreferenceInner(MessageParcel &data, MessageParcel &reply);
47 ErrCode SetCodecPreferenceInner(MessageParcel &data, MessageParcel &reply);50 ErrCode SetCodecPreferenceInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode SwitchOptionalCodecsInner(MessageParcel &data, MessageParcel &reply);51+ int32_t SwitchOptionalCodecsInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode GetOptionalCodecsSupportStateInner(MessageParcel &data, MessageParcel &reply);52+ int32_t GetOptionalCodecsSupportStateInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode StartPlayingInner(MessageParcel &data, MessageParcel &reply);53+ int32_t StartPlayingInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode SuspendPlayingInner(MessageParcel &data, MessageParcel &reply);54+ int32_t SuspendPlayingInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode StopPlayingInner(MessageParcel &data, MessageParcel &reply);55+ int32_t StopPlayingInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode WriteFrameInner(MessageParcel &data, MessageParcel &reply);56+ int32_t WriteFrameInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode GetRenderPositionInner(MessageParcel &data, MessageParcel &reply);57+ int32_t GetRenderPositionInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode OffloadStartPlayingInner(MessageParcel &data, MessageParcel &reply);58+ int32_t OffloadStartPlayingInner(MessageParcel &data, MessageParcel &reply);
56- ErrCode OffloadStopPlayingInner(MessageParcel &data, MessageParcel &reply);59+ int32_t OffloadStopPlayingInner(MessageParcel &data, MessageParcel &reply);
57- ErrCode A2dpOffloadSessionPathRequestInner(MessageParcel &data, MessageParcel &reply);60+ int32_t A2dpOffloadSessionPathRequestInner(MessageParcel &data, MessageParcel &reply);
58- ErrCode GetOffloadCodecStatusInner(MessageParcel &data, MessageParcel &reply);61+ int32_t GetOffloadCodecStatusInner(MessageParcel &data, MessageParcel &reply);
59- ErrCode EnableAutoPlayInner(MessageParcel &data, MessageParcel &reply);62+ int32_t EnableAutoPlayInner(MessageParcel &data, MessageParcel &reply);
60- ErrCode DisableAutoPlayInner(MessageParcel &data, MessageParcel &reply);63+ int32_t DisableAutoPlayInner(MessageParcel &data, MessageParcel &reply);
61- ErrCode GetAutoPlayDisabledDurationInner(MessageParcel &data, MessageParcel &reply);64+ int32_t GetAutoPlayDisabledDurationInner(MessageParcel &data, MessageParcel &reply);
62- ErrCode GetVirtualDeviceListInner(MessageParcel &data, MessageParcel &reply);65+ int32_t GetVirtualDeviceListInner(MessageParcel &data, MessageParcel &reply);
63 66 
64- using BluetoothA2dpSrcServerFunc = ErrCode (BluetoothA2dpSrcStub::*)(MessageParcel &data, MessageParcel &reply);67+private:
65- std::map<uint32_t, BluetoothA2dpSrcServerFunc> memberFuncMap_;68+ static const std::map<uint32_t, A2dpSrcStubFuncPerm> memberFuncMap_;
66 69 
67 DISALLOW_COPY_AND_MOVE(BluetoothA2dpSrcStub);70 DISALLOW_COPY_AND_MOVE(BluetoothA2dpSrcStub);
68};71};
Mservices/bluetooth/ipc/include/bluetooth_avrcp_ct_stub.h+36-34
@@ -21,6 +21,7 @@
21#include "iremote_stub.h"21#include "iremote_stub.h"
22#include "i_bluetooth_host.h"22#include "i_bluetooth_host.h"
23#include "i_bluetooth_avrcp_ct.h"23#include "i_bluetooth_avrcp_ct.h"
24+#include "permission_item.h"
24 25 
25namespace OHOS {26namespace OHOS {
26namespace Bluetooth {27namespace Bluetooth {
@@ -29,46 +30,47 @@ public:
29 BluetoothAvrcpCtStub();30 BluetoothAvrcpCtStub();
30 virtual ~BluetoothAvrcpCtStub();31 virtual ~BluetoothAvrcpCtStub();
31 32 
32- virtual int OnRemoteRequest(33+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
33- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;34+ using AvrcpCtStubFunc = std::function<int32_t(BluetoothAvrcpCtStub *, MessageParcel &, MessageParcel &)>;
35+ using AvrcpCtStubFuncPerm = std::pair<AvrcpCtStubFunc, std::shared_ptr<PermissionItem>>;
34 36 
35private:37private:
36- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);38+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode UnregisterObserverInner(MessageParcel &data, MessageParcel &reply);39+ int32_t UnregisterObserverInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply);40+ int32_t GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);41+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);43+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);44+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode PressButtonnner(MessageParcel &data, MessageParcel &reply);45+ int32_t PressButtonnner(MessageParcel &data, MessageParcel &reply);
44- ErrCode ReleaseButtonInner(MessageParcel &data, MessageParcel &reply);46+ int32_t ReleaseButtonInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode GetUnitInfoInner(MessageParcel &data, MessageParcel &reply);47+ int32_t GetUnitInfoInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode GetSubUnitInfoInner(MessageParcel &data, MessageParcel &reply);48+ int32_t GetSubUnitInfoInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode GetSupportedCompaniesInner(MessageParcel &data, MessageParcel &reply);49+ int32_t GetSupportedCompaniesInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode GetSupportedEventsInner(MessageParcel &data, MessageParcel &reply);50+ int32_t GetSupportedEventsInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode GetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply);51+ int32_t GetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode GetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply);52+ int32_t GetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode GetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply);53+ int32_t GetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode SetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply);54+ int32_t SetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode GetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply);55+ int32_t GetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode GetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply);56+ int32_t GetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode GetElementAttributesInner(MessageParcel &data, MessageParcel &reply);57+ int32_t GetElementAttributesInner(MessageParcel &data, MessageParcel &reply);
56- ErrCode GetPlayStatusInner(MessageParcel &data, MessageParcel &reply);58+ int32_t GetPlayStatusInner(MessageParcel &data, MessageParcel &reply);
57- ErrCode PlayItemInner(MessageParcel &data, MessageParcel &reply);59+ int32_t PlayItemInner(MessageParcel &data, MessageParcel &reply);
58- ErrCode GetFolderItemsInner(MessageParcel &data, MessageParcel &reply);60+ int32_t GetFolderItemsInner(MessageParcel &data, MessageParcel &reply);
59- ErrCode GetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply);61+ int32_t GetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply);
60- ErrCode SetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply);62+ int32_t SetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply);
61- ErrCode EnableNotificationInner(MessageParcel &data, MessageParcel &reply);63+ int32_t EnableNotificationInner(MessageParcel &data, MessageParcel &reply);
62- ErrCode DisableNotificationInner(MessageParcel &data, MessageParcel &reply);64+ int32_t DisableNotificationInner(MessageParcel &data, MessageParcel &reply);
63- ErrCode GetItemAttributesInner(MessageParcel &data, MessageParcel &reply);65+ int32_t GetItemAttributesInner(MessageParcel &data, MessageParcel &reply);
64- ErrCode SetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply);66+ int32_t SetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply);
65- ErrCode GetMeidaPlayerListInner(MessageParcel &data, MessageParcel &reply);67+ int32_t GetMeidaPlayerListInner(MessageParcel &data, MessageParcel &reply);
66 68 
67 bool IsInvalidAttributesSize(int32_t attributesSize);69 bool IsInvalidAttributesSize(int32_t attributesSize);
68 bool IsInvalidDeviceStatesSize(int32_t statesSize);70 bool IsInvalidDeviceStatesSize(int32_t statesSize);
69 71 
70- using BluetoothAvrcpCtStubFunc = ErrCode (BluetoothAvrcpCtStub::*)(MessageParcel &data, MessageParcel &reply);72+private:
71- std::map<uint32_t, BluetoothAvrcpCtStubFunc> memberFuncMap_;73+ static const std::map<uint32_t, AvrcpCtStubFuncPerm> memberFuncMap_;
72 74 
73 DISALLOW_COPY_AND_MOVE(BluetoothAvrcpCtStub);75 DISALLOW_COPY_AND_MOVE(BluetoothAvrcpCtStub);
74};76};
Mservices/bluetooth/ipc/include/bluetooth_avrcp_tg_stub.h+28-26
@@ -20,6 +20,7 @@
20 20 
21#include "iremote_stub.h"21#include "iremote_stub.h"
22#include "i_bluetooth_avrcp_tg.h"22#include "i_bluetooth_avrcp_tg.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -28,38 +29,39 @@ public:
28 BluetoothAvrcpTgStub();29 BluetoothAvrcpTgStub();
29 virtual ~BluetoothAvrcpTgStub();30 virtual ~BluetoothAvrcpTgStub();
30 31 
31- ErrCode OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
32- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using AvrcpTgStubFunc = std::function<int32_t(BluetoothAvrcpTgStub *, MessageParcel &, MessageParcel &)>;
34+ using AvrcpTgStubFuncPerm = std::pair<AvrcpTgStubFunc, std::shared_ptr<PermissionItem>>;
33 35 
34private:36private:
35- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);37+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode UnregisterObserverInner(MessageParcel &data, MessageParcel &reply);38+ int32_t UnregisterObserverInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);39+ int32_t SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);40+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);41+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);43+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);44+ int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode NotifyPlaybackStatusChangedInner(MessageParcel &data, MessageParcel &reply);45+ int32_t NotifyPlaybackStatusChangedInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode NotifyTrackChangedInner(MessageParcel &data, MessageParcel &reply);46+ int32_t NotifyTrackChangedInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode NotifyTrackReachedEndInner(MessageParcel &data, MessageParcel &reply);47+ int32_t NotifyTrackReachedEndInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode NotifyTrackReachedStartInner(MessageParcel &data, MessageParcel &reply);48+ int32_t NotifyTrackReachedStartInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode NotifyPlaybackPosChangedInner(MessageParcel &data, MessageParcel &reply);49+ int32_t NotifyPlaybackPosChangedInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode NotifyPlayerAppSettingChangedInner(MessageParcel &data, MessageParcel &reply);50+ int32_t NotifyPlayerAppSettingChangedInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode NotifyNowPlayingContentChangedInner(MessageParcel &data, MessageParcel &reply);51+ int32_t NotifyNowPlayingContentChangedInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode NotifyAvailablePlayersChangedInner(MessageParcel &data, MessageParcel &reply);52+ int32_t NotifyAvailablePlayersChangedInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode NotifyAddressedPlayerChangedInner(MessageParcel &data, MessageParcel &reply);53+ int32_t NotifyAddressedPlayerChangedInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode NotifyUidChangedInner(MessageParcel &data, MessageParcel &reply);54+ int32_t NotifyUidChangedInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode NotifyVolumeChangedInner(MessageParcel &data, MessageParcel &reply);55+ int32_t NotifyVolumeChangedInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode SetDeviceAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply);56+ int32_t SetDeviceAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode SetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply);57+ int32_t SetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply);
56- ErrCode GetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply);58+ int32_t GetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply);
57 59 
58 bool IsInvalidAttributesSize(int32_t attributesSize);60 bool IsInvalidAttributesSize(int32_t attributesSize);
59 bool IsInvalidDeviceStatesSize(int32_t statesSize);61 bool IsInvalidDeviceStatesSize(int32_t statesSize);
60 62 
61- using BluetoothHostFunc = ErrCode (BluetoothAvrcpTgStub::*)(MessageParcel &data, MessageParcel &reply);63+private:
62- std::map<uint32_t, BluetoothHostFunc> memberFuncMap_;64+ static const std::map<uint32_t, AvrcpTgStubFuncPerm> memberFuncMap_;
63 DISALLOW_COPY_AND_MOVE(BluetoothAvrcpTgStub);65 DISALLOW_COPY_AND_MOVE(BluetoothAvrcpTgStub);
64};66};
65} // namespace Bluetooth67} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_ble_advertiser_stub.h+20-16
@@ -20,6 +20,7 @@
20 20 
21#include "i_bluetooth_ble_advertiser.h"21#include "i_bluetooth_ble_advertiser.h"
22#include "iremote_stub.h"22#include "iremote_stub.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -27,26 +28,29 @@ class BluetoothBleAdvertiserStub : public IRemoteStub<IBluetoothBleAdvertiser> {
27public:28public:
28 BluetoothBleAdvertiserStub();29 BluetoothBleAdvertiserStub();
29 ~BluetoothBleAdvertiserStub() override;30 ~BluetoothBleAdvertiserStub() override;
30- DISALLOW_COPY_AND_MOVE(BluetoothBleAdvertiserStub);
31 31 
32- virtual int OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
33- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using BleAdvertiserStubFunc =
34+ std::function<int32_t(BluetoothBleAdvertiserStub *, MessageParcel &, MessageParcel &)>;
35+ 
36+ using BleAdvertiserStubFuncPerm = std::pair<BleAdvertiserStubFunc, std::shared_ptr<PermissionItem>>;
37+ using BleAdvertiserStubFuncMap = std::map<uint32_t, BleAdvertiserStubFuncPerm>;
34 38 
35private:39private:
36- static const std::map<uint32_t,40+ int32_t RegisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply);
37- std::function<ErrCode(BluetoothBleAdvertiserStub *, MessageParcel &, MessageParcel &)>>41+ int32_t DeregisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply);
38- interfaces_;42+ int32_t StartAdvertisingInner(MessageParcel &data, MessageParcel &reply);
43+ int32_t EnableAdvertisingInner(MessageParcel &data, MessageParcel &reply);
44+ int32_t DisableAdvertisingInner(MessageParcel &data, MessageParcel &reply);
45+ int32_t StopAdvertisingInner(MessageParcel &data, MessageParcel &reply);
46+ int32_t CloseInner(MessageParcel &data, MessageParcel &reply);
47+ int32_t GetAdvertiserHandleInner(MessageParcel &data, MessageParcel &reply);
48+ int32_t SetAdvertisingDataInner(MessageParcel &data, MessageParcel &reply);
49+ int32_t ChangeAdvertisingParamsInner(MessageParcel &data, MessageParcel &reply);
39 50 
40- ErrCode RegisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply);51+private:
41- ErrCode DeregisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply);52+ static const BleAdvertiserStubFuncMap memberFuncMap_;
42- ErrCode StartAdvertisingInner(MessageParcel &data, MessageParcel &reply);53+ DISALLOW_COPY_AND_MOVE(BluetoothBleAdvertiserStub);
43- ErrCode EnableAdvertisingInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode DisableAdvertisingInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode StopAdvertisingInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode CloseInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode GetAdvertiserHandleInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode SetAdvertisingDataInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode ChangeAdvertisingParamsInner(MessageParcel &data, MessageParcel &reply);
50};54};
51} // namespace Bluetooth55} // namespace Bluetooth
52} // namespace OHOS56} // namespace OHOS
Mservices/bluetooth/ipc/include/bluetooth_ble_central_manager_stub.h+27-23
@@ -20,6 +20,7 @@
20 20 
21#include "i_bluetooth_ble_central_manager.h"21#include "i_bluetooth_ble_central_manager.h"
22#include "iremote_stub.h"22#include "iremote_stub.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -27,33 +28,36 @@ class BluetoothBleCentralManagerStub : public IRemoteStub<IBluetoothBleCentralMa
27public:28public:
28 BluetoothBleCentralManagerStub();29 BluetoothBleCentralManagerStub();
29 ~BluetoothBleCentralManagerStub() override;30 ~BluetoothBleCentralManagerStub() override;
30- DISALLOW_COPY_AND_MOVE(BluetoothBleCentralManagerStub);
31 31 
32- virtual int OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
33- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ 
34+ using BleCentralManagerStubFunc =
35+ std::function<int32_t(BluetoothBleCentralManagerStub *, MessageParcel &, MessageParcel &)>;
36+ using BleCentralManagerStubFuncPerm = std::pair<BleCentralManagerStubFunc, std::shared_ptr<PermissionItem>>;
37+ using BleCentralManagerStubFuncMap = std::map<uint32_t, BleCentralManagerStubFuncPerm>;
34 38 
35private:39private:
36- static const std::map<uint32_t,40+ int32_t RegisterBleCentralManagerCallbackInner(MessageParcel &data, MessageParcel &reply);
37- std::function<ErrCode(BluetoothBleCentralManagerStub *, MessageParcel &, MessageParcel &)>>41+ int32_t DeregisterBleCentralManagerCallbackInner(MessageParcel &data, MessageParcel &reply);
38- interfaces_;42+ int32_t StartScanInner(MessageParcel &data, MessageParcel &reply);
43+ int32_t StopScanInner(MessageParcel &data, MessageParcel &reply);
44+ int32_t RemoveScanFilterInner(MessageParcel &data, MessageParcel &reply);
45+ int32_t FreezeByRssInner(MessageParcel &data, MessageParcel &reply);
46+ int32_t ResetAllProxyInner(MessageParcel &data, MessageParcel &reply);
47+ int32_t SetLpDeviceAdvParamInner(MessageParcel &data, MessageParcel &reply);
48+ int32_t SetScanReportChannelToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
49+ int32_t EnableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
50+ int32_t DisableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
51+ int32_t SendParamsToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
52+ int32_t IsLpDeviceAvailableInner(MessageParcel &data, MessageParcel &reply);
53+ int32_t SetLpDeviceParamInner(MessageParcel &data, MessageParcel &reply);
54+ int32_t RemoveLpDeviceParamInner(MessageParcel &data, MessageParcel &reply);
55+ int32_t ChangeScanParamsInner(MessageParcel &data, MessageParcel &reply);
56+ int32_t IsValidScannerIdInner(MessageParcel &data, MessageParcel &reply);
39 57 
40- ErrCode RegisterBleCentralManagerCallbackInner(MessageParcel &data, MessageParcel &reply);58+private:
41- ErrCode DeregisterBleCentralManagerCallbackInner(MessageParcel &data, MessageParcel &reply);59+ static const BleCentralManagerStubFuncMap memberFuncMap_;
42- ErrCode StartScanInner(MessageParcel &data, MessageParcel &reply);60+ DISALLOW_COPY_AND_MOVE(BluetoothBleCentralManagerStub);
43- ErrCode StopScanInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode RemoveScanFilterInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode FreezeByRssInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode ResetAllProxyInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode SetLpDeviceAdvParamInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode SetScanReportChannelToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode EnableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode DisableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode SendParamsToLpDeviceInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode IsLpDeviceAvailableInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode SetLpDeviceParamInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode RemoveLpDeviceParamInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode ChangeScanParamsInner(MessageParcel &data, MessageParcel &reply);
56- ErrCode IsValidScannerIdInner(MessageParcel &data, MessageParcel &reply);
57};61};
58} // namespace Bluetooth62} // namespace Bluetooth
59} // namespace OHOS63} // namespace OHOS
Mservices/bluetooth/ipc/include/bluetooth_gatt_client_stub.h+26-25
@@ -20,6 +20,7 @@
20 20 
21#include "iremote_stub.h"21#include "iremote_stub.h"
22#include "i_bluetooth_gatt_client.h"22#include "i_bluetooth_gatt_client.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -28,33 +29,33 @@ public:
28 BluetoothGattClientStub();29 BluetoothGattClientStub();
29 virtual ~BluetoothGattClientStub();30 virtual ~BluetoothGattClientStub();
30 31 
31- virtual int OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
32- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using GattClientStubFunc = std::function<int32_t(BluetoothGattClientStub *, MessageParcel &, MessageParcel &)>;
34+ using GattClientStubFuncPerm = std::pair<GattClientStubFunc, std::shared_ptr<PermissionItem>>;
35+private:
36+ int32_t RegisterApplicationInner(MessageParcel &data, MessageParcel &reply);
37+ int32_t DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply);
38+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
39+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
40+ int32_t DiscoveryServicesInner(MessageParcel &data, MessageParcel &reply);
41+ int32_t ReadCharacteristicInner(MessageParcel &data, MessageParcel &reply);
42+ int32_t WriteCharacteristicInner(MessageParcel &data, MessageParcel &reply);
43+ int32_t SignedWriteCharacteristicInner(MessageParcel &data, MessageParcel &reply);
44+ int32_t ReadDescriptorInner(MessageParcel &data, MessageParcel &reply);
45+ int32_t WriteDescriptorInner(MessageParcel &data, MessageParcel &reply);
46+ int32_t RequestExchangeMtuInner(MessageParcel &data, MessageParcel &reply);
47+ int32_t GetAllDeviceInner(MessageParcel &data, MessageParcel &reply);
48+ int32_t RequestConnectionPriorityInner(MessageParcel &data, MessageParcel &reply);
49+ int32_t GetServicesInner(MessageParcel &data, MessageParcel &reply);
50+ int32_t RequestFastestConnInner(MessageParcel &data, MessageParcel &reply);
51+ int32_t ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply);
52+ int32_t RequestNotificationInner(MessageParcel &data, MessageParcel &reply);
53+ int32_t GetConnectedStateInner(MessageParcel &data, MessageParcel &reply);
54+ int32_t SetPhyInner(MessageParcel &data, MessageParcel &reply);
55+ int32_t ReadPhyInner(MessageParcel &data, MessageParcel &reply);
33 56 
34private:57private:
35- ErrCode RegisterApplicationInner(MessageParcel &data, MessageParcel &reply);58+ static const std::map<uint32_t, GattClientStubFuncPerm> memberFuncMap_;
36- ErrCode DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode DiscoveryServicesInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode ReadCharacteristicInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode WriteCharacteristicInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode SignedWriteCharacteristicInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode ReadDescriptorInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode WriteDescriptorInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode RequestExchangeMtuInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode GetAllDeviceInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode RequestConnectionPriorityInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode GetServicesInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode RequestFastestConnInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode RequestNotificationInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode GetConnectedStateInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode SetPhyInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode ReadPhyInner(MessageParcel &data, MessageParcel &reply);
55- 
56- using BluetoothHostFunc = ErrCode (BluetoothGattClientStub::*)(MessageParcel &data, MessageParcel &reply);
57- std::map<uint32_t, BluetoothHostFunc> memberFuncMap_;
58 DISALLOW_COPY_AND_MOVE(BluetoothGattClientStub);59 DISALLOW_COPY_AND_MOVE(BluetoothGattClientStub);
59};60};
60} // namespace Bluetooth61} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_gatt_server_stub.h+21-20
@@ -21,6 +21,7 @@
21#include "iremote_stub.h"21#include "iremote_stub.h"
22#include "i_bluetooth_host.h"22#include "i_bluetooth_host.h"
23#include "i_bluetooth_gatt_server.h"23#include "i_bluetooth_gatt_server.h"
24+#include "permission_item.h"
24 25 
25namespace OHOS {26namespace OHOS {
26namespace Bluetooth {27namespace Bluetooth {
@@ -29,28 +30,28 @@ public:
29 BluetoothGattServerStub();30 BluetoothGattServerStub();
30 virtual ~BluetoothGattServerStub();31 virtual ~BluetoothGattServerStub();
31 32 
32- virtual int OnRemoteRequest(33+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
33- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;34+ using GattServerStubFunc = std::function<int32_t(BluetoothGattServerStub *, MessageParcel &, MessageParcel &)>;
35+ using GattServerStubFuncPerm = std::pair<GattServerStubFunc, std::shared_ptr<PermissionItem>>;
36+private:
37+ int32_t AddServiceInner(MessageParcel &data, MessageParcel &reply);
38+ int32_t ClearServicesInner(MessageParcel &data, MessageParcel &reply);
39+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
40+ int32_t CancelConnectionInner(MessageParcel &data, MessageParcel &reply);
41+ int32_t RegisterApplicationInner(MessageParcel &data, MessageParcel &reply);
42+ int32_t DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply);
43+ int32_t NotifyClientInner(MessageParcel &data, MessageParcel &reply);
44+ int32_t RemoveServiceInner(MessageParcel &data, MessageParcel &reply);
45+ int32_t RespondCharacteristicReadInner(MessageParcel &data, MessageParcel &reply);
46+ int32_t RespondCharacteristicWriteInner(MessageParcel &data, MessageParcel &reply);
47+ int32_t RespondDescriptorReadInner(MessageParcel &data, MessageParcel &reply);
48+ int32_t RespondDescriptorWriteInner(MessageParcel &data, MessageParcel &reply);
49+ int32_t GetConnectedStateInner(MessageParcel &data, MessageParcel &reply);
50+ int32_t SetPhyInner(MessageParcel &data, MessageParcel &reply);
51+ int32_t ReadPhyInner(MessageParcel &data, MessageParcel &reply);
34 52 
35private:53private:
36- ErrCode AddServiceInner(MessageParcel &data, MessageParcel &reply);54+ static const std::map<uint32_t, GattServerStubFuncPerm> memberFuncMap_;
37- ErrCode ClearServicesInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode CancelConnectionInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode RegisterApplicationInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode NotifyClientInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode RemoveServiceInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode RespondCharacteristicReadInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode RespondCharacteristicWriteInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode RespondDescriptorReadInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode RespondDescriptorWriteInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode GetConnectedStateInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode SetPhyInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode ReadPhyInner(MessageParcel &data, MessageParcel &reply);
51- using BluetoothGattServerFunc = ErrCode (BluetoothGattServerStub::*)(MessageParcel &data, MessageParcel &reply);
52- std::map<uint32_t, BluetoothGattServerFunc> memberFuncMap_;
53- 
54 DISALLOW_COPY_AND_MOVE(BluetoothGattServerStub);55 DISALLOW_COPY_AND_MOVE(BluetoothGattServerStub);
55};56};
56} // namespace Bluetooth57} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_hfp_ag_stub.h+26-25
@@ -18,6 +18,7 @@
18#include <map>18#include <map>
19#include "iremote_stub.h"19#include "iremote_stub.h"
20#include "i_bluetooth_hfp_ag.h"20#include "i_bluetooth_hfp_ag.h"
21+#include "permission_item.h"
21 22 
22namespace OHOS {23namespace OHOS {
23namespace Bluetooth {24namespace Bluetooth {
@@ -26,46 +27,46 @@ public:
26 BluetoothHfpAgStub();27 BluetoothHfpAgStub();
27 ~BluetoothHfpAgStub();28 ~BluetoothHfpAgStub();
28 29 
29- virtual int OnRemoteRequest(30+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
30- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;31+ using HfpAgStubFunc = std::function<int32_t(BluetoothHfpAgStub *, MessageParcel &, MessageParcel &)>;
32+ using HfpAgStubFuncPerm = std::pair<HfpAgStubFunc, std::shared_ptr<PermissionItem>>;
31 33 
32private:34private:
33 void RegisterBasicConnectionFunctions();35 void RegisterBasicConnectionFunctions();
34 void RegisterScoConnectionFunctions();36 void RegisterScoConnectionFunctions();
35 int32_t GetConnectDevicesInner(MessageParcel &data, MessageParcel &reply);37 int32_t GetConnectDevicesInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);38+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
37 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);39 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
38 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);40 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
39 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);41 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetScoStateInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetScoStateInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode ConnectScoInner(MessageParcel &data, MessageParcel &reply);43+ int32_t ConnectScoInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode DisconnectScoInner(MessageParcel &data, MessageParcel &reply);44+ int32_t DisconnectScoInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode PhoneStateChangedInner(MessageParcel &data, MessageParcel &reply);45+ int32_t PhoneStateChangedInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode ClccResponseInner(MessageParcel &data, MessageParcel &reply);46+ int32_t ClccResponseInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);47+ int32_t OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);48+ int32_t CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode IsAudioConnectedInner(MessageParcel &data, MessageParcel &reply);49+ int32_t IsAudioConnectedInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);50+ int32_t SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode GetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);51+ int32_t GetActiveDeviceInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode IntoMockInner(MessageParcel &data, MessageParcel &reply);52+ int32_t IntoMockInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode SendNoCarrierInner(MessageParcel &data, MessageParcel &reply);53+ int32_t SendNoCarrierInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);54+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);55+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);56+ int32_t SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);57+ int32_t GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
56 int32_t IsInbandRingingEnabledInner(MessageParcel &data, MessageParcel &reply);58 int32_t IsInbandRingingEnabledInner(MessageParcel &data, MessageParcel &reply);
57- ErrCode ConnectScoInnerEx(MessageParcel &data, MessageParcel &reply);59+ int32_t ConnectScoInnerEx(MessageParcel &data, MessageParcel &reply);
58- ErrCode DisconnectScoInnerEx(MessageParcel &data, MessageParcel &reply);60+ int32_t DisconnectScoInnerEx(MessageParcel &data, MessageParcel &reply);
59 int32_t CallDetailsChangedInner(MessageParcel &data, MessageParcel &reply);61 int32_t CallDetailsChangedInner(MessageParcel &data, MessageParcel &reply);
60 int32_t IsHfpFeatureSupportedInner(MessageParcel &data, MessageParcel &reply);62 int32_t IsHfpFeatureSupportedInner(MessageParcel &data, MessageParcel &reply);
61- ErrCode EnableBtCallLogInner(MessageParcel &data, MessageParcel &reply);63+ int32_t EnableBtCallLogInner(MessageParcel &data, MessageParcel &reply);
62 int32_t GetVirtualDeviceListInner(MessageParcel &data, MessageParcel &reply);64 int32_t GetVirtualDeviceListInner(MessageParcel &data, MessageParcel &reply);
63 int32_t UpdateVirtualDeviceInner(MessageParcel &data, MessageParcel &reply);65 int32_t UpdateVirtualDeviceInner(MessageParcel &data, MessageParcel &reply);
64 int32_t GetCurrentCallTypeInner(MessageParcel &data, MessageParcel &reply);66 int32_t GetCurrentCallTypeInner(MessageParcel &data, MessageParcel &reply);
65 67 
66- using BluetoothHfpAgFunc = ErrCode (BluetoothHfpAgStub::*)(MessageParcel &data, MessageParcel &reply);68+private:
67- std::map<uint32_t, BluetoothHfpAgFunc> memberFuncMap_;69+ static const std::map<uint32_t, HfpAgStubFuncPerm> memberFuncMap_;
68- 
69 DISALLOW_COPY_AND_MOVE(BluetoothHfpAgStub);70 DISALLOW_COPY_AND_MOVE(BluetoothHfpAgStub);
70};71};
71 72 
Mservices/bluetooth/ipc/include/bluetooth_hfp_hf_stub.h+30-30
@@ -18,6 +18,7 @@
18#include <map>18#include <map>
19#include "iremote_stub.h"19#include "iremote_stub.h"
20#include "i_bluetooth_hfp_hf.h"20#include "i_bluetooth_hfp_hf.h"
21+#include "permission_item.h"
21 22 
22namespace OHOS {23namespace OHOS {
23namespace Bluetooth {24namespace Bluetooth {
@@ -28,41 +29,40 @@ public:
28 BluetoothHfpHfStub();29 BluetoothHfpHfStub();
29 ~BluetoothHfpHfStub();30 ~BluetoothHfpHfStub();
30 31 
31- virtual int OnRemoteRequest(32+ int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
32- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using HfpHfStubFunc = std::function<int32_t(BluetoothHfpHfStub *, MessageParcel &, MessageParcel &)>;
34+ using HfpHfStubFuncPerm = std::pair<HfpHfStubFunc, std::shared_ptr<PermissionItem>>;
33 35 
34private:36private:
35 37 
36- ErrCode ConnectScoInner(MessageParcel &data, MessageParcel &reply);38+ int32_t ConnectScoInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode DisconnectScoInner(MessageParcel &data, MessageParcel &reply);39+ int32_t DisconnectScoInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);40+ int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);41+ int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetScoStateInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetScoStateInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode SendDTMFToneInner(MessageParcel &data, MessageParcel &reply);43+ int32_t SendDTMFToneInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);44+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode DisconnectInner(MessageParcel &data, MessageParcel &reply);45+ int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);46+ int32_t OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);47+ int32_t CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode GetCurrentCallListInner(MessageParcel &data, MessageParcel &reply);48+ int32_t GetCurrentCallListInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode AcceptIncomingCallInner(MessageParcel &data, MessageParcel &reply);49+ int32_t AcceptIncomingCallInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode HoldActiveCallInner(MessageParcel &data, MessageParcel &reply);50+ int32_t HoldActiveCallInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode RejectIncomingCallInner(MessageParcel &data, MessageParcel &reply);51+ int32_t RejectIncomingCallInner(MessageParcel &data, MessageParcel &reply);
50- ErrCode SendKeyPressedInner(MessageParcel &data, MessageParcel &reply);52+ int32_t SendKeyPressedInner(MessageParcel &data, MessageParcel &reply);
51- ErrCode HandleIncomingCallInner(MessageParcel &data, MessageParcel &reply);53+ int32_t HandleIncomingCallInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode HandleMultiCallInner(MessageParcel &data, MessageParcel &reply);54+ int32_t HandleMultiCallInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode DialLastNumberInner(MessageParcel &data, MessageParcel &reply);55+ int32_t DialLastNumberInner(MessageParcel &data, MessageParcel &reply);
54- ErrCode DialMemoryInner(MessageParcel &data, MessageParcel &reply);56+ int32_t DialMemoryInner(MessageParcel &data, MessageParcel &reply);
55- ErrCode SendVoiceTagInner(MessageParcel &data, MessageParcel &reply);57+ int32_t SendVoiceTagInner(MessageParcel &data, MessageParcel &reply);
56- ErrCode FinishActiveCallInner(MessageParcel &data, MessageParcel &reply);58+ int32_t FinishActiveCallInner(MessageParcel &data, MessageParcel &reply);
57- ErrCode StartDialInner(MessageParcel &data, MessageParcel &reply);59+ int32_t StartDialInner(MessageParcel &data, MessageParcel &reply);
58- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);60+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
59- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);61+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
60- 
61- using BluetoothHfpHfFunc = ErrCode (BluetoothHfpHfStub::*)(MessageParcel &data, MessageParcel &reply);
62- std::map<uint32_t, BluetoothHfpHfFunc> memberFuncMap_;
63 62 
63+private:
64+ static const std::map<uint32_t, HfpHfStubFuncPerm> memberFuncMap_;
64 DISALLOW_COPY_AND_MOVE(BluetoothHfpHfStub);65 DISALLOW_COPY_AND_MOVE(BluetoothHfpHfStub);
65- 
66};66};
67 67 
68} // namespace Bluetooth68} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_hid_device_stub.h+6-7
@@ -18,6 +18,7 @@
18#include <map>18#include <map>
19#include <iremote_stub.h>19#include <iremote_stub.h>
20#include "i_bluetooth_hid_device.h"20#include "i_bluetooth_hid_device.h"
21+#include "permission_item.h"
21 22 
22namespace OHOS {23namespace OHOS {
23namespace Bluetooth {24namespace Bluetooth {
@@ -26,11 +27,9 @@ public:
26 BluetoothHidDeviceStub();27 BluetoothHidDeviceStub();
27 ~BluetoothHidDeviceStub();28 ~BluetoothHidDeviceStub();
28 29 
29- virtual int OnRemoteRequest(30+ int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
30- uint32_t code,31+ using HidDeviceStubFunc = std::function<int32_t(BluetoothHidDeviceStub *, MessageParcel &, MessageParcel &)>;
31- MessageParcel& data,32+ using HidDeviceStubFuncPerm = std::pair<HidDeviceStubFunc, std::shared_ptr<PermissionItem>>;
32- MessageParcel& reply,
33- MessageOption& option) override;
34private:33private:
35 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);34 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
36 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);35 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
@@ -46,8 +45,8 @@ private:
46 int32_t HidDeviceSetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);45 int32_t HidDeviceSetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
47 int32_t HidDeviceGetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);46 int32_t HidDeviceGetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
48 47 
49- using BluetoothHidDeviceFunc = ErrCode (BluetoothHidDeviceStub::*)(MessageParcel &data, MessageParcel &reply);48+private:
50- std::map<uint32_t, BluetoothHidDeviceFunc> memberFuncMap_;49+ static const std::map<uint32_t, HidDeviceStubFuncPerm> memberFuncMap_;
51 DISALLOW_COPY_AND_MOVE(BluetoothHidDeviceStub);50 DISALLOW_COPY_AND_MOVE(BluetoothHidDeviceStub);
52};51};
53} // Bluetooth52} // Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_hid_host_stub.h+14-15
@@ -18,6 +18,7 @@
18#include <map>18#include <map>
19#include <iremote_stub.h>19#include <iremote_stub.h>
20#include "i_bluetooth_hid_host.h"20#include "i_bluetooth_hid_host.h"
21+#include "permission_item.h"
21 22 
22namespace OHOS {23namespace OHOS {
23namespace Bluetooth {24namespace Bluetooth {
@@ -27,28 +28,26 @@ public:
27 BluetoothHidHostStub();28 BluetoothHidHostStub();
28 ~BluetoothHidHostStub();29 ~BluetoothHidHostStub();
29 30 
30- virtual int OnRemoteRequest(31+ int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
31- uint32_t code,32+ using HidHostStubFunc = std::function<int32_t(BluetoothHidHostStub *, MessageParcel &, MessageParcel &)>;
32- MessageParcel& data,33+ using HidHostStubFuncPerm = std::pair<HidHostStubFunc, std::shared_ptr<PermissionItem>>;
33- MessageParcel& reply,
34- MessageOption& option) override;
35 34 
36private:35private:
37 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);36 int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
38 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);37 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
39 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);38 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
40 int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);39 int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);40+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
42- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);41+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode HidHostVCUnplugInner(MessageParcel &data, MessageParcel &reply);42+ int32_t HidHostVCUnplugInner(MessageParcel &data, MessageParcel &reply);
44- ErrCode HidHostSendDataInner(MessageParcel &data, MessageParcel &reply);43+ int32_t HidHostSendDataInner(MessageParcel &data, MessageParcel &reply);
45- ErrCode HidHostSetReportInner(MessageParcel &data, MessageParcel &reply);44+ int32_t HidHostSetReportInner(MessageParcel &data, MessageParcel &reply);
46- ErrCode HidHostGetReportInner(MessageParcel &data, MessageParcel &reply);45+ int32_t HidHostGetReportInner(MessageParcel &data, MessageParcel &reply);
47- ErrCode HidHostSetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);46+ int32_t HidHostSetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode HidHostGetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);47+ int32_t HidHostGetConnectStrategyInner(MessageParcel &data, MessageParcel &reply);
49 48 
50- using BluetoothHidHostFunc = ErrCode (BluetoothHidHostStub::*)(MessageParcel &data, MessageParcel &reply);49+private:
51- std::map<uint32_t, BluetoothHidHostFunc> memberFuncMap_;50+ static const std::map<uint32_t, HidHostStubFuncPerm> memberFuncMap_;
52 DISALLOW_COPY_AND_MOVE(BluetoothHidHostStub);51 DISALLOW_COPY_AND_MOVE(BluetoothHidHostStub);
53};52};
54} // Bluetooth53} // Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_host_stub.h+53-50
@@ -20,6 +20,7 @@
20 20 
21#include "i_bluetooth_host.h"21#include "i_bluetooth_host.h"
22#include "iremote_stub.h"22#include "iremote_stub.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -28,80 +29,81 @@ public:
28 BluetoothHostStub();29 BluetoothHostStub();
29 virtual ~BluetoothHostStub();30 virtual ~BluetoothHostStub();
30 31 
31- virtual int OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
32- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using BluetoothHostStubFunc = std::function<int32_t(BluetoothHostStub *, MessageParcel &, MessageParcel &)>;
34+ using BluetoothHostStubFuncPerm = std::pair<BluetoothHostStubFunc, std::shared_ptr<PermissionItem>>;
33 35 
34private:36private:
35- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);37+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);38+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode EnableBtInner(MessageParcel &data, MessageParcel &reply);39+ int32_t EnableBtInner(MessageParcel &data, MessageParcel &reply);
38 int32_t DisableBtInner(MessageParcel &data, MessageParcel &reply);40 int32_t DisableBtInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode SatelliteControlInner(MessageParcel &data, MessageParcel &reply);41+ int32_t SatelliteControlInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode GetProfileInner(MessageParcel &data, MessageParcel &reply);42+ int32_t GetProfileInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode GetBleRemoteInner(MessageParcel &data, MessageParcel &reply);43+ int32_t GetBleRemoteInner(MessageParcel &data, MessageParcel &reply);
42 int32_t BluetoothFactoryResetInner(MessageParcel &data, MessageParcel &reply);44 int32_t BluetoothFactoryResetInner(MessageParcel &data, MessageParcel &reply);
43- ErrCode GetBtStateInner(MessageParcel &data, MessageParcel &reply);45+ int32_t GetBtStateInner(MessageParcel &data, MessageParcel &reply);
44 int32_t GetLocalAddressInner(MessageParcel &data, MessageParcel &reply);46 int32_t GetLocalAddressInner(MessageParcel &data, MessageParcel &reply);
45 int32_t GenerateLocalOobDataInner(MessageParcel &data, MessageParcel &reply);47 int32_t GenerateLocalOobDataInner(MessageParcel &data, MessageParcel &reply);
46 int32_t DisableBleInner(MessageParcel &data, MessageParcel &reply);48 int32_t DisableBleInner(MessageParcel &data, MessageParcel &reply);
47 int32_t EnableBleInner(MessageParcel &data, MessageParcel &reply);49 int32_t EnableBleInner(MessageParcel &data, MessageParcel &reply);
48- ErrCode GetProfileListInner(MessageParcel &data, MessageParcel &reply);50+ int32_t GetProfileListInner(MessageParcel &data, MessageParcel &reply);
49- ErrCode GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply);51+ int32_t GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply);
50 int32_t GetBtConnectionStateInner(MessageParcel &data, MessageParcel &reply);52 int32_t GetBtConnectionStateInner(MessageParcel &data, MessageParcel &reply);
51 int32_t GetBtProfileConnStateInner(MessageParcel &data, MessageParcel &reply);53 int32_t GetBtProfileConnStateInner(MessageParcel &data, MessageParcel &reply);
52- ErrCode GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply);54+ int32_t GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply);
53- ErrCode SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply);55+ int32_t SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply);
54 int32_t GetLocalNameInner(MessageParcel &data, MessageParcel &reply);56 int32_t GetLocalNameInner(MessageParcel &data, MessageParcel &reply);
55 int32_t SetLocalNameInner(MessageParcel &data, MessageParcel &reply);57 int32_t SetLocalNameInner(MessageParcel &data, MessageParcel &reply);
56 int32_t GetBtScanModeInner(MessageParcel &data, MessageParcel &reply);58 int32_t GetBtScanModeInner(MessageParcel &data, MessageParcel &reply);
57 int32_t SetBtScanModeInner(MessageParcel &data, MessageParcel &reply);59 int32_t SetBtScanModeInner(MessageParcel &data, MessageParcel &reply);
58- ErrCode GetBondableModeInner(MessageParcel &data, MessageParcel &reply);60+ int32_t GetBondableModeInner(MessageParcel &data, MessageParcel &reply);
59- ErrCode SetBondableModeInner(MessageParcel &data, MessageParcel &reply);61+ int32_t SetBondableModeInner(MessageParcel &data, MessageParcel &reply);
60 int32_t StartBtDiscoveryInner(MessageParcel &data, MessageParcel &reply);62 int32_t StartBtDiscoveryInner(MessageParcel &data, MessageParcel &reply);
61 int32_t CancelBtDiscoveryInner(MessageParcel &data, MessageParcel &reply);63 int32_t CancelBtDiscoveryInner(MessageParcel &data, MessageParcel &reply);
62- ErrCode IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply);64+ int32_t IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply);
63- ErrCode GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply);65+ int32_t GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply);
64 int32_t GetPairedDevicesInner(MessageParcel &data, MessageParcel &reply);66 int32_t GetPairedDevicesInner(MessageParcel &data, MessageParcel &reply);
65 int32_t RemovePairInner(MessageParcel &data, MessageParcel &reply);67 int32_t RemovePairInner(MessageParcel &data, MessageParcel &reply);
66- ErrCode RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply);68+ int32_t RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply);
67- ErrCode RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply);69+ int32_t RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply);
68- ErrCode DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply);70+ int32_t DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply);
69- ErrCode GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply);71+ int32_t GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply);
70 int32_t GetConnectedBLEDevicesInner(MessageParcel &data, MessageParcel &reply);72 int32_t GetConnectedBLEDevicesInner(MessageParcel &data, MessageParcel &reply);
71- ErrCode GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply);73+ int32_t GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply);
72- ErrCode GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply);74+ int32_t GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply);
73- ErrCode SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply);75+ int32_t SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply);
74- ErrCode GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply);76+ int32_t GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply);
75- ErrCode SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply);77+ int32_t SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply);
76- ErrCode GetPowerModeInner(MessageParcel &data, MessageParcel &reply);78+ int32_t GetPowerModeInner(MessageParcel &data, MessageParcel &reply);
77 int32_t GetDeviceNameInner(MessageParcel &data, MessageParcel &reply);79 int32_t GetDeviceNameInner(MessageParcel &data, MessageParcel &reply);
78- ErrCode GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply);80+ int32_t GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply);
79- ErrCode SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply);81+ int32_t SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply);
80 int32_t GetRemoteDeviceBatteryInfoInner(MessageParcel &data, MessageParcel &reply);82 int32_t GetRemoteDeviceBatteryInfoInner(MessageParcel &data, MessageParcel &reply);
81 int32_t SetRemoteDeviceBatteryInfoInner(MessageParcel &data, MessageParcel &reply);83 int32_t SetRemoteDeviceBatteryInfoInner(MessageParcel &data, MessageParcel &reply);
82- ErrCode GetPairStateInner(MessageParcel &data, MessageParcel &reply);84+ int32_t GetPairStateInner(MessageParcel &data, MessageParcel &reply);
83 int32_t StartPairInner(MessageParcel &data, MessageParcel &reply);85 int32_t StartPairInner(MessageParcel &data, MessageParcel &reply);
84- ErrCode CancelPairingInner(MessageParcel &data, MessageParcel &reply);86+ int32_t CancelPairingInner(MessageParcel &data, MessageParcel &reply);
85- ErrCode IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply);87+ int32_t IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply);
86- ErrCode IsAclConnectedInner(MessageParcel &data, MessageParcel &reply);88+ int32_t IsAclConnectedInner(MessageParcel &data, MessageParcel &reply);
87- ErrCode IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply);89+ int32_t IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply);
88 int32_t GetDeviceClassInner(MessageParcel &data, MessageParcel &reply);90 int32_t GetDeviceClassInner(MessageParcel &data, MessageParcel &reply);
89- ErrCode SetDevicePinInner(MessageParcel &data, MessageParcel &reply);91+ int32_t SetDevicePinInner(MessageParcel &data, MessageParcel &reply);
90 int32_t SetDevicePairingConfirmationInner(MessageParcel &data, MessageParcel &reply);92 int32_t SetDevicePairingConfirmationInner(MessageParcel &data, MessageParcel &reply);
91- ErrCode SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply);93+ int32_t SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply);
92- ErrCode PairRequestReplyInner(MessageParcel &data, MessageParcel &reply);94+ int32_t PairRequestReplyInner(MessageParcel &data, MessageParcel &reply);
93- ErrCode ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply);95+ int32_t ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply);
94- ErrCode GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply);96+ int32_t GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply);
95- ErrCode GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply);97+ int32_t GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply);
96- ErrCode GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply);98+ int32_t GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply);
97 int32_t SetFastScanInner(MessageParcel &data, MessageParcel &reply);99 int32_t SetFastScanInner(MessageParcel &data, MessageParcel &reply);
98- ErrCode RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply);100+ int32_t RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply);
99- ErrCode DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply);101+ int32_t DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply);
100- ErrCode RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply);102+ int32_t RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply);
101- ErrCode DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply);103+ int32_t DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply);
102- ErrCode GetRandomAddressInner(MessageParcel &data, MessageParcel &reply);104+ int32_t GetRandomAddressInner(MessageParcel &data, MessageParcel &reply);
103- ErrCode SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply);105+ int32_t SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply);
104- ErrCode StartCrediblePairInner(MessageParcel &data, MessageParcel &reply);106+ int32_t StartCrediblePairInner(MessageParcel &data, MessageParcel &reply);
105 int32_t ConnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply);107 int32_t ConnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply);
106 int32_t DisconnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply);108 int32_t DisconnectAllowedProfilesInner(MessageParcel &data, MessageParcel &reply);
107 int32_t SetDeviceCustomTypeInner(MessageParcel &data, MessageParcel &reply);109 int32_t SetDeviceCustomTypeInner(MessageParcel &data, MessageParcel &reply);
@@ -126,8 +128,9 @@ private:
126 int32_t StartRemoteSdpSearchInner(MessageParcel &data, MessageParcel &reply);128 int32_t StartRemoteSdpSearchInner(MessageParcel &data, MessageParcel &reply);
127 int32_t GetRemoteServicesInner(MessageParcel &data, MessageParcel &reply);129 int32_t GetRemoteServicesInner(MessageParcel &data, MessageParcel &reply);
128 int32_t SetConnectionPriorityInner(MessageParcel &data, MessageParcel &reply);130 int32_t SetConnectionPriorityInner(MessageParcel &data, MessageParcel &reply);
129- static const std::map<uint32_t, std::function<ErrCode(BluetoothHostStub *, MessageParcel &, MessageParcel &)>>131+ 
130- memberFuncMap_;132+private:
133+ static const std::map<uint32_t, BluetoothHostStubFuncPerm> memberFuncMap_;
131 134 
132 DISALLOW_COPY_AND_MOVE(BluetoothHostStub);135 DISALLOW_COPY_AND_MOVE(BluetoothHostStub);
133};136};
Mservices/bluetooth/ipc/include/bluetooth_pan_stub.h+8-9
@@ -18,6 +18,7 @@
18#include <map>18#include <map>
19#include <iremote_stub.h>19#include <iremote_stub.h>
20#include "i_bluetooth_pan.h"20#include "i_bluetooth_pan.h"
21+#include "permission_item.h"
21 22 
22namespace OHOS {23namespace OHOS {
23namespace Bluetooth {24namespace Bluetooth {
@@ -26,23 +27,21 @@ public:
26 BluetoothPanStub();27 BluetoothPanStub();
27 ~BluetoothPanStub();28 ~BluetoothPanStub();
28 29 
29- virtual int OnRemoteRequest(30+ int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
30- uint32_t code,31+ using BluetoothPanStubFunc = std::function<int32_t(BluetoothPanStub *, MessageParcel &, MessageParcel &)>;
31- MessageParcel& data,32+ using BluetoothPanStubFuncPerm = std::pair<BluetoothPanStub, std::shared_ptr<PermissionItem>>;
32- MessageParcel& reply,
33- MessageOption& option) override;
34 33 
35private:34private:
36 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);35 int32_t DisconnectInner(MessageParcel &data, MessageParcel &reply);
37 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);36 int32_t GetDeviceStateInner(MessageParcel &data, MessageParcel &reply);
38 int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);37 int32_t GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode RegisterObserverInner(MessageParcel &data, MessageParcel &reply);38+ int32_t RegisterObserverInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);39+ int32_t DeregisterObserverInner(MessageParcel &data, MessageParcel &reply);
41 int32_t SetTetheringInner(MessageParcel &data, MessageParcel &reply);40 int32_t SetTetheringInner(MessageParcel &data, MessageParcel &reply);
42 int32_t IsTetheringOnInner(MessageParcel &data, MessageParcel &reply);41 int32_t IsTetheringOnInner(MessageParcel &data, MessageParcel &reply);
43 42 
44- using BluetoothPanFunc = ErrCode (BluetoothPanStub::*)(MessageParcel &data, MessageParcel &reply);43+private:
45- std::map<uint32_t, BluetoothPanFunc> memberFuncMap_;44+ static const std::map<uint32_t, BluetoothPanStubFuncPerm> memberFuncMap_;
46 DISALLOW_COPY_AND_MOVE(BluetoothPanStub);45 DISALLOW_COPY_AND_MOVE(BluetoothPanStub);
47};46};
48} // namespace Bluetooth47} // namespace Bluetooth
Mservices/bluetooth/ipc/include/bluetooth_socket_stub.h+13-12
@@ -20,6 +20,7 @@
20 20 
21#include "iremote_stub.h"21#include "iremote_stub.h"
22#include "i_bluetooth_socket.h"22#include "i_bluetooth_socket.h"
23+#include "permission_item.h"
23 24 
24namespace OHOS {25namespace OHOS {
25namespace Bluetooth {26namespace Bluetooth {
@@ -28,21 +29,21 @@ public:
28 BluetoothSocketStub();29 BluetoothSocketStub();
29 ~BluetoothSocketStub();30 ~BluetoothSocketStub();
30 31 
31- virtual int32_t OnRemoteRequest(32+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
32- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;33+ using SocketStubFunc = std::function<int32_t(BluetoothSocketStub *, MessageParcel &, MessageParcel &)>;
34+ using SocketStubFuncPerm = std::pair<SocketStubFunc, std::shared_ptr<PermissionItem>>;
33 35 
34private:36private:
35- ErrCode ConnectInner(MessageParcel &data, MessageParcel &reply);37+ int32_t ConnectInner(MessageParcel &data, MessageParcel &reply);
36- ErrCode ListenInner(MessageParcel &data, MessageParcel &reply);38+ int32_t ListenInner(MessageParcel &data, MessageParcel &reply);
37- ErrCode DeregisterServerObserverInner(MessageParcel &data, MessageParcel &reply);39+ int32_t DeregisterServerObserverInner(MessageParcel &data, MessageParcel &reply);
38- ErrCode RegisterClientObserverInner(MessageParcel &data, MessageParcel &reply);40+ int32_t RegisterClientObserverInner(MessageParcel &data, MessageParcel &reply);
39- ErrCode DeregisterClientObserverInner(MessageParcel &data, MessageParcel &reply);41+ int32_t DeregisterClientObserverInner(MessageParcel &data, MessageParcel &reply);
40- ErrCode UpdateCocConnectionParamsInner(MessageParcel &data, MessageParcel &reply);42+ int32_t UpdateCocConnectionParamsInner(MessageParcel &data, MessageParcel &reply);
41- ErrCode IsAllowSocketConnectInner(MessageParcel &data, MessageParcel &reply);43+ int32_t IsAllowSocketConnectInner(MessageParcel &data, MessageParcel &reply);
42- 
43- using BluetoothSocketFunc = ErrCode (BluetoothSocketStub::*)(MessageParcel &data, MessageParcel &reply);
44- std::map<uint32_t, BluetoothSocketFunc> memberFuncMap_;
45 44 
45+private:
46+ static const std::map<uint32_t, SocketStubFuncPerm> memberFuncMap_;
46 DISALLOW_COPY_AND_MOVE(BluetoothSocketStub);47 DISALLOW_COPY_AND_MOVE(BluetoothSocketStub);
47};48};
48} // namespace Bluetooth49} // namespace Bluetooth
Mservices/bluetooth/ipc/src/bluetooth_a2dp_sink_stub.cpp+39-51
@@ -18,62 +18,50 @@
18#include "ipc_types.h"18#include "ipc_types.h"
19#include "parcel_bt_uuid.h"19#include "parcel_bt_uuid.h"
20#include "raw_address.h"20#include "raw_address.h"
21+#include "permission_manager.h"
22+ 
23+#ifdef STUB_FUNC
24+#undef STUB_FUNC
25+#endif
26+#define STUB_FUNC(code, func, perm) BluetoothA2dpSinkInterfaceCode::code, {&BluetoothA2dpSinkStub::func, perm}
21 27 
22namespace OHOS {28namespace OHOS {
23namespace Bluetooth {29namespace Bluetooth {
24using namespace OHOS::bluetooth;30using namespace OHOS::bluetooth;
25const int32_t A2DP_MAX_SNK_CONNECTION_NUMS = 0x07;31const int32_t A2DP_MAX_SNK_CONNECTION_NUMS = 0x07;
32+ 
33+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
34+const std::map<uint32_t, BluetoothA2dpSinkStub::A2dpSinkStubFuncPerm> BluetoothA2dpSinkStub::memberFuncMap_ = {
35+ {STUB_FUNC(BT_A2DP_SINK_CONNECT, ConnectInner,
36+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
37+ {STUB_FUNC(BT_A2DP_SINK_DISCONNECT, DisconnectInner,
38+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
39+ {STUB_FUNC(BT_A2DP_SINK_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
40+ {STUB_FUNC(BT_A2DP_SINK_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
41+ {STUB_FUNC(BT_A2DP_SINK_GET_DEVICE_BY_STATES, GetDevicesByStatesInner, nullptr)},
42+ {STUB_FUNC(BT_A2DP_SINK_GET_DEVICE_STATE, GetDeviceStateInner, nullptr)},
43+ {STUB_FUNC(BT_A2DP_SINK_GET_PLAYING_STATE, GetPlayingStateInner, nullptr)},
44+ {STUB_FUNC(BT_A2DP_SINK_SET_CONNECT_STRATEGY, SetConnectStrategyInner,
45+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
46+ {STUB_FUNC(BT_A2DP_SINK_GET_CONNECT_STRATEGY, GetConnectStrategyInner,
47+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48+ {STUB_FUNC(BT_A2DP_SINK_SEND_DELAY, SendDelayInner,
49+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
50+};
51+ 
26BluetoothA2dpSinkStub::BluetoothA2dpSinkStub()52BluetoothA2dpSinkStub::BluetoothA2dpSinkStub()
27-{53+{}
28- HILOGD("%{public}s start.", __func__);
29- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_CONNECT)] =
30- nullptr;
31- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_DISCONNECT)] =
32- &BluetoothA2dpSinkStub::DisconnectInner;
33- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_REGISTER_OBSERVER)] =
34- &BluetoothA2dpSinkStub::RegisterObserverInner;
35- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_DEREGISTER_OBSERVER)] =
36- &BluetoothA2dpSinkStub::DeregisterObserverInner;
37- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_GET_DEVICE_BY_STATES)] =
38- &BluetoothA2dpSinkStub::GetDevicesByStatesInner;
39- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_GET_DEVICE_STATE)] =
40- &BluetoothA2dpSinkStub::GetDeviceStateInner;
41- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_GET_PLAYING_STATE)] =
42- &BluetoothA2dpSinkStub::GetPlayingStateInner;
43- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_SET_CONNECT_STRATEGY)] =
44- &BluetoothA2dpSinkStub::SetConnectStrategyInner;
45- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_GET_CONNECT_STRATEGY)] =
46- &BluetoothA2dpSinkStub::GetConnectStrategyInner;
47- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSinkInterfaceCode::BT_A2DP_SINK_SEND_DELAY)] =
48- &BluetoothA2dpSinkStub::SendDelayInner;
49-}
50 54 
51BluetoothA2dpSinkStub::~BluetoothA2dpSinkStub()55BluetoothA2dpSinkStub::~BluetoothA2dpSinkStub()
52-{56+{}
53- HILOGD("%{public}s start.", __func__);
54- memberFuncMap_.clear();
55-}
56 57 
57int BluetoothA2dpSinkStub::OnRemoteRequest(58int BluetoothA2dpSinkStub::OnRemoteRequest(
58 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)59 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
59{60{
60- HILOGI("BluetoothA2dpSinkStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());61+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothA2dpSinkStub);
61- if (BluetoothA2dpSinkStub::GetDescriptor() != data.ReadInterfaceToken()) {
62- HILOGI("local descriptor is not equal to remote");
63- return ERR_INVALID_STATE;
64- }
65- auto itFunc = memberFuncMap_.find(code);
66- if (itFunc != memberFuncMap_.end()) {
67- auto memberFunc = itFunc->second;
68- if (memberFunc != nullptr) {
69- return (this->*memberFunc)(data, reply);
70- }
71- }
72- HILOGW("BluetoothA2dpSinkStub::OnRemoteRequest, default case, need check.");
73- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
74}62}
75 63 
76-ErrCode BluetoothA2dpSinkStub::ConnectInner(MessageParcel &data, MessageParcel &reply)64+int32_t BluetoothA2dpSinkStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
77{65{
78 std::string addr = data.ReadString();66 std::string addr = data.ReadString();
79 67 
@@ -88,7 +76,7 @@ ErrCode BluetoothA2dpSinkStub::ConnectInner(MessageParcel &data, MessageParcel &
88 return NO_ERROR;76 return NO_ERROR;
89}77}
90 78 
91-ErrCode BluetoothA2dpSinkStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)79+int32_t BluetoothA2dpSinkStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
92{80{
93 std::string addr = data.ReadString();81 std::string addr = data.ReadString();
94 82 
@@ -103,7 +91,7 @@ ErrCode BluetoothA2dpSinkStub::DisconnectInner(MessageParcel &data, MessageParce
103 return NO_ERROR;91 return NO_ERROR;
104}92}
105 93 
106-ErrCode BluetoothA2dpSinkStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)94+int32_t BluetoothA2dpSinkStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
107{95{
108 sptr<IRemoteObject> remote = data.ReadRemoteObject();96 sptr<IRemoteObject> remote = data.ReadRemoteObject();
109 const sptr<IBluetoothA2dpSinkObserver> observer = OHOS::iface_cast<IBluetoothA2dpSinkObserver>(remote);97 const sptr<IBluetoothA2dpSinkObserver> observer = OHOS::iface_cast<IBluetoothA2dpSinkObserver>(remote);
@@ -112,7 +100,7 @@ ErrCode BluetoothA2dpSinkStub::RegisterObserverInner(MessageParcel &data, Messag
112 return NO_ERROR;100 return NO_ERROR;
113}101}
114 102 
115-ErrCode BluetoothA2dpSinkStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)103+int32_t BluetoothA2dpSinkStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
116{104{
117 sptr<IRemoteObject> remote = data.ReadRemoteObject();105 sptr<IRemoteObject> remote = data.ReadRemoteObject();
118 const sptr<IBluetoothA2dpSinkObserver> observer = OHOS::iface_cast<IBluetoothA2dpSinkObserver>(remote);106 const sptr<IBluetoothA2dpSinkObserver> observer = OHOS::iface_cast<IBluetoothA2dpSinkObserver>(remote);
@@ -121,7 +109,7 @@ ErrCode BluetoothA2dpSinkStub::DeregisterObserverInner(MessageParcel &data, Mess
121 return NO_ERROR;109 return NO_ERROR;
122}110}
123 111 
124-ErrCode BluetoothA2dpSinkStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)112+int32_t BluetoothA2dpSinkStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
125{113{
126 std::vector<int32_t> states = {};114 std::vector<int32_t> states = {};
127 int32_t stateSize = data.ReadInt32();115 int32_t stateSize = data.ReadInt32();
@@ -146,7 +134,7 @@ ErrCode BluetoothA2dpSinkStub::GetDevicesByStatesInner(MessageParcel &data, Mess
146 return NO_ERROR;134 return NO_ERROR;
147}135}
148 136 
149-ErrCode BluetoothA2dpSinkStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)137+int32_t BluetoothA2dpSinkStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
150{138{
151 std::string addr = data.ReadString();139 std::string addr = data.ReadString();
152 140 
@@ -161,7 +149,7 @@ ErrCode BluetoothA2dpSinkStub::GetDeviceStateInner(MessageParcel &data, MessageP
161 return NO_ERROR;149 return NO_ERROR;
162}150}
163 151 
164-ErrCode BluetoothA2dpSinkStub::GetPlayingStateInner(MessageParcel &data, MessageParcel &reply)152+int32_t BluetoothA2dpSinkStub::GetPlayingStateInner(MessageParcel &data, MessageParcel &reply)
165{153{
166 std::string addr = data.ReadString();154 std::string addr = data.ReadString();
167 int32_t state = 0;155 int32_t state = 0;
@@ -172,7 +160,7 @@ ErrCode BluetoothA2dpSinkStub::GetPlayingStateInner(MessageParcel &data, Message
172 return NO_ERROR;160 return NO_ERROR;
173}161}
174 162 
175-ErrCode BluetoothA2dpSinkStub::SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)163+int32_t BluetoothA2dpSinkStub::SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)
176{164{
177 std::string addr = data.ReadString();165 std::string addr = data.ReadString();
178 int strategy = data.ReadInt32();166 int strategy = data.ReadInt32();
@@ -188,7 +176,7 @@ ErrCode BluetoothA2dpSinkStub::SetConnectStrategyInner(MessageParcel &data, Mess
188 return NO_ERROR;176 return NO_ERROR;
189}177}
190 178 
191-ErrCode BluetoothA2dpSinkStub::GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)179+int32_t BluetoothA2dpSinkStub::GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)
192{180{
193 std::string addr = data.ReadString();181 std::string addr = data.ReadString();
194 int result = GetConnectStrategy(RawAddress(addr));182 int result = GetConnectStrategy(RawAddress(addr));
@@ -202,7 +190,7 @@ ErrCode BluetoothA2dpSinkStub::GetConnectStrategyInner(MessageParcel &data, Mess
202 return NO_ERROR;190 return NO_ERROR;
203}191}
204 192 
205-ErrCode BluetoothA2dpSinkStub::SendDelayInner(MessageParcel &data, MessageParcel &reply)193+int32_t BluetoothA2dpSinkStub::SendDelayInner(MessageParcel &data, MessageParcel &reply)
206{194{
207 std::string addr = data.ReadString();195 std::string addr = data.ReadString();
208 int delayValue = data.ReadInt32();196 int delayValue = data.ReadInt32();
Mservices/bluetooth/ipc/src/bluetooth_a2dp_src_stub.cpp+67-80
@@ -19,98 +19,85 @@
19#include "ipc_types.h"19#include "ipc_types.h"
20#include "parcel_bt_uuid.h"20#include "parcel_bt_uuid.h"
21#include "raw_address.h"21#include "raw_address.h"
22+#include "permission_manager.h"
23+ 
24+#ifdef STUB_FUNC
25+#undef STUB_FUNC
26+#endif
27+#define STUB_FUNC(code, func, perm) BluetoothA2dpSrcInterfaceCode::code, {&BluetoothA2dpSrcStub::func, perm}
22 28 
23namespace OHOS {29namespace OHOS {
24namespace Bluetooth {30namespace Bluetooth {
25using namespace OHOS::bluetooth;31using namespace OHOS::bluetooth;
26const int32_t A2DP_MAX_SRC_CONNECTION_NUMS = 0x07;32const int32_t A2DP_MAX_SRC_CONNECTION_NUMS = 0x07;
33+ 
34+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
35+const std::map<uint32_t, BluetoothA2dpSrcStub::A2dpSrcStubFuncPerm> BluetoothA2dpSrcStub::memberFuncMap_ = {
36+ {STUB_FUNC(BT_A2DP_SRC_CONNECT, ConnectInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
37+ {STUB_FUNC(BT_A2DP_SRC_DISCONNECT, DisconnectInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
38+ {STUB_FUNC(BT_A2DP_SRC_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
39+ {STUB_FUNC(BT_A2DP_SRC_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
40+ {STUB_FUNC(BT_A2DP_SRC_GET_DEVICE_BY_STATES, GetDevicesByStatesInner,
41+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
42+ {STUB_FUNC(BT_A2DP_SRC_GET_DEVICE_STATE, GetDeviceStateInner,
43+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
44+ {STUB_FUNC(BT_A2DP_SRC_GET_PLAYING_STATE, GetPlayingStateInner,
45+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
46+ {STUB_FUNC(BT_A2DP_SRC_SET_CONNECT_STRATEGY, SetConnectStrategyInner,
47+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48+ {STUB_FUNC(BT_A2DP_SRC_GET_CONNECT_STRATEGY, GetConnectStrategyInner,
49+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
50+ {STUB_FUNC(BT_A2DP_SRC_SET_ACTIVE_SINK_DEVICE, SetActiveSinkDeviceInner,
51+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
52+ {STUB_FUNC(BT_A2DP_SRC_GET_ACTIVE_SINK_DEVICE, GetActiveSinkDeviceInner,
53+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
54+ {STUB_FUNC(BT_A2DP_SRC_GET_CODEC_STATUS, GetCodecStatusInner,
55+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
56+ {STUB_FUNC(BT_A2DP_SRC_GET_CODEC_PREFERENCE, GetCodecPreferenceInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
57+ {STUB_FUNC(BT_A2DP_SRC_SET_CODEC_PREFERENCE, SetCodecPreferenceInner,
58+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
59+ {STUB_FUNC(BT_A2DP_SRC_SWITCH_OPTIONAL_CODECS, SwitchOptionalCodecsInner,
60+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
61+ {STUB_FUNC(BT_A2DP_SRC_GET_OPTIONAL_CODECS_SUPPORT_STATE, GetOptionalCodecsSupportStateInner,
62+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
63+ {STUB_FUNC(BT_A2DP_SRC_START_PLAYING, StartPlayingInner,
64+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
65+ {STUB_FUNC(BT_A2DP_SRC_SUSPEND_PLAYING, SuspendPlayingInner,
66+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
67+ {STUB_FUNC(BT_A2DP_SRC_STOP_PLAYING, StopPlayingInner,
68+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
69+ {STUB_FUNC(BT_A2DP_SRC_WRITE_FRAME, WriteFrameInner,
70+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
71+ {STUB_FUNC(BT_A2DP_SRC_GET_RENDER_POSITION, GetRenderPositionInner,
72+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
73+ {STUB_FUNC(BT_A2DP_SRC_OFFLOAD_START_PLAYING, OffloadStartPlayingInner,
74+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
75+ {STUB_FUNC(BT_A2DP_SRC_OFFLOAD_STOP_PLAYING, OffloadStopPlayingInner,
76+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
77+ {STUB_FUNC(BT_A2DP_SRC_OFFLOAD_SESSION_REQUEST, A2dpOffloadSessionPathRequestInner,
78+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
79+ {STUB_FUNC(BT_A2DP_SRC_OFFLOAD_GET_CODEC_STATUS, GetOffloadCodecStatusInner,
80+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
81+ {STUB_FUNC(BT_A2DP_SRC_ENABLE_AUTO_PLAY, EnableAutoPlayInner,
82+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
83+ {STUB_FUNC(BT_A2DP_SRC_DISABLE_AUTO_PLAY, DisableAutoPlayInner,
84+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
85+ {STUB_FUNC(BT_A2DP_SRC_GET_AUTO_PLAY_DISABLED_DURATION, GetAutoPlayDisabledDurationInner,
86+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
87+ {STUB_FUNC(BT_A2DP_SRC_GET_VIRTUALDEVICE_LIST, GetVirtualDeviceListInner,
88+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
89+};
90+ 
27BluetoothA2dpSrcStub::BluetoothA2dpSrcStub()91BluetoothA2dpSrcStub::BluetoothA2dpSrcStub()
28-{92+{}
29- HILOGD("%{public}s start.", __func__);
30- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_CONNECT)] =
31- &BluetoothA2dpSrcStub::ConnectInner;
32- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_DISCONNECT)] =
33- &BluetoothA2dpSrcStub::DisconnectInner;
34- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_REGISTER_OBSERVER)] =
35- &BluetoothA2dpSrcStub::RegisterObserverInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_DEREGISTER_OBSERVER)] =
37- &BluetoothA2dpSrcStub::DeregisterObserverInner;
38- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_DEVICE_BY_STATES)] =
39- &BluetoothA2dpSrcStub::GetDevicesByStatesInner;
40- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_DEVICE_STATE)] =
41- &BluetoothA2dpSrcStub::GetDeviceStateInner;
42- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_PLAYING_STATE)] =
43- &BluetoothA2dpSrcStub::GetPlayingStateInner;
44- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_SET_CONNECT_STRATEGY)] =
45- &BluetoothA2dpSrcStub::SetConnectStrategyInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_CONNECT_STRATEGY)] =
47- &BluetoothA2dpSrcStub::GetConnectStrategyInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_SET_ACTIVE_SINK_DEVICE)] =
49- &BluetoothA2dpSrcStub::SetActiveSinkDeviceInner;
50- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_ACTIVE_SINK_DEVICE)] =
51- &BluetoothA2dpSrcStub::GetActiveSinkDeviceInner;
52- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_CODEC_STATUS)] =
53- &BluetoothA2dpSrcStub::GetCodecStatusInner;
54- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_CODEC_PREFERENCE)] =
55- &BluetoothA2dpSrcStub::GetCodecPreferenceInner;
56- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_SET_CODEC_PREFERENCE)] =
57- &BluetoothA2dpSrcStub::SetCodecPreferenceInner;
58- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_SWITCH_OPTIONAL_CODECS)] =
59- &BluetoothA2dpSrcStub::SwitchOptionalCodecsInner;
60- memberFuncMap_[static_cast<uint32_t>(
61- BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_OPTIONAL_CODECS_SUPPORT_STATE)] =
62- &BluetoothA2dpSrcStub::GetOptionalCodecsSupportStateInner;
63- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_START_PLAYING)] =
64- &BluetoothA2dpSrcStub::StartPlayingInner;
65- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_SUSPEND_PLAYING)] =
66- &BluetoothA2dpSrcStub::SuspendPlayingInner;
67- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_STOP_PLAYING)] =
68- &BluetoothA2dpSrcStub::StopPlayingInner;
69- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_WRITE_FRAME)] =
70- &BluetoothA2dpSrcStub::WriteFrameInner;
71- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_RENDER_POSITION)] =
72- &BluetoothA2dpSrcStub::GetRenderPositionInner;
73- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_OFFLOAD_START_PLAYING)] =
74- &BluetoothA2dpSrcStub::OffloadStartPlayingInner;
75- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_OFFLOAD_STOP_PLAYING)] =
76- &BluetoothA2dpSrcStub::OffloadStopPlayingInner;
77- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_OFFLOAD_SESSION_REQUEST)] =
78- &BluetoothA2dpSrcStub::A2dpOffloadSessionPathRequestInner;
79- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_OFFLOAD_GET_CODEC_STATUS)] =
80- &BluetoothA2dpSrcStub::GetOffloadCodecStatusInner;
81- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_ENABLE_AUTO_PLAY)] =
82- &BluetoothA2dpSrcStub::EnableAutoPlayInner;
83- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_DISABLE_AUTO_PLAY)] =
84- &BluetoothA2dpSrcStub::DisableAutoPlayInner;
85- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_AUTO_PLAY_DISABLED_DURATION)] =
86- &BluetoothA2dpSrcStub::GetAutoPlayDisabledDurationInner;
87- memberFuncMap_[static_cast<uint32_t>(BluetoothA2dpSrcInterfaceCode::BT_A2DP_SRC_GET_VIRTUALDEVICE_LIST)] =
88- &BluetoothA2dpSrcStub::GetVirtualDeviceListInner;
89-}
90 93 
91BluetoothA2dpSrcStub::~BluetoothA2dpSrcStub()94BluetoothA2dpSrcStub::~BluetoothA2dpSrcStub()
92-{95+{}
93- HILOGD("%{public}s start.", __func__);
94- memberFuncMap_.clear();
95-}
96 96 
97int BluetoothA2dpSrcStub::OnRemoteRequest(97int BluetoothA2dpSrcStub::OnRemoteRequest(
98 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)98 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
99{99{
100- HILOGI("BluetoothA2dpSrcStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());100+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothA2dpSrcStub);
101- if (BluetoothA2dpSrcStub::GetDescriptor() != data.ReadInterfaceToken()) {
102- HILOGI("local descriptor is not equal to remote");
103- return ERR_INVALID_STATE;
104- }
105- auto itFunc = memberFuncMap_.find(code);
106- if (itFunc != memberFuncMap_.end()) {
107- auto memberFunc = itFunc->second;
108- if (memberFunc != nullptr) {
109- return (this->*memberFunc)(data, reply);
110- }
111- }
112- HILOGW("BluetoothA2dpSrcStub::OnRemoteRequest, default case, need check.");
113- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
114}101}
115 102 
116int32_t BluetoothA2dpSrcStub::ConnectInner(MessageParcel &data, MessageParcel &reply)103int32_t BluetoothA2dpSrcStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
Mservices/bluetooth/ipc/src/bluetooth_avrcp_ct_stub.cpp+128-125
@@ -15,113 +15,119 @@
15 15 
16#include "bluetooth_avrcp_ct_stub.h"16#include "bluetooth_avrcp_ct_stub.h"
17#include "bluetooth_log.h"17#include "bluetooth_log.h"
18-#include "ipc_types.h"18+#include "permission_manager.h"
19-#include "string_ex.h"19+ 
20+#ifdef STUB_FUNC
21+#undef STUB_FUNC
22+#endif
23+#define STUB_FUNC(code, func, perm) std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::func), perm)
20 24 
21namespace OHOS {25namespace OHOS {
22namespace Bluetooth {26namespace Bluetooth {
23const uint32_t AVRCP_NOTIDICATION_EVENT_COUNT_MAX = 0XFF;27const uint32_t AVRCP_NOTIDICATION_EVENT_COUNT_MAX = 0XFF;
24const uint32_t AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX = 0XFF;28const uint32_t AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX = 0XFF;
29+ 
30+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
31+const std::map<uint32_t, BluetoothAvrcpCtStub::AvrcpCtStubFuncPerm> BluetoothAvrcpCtStub::memberFuncMap_ = {
32+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_REGISTER_OBSERVER),
33+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::RegisterObserverInner), nullptr)},
34+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_UNREGISTER_OBSERVER),
35+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::UnregisterObserverInner), nullptr)},
36+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_CONNECTED_DEVICES),
37+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetConnectedDevicesInner), nullptr)},
38+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICES_BY_STATES),
39+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetDevicesByStatesInner), nullptr)},
40+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICE_STATE),
41+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetDeviceStateInner), nullptr)},
42+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_CONNECT),
43+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::ConnectInner),
44+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
45+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISCONNECT),
46+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::DisconnectInner),
47+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PRESS_BUTTON),
49+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::PressButtonnner),
50+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
51+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_RELEASE_BUTTON),
52+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::ReleaseButtonInner),
53+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
54+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_UNIT_INFO),
55+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetUnitInfoInner),
56+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
57+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUB_UNIT_INFO),
58+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetSubUnitInfoInner),
59+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
60+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_COMPANIES),
61+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetSupportedCompaniesInner),
62+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
63+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_EVENTS),
64+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetSupportedEventsInner), nullptr)},
65+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTES),
66+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner),
67+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
68+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES),
69+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner),
70+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
71+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_CURRENT_VALUE),
72+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner),
73+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
74+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_PLAYER_APP_SETTING_CURRENT_VALUE),
75+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner),
76+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
77+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT),
78+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner),
79+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
80+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES_TEXT),
81+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner),
82+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
83+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ELEMENT_ATTRIBUTES),
84+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetElementAttributesInner),
85+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
86+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_STATUS),
87+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetPlayStatusInner),
88+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
89+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PLAY_ITEM),
90+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::PlayItemInner),
91+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
92+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_FOLDER_ITEMS),
93+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetFolderItemsInner),
94+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
95+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_TOTAL_NUMBER_OF_ITEMS),
96+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner),
97+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
98+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_ABSOLUTE_VOLUME),
99+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::SetAbsoluteVolumeInner),
100+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
101+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_ENABLE_NOTIFICATION),
102+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::EnableNotificationInner),
103+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
104+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISABLE_NOTIFICATION),
105+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::DisableNotificationInner),
106+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
107+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ITEM_ATTRIBUTES),
108+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetItemAttributesInner),
109+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
110+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_BROWSERED_PLAYER),
111+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::SetBrowsedPlayerInner),
112+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
113+ {static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_MEDIA_PLAYER_LIST),
114+ std::make_pair(AvrcpCtStubFunc(&BluetoothAvrcpCtStub::GetMeidaPlayerListInner),
115+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
116+};
117+ 
25BluetoothAvrcpCtStub::BluetoothAvrcpCtStub()118BluetoothAvrcpCtStub::BluetoothAvrcpCtStub()
26-{119+{}
27- HILOGD("%{public}s start.", __func__);
28- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_REGISTER_OBSERVER)] =
29- &BluetoothAvrcpCtStub::RegisterObserverInner;
30- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_UNREGISTER_OBSERVER)] =
31- &BluetoothAvrcpCtStub::UnregisterObserverInner;
32- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_CONNECTED_DEVICES)] =
33- &BluetoothAvrcpCtStub::GetConnectedDevicesInner;
34- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICES_BY_STATES)] =
35- &BluetoothAvrcpCtStub::GetDevicesByStatesInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICE_STATE)] =
37- &BluetoothAvrcpCtStub::GetDeviceStateInner;
38- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_CONNECT)] =
39- nullptr;
40- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISCONNECT)] =
41- &BluetoothAvrcpCtStub::DisconnectInner;
42- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PRESS_BUTTON)] =
43- &BluetoothAvrcpCtStub::PressButtonnner;
44- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_RELEASE_BUTTON)] =
45- &BluetoothAvrcpCtStub::ReleaseButtonInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_UNIT_INFO)] =
47- &BluetoothAvrcpCtStub::GetUnitInfoInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUB_UNIT_INFO)] =
49- &BluetoothAvrcpCtStub::GetSubUnitInfoInner;
50- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_COMPANIES)] =
51- &BluetoothAvrcpCtStub::GetSupportedCompaniesInner;
52- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_EVENTS)] =
53- &BluetoothAvrcpCtStub::GetSupportedEventsInner;
54- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTES)] =
55- &BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner;
56- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES)] =
57- &BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner;
58- memberFuncMap_[static_cast<uint32_t>(
59- BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
60- &BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner;
61- memberFuncMap_[static_cast<uint32_t>(
62- BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
63- &BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner;
64- memberFuncMap_[static_cast<uint32_t>(
65- BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT)] =
66- &BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner;
67- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES_TEXT)] =
68- &BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner;
69- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ELEMENT_ATTRIBUTES)] =
70- &BluetoothAvrcpCtStub::GetElementAttributesInner;
71- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_STATUS)] =
72- &BluetoothAvrcpCtStub::GetPlayStatusInner;
73- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PLAY_ITEM)] =
74- &BluetoothAvrcpCtStub::PlayItemInner;
75- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_FOLDER_ITEMS)] =
76- &BluetoothAvrcpCtStub::GetFolderItemsInner;
77- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_TOTAL_NUMBER_OF_ITEMS)] =
78- &BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner;
79- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_ABSOLUTE_VOLUME)] =
80- &BluetoothAvrcpCtStub::SetAbsoluteVolumeInner;
81- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_ENABLE_NOTIFICATION)] =
82- &BluetoothAvrcpCtStub::EnableNotificationInner;
83- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISABLE_NOTIFICATION)] =
84- &BluetoothAvrcpCtStub::DisableNotificationInner;
85- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ITEM_ATTRIBUTES)] =
86- &BluetoothAvrcpCtStub::GetItemAttributesInner;
87- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_BROWSERED_PLAYER)] =
88- &BluetoothAvrcpCtStub::SetBrowsedPlayerInner;
89- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_MEDIA_PLAYER_LIST)] =
90- &BluetoothAvrcpCtStub::GetMeidaPlayerListInner;
91-}
92 120 
93BluetoothAvrcpCtStub::~BluetoothAvrcpCtStub()121BluetoothAvrcpCtStub::~BluetoothAvrcpCtStub()
94-{122+{}
95- HILOGD("%{public}s start.", __func__);
96- memberFuncMap_.clear();
97-}
98 123 
99int BluetoothAvrcpCtStub::OnRemoteRequest(124int BluetoothAvrcpCtStub::OnRemoteRequest(
100 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)125 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
101{126{
102- HILOGD("BluetoothAvrcpCtStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",127+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothAvrcpCtStub);
103- code,
104- option.GetFlags());
105- std::u16string descriptor = BluetoothAvrcpCtStub::GetDescriptor();
106- std::u16string remoteDescriptor = data.ReadInterfaceToken();
107- if (descriptor != remoteDescriptor) {
108- HILOGI("local descriptor is not equal to remote");
109- return ERR_INVALID_STATE;
110- }
111- 
112- auto itFunc = memberFuncMap_.find(code);
113- if (itFunc != memberFuncMap_.end()) {
114- auto memberFunc = itFunc->second;
115- if (memberFunc != nullptr) {
116- return (this->*memberFunc)(data,reply);
117- }
118- }
119- 
120- HILOGW("BluetoothAvrcpCtStub::OnRemoteRequest, default case, need check.");
121- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
122}128}
123 129 
124-ErrCode BluetoothAvrcpCtStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)130+int32_t BluetoothAvrcpCtStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
125{131{
126 sptr<IRemoteObject> tempObject = data.ReadRemoteObject(); 132 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
127 sptr<IBluetoothAvrcpCtObserver> observer;133 sptr<IBluetoothAvrcpCtObserver> observer;
@@ -130,7 +136,7 @@ ErrCode BluetoothAvrcpCtStub::RegisterObserverInner(MessageParcel &data, Message
130 return NO_ERROR;136 return NO_ERROR;
131}137}
132 138 
133-ErrCode BluetoothAvrcpCtStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)139+int32_t BluetoothAvrcpCtStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
134{140{
135 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();141 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
136 sptr<IBluetoothAvrcpCtObserver> observer;142 sptr<IBluetoothAvrcpCtObserver> observer;
@@ -139,7 +145,7 @@ ErrCode BluetoothAvrcpCtStub::UnregisterObserverInner(MessageParcel &data, Messa
139 return NO_ERROR;145 return NO_ERROR;
140}146}
141 147 
142-ErrCode BluetoothAvrcpCtStub::GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply)148+int32_t BluetoothAvrcpCtStub::GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply)
143{149{
144 std::vector<RawAddress> rawAdds = GetConnectedDevices();150 std::vector<RawAddress> rawAdds = GetConnectedDevices();
145 reply.WriteInt32(rawAdds.size());151 reply.WriteInt32(rawAdds.size());
@@ -152,7 +158,7 @@ ErrCode BluetoothAvrcpCtStub::GetConnectedDevicesInner(MessageParcel &data, Mess
152 return NO_ERROR;158 return NO_ERROR;
153}159}
154 160 
155-ErrCode BluetoothAvrcpCtStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)161+int32_t BluetoothAvrcpCtStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
156{162{
157 std::vector<int32_t> states = {};163 std::vector<int32_t> states = {};
158 int32_t stateSize = data.ReadInt32();164 int32_t stateSize = data.ReadInt32();
@@ -177,7 +183,7 @@ ErrCode BluetoothAvrcpCtStub::GetDevicesByStatesInner(MessageParcel &data, Messa
177 return NO_ERROR;183 return NO_ERROR;
178}184}
179 185 
180-ErrCode BluetoothAvrcpCtStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)186+int32_t BluetoothAvrcpCtStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
181{187{
182 int32_t state = GetDeviceState(RawAddress(data.ReadString()));188 int32_t state = GetDeviceState(RawAddress(data.ReadString()));
183 reply.WriteInt32(state);189 reply.WriteInt32(state);
@@ -185,7 +191,7 @@ ErrCode BluetoothAvrcpCtStub::GetDeviceStateInner(MessageParcel &data, MessagePa
185 return NO_ERROR;191 return NO_ERROR;
186}192}
187 193 
188-ErrCode BluetoothAvrcpCtStub::ConnectInner(MessageParcel &data, MessageParcel &reply)194+int32_t BluetoothAvrcpCtStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
189{195{
190 int32_t result = Connect(RawAddress(data.ReadString()));196 int32_t result = Connect(RawAddress(data.ReadString()));
191 reply.WriteInt32(result);197 reply.WriteInt32(result);
@@ -193,7 +199,7 @@ ErrCode BluetoothAvrcpCtStub::ConnectInner(MessageParcel &data, MessageParcel &r
193 return NO_ERROR;199 return NO_ERROR;
194}200}
195 201 
196-ErrCode BluetoothAvrcpCtStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)202+int32_t BluetoothAvrcpCtStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
197{203{
198 int32_t result = Disconnect(RawAddress(data.ReadString()));204 int32_t result = Disconnect(RawAddress(data.ReadString()));
199 reply.WriteInt32(result);205 reply.WriteInt32(result);
@@ -201,7 +207,7 @@ ErrCode BluetoothAvrcpCtStub::DisconnectInner(MessageParcel &data, MessageParcel
201 return NO_ERROR;207 return NO_ERROR;
202}208}
203 209 
204-ErrCode BluetoothAvrcpCtStub::PressButtonnner(MessageParcel &data, MessageParcel &reply)210+int32_t BluetoothAvrcpCtStub::PressButtonnner(MessageParcel &data, MessageParcel &reply)
205{211{
206 int32_t result = PressButton(RawAddress(data.ReadString()), data.ReadInt32());212 int32_t result = PressButton(RawAddress(data.ReadString()), data.ReadInt32());
207 reply.WriteInt32(result);213 reply.WriteInt32(result);
@@ -209,7 +215,7 @@ ErrCode BluetoothAvrcpCtStub::PressButtonnner(MessageParcel &data, MessageParcel
209 return NO_ERROR;215 return NO_ERROR;
210}216}
211 217 
212-ErrCode BluetoothAvrcpCtStub::ReleaseButtonInner(MessageParcel &data, MessageParcel &reply)218+int32_t BluetoothAvrcpCtStub::ReleaseButtonInner(MessageParcel &data, MessageParcel &reply)
213{219{
214 int32_t result = ReleaseButton(RawAddress(data.ReadString()), data.ReadInt32());220 int32_t result = ReleaseButton(RawAddress(data.ReadString()), data.ReadInt32());
215 reply.WriteInt32(result);221 reply.WriteInt32(result);
@@ -217,7 +223,7 @@ ErrCode BluetoothAvrcpCtStub::ReleaseButtonInner(MessageParcel &data, MessagePar
217 return NO_ERROR;223 return NO_ERROR;
218}224}
219 225 
220-ErrCode BluetoothAvrcpCtStub::GetUnitInfoInner(MessageParcel &data, MessageParcel &reply)226+int32_t BluetoothAvrcpCtStub::GetUnitInfoInner(MessageParcel &data, MessageParcel &reply)
221{227{
222 int32_t result = GetUnitInfo(RawAddress(data.ReadString()));228 int32_t result = GetUnitInfo(RawAddress(data.ReadString()));
223 reply.WriteInt32(result);229 reply.WriteInt32(result);
@@ -225,7 +231,7 @@ ErrCode BluetoothAvrcpCtStub::GetUnitInfoInner(MessageParcel &data, MessageParce
225 return NO_ERROR;231 return NO_ERROR;
226}232}
227 233 
228-ErrCode BluetoothAvrcpCtStub::GetSubUnitInfoInner(MessageParcel &data, MessageParcel &reply)234+int32_t BluetoothAvrcpCtStub::GetSubUnitInfoInner(MessageParcel &data, MessageParcel &reply)
229{235{
230 int32_t result = GetSubUnitInfo(RawAddress(data.ReadString()));236 int32_t result = GetSubUnitInfo(RawAddress(data.ReadString()));
231 reply.WriteInt32(result);237 reply.WriteInt32(result);
@@ -233,7 +239,7 @@ ErrCode BluetoothAvrcpCtStub::GetSubUnitInfoInner(MessageParcel &data, MessagePa
233 return NO_ERROR;239 return NO_ERROR;
234}240}
235 241 
236-ErrCode BluetoothAvrcpCtStub::GetSupportedCompaniesInner(MessageParcel &data, MessageParcel &reply)242+int32_t BluetoothAvrcpCtStub::GetSupportedCompaniesInner(MessageParcel &data, MessageParcel &reply)
237{243{
238 int32_t result = GetSupportedCompanies(RawAddress(data.ReadString()));244 int32_t result = GetSupportedCompanies(RawAddress(data.ReadString()));
239 reply.WriteInt32(result);245 reply.WriteInt32(result);
@@ -241,7 +247,7 @@ ErrCode BluetoothAvrcpCtStub::GetSupportedCompaniesInner(MessageParcel &data, Me
241 return NO_ERROR;247 return NO_ERROR;
242}248}
243 249 
244-ErrCode BluetoothAvrcpCtStub::GetSupportedEventsInner(MessageParcel &data, MessageParcel &reply)250+int32_t BluetoothAvrcpCtStub::GetSupportedEventsInner(MessageParcel &data, MessageParcel &reply)
245{251{
246 int32_t result = GetSupportedEvents(RawAddress(data.ReadString()));252 int32_t result = GetSupportedEvents(RawAddress(data.ReadString()));
247 reply.WriteInt32(result);253 reply.WriteInt32(result);
@@ -249,7 +255,7 @@ ErrCode BluetoothAvrcpCtStub::GetSupportedEventsInner(MessageParcel &data, Messa
249 return NO_ERROR;255 return NO_ERROR;
250}256}
251 257 
252-ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply)258+int32_t BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply)
253{259{
254 int32_t result = GetPlayerAppSettingAttributes(RawAddress(data.ReadString()));260 int32_t result = GetPlayerAppSettingAttributes(RawAddress(data.ReadString()));
255 reply.WriteInt32(result);261 reply.WriteInt32(result);
@@ -257,7 +263,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner(MessageParcel &
257 return NO_ERROR;263 return NO_ERROR;
258}264}
259 265 
260-ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply)266+int32_t BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply)
261{267{
262 int32_t result = GetPlayerAppSettingValues(RawAddress(data.ReadString()), data.ReadInt32());268 int32_t result = GetPlayerAppSettingValues(RawAddress(data.ReadString()), data.ReadInt32());
263 reply.WriteInt32(result);269 reply.WriteInt32(result);
@@ -265,7 +271,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner(MessageParcel &data
265 return NO_ERROR;271 return NO_ERROR;
266}272}
267 273 
268-ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)274+int32_t BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
269{275{
270 RawAddress raw = RawAddress(data.ReadString());276 RawAddress raw = RawAddress(data.ReadString());
271 std::vector<int32_t> attributes = {};277 std::vector<int32_t> attributes = {};
@@ -284,7 +290,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner(MessageParcel
284 return NO_ERROR;290 return NO_ERROR;
285}291}
286 292 
287-ErrCode BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)293+int32_t BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
288{294{
289 RawAddress raw = RawAddress(data.ReadString());295 RawAddress raw = RawAddress(data.ReadString());
290 std::vector<int32_t> attributes = {};296 std::vector<int32_t> attributes = {};
@@ -315,7 +321,7 @@ ErrCode BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner(MessageParcel
315 return NO_ERROR;321 return NO_ERROR;
316}322}
317 323 
318-ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply)324+int32_t BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply)
319{325{
320 RawAddress raw = RawAddress(data.ReadString());326 RawAddress raw = RawAddress(data.ReadString());
321 std::vector<int32_t> attributes = {};327 std::vector<int32_t> attributes = {};
@@ -334,7 +340,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner(MessageParce
334 return NO_ERROR;340 return NO_ERROR;
335}341}
336 342 
337-ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply)343+int32_t BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply)
338{344{
339 RawAddress raw = RawAddress(data.ReadString());345 RawAddress raw = RawAddress(data.ReadString());
340 int32_t attributes = data.ReadInt32();346 int32_t attributes = data.ReadInt32();
@@ -355,7 +361,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner(MessageParcel &d
355 return NO_ERROR;361 return NO_ERROR;
356}362}
357 363 
358-ErrCode BluetoothAvrcpCtStub::GetElementAttributesInner(MessageParcel &data, MessageParcel &reply)364+int32_t BluetoothAvrcpCtStub::GetElementAttributesInner(MessageParcel &data, MessageParcel &reply)
359{365{
360 RawAddress raw = RawAddress(data.ReadString());366 RawAddress raw = RawAddress(data.ReadString());
361 std::vector<int32_t> attributes = {};367 std::vector<int32_t> attributes = {};
@@ -374,7 +380,7 @@ ErrCode BluetoothAvrcpCtStub::GetElementAttributesInner(MessageParcel &data, Mes
374 return NO_ERROR;380 return NO_ERROR;
375}381}
376 382 
377-ErrCode BluetoothAvrcpCtStub::GetPlayStatusInner(MessageParcel &data, MessageParcel &reply)383+int32_t BluetoothAvrcpCtStub::GetPlayStatusInner(MessageParcel &data, MessageParcel &reply)
378{384{
379 RawAddress raw = RawAddress(data.ReadString());385 RawAddress raw = RawAddress(data.ReadString());
380 int32_t result = GetPlayStatus(raw);386 int32_t result = GetPlayStatus(raw);
@@ -383,7 +389,7 @@ ErrCode BluetoothAvrcpCtStub::GetPlayStatusInner(MessageParcel &data, MessagePar
383 return NO_ERROR;389 return NO_ERROR;
384}390}
385 391 
386-ErrCode BluetoothAvrcpCtStub::PlayItemInner(MessageParcel &data, MessageParcel &reply)392+int32_t BluetoothAvrcpCtStub::PlayItemInner(MessageParcel &data, MessageParcel &reply)
387{393{
388 RawAddress raw = RawAddress(data.ReadString());394 RawAddress raw = RawAddress(data.ReadString());
389 int32_t result = PlayItem(raw, data.ReadInt32(), data.ReadInt64(), data.ReadInt32());395 int32_t result = PlayItem(raw, data.ReadInt32(), data.ReadInt64(), data.ReadInt32());
@@ -392,7 +398,7 @@ ErrCode BluetoothAvrcpCtStub::PlayItemInner(MessageParcel &data, MessageParcel &
392 return NO_ERROR;398 return NO_ERROR;
393}399}
394 400 
395-ErrCode BluetoothAvrcpCtStub::GetFolderItemsInner(MessageParcel &data, MessageParcel &reply)401+int32_t BluetoothAvrcpCtStub::GetFolderItemsInner(MessageParcel &data, MessageParcel &reply)
396{402{
397 RawAddress raw = RawAddress(data.ReadString());403 RawAddress raw = RawAddress(data.ReadString());
398 int32_t startItem = data.ReadInt32();404 int32_t startItem = data.ReadInt32();
@@ -414,7 +420,7 @@ ErrCode BluetoothAvrcpCtStub::GetFolderItemsInner(MessageParcel &data, MessagePa
414 return NO_ERROR;420 return NO_ERROR;
415}421}
416 422 
417-ErrCode BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply)423+int32_t BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply)
418{424{
419 RawAddress raw = RawAddress(data.ReadString());425 RawAddress raw = RawAddress(data.ReadString());
420 int32_t scope = data.ReadInt32();426 int32_t scope = data.ReadInt32();
@@ -424,7 +430,7 @@ ErrCode BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner(MessageParcel &data, Me
424 return NO_ERROR;430 return NO_ERROR;
425}431}
426 432 
427-ErrCode BluetoothAvrcpCtStub::SetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)433+int32_t BluetoothAvrcpCtStub::SetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)
428{434{
429 RawAddress raw = RawAddress(data.ReadString());435 RawAddress raw = RawAddress(data.ReadString());
430 int32_t volume = data.ReadInt32();436 int32_t volume = data.ReadInt32();
@@ -434,7 +440,7 @@ ErrCode BluetoothAvrcpCtStub::SetAbsoluteVolumeInner(MessageParcel &data, Messag
434 return NO_ERROR;440 return NO_ERROR;
435}441}
436 442 
437-ErrCode BluetoothAvrcpCtStub::EnableNotificationInner(MessageParcel &data, MessageParcel &reply)443+int32_t BluetoothAvrcpCtStub::EnableNotificationInner(MessageParcel &data, MessageParcel &reply)
438{444{
439 RawAddress raw = RawAddress(data.ReadString());445 RawAddress raw = RawAddress(data.ReadString());
440 std::vector<int32_t> events = {};446 std::vector<int32_t> events = {};
@@ -453,7 +459,7 @@ ErrCode BluetoothAvrcpCtStub::EnableNotificationInner(MessageParcel &data, Messa
453 return NO_ERROR;459 return NO_ERROR;
454}460}
455 461 
456-ErrCode BluetoothAvrcpCtStub::DisableNotificationInner(MessageParcel &data, MessageParcel &reply)462+int32_t BluetoothAvrcpCtStub::DisableNotificationInner(MessageParcel &data, MessageParcel &reply)
457{463{
458 RawAddress raw = RawAddress(data.ReadString());464 RawAddress raw = RawAddress(data.ReadString());
459 std::vector<int32_t> events = {};465 std::vector<int32_t> events = {};
@@ -471,7 +477,7 @@ ErrCode BluetoothAvrcpCtStub::DisableNotificationInner(MessageParcel &data, Mess
471 return NO_ERROR;477 return NO_ERROR;
472}478}
473 479 
474-ErrCode BluetoothAvrcpCtStub::GetItemAttributesInner(MessageParcel &data, MessageParcel &reply)480+int32_t BluetoothAvrcpCtStub::GetItemAttributesInner(MessageParcel &data, MessageParcel &reply)
475{481{
476 RawAddress raw = RawAddress(data.ReadString());482 RawAddress raw = RawAddress(data.ReadString());
477 int64_t uid = data.ReadInt64();483 int64_t uid = data.ReadInt64();
@@ -491,19 +497,16 @@ ErrCode BluetoothAvrcpCtStub::GetItemAttributesInner(MessageParcel &data, Messag
491 return NO_ERROR;497 return NO_ERROR;
492}498}
493 499 
494-ErrCode BluetoothAvrcpCtStub::SetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply)500+int32_t BluetoothAvrcpCtStub::SetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply)
495{501{
496 RawAddress raw = RawAddress(data.ReadString());502 RawAddress raw = RawAddress(data.ReadString());
497 int32_t playerId = data.ReadInt32();503 int32_t playerId = data.ReadInt32();
498- 
499 int32_t result = SetBrowsedPlayer(raw, playerId);504 int32_t result = SetBrowsedPlayer(raw, playerId);
500 reply.WriteInt32(result);505 reply.WriteInt32(result);
501- 
502 return NO_ERROR;506 return NO_ERROR;
503- 
504}507}
505 508 
506-ErrCode BluetoothAvrcpCtStub::GetMeidaPlayerListInner(MessageParcel &data, MessageParcel &reply)509+int32_t BluetoothAvrcpCtStub::GetMeidaPlayerListInner(MessageParcel &data, MessageParcel &reply)
507{510{
508 RawAddress raw = RawAddress(data.ReadString());511 RawAddress raw = RawAddress(data.ReadString());
509 int32_t startItem = data.ReadInt32();512 int32_t startItem = data.ReadInt32();
Mservices/bluetooth/ipc/src/bluetooth_avrcp_tg_stub.cpp+75-91
@@ -17,88 +17,72 @@
17#include "bluetooth_log.h"17#include "bluetooth_log.h"
18#include "ipc_types.h"18#include "ipc_types.h"
19#include "string_ex.h"19#include "string_ex.h"
20+#include "permission_manager.h"
21+ 
22+#ifdef STUB_FUNC
23+#undef STUB_FUNC
24+#endif
25+#define STUB_FUNC(code, func, perm) BluetoothAvrcpTgInterfaceCode::code, {&BluetoothAvrcpTgStub::func, perm}
20 26 
21namespace OHOS {27namespace OHOS {
22namespace Bluetooth {28namespace Bluetooth {
29+ 
30+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
31+const std::map<uint32_t, BluetoothAvrcpTgStub::AvrcpTgStubFuncPerm> BluetoothAvrcpTgStub::memberFuncMap_ = {
32+ {STUB_FUNC(BT_AVRCP_TG_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
33+ {STUB_FUNC(BT_AVRCP_TG_UNREGISTER_OBSERVER, UnregisterObserverInner, nullptr)},
34+ {STUB_FUNC(BT_AVRCP_TG_SET_ACTIVE_DEVICE, SetActiveDeviceInner,
35+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
36+ {STUB_FUNC(BT_AVRCP_TG_CONNECT, ConnectInner,
37+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
38+ {STUB_FUNC(BT_AVRCP_TG_DISCONNECT, DisconnectInner,
39+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
40+ {STUB_FUNC(BT_AVRCP_TG_GET_CONNECTED_DEVICES, GetConnectedDevicesInner, nullptr)},
41+ {STUB_FUNC(BT_AVRCP_TG_GET_DEVICES_BY_STATES, GetDevicesByStatesInner, nullptr)},
42+ {STUB_FUNC(BT_AVRCP_TG_GET_DEVICE_STATE, GetDeviceStateInner, nullptr)},
43+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_PLAYBACK_STATUS_CHANGED, NotifyPlaybackStatusChangedInner,
44+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
45+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_TRACK_CHANGED, NotifyTrackChangedInner,
46+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
47+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_TRACK_REACHED_END, NotifyTrackReachedEndInner,
48+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
49+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_TRACK_REACHED_START, NotifyTrackReachedStartInner,
50+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
51+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_PLAYBACK_POS_CHANGED, NotifyPlaybackPosChangedInner,
52+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
53+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_PLAYER_APP_SETTING_CHANGED, NotifyPlayerAppSettingChangedInner,
54+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
55+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_NOWPLAYING_CONTENT_CHANGED, NotifyNowPlayingContentChangedInner,
56+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
57+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_AVAILABLE_PLAYERS_CHANGED, NotifyAvailablePlayersChangedInner,
58+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
59+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_ADDRESSED_PLAYER_CHANGED, NotifyAddressedPlayerChangedInner,
60+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
61+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_UID_CHANGED, NotifyUidChangedInner,
62+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
63+ {STUB_FUNC(BT_AVRCP_TG_NOTIFY_VOLUME_CHANGED, NotifyVolumeChangedInner,
64+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
65+ {STUB_FUNC(BT_AVRCP_TG_SET_DEVICE_ABSOLUTE_VOLUME, SetDeviceAbsoluteVolumeInner,
66+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
67+ {STUB_FUNC(BT_AVRCP_TG_GET_DEVICE_ABS_VOLUME_ABILITY, GetDeviceAbsVolumeAbilityInner,
68+ CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
69+ {STUB_FUNC(BT_AVRCP_TG_SET_DEVICE_ABS_VOLUME_ABILITY, SetDeviceAbsVolumeAbilityInner,
70+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
71+};
72+ 
23BluetoothAvrcpTgStub::BluetoothAvrcpTgStub()73BluetoothAvrcpTgStub::BluetoothAvrcpTgStub()
24-{74+{}
25- HILOGD("%{public}s start.", __func__);
26- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_REGISTER_OBSERVER)] =
27- &BluetoothAvrcpTgStub::RegisterObserverInner;
28- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_UNREGISTER_OBSERVER)] =
29- &BluetoothAvrcpTgStub::UnregisterObserverInner;
30- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_SET_ACTIVE_DEVICE)] =
31- &BluetoothAvrcpTgStub::SetActiveDeviceInner;
32- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_CONNECT)] =
33- &BluetoothAvrcpTgStub::ConnectInner;
34- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_DISCONNECT)] =
35- &BluetoothAvrcpTgStub::DisconnectInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_GET_CONNECTED_DEVICES)] =
37- &BluetoothAvrcpTgStub::GetConnectedDevicesInner;
38- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_GET_DEVICES_BY_STATES)] =
39- &BluetoothAvrcpTgStub::GetDevicesByStatesInner;
40- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_GET_DEVICE_STATE)] =
41- &BluetoothAvrcpTgStub::GetDeviceStateInner;
42- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_PLAYBACK_STATUS_CHANGED)] =
43- &BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner;
44- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_TRACK_CHANGED)] =
45- &BluetoothAvrcpTgStub::NotifyTrackChangedInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_TRACK_REACHED_END)] =
47- &BluetoothAvrcpTgStub::NotifyTrackReachedEndInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_TRACK_REACHED_START)] =
49- &BluetoothAvrcpTgStub::NotifyTrackReachedStartInner;
50- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_PLAYBACK_POS_CHANGED)] =
51- &BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner;
52- memberFuncMap_[static_cast<uint32_t>(
53- BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_PLAYER_APP_SETTING_CHANGED)] =
54- &BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner;
55- memberFuncMap_[static_cast<uint32_t>(
56- BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_NOWPLAYING_CONTENT_CHANGED)] =
57- &BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner;
58- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_AVAILABLE_PLAYERS_CHANGED)] =
59- &BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner;
60- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_ADDRESSED_PLAYER_CHANGED)] =
61- &BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner;
62- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_UID_CHANGED)] =
63- &BluetoothAvrcpTgStub::NotifyUidChangedInner;
64- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_NOTIFY_VOLUME_CHANGED)] =
65- &BluetoothAvrcpTgStub::NotifyVolumeChangedInner;
66- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_SET_DEVICE_ABSOLUTE_VOLUME)] =
67- &BluetoothAvrcpTgStub::SetDeviceAbsoluteVolumeInner;
68- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_SET_DEVICE_ABS_VOLUME_ABILITY)] =
69- &BluetoothAvrcpTgStub::SetDeviceAbsVolumeAbilityInner;
70- memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpTgInterfaceCode::BT_AVRCP_TG_GET_DEVICE_ABS_VOLUME_ABILITY)] =
71- &BluetoothAvrcpTgStub::GetDeviceAbsVolumeAbilityInner;
72-}
73 75 
74BluetoothAvrcpTgStub::~BluetoothAvrcpTgStub()76BluetoothAvrcpTgStub::~BluetoothAvrcpTgStub()
75-{77+{}
76- HILOGD("%{public}s start.", __func__);
77- memberFuncMap_.clear();
78-}
79 78 
80int BluetoothAvrcpTgStub::OnRemoteRequest(79int BluetoothAvrcpTgStub::OnRemoteRequest(
81 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)80 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
82{81{
83- HILOGD("BluetoothAvrcpTgStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());82+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothAvrcpTgStub);
84- std::u16string descriptor = BluetoothAvrcpTgStub::GetDescriptor();
85- std::u16string remoteDescriptor = data.ReadInterfaceToken();
86- if (descriptor != remoteDescriptor) {
87- HILOGI("local descriptor is not equal to remote");
88- return ERR_INVALID_STATE;
89- }
90- auto itFunc = memberFuncMap_.find(code);
91- if (itFunc != memberFuncMap_.end()) {
92- auto memberFunc = itFunc->second;
93- if (memberFunc != nullptr) {
94- return (this->*memberFunc)(data, reply);
95- }
96- }
97- HILOGW("BluetoothAvrcpTgStub::OnRemoteRequest, default case, need check.");
98- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
99}83}
100 84 
101-ErrCode BluetoothAvrcpTgStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)85+int32_t BluetoothAvrcpTgStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
102{86{
103 HILOGI("BluetoothAvrcpTgStub::RegisterObserverInner starts");87 HILOGI("BluetoothAvrcpTgStub::RegisterObserverInner starts");
104 sptr<IRemoteObject> remote = data.ReadRemoteObject();88 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -108,7 +92,7 @@ ErrCode BluetoothAvrcpTgStub::RegisterObserverInner(MessageParcel &data, Message
108 return NO_ERROR;92 return NO_ERROR;
109}93}
110 94 
111-ErrCode BluetoothAvrcpTgStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)95+int32_t BluetoothAvrcpTgStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
112{96{
113 HILOGI("BluetoothAvrcpTgStub::UnregisterObserverInner starts");97 HILOGI("BluetoothAvrcpTgStub::UnregisterObserverInner starts");
114 sptr<IRemoteObject> remote = data.ReadRemoteObject();98 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -118,7 +102,7 @@ ErrCode BluetoothAvrcpTgStub::UnregisterObserverInner(MessageParcel &data, Messa
118 return NO_ERROR;102 return NO_ERROR;
119}103}
120 104 
121-ErrCode BluetoothAvrcpTgStub::SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)105+int32_t BluetoothAvrcpTgStub::SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)
122{106{
123 HILOGI("BluetoothAvrcpTgStub::SetActiveDeviceInner starts");107 HILOGI("BluetoothAvrcpTgStub::SetActiveDeviceInner starts");
124 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());108 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -130,7 +114,7 @@ ErrCode BluetoothAvrcpTgStub::SetActiveDeviceInner(MessageParcel &data, MessageP
130}114}
131 115 
132 116
133-ErrCode BluetoothAvrcpTgStub::ConnectInner(MessageParcel &data, MessageParcel &reply)117+int32_t BluetoothAvrcpTgStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
134{118{
135 HILOGI("BluetoothAvrcpTgStub::ConnectInner starts");119 HILOGI("BluetoothAvrcpTgStub::ConnectInner starts");
136 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());120 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -147,7 +131,7 @@ ErrCode BluetoothAvrcpTgStub::ConnectInner(MessageParcel &data, MessageParcel &r
147 return NO_ERROR;131 return NO_ERROR;
148}132}
149 133 
150-ErrCode BluetoothAvrcpTgStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)134+int32_t BluetoothAvrcpTgStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
151{135{
152 HILOGI("BluetoothAvrcpTgStub::DisconnectInner starts");136 HILOGI("BluetoothAvrcpTgStub::DisconnectInner starts");
153 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());137 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -165,7 +149,7 @@ ErrCode BluetoothAvrcpTgStub::DisconnectInner(MessageParcel &data, MessageParcel
165 return NO_ERROR;149 return NO_ERROR;
166}150}
167 151 
168-ErrCode BluetoothAvrcpTgStub::GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply)152+int32_t BluetoothAvrcpTgStub::GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply)
169{153{
170 HILOGI("BluetoothAvrcpTgStub::GetConnectedDevicesInner starts");154 HILOGI("BluetoothAvrcpTgStub::GetConnectedDevicesInner starts");
171 std::vector<BluetoothRawAddress> result = GetConnectedDevices();155 std::vector<BluetoothRawAddress> result = GetConnectedDevices();
@@ -180,7 +164,7 @@ ErrCode BluetoothAvrcpTgStub::GetConnectedDevicesInner(MessageParcel &data, Mess
180 return NO_ERROR;164 return NO_ERROR;
181}165}
182 166 
183-ErrCode BluetoothAvrcpTgStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)167+int32_t BluetoothAvrcpTgStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
184{168{
185 int32_t statesSize = data.ReadInt32();169 int32_t statesSize = data.ReadInt32();
186 if (IsInvalidAttributesSize(statesSize)) {170 if (IsInvalidAttributesSize(statesSize)) {
@@ -205,7 +189,7 @@ ErrCode BluetoothAvrcpTgStub::GetDevicesByStatesInner(MessageParcel &data, Messa
205 return NO_ERROR;189 return NO_ERROR;
206}190}
207 191 
208-ErrCode BluetoothAvrcpTgStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)192+int32_t BluetoothAvrcpTgStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
209{193{
210 HILOGI("BluetoothAvrcpTgStub::GetDeviceStateInner starts");194 HILOGI("BluetoothAvrcpTgStub::GetDeviceStateInner starts");
211 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());195 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -222,7 +206,7 @@ ErrCode BluetoothAvrcpTgStub::GetDeviceStateInner(MessageParcel &data, MessagePa
222 return NO_ERROR;206 return NO_ERROR;
223}207}
224 208 
225-ErrCode BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner(MessageParcel &data, MessageParcel &reply)209+int32_t BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner(MessageParcel &data, MessageParcel &reply)
226{210{
227 HILOGI("BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner starts");211 HILOGI("BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner starts");
228 int32_t playStatus = data.ReadInt32();212 int32_t playStatus = data.ReadInt32();
@@ -232,7 +216,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyPlaybackStatusChangedInner(MessageParcel &da
232 return NO_ERROR;216 return NO_ERROR;
233}217}
234 218 
235-ErrCode BluetoothAvrcpTgStub::NotifyTrackChangedInner(MessageParcel &data, MessageParcel &reply)219+int32_t BluetoothAvrcpTgStub::NotifyTrackChangedInner(MessageParcel &data, MessageParcel &reply)
236{220{
237 HILOGI("BluetoothAvrcpTgStub::NotifyTrackChangedInner starts");221 HILOGI("BluetoothAvrcpTgStub::NotifyTrackChangedInner starts");
238 long uid = data.ReadInt64();222 long uid = data.ReadInt64();
@@ -242,7 +226,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyTrackChangedInner(MessageParcel &data, Messa
242 return NO_ERROR;226 return NO_ERROR;
243}227}
244 228 
245-ErrCode BluetoothAvrcpTgStub::NotifyTrackReachedEndInner(MessageParcel &data, MessageParcel &reply)229+int32_t BluetoothAvrcpTgStub::NotifyTrackReachedEndInner(MessageParcel &data, MessageParcel &reply)
246{230{
247 HILOGI("BluetoothAvrcpTgStub::NotifyTrackReachedEndInner starts");231 HILOGI("BluetoothAvrcpTgStub::NotifyTrackReachedEndInner starts");
248 int32_t playbackPos = data.ReadInt32();232 int32_t playbackPos = data.ReadInt32();
@@ -251,7 +235,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyTrackReachedEndInner(MessageParcel &data, Me
251 return NO_ERROR;235 return NO_ERROR;
252}236}
253 237 
254-ErrCode BluetoothAvrcpTgStub::NotifyTrackReachedStartInner(MessageParcel &data, MessageParcel &reply)238+int32_t BluetoothAvrcpTgStub::NotifyTrackReachedStartInner(MessageParcel &data, MessageParcel &reply)
255{239{
256 HILOGI("BluetoothAvrcpTgStub::NotifyTrackReachedStartInner starts");240 HILOGI("BluetoothAvrcpTgStub::NotifyTrackReachedStartInner starts");
257 int32_t playbackPos = data.ReadInt32();241 int32_t playbackPos = data.ReadInt32();
@@ -260,7 +244,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyTrackReachedStartInner(MessageParcel &data,
260 return NO_ERROR;244 return NO_ERROR;
261}245}
262 246 
263-ErrCode BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner(MessageParcel &data, MessageParcel &reply)247+int32_t BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner(MessageParcel &data, MessageParcel &reply)
264{248{
265 HILOGI("BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner starts");249 HILOGI("BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner starts");
266 int32_t playbackPos = data.ReadInt32();250 int32_t playbackPos = data.ReadInt32();
@@ -269,7 +253,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyPlaybackPosChangedInner(MessageParcel &data,
269 return NO_ERROR;253 return NO_ERROR;
270}254}
271 255 
272-ErrCode BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner(MessageParcel &data, MessageParcel &reply)256+int32_t BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner(MessageParcel &data, MessageParcel &reply)
273{257{
274 HILOGI("BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner starts");258 HILOGI("BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner starts");
275 int32_t attributesSize = data.ReadInt32();259 int32_t attributesSize = data.ReadInt32();
@@ -298,7 +282,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyPlayerAppSettingChangedInner(MessageParcel &
298 return NO_ERROR;282 return NO_ERROR;
299}283}
300 284 
301-ErrCode BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner(MessageParcel &data, MessageParcel &reply)285+int32_t BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner(MessageParcel &data, MessageParcel &reply)
302{286{
303 HILOGI("BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner starts");287 HILOGI("BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner starts");
304 288 
@@ -306,7 +290,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyNowPlayingContentChangedInner(MessageParcel
306 return NO_ERROR;290 return NO_ERROR;
307}291}
308 292 
309-ErrCode BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner(MessageParcel &data, MessageParcel &reply)293+int32_t BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner(MessageParcel &data, MessageParcel &reply)
310{294{
311 HILOGI("BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner starts");295 HILOGI("BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner starts");
312 296 
@@ -314,7 +298,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyAvailablePlayersChangedInner(MessageParcel &
314 return NO_ERROR;298 return NO_ERROR;
315}299}
316 300 
317-ErrCode BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner(MessageParcel &data, MessageParcel &reply)301+int32_t BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner(MessageParcel &data, MessageParcel &reply)
318{302{
319 HILOGI("BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner starts");303 HILOGI("BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner starts");
320 int32_t playerId = data.ReadInt32();304 int32_t playerId = data.ReadInt32();
@@ -324,7 +308,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyAddressedPlayerChangedInner(MessageParcel &d
324 return NO_ERROR;308 return NO_ERROR;
325}309}
326 310 
327-ErrCode BluetoothAvrcpTgStub::NotifyUidChangedInner(MessageParcel &data, MessageParcel &reply)311+int32_t BluetoothAvrcpTgStub::NotifyUidChangedInner(MessageParcel &data, MessageParcel &reply)
328{312{
329 HILOGI("BluetoothAvrcpTgStub::NotifyUidChangedInner starts");313 HILOGI("BluetoothAvrcpTgStub::NotifyUidChangedInner starts");
330 int32_t uidCounter = data.ReadInt32();314 int32_t uidCounter = data.ReadInt32();
@@ -333,7 +317,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyUidChangedInner(MessageParcel &data, Message
333 return NO_ERROR;317 return NO_ERROR;
334}318}
335 319 
336-ErrCode BluetoothAvrcpTgStub::NotifyVolumeChangedInner(MessageParcel &data, MessageParcel &reply)320+int32_t BluetoothAvrcpTgStub::NotifyVolumeChangedInner(MessageParcel &data, MessageParcel &reply)
337{321{
338 HILOGI("BluetoothAvrcpTgStub::NotifyVolumeChangedInner starts");322 HILOGI("BluetoothAvrcpTgStub::NotifyVolumeChangedInner starts");
339 int32_t volume = data.ReadInt32();323 int32_t volume = data.ReadInt32();
@@ -342,7 +326,7 @@ ErrCode BluetoothAvrcpTgStub::NotifyVolumeChangedInner(MessageParcel &data, Mess
342 return NO_ERROR;326 return NO_ERROR;
343}327}
344 328 
345-ErrCode BluetoothAvrcpTgStub::SetDeviceAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)329+int32_t BluetoothAvrcpTgStub::SetDeviceAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)
346{330{
347 HILOGI("enter");331 HILOGI("enter");
348 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());332 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -357,7 +341,7 @@ ErrCode BluetoothAvrcpTgStub::SetDeviceAbsoluteVolumeInner(MessageParcel &data,
357 }341 }
358 return NO_ERROR;342 return NO_ERROR;
359}343}
360-ErrCode BluetoothAvrcpTgStub::SetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply)344+int32_t BluetoothAvrcpTgStub::SetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply)
361{345{
362 HILOGI("enter");346 HILOGI("enter");
363 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());347 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
@@ -371,7 +355,7 @@ ErrCode BluetoothAvrcpTgStub::SetDeviceAbsVolumeAbilityInner(MessageParcel &data
371 }355 }
372 return NO_ERROR;356 return NO_ERROR;
373}357}
374-ErrCode BluetoothAvrcpTgStub::GetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply)358+int32_t BluetoothAvrcpTgStub::GetDeviceAbsVolumeAbilityInner(MessageParcel &data, MessageParcel &reply)
375{359{
376 HILOGI("enter");360 HILOGI("enter");
377 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());361 std::shared_ptr<BluetoothRawAddress> addr(data.ReadParcelable<BluetoothRawAddress>());
Mservices/bluetooth/ipc/src/bluetooth_ble_advertiser_stub.cpp+39-59
@@ -20,34 +20,37 @@
20#include "ipc_types.h"20#include "ipc_types.h"
21#include "parcel_bt_uuid.h"21#include "parcel_bt_uuid.h"
22#include "bt_def.h"22#include "bt_def.h"
23+#include "permission_manager.h"
24+ 
25+#ifdef STUB_FUNC
26+#undef STUB_FUNC
27+#endif
28+#define STUB_FUNC(code, func, perm) \
29+BluetoothBleAdvertiserInterfaceCode::code, {&BluetoothBleAdvertiserStub::func, perm} \
23 30 
24-using std::placeholders::_1;
25-using std::placeholders::_2;
26-using std::placeholders::_3;
27namespace OHOS {31namespace OHOS {
28namespace Bluetooth {32namespace Bluetooth {
29-const std::map<uint32_t, std::function<ErrCode(BluetoothBleAdvertiserStub *, MessageParcel &, MessageParcel &)>>33+using namespace OHOS::bluetooth;
30- BluetoothBleAdvertiserStub::interfaces_ = {34+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
31- {BluetoothBleAdvertiserInterfaceCode::BLE_REGISTER_BLE_ADVERTISER_CALLBACK,35+const BluetoothBleAdvertiserStub::BleAdvertiserStubFuncMap BluetoothBleAdvertiserStub::memberFuncMap_ = {
32- std::bind(&BluetoothBleAdvertiserStub::RegisterBleAdvertiserCallbackInner, _1, _2, _3)},36+ {STUB_FUNC(BLE_REGISTER_BLE_ADVERTISER_CALLBACK, RegisterBleAdvertiserCallbackInner, nullptr)},
33- {BluetoothBleAdvertiserInterfaceCode::BLE_DE_REGISTER_BLE_ADVERTISER_CALLBACK,37+ {STUB_FUNC(BLE_DE_REGISTER_BLE_ADVERTISER_CALLBACK, DeregisterBleAdvertiserCallbackInner, nullptr)},
34- std::bind(&BluetoothBleAdvertiserStub::DeregisterBleAdvertiserCallbackInner, _1, _2, _3)},38+ {STUB_FUNC(BLE_START_ADVERTISING, StartAdvertisingInner,
35- {BluetoothBleAdvertiserInterfaceCode::BLE_START_ADVERTISING,39+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
36- std::bind(&BluetoothBleAdvertiserStub::StartAdvertisingInner, _1, _2, _3)},40+ {STUB_FUNC(BLE_ENABLE_ADVERTISING, EnableAdvertisingInner,
37- {BluetoothBleAdvertiserInterfaceCode::BLE_ENABLE_ADVERTISING,41+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
38- std::bind(&BluetoothBleAdvertiserStub::EnableAdvertisingInner, _1, _2, _3)},42+ {STUB_FUNC(BLE_DISABLE_ADVERTISING, DisableAdvertisingInner,
39- {BluetoothBleAdvertiserInterfaceCode::BLE_DISABLE_ADVERTISING,43+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
40- std::bind(&BluetoothBleAdvertiserStub::DisableAdvertisingInner, _1, _2, _3)},44+ {STUB_FUNC(BLE_STOP_ADVERTISING, StopAdvertisingInner,
41- {BluetoothBleAdvertiserInterfaceCode::BLE_STOP_ADVERTISING,45+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
42- std::bind(&BluetoothBleAdvertiserStub::StopAdvertisingInner, _1, _2, _3)},46+ {STUB_FUNC(BLE_CLOSE, CloseInner,
43- {BluetoothBleAdvertiserInterfaceCode::BLE_CLOSE,47+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
44- std::bind(&BluetoothBleAdvertiserStub::CloseInner, _1, _2, _3)},48+ {STUB_FUNC(BLE_GET_ADVERTISER_HANDLE, GetAdvertiserHandleInner,
45- {BluetoothBleAdvertiserInterfaceCode::BLE_GET_ADVERTISER_HANDLE,49+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
46- std::bind(&BluetoothBleAdvertiserStub::GetAdvertiserHandleInner, _1, _2, _3)},50+ {STUB_FUNC(BLE_SET_ADVERTISING_DATA, SetAdvertisingDataInner,
47- {BluetoothBleAdvertiserInterfaceCode::BLE_SET_ADVERTISING_DATA,51+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48- std::bind(&BluetoothBleAdvertiserStub::SetAdvertisingDataInner, _1, _2, _3)},52+ {STUB_FUNC(BLE_CHANGE_ADVERTISING_PARAMS, ChangeAdvertisingParamsInner,
49- {BluetoothBleAdvertiserInterfaceCode::BLE_CHANGE_ADVERTISING_PARAMS,53+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
50- std::bind(&BluetoothBleAdvertiserStub::ChangeAdvertisingParamsInner, _1, _2, _3)},
51};54};
52 55 
53BluetoothBleAdvertiserStub::BluetoothBleAdvertiserStub()56BluetoothBleAdvertiserStub::BluetoothBleAdvertiserStub()
@@ -59,33 +62,10 @@ BluetoothBleAdvertiserStub::~BluetoothBleAdvertiserStub()
59int BluetoothBleAdvertiserStub::OnRemoteRequest(62int BluetoothBleAdvertiserStub::OnRemoteRequest(
60 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)63 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
61{64{
62- if (BluetoothBleAdvertiserStub::GetDescriptor() != data.ReadInterfaceToken()) {65+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothBleAdvertiserStub);
63- HILOGW("[OnRemoteRequest] fail: invalid interface token!");
64- return OBJECT_NULL;
65- }
66- 
67- auto it = interfaces_.find(code);
68- if (it == interfaces_.end()) {
69- HILOGW("[OnRemoteRequest] fail: unknown code!");
70- return IRemoteStub<IBluetoothBleAdvertiser>::OnRemoteRequest(code, data, reply, option);
71- }
72- 
73- auto fun = it->second;
74- if (fun == nullptr) {
75- HILOGW("[OnRemoteRequest] fail: not find function!");
76- return IRemoteStub<IBluetoothBleAdvertiser>::OnRemoteRequest(code, data, reply, option);
77- }
78- 
79- ErrCode result = fun(this, data, reply);
80- if (SUCCEEDED(result)) {
81- return NO_ERROR;
82- }
83- 
84- HILOGW("[OnRemoteRequest] fail: Failed to call interface %{public}u, err:%{public}d", code, result);
85- return result;
86}66}
87 67 
88-ErrCode BluetoothBleAdvertiserStub::RegisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply)68+int32_t BluetoothBleAdvertiserStub::RegisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply)
89{69{
90 sptr<IRemoteObject> remote = data.ReadRemoteObject();70 sptr<IRemoteObject> remote = data.ReadRemoteObject();
91 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);71 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);
@@ -93,7 +73,7 @@ ErrCode BluetoothBleAdvertiserStub::RegisterBleAdvertiserCallbackInner(MessagePa
93 return NO_ERROR;73 return NO_ERROR;
94}74}
95 75 
96-ErrCode BluetoothBleAdvertiserStub::DeregisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply)76+int32_t BluetoothBleAdvertiserStub::DeregisterBleAdvertiserCallbackInner(MessageParcel &data, MessageParcel &reply)
97{77{
98 sptr<IRemoteObject> remote = data.ReadRemoteObject();78 sptr<IRemoteObject> remote = data.ReadRemoteObject();
99 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);79 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);
@@ -101,7 +81,7 @@ ErrCode BluetoothBleAdvertiserStub::DeregisterBleAdvertiserCallbackInner(Message
101 return NO_ERROR;81 return NO_ERROR;
102}82}
103 83 
104-ErrCode BluetoothBleAdvertiserStub::StartAdvertisingInner(MessageParcel &data, MessageParcel &reply)84+int32_t BluetoothBleAdvertiserStub::StartAdvertisingInner(MessageParcel &data, MessageParcel &reply)
105{85{
106 std::shared_ptr<BluetoothBleAdvertiserSettings> settings(data.ReadParcelable<BluetoothBleAdvertiserSettings>());86 std::shared_ptr<BluetoothBleAdvertiserSettings> settings(data.ReadParcelable<BluetoothBleAdvertiserSettings>());
107 if (settings == nullptr) {87 if (settings == nullptr) {
@@ -131,7 +111,7 @@ ErrCode BluetoothBleAdvertiserStub::StartAdvertisingInner(MessageParcel &data, M
131 return NO_ERROR;111 return NO_ERROR;
132}112}
133 113 
134-ErrCode BluetoothBleAdvertiserStub::EnableAdvertisingInner(MessageParcel &data, MessageParcel &reply)114+int32_t BluetoothBleAdvertiserStub::EnableAdvertisingInner(MessageParcel &data, MessageParcel &reply)
135{115{
136 uint8_t advHandle = data.ReadUint8();116 uint8_t advHandle = data.ReadUint8();
137 uint16_t duration = data.ReadUint16();117 uint16_t duration = data.ReadUint16();
@@ -143,7 +123,7 @@ ErrCode BluetoothBleAdvertiserStub::EnableAdvertisingInner(MessageParcel &data,
143 return NO_ERROR;123 return NO_ERROR;
144}124}
145 125 
146-ErrCode BluetoothBleAdvertiserStub::DisableAdvertisingInner(MessageParcel &data, MessageParcel &reply)126+int32_t BluetoothBleAdvertiserStub::DisableAdvertisingInner(MessageParcel &data, MessageParcel &reply)
147{127{
148 uint8_t advHandle = data.ReadUint8();128 uint8_t advHandle = data.ReadUint8();
149 int32_t ret = DisableAdvertising(advHandle);129 int32_t ret = DisableAdvertising(advHandle);
@@ -154,7 +134,7 @@ ErrCode BluetoothBleAdvertiserStub::DisableAdvertisingInner(MessageParcel &data,
154 return NO_ERROR;134 return NO_ERROR;
155}135}
156 136 
157-ErrCode BluetoothBleAdvertiserStub::StopAdvertisingInner(MessageParcel &data, MessageParcel &reply)137+int32_t BluetoothBleAdvertiserStub::StopAdvertisingInner(MessageParcel &data, MessageParcel &reply)
158{138{
159 int32_t advHandle = data.ReadInt32();139 int32_t advHandle = data.ReadInt32();
160 int32_t ret = StopAdvertising(advHandle);140 int32_t ret = StopAdvertising(advHandle);
@@ -165,14 +145,14 @@ ErrCode BluetoothBleAdvertiserStub::StopAdvertisingInner(MessageParcel &data, Me
165 return NO_ERROR;145 return NO_ERROR;
166}146}
167 147 
168-ErrCode BluetoothBleAdvertiserStub::CloseInner(MessageParcel &data, MessageParcel &reply)148+int32_t BluetoothBleAdvertiserStub::CloseInner(MessageParcel &data, MessageParcel &reply)
169{149{
170 int32_t advHandle = data.ReadInt32();150 int32_t advHandle = data.ReadInt32();
171 Close(advHandle);151 Close(advHandle);
172 return NO_ERROR;152 return NO_ERROR;
173}153}
174 154 
175-ErrCode BluetoothBleAdvertiserStub::GetAdvertiserHandleInner(MessageParcel &data, MessageParcel &reply)155+int32_t BluetoothBleAdvertiserStub::GetAdvertiserHandleInner(MessageParcel &data, MessageParcel &reply)
176{156{
177 sptr<IRemoteObject> remote = data.ReadRemoteObject();157 sptr<IRemoteObject> remote = data.ReadRemoteObject();
178 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);158 const sptr<IBluetoothBleAdvertiseCallback> callBack = OHOS::iface_cast<IBluetoothBleAdvertiseCallback>(remote);
@@ -187,12 +167,12 @@ ErrCode BluetoothBleAdvertiserStub::GetAdvertiserHandleInner(MessageParcel &data
187 return NO_ERROR;167 return NO_ERROR;
188}168}
189 169 
190-ErrCode BluetoothBleAdvertiserStub::SetAdvertisingDataInner(MessageParcel &data, MessageParcel &reply)170+int32_t BluetoothBleAdvertiserStub::SetAdvertisingDataInner(MessageParcel &data, MessageParcel &reply)
191{171{
192 return NO_ERROR;172 return NO_ERROR;
193}173}
194 174 
195-ErrCode BluetoothBleAdvertiserStub::ChangeAdvertisingParamsInner(MessageParcel &data, MessageParcel &reply)175+int32_t BluetoothBleAdvertiserStub::ChangeAdvertisingParamsInner(MessageParcel &data, MessageParcel &reply)
196{176{
197 int advHandle = data.ReadUint8();177 int advHandle = data.ReadUint8();
198 std::shared_ptr<BluetoothBleAdvertiserSettings> settings(data.ReadParcelable<BluetoothBleAdvertiserSettings>());178 std::shared_ptr<BluetoothBleAdvertiserSettings> settings(data.ReadParcelable<BluetoothBleAdvertiserSettings>());
Mservices/bluetooth/ipc/src/bluetooth_ble_central_manager_stub.cpp+58-94
@@ -21,63 +21,50 @@
21#include "ipc_types.h"21#include "ipc_types.h"
22#include "parcel_bt_uuid.h"22#include "parcel_bt_uuid.h"
23#include "bluetooth_bt_uuid.h"23#include "bluetooth_bt_uuid.h"
24+#include "bluetooth_errorcode.h"
25+#include "permission_manager.h"
26+ 
27+#ifdef STUB_FUNC
28+#undef STUB_FUNC
29+#endif
30+#define STUB_FUNC(code, func, perm) \
31+BluetoothBleCentralManagerInterfaceCode::code, {&BluetoothBleCentralManagerStub::func, perm} \
24 32 
25namespace OHOS {33namespace OHOS {
26namespace Bluetooth {34namespace Bluetooth {
35+using namespace OHOS::bluetooth;
27const int32_t BLE_CENTRAL_MANAGER_STUB_READ_DATA_SIZE_MAX_LEN = 0x100;36const int32_t BLE_CENTRAL_MANAGER_STUB_READ_DATA_SIZE_MAX_LEN = 0x100;
28-const std::map<uint32_t, std::function<ErrCode(BluetoothBleCentralManagerStub *, MessageParcel &, MessageParcel &)>>37+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
29- BluetoothBleCentralManagerStub::interfaces_ = {38+const BluetoothBleCentralManagerStub::BleCentralManagerStubFuncMap BluetoothBleCentralManagerStub::memberFuncMap_ = {
30- {BluetoothBleCentralManagerInterfaceCode::BLE_REGISTER_BLE_CENTRAL_MANAGER_CALLBACK,39+ {STUB_FUNC(BLE_REGISTER_BLE_CENTRAL_MANAGER_CALLBACK, RegisterBleCentralManagerCallbackInner, nullptr)},
31- std::bind(&BluetoothBleCentralManagerStub::RegisterBleCentralManagerCallbackInner, std::placeholders::_1,40+ {STUB_FUNC(BLE_DE_REGISTER_BLE_CENTRAL_MANAGER_CALLBACK, DeregisterBleCentralManagerCallbackInner, nullptr)},
32- std::placeholders::_2, std::placeholders::_3)},41+ {STUB_FUNC(BLE_START_SCAN, StartScanInner, nullptr)},
33- {BluetoothBleCentralManagerInterfaceCode::BLE_DE_REGISTER_BLE_CENTRAL_MANAGER_CALLBACK,42+ {STUB_FUNC(BLE_REMOVE_SCAN_FILTER, RemoveScanFilterInner,
34- std::bind(&BluetoothBleCentralManagerStub::DeregisterBleCentralManagerCallbackInner, std::placeholders::_1,43+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
35- std::placeholders::_2, std::placeholders::_3)},44+ {STUB_FUNC(BLE_STOP_SCAN, StopScanInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
36- {BluetoothBleCentralManagerInterfaceCode::BLE_START_SCAN,45+ {STUB_FUNC(BLE_FREEZE_BY_RSS, FreezeByRssInner,
37- std::bind(&BluetoothBleCentralManagerStub::StartScanInner, std::placeholders::_1, std::placeholders::_2,46+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
38- std::placeholders::_3)},47+ {STUB_FUNC(BLE_RESET_ALL_PROXY, ResetAllProxyInner,
39- {BluetoothBleCentralManagerInterfaceCode::BLE_REMOVE_SCAN_FILTER,48+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
40- std::bind(&BluetoothBleCentralManagerStub::RemoveScanFilterInner, std::placeholders::_1,49+ {STUB_FUNC(BLE_SET_LPDEVICE_ADV_PARAM, SetLpDeviceAdvParamInner,
41- std::placeholders::_2, std::placeholders::_3)},50+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
42- {BluetoothBleCentralManagerInterfaceCode::BLE_STOP_SCAN,51+ {STUB_FUNC(BLE_SET_SCAN_REPORT_CHANNEL_TO_LPDEVICE, SetScanReportChannelToLpDeviceInner,
43- std::bind(&BluetoothBleCentralManagerStub::StopScanInner, std::placeholders::_1, std::placeholders::_2,52+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
44- std::placeholders::_3)},53+ {STUB_FUNC(BLE_ENABLE_SYNC_DATA_TO_LPDEVICE, EnableSyncDataToLpDeviceInner,
45- {BluetoothBleCentralManagerInterfaceCode::BLE_FREEZE_BY_RSS,54+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
46- std::bind(&BluetoothBleCentralManagerStub::FreezeByRssInner, std::placeholders::_1, std::placeholders::_2,55+ {STUB_FUNC(BLE_DISABLE_SYNC_DATA_TO_LPDEVICE, DisableSyncDataToLpDeviceInner,
47- std::placeholders::_3)},56+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48- {BluetoothBleCentralManagerInterfaceCode::BLE_RESET_ALL_PROXY,57+ {STUB_FUNC(BLE_SEND_PARAMS_TO_LPDEVICE, SendParamsToLpDeviceInner,
49- std::bind(&BluetoothBleCentralManagerStub::ResetAllProxyInner, std::placeholders::_1, std::placeholders::_2,58+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
50- std::placeholders::_3)},59+ {STUB_FUNC(BLE_IS_LPDEVICE_AVAILABLE, IsLpDeviceAvailableInner,
51- {BluetoothBleCentralManagerInterfaceCode::BLE_SET_LPDEVICE_ADV_PARAM,60+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
52- std::bind(&BluetoothBleCentralManagerStub::SetLpDeviceAdvParamInner, std::placeholders::_1,61+ {STUB_FUNC(BLE_SET_LPDEVICE_PARAM, SetLpDeviceParamInner,
53- std::placeholders::_2, std::placeholders::_3)},62+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
54- {BluetoothBleCentralManagerInterfaceCode::BLE_SET_SCAN_REPORT_CHANNEL_TO_LPDEVICE,63+ {STUB_FUNC(BLE_REMOVE_LPDEVICE_PARAM, RemoveLpDeviceParamInner,
55- std::bind(&BluetoothBleCentralManagerStub::SetScanReportChannelToLpDeviceInner, std::placeholders::_1,64+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
56- std::placeholders::_2, std::placeholders::_3)},65+ {STUB_FUNC(BLE_CHANGE_SCAN_PARAM, ChangeScanParamsInner,
57- {BluetoothBleCentralManagerInterfaceCode::BLE_ENABLE_SYNC_DATA_TO_LPDEVICE,66+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
58- std::bind(&BluetoothBleCentralManagerStub::EnableSyncDataToLpDeviceInner, std::placeholders::_1,67+ {STUB_FUNC(BLE_IS_VALID_SCANNERID, IsValidScannerIdInner, nullptr)},
59- std::placeholders::_2, std::placeholders::_3)},
60- {BluetoothBleCentralManagerInterfaceCode::BLE_DISABLE_SYNC_DATA_TO_LPDEVICE,
61- std::bind(&BluetoothBleCentralManagerStub::DisableSyncDataToLpDeviceInner, std::placeholders::_1,
62- std::placeholders::_2, std::placeholders::_3)},
63- {BluetoothBleCentralManagerInterfaceCode::BLE_SEND_PARAMS_TO_LPDEVICE,
64- std::bind(&BluetoothBleCentralManagerStub::SendParamsToLpDeviceInner, std::placeholders::_1,
65- std::placeholders::_2, std::placeholders::_3)},
66- {BluetoothBleCentralManagerInterfaceCode::BLE_IS_LPDEVICE_AVAILABLE,
67- std::bind(&BluetoothBleCentralManagerStub::IsLpDeviceAvailableInner, std::placeholders::_1,
68- std::placeholders::_2, std::placeholders::_3)},
69- {BluetoothBleCentralManagerInterfaceCode::BLE_SET_LPDEVICE_PARAM,
70- std::bind(&BluetoothBleCentralManagerStub::SetLpDeviceParamInner, std::placeholders::_1,
71- std::placeholders::_2, std::placeholders::_3)},
72- {BluetoothBleCentralManagerInterfaceCode::BLE_REMOVE_LPDEVICE_PARAM,
73- std::bind(&BluetoothBleCentralManagerStub::RemoveLpDeviceParamInner, std::placeholders::_1,
74- std::placeholders::_2, std::placeholders::_3)},
75- {BluetoothBleCentralManagerInterfaceCode::BLE_CHANGE_SCAN_PARAM,
76- std::bind(&BluetoothBleCentralManagerStub::ChangeScanParamsInner, std::placeholders::_1,
77- std::placeholders::_2, std::placeholders::_3)},
78- {BluetoothBleCentralManagerInterfaceCode::BLE_IS_VALID_SCANNERID,
79- std::bind(&BluetoothBleCentralManagerStub::IsValidScannerIdInner, std::placeholders::_1,
80- std::placeholders::_2, std::placeholders::_3)},
81};68};
82 69 
83BluetoothBleCentralManagerStub::BluetoothBleCentralManagerStub()70BluetoothBleCentralManagerStub::BluetoothBleCentralManagerStub()
@@ -89,33 +76,10 @@ BluetoothBleCentralManagerStub::~BluetoothBleCentralManagerStub()
89int BluetoothBleCentralManagerStub::OnRemoteRequest(76int BluetoothBleCentralManagerStub::OnRemoteRequest(
90 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)77 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
91{78{
92- if (BluetoothBleCentralManagerStub::GetDescriptor() != data.ReadInterfaceToken()) {79+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothBleCentralManagerStub);
93- HILOGW("[OnRemoteRequest] fail: invalid interface token!");
94- return OBJECT_NULL;
95- }
96- 
97- auto it = interfaces_.find(code);
98- if (it == interfaces_.end()) {
99- HILOGW("[OnRemoteRequest] fail: unknown code!");
100- return IRemoteStub<IBluetoothBleCentralManager>::OnRemoteRequest(code, data, reply, option);
101- }
102- 
103- auto fun = it->second;
104- if (fun == nullptr) {
105- HILOGW("[OnRemoteRequest] fail: not find function!");
106- return IRemoteStub<IBluetoothBleCentralManager>::OnRemoteRequest(code, data, reply, option);
107- }
108- 
109- ErrCode result = fun(this, data, reply);
110- if (SUCCEEDED(result)) {
111- return NO_ERROR;
112- }
113- 
114- HILOGW("[OnRemoteRequest] fail: Failed to call interface %{public}u, err:%{public}d", code, result);
115- return result;
116}80}
117 81 
118-ErrCode BluetoothBleCentralManagerStub::RegisterBleCentralManagerCallbackInner(82+int32_t BluetoothBleCentralManagerStub::RegisterBleCentralManagerCallbackInner(
119 MessageParcel &data, MessageParcel &reply)83 MessageParcel &data, MessageParcel &reply)
120{84{
121 sptr<IRemoteObject> remote = data.ReadRemoteObject();85 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -131,7 +95,7 @@ ErrCode BluetoothBleCentralManagerStub::RegisterBleCentralManagerCallbackInner(
131 return NO_ERROR;95 return NO_ERROR;
132}96}
133 97 
134-ErrCode BluetoothBleCentralManagerStub::DeregisterBleCentralManagerCallbackInner(98+int32_t BluetoothBleCentralManagerStub::DeregisterBleCentralManagerCallbackInner(
135 MessageParcel &data, MessageParcel &reply)99 MessageParcel &data, MessageParcel &reply)
136{100{
137 int32_t scannerId = data.ReadInt32();101 int32_t scannerId = data.ReadInt32();
@@ -142,7 +106,7 @@ ErrCode BluetoothBleCentralManagerStub::DeregisterBleCentralManagerCallbackInner
142 return NO_ERROR;106 return NO_ERROR;
143}107}
144 108 
145-ErrCode BluetoothBleCentralManagerStub::StartScanInner(MessageParcel &data, MessageParcel &reply)109+int32_t BluetoothBleCentralManagerStub::StartScanInner(MessageParcel &data, MessageParcel &reply)
146{110{
147 int32_t scannerId = data.ReadInt32();111 int32_t scannerId = data.ReadInt32();
148 std::shared_ptr<BluetoothBleScanSettings> settings(data.ReadParcelable<BluetoothBleScanSettings>());112 std::shared_ptr<BluetoothBleScanSettings> settings(data.ReadParcelable<BluetoothBleScanSettings>());
@@ -176,7 +140,7 @@ ErrCode BluetoothBleCentralManagerStub::StartScanInner(MessageParcel &data, Mess
176 return NO_ERROR;140 return NO_ERROR;
177}141}
178 142 
179-ErrCode BluetoothBleCentralManagerStub::StopScanInner(MessageParcel &data, MessageParcel &reply)143+int32_t BluetoothBleCentralManagerStub::StopScanInner(MessageParcel &data, MessageParcel &reply)
180{144{
181 int32_t scannerId = data.ReadInt32();145 int32_t scannerId = data.ReadInt32();
182 int ret = StopScan(scannerId);146 int ret = StopScan(scannerId);
@@ -187,7 +151,7 @@ ErrCode BluetoothBleCentralManagerStub::StopScanInner(MessageParcel &data, Messa
187 return NO_ERROR;151 return NO_ERROR;
188}152}
189 153 
190-ErrCode BluetoothBleCentralManagerStub::RemoveScanFilterInner(MessageParcel &data, MessageParcel &reply)154+int32_t BluetoothBleCentralManagerStub::RemoveScanFilterInner(MessageParcel &data, MessageParcel &reply)
191{155{
192 int32_t scannerId = data.ReadInt32();156 int32_t scannerId = data.ReadInt32();
193 157 
@@ -195,7 +159,7 @@ ErrCode BluetoothBleCentralManagerStub::RemoveScanFilterInner(MessageParcel &dat
195 return NO_ERROR;159 return NO_ERROR;
196}160}
197 161 
198-ErrCode BluetoothBleCentralManagerStub::FreezeByRssInner(MessageParcel &data, MessageParcel &reply)162+int32_t BluetoothBleCentralManagerStub::FreezeByRssInner(MessageParcel &data, MessageParcel &reply)
199{163{
200 std::vector<int> pidVec {};164 std::vector<int> pidVec {};
201 CHECK_AND_RETURN_LOG_RET(data.ReadInt32Vector(&pidVec), ERR_INVALID_VALUE, "ipc failed");165 CHECK_AND_RETURN_LOG_RET(data.ReadInt32Vector(&pidVec), ERR_INVALID_VALUE, "ipc failed");
@@ -210,7 +174,7 @@ ErrCode BluetoothBleCentralManagerStub::FreezeByRssInner(MessageParcel &data, Me
210 return NO_ERROR;174 return NO_ERROR;
211}175}
212 176 
213-ErrCode BluetoothBleCentralManagerStub::ResetAllProxyInner(MessageParcel &data, MessageParcel &reply)177+int32_t BluetoothBleCentralManagerStub::ResetAllProxyInner(MessageParcel &data, MessageParcel &reply)
214{178{
215 bool ret = ResetAllProxy();179 bool ret = ResetAllProxy();
216 if (!reply.WriteBool(ret)) {180 if (!reply.WriteBool(ret)) {
@@ -219,47 +183,47 @@ ErrCode BluetoothBleCentralManagerStub::ResetAllProxyInner(MessageParcel &data,
219 return NO_ERROR;183 return NO_ERROR;
220}184}
221 185 
222-ErrCode BluetoothBleCentralManagerStub::SetLpDeviceAdvParamInner(MessageParcel &data, MessageParcel &reply)186+int32_t BluetoothBleCentralManagerStub::SetLpDeviceAdvParamInner(MessageParcel &data, MessageParcel &reply)
223{187{
224 return NO_ERROR;188 return NO_ERROR;
225}189}
226 190 
227-ErrCode BluetoothBleCentralManagerStub::SetScanReportChannelToLpDeviceInner(MessageParcel &data, MessageParcel &reply)191+int32_t BluetoothBleCentralManagerStub::SetScanReportChannelToLpDeviceInner(MessageParcel &data, MessageParcel &reply)
228{192{
229 return NO_ERROR;193 return NO_ERROR;
230}194}
231 195 
232-ErrCode BluetoothBleCentralManagerStub::EnableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply)196+int32_t BluetoothBleCentralManagerStub::EnableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply)
233{197{
234 return NO_ERROR;198 return NO_ERROR;
235}199}
236 200 
237-ErrCode BluetoothBleCentralManagerStub::DisableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply)201+int32_t BluetoothBleCentralManagerStub::DisableSyncDataToLpDeviceInner(MessageParcel &data, MessageParcel &reply)
238{202{
239 return NO_ERROR;203 return NO_ERROR;
240}204}
241 205 
242-ErrCode BluetoothBleCentralManagerStub::SendParamsToLpDeviceInner(MessageParcel &data, MessageParcel &reply)206+int32_t BluetoothBleCentralManagerStub::SendParamsToLpDeviceInner(MessageParcel &data, MessageParcel &reply)
243{207{
244 return NO_ERROR;208 return NO_ERROR;
245}209}
246 210 
247-ErrCode BluetoothBleCentralManagerStub::IsLpDeviceAvailableInner(MessageParcel &data, MessageParcel &reply)211+int32_t BluetoothBleCentralManagerStub::IsLpDeviceAvailableInner(MessageParcel &data, MessageParcel &reply)
248{212{
249 return NO_ERROR;213 return NO_ERROR;
250}214}
251 215 
252-ErrCode BluetoothBleCentralManagerStub::SetLpDeviceParamInner(MessageParcel &data, MessageParcel &reply)216+int32_t BluetoothBleCentralManagerStub::SetLpDeviceParamInner(MessageParcel &data, MessageParcel &reply)
253{217{
254 return NO_ERROR;218 return NO_ERROR;
255}219}
256 220 
257-ErrCode BluetoothBleCentralManagerStub::RemoveLpDeviceParamInner(MessageParcel &data, MessageParcel &reply)221+int32_t BluetoothBleCentralManagerStub::RemoveLpDeviceParamInner(MessageParcel &data, MessageParcel &reply)
258{222{
259 return NO_ERROR;223 return NO_ERROR;
260}224}
261 225 
262-ErrCode BluetoothBleCentralManagerStub::ChangeScanParamsInner(MessageParcel &data, MessageParcel &reply)226+int32_t BluetoothBleCentralManagerStub::ChangeScanParamsInner(MessageParcel &data, MessageParcel &reply)
263{227{
264 int32_t scannerId = data.ReadInt32();228 int32_t scannerId = data.ReadInt32();
265 std::shared_ptr<BluetoothBleScanSettings> settings(data.ReadParcelable<BluetoothBleScanSettings>());229 std::shared_ptr<BluetoothBleScanSettings> settings(data.ReadParcelable<BluetoothBleScanSettings>());
@@ -294,7 +258,7 @@ ErrCode BluetoothBleCentralManagerStub::ChangeScanParamsInner(MessageParcel &dat
294 return NO_ERROR;258 return NO_ERROR;
295}259}
296 260 
297-ErrCode BluetoothBleCentralManagerStub::IsValidScannerIdInner(MessageParcel &data, MessageParcel &reply)261+int32_t BluetoothBleCentralManagerStub::IsValidScannerIdInner(MessageParcel &data, MessageParcel &reply)
298{262{
299 int32_t scannerId = data.ReadInt32();263 int32_t scannerId = data.ReadInt32();
300 bool isValid = true;264 bool isValid = true;
Mservices/bluetooth/ipc/src/bluetooth_gatt_client_stub.cpp+76-85
@@ -18,84 +18,75 @@
18#include "bluetooth_errorcode.h"18#include "bluetooth_errorcode.h"
19#include "ipc_types.h"19#include "ipc_types.h"
20#include "string_ex.h"20#include "string_ex.h"
21+#include "permission_manager.h"
22+ 
23+#ifdef STUB_FUNC
24+#undef STUB_FUNC
25+#endif
26+#define STUB_FUNC(code, func, perm) BluetoothGattClientInterfaceCode::code, {&BluetoothGattClientStub::func, perm}
21 27 
22namespace OHOS {28namespace OHOS {
23namespace Bluetooth {29namespace Bluetooth {
30+using namespace OHOS::bluetooth;
31+ 
32+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
33+const std::map<uint32_t, BluetoothGattClientStub::GattClientStubFuncPerm> BluetoothGattClientStub::memberFuncMap_ = {
34+ {STUB_FUNC(BT_GATT_CLIENT_REGISTER_APP, RegisterApplicationInner,
35+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
36+ {STUB_FUNC(BT_GATT_CLIENT_DEREGISTER_APP, DeregisterApplicationInner,
37+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
38+ {STUB_FUNC(BT_GATT_CLIENT_CONNECT, ConnectInner,
39+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
40+ {STUB_FUNC(BT_GATT_CLIENT_DIS_CONNECT, DisconnectInner,
41+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
42+ {STUB_FUNC(BT_GATT_CLIENT_DISCOVERY_SERVICES, DiscoveryServicesInner,
43+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
44+ {STUB_FUNC(BT_GATT_CLIENT_READ_CHARACTERISTIC, ReadCharacteristicInner,
45+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
46+ {STUB_FUNC(BT_GATT_CLIENT_WRITE_CHARACTERISTIC, WriteCharacteristicInner,
47+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
48+ {STUB_FUNC(BT_GATT_CLIENT_SIGNED_WRITE_CHARACTERISTIC, SignedWriteCharacteristicInner,
49+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
50+ {STUB_FUNC(BT_GATT_CLIENT_READ_DESCRIPTOR, ReadDescriptorInner,
51+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
52+ {STUB_FUNC(BT_GATT_CLIENT_WRITE_DESCRIPTOR, WriteDescriptorInner,
53+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
54+ {STUB_FUNC(BT_GATT_CLIENT_REQUEST_EXCHANGE_MTU, RequestExchangeMtuInner,
55+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
56+ {STUB_FUNC(BT_GATT_CLIENT_GET_ALL_DEVICE, GetAllDeviceInner,
57+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
58+ {STUB_FUNC(BT_GATT_CLIENT_REQUEST_CONNECTION_PRIORITY, RequestConnectionPriorityInner,
59+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
60+ {STUB_FUNC(BT_GATT_CLIENT_GET_SERVICES, GetServicesInner,
61+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
62+ {STUB_FUNC(BT_GATT_CLIENT_REQUEST_FASTEST_CONNECTION, RequestFastestConnInner,
63+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
64+ {STUB_FUNC(BT_GATT_CLIENT_READ_REMOTE_RSSI_VALUE, ReadRemoteRssiValueInner,
65+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
66+ {STUB_FUNC(BT_GATT_CLIENT_REQUEST_NOTIFICATION, RequestNotificationInner,
67+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
68+ {STUB_FUNC(BT_GATT_CLIENT_GET_CONNECTED_STATE, GetConnectedStateInner,
69+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
70+ {STUB_FUNC(BT_GATT_CLIENT_SET_PHY, SetPhyInner,
71+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
72+ {STUB_FUNC(BT_GATT_CLIENT_READ_PHY, ReadPhyInner,
73+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
74+};
75+ 
76+ 
24BluetoothGattClientStub::BluetoothGattClientStub()77BluetoothGattClientStub::BluetoothGattClientStub()
25-{78+{}
26- HILOGD("%{public}s start.", __func__);
27- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REGISTER_APP)] =
28- &BluetoothGattClientStub::RegisterApplicationInner;
29- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DEREGISTER_APP)] =
30- &BluetoothGattClientStub::DeregisterApplicationInner;
31- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_CONNECT)] =
32- &BluetoothGattClientStub::ConnectInner;
33- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DIS_CONNECT)] =
34- &BluetoothGattClientStub::DisconnectInner;
35- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DISCOVERY_SERVICES)] =
36- &BluetoothGattClientStub::DiscoveryServicesInner;
37- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_CHARACTERISTIC)] =
38- &BluetoothGattClientStub::ReadCharacteristicInner;
39- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_WRITE_CHARACTERISTIC)] =
40- &BluetoothGattClientStub::WriteCharacteristicInner;
41- memberFuncMap_[static_cast<uint32_t>(
42- BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_SIGNED_WRITE_CHARACTERISTIC)] =
43- &BluetoothGattClientStub::SignedWriteCharacteristicInner;
44- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_DESCRIPTOR)] =
45- &BluetoothGattClientStub::ReadDescriptorInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_WRITE_DESCRIPTOR)] =
47- &BluetoothGattClientStub::WriteDescriptorInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_EXCHANGE_MTU)] =
49- &BluetoothGattClientStub::RequestExchangeMtuInner;
50- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_GET_ALL_DEVICE)] =
51- &BluetoothGattClientStub::GetAllDeviceInner;
52- memberFuncMap_[static_cast<uint32_t>(
53- BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_CONNECTION_PRIORITY)] =
54- &BluetoothGattClientStub::RequestConnectionPriorityInner;
55- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_GET_SERVICES)] =
56- &BluetoothGattClientStub::GetServicesInner;
57- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_FASTEST_CONNECTION)] =
58- &BluetoothGattClientStub::RequestFastestConnInner;
59- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_REMOTE_RSSI_VALUE)] =
60- &BluetoothGattClientStub::ReadRemoteRssiValueInner;
61- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_NOTIFICATION)] =
62- &BluetoothGattClientStub::RequestNotificationInner;
63- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_GET_CONNECTED_STATE)] =
64- &BluetoothGattClientStub::GetConnectedStateInner;
65- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_SET_PHY)] =
66- &BluetoothGattClientStub::SetPhyInner;
67- memberFuncMap_[static_cast<uint32_t>(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_PHY)] =
68- &BluetoothGattClientStub::ReadPhyInner;
69-}
70 79 
71BluetoothGattClientStub::~BluetoothGattClientStub()80BluetoothGattClientStub::~BluetoothGattClientStub()
72-{81+{}
73- HILOGD("%{public}s start.", __func__);
74- memberFuncMap_.clear();
75-}
76 82 
77int BluetoothGattClientStub::OnRemoteRequest(83int BluetoothGattClientStub::OnRemoteRequest(
78 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)84 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
79{85{
80- HILOGD("BluetoothGattClientStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());86+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothGattClientStub);
81- std::u16string descriptor = BluetoothGattClientStub::GetDescriptor();
82- std::u16string remoteDescriptor = data.ReadInterfaceToken();
83- if (descriptor != remoteDescriptor) {
84- HILOGI("local descriptor is not equal to remote");
85- return ERR_INVALID_STATE;
86- }
87- auto itFunc = memberFuncMap_.find(code);
88- if (itFunc != memberFuncMap_.end()) {
89- auto memberFunc = itFunc->second;
90- if (memberFunc != nullptr) {
91- return (this->*memberFunc)(data, reply);
92- }
93- }
94- HILOGW("BluetoothGattClientStub::OnRemoteRequest, default case, need check.");
95- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
96}87}
97 88 
98-ErrCode BluetoothGattClientStub::RegisterApplicationInner(MessageParcel &data, MessageParcel &reply)89+int32_t BluetoothGattClientStub::RegisterApplicationInner(MessageParcel &data, MessageParcel &reply)
99{90{
100 HILOGI("BluetoothGattClientStub::RegisterApplicationInner starts");91 HILOGI("BluetoothGattClientStub::RegisterApplicationInner starts");
101 sptr<IRemoteObject> remote = data.ReadRemoteObject();92 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -116,7 +107,7 @@ ErrCode BluetoothGattClientStub::RegisterApplicationInner(MessageParcel &data, M
116 return NO_ERROR;107 return NO_ERROR;
117}108}
118 109 
119-ErrCode BluetoothGattClientStub::DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply)110+int32_t BluetoothGattClientStub::DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply)
120{111{
121 HILOGI("BluetoothGattClientStub::DeregisterApplicationInner starts");112 HILOGI("BluetoothGattClientStub::DeregisterApplicationInner starts");
122 int32_t appId = data.ReadInt32();113 int32_t appId = data.ReadInt32();
@@ -129,7 +120,7 @@ ErrCode BluetoothGattClientStub::DeregisterApplicationInner(MessageParcel &data,
129 return NO_ERROR;120 return NO_ERROR;
130}121}
131 122 
132-ErrCode BluetoothGattClientStub::ConnectInner(MessageParcel &data, MessageParcel &reply)123+int32_t BluetoothGattClientStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
133{124{
134 HILOGI("BluetoothGattClientStub::ConnectInner starts");125 HILOGI("BluetoothGattClientStub::ConnectInner starts");
135 int32_t appId = data.ReadInt32();126 int32_t appId = data.ReadInt32();
@@ -143,7 +134,7 @@ ErrCode BluetoothGattClientStub::ConnectInner(MessageParcel &data, MessageParcel
143 return NO_ERROR;134 return NO_ERROR;
144}135}
145 136 
146-ErrCode BluetoothGattClientStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)137+int32_t BluetoothGattClientStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
147{138{
148 HILOGI("BluetoothGattClientStub::DisconnectInner starts");139 HILOGI("BluetoothGattClientStub::DisconnectInner starts");
149 int32_t appId = data.ReadInt32();140 int32_t appId = data.ReadInt32();
@@ -156,7 +147,7 @@ ErrCode BluetoothGattClientStub::DisconnectInner(MessageParcel &data, MessagePar
156 return NO_ERROR;147 return NO_ERROR;
157}148}
158 149 
159-ErrCode BluetoothGattClientStub::DiscoveryServicesInner(MessageParcel &data, MessageParcel &reply)150+int32_t BluetoothGattClientStub::DiscoveryServicesInner(MessageParcel &data, MessageParcel &reply)
160{151{
161 HILOGI("BluetoothGattClientStub::DiscoveryServicesInner starts");152 HILOGI("BluetoothGattClientStub::DiscoveryServicesInner starts");
162 int32_t appId = data.ReadInt32();153 int32_t appId = data.ReadInt32();
@@ -169,7 +160,7 @@ ErrCode BluetoothGattClientStub::DiscoveryServicesInner(MessageParcel &data, Mes
169 return NO_ERROR;160 return NO_ERROR;
170}161}
171 162 
172-ErrCode BluetoothGattClientStub::ReadCharacteristicInner(MessageParcel &data, MessageParcel &reply)163+int32_t BluetoothGattClientStub::ReadCharacteristicInner(MessageParcel &data, MessageParcel &reply)
173{164{
174 HILOGI("BluetoothGattClientStub::ReadCharacteristicInner starts");165 HILOGI("BluetoothGattClientStub::ReadCharacteristicInner starts");
175 int32_t appId = data.ReadInt32();166 int32_t appId = data.ReadInt32();
@@ -186,7 +177,7 @@ ErrCode BluetoothGattClientStub::ReadCharacteristicInner(MessageParcel &data, Me
186 return NO_ERROR;177 return NO_ERROR;
187}178}
188 179 
189-ErrCode BluetoothGattClientStub::WriteCharacteristicInner(MessageParcel &data, MessageParcel &reply)180+int32_t BluetoothGattClientStub::WriteCharacteristicInner(MessageParcel &data, MessageParcel &reply)
190{181{
191 HILOGI("BluetoothGattClientStub::WriteCharacteristicInner starts");182 HILOGI("BluetoothGattClientStub::WriteCharacteristicInner starts");
192 int32_t appId = data.ReadInt32();183 int32_t appId = data.ReadInt32();
@@ -205,7 +196,7 @@ ErrCode BluetoothGattClientStub::WriteCharacteristicInner(MessageParcel &data, M
205 return NO_ERROR;196 return NO_ERROR;
206}197}
207 198 
208-ErrCode BluetoothGattClientStub::SignedWriteCharacteristicInner(MessageParcel &data, MessageParcel &reply)199+int32_t BluetoothGattClientStub::SignedWriteCharacteristicInner(MessageParcel &data, MessageParcel &reply)
209{200{
210 HILOGI("BluetoothGattClientStub::SignedWriteCharacteristicInner starts");201 HILOGI("BluetoothGattClientStub::SignedWriteCharacteristicInner starts");
211 int32_t appId = data.ReadInt32();202 int32_t appId = data.ReadInt32();
@@ -222,7 +213,7 @@ ErrCode BluetoothGattClientStub::SignedWriteCharacteristicInner(MessageParcel &d
222 return NO_ERROR;213 return NO_ERROR;
223}214}
224 215 
225-ErrCode BluetoothGattClientStub::ReadDescriptorInner(MessageParcel &data, MessageParcel &reply)216+int32_t BluetoothGattClientStub::ReadDescriptorInner(MessageParcel &data, MessageParcel &reply)
226{217{
227 HILOGI("BluetoothGattClientStub::ReadDescriptorInner starts");218 HILOGI("BluetoothGattClientStub::ReadDescriptorInner starts");
228 int32_t appId = data.ReadInt32();219 int32_t appId = data.ReadInt32();
@@ -239,7 +230,7 @@ ErrCode BluetoothGattClientStub::ReadDescriptorInner(MessageParcel &data, Messag
239 return NO_ERROR;230 return NO_ERROR;
240}231}
241 232 
242-ErrCode BluetoothGattClientStub::WriteDescriptorInner(MessageParcel &data, MessageParcel &reply)233+int32_t BluetoothGattClientStub::WriteDescriptorInner(MessageParcel &data, MessageParcel &reply)
243{234{
244 HILOGI("BluetoothGattClientStub::WriteDescriptorInner starts");235 HILOGI("BluetoothGattClientStub::WriteDescriptorInner starts");
245 int32_t appId = data.ReadInt32();236 int32_t appId = data.ReadInt32();
@@ -257,7 +248,7 @@ ErrCode BluetoothGattClientStub::WriteDescriptorInner(MessageParcel &data, Messa
257 return NO_ERROR;248 return NO_ERROR;
258}249}
259 250 
260-ErrCode BluetoothGattClientStub::RequestExchangeMtuInner(MessageParcel &data, MessageParcel &reply)251+int32_t BluetoothGattClientStub::RequestExchangeMtuInner(MessageParcel &data, MessageParcel &reply)
261{252{
262 HILOGI("BluetoothGattClientStub::RequestExchangeMtuInner starts");253 HILOGI("BluetoothGattClientStub::RequestExchangeMtuInner starts");
263 int32_t appId = data.ReadInt32();254 int32_t appId = data.ReadInt32();
@@ -272,7 +263,7 @@ ErrCode BluetoothGattClientStub::RequestExchangeMtuInner(MessageParcel &data, Me
272 return NO_ERROR;263 return NO_ERROR;
273}264}
274 265 
275-ErrCode BluetoothGattClientStub::GetAllDeviceInner(MessageParcel &data, MessageParcel &reply)266+int32_t BluetoothGattClientStub::GetAllDeviceInner(MessageParcel &data, MessageParcel &reply)
276{267{
277 HILOGI("BluetoothGattClientStub::GetAllDeviceInner starts");268 HILOGI("BluetoothGattClientStub::GetAllDeviceInner starts");
278 std::vector<BluetoothGattDevice> device;269 std::vector<BluetoothGattDevice> device;
@@ -289,7 +280,7 @@ ErrCode BluetoothGattClientStub::GetAllDeviceInner(MessageParcel &data, MessageP
289 return NO_ERROR;280 return NO_ERROR;
290}281}
291 282 
292-ErrCode BluetoothGattClientStub::RequestConnectionPriorityInner(MessageParcel &data, MessageParcel &reply)283+int32_t BluetoothGattClientStub::RequestConnectionPriorityInner(MessageParcel &data, MessageParcel &reply)
293{284{
294 HILOGI("BluetoothGattClientStub::RequestConnectionPriorityInner starts");285 HILOGI("BluetoothGattClientStub::RequestConnectionPriorityInner starts");
295 int32_t appId = data.ReadInt32();286 int32_t appId = data.ReadInt32();
@@ -303,7 +294,7 @@ ErrCode BluetoothGattClientStub::RequestConnectionPriorityInner(MessageParcel &d
303 return NO_ERROR;294 return NO_ERROR;
304}295}
305 296 
306-ErrCode BluetoothGattClientStub::GetServicesInner(MessageParcel &data, MessageParcel &reply)297+int32_t BluetoothGattClientStub::GetServicesInner(MessageParcel &data, MessageParcel &reply)
307{298{
308 HILOGI("BluetoothGattClientStub::GetServicesInner starts");299 HILOGI("BluetoothGattClientStub::GetServicesInner starts");
309 int32_t appId = data.ReadInt32();300 int32_t appId = data.ReadInt32();
@@ -326,22 +317,22 @@ ErrCode BluetoothGattClientStub::GetServicesInner(MessageParcel &data, MessagePa
326 return NO_ERROR;317 return NO_ERROR;
327}318}
328 319 
329-ErrCode BluetoothGattClientStub::RequestFastestConnInner(MessageParcel &data, MessageParcel &reply)320+int32_t BluetoothGattClientStub::RequestFastestConnInner(MessageParcel &data, MessageParcel &reply)
330{321{
331 return NO_ERROR;322 return NO_ERROR;
332}323}
333 324 
334-ErrCode BluetoothGattClientStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)325+int32_t BluetoothGattClientStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)
335{326{
336 return NO_ERROR;327 return NO_ERROR;
337}328}
338 329 
339-ErrCode BluetoothGattClientStub::RequestNotificationInner(MessageParcel &data, MessageParcel &reply)330+int32_t BluetoothGattClientStub::RequestNotificationInner(MessageParcel &data, MessageParcel &reply)
340{331{
341 return NO_ERROR;332 return NO_ERROR;
342}333}
343 334 
344-ErrCode BluetoothGattClientStub::GetConnectedStateInner(MessageParcel &data, MessageParcel &reply)335+int32_t BluetoothGattClientStub::GetConnectedStateInner(MessageParcel &data, MessageParcel &reply)
345{336{
346 HILOGI("Not Support");337 HILOGI("Not Support");
347 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {338 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
@@ -351,7 +342,7 @@ ErrCode BluetoothGattClientStub::GetConnectedStateInner(MessageParcel &data, Mes
351 return NO_ERROR;342 return NO_ERROR;
352}343}
353 344 
354-ErrCode BluetoothGattClientStub::SetPhyInner(MessageParcel &data, MessageParcel &reply)345+int32_t BluetoothGattClientStub::SetPhyInner(MessageParcel &data, MessageParcel &reply)
355{346{
356 HILOGI("Not Support");347 HILOGI("Not Support");
357 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {348 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
@@ -361,7 +352,7 @@ ErrCode BluetoothGattClientStub::SetPhyInner(MessageParcel &data, MessageParcel
361 return NO_ERROR;352 return NO_ERROR;
362}353}
363 354 
364-ErrCode BluetoothGattClientStub::ReadPhyInner(MessageParcel &data, MessageParcel &reply)355+int32_t BluetoothGattClientStub::ReadPhyInner(MessageParcel &data, MessageParcel &reply)
365{356{
366 HILOGI("Not Support");357 HILOGI("Not Support");
367 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {358 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
Mservices/bluetooth/ipc/src/bluetooth_gatt_server_stub.cpp+60-69
@@ -18,71 +18,62 @@
18#include "bluetooth_errorcode.h"18#include "bluetooth_errorcode.h"
19#include "ipc_types.h"19#include "ipc_types.h"
20#include "string_ex.h"20#include "string_ex.h"
21+#include "permission_manager.h"
22+ 
23+#ifdef STUB_FUNC
24+#undef STUB_FUNC
25+#endif
26+#define STUB_FUNC(code, func, perm) BluetoothGattServerInterfaceCode::code, {&BluetoothGattServerStub::func, perm}
21 27 
22namespace OHOS {28namespace OHOS {
23namespace Bluetooth {29namespace Bluetooth {
30+using namespace OHOS::bluetooth;
31+ 
32+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
33+const std::map<uint32_t, BluetoothGattServerStub::GattServerStubFuncPerm> BluetoothGattServerStub::memberFuncMap_ = {
34+ {STUB_FUNC(GATT_SERVER_ADD_SERVICE, AddServiceInner,
35+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
36+ {STUB_FUNC(GATT_SERVER_CLEAR_SERVICES, ClearServicesInner,
37+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
38+ {STUB_FUNC(GATT_SERVER_CONNECT, ConnectInner,
39+ CHECK_PERM(false, {USE_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
40+ {STUB_FUNC(GATT_SERVER_CANCEL_CONNECTION, CancelConnectionInner,
41+ CHECK_PERM(false, {USE_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
42+ {STUB_FUNC(GATT_SERVER_REGISTER, RegisterApplicationInner,
43+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
44+ {STUB_FUNC(GATT_SERVER_DEREGISTER, DeregisterApplicationInner,
45+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
46+ {STUB_FUNC(GATT_SERVER_NOTIFY_CLIENT, NotifyClientInner,
47+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
48+ {STUB_FUNC(GATT_SERVER_REMOVE_SERVICE, RemoveServiceInner,
49+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
50+ {STUB_FUNC(GATT_SERVER_RESPOND_CHARACTERISTIC_READ, RespondCharacteristicReadInner,
51+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
52+ {STUB_FUNC(GATT_SERVER_RESPOND_CHARACTERISTIC_WRITE, RespondCharacteristicWriteInner,
53+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
54+ {STUB_FUNC(GATT_SERVER_RESPOND_DESCRIPTOR_READ, RespondDescriptorReadInner,
55+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
56+ {STUB_FUNC(GATT_SERVER_RESPOND_DESCRIPTOR_WRITE, RespondDescriptorWriteInner,
57+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
58+ {STUB_FUNC(GATT_SERVER_GET_CONNECTED_STATE, GetConnectedStateInner,
59+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
60+ {STUB_FUNC(GATT_SERVER_SET_PHY, SetPhyInner,
61+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
62+ {STUB_FUNC(GATT_SERVER_READ_PHY, ReadPhyInner,
63+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
64+};
65+ 
24BluetoothGattServerStub::BluetoothGattServerStub()66BluetoothGattServerStub::BluetoothGattServerStub()
25-{67+{}
26- HILOGD("%{public}s start.", __func__);
27- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_ADD_SERVICE)] =
28- &BluetoothGattServerStub::AddServiceInner;
29- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_CLEAR_SERVICES)] =
30- &BluetoothGattServerStub::ClearServicesInner;
31- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_CANCEL_CONNECTION)] =
32- &BluetoothGattServerStub::CancelConnectionInner;
33- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_REGISTER)] =
34- &BluetoothGattServerStub::RegisterApplicationInner;
35- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_DEREGISTER)] =
36- &BluetoothGattServerStub::DeregisterApplicationInner;
37- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_NOTIFY_CLIENT)] =
38- &BluetoothGattServerStub::NotifyClientInner;
39- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_REMOVE_SERVICE)] =
40- &BluetoothGattServerStub::RemoveServiceInner;
41- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_RESPOND_CHARACTERISTIC_READ)] =
42- &BluetoothGattServerStub::RespondCharacteristicReadInner;
43- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_RESPOND_CHARACTERISTIC_WRITE)] =
44- &BluetoothGattServerStub::RespondCharacteristicWriteInner;
45- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_RESPOND_DESCRIPTOR_READ)] =
46- &BluetoothGattServerStub::RespondDescriptorReadInner;
47- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_RESPOND_DESCRIPTOR_WRITE)] =
48- &BluetoothGattServerStub::RespondDescriptorWriteInner;
49- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_CONNECT)] =
50- &BluetoothGattServerStub::ConnectInner;
51- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_GET_CONNECTED_STATE)] =
52- &BluetoothGattServerStub::GetConnectedStateInner;
53- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_SET_PHY)] =
54- &BluetoothGattServerStub::SetPhyInner;
55- memberFuncMap_[static_cast<uint32_t>(BluetoothGattServerInterfaceCode::GATT_SERVER_READ_PHY)] =
56- &BluetoothGattServerStub::ReadPhyInner;
57-}
58 68 
59BluetoothGattServerStub::~BluetoothGattServerStub()69BluetoothGattServerStub::~BluetoothGattServerStub()
60-{70+{}
61- HILOGD("%{public}s start.", __func__);
62- memberFuncMap_.clear();
63-}
64int BluetoothGattServerStub::OnRemoteRequest(71int BluetoothGattServerStub::OnRemoteRequest(
65 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)72 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
66{73{
67- HILOGD("BluetoothGattServerStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags());74+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothGattServerStub);
68- std::u16string descriptor = BluetoothGattServerStub::GetDescriptor();
69- std::u16string remoteDescriptor = data.ReadInterfaceToken();
70- if (descriptor != remoteDescriptor) {
71- HILOGI("local descriptor is not equal to remote");
72- return ERR_INVALID_STATE;
73- }
74- 
75- auto itFunc = memberFuncMap_.find(code);
76- if (itFunc != memberFuncMap_.end()) {
77- auto memberFunc = itFunc->second;
78- if (memberFunc != nullptr) {
79- return (this->*memberFunc)(data, reply);
80- }
81- }
82- HILOGW("BluetoothGattServerStub::OnRemoteRequest, default case, need check.");
83- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
84}75}
85-ErrCode BluetoothGattServerStub::AddServiceInner(MessageParcel &data, MessageParcel &reply)76+int32_t BluetoothGattServerStub::AddServiceInner(MessageParcel &data, MessageParcel &reply)
86{77{
87 int32_t appID = data.ReadInt32();78 int32_t appID = data.ReadInt32();
88 std::shared_ptr<BluetoothGattService> service(data.ReadParcelable<BluetoothGattService>());79 std::shared_ptr<BluetoothGattService> service(data.ReadParcelable<BluetoothGattService>());
@@ -97,14 +88,14 @@ ErrCode BluetoothGattServerStub::AddServiceInner(MessageParcel &data, MessagePar
97 }88 }
98 return NO_ERROR;89 return NO_ERROR;
99}90}
100-ErrCode BluetoothGattServerStub::ClearServicesInner(MessageParcel &data, MessageParcel &reply)91+int32_t BluetoothGattServerStub::ClearServicesInner(MessageParcel &data, MessageParcel &reply)
101{92{
102 int appId = data.ReadInt32();93 int appId = data.ReadInt32();
103 ClearServices(appId);94 ClearServices(appId);
104 return NO_ERROR;95 return NO_ERROR;
105}96}
106 97 
107-ErrCode BluetoothGattServerStub::ConnectInner(MessageParcel &data, MessageParcel &reply)98+int32_t BluetoothGattServerStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
108{99{
109 int appId = data.ReadInt32();100 int appId = data.ReadInt32();
110 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());101 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
@@ -113,14 +104,14 @@ ErrCode BluetoothGattServerStub::ConnectInner(MessageParcel &data, MessageParcel
113 return Connect(appId, *device, isDirect);104 return Connect(appId, *device, isDirect);
114}105}
115 106 
116-ErrCode BluetoothGattServerStub::CancelConnectionInner(MessageParcel &data, MessageParcel &reply)107+int32_t BluetoothGattServerStub::CancelConnectionInner(MessageParcel &data, MessageParcel &reply)
117{108{
118 int appId = data.ReadInt32();109 int appId = data.ReadInt32();
119 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());110 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
120 CHECK_AND_RETURN_LOG_RET(device != nullptr, TRANSACTION_ERR, "Read parcelable BluetoothGattDevice failed");111 CHECK_AND_RETURN_LOG_RET(device != nullptr, TRANSACTION_ERR, "Read parcelable BluetoothGattDevice failed");
121 return CancelConnection(appId, *device);112 return CancelConnection(appId, *device);
122}113}
123-ErrCode BluetoothGattServerStub::RegisterApplicationInner(MessageParcel &data, MessageParcel &reply)114+int32_t BluetoothGattServerStub::RegisterApplicationInner(MessageParcel &data, MessageParcel &reply)
124{115{
125 sptr<IRemoteObject> remote = data.ReadRemoteObject();116 sptr<IRemoteObject> remote = data.ReadRemoteObject();
126 const sptr<IBluetoothGattServerCallback> callback = OHOS::iface_cast<IBluetoothGattServerCallback>(remote);117 const sptr<IBluetoothGattServerCallback> callback = OHOS::iface_cast<IBluetoothGattServerCallback>(remote);
@@ -132,7 +123,7 @@ ErrCode BluetoothGattServerStub::RegisterApplicationInner(MessageParcel &data, M
132 }123 }
133 return NO_ERROR;124 return NO_ERROR;
134}125}
135-ErrCode BluetoothGattServerStub::DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply)126+int32_t BluetoothGattServerStub::DeregisterApplicationInner(MessageParcel &data, MessageParcel &reply)
136{127{
137 int appId = data.ReadInt32();128 int appId = data.ReadInt32();
138 int result = DeregisterApplication(appId);129 int result = DeregisterApplication(appId);
@@ -143,7 +134,7 @@ ErrCode BluetoothGattServerStub::DeregisterApplicationInner(MessageParcel &data,
143 }134 }
144 return NO_ERROR;135 return NO_ERROR;
145}136}
146-ErrCode BluetoothGattServerStub::NotifyClientInner(MessageParcel &data, MessageParcel &reply)137+int32_t BluetoothGattServerStub::NotifyClientInner(MessageParcel &data, MessageParcel &reply)
147{138{
148 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());139 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
149 if (!device) {140 if (!device) {
@@ -162,7 +153,7 @@ ErrCode BluetoothGattServerStub::NotifyClientInner(MessageParcel &data, MessageP
162 }153 }
163 return NO_ERROR;154 return NO_ERROR;
164}155}
165-ErrCode BluetoothGattServerStub::RemoveServiceInner(MessageParcel &data, MessageParcel &reply)156+int32_t BluetoothGattServerStub::RemoveServiceInner(MessageParcel &data, MessageParcel &reply)
166{157{
167 int appId = data.ReadInt32();158 int appId = data.ReadInt32();
168 std::shared_ptr<BluetoothGattService> service(data.ReadParcelable<BluetoothGattService>());159 std::shared_ptr<BluetoothGattService> service(data.ReadParcelable<BluetoothGattService>());
@@ -177,7 +168,7 @@ ErrCode BluetoothGattServerStub::RemoveServiceInner(MessageParcel &data, Message
177 }168 }
178 return NO_ERROR;169 return NO_ERROR;
179}170}
180-ErrCode BluetoothGattServerStub::RespondCharacteristicReadInner(MessageParcel &data, MessageParcel &reply)171+int32_t BluetoothGattServerStub::RespondCharacteristicReadInner(MessageParcel &data, MessageParcel &reply)
181{172{
182 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());173 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
183 if (!device) {174 if (!device) {
@@ -196,7 +187,7 @@ ErrCode BluetoothGattServerStub::RespondCharacteristicReadInner(MessageParcel &d
196 }187 }
197 return NO_ERROR;188 return NO_ERROR;
198}189}
199-ErrCode BluetoothGattServerStub::RespondCharacteristicWriteInner(MessageParcel &data, MessageParcel &reply)190+int32_t BluetoothGattServerStub::RespondCharacteristicWriteInner(MessageParcel &data, MessageParcel &reply)
200{191{
201 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());192 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
202 if (!device) {193 if (!device) {
@@ -215,7 +206,7 @@ ErrCode BluetoothGattServerStub::RespondCharacteristicWriteInner(MessageParcel &
215 }206 }
216 return NO_ERROR;207 return NO_ERROR;
217}208}
218-ErrCode BluetoothGattServerStub::RespondDescriptorReadInner(MessageParcel &data, MessageParcel &reply)209+int32_t BluetoothGattServerStub::RespondDescriptorReadInner(MessageParcel &data, MessageParcel &reply)
219{210{
220 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());211 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
221 if (!device) {212 if (!device) {
@@ -234,7 +225,7 @@ ErrCode BluetoothGattServerStub::RespondDescriptorReadInner(MessageParcel &data,
234 }225 }
235 return NO_ERROR;226 return NO_ERROR;
236}227}
237-ErrCode BluetoothGattServerStub::RespondDescriptorWriteInner(MessageParcel &data, MessageParcel &reply)228+int32_t BluetoothGattServerStub::RespondDescriptorWriteInner(MessageParcel &data, MessageParcel &reply)
238{229{
239 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());230 std::shared_ptr<BluetoothGattDevice> device(data.ReadParcelable<BluetoothGattDevice>());
240 if (!device) {231 if (!device) {
@@ -254,7 +245,7 @@ ErrCode BluetoothGattServerStub::RespondDescriptorWriteInner(MessageParcel &data
254 return NO_ERROR;245 return NO_ERROR;
255}246}
256 247 
257-ErrCode BluetoothGattServerStub::GetConnectedStateInner(MessageParcel &data, MessageParcel &reply)248+int32_t BluetoothGattServerStub::GetConnectedStateInner(MessageParcel &data, MessageParcel &reply)
258{249{
259 HILOGI("Not Support");250 HILOGI("Not Support");
260 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {251 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
@@ -264,7 +255,7 @@ ErrCode BluetoothGattServerStub::GetConnectedStateInner(MessageParcel &data, Mes
264 return NO_ERROR;255 return NO_ERROR;
265}256}
266 257 
267-ErrCode BluetoothGattServerStub::SetPhyInner(MessageParcel &data, MessageParcel &reply)258+int32_t BluetoothGattServerStub::SetPhyInner(MessageParcel &data, MessageParcel &reply)
268{259{
269 HILOGI("Not Support");260 HILOGI("Not Support");
270 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {261 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
@@ -274,7 +265,7 @@ ErrCode BluetoothGattServerStub::SetPhyInner(MessageParcel &data, MessageParcel
274 return NO_ERROR;265 return NO_ERROR;
275}266}
276 267 
277-ErrCode BluetoothGattServerStub::ReadPhyInner(MessageParcel &data, MessageParcel &reply)268+int32_t BluetoothGattServerStub::ReadPhyInner(MessageParcel &data, MessageParcel &reply)
278{269{
279 HILOGI("Not Support");270 HILOGI("Not Support");
280 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {271 if (!reply.WriteInt32(BT_ERR_API_NOT_SUPPORT)) {
Mservices/bluetooth/ipc/src/bluetooth_hfp_ag_stub.cpp+103-114
@@ -17,108 +17,97 @@
17 17 
18#include "bluetooth_errorcode.h"18#include "bluetooth_errorcode.h"
19#include "bluetooth_log.h"19#include "bluetooth_log.h"
20+#include "permission_manager.h"
21+ 
22+#ifdef STUB_FUNC
23+#undef STUB_FUNC
24+#endif
25+#define STUB_FUNC(code, func, perm) BluetoothHfpAgInterfaceCode::code, {&BluetoothHfpAgStub::func, perm}
20 26 
21namespace OHOS {27namespace OHOS {
22namespace Bluetooth {28namespace Bluetooth {
23-BluetoothHfpAgStub::BluetoothHfpAgStub() {29+using namespace OHOS::bluetooth;
24- HILOGI("%{public}s start.", __func__);
25- RegisterBasicConnectionFunctions();
26- RegisterScoConnectionFunctions();
27- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_PHONE_STATE_CHANGED)] =
28- &BluetoothHfpAgStub::PhoneStateChangedInner;
29- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLCC_RESPONSE)] =
30- &BluetoothHfpAgStub::ClccResponseInner;
31- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_OPEN_VOICE_RECOGNITION)] =
32- &BluetoothHfpAgStub::OpenVoiceRecognitionInner;
33- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLOSE_VOICE_RECOGNITION)] =
34- &BluetoothHfpAgStub::CloseVoiceRecognitionInner;
35- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_IS_AUDIO_CONNECTED)] =
36- &BluetoothHfpAgStub::IsAudioConnectedInner;
37- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_ACTIVE_DEVICE)] =
38- &BluetoothHfpAgStub::SetActiveDeviceInner;
39- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_ACTIVE_DEVICE)] =
40- &BluetoothHfpAgStub::GetActiveDeviceInner;
41- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_INTO_MOCK)] =
42- &BluetoothHfpAgStub::IntoMockInner;
43- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SEND_NO_CARRIER)] =
44- &BluetoothHfpAgStub::SendNoCarrierInner;
45- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_REGISTER_OBSERVER)] =
46- &BluetoothHfpAgStub::RegisterObserverInner;
47- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DEREGISTER_OBSERVER)] =
48- &BluetoothHfpAgStub::DeregisterObserverInner;
49- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_CONNECT_STRATEGY)] =
50- &BluetoothHfpAgStub::SetConnectStrategyInner;
51- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_STRATEGY)] =
52- &BluetoothHfpAgStub::GetConnectStrategyInner;
53- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_IS_IN_BAND_RINGING_ENABLE)] =
54- &BluetoothHfpAgStub::IsInbandRingingEnabledInner;
55- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CALL_DETAILS_CHANGED)] =
56- &BluetoothHfpAgStub::CallDetailsChangedInner;
57- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_IS_HFP_FEATURE_SUPPORTED)] =
58- &BluetoothHfpAgStub::IsHfpFeatureSupportedInner;
59- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CALL_LOG)] =
60- &BluetoothHfpAgStub::EnableBtCallLogInner;
61- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_VIRTUALDEVICE_LIST)] =
62- &BluetoothHfpAgStub::GetVirtualDeviceListInner;
63- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_UPDATE_VIRTUALDEVICE)] =
64- &BluetoothHfpAgStub::UpdateVirtualDeviceInner;
65- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CALLTYPE)] =
66- &BluetoothHfpAgStub::GetCurrentCallTypeInner;
67- HILOGI("%{public}s ends.", __func__);
68-}
69 30 
70-void BluetoothHfpAgStub::RegisterBasicConnectionFunctions()31+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
71-{32+const std::map<uint32_t, BluetoothHfpAgStub::HfpAgStubFuncPerm> BluetoothHfpAgStub::memberFuncMap_ = {
72- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_DEVICES)] =33+ {STUB_FUNC(BT_HFP_AG_GET_CONNECT_DEVICES, GetConnectDevicesInner,
73- &BluetoothHfpAgStub::GetConnectDevicesInner;34+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
74- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICES_BY_STATES)] =35+ {STUB_FUNC(BT_HFP_AG_GET_DEVICES_BY_STATES, GetDevicesByStatesInner,
75- &BluetoothHfpAgStub::GetDevicesByStatesInner;36+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
76- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICE_STATE)] =37+ {STUB_FUNC(BT_HFP_AG_GET_DEVICE_STATE, GetDeviceStateInner,
77- &BluetoothHfpAgStub::GetDeviceStateInner;38+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
78- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT)] =39+ {STUB_FUNC(BT_HFP_AG_CONNECT, ConnectInner,
79- &BluetoothHfpAgStub::ConnectInner;40+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
80- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT)] =41+ {STUB_FUNC(BT_HFP_AG_DISCONNECT, DisconnectInner,
81- &BluetoothHfpAgStub::DisconnectInner;42+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
82-}43+ {STUB_FUNC(BT_HFP_AG_GET_SCO_STATE, GetScoStateInner, nullptr)},
44+ {STUB_FUNC(BT_HFP_AG_CONNECT_SCO_EX, ConnectScoInnerEx,
45+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
46+ {STUB_FUNC(BT_HFP_AG_DISCONNECT_SCO_EX, DisconnectScoInnerEx,
47+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
48+ {STUB_FUNC(BT_HFP_AG_CONNECT_SCO, ConnectScoInner,
49+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
50+ {STUB_FUNC(BT_HFP_AG_DISCONNECT_SCO, DisconnectScoInner,
51+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
83 52 
84-void BluetoothHfpAgStub::RegisterScoConnectionFunctions()53+ {STUB_FUNC(BT_HFP_AG_PHONE_STATE_CHANGED, PhoneStateChangedInner,
85-{54+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
86- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_SCO_STATE)] =55+ 
87- &BluetoothHfpAgStub::GetScoStateInner;56+ {STUB_FUNC(BT_HFP_AG_CLCC_RESPONSE, ClccResponseInner,
88- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT_SCO)] =57+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
89- &BluetoothHfpAgStub::ConnectScoInner;58+ 
90- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT_SCO)] =59+ {STUB_FUNC(BT_HFP_AG_OPEN_VOICE_RECOGNITION, OpenVoiceRecognitionInner,
91- &BluetoothHfpAgStub::DisconnectScoInner;60+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
92- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT_SCO_EX)] =61+ 
93- &BluetoothHfpAgStub::ConnectScoInnerEx;62+ {STUB_FUNC(BT_HFP_AG_CLOSE_VOICE_RECOGNITION, CloseVoiceRecognitionInner,
94- memberFuncMap_[static_cast<uint32_t>(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT_SCO_EX)] =63+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
95- &BluetoothHfpAgStub::DisconnectScoInnerEx;64+ 
96-}65+ {STUB_FUNC(BT_HFP_AG_IS_AUDIO_CONNECTED, IsAudioConnectedInner,
66+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
67+ {STUB_FUNC(BT_HFP_AG_SET_ACTIVE_DEVICE, SetActiveDeviceInner,
68+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
69+ 
70+ {STUB_FUNC(BT_HFP_AG_GET_ACTIVE_DEVICE, GetActiveDeviceInner,
71+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
72+ 
73+ {STUB_FUNC(BT_HFP_AG_INTO_MOCK, IntoMockInner,
74+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
75+ 
76+ {STUB_FUNC(BT_HFP_AG_SEND_NO_CARRIER, SendNoCarrierInner,
77+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
78+ 
79+ {STUB_FUNC(BT_HFP_AG_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
80+ {STUB_FUNC(BT_HFP_AG_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
81+ {STUB_FUNC(BT_HFP_AG_SET_CONNECT_STRATEGY, SetConnectStrategyInner,
82+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
83+ {STUB_FUNC(BT_HFP_AG_GET_CONNECT_STRATEGY, GetConnectStrategyInner,
84+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
85+ 
86+ {STUB_FUNC(BT_HFP_AG_IS_IN_BAND_RINGING_ENABLE, IsInbandRingingEnabledInner,
87+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
88+ {STUB_FUNC(BT_HFP_AG_CALL_DETAILS_CHANGED, CallDetailsChangedInner,
89+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
90+ {STUB_FUNC(BT_HFP_AG_IS_HFP_FEATURE_SUPPORTED, IsHfpFeatureSupportedInner, nullptr)},
91+ {STUB_FUNC(BT_HFP_AG_CALL_LOG, EnableBtCallLogInner,
92+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
93+ {STUB_FUNC(BT_HFP_AG_GET_VIRTUALDEVICE_LIST, GetVirtualDeviceListInner,
94+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
95+ {STUB_FUNC(BT_HFP_AG_UPDATE_VIRTUALDEVICE, UpdateVirtualDeviceInner,
96+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
97+ {STUB_FUNC(BT_HFP_AG_GET_CALLTYPE, GetCurrentCallTypeInner,
98+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
99+};
100+ 
101+BluetoothHfpAgStub::BluetoothHfpAgStub()
102+{}
97 103 
98BluetoothHfpAgStub::~BluetoothHfpAgStub()104BluetoothHfpAgStub::~BluetoothHfpAgStub()
99-{105+{}
100- HILOGI("%{public}s start.", __func__);
101- memberFuncMap_.clear();
102-}
103 106 
104int BluetoothHfpAgStub::OnRemoteRequest(107int BluetoothHfpAgStub::OnRemoteRequest(
105 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)108 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
106{109{
107- HILOGI("BluetoothHfpAgStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());110+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothHfpAgStub);
108- if (BluetoothHfpAgStub::GetDescriptor() != data.ReadInterfaceToken()) {
109- HILOGI("local descriptor is not equal to remote");
110- return ERR_INVALID_STATE;
111- }
112- 
113- auto itFunc = memberFuncMap_.find(code);
114- if (itFunc != memberFuncMap_.end()) {
115- auto memberFunc = itFunc->second;
116- if (memberFunc != nullptr) {
117- return (this->*memberFunc)(data, reply);
118- }
119- }
120- HILOGW("BluetoothHfpAgStub::OnRemoteRequest, default case, need check.");
121- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
122}111}
123 112 
124int32_t BluetoothHfpAgStub::GetConnectDevicesInner(MessageParcel &data, MessageParcel &reply)113int32_t BluetoothHfpAgStub::GetConnectDevicesInner(MessageParcel &data, MessageParcel &reply)
@@ -139,7 +128,7 @@ int32_t BluetoothHfpAgStub::GetConnectDevicesInner(MessageParcel &data, MessageP
139 return NO_ERROR;128 return NO_ERROR;
140}129}
141 130 
142-ErrCode BluetoothHfpAgStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)131+int32_t BluetoothHfpAgStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
143{132{
144 std::vector<BluetoothRawAddress> devices;133 std::vector<BluetoothRawAddress> devices;
145 std::vector<int> states;134 std::vector<int> states;
@@ -159,7 +148,7 @@ ErrCode BluetoothHfpAgStub::GetDevicesByStatesInner(MessageParcel &data, Message
159 return NO_ERROR;148 return NO_ERROR;
160}149}
161 150 
162-ErrCode BluetoothHfpAgStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)151+int32_t BluetoothHfpAgStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
163{152{
164 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());153 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
165 if (!device) {154 if (!device) {
@@ -211,7 +200,7 @@ int32_t BluetoothHfpAgStub::DisconnectInner(MessageParcel &data, MessageParcel &
211 return NO_ERROR;200 return NO_ERROR;
212}201}
213 202 
214-ErrCode BluetoothHfpAgStub::GetScoStateInner(MessageParcel &data, MessageParcel &reply)203+int32_t BluetoothHfpAgStub::GetScoStateInner(MessageParcel &data, MessageParcel &reply)
215{204{
216 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());205 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
217 if (!device) {206 if (!device) {
@@ -225,7 +214,7 @@ ErrCode BluetoothHfpAgStub::GetScoStateInner(MessageParcel &data, MessageParcel
225 return NO_ERROR;214 return NO_ERROR;
226}215}
227 216 
228-ErrCode BluetoothHfpAgStub::ConnectScoInner(MessageParcel &data, MessageParcel &reply)217+int32_t BluetoothHfpAgStub::ConnectScoInner(MessageParcel &data, MessageParcel &reply)
229{218{
230 bool result = ConnectSco();219 bool result = ConnectSco();
231 if (!reply.WriteBool(result)) {220 if (!reply.WriteBool(result)) {
@@ -235,7 +224,7 @@ ErrCode BluetoothHfpAgStub::ConnectScoInner(MessageParcel &data, MessageParcel &
235 return NO_ERROR;224 return NO_ERROR;
236}225}
237 226 
238-ErrCode BluetoothHfpAgStub::DisconnectScoInner(MessageParcel &data, MessageParcel &reply)227+int32_t BluetoothHfpAgStub::DisconnectScoInner(MessageParcel &data, MessageParcel &reply)
239{228{
240 bool result = DisconnectSco();229 bool result = DisconnectSco();
241 if (!reply.WriteBool(result)) {230 if (!reply.WriteBool(result)) {
@@ -245,7 +234,7 @@ ErrCode BluetoothHfpAgStub::DisconnectScoInner(MessageParcel &data, MessageParce
245 return NO_ERROR;234 return NO_ERROR;
246}235}
247 236 
248-ErrCode BluetoothHfpAgStub::PhoneStateChangedInner(MessageParcel &data, MessageParcel &reply)237+int32_t BluetoothHfpAgStub::PhoneStateChangedInner(MessageParcel &data, MessageParcel &reply)
249{238{
250 std::shared_ptr<BluetoothPhoneState> phoneState(data.ReadParcelable<BluetoothPhoneState>());239 std::shared_ptr<BluetoothPhoneState> phoneState(data.ReadParcelable<BluetoothPhoneState>());
251 CHECK_AND_RETURN_LOG_RET(phoneState, BT_ERR_IPC_TRANS_FAILED,240 CHECK_AND_RETURN_LOG_RET(phoneState, BT_ERR_IPC_TRANS_FAILED,
@@ -254,7 +243,7 @@ ErrCode BluetoothHfpAgStub::PhoneStateChangedInner(MessageParcel &data, MessageP
254 return NO_ERROR;243 return NO_ERROR;
255}244}
256 245 
257-ErrCode BluetoothHfpAgStub::ClccResponseInner(MessageParcel &data, MessageParcel &reply)246+int32_t BluetoothHfpAgStub::ClccResponseInner(MessageParcel &data, MessageParcel &reply)
258{247{
259 int index = data.ReadInt32();248 int index = data.ReadInt32();
260 int direction = data.ReadInt32();249 int direction = data.ReadInt32();
@@ -267,7 +256,7 @@ ErrCode BluetoothHfpAgStub::ClccResponseInner(MessageParcel &data, MessageParcel
267 return NO_ERROR;256 return NO_ERROR;
268}257}
269 258 
270-ErrCode BluetoothHfpAgStub::OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)259+int32_t BluetoothHfpAgStub::OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)
271{260{
272 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());261 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
273 if (!device) {262 if (!device) {
@@ -281,7 +270,7 @@ ErrCode BluetoothHfpAgStub::OpenVoiceRecognitionInner(MessageParcel &data, Messa
281 return NO_ERROR;270 return NO_ERROR;
282}271}
283 272 
284-ErrCode BluetoothHfpAgStub::CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)273+int32_t BluetoothHfpAgStub::CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)
285{274{
286 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());275 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
287 if (!device) {276 if (!device) {
@@ -295,7 +284,7 @@ ErrCode BluetoothHfpAgStub::CloseVoiceRecognitionInner(MessageParcel &data, Mess
295 return NO_ERROR;284 return NO_ERROR;
296}285}
297 286 
298-ErrCode BluetoothHfpAgStub::IsAudioConnectedInner(MessageParcel &data, MessageParcel &reply)287+int32_t BluetoothHfpAgStub::IsAudioConnectedInner(MessageParcel &data, MessageParcel &reply)
299{288{
300 bool isAudioOn = false;289 bool isAudioOn = false;
301 int result = IsAudioConnected(isAudioOn);290 int result = IsAudioConnected(isAudioOn);
@@ -304,7 +293,7 @@ ErrCode BluetoothHfpAgStub::IsAudioConnectedInner(MessageParcel &data, MessagePa
304 return NO_ERROR;293 return NO_ERROR;
305}294}
306 295 
307-ErrCode BluetoothHfpAgStub::SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)296+int32_t BluetoothHfpAgStub::SetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)
308{297{
309 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());298 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
310 if (!device) {299 if (!device) {
@@ -318,7 +307,7 @@ ErrCode BluetoothHfpAgStub::SetActiveDeviceInner(MessageParcel &data, MessagePar
318 return NO_ERROR;307 return NO_ERROR;
319}308}
320 309 
321-ErrCode BluetoothHfpAgStub::IntoMockInner(MessageParcel &data, MessageParcel &reply)310+int32_t BluetoothHfpAgStub::IntoMockInner(MessageParcel &data, MessageParcel &reply)
322{311{
323 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());312 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
324 if (!device) {313 if (!device) {
@@ -333,7 +322,7 @@ ErrCode BluetoothHfpAgStub::IntoMockInner(MessageParcel &data, MessageParcel &re
333 return NO_ERROR;322 return NO_ERROR;
334}323}
335 324 
336-ErrCode BluetoothHfpAgStub::SendNoCarrierInner(MessageParcel &data, MessageParcel &reply)325+int32_t BluetoothHfpAgStub::SendNoCarrierInner(MessageParcel &data, MessageParcel &reply)
337{326{
338 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());327 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
339 if (!device) {328 if (!device) {
@@ -347,7 +336,7 @@ ErrCode BluetoothHfpAgStub::SendNoCarrierInner(MessageParcel &data, MessageParce
347 return NO_ERROR;336 return NO_ERROR;
348}337}
349 338 
350-ErrCode BluetoothHfpAgStub::GetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)339+int32_t BluetoothHfpAgStub::GetActiveDeviceInner(MessageParcel &data, MessageParcel &reply)
351{340{
352 std::string result = GetActiveDevice();341 std::string result = GetActiveDevice();
353 if (!reply.WriteString(result)) {342 if (!reply.WriteString(result)) {
@@ -357,7 +346,7 @@ ErrCode BluetoothHfpAgStub::GetActiveDeviceInner(MessageParcel &data, MessagePar
357 return NO_ERROR;346 return NO_ERROR;
358}347}
359 348 
360-ErrCode BluetoothHfpAgStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)349+int32_t BluetoothHfpAgStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
361{350{
362 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();351 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
363 sptr<IBluetoothHfpAgObserver> observer = iface_cast<IBluetoothHfpAgObserver>(tempObject);352 sptr<IBluetoothHfpAgObserver> observer = iface_cast<IBluetoothHfpAgObserver>(tempObject);
@@ -365,7 +354,7 @@ ErrCode BluetoothHfpAgStub::RegisterObserverInner(MessageParcel &data, MessagePa
365 return NO_ERROR;354 return NO_ERROR;
366}355}
367 356 
368-ErrCode BluetoothHfpAgStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)357+int32_t BluetoothHfpAgStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
369{358{
370 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();359 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
371 sptr<IBluetoothHfpAgObserver> observer = iface_cast<IBluetoothHfpAgObserver>(tempObject);360 sptr<IBluetoothHfpAgObserver> observer = iface_cast<IBluetoothHfpAgObserver>(tempObject);
@@ -373,7 +362,7 @@ ErrCode BluetoothHfpAgStub::DeregisterObserverInner(MessageParcel &data, Message
373 return NO_ERROR;362 return NO_ERROR;
374}363}
375 364 
376-ErrCode BluetoothHfpAgStub::SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)365+int32_t BluetoothHfpAgStub::SetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)
377{366{
378 int result = BT_ERR_SYSTEM_PERMISSION_FAILED;367 int result = BT_ERR_SYSTEM_PERMISSION_FAILED;
379 if (!reply.WriteInt32(result)) {368 if (!reply.WriteInt32(result)) {
@@ -383,12 +372,12 @@ ErrCode BluetoothHfpAgStub::SetConnectStrategyInner(MessageParcel &data, Message
383 return NO_ERROR;372 return NO_ERROR;
384}373}
385 374 
386-ErrCode BluetoothHfpAgStub::GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)375+int32_t BluetoothHfpAgStub::GetConnectStrategyInner(MessageParcel &data, MessageParcel &reply)
387{376{
388 return NO_ERROR;377 return NO_ERROR;
389}378}
390 379 
391-ErrCode BluetoothHfpAgStub::IsInbandRingingEnabledInner(MessageParcel &data, MessageParcel &reply)380+int32_t BluetoothHfpAgStub::IsInbandRingingEnabledInner(MessageParcel &data, MessageParcel &reply)
392{381{
393 bool isEnabled = true;382 bool isEnabled = true;
394 int result = IsInbandRingingEnabled(isEnabled);383 int result = IsInbandRingingEnabled(isEnabled);
@@ -403,7 +392,7 @@ ErrCode BluetoothHfpAgStub::IsInbandRingingEnabledInner(MessageParcel &data, Mes
403 return NO_ERROR;392 return NO_ERROR;
404}393}
405 394 
406-ErrCode BluetoothHfpAgStub::ConnectScoInnerEx(MessageParcel &data, MessageParcel &reply)395+int32_t BluetoothHfpAgStub::ConnectScoInnerEx(MessageParcel &data, MessageParcel &reply)
407{396{
408 bool result = ConnectSco();397 bool result = ConnectSco();
409 if (!reply.WriteBool(result)) {398 if (!reply.WriteBool(result)) {
@@ -413,7 +402,7 @@ ErrCode BluetoothHfpAgStub::ConnectScoInnerEx(MessageParcel &data, MessageParcel
413 return NO_ERROR;402 return NO_ERROR;
414}403}
415 404 
416-ErrCode BluetoothHfpAgStub::DisconnectScoInnerEx(MessageParcel &data, MessageParcel &reply)405+int32_t BluetoothHfpAgStub::DisconnectScoInnerEx(MessageParcel &data, MessageParcel &reply)
417{406{
418 bool result = DisconnectSco();407 bool result = DisconnectSco();
419 if (!reply.WriteBool(result)) {408 if (!reply.WriteBool(result)) {
@@ -423,12 +412,12 @@ ErrCode BluetoothHfpAgStub::DisconnectScoInnerEx(MessageParcel &data, MessagePar
423 return NO_ERROR;412 return NO_ERROR;
424}413}
425 414 
426-ErrCode BluetoothHfpAgStub::CallDetailsChangedInner(MessageParcel &data, MessageParcel &reply)415+int32_t BluetoothHfpAgStub::CallDetailsChangedInner(MessageParcel &data, MessageParcel &reply)
427{416{
428 return NO_ERROR;417 return NO_ERROR;
429}418}
430 419 
431-ErrCode BluetoothHfpAgStub::EnableBtCallLogInner(MessageParcel &data, MessageParcel &reply)420+int32_t BluetoothHfpAgStub::EnableBtCallLogInner(MessageParcel &data, MessageParcel &reply)
432{421{
433 return NO_ERROR;422 return NO_ERROR;
434}423}
Mservices/bluetooth/ipc/src/bluetooth_hfp_hf_stub.cpp+104-125
@@ -15,114 +15,75 @@
15 15 
16#include "bluetooth_hfp_hf_stub.h"16#include "bluetooth_hfp_hf_stub.h"
17#include "bluetooth_log.h"17#include "bluetooth_log.h"
18+#include "permission_manager.h"
19+ 
20+#ifdef STUB_FUNC
21+#undef STUB_FUNC
22+#endif
23+#define STUB_FUNC(code, func, perm) BluetoothHfpHfInterfaceCode::code, {&BluetoothHfpHfStub::func, perm}
18 24 
19namespace OHOS {25namespace OHOS {
20namespace Bluetooth {26namespace Bluetooth {
21-BluetoothHfpHfStub::BluetoothHfpHfStub() {27+using namespace OHOS::bluetooth;
22- HILOGD("%{public}s start.", __func__);28+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
23- memberFuncMap_[static_cast<uint32_t>(29+const std::map<uint32_t, BluetoothHfpHfStub::HfpHfStubFuncPerm> BluetoothHfpHfStub::memberFuncMap_ = {
24- BluetoothHfpHfInterfaceCode::BT_HFP_HF_CONNECT_SCO)] =30+ {STUB_FUNC(BT_HFP_HF_CONNECT_SCO, ConnectScoInner,
25- &BluetoothHfpHfStub::ConnectScoInner;31+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
26- memberFuncMap_[static_cast<uint32_t>(32+ {STUB_FUNC(BT_HFP_HF_DISCONNECT_SCO, DisconnectScoInner,
27- BluetoothHfpHfInterfaceCode::BT_HFP_HF_DISCONNECT_SCO)] =33+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
28- &BluetoothHfpHfStub::DisconnectScoInner;34+ {STUB_FUNC(BT_HFP_HF_GET_DEVICES_BY_STATES, GetDevicesByStatesInner, nullptr)},
29- memberFuncMap_[static_cast<uint32_t>(35+ {STUB_FUNC(BT_HFP_HF_GET_DEVICE_STATE, GetDeviceStateInner, nullptr)},
30- BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_DEVICES_BY_STATES)] =36+ {STUB_FUNC(BT_HFP_HF_GET_SCO_STATE, GetScoStateInner, nullptr)},
31- &BluetoothHfpHfStub::GetDevicesByStatesInner;37+ {STUB_FUNC(BT_HFP_HF_SEND_DTMF_TONE, SendDTMFToneInner, nullptr)},
32- memberFuncMap_[static_cast<uint32_t>(38+ {STUB_FUNC(BT_HFP_HF_CONNECT, ConnectInner,
33- BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_DEVICE_STATE)] =39+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
34- &BluetoothHfpHfStub::GetDeviceStateInner;40+ {STUB_FUNC(BT_HFP_HF_DISCONNECT, DisconnectInner,
35- memberFuncMap_[static_cast<uint32_t>(41+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
36- BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_SCO_STATE)] =42+ {STUB_FUNC(BT_HFP_HF_OPEN_VOICE_RECOGNITION, OpenVoiceRecognitionInner,
37- &BluetoothHfpHfStub::GetScoStateInner;43+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
38- memberFuncMap_[static_cast<uint32_t>(44+ {STUB_FUNC(BT_HFP_HF_CLOSE_VOICE_RECOGNITION, CloseVoiceRecognitionInner,
39- BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_DTMF_TONE)] =45+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
40- &BluetoothHfpHfStub::SendDTMFToneInner;46+ {STUB_FUNC(BT_HFP_HF_GET_CURRENT_CALL_LIST, GetCurrentCallListInner,
41- memberFuncMap_[static_cast<uint32_t>(47+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
42- BluetoothHfpHfInterfaceCode::BT_HFP_HF_CONNECT)] =48+ {STUB_FUNC(BT_HFP_HF_ACCEPT_INCOMING_CALL, AcceptIncomingCallInner,
43- nullptr;49+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
44- memberFuncMap_[static_cast<uint32_t>(50+ {STUB_FUNC(BT_HFP_HF_HOLD_ACTIVE_CALL, HoldActiveCallInner,
45- BluetoothHfpHfInterfaceCode::BT_HFP_HF_DISCONNECT)] =51+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
46- &BluetoothHfpHfStub::DisconnectInner;52+ {STUB_FUNC(BT_HFP_HF_REJECT_INCOMING_CALL, RejectIncomingCallInner,
47- memberFuncMap_[static_cast<uint32_t>(53+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
48- BluetoothHfpHfInterfaceCode::BT_HFP_HF_OPEN_VOICE_RECOGNITION)] =54+ {STUB_FUNC(BT_HFP_HF_SEND_KEY_PRESSED, SendKeyPressedInner,
49- &BluetoothHfpHfStub::OpenVoiceRecognitionInner;55+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
50- memberFuncMap_[static_cast<uint32_t>(56+ {STUB_FUNC(BT_HFP_HF_HANDLE_INCOMING_CALL, HandleIncomingCallInner,
51- BluetoothHfpHfInterfaceCode::BT_HFP_HF_CLOSE_VOICE_RECOGNITION)] =57+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
52- &BluetoothHfpHfStub::CloseVoiceRecognitionInner;58+ {STUB_FUNC(BT_HFP_HF_HANDLE_MULLTI_CALL, HandleMultiCallInner,
53- memberFuncMap_[static_cast<uint32_t>(59+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
54- BluetoothHfpHfInterfaceCode::BT_HFP_HF_GET_CURRENT_CALL_LIST)] =60+ {STUB_FUNC(BT_HFP_HF_DIAL_LAST_NUMBER, DialLastNumberInner,
55- &BluetoothHfpHfStub::GetCurrentCallListInner;61+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
56- memberFuncMap_[static_cast<uint32_t>(62+ {STUB_FUNC(BT_HFP_HF_DIAL_MEMORY, DialMemoryInner,
57- BluetoothHfpHfInterfaceCode::BT_HFP_HF_ACCEPT_INCOMING_CALL)] =63+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
58- &BluetoothHfpHfStub::AcceptIncomingCallInner;64+ {STUB_FUNC(BT_HFP_HF_SEND_VOICE_TAG, SendVoiceTagInner,
59- memberFuncMap_[static_cast<uint32_t>(65+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
60- BluetoothHfpHfInterfaceCode::BT_HFP_HF_HOLD_ACTIVE_CALL)] =66+ {STUB_FUNC(BT_HFP_HF_FINISH_ATIVE_CALL, FinishActiveCallInner,
61- &BluetoothHfpHfStub::HoldActiveCallInner;67+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
62- memberFuncMap_[static_cast<uint32_t>(68+ {STUB_FUNC(BT_HFP_HF_START_DIAL, StartDialInner,
63- BluetoothHfpHfInterfaceCode::BT_HFP_HF_REJECT_INCOMING_CALL)] =69+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
64- &BluetoothHfpHfStub::RejectIncomingCallInner;70+ {STUB_FUNC(BT_HFP_HF_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
65- memberFuncMap_[static_cast<uint32_t>(71+ {STUB_FUNC(BT_HFP_HF_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
66- BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_KEY_PRESSED)] =72+};
67- &BluetoothHfpHfStub::SendKeyPressedInner;
68- memberFuncMap_[static_cast<uint32_t>(
69- BluetoothHfpHfInterfaceCode::BT_HFP_HF_HANDLE_INCOMING_CALL)] =
70- &BluetoothHfpHfStub::HandleIncomingCallInner;
71- memberFuncMap_[static_cast<uint32_t>(
72- BluetoothHfpHfInterfaceCode::BT_HFP_HF_HANDLE_MULLTI_CALL)] =
73- &BluetoothHfpHfStub::HandleMultiCallInner;
74- memberFuncMap_[static_cast<uint32_t>(
75- BluetoothHfpHfInterfaceCode::BT_HFP_HF_DIAL_LAST_NUMBER)] =
76- &BluetoothHfpHfStub::DialLastNumberInner;
77- memberFuncMap_[static_cast<uint32_t>(
78- BluetoothHfpHfInterfaceCode::BT_HFP_HF_DIAL_MEMORY)] =
79- &BluetoothHfpHfStub::DialMemoryInner;
80- memberFuncMap_[static_cast<uint32_t>(
81- BluetoothHfpHfInterfaceCode::BT_HFP_HF_SEND_VOICE_TAG)] =
82- &BluetoothHfpHfStub::SendVoiceTagInner;
83- memberFuncMap_[static_cast<uint32_t>(
84- BluetoothHfpHfInterfaceCode::BT_HFP_HF_FINISH_ATIVE_CALL)] =
85- &BluetoothHfpHfStub::FinishActiveCallInner;
86- memberFuncMap_[static_cast<uint32_t>(
87- BluetoothHfpHfInterfaceCode::BT_HFP_HF_START_DIAL)] =
88- &BluetoothHfpHfStub::StartDialInner;
89- memberFuncMap_[static_cast<uint32_t>(
90- BluetoothHfpHfInterfaceCode::BT_HFP_HF_REGISTER_OBSERVER)] =
91- &BluetoothHfpHfStub::RegisterObserverInner;
92- memberFuncMap_[static_cast<uint32_t>(
93- BluetoothHfpHfInterfaceCode::BT_HFP_HF_DEREGISTER_OBSERVER)] =
94- &BluetoothHfpHfStub::DeregisterObserverInner;
95 73 
96- HILOGD("%{public}s ends.", __func__);74+BluetoothHfpHfStub::BluetoothHfpHfStub()
75+{}
76+ 
77+BluetoothHfpHfStub::~BluetoothHfpHfStub()
78+{}
79+ 
80+int BluetoothHfpHfStub::OnRemoteRequest()
81+{
82+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothHfpHfStub);
97}83}
98 84 
99-BluetoothHfpHfStub::~BluetoothHfpHfStub() {85+int32_t BluetoothHfpHfStub::ConnectScoInner(MessageParcel &data, MessageParcel &reply)
100- HILOGD("%{public}s start.", __func__);86+{
101- memberFuncMap_.clear();
102-}
103- 
104-int BluetoothHfpHfStub::OnRemoteRequest(
105- uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
106- HILOGD("BluetoothHfpHfStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
107- std::u16string descriptor = BluetoothHfpHfStub::GetDescriptor();
108- std::u16string remoteDescriptor = data.ReadInterfaceToken();
109- if (descriptor != remoteDescriptor) {
110- HILOGI("local descriptor is not equal to remote");
111- return ERR_INVALID_STATE;
112- }
113- 
114- auto itFunc = memberFuncMap_.find(code);
115- if (itFunc != memberFuncMap_.end()) {
116- auto memberFunc = itFunc->second;
117- if (memberFunc != nullptr) {
118- return (this->*memberFunc)(data, reply);
119- }
120- }
121- HILOGW("BluetoothHfpHfStub::OnRemoteRequest, default case, need check.");
122- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
123-}
124- 
125-ErrCode BluetoothHfpHfStub::ConnectScoInner(MessageParcel &data, MessageParcel &reply) {
126 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());87 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
127 if (!device) {88 if (!device) {
128 return TRANSACTION_ERR;89 return TRANSACTION_ERR;
@@ -135,7 +96,8 @@ ErrCode BluetoothHfpHfStub::ConnectScoInner(MessageParcel &data, MessageParcel &
135 return NO_ERROR;96 return NO_ERROR;
136}97}
137 98 
138-ErrCode BluetoothHfpHfStub::DisconnectScoInner(MessageParcel &data, MessageParcel &reply) {99+int32_t BluetoothHfpHfStub::DisconnectScoInner(MessageParcel &data, MessageParcel &reply)
100+{
139 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());101 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
140 if (!device) {102 if (!device) {
141 return TRANSACTION_ERR;103 return TRANSACTION_ERR;
@@ -148,7 +110,8 @@ ErrCode BluetoothHfpHfStub::DisconnectScoInner(MessageParcel &data, MessageParce
148 return NO_ERROR;110 return NO_ERROR;
149}111}
150 112 
151-ErrCode BluetoothHfpHfStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply) {113+int32_t BluetoothHfpHfStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
114+{
152 std::vector<BluetoothRawAddress> devices;115 std::vector<BluetoothRawAddress> devices;
153 std::vector<int> states;116 std::vector<int> states;
154 data.ReadInt32Vector(&states);117 data.ReadInt32Vector(&states);
@@ -167,7 +130,8 @@ ErrCode BluetoothHfpHfStub::GetDevicesByStatesInner(MessageParcel &data, Message
167 return NO_ERROR;130 return NO_ERROR;
168}131}
169 132 
170-ErrCode BluetoothHfpHfStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply) {133+int32_t BluetoothHfpHfStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
134+{
171 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());135 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
172 if (!device) {136 if (!device) {
173 return TRANSACTION_ERR;137 return TRANSACTION_ERR;
@@ -180,7 +144,8 @@ ErrCode BluetoothHfpHfStub::GetDeviceStateInner(MessageParcel &data, MessageParc
180 return NO_ERROR;144 return NO_ERROR;
181}145}
182 146 
183-ErrCode BluetoothHfpHfStub::GetScoStateInner(MessageParcel &data, MessageParcel &reply) {147+int32_t BluetoothHfpHfStub::GetScoStateInner(MessageParcel &data, MessageParcel &reply)
148+{
184 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());149 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
185 if (!device) {150 if (!device) {
186 return TRANSACTION_ERR;151 return TRANSACTION_ERR;
@@ -193,7 +158,8 @@ ErrCode BluetoothHfpHfStub::GetScoStateInner(MessageParcel &data, MessageParcel
193 return NO_ERROR;158 return NO_ERROR;
194}159}
195 160 
196-ErrCode BluetoothHfpHfStub::SendDTMFToneInner(MessageParcel &data, MessageParcel &reply) {161+int32_t BluetoothHfpHfStub::SendDTMFToneInner(MessageParcel &data, MessageParcel &reply)
162+{
197 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());163 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
198 if (!device) {164 if (!device) {
199 return TRANSACTION_ERR;165 return TRANSACTION_ERR;
@@ -207,7 +173,8 @@ ErrCode BluetoothHfpHfStub::SendDTMFToneInner(MessageParcel &data, MessageParcel
207 return NO_ERROR;173 return NO_ERROR;
208}174}
209 175 
210-ErrCode BluetoothHfpHfStub::ConnectInner(MessageParcel &data, MessageParcel &reply) {176+int32_t BluetoothHfpHfStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
177+{
211 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());178 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
212 if (!device) {179 if (!device) {
213 return TRANSACTION_ERR;180 return TRANSACTION_ERR;
@@ -220,7 +187,8 @@ ErrCode BluetoothHfpHfStub::ConnectInner(MessageParcel &data, MessageParcel &rep
220 return NO_ERROR;187 return NO_ERROR;
221}188}
222 189 
223-ErrCode BluetoothHfpHfStub::DisconnectInner(MessageParcel &data, MessageParcel &reply) {190+int32_t BluetoothHfpHfStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
191+{
224 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());192 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
225 if (!device) {193 if (!device) {
226 return TRANSACTION_ERR;194 return TRANSACTION_ERR;
@@ -233,7 +201,8 @@ ErrCode BluetoothHfpHfStub::DisconnectInner(MessageParcel &data, MessageParcel &
233 return NO_ERROR;201 return NO_ERROR;
234}202}
235 203 
236-ErrCode BluetoothHfpHfStub::OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply) {204+int32_t BluetoothHfpHfStub::OpenVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)
205+{
237 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());206 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
238 if (!device) {207 if (!device) {
239 return TRANSACTION_ERR;208 return TRANSACTION_ERR;
@@ -246,7 +215,8 @@ ErrCode BluetoothHfpHfStub::OpenVoiceRecognitionInner(MessageParcel &data, Messa
246 return NO_ERROR;215 return NO_ERROR;
247}216}
248 217 
249-ErrCode BluetoothHfpHfStub::CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply) {218+int32_t BluetoothHfpHfStub::CloseVoiceRecognitionInner(MessageParcel &data, MessageParcel &reply)
219+{
250 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());220 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
251 if (!device) {221 if (!device) {
252 return TRANSACTION_ERR;222 return TRANSACTION_ERR;
@@ -259,7 +229,8 @@ ErrCode BluetoothHfpHfStub::CloseVoiceRecognitionInner(MessageParcel &data, Mess
259 return NO_ERROR;229 return NO_ERROR;
260}230}
261 231 
262-ErrCode BluetoothHfpHfStub::GetCurrentCallListInner(MessageParcel &data, MessageParcel &reply) {232+int32_t BluetoothHfpHfStub::GetCurrentCallListInner(MessageParcel &data, MessageParcel &reply)
233+{
263 std::vector<BluetoothHfpHfCall> calls;234 std::vector<BluetoothHfpHfCall> calls;
264 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());235 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
265 if (!device) {236 if (!device) {
@@ -280,7 +251,8 @@ ErrCode BluetoothHfpHfStub::GetCurrentCallListInner(MessageParcel &data, Message
280 return NO_ERROR;251 return NO_ERROR;
281}252}
282 253 
283-ErrCode BluetoothHfpHfStub::AcceptIncomingCallInner(MessageParcel &data, MessageParcel &reply) {254+int32_t BluetoothHfpHfStub::AcceptIncomingCallInner(MessageParcel &data, MessageParcel &reply)
255+{
284 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());256 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
285 if (!device) {257 if (!device) {
286 return TRANSACTION_ERR;258 return TRANSACTION_ERR;
@@ -294,7 +266,8 @@ ErrCode BluetoothHfpHfStub::AcceptIncomingCallInner(MessageParcel &data, Message
294 return NO_ERROR;266 return NO_ERROR;
295}267}
296 268 
297-ErrCode BluetoothHfpHfStub::HoldActiveCallInner(MessageParcel &data, MessageParcel &reply) {269+int32_t BluetoothHfpHfStub::HoldActiveCallInner(MessageParcel &data, MessageParcel &reply)
270+{
298 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());271 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
299 if (!device) {272 if (!device) {
300 return TRANSACTION_ERR;273 return TRANSACTION_ERR;
@@ -307,7 +280,8 @@ ErrCode BluetoothHfpHfStub::HoldActiveCallInner(MessageParcel &data, MessageParc
307 return NO_ERROR;280 return NO_ERROR;
308}281}
309 282 
310-ErrCode BluetoothHfpHfStub::SendKeyPressedInner(MessageParcel &data, MessageParcel &reply) {283+int32_t BluetoothHfpHfStub::SendKeyPressedInner(MessageParcel &data, MessageParcel &reply)
284+{
311 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());285 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
312 if (!device) {286 if (!device) {
313 return TRANSACTION_ERR;287 return TRANSACTION_ERR;
@@ -320,7 +294,8 @@ ErrCode BluetoothHfpHfStub::SendKeyPressedInner(MessageParcel &data, MessageParc
320 return NO_ERROR;294 return NO_ERROR;
321}295}
322 296 
323-ErrCode BluetoothHfpHfStub::RejectIncomingCallInner(MessageParcel &data, MessageParcel &reply) {297+int32_t BluetoothHfpHfStub::RejectIncomingCallInner(MessageParcel &data, MessageParcel &reply)
298+{
324 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());299 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
325 if (!device) {300 if (!device) {
326 return TRANSACTION_ERR;301 return TRANSACTION_ERR;
@@ -333,7 +308,7 @@ ErrCode BluetoothHfpHfStub::RejectIncomingCallInner(MessageParcel &data, Message
333 return NO_ERROR;308 return NO_ERROR;
334}309}
335 310 
336-ErrCode BluetoothHfpHfStub::HandleIncomingCallInner(MessageParcel &data, MessageParcel &reply)311+int32_t BluetoothHfpHfStub::HandleIncomingCallInner(MessageParcel &data, MessageParcel &reply)
337{312{
338 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());313 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
339 if (!device) {314 if (!device) {
@@ -349,7 +324,7 @@ ErrCode BluetoothHfpHfStub::HandleIncomingCallInner(MessageParcel &data, Message
349 return NO_ERROR;324 return NO_ERROR;
350}325}
351 326 
352-ErrCode BluetoothHfpHfStub::HandleMultiCallInner(MessageParcel &data, MessageParcel &reply)327+int32_t BluetoothHfpHfStub::HandleMultiCallInner(MessageParcel &data, MessageParcel &reply)
353{328{
354 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());329 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
355 if (!device) {330 if (!device) {
@@ -366,7 +341,7 @@ ErrCode BluetoothHfpHfStub::HandleMultiCallInner(MessageParcel &data, MessagePar
366 return NO_ERROR;341 return NO_ERROR;
367}342}
368 343 
369-ErrCode BluetoothHfpHfStub::DialLastNumberInner(MessageParcel &data, MessageParcel &reply)344+int32_t BluetoothHfpHfStub::DialLastNumberInner(MessageParcel &data, MessageParcel &reply)
370{345{
371 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());346 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
372 if (!device) {347 if (!device) {
@@ -381,7 +356,7 @@ ErrCode BluetoothHfpHfStub::DialLastNumberInner(MessageParcel &data, MessageParc
381 return NO_ERROR;356 return NO_ERROR;
382}357}
383 358 
384-ErrCode BluetoothHfpHfStub::DialMemoryInner(MessageParcel &data, MessageParcel &reply)359+int32_t BluetoothHfpHfStub::DialMemoryInner(MessageParcel &data, MessageParcel &reply)
385{360{
386 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());361 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
387 if (!device) {362 if (!device) {
@@ -398,7 +373,7 @@ ErrCode BluetoothHfpHfStub::DialMemoryInner(MessageParcel &data, MessageParcel &
398 return NO_ERROR;373 return NO_ERROR;
399}374}
400 375 
401-ErrCode BluetoothHfpHfStub::SendVoiceTagInner(MessageParcel &data, MessageParcel &reply)376+int32_t BluetoothHfpHfStub::SendVoiceTagInner(MessageParcel &data, MessageParcel &reply)
402{377{
403 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());378 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
404 if (!device) {379 if (!device) {
@@ -415,7 +390,8 @@ ErrCode BluetoothHfpHfStub::SendVoiceTagInner(MessageParcel &data, MessageParcel
415}390}
416 391 
417 392 
418-ErrCode BluetoothHfpHfStub::FinishActiveCallInner(MessageParcel &data, MessageParcel &reply) {393+int32_t BluetoothHfpHfStub::FinishActiveCallInner(MessageParcel &data, MessageParcel &reply)
394+{
419 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());395 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
420 if (!device) {396 if (!device) {
421 return TRANSACTION_ERR;397 return TRANSACTION_ERR;
@@ -432,7 +408,8 @@ ErrCode BluetoothHfpHfStub::FinishActiveCallInner(MessageParcel &data, MessagePa
432 return NO_ERROR;408 return NO_ERROR;
433}409}
434 410 
435-ErrCode BluetoothHfpHfStub::StartDialInner(MessageParcel &data, MessageParcel &reply) {411+int32_t BluetoothHfpHfStub::StartDialInner(MessageParcel &data, MessageParcel &reply)
412+{
436 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());413 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
437 if (!device) {414 if (!device) {
438 return TRANSACTION_ERR;415 return TRANSACTION_ERR;
@@ -450,14 +427,16 @@ ErrCode BluetoothHfpHfStub::StartDialInner(MessageParcel &data, MessageParcel &r
450 return NO_ERROR;427 return NO_ERROR;
451}428}
452 429 
453-ErrCode BluetoothHfpHfStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply) {430+int32_t BluetoothHfpHfStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
431+{
454 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();432 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
455 sptr<IBluetoothHfpHfObserver> observer = iface_cast<IBluetoothHfpHfObserver>(tempObject);433 sptr<IBluetoothHfpHfObserver> observer = iface_cast<IBluetoothHfpHfObserver>(tempObject);
456 RegisterObserver(observer);434 RegisterObserver(observer);
457 return NO_ERROR;435 return NO_ERROR;
458}436}
459 437 
460-ErrCode BluetoothHfpHfStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply) {438+int32_t BluetoothHfpHfStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
439+{
461 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();440 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
462 sptr<IBluetoothHfpHfObserver> observer = iface_cast<IBluetoothHfpHfObserver>(tempObject);441 sptr<IBluetoothHfpHfObserver> observer = iface_cast<IBluetoothHfpHfObserver>(tempObject);
463 DeregisterObserver(observer);442 DeregisterObserver(observer);
Mservices/bluetooth/ipc/src/bluetooth_hid_device_stub.cpp+40-52
@@ -16,68 +16,56 @@
16 16 
17#include "bluetooth_errorcode.h"17#include "bluetooth_errorcode.h"
18#include "bluetooth_log.h"18#include "bluetooth_log.h"
19+#include "permission_manager.h"
20+#ifdef STUB_FUNC
21+#undef STUB_FUNC
22+#endif
23+#define STUB_FUNC(code, func, perm) BluetoothHidDeviceInterfaceCode::code, {&BluetoothHidDeviceStub::func, perm}
24+ 
19 25 
20namespace OHOS {26namespace OHOS {
21namespace Bluetooth {27namespace Bluetooth {
28+using namespace OHOS::bluetooth;
29+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
30+const std::map<uint32_t, BluetoothHidDeviceStub::HidDeviceStubFuncPerm> BluetoothHidDeviceStub::memberFuncMap_ = {
31+ {STUB_FUNC(COMMAND_CONNECT, ConnectInner,
32+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
33+ {STUB_FUNC(COMMAND_DISCONNECT, DisconnectInner,
34+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
35+ {STUB_FUNC(COMMAND_GET_CONNECTION_STATE, GetConnectionStateInner,
36+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
37+ {STUB_FUNC(COMMAND_GET_CONNECTED_DEVICES, GetConnectedDevicesInner,
38+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
39+ {STUB_FUNC(COMMAND_REGISTER_APP, RegisterAppInner,
40+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
41+ {STUB_FUNC(COMMAND_UNREGISTER_APP, UnRegisterAppInner,
42+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
43+ {STUB_FUNC(COMMAND_REGISTER_OBSERVER, RegisterObserverInner,
44+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
45+ {STUB_FUNC(COMMAND_DEREGISTER_OBSERVER, DeregisterObserverInner,
46+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
47+ {STUB_FUNC(COMMAND_SEND_REPORT, SendReportInner,
48+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
49+ {STUB_FUNC(COMMAND_REPLY_REPORT, ReplyReportInner,
50+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
51+ {STUB_FUNC(COMMAND_REPORT_ERROR, ReportErrorInner,
52+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
53+ {STUB_FUNC(COMMAND_SET_CONNECT_STRATEGY, HidDeviceSetConnectStrategyInner,
54+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
55+ {STUB_FUNC(COMMAND_GET_CONNECT_STRATEGY, HidDeviceGetConnectStrategyInner,
56+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
57+};
58+ 
22BluetoothHidDeviceStub::BluetoothHidDeviceStub()59BluetoothHidDeviceStub::BluetoothHidDeviceStub()
23-{60+{}
24- HILOGD("%{public}s start.", __func__);
25- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_REGISTER_APP)] =
26- &BluetoothHidDeviceStub::RegisterAppInner;
27- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_UNREGISTER_APP)] =
28- &BluetoothHidDeviceStub::UnRegisterAppInner;
29- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_CONNECT)] =
30- &BluetoothHidDeviceStub::ConnectInner;
31- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_DISCONNECT)] =
32- &BluetoothHidDeviceStub::DisconnectInner;
33- 
34- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_GET_CONNECTION_STATE)] =
35- &BluetoothHidDeviceStub::GetConnectionStateInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_GET_CONNECTED_DEVICES)] =
37- &BluetoothHidDeviceStub::GetConnectedDevicesInner;
38- 
39- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_REGISTER_OBSERVER)] =
40- &BluetoothHidDeviceStub::RegisterObserverInner;
41- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_DEREGISTER_OBSERVER)] =
42- &BluetoothHidDeviceStub::DeregisterObserverInner;
43- 
44- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_SEND_REPORT)] =
45- &BluetoothHidDeviceStub::SendReportInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_REPLY_REPORT)] =
47- &BluetoothHidDeviceStub::ReplyReportInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_REPORT_ERROR)] =
49- &BluetoothHidDeviceStub::ReportErrorInner;
50- 
51- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_SET_CONNECT_STRATEGY)] =
52- &BluetoothHidDeviceStub::HidDeviceSetConnectStrategyInner;
53- memberFuncMap_[static_cast<uint32_t>(BluetoothHidDeviceInterfaceCode::COMMAND_GET_CONNECT_STRATEGY)] =
54- &BluetoothHidDeviceStub::HidDeviceGetConnectStrategyInner;
55- HILOGD("%{public}s ends.", __func__);
56-}
57 61 
58BluetoothHidDeviceStub::~BluetoothHidDeviceStub()62BluetoothHidDeviceStub::~BluetoothHidDeviceStub()
59-{63+{}
60- HILOGD("%{public}s start.", __func__);
61- memberFuncMap_.clear();
62-}
63 64 
64int BluetoothHidDeviceStub::OnRemoteRequest(65int BluetoothHidDeviceStub::OnRemoteRequest(
65 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)66 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
66{67{
67- HILOGI("BluetoothHidDeviceStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());68+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothHidDeviceStub);
68- if (BluetoothHidDeviceStub::GetDescriptor() != data.ReadInterfaceToken()) {
69- HILOGE("local descriptor is not equal to remote");
70- return IPC_INVOKER_TRANSLATE_ERR;
71- }
72- auto itFunc = memberFuncMap_.find(code);
73- if (itFunc != memberFuncMap_.end()) {
74- auto memberFunc = itFunc->second;
75- if (memberFunc != nullptr) {
76- return (this->*memberFunc)(data, reply);
77- }
78- }
79- HILOGW("BluetoothHidDeviceStub::OnRemoteRequest, default case, need check.");
80- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
81}69}
82 70 
83int32_t BluetoothHidDeviceStub::ConnectInner(MessageParcel &data, MessageParcel &reply)71int32_t BluetoothHidDeviceStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
Mservices/bluetooth/ipc/src/bluetooth_hid_host_stub.cpp+37-46
@@ -16,63 +16,54 @@
16 16 
17#include "bluetooth_errorcode.h"17#include "bluetooth_errorcode.h"
18#include "bluetooth_log.h"18#include "bluetooth_log.h"
19+#include "permission_manager.h"
20+ 
21+#ifdef STUB_FUNC
22+#undef STUB_FUNC
23+#endif
24+#define STUB_FUNC(code, func, perm) \
25+static_cast<uint32_t>(BluetoothHidHostInterfaceCode::code), {&BluetoothHidHostStub::func, perm} \
19 26 
20namespace OHOS {27namespace OHOS {
21namespace Bluetooth {28namespace Bluetooth {
29+using namespace OHOS::bluetooth;
22const uint32_t HID_DEVICE_BY_STATES_NUM_MAX = 0XFF;30const uint32_t HID_DEVICE_BY_STATES_NUM_MAX = 0XFF;
31+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
32+const std::map<uint32_t, BluetoothHidHostStub::HidHostStubFuncPerm> BluetoothHidHostStub::memberFuncMap_ = {
33+ {STUB_FUNC(COMMAND_CONNECT, ConnectInner,
34+ CHECK_PERM(true, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
35+ {STUB_FUNC(COMMAND_DISCONNECT, DisconnectInner,
36+ CHECK_PERM(true, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
37+ {STUB_FUNC(COMMAND_GET_DEVICE_STATE, GetDeviceStateInner,
38+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
39+ {STUB_FUNC(COMMAND_GET_DEVICES_BY_STATES, GetDevicesByStatesInner,
40+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
41+ {STUB_FUNC(COMMAND_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
42+ {STUB_FUNC(COMMAND_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
43+ {STUB_FUNC(COMMAND_VCUN_PLUG, HidHostVCUnplugInner,
44+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
45+ {STUB_FUNC(COMMAND_SEND_DATA, HidHostSendDataInner,
46+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
47+ {STUB_FUNC(COMMAND_SET_REPORT, HidHostSetReportInner,
48+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
49+ {STUB_FUNC(COMMAND_GET_REPORT, HidHostGetReportInner,
50+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
51+ {STUB_FUNC(COMMAND_SET_CONNECT_STRATEGY, HidHostSetConnectStrategyInner,
52+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
53+ {STUB_FUNC(COMMAND_GET_CONNECT_STRATEGY, HidHostGetConnectStrategyInner,
54+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
55+};
56+ 
23BluetoothHidHostStub::BluetoothHidHostStub()57BluetoothHidHostStub::BluetoothHidHostStub()
24-{58+{}
25- HILOGD("%{public}s start.", __func__);
26- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_CONNECT)] =
27- &BluetoothHidHostStub::ConnectInner;
28- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_DISCONNECT)] =
29- &BluetoothHidHostStub::DisconnectInner;
30- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_GET_DEVICE_STATE)] =
31- &BluetoothHidHostStub::GetDeviceStateInner;
32- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_GET_DEVICES_BY_STATES)] =
33- &BluetoothHidHostStub::GetDevicesByStatesInner;
34- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_REGISTER_OBSERVER)] =
35- &BluetoothHidHostStub::RegisterObserverInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_DEREGISTER_OBSERVER)] =
37- &BluetoothHidHostStub::DeregisterObserverInner;
38- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_VCUN_PLUG)] =
39- &BluetoothHidHostStub::HidHostVCUnplugInner;
40- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_SEND_DATA)] =
41- &BluetoothHidHostStub::HidHostSendDataInner;
42- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_SET_REPORT)] =
43- &BluetoothHidHostStub::HidHostSetReportInner;
44- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_GET_REPORT)] =
45- &BluetoothHidHostStub::HidHostGetReportInner;
46- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_SET_CONNECT_STRATEGY)] =
47- &BluetoothHidHostStub::HidHostSetConnectStrategyInner;
48- memberFuncMap_[static_cast<uint32_t>(BluetoothHidHostInterfaceCode::COMMAND_GET_CONNECT_STRATEGY)] =
49- &BluetoothHidHostStub::HidHostGetConnectStrategyInner;
50- HILOGD("%{public}s ends.", __func__);
51-}
52 59 
53BluetoothHidHostStub::~BluetoothHidHostStub()60BluetoothHidHostStub::~BluetoothHidHostStub()
54-{61+{}
55- HILOGD("%{public}s start.", __func__);
56- memberFuncMap_.clear();
57-}
58 62 
59int BluetoothHidHostStub::OnRemoteRequest(63int BluetoothHidHostStub::OnRemoteRequest(
60 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)64 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
61{65{
62- HILOGI("BluetoothHidHostStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());66+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothHidHostStub);
63- if (BluetoothHidHostStub::GetDescriptor() != data.ReadInterfaceToken()) {
64- HILOGE("local descriptor is not equal to remote");
65- return IPC_INVOKER_TRANSLATE_ERR;
66- }
67- auto itFunc = memberFuncMap_.find(code);
68- if (itFunc != memberFuncMap_.end()) {
69- auto memberFunc = itFunc->second;
70- if (memberFunc != nullptr) {
71- return (this->*memberFunc)(data, reply);
72- }
73- }
74- HILOGW("BluetoothHfpHfStub::OnRemoteRequest, default case, need check.");
75- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
76}67}
77 68 
78int32_t BluetoothHidHostStub::ConnectInner(MessageParcel &data, MessageParcel &reply)69int32_t BluetoothHidHostStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
Mservices/bluetooth/ipc/src/bluetooth_host_stub.cpp+197-338
@@ -19,312 +19,171 @@
19#include "ipc_types.h"19#include "ipc_types.h"
20#include "raw_address.h"20#include "raw_address.h"
21#include "string_ex.h"21#include "string_ex.h"
22-#include "permission_utils.h"22+#include "permission_manager.h"
23+ 
24+#ifdef STUB_FUNC
25+#undef STUB_FUNC
26+#endif
27+#define STUB_FUNC(code, func, perm) BluetoothHostInterfaceCode::code, {&BluetoothHostStub::func, perm}
23 28 
24namespace OHOS {29namespace OHOS {
25namespace Bluetooth {30namespace Bluetooth {
26-const std::map<uint32_t, std::function<ErrCode(BluetoothHostStub *, MessageParcel &, MessageParcel &)>>31+using namespace OHOS::bluetooth;
27- BluetoothHostStub::memberFuncMap_ = {32+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
28- {BluetoothHostInterfaceCode::BT_REGISTER_OBSERVER,33+const std::map<uint32_t, BluetoothHostStub::BluetoothHostStubFuncPerm> BluetoothHostStub::memberFuncMap_ = {
29- std::bind(&BluetoothHostStub::RegisterObserverInner, std::placeholders::_1, std::placeholders::_2,34+ {STUB_FUNC(BT_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
30- std::placeholders::_3)},35+ {STUB_FUNC(BT_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
31- {BluetoothHostInterfaceCode::BT_DEREGISTER_OBSERVER,36+ {STUB_FUNC(BT_ENABLE, EnableBtInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
32- std::bind(&BluetoothHostStub::DeregisterObserverInner, std::placeholders::_1, std::placeholders::_2,37+ {STUB_FUNC(BT_DISABLE, DisableBtInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
33- std::placeholders::_3)},38+ {STUB_FUNC(BT_GETPROFILE, GetProfileInner, nullptr)},
34- {BluetoothHostInterfaceCode::BT_ENABLE,39+ {STUB_FUNC(BT_GET_BLE, GetBleRemoteInner, nullptr)},
35- std::bind(&BluetoothHostStub::EnableBtInner, std::placeholders::_1, std::placeholders::_2,40+ {STUB_FUNC(BT_FACTORY_RESET, BluetoothFactoryResetInner,
36- std::placeholders::_3)},41+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
37- {BluetoothHostInterfaceCode::BT_DISABLE,42+ {STUB_FUNC(BT_GETSTATE, GetBtStateInner, nullptr)},
38- std::bind(&BluetoothHostStub::DisableBtInner, std::placeholders::_1, std::placeholders::_2,43+ {STUB_FUNC(BT_GET_LOCAL_ADDRESS, GetLocalAddressInner,
39- std::placeholders::_3)},44+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, GET_BLUETOOTH_LOCAL_MAC)))},
40- {BluetoothHostInterfaceCode::BT_GETPROFILE,45+ {STUB_FUNC(BT_GENERATE_LOCAL_OOB_DATA, GenerateLocalOobDataInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
41- std::bind(&BluetoothHostStub::GetProfileInner, std::placeholders::_1, std::placeholders::_2,46+ {STUB_FUNC(BT_DISABLE_BLE, DisableBleInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
42- std::placeholders::_3)},47+ {STUB_FUNC(BT_ENABLE_BLE, EnableBleInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
43- {BluetoothHostInterfaceCode::BT_GET_BLE,48+ {STUB_FUNC(BT_GET_PROFILE_LIST, GetProfileListInner,
44- std::bind(&BluetoothHostStub::GetBleRemoteInner, std::placeholders::_1, std::placeholders::_2,49+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
45- std::placeholders::_3)},50+ {STUB_FUNC(BT_GET_MAXNUM_CONNECTED_AUDIODEVICES, GetMaxNumConnectedAudioDevicesInner,
46- {BluetoothHostInterfaceCode::BT_FACTORY_RESET,51+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
47- std::bind(&BluetoothHostStub::BluetoothFactoryResetInner, std::placeholders::_1, std::placeholders::_2,52+ {STUB_FUNC(BT_GET_BT_STATE, GetBtConnectionStateInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
48- std::placeholders::_3)},53+ {STUB_FUNC(BT_GET_BT_PROFILE_CONNSTATE, GetBtProfileConnStateInner,
49- {BluetoothHostInterfaceCode::BT_GETSTATE,54+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
50- std::bind(&BluetoothHostStub::GetBtStateInner, std::placeholders::_1, std::placeholders::_2,55+ {STUB_FUNC(BT_GET_LOCAL_DEVICE_CLASS, GetLocalDeviceClassInner,
51- std::placeholders::_3)},56+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
52- {BluetoothHostInterfaceCode::BT_GET_LOCAL_ADDRESS,57+ {STUB_FUNC(BT_SET_LOCAL_DEVICE_CLASS, SetLocalDeviceClassInner,
53- std::bind(&BluetoothHostStub::GetLocalAddressInner, std::placeholders::_1, std::placeholders::_2,58+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
54- std::placeholders::_3)},59+ {STUB_FUNC(BT_GET_LOCAL_NAME, GetLocalNameInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
55- {BluetoothHostInterfaceCode::BT_GENERATE_LOCAL_OOB_DATA,60+ {STUB_FUNC(BT_SET_LOCAL_NAME, SetLocalNameInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
56- std::bind(&BluetoothHostStub::GenerateLocalOobDataInner, std::placeholders::_1, std::placeholders::_2,61+ {STUB_FUNC(BT_GET_BT_SCAN_MODE, GetBtScanModeInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
57- std::placeholders::_3)},62+ {STUB_FUNC(BT_SET_BT_SCAN_MODE, SetBtScanModeInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
58- {BluetoothHostInterfaceCode::BT_DISABLE_BLE,63+ {STUB_FUNC(BT_GET_BONDABLE_MODE, GetBondableModeInner,
59- std::bind(&BluetoothHostStub::DisableBleInner, std::placeholders::_1, std::placeholders::_2,64+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
60- std::placeholders::_3)},65+ {STUB_FUNC(BT_SET_BONDABLE_MODE, SetBondableModeInner,
61- {BluetoothHostInterfaceCode::BT_ENABLE_BLE,66+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
62- std::bind(&BluetoothHostStub::EnableBleInner, std::placeholders::_1, std::placeholders::_2,67+ {STUB_FUNC(BT_START_BT_DISCOVERY, StartBtDiscoveryInner, nullptr)},
63- std::placeholders::_3)},68+ {STUB_FUNC(BT_CANCEL_BT_DISCOVERY, CancelBtDiscoveryInner,
64- {BluetoothHostInterfaceCode::BT_GET_PROFILE_LIST,69+ CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
65- std::bind(&BluetoothHostStub::GetProfileListInner, std::placeholders::_1, std::placeholders::_2,70+ {STUB_FUNC(BT_IS_BT_DISCOVERING, IsBtDiscoveringInner, CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
66- std::placeholders::_3)},71+ {STUB_FUNC(BT_GET_BT_DISCOVERY_END_MILLIS, GetBtDiscoveryEndMillisInner,
67- {BluetoothHostInterfaceCode::BT_GET_MAXNUM_CONNECTED_AUDIODEVICES,72+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
68- std::bind(&BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner, std::placeholders::_1,73+ {STUB_FUNC(BT_GET_PAIRED_DEVICES, GetPairedDevicesInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
69- std::placeholders::_2, std::placeholders::_3)},74+ {STUB_FUNC(BT_REMOVE_PAIR, RemovePairInner, CHECK_PERM(true, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
70- {BluetoothHostInterfaceCode::BT_GET_BT_STATE,75+ {STUB_FUNC(BT_REMOVE_ALL_PAIRS, RemoveAllPairsInner,
71- std::bind(&BluetoothHostStub::GetBtConnectionStateInner, std::placeholders::_1, std::placeholders::_2,76+ CHECK_PERM(true, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
72- std::placeholders::_3)},77+ {STUB_FUNC(CANCEL_PAIRING, CancelPairingInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
73- {BluetoothHostInterfaceCode::BT_GET_BT_PROFILE_CONNSTATE,78+ {STUB_FUNC(BT_REGISTER_REMOTE_DEVICE_OBSERVER, RegisterRemoteDeviceObserverInner, nullptr)},
74- std::bind(&BluetoothHostStub::GetBtProfileConnStateInner, std::placeholders::_1, std::placeholders::_2,79+ {STUB_FUNC(BT_DEREGISTER_REMOTE_DEVICE_OBSERVER, DeregisterRemoteDeviceObserverInner, nullptr)},
75- std::placeholders::_3)},80+ {STUB_FUNC(BT_GET_BLE_MAX_ADVERTISING_DATALENGTH, GetBleMaxAdvertisingDataLengthInner, nullptr)},
76- {BluetoothHostInterfaceCode::BT_GET_LOCAL_DEVICE_CLASS,81+ {STUB_FUNC(BT_GET_CONNECTED_BLE_DEVICES, GetConnectedBLEDevicesInner,
77- std::bind(&BluetoothHostStub::GetLocalDeviceClassInner, std::placeholders::_1, std::placeholders::_2,82+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
78- std::placeholders::_3)},83+ {STUB_FUNC(GET_DEVICE_TYPE, GetDeviceTypeInner, nullptr)},
79- {BluetoothHostInterfaceCode::BT_SET_LOCAL_DEVICE_CLASS,84+ {STUB_FUNC(GET_PHONEBOOK_PERMISSION, GetPhonebookPermissionInner,
80- std::bind(&BluetoothHostStub::SetLocalDeviceClassInner, std::placeholders::_1, std::placeholders::_2,85+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
81- std::placeholders::_3)},86+ {STUB_FUNC(SET_PHONEBOOK_PERMISSION, SetPhonebookPermissionInner,
82- {BluetoothHostInterfaceCode::BT_GET_LOCAL_NAME,87+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
83- std::bind(&BluetoothHostStub::GetLocalNameInner, std::placeholders::_1, std::placeholders::_2,88+ {STUB_FUNC(GET_MESSAGE_PERMISSION, GetMessagePermissionInner,
84- std::placeholders::_3)},89+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
85- {BluetoothHostInterfaceCode::BT_SET_LOCAL_NAME,90+ {STUB_FUNC(SET_MESSAGE_PERMISSION, SetMessagePermissionInner,
86- std::bind(&BluetoothHostStub::SetLocalNameInner, std::placeholders::_1, std::placeholders::_2,91+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
87- std::placeholders::_3)},92+ {STUB_FUNC(GET_POWER_MODE, GetPowerModeInner,
88- {BluetoothHostInterfaceCode::BT_GET_BT_SCAN_MODE,93+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
89- std::bind(&BluetoothHostStub::GetBtScanModeInner, std::placeholders::_1, std::placeholders::_2,94+ {STUB_FUNC(GET_DEVICE_NAME, GetDeviceNameInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
90- std::placeholders::_3)},95+ {STUB_FUNC(GET_DEVICE_ALIAS, GetDeviceAliasInner,
91- {BluetoothHostInterfaceCode::BT_SET_BT_SCAN_MODE,96+ CHECK_PERM(true, {USE_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
92- std::bind(&BluetoothHostStub::SetBtScanModeInner, std::placeholders::_1, std::placeholders::_2,97+ {STUB_FUNC(SET_DEVICE_ALIAS, SetDeviceAliasInner,
93- std::placeholders::_3)},98+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
94- {BluetoothHostInterfaceCode::BT_GET_BONDABLE_MODE,99+ {STUB_FUNC(GET_DEVICE_BATTERY_INFO, GetRemoteDeviceBatteryInfoInner, CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
95- std::bind(&BluetoothHostStub::GetBondableModeInner, std::placeholders::_1, std::placeholders::_2,100+ {STUB_FUNC(SET_DEVICE_BATTERY_INFO, SetRemoteDeviceBatteryInfoInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
96- std::placeholders::_3)},101+ {STUB_FUNC(GET_PAIR_STATE, GetPairStateInner, CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
97- {BluetoothHostInterfaceCode::BT_SET_BONDABLE_MODE,102+ {STUB_FUNC(START_PAIR, StartPairInner, CHECK_PERM(false, {DISCOVER_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
98- std::bind(&BluetoothHostStub::SetBondableModeInner, std::placeholders::_1, std::placeholders::_2,103+ {STUB_FUNC(START_CREDIBLE_PAIR, StartCrediblePairInner,
99- std::placeholders::_3)},104+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
100- {BluetoothHostInterfaceCode::BT_START_BT_DISCOVERY,105+ {STUB_FUNC(IS_BONDED_FROM_LOCAL, IsBondedFromLocalInner,
101- std::bind(&BluetoothHostStub::StartBtDiscoveryInner, std::placeholders::_1, std::placeholders::_2,106+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
102- std::placeholders::_3)},107+ {STUB_FUNC(IS_ACL_CONNECTED, IsAclConnectedInner,
103- {BluetoothHostInterfaceCode::BT_CANCEL_BT_DISCOVERY,108+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
104- std::bind(&BluetoothHostStub::CancelBtDiscoveryInner, std::placeholders::_1, std::placeholders::_2,109+ {STUB_FUNC(IS_ACL_ENCRYPTED, IsAclEncryptedInner, nullptr)},
105- std::placeholders::_3)},110+ {STUB_FUNC(GET_DEVICE_CLASS, GetDeviceClassInner, nullptr)},
106- {BluetoothHostInterfaceCode::BT_IS_BT_DISCOVERING,111+ {STUB_FUNC(SET_DEVICE_PIN, SetDevicePinInner, CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
107- std::bind(&BluetoothHostStub::IsBtDiscoveringInner, std::placeholders::_1, std::placeholders::_2,112+ {STUB_FUNC(SET_DEVICE_PAIRING_CONFIRMATION, SetDevicePairingConfirmationInner,
108- std::placeholders::_3)},113+ CHECK_PERM(false, {MANAGE_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
109- {BluetoothHostInterfaceCode::BT_GET_BT_DISCOVERY_END_MILLIS,114+ {STUB_FUNC(SET_DEVICE_PASSKEY, SetDevicePasskeyInner,
110- std::bind(&BluetoothHostStub::GetBtDiscoveryEndMillisInner, std::placeholders::_1, std::placeholders::_2,115+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
111- std::placeholders::_3)},116+ {STUB_FUNC(PAIR_REQUEST_PEPLY, PairRequestReplyInner,
112- {BluetoothHostInterfaceCode::BT_GET_PAIRED_DEVICES,117+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
113- std::bind(&BluetoothHostStub::GetPairedDevicesInner, std::placeholders::_1, std::placeholders::_2,118+ {STUB_FUNC(READ_REMOTE_RSSI_VALUE, ReadRemoteRssiValueInner, nullptr)},
114- std::placeholders::_3)},119+ {STUB_FUNC(GET_LOCAL_SUPPORTED_UUIDS, GetLocalSupportedUuidsInner,
115- {BluetoothHostInterfaceCode::BT_REMOVE_PAIR,120+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
116- std::bind(&BluetoothHostStub::RemovePairInner, std::placeholders::_1, std::placeholders::_2,121+ {STUB_FUNC(GET_LOCAL_PROFILE_UUIDS, GetLocalProfileUuidsInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
117- std::placeholders::_3)},122+ {STUB_FUNC(GET_DEVICE_UUIDS, GetDeviceUuidsInner, CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
118- {BluetoothHostInterfaceCode::BT_REMOVE_ALL_PAIRS,123+ {STUB_FUNC(BT_REGISTER_BLE_ADAPTER_OBSERVER, RegisterBleAdapterObserverInner, nullptr)},
119- std::bind(&BluetoothHostStub::RemoveAllPairsInner, std::placeholders::_1, std::placeholders::_2,124+ {STUB_FUNC(BT_DEREGISTER_BLE_ADAPTER_OBSERVER, DeregisterBleAdapterObserverInner, nullptr)},
120- std::placeholders::_3)},125+ {STUB_FUNC(BT_REGISTER_BLE_PERIPHERAL_OBSERVER, RegisterBlePeripheralCallbackInner, nullptr)},
121- {BluetoothHostInterfaceCode::BT_REGISTER_REMOTE_DEVICE_OBSERVER,126+ {STUB_FUNC(BT_DEREGISTER_BLE_PERIPHERAL_OBSERVER, DeregisterBlePeripheralCallbackInner, nullptr)},
122- std::bind(&BluetoothHostStub::RegisterRemoteDeviceObserverInner, std::placeholders::_1,127+ {STUB_FUNC(BT_SET_FAST_SCAN, SetFastScanInner,
123- std::placeholders::_2, std::placeholders::_3)},128+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
124- {BluetoothHostInterfaceCode::BT_DEREGISTER_REMOTE_DEVICE_OBSERVER,129+ {STUB_FUNC(GET_RANDOM_ADDRESS, GetRandomAddressInner,
125- std::bind(&BluetoothHostStub::DeregisterRemoteDeviceObserverInner, std::placeholders::_1,130+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
126- std::placeholders::_2, std::placeholders::_3)},131+ {STUB_FUNC(SYNC_RANDOM_ADDRESS, SyncRandomAddressInner,
127- {BluetoothHostInterfaceCode::BT_GET_BLE_MAX_ADVERTISING_DATALENGTH,132+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
128- std::bind(&BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner, std::placeholders::_1,133+ {STUB_FUNC(CONNECT_ALLOWED_PROFILES, ConnectAllowedProfilesInner,
129- std::placeholders::_2, std::placeholders::_3)},134+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
130- {BluetoothHostInterfaceCode::BT_GET_CONNECTED_BLE_DEVICES,135+ {STUB_FUNC(DISCONNECT_ALLOWED_PROFILES, DisconnectAllowedProfilesInner,
131- std::bind(&BluetoothHostStub::GetConnectedBLEDevicesInner, std::placeholders::_1,136+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
132- std::placeholders::_2, std::placeholders::_3)},137+ {STUB_FUNC(SET_CUSTOM_TYPE, SetDeviceCustomTypeInner, CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
133- {BluetoothHostInterfaceCode::GET_DEVICE_TYPE,138+ {STUB_FUNC(SATELLITE_CONTROL, SatelliteControlInner,
134- std::bind(&BluetoothHostStub::GetDeviceTypeInner, std::placeholders::_1, std::placeholders::_2,139+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
135- std::placeholders::_3)},140+ {STUB_FUNC(BT_REGISTER_RESOURCE_MANAGER_OBSERVER, RegisterBtResourceManagerObserverInner,
136- {BluetoothHostInterfaceCode::GET_PHONEBOOK_PERMISSION,141+ CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
137- std::bind(&BluetoothHostStub::GetPhonebookPermissionInner, std::placeholders::_1, std::placeholders::_2,142+ {STUB_FUNC(BT_DEREGISTER_RESOURCE_MANAGER_OBSERVER, DeregisterBtResourceManagerObserverInner,
138- std::placeholders::_3)},143+ CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
139- {BluetoothHostInterfaceCode::SET_PHONEBOOK_PERMISSION,144+ {STUB_FUNC(GET_VIRTUAL_AUTO_CONN_SWITCH, IsSupportVirtualAutoConnectInner,
140- nullptr},145+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
141- {BluetoothHostInterfaceCode::GET_MESSAGE_PERMISSION,146+ {STUB_FUNC(SET_VIRTUAL_AUTO_CONN_TYPE, SetVirtualAutoConnectTypeInner,
142- std::bind(&BluetoothHostStub::GetMessagePermissionInner, std::placeholders::_1, std::placeholders::_2,147+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
143- std::placeholders::_3)},148+ {STUB_FUNC(SET_FAST_SCAN_LEVEL, SetFastScanLevelInner,
144- {BluetoothHostInterfaceCode::SET_MESSAGE_PERMISSION,149+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
145- nullptr},150+ {STUB_FUNC(UPDATE_VIRTUAL_DEVICE, UpdateVirtualDeviceInner,
146- {BluetoothHostInterfaceCode::GET_POWER_MODE,151+ CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
147- std::bind(&BluetoothHostStub::GetPowerModeInner, std::placeholders::_1, std::placeholders::_2,152+ {STUB_FUNC(CTRL_DEVICE_ACTION, ControlDeviceActionInner,
148- std::placeholders::_3)},153+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
149- {BluetoothHostInterfaceCode::GET_DEVICE_NAME,154+ {STUB_FUNC(GET_CONNECTION_TIME, GetLastConnectionTimeInner, nullptr)},
150- std::bind(&BluetoothHostStub::GetDeviceNameInner, std::placeholders::_1, std::placeholders::_2,155+ {STUB_FUNC(BT_UPDATE_CLOUD_DEVICE, UpdateCloudBluetoothDevInner,
151- std::placeholders::_3)},156+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
152- {BluetoothHostInterfaceCode::GET_DEVICE_ALIAS,157+ {STUB_FUNC(GET_CLOUD_BOND_STATE, GetCloudBondStateInner,
153- std::bind(&BluetoothHostStub::GetDeviceAliasInner, std::placeholders::_1, std::placeholders::_2,158+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
154- std::placeholders::_3)},159+ {STUB_FUNC(BT_UPDATE_REFUSE_POLICY, UpdateRefusePolicyInner,
155- {BluetoothHostInterfaceCode::SET_DEVICE_ALIAS,160+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
156- std::bind(&BluetoothHostStub::SetDeviceAliasInner, std::placeholders::_1, std::placeholders::_2,161+ {STUB_FUNC(PROCESS_RANDOM_DEVICE_ID_COMMAND, ProcessRandomDeviceIdCommandInner,
157- std::placeholders::_3)},162+ CHECK_PERM(false, {}, {ACCESS_BLUETOOTH}))},
158- {BluetoothHostInterfaceCode::GET_DEVICE_BATTERY_INFO,163+ {STUB_FUNC(GET_DEVICE_TRANSPORT, GetDeviceTransportInner, nullptr)},
159- std::bind(&BluetoothHostStub::GetRemoteDeviceBatteryInfoInner, std::placeholders::_1, std::placeholders::_2,164+ {STUB_FUNC(BT_GET_CAR_KEY_DFX_DATA, GetCarKeyDfxDataInner, nullptr)},
160- std::placeholders::_3)},165+ {STUB_FUNC(BT_SET_CAR_KEY_CARD_DATA, SetCarKeyCardDataInner, nullptr)},
161- {BluetoothHostInterfaceCode::SET_DEVICE_BATTERY_INFO,166+ {STUB_FUNC(IS_PROFILE_EXIST, IsProfileExistInner, nullptr)},
162- std::bind(&BluetoothHostStub::SetRemoteDeviceBatteryInfoInner, std::placeholders::_1, std::placeholders::_2,167+ {STUB_FUNC(BT_NOTIFY_DIALOG_RESULT, NotifyDialogResultInner,
163- std::placeholders::_3)},168+ CHECK_PERM(true, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
164- {BluetoothHostInterfaceCode::GET_PAIR_STATE,169+ {STUB_FUNC(START_REMOTE_SDP_SEARCH, StartRemoteSdpSearchInner,
165- std::bind(&BluetoothHostStub::GetPairStateInner, std::placeholders::_1, std::placeholders::_2,170+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
166- std::placeholders::_3)},171+ {STUB_FUNC(GET_REMOTE_SERVICES, GetRemoteServicesInner,
167- {BluetoothHostInterfaceCode::START_PAIR,172+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
168- std::bind(&BluetoothHostStub::StartPairInner, std::placeholders::_1, std::placeholders::_2,173+ {STUB_FUNC(SET_CONNECTION_PRIORITY, SetConnectionPriorityInner,
169- std::placeholders::_3)},174+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
170- {BluetoothHostInterfaceCode::CANCEL_PAIRING,
171- std::bind(&BluetoothHostStub::CancelPairingInner, std::placeholders::_1, std::placeholders::_2,
172- std::placeholders::_3)},
173- {BluetoothHostInterfaceCode::IS_BONDED_FROM_LOCAL,
174- std::bind(&BluetoothHostStub::IsBondedFromLocalInner, std::placeholders::_1, std::placeholders::_2,
175- std::placeholders::_3)},
176- {BluetoothHostInterfaceCode::IS_ACL_CONNECTED,
177- std::bind(&BluetoothHostStub::IsAclConnectedInner, std::placeholders::_1, std::placeholders::_2,
178- std::placeholders::_3)},
179- {BluetoothHostInterfaceCode::IS_ACL_ENCRYPTED,
180- std::bind(&BluetoothHostStub::IsAclEncryptedInner, std::placeholders::_1, std::placeholders::_2,
181- std::placeholders::_3)},
182- {BluetoothHostInterfaceCode::GET_DEVICE_CLASS,
183- std::bind(&BluetoothHostStub::GetDeviceClassInner, std::placeholders::_1, std::placeholders::_2,
184- std::placeholders::_3)},
185- {BluetoothHostInterfaceCode::SET_DEVICE_PIN,
186- std::bind(&BluetoothHostStub::SetDevicePinInner, std::placeholders::_1, std::placeholders::_2,
187- std::placeholders::_3)},
188- {BluetoothHostInterfaceCode::SET_DEVICE_PAIRING_CONFIRMATION,
189- std::bind(&BluetoothHostStub::SetDevicePairingConfirmationInner, std::placeholders::_1,
190- std::placeholders::_2, std::placeholders::_3)},
191- {BluetoothHostInterfaceCode::SET_DEVICE_PASSKEY,
192- std::bind(&BluetoothHostStub::SetDevicePasskeyInner, std::placeholders::_1, std::placeholders::_2,
193- std::placeholders::_3)},
194- {BluetoothHostInterfaceCode::PAIR_REQUEST_PEPLY,
195- std::bind(&BluetoothHostStub::PairRequestReplyInner, std::placeholders::_1, std::placeholders::_2,
196- std::placeholders::_3)},
197- {BluetoothHostInterfaceCode::READ_REMOTE_RSSI_VALUE,
198- std::bind(&BluetoothHostStub::ReadRemoteRssiValueInner, std::placeholders::_1, std::placeholders::_2,
199- std::placeholders::_3)},
200- {BluetoothHostInterfaceCode::GET_LOCAL_SUPPORTED_UUIDS,
201- std::bind(&BluetoothHostStub::GetLocalSupportedUuidsInner, std::placeholders::_1, std::placeholders::_2,
202- std::placeholders::_3)},
203- {BluetoothHostInterfaceCode::IS_PROFILE_EXIST,
204- std::bind(&BluetoothHostStub::IsProfileExistInner, std::placeholders::_1, std::placeholders::_2,
205- std::placeholders::_3)},
206- {BluetoothHostInterfaceCode::GET_DEVICE_UUIDS,
207- std::bind(&BluetoothHostStub::GetDeviceUuidsInner, std::placeholders::_1, std::placeholders::_2,
208- std::placeholders::_3)},
209- {BluetoothHostInterfaceCode::GET_LOCAL_PROFILE_UUIDS,
210- std::bind(&BluetoothHostStub::GetLocalProfileUuidsInner, std::placeholders::_1, std::placeholders::_2,
211- std::placeholders::_3)},
212- {BluetoothHostInterfaceCode::BT_REGISTER_BLE_ADAPTER_OBSERVER,
213- std::bind(&BluetoothHostStub::RegisterBleAdapterObserverInner, std::placeholders::_1, std::placeholders::_2,
214- std::placeholders::_3)},
215- {BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_ADAPTER_OBSERVER,
216- std::bind(&BluetoothHostStub::DeregisterBleAdapterObserverInner, std::placeholders::_1,
217- std::placeholders::_2, std::placeholders::_3)},
218- {BluetoothHostInterfaceCode::BT_REGISTER_BLE_PERIPHERAL_OBSERVER,
219- std::bind(&BluetoothHostStub::RegisterBlePeripheralCallbackInner, std::placeholders::_1,
220- std::placeholders::_2, std::placeholders::_3)},
221- {BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_PERIPHERAL_OBSERVER,
222- std::bind(&BluetoothHostStub::DeregisterBlePeripheralCallbackInner, std::placeholders::_1,
223- std::placeholders::_2, std::placeholders::_3)},
224- {BluetoothHostInterfaceCode::BT_SET_FAST_SCAN,
225- std::bind(&BluetoothHostStub::SetFastScanInner, std::placeholders::_1,
226- std::placeholders::_2, std::placeholders::_3)},
227- {BluetoothHostInterfaceCode::GET_RANDOM_ADDRESS, std::bind(&BluetoothHostStub::GetRandomAddressInner,
228- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
229- {BluetoothHostInterfaceCode::SYNC_RANDOM_ADDRESS, std::bind(&BluetoothHostStub::SyncRandomAddressInner,
230- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
231- {BluetoothHostInterfaceCode::START_CREDIBLE_PAIR,
232- std::bind(&BluetoothHostStub::StartCrediblePairInner, std::placeholders::_1, std::placeholders::_2,
233- std::placeholders::_3)},
234- {BluetoothHostInterfaceCode::CONNECT_ALLOWED_PROFILES,
235- std::bind(&BluetoothHostStub::ConnectAllowedProfilesInner, std::placeholders::_1, std::placeholders::_2,
236- std::placeholders::_3)},
237- {BluetoothHostInterfaceCode::DISCONNECT_ALLOWED_PROFILES,
238- std::bind(&BluetoothHostStub::DisconnectAllowedProfilesInner, std::placeholders::_1, std::placeholders::_2,
239- std::placeholders::_3)},
240- {BluetoothHostInterfaceCode::SET_CUSTOM_TYPE,
241- std::bind(&BluetoothHostStub::SetDeviceCustomTypeInner, std::placeholders::_1, std::placeholders::_2,
242- std::placeholders::_3)},
243- {BluetoothHostInterfaceCode::SATELLITE_CONTROL,
244- std::bind(&BluetoothHostStub::SatelliteControlInner, std::placeholders::_1, std::placeholders::_2,
245- std::placeholders::_3)},
246- {BluetoothHostInterfaceCode::BT_REGISTER_RESOURCE_MANAGER_OBSERVER,
247- std::bind(&BluetoothHostStub::RegisterBtResourceManagerObserverInner,
248- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
249- {BluetoothHostInterfaceCode::BT_DEREGISTER_RESOURCE_MANAGER_OBSERVER,
250- std::bind(&BluetoothHostStub::DeregisterBtResourceManagerObserverInner,
251- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
252- {BluetoothHostInterfaceCode::UPDATE_VIRTUAL_DEVICE,
253- std::bind(&BluetoothHostStub::UpdateVirtualDeviceInner,
254- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
255- {BluetoothHostInterfaceCode::GET_VIRTUAL_AUTO_CONN_SWITCH,
256- std::bind(&BluetoothHostStub::IsSupportVirtualAutoConnectInner,
257- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
258- {BluetoothHostInterfaceCode::SET_VIRTUAL_AUTO_CONN_TYPE,
259- std::bind(&BluetoothHostStub::SetVirtualAutoConnectTypeInner,
260- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
261- {BluetoothHostInterfaceCode::SET_FAST_SCAN_LEVEL,
262- std::bind(&BluetoothHostStub::SetFastScanLevelInner,
263- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
264- {BluetoothHostInterfaceCode::CTRL_DEVICE_ACTION,
265- std::bind(&BluetoothHostStub::ControlDeviceActionInner,
266- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
267- {BluetoothHostInterfaceCode::GET_CONNECTION_TIME,
268- std::bind(&BluetoothHostStub::GetLastConnectionTimeInner,
269- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
270- {BluetoothHostInterfaceCode::BT_UPDATE_CLOUD_DEVICE,
271- std::bind(&BluetoothHostStub::UpdateCloudBluetoothDevInner,
272- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
273- {BluetoothHostInterfaceCode::GET_CLOUD_BOND_STATE,
274- std::bind(&BluetoothHostStub::GetCloudBondStateInner,
275- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
276- {BluetoothHostInterfaceCode::GET_DEVICE_TRANSPORT,
277- std::bind(&BluetoothHostStub::GetDeviceTransportInner,
278- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
279- {BluetoothHostInterfaceCode::BT_UPDATE_REFUSE_POLICY,
280- std::bind(&BluetoothHostStub::UpdateRefusePolicyInner,
281- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
282- {BluetoothHostInterfaceCode::PROCESS_RANDOM_DEVICE_ID_COMMAND,
283- std::bind(&BluetoothHostStub::ProcessRandomDeviceIdCommandInner,
284- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
285- {BluetoothHostInterfaceCode::BT_GET_CAR_KEY_DFX_DATA,
286- std::bind(&BluetoothHostStub::GetCarKeyDfxDataInner,
287- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
288- {BluetoothHostInterfaceCode::BT_SET_CAR_KEY_CARD_DATA,
289- std::bind(&BluetoothHostStub::SetCarKeyCardDataInner,
290- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
291- {BluetoothHostInterfaceCode::BT_NOTIFY_DIALOG_RESULT,
292- std::bind(&BluetoothHostStub::NotifyDialogResultInner,
293- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
294- {BluetoothHostInterfaceCode::START_REMOTE_SDP_SEARCH,
295- std::bind(&BluetoothHostStub::StartRemoteSdpSearchInner,
296- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
297- {BluetoothHostInterfaceCode::GET_REMOTE_SERVICES,
298- std::bind(&BluetoothHostStub::GetRemoteServicesInner,
299- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
300- {BluetoothHostInterfaceCode::SET_CONNECTION_PRIORITY,
301- std::bind(&BluetoothHostStub::SetConnectionPriorityInner,
302- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
303};175};
304 176 
305BluetoothHostStub::BluetoothHostStub(){};177BluetoothHostStub::BluetoothHostStub(){};
306-BluetoothHostStub::~BluetoothHostStub()178+BluetoothHostStub::~BluetoothHostStub(){};
307-{}179+ 
308int32_t BluetoothHostStub::OnRemoteRequest(180int32_t BluetoothHostStub::OnRemoteRequest(
309 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)181 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
310{182{
311- HILOGI("BluetoothHostStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d", code, option.GetFlags());183+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothHostStub);
312- if (BluetoothHostStub::GetDescriptor() != data.ReadInterfaceToken()) {
313- HILOGE("BluetoothHostStub::OnRemoteRequest, local descriptor is not equal to remote");
314- return ERR_INVALID_STATE;
315- }
316- auto itFunc = memberFuncMap_.find(code);
317- if (itFunc != memberFuncMap_.end()) {
318- auto memberFunc = itFunc->second;
319- if (memberFunc != nullptr) {
320- return memberFunc(this, data, reply);
321- }
322- }
323- HILOGW("BluetoothHostStub::OnRemoteRequest, default case, need check.");
324- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
325}184}
326 185 
327-ErrCode BluetoothHostStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)186+int32_t BluetoothHostStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
328{187{
329 HILOGI("BluetoothHostStub::RegisterObserverInner starts");188 HILOGI("BluetoothHostStub::RegisterObserverInner starts");
330 sptr<IRemoteObject> remote = data.ReadRemoteObject();189 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -333,7 +192,7 @@ ErrCode BluetoothHostStub::RegisterObserverInner(MessageParcel &data, MessagePar
333 return NO_ERROR;192 return NO_ERROR;
334}193}
335 194 
336-ErrCode BluetoothHostStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)195+int32_t BluetoothHostStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
337{196{
338 HILOGI("BluetoothHostStub::DeregisterObserverInner starts");197 HILOGI("BluetoothHostStub::DeregisterObserverInner starts");
339 sptr<IRemoteObject> remote = data.ReadRemoteObject();198 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -370,7 +229,7 @@ int32_t BluetoothHostStub::DisableBtInner(MessageParcel &data, MessageParcel &re
370 return NO_ERROR;229 return NO_ERROR;
371}230}
372 231 
373-ErrCode BluetoothHostStub::GetProfileInner(MessageParcel &data, MessageParcel &reply)232+int32_t BluetoothHostStub::GetProfileInner(MessageParcel &data, MessageParcel &reply)
374{233{
375 HILOGI("BluetoothHostStub::GetProfileInner starts");234 HILOGI("BluetoothHostStub::GetProfileInner starts");
376 std::string name = data.ReadString();235 std::string name = data.ReadString();
@@ -383,7 +242,7 @@ ErrCode BluetoothHostStub::GetProfileInner(MessageParcel &data, MessageParcel &r
383 return NO_ERROR;242 return NO_ERROR;
384}243}
385 244 
386-ErrCode BluetoothHostStub::GetBleRemoteInner(MessageParcel &data, MessageParcel &reply)245+int32_t BluetoothHostStub::GetBleRemoteInner(MessageParcel &data, MessageParcel &reply)
387{246{
388 HILOGI("BluetoothHostStub::GetBleRemoteInner starts");247 HILOGI("BluetoothHostStub::GetBleRemoteInner starts");
389 std::string name = data.ReadString();248 std::string name = data.ReadString();
@@ -407,7 +266,7 @@ int32_t BluetoothHostStub::BluetoothFactoryResetInner(MessageParcel &data, Messa
407 return NO_ERROR;266 return NO_ERROR;
408}267}
409 268 
410-ErrCode BluetoothHostStub::GetBtStateInner(MessageParcel &data, MessageParcel &reply)269+int32_t BluetoothHostStub::GetBtStateInner(MessageParcel &data, MessageParcel &reply)
411{270{
412 HILOGI("BluetoothHostStub::GetBtStateInner starts");271 HILOGI("BluetoothHostStub::GetBtStateInner starts");
413 int32_t state = 0;272 int32_t state = 0;
@@ -468,7 +327,7 @@ int32_t BluetoothHostStub::EnableBleInner(MessageParcel &data, MessageParcel &re
468 return NO_ERROR;327 return NO_ERROR;
469}328}
470 329 
471-ErrCode BluetoothHostStub::GetProfileListInner(MessageParcel &data, MessageParcel &reply)330+int32_t BluetoothHostStub::GetProfileListInner(MessageParcel &data, MessageParcel &reply)
472{331{
473 std::vector<uint32_t> result = GetProfileList();332 std::vector<uint32_t> result = GetProfileList();
474 bool ret = reply.WriteUInt32Vector(result);333 bool ret = reply.WriteUInt32Vector(result);
@@ -479,7 +338,7 @@ ErrCode BluetoothHostStub::GetProfileListInner(MessageParcel &data, MessageParce
479 return NO_ERROR;338 return NO_ERROR;
480}339}
481 340 
482-ErrCode BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply)341+int32_t BluetoothHostStub::GetMaxNumConnectedAudioDevicesInner(MessageParcel &data, MessageParcel &reply)
483{342{
484 int32_t result = GetMaxNumConnectedAudioDevices();343 int32_t result = GetMaxNumConnectedAudioDevices();
485 bool ret = reply.WriteInt32(result);344 bool ret = reply.WriteInt32(result);
@@ -527,7 +386,7 @@ int32_t BluetoothHostStub::GetBtProfileConnStateInner(MessageParcel &data, Messa
527 return NO_ERROR;386 return NO_ERROR;
528}387}
529 388 
530-ErrCode BluetoothHostStub::GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)389+int32_t BluetoothHostStub::GetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
531{390{
532 int32_t result = GetLocalDeviceClass();391 int32_t result = GetLocalDeviceClass();
533 bool ret = reply.WriteInt32(result);392 bool ret = reply.WriteInt32(result);
@@ -538,7 +397,7 @@ ErrCode BluetoothHostStub::GetLocalDeviceClassInner(MessageParcel &data, Message
538 return NO_ERROR;397 return NO_ERROR;
539}398}
540 399 
541-ErrCode BluetoothHostStub::SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)400+int32_t BluetoothHostStub::SetLocalDeviceClassInner(MessageParcel &data, MessageParcel &reply)
542{401{
543 int32_t deviceClass;402 int32_t deviceClass;
544 data.ReadInt32(deviceClass);403 data.ReadInt32(deviceClass);
@@ -582,7 +441,7 @@ int32_t BluetoothHostStub::SetLocalNameInner(MessageParcel &data, MessageParcel
582 return NO_ERROR;441 return NO_ERROR;
583}442}
584 443 
585-ErrCode BluetoothHostStub::GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply)444+int32_t BluetoothHostStub::GetDeviceTypeInner(MessageParcel &data, MessageParcel &reply)
586{445{
587 int32_t transport;446 int32_t transport;
588 if (!data.ReadInt32(transport)) {447 if (!data.ReadInt32(transport)) {
@@ -620,7 +479,7 @@ int32_t BluetoothHostStub::GetBtScanModeInner(MessageParcel &data, MessageParcel
620 return NO_ERROR;479 return NO_ERROR;
621}480}
622 481 
623-ErrCode BluetoothHostStub::GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)482+int32_t BluetoothHostStub::GetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
624{483{
625 std::string address;484 std::string address;
626 if (!data.ReadString(address)) {485 if (!data.ReadString(address)) {
@@ -651,7 +510,7 @@ int32_t BluetoothHostStub::SetBtScanModeInner(MessageParcel &data, MessageParcel
651 return NO_ERROR;510 return NO_ERROR;
652}511}
653 512 
654-ErrCode BluetoothHostStub::SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)513+int32_t BluetoothHostStub::SetPhonebookPermissionInner(MessageParcel &data, MessageParcel &reply)
655{514{
656 std::string address;515 std::string address;
657 if (!data.ReadString(address)) {516 if (!data.ReadString(address)) {
@@ -672,7 +531,7 @@ ErrCode BluetoothHostStub::SetPhonebookPermissionInner(MessageParcel &data, Mess
672 return NO_ERROR;531 return NO_ERROR;
673}532}
674 533 
675-ErrCode BluetoothHostStub::GetBondableModeInner(MessageParcel &data, MessageParcel &reply)534+int32_t BluetoothHostStub::GetBondableModeInner(MessageParcel &data, MessageParcel &reply)
676{535{
677 int32_t transport;536 int32_t transport;
678 data.ReadInt32(transport);537 data.ReadInt32(transport);
@@ -684,7 +543,7 @@ ErrCode BluetoothHostStub::GetBondableModeInner(MessageParcel &data, MessageParc
684 }543 }
685 return NO_ERROR;544 return NO_ERROR;
686}545}
687-ErrCode BluetoothHostStub::GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)546+int32_t BluetoothHostStub::GetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
688{547{
689 std::string address;548 std::string address;
690 if (!data.ReadString(address)) {549 if (!data.ReadString(address)) {
@@ -700,7 +559,7 @@ ErrCode BluetoothHostStub::GetMessagePermissionInner(MessageParcel &data, Messag
700 return NO_ERROR;559 return NO_ERROR;
701}560}
702 561 
703-ErrCode BluetoothHostStub::SetBondableModeInner(MessageParcel &data, MessageParcel &reply)562+int32_t BluetoothHostStub::SetBondableModeInner(MessageParcel &data, MessageParcel &reply)
704{563{
705 int32_t transport;564 int32_t transport;
706 data.ReadInt32(transport);565 data.ReadInt32(transport);
@@ -716,7 +575,7 @@ ErrCode BluetoothHostStub::SetBondableModeInner(MessageParcel &data, MessageParc
716 return NO_ERROR;575 return NO_ERROR;
717}576}
718 577 
719-ErrCode BluetoothHostStub::SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)578+int32_t BluetoothHostStub::SetMessagePermissionInner(MessageParcel &data, MessageParcel &reply)
720{579{
721 std::string address;580 std::string address;
722 if (!data.ReadString(address)) {581 if (!data.ReadString(address)) {
@@ -737,7 +596,7 @@ ErrCode BluetoothHostStub::SetMessagePermissionInner(MessageParcel &data, Messag
737 return NO_ERROR;596 return NO_ERROR;
738}597}
739 598 
740-ErrCode BluetoothHostStub::GetPowerModeInner(MessageParcel &data, MessageParcel &reply)599+int32_t BluetoothHostStub::GetPowerModeInner(MessageParcel &data, MessageParcel &reply)
741{600{
742 std::string address;601 std::string address;
743 if (!data.ReadString(address)) {602 if (!data.ReadString(address)) {
@@ -807,7 +666,7 @@ int32_t BluetoothHostStub::GetDeviceNameInner(MessageParcel &data, MessageParcel
807 return NO_ERROR;666 return NO_ERROR;
808}667}
809 668 
810-ErrCode BluetoothHostStub::GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)669+int32_t BluetoothHostStub::GetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
811{670{
812 std::string address;671 std::string address;
813 if (!data.ReadString(address)) {672 if (!data.ReadString(address)) {
@@ -823,7 +682,7 @@ ErrCode BluetoothHostStub::GetDeviceAliasInner(MessageParcel &data, MessageParce
823 return NO_ERROR;682 return NO_ERROR;
824}683}
825 684 
826-ErrCode BluetoothHostStub::IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply)685+int32_t BluetoothHostStub::IsBtDiscoveringInner(MessageParcel &data, MessageParcel &reply)
827{686{
828 bool isDiscovering = false;687 bool isDiscovering = false;
829 int32_t transport;688 int32_t transport;
@@ -842,7 +701,7 @@ ErrCode BluetoothHostStub::IsBtDiscoveringInner(MessageParcel &data, MessageParc
842 return BT_NO_ERROR;701 return BT_NO_ERROR;
843}702}
844 703 
845-ErrCode BluetoothHostStub::SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)704+int32_t BluetoothHostStub::SetDeviceAliasInner(MessageParcel &data, MessageParcel &reply)
846{705{
847 std::string address;706 std::string address;
848 if (!data.ReadString(address)) {707 if (!data.ReadString(address)) {
@@ -885,7 +744,7 @@ int32_t BluetoothHostStub::SetRemoteDeviceBatteryInfoInner(MessageParcel &data,
885 return NO_ERROR;744 return NO_ERROR;
886}745}
887 746 
888-ErrCode BluetoothHostStub::GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply)747+int32_t BluetoothHostStub::GetBtDiscoveryEndMillisInner(MessageParcel &data, MessageParcel &reply)
889{748{
890 int64_t result = GetBtDiscoveryEndMillis();749 int64_t result = GetBtDiscoveryEndMillis();
891 bool ret = reply.WriteInt64(result);750 bool ret = reply.WriteInt64(result);
@@ -896,7 +755,7 @@ ErrCode BluetoothHostStub::GetBtDiscoveryEndMillisInner(MessageParcel &data, Mes
896 return NO_ERROR;755 return NO_ERROR;
897}756}
898 757 
899-ErrCode BluetoothHostStub::GetPairStateInner(MessageParcel &data, MessageParcel &reply)758+int32_t BluetoothHostStub::GetPairStateInner(MessageParcel &data, MessageParcel &reply)
900{759{
901 int32_t transport;760 int32_t transport;
902 if (!data.ReadInt32(transport)) {761 if (!data.ReadInt32(transport)) {
@@ -984,7 +843,7 @@ int32_t BluetoothHostStub::RemovePairInner(MessageParcel &data, MessageParcel &r
984 return NO_ERROR;843 return NO_ERROR;
985}844}
986 845 
987-ErrCode BluetoothHostStub::CancelPairingInner(MessageParcel &data, MessageParcel &reply)846+int32_t BluetoothHostStub::CancelPairingInner(MessageParcel &data, MessageParcel &reply)
988{847{
989 int32_t transport;848 int32_t transport;
990 if (!data.ReadInt32(transport)) {849 if (!data.ReadInt32(transport)) {
@@ -1005,7 +864,7 @@ ErrCode BluetoothHostStub::CancelPairingInner(MessageParcel &data, MessageParcel
1005 return NO_ERROR;864 return NO_ERROR;
1006}865}
1007 866 
1008-ErrCode BluetoothHostStub::RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply)867+int32_t BluetoothHostStub::RemoveAllPairsInner(MessageParcel &data, MessageParcel &reply)
1009{868{
1010 bool result = RemoveAllPairs();869 bool result = RemoveAllPairs();
1011 bool ret = reply.WriteBool(result);870 bool ret = reply.WriteBool(result);
@@ -1017,7 +876,7 @@ ErrCode BluetoothHostStub::RemoveAllPairsInner(MessageParcel &data, MessageParce
1017 return NO_ERROR;876 return NO_ERROR;
1018}877}
1019 878 
1020-ErrCode BluetoothHostStub::IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply)879+int32_t BluetoothHostStub::IsBondedFromLocalInner(MessageParcel &data, MessageParcel &reply)
1021{880{
1022 int32_t transport;881 int32_t transport;
1023 if (!data.ReadInt32(transport)) {882 if (!data.ReadInt32(transport)) {
@@ -1059,7 +918,7 @@ int32_t BluetoothHostStub::SetDevicePinInner(MessageParcel &data, MessageParcel
1059 return NO_ERROR;918 return NO_ERROR;
1060}919}
1061 920 
1062-ErrCode BluetoothHostStub::IsAclConnectedInner(MessageParcel &data, MessageParcel &reply)921+int32_t BluetoothHostStub::IsAclConnectedInner(MessageParcel &data, MessageParcel &reply)
1063{922{
1064 int32_t transport;923 int32_t transport;
1065 if (!data.ReadInt32(transport)) {924 if (!data.ReadInt32(transport)) {
@@ -1084,7 +943,7 @@ ErrCode BluetoothHostStub::IsAclConnectedInner(MessageParcel &data, MessageParce
1084 return NO_ERROR;943 return NO_ERROR;
1085}944}
1086 945 
1087-ErrCode BluetoothHostStub::RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)946+int32_t BluetoothHostStub::RegisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
1088{947{
1089 auto tempObject = data.ReadRemoteObject();948 auto tempObject = data.ReadRemoteObject();
1090 sptr<IBluetoothRemoteDeviceObserver> observer;949 sptr<IBluetoothRemoteDeviceObserver> observer;
@@ -1093,7 +952,7 @@ ErrCode BluetoothHostStub::RegisterRemoteDeviceObserverInner(MessageParcel &data
1093 return NO_ERROR;952 return NO_ERROR;
1094}953}
1095 954 
1096-ErrCode BluetoothHostStub::DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)955+int32_t BluetoothHostStub::DeregisterRemoteDeviceObserverInner(MessageParcel &data, MessageParcel &reply)
1097{956{
1098 auto tempObject = data.ReadRemoteObject();957 auto tempObject = data.ReadRemoteObject();
1099 sptr<IBluetoothRemoteDeviceObserver> observer;958 sptr<IBluetoothRemoteDeviceObserver> observer;
@@ -1102,7 +961,7 @@ ErrCode BluetoothHostStub::DeregisterRemoteDeviceObserverInner(MessageParcel &da
1102 return NO_ERROR;961 return NO_ERROR;
1103}962}
1104 963 
1105-ErrCode BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply)964+int32_t BluetoothHostStub::GetBleMaxAdvertisingDataLengthInner(MessageParcel &data, MessageParcel &reply)
1106{965{
1107 int32_t result = GetBleMaxAdvertisingDataLength();966 int32_t result = GetBleMaxAdvertisingDataLength();
1108 bool ret = reply.WriteInt32(result);967 bool ret = reply.WriteInt32(result);
@@ -1119,7 +978,7 @@ int32_t BluetoothHostStub::GetConnectedBLEDevicesInner(MessageParcel &data, Mess
1119 return NO_ERROR;978 return NO_ERROR;
1120}979}
1121 980 
1122-ErrCode BluetoothHostStub::IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply)981+int32_t BluetoothHostStub::IsAclEncryptedInner(MessageParcel &data, MessageParcel &reply)
1123{982{
1124 int32_t transport;983 int32_t transport;
1125 if (!data.ReadInt32(transport)) {984 if (!data.ReadInt32(transport)) {
@@ -1188,7 +1047,7 @@ int32_t BluetoothHostStub::SetDevicePairingConfirmationInner(MessageParcel &data
1188 return NO_ERROR;1047 return NO_ERROR;
1189}1048}
1190 1049 
1191-ErrCode BluetoothHostStub::SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply)1050+int32_t BluetoothHostStub::SetDevicePasskeyInner(MessageParcel &data, MessageParcel &reply)
1192{1051{
1193 int32_t transport;1052 int32_t transport;
1194 if (!data.ReadInt32(transport)) {1053 if (!data.ReadInt32(transport)) {
@@ -1219,7 +1078,7 @@ ErrCode BluetoothHostStub::SetDevicePasskeyInner(MessageParcel &data, MessagePar
1219 return NO_ERROR;1078 return NO_ERROR;
1220}1079}
1221 1080 
1222-ErrCode BluetoothHostStub::PairRequestReplyInner(MessageParcel &data, MessageParcel &reply)1081+int32_t BluetoothHostStub::PairRequestReplyInner(MessageParcel &data, MessageParcel &reply)
1223{1082{
1224 int32_t transport;1083 int32_t transport;
1225 if (!data.ReadInt32(transport)) {1084 if (!data.ReadInt32(transport)) {
@@ -1245,7 +1104,7 @@ ErrCode BluetoothHostStub::PairRequestReplyInner(MessageParcel &data, MessagePar
1245 return NO_ERROR;1104 return NO_ERROR;
1246}1105}
1247 1106 
1248-ErrCode BluetoothHostStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)1107+int32_t BluetoothHostStub::ReadRemoteRssiValueInner(MessageParcel &data, MessageParcel &reply)
1249{1108{
1250 std::string address;1109 std::string address;
1251 if (!data.ReadString(address)) {1110 if (!data.ReadString(address)) {
@@ -1261,7 +1120,7 @@ ErrCode BluetoothHostStub::ReadRemoteRssiValueInner(MessageParcel &data, Message
1261 return NO_ERROR;1120 return NO_ERROR;
1262}1121}
1263 1122 
1264-ErrCode BluetoothHostStub::GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply)1123+int32_t BluetoothHostStub::GetLocalSupportedUuidsInner(MessageParcel &data, MessageParcel &reply)
1265{1124{
1266 std::vector<std::string> uuids;1125 std::vector<std::string> uuids;
1267 GetLocalSupportedUuids(uuids);1126 GetLocalSupportedUuids(uuids);
@@ -1280,7 +1139,7 @@ ErrCode BluetoothHostStub::GetLocalSupportedUuidsInner(MessageParcel &data, Mess
1280 return NO_ERROR;1139 return NO_ERROR;
1281}1140}
1282 1141 
1283-ErrCode BluetoothHostStub::GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply)1142+int32_t BluetoothHostStub::GetDeviceUuidsInner(MessageParcel &data, MessageParcel &reply)
1284{1143{
1285 std::string address;1144 std::string address;
1286 std::vector<std::string> uuids;1145 std::vector<std::string> uuids;
@@ -1308,12 +1167,12 @@ ErrCode BluetoothHostStub::GetDeviceUuidsInner(MessageParcel &data, MessageParce
1308 return NO_ERROR;1167 return NO_ERROR;
1309}1168}
1310 1169 
1311-ErrCode BluetoothHostStub::GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply)1170+int32_t BluetoothHostStub::GetLocalProfileUuidsInner(MessageParcel &data, MessageParcel &reply)
1312{1171{
1313 return NO_ERROR;1172 return NO_ERROR;
1314}1173}
1315 1174 
1316-ErrCode BluetoothHostStub::RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)1175+int32_t BluetoothHostStub::RegisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1317{1176{
1318 auto tempObject = data.ReadRemoteObject();1177 auto tempObject = data.ReadRemoteObject();
1319 sptr<IBluetoothHostObserver> observer;1178 sptr<IBluetoothHostObserver> observer;
@@ -1322,7 +1181,7 @@ ErrCode BluetoothHostStub::RegisterBleAdapterObserverInner(MessageParcel &data,
1322 return NO_ERROR;1181 return NO_ERROR;
1323}1182}
1324 1183 
1325-ErrCode BluetoothHostStub::DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)1184+int32_t BluetoothHostStub::DeregisterBleAdapterObserverInner(MessageParcel &data, MessageParcel &reply)
1326{1185{
1327 auto tempObject = data.ReadRemoteObject();1186 auto tempObject = data.ReadRemoteObject();
1328 sptr<IBluetoothHostObserver> observer;1187 sptr<IBluetoothHostObserver> observer;
@@ -1331,7 +1190,7 @@ ErrCode BluetoothHostStub::DeregisterBleAdapterObserverInner(MessageParcel &data
1331 return NO_ERROR;1190 return NO_ERROR;
1332}1191}
1333 1192 
1334-ErrCode BluetoothHostStub::RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)1193+int32_t BluetoothHostStub::RegisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1335{1194{
1336 auto tempObject = data.ReadRemoteObject();1195 auto tempObject = data.ReadRemoteObject();
1337 sptr<IBluetoothBlePeripheralObserver> observer;1196 sptr<IBluetoothBlePeripheralObserver> observer;
@@ -1340,7 +1199,7 @@ ErrCode BluetoothHostStub::RegisterBlePeripheralCallbackInner(MessageParcel &dat
1340 return NO_ERROR;1199 return NO_ERROR;
1341}1200}
1342 1201 
1343-ErrCode BluetoothHostStub::DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)1202+int32_t BluetoothHostStub::DeregisterBlePeripheralCallbackInner(MessageParcel &data, MessageParcel &reply)
1344{1203{
1345 auto tempObject = data.ReadRemoteObject();1204 auto tempObject = data.ReadRemoteObject();
1346 sptr<IBluetoothBlePeripheralObserver> observer;1205 sptr<IBluetoothBlePeripheralObserver> observer;
@@ -1354,7 +1213,7 @@ int32_t BluetoothHostStub::SetFastScanInner(MessageParcel &data, MessageParcel &
1354 return NO_ERROR;1213 return NO_ERROR;
1355}1214}
1356 1215 
1357-ErrCode BluetoothHostStub::GetRandomAddressInner(MessageParcel &data, MessageParcel &reply)1216+int32_t BluetoothHostStub::GetRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1358{1217{
1359 std::string realAddress = data.ReadString();1218 std::string realAddress = data.ReadString();
1360 std::string randomAddress;1219 std::string randomAddress;
@@ -1373,12 +1232,12 @@ ErrCode BluetoothHostStub::GetRandomAddressInner(MessageParcel &data, MessagePar
1373 return NO_ERROR;1232 return NO_ERROR;
1374}1233}
1375 1234 
1376-ErrCode BluetoothHostStub::SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply)1235+int32_t BluetoothHostStub::SyncRandomAddressInner(MessageParcel &data, MessageParcel &reply)
1377{1236{
1378 return NO_ERROR;1237 return NO_ERROR;
1379}1238}
1380 1239 
1381-ErrCode BluetoothHostStub::StartCrediblePairInner(MessageParcel &data, MessageParcel &reply)1240+int32_t BluetoothHostStub::StartCrediblePairInner(MessageParcel &data, MessageParcel &reply)
1382{1241{
1383 std::string address = data.ReadString();1242 std::string address = data.ReadString();
1384 int32_t transport = data.ReadInt32();1243 int32_t transport = data.ReadInt32();
@@ -1390,7 +1249,7 @@ ErrCode BluetoothHostStub::StartCrediblePairInner(MessageParcel &data, MessagePa
1390 return NO_ERROR;1249 return NO_ERROR;
1391}1250}
1392 1251 
1393-ErrCode BluetoothHostStub::SatelliteControlInner(MessageParcel &data, MessageParcel &reply)1252+int32_t BluetoothHostStub::SatelliteControlInner(MessageParcel &data, MessageParcel &reply)
1394{1253{
1395 return NO_ERROR;1254 return NO_ERROR;
1396}1255}
Mservices/bluetooth/ipc/src/bluetooth_pan_stub.cpp+29-38
@@ -15,53 +15,44 @@
15#include "bluetooth_errorcode.h"15#include "bluetooth_errorcode.h"
16#include "bluetooth_pan_stub.h"16#include "bluetooth_pan_stub.h"
17#include "bluetooth_log.h"17#include "bluetooth_log.h"
18+#include "permission_manager.h"
19+ 
20+#ifdef STUB_FUNC
21+#undef STUB_FUNC
22+#endif
23+#define STUB_FUNC(code, func, perm) BluetoothPanInterfaceCode::code, {&BluetoothPanStub::func, perm}
18 24 
19namespace OHOS {25namespace OHOS {
20namespace Bluetooth {26namespace Bluetooth {
27+using namespace OHOS::bluetooth;
21const uint32_t PAN_DEVICES_STATES_MAX_NUMS = 0XFF;28const uint32_t PAN_DEVICES_STATES_MAX_NUMS = 0XFF;
29+ 
30+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
31+const std::map<uint32_t, BluetoothPanStub::BluetoothPanStubPerm> BluetoothPanStub::memberFuncMap_ = {
32+ 
33+ {STUB_FUNC(COMMAND_DISCONNECT, DisconnectInner,
34+ CHECK_PERM(true, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
35+ {STUB_FUNC(COMMAND_GET_DEVICE_STATE, GetDeviceStateInner,
36+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
37+ {STUB_FUNC(COMMAND_GET_DEVICES_BY_STATES, GetDevicesByStatesInner,
38+ CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
39+ {STUB_FUNC(COMMAND_REGISTER_OBSERVER, RegisterObserverInner, nullptr)},
40+ {STUB_FUNC(COMMAND_DEREGISTER_OBSERVER, DeregisterObserverInner, nullptr)},
41+ {STUB_FUNC(COMMAND_SET_TETHERING, SetTetheringInner,
42+ CHECK_PERM(true, {DISCOVER_BLUETOOTH}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
43+ {STUB_FUNC(COMMAND_IS_TETHERING_ON, IsTetheringOnInner,
44+ CHECK_PERM(true, {}, {ACCESS_BLUETOOTH}))},
45+};
22BluetoothPanStub::BluetoothPanStub()46BluetoothPanStub::BluetoothPanStub()
23-{47+{}
24- HILOGD("start.");
25- memberFuncMap_[static_cast<uint32_t>(COMMAND_DISCONNECT)] =
26- &BluetoothPanStub::DisconnectInner;
27- memberFuncMap_[static_cast<uint32_t>(COMMAND_GET_DEVICE_STATE)] =
28- &BluetoothPanStub::GetDeviceStateInner;
29- memberFuncMap_[static_cast<uint32_t>(COMMAND_GET_DEVICES_BY_STATES)] =
30- &BluetoothPanStub::GetDevicesByStatesInner;
31- memberFuncMap_[static_cast<uint32_t>(COMMAND_REGISTER_OBSERVER)] =
32- &BluetoothPanStub::RegisterObserverInner;
33- memberFuncMap_[static_cast<uint32_t>(COMMAND_DEREGISTER_OBSERVER)] =
34- &BluetoothPanStub::DeregisterObserverInner;
35- memberFuncMap_[static_cast<uint32_t>(COMMAND_SET_TETHERING)] =
36- &BluetoothPanStub::SetTetheringInner;
37- memberFuncMap_[static_cast<uint32_t>(COMMAND_IS_TETHERING_ON)] =
38- &BluetoothPanStub::IsTetheringOnInner;
39- HILOGD("ends.");
40-}
41 48 
42BluetoothPanStub::~BluetoothPanStub()49BluetoothPanStub::~BluetoothPanStub()
43-{50+{}
44- HILOGD("start.");
45- memberFuncMap_.clear();
46-}
47 51 
48int BluetoothPanStub::OnRemoteRequest(52int BluetoothPanStub::OnRemoteRequest(
49 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)53 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
50{54{
51- HILOGI("BluetoothPanStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());55+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothPanStub);
52- if (BluetoothPanStub::GetDescriptor() != data.ReadInterfaceToken()) {
53- HILOGE("local descriptor is not equal to remote");
54- return IPC_INVOKER_TRANSLATE_ERR;
55- }
56- auto itFunc = memberFuncMap_.find(code);
57- if (itFunc != memberFuncMap_.end()) {
58- auto memberFunc = itFunc->second;
59- if (memberFunc != nullptr) {
60- return (this->*memberFunc)(data, reply);
61- }
62- }
63- HILOGW("BluetoothHfpHfStub::OnRemoteRequest, default case, need check.");
64- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65}56}
66 57 
67int32_t BluetoothPanStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)58int32_t BluetoothPanStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
@@ -140,7 +131,7 @@ int32_t BluetoothPanStub::GetDevicesByStatesInner(MessageParcel &data, MessagePa
140 return NO_ERROR;131 return NO_ERROR;
141}132}
142 133 
143-ErrCode BluetoothPanStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)134+int32_t BluetoothPanStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
144{135{
145 HILOGD("BluetoothPanStub::RegisterObserverInner");136 HILOGD("BluetoothPanStub::RegisterObserverInner");
146 sptr<IRemoteObject> remote = data.ReadRemoteObject();137 sptr<IRemoteObject> remote = data.ReadRemoteObject();
@@ -149,7 +140,7 @@ ErrCode BluetoothPanStub::RegisterObserverInner(MessageParcel &data, MessageParc
149 return NO_ERROR;140 return NO_ERROR;
150}141}
151 142 
152-ErrCode BluetoothPanStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)143+int32_t BluetoothPanStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
153{144{
154 HILOGD("BluetoothPanStub::DeregisterObserverInner");145 HILOGD("BluetoothPanStub::DeregisterObserverInner");
155 sptr<IRemoteObject> remote = data.ReadRemoteObject();146 sptr<IRemoteObject> remote = data.ReadRemoteObject();
Mservices/bluetooth/ipc/src/bluetooth_socket_stub.cpp+52-51
@@ -19,59 +19,41 @@
19#include "bluetooth_socket_observer_proxy.h"19#include "bluetooth_socket_observer_proxy.h"
20#include "ipc_types.h"20#include "ipc_types.h"
21#include "bluetooth_socket_stub.h"21#include "bluetooth_socket_stub.h"
22+#include "permission_manager.h"
23+ 
24+#ifdef STUB_FUNC
25+#undef STUB_FUNC
26+#endif
27+#define STUB_FUNC(code, func, perm) BluetoothSocketInterfaceCode::code, {&BluetoothSocketStub::func, perm}
22 28 
23namespace OHOS {29namespace OHOS {
24namespace Bluetooth {30namespace Bluetooth {
31+using namespace OHOS::bluetooth;
32+// Note: Permissions need to be configured when the itf to be used. "nullptr" means no permission needed.
33+const std::map<uint32_t, BluetoothSocketStub::SocketStubFuncPerm> BluetoothSocketStub::memberFuncMap_ = {
34+{STUB_FUNC(SOCKET_CONNECT, ConnectInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
35+{STUB_FUNC(SOCKET_LISTEN, ListenInner, CHECK_PERM(false, {USE_BLUETOOTH}, {ACCESS_BLUETOOTH}))},
36+{STUB_FUNC(SOCKET_UPDATE_COC_PARAMS, UpdateCocConnectionParamsInner,
37+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
38+{STUB_FUNC(DEREGISTER_SERVER_OBSERVER, DeregisterServerObserverInner, nullptr)},
39+{STUB_FUNC(REGISTER_CLIENT_OBSERVER, RegisterClientObserverInner, nullptr)},
40+{STUB_FUNC(DEREGISTER_CLIENT_OBSERVER, DeregisterClientObserverInner, nullptr)},
41+{STUB_FUNC(SOCKET_IS_ALLOW_CONNECT, IsAllowSocketConnectInner,
42+ CHECK_PERM(false, {}, MULTI_PERM(ACCESS_BLUETOOTH, MANAGE_BLUETOOTH)))},
43+};
25BluetoothSocketStub::BluetoothSocketStub()44BluetoothSocketStub::BluetoothSocketStub()
26-{45+{}
27- HILOGD("%{public}s start.", __func__);
28- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::SOCKET_CONNECT)] =
29- &BluetoothSocketStub::ConnectInner;
30- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::SOCKET_LISTEN)] =
31- &BluetoothSocketStub::ListenInner;
32- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::DEREGISTER_SERVER_OBSERVER)] =
33- &BluetoothSocketStub::DeregisterServerObserverInner;
34- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::REGISTER_CLIENT_OBSERVER)] =
35- &BluetoothSocketStub::RegisterClientObserverInner;
36- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::DEREGISTER_SERVER_OBSERVER)] =
37- &BluetoothSocketStub::DeregisterClientObserverInner;
38- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::SOCKET_UPDATE_COC_PARAMS)] =
39- &BluetoothSocketStub::UpdateCocConnectionParamsInner;
40- memberFuncMap_[static_cast<uint32_t>(BluetoothSocketInterfaceCode::SOCKET_IS_ALLOW_CONNECT)] =
41- &BluetoothSocketStub::IsAllowSocketConnectInner;
42-}
43 46 
44BluetoothSocketStub::~BluetoothSocketStub()47BluetoothSocketStub::~BluetoothSocketStub()
45-{48+{}
46- HILOGD("%{public}s start.", __func__);
47- memberFuncMap_.clear();
48-}
49 49 
50int32_t BluetoothSocketStub::OnRemoteRequest(50int32_t BluetoothSocketStub::OnRemoteRequest(
51 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)51 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
52{52{
53- HILOGD("BluetoothSocketStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());53+ CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(BluetoothSocketStub);
54- 
55- std::u16string descriptor = BluetoothSocketStub::GetDescriptor();
56- std::u16string remoteDescriptor = data.ReadInterfaceToken();
57- if (descriptor != remoteDescriptor) {
58- HILOGE("BluetoothSocketStub::OnRemoteRequest, local descriptor is not equal to remote");
59- return ERR_INVALID_STATE;
60- }
61- 
62- auto itFunc = memberFuncMap_.find(code);
63- if (itFunc != memberFuncMap_.end()) {
64- auto memberFunc = itFunc->second;
65- if (memberFunc != nullptr) {
66- return (this->*memberFunc)(data, reply);
67- }
68- }
69- 
70- HILOGW("BluetoothHostObserverStub::OnRemoteRequest, default case, need check.");
71- return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
72}54}
73 55 
74-ErrCode BluetoothSocketStub::ConnectInner(MessageParcel &data, MessageParcel &reply)56+int32_t BluetoothSocketStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
75{57{
76 HILOGI("ConnectInner starts");58 HILOGI("ConnectInner starts");
77 std::string addr = data.ReadString();59 std::string addr = data.ReadString();
@@ -103,7 +85,7 @@ ErrCode BluetoothSocketStub::ConnectInner(MessageParcel &data, MessageParcel &re
103 return NO_ERROR;85 return NO_ERROR;
104}86}
105 87 
106-ErrCode BluetoothSocketStub::ListenInner(MessageParcel &data, MessageParcel &reply)88+int32_t BluetoothSocketStub::ListenInner(MessageParcel &data, MessageParcel &reply)
107{89{
108 HILOGI("ListenInner starts");90 HILOGI("ListenInner starts");
109 std::string name = data.ReadString();91 std::string name = data.ReadString();
@@ -136,7 +118,7 @@ ErrCode BluetoothSocketStub::ListenInner(MessageParcel &data, MessageParcel &rep
136 return NO_ERROR;118 return NO_ERROR;
137}119}
138 120 
139-ErrCode BluetoothSocketStub::DeregisterServerObserverInner(MessageParcel &data, MessageParcel &reply)121+int32_t BluetoothSocketStub::DeregisterServerObserverInner(MessageParcel &data, MessageParcel &reply)
140{122{
141 HILOGI("DeregisterServerObserverInner starts");123 HILOGI("DeregisterServerObserverInner starts");
142 sptr<IBluetoothServerSocketObserver> observer =124 sptr<IBluetoothServerSocketObserver> observer =
@@ -146,22 +128,41 @@ ErrCode BluetoothSocketStub::DeregisterServerObserverInner(MessageParcel &data,
146 return NO_ERROR;128 return NO_ERROR;
147}129}
148 130 
149-ErrCode BluetoothSocketStub::RegisterClientObserverInner(MessageParcel &data, MessageParcel &reply)131+int32_t BluetoothSocketStub::RegisterClientObserverInner(MessageParcel &data, MessageParcel &reply)
132+{
133+ sptr<BluetoothRawAddress> addr(data.ReadStrongParcelable<BluetoothRawAddress>());
134+ if (!addr) {
135+ HILOGE("BluetoothSocketStub::RegisterClientObserver failed");
136+ return ERR_INVALID_VALUE;
137+ }
138+ std::shared_ptr<BluetoothUuid> uuid(data.ReadParcelable<BluetoothUuid>());
139+ if (uuid == nullptr) {
140+ HILOGE("reply writing failed in: %{public}s.", __func__);
141+ return ERR_INVALID_VALUE;
142+ }
143+ sptr<IBluetoothClientSocketObserver> observer =
144+ OHOS::iface_cast<IBluetoothClientSocketObserver>(data.ReadRemoteObject());
145+ CHECK_AND_RETURN_LOG_RET(observer != nullptr, ERR_INVALID_VALUE, "observer is nullptr");
146+ int result = RegisterClientObserver(*addr, *uuid, observer);
147+ bool ret = reply.WriteInt32(result);
148+ if (!ret) {
149+ HILOGE("reply writing failed.");
150+ return BT_ERR_IPC_TRANS_FAILED;
151+ }
152+ return BT_NO_ERROR;
153+}
154+ 
155+int32_t BluetoothSocketStub::DeregisterClientObserverInner(MessageParcel &data, MessageParcel &reply)
150{156{
151 return reply.WriteInt32(BT_NO_ERROR);157 return reply.WriteInt32(BT_NO_ERROR);
152}158}
153 159 
154-ErrCode BluetoothSocketStub::DeregisterClientObserverInner(MessageParcel &data, MessageParcel &reply)160+int32_t BluetoothSocketStub::UpdateCocConnectionParamsInner(MessageParcel &data, MessageParcel &reply)
155-{
156- return reply.WriteInt32(BT_NO_ERROR);
157-}
158- 
159-ErrCode BluetoothSocketStub::UpdateCocConnectionParamsInner(MessageParcel &data, MessageParcel &reply)
160{161{
161 return reply.WriteInt32(BT_ERR_API_NOT_SUPPORT);162 return reply.WriteInt32(BT_ERR_API_NOT_SUPPORT);
162}163}
163 164 
164-ErrCode BluetoothSocketStub::IsAllowSocketConnectInner(MessageParcel &data, MessageParcel &reply)165+int32_t BluetoothSocketStub::IsAllowSocketConnectInner(MessageParcel &data, MessageParcel &reply)
165{166{
166 reply.WriteInt32(BT_NO_ERROR);167 reply.WriteInt32(BT_NO_ERROR);
167 return reply.WriteBool(true);168 return reply.WriteBool(true);
Mservices/bluetooth/server/include/bluetooth_utils_server.h+1-0
@@ -25,6 +25,7 @@ namespace OHOS {
25namespace Bluetooth {25namespace Bluetooth {
26std::string GetEncryptAddr(std::string addr);26std::string GetEncryptAddr(std::string addr);
27std::string GetScanModeName(int mode);27std::string GetScanModeName(int mode);
28+bool IsValidAddress(const std::string &addr);
28 29 
29#define GET_ENCRYPT_ADDR(device) (GetEncryptAddr((device).GetAddress()).c_str())30#define GET_ENCRYPT_ADDR(device) (GetEncryptAddr((device).GetAddress()).c_str())
30#define GET_ENCRYPT_GATT_ADDR(device) (GetEncryptAddr((device).addr_.GetAddress()).c_str())31#define GET_ENCRYPT_GATT_ADDR(device) (GetEncryptAddr((device).addr_.GetAddress()).c_str())
Mservices/bluetooth/server/src/bluetooth_a2dp_sink_server.cpp+0-17
@@ -20,7 +20,6 @@
20#include "interface_profile_a2dp_snk.h"20#include "interface_profile_a2dp_snk.h"
21#include "remote_observer_list.h"21#include "remote_observer_list.h"
22#include "interface_adapter_manager.h"22#include "interface_adapter_manager.h"
23-#include "permission_utils.h"
24#include "bluetooth_a2dp_sink_server.h"23#include "bluetooth_a2dp_sink_server.h"
25 24 
26namespace OHOS {25namespace OHOS {
@@ -168,10 +167,6 @@ int BluetoothA2dpSinkServer::Disconnect(const RawAddress &device)
168int BluetoothA2dpSinkServer::GetDeviceState(const RawAddress &device)167int BluetoothA2dpSinkServer::GetDeviceState(const RawAddress &device)
169{168{
170 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));169 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
171- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
172- HILOGE("false, check permission failed");
173- return BT_FAILURE;
174- }
175 return pimpl->a2dpSnkService_->GetDeviceState(device);170 return pimpl->a2dpSnkService_->GetDeviceState(device);
176}171}
177 172 
@@ -179,10 +174,6 @@ std::vector<RawAddress> BluetoothA2dpSinkServer::GetDevicesByStates(const std::v
179{174{
180 HILOGI("starts");175 HILOGI("starts");
181 std::vector<RawAddress> rawDevices;176 std::vector<RawAddress> rawDevices;
182- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
183- HILOGE("false, check permission failed");
184- return rawDevices;
185- }
186 std::vector<int> tmpStates;177 std::vector<int> tmpStates;
187 for (int32_t state : states) {178 for (int32_t state : states) {
188 HILOGI("state = %{public}d", state);179 HILOGI("state = %{public}d", state);
@@ -196,19 +187,11 @@ std::vector<RawAddress> BluetoothA2dpSinkServer::GetDevicesByStates(const std::v
196int BluetoothA2dpSinkServer::GetPlayingState(const RawAddress &device, int &state)187int BluetoothA2dpSinkServer::GetPlayingState(const RawAddress &device, int &state)
197{188{
198 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));189 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
199- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
200- HILOGE("false, check permission failed");
201- return BT_FAILURE;
202- }
203 return pimpl->a2dpSnkService_->GetPlayingState(device, state);190 return pimpl->a2dpSnkService_->GetPlayingState(device, state);
204}191}
205 192 
206int BluetoothA2dpSinkServer::SetConnectStrategy(const RawAddress &device, int strategy)193int BluetoothA2dpSinkServer::SetConnectStrategy(const RawAddress &device, int strategy)
207{194{
208- if (!PermissionUtils::CheckSystemHapApp()) {
209- HILOGE("check system api failed.");
210- return BT_ERR_SYSTEM_PERMISSION_FAILED;
211- }
212 HILOGI("addr: %{public}s, strategy: %{public}d", GET_ENCRYPT_ADDR(device), strategy);195 HILOGI("addr: %{public}s, strategy: %{public}d", GET_ENCRYPT_ADDR(device), strategy);
213 return pimpl->a2dpSnkService_->SetConnectStrategy(device, strategy);196 return pimpl->a2dpSnkService_->SetConnectStrategy(device, strategy);
214}197}
Mservices/bluetooth/server/src/bluetooth_a2dp_source_server.cpp+7-31
@@ -23,8 +23,8 @@
23#include "interface_profile_a2dp_src.h"23#include "interface_profile_a2dp_src.h"
24#include "remote_observer_list.h"24#include "remote_observer_list.h"
25#include "interface_adapter_manager.h"25#include "interface_adapter_manager.h"
26-#include "permission_utils.h"
27#include "bluetooth_a2dp_source_server.h"26#include "bluetooth_a2dp_source_server.h"
27+#include "permission_manager.h"
28 28 
29namespace OHOS {29namespace OHOS {
30namespace Bluetooth {30namespace Bluetooth {
@@ -225,13 +225,9 @@ void BluetoothA2dpSourceServer::DeregisterObserver(const sptr<IBluetoothA2dpSour
225int32_t BluetoothA2dpSourceServer::Connect(const RawAddress &device)225int32_t BluetoothA2dpSourceServer::Connect(const RawAddress &device)
226{226{
227 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));227 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
228- if (!PermissionUtils::CheckSystemHapApp()) {228+ if (PermissionManager::GetApiVersion() >= API_VERSION_10 && !PermissionManager::IsSystemHap()) {
229- HILOGE("check system api failed.");229+ HILOGE("check permission failed, system hap need.");
230- return BT_ERR_SYSTEM_PERMISSION_FAILED;230+ return BT_ERR_PERMISSION_FAILED;
231- }
232- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
233- HILOGE("Connect error, check permission failed");
234- return BT_ERR_SYSTEM_PERMISSION_FAILED;
235 }231 }
236 OHOS::Bluetooth::BluetoothHiTrace::BluetoothStartAsyncTrace("A2DP_SRC_CONNECT", 1);232 OHOS::Bluetooth::BluetoothHiTrace::BluetoothStartAsyncTrace("A2DP_SRC_CONNECT", 1);
237 int32_t result = pimpl->a2dpSrcService_->Connect(device);233 int32_t result = pimpl->a2dpSrcService_->Connect(device);
@@ -242,13 +238,9 @@ int32_t BluetoothA2dpSourceServer::Connect(const RawAddress &device)
242int32_t BluetoothA2dpSourceServer::Disconnect(const RawAddress &device)238int32_t BluetoothA2dpSourceServer::Disconnect(const RawAddress &device)
243{239{
244 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));240 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
245- if (!PermissionUtils::CheckSystemHapApp()) {241+ if (PermissionManager::GetApiVersion() >= API_VERSION_10 && !PermissionManager::IsSystemHap()) {
246- HILOGE("check system api failed.");242+ HILOGE("check permission failed, system hap need.");
247- return BT_ERR_SYSTEM_PERMISSION_FAILED;243+ return BT_ERR_PERMISSION_FAILED;
248- }
249- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
250- HILOGE("Disconnect error, check permission failed");
251- return BT_ERR_SYSTEM_PERMISSION_FAILED;
252 }244 }
253 return pimpl->a2dpSrcService_->Disconnect(device);245 return pimpl->a2dpSrcService_->Disconnect(device);
254}246}
@@ -256,10 +248,6 @@ int32_t BluetoothA2dpSourceServer::Disconnect(const RawAddress &device)
256int BluetoothA2dpSourceServer::GetDeviceState(const RawAddress &device, int &state)248int BluetoothA2dpSourceServer::GetDeviceState(const RawAddress &device, int &state)
257{249{
258 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));250 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
259- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
260- HILOGE("false, check permission failed");
261- return RET_NO_SUPPORT;
262- }
263 state = pimpl->a2dpSrcService_->GetDeviceState(device);251 state = pimpl->a2dpSrcService_->GetDeviceState(device);
264 return NO_ERROR;252 return NO_ERROR;
265}253}
@@ -267,10 +255,6 @@ int BluetoothA2dpSourceServer::GetDeviceState(const RawAddress &device, int &sta
267int BluetoothA2dpSourceServer::GetDevicesByStates(const std::vector<int32_t> &states, std::vector<RawAddress> &rawAddrs)255int BluetoothA2dpSourceServer::GetDevicesByStates(const std::vector<int32_t> &states, std::vector<RawAddress> &rawAddrs)
268{256{
269 HILOGI("starts");257 HILOGI("starts");
270- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
271- HILOGE("false, check permission failed");
272- return BT_ERR_PERMISSION_FAILED;
273- }
274 std::vector<int> tmpStates;258 std::vector<int> tmpStates;
275 for (int32_t state : states) {259 for (int32_t state : states) {
276 HILOGI("state = %{public}d", state);260 HILOGI("state = %{public}d", state);
@@ -284,10 +268,6 @@ int BluetoothA2dpSourceServer::GetDevicesByStates(const std::vector<int32_t> &st
284int32_t BluetoothA2dpSourceServer::GetPlayingState(const RawAddress &device, int &state)268int32_t BluetoothA2dpSourceServer::GetPlayingState(const RawAddress &device, int &state)
285{269{
286 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));270 HILOGI("addr: %{public}s", GET_ENCRYPT_ADDR(device));
287- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
288- HILOGE("false, check permission failed");
289- return BT_ERR_SYSTEM_PERMISSION_FAILED;
290- }
291 int ret = pimpl->a2dpSrcService_->GetPlayingState(device, state);271 int ret = pimpl->a2dpSrcService_->GetPlayingState(device, state);
292 if (ret != NO_ERROR) {272 if (ret != NO_ERROR) {
293 return BT_ERR_INTERNAL_ERROR;273 return BT_ERR_INTERNAL_ERROR;
@@ -297,10 +277,6 @@ int32_t BluetoothA2dpSourceServer::GetPlayingState(const RawAddress &device, int
297 277 
298int BluetoothA2dpSourceServer::SetConnectStrategy(const RawAddress &device, int strategy)278int BluetoothA2dpSourceServer::SetConnectStrategy(const RawAddress &device, int strategy)
299{279{
300- if (!PermissionUtils::CheckSystemHapApp()) {
301- HILOGE("check system api failed.");
302- return BT_ERR_SYSTEM_PERMISSION_FAILED;
303- }
304 HILOGI("addr: %{public}s, strategy: %{public}d", GET_ENCRYPT_ADDR(device), strategy);280 HILOGI("addr: %{public}s, strategy: %{public}d", GET_ENCRYPT_ADDR(device), strategy);
305 return pimpl->a2dpSrcService_->SetConnectStrategy(device, strategy);281 return pimpl->a2dpSrcService_->SetConnectStrategy(device, strategy);
306}282}
Mservices/bluetooth/server/src/bluetooth_avrcp_ct_server.cpp+0-9
@@ -22,7 +22,6 @@
22#include "interface_profile_avrcp_ct.h"22#include "interface_profile_avrcp_ct.h"
23#include "interface_profile_manager.h"23#include "interface_profile_manager.h"
24#include "remote_observer_list.h"24#include "remote_observer_list.h"
25-#include "permission_utils.h"
26 25 
27 26 
28namespace OHOS {27namespace OHOS {
@@ -818,10 +817,6 @@ std::vector<RawAddress> BluetoothAvrcpCtServer::GetDevicesByStates(const std::ve
818{817{
819 HILOGI("start.");818 HILOGI("start.");
820 std::vector<RawAddress> devices {};819 std::vector<RawAddress> devices {};
821- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
822- HILOGE("false, check permission failed");
823- return devices;
824- }
825 if (pimpl->IsEnabled()) {820 if (pimpl->IsEnabled()) {
826 std::vector<int> convertStates;821 std::vector<int> convertStates;
827 for (auto state : states) {822 for (auto state : states) {
@@ -839,10 +834,6 @@ std::vector<RawAddress> BluetoothAvrcpCtServer::GetDevicesByStates(const std::ve
839int32_t BluetoothAvrcpCtServer::GetDeviceState(const RawAddress &device)834int32_t BluetoothAvrcpCtServer::GetDeviceState(const RawAddress &device)
840{835{
841 HILOGI("addr: %{public}s", GetEncryptAddr(device.GetAddress()).c_str());836 HILOGI("addr: %{public}s", GetEncryptAddr(device.GetAddress()).c_str());
842- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
843- HILOGE("false, check permission failed");
844- return BT_FAILURE;
845- }
846 int32_t result = 0;837 int32_t result = 0;
847 838 
848 if (pimpl->IsEnabled()) {839 if (pimpl->IsEnabled()) {
Mservices/bluetooth/server/src/bluetooth_avrcp_tg_server.cpp+0-14
@@ -22,7 +22,6 @@
22#include "interface_profile_avrcp_tg.h"22#include "interface_profile_avrcp_tg.h"
23#include "interface_profile_manager.h"23#include "interface_profile_manager.h"
24#include "remote_observer_list.h"24#include "remote_observer_list.h"
25-#include "permission_utils.h"
26#include "bluetooth_errorcode.h"25#include "bluetooth_errorcode.h"
27 26 
28 27 
@@ -209,10 +208,6 @@ void BluetoothAvrcpTgServer::SetActiveDevice(const BluetoothRawAddress &addr)
209int32_t BluetoothAvrcpTgServer::Connect(const BluetoothRawAddress &addr)208int32_t BluetoothAvrcpTgServer::Connect(const BluetoothRawAddress &addr)
210{209{
211 HILOGI("address: %{public}s", GetEncryptAddr(addr.GetAddress()).c_str());210 HILOGI("address: %{public}s", GetEncryptAddr(addr.GetAddress()).c_str());
212- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
213- HILOGE("Connect error, check permission failed");
214- return BT_FAILURE;
215- }
216 int32_t result = 0;211 int32_t result = 0;
217 212 
218 if (pimpl->IsEnabled()) {213 if (pimpl->IsEnabled()) {
@@ -265,11 +260,6 @@ std::vector<BluetoothRawAddress> BluetoothAvrcpTgServer::GetDevicesByStates(cons
265 HILOGI("start.");260 HILOGI("start.");
266 261 
267 std::vector<BluetoothRawAddress> results;262 std::vector<BluetoothRawAddress> results;
268- 
269- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
270- HILOGE("false, check permission failed");
271- return results;
272- }
273 if (!pimpl->IsEnabled()) {263 if (!pimpl->IsEnabled()) {
274 HILOGE("service is null or disable ");264 HILOGE("service is null or disable ");
275 return results;265 return results;
@@ -295,10 +285,6 @@ std::vector<BluetoothRawAddress> BluetoothAvrcpTgServer::GetDevicesByStates(cons
295int32_t BluetoothAvrcpTgServer::GetDeviceState(const BluetoothRawAddress &addr)285int32_t BluetoothAvrcpTgServer::GetDeviceState(const BluetoothRawAddress &addr)
296{286{
297 HILOGI("address: %{public}s", GetEncryptAddr(addr.GetAddress()).c_str());287 HILOGI("address: %{public}s", GetEncryptAddr(addr.GetAddress()).c_str());
298- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
299- HILOGE("false, check permission failed");
300- return BT_FAILURE;
301- }
302 int32_t result = 0;288 int32_t result = 0;
303 289 
304 if (pimpl->IsEnabled()) {290 if (pimpl->IsEnabled()) {
Mservices/bluetooth/server/src/bluetooth_ble_advertiser_server.cpp+0-15
@@ -22,7 +22,6 @@
22#include "interface_adapter_manager.h"22#include "interface_adapter_manager.h"
23#include "ipc_skeleton.h"23#include "ipc_skeleton.h"
24#include "remote_observer_list.h"24#include "remote_observer_list.h"
25-#include "permission_utils.h"
26#include "safe_map.h"25#include "safe_map.h"
27 26 
28#define ADVERTISE_FAILED_TOO_MANY_ADVERTISERS 0x0227#define ADVERTISE_FAILED_TOO_MANY_ADVERTISERS 0x02
@@ -204,11 +203,6 @@ int BluetoothBleAdvertiserServer::StartAdvertising(const BluetoothBleAdvertiserS
204 uint16_t duration, bool isRawData)203 uint16_t duration, bool isRawData)
205{204{
206 HILOGI("enter");205 HILOGI("enter");
207- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
208- HILOGE("check permission failed");
209- return BT_ERR_PERMISSION_FAILED;
210- }
211- 
212 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();206 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
213 if (bleService != nullptr) {207 if (bleService != nullptr) {
214 BleAdvertiserSettingsImpl settingsImpl;208 BleAdvertiserSettingsImpl settingsImpl;
@@ -245,11 +239,6 @@ int BluetoothBleAdvertiserServer::DisableAdvertising(uint8_t advHandle)
245int BluetoothBleAdvertiserServer::StopAdvertising(int32_t advHandle)239int BluetoothBleAdvertiserServer::StopAdvertising(int32_t advHandle)
246{240{
247 HILOGI("enter, advHandle: %{public}d", advHandle);241 HILOGI("enter, advHandle: %{public}d", advHandle);
248- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
249- HILOGE("check permission failed");
250- return BT_ERR_PERMISSION_FAILED;
251- }
252- 
253 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();242 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
254 if (bleService != nullptr) {243 if (bleService != nullptr) {
255 bleService->StopAdvertising(advHandle);244 bleService->StopAdvertising(advHandle);
@@ -312,10 +301,6 @@ int32_t BluetoothBleAdvertiserServer::GetAdvertiserHandle(int32_t &advHandle,
312 const sptr<IBluetoothBleAdvertiseCallback> &callback)301 const sptr<IBluetoothBleAdvertiseCallback> &callback)
313{302{
314 HILOGI("enter");303 HILOGI("enter");
315- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
316- HILOGE("check permission failed");
317- return BT_ERR_PERMISSION_FAILED;
318- }
319 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();304 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
320 if (bleService == nullptr) {305 if (bleService == nullptr) {
321 return BT_ERR_INTERNAL_ERROR;306 return BT_ERR_INTERNAL_ERROR;
Mservices/bluetooth/server/src/bluetooth_ble_central_manager_server.cpp+41-30
@@ -26,7 +26,7 @@
26#include "interface_adapter_manager.h"26#include "interface_adapter_manager.h"
27#include "ipc_skeleton.h"27#include "ipc_skeleton.h"
28#include "remote_observer_list.h"28#include "remote_observer_list.h"
29-#include "permission_utils.h"29+#include "permission_manager.h"
30#include "bluetooth_ble_central_manager_server.h"30#include "bluetooth_ble_central_manager_server.h"
31#include "safe_map.h"31#include "safe_map.h"
32 32 
@@ -94,28 +94,36 @@ public:
94 HILOGD("pid:%{public}d is proxy pid, not callback.", pid);94 HILOGD("pid:%{public}d is proxy pid, not callback.", pid);
95 return;95 return;
96 }96 }
97- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {97+ if (PermissionManager::IsNativeCaller(tokenId) ||
98- HILOGE("OnScanCallback(): failed, check permission failed, tokenId: %{public}u", tokenId);98+ PermissionManager::GetApiVersion(tokenId) >= API_VERSION_10) {
99- } else {99+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
100- BluetoothBleScanResult bleScanResult(result);100+ HILOGI("check ACCESS_BLUETOOTH permission failed");
101- int32_t scannerId = this->pimpl_->observersScannerId_[observer->AsObject()];
102- std::lock_guard<std::mutex> lock(this->pimpl_->bleScanFiltersMutex_);
103- HILOGD("OnScanCallback() start bleScanFilter Address: %{public}s scannerId:%{public}d",
104- GetEncryptAddr(result.GetPeripheralDevice().GetRawAddress().GetAddress()).c_str(), scannerId);
105- bool scanFiltersIsEnanled_ = this->pimpl_->observersScanFiltersIsEnanled_[scannerId];
106- // if bleScanFilter been set empty when stopped scan, we need refuse callback instead of filter pass
107- if (!scanFiltersIsEnanled_) {
108 return;101 return;
109 }102 }
110- std::vector<bluetooth::BleScanFilterImpl> scanFilters_ = this->pimpl_->103+ } else {
111- observersBleScanFilters_[scannerId];104+ if (!PermissionManager::VerifyPermission(USE_BLUETOOTH, tokenId)) {
112- if (scanFilters_.empty() ||105+ HILOGI("check USE_BLUETOOTH permission failed");
113- BluetoothBleFilterMatcher::MatchesScanFilters(scanFilters_, bleScanResult) == MatchResult::MATCH) {106+ return;
114- observer->OnScanCallback(bleScanResult);
115- HILOGD("OnScanCallback() passed bleScanFilter Address: %{public}s scannerId:%{public}d",
116- GetEncryptAddr(result.GetPeripheralDevice().GetRawAddress().GetAddress()).c_str(), scannerId);
117 }107 }
118 }108 }
109+ BluetoothBleScanResult bleScanResult(result);
110+ int32_t scannerId = this->pimpl_->observersScannerId_[observer->AsObject()];
111+ std::lock_guard<std::mutex> lock(this->pimpl_->bleScanFiltersMutex_);
112+ HILOGD("OnScanCallback() start bleScanFilter Address: %{public}s scannerId:%{public}d",
113+ GetEncryptAddr(result.GetPeripheralDevice().GetRawAddress().GetAddress()).c_str(), scannerId);
114+ bool scanFiltersIsEnanled_ = this->pimpl_->observersScanFiltersIsEnanled_[scannerId];
115+ // if bleScanFilter been set empty when stopped scan, we need refuse callback instead of filter pass
116+ if (!scanFiltersIsEnanled_) {
117+ return;
118+ }
119+ std::vector<bluetooth::BleScanFilterImpl> scanFilters_ = this->pimpl_->
120+ observersBleScanFilters_[scannerId];
121+ if (scanFilters_.empty() ||
122+ BluetoothBleFilterMatcher::MatchesScanFilters(scanFilters_, bleScanResult) == MatchResult::MATCH) {
123+ observer->OnScanCallback(bleScanResult);
124+ HILOGD("OnScanCallback() passed bleScanFilter Address: %{public}s scannerId:%{public}d",
125+ GetEncryptAddr(result.GetPeripheralDevice().GetRawAddress().GetAddress()).c_str(), scannerId);
126+ }
119 });127 });
120 }128 }
121 129 
@@ -349,19 +357,19 @@ bool BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(int32_t pid)
349 357 
350bool CheckBleScanPermission()358bool CheckBleScanPermission()
351{359{
352- if (PermissionUtils::GetApiVersion() >= 10) { // 10:api version360+ if (PermissionManager::GetApiVersion() >= API_VERSION_10) { // 10:api version
353- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {361+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH) == false) {
354 HILOGE("check access permission failed.");362 HILOGE("check access permission failed.");
355 return false;363 return false;
356 }364 }
357 } else {365 } else {
358- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED ||366+ if (PermissionManager::VerifyPermission(DISCOVER_BLUETOOTH) == false ||
359- PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {367+ PermissionManager::VerifyPermission(MANAGE_BLUETOOTH) == false) {
360 HILOGE("check permission failed.");368 HILOGE("check permission failed.");
361 return false;369 return false;
362 }370 }
363- if (PermissionUtils::VerifyApproximatelyPermission() == PERMISSION_DENIED &&371+ if (PermissionManager::VerifyPermission(APPROXIMATELY_LOCATION) == false &&
364- PermissionUtils::VerifyLocationPermission() == PERMISSION_DENIED) {372+ PermissionManager::VerifyPermission(LOCATION) == false) {
365 HILOGE("No location permission");373 HILOGE("No location permission");
366 return false;374 return false;
367 }375 }
@@ -430,11 +438,6 @@ int BluetoothBleCentralManagerServer::StopScan(int32_t scannerId)
430 int32_t pid = IPCSkeleton::GetCallingPid();438 int32_t pid = IPCSkeleton::GetCallingPid();
431 int32_t uid = IPCSkeleton::GetCallingUid();439 int32_t uid = IPCSkeleton::GetCallingUid();
432 HILOGI("pid: %{public}d, uid: %{public}d", pid, uid);440 HILOGI("pid: %{public}d, uid: %{public}d", pid, uid);
433- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
434- HILOGE("check permission failed.");
435- return BT_ERR_PERMISSION_FAILED;
436- }
437- 
438 pimpl->eventHandler_->PostSyncTask([&]() {441 pimpl->eventHandler_->PostSyncTask([&]() {
439 if (!pimpl->isScanning) {442 if (!pimpl->isScanning) {
440 HILOGE("scan is not started.");443 HILOGE("scan is not started.");
@@ -566,11 +569,19 @@ void BluetoothBleCentralManagerServer::DeregisterBleCentralManagerCallbackInner(
566int BluetoothBleCentralManagerServer::ChangeScanParams(int32_t scannerId, const BluetoothBleScanSettings &settings,569int BluetoothBleCentralManagerServer::ChangeScanParams(int32_t scannerId, const BluetoothBleScanSettings &settings,
567 const std::vector<BluetoothBleScanFilter> &filters, uint32_t filterAction)570 const std::vector<BluetoothBleScanFilter> &filters, uint32_t filterAction)
568{571{
572+ if (!CheckBleScanPermission()) {
573+ HILOGE("check permission failed.");
574+ return BT_ERR_PERMISSION_FAILED;
575+ }
569 return BT_ERR_API_NOT_SUPPORT;576 return BT_ERR_API_NOT_SUPPORT;
570}577}
571 578 
572int BluetoothBleCentralManagerServer::IsValidScannerId(int32_t scannerId, bool &isValid)579int BluetoothBleCentralManagerServer::IsValidScannerId(int32_t scannerId, bool &isValid)
573{580{
581+ if (!CheckBleScanPermission()) {
582+ HILOGE("check permission failed.");
583+ return BT_ERR_PERMISSION_FAILED;
584+ }
574 isValid = true;585 isValid = true;
575 return NO_ERROR;586 return NO_ERROR;
576}587}
Mservices/bluetooth/server/src/bluetooth_gatt_client_server.cpp+29-41
@@ -31,7 +31,7 @@
31#include "string_ex.h"31#include "string_ex.h"
32#include "system_ability_definition.h"32#include "system_ability_definition.h"
33#include "ipc_skeleton.h"33#include "ipc_skeleton.h"
34-#include "permission_utils.h"34+#include "permission_manager.h"
35 35 
36using namespace OHOS::bluetooth;36using namespace OHOS::bluetooth;
37namespace OHOS {37namespace OHOS {
@@ -84,13 +84,31 @@ private:
84 BluetoothGattClientServer::impl *impl_;84 BluetoothGattClientServer::impl *impl_;
85};85};
86 86 
87+namespace {
88+ 
89+bool CheckGattClientPermission(uint64_t tokenId, int sdkVersion)
90+{
91+ if (PermissionManager::IsNativeCaller(tokenId) || sdkVersion >= API_VERSION_10) {
92+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
93+ HILOGI("check ACCESS_BLUETOOTH permission failed");
94+ return false;
95+ }
96+ } else {
97+ if (!PermissionManager::VerifyPermission(USE_BLUETOOTH, tokenId)) {
98+ HILOGI("check USE_BLUETOOTH permission failed");
99+ return false;
100+ }
101+ }
102+ return true;
103+}
104+} // namespace {}
105+ 
87class BluetoothGattClientServer::impl::GattClientCallbackImpl : public IGattClientCallback {106class BluetoothGattClientServer::impl::GattClientCallbackImpl : public IGattClientCallback {
88public:107public:
89 void OnConnectionStateChanged(int state, int newState) override108 void OnConnectionStateChanged(int state, int newState) override
90 {109 {
91 HILOGI("curState(%{public}d) -> newState(%{public}d)", state, newState);110 HILOGI("curState(%{public}d) -> newState(%{public}d)", state, newState);
92- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {111+ if (!CheckGattClientPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
93- HILOGE("check permission failed, tokenId: %{public}u", tokenId_);
94 return;112 return;
95 }113 }
96 int32_t pid = IPCSkeleton::GetCallingPid();114 int32_t pid = IPCSkeleton::GetCallingPid();
@@ -106,8 +124,7 @@ public:
106 void OnCharacteristicChanged(const Characteristic &characteristic) override124 void OnCharacteristicChanged(const Characteristic &characteristic) override
107 {125 {
108 HILOGI("enter");126 HILOGI("enter");
109- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {127+ if (!CheckGattClientPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
110- HILOGE("check permission failed, tokenId: %{public}u", tokenId_);
111 return;128 return;
112 }129 }
113 callback_->OnCharacteristicChanged((BluetoothGattCharacteristic)characteristic);130 callback_->OnCharacteristicChanged((BluetoothGattCharacteristic)characteristic);
@@ -141,6 +158,13 @@ public:
141 void OnMtuChanged(int state, int mtu) override158 void OnMtuChanged(int state, int mtu) override
142 {159 {
143 HILOGI("state: %{public}d, mtu: %{public}d", state, mtu);160 HILOGI("state: %{public}d, mtu: %{public}d", state, mtu);
161+ if (PermissionManager::IsNativeCaller(tokenId_) ||
162+ PermissionManager::GetApiVersion(tokenId_) >= API_VERSION_10) {
163+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId_) == false) {
164+ HILOGE("check access permission failed.");
165+ return;
166+ }
167+ }
144 callback_->OnMtuChanged(state, mtu);168 callback_->OnMtuChanged(state, mtu);
145 }169 }
146 170 
@@ -313,10 +337,6 @@ int BluetoothGattClientServer::RegisterApplication(
313int BluetoothGattClientServer::DeregisterApplication(int32_t appId)337int BluetoothGattClientServer::DeregisterApplication(int32_t appId)
314{338{
315 HILOGI("appId: %{public}d", appId);339 HILOGI("appId: %{public}d", appId);
316- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
317- HILOGE("check permission failed");
318- return REQUEST_NOT_SUPPORT;
319- }
320 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);340 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
321 if (pimpl->clientService_ == nullptr) {341 if (pimpl->clientService_ == nullptr) {
322 HILOGE("request not support.");342 HILOGE("request not support.");
@@ -342,10 +362,6 @@ int BluetoothGattClientServer::DeregisterApplication(int32_t appId)
342int BluetoothGattClientServer::Connect(int32_t appId, bool autoConnect)362int BluetoothGattClientServer::Connect(int32_t appId, bool autoConnect)
343{363{
344 HILOGI("appId: %{public}d, autoConnect: %{public}d", appId, autoConnect);364 HILOGI("appId: %{public}d, autoConnect: %{public}d", appId, autoConnect);
345- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
346- HILOGE("check permission failed");
347- return BT_ERR_PERMISSION_FAILED;
348- }
349 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);365 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
350 if (pimpl->clientService_ == nullptr) {366 if (pimpl->clientService_ == nullptr) {
351 HILOGE("request not support.");367 HILOGE("request not support.");
@@ -360,10 +376,6 @@ int BluetoothGattClientServer::Connect(int32_t appId, bool autoConnect)
360int BluetoothGattClientServer::Disconnect(int32_t appId)376int BluetoothGattClientServer::Disconnect(int32_t appId)
361{377{
362 HILOGI("appId: %{public}d", appId);378 HILOGI("appId: %{public}d", appId);
363- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
364- HILOGE("check permission failed");
365- return BT_ERR_PERMISSION_FAILED;
366- }
367 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);379 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
368 if (pimpl->clientService_ == nullptr) {380 if (pimpl->clientService_ == nullptr) {
369 HILOGE("request not support.");381 HILOGE("request not support.");
@@ -386,10 +398,6 @@ int BluetoothGattClientServer::DiscoveryServices(int32_t appId)
386int BluetoothGattClientServer::ReadCharacteristic(int32_t appId, const BluetoothGattCharacteristic &characteristic)398int BluetoothGattClientServer::ReadCharacteristic(int32_t appId, const BluetoothGattCharacteristic &characteristic)
387{399{
388 HILOGI("appId: %{public}d", appId);400 HILOGI("appId: %{public}d", appId);
389- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
390- HILOGE("check permission failed");
391- return BT_ERR_PERMISSION_FAILED;
392- }
393 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);401 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
394 if (pimpl->clientService_ == nullptr) {402 if (pimpl->clientService_ == nullptr) {
395 HILOGE("request not support.");403 HILOGE("request not support.");
@@ -406,10 +414,6 @@ int BluetoothGattClientServer::WriteCharacteristic(
406 return BT_ERR_API_NOT_SUPPORT;414 return BT_ERR_API_NOT_SUPPORT;
407 }415 }
408 HILOGI("appId: %{public}d, withoutRespond: %{public}d", appId, withoutRespond);416 HILOGI("appId: %{public}d, withoutRespond: %{public}d", appId, withoutRespond);
409- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
410- HILOGE("check permission failed");
411- return BT_ERR_PERMISSION_FAILED;
412- }
413 Characteristic character(characteristic->handle_);417 Characteristic character(characteristic->handle_);
414 character.length_ = characteristic->length_;418 character.length_ = characteristic->length_;
415 character.value_ = std::move(characteristic->value_);419 character.value_ = std::move(characteristic->value_);
@@ -439,10 +443,6 @@ int BluetoothGattClientServer::SignedWriteCharacteristic(int32_t appId, Bluetoot
439int BluetoothGattClientServer::ReadDescriptor(int32_t appId, const BluetoothGattDescriptor &descriptor)443int BluetoothGattClientServer::ReadDescriptor(int32_t appId, const BluetoothGattDescriptor &descriptor)
440{444{
441 HILOGI("appId: %{public}d", appId);445 HILOGI("appId: %{public}d", appId);
442- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
443- HILOGE("check permission failed");
444- return BT_ERR_PERMISSION_FAILED;
445- }
446 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);446 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
447 if (pimpl->clientService_ == nullptr) {447 if (pimpl->clientService_ == nullptr) {
448 HILOGE("request not support.");448 HILOGE("request not support.");
@@ -454,10 +454,6 @@ int BluetoothGattClientServer::ReadDescriptor(int32_t appId, const BluetoothGatt
454int BluetoothGattClientServer::WriteDescriptor(int32_t appId, BluetoothGattDescriptor *descriptor)454int BluetoothGattClientServer::WriteDescriptor(int32_t appId, BluetoothGattDescriptor *descriptor)
455{455{
456 HILOGI("appId: %{public}d", appId);456 HILOGI("appId: %{public}d", appId);
457- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
458- HILOGE("check permission failed");
459- return BT_ERR_PERMISSION_FAILED;
460- }
461 Descriptor desc(descriptor->handle_);457 Descriptor desc(descriptor->handle_);
462 desc.length_ = descriptor->length_;458 desc.length_ = descriptor->length_;
463 desc.value_ = std::move(descriptor->value_);459 desc.value_ = std::move(descriptor->value_);
@@ -473,10 +469,6 @@ int BluetoothGattClientServer::WriteDescriptor(int32_t appId, BluetoothGattDescr
473int BluetoothGattClientServer::RequestExchangeMtu(int32_t appId, int32_t mtu)469int BluetoothGattClientServer::RequestExchangeMtu(int32_t appId, int32_t mtu)
474{470{
475 HILOGI("appId: %{public}d, mtu: %{public}d", appId, mtu);471 HILOGI("appId: %{public}d, mtu: %{public}d", appId, mtu);
476- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
477- HILOGE("check permission failed");
478- return BT_ERR_PERMISSION_FAILED;
479- }
480 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);472 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
481 if (pimpl->clientService_ == nullptr) {473 if (pimpl->clientService_ == nullptr) {
482 HILOGE("request not support.");474 HILOGE("request not support.");
@@ -512,10 +504,6 @@ int BluetoothGattClientServer::RequestConnectionPriority(int32_t appId, int32_t
512int BluetoothGattClientServer::GetServices(int32_t appId, ::std::vector<BluetoothGattService> &service)504int BluetoothGattClientServer::GetServices(int32_t appId, ::std::vector<BluetoothGattService> &service)
513{505{
514 HILOGI("appId: %{public}d", appId);506 HILOGI("appId: %{public}d", appId);
515- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
516- HILOGE("check permission failed");
517- return RET_NO_SUPPORT;
518- }
519 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);507 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
520 if (pimpl->clientService_ == nullptr) {508 if (pimpl->clientService_ == nullptr) {
521 HILOGE("request not support.");509 HILOGE("request not support.");
Mservices/bluetooth/server/src/bluetooth_gatt_server_server.cpp+24-43
@@ -27,7 +27,7 @@
27#include "interface_profile_gatt_server.h"27#include "interface_profile_gatt_server.h"
28#include "interface_profile_manager.h"28#include "interface_profile_manager.h"
29#include "ipc_skeleton.h"29#include "ipc_skeleton.h"
30-#include "permission_utils.h"30+#include "permission_manager.h"
31 31 
32namespace OHOS {32namespace OHOS {
33namespace Bluetooth {33namespace Bluetooth {
@@ -82,14 +82,31 @@ private:
82 BluetoothGattServerServer::impl *impl_;82 BluetoothGattServerServer::impl *impl_;
83};83};
84 84 
85+namespace {
86+ bool CheckGattServerPermission(uint64_t tokenId, int sdkVersion)
87+ {
88+ if (PermissionManager::IsNativeCaller(tokenId) || sdkVersion >= API_VERSION_10) {
89+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
90+ HILOGI("check ACCESS_BLUETOOTH permission failed");
91+ return false;
92+ }
93+ } else {
94+ if (!PermissionManager::VerifyPermission(USE_BLUETOOTH, tokenId)) {
95+ HILOGI("check USE_BLUETOOTH permission failed");
96+ return false;
97+ }
98+ }
99+ return true;
100+ }
101+} // namespace {}
102+ 
85class BluetoothGattServerServer::impl::GattServerCallbackImpl : public bluetooth::IGattServerCallback {103class BluetoothGattServerServer::impl::GattServerCallbackImpl : public bluetooth::IGattServerCallback {
86public:104public:
87 void OnCharacteristicReadRequest(105 void OnCharacteristicReadRequest(
88 const bluetooth::GattDevice &device, const bluetooth::Characteristic &characteristic) override106 const bluetooth::GattDevice &device, const bluetooth::Characteristic &characteristic) override
89 {107 {
90 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));108 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));
91- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {109+ if (!CheckGattServerPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
92- HILOGE("check permission failed, tokenId_: %{public}u", tokenId_);
93 return;110 return;
94 }111 }
95 callback_->OnCharacteristicReadRequest(112 callback_->OnCharacteristicReadRequest(
@@ -104,8 +121,7 @@ public:
104 const bluetooth::Characteristic &characteristic, bool needRespones) override121 const bluetooth::Characteristic &characteristic, bool needRespones) override
105 {122 {
106 HILOGI("addr: %{public}s, needRespones: %{public}d", GET_ENCRYPT_GATT_ADDR(device), needRespones);123 HILOGI("addr: %{public}s, needRespones: %{public}d", GET_ENCRYPT_GATT_ADDR(device), needRespones);
107- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {124+ if (!CheckGattServerPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
108- HILOGE("check permission failed, tokenId_: %{public}u", tokenId_);
109 return;125 return;
110 }126 }
111 callback_->OnCharacteristicWriteRequest(127 callback_->OnCharacteristicWriteRequest(
@@ -114,8 +130,7 @@ public:
114 void OnDescriptorReadRequest(const bluetooth::GattDevice &device, const bluetooth::Descriptor &descriptor) override130 void OnDescriptorReadRequest(const bluetooth::GattDevice &device, const bluetooth::Descriptor &descriptor) override
115 {131 {
116 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));132 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));
117- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {133+ if (!CheckGattServerPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
118- HILOGE("check permission failed, tokenId_: %{public}u", tokenId_);
119 return;134 return;
120 }135 }
121 callback_->OnDescriptorReadRequest((BluetoothGattDevice)device, (BluetoothGattDescriptor)descriptor);136 callback_->OnDescriptorReadRequest((BluetoothGattDevice)device, (BluetoothGattDescriptor)descriptor);
@@ -123,8 +138,7 @@ public:
123 void OnDescriptorWriteRequest(const bluetooth::GattDevice &device, const bluetooth::Descriptor &descriptor) override138 void OnDescriptorWriteRequest(const bluetooth::GattDevice &device, const bluetooth::Descriptor &descriptor) override
124 {139 {
125 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));140 HILOGI("addr: %{public}s", GET_ENCRYPT_GATT_ADDR(device));
126- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {141+ if (!CheckGattServerPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
127- HILOGE("check permission failed, tokenId_: %{public}u", tokenId_);
128 return;142 return;
129 }143 }
130 callback_->OnDescriptorWriteRequest((BluetoothGattDevice)device, (BluetoothGattDescriptor)descriptor);144 callback_->OnDescriptorWriteRequest((BluetoothGattDevice)device, (BluetoothGattDescriptor)descriptor);
@@ -138,8 +152,7 @@ public:
138 void OnConnectionStateChanged(const bluetooth::GattDevice &device, int ret, int state) override152 void OnConnectionStateChanged(const bluetooth::GattDevice &device, int ret, int state) override
139 {153 {
140 HILOGI("addr: %{public}s, ret: %{public}d, state: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret, state);154 HILOGI("addr: %{public}s, ret: %{public}d, state: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret, state);
141- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {155+ if (!CheckGattServerPermission(tokenId_, PermissionManager::GetApiVersion(tokenId_))) {
142- HILOGE("check permission failed, tokenId_: %{public}u", tokenId_);
143 return;156 return;
144 }157 }
145 int32_t pid = IPCSkeleton::GetCallingPid();158 int32_t pid = IPCSkeleton::GetCallingPid();
@@ -307,10 +320,6 @@ void ConvertCharacterPermission(bluetooth::Service &service)
307int BluetoothGattServerServer::AddService(int32_t appId, BluetoothGattService *services)320int BluetoothGattServerServer::AddService(int32_t appId, BluetoothGattService *services)
308{321{
309 HILOGI("enter, appId: %{public}d", appId);322 HILOGI("enter, appId: %{public}d", appId);
310- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
311- HILOGE("check permission failed");
312- return BT_ERR_PERMISSION_FAILED;
313- }
314 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);323 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
315 if (!pimpl->serverService_) {324 if (!pimpl->serverService_) {
316 HILOGE("serverService_ is null");325 HILOGE("serverService_ is null");
@@ -350,10 +359,6 @@ int BluetoothGattServerServer::NotifyClient(
350 const BluetoothGattDevice &device, BluetoothGattCharacteristic *characteristic, bool needConfirm)359 const BluetoothGattDevice &device, BluetoothGattCharacteristic *characteristic, bool needConfirm)
351{360{
352 HILOGI("addr: %{public}s, needConfirm: %{public}d", GET_ENCRYPT_GATT_ADDR(device), needConfirm);361 HILOGI("addr: %{public}s, needConfirm: %{public}d", GET_ENCRYPT_GATT_ADDR(device), needConfirm);
353- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
354- HILOGE("check permission failed");
355- return BT_ERR_PERMISSION_FAILED;
356- }
357 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);362 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
358 if (!pimpl->serverService_) {363 if (!pimpl->serverService_) {
359 HILOGE("serverService_ is null");364 HILOGE("serverService_ is null");
@@ -371,10 +376,6 @@ int BluetoothGattServerServer::NotifyClient(
371int BluetoothGattServerServer::RemoveService(int32_t appId, const BluetoothGattService &services)376int BluetoothGattServerServer::RemoveService(int32_t appId, const BluetoothGattService &services)
372{377{
373 HILOGI("appId: %{public}d", appId);378 HILOGI("appId: %{public}d", appId);
374- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
375- HILOGE("check permission failed");
376- return BT_ERR_PERMISSION_FAILED;
377- }
378 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);379 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
379 if (!pimpl->serverService_) {380 if (!pimpl->serverService_) {
380 HILOGE("serverService_ is null");381 HILOGE("serverService_ is null");
@@ -389,10 +390,6 @@ int BluetoothGattServerServer::RespondCharacteristicRead(
389 const BluetoothGattDevice &device, BluetoothGattCharacteristic *characteristic, int32_t ret)390 const BluetoothGattDevice &device, BluetoothGattCharacteristic *characteristic, int32_t ret)
390{391{
391 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);392 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);
392- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
393- HILOGE("check permission failed");
394- return BT_ERR_PERMISSION_FAILED;
395- }
396 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);393 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
397 if (!pimpl->serverService_) {394 if (!pimpl->serverService_) {
398 HILOGE("serverService_ is null");395 HILOGE("serverService_ is null");
@@ -411,10 +408,6 @@ int BluetoothGattServerServer::RespondCharacteristicWrite(
411 const BluetoothGattDevice &device, const BluetoothGattCharacteristic &characteristic, int32_t ret)408 const BluetoothGattDevice &device, const BluetoothGattCharacteristic &characteristic, int32_t ret)
412{409{
413 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);410 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);
414- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
415- HILOGE("check permission failed");
416- return BT_ERR_PERMISSION_FAILED;
417- }
418 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);411 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
419 if (!pimpl->serverService_) {412 if (!pimpl->serverService_) {
420 HILOGE("serverService_ is null");413 HILOGE("serverService_ is null");
@@ -430,10 +423,6 @@ int BluetoothGattServerServer::RespondDescriptorRead(
430 const BluetoothGattDevice &device, BluetoothGattDescriptor *descriptor, int32_t ret)423 const BluetoothGattDevice &device, BluetoothGattDescriptor *descriptor, int32_t ret)
431{424{
432 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);425 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);
433- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
434- HILOGE("check permission failed");
435- return BT_ERR_PERMISSION_FAILED;
436- }
437 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);426 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
438 if (!pimpl->serverService_) {427 if (!pimpl->serverService_) {
439 HILOGE("serverService_ is null");428 HILOGE("serverService_ is null");
@@ -452,10 +441,6 @@ int BluetoothGattServerServer::RespondDescriptorWrite(
452 const BluetoothGattDevice &device, const BluetoothGattDescriptor &descriptor, int32_t ret)441 const BluetoothGattDevice &device, const BluetoothGattDescriptor &descriptor, int32_t ret)
453{442{
454 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);443 HILOGI("addr: %{public}s, ret: %{public}d", GET_ENCRYPT_GATT_ADDR(device), ret);
455- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
456- HILOGE("check permission failed");
457- return BT_ERR_PERMISSION_FAILED;
458- }
459 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);444 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
460 if (!pimpl->serverService_) {445 if (!pimpl->serverService_) {
461 HILOGE("serverService_ is null");446 HILOGE("serverService_ is null");
@@ -497,10 +482,6 @@ int BluetoothGattServerServer::RegisterApplication(const sptr<IBluetoothGattServ
497int BluetoothGattServerServer::DeregisterApplication(int32_t appId)482int BluetoothGattServerServer::DeregisterApplication(int32_t appId)
498{483{
499 HILOGI("appId: %{public}d", appId);484 HILOGI("appId: %{public}d", appId);
500- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
501- HILOGE("check permission failed");
502- return BT_ERR_PERMISSION_FAILED;
503- }
504 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);485 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
505 if (!pimpl->serverService_) {486 if (!pimpl->serverService_) {
506 HILOGE("serverService_ is null");487 HILOGE("serverService_ is null");
Mservices/bluetooth/server/src/bluetooth_hfp_ag_server.cpp+5-33
@@ -26,7 +26,7 @@
26#include "interface_profile.h"26#include "interface_profile.h"
27#include "interface_adapter_manager.h"27#include "interface_adapter_manager.h"
28#include "remote_observer_list.h"28#include "remote_observer_list.h"
29-#include "permission_utils.h"29+#include "permission_manager.h"
30 30 
31 31 
32namespace OHOS {32namespace OHOS {
@@ -163,10 +163,6 @@ BluetoothHfpAgServer::~BluetoothHfpAgServer()
163int32_t BluetoothHfpAgServer::GetConnectDevices(std::vector<BluetoothRawAddress> &devices)163int32_t BluetoothHfpAgServer::GetConnectDevices(std::vector<BluetoothRawAddress> &devices)
164{164{
165 HILOGI("Enter!");165 HILOGI("Enter!");
166- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
167- HILOGE("GetConnectDevices() false, check permission failed");
168- return BT_ERR_PERMISSION_FAILED;
169- }
170 std::list<RawAddress> deviceList;166 std::list<RawAddress> deviceList;
171 if (pimpl->HfpAgService_ != nullptr) {167 if (pimpl->HfpAgService_ != nullptr) {
172 deviceList = pimpl->HfpAgService_->GetConnectDevices();168 deviceList = pimpl->HfpAgService_->GetConnectDevices();
@@ -200,10 +196,6 @@ int BluetoothHfpAgServer::GetDevicesByStates(const std::vector<int> &states, std
200 196 
201int32_t BluetoothHfpAgServer::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)197int32_t BluetoothHfpAgServer::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)
202{198{
203- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
204- HILOGE("GetDeviceState() false, check permission failed");
205- return BT_ERR_PERMISSION_FAILED;
206- }
207 RawAddress addr(device.GetAddress());199 RawAddress addr(device.GetAddress());
208 if (pimpl->HfpAgService_) {200 if (pimpl->HfpAgService_) {
209 state = pimpl->HfpAgService_->GetDeviceState(addr);201 state = pimpl->HfpAgService_->GetDeviceState(addr);
@@ -217,12 +209,8 @@ int32_t BluetoothHfpAgServer::GetDeviceState(const BluetoothRawAddress &device,
217int32_t BluetoothHfpAgServer::Connect(const BluetoothRawAddress &device)209int32_t BluetoothHfpAgServer::Connect(const BluetoothRawAddress &device)
218{210{
219 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));211 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));
220- if (!PermissionUtils::CheckSystemHapApp()) {212+ if (PermissionManager::GetApiVersion() >= API_VERSION_10 && !PermissionManager::IsSystemHap()) {
221- HILOGE("check system api failed.");213+ HILOGE("check permission failed, system hap need.");
222- return BT_ERR_SYSTEM_PERMISSION_FAILED;
223- }
224- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
225- HILOGE("Connect error, check permission failed");
226 return BT_ERR_PERMISSION_FAILED;214 return BT_ERR_PERMISSION_FAILED;
227 }215 }
228 RawAddress addr(device.GetAddress());216 RawAddress addr(device.GetAddress());
@@ -238,12 +226,8 @@ int32_t BluetoothHfpAgServer::Connect(const BluetoothRawAddress &device)
238int32_t BluetoothHfpAgServer::Disconnect(const BluetoothRawAddress &device)226int32_t BluetoothHfpAgServer::Disconnect(const BluetoothRawAddress &device)
239{227{
240 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));228 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));
241- if (!PermissionUtils::CheckSystemHapApp()) {229+ if (PermissionManager::GetApiVersion() >= API_VERSION_10 && !PermissionManager::IsSystemHap()) {
242- HILOGE("check system api failed.");230+ HILOGE("check permission failed, system hap need.");
243- return BT_ERR_SYSTEM_PERMISSION_FAILED;
244- }
245- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
246- HILOGE("Disconnect error, check permission failed");
247 return BT_ERR_PERMISSION_FAILED;231 return BT_ERR_PERMISSION_FAILED;
248 }232 }
249 RawAddress addr(device.GetAddress());233 RawAddress addr(device.GetAddress());
@@ -266,10 +250,6 @@ int BluetoothHfpAgServer::GetScoState(const BluetoothRawAddress &device)
266bool BluetoothHfpAgServer::ConnectSco()250bool BluetoothHfpAgServer::ConnectSco()
267{251{
268 HILOGI("Enter!");252 HILOGI("Enter!");
269- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
270- HILOGE("error, check permission failed");
271- return false;
272- }
273 if (pimpl->HfpAgService_ != nullptr) {253 if (pimpl->HfpAgService_ != nullptr) {
274 return pimpl->HfpAgService_->ConnectSco();254 return pimpl->HfpAgService_->ConnectSco();
275 }255 }
@@ -307,10 +287,6 @@ void BluetoothHfpAgServer::ClccResponse(int index, int direction, int status, in
307bool BluetoothHfpAgServer::OpenVoiceRecognition(const BluetoothRawAddress &device)287bool BluetoothHfpAgServer::OpenVoiceRecognition(const BluetoothRawAddress &device)
308{288{
309 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));289 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));
310- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
311- HILOGE("error, check permission failed");
312- return false;
313- }
314 RawAddress addr(device.GetAddress());290 RawAddress addr(device.GetAddress());
315 if (pimpl->HfpAgService_ != nullptr) {291 if (pimpl->HfpAgService_ != nullptr) {
316 return pimpl->HfpAgService_->OpenVoiceRecognition(addr);292 return pimpl->HfpAgService_->OpenVoiceRecognition(addr);
@@ -418,10 +394,6 @@ void BluetoothHfpAgServer::DeregisterObserver(const sptr<IBluetoothHfpAgObserver
418int BluetoothHfpAgServer::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)394int BluetoothHfpAgServer::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)
419{395{
420 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));396 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));
421- if (!PermissionUtils::CheckSystemHapApp()) {
422- HILOGE("check system api failed.");
423- return BT_ERR_SYSTEM_PERMISSION_FAILED;
424- }
425 return NO_ERROR;397 return NO_ERROR;
426}398}
427 399 
Mservices/bluetooth/server/src/bluetooth_hfp_hf_server.cpp+0-9
@@ -22,7 +22,6 @@
22#include "interface_profile_manager.h"22#include "interface_profile_manager.h"
23#include "interface_profile.h"23#include "interface_profile.h"
24#include "interface_adapter_manager.h"24#include "interface_adapter_manager.h"
25-#include "permission_utils.h"
26#include "remote_observer_list.h"25#include "remote_observer_list.h"
27 26 
28using namespace OHOS::bluetooth;27using namespace OHOS::bluetooth;
@@ -211,10 +210,6 @@ bool BluetoothHfpHfServer::DisconnectSco(const BluetoothRawAddress &device) {
211int BluetoothHfpHfServer::GetDevicesByStates(const std::vector<int> &states,210int BluetoothHfpHfServer::GetDevicesByStates(const std::vector<int> &states,
212 std::vector<BluetoothRawAddress> &devices) {211 std::vector<BluetoothRawAddress> &devices) {
213 HILOGI("Enter!");212 HILOGI("Enter!");
214- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
215- HILOGE("false, check permission failed");
216- return BT_FAILURE;
217- }
218 std::vector<int> tmpStates;213 std::vector<int> tmpStates;
219 for (int32_t state : states) {214 for (int32_t state : states) {
220 HILOGI("state = %{public}d", state);215 HILOGI("state = %{public}d", state);
@@ -235,10 +230,6 @@ int BluetoothHfpHfServer::GetDevicesByStates(const std::vector<int> &states,
235 230 
236int BluetoothHfpHfServer::GetDeviceState(const BluetoothRawAddress &device) {231int BluetoothHfpHfServer::GetDeviceState(const BluetoothRawAddress &device) {
237 HILOGI("addr: %{public}s", GetEncryptAddr((device).GetAddress()).c_str());232 HILOGI("addr: %{public}s", GetEncryptAddr((device).GetAddress()).c_str());
238- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
239- HILOGE("false, check permission failed");
240- return BT_FAILURE;
241- }
242 RawAddress addr(device.GetAddress());233 RawAddress addr(device.GetAddress());
243 if (pimpl->HfpHfService_ != nullptr) {234 if (pimpl->HfpHfService_ != nullptr) {
244 return pimpl->HfpHfService_->GetDeviceState(addr);235 return pimpl->HfpHfService_->GetDeviceState(addr);
Mservices/bluetooth/server/src/bluetooth_hid_host_server.cpp+0-45
@@ -20,7 +20,6 @@
20#include "interface_profile.h"20#include "interface_profile.h"
21#include "interface_profile_hid_host.h"21#include "interface_profile_hid_host.h"
22#include "i_bluetooth_host_observer.h"22#include "i_bluetooth_host_observer.h"
23-#include "permission_utils.h"
24#include "remote_observer_list.h"23#include "remote_observer_list.h"
25#include "hilog/log.h"24#include "hilog/log.h"
26#include "bluetooth_hid_host_server.h"25#include "bluetooth_hid_host_server.h"
@@ -191,10 +190,6 @@ int32_t BluetoothHidHostServer::GetDevicesByStates(
191 const std::vector<int32_t> &states, std::vector<BluetoothRawAddress>& result)190 const std::vector<int32_t> &states, std::vector<BluetoothRawAddress>& result)
192{191{
193 HILOGI("start");192 HILOGI("start");
194- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
195- HILOGE("check permission failed");
196- return BT_ERR_PERMISSION_FAILED;
197- }
198 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {193 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
199 HILOGI("hidHostService_ is null");194 HILOGI("hidHostService_ is null");
200 return BT_ERR_INTERNAL_ERROR;195 return BT_ERR_INTERNAL_ERROR;
@@ -212,10 +207,6 @@ int32_t BluetoothHidHostServer::GetDevicesByStates(
212int32_t BluetoothHidHostServer::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)207int32_t BluetoothHidHostServer::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)
213{208{
214 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));209 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));
215- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
216- HILOGE("check permission failed");
217- return BT_ERR_PERMISSION_FAILED;
218- }
219 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {210 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
220 HILOGI("hidHostService_ is null");211 HILOGI("hidHostService_ is null");
221 return BT_ERR_INTERNAL_ERROR;212 return BT_ERR_INTERNAL_ERROR;
@@ -228,14 +219,6 @@ int32_t BluetoothHidHostServer::GetDeviceState(const BluetoothRawAddress &device
228int32_t BluetoothHidHostServer::Connect(const BluetoothRawAddress &device)219int32_t BluetoothHidHostServer::Connect(const BluetoothRawAddress &device)
229{220{
230 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));221 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));
231- if (!PermissionUtils::CheckSystemHapApp()) {
232- HILOGE("check system api failed.");
233- return BT_ERR_SYSTEM_PERMISSION_FAILED;
234- }
235- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
236- HILOGE("check permission failed");
237- return BT_ERR_PERMISSION_FAILED;
238- }
239 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {222 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
240 HILOGE("hidHostService_ is null");223 HILOGE("hidHostService_ is null");
241 return BT_ERR_INTERNAL_ERROR;224 return BT_ERR_INTERNAL_ERROR;
@@ -246,14 +229,6 @@ int32_t BluetoothHidHostServer::Connect(const BluetoothRawAddress &device)
246int32_t BluetoothHidHostServer::Disconnect(const BluetoothRawAddress &device)229int32_t BluetoothHidHostServer::Disconnect(const BluetoothRawAddress &device)
247{230{
248 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));231 HILOGI("start, addr:%{public}s", GET_ENCRYPT_ADDR(device));
249- if (!PermissionUtils::CheckSystemHapApp()) {
250- HILOGE("check system api failed.");
251- return BT_ERR_SYSTEM_PERMISSION_FAILED;
252- }
253- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
254- HILOGE("check permission failed");
255- return BT_ERR_PERMISSION_FAILED;
256- }
257 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {232 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
258 HILOGI("hidHostService_ is null");233 HILOGI("hidHostService_ is null");
259 return BT_ERR_INTERNAL_ERROR;234 return BT_ERR_INTERNAL_ERROR;
@@ -265,10 +240,6 @@ ErrCode BluetoothHidHostServer::HidHostVCUnplug(std::string &device,
265 uint8_t &id, uint16_t &size, uint8_t &type, int& result)240 uint8_t &id, uint16_t &size, uint8_t &type, int& result)
266{241{
267 HILOGI("start");242 HILOGI("start");
268- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
269- HILOGE("check permission failed");
270- return ERR_PERMISSION_DENIED;
271- }
272 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {243 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
273 HILOGI("hidHostService_ is null");244 HILOGI("hidHostService_ is null");
274 return ERR_NO_INIT;245 return ERR_NO_INIT;
@@ -282,10 +253,6 @@ ErrCode BluetoothHidHostServer::HidHostSendData(std::string &device,
282 uint8_t &id, uint16_t &size, uint8_t &type, int& result)253 uint8_t &id, uint16_t &size, uint8_t &type, int& result)
283{254{
284 HILOGI("start");255 HILOGI("start");
285- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
286- HILOGE("check permission failed");
287- return ERR_PERMISSION_DENIED;
288- }
289 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {256 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
290 HILOGI("hidHostService_ is null");257 HILOGI("hidHostService_ is null");
291 return ERR_NO_INIT;258 return ERR_NO_INIT;
@@ -299,10 +266,6 @@ ErrCode BluetoothHidHostServer::HidHostSetReport(std::string &device,
299 uint8_t &type, std::string &report, int& result)266 uint8_t &type, std::string &report, int& result)
300{267{
301 HILOGI("start");268 HILOGI("start");
302- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
303- HILOGE("check permission failed");
304- return ERR_PERMISSION_DENIED;
305- }
306 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {269 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
307 HILOGI("hidHostService_ is null");270 HILOGI("hidHostService_ is null");
308 return ERR_NO_INIT;271 return ERR_NO_INIT;
@@ -321,10 +284,6 @@ ErrCode BluetoothHidHostServer::HidHostGetReport(std::string &device,
321 uint8_t &id, uint16_t &size, uint8_t &type, int& result)284 uint8_t &id, uint16_t &size, uint8_t &type, int& result)
322{285{
323 HILOGI("start");286 HILOGI("start");
324- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
325- HILOGE("check permission failed");
326- return ERR_PERMISSION_DENIED;
327- }
328 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {287 if (pimpl == nullptr || pimpl->hidHostService_ == nullptr) {
329 HILOGI("hidHostService_ is null");288 HILOGI("hidHostService_ is null");
330 return ERR_NO_INIT;289 return ERR_NO_INIT;
@@ -337,10 +296,6 @@ ErrCode BluetoothHidHostServer::HidHostGetReport(std::string &device,
337int32_t BluetoothHidHostServer::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)296int32_t BluetoothHidHostServer::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)
338{297{
339 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));298 HILOGI("target device:%{public}s()", GET_ENCRYPT_ADDR(device));
340- if (!PermissionUtils::CheckSystemHapApp()) {
341- HILOGE("check system api failed.");
342- return BT_ERR_SYSTEM_PERMISSION_FAILED;
343- }
344 return NO_ERROR;299 return NO_ERROR;
345}300}
346 301 
Mservices/bluetooth/server/src/bluetooth_host_server.cpp+87-162
@@ -36,7 +36,6 @@
36#include "dialog_switch.h"36#include "dialog_switch.h"
37#include "hisysevent.h"37#include "hisysevent.h"
38#include "interface_adapter_manager.h"38#include "interface_adapter_manager.h"
39-#include "permission_utils.h"
40#include "permission_manager.h"39#include "permission_manager.h"
41#include "bluetooth_host_server.h"40#include "bluetooth_host_server.h"
42 41 
@@ -201,7 +200,7 @@ public:
201 return;200 return;
202 }201 }
203 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());202 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
204- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {203+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId) == false) {
205 HILOGE("false, check permission failed");204 HILOGE("false, check permission failed");
206 } else {205 } else {
207 observer->OnStateChanged(transport, state);206 observer->OnStateChanged(transport, state);
@@ -221,8 +220,8 @@ public:
221 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);220 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
222 return;221 return;
223 }222 }
224- uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());223+ uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
225- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {224+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId) == false) {
226 HILOGE("false, check permission failed");225 HILOGE("false, check permission failed");
227 } else {226 } else {
228 observer->OnStateChanged(transport, state);227 observer->OnStateChanged(transport, state);
@@ -247,6 +246,23 @@ public:
247 AdapterClassicObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};246 AdapterClassicObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};
248 ~AdapterClassicObserver() override = default;247 ~AdapterClassicObserver() override = default;
249 248 
249+ bool CheckDiscoverOrAccessPermission(uint64_t tokenId)
250+ {
251+ if (PermissionManager::IsNativeCaller(tokenId) ||
252+ PermissionManager::GetApiVersion(tokenId) >= API_VERSION_10) {
253+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
254+ HILOGI("check ACCESS_BLUETOOTH permission failed");
255+ return false;
256+ }
257+ } else {
258+ if (!PermissionManager::VerifyPermission(DISCOVER_BLUETOOTH, tokenId)) {
259+ HILOGI("check DISCOVER_BLUETOOTH permission failed");
260+ return false;
261+ }
262+ }
263+ return true;
264+ }
265+ 
250 void OnDiscoveryStateChanged(const int32_t status) override266 void OnDiscoveryStateChanged(const int32_t status) override
251 {267 {
252 HILOGI("status: %{public}d", status);268 HILOGI("status: %{public}d", status);
@@ -278,11 +294,10 @@ public:
278 return;294 return;
279 }295 }
280 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());296 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
281- if (PermissionUtils::VerifyDiscoverBluetoothPermission(tokenId) == PERMISSION_DENIED) {297+ if (!CheckDiscoverOrAccessPermission(tokenId)) {
282- HILOGE("OnDiscoveryResult() false, check permission failed");298+ return;
283- } else {
284- observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
285 }299 }
300+ observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
286 });301 });
287 }302 }
288 303 
@@ -300,11 +315,10 @@ public:
300 GET_ENCRYPT_ADDR(device), reqType, number);315 GET_ENCRYPT_ADDR(device), reqType, number);
301 impl_->observers_.ForEach([this, transport, device, reqType, number](IBluetoothHostObserver *observer) {316 impl_->observers_.ForEach([this, transport, device, reqType, number](IBluetoothHostObserver *observer) {
302 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());317 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
303- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {318+ if (!CheckDiscoverOrAccessPermission(tokenId)) {
304- HILOGE("false, check permission failed");319+ return;
305- } else {
306- observer->OnPairConfirmed(transport, device, reqType, number);
307 }320 }
321+ observer->OnPairConfirmed(transport, device, reqType, number);
308 });322 });
309 }323 }
310 324 
@@ -337,6 +351,23 @@ public:
337 ClassicRemoteDeviceObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};351 ClassicRemoteDeviceObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};
338 ~ClassicRemoteDeviceObserver() override = default;352 ~ClassicRemoteDeviceObserver() override = default;
339 353 
354+ bool CheckDiscoverOrAccessPermission(uint64_t tokenId)
355+ {
356+ if (PermissionManager::IsNativeCaller(tokenId) ||
357+ PermissionManager::GetApiVersion(tokenId) >= API_VERSION_10) {
358+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
359+ HILOGI("check ACCESS_BLUETOOTH permission failed");
360+ return false;
361+ }
362+ } else {
363+ if (!PermissionManager::VerifyPermission(DISCOVER_BLUETOOTH, tokenId)) {
364+ HILOGI("check DISCOVER_BLUETOOTH permission failed");
365+ return false;
366+ }
367+ }
368+ return true;
369+ }
370+ 
340 void OnAclStateChanged(const RawAddress &device, int state, unsigned int reason) override371 void OnAclStateChanged(const RawAddress &device, int state, unsigned int reason) override
341 {372 {
342 return;373 return;
@@ -352,11 +383,10 @@ public:
352 return;383 return;
353 }384 }
354 uint32_t tokenId = this->impl_->remoteObserversToken_.ReadVal(observer->AsObject());385 uint32_t tokenId = this->impl_->remoteObserversToken_.ReadVal(observer->AsObject());
355- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {386+ if (!CheckDiscoverOrAccessPermission(tokenId)) {
356- HILOGE("false, check permission failed");387+ return;
357- } else {
358- observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);
359 }388 }
389+ observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);
360 });390 });
361 }391 }
362 392 
@@ -421,6 +451,23 @@ public:
421 AdapterBleObserver(BluetoothHostServer::impl *impl) : impl_(impl){};451 AdapterBleObserver(BluetoothHostServer::impl *impl) : impl_(impl){};
422 ~AdapterBleObserver() override = default;452 ~AdapterBleObserver() override = default;
423 453 
454+ bool CheckDiscoverOrAccessPermission(uint64_t tokenId)
455+ {
456+ if (PermissionManager::IsNativeCaller(tokenId) ||
457+ PermissionManager::GetApiVersion(tokenId) >= API_VERSION_10) {
458+ if (!PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId)) {
459+ HILOGI("check ACCESS_BLUETOOTH permission failed");
460+ return false;
461+ }
462+ } else {
463+ if (!PermissionManager::VerifyPermission(DISCOVER_BLUETOOTH, tokenId)) {
464+ HILOGI("check DISCOVER_BLUETOOTH permission failed");
465+ return false;
466+ }
467+ }
468+ return true;
469+ }
470+ 
424 void OnDiscoveryStateChanged(const int32_t status) override471 void OnDiscoveryStateChanged(const int32_t status) override
425 {472 {
426 HILOGI("status: %{public}d", status);473 HILOGI("status: %{public}d", status);
@@ -446,11 +493,10 @@ public:
446 return;493 return;
447 }494 }
448 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());495 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
449- if (PermissionUtils::VerifyDiscoverBluetoothPermission(tokenId) == PERMISSION_DENIED) {496+ if (!CheckDiscoverOrAccessPermission(tokenId)) {
450- HILOGE("false, check permission failed");497+ return;
451- } else {
452- observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
453 }498 }
499+ observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
454 });500 });
455 }501 }
456 502 
@@ -473,11 +519,10 @@ public:
473 return;519 return;
474 }520 }
475 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());521 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
476- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {522+ if (!CheckDiscoverOrAccessPermission(tokenId)) {
477- HILOGE("OnPairConfirmed() false, check permission failed");523+ return;
478- } else {
479- observer->OnPairConfirmed(transport, device, reqType, number);
480 }524 }
525+ observer->OnPairConfirmed(transport, device, reqType, number);
481 });526 });
482 }527 }
483 528 
@@ -528,7 +573,7 @@ public:
528 impl_->bleRemoteObservers_.ForEach([this, transport, device, status](573 impl_->bleRemoteObservers_.ForEach([this, transport, device, status](
529 IBluetoothBlePeripheralObserver *observer) {574 IBluetoothBlePeripheralObserver *observer) {
530 uint32_t tokenId = this->impl_->bleRemoteObserversToken_.ReadVal(observer->AsObject());575 uint32_t tokenId = this->impl_->bleRemoteObserversToken_.ReadVal(observer->AsObject());
531- if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {576+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH, tokenId) == false) {
532 HILOGE("false, check permission failed");577 HILOGE("false, check permission failed");
533 } else {578 } else {
534 observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);579 observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);
@@ -796,10 +841,6 @@ int32_t BluetoothHostServer::EnableBt()
796int32_t BluetoothHostServer::DisableBt(bool isAsync, const std::string &callingName)841int32_t BluetoothHostServer::DisableBt(bool isAsync, const std::string &callingName)
797{842{
798 (void)(callingName);843 (void)(callingName);
799- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
800- HILOGE("false, check Access permission failed");
801- return BT_ERR_PERMISSION_FAILED;
802- }
803 if (isAsync) {844 if (isAsync) {
804 return BT_ERR_API_NOT_SUPPORT;845 return BT_ERR_API_NOT_SUPPORT;
805 }846 }
@@ -883,14 +924,6 @@ int32_t BluetoothHostServer::GetDeviceType(int32_t transport, const std::string
883int32_t BluetoothHostServer::GetLocalAddress(std::string &addr)924int32_t BluetoothHostServer::GetLocalAddress(std::string &addr)
884{925{
885 HILOGI("Enter!");926 HILOGI("Enter!");
886- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
887- HILOGE("false, check Access permission failed");
888- return BT_ERR_PERMISSION_FAILED;
889- }
890- if (PermissionUtils::VerifyGetBluetoothLocalMacPermission() == PERMISSION_DENIED) {
891- HILOGE("false, check GetLocalMac permission failed");
892- return BT_ERR_PERMISSION_FAILED;
893- }
894 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();927 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
895 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();928 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
896 if (IsBtEnabled() && classicService) {929 if (IsBtEnabled() && classicService) {
@@ -914,10 +947,6 @@ int32_t BluetoothHostServer::EnableBle(bool noAutoConnect, bool isAsync, const s
914{947{
915 HILOGI("Enter!");948 HILOGI("Enter!");
916 (void)(callingName);949 (void)(callingName);
917- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
918- HILOGE("false, check Access permission failed");
919- return BT_ERR_PERMISSION_FAILED;
920- }
921 if (isAsync) {950 if (isAsync) {
922 return BT_ERR_API_NOT_SUPPORT;951 return BT_ERR_API_NOT_SUPPORT;
923 }952 }
@@ -960,10 +989,6 @@ int32_t BluetoothHostServer::GetMaxNumConnectedAudioDevices()
960 989 
961int32_t BluetoothHostServer::GetBtConnectionState(int32_t &state)990int32_t BluetoothHostServer::GetBtConnectionState(int32_t &state)
962{991{
963- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
964- HILOGE("false, check permission failed");
965- return BT_ERR_PERMISSION_FAILED;
966- }
967 if (IsBtEnabled()) {992 if (IsBtEnabled()) {
968 state = (int32_t)IAdapterManager::GetInstance()->GetAdapterConnectState();993 state = (int32_t)IAdapterManager::GetInstance()->GetAdapterConnectState();
969 HILOGI("state: %{public}d", state);994 HILOGI("state: %{public}d", state);
@@ -977,10 +1002,6 @@ int32_t BluetoothHostServer::GetBtConnectionState(int32_t &state)
977int32_t BluetoothHostServer::GetBtProfileConnState(uint32_t profileId, int &state)1002int32_t BluetoothHostServer::GetBtProfileConnState(uint32_t profileId, int &state)
978{1003{
979 HILOGI("Enter!");1004 HILOGI("Enter!");
980- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
981- HILOGE("false, check permission failed");
982- return BT_ERR_PERMISSION_FAILED;
983- }
984 if (IsBtEnabled()) {1005 if (IsBtEnabled()) {
985 state = (int32_t)IProfileManager::GetInstance()->GetProfileServiceConnectState(profileId);1006 state = (int32_t)IProfileManager::GetInstance()->GetProfileServiceConnectState(profileId);
986 return NO_ERROR;1007 return NO_ERROR;
@@ -1023,10 +1044,6 @@ bool BluetoothHostServer::SetLocalDeviceClass(const int32_t &deviceClass)
1023int32_t BluetoothHostServer::GetLocalName(std::string &name)1044int32_t BluetoothHostServer::GetLocalName(std::string &name)
1024{1045{
1025 HILOGI("Enter!");1046 HILOGI("Enter!");
1026- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1027- HILOGE("false, check permission failed");
1028- return BT_ERR_PERMISSION_FAILED;
1029- }
1030 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1047 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1031 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1048 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1032 if (IsBtEnabled() && classicService) {1049 if (IsBtEnabled() && classicService) {
@@ -1044,14 +1061,9 @@ int32_t BluetoothHostServer::GetLocalName(std::string &name)
1044int32_t BluetoothHostServer::SetLocalName(const std::string &name)1061int32_t BluetoothHostServer::SetLocalName(const std::string &name)
1045{1062{
1046 HILOGI("name: %{public}s", name.c_str());1063 HILOGI("name: %{public}s", name.c_str());
1047- int api12 = 12;1064+ if (!PermissionManager::IsSystemHap() && PermissionManager::GetApiVersion() >= API_VERSION_12) {
1048- if (!PermissionUtils::CheckSystemHapApp() && PermissionUtils::GetApiVersion() >= api12) {
1049 return BT_ERR_API_NOT_SUPPORT;1065 return BT_ERR_API_NOT_SUPPORT;
1050 }1066 }
1051- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1052- HILOGE("false, check permission failed");
1053- return BT_ERR_PERMISSION_FAILED;
1054- }
1055 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1067 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1056 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1068 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1057 if (IsBtEnabled() && classicService) {1069 if (IsBtEnabled() && classicService) {
@@ -1078,10 +1090,6 @@ int32_t BluetoothHostServer::SetLocalName(const std::string &name)
1078int32_t BluetoothHostServer::GetBtScanMode(int32_t &scanMode)1090int32_t BluetoothHostServer::GetBtScanMode(int32_t &scanMode)
1079{1091{
1080 HILOGI("Enter!");1092 HILOGI("Enter!");
1081- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1082- HILOGE("false, check permission failed");
1083- return BT_ERR_PERMISSION_FAILED;
1084- }
1085 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1093 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1086 if (IsBtEnabled() && classicService) {1094 if (IsBtEnabled() && classicService) {
1087 scanMode = classicService->GetBtScanMode();1095 scanMode = classicService->GetBtScanMode();
@@ -1095,10 +1103,6 @@ int32_t BluetoothHostServer::GetBtScanMode(int32_t &scanMode)
1095int32_t BluetoothHostServer::SetBtScanMode(int32_t mode, int32_t duration)1103int32_t BluetoothHostServer::SetBtScanMode(int32_t mode, int32_t duration)
1096{1104{
1097 HILOGI("mode: %{public}d, duration: %{public}d", mode, duration);1105 HILOGI("mode: %{public}d, duration: %{public}d", mode, duration);
1098- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1099- HILOGE("false, check permission failed");
1100- return BT_ERR_PERMISSION_FAILED;
1101- }
1102 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1106 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1103 if (IsBtEnabled() && classicService) {1107 if (IsBtEnabled() && classicService) {
1104 if (classicService->SetBtScanMode(mode, duration)) {1108 if (classicService->SetBtScanMode(mode, duration)) {
@@ -1144,14 +1148,22 @@ bool BluetoothHostServer::SetBondableMode(int32_t transport, int32_t mode)
1144int32_t BluetoothHostServer::StartBtDiscovery()1148int32_t BluetoothHostServer::StartBtDiscovery()
1145{1149{
1146 HILOGI("Enter!");1150 HILOGI("Enter!");
1147- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {1151+ if (PermissionManager::IsNativeCaller()||PermissionManager::GetApiVersion() >= API_VERSION_10) {
1148- HILOGE("false, check permission failed");1152+ if (PermissionManager::VerifyPermission(ACCESS_BLUETOOTH) == false) {
1149- return BT_ERR_PERMISSION_FAILED;1153+ HILOGE("check access permission failed.");
1150- }1154+ return BT_ERR_PERMISSION_FAILED;
1151- if (PermissionUtils::VerifyApproximatelyPermission() == PERMISSION_DENIED &&1155+ }
1152- PermissionUtils::VerifyLocationPermission() == PERMISSION_DENIED) {1156+ } else {
1153- HILOGE("No location permission");1157+ if (PermissionManager::VerifyPermission(DISCOVER_BLUETOOTH) == false ||
1154- return BT_ERR_PERMISSION_FAILED;1158+ PermissionManager::VerifyPermission(MANAGE_BLUETOOTH) == false) {
1159+ HILOGE("check permission failed.");
1160+ return BT_ERR_PERMISSION_FAILED;
1161+ }
1162+ if (PermissionManager::VerifyPermission(APPROXIMATELY_LOCATION) == false &&
1163+ PermissionManager::VerifyPermission(LOCATION) == false) {
1164+ HILOGE("No location permission");
1165+ return BT_ERR_PERMISSION_FAILED;
1166+ }
1155 }1167 }
1156 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1168 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1157 if (IsBtEnabled() && classicService) {1169 if (IsBtEnabled() && classicService) {
@@ -1168,10 +1180,6 @@ int32_t BluetoothHostServer::StartBtDiscovery()
1168int32_t BluetoothHostServer::CancelBtDiscovery()1180int32_t BluetoothHostServer::CancelBtDiscovery()
1169{1181{
1170 HILOGI("Enter!");1182 HILOGI("Enter!");
1171- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1172- HILOGE("false, check permission failed");
1173- return BT_ERR_PERMISSION_FAILED;
1174- }
1175 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1183 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1176 if (IsBtEnabled() && classicService) {1184 if (IsBtEnabled() && classicService) {
1177 if (classicService->CancelBtDiscovery()) {1185 if (classicService->CancelBtDiscovery()) {
@@ -1187,10 +1195,6 @@ int32_t BluetoothHostServer::CancelBtDiscovery()
1187int32_t BluetoothHostServer::IsBtDiscovering(bool &isDisCovering, int32_t transport)1195int32_t BluetoothHostServer::IsBtDiscovering(bool &isDisCovering, int32_t transport)
1188{1196{
1189 HILOGI("transport: %{public}d", transport);1197 HILOGI("transport: %{public}d", transport);
1190- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1191- HILOGE("false, check permission failed");
1192- return BT_ERR_PERMISSION_FAILED;
1193- }
1194 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1198 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1195 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1199 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1196 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {1200 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
@@ -1219,17 +1223,6 @@ long BluetoothHostServer::GetBtDiscoveryEndMillis()
1219int32_t BluetoothHostServer::GetPairedDevices(std::vector<BluetoothRawAddress> &pairedAddr)1223int32_t BluetoothHostServer::GetPairedDevices(std::vector<BluetoothRawAddress> &pairedAddr)
1220{1224{
1221 HILOGI("GetPairedDevices");1225 HILOGI("GetPairedDevices");
1222- if (PermissionUtils::GetApiVersion() >= 10) { // 10:api version
1223- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1224- HILOGE("false, check Access permission failed");
1225- return BT_ERR_PERMISSION_FAILED;
1226- }
1227- } else {
1228- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1229- HILOGE("false, check permission failed");
1230- return BT_ERR_SYSTEM_PERMISSION_FAILED;
1231- }
1232- }
1233 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1226 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1234 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1227 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1235 std::vector<RawAddress> rawAddrVec;1228 std::vector<RawAddress> rawAddrVec;
@@ -1277,14 +1270,6 @@ int32_t BluetoothHostServer::RemovePair(int32_t transport, const sptr<BluetoothR
1277 return BT_ERR_INTERNAL_ERROR;1270 return BT_ERR_INTERNAL_ERROR;
1278 }1271 }
1279 HILOGI("addr:%{public}s, transport:%{public}d", GET_ENCRYPT_ADDR(*device), transport);1272 HILOGI("addr:%{public}s, transport:%{public}d", GET_ENCRYPT_ADDR(*device), transport);
1280- if (!PermissionUtils::CheckSystemHapApp()) {
1281- HILOGE("check system api failed.");
1282- return BT_ERR_SYSTEM_PERMISSION_FAILED;
1283- }
1284- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1285- HILOGE("check permission failed.");
1286- return BT_ERR_PERMISSION_FAILED;
1287- }
1288 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1273 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1289 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1274 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1290 transport = GetTransportByDeviceType(transport, device->GetAddress());1275 transport = GetTransportByDeviceType(transport, device->GetAddress());
@@ -1306,10 +1291,6 @@ int32_t BluetoothHostServer::RemovePair(int32_t transport, const sptr<BluetoothR
1306bool BluetoothHostServer::RemoveAllPairs()1291bool BluetoothHostServer::RemoveAllPairs()
1307{1292{
1308 HILOGI("Enter!");1293 HILOGI("Enter!");
1309- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1310- HILOGE("check permission failed");
1311- return false;
1312- }
1313 if (BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BREDR) &&1294 if (BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BREDR) &&
1314 BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BLE)) {1295 BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BLE)) {
1315 HILOGW("BT current state is not enabled!");1296 HILOGW("BT current state is not enabled!");
@@ -1379,10 +1360,6 @@ int32_t BluetoothHostServer::GetPowerMode(const std::string &address)
1379 1360 
1380int32_t BluetoothHostServer::GetDeviceName(int32_t transport, const std::string &address, std::string &name, bool alias)1361int32_t BluetoothHostServer::GetDeviceName(int32_t transport, const std::string &address, std::string &name, bool alias)
1381{1362{
1382- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1383- HILOGE("false, check permission failed");
1384- return BT_ERR_PERMISSION_FAILED;
1385- }
1386 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1363 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1387 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1364 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1388 RawAddress addr(address);1365 RawAddress addr(address);
@@ -1402,10 +1379,6 @@ int32_t BluetoothHostServer::GetDeviceName(int32_t transport, const std::string
1402std::string BluetoothHostServer::GetDeviceAlias(const std::string &address)1379std::string BluetoothHostServer::GetDeviceAlias(const std::string &address)
1403{1380{
1404 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());1381 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1405- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1406- HILOGE("false, check permission failed");
1407- return INVALID_NAME;
1408- }
1409 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1382 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1410 if (IsBtEnabled() && classicService) {1383 if (IsBtEnabled() && classicService) {
1411 RawAddress addr(address);1384 RawAddress addr(address);
@@ -1419,10 +1392,6 @@ std::string BluetoothHostServer::GetDeviceAlias(const std::string &address)
1419int32_t BluetoothHostServer::SetDeviceAlias(const std::string &address, const std::string &aliasName)1392int32_t BluetoothHostServer::SetDeviceAlias(const std::string &address, const std::string &aliasName)
1420{1393{
1421 HILOGI("address: %{public}s, aliasName: %{public}s", GetEncryptAddr(address).c_str(), aliasName.c_str());1394 HILOGI("address: %{public}s, aliasName: %{public}s", GetEncryptAddr(address).c_str(), aliasName.c_str());
1422- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1423- HILOGE("false, check permission failed");
1424- return BT_ERR_PERMISSION_FAILED;
1425- }
1426 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1395 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1427 if (IsBtEnabled() && classicService) {1396 if (IsBtEnabled() && classicService) {
1428 RawAddress addr(address);1397 RawAddress addr(address);
@@ -1447,10 +1416,6 @@ int32_t BluetoothHostServer::IsProfileExist(const std::string &profileName, bool
1447int32_t BluetoothHostServer::GetRemoteDeviceBatteryInfo(const std::string &address,1416int32_t BluetoothHostServer::GetRemoteDeviceBatteryInfo(const std::string &address,
1448 BluetoothBatteryInfo &batteryInfo)1417 BluetoothBatteryInfo &batteryInfo)
1449{1418{
1450- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1451- HILOGE("false, check Access permission failed");
1452- return BT_ERR_PERMISSION_FAILED;
1453- }
1454 return BT_ERR_INTERNAL_ERROR;1419 return BT_ERR_INTERNAL_ERROR;
1455}1420}
1456 1421 
@@ -1463,10 +1428,6 @@ int32_t BluetoothHostServer::SetRemoteDeviceBatteryInfo(const std::string &addre
1463int32_t BluetoothHostServer::GetPairState(int32_t transport, const std::string &address, int32_t &pairState)1428int32_t BluetoothHostServer::GetPairState(int32_t transport, const std::string &address, int32_t &pairState)
1464{1429{
1465 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());1430 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1466- if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1467- HILOGE("false, check Access permission failed");
1468- return BT_ERR_PERMISSION_FAILED;
1469- }
1470 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1431 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1471 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1432 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1472 RawAddress addr(address);1433 RawAddress addr(address);
@@ -1489,10 +1450,6 @@ int32_t BluetoothHostServer::StartPair(int32_t transport, const BluetoothRawAddr
1489 }1450 }
1490 std::string address = bluetoothRawAddress.GetAddress();1451 std::string address = bluetoothRawAddress.GetAddress();
1491 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());1452 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1492- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1493- HILOGE("StartPair false, check permission failed");
1494- return BT_ERR_PERMISSION_FAILED;
1495- }
1496 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1453 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1497 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1454 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1498 RawAddress addr(address);1455 RawAddress addr(address);
@@ -1515,14 +1472,6 @@ int32_t BluetoothHostServer::StartPair(int32_t transport, const BluetoothRawAddr
1515bool BluetoothHostServer::CancelPairing(int32_t transport, const std::string &address)1472bool BluetoothHostServer::CancelPairing(int32_t transport, const std::string &address)
1516{1473{
1517 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());1474 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1518- if (!PermissionUtils::CheckSystemHapApp()) {
1519- HILOGE("check system api failed.");
1520- return BT_ERR_SYSTEM_PERMISSION_FAILED;
1521- }
1522- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1523- HILOGE("false, check permission failed");
1524- return false;
1525- }
1526 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1475 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1527 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1476 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1528 RawAddress addr(address);1477 RawAddress addr(address);
@@ -1588,10 +1537,6 @@ bool BluetoothHostServer::IsAclEncrypted(int32_t transport, const std::string &a
1588int32_t BluetoothHostServer::GetDeviceClass(const std::string &address, int32_t &cod)1537int32_t BluetoothHostServer::GetDeviceClass(const std::string &address, int32_t &cod)
1589{1538{
1590 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());1539 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1591- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1592- HILOGE("false, check permission failed");
1593- return BT_ERR_PERMISSION_FAILED;
1594- }
1595 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1540 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1596 if (IsBtEnabled() && classicService) {1541 if (IsBtEnabled() && classicService) {
1597 RawAddress addr(address);1542 RawAddress addr(address);
@@ -1635,10 +1580,6 @@ int32_t BluetoothHostServer::GetLocalProfileUuids(std::vector<std::string> &uuid
1635int32_t BluetoothHostServer::SetDevicePin(const std::string &address, const std::string &pin)1580int32_t BluetoothHostServer::SetDevicePin(const std::string &address, const std::string &pin)
1636{1581{
1637 HILOGI("address: %{public}s, pin: %{public}s", GetEncryptAddr(address).c_str(), pin.c_str());1582 HILOGI("address: %{public}s, pin: %{public}s", GetEncryptAddr(address).c_str(), pin.c_str());
1638- if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1639- HILOGE("false, check permission failed");
1640- return BT_ERR_PERMISSION_FAILED;
1641- }
1642 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1583 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1643 if (IsBtEnabled() && classicService) {1584 if (IsBtEnabled() && classicService) {
1644 RawAddress addr(address);1585 RawAddress addr(address);
@@ -1656,10 +1597,6 @@ int32_t BluetoothHostServer::SetDevicePairingConfirmation(int32_t transport, con
1656{1597{
1657 HILOGI("transport: %{public}d, address: %{public}s, accept: %{public}d",1598 HILOGI("transport: %{public}d, address: %{public}s, accept: %{public}d",
1658 transport, GetEncryptAddr(address).c_str(), accept);1599 transport, GetEncryptAddr(address).c_str(), accept);
1659- if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1660- HILOGE("false, check permission failed");
1661- return BT_ERR_PERMISSION_FAILED;
1662- }
1663 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1600 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1664 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1601 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1665 RawAddress addr(address);1602 RawAddress addr(address);
@@ -1683,10 +1620,6 @@ bool BluetoothHostServer::SetDevicePasskey(int32_t transport, const std::string
1683{1620{
1684 HILOGI("transport: %{public}d, address: %{public}s, passkey: %{public}d, accept: %{public}d",1621 HILOGI("transport: %{public}d, address: %{public}s, passkey: %{public}d, accept: %{public}d",
1685 transport, GetEncryptAddr(address).c_str(), passkey, accept);1622 transport, GetEncryptAddr(address).c_str(), passkey, accept);
1686- if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1687- HILOGE("false, check permission failed");
1688- return false;
1689- }
1690 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();1623 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1691 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1624 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1692 RawAddress addr(address);1625 RawAddress addr(address);
@@ -1720,10 +1653,6 @@ bool BluetoothHostServer::PairRequestReply(int32_t transport, const std::string
1720bool BluetoothHostServer::ReadRemoteRssiValue(const std::string &address)1653bool BluetoothHostServer::ReadRemoteRssiValue(const std::string &address)
1721{1654{
1722 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());1655 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1723- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1724- HILOGE("false, check permission failed");
1725- return false;
1726- }
1727 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();1656 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1728 if (IsBleEnabled() && bleService) {1657 if (IsBleEnabled() && bleService) {
1729 RawAddress addr(address);1658 RawAddress addr(address);
@@ -1887,10 +1816,6 @@ int32_t BluetoothHostServer::SyncRandomAddress(const std::string &realAddr, cons
1887 1816 
1888int32_t BluetoothHostServer::StartCrediblePair(int32_t transport, const std::string &address)1817int32_t BluetoothHostServer::StartCrediblePair(int32_t transport, const std::string &address)
1889{1818{
1890- if (!PermissionUtils::CheckSystemHapApp()) {
1891- HILOGE("check system api failed.");
1892- return BT_ERR_SYSTEM_PERMISSION_FAILED;
1893- }
1894 return NO_ERROR;1819 return NO_ERROR;
1895}1820}
1896 1821 
Mservices/bluetooth/server/src/bluetooth_pan_server.cpp+0-21
@@ -20,7 +20,6 @@
20#include "interface_profile.h"20#include "interface_profile.h"
21#include "interface_profile_pan.h"21#include "interface_profile_pan.h"
22#include "i_bluetooth_host_observer.h"22#include "i_bluetooth_host_observer.h"
23-#include "permission_utils.h"
24#include "remote_observer_list.h"23#include "remote_observer_list.h"
25#include "hilog/log.h"24#include "hilog/log.h"
26 25 
@@ -205,14 +204,6 @@ int32_t BluetoothPanServer::GetDeviceState(const BluetoothRawAddress &device, in
205int32_t BluetoothPanServer::Disconnect(const BluetoothRawAddress &device)204int32_t BluetoothPanServer::Disconnect(const BluetoothRawAddress &device)
206{205{
207 HILOGI("addr:%{public}s", GET_ENCRYPT_ADDR(device));206 HILOGI("addr:%{public}s", GET_ENCRYPT_ADDR(device));
208- if (!PermissionUtils::CheckSystemHapApp()) {
209- HILOGE("check system api failed.");
210- return BT_ERR_SYSTEM_PERMISSION_FAILED;
211- }
212- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
213- HILOGE("check permission failed");
214- return BT_ERR_PERMISSION_FAILED;
215- }
216 if (pimpl == nullptr || pimpl->panService_ == nullptr) {207 if (pimpl == nullptr || pimpl->panService_ == nullptr) {
217 HILOGI("not init.");208 HILOGI("not init.");
218 return BT_ERR_INTERNAL_ERROR;209 return BT_ERR_INTERNAL_ERROR;
@@ -223,14 +214,6 @@ int32_t BluetoothPanServer::Disconnect(const BluetoothRawAddress &device)
223int32_t BluetoothPanServer::SetTethering(const bool enable)214int32_t BluetoothPanServer::SetTethering(const bool enable)
224{215{
225 HILOGI("enable:%{public}d", enable);216 HILOGI("enable:%{public}d", enable);
226- if (!PermissionUtils::CheckSystemHapApp()) {
227- HILOGE("check system api failed.");
228- return BT_ERR_SYSTEM_PERMISSION_FAILED;
229- }
230- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
231- HILOGE("check permission failed");
232- return BT_ERR_PERMISSION_FAILED;
233- }
234 if (pimpl == nullptr || pimpl->panService_ == nullptr) {217 if (pimpl == nullptr || pimpl->panService_ == nullptr) {
235 HILOGI("not init.");218 HILOGI("not init.");
236 return BT_ERR_INTERNAL_ERROR;219 return BT_ERR_INTERNAL_ERROR;
@@ -240,10 +223,6 @@ int32_t BluetoothPanServer::SetTethering(const bool enable)
240 223 
241int32_t BluetoothPanServer::IsTetheringOn(bool& result)224int32_t BluetoothPanServer::IsTetheringOn(bool& result)
242{225{
243- if (!PermissionUtils::CheckSystemHapApp()) {
244- HILOGE("check system api failed.");
245- return BT_ERR_SYSTEM_PERMISSION_FAILED;
246- }
247 if (pimpl == nullptr || pimpl->panService_ == nullptr) {226 if (pimpl == nullptr || pimpl->panService_ == nullptr) {
248 HILOGI("not init.");227 HILOGI("not init.");
249 return BT_ERR_INTERNAL_ERROR;228 return BT_ERR_INTERNAL_ERROR;
Mservices/bluetooth/server/src/bluetooth_socket_server.cpp+3-10
@@ -19,7 +19,6 @@
19#include "bt_def.h"19#include "bt_def.h"
20#include "interface_profile_manager.h"20#include "interface_profile_manager.h"
21#include "interface_profile_socket.h"21#include "interface_profile_socket.h"
22-#include "permission_utils.h"
23#include "bluetooth_socket_server.h"22#include "bluetooth_socket_server.h"
24 23 
25using namespace OHOS::bluetooth;24using namespace OHOS::bluetooth;
@@ -28,10 +27,6 @@ namespace OHOS {
28namespace Bluetooth {27namespace Bluetooth {
29int BluetoothSocketServer::Connect(ConnectSocketParam &param, int &fd)28int BluetoothSocketServer::Connect(ConnectSocketParam &param, int &fd)
30{29{
31- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
32- HILOGE("false, check permission failed");
33- return BT_ERR_INTERNAL_ERROR;
34- }
35 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);30 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);
36 if (socket != nullptr) {31 if (socket != nullptr) {
37 fd = socket->Connect(param.addr, param.uuid, (int)param.securityFlag, (int)param.type);32 fd = socket->Connect(param.addr, param.uuid, (int)param.securityFlag, (int)param.type);
@@ -42,11 +37,6 @@ int BluetoothSocketServer::Connect(ConnectSocketParam &param, int &fd)
42 37 
43int BluetoothSocketServer::Listen(ListenSocketParam &param, int &fd)38int BluetoothSocketServer::Listen(ListenSocketParam &param, int &fd)
44{39{
45- if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
46- HILOGE("false, check permission failed");
47- return BT_ERR_PERMISSION_FAILED;
48- }
49- 
50 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);40 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);
51 if (socket != nullptr) {41 if (socket != nullptr) {
52 fd = socket->Listen(param.name, param.uuid, (int)param.securityFlag, (int)param.type);42 fd = socket->Listen(param.name, param.uuid, (int)param.securityFlag, (int)param.type);
@@ -68,6 +58,9 @@ int BluetoothSocketServer::DeregisterServerObserver(const sptr<IBluetoothServerS
68int BluetoothSocketServer::RegisterClientObserver(const BluetoothRawAddress &addr, const bluetooth::Uuid uuid,58int BluetoothSocketServer::RegisterClientObserver(const BluetoothRawAddress &addr, const bluetooth::Uuid uuid,
69 const sptr<IBluetoothClientSocketObserver> &observer)59 const sptr<IBluetoothClientSocketObserver> &observer)
70{60{
61+ if (!IsValidAddress(addr.GetAddress())) {
62+ return BT_ERR_INTERNAL_ERROR;
63+ }
71 return BT_ERR_API_NOT_SUPPORT;64 return BT_ERR_API_NOT_SUPPORT;
72}65}
73 66 
Mservices/bluetooth/server/src/bluetooth_utils_server.cpp+25-0
@@ -37,6 +37,31 @@ std::string GetEncryptAddr(std::string addr)
37 return out;37 return out;
38}38}
39 39 
40+bool IsValidAddress(const std::string &addr)
41+{
42+ if (addr.empty() || addr.length() != ADDRESS_LENGTH) {
43+ return false;
44+ }
45+ for (size_t i = 0; i < ADDRESS_LENGTH; i++) {
46+ char c = addr[i];
47+ switch (i % ADDRESS_SEPARATOR_UNIT) {
48+ case 0:
49+ case 1:
50+ if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
51+ break;
52+ }
53+ return false;
54+ case ADDRESS_COLON_INDEX:
55+ default:
56+ if (c == ':') {
57+ break;
58+ }
59+ return false;
60+ }
61+ }
62+ return true;
63+}
64+ 
40std::string GetScanModeName(int mode)65std::string GetScanModeName(int mode)
41{66{
42 switch (mode) {67 switch (mode) {
Mservices/bluetooth/service/BUILD.gn+1-3
@@ -150,10 +150,8 @@ ServiceUtilSrc = [
150]150]
151 151 
152ServicePermissionSrc = [152ServicePermissionSrc = [
153- "src/permission/auth_center.cpp",153+ "src/permission/permission_item.cpp",
154- "src/permission/permission_helper.cpp",
155 "src/permission/permission_manager.cpp",154 "src/permission/permission_manager.cpp",
156- "src/permission/permission_utils.cpp",
157]155]
158 156 
159config("btservice_public_config") {157config("btservice_public_config") {
Mservices/bluetooth/service/src/common/adapter_manager.cpp+1-12
@@ -34,7 +34,6 @@
34#include "class_creator.h"34#include "class_creator.h"
35#include "foundation/communication/bluetooth_service/services/bluetooth/service/src/dialog/dialog_switch.h"35#include "foundation/communication/bluetooth_service/services/bluetooth/service/src/dialog/dialog_switch.h"
36#include "interface_adapter_classic.h"36#include "interface_adapter_classic.h"
37-#include "permission_utils.h"
38#include "permission_manager.h"37#include "permission_manager.h"
39#include "power_manager.h"38#include "power_manager.h"
40#include "profile_config.h"39#include "profile_config.h"
@@ -353,11 +352,6 @@ bool AdapterManager::Enable(const BTTransport transport) const
353 std::lock_guard<std::recursive_mutex> lock(pimpl->syncMutex_);352 std::lock_guard<std::recursive_mutex> lock(pimpl->syncMutex_);
354 std::string propertynames[] = {PROPERTY_BREDR_TURNON, PROPERTY_BLE_TURNON};353 std::string propertynames[] = {PROPERTY_BREDR_TURNON, PROPERTY_BLE_TURNON};
355 354 
356- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
357- LOG_ERROR("Enable() false, check permission failed");
358- return false;
359- }
360- 
361 if (GetSysState() != SYS_STATE_STARTED) {355 if (GetSysState() != SYS_STATE_STARTED) {
362 LOG_ERROR("AdapterManager system is stoped");356 LOG_ERROR("AdapterManager system is stoped");
363 return false;357 return false;
@@ -370,7 +364,7 @@ bool AdapterManager::Enable(const BTTransport transport) const
370 }364 }
371 365 
372 if (GetState(transport) == BTStateID::STATE_TURN_OFF) {366 if (GetState(transport) == BTStateID::STATE_TURN_OFF) {
373- if (!PermissionManager::IsSystemHap() && transport == ADAPTER_BLE &&367+ if (!Bluetooth::PermissionManager::IsSystemHap() && transport == ADAPTER_BLE &&
374 DialogSwitch::RequestBluetoothSwitchDialog(ENABLE_BLUETOOTH)) {368 DialogSwitch::RequestBluetoothSwitchDialog(ENABLE_BLUETOOTH)) {
375 return true;369 return true;
376 }370 }
@@ -396,11 +390,6 @@ bool AdapterManager::Disable(const BTTransport transport) const
396 std::lock_guard<std::recursive_mutex> lock(pimpl->syncMutex_);390 std::lock_guard<std::recursive_mutex> lock(pimpl->syncMutex_);
397 std::string propertynames[] = {PROPERTY_BREDR_TURNON, PROPERTY_BLE_TURNON};391 std::string propertynames[] = {PROPERTY_BREDR_TURNON, PROPERTY_BLE_TURNON};
398 392 
399- if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
400- LOG_ERROR("Disable() false, check permission failed");
401- return false;
402- }
403- 
404 if ((transport == ADAPTER_BREDR && pimpl->classicAdapter_ == nullptr) ||393 if ((transport == ADAPTER_BREDR && pimpl->classicAdapter_ == nullptr) ||
405 (transport == ADAPTER_BLE && pimpl->bleAdapter_ == nullptr)) {394 (transport == ADAPTER_BLE && pimpl->bleAdapter_ == nullptr)) {
406 LOG_INFO("%{public}s BTTransport not register", __PRETTY_FUNCTION__);395 LOG_INFO("%{public}s BTTransport not register", __PRETTY_FUNCTION__);
Mservices/bluetooth/service/src/dialog/dialog_switch.cpp+1-1
@@ -43,7 +43,7 @@ bool DialogSwitch::RequestBluetoothSwitchDialog(DialogSwitchType type)
43{43{
44 const std::string abilityName = "bluetooth";44 const std::string abilityName = "bluetooth";
45 const std::string bundleName = "com.ohos.settings";45 const std::string bundleName = "com.ohos.settings";
46- std::string thirdlyBundleName = PermissionManager::GetCallingName();46+ std::string thirdlyBundleName = Bluetooth::PermissionManager::GetCallingName();
47 std::string connectStr = DialogSwitch::BuildStartCommand(type, thirdlyBundleName);47 std::string connectStr = DialogSwitch::BuildStartCommand(type, thirdlyBundleName);
48 HILOGI("The bundlename is %{public}s.", thirdlyBundleName.c_str());48 HILOGI("The bundlename is %{public}s.", thirdlyBundleName.c_str());
49 if (!BluetoothDialog::DialogConnectExtension(connectStr, bundleName, abilityName)) {49 if (!BluetoothDialog::DialogConnectExtension(connectStr, bundleName, abilityName)) {
Dservices/bluetooth/service/src/permission/auth_center.cpp+0-110
@@ -1,110 +0,0 @@
1-/*
2- * Copyright (C) 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-#include "auth_center.h"
16-#include "stdbool.h"
17-#include "accesstoken_kit.h"
18-#include "permission_helper.h"
19- 
20- 
21-namespace OHOS {
22-namespace bluetooth {
23-#ifdef PERMISSION_ALWAYS_GRANT
24-bool g_permissionAlwaysGrant = true;
25-#else
26-bool g_permissionAlwaysGrant = false;
27-#endif
28- 
29-using namespace OHOS::Security::AccessToken;
30- 
31-AuthCenter &AuthCenter::GetInstance()
32-{
33- static AuthCenter authCenter;
34- return authCenter;
35-}
36- 
37-int AuthCenter::VerifyUseBluetoothPermission(const int &pid, const int &uid)
38-{
39- if (g_permissionAlwaysGrant) {
40- return PERMISSION_GRANTED;
41- }
42- 
43- return PermissionHelper::VerifyUseBluetoothPermission(pid, uid);
44-}
45- 
46-int AuthCenter::VerifyDiscoverBluetoothPermission(const int &pid, const int &uid)
47-{
48- if (g_permissionAlwaysGrant) {
49- return PERMISSION_GRANTED;
50- }
51- return PermissionHelper::VerifyDiscoverBluetoothPermission(pid, uid);
52-}
53- 
54-int AuthCenter::VerifyManageBluetoothPermission(const int &pid, const int &uid)
55-{
56- if (g_permissionAlwaysGrant) {
57- return PERMISSION_GRANTED;
58- }
59- return PermissionHelper::VerifyManageBluetoothPermission(pid, uid);
60-}
61- 
62-int AuthCenter::VerifyLocationPermission(const int &pid, const int &uid)
63-{
64- if (g_permissionAlwaysGrant) {
65- return PERMISSION_GRANTED;
66- }
67- return PERMISSION_GRANTED;
68-}
69- 
70-int AuthCenter::VerifyApproximatelyPermission(const int &pid, const int &uid)
71-{
72- if (g_permissionAlwaysGrant) {
73- return PERMISSION_GRANTED;
74- }
75- return PERMISSION_GRANTED;
76-}
77- 
78-int AuthCenter::VerifyAccessBluetoothPermission(const int &pid, const int &uid)
79-{
80- if (g_permissionAlwaysGrant) {
81- return PERMISSION_GRANTED;
82- }
83- return PermissionHelper::VerifyAccessBluetoothPermission(pid, uid);
84-}
85- 
86-int AuthCenter::VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid)
87-{
88- if (g_permissionAlwaysGrant) {
89- return PERMISSION_GRANTED;
90- }
91- return PermissionHelper::VerifyGetBluetoothLocalMacPermission(pid, uid);
92-}
93- 
94-int AuthCenter::VerifyUseBluetoothPermission(const std::uint32_t &tokenID)
95-{
96- if (g_permissionAlwaysGrant) {
97- return PERMISSION_GRANTED;
98- }
99- return PermissionHelper::VerifyUseBluetoothPermission(tokenID);
100-}
101- 
102-int AuthCenter::VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID)
103-{
104- if (g_permissionAlwaysGrant) {
105- return PERMISSION_GRANTED;
106- }
107- return PermissionHelper::VerifyDiscoverBluetoothPermission(tokenID);
108-}
109-} // namespace bluetooth
110-} // namespace OHOS
Dservices/bluetooth/service/src/permission/auth_center.h+0-108
@@ -1,108 +0,0 @@
1-/*
2- * Copyright (C) 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-#ifndef AUTH_CENTER_H
17-#define AUTH_CENTER_H
18- 
19-#include <cstdint>
20- 
21-namespace OHOS {
22-namespace bluetooth {
23-class AuthCenter {
24-public:
25- static AuthCenter &GetInstance();
26- 
27- /**
28- * @Description Verify where the app has the permission to use bluetooth
29- *
30- * @param pid the app's process id.
31- * @param uid the app id.
32- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
33- */
34- static int VerifyUseBluetoothPermission(const int &pid, const int &uid);
35- 
36- /**
37- * @Description Verify where the app has the permission to discover bluetooth
38- *
39- * @param pid the app's process id.
40- * @param uid the app id.
41- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
42- */
43- static int VerifyDiscoverBluetoothPermission(const int &pid, const int &uid);
44- 
45- /**
46- * @Description Verify where the app has the permission to manager bluetooth
47- *
48- * @param pid the app's process id.
49- * @param uid the app id.
50- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
51- */
52- static int VerifyManageBluetoothPermission(const int &pid, const int &uid);
53- 
54- /**
55- * @Description Verify where the app has the permission to Location
56- *
57- * @param pid the app's process id.
58- * @param uid the app id.
59- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
60- */
61- static int VerifyLocationPermission(const int &pid, const int &uid);
62- 
63- /**
64- * @Description Verify where the app has the permission to Approximately Location
65- *
66- * @param pid the app's process id.
67- * @param uid the app id.
68- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
69- */
70- static int VerifyApproximatelyPermission(const int &pid, const int &uid);
71- 
72- /**
73- * @Description Verify where the app has the permission to access bluetooth
74- *
75- * @param pid the app's process id.
76- * @param uid the app id.
77- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
78- */
79- static int VerifyAccessBluetoothPermission(const int &pid, const int &uid);
80- 
81- /**
82- * @Description Verify where the app has the permission to get bluetooth local mac
83- *
84- * @param pid the app's process id.
85- * @param uid the app id.
86- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
87- */
88- static int VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid);
89- 
90- /**
91- * @Description Verify where the app has the permission to use bluetooth
92- *
93- * @param tokenID the app's token id.
94- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
95- */
96- static int VerifyUseBluetoothPermission(const std::uint32_t &tokenID);
97- 
98- /**
99- * @Description Verify where the app has the permission to discover bluetooth
100- *
101- * @param tokenID the app's token id.
102- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
103- */
104- static int VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID);
105-};
106-} // namespace bluetooth
107-} // namespace OHOS
108-#endif
Dservices/bluetooth/service/src/permission/permission_helper.cpp+0-162
@@ -1,162 +0,0 @@
1-/*
2- * Copyright (C) 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 "permission_helper.h"
17-#include "permission_utils.h"
18-#include "accesstoken_kit.h"
19-#include "ipc_skeleton.h"
20-#include "log.h"
21- 
22-namespace OHOS {
23-namespace bluetooth {
24-using namespace OHOS;
25-using namespace Security::AccessToken;
26- 
27-int PermissionHelper::VerifyPermission(const std::string &permissionName, const int &pid, const int &uid)
28-{
29- auto callerToken = IPCSkeleton::GetCallingTokenID();
30- int result;
31- 
32- if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_NATIVE) {
33- result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
34- } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_SHELL) {
35- result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
36- } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_HAP) {
37- result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permissionName);
38- } else {
39- LOG_INFO("callerToken=0x%{public}x is invalid token", pid);
40- return PERMISSION_DENIED;
41- }
42- if (result == Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
43- return PERMISSION_GRANTED;
44- } else {
45- LOG_INFO("callerToken=0x%{public}x has no permission_name=%{public}s", pid, permissionName.c_str());
46- return PERMISSION_DENIED;
47- }
48-}
49- 
50-int PermissionHelper::VerifyPermission(const std::string &permissionName, const std::uint32_t &callerToken)
51-{
52- auto pid = IPCSkeleton::GetCallingPid();
53- int result;
54- 
55- if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_NATIVE) {
56- result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
57- } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_SHELL) {
58- result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
59- } else if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken) == TOKEN_HAP) {
60- result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permissionName);
61- } else {
62- LOG_INFO("callerToken=0x%{public}x is invalid token", pid);
63- return PERMISSION_DENIED;
64- }
65- if (result == Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
66- return PERMISSION_GRANTED;
67- } else {
68- LOG_INFO("callerToken=0x%{public}x has no permission_name=%{public}s", pid, permissionName.c_str());
69- return PERMISSION_DENIED;
70- }
71-}
72- 
73-int PermissionHelper::VerifyUseBluetoothPermission(const int &pid, const int &uid)
74-{
75- if (VerifyPermission("ohos.permission.USE_BLUETOOTH", pid, uid) == PERMISSION_DENIED) {
76- return PERMISSION_DENIED;
77- }
78- 
79- return PERMISSION_GRANTED;
80-}
81- 
82-int PermissionHelper::VerifyDiscoverBluetoothPermission(const int &pid, const int &uid)
83-{
84- if (VerifyPermission("ohos.permission.DISCOVER_BLUETOOTH", pid, uid) == PERMISSION_DENIED) {
85- return PERMISSION_DENIED;
86- }
87- 
88- return PERMISSION_GRANTED;
89-}
90- 
91-int PermissionHelper::VerifyManageBluetoothPermission(const int &pid, const int &uid)
92-{
93- if (VerifyPermission("ohos.permission.MANAGE_BLUETOOTH", pid, uid) == PERMISSION_DENIED) {
94- return PERMISSION_DENIED;
95- }
96- 
97- return PERMISSION_GRANTED;
98-}
99- 
100-int PermissionHelper::VerifyLocationPermission(const int &pid, const int &uid)
101-{
102- if (VerifyPermission("ohos.permission.LOCATION", pid, uid) == PERMISSION_DENIED) {
103- return PERMISSION_DENIED;
104- }
105- 
106- return PERMISSION_GRANTED;
107-}
108- 
109-int PermissionHelper::VerifyApproximatelyPermission(const int &pid, const int &uid)
110-{
111- if (VerifyPermission("ohos.permission.APPROXIMATELY_LOCATION", pid, uid) == PERMISSION_DENIED) {
112- return PERMISSION_DENIED;
113- }
114- 
115- return PERMISSION_GRANTED;
116-}
117- 
118-int PermissionHelper::VerifyAccessBluetoothPermission(const int &pid, const int &uid)
119-{
120- HapTokenInfo hapTokenInfo;
121- auto callerToken = IPCSkeleton::GetCallingTokenID();
122- if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(callerToken, hapTokenInfo) == RET_SUCCESS) {
123- if (PermissionUtils::CheckSystemHapApp() &&
124- (hapTokenInfo.bundleName == "com.ohos.settings" || hapTokenInfo.bundleName == "com.ohos.systemui")) {
125- return PERMISSION_GRANTED;
126- }
127- }
128- if (VerifyPermission("ohos.permission.ACCESS_BLUETOOTH", pid, uid) == PERMISSION_DENIED) {
129- return PERMISSION_DENIED;
130- }
131- 
132- return PERMISSION_GRANTED;
133-}
134- 
135-int PermissionHelper::VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid)
136-{
137- if (VerifyPermission("ohos.permission.GET_BLUETOOTH_LOCAL_MAC", pid, uid) == PERMISSION_DENIED) {
138- return PERMISSION_DENIED;
139- }
140- 
141- return PERMISSION_GRANTED;
142-}
143- 
144-int PermissionHelper::VerifyUseBluetoothPermission(const std::uint32_t &tokenID)
145-{
146- if (VerifyPermission("ohos.permission.USE_BLUETOOTH", tokenID) == PERMISSION_DENIED) {
147- return PERMISSION_DENIED;
148- }
149- 
150- return PERMISSION_GRANTED;
151-}
152- 
153-int PermissionHelper::VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID)
154-{
155- if (VerifyPermission("ohos.permission.DISCOVER_BLUETOOTH", tokenID) == PERMISSION_DENIED) {
156- return PERMISSION_DENIED;
157- }
158- 
159- return PERMISSION_GRANTED;
160-}
161-} // namespace bluetooth
162-} // namespace OHOS
Dservices/bluetooth/service/src/permission/permission_helper.h+0-124
@@ -1,124 +0,0 @@
1-/*
2- * Copyright (C) 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-#ifndef PERMISSION_HELPER_H
17-#define PERMISSION_HELPER_H
18-#include <string>
19- 
20-namespace OHOS {
21-namespace bluetooth {
22-class PermissionHelper {
23-public:
24- /**
25- * @Description Verify where the app has the permission.
26- *
27- * @param permissionName Permission name.
28- * @param pid The app's process id.
29- * @param uid The app id.
30- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
31- */
32- static int VerifyPermission(const std::string &permissionName, const int &pid, const int &uid);
33- 
34- /**
35- * @Description Verify where the app has the permission.
36- *
37- * @param permissionName Permission name.
38- * @param callerToken The app's token id.
39- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
40- */
41- static int VerifyPermission(const std::string &permissionName, const std::uint32_t &callerToken);
42- 
43- /**
44- * @Description Verify where the app has the permission to use bluetooth
45- *
46- * @param pid The app's process id.
47- * @param uid The app id.
48- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
49- */
50- static int VerifyUseBluetoothPermission(const int &pid, const int &uid);
51- 
52- /**
53- * @Description Verify where the app has the permission to discover bluetooth
54- *
55- * @param pid The app's process id.
56- * @param uid The app id.
57- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
58- */
59- static int VerifyDiscoverBluetoothPermission(const int &pid, const int &uid);
60- 
61- /**
62- * @Description Verify where the app has the permission to manager bluetooth
63- *
64- * @param pid The app's process id.
65- * @param uid The app id.
66- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
67- */
68- static int VerifyManageBluetoothPermission(const int &pid, const int &uid);
69- 
70- /**
71- * @Description Verify where the app has the permission to location
72- *
73- * @param pid The app's process id.
74- * @param uid The app id.
75- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
76- */
77- static int VerifyLocationPermission(const int &pid, const int &uid);
78- 
79- /**
80- * @Description Verify where the app has the permission to approximately location
81- *
82- * @param pid The app's process id.
83- * @param uid The app id.
84- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
85- */
86- static int VerifyApproximatelyPermission(const int &pid, const int &uid);
87- 
88- /**
89- * @Description Verify where the app has the permission to access bluetooth
90- *
91- * @param pid the app's process id.
92- * @param uid the app id.
93- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
94- */
95- static int VerifyAccessBluetoothPermission(const int &pid, const int &uid);
96- 
97- /**
98- * @Description Verify where the app has the permission to get bluetooth local mac
99- *
100- * @param pid the app's process id.
101- * @param uid the app id.
102- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
103- */
104- static int VerifyGetBluetoothLocalMacPermission(const int &pid, const int &uid);
105- 
106- /**
107- * @Description Verify where the app has the permission to use bluetooth
108- *
109- * @param tokenID The app's token id.
110- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
111- */
112- static int VerifyUseBluetoothPermission(const std::uint32_t &tokenID);
113- 
114- /**
115- * @Description Verify where the app has the permission to discover bluetooth
116- *
117- * @param tokenID The app's token id.
118- * @return int PERMISSION_DENIED or PERMISSION_GRANTED
119- */
120- static int VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID);
121-};
122-} // namespace bluetooth
123-} // namespace OHOS
124-#endif
Aservices/bluetooth/service/src/permission/permission_item.cpp+48-0
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2026 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 "permission_item.h"
17+#include "log.h"
18+ 
19+namespace OHOS {
20+namespace Bluetooth {
21+ 
22+PermissionItem::PermissionItem(bool systemHapNeeded, const std::set<std::string> permissionsApi9,
23+ const std::set<std::string> permissionsApi10)
24+{
25+ systemHapNeeded_ = systemHapNeeded;
26+ permissionsApi9_ = permissionsApi9;
27+ permissionsApi10_ = permissionsApi10;
28+}
29+ 
30+PermissionItem::~PermissionItem()
31+{}
32+ 
33+bool PermissionItem::SystemHapNeeded()
34+{
35+ return systemHapNeeded_;
36+}
37+ 
38+std::set<std::string> PermissionItem::GetPermissions(int apiVer)
39+{
40+ if (apiVer != API_VERSION_9 && apiVer != API_VERSION_10) {
41+ HILOGE("[PERMISSION] invalid input: apiVer{%{public}d}", apiVer);
42+ return {};
43+ }
44+ return (apiVer == API_VERSION_9) ? permissionsApi9_ : permissionsApi10_;
45+}
46+ 
47+} // namespace Bluetooth
48+} // namespace OHOS
Rservices/bluetooth/service/src/permission/permission_utils.hservices/bluetooth/service/src/permission/permission_item.h+23-23
@@ -1,5 +1,5 @@
1/*1/*
2- * Copyright (C) 2022 Huawei Device Co., Ltd.2+ * Copyright (C) 2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -13,31 +13,31 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16-#ifndef PERMISSION_UTILS_H16+#ifndef PERMISSION_ITEM_H
17-#define PERMISSION_UTILS_H17+#define PERMISSION_ITEM_H
18 18 
19-#include <cstdint>19+#include <map>
20-#include "accesstoken_kit.h"20+#include <set>
21+#include <string>
21 22 
22namespace OHOS {23namespace OHOS {
23-namespace bluetooth {24+namespace Bluetooth {
24-using namespace OHOS::Security::AccessToken;25+constexpr int32_t API_VERSION_INVALID = -1;
25- 26+constexpr int32_t API_VERSION_9 = 9;
26-class PermissionUtils {27+constexpr int32_t API_VERSION_10 = 10;
28+constexpr int32_t API_VERSION_12 = 12;
29+class PermissionItem {
27public:30public:
28- static int VerifyUseBluetoothPermission();31+ explicit PermissionItem(bool systemHapNeeded, const std::set<std::string> permissionsApi9,
29- static int VerifyDiscoverBluetoothPermission();32+ const std::set<std::string> permissionsApi10);
30- static int VerifyManageBluetoothPermission();33+ ~PermissionItem();
31- static int VerifyLocationPermission();34+ bool SystemHapNeeded();
32- static int VerifyApproximatelyPermission();35+ std::set<std::string> GetPermissions(int apiVer);
33- static int VerifyAccessBluetoothPermission();36+private:
34- static int VerifyGetBluetoothLocalMacPermission();37+ bool systemHapNeeded_ = false;
35- 38+ std::set<std::string> permissionsApi9_ {};
36- static int VerifyUseBluetoothPermission(const std::uint32_t &tokenID);39+ std::set<std::string> permissionsApi10_ {};
37- static int VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID);
38- static bool CheckSystemHapApp();
39- static int GetApiVersion();
40};40};
41-} // namespace bluetooth41+} // namespace Bluetooth
42-} // namespace OHOS42+} // namespace OHOS
43#endif43#endif
Mservices/bluetooth/service/src/permission/permission_manager.cpp+157-32
@@ -1,5 +1,5 @@
1-/**1+/*
2- * Copyright (c) 2024 Huawei Device Co., Ltd.2+ * Copyright (C) 2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -14,25 +14,161 @@
14 */14 */
15 15 
16#include "permission_manager.h"16#include "permission_manager.h"
17- 
18-#include <cstdint>
19-#include <string>
20- 
21-#include "access_token.h"
22-#include "accesstoken_kit.h"
23-#include "bundlemgr/bundle_mgr_proxy.h"
24-#include "common/log.h"
25-#include "hap_token_info.h"
26#include "ipc_skeleton.h"17#include "ipc_skeleton.h"
18+#include "bluetooth_errorcode.h"
19+#include "log.h"
27#include "iservice_registry.h"20#include "iservice_registry.h"
28-#include "native_token_info.h"
29#include "system_ability_definition.h"21#include "system_ability_definition.h"
30-#include "tokenid_kit.h"22+#include "bundle_mgr_proxy.h"
31- 
32-#include "hitrace_meter.h"
33 23 
34namespace OHOS {24namespace OHOS {
35-namespace bluetooth {25+namespace Bluetooth {
26+ 
27+using namespace OHOS;
28+using namespace Security::AccessToken;
29+ 
30+#ifdef PERMISSION_ALWAYS_GRANT
31+bool g_isAllGranted = true;
32+#else
33+bool g_isAllGranted = false;
34+#endif
35+ 
36+bool PermissionManager::VerifyPermission(const std::string &permissionName)
37+{
38+ uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
39+ return VerifyPermission(permissionName, tokenId);
40+}
41+bool PermissionManager::VerifyPermission(const std::string &permissionName, const uint32_t &tokenId)
42+{
43+ int result;
44+ ATokenTypeEnum tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
45+ if (tokenType == TOKEN_NATIVE || tokenType == TOKEN_SHELL) {
46+ result = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
47+ return true;
48+ } else if (tokenType == TOKEN_HAP) {
49+ result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, permissionName);
50+ HILOGI("permission(%{public}s) tokenId(%{public}d), result(%{public}d)",
51+ permissionName.c_str(), tokenId, result);
52+ HapTokenInfo hapTokenInfo;
53+ if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo) == RET_SUCCESS) {
54+ if (IsSystemHap() && (hapTokenInfo.bundleName == "com.ohos.settings" ||
55+ hapTokenInfo.bundleName == "com.ohos.systemui")) {
56+ return true;
57+ }
58+ }
59+ bool ret = (result == Security::AccessToken::PermissionState::PERMISSION_GRANTED);
60+ return ret;
61+ } else {
62+ HILOGI("[PERMISSION] unknown token type(%{public}d)", tokenType);
63+ return false;
64+ }
65+}
66+ 
67+bool PermissionManager::IsPermissionsGranted(const std::set<std::string> &permissions)
68+{
69+ for (auto &it : permissions) {
70+ CHECK_AND_RETURN_LOG_RET(VerifyPermission(it), false,
71+ "[PERMISSION] check permission failed, permission(%{public}s)", it.c_str());
72+ }
73+ return true;
74+}
75+ 
76+int32_t PermissionManager::VerifyMultiPermissions(const std::shared_ptr<PermissionItem> &item)
77+{
78+ if (g_isAllGranted) {
79+ return Bluetooth::BT_NO_ERROR;
80+ }
81+ if (item == nullptr) {
82+ return Bluetooth::BT_NO_ERROR;
83+ }
84+ 
85+ int32_t apiVerIdx = API_VERSION_10;
86+ int32_t apiVersion = API_VERSION_10;
87+ if (IsHapCaller()) {
88+ apiVersion = GetApiVersion();
89+ apiVerIdx =
90+ (apiVersion >= API_VERSION_10 || apiVersion == API_VERSION_INVALID) ? API_VERSION_10 : API_VERSION_9;
91+ }
92+ std::set<std::string> perm = item->GetPermissions(apiVerIdx);
93+ CHECK_AND_RETURN_LOG_RET(!perm.empty(), Bluetooth::BT_ERR_PERMISSION_FAILED,
94+ "[PERMISSION] the caller's api version is unsupported, apiVersion(%{public}d)", apiVersion);
95+ if (item->SystemHapNeeded() && !IsSystemHap()) {
96+ HILOGE("[PERMISSION] system hap needed.");
97+ return Bluetooth::BT_ERR_SYSTEM_PERMISSION_FAILED;
98+ }
99+ CHECK_AND_RETURN_LOG_RET(IsPermissionsGranted(perm), Bluetooth::BT_ERR_PERMISSION_FAILED,
100+ "[PERMISSION] check permissions failed. apiVersion is %{public}d", apiVersion);
101+ return Bluetooth::BT_NO_ERROR;
102+}
103+ 
104+int32_t PermissionManager::GetCallingUid()
105+{
106+ return IPCSkeleton::GetCallingUid();
107+}
108+ 
109+bool PermissionManager::IsHapCaller(void)
110+{
111+ uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
112+ return IsHapCaller(tokenId);
113+}
114+ 
115+bool PermissionManager::IsHapCaller(uint32_t &tokenId)
116+{
117+ ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
118+ if (callingType == ATokenTypeEnum::TOKEN_HAP) {
119+ return true;
120+ }
121+ return false;
122+}
123+ 
124+int32_t PermissionManager::GetApiVersion()
125+{
126+ uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
127+ return GetApiVersion(tokenId);
128+}
129+ 
130+int32_t PermissionManager::GetApiVersion(uint32_t tokenId)
131+{
132+ if (!IsHapCaller(tokenId)) {
133+ return API_VERSION_INVALID;
134+ }
135+ HapTokenInfo hapTokenInfo;
136+ if (AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo) != AccessTokenKitRet::RET_SUCCESS) {
137+ HILOGE("[PERMISSION] GetHapTokenInfo failed.");
138+ return API_VERSION_INVALID;
139+ }
140+ return hapTokenInfo.apiVersion;
141+}
142+ 
143+bool PermissionManager::IsNativeCaller(void)
144+{
145+ uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
146+ return IsNativeCaller(tokenId);
147+}
148+bool PermissionManager::IsNativeCaller(const uint32_t &tokenId)
149+{
150+ ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
151+ if (callingType == ATokenTypeEnum::TOKEN_NATIVE || callingType == ATokenTypeEnum::TOKEN_SHELL) {
152+ return true;
153+ }
154+ return false;
155+}
156+bool PermissionManager::IsSystemHap()
157+{
158+ uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID();
159+ return IsSystemHap(fullTokenId);
160+}
161+ 
162+bool PermissionManager::IsSystemHap(const uint64_t &fullTokenId)
163+{
164+ bool isSystemApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId);
165+ Security::AccessToken::ATokenTypeEnum callingType =
166+ Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(static_cast<uint32_t>(fullTokenId));
167+ if (callingType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP && !isSystemApp) {
168+ return false;
169+ }
170+ return true;
171+}
36 172 
37std::string PermissionManager::GetCallingName()173std::string PermissionManager::GetCallingName()
38{174{
@@ -70,21 +206,10 @@ std::string PermissionManager::GetCallingName(const uint32_t& tokenId)
70 }206 }
71}207}
72 208 
73-bool PermissionManager::IsSystemHap()209+std::shared_ptr<PermissionItem> PermissionManager::CreateItem(bool isSystemApi,
210+ const std::set<std::string> api9PermSet, const std::set<std::string> api10PermSet)
74{211{
75- uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID();212+ return std::make_shared<PermissionItem>(isSystemApi, api9PermSet, api10PermSet);
76- return IsSystemHap(fullTokenId);
77}213}
78- 214+} // namespace Bluetooth
79-bool PermissionManager::IsSystemHap(const uint64_t& fullTokenId)215+} // namespace OHOS
80-{
81- bool isSystemApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId);
82- Security::AccessToken::ATokenTypeEnum callingType =
83- Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(static_cast<uint32_t>(fullTokenId));
84- if (callingType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP && !isSystemApp) {
85- return false;
86- }
87- return true;
88-}
89-} // namespace bluetooth
90-} // namespace OHOS
Mservices/bluetooth/service/src/permission/permission_manager.h+71-11
@@ -1,5 +1,5 @@
1-/**1+/*
2- * Copyright (c) 2024 Huawei Device Co., Ltd.2+ * Copyright (C) 2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -15,23 +15,83 @@
15 15 
16#ifndef PERMISSION_MANAGER_H16#ifndef PERMISSION_MANAGER_H
17#define PERMISSION_MANAGER_H17#define PERMISSION_MANAGER_H
18- 18+#include <map>
19#include <string>19#include <string>
20- 20+#include "accesstoken_kit.h"
21+#include "permission_item.h"
21#include "tokenid_kit.h"22#include "tokenid_kit.h"
23+#ifdef CHECK_PERM
24+#undef CHECK_PERM
25+#endif
26+#define CHECK_PERM(isSystemApi, api9Perm, api10Perm) PermissionManager::CreateItem(isSystemApi, api9Perm, api10Perm)
27+ 
28+#ifdef MULTI_PERM
29+#undef MULTI_PERM
30+#endif
31+#define MULTI_PERM(...) {__VA_ARGS__}
32+ 
33+#define CHECK_PERMISSION_AND_EXECUTE_FUNC_RETURN(STUB_CLASS) \
34+do { \
35+ HILOGI("cmd(%{public}u), flags(%{public}d)", code, option.GetFlags()); \
36+ if (STUB_CLASS::GetDescriptor() != data.ReadInterfaceToken()) { \
37+ HILOGE("interface token check failed."); \
38+ return ERR_INVALID_STATE; \
39+ } \
40+ auto itFunc = memberFuncMap_.find(code); \
41+ if (itFunc == memberFuncMap_.end()) { \
42+ HILOGE("code(%{public}d) is not exist.", code); \
43+ return IPCObjectStub::OnRemoteRequest(code, data, reply, option); \
44+ } \
45+ auto memberFunc = itFunc->second.first; \
46+ if (memberFunc == nullptr) { \
47+ HILOGE("memberFunc is nullptr. code(%{public}d)", code); \
48+ return IPCObjectStub::OnRemoteRequest(code, data, reply, option); \
49+ } \
50+ int errCode = PermissionManager::VerifyMultiPermissions(itFunc->second.second); \
51+ if (errCode != NO_ERROR) { \
52+ HILOGE("[PERMISSION] failed. code(%{public}d)", code); \
53+ reply.WriteInt32(errCode); \
54+ return NO_ERROR; \
55+ } \
56+ return memberFunc(this, data, reply); \
57+} while (0) \
22 58 
23namespace OHOS {59namespace OHOS {
24-namespace bluetooth {60+namespace Bluetooth {
61+ 
62+const std::string GET_BLUETOOTH_LOCAL_MAC =
63+ "ohos.permission.GET_BLUETOOTH_LOCAL_MAC";
64+const std::string ACCESS_BLUETOOTH = "ohos.permission.ACCESS_BLUETOOTH";
65+const std::string USE_BLUETOOTH = "ohos.permission.USE_BLUETOOTH";
66+const std::string DISCOVER_BLUETOOTH = "ohos.permission.DISCOVER_BLUETOOTH";
67+const std::string MANAGE_BLUETOOTH = "ohos.permission.MANAGE_BLUETOOTH";
68+ 
69+const std::string APPROXIMATELY_LOCATION = "ohos.permission.APPROXIMATELY_LOCATION";
70+const std::string LOCATION = "ohos.permission.LOCATION";
71+ 
25class PermissionManager {72class PermissionManager {
26public:73public:
74+ static bool VerifyPermission(const std::string &permissionName);
75+ static bool VerifyPermission(
76+ const std::string &permissionName, const uint32_t &tokenId);
77+ static int32_t VerifyMultiPermissions(const std::shared_ptr<PermissionItem> &item);
78+ static int32_t GetApiVersion();
79+ static int32_t GetApiVersion(uint32_t tokenId);
80+ static int32_t GetCallingUid();
27 static std::string GetCallingName();81 static std::string GetCallingName();
28- 
29 static std::string GetCallingName(const uint32_t& tokenId);82 static std::string GetCallingName(const uint32_t& tokenId);
30- 83+ static bool IsHapCaller(void);
84+ static bool IsHapCaller(uint32_t &tokenId);
85+ static bool IsNativeCaller(void);
86+ static bool IsNativeCaller(const uint32_t &tokenId);
31 static bool IsSystemHap();87 static bool IsSystemHap();
32- 88+ static bool IsSystemHap(const uint64_t &fullTokenId);
33- static bool IsSystemHap(const uint64_t& fullTokenId);89+ static std::shared_ptr<PermissionItem> CreateItem(
90+ bool isSystemApi, const std::set<std::string> api9PermSet, const std::set<std::string> api10PermSet);
91+private:
92+ static bool IsPermissionsGranted(const std::set<std::string> &permissions);
34};93};
35-} // namespace bluetooth94+ 
95+} // namespace Bluetooth
36} // namespace OHOS96} // namespace OHOS
37-#endif97+#endif
Dservices/bluetooth/service/src/permission/permission_utils.cpp+0-124
@@ -1,124 +0,0 @@
1-/*
2- * Copyright (C) 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 "permission_utils.h"
17-#include "auth_center.h"
18-#include "ipc_skeleton.h"
19-#include "log.h"
20-#include "tokenid_kit.h"
21- 
22-namespace OHOS {
23-namespace bluetooth {
24-using namespace OHOS;
25-const int API_VERSION_INVALID = -1;
26-int PermissionUtils::VerifyUseBluetoothPermission()
27-{
28- if (GetApiVersion() >= 10) { // 10:api version
29- return VerifyAccessBluetoothPermission();
30- }
31- return AuthCenter::GetInstance().VerifyUseBluetoothPermission(
32- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
33-}
34- 
35-int PermissionUtils::VerifyDiscoverBluetoothPermission()
36-{
37- if (GetApiVersion() >= 10) { // 10:api version
38- return VerifyAccessBluetoothPermission();
39- }
40- return AuthCenter::GetInstance().VerifyDiscoverBluetoothPermission(
41- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
42-}
43- 
44-int PermissionUtils::VerifyManageBluetoothPermission()
45-{
46- return AuthCenter::GetInstance().VerifyManageBluetoothPermission(
47- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
48-}
49- 
50-int PermissionUtils::VerifyLocationPermission()
51-{
52- if (GetApiVersion() >= 10) { // 10:api version
53- return VerifyAccessBluetoothPermission();
54- }
55- return AuthCenter::GetInstance().VerifyLocationPermission(
56- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
57-}
58- 
59-int PermissionUtils::VerifyApproximatelyPermission()
60-{
61- if (GetApiVersion() >= 10) { // 10:api version
62- return VerifyAccessBluetoothPermission();
63- }
64- return AuthCenter::GetInstance().VerifyApproximatelyPermission(
65- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
66-}
67- 
68-int PermissionUtils::VerifyAccessBluetoothPermission()
69-{
70- if (GetApiVersion() >= 10) { // 10:api version
71- return AuthCenter::GetInstance().VerifyAccessBluetoothPermission(
72- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
73- } else {
74- return PERMISSION_GRANTED;
75- }
76-}
77- 
78-int PermissionUtils::VerifyGetBluetoothLocalMacPermission()
79-{
80- return AuthCenter::GetInstance().VerifyGetBluetoothLocalMacPermission(
81- IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
82-}
83- 
84-int PermissionUtils::VerifyUseBluetoothPermission(const std::uint32_t &tokenID)
85-{
86- return AuthCenter::GetInstance().VerifyUseBluetoothPermission(tokenID);
87-}
88- 
89-int PermissionUtils::VerifyDiscoverBluetoothPermission(const std::uint32_t &tokenID)
90-{
91- return AuthCenter::GetInstance().VerifyDiscoverBluetoothPermission(tokenID);
92-}
93- 
94-bool PermissionUtils::CheckSystemHapApp()
95-{
96- uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
97- ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
98- uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID();
99- bool isSystemApp = TokenIdKit::IsSystemAppByFullTokenID(fullTokenId);
100- HILOGI("tokenId:0x%{public}x, callingType:0x%{public}x, fullTokenId:0x%{public}llx, isSystemApp:%{public}d",
101- tokenId, callingType, static_cast<unsigned long long>(fullTokenId), isSystemApp);
102- // Only the system app can invoke the system interface.
103- if (callingType == TOKEN_HAP && !isSystemApp) {
104- HILOGE("The caller is not a system app.");
105- return false;
106- }
107- return true;
108-}
109- 
110-int PermissionUtils::GetApiVersion()
111-{
112- uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
113- ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
114- if (callingType != ATokenTypeEnum::TOKEN_HAP) {
115- return API_VERSION_INVALID;
116- }
117- HapTokenInfo hapTokenInfo;
118- if (AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo) != AccessTokenKitRet::RET_SUCCESS) {
119- return API_VERSION_INVALID;
120- }
121- return hapTokenInfo.apiVersion;
122-}
123-} // namespace bluetooth
124-} // namespace OHOS