]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/interfaces/IStatusBarService.py
4 from tools
import helpers
5 from gi
.repository
import GLib
9 INTERFACE
= "com.android.internal.statusbar.IStatusBarService"
10 SERVICE_NAME
= "statusbar"
12 TRANSACTION_expand
= 1
13 TRANSACTION_collapse
= 2
15 class IStatusBarService
:
16 def __init__(self
, remote
):
17 self
.client
= gbinder
.Client(remote
, INTERFACE
)
20 request
= self
.client
.new_request()
21 reply
, status
= self
.client
.transact_sync_reply(
22 TRANSACTION_expand
, request
)
25 logging
.error("Sending reply failed")
27 reader
= reply
.init_reader()
28 status
, exception
= reader
.read_int32()
30 logging
.error("Failed with code: {}".format(exception
))
33 request
= self
.client
.new_request()
34 reply
, status
= self
.client
.transact_sync_reply(
35 TRANSACTION_collapse
, request
)
38 logging
.error("Sending reply failed")
40 reader
= reply
.init_reader()
41 status
, exception
= reader
.read_int32()
43 logging
.error("Failed with code: {}".format(exception
))
45 def get_service(args
):
46 helpers
.drivers
.loadBinderNodes(args
)
48 serviceManager
= gbinder
.ServiceManager("/dev/" + args
.BINDER_DRIVER
, args
.SERVICE_MANAGER_PROTOCOL
, args
.BINDER_PROTOCOL
)
50 serviceManager
= gbinder
.ServiceManager("/dev/" + args
.BINDER_DRIVER
)
52 if not serviceManager
.is_present():
53 logging
.info("Waiting for binder Service Manager...")
54 if not wait_for_manager(serviceManager
):
55 logging
.error("Service Manager never appeared")
60 remote
, status
= serviceManager
.get_service_sync(SERVICE_NAME
)
64 "Failed to get service {}, trying again...".format(SERVICE_NAME
))
66 remote
, status
= serviceManager
.get_service_sync(SERVICE_NAME
)
71 return IStatusBarService(remote
)
73 # Like ServiceManager.wait() but can be interrupted
74 def wait_for_manager(sm
):
75 mainloop
= GLib
.MainLoop()
76 hndl
= sm
.add_presence_handler(lambda: mainloop
.quit() if sm
.is_present() else None)
77 GLib
.timeout_add_seconds(60, lambda: mainloop
.quit())
78 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGINT
, lambda _
: mainloop
.quit(), None)
80 sm
.remove_handler(hndl
)
81 if not sm
.is_present():