Dispatch commands via service on Android

This commit is contained in:
Mark Qvist 2024-09-12 21:37:36 +02:00
parent 9c66538ec1
commit a13607646c

View File

@ -1623,9 +1623,6 @@ class SidebandCore():
connection.send(self._get_plugins_info()) connection.send(self._get_plugins_info())
elif "send_message" in call: elif "send_message" in call:
args = call["send_message"] args = call["send_message"]
RNS.log(str(call))
RNS.log(str(args))
RNS.log("Handling RPC send")
send_result = self.send_message( send_result = self.send_message(
args["content"], args["content"],
args["destination_hash"], args["destination_hash"],
@ -1635,7 +1632,13 @@ class SidebandCore():
attachment=args["attachment"], attachment=args["attachment"],
image=args["image"], image=args["image"],
audio=args["audio"]) audio=args["audio"])
RNS.log("RPC send complete") connection.send(send_result)
elif "send_command" in call:
args = call["send_command"]
send_result = self.send_command(
args["content"],
args["destination_hash"],
args["propagation"])
connection.send(send_result) connection.send(send_result)
elif "get_lxm_progress" in call: elif "get_lxm_progress" in call:
args = call["get_lxm_progress"] args = call["get_lxm_progress"]
@ -3896,6 +3899,30 @@ class SidebandCore():
else: else:
return False return False
def _service_send_command(self, content, destination_hash, propagation):
if not RNS.vendor.platformutils.is_android():
return False
else:
if self.is_client:
try:
if self.rpc_connection == None:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
self.rpc_connection.send({"send_command": {
"content": content,
"destination_hash": destination_hash,
"propagation": propagation}
})
response = self.rpc_connection.recv()
return response
except Exception as e:
RNS.log("Error while sending command over RPC: "+str(e), RNS.LOG_DEBUG)
RNS.trace_exception(e)
return False
else:
return False
def send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None): def send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None):
if self.allow_service_dispatch and self.is_client: if self.allow_service_dispatch and self.is_client:
try: try:
@ -3958,6 +3985,16 @@ class SidebandCore():
return False return False
def send_command(self, content, destination_hash, propagation): def send_command(self, content, destination_hash, propagation):
if self.allow_service_dispatch and self.is_client:
try:
return self._service_send_command(content, destination_hash, propagation)
except Exception as e:
RNS.log("Error while sending message: "+str(e), RNS.LOG_ERROR)
RNS.trace_exception(e)
return False
else:
try: try:
if content == "": if content == "":
return False return False