1---2name: android-security-best-practices3description: Apply Android app security guidance around secrets, storage, network trust, exported components, and least privilege.4---5# Android Security Best Practices67## When To Use8- Use this skill when the request is about: android security review, secret handling android app, exported component security android.9- Primary outcome: Apply Android app security guidance around secrets, storage, network trust, exported components, and least privilege.10- Read `references/patterns.md` when you need the attack-surface checklist or the storage/network/component decision matrix.11- Read `references/scenarios.md` for manifest, backup, WebView, and release-hardening review paths.12- Handoff skills when the scope expands:13- `android-modernization-upgrade`14- `android-ci-cd-release-playstore`1516## Workflow171. Inventory the attack surface first: exported components, intent/deep link entry points, file sharing, WebView usage, local storage, logs, backups, and network trust config.182. Remove avoidable risk before hardening details: prefer platform pickers and choosers, internal storage, server-issued short-lived tokens, and least-privilege permissions instead of shipping broad access or long-lived secrets.193. Lock the remaining boundaries explicitly with `android:exported`, component permissions, `FileProvider`, `networkSecurityConfig`, debug-only trust anchors, and immutable `PendingIntent`s.204. Review sensitive surfaces that often regress in Android apps: WebView JavaScript bridges, backup/data extraction rules, cleartext exceptions, log redaction, and same-developer IPC assumptions.215. Validate the release posture with reproducible checks, then document residual risks and whether backend enforcement or Play Integrity is advisory or blocking.2223## Guardrails24- Treat client-side secrets as recoverable by attackers; move trust decisions and privileged API access server-side whenever possible.25- Export components only when there is a real external caller, and permission-protect or signature-protect them when the contract is private.26- Use network security config to scope debug trust anchors or cleartext exceptions instead of broad manifest toggles.27- Redact logs, review backups, and keep sensitive data out of shared external storage by default.2829## Anti-Patterns30- Hiding API keys in resources, the NDK, or obfuscation and calling that secure.31- Leaving `android:exported` or intent filters ambiguous on launchable or IPC components.32- Sharing files through raw file paths or overly broad storage permissions instead of `FileProvider` and system surfaces.33- Pinning certificates without an operational rotation story or fallback plan.3435## Review Focus36- Exported activities, services, receivers, and providers with clear ownership and caller expectations.37- Secrets, tokens, and backend trust assumptions.38- Network trust, debug overrides, cleartext usage, and certificate handling.39- File sharing, backups, logs, and user-data leakage paths.40- Abuse signals such as Play Integrity only as layered defense, never as the sole authorization model.4142## Examples43### Happy path44- Scenario: Audit manifests and sharing surfaces for explicit exports, permissions, and `FileProvider` usage.45- Command: `rg -n "android:exported|android:permission|FileProvider|grantUriPermissions" examples`4647### Edge case48- Scenario: Catch insecure backup or network defaults before a release candidate goes out.49- Command: `rg -n "networkSecurityConfig|usesCleartextTraffic|allowBackup|fullBackupContent|dataExtractionRules" examples`5051### Failure recovery52- Scenario: Separate app hardening from modernization or release-pipeline requests.53- Command: `python3 scripts/eval_triggers.py --skill android-security-best-practices`5455## Done Checklist56- Every externally reachable component has explicit exposure and caller constraints.57- Secrets, tokens, and trust decisions are not relying on obscurity in the client app.58- Network, backup, logging, and sharing behavior have explicit release-safe defaults.59- Residual risks and any backend dependencies are documented with clear follow-up work.6061## Official References62- [https://developer.android.com/privacy-and-security/security-best-practices](https://developer.android.com/privacy-and-security/security-best-practices)63- [https://developer.android.com/privacy-and-security/security-tips](https://developer.android.com/privacy-and-security/security-tips)64- [https://developer.android.com/privacy-and-security/risks/unsafe-exported-components](https://developer.android.com/privacy-and-security/risks/unsafe-exported-components)65- [https://developer.android.com/privacy-and-security/risks/access-control-to-exported-components](https://developer.android.com/privacy-and-security/risks/access-control-to-exported-components)66- [https://developer.android.com/privacy-and-security/security-config](https://developer.android.com/privacy-and-security/security-config)67- [https://developer.android.com/privacy-and-security/minimize-permission-requests](https://developer.android.com/privacy-and-security/minimize-permission-requests)68- [https://developer.android.com/google/play/integrity/overview](https://developer.android.com/google/play/integrity/overview)