<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.b44t.messenger"
    android:installLocation="auto">

    <supports-screens android:anyDensity="true"
                      android:largeScreens="true"
                      android:normalScreens="true"
                      android:resizeable="true"
                      android:smallScreens="true"
                      android:xlargeScreens="true"/>

    <uses-feature android:glEsVersion="0x00020000" android:required="false"/>
    <uses-feature android:name="android.hardware.telephony" android:required="false" />
    <uses-feature android:name="android.hardware.wifi" android:required="false" />
    <uses-feature android:name="android.hardware.screen.PORTRAIT" android:required="false" />
    <uses-feature android:name="android.hardware.microphone" android:required="false" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera2" android:required="false" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- we need it eg. for getActiveNetworkInfo() -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <!-- <uses-permission android:name="android.permission.GET_ACCOUNTS" /> - required for AccountManager -->
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <!-- <uses-permission android:name="android.permission.WRITE_CONTACTS" /> -->
    <!-- <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/> - required for AccountManager in API level <= 22 -->
    <!-- <uses-permission android:name="android.permission.READ_PROFILE"/> - required for ContactsContract.Profile -->
    <!-- <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/> required for AbstractThreadedSyncAdapter-->
    <!-- <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> - required for AbstractThreadedSyncAdapter -->
    <!-- <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/> - seems to be unneeded and is no longer supported by Android, was needed for AbstractAccountAuthenticator, see http://stackoverflow.com/questions/32601456/marshmallow-permission-implementation#36907308 -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> - required for windows using the TYPE_SYSTEM_ALERT flag -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- we need the TelephonyManager to pause the audio player on calls -->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <!-- <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> - required for AndroidUtilities.uninstallShortcut() -->
    <uses-permission android:name="android.permission.CAMERA" /> <!-- needed for qr code scanning, not needed for taking photos (we're using an intent for this) -->

    <application
        android:name=".ApplicationLoader"
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/AppName"
        android:largeHeap="true"
        android:theme="@style/Theme.MessengerProj.Start"
        android:supportsRtl="true">

        <activity
            android:name=".LaunchActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustPan">
            <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>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="image/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="video/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="image/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="*/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="*/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="vnd.android.cursor.item/vnd.com.b44t.messenger.android.profile"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <action android:name="android.intent.action.SENDTO"/> <!-- VIEW seems to be standard, however, SENDTO is also mentioned in some examples -->
                <data android:scheme="mailto"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>

        <activity
            android:name=".WelcomeActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name=".QRshowActivity"
            android:theme="@style/Theme.MessengerProj.AppCompat"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name=".QRscanActivity"
            android:theme="@style/Theme.MessengerProj.AppCompat"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        </activity>

        <activity
            android:name="com.b44t.messenger.OpenChatReceiver"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:exported="true">
        </activity>

        <receiver
            android:name=".AutoMessageHeardReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.b44t.messenger.ACTION_MESSAGE_HEARD"/>
            </intent-filter>
        </receiver>

        <receiver
            android:name=".AutoMessageReplyReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.b44t.messenger.ACTION_MESSAGE_REPLY"/>
            </intent-filter>
        </receiver>

        <!--
        <receiver android:name=".CallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
        -->

        <!-- currently, we do not use the android account system
        <service android:name=".AuthenticatorService" android:exported="true">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"/>
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator"
                android:resource="@xml/auth"/>
        </service>
        -->

        <!-- seems to be not needed, derived from AbstractThreadedSyncAdapter, would need the READ/WRITE_SYNC_SETTINGS
        <service android:name=".ContactsSyncAdapterService" android:exported="true">
            <intent-filter>
                <action android:name="android.content.SyncAdapter" />
            </intent-filter>
            <meta-data android:name="android.content.SyncAdapter"
                android:resource="@xml/sync_contacts" />
            <meta-data android:name="android.provider.CONTACTS_STRUCTURE"
                android:resource="@xml/contacts" />
        </service>
        -->

        <!-- this would implement the "direct share" functionality (the system shows some direct links eg.
        to the most recent chats when calling "share" from another app, see https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html )
        however, if we want this feature, we have to implement  a ChooserTargetService and add <meta-data android:name="android.service.chooser.chooser_target_service" android:value=".OurChooserTargetService" />
        <service
            android:name="com.b44t.messenger.TgChooserTargetService"
            android:label="@string/AppName"
            android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
            <intent-filter>
                <action android:name="android.service.chooser.ChooserTargetService" />
            </intent-filter>
        </service> -->

        <service android:name=".KeepAliveService" android:enabled="true"/>
        <service android:name=".NotificationRepeat" android:exported="false"/>
        <service android:name=".MusicPlayerService" android:exported="true" android:enabled="true"/>
        <!-- Do not expose data through MediaBrowserService, this seems unexpected for an messenger.
        Instead, the user can use 'save to music' or 'share' explicitly for items not privacy related.
        <service android:name=".MusicBrowserService" android:exported="true">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service> -->

        <receiver android:name=".MusicPlayerReceiver" >
            <intent-filter>
                <action android:name="com.b44t.android.musicplayer.close" />
                <action android:name="com.b44t.android.musicplayer.pause" />
                <action android:name="com.b44t.android.musicplayer.next" />
                <action android:name="com.b44t.android.musicplayer.play" />
                <action android:name="com.b44t.android.musicplayer.previous" />
                <action android:name="android.intent.action.MEDIA_BUTTON" />
                <action android:name="android.media.AUDIO_BECOMING_NOISY" />
            </intent-filter>
        </receiver>

        <receiver android:name=".BootCompletedReceiver" android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <receiver android:name=".WearReplyReceiver" android:enabled="true"/>
        <!-- <receiver android:name=".NetworkAlarm" android:enabled="true"/> -->

        <!-- seems to be unneeded (bp)
        <receiver android:name=".ShareBroadcastReceiver" android:enabled="true"/>
        -->

        <receiver android:name=".TimerReceiver" android:enabled="true"/>

        <receiver android:name=".NotificationDismissReceiver" android:exported="false"/>

        <provider android:name=".AttachmentsContentProvider" android:authorities="${applicationId}.attachments" android:exported="true" />

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

        <uses-library android:name="com.sec.android.app.multiwindow" android:required="false" />
        <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="632dp" />
        <meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598dp" />
        <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632dp" />
        <meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598dp" />

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

    </application>

</manifest>
