# SPDX-License-Identifier: MPL-2.0 """Android 6 audio services used by the Nokia firmware, outside Gecko. Transaction IDs and argument types: AOSP android-6.0.1_r1, frameworks/av/media/libmedia/{IAudioPolicyService,IAudioFlinger}.cpp. This adapter is specific to that ABI. No arbitrary Binder transaction is exposed. """ import re import subprocess import time class CallAudio: def __init__(self): self.mode=0;self.muted=False;self.speaker=False;self.available=False self.original=None;self.retry_at=0 def transact(self,service,method,*values): command=['/system/bin/service','call','media.audio_'+service,str(method)] for value in values:command.extend(('i32',str(value))) result=subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL, text=True,timeout=2,env={'PATH':'/system/bin','LD_LIBRARY_PATH':'/system/lib'}) match=re.fullmatch(r"Result: Parcel\(([0-9a-fA-F]{8})\s+'[^']*'\)\s*",result.stdout) if result.returncode or not match:raise RuntimeError('CALL_AUDIO_UNAVAILABLE') return int(match[1],16) def initialize(self): if self.available:return if time.monotonic()