diff --git a/.p4a b/.p4a index ebe0da94..219bb80e 100644 --- a/.p4a +++ b/.p4a @@ -20,5 +20,6 @@ --fileprovider-paths src/fileprovider_paths.xml --add-asset assets/_load.html:_load.html --add-asset assets/loadingScreen:loadingScreen +--add-source src/java/ --whitelist ./allowlist.txt --blacklist ./blocklist.txt diff --git a/src/java/WelcomeScreenInterface.java b/src/java/WelcomeScreenInterface.java new file mode 100644 index 00000000..f204d963 --- /dev/null +++ b/src/java/WelcomeScreenInterface.java @@ -0,0 +1,21 @@ +package org.endlessos.Key; +import android.webkit.JavascriptInterface; +import android.util.Log; + +public class WelcomeScreenInterface { + + private static final String TAG = "WelcomeScreen"; + + public void test() { + Log.d(TAG, "test called!"); + } + + @JavascriptInterface + public void load() { + Log.d(TAG, "load called!"); + } + @JavascriptInterface + public void loadWithUSB() { + Log.d(TAG, "loadWithUSB called!"); + } +} diff --git a/src/main.py b/src/main.py index dc8d1d01..a484c6b3 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,7 @@ import time import initialization # noqa: F401 keep this first, to ensure we're set up for other imports +from android.runnable import run_on_ui_thread from android_utils import ask_all_files_access from android_utils import get_endless_key_paths from android_utils import provision_endless_key_database @@ -87,22 +88,40 @@ def _enable_kolibri_plugin(plugin_name: str, optional=False) -> bool: except FileNotFoundError: pass -# we need to initialize Kolibri to allow us to access the app key -initialize() -# start kolibri server -logging.info("Starting kolibri server via Android service...") -start_service("server") +def start_kolibri(): + # we need to initialize Kolibri to allow us to access the app key + initialize() -# Tie up this thread until the server is running -wait_for_status(STATUS_RUNNING, timeout=120) + # start kolibri server + logging.info("Starting kolibri server via Android service...") + start_service("server") -_, port, _, _ = _read_pid_file(PID_FILE) + # Tie up this thread until the server is running + wait_for_status(STATUS_RUNNING, timeout=120) -start_url = "http://127.0.0.1:{port}".format(port=port) + interface.get_initialize_url() -loadUrl(start_url) + _, port, _, _ = _read_pid_file(PID_FILE) -start_service("remoteshell") + start_url = ( + "http://127.0.0.1:{port}".format(port=port) + interface.get_initialize_url() + ) + loadUrl(start_url) + + start_service("remoteshell") + + +@run_on_ui_thread +def hook(): + WelcomeScreenInterface = autoclass("org.endlessos.Key.WelcomeScreenInterface") + welcomeScreenInterface = WelcomeScreenInterface() + welcomeScreenInterface.test() + PythonActivity.mWebView.addJavascriptInterface(welcomeScreenInterface, "EndlessAPI") + PythonActivity.mWebView.loadUrl( + "file:///android_asset/loadingScreen/index.html#/welcome" + ) + + +hook() while True: time.sleep(0.05)