Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/android_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re
from functools import cache
from uuid import uuid4

from cryptography import x509
from cryptography.hazmat.backends import default_backend
Expand Down Expand Up @@ -229,6 +230,21 @@ def get_dummy_user_name():
return value


def get_os_user_auth_token():
cache_key = "OS_USER_AUTH_TOKEN"
value = value_cache.get(cache_key)
if value is None:
value = uuid4().hex
value_cache.set(cache_key, value)
return value


def os_user(auth_token):
if auth_token == get_os_user_auth_token():
return (get_dummy_user_name(), True)
return None, False


def is_active_network_metered():
ConnectivityManager = autoclass("android.net.ConnectivityManager")

Expand Down
12 changes: 3 additions & 9 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from uuid import uuid4

import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
from android_utils import get_dummy_user_name
from android_utils import get_os_user_auth_token
from android_utils import is_active_network_metered
from android_utils import os_user
from android_utils import share_by_intent
from jnius import autoclass
from kolibri.main import enable_plugin
Expand All @@ -25,13 +25,7 @@

loadUrl = Runnable(PythonActivity.mWebView.loadUrl)

auth_token_value = uuid4().hex


def os_user(auth_token):
if auth_token == auth_token_value:
return (get_dummy_user_name(), True)
return None, False
auth_token_value = get_os_user_auth_token()


class AppPlugin(SimplePlugin):
Expand Down
4 changes: 3 additions & 1 deletion src/taskworker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging

import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
from android_utils import os_user
from kolibri.main import initialize

from kolibri.plugins.app.utils import interface

initialize(skip_update=True)
interface.register(get_os_user=os_user)

logger = logging.getLogger(__name__)

Expand Down