TL;DR — On Android 14 a regular app cannot start a foreground service with systemExempted: startForeground() throws SecurityException, the service silently dies, and the user just sees "VPN is not working". For a VPN client that isn't a system app, the working path is specialUse + FOREGROUND_SERVICE_SPECIAL_USE + a vpn subtype in the manifest.
Context
I maintain an Android VPN client built on VpnService. Since API 26 it runs as a foreground service: persistent notification, startForegroundService(), startForeground() inside the service. That worked fine on Android 8–13.
Android 14 (API 34) tightened the rules: every foreground service must declare a type, and the type must be allowed for the app. Depending on what exactly the system considers violated, you get MissingForegroundServiceTypeException or SecurityException.
For a VPN, FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED looked logical:
val fgsType = if (Build.VERSION.SDK_INT >= 34) { ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED } else 0 startForeground(NOTIF_VPN_ID, notif, fgsType) It works constantly like an antivirus or a system daemon, so "system exempted" seemed right. The manifest got android:foregroundServiceType="systemExempted".
On Android 12 this worked perfectly — the type wasn't enforced that strictly. On Android 14 it did not.
Symptoms
On an API 34 emulator the app started, showed "Connecting…", and a few seconds later dropped into an error state. Logcat and the service's own log looked like this:
E/AppVpnService: startForeground failed: SecurityException: ... I/AppVpnService: SVC_FATAL reason=foreground_fail I/AppVpnService: SVC_STOP reason=exhausted last=foreground_fail startForeground() threw SecurityException, the service never got the foreground flag, retries were exhausted (the app has a 3-attempt limit), and the user saw "Disconnected (error)".
The important detail: the app did not crash. The exception was caught, the UI kept working — but the VPN did not. This kind of bug is easy to miss if you only check "does the app crash?".
The exact message varies between versions, but the root cause is the same: systemExempted requires android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED, which has signature|privileged protection level — a regular app can't get it at all.
Why Android 12 didn't reproduce it
Before Android 14 the FGS type was only needed for some permissions and wasn't enforced that hard. On Android 12 (API 31) the old code worked, so the bug only appeared on an API 34 emulator. Lesson: don't test foreground services only on older APIs.
Another emulator surprise: after fixing FGS the native tunnel still didn't come up — the app is arm64-only and the x86 emulator uses ARM translation. So SVC_FOREGROUND ok is a real win, but "full VPN on emulator" is not a valid test. You need a real arm64 device. That's a separate story.
What actually needs to change
1. Manifest
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" /> <service android:name=".AppVpnService" android:exported="false" android:permission="android.permission.BIND_VPN_SERVICE" android:foregroundServiceType="specialUse"> <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="vpn" /> </service> Key elements:
-
android:foregroundServiceType="specialUse"— the type; -
FOREGROUND_SERVICE_SPECIAL_USE— a normal (not runtime) permission; -
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" ...>— the subtype that explains why. Google Play reviewers read it when the app is published there.
2. Code
return try { val fgsType = if (Build.VERSION.SDK_INT >= 34) { ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE } else 0 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && fgsType != 0) { startForeground(NOTIF_VPN_ID, notif, fgsType) } else { startForeground(NOTIF_VPN_ID, notif) } foregroundStarted = true log("SVC_FOREGROUND ok") true } catch (e: Throwable) { Log.e(TAG, "startForeground failed: ${e.javaClass.simpleName}: ${e.message}") log("SVC_FOREGROUND fail error=${e.javaClass.simpleName}") false } Two things worth calling out:
- Wrap
startForegroundin try/catch. Different APIs throw different exceptions:SecurityException,MissingForegroundServiceTypeException,ForegroundServiceStartNotAllowedException. The app must not crash because the system denied foreground. - Log into your own black box. My service writes key events to its own log (
SVC_FOREGROUND ok,SVC_FATAL reason=...). On a real device debugging these issues without it is much harder.
How to verify FGS actually started
- Logs:
SVC_FOREGROUND okin the service log / logcat; -
dumpsys:
adb shell dumpsys activity services com.example.vpnclient | grep -i foreground - Behaviour: on Android 14 the service must not die 1–2 minutes after the screen turns off; the notification must stay visible.
Pitfalls
-
systemExemptedis not for regular apps. TheFOREGROUND_SERVICE_SYSTEM_EXEMPTEDpermission issignature|privileged. Being a VPN is not a reason. - Google Play and
specialUse.specialUseitself is a valid path, but Play asks you to justify it: fill the FGS declaration in Play Console, otherwise the release is rejected. For RuStore and direct APK distribution there's no such declaration, but filling in the subtype still helps manual review. -
specialUseis not a free pass. Reviewers check that the activity can't be classified as another type. For VPNs it's usually fine. - Time. After
startForegroundService()you have roughly 5 seconds to callstartForeground(). Do heavy init after it, not before. - Don't use
connectedDevice/dataSyncfor VPN. If unsure —specialUsewith a clear subtype. - The silent regression. If
startForegroundthrows and you swallow it, the app keeps running without foreground and Android kills the service in the background. Always check the result, not just the absence of a crash.
Checklist for VPN apps on Android 14+
- [ ] Manifest:
foregroundServiceType="specialUse",FOREGROUND_SERVICE_SPECIAL_USE,PROPERTY_SPECIAL_USE_FGS_SUBTYPE=vpn; - [ ] Code: on SDK ≥ 34 call
startForeground(id, notif, FOREGROUND_SERVICE_TYPE_SPECIAL_USE); - [ ]
startForegroundwrapped in try/catch, error logged and handled; - [ ] FGS declaration filled in Play Console (if publishing to Google Play);
- [ ] Tested on a real Android 14+ device, not only on older APIs;
- [ ] Logs show the equivalent of
SVC_FOREGROUND ok, not just "the app didn't crash".
Conclusion
Android 14 forces you to pick an FGS type explicitly and verify it's allowed. For a VPN client that isn't a system app, systemExempted is a dead end: the exception is thrown inside startForeground, the service quietly dies, and the user sees "VPN is not working". specialUse with the vpn subtype is the supported, working option. And the most useful addition besides the fix is logging key service events into your own log — without it these bugs look like "it sometimes doesn't work".

