<?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="internalOnly">

    <uses-sdk tools:overrideLibrary="com.google.zxing.client.android, com.blacksquircle.ui.editorkit" />

    <permission
        android:name="${applicationId}.SERVICE"
        android:protectionLevel="signature" />

    <uses-permission android:name="${applicationId}.SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

    <uses-permission
        android:name="android.permission.QUERY_ALL_PACKAGES"
        tools:ignore="QueryAllPackagesPermission" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

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

    <queries>
        <intent>
            <action android:name="io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN" />
        </intent>
    </queries>

    <application
        android:name="io.nekohasekai.sagernet.SagerNet"
        android:allowBackup="true"
        android:autoRevokePermissions="allowed"
        android:banner="@mipmap/ic_launcher"
        android:dataExtractionRules="@xml/backup_rules"
        android:fullBackupContent="@xml/backup_descriptor"
        android:fullBackupOnly="true"
        android:hardwareAccelerated="true"
        android:hasFragileUserData="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/Theme.Start">
        <meta-data
            android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts" />

        <activity
            android:name="io.nekohasekai.sagernet.ui.BlankActivity"
            android:configChanges="uiMode" />

        <activity
            android:name="io.nekohasekai.sagernet.ui.MainActivity"
            android:configChanges="uiMode"
            android:exported="true"
            android:launchMode="singleTask">
            <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.MAIN" />

                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
            </intent-filter>

            <intent-filter android:label="@string/subscription_import">
                <action android:name="android.intent.action.VIEW" />

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

                <data
                    android:host="subscription"
                    android:scheme="sn" />

            </intent-filter>

            <intent-filter android:label="@string/subscription_import">
                <action android:name="android.intent.action.VIEW" />

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

                <data
                    android:host="install-config"
                    android:scheme="clash" />
            </intent-filter>

            <intent-filter android:label="@string/profile_import">
                <action android:name="android.intent.action.VIEW" />

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

                <data android:scheme="sn" />
                <data android:scheme="ss" />
                <data android:scheme="ssr" />
                <data android:scheme="socks" />
                <data android:scheme="socks4" />
                <data android:scheme="socksa" />
                <data android:scheme="sock5" />
                <data android:scheme="vmess" />
                <data android:scheme="trojan" />
                <data android:scheme="trojan-go" />
                <data android:scheme="naive+https" />
                <data android:scheme="naive+quic" />
                <data android:scheme="hysteria" />

            </intent-filter>

            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>
        <activity
            android:name="io.nekohasekai.sagernet.ui.VpnRequestActivity"
            android:excludeFromRecents="true"
            android:taskAffinity="" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.ConfigEditActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.SocksSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.HttpSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.ShadowsocksSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.VMessSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.TrojanSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.TrojanGoSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.MieruSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.NaiveSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.HysteriaSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.SSHSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.WireGuardSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.TuicSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.profile.ChainSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="moe.matsuri.nb4a.proxy.shadowtls.ShadowTLSSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="moe.matsuri.nb4a.proxy.anytls.AnyTLSSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="moe.matsuri.nb4a.proxy.config.ConfigSettingActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.GroupSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.RouteSettingsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.AssetsActivity"
            android:configChanges="uiMode" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.AppListActivity"
            android:configChanges="uiMode" />
        <activity
            android:name=".QuickToggleShortcut"
            android:excludeFromRecents="true"
            android:exported="true"
            android:label="@string/quick_toggle"
            android:launchMode="singleTask"
            android:process=":bg"
            android:taskAffinity=""
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
            </intent-filter>
        </activity>
        <activity
            android:name="io.nekohasekai.sagernet.ui.AppManagerActivity"
            android:configChanges="uiMode"
            android:excludeFromRecents="true"
            android:label="@string/proxied_apps"
            android:launchMode="singleTask"
            android:parentActivityName=".ui.MainActivity" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.ScannerActivity"
            android:configChanges="uiMode"
            android:excludeFromRecents="true"
            android:label="@string/add_profile_methods_scan_qr_code"
            android:launchMode="singleTask"
            android:parentActivityName="io.nekohasekai.sagernet.ui.MainActivity" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.ProfileSelectActivity"
            android:configChanges="uiMode"
            android:label="@string/select_profile"
            android:launchMode="singleTask"
            android:parentActivityName="io.nekohasekai.sagernet.ui.MainActivity" />
        <activity
            android:name="io.nekohasekai.sagernet.ui.StunActivity"
            android:configChanges="uiMode"
            android:launchMode="singleTask"
            android:parentActivityName="io.nekohasekai.sagernet.ui.MainActivity" />

        <activity
            android:name="io.nekohasekai.sagernet.ui.SwitchActivity"
            android:configChanges="uiMode"
            android:excludeFromRecents="true"
            android:launchMode="singleInstance"
            android:theme="@style/Theme.SagerNet.Dialog" />

        <service
            android:name="io.nekohasekai.sagernet.bg.ProxyService"
            android:exported="false"
            android:foregroundServiceType="systemExempted"
            android:process=":bg"
            tools:ignore="ForegroundServicePermission" />

        <service
            android:name="io.nekohasekai.sagernet.bg.VpnService"
            android:exported="false"
            android:foregroundServiceType="systemExempted"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_VPN_SERVICE"
            android:process=":bg"
            tools:ignore="ForegroundServicePermission">

            <intent-filter>
                <action android:name="android.net.VpnService" />
            </intent-filter>
        </service>

        <service
            android:name="io.nekohasekai.sagernet.bg.TileService"
            android:exported="true"
            android:foregroundServiceType="systemExempted"
            android:icon="@drawable/ic_service_active"
            android:label="@string/tile_title"
            android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
            android:process=":bg"
            tools:ignore="ForegroundServicePermission"
            tools:targetApi="n">
            <intent-filter>
                <action android:name="android.service.quicksettings.action.QS_TILE" />
            </intent-filter>
            <meta-data
                android:name="android.service.quicksettings.TOGGLEABLE_TILE"
                android:value="true" />
        </service>

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

        <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup"
            tools:node="remove" />

        <receiver
            android:name="io.nekohasekai.sagernet.BootReceiver"
            android:enabled="false"
            android:exported="true"
            android:process=":bg">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            </intent-filter>
        </receiver>

        <service
            android:name="androidx.room.MultiInstanceInvalidationService"
            android:process=":bg" />

    </application>

</manifest>