<?xml version="1.0" encoding="utf-8"?>
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
     com.gamemaker.game
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      android:versionCode="{{ args.numeric_version }}"
      android:versionName="{{ args.version }}"
      android:installLocation="auto">

    <supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens="true"
            android:anyDensity="true"
            {% if args.min_sdk_version >= 9 %}
            android:xlargeScreens="true"
            {% endif %}
    />

    <!-- Android 2.3.3 -->
    <uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />

    <!-- OpenGL ES 2.0 -->
    <uses-feature android:glEsVersion="0x00020000" />
    <uses-feature android:name="android.hardware.usb.host" />

    <!-- Allow writing to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Legacy permissions for bluetooth access (Android < 12) -->
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

    {% for perm in args.permissions %}
        <uses-permission android:name="{{ perm.name }}"{% if perm.maxSdkVersion %} android:maxSdkVersion="{{ perm.maxSdkVersion }}"{% endif %}{% if perm.usesPermissionFlags %} android:usesPermissionFlags="{{ perm.usesPermissionFlags }}"{% endif %} />
    {% endfor %}

    {% if args.wakelock %}
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    {% endif %}

    {% if args.billing_pubkey %}
    <uses-permission android:name="com.android.vending.BILLING" />
    {% endif %}

    {{ args.extra_manifest_xml }}

    <!-- Add android:extractNativeLibs="true" when building for API level >= 28 -->
    <application android:label="@string/app_name"
                 {% if debug %}android:debuggable="true"{% endif %}
                 android:icon="@mipmap/icon"
                 android:allowBackup="{{ args.allow_backup }}"
                 {% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
                 {{ args.extra_manifest_application_arguments }}
                 android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
                 android:hardwareAccelerated="true"
                 android:requestLegacyExternalStorage="true"
                 >
        {% for l in args.android_used_libs %}
        <uses-library android:name="{{ l }}" />
        {% endfor %}

        {% for m in args.meta_data %}
        <meta-data android:name="{{ m.split('=', 1)[0] }}" android:value="{{ m.split('=', 1)[-1] }}"/>{% endfor %}
        <meta-data android:name="wakelock" android:value="{% if args.wakelock %}1{% else %}0{% endif %}"/>

        <activity android:name="{{args.android_entrypoint}}"
                  android:label="@string/app_name"
                  android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode{% if args.min_sdk_version >= 8 %}|uiMode{% endif %}{% if args.min_sdk_version >= 13 %}|screenSize|smallestScreenSize{% endif %}{% if args.min_sdk_version >= 17 %}|layoutDirection{% endif %}{% if args.min_sdk_version >= 24 %}|density{% endif %}"
                  android:screenOrientation="user"
                  android:exported="true"
                  {% if args.activity_launch_mode %}
                  android:launchMode="{{ args.activity_launch_mode }}"
                  {% endif %}
                  >

            <intent-filter>
            {% if args.launcher %}            
                <action android:name="org.kivy.LAUNCH" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="{{ url_scheme }}" />
            {% else  %}
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            {% endif %}

            {% if args.home_app %}
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            {% endif %}
            </intent-filter>

            {%- if args.intent_filters -%}
            {{- args.intent_filters -}}
            {%- endif -%}
        </activity>

        {% if args.launcher %}
        <activity android:name="org.kivy.android.launcher.ProjectChooser"
                  android:icon="@mipmap/icon"
                  android:label="@string/app_name"
                  android:exported="true">

          <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>

        </activity>
        {% endif %}

        {% if service or args.launcher %}
        <service android:name="{{ args.service_class_name }}"
                 android:process=":pythonservice" />
        {% endif %}
        {% for name in service_names %}
        <service android:name="{{ args.package }}.Service{{ name|capitalize }}"
                 android:process=":service_{{ name }}" />
        {% endfor %}
        {% for name in native_services %}
        <service android:name="{{ name }}" />
        {% endfor %}

        {% if args.billing_pubkey %}
        <service android:name="org.kivy.android.billing.BillingReceiver"
                 android:process=":pythonbilling" />
        <receiver android:name="org.kivy.android.billing.BillingReceiver"
                  android:process=":pythonbillingreceiver"
                  android:exported="false">
            <intent-filter>
                <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
                <action android:name="com.android.vending.billing.RESPONSE_CODE" />
                <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
            </intent-filter>
        </receiver>
        {% endif %}
    {% for a in args.add_activity  %}
    <activity android:name="{{ a }}"></activity>
    {% endfor %}

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="io.unsigned.sideband.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <!-- ressource file to create -->
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths">  
        </meta-data>
    </provider>
    </application>

</manifest>
