<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2022 Proton AG
  ~
  ~ This file is part of Proton Mail.
  ~
  ~ Proton Mail is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ Proton Mail is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with Proton Mail. If not, see https://www.gnu.org/licenses/.
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="ch.protonmail.android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />

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

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


    <queries>
        <!-- WebView -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
        </intent>

        <!-- Camera -->
        <intent>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
        </intent>

        <!-- Telephony -->
        <intent>
            <action android:name="android.intent.action.DIAL" />
        </intent>

        <!-- Calendar -->
        <package android:name="me.proton.android.calendar" />

    </queries>

    <application
        android:name=".core.ProtonMailApplication"
        android:allowBackup="false"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/ProtonTheme.Mail.V5"
        android:taskAffinity=""
        tools:replace="android:theme">
        <!-- Disable Core SentryInitProvider. Replaced by SentryInitializer -->
        <provider
            android:name="io.sentry.android.core.SentryInitProvider"
            android:authorities="io.sentry.android.core"
            tools:node="remove" />
        <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup"
            android:exported="false"
            tools:node="merge">

            <meta-data
                android:name="me.proton.core.humanverification.presentation.HumanVerificationInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="me.proton.core.auth.presentation.MissingScopeInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="me.proton.core.plan.presentation.UnredeemedPurchaseInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <!-- Disable default WorkManagerInitializer for use Hilt injection -->
            <meta-data
                android:name="androidx.work.WorkManagerInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="ch.protonmail.android.feature.account.AccountStateHandlerInitializer"
                android:value="androidx.startup"
                tools:node="remove"/>

            <meta-data
                android:name="me.proton.core.crypto.validator.presentation.init.CryptoValidatorInitializer"
                android:value="androidx.startup"
                tools:node="remove"/>

            <meta-data
                android:name="me.proton.core.network.presentation.init.UnAuthSessionFetcherInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="ch.protonmail.android.security.presentation.SecurityManagerInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="ch.protonmail.android.sentry.SentryInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="ch.protonmail.android.onboarding.base.presentation.StartOnboardingObserverInitializer"
                android:value="androidx.startup"
                tools:node="remove" />

            <meta-data
                android:name="ch.protonmail.android.featureflags.FeatureFlagsInitializer"
                android:value="androidx.startup"
                tools:node="remove" />
        </provider>
        <provider
            android:name="androidx.core.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>

        <receiver
            android:name=".receivers.LocaleChangeReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.LOCALE_CHANGED" />
            </intent-filter>
        </receiver>

        <service
            android:name="ch.protonmail.android.notifications.data.remote.fcm.PMFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <receiver
            android:name=".receivers.OnBootReceiver"
            android:enabled="false"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <receiver android:name=".api.segments.event.AlarmReceiver" />
        <receiver android:name=".receivers.NotificationReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="protonmail_notif_action_archive" />
                <action android:name="protonmail_notif_action_delete" />
                <action android:name="protonmail_notif_action_trash" />
            </intent-filter>
        </receiver>
        <receiver android:name=".receivers.TimeChangedReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.TIME_SET" />
            </intent-filter>
        </receiver>


        <activity android:name=".ViewTestActivity"/>
        <activity android:name=".util.HiltViewTestActivity"/>

        <!-- Begin - Root Activities -->
        <activity-alias
            android:name=".activities.SplashActivity"
            android:targetActivity=".mailbox.presentation.ui.MailboxActivity"/>
        <activity
            android:name=".mailbox.presentation.ui.MailboxActivity"
            android:configChanges="orientation|screenSize"
            android:exported="true"
            android:launchMode="standard"
            android:maxRecents="1"
            android:theme="@style/ProtonTheme.Splash.Mail.V5">
            <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>
        <!-- End - Root Activities -->
        <activity
            android:name=".settings.presentation.AttachmentStorageActivity"
            android:exported="false"
            android:label="@string/local_storage"
            android:screenOrientation="portrait" />
        <activity android:name=".details.presentation.ui.SwitchUserAndOpenMessageDetailsActivity" />
        <activity
            android:name=".details.presentation.ui.MessageDetailsActivity"
            android:exported="false"
            android:configChanges="orientation|screenSize"
            android:parentActivityName=".mailbox.presentation.ui.MailboxActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".mailbox.presentation.ui.MailboxActivity" />
        </activity>
        <activity
            android:name=".activities.messageDetails.MessageViewHeadersActivity"
            android:configChanges="orientation|screenSize"
            android:exported="false"
            android:parentActivityName=".details.presentation.ui.MessageDetailsActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".details.presentation.ui.MessageDetailsActivity" />
        </activity>
        <activity
            android:name=".activities.composeMessage.ComposeMessageActivity"
            android:configChanges="orientation|screenSize"
            android:parentActivityName=".mailbox.presentation.ui.MailboxActivity"
            android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
            android:exported="true">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".mailbox.presentation.ui.MailboxActivity" />

            <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.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.SENDTO" />

                <data android:scheme="mailto" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
        <activity android:name=".compose.presentation.ui.SetMessageExpirationActivity"/>
        <activity android:name=".compose.presentation.ui.SetMessagePasswordActivity"/>
        <activity
            android:name=".activities.AddAttachmentsActivity"
            android:exported="false"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.SearchActivity"
            android:exported="false"
            android:configChanges="orientation|screenSize"
            android:windowSoftInputMode="stateVisible" />
        <activity
            android:name=".contacts.ContactsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name=".settings.presentation.SettingsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/settings"/>
        <activity
            android:name=".settings.presentation.AccountSettingsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/account_settings"/>
        <activity
            android:name=".settings.presentation.EditSettingsItemActivity"
            android:exported="false"
            android:parentActivityName=".settings.presentation.SettingsActivity"
            android:screenOrientation="portrait">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".settings.presentation.SettingsActivity" />
        </activity>
        <activity
            android:name=".settings.pin.CreatePinActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing" />
        <activity
            android:name=".settings.pin.ChangePinActivity"
            android:exported="false"
            android:label="@string/settings_confirm_pin_code_title"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing" />
        <activity
            android:name=".settings.pin.ValidatePinActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing" />
        <activity
            android:name=".contacts.details.presentation.ContactDetailsActivity"
            android:exported="false"
            android:label="@string/contact_details"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" />
        <activity
            android:name=".contacts.details.edit.EditContactDetailsActivity"
            android:exported="false"
            android:label="@string/contact_details"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".settings.presentation.DefaultAddressActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/default_mail_address"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".settings.swipe.SwipeChooserActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/swipe_action_chooser_title"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".settings.pin.PinSettingsActivity"
            android:exported="false"
            android:label="@string/auto_lock"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".labels.presentation.ui.LabelsManagerActivity"
            android:exported="false"
            android:label="@string/labels_and_folders"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".settings.presentation.NotificationSettingsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/notification_settings"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".settings.presentation.SnoozeNotificationsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/notifications_snooze"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity
            android:name=".contacts.groups.details.ContactGroupDetailsActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
            android:label="@string/title_activity_contact_group_details"/>
        <activity
            android:name=".contacts.groups.edit.ContactGroupEditCreateActivity"
            android:exported="false"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
            android:screenOrientation="portrait"
            android:label="@string/title_activity_contact_group_details"/>
        <activity
            android:name=".contacts.groups.edit.chooser.AddressChooserActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:label="@string/title_activity_address_chooser"/>
        <activity
            android:name=".labels.presentation.ui.ParentFolderPickerActivity"
            android:exported="true"/>
        <activity
            android:name=".settings.presentation.ui.ThemeChooserActivity"
            android:exported="false"/>

        <service
            android:name=".api.services.MessagesService"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <service
            android:name=".api.segments.event.EventUpdaterService"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <service
            android:name=".storage.AttachmentClearingService"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <service
            android:name=".storage.MessageBodyClearingService"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <service
            android:name=".api.services.ConnectivityService"
            android:exported="true"
            android:permission="android.permission.BIND_JOB_SERVICE" />

        <!-- Core -->
        <activity
            android:name="me.proton.core.auth.presentation.ui.AuthHelpActivity"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name="me.proton.core.auth.presentation.ui.ChooseAddressActivity"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name="me.proton.core.auth.presentation.ui.AddAccountActivity"
            android:theme="@style/ProtonTheme.Mail.AddAccount"
            tools:replace="theme" />
        <activity
            android:name="me.proton.core.crypto.validator.presentation.ui.CryptoValidatorErrorDialogActivity"
            android:theme="@style/ProtonTheme.Transparent" />
        <activity android:name=".onboarding.newuser.presentation.NewUserOnboardingActivity" />
        <activity android:name=".onboarding.existinguser.presentation.ExistingUserOnboardingActivity" />
    </application>

</manifest>
