Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from able.android.jni import PythonBluetooth
from able.dispatcher import BluetoothDispatcherBase
Activity = autoclass('android.app.Activity')
BLE = autoclass('org.able.BLE')
BluetoothGattDescriptor = autoclass('android.bluetooth.BluetoothGattDescriptor')
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
ENABLE_NOTIFICATION_VALUE = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
ENABLE_INDICATION_VALUE = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
DISABLE_NOTIFICATION_VALUE = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE
class BluetoothDispatcher(BluetoothDispatcherBase):
def _set_ble_interface(self):
self._events_interface = PythonBluetooth(self)
self._ble = BLE(self._events_interface)
activity.bind(on_activity_result=self.on_activity_result)
def _check_runtime_permissions(self):
# Either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission
# is needed to obtain BLE scan results
return check_permission(Permission.ACCESS_COARSE_LOCATION) or \
check_permission(Permission.ACCESS_FINE_LOCATION)
def _request_runtime_permissions(self):
request_permission(Permission.ACCESS_COARSE_LOCATION,
self.on_runtime_permissions)
def __init__(self, queue_timeout=0.5, enable_ble_code=0xab1e):
super(BluetoothDispatcherBase, self).__init__()
self.queue_timeout = queue_timeout
self.enable_ble_code = enable_ble_code
self._remote_device_address = None
self._set_ble_interface()
self._set_queue()