<?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.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <!--
        READ_MEDIA_IMAGES and READ_EXTERNAL_STORAGE were declared here and used nowhere: there is
        no avatar upload and no gallery picker in this app. Play asks buyers to justify storage
        access at review, and an unjustifiable declaration is a rejection over a feature that does
        not exist. Removed rather than left "in case".

        PACKAGE_USAGE_STATS stays because it is genuinely used - see UsageAccess and
        OfferDetailViewModel, which verify that a rewarded app was actually opened. It is not a
        runtime permission; the user grants it in Settings, and every offer requiring it says so
        before asking. Buyers must still declare and justify it on the Play listing.
    -->
    <uses-permission
        android:name="android.permission.PACKAGE_USAGE_STATS"
        tools:ignore="ProtectedPermissions" />

    <queries>
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
    </queries>

    <!--
        allowBackup is off because the DataStore holds the API session, including a refresh
        token good for 90 days. With backup on, `adb backup` extracts that token off an
        unlocked device and it replays as the user until it expires. Cloud Backup would put
        the same token on Google's servers and restore it onto a different handset.
        dataExtractionRules covers Android 12+, where allowBackup alone no longer decides it.
    -->
    <application
        android:name="com.cashparty.rewards.app.CashLoopApplication"
        android:allowBackup="false"
        android:fullBackupContent="false"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.CashParty"
        android:usesCleartextTraffic="false">

        <activity
            android:name="com.cashparty.rewards.app.ui.MainActivity"
            android:exported="true"
            android:theme="@style/Theme.CashParty">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" />

        <activity
            android:name="com.facebook.CustomTabActivity"
            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="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data
            android:name="com.facebook.sdk.ClientToken"
            android:value="@string/facebook_client_token" />

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/admob_app_id" />

        <meta-data
            android:name="com.google.android.gms.ads.flag.NATIVE_AD_DEBUGGER_ENABLED"
            android:value="false" />

        <!--
            Disabled on purpose. AppCompat arrives transitively and would otherwise offer to store
            the per-app locale itself, but this app already persists the chosen language in its
            DataStore and applies it in CashLoopApplication.onCreate. Two owners for one setting is
            how a language silently reverts on the next cold start, so AppCompat's is switched off
            and ours is the only one.
        -->
        <service
            android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
            android:enabled="false"
            android:exported="false">
            <meta-data
                android:name="autoStoreLocales"
                android:value="true" />
        </service>

        <service
            android:name=".service.CashLoopMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

    </application>

</manifest>
