<?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.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <!--
      Required so the App-splitting picker can enumerate user-visible
      apps. Without this on API 30+ (targetSdk 34), PackageManager
      returns an empty list for CATEGORY_LAUNCHER queries against other
      apps' labels/icons — result: an empty picker dialog. Declaring
      it makes Android show a "com.therealaleph.mhrv wants to see which
      apps you have installed" note in Play Protect but no runtime
      prompt.
    -->
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

    <!--
      App-launcher visibility filter. Complements QUERY_ALL_PACKAGES:
      the system uses `<queries>` as the allowlist for metadata reads
      (labels, icons) so we can render the picker rows with the app
      name the user recognizes, rather than a bare package string.
    -->
    <queries>
        <intent>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent>
    </queries>

    <application
        android:name=".MhrvApp"
        android:allowBackup="false"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:localeConfig="@xml/locales_config"
        android:networkSecurityConfig="@xml/network_security_config"
        android:supportsRtl="true"
        android:theme="@style/Theme.Mhrv"
        tools:targetApi="34">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTask"
            android:theme="@style/Theme.Mhrv">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!--
          VpnService: Android captures all traffic at the IP layer and feeds
          it to us via a TUN file descriptor. The android.net.VpnService action
          is what lets the system show us in the "VPN" section of settings
          and route through us.
        -->
        <service
            android:name=".MhrvVpnService"
            android:exported="false"
            android:permission="android.permission.BIND_VPN_SERVICE"
            android:foregroundServiceType="specialUse">
            <intent-filter>
                <action android:name="android.net.VpnService" />
            </intent-filter>
            <property
                android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
                android:value="vpn_relay" />
        </service>

        <!--
          AppCompat runtime-locale bootstrap. AppCompatDelegate.setApplicationLocales()
          is a no-op on API < 33 without this service declaration — it's how
          AppCompat signals to itself that the app opted into the per-app
          language API and wants AppCompat to persist the preference across
          cold starts. `autoStoreLocales=true` ON older Android makes it
          survive process death without us doing our own file I/O.
          https://developer.android.com/guide/topics/resources/app-languages
        -->
        <service
            android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
            android:enabled="false"
            android:exported="false">
            <meta-data
                android:name="autoStoreLocales"
                android:value="true" />
        </service>

    </application>

</manifest>
