<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="auto">

    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.software.leanback"
        android:required="false" />

    <!--
    TODO TLAD [Android 14 (API 34)] request/handle READ_MEDIA_VISUAL_USER_SELECTED permission
    cf https://developer.android.com/about/versions/14/changes/partial-photo-video-access
    -->
    <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <!--
    Scoped storage on Android 10 (API 29) is inconvenient because users need to confirm edition on each individual file.
    So we request `WRITE_EXTERNAL_STORAGE` until Android 10 (API 29), and enable `requestLegacyExternalStorage`
    -->
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="29"
        tools:ignore="ScopedStorage" />

    <!-- to access media with original metadata with scoped storage (API >=29) -->
    <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
    <!-- to analyze media in a service -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <!-- to fetch map tiles -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- from Android 12 (API 31), users can optionally grant access to the media management special permission -->
    <uses-permission
        android:name="android.permission.MANAGE_MEDIA"
        tools:ignore="ProtectedPermissions" />
    <!-- to show foreground service progress via notification -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <!-- to change wallpaper -->
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <!-- to unlock vaults (API >=28) -->
    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <!-- TODO TLAD remove this permission when this is fixed: https://github.com/flutter/flutter/issues/42451 -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
        android:maxSdkVersion="25" />

    <!--
    allow install on API 19, despite the `minSdkVersion` declared in dependencies:
    - Google Maps is from API 20
    - the Security library is from API 21
    - FFmpegKit for Flutter is from API 24
    -->
    <uses-sdk tools:overrideLibrary="io.flutter.plugins.googlemaps, androidx.security:security-crypto, com.arthenica.ffmpegkit.flutter" />

    <!-- from Android 11, we should define <queries> to make other apps visible to this app -->
    <queries>
        <intent>
            <action android:name="android.intent.action.MAIN" />
        </intent>
        <!-- necessary to resolve image editor apps that are not visible in the launcher -->
        <intent>
            <action android:name="android.intent.action.EDIT" />
            <data android:mimeType="image/*" />
        </intent>
        <!-- necessary to resolve video editor apps that are not visible in the launcher -->
        <intent>
            <action android:name="android.intent.action.EDIT" />
            <data android:mimeType="video/*" />
        </intent>
        <!--
        from Android 11, `url_launcher` method `canLaunchUrl()` will return false,
        if appropriate intents are not declared, cf https://pub.dev/packages/url_launcher#configuration=
        -->
        <!-- to open https URLs -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>
    </queries>

    <application
        android:allowBackup="true"
        android:appCategory="image"
        android:banner="@drawable/banner"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/full_backup_content"
        android:fullBackupOnly="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        tools:targetApi="s">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:supportsPictureInPicture="true"
            android:theme="@style/NormalTheme"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
                <data android:mimeType="vnd.android.cursor.dir/video" />
            </intent-filter>
            <intent-filter tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
                <data android:mimeType="vnd.android.cursor.dir/video" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.android.camera.action.REVIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
                <data android:mimeType="vnd.android.cursor.dir/video" />
            </intent-filter>
            <!--
            <intent-filter>
                <action android:name="android.intent.action.EDIT" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
            </intent-filter>
            -->
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />

                <category android:name="android.intent.category.OPENABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
                <data android:mimeType="vnd.android.cursor.dir/video" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
                <data android:mimeType="vnd.android.cursor.dir/video" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

        <activity
            android:name=".ScreenSaverSettingsActivity"
            android:exported="true"
            android:theme="@style/NormalTheme" />

        <activity
            android:name=".WallpaperActivity"
            android:exported="true"
            android:label="@string/wallpaper"
            android:theme="@style/NormalTheme">
            <intent-filter>
                <action android:name="android.intent.action.ATTACH_DATA" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.SET_WALLPAPER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <!-- exported for Android API 19 launcher to access this activity -->
        <activity
            android:name=".HomeWidgetSettingsActivity"
            android:exported="true"
            android:theme="@style/NormalTheme">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".HomeWidgetProvider"
            android:exported="false"
            android:label="@string/app_widget_label">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/app_widget_info" />
        </receiver>

        <receiver
            android:name="androidx.media.session.MediaButtonReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>

        <service
            android:name=".MediaPlaybackService"
            android:exported="false"
            android:foregroundServiceType="mediaPlayback">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>

        <service
            android:name=".ScreenSaverService"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DREAM_SERVICE">
            <intent-filter>
                <action android:name="android.service.dreams.DreamService" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.service.dream"
                android:resource="@xml/screen_saver" />
        </service>

        <!-- file provider to share files having a file:// URI -->
        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.file_provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>

        <provider
            android:name=".SearchSuggestionsProvider"
            android:authorities="@string/search_provider"
            android:exported="true"
            tools:ignore="ExportedContentProvider" />

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${googleApiKey}" />
        <meta-data
            android:name="deckers.thibault.aves.huawei.API_KEY"
            android:value="${huaweiApiKey}" />
        <meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="false" />
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <!-- as of Flutter v3.10.1 (stable) / v3.12.0-15.0.pre.105 (master),
        Impeller badly renders text, fails to render videos, and crashes with Google Maps -->
        <meta-data
            android:name="io.flutter.embedding.android.EnableImpeller"
            android:value="false" />
    </application>
</manifest>
