Skip to content

Colota - Android GPS Location tracker

Add prominent location disclosure modal for Google Play compliance

Max Dietrich6c68996827f5
diff --git a/apps/mobile/src/components/index.ts b/apps/mobile/src/components/index.ts
index c8e9e34f6..5f1fcb7b 100644
--- a/apps/mobile/src/components/index.ts
+++ b/apps/mobile/src/components/index.ts
@@ -22,6 +22,7 @@ export { NumericInput } from "./ui/NumericInput"
export { FloatingSaveIndicator } from "./ui/FloatingSaveIndicator"
export { Footer } from "./ui/Footer"
export { SpinningLoader } from "./ui/SpinningLoader"
+export { LocationDisclosureModal } from "./ui/LocationDisclosureModal"
// ============================================================================
// Feature Components - Dashboard
diff --git a/apps/mobile/src/components/ui/LocationDisclosureModal.tsx b/apps/mobile/src/components/ui/LocationDisclosureModal.tsx
new file mode 100644
index 00000000..0d5193af
--- /dev/null
+++ b/apps/mobile/src/components/ui/LocationDisclosureModal.tsx
@@ -0,0 +1,159 @@
+/**
+ * Copyright (C) 2026 Max Dietrich
+ * Licensed under the GNU AGPLv3. See LICENSE in the project root for details.
+ */
+
+import React, { useState, useRef, useEffect, useCallback } from "react"
+import { Modal, View, Text, TouchableOpacity, StyleSheet, BackHandler } from "react-native"
+import { useTheme } from "../../hooks/useTheme"
+import { fonts } from "../../styles/typography"
+import { fontSizes } from "@colota/shared"
+import { MapPin } from "lucide-react-native"
+import { registerDisclosureCallback } from "../../services/LocationServicePermission"
+
+/**
+ * Prominent in-app disclosure modal for location data collection.
+ * Required by Google Play's User Data policy.
+ *
+ * Uses the app's theme (not system AlertDialog) to avoid
+ * looking like an Android system prompt.
+ */
+export function LocationDisclosureModal() {
+ const { colors } = useTheme()
+ const [visible, setVisible] = useState(false)
+ const resolveRef = useRef<((value: boolean) => void) | null>(null)
+
+ useEffect(() => {
+ registerDisclosureCallback(() => {
+ return new Promise<boolean>((resolve) => {
+ resolveRef.current = resolve
+ setVisible(true)
+ })
+ })
+ }, [])
+
+ // Block hardware back button while visible
+ useEffect(() => {
+ if (!visible) return
+ const handler = BackHandler.addEventListener("hardwareBackPress", () => true)
+ return () => handler.remove()
+ }, [visible])
+
+ const handleAgree = useCallback(() => {
+ setVisible(false)
+ resolveRef.current?.(true)
+ resolveRef.current = null
+ }, [])
+
+ const handleNotNow = useCallback(() => {
+ setVisible(false)
+ resolveRef.current?.(false)
+ resolveRef.current = null
+ }, [])
+
+ return (
+ <Modal visible={visible} transparent animationType="fade" statusBarTranslucent>
+ <View style={[styles.overlay, { backgroundColor: colors.overlay }]}>
+ <View style={[styles.card, { backgroundColor: colors.cardElevated, borderRadius: colors.borderRadius + 4 }]}>
+ {/* Icon */}
+ <View style={[styles.iconContainer, { backgroundColor: colors.primary + "15" }]}>
+ <MapPin size={28} color={colors.primary} />
+ </View>
+
+ {/* Title */}
+ <Text style={[styles.title, { color: colors.text }]}>Location Data Collection</Text>
+
+ {/* Body */}
+ <Text style={[styles.body, { color: colors.textSecondary }]}>
+ Colota collects location data to enable GPS tracking and sending your position to your configured server,
+ even when the app is closed or not in use.
+ </Text>
+
+ <Text style={[styles.body, { color: colors.textSecondary, marginTop: 8 }]}>
+ This data is sent only to the server you set up. No data is shared with third parties.
+ </Text>
+
+ <Text style={[styles.body, { color: colors.textSecondary, marginTop: 8 }]}>
+ The app also needs notification and battery permissions to keep tracking running reliably.
+ </Text>
+
+ {/* Buttons */}
+ <View style={styles.buttons}>
+ <TouchableOpacity
+ style={[styles.button, styles.secondaryButton, { borderColor: colors.border }]}
+ onPress={handleNotNow}
+ activeOpacity={0.7}
+ >
+ <Text style={[styles.buttonText, { color: colors.textSecondary }]}>Not Now</Text>
+ </TouchableOpacity>
+
+ <TouchableOpacity
+ style={[styles.button, styles.primaryButton, { backgroundColor: colors.primary }]}
+ onPress={handleAgree}
+ activeOpacity={0.7}
+ >
+ <Text style={[styles.buttonText, { color: colors.textOnPrimary }]}>Agree</Text>
+ </TouchableOpacity>
+ </View>
+ </View>
+ </View>
+ </Modal>
+ )
+}
+
+const styles = StyleSheet.create({
+ overlay: {
+ flex: 1,
+ justifyContent: "center",
+ alignItems: "center",
+ paddingHorizontal: 32
+ },
+ card: {
+ width: "100%",
+ padding: 24,
+ elevation: 8,
+ shadowColor: "#000",
+ shadowOffset: { width: 0, height: 4 },
+ shadowOpacity: 0.2,
+ shadowRadius: 12
+ },
+ iconContainer: {
+ width: 56,
+ height: 56,
+ borderRadius: 28,
+ justifyContent: "center",
+ alignItems: "center",
+ alignSelf: "center",
+ marginBottom: 16
+ },
+ title: {
+ fontSize: fontSizes.cardTitle,
+ ...fonts.bold,
+ textAlign: "center",
+ marginBottom: 16
+ },
+ body: {
+ fontSize: fontSizes.body,
+ ...fonts.regular,
+ lineHeight: 20
+ },
+ buttons: {
+ flexDirection: "row",
+ gap: 12,
+ marginTop: 24
+ },
+ button: {
+ flex: 1,
+ paddingVertical: 14,
+ borderRadius: 8,
+ alignItems: "center"
+ },
+ primaryButton: {},
+ secondaryButton: {
+ borderWidth: 1.5
+ },
+ buttonText: {
+ fontSize: fontSizes.label,
+ ...fonts.semiBold
+ }
+})
diff --git a/apps/mobile/src/contexts/TrackingProvider.tsx b/apps/mobile/src/contexts/TrackingProvider.tsx
index 7394b49b..f34aa02a 100644
--- a/apps/mobile/src/contexts/TrackingProvider.tsx
+++ b/apps/mobile/src/contexts/TrackingProvider.tsx
@@ -8,6 +8,7 @@ import { Settings, DEFAULT_SETTINGS, LocationCoords, ApiTemplateName, HttpMethod
import { useLocationTracking } from "../hooks/useLocationTracking"
import NativeLocationService from "../services/NativeLocationService"
import SettingsService from "../services/SettingsService"
+import { LocationDisclosureModal } from "../components/ui/LocationDisclosureModal"
import { logger } from "../utils/logger"
type TrackingContextType = {
@@ -252,7 +253,12 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) {
[settings, coords, tracking, isLoading, error, setSettings, startTracking, stopTracking, restartTracking]
)
- return <TrackingContext.Provider value={value}>{children}</TrackingContext.Provider>
+ return (
+ <TrackingContext.Provider value={value}>
+ <LocationDisclosureModal />
+ {children}
+ </TrackingContext.Provider>
+ )
}
/**
diff --git a/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx b/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
index 1608fb06..714eaf7d 100644
--- a/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
+++ b/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
@@ -16,6 +16,10 @@ jest.mock("../../services/SettingsService", () => ({
updateSetting: jest.fn().mockResolvedValue(true)
}))
+jest.mock("../../components/ui/LocationDisclosureModal", () => ({
+ LocationDisclosureModal: () => null
+}))
+
const mockStartTracking = jest.fn().mockResolvedValue(undefined)
const mockStopTracking = jest.fn()
const mockRestartTracking = jest.fn().mockResolvedValue(undefined)
diff --git a/apps/mobile/src/services/LocationServicePermission.ts b/apps/mobile/src/services/LocationServicePermission.ts
index 469d8d0c..ee4697a7 100644
--- a/apps/mobile/src/services/LocationServicePermission.ts
+++ b/apps/mobile/src/services/LocationServicePermission.ts
@@ -23,44 +23,62 @@ const ANDROID_10 = 29
/** Android version for notifications (Android 13) */
const ANDROID_13 = 33
+/**
+ * Callback registered by LocationDisclosureModal to show the themed disclosure.
+ * Falls back to Alert.alert if no modal is registered (e.g. in tests).
+ */
+type DisclosureCallback = () => Promise<boolean>
+let _disclosureCallback: DisclosureCallback | null = null
+
+/**
+ * Registers the disclosure modal callback.
+ * Called by LocationDisclosureModal on mount.
+ */
+export function registerDisclosureCallback(cb: DisclosureCallback) {
+ _disclosureCallback = cb
+}
+
/**
* Requests all necessary permissions for location tracking.
*
- * Requests in sequence:
- * 1. Fine location (always required)
- * 2. Background location (Android 10+)
- * 3. Notifications (Android 13+)
- * 4. Battery optimization exemption
- *
- * Shows alerts explaining each permission and returns false if any critical permission is denied.
+ * Shows a prominent disclosure first (required by Google Play),
+ * then requests permissions. Skips if all permissions are already granted.
*
* @returns True if all required permissions granted
- *
- * @example
- * ```ts
- * if (await ensurePermissions()) {
- * startLocationTracking();
- * }
- * ```
*/
export async function ensurePermissions(): Promise<boolean> {
if (Platform.OS !== "android") return true
try {
- // 1. Fine location (required)
- if (!(await requestFineLocation())) return false
+ // Skip disclosure + requests if everything is already granted
+ const status = await checkPermissions()
+ if (status.location && status.background && status.notifications) {
+ await requestBatteryOptimizationExemption()
+ return true
+ }
+
+ // Prominent disclosure (required by Google Play User Data policy)
+ const consented = _disclosureCallback ? await _disclosureCallback() : await fallbackDisclosure()
+ if (!consented) return false
+
+ // Fine location
+ if (!status.location) {
+ const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
+ if (result !== PermissionsAndroid.RESULTS.GRANTED) return false
+ }
- // 2. Background location (Android 10+)
- if (Platform.Version >= ANDROID_10) {
- if (!(await requestBackgroundLocation())) return false
+ // Background location (Android 10+)
+ if (Platform.Version >= ANDROID_10 && !status.background) {
+ const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION)
+ if (result !== PermissionsAndroid.RESULTS.GRANTED) return false
}
- // 3. Notifications (Android 13+)
- if (Platform.Version >= ANDROID_13) {
- if (!(await requestNotificationPermission())) return false
+ // Notifications (Android 13+, non-blocking)
+ if (Platform.Version >= ANDROID_13 && !status.notifications) {
+ await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS)
}
- // 4. Battery optimization exemption (optional but recommended)
+ // Battery optimization exemption (optional)
await requestBatteryOptimizationExemption()
return true
@@ -72,69 +90,20 @@ export async function ensurePermissions(): Promise<boolean> {
}
/**
- * Requests fine location permission
+ * Fallback disclosure using Alert (for tests or if modal not mounted).
*/
-async function requestFineLocation(): Promise<boolean> {
- const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
- title: "Location Permission",
- message: "Colota needs access to your location to track your position.",
- buttonPositive: "Allow",
- buttonNegative: "Deny"
- })
-
- if (result !== PermissionsAndroid.RESULTS.GRANTED) {
- Alert.alert("Permission Required", "Location permission is required for this app to function.", [{ text: "OK" }])
- return false
- }
-
- return true
-}
-
-/**
- * Requests background location permission (Android 10+)
- */
-async function requestBackgroundLocation(): Promise<boolean> {
- const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION, {
- title: "Background Location Permission",
- message:
- "To track your location continuously, Colota needs permission to access your location in the background, even when you are not actively using it.",
- buttonPositive: "Allow",
- buttonNegative: "Deny"
- })
-
- if (result !== PermissionsAndroid.RESULTS.GRANTED) {
+function fallbackDisclosure(): Promise<boolean> {
+ return new Promise((resolve) => {
Alert.alert(
- "Background Permission Denied",
- "Background location permission is needed for continuous tracking. The app may stop when closed or in the background.",
- [{ text: "OK" }]
+ "Location Data Collection",
+ "Colota collects location data to enable GPS tracking and sending your position to your configured server, even when the app is closed or not in use.\n\nNo data is shared with third parties.",
+ [
+ { text: "Not Now", style: "cancel", onPress: () => resolve(false) },
+ { text: "Agree", onPress: () => resolve(true) }
+ ],
+ { cancelable: false }
)
- return false
- }
-
- return true
-}
-
-/**
- * Requests notification permission (Android 13+)
- */
-async function requestNotificationPermission(): Promise<boolean> {
- const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS, {
- title: "Notification Permission",
- message: "Colota needs permission to show notifications while tracking your location.",
- buttonPositive: "Allow",
- buttonNegative: "Deny"
})
-
- if (result !== PermissionsAndroid.RESULTS.GRANTED) {
- Alert.alert(
- "Notification Permission Denied",
- "Without notification permission, you will not see tracking status updates.",
- [{ text: "OK" }]
- )
- return false
- }
-
- return true
}
/**
@@ -148,20 +117,11 @@ async function requestBatteryOptimizationExemption(): Promise<void> {
}
} catch (err) {
logger.error("[PermissionService] Battery optimization request failed:", err)
- // Non-critical, don't block
}
}
/**
* Checks current permission status without requesting.
- *
- * Useful for checking before starting tracking or displaying status in settings.
- *
- * @example
- * ```ts
- * const status = await checkPermissions();
- * if (!status.location) console.log('Location not granted');
- * ```
*/
export async function checkPermissions(): Promise<PermissionStatus> {
if (Platform.OS !== "android") {
@@ -188,42 +148,25 @@ export async function checkPermissions(): Promise<PermissionStatus> {
}
}
-/**
- * Check fine location permission
- */
async function checkFineLocation(): Promise<boolean> {
return await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
}
-/**
- * Gets Android version as a number
- */
function getAndroidVersion(): number {
if (Platform.OS !== "android") return 0
return typeof Platform.Version === "number" ? Platform.Version : parseInt(Platform.Version, 10) || 0
}
-/**
- * Check background location permission (Android 10+)
- */
async function checkBackgroundLocation(): Promise<boolean> {
if (getAndroidVersion() < ANDROID_10) return true
-
return await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION)
}
-/**
- * Check notification permission (Android 13+)
- */
async function checkNotifications(): Promise<boolean> {
if (getAndroidVersion() < ANDROID_13) return true
-
return await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS)
}
-/**
- * Check battery optimization status
- */
async function checkBatteryOptimization(): Promise<boolean> {
try {
return await NativeLocationService.isIgnoringBatteryOptimizations()
diff --git a/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts b/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
index d0f9993c..874c02b7 100644
--- a/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
+++ b/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
@@ -1,5 +1,5 @@
import { Platform, PermissionsAndroid, Alert } from "react-native"
-import { ensurePermissions, checkPermissions } from "../LocationServicePermission"
+import { ensurePermissions, checkPermissions, registerDisclosureCallback } from "../LocationServicePermission"
// Mock NativeLocationService
jest.mock("../NativeLocationService", () => ({
@@ -28,13 +28,18 @@ beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(console, "error").mockImplementation()
requestSpy = jest.spyOn(PermissionsAndroid, "request").mockResolvedValue(PermissionsAndroid.RESULTS.GRANTED)
- checkSpy = jest.spyOn(PermissionsAndroid, "check").mockResolvedValue(true)
+ // Default: permissions not granted (so disclosure + request flow runs)
+ checkSpy = jest.spyOn(PermissionsAndroid, "check").mockResolvedValue(false)
alertSpy = jest.spyOn(Alert, "alert").mockImplementation()
+ // Register auto-agree disclosure for tests
+ registerDisclosureCallback(() => Promise.resolve(true))
})
afterEach(() => {
jest.restoreAllMocks()
setPlatform(originalOS, originalVersion as number)
+ // Reset disclosure callback
+ registerDisclosureCallback(() => Promise.resolve(true))
})
describe("ensurePermissions", () => {
@@ -47,12 +52,47 @@ describe("ensurePermissions", () => {
expect(requestSpy).not.toHaveBeenCalled()
})
+ it("skips disclosure and requests if all permissions already granted", async () => {
+ setPlatform("android", 33)
+ checkSpy.mockResolvedValue(true)
+
+ const disclosureSpy = jest.fn().mockResolvedValue(true)
+ registerDisclosureCallback(disclosureSpy)
+
+ const result = await ensurePermissions()
+
+ expect(result).toBe(true)
+ expect(disclosureSpy).not.toHaveBeenCalled()
+ expect(requestSpy).not.toHaveBeenCalled()
+ })
+
+ it("shows disclosure before requesting permissions", async () => {
+ setPlatform("android", 28)
+ const disclosureSpy = jest.fn().mockResolvedValue(true)
+ registerDisclosureCallback(disclosureSpy)
+
+ await ensurePermissions()
+
+ expect(disclosureSpy).toHaveBeenCalledTimes(1)
+ expect(requestSpy).toHaveBeenCalled()
+ })
+
+ it("returns false if user denies disclosure", async () => {
+ setPlatform("android", 28)
+ registerDisclosureCallback(() => Promise.resolve(false))
+
+ const result = await ensurePermissions()
+
+ expect(result).toBe(false)
+ expect(requestSpy).not.toHaveBeenCalled()
+ })
+
it("requests fine location permission", async () => {
setPlatform("android", 28)
await ensurePermissions()
- expect(requestSpy).toHaveBeenCalledWith(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, expect.any(Object))
+ expect(requestSpy).toHaveBeenCalledWith(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
})
it("returns false if fine location denied", async () => {
@@ -62,7 +102,6 @@ describe("ensurePermissions", () => {
const result = await ensurePermissions()
expect(result).toBe(false)
- expect(alertSpy).toHaveBeenCalledWith("Permission Required", expect.any(String), expect.any(Array))
})
it("requests background location on Android 10+", async () => {
@@ -70,10 +109,7 @@ describe("ensurePermissions", () => {
await ensurePermissions()
- expect(requestSpy).toHaveBeenCalledWith(
- PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
- expect.any(Object)
- )
+ expect(requestSpy).toHaveBeenCalledWith(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION)
})
it("skips background location on Android < 10", async () => {
@@ -90,7 +126,7 @@ describe("ensurePermissions", () => {
await ensurePermissions()
- expect(requestSpy).toHaveBeenCalledWith(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS, expect.any(Object))
+ expect(requestSpy).toHaveBeenCalledWith(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS)
})
it("skips notification permission on Android < 13", async () => {
@@ -113,7 +149,7 @@ describe("ensurePermissions", () => {
expect(result).toBe(false)
})
- it("returns false if notification permission denied", async () => {
+ it("still returns true if notification permission denied (non-blocking)", async () => {
setPlatform("android", 33)
requestSpy
.mockResolvedValueOnce(PermissionsAndroid.RESULTS.GRANTED) // fine location
@@ -122,12 +158,13 @@ describe("ensurePermissions", () => {
const result = await ensurePermissions()
- expect(result).toBe(false)
+ expect(result).toBe(true)
})
it("requests battery optimization exemption", async () => {
setPlatform("android", 33)
- mockIsIgnoring.mockResolvedValueOnce(false)
+ // First call from checkPermissions (checkBatteryOptimization), second from requestBatteryOptimizationExemption
+ mockIsIgnoring.mockResolvedValueOnce(false).mockResolvedValueOnce(false)
await ensurePermissions()
@@ -154,13 +191,54 @@ describe("ensurePermissions", () => {
it("returns false and shows alert on unexpected error", async () => {
setPlatform("android", 28)
- requestSpy.mockRejectedValueOnce(new Error("unexpected"))
+ checkSpy.mockRejectedValueOnce(new Error("unexpected"))
const result = await ensurePermissions()
expect(result).toBe(false)
expect(alertSpy).toHaveBeenCalledWith("Permission Error", expect.any(String), expect.any(Array))
})
+
+ it("uses fallback Alert disclosure if no callback registered", async () => {
+ setPlatform("android", 28)
+ // Unregister callback to trigger fallback
+ registerDisclosureCallback(undefined as any)
+
+ // ensurePermissions will call fallbackDisclosure() which uses Alert.alert
+ // Alert.alert is mocked so it won't block - we need to simulate the tap
+ alertSpy.mockImplementation((_title: string, _msg: string, buttons: any[]) => {
+ // Auto-tap "Agree"
+ const agreeButton = buttons.find((b: any) => b.text === "Agree")
+ if (agreeButton?.onPress) agreeButton.onPress()
+ })
+
+ const result = await ensurePermissions()
+
+ expect(alertSpy).toHaveBeenCalledWith(
+ "Location Data Collection",
+ expect.stringContaining("location data"),
+ expect.any(Array),
+ expect.any(Object)
+ )
+ expect(result).toBe(true)
+ })
+
+ it("skips already-granted permissions", async () => {
+ setPlatform("android", 33)
+ // Fine location already granted, background and notifications not
+ checkSpy.mockImplementation((permission: string) => {
+ if (permission === PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) {
+ return Promise.resolve(true)
+ }
+ return Promise.resolve(false)
+ })
+
+ await ensurePermissions()
+
+ const permissions = requestSpy.mock.calls.map((c: any[]) => c[0])
+ expect(permissions).not.toContain(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
+ expect(permissions).toContain(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION)
+ })
})
describe("checkPermissions", () => {