]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/interfaces/IClipboard.py
debian/control: add Depends on pipewire-pulse | pulseaudio
[waydroid.git] / tools / interfaces / IClipboard.py
1 import gbinder
2 import logging
3 from tools import helpers
4 from gi.repository import GLib
5
6
7 INTERFACE = "lineageos.waydroid.IClipboard"
8 SERVICE_NAME = "waydroidclipboard"
9
10 TRANSACTION_sendClipboardData = 1
11 TRANSACTION_getClipboardData = 2
12
13 def add_service(args, sendClipboardData, getClipboardData):
14 helpers.drivers.loadBinderNodes(args)
15 try:
16 serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER, args.SERVICE_MANAGER_PROTOCOL, args.BINDER_PROTOCOL)
17 except TypeError:
18 serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER)
19
20 def response_handler(req, code, flags):
21 logging.debug(
22 "{}: Received transaction: {}".format(SERVICE_NAME, code))
23 reader = req.init_reader()
24 local_response = response.new_reply()
25 if code == TRANSACTION_sendClipboardData:
26 arg1 = reader.read_string16()
27 sendClipboardData(arg1)
28 local_response.append_int32(0)
29 elif code == TRANSACTION_getClipboardData:
30 ret = getClipboardData()
31 local_response.append_int32(0)
32 local_response.append_string16(ret)
33 else:
34 return local_response, -99999 # Some error unknown to binder to force a RemoteException
35
36 return local_response, 0
37
38 def binder_presence():
39 if serviceManager.is_present():
40 status = serviceManager.add_service_sync(SERVICE_NAME, response)
41
42 if status:
43 logging.error("Failed to add service {}: {}".format(
44 SERVICE_NAME, status))
45 args.clipboardLoop.quit()
46
47 response = serviceManager.new_local_object(INTERFACE, response_handler)
48 args.clipboardLoop = GLib.MainLoop()
49 binder_presence()
50 status = serviceManager.add_presence_handler(binder_presence)
51 if status:
52 args.clipboardLoop.run()
53 serviceManager.remove_handler(status)
54 del serviceManager
55 else:
56 logging.error("Failed to add presence handler: {}".format(status))