<?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 13 uses READ_MEDIA_AUDIO instead of READ_EXTERNAL_STORAGE -->
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"  />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"  />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!-- Bluetooth auto-connect functionality (Disabled until permission workflow can be made) -->
<!--    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />-->
<!--    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />-->
<!--    <uses-feature android:name="android.hardware.bluetooth" android:required="false"/>-->

    <!-- Work around ExoPlayer requiring network permissions we do not use -->
    <uses-permission
        android:name="android.permission.ACCESS_NETWORK_STATE"
        tools:node="remove" />

    <queries />

    <application
        android:name=".Auxio"
        android:allowBackup="true"
        android:fullBackupContent="@xml/backup_descriptor"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/info_app_name"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/Theme.Auxio.App"
        android:appCategory="audio"
        android:enableOnBackInvokedCallback="true"
        tools:ignore="UnusedAttribute">

        <meta-data android:name="com.google.android.gms.car.application"
            android:resource="@xml/automotive_app_desc"/>
        <meta-data
                android:name="androidx.car.app.TintableAttributionIcon"
                android:resource="@drawable/ic_auxio_24" />

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:launchMode="singleTask"
            android:allowCrossUidActivitySwitchFromBelow="false"
            android:roundIcon="@mipmap/ic_launcher"
            android:windowSoftInputMode="adjustPan">

            <intent-filter>
                <!-- Expose that we are a music player. -->
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.MUSIC_PLAYER" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.APP_MUSIC" />
            </intent-filter>

            <intent-filter>
                <!--
                Signal that we can take audio of *any* format, file or content. This is important,
                as some apps use this to determine if Auxio is eligible to be a default music
                player.
                -->
                <action android:name="android.intent.action.VIEW" />

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

                <data android:scheme="content" />
                <data android:scheme="file" />

                <!-- Normal audio mime types + weird mime types -->
                <data android:mimeType="audio/*" />
                <data android:mimeType="application/ogg" />
                <data android:mimeType="application/x-ogg" />
                <data android:mimeType="application/itunes" />
            </intent-filter>
        </activity>


        <!--
        Service handling music playback, system components, and state saving.
        -->
        <service
            android:name=".AuxioService"
            android:foregroundServiceType="mediaPlayback"
            android:icon="@mipmap/ic_launcher"
            android:exported="true"
            android:roundIcon="@mipmap/ic_launcher"
            tools:ignore="ExportedService">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>

        <!--
        Work around apps that blindly query for ACTION_MEDIA_BUTTON working.
        See the class for more info.
        -->
        <receiver
            android:name=".playback.service.MediaButtonReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>

        <!-- Receiver for bluetooth headset events -->
<!--        <receiver-->
<!--            android:name=".playback.system.BluetoothConnectReceiver"-->
<!--            android:exported="true">-->
<!--            <intent-filter>-->
<!--                <action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" />-->
<!--            </intent-filter>-->
<!--        </receiver>-->

        <!-- "Now Playing" widget. -->
        <receiver
            android:name=".widgets.WidgetProvider"
            android:exported="false"
            android:label="@string/lbl_playback">

            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_info" />
        </receiver>

        <!-- Tasker 'start service' integration -->
        <activity
            android:name=".tasker.ActivityConfigStartAction"
            android:exported="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/lbl_start_playback">
            <intent-filter>
                <action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
            </intent-filter>
        </activity>
    </application>
</manifest>