diff --git a/qubesguidaemon/mic.py b/qubesguidaemon/mic.py index a9f44426..e925df67 100644 --- a/qubesguidaemon/mic.py +++ b/qubesguidaemon/mic.py @@ -18,46 +18,55 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, see . -'''Microphone control extension''' +"""Microphone control extension""" -import asyncio import subprocess -import qubes.devices +import qubes.device_protocol import qubes.ext import qubes.vm.adminvm -class MicDevice(qubes.devices.DeviceInfo): - '''Microphone device info class''' - pass -class MicDeviceExtension(qubes.ext.Extension): - '''Extension to control microphone access +class MicDevice(qubes.device_protocol.DeviceInfo): + """Microphone device info class""" + + def __init__(self, backend_domain, product, manufacturer): + super().__init__( + backend_domain=backend_domain, + ident="mic", devclass="mic", + product=product, manufacturer=manufacturer) + self._interfaces = [ + qubes.device_protocol.DeviceInterface("******", devclass="mic")] - ''' + +class MicDeviceExtension(qubes.ext.Extension): + """ + Extension to control microphone access + """ def __init__(self): super(MicDeviceExtension, self).__init__() def get_device(self, app): - return MicDevice(app.domains[0], 'mic', 'Microphone') + return MicDevice( + app.domains[0], product="microphone", manufacturer="build-in") @qubes.ext.handler('device-list:mic') def on_device_list_mic(self, vm, event): - '''List microphone device + """List microphone device - Currently this assume audio being handled in dom0. When adding support + Currently, this assumes audio being handled in dom0. When adding support for GUI domain, this needs to be changed - ''' + """ return self.on_device_get_mic(vm, event, 'mic') @qubes.ext.handler('device-get:mic') def on_device_get_mic(self, vm, event, ident): - '''Get microphone device + """Get microphone device - Currently this assume audio being handled in dom0. When adding support + Currently, this assumes audio being handled in dom0. When adding support for GUI domain, this needs to be changed - ''' + """ # pylint: disable=unused-argument,no-self-use if not isinstance(vm, qubes.vm.adminvm.AdminVM): @@ -70,7 +79,7 @@ def on_device_get_mic(self, vm, event, ident): @qubes.ext.handler('device-list-attached:mic') def on_device_list_attached_mic(self, vm, event, persistent=None): - '''List attached microphone to the VM''' + """List attached microphone to the VM""" if persistent is True: return @@ -88,7 +97,7 @@ def on_device_list_attached_mic(self, vm, event, persistent=None): @qubes.ext.handler('device-pre-attach:mic') async def on_device_pre_attach_mic(self, vm, event, device, options): - '''Attach microphone to the VM''' + """Attach microphone to the VM""" # there is only one microphone assert device == self.get_device(vm.app) @@ -101,21 +110,22 @@ async def on_device_pre_attach_mic(self, vm, event, device, options): if audiovm is None: raise qubes.exc.QubesException( "VM {} has no AudioVM set".format(vm)) - + if not audiovm.is_running(): - raise qubes.exc.QubesVMNotRunningError(audiovm, - "Audio VM {} isn't running".format(audiovm)) + raise qubes.exc.QubesVMNotRunningError( + audiovm, "Audio VM {} isn't running".format(audiovm)) try: await audiovm.run_service_for_stdio( 'qubes.AudioInputEnable+{}'.format(vm.name)) - except subprocess.CalledProcessError as e: - raise qubes.exc.QubesVMError(vm, - 'Failed to attach audio input from {!s} to {!s}: ' + except subprocess.CalledProcessError: + raise qubes.exc.QubesVMError( + vm, 'Failed to attach audio input from {!s} to {!s}: ' 'pulseaudio agent not running'.format(audiovm, vm)) + # pylint: disable=unused-argument @qubes.ext.handler('device-pre-detach:mic') async def on_device_pre_detach_mic(self, vm, event, device): - '''Detach microphone from the VM''' + """Detach microphone from the VM""" # there is only one microphone assert device == self.get_device(vm.app) @@ -127,12 +137,12 @@ async def on_device_pre_detach_mic(self, vm, event, device): "VM {} has no AudioVM set".format(vm)) if not audiovm.is_running(): - raise qubes.exc.QubesVMNotRunningError(audiovm, - "Audio VM {} isn't running".format(audiovm)) + raise qubes.exc.QubesVMNotRunningError( + audiovm, "Audio VM {} isn't running".format(audiovm)) try: await audiovm.run_service_for_stdio( 'qubes.AudioInputDisable+{}'.format(vm.name)) - except subprocess.CalledProcessError as e: - raise qubes.exc.QubesVMError(vm, - 'Failed to detach audio input from {!s} to {!s}: ' + except subprocess.CalledProcessError: + raise qubes.exc.QubesVMError( + vm, 'Failed to detach audio input from {!s} to {!s}: ' 'pulseaudio agent not running'.format(audiovm, vm))