learningequality / kolibri-installer-android

Android wrapper for Kolibri.
MIT License
26 stars 22 forks source link

Add twisted manhole to provide remote provisioning/debugging shell #71

Closed jamalex closed 4 years ago

jamalex commented 4 years ago

For purposes of automating the provisioning, updating, etc of the Android application, and for purposes of debugging/testing code during development, this PR adds an SSH server (via twisted conch manhole) that runs within the app and allows incoming SSH connections to be dropped into a Python interpreter running within the context of the app. This allows arbitrary Kolibri code to be run (Django ORM, run_command etc) as well as other jnius-based system operations (within the app's permission scope).

jamalex commented 4 years ago

It looks like this does increase the size of the app somewhat, from 56MB to 64MB, due to the additional dependencies. It's possible we could do some pruning of the twisted code, for example, to exclude stuff we don't use and cut this size back down.

kollivier commented 4 years ago

The shell access works, but I'm seeing an error during startup:

07-27 10:28:39.198 31465 31801 I python : Unhandled Error 07-27 10:28:39.198 31465 31801 I python : Traceback (most recent call last): 07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/base.py", line 434, in fireEvent 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/defer.py", line 321, in addCallback 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/defer.py", line 311, in addCallbacks 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/defer.py", line 654, in _runCallbacks 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : --- --- 07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/base.py", line 447, in _continueFiring 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/base.py", line 1278, in _reallyStartRunning 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/posixbase.py", line 295, in _handleSignals 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/python-installs/Kolibri_dist/twisted/internet/base.py", line 1243, in _handleSignals 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.198 31465 31801 I python : File "/home/kevino/.local/share/python-for-android/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/signal.py", line 47, in signal 07-27 10:28:39.198 31465 31801 I python :
07-27 10:28:39.199 31465 31801 I python : builtins.ValueError: signal only works in main thread

Also, possibly related to this, calling exit() in the shell just threw an error message, so the only way I could find to close out the ssh connection and return to my terminal was to close the app. If it's just an issue with not being able to send signals to the process, we can probably just document for now, but this might warrant some further investigation as to whether or not twisted is designed to always be run on the main thread.

jamalex commented 4 years ago

builtins.ValueError: signal only works in main thread

Yeah, I saw this in logcat as well (every time it runs), but it didn't impact behavior for me.

Also, possibly related to this, calling exit() in the shell just threw an error message, so the only way I could find to close out the ssh connection and return to my terminal was to close the app.

Ah, I hadn't tried exit(). I always just use CTRL-D in the Python shell to exit, and that seems to work as expected for me here.