Skip to content
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

Fix foreground notification being mandatory and more (attempt 2) #1888

Merged
1 commit merged into from Jul 28, 2019
Merged

Fix foreground notification being mandatory and more (attempt 2) #1888

1 commit merged into from Jul 28, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jun 26, 2019

  • Adds start_service_not_as_foreground() to avoid always displaying
    an associated notification without this being configurable at runtime.
    It only is configurable right now if setting the foreground property
    via --service, which cannot be done when using the simpler
    service/main.py entrypoint

  • Fixes service_only service code template not rendering .foreground
    correctly since it added an outdated, useless function name override

  • Fixes notification channel name which is visible to end user
    hardcoding "python" in its name which is not ideal for end user
    naming (since the average user might not even know what python is)

  • Fixes override of doStartForeground() leading to quite some
    error-prone code duplication

@ghost ghost added the WIP label Jun 26, 2019
@ghost ghost changed the title [WIP] Fix foreground notification being mandatory and more (attempt 2) Fix foreground notification being mandatory and more (attempt 2) Jul 8, 2019
@ghost ghost added need-testing and removed WIP labels Jul 8, 2019
@ghost
Copy link
Author

ghost commented Jul 21, 2019

@AndreMiras you seem to be using to be services a lot, could you possibly test if this pull request breaks any of your service things or works fine?

@ghost ghost requested a review from AndreMiras July 25, 2019 22:52
inclement
inclement previously approved these changes Jul 26, 2019
Copy link
Member

@inclement inclement left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From looking at the code it looks fine to me, but I don't use services much so I don't have a good idea of what could break. @AndreMiras any thoughts?

One issue we've had with Services in the past is from calls to android apis that get deprecated or which are too new for some devices - I don't think it's really because of the services so much as simply that it's one of the few places where we routinely make use of more dynamic android apis. Do you think there's any chance of that kind of issue here? Maybe the CI is already doing a good job here since we test the vital minapi=21 targetapi>=26 cases.

@AndreMiras
Copy link
Member

Thanks @inclement for reviewing and thank you @Jonast for pinging me. I'll give it a try hopefully over the weekend so you can merge it.
I'll keep you posted

@ghost
Copy link
Author

ghost commented Jul 26, 2019

@inclement good point! for what it's worth I'm pretty sure I didn't touch any of the SDK/NDK/Android-facing APIs but only all the p4a handling before, but one can never be safe enough so I wouldn't mind more testing. I tested with Android 8.1 / API level 27 on a real device (the app being built with target api 27 and min-api 21) and with a side service to an SDL2 bootstrap - so I didn't test service_only because I have no app that uses that

@AndreMiras
Copy link
Member

I'm getting build errors.

[INFO]:    Selecting java build tool:
[INFO]:    Detected highest available build tools version to be 29.0.1
[INFO]:        Building with gradle, as gradle executable is present
[DEBUG]:   -> running gradlew assembleDebug
[DEBUG]:
[DEBUG]:        > Task :processDebugManifest 
[DEBUG]:        /home/andre/workspace/EtherollApp/.buildozer/android/platform/build/dists/etheroll/src/main/AndroidManifest.xml:35:5-81 Warning:
[DEBUG]:                Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:35:5-81 duplicated with element declared at AndroidManifest.xml:28:5-81
[DEBUG]:
[DEBUG]:        > Task :compileDebugJavaWithJavac FAILED
[DEBUG]:        /home/andre/workspace/EtherollApp/.buildozer/android/platform/build/dists/etheroll/src/main/java/com/github/andremiras/etheroll/ServiceService.java:11: error: cannot find symbol
[DEBUG]:            @override
[DEBUG]:             ^
[DEBUG]:          symbol:   class override
[DEBUG]:          location: class ServiceService
[DEBUG]:        Note: Some input files use or override a deprecated API.
[DEBUG]:        Note: Recompile with -Xlint:deprecation for details.
[DEBUG]:        Note: Some input files use unchecked or unsafe operations.
[DEBUG]:        Note: Recompile with -Xlint:unchecked for details.
[DEBUG]:        1 error
[DEBUG]:
[DEBUG]:
[DEBUG]:        FAILURE: Build failed with an exception.
[DEBUG]:
[DEBUG]:        * What went wrong:
[DEBUG]:        Execution failed for task ':compileDebugJavaWithJavac'.
[DEBUG]:        > Compilation failed; see the compiler error output for details.
[DEBUG]:
[DEBUG]:        * Try:
[DEBUG]:        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[DEBUG]:
[DEBUG]:        * Get more help at https://help.gradle.org
[DEBUG]:
[DEBUG]:        BUILD FAILED in 1s
[DEBUG]:        15 actionable tasks: 15 executed

See full build.log and buildozer spec attached

notification = builder.build();
}
startForeground({{ service_id }}, notification);
@override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be @Override with uppercase O it seems

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no that's no good 😮 that is why I want to get some of these merged 😱 I must have done something weird rebasing, I'll do a manual comparison to my rebased combined strange branch I actually used for build and make sure I didn't miss out anything important since apparently at least one rebase conflict ended up weird 😬

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that probably mean we should introduce service compilation to our CI. But at the same time it's time/resources every time we add something new to it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to add service/main.py to an existing test app? I think this particular bug should also have been triggered if there had been a service used in addition rather than a standalone service service_only test app

Copy link
Author

@ghost ghost Jul 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, fascinating! This is not actually a rebase error, it seems when using service/main.py (which is what I tested) this indeed isn't rendered out. So that's the reason, I guess it needed a service_only test to show up - I assume that's what you tested with?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's probably the named extra services with the --service parameter. We have three ways to do services, I forgot (service/main.py with no name which is what I tested, --service with named services, and service_only)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, I'm using the --service service:service/main.py, see from the the logs.
Complete command was:

/usr/bin/python3 -m pythonforandroid.toolchain apk --debug --bootstrap=sdl2 --dist_name etheroll --name Etheroll --version 2019.0624 --package com.github.andremiras.etheroll --android_api 27 --minsdk 21 --ndk-api 21 --private /home/andre/workspace/EtherollApp/.buildozer/android/app --permission INTERNET --permission WRITE_EXTERNAL_STORAGE --presplash /home/andre/workspace/EtherollApp/docs/images/etheroll-logo.png --icon /home/andre/workspace/EtherollApp/docs/images/icon.png --orientation portrait --window --service service:service/main.py --copy-libs --local-recipes /home/andre/workspace/EtherollApp/src/python-for-android/recipes --blacklist /home/andre/workspace/EtherollApp/blacklist.txt --arch armeabi-v7a --color=always --storage-dir="/home/andre/workspace/EtherollApp/.buildozer/android/platform/build" --ndk-api=21

def start_service(title=None, description=None, arg=None,
as_foreground=True):
from jnius import autoclass
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also already available at module level.
https://github.com/kivy/python-for-android/blob/v2019.07.08/pythonforandroid/recipes/android/src/android/_android.pyx#L164
That probably requires some refactor though 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I've kept the mActivity for now, seems a bit ugly to have that outside the function and rely on that being available

@inclement
Copy link
Member

@AndreMiras When making many comments, could you use 'start a review' to submit them all at once? When they're made as individual reviews they cause an email notification for every one!

@AndreMiras
Copy link
Member

Will try to next time, thanks for the heads up 😄

AndreMiras
AndreMiras previously approved these changes Jul 28, 2019
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good 👏
Do you mind rebasing to upstream/develop before we can merge?
This is just to make sure tests introduced in #1933 are passing

- Adds start_service_not_as_foreground() to avoid always displaying
  an associated notification without this being configurable at runtime.
  It only is configurable right now if setting the foreground property
  via --service, which cannot be done when using the simpler
  service/main.py entrypoint

- Fixes service_only service code template not rendering .foreground
  correctly since it added an outdated, useless function name override

- Fixes notification channel name which is visible to end user
  hardcoding "python" in its name which is not ideal for end user
  naming (since the average user might not even know what python is)

- Fixes override of doStartForeground() leading to quite some
  error-prone code duplication
@ghost
Copy link
Author

ghost commented Jul 28, 2019

@AndreMiras I just rebased, and I actually ran into the same problem as with the SDL2 pull request: test_folder_exist in tests/test_distribution.py incorrectly doesn't set mock_exists.return_value = False which leads to test failure since the code tries to open a non-existing file, and if I fix it then I also need to change mock_exists.assert_called_once_with to mock_exists.assert_called_with or it'll fail complaining it was called twice 🤷‍♀️ so this problem seems to be actually unrelated to any of my changes in any of these two pull requests

Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rebase, feel free to merge it once the tests turn green

@ghost ghost merged commit 308df31 into kivy:develop Jul 28, 2019
@ghost ghost deleted the fix_forced_service_foreground2 branch July 28, 2019 15:06
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants