<?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.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.gps"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.network"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!--    New permissions required to run as foreground service on Android 14.
            SYSTEM_EXEMPTED is used when the app is on the doze allow list. This is normal
            and the expected default behaviour. The other two hijack RECORD_AUDIO and CAMERA if they
            happen to be granted. -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

    <!-- this foreground service type permission is exclusively used for import and export backup -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

    <uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />

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

    <uses-feature
        android:name="android.hardware.microphone"
        android:required="false" />

    <uses-sdk tools:overrideLibrary="androidx.heifwriter" />

    <queries>
        <package android:name="org.sufficientlysecure.keychain" />
        <package android:name="org.torproject.android" />

        <intent>
            <action android:name="eu.siacs.conversations.location.request" />
        </intent>
        <intent>
            <action android:name="eu.siacs.conversations.location.show" />
        </intent>
        <intent>
            <action android:name="android.intent.action.VIEW" />
        </intent>
        <intent>
            <action android:name="org.unifiedpush.android.connector.MESSAGE" />
        </intent>
    </queries>

    <application
        android:name=".Conversations"
        android:allowBackup="true"
        android:appCategory="social"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:enableOnBackInvokedCallback="true"
        android:fullBackupContent="@xml/backup_content"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/new_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:localeConfig="@xml/locales_config"
        android:networkSecurityConfig="@xml/network_security_configuration"
        android:preserveLegacyExternalStorage="true"
        android:requestLegacyExternalStorage="true"
        android:theme="@style/Theme.Conversations3"
        tools:targetApi="tiramisu">

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

        <!-- The warning that systemExempted requires alarm permission is incorrect because doze white list is sufficient -->
        <service
            android:name=".services.XmppConnectionService"
            android:exported="false"
            android:foregroundServiceType="specialUse|systemExempted|microphone|camera"
            tools:ignore="ForegroundServicePermission">
            <property
                android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
                android:value="xmpp-im" />
        </service>

        <service
            android:name="androidx.work.impl.foreground.SystemForegroundService"
            android:foregroundServiceType="dataSync"
            tools:node="merge" />

        <service
            android:name=".services.CallIntegrationConnectionService"
            android:exported="true"
            android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
            <intent-filter>
                <action android:name="android.telecom.ConnectionService" />
            </intent-filter>
        </service>

        <receiver
            android:name=".receiver.SystemEventReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
                <action
                    android:name="android.net.conn.CONNECTIVITY_CHANGE"
                    tools:ignore="BatteryLife" />
                <action android:name="android.intent.action.ACTION_SHUTDOWN" />
                <action android:name="android.media.RINGER_MODE_CHANGED" />
                <action android:name="android.intent.action.AIRPLANE_MODE_CHANGED" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ui.UnifiedPushDistributor"
            android:enabled="false"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:host="link"
                    android:scheme="unifiedpush" />
            </intent-filter>
        </activity>

        <receiver
            android:name=".receiver.UnifiedPushDistributor"
            android:enabled="false"
            android:exported="true">
            <intent-filter>
                <action android:name="org.unifiedpush.android.distributor.REGISTER" />
                <action android:name="org.unifiedpush.android.distributor.UNREGISTER" />
                <action android:name="org.unifiedpush.android.distributor.feature.BYTES_MESSAGE" />
                <action android:name="org.unifiedpush.android.distributor.feature.MESSENGER" />
                <action android:name="org.unifiedpush.android.distributor.feature.APP_VALIDATION" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ui.ShareLocationActivity"
            android:label="@string/title_activity_share_location" />
        <activity
            android:name=".ui.SearchActivity"
            android:label="@string/search_messages" />
        <activity
            android:name=".ui.RecordingActivity"
            android:configChanges="orientation|screenSize"
            android:theme="@style/Theme.Conversations3.Dialog" />
        <activity
            android:name=".ui.ShowLocationActivity"
            android:label="@string/title_activity_show_location" />
        <activity
            android:name=".ui.ConversationActivity"
            android:exported="true"
            android:theme="@style/Theme.Conversations3.SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>
        <activity
            android:name=".ui.ConversationsActivity"
            android:launchMode="singleTask"
            android:windowSoftInputMode="stateUnchanged" />
        <activity
            android:name=".ui.ScanQrCodeActivity"
            android:enableOnBackInvokedCallback="false"
            android:theme="@style/Theme.Conversations3.FullScreen"
            android:windowSoftInputMode="stateAlwaysHidden" />
        <activity
            android:name=".ui.YuriLauncherActivity"
            android:exported="true">
            <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="xmpp" />
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

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

                <data android:scheme="https" />
                <data android:host="conversations.im" />
                <data android:pathPrefix="/i/" />
                <data android:pathPrefix="/j/" />
            </intent-filter>
            <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:host="invite.joinjabber.org"
                    android:scheme="https" />

                <uri-relative-filter-group android:allow="true">
                    <data android:path="/" />
                    <data android:fragmentPattern=".*" />
                </uri-relative-filter-group>
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

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

                <data
                    android:host="xmpp.link"
                    android:scheme="https" />

                <uri-relative-filter-group android:allow="true">
                    <data android:path="/" />
                    <data android:fragmentPattern=".*" />
                </uri-relative-filter-group>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SENDTO" />

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

                <data android:scheme="imto" />
                <data android:host="jabber" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SENDTO" />

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

                <data android:scheme="imto" />
                <data android:host="xmpp" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.StartConversationActivity"
            android:exported="true"
            android:label="@string/title_activity_new_chat"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.activity.SettingsActivity"
            android:exported="true"
            android:label="@string/title_activity_settings">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ChooseContactActivity"
            android:label="@string/title_activity_choose_contact" />
        <activity
            android:name=".ui.BlocklistActivity"
            android:label="@string/title_activity_block_list" />
        <activity
            android:name=".ui.ChangePasswordActivity"
            android:label="@string/change_password_on_server" />
        <activity
            android:name=".ui.ChooseAccountForProfilePictureActivity"
            android:enabled="false"
            android:exported="true"
            android:label="@string/choose_account">
            <intent-filter android:label="@string/set_profile_picture">
                <action android:name="android.intent.action.ATTACH_DATA" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ShareViaAccountActivity"
            android:label="@string/title_activity_share_via_account"
            android:launchMode="singleTop" />
        <activity
            android:name=".ui.EditAccountActivity"
            android:enableOnBackInvokedCallback="false"
            android:exported="false"
            android:launchMode="singleTop" />
        <activity
            android:name=".ui.ConferenceDetailsActivity"
            android:enableOnBackInvokedCallback="false"
            android:label="@string/action_muc_details" />
        <!-- ContactDetails technically works with onBackInvokeCallback
             but we disable that to be consistent with conference details -->
        <activity
            android:name=".ui.ContactDetailsActivity"
            android:enableOnBackInvokedCallback="false" />
        <activity
            android:name=".ui.PublishProfilePictureActivity"
            android:label="@string/mgmt_account_publish_avatar" />
        <activity
            android:name=".ui.PublishGroupChatProfilePictureActivity"
            android:label="@string/group_chat_avatar" />
        <activity
            android:name=".ui.ShareWithActivity"
            android:exported="true"
            android:launchMode="singleTop">

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />

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

                <data android:mimeType="text/plain" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />

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

                <data android:mimeType="*/*" />
            </intent-filter>

            <meta-data
                android:name="android.service.chooser.chooser_target_service"
                android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
        </activity>
        <activity
            android:name=".ui.TrustKeysActivity"
            android:label="@string/trust_omemo_fingerprints" />
        <activity
            android:name=".ui.AboutActivity"
            android:parentActivityName=".ui.activity.SettingsActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="eu.siacs.conversations.ui.activity.SettingsActivity" />
        </activity>
        <activity
            android:name="com.canhub.cropper.CropImageActivity"
            android:theme="@style/Base.Theme.AppCompat" />
        <activity android:name=".ui.MemorizingActivity" />

        <activity
            android:name=".ui.MediaBrowserActivity"
            android:label="@string/media_browser" />
        <activity android:name=".ui.AddReactionActivity" />

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

        <activity
            android:name=".ui.ShortcutActivity"
            android:exported="true"
            android:label="@string/contact">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.ViewProfilePictureActivity"
            android:theme="@style/Theme.Conversations3.Dark" />
        <activity
            android:name=".ui.MucUsersActivity"
            android:label="@string/group_chat_members" />
        <activity
            android:name=".ui.ChannelDiscoveryActivity"
            android:label="@string/discover_channels" />
        <activity
            android:name=".ui.RtpSessionActivity"
            android:autoRemoveFromRecents="true"
            android:enableOnBackInvokedCallback="false"
            android:launchMode="singleInstance"
            android:supportsPictureInPicture="true" />
        <activity
            android:name=".ui.ImportBackupActivity"
            android:exported="true"
            android:label="@string/restore_backup"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="application/vnd.conversations.backup" />
                <data android:scheme="content" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="application/vnd.conversations.backup" />
                <data android:scheme="file" />
            </intent-filter>
            <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="content" />
                <data android:host="*" />
                <data android:mimeType="*/*" />
                <data android:pathPattern=".*\\.ceb" />
                <data android:pathPattern=".*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.ceb" />
            </intent-filter>
            <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="file" />
                <data android:host="*" />
                <data android:mimeType="*/*" />
                <data android:pathPattern=".*\\.ceb" />
                <data android:pathPattern=".*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.ceb" />
                <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.ceb" />
            </intent-filter>
        </activity>
    </application>

</manifest>
