Skip to content

Commit 52f4bbc

Browse files
authored
Merge pull request #1586 from opacam/minor-fix-bootstraps
Corrections for `Fix bootstraps for webview and service_only` (recently merged)
2 parents d0798b2 + cb94ed5 commit 52f4bbc

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,11 @@ def make_package(args):
336336
with open(args.intent_filters) as fd:
337337
args.intent_filters = fd.read()
338338

339-
# if get_bootstrap_name() == "sdl2":
340-
args.add_activity = args.add_activity or []
341-
args.activity_launch_mode = args.activity_launch_mode or ''
339+
if not args.add_activity:
340+
args.add_activity = []
341+
342+
if not args.activity_launch_mode:
343+
args.activity_launch_mode = ''
342344

343345
if args.extra_source_dirs:
344346
esd = []
@@ -536,6 +538,9 @@ def parse_args(args=None):
536538
ap.add_argument('--icon', dest='icon',
537539
help=('A png file to use as the icon for '
538540
'the application.'))
541+
ap.add_argument('--service', dest='services', action='append',
542+
help='Declare a new service entrypoint: '
543+
'NAME:PATH_TO_PY[:foreground]')
539544
if get_bootstrap_name() != "service_only":
540545
ap.add_argument('--presplash', dest='presplash',
541546
help=('A jpeg file to use as a screen while the '
@@ -564,10 +569,6 @@ def parse_args(args=None):
564569
'https://developer.android.com/guide/'
565570
'topics/manifest/'
566571
'activity-element.html'))
567-
else:
568-
ap.add_argument('--service', dest='services', action='append',
569-
help='Declare a new service entrypoint: '
570-
'NAME:PATH_TO_PY[:foreground]')
571572
ap.add_argument('--wakelock', dest='wakelock', action='store_true',
572573
help=('Indicate if the application needs the device '
573574
'to stay on'))
@@ -687,7 +688,7 @@ def _read_configuration():
687688
if args.meta_data is None:
688689
args.meta_data = []
689690

690-
if (not hasattr(args, 'services')) or args.services is None:
691+
if args.services is None:
691692
args.services = []
692693

693694
if args.try_system_python_compile:

pythonforandroid/bootstraps/service_only/build/templates/Service.tmpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package {{ args.package }};
22

3+
import android.os.Binder;
4+
import android.os.IBinder;
35
import android.content.Intent;
46
import android.content.Context;
57
import org.kivy.android.PythonService;
@@ -31,7 +33,7 @@ public boolean getStartForeground() {
3133
{% endif %}
3234

3335
public static void start(Context ctx, String pythonServiceArgument) {
34-
String argument = ctx.getFilesDir().getAbsolutePath();
36+
String argument = ctx.getFilesDir().getAbsolutePath() + "/app";
3537
Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
3638
intent.putExtra("androidPrivate", argument);
3739
intent.putExtra("androidArgument", argument);
@@ -45,7 +47,7 @@ public static void start(Context ctx, String pythonServiceArgument) {
4547
intent.putExtra("pythonServiceArgument", pythonServiceArgument);
4648
ctx.startService(intent);
4749
}
48-
50+
4951
public static void stop(Context ctx) {
5052
Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
5153
ctx.stopService(intent);
@@ -58,7 +60,7 @@ public static void stop(Context ctx) {
5860
public IBinder onBind(Intent intent) {
5961
return mBinder;
6062
}
61-
63+
6264
/**
6365
* Class used for the client Binder. Because we know this service always
6466
* runs in the same process as its clients, we don't need to deal with IPC.

testapps/setup_testapp_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import find_packages
44

55
options = {'apk': {'debug': None,
6-
'requirements': 'python2,genericndkbuild',
6+
'requirements': 'python2,genericndkbuild,pyjnius',
77
'android-api': 27,
88
'ndk-api': 21,
99
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
@@ -12,6 +12,7 @@
1212
'bootstrap': 'service_only',
1313
'permissions': ['INTERNET', 'VIBRATE'],
1414
'arch': 'armeabi-v7a',
15+
'service': 'time:p4atime.py',
1516
}}
1617

1718
package_data = {'': ['*.py']}
@@ -21,7 +22,7 @@
2122

2223
setup(
2324
name='testapp_service',
24-
version='1.0',
25+
version='1.1',
2526
description='p4a service testapp',
2627
author='Alexander Taylor',
2728
author_email='[email protected]',

testapps/testapp_service/main.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print('main.py was successfully called')
1+
print('Service Test App main.py was successfully called')
22

33
import sys
44
print('python version is: ', sys.version)
@@ -11,17 +11,9 @@
1111
print(i, sqrt(i))
1212

1313
print('Just printing stuff apparently worked, trying a simple service')
14-
import datetime, threading, time
1514

16-
next_call = time.time()
17-
18-
19-
def service_timer():
20-
global next_call
21-
print('P4a datetime service: {}'.format(datetime.datetime.now()))
22-
next_call = next_call + 1
23-
threading.Timer(next_call - time.time(), service_timer).start()
24-
25-
26-
print('Starting the service timer...')
27-
service_timer()
15+
from jnius import autoclass
16+
service = autoclass('org.test.testapp_service.ServiceTime')
17+
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
18+
argument = 'test argument ok'
19+
service.start(mActivity, argument)

testapps/testapp_service/p4atime.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import datetime
2+
import threading
3+
import time
4+
from os import environ
5+
argument = environ.get('PYTHON_SERVICE_ARGUMENT', '')
6+
print('p4atime.py was successfully called with argument: "{}"'.format(argument))
7+
8+
next_call = time.time()
9+
10+
11+
def service_timer():
12+
global next_call
13+
print('P4a datetime service: {}'.format(datetime.datetime.now()))
14+
next_call = next_call + 1
15+
threading.Timer(next_call - time.time(), service_timer).start()
16+
17+
18+
print('Starting the service timer...')
19+
service_timer()

0 commit comments

Comments
 (0)