In my OnePlus 6 running Android 9.0, changing the value for the system key (for Settings) bluetooth_default_scan_mode
toggles the discoverability of bluetooth. Value 21
to disable, 23
to enable.
MacroDroid has a trigger named System Settings under Device Settings category, and after selecting System in the list there, you can set the key-value. Unfortunately, for some reason I didn't investigate into, MacroDroid failed to work in this case. In turn, I resorted to Tasker which also allows changing custom settings.
In Tasker, the action under a task should be: Settings → Custom Setting:
- Type: System
- Name: bluetooth_default_scan_mode or pick a related one using lens icon and test it out
- Value: 21 or 23 or whatever you found
Save the task and assign it to a profile of your liking. A profile is a trigger in MacroDroid terms.
I used logcat to find out the key-value corresponding to the discoverability of bluetooth. You can use it if you fail to find the key-value for your device. Here's what I did:
adb logcat SettingsProvider:V *:S -v long # to find the key
adb settings get system KEY # to obtain the value of the key. You would have to get the value for both cases