android T蓝牙关闭流程

文章详细描述了在Android系统中禁用Bluetooth的过程,从Settings应用触发到底层堆栈关闭的完整步骤。涉及到BluetoothAdapter的disable方法,BluetoothManagerService的持久化设置更新,Binder调用的超时机制,以及不同层次的服务停止,包括profile服务清理和连接断开等操作。
摘要由CSDN通过智能技术生成

设置应用目录:
packages/apps/Settings/src/com/android/settings/bluetooth/
文件:
1,BluetoothSwitchPreferenceController.java
mBluetoothEnabler = new BluetoothEnabler(…)
2,BluetoothEnabler.java
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
onSwitchToggled(boolean isChecked) {
setBluetoothEnabled(isChecked) {
mBluetoothAdapter.disable();
}
}
蓝牙应用目录:
packages/modules/Bluetooth
framework
framework/java/android/bluetooth/
文件:
BluetoothAdapter.java
disable() -> disable(true) : mManagerService.disable(mAttributionSource, persist);
service
service\java\com\android\server\bluetooth
文件:
BluetoothManagerService.java
disable(AttributionSource attributionSource, boolean persist)
->persistBluetoothSetting(BLUETOOTH_OFF);
persistBluetoothSetting(int value) : Settings.Global.putInt(Settings.Global.BLUETOOTH_ON)

BluetoothManagerService.java
Intent.ACTION_SETTING_RESTORED:
=> Settings.Global.BLUETOOTH_ON.equals(name)
MESSAGE_RESTORE_USER_SETTING: RESTORE_SETTING_TO_OFF
(ENABLE_DISABLE_DELAY_MS = 300;)
synchronousDisable -> mBluetooth.disable(attributionSource, recv);
Timeout value for synchronous binder call: Duration.ofSeconds(3) // 应用等等binder超时3秒。
recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false);
=跨进程====************
android/app/src/com/android/bluetooth/btservice/AdapterState.java
receiver.send(disable(source)) -> service.disable
USER_TURN_OFF: transitionTo(mTurningOffState);
TurningOffState: enter -> mAdapterService.stopProfileServices();
android/app/src/com/android/bluetooth/btservice/AdapterService.java
stopProfileServices: cancelDiscoveryNative / setAllProfileServiceStates
for() {
setProfileServiceState();
}
if(mRunningProfiles.size = 0) {
disableNative() // java to cc
}
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
(hal_util_load_bt_library((bt_interface_t const**)&sBluetoothInterface))
sBluetoothInterface->disable()
system/btif/src/bluetooth.cc
static void stop_profiles() {
btif_sock_cleanup();
btif_pan_cleanup();
}
disable -> stack_manager_get_interface()->shut_down_stack_async(stop_profiles)
system/btif/src/stack_manager.cc
shut_down_stack_async -> base::Bind(event_shut_down_stack, stopProfiles)
event_shut_down_stack // Synchronous function to shut down the stack
system/stack/btm/btm_ble_multi_adv.cc:1086:void btm_ble_multi_adv_cleanup
system/stack/btm/btm_ble_scanner.cc:178:void btm_ble_scanner_cleanup
system/bta/dm/bta_dm_act.cc:459:void bta_dm_disable

	用future_await(local_hack_future);  同步等待

system/bta/dm/bta_dm_act.cc
bta_dm_disable : bta_dm_wait_for_acl_to_drain_cback -> force_disconnect_all_acl_connections()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值