<?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.POST_NOTIFICATIONS" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
  <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

  <!--
    Android 11+ package visibility: without these the PackageManager fallback in
    WebViewCompatibilityChecker can't read the WebView provider version, so a
    transient getCurrentWebViewPackage() miss leaves the block screen with no
    detected version. Listing the providers explicitly keeps us off
    QUERY_ALL_PACKAGES. → issue #7518.
    Keep this list in sync with KNOWN_WEBVIEW_PACKAGES in WebViewCompatibilityChecker.kt.
  -->
  <queries>
    <package android:name="com.google.android.webview" />
    <package android:name="com.android.webview" />
    <package android:name="com.android.chrome" />
    <package android:name="com.chrome.beta" />
    <package android:name="com.chrome.dev" />
    <package android:name="com.chrome.canary" />
    <package android:name="com.sec.android.app.sbrowser" />
    <package android:name="com.huawei.webview" />
    <package android:name="app.vanadium.webview" />
  </queries>

  <application
    android:name=".App"
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">

    <!-- FileProvider for secure file sharing via Share plugin -->
    <provider
      android:name="androidx.core.content.FileProvider"
      android:authorities="${applicationId}.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true">
      <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
    </provider>

    <!-- Set FullscreenActivity as the default launcher -->
    <activity
      android:name=".FullscreenActivity"
      android:allowTaskReparenting="true"
      android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
      android:exported="true"
      android:hardwareAccelerated="true"
      android:label="@string/title_activity_fullscreen"
      android:launchMode="singleTask"
      android:theme="@style/AppTheme.NoActionBarLaunch"
      android:windowSoftInputMode="adjustResize">

      <!-- This intent-filter adds the Trusted Web Activity to the Android Launcher -->
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

        <action android:name="com.superproductivity.superproductivity.DONE" />
        <action android:name="com.superproductivity.superproductivity.PAUSE" />
      </intent-filter>
    </activity>

    <!-- All new Super-Productivity main activity, based on Capacitor to support offline use -->
    <activity
      android:name=".CapacitorMainActivity"
      android:allowTaskReparenting="true"
      android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
      android:exported="true"
      android:hardwareAccelerated="true"
      android:label="@string/title_activity_fullscreen"
      android:launchMode="singleTask"
      android:theme="@style/AppTheme.NoActionBarLaunch"
      android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/*" />
      </intent-filter>

      <!-- OAuth callback handler for Dropbox authentication -->
      <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="com.super-productivity.app"
          android:host="oauth-callback" />
      </intent-filter>

      <!-- OAuth callback handler for plugin authentication -->
      <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="com.super-productivity.app"
          android:host="plugin-oauth-callback" />
      </intent-filter>

      <!-- OAuth callback for plugin auth using Android package name scheme -->
      <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="com.superproductivity.superproductivity"
          android:pathPrefix="/plugin-oauth-callback" />
      </intent-filter>
    </activity>

    <activity
      android:name=".webview.WebViewBlockActivity"
      android:exported="false"
      android:theme="@style/AppTheme.NoActionBar" />

    <service
      android:name=".service.TrackingForegroundService"
      android:enabled="true"
      android:exported="false"
      android:foregroundServiceType="specialUse">
      <property
        android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
        android:value="time_tracking" />
    </service>

    <service
      android:name=".service.FocusModeForegroundService"
      android:enabled="true"
      android:exported="false"
      android:foregroundServiceType="specialUse">
      <property
        android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
        android:value="focus_timer" />
    </service>

    <receiver
      android:name=".receiver.ReminderAlarmReceiver"
      android:enabled="true"
      android:exported="false" />

    <receiver
      android:name=".receiver.ReminderActionReceiver"
      android:enabled="true"
      android:exported="false" />

    <receiver
      android:name=".receiver.BootReceiver"
      android:enabled="true"
      android:exported="true"
      android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
      </intent-filter>
    </receiver>

    <!-- Home screen widget. exported="true" is required for APPWIDGET_UPDATE from
         the launcher; the custom click/done actions are deliberately NOT listed here —
         they are delivered via explicit-component PendingIntents, and listing them
         would let any app on the device trigger them. -->
    <receiver
      android:name=".widget.TaskListWidgetProvider"
      android:exported="true"
      android:label="@string/widget_title">
      <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
      </intent-filter>
      <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/appwidget_info" />
    </receiver>

    <service
      android:name=".widget.TaskListWidgetService"
      android:exported="false"
      android:permission="android.permission.BIND_REMOTEVIEWS" />

  </application>
</manifest>
