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

    <!-- Permissions -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
    <!--
    Added notification permission so that code in MediaSessionService doesn't show errors.
    This is not really necessary, given that notifications are sent via MediaService, and those
    are exempt from being explicitly requested but it doesn't hurt
    -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!-- Dangerous permissions -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:supportsRtl="true"
        android:networkSecurityConfig="@xml/network_security_config">

        <!-- Activities -->
        <activity
            android:name=".ui.sections.remote.RemoteActivity"
            android:exported="true">

            <!-- Main intent filter to open this activity from the launcher -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Auxiliary activity to handle "Play on Kodi" share intents -->
        <activity
            android:name=".ShareOpenActivity"
            android:exported="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">

            <!-- Send image/video/audio directly to Kodi -->
            <intent-filter android:label="@string/play_on_kodi">
                <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="audio/*" />
            </intent-filter>

            <!--
            Open plain text URLs (eg, from youtube player, chrome when on a supported site, etc).
            This is a very generic filter, but it's the only way to get sharing requests from the youtube app
            -->
            <intent-filter android:label="@string/play_on_kodi">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>

            <!-- Open URLs of image/video/audio -->
            <intent-filter android:label="@string/play_on_kodi">
                <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:mimeType="video/*" />
                <data android:mimeType="audio/*" />
                <data android:mimeType="application/vnd.apple.mpegurl" />
            </intent-filter>

            <!-- Open supported URLs - youtube, vimeo, svtplay, etc. -->
            <intent-filter android:label="@string/play_on_kodi">
                <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="youtu.be" />
                <data android:host="youtube.com" />
                <data android:host="m.youtube.com" />
                <data android:host="www.youtube.com" />
                <data android:host="vimeo.com" />
                <data android:host="www.vimeo.com" />
                <data android:host="player.vimeo.com" />
                <data android:host="www.svtplay.se" />
                <data android:host="soundcloud.com" />
                <data android:host="m.soundcloud.com" />
                <data android:host="www.arte.tv" />
                <data android:host="twitch.tv" />
                <data android:host="m.twitch.tv" />
            </intent-filter>

            <!-- To provide backwards compatibility with the old DirectShare API -->
            <meta-data
                android:name="android.service.chooser.chooser_target_service"
                android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>

        <!-- Auxiliary activity to handle "Queue on Kodi" share intents -->
        <activity
            android:name=".ShareQueueActivity"
            android:exported="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">

            <!-- See intent filters on Share Open Activity, as these are similar -->
            <intent-filter android:label="@string/queue_on_kodi">
                <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="audio/*" />
            </intent-filter>

            <intent-filter android:label="@string/queue_on_kodi">
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
            
            <intent-filter android:label="@string/queue_on_kodi">
                <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:mimeType="video/*" />
                <data android:mimeType="audio/*" />
                <data android:mimeType="application/vnd.apple.mpegurl" />
            </intent-filter>

            <intent-filter android:label="@string/queue_on_kodi">
                <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="youtu.be" />
                <data android:host="youtube.com" />
                <data android:host="m.youtube.com" />
                <data android:host="www.youtube.com" />
                <data android:host="vimeo.com" />
                <data android:host="www.vimeo.com" />
                <data android:host="player.vimeo.com" />
                <data android:host="www.svtplay.se" />
                <data android:host="soundcloud.com" />
                <data android:host="m.soundcloud.com" />
                <data android:host="www.arte.tv" />
                <data android:host="twitch.tv" />
                <data android:host="m.twitch.tv" />
            </intent-filter>
        </activity>

        <activity android:name=".ui.sections.hosts.HostManagerActivity" />
        <activity android:name=".ui.sections.hosts.AddHostActivity" />
        <activity android:name=".ui.sections.hosts.EditHostActivity" />
        <activity android:name=".ui.sections.video.MoviesActivity" />
        <activity android:name=".ui.sections.video.TVShowsActivity" />
        <activity android:name=".ui.sections.audio.MusicActivity" />
        <activity android:name=".ui.sections.addon.AddonsActivity" />
        <activity android:name=".ui.sections.settings.SettingsActivity" />
        <activity android:name=".ui.sections.file.FileActivity" />
        <activity android:name=".ui.sections.localfile.LocalFileActivity" />
        <activity android:name=".ui.sections.video.PVRActivity" />
        <activity android:name=".ui.sections.video.AllCastActivity" />
        <activity android:name=".ui.sections.favourites.FavouritesActivity" />

        <!-- Providers -->
        <provider
            android:name=".provider.MediaProvider"
            android:authorities="org.xbmc.kore.provider"
            android:exported="false" />

        <!-- Services -->
        <service
            android:name=".service.library.LibrarySyncService"
            android:exported="false" />
        <service
            android:name=".service.MediaSessionService"
            android:foregroundServiceType="mediaPlayback"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </service>

        <!-- Broadcast Receivers -->
        <receiver
            android:name="androidx.media.session.MediaButtonReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>

        <uses-library android:required="false" android:name="com.sec.android.app.multiwindow"/>
        <meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
        <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632.0dip" />
        <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598.0dip" />
        <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632.0dip" />
        <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip" />

        <meta-data android:name="com.lge.support.SPLIT_WINDOW" android:value="true" />
    </application>

</manifest>