Skip to content

Commit

Permalink
Add possibility to add a backup rules xml file (kivy#2208)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
tcdude authored and germn committed Mar 20, 2021
1 parent 432d9f9 commit c5753be
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ def make_package(args):
# Folder name for launcher (used by SDL2 bootstrap)
url_scheme = 'kivy'

# Copy backup rules file if specified and update the argument
if args.backup_rules:
res_xml_dir = join(res_dir, 'xml')
ensure_dir(res_xml_dir)
shutil.copy(join(args.private, args.backup_rules), res_xml_dir)
args.backup_rules = split(args.backup_rules)[1][:-4]

# Render out android manifest:
manifest_path = "src/main/AndroidManifest.xml"
render_args = {
Expand Down Expand Up @@ -758,6 +765,13 @@ def parse_args_and_make_package(args=None):
help='Set the launch mode of the main activity in the manifest.')
ap.add_argument('--allow-backup', dest='allow_backup', default='true',
help="if set to 'false', then android won't backup the application.")
ap.add_argument('--backup-rules', dest='backup_rules', default='',
help=('Backup rules for Android Auto Backup. Argument is a '
'filename containing xml. The filename should be '
'located relative to the private directory containing your source code '
'files (containing your main.py entrypoint). '
'See https://developer.android.com/guide/topics/data/'
'autobackup#IncludingFiles for more information'))
ap.add_argument('--no-optimize-python', dest='optimize_python',
action='store_false', default=True,
help=('Whether to compile to optimised .pyo files, using -OO '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
{% if debug %}android:debuggable="true"{% endif %}
android:icon="@drawable/icon"
android:allowBackup="{{ args.allow_backup }}"
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
android:hardwareAccelerated="true" >
{% for l in args.android_used_libs %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<application android:label="@string/app_name"
{% if debug %}android:debuggable="true"{% endif %}
android:icon="@drawable/icon"
android:allowBackup="true"
android:allowBackup="{{ args.allow_backup }}"
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
android:hardwareAccelerated="true" >
{% for l in args.android_used_libs %}
Expand All @@ -72,7 +73,7 @@

{% if service %}
<service android:name="org.kivy.android.PythonService"
android:process=":pythonservice"
android:process=":pythonservice"
android:exported="true"/>
{% endif %}
{% for name in service_names %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
-->
<application android:label="@string/app_name"
android:icon="@drawable/icon"
android:allowBackup="true"
android:allowBackup="{{ args.allow_backup }}"
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
Expand Down

0 comments on commit c5753be

Please sign in to comment.