Skip to content

Commit ce94eef

Browse files
committed
Register get_os_user for taskworker
1 parent e5064b9 commit ce94eef

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/android_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import re
4+
from uuid import uuid4
45
from functools import cache
56

67
from cryptography import x509
@@ -228,6 +229,19 @@ def get_dummy_user_name():
228229
value_cache.set(cache_key, value)
229230
return value
230231

232+
def get_os_user_auth_token():
233+
cache_key = "OS_USER_AUTH_TOKEN"
234+
value = value_cache.get(cache_key)
235+
if value is None:
236+
value = uuid4().hex
237+
value_cache.set(cache_key, value)
238+
return value
239+
240+
def os_user(auth_token):
241+
if auth_token == get_os_user_auth_token():
242+
return (get_dummy_user_name(), True)
243+
return None, False
244+
231245

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

src/main.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from uuid import uuid4
33

44
import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
5-
from android_utils import get_dummy_user_name
5+
from android_utils import os_user
6+
from android_utils import get_os_user_auth_token
67
from android_utils import is_active_network_metered
78
from android_utils import share_by_intent
89
from jnius import autoclass
@@ -25,14 +26,7 @@
2526

2627
loadUrl = Runnable(PythonActivity.mWebView.loadUrl)
2728

28-
auth_token_value = uuid4().hex
29-
30-
31-
def os_user(auth_token):
32-
if auth_token == auth_token_value:
33-
return (get_dummy_user_name(), True)
34-
return None, False
35-
29+
auth_token_value = get_os_user_auth_token()
3630

3731
class AppPlugin(SimplePlugin):
3832
def __init__(self, bus):

src/taskworker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import logging
22

33
import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
4+
from android_utils import os_user
45
from kolibri.main import initialize
5-
6+
from kolibri.plugins.app.utils import interface
67

78
initialize(skip_update=True)
9+
interface.register(get_os_user=os_user)
810

911
logger = logging.getLogger(__name__)
1012

0 commit comments

Comments
 (0)