<?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.software.leanback"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <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_MEDIA_PLAYBACK" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:name=".LibreTubeApp"
        android:allowBackup="true"
        android:banner="@mipmap/ic_youtube_launcher"
        android:enableOnBackInvokedCallback="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_youtube_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:usesCleartextTraffic="false"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_youtube_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/BaseTheme"
        android:memtagMode="async"
        tools:targetApi="tiramisu">

        <!-- Register Cast OptionsProvider -->
        <meta-data
            android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
            android:value="com.github.libretube.cast.CastOptionsProvider" />

        <activity
            android:name=".ui.activities.NoInternetActivity"
            android:label="@string/noInternet"
            android:launchMode="singleTop"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:supportsPictureInPicture="true"
            android:screenOrientation="locked" />

        <activity
            android:name=".ui.activities.SettingsActivity"
            android:label="@string/settings"
            android:screenOrientation="locked" />

        <activity
            android:name=".ui.activities.AboutActivity"
            android:label="@string/settings"
            android:screenOrientation="locked" />

        <activity
            android:name=".ui.activities.HelpActivity"
            android:label="@string/settings"
            android:screenOrientation="locked" />

        <activity
            android:name=".ui.activities.ZoomableImageActivity"
            android:screenOrientation="locked" />

        <activity
            android:name=".ui.activities.AddToQueueActivity"
            android:enabled="true"
            android:exported="true"
            android:label="@string/add_to_queue"
            android:launchMode="singleTop">

            <intent-filter android:label="@string/add_to_queue">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>

        </activity>

        <activity
            android:name=".ui.activities.AddToPlaylistActivity"
            android:enabled="true"
            android:exported="true"
            android:label="@string/addToPlaylist"
            android:launchMode="singleTop"
            android:theme="@style/Theme.Material3.DayNight.Dialog">

            <intent-filter android:label="@string/addToPlaylist">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>

        </activity>

        <activity
            android:name=".ui.activities.DownloadActivity"
            android:enabled="true"
            android:exported="true"
            android:label="@string/download"
            android:launchMode="singleTop"
            android:theme="@style/Theme.Material3.DayNight.Dialog">

            <intent-filter android:label="@string/download">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>

        </activity>

        <activity
            android:name=".ui.activities.MainActivity"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:exported="true"
            android:launchMode="singleTask"
            android:screenOrientation="locked"
            android:supportsPictureInPicture="true"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan">
            <!-- allow being recognized as a music player -->
            <intent-filter>
                <action android:name="android.intent.action.MUSIC_PLAYER" />
                <category android:name="android.intent.category.CATEGORY_APP_MUSIC" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ui.activities.AccessCodeActivity"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:screenOrientation="locked"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity-alias
            android:name=".IconGradient"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".DefaultLight"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconFire"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconFlame"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconShaped"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconTorch"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconLegacy"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity-alias
            android:name=".IconBird"
            android:configChanges="keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
            android:enabled="false"
            android:exported="true"
            android:icon="@mipmap/ic_youtube_launcher"
            android:roundIcon="@mipmap/ic_youtube_launcher_round"
            android:supportsPictureInPicture="true"
            android:targetActivity=".ui.activities.MainActivity"
            android:theme="@style/SplashScreenTheme"
            android:windowSoftInputMode="adjustPan" />

        <activity
            android:name=".ui.activities.RouterActivity"
            android:exported="true"
            android:launchMode="singleInstance">

            <intent-filter android:label="@string/open">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>

            <!-- YouTube -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

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

                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="youtube.com" />
                <data android:host="m.youtube.com" />
                <data android:host="www.youtube.com" />
                <data android:host="music.youtube.com" />
                <data android:host="www.youtube-nocookie.com" />
                <!-- video prefix -->
                <data android:pathPrefix="/v/" />
                <data android:pathPrefix="/embed/" />
                <data android:pathPrefix="/watch" />
                <data android:pathPrefix="/shorts/" />
                <data android:pathPrefix="/live/" />
                <!-- channel prefix -->
                <data android:pathPrefix="/channel/" />
                <data android:pathPrefix="/user/" />
                <data android:pathPrefix="/c/" />
                <!-- playlist prefix -->
                <data android:pathPrefix="/playlist" />
                <!-- search prefix -->
                <data android:pathPrefix="/results" />
                <!-- temporary playlist prefix -->
                <data android:pathPrefix="/watch_videos" />
            </intent-filter>

            <!-- Support being detected as media player -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />

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

                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="youtu.be" />
                <data android:pathPrefix="/" />
            </intent-filter>

            <!-- Piped filter -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />

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

                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:pathPrefix="/" />

                <data android:host="piped.drgns.space" />
                <data android:host="piped.syncpundit.io" />
                <data android:host="piped.video" />
            </intent-filter>
        </activity>

        <service
            android:name=".services.DownloadService"
            android:enabled="true"
            android:exported="false"
            android:foregroundServiceType="dataSync" />

        <service
            android:name=".services.PlaylistDownloadEnqueueService"
            android:enabled="true"
            android:exported="false"
            android:foregroundServiceType="dataSync" />

        <service
            android:name=".services.OnlinePlayerService"
            android:enabled="true"
            android:exported="false"
            android:stopWithTask="false"
            android:foregroundServiceType="mediaPlayback">

            <intent-filter>
                <action android:name="androidx.media3.session.MediaSessionService"/>
            </intent-filter>

        </service>

        <service
            android:name=".services.OfflinePlayerService"
            android:enabled="true"
            android:exported="false"
            android:stopWithTask="false"
            android:foregroundServiceType="mediaPlayback">

            <intent-filter>
                <action android:name="androidx.media3.session.MediaSessionService"/>
            </intent-filter>

        </service>

        <service
            android:name=".services.OnClearFromRecentService"
            android:enabled="true"
            android:exported="false" />

        <receiver
            android:name=".receivers.NotificationReceiver"
            android:enabled="true"
            android:exported="false" />
    </application>

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="*" />
        </intent>
    </queries>
</manifest>
