<?xml version="1.0" encoding="utf-8"?>
<!--
  Authoritative AndroidManifest for BikeControl.

  This is NOT a manifest-merger fragment. Gradle reads only
  gen/android/app/src/main/AndroidManifest.xml, and `tauri android init`
  regenerates that file from tauri.conf.json — dropping anything it does not
  know about. scripts/sync-android-sources.sh copies this file over the
  generated one, so this is the complete manifest and the single source of
  truth.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <!-- Tauri's dev server; harmless in release, where the assets are local. -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!--
      BLE (FR-1). Android split these permissions at API 31, so both eras are
      declared and each is capped to the era it belongs to.

      `neverForLocation` on BLUETOOTH_SCAN is the load-bearing one: it is a
      promise that we do not derive location from scan results, and it is what
      lets the app scan on API 31+ *without* holding a location permission. We
      can make that promise honestly because every scan is filtered by service
      UUID (FTMS / the Click's Zwift service) — see `bikecontrol-ble::scan`.
      Below API 31 there is no such escape hatch: a BLE scan legally required
      ACCESS_FINE_LOCATION, so it is declared with maxSdkVersion="30" and asked
      for at runtime only on those versions.
    -->
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <!-- No trainer, no app. Let the store and the installer say so up front. -->
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.bikecontrol"
        android:hardwareAccelerated="true"
        android:usesCleartextTraffic="${usesCleartextTraffic}">
        <activity
            android:name=".MainActivity"
            android:label="@string/main_activity_title"
            android:launchMode="singleTask"
            android:exported="true"
            android:resizeableActivity="true"
            android:screenOrientation="fullSensor"
            android:windowSoftInputMode="adjustResize"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|screenLayout|density|locale|uiMode">
            <!--
              Every size-affecting change is in `configChanges` on purpose. The
              activity handles them itself instead of being recreated, so a
              rotation, a fold, or entering split-screen mid-ride re-measures
              the webview (see ui/src/lib/viewport.ts) rather than tearing down
              the process that owns the BLE links and the ride loop. Dropping
              `screenSize` or `density` here would restart the app on rotation
              and disconnect the trainer.
            -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Used by the dialog plugin when the rider exports a FIT file. -->
        <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>
    </application>
</manifest>
