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

<!--
Gradle v7.4 / Android Gradle Plugin v7.3.0 recommend:
- removing "package" from AndroidManifest.xml
- adding it as "namespace" in app/build.gradle
This change eventually prevents building the app with Flutter v3.3.3.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="deckers.thibault.aves"
    android:installLocation="auto">

    <!--
    Scoped storage on Android 10 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.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="29"
        tools:ignore="ScopedStorage" />

    <!-- 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" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <!-- to show foreground service progress via notification -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!-- to access media with original metadata with scoped storage (Android >=10) -->
    <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

    <!-- TODO TLAD remove this permission when this is fixed: https://github.com/flutter/flutter/issues/42451 -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- for API <26 -->
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

    <!-- allow install on API 19, but Google Maps is from API 20 -->
    <uses-sdk tools:overrideLibrary="io.flutter.plugins.googlemaps" />

    <!-- 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>
        <!--
        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:fullBackupOnly="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        tools:targetApi="o">
        <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:theme="@style/NormalTheme"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <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.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>

        <service
            android:name=".AnalysisService"
            android:description="@string/analysis_service_description"
            android:exported="false" />

        <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.3.0, background blur & icon shading fail with Impeller -->
        <meta-data
            android:name="io.flutter.embedding.android.EnableImpeller"
            android:value="false" />
    </application>
</manifest>
