-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work manager integration #119
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
42b6324
Define default tasks setup and hooks.
rtibbles f1ef772
Remove use of kolibri workers.
rtibbles 4860e43
Add basic task worker integration.
rtibbles 831403a
Lint and reorganize code.
rtibbles f07c67d
Update to latest p4a commit.
rtibbles 5f489b5
Add expedited processing for high priority tasks.
rtibbles 2864e56
Commit built bootstrap to allow for direct editing in Android Studio.
rtibbles a0f1097
Move notification channel creation into main activity.
rtibbles d9d785d
Show notification statuses when available.
rtibbles 8f4b901
Set update hooks to ensure that changes in status trigger appropriately.
rtibbles d02edc0
Update build scripts to preserve local edits to bootstrap.
rtibbles 83b796d
Update kolibri notification icon files.
rtibbles 426ac58
Make long running tasks get set to foreground.
rtibbles f2db879
Update README and make command.
rtibbles ac09bf8
Update python for android to latest release.
rtibbles 8fc35e8
Add a notification color.
rtibbles 290ec04
Make notification explicitly silent.
rtibbles 0703d2a
Remove unnecessary asset unpacking.
rtibbles 3d5c953
Properly handle finite repeating task rescheduling.
rtibbles bb44d03
Delete the kolibri dist before rebuilding.
rtibbles 679f489
Simplify loadLibraries and prevent unnecessary repeated load library …
rtibbles 7fb01af
Do not just exit the system process, interrupt the Python thread inst…
rtibbles ebab523
Add more specific logging.
rtibbles a509b4f
Count active python threads in the process to prevent premature teard…
rtibbles 9e60047
Add util for getting context.
rtibbles 002a696
Add informative tags to queued tasks.
rtibbles 04e91a9
Update hooks to use storage hook.
rtibbles f890001
Handle task clearing.
rtibbles cd06417
Properly setup android app plugin.
rtibbles 8276578
Ensure job isn't currently running before trying to clear it.
rtibbles c5b0f14
Remove code that fails to remove notifications on clear.
rtibbles 3dad265
Update clear task handler to consistent signature.
rtibbles 803f639
Remove potentially destructive System.exit call.
rtibbles 14a7159
Move handling of notifications to a separate class.
rtibbles f24b159
Re add system.exit to destroy process once we've torn down.
rtibbles ffaffd2
Update to latest python for android.
rtibbles 8de5db7
Prevent module level autoclass declarations that could be shared acro…
rtibbles 897bb77
Defer library loading and teardown to parent service.
rtibbles 7e74447
Update makefile and readme for more explanation and effective pyc del…
rtibbles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ This project was primarily developed on Docker, so this method is more rigorousl | |
|
||
4. The generated APK will end up in the `bin/` folder. | ||
|
||
## Building for Development | ||
## Development Flow | ||
|
||
1. Install the Android SDK and Android NDK. | ||
1. Setup a Python virtual environment in which to do development. The Kolibri developer documentation has a [How To guide for doing this with pyenv](https://kolibri-dev.readthedocs.io/en/develop/howtos/pyenv_virtualenv.html) but any Python virtualenv should work. | ||
|
||
2. Install the Android SDK and Android NDK. | ||
|
||
Set the `ANDROID_HOME` environment variable to the location you would like these to be installed, e.g.: | ||
`export ANDROID_HOME=./android_root` | ||
|
@@ -25,22 +27,33 @@ Run `make setup`. | |
|
||
Follow the instructions from the command to set the additional environment variables. | ||
|
||
2. Install the Python dependencies: | ||
3. Install the Python dependencies: | ||
|
||
`pip install -r requirements.txt` | ||
|
||
3. Ensure you have all [necessary packages for Python for Android](https://python-for-android.readthedocs.io/en/latest/quickstart/#installing-dependencies). | ||
4. Ensure you have all [necessary packages for Python for Android](https://python-for-android.readthedocs.io/en/latest/quickstart/#installing-dependencies). | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth above these pieces suggesting a venv? |
||
5. Build or download a Kolibri WHL file, and place it in the `whl/` directory. | ||
|
||
To download a Kolibri WHL file, you can use `make get-whl whl=<URL>` from the command line. It will download it and put it in the correct directory. | ||
|
||
6. By default the APK/AAB will be built for most architectures supported by Python for Android. To build for a smaller set of architectures, set the `ARCHES` environment variable. Run `p4a archs` to see the available targets. | ||
|
||
7. Run `make p4a_android_project` this will do all of the Python for Android setup up until the point of actually building an APK or AAB. | ||
|
||
N.B. You will need to rerun this step any time you update the Kolibri WHL file you are using, or any time you update the Python code in this repository. | ||
|
||
8. You can now run Android Studio and open the folder `python-for-android/dists/kolibri` as the project folder to work from. You should be able to make updates to Java code, resource files, etc. using Android Studio, and build and run the project using Android Studio, including launching into emulators and real physical devices. | ||
|
||
4. Build or download a Kolibri WHL file, and place it in the `whl/` directory. | ||
N.B. When you rerun step 7, it will complain loudly and exit early if you have uncommitted changes in the python-for-android folder. Any changes should be committed (even if in a temporary commit) before rerunning this step, as we use git stash to undo any changes in the Android project caused by the Python for Android project bootstrapping process. Also, when rerunning step 5, the Android version will not have incremented, meaning that any emulator or physical device will need to have Kolibri explicitly uninstalled for any changes to Python code to be updated on install. | ||
|
||
To download a Kolibri WHL file, you can use `make whl=<URL>` from the command line. It will download it and put it in the correct directory. | ||
## Debugging the app | ||
|
||
1. When running the app from Android Studio, if you are using an emulator, it is possible that there will be many warning messages due to GPU emulation. In the logcat tab, update the filter to this `package:mine & -tag:eglCodecCommon` to hide those errors from the logcat output. | ||
|
||
5. By default the APK will be built for most architectures supported by | ||
Python for Android. To build for a smaller set of architectures, set | ||
the `ARCHES` environment variable. Run `p4a archs` to see the | ||
available targets. | ||
## Building from the commandline | ||
|
||
6. Run `make kolibri.apk.unsigned` to build the apk. Watch for success at the end, or errors, which might indicate missing build dependencies or build errors. If successful, there should be an APK in the `dist/` directory. | ||
1. Run `make kolibri.apk.unsigned` to build the development apk. Watch for success at the end, or errors, which might indicate missing build dependencies or build errors. If successful, there should be an APK in the `dist/` directory. | ||
|
||
## Installing the apk | ||
1. Connect your Android device over USB, with USB Debugging enabled. | ||
|
@@ -52,8 +65,6 @@ To download a Kolibri WHL file, you can use `make whl=<URL>` from the command li | |
|
||
1. Run `adb shell am start -n org.learningequality.Kolibri/org.kivy.android.PythonActivity` | ||
|
||
## Debugging the app | ||
|
||
### Server Side | ||
Run `adb logcat -v brief python:D *:F` to get all debug logs from the Kolibri server | ||
|
||
|
@@ -102,3 +113,9 @@ Host kolibri-android | |
HostkeyAlgorithms +ssh-rsa | ||
``` | ||
Then, you should be able to just do “ssh kolibri-android” | ||
|
||
## Updating Python for Android | ||
|
||
We maintain a fork of Python for Android that includes various changes we have made to the source code to support our specific needs. As P4A make new releases, we make a branch from the latest release tag, and then replay the commits on top of this tag using an interactive rebase. Sometimes, this allows us to drop commits as new features are merged into P4A. Our naming convention for the branch on our fork is `from_upstream_<tag_name>`. Any time we push new commits to this branch, we must also update the pinned commit in `requirements.txt`, so that we are always building with a completely predictable version of Python for Android. | ||
|
||
By default we stash any updates to our bootstrap coming from Python for Android, because mostly we have overwritten their bootstrap code to make the relevant changes for us. If there are upstream changes to code we have committed in this repo from the bootstraps, then if the diff is small, it is probably simplest to manually copy in these changes to our committed code. If the diff is larger, or the developer fancies exercising some git-fu, then the make command `make update_project_from_p4a` will update the bootstrap from Python for Android, and not stash any changes that introduces. Through judicious change reversion and diffing, the appropriate changes can then be applied. Here be dragons. |
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
python-for-android/dists/kolibri/src/main/assets/_loading_style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
h1 { | ||
font-size: 30px; | ||
color: blue; | ||
font-weight: bold; | ||
text-align:center; | ||
} | ||
|
||
h2 { | ||
text-align:center; | ||
} | ||
|
||
button { | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: block; | ||
margin-top: 50px; | ||
font-size: 30px; | ||
} | ||
|
||
|
||
/* Loader from http://projects.lukehaas.me/css-loaders/#load1 */ | ||
|
||
.loader, | ||
.loader:before, | ||
.loader:after { | ||
background: #aaaaff; | ||
-webkit-animation: load1 1s infinite ease-in-out; | ||
animation: load1 1s infinite ease-in-out; | ||
width: 1em; | ||
height: 4em; | ||
} | ||
.loader:before, | ||
.loader:after { | ||
position: absolute; | ||
top: 0; | ||
content: ''; | ||
} | ||
.loader:before { | ||
left: -1.5em; | ||
} | ||
.loader { | ||
text-indent: -9999em; | ||
margin: 8em auto; | ||
position: relative; | ||
font-size: 11px; | ||
-webkit-animation-delay: -0.16s; | ||
animation-delay: -0.16s; | ||
} | ||
.loader:after { | ||
left: 1.5em; | ||
-webkit-animation-delay: -0.32s; | ||
animation-delay: -0.32s; | ||
} | ||
@-webkit-keyframes load1 { | ||
0%, | ||
80%, | ||
100% { | ||
box-shadow: 0 0 #aaaaff; | ||
height: 4em; | ||
} | ||
40% { | ||
box-shadow: 0 -2em #aaaaff; | ||
height: 5em; | ||
} | ||
} | ||
@keyframes load1 { | ||
0%, | ||
80%, | ||
100% { | ||
box-shadow: 0 0 #aaaaff; | ||
height: 4em; | ||
} | ||
40% { | ||
box-shadow: 0 -2em #aaaaff; | ||
height: 5em; | ||
} | ||
} |
Binary file added
BIN
+1.06 KB
...n-for-android/dists/kolibri/src/main/java/kolibri/org/jnius/NativeInvocationHandler.class
Binary file not shown.
41 changes: 41 additions & 0 deletions
41
...on-for-android/dists/kolibri/src/main/java/kolibri/org/jnius/NativeInvocationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jnius; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
|
||
public class NativeInvocationHandler implements InvocationHandler { | ||
static boolean DEBUG = false; | ||
private long ptr; | ||
|
||
public NativeInvocationHandler(long ptr) { | ||
this.ptr = ptr; | ||
} | ||
|
||
public Object invoke(Object proxy, Method method, Object[] args) { | ||
if ( DEBUG ) { | ||
System.out.print("+ java:invoke(<proxy>, "); | ||
// don't call it, or recursive lookup/proxy will go! | ||
//System.out.print(proxy); | ||
//System.out.print(", "); | ||
System.out.print(method); | ||
System.out.print(", "); | ||
System.out.print(args); | ||
System.out.println(")"); | ||
System.out.flush(); | ||
} | ||
|
||
Object ret = invoke0(proxy, method, args); | ||
|
||
if ( DEBUG ) { | ||
System.out.print("+ java:invoke returned: "); | ||
System.out.println(ret); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
public long getPythonObjectPointer() { | ||
return ptr; | ||
} | ||
|
||
native Object invoke0(Object proxy, Method method, Object[] args); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just displayed as a warning? Or does the
exit 1
make it bail, I guess? Would one not want to be able to build while the P4A is still being iterated.Probably I'm also misinterpreting these new make targets. Could you add a one-line comment on each as to what it does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can build while the Java files are being actively edited - we just can't reimport from the bootstrap while that is the case. Will add some comments to make it clearer.