<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

    <uses-permission android:name="android.permission.health.READ_WEIGHT" />
    <uses-permission android:name="android.permission.health.WRITE_WEIGHT" />
    <uses-permission android:name="android.permission.health.READ_NUTRITION" />
    <uses-permission android:name="android.permission.health.WRITE_NUTRITION" />
    <uses-permission android:name="android.permission.health.READ_BODY_FAT" />
    <uses-permission android:name="android.permission.health.WRITE_BODY_FAT" />
    <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
    <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
    <uses-permission android:name="android.permission.health.READ_STEPS" />
    <uses-permission android:name="android.permission.health.READ_EXERCISE" />
    <uses-permission android:name="android.permission.health.WRITE_HEIGHT" />
    <uses-permission android:name="android.permission.health.READ_SLEEP" />
    <uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
    <uses-permission android:name="android.permission.health.READ_HYDRATION" />
    <uses-permission android:name="android.permission.health.WRITE_HYDRATION" />
    <uses-permission android:name="android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND" />
    <uses-permission android:name="android.permission.health.READ_HEALTH_DATA_HISTORY" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.microphone"
        android:required="false" />

    <queries>
        <package android:name="com.google.android.apps.healthdata" />
        <package android:name="dev.soupslurpr.transcribro" />
        <intent>
            <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
        </intent>
        <!-- Required for SpeechRecognizer on Android 11+ (package visibility). -->
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>

    <application
        android:name=".ChompassApp"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher_teal"
        android:label="@string/app_name"
        android:localeConfig="@xml/locale_config"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_teal"
        android:supportsRtl="true"
        android:theme="@style/Theme.Chompass">
        <!-- LiteRT-LM GPU (OpenCL) — required on Android 12+ to dlopen vendor drivers. -->
        <uses-native-library android:name="libvndksupport.so" android:required="false" />
        <uses-native-library android:name="libOpenCL.so" android:required="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:windowSoftInputMode="adjustResize"
            android:theme="@style/Theme.Chompass.Splash">
            <!-- Shared-meal deep link: chompass://add-meal?d=… (also accepts nofud:// and fudai:// for import) -->
            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="chompass" android:host="add-meal" />
            </intent-filter>
            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="nofud" android:host="add-meal" />
            </intent-filter>
            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="fudai" android:host="add-meal" />
            </intent-filter>
            <!-- Image share filters live on launcher aliases (not here): sharing to
                 MainActivity while the task was started via an alias breaks
                 singleTop matching and a stopped HomeScreen can steal the inbox. -->
        </activity>

        <activity-alias
            android:name=".LauncherTeal"
            android:enabled="true"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_teal"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_teal"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherBlue"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_blue"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_blue"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherGreen"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_green"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_green"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherPurple"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_purple"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_purple"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherBabyPink"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_baby_pink"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_baby_pink"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherOrange"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_orange"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_orange"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherIndigo"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_indigo"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_indigo"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".LauncherGraphite"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_launcher_graphite"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_graphite"
            android:targetActivity=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
            </intent-filter>
        </activity-alias>

        <!-- Health Connect opens this privacy-policy entry point on Android 13 and below.
             Without it, the standalone Health Connect app cannot reliably discover Chompass
             as a permission-capable app. -->
        <activity
            android:name=".HealthPermissionsRationaleActivity"
            android:excludeFromRecents="true"
            android:exported="true"
            android:noHistory="true">
            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
            </intent-filter>
        </activity>

        <activity-alias
            android:name="ViewPermissionUsageActivity"
            android:exported="true"
            android:permission="android.permission.START_VIEW_PERMISSION_USAGE"
            android:targetActivity=".HealthPermissionsRationaleActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
                <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
            </intent-filter>
        </activity-alias>

        <receiver
            android:name=".services.ReminderReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <receiver
            android:name=".widget.CalorieWidgetReceiver"
            android:exported="true"
            android:label="@string/widget_calorie_label">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/calorie_widget_info" />
        </receiver>

        <receiver
            android:name=".widget.ProteinWidgetReceiver"
            android:exported="true"
            android:label="@string/widget_protein_label">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/protein_widget_info" />
        </receiver>

        <receiver
            android:name=".widget.AllMetricsWidgetReceiver"
            android:exported="true"
            android:label="@string/widget_all_metrics_label">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/all_metrics_widget_info" />
        </receiver>

        <receiver
            android:name=".widget.WaterWidgetReceiver"
            android:exported="true"
            android:label="@string/widget_water_label">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/water_widget_info" />
        </receiver>

        <!-- WorkManager FGS used by ModelDownloadWorker (Codeberg #51). -->
        <service
            android:name="androidx.work.impl.foreground.SystemForegroundService"
            android:foregroundServiceType="dataSync"
            android:exported="false"
            tools:node="merge" />

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>
    </application>

</manifest>
