changeset 380:9d3481663964

android: handle new SàT specific "action" dict which may be attach to an intent: this data is used with notifications to tell the frontend which widget/target to open.
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents 1da3c379205b
children eb3f622d8791
files cagou/core/platform_/android.py
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/platform_/android.py	Wed Jan 29 10:04:35 2020 +0100
+++ b/cagou/core/platform_/android.py	Tue Feb 04 20:47:17 2020 +0100
@@ -19,12 +19,14 @@
 import sys
 import os
 import socket
+import json
 from functools import partial
+from urllib.parse import urlparse
 from jnius import autoclass, cast
 from android import activity
 from sat.core.i18n import _
 from sat.core import log as logging
-from urllib.parse import urlparse
+from sat_frontends.tools import jid
 from cagou.core.constants import Const as C
 from cagou.core import dialog
 from cagou import G
@@ -52,6 +54,7 @@
 STATE_STOPPED = b"stopped"
 SOCKET_DIR = "/data/data/org.salutatoi.cagou/"
 SOCKET_FILE = ".socket"
+INTENT_EXTRA_ACTION = AndroidString("org.salut-a-toi.IntentAction")
 
 
 class Platform(BasePlatform):
@@ -190,7 +193,31 @@
         log.debug("on_new_intent")
         action = intent.getAction();
         intent_type = intent.getType();
-        if action == Intent.ACTION_SEND:
+        if action == Intent.ACTION_MAIN:
+            action_str = intent.getStringExtra(INTENT_EXTRA_ACTION)
+            if action_str is not None:
+                action = json.loads(action_str)
+                log.debug(f"Extra action found: {action}")
+                action_type = action.get('type')
+                if action_type == "open":
+                    try:
+                        widget = action['widget']
+                        target = action['target']
+                    except KeyError as e:
+                        log.warning(f"incomplete action {action}: {e}")
+                    else:
+                        current_profile = next(iter(G.host.profiles))
+                        Clock.schedule_once(
+                            lambda *args: G.host.doAction(
+                                widget, jid.JID(target), [current_profile]),
+                            0)
+                else:
+                    log.warning(f"unexpected action: {action}")
+
+            text = None
+            uri = None
+            path = None
+        elif action == Intent.ACTION_SEND:
             # we have receiving data to share, we parse the intent data
             # and show the share widget
             data = {}