# Android foreground service types declared correctly

- **Pattern:** `ab-000438` (`app-store-metadata-listing.compliance-declarations.foreground-services`)
- **Severity:** low
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-000438
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-000438)

## Why it matters

Android 14 (API 34) made `android:foregroundServiceType` a hard requirement — a service that starts as a foreground service without a declared type throws a `MissingForegroundServiceTypeException` at runtime and crashes immediately on all Android 14+ devices. As of 2026, Android 14+ accounts for the majority of active Android installs. This is not a review rejection issue; it is a production crash that manifests the moment a user's device upgrades to Android 14. Libraries that depend on foreground services — audio players (`react-native-track-player`), background location (`react-native-background-geolocation`), and background sync (`expo-background-fetch`) — are all affected.

## Severity rationale

Low as a submission issue because Google Play does not catch it pre-publication, but the runtime crash on Android 14+ devices makes it a production reliability issue at scale.

## Remediation

Add `android:foregroundServiceType` to each foreground service in `android/app/src/main/AndroidManifest.xml`:

```xml
<service
  android:name=".TrackPlayerService"
  android:foregroundServiceType="mediaPlayback"
  android:exported="false" />
```

Add the corresponding permission declaration above `<application>`:

```xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
```

For Expo Managed Workflow, use a config plugin in `app.config.ts` to inject the service type attribute, since `app.json` does not expose this field directly. Test on an Android 14 emulator (API 34) or physical device after making the change — foreground service crashes reproduce immediately in development.

## Detection

- **ID:** `foreground-services`
- **Severity:** `low`
- **What to look for:** Check `android/app/src/main/AndroidManifest.xml` for `<service>` elements. Starting with Android 14 (API 34), foreground services require an explicit `android:foregroundServiceType` attribute. Also check for the corresponding `<uses-permission>` for each service type (e.g., `FOREGROUND_SERVICE_LOCATION`, `FOREGROUND_SERVICE_CAMERA`, `FOREGROUND_SERVICE_MICROPHONE`). In React Native projects with Expo, check `app.json` for `expo.android.permissions` that include foreground service permissions. Common libraries that use foreground services: `expo-background-fetch`, `expo-task-manager`, `react-native-background-actions`, `react-native-track-player`, `react-native-background-geolocation`. If these libraries are present, verify that `android:foregroundServiceType` is declared. Valid types: `camera`, `connectedDevice`, `dataSync`, `health`, `location`, `mediaPlayback`, `mediaProjection`, `microphone`, `phoneCall`, `remoteMessaging`, `shortService`, `specialUse`, `systemExempted`. Count all instances found and enumerate each.
- **Pass criteria:** All `<service>` elements with foreground service behavior have an explicit `android:foregroundServiceType` attribute matching their use case; required permissions are declared; or no foreground services are used. At least 1 implementation must be confirmed.
- **Fail criteria:** A `<service>` element is present that starts as a foreground service (evident from the library type) but lacks `android:foregroundServiceType` when `targetSdkVersion` is 34 or higher.
- **Skip (N/A) when:** iOS-only project; or Android project with no foreground service libraries or `<service>` elements in the manifest.
- **Detail on fail:** `"react-native-track-player detected but no android:foregroundServiceType='mediaPlayback' declared in AndroidManifest.xml — required for targetSdkVersion 34+"`.
- **Remediation:** Missing `foregroundServiceType` causes a crash on Android 14+ devices when the service is started.
  1. Add `android:foregroundServiceType` to each foreground service declaration in `AndroidManifest.xml`:
     ```xml
     <service
       android:name=".TrackPlayerService"
       android:foregroundServiceType="mediaPlayback"
       android:exported="false" />
     ```
  2. Add the corresponding permission above the `<application>` tag:
     ```xml
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
     ```
  3. For Expo Managed Workflow, add the permission to `app.json` and use a config plugin to set the service type

## External references

- external android-foreground-service-types-api34 — https://developer.android.com/about/versions/14/changes/fgs-types-required

Taxons: operational-readiness

HTML version: https://auditbuffet.com/patterns/ab-000438
