Skip to content

Commit b3ac38a

Browse files
authored
Add possibility to add a backup rules xml file (kivy#2208)
* Add possibility to add a backup rules xml file Also enables the "allowBackup" flag for webview and service_only bootstraps, where the AndroidManifest.tmpl.xml would set it to a hardcoded "true". Use path relative to the private directory.
1 parent 7a934f3 commit b3ac38a

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ def make_package(args):
470470
# Folder name for launcher (used by SDL2 bootstrap)
471471
url_scheme = 'kivy'
472472

473+
# Copy backup rules file if specified and update the argument
474+
if args.backup_rules:
475+
res_xml_dir = join(res_dir, 'xml')
476+
ensure_dir(res_xml_dir)
477+
shutil.copy(join(args.private, args.backup_rules), res_xml_dir)
478+
args.backup_rules = split(args.backup_rules)[1][:-4]
479+
473480
# Render out android manifest:
474481
manifest_path = "src/main/AndroidManifest.xml"
475482
render_args = {
@@ -754,6 +761,13 @@ def parse_args_and_make_package(args=None):
754761
help='Set the launch mode of the main activity in the manifest.')
755762
ap.add_argument('--allow-backup', dest='allow_backup', default='true',
756763
help="if set to 'false', then android won't backup the application.")
764+
ap.add_argument('--backup-rules', dest='backup_rules', default='',
765+
help=('Backup rules for Android Auto Backup. Argument is a '
766+
'filename containing xml. The filename should be '
767+
'located relative to the private directory containing your source code '
768+
'files (containing your main.py entrypoint). '
769+
'See https://developer.android.com/guide/topics/data/'
770+
'autobackup#IncludingFiles for more information'))
757771
ap.add_argument('--no-optimize-python', dest='optimize_python',
758772
action='store_false', default=True,
759773
help=('Whether to compile to optimised .pyo files, using -OO '

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
{% if debug %}android:debuggable="true"{% endif %}
5959
android:icon="@drawable/icon"
6060
android:allowBackup="{{ args.allow_backup }}"
61+
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
6162
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
6263
android:hardwareAccelerated="true" >
6364
{% for l in args.android_used_libs %}

pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
<application android:label="@string/app_name"
4848
{% if debug %}android:debuggable="true"{% endif %}
4949
android:icon="@drawable/icon"
50-
android:allowBackup="true"
50+
android:allowBackup="{{ args.allow_backup }}"
51+
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
5152
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
5253
android:hardwareAccelerated="true" >
5354
{% for l in args.android_used_libs %}
@@ -72,7 +73,7 @@
7273

7374
{% if service %}
7475
<service android:name="org.kivy.android.PythonService"
75-
android:process=":pythonservice"
76+
android:process=":pythonservice"
7677
android:exported="true"/>
7778
{% endif %}
7879
{% for name in service_names %}

pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
-->
4848
<application android:label="@string/app_name"
4949
android:icon="@drawable/icon"
50-
android:allowBackup="true"
50+
android:allowBackup="{{ args.allow_backup }}"
51+
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
5152
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
5253
android:hardwareAccelerated="true"
5354
android:usesCleartextTraffic="true"

0 commit comments

Comments
 (0)