Skip to content

Colota - Android GPS Location tracker

fix(permissions): remove the unused disclosure fallbacks (#919)

Max Dietrich41a994a82b55
diff --git a/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx b/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
index 568af7db..22e0cf70 100644
--- a/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
+++ b/apps/mobile/src/contexts/__tests__/TrackingProvider.test.tsx
@@ -17,12 +17,20 @@ jest.mock("../../services/SettingsService", () => ({
updateSetting: jest.fn().mockResolvedValue(true)
}))
+const mockMountedDisclosures: string[] = []
+
jest.mock("../../components/ui/LocationDisclosureModal", () => ({
- LocationDisclosureModal: () => null
+ LocationDisclosureModal: () => {
+ mockMountedDisclosures.push("location")
+ return null
+ }
}))
jest.mock("../../components/ui/LocalNetworkDisclosureModal", () => ({
- LocalNetworkDisclosureModal: () => null
+ LocalNetworkDisclosureModal: () => {
+ mockMountedDisclosures.push("localNetwork")
+ return null
+ }
}))
jest.mock("../../components/ui/AppModal", () => ({
@@ -77,6 +85,14 @@ const settleHydration = async () => {
const wrapper = ({ children }: { children: React.ReactNode }) => <TrackingProvider>{children}</TrackingProvider>
+// Nothing else shows a disclosure: without these mounts no permission is ever requested on a fresh install.
+it("mounts both permission disclosures", () => {
+ mockMountedDisclosures.length = 0
+ renderHook(() => useTracking(), { wrapper })
+
+ expect(mockMountedDisclosures).toEqual(expect.arrayContaining(["location", "localNetwork"]))
+})
+
describe("useTracking", () => {
it("throws when used outside TrackingProvider", () => {
const spy = jest.spyOn(console, "error").mockImplementation()
diff --git a/apps/mobile/src/hooks/useLocationTracking.ts b/apps/mobile/src/hooks/useLocationTracking.ts
index 471266e9..7594606b 100644
--- a/apps/mobile/src/hooks/useLocationTracking.ts
+++ b/apps/mobile/src/hooks/useLocationTracking.ts
@@ -11,6 +11,7 @@ import { LocationCoords, Settings, LocationTrackingResult } from "../types/globa
import { ensurePermissions, checkPermissions } from "../services/LocationServicePermission"
import { SERVICE_RESTART_DELAY_MS, RESTART_DEBOUNCE_MS } from "../constants"
import { logger } from "../utils/logger"
+import { t } from "../i18n/t"
const { LocationServiceModule } = NativeModules
const locationEventEmitter = new NativeEventEmitter(LocationServiceModule)
@@ -170,7 +171,7 @@ export function useLocationTracking(settings: Settings, settingsHydrated: boolea
const granted = await ensurePermissions()
if (!granted) {
- showAlert("Permission Required", "Background location permission is required for tracking.", "warning")
+ showAlert(t("permission.required.title"), t("permission.required.message"), "warning")
return
}
@@ -182,7 +183,7 @@ export function useLocationTracking(settings: Settings, settingsHydrated: boolea
} catch (error) {
setTracking(false)
logger.error("[useLocationTracking] Failed to start:", error)
- showAlert("Error", "Failed to start location tracking.", "error")
+ showAlert(t("common.error"), t("permission.startFailed"), "error")
}
}, [])
diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.json
index 5390986d..00599378 100644
--- a/apps/mobile/src/i18n/locales/en.json
+++ b/apps/mobile/src/i18n/locales/en.json
@@ -1241,5 +1241,10 @@
"about.copyright": "Copyright © 2026 Max Dietrich and contributors. Colota is free software, with no warranty; the License row above has the terms.",
"log.delete.subCarries": "Removes {{size}}. Recording carries on into a new file.",
"language.system": "System default",
- "language.changeFailed": "Could not change the language."
+ "language.changeFailed": "Could not change the language.",
+ "permission.error.title": "Permission Error",
+ "permission.error.message": "Failed to request permissions. Please try again.",
+ "permission.required.title": "Permission Required",
+ "permission.required.message": "Background location permission is required for tracking.",
+ "permission.startFailed": "Failed to start location tracking."
}
diff --git a/apps/mobile/src/services/LocationServicePermission.ts b/apps/mobile/src/services/LocationServicePermission.ts
index ebc3375d..ead7b7c0 100644
--- a/apps/mobile/src/services/LocationServicePermission.ts
+++ b/apps/mobile/src/services/LocationServicePermission.ts
@@ -3,10 +3,11 @@
* Licensed under the GNU AGPLv3. See LICENSE in the project root for details.
*/
-import { Platform, PermissionsAndroid, Alert } from "react-native"
+import { Platform, PermissionsAndroid } from "react-native"
import NativeLocationService from "./NativeLocationService"
import { showAlert } from "./modalService"
import { logger } from "../utils/logger"
+import { t } from "../i18n/t"
/**
* Permission status for location tracking
@@ -30,7 +31,7 @@ const ANDROID_LOCAL_NETWORK = 37
/**
* Callback registered by LocationDisclosureModal to show the themed disclosure.
- * Falls back to Alert.alert if no modal is registered (e.g. in tests).
+ * Without one nothing is requested: the reviewed disclosure is the only one Colota shows.
*/
type DisclosureCallback = () => Promise<boolean>
let _disclosureCallback: DisclosureCallback | null = null
@@ -69,7 +70,7 @@ export async function ensurePermissions(): Promise<boolean> {
// Location grants only - including notifications here replays the disclosure on every start
if (!status.location || !status.background) {
// Prominent disclosure (required by Google Play User Data policy)
- const consented = _disclosureCallback ? await _disclosureCallback() : await fallbackDisclosure()
+ const consented = _disclosureCallback ? await _disclosureCallback() : noDisclosure("location")
if (!consented) return false
// Fine location
@@ -97,26 +98,14 @@ export async function ensurePermissions(): Promise<boolean> {
return true
} catch (err) {
logger.error("[PermissionService] Permission request error:", err)
- showAlert("Permission Error", "Failed to request permissions. Please try again.", "error")
+ showAlert(t("permission.error.title"), t("permission.error.message"), "error")
return false
}
}
-/**
- * Fallback disclosure using Alert (for tests or if modal not mounted).
- */
-function fallbackDisclosure(): Promise<boolean> {
- return new Promise((resolve) => {
- Alert.alert(
- "Location Data Collection",
- "Colota collects location data in the background to enable continuous GPS tracking, recording your position history and uploading it to your own server, even when the app is closed or not in use.\n\nYour location is sent only to the server you configure. No data is shared with third parties.",
- [
- { text: "Not Now", style: "cancel", onPress: () => resolve(false) },
- { text: "Agree", onPress: () => resolve(true) }
- ],
- { cancelable: false }
- )
- })
+function noDisclosure(which: string): boolean {
+ logger.warn(`[PermissionService] No ${which} disclosure registered, nothing requested`)
+ return false
}
/**
@@ -214,7 +203,7 @@ export async function ensureLocalNetworkPermission(): Promise<boolean> {
// Show themed disclosure modal first
const consented = _localNetworkDisclosureCallback
? await _localNetworkDisclosureCallback()
- : await fallbackLocalNetworkDisclosure()
+ : noDisclosure("local network")
if (!consented) return false
const result = await PermissionsAndroid.request("android.permission.ACCESS_LOCAL_NETWORK" as any)
@@ -224,20 +213,3 @@ export async function ensureLocalNetworkPermission(): Promise<boolean> {
return false
}
}
-
-/**
- * Fallback disclosure using Alert (for tests or if modal not mounted).
- */
-function fallbackLocalNetworkDisclosure(): Promise<boolean> {
- return new Promise((resolve) => {
- Alert.alert(
- "Local Network Access",
- "Your server is on the local network. Colota needs local network access permission to reach it.",
- [
- { text: "Not Now", style: "cancel", onPress: () => resolve(false) },
- { text: "Continue", onPress: () => resolve(true) }
- ],
- { cancelable: false }
- )
- })
-}
diff --git a/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts b/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
index 6cddb430..3da7f57f 100644
--- a/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
+++ b/apps/mobile/src/services/__tests__/LocationServicePermission.test.ts
@@ -1,4 +1,4 @@
-import { Platform, PermissionsAndroid, Alert } from "react-native"
+import { Platform, PermissionsAndroid } from "react-native"
import {
ensurePermissions,
checkPermissions,
@@ -24,7 +24,6 @@ import NativeLocationService from "../NativeLocationService"
const mockIsIgnoring = NativeLocationService.isIgnoringBatteryOptimizations as jest.Mock
const mockRequestIgnore = NativeLocationService.requestIgnoreBatteryOptimizations as jest.Mock
-let alertSpy: jest.SpyInstance
let requestSpy: jest.SpyInstance
let checkSpy: jest.SpyInstance
@@ -42,7 +41,6 @@ beforeEach(() => {
requestSpy = jest.spyOn(PermissionsAndroid, "request").mockResolvedValue(PermissionsAndroid.RESULTS.GRANTED)
// 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))
})
@@ -253,28 +251,13 @@ describe("ensurePermissions", () => {
expect(showAlert).toHaveBeenCalledWith("Permission Error", expect.any(String), "error")
})
- it("uses fallback Alert disclosure if no callback registered", async () => {
+ // Play reviewed the modal's wording; a stand-in with other text must never reach a user.
+ it("requests nothing when no disclosure is 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)
+ expect(await ensurePermissions()).toBe(false)
+ expect(requestSpy).not.toHaveBeenCalled()
})
it("skips already-granted permissions", async () => {
@@ -451,24 +434,12 @@ describe("ensureLocalNetworkPermission", () => {
expect(result).toBe(false)
})
- it("uses fallback Alert if no callback registered", async () => {
+ it("requests nothing when no local network disclosure is registered", async () => {
setPlatform("android", 37)
registerLocalNetworkDisclosureCallback(undefined as any)
- alertSpy.mockImplementation((_title: string, _msg: string, buttons: any[]) => {
- const continueBtn = buttons.find((b: any) => b.text === "Continue")
- if (continueBtn?.onPress) continueBtn.onPress()
- })
-
- const result = await ensureLocalNetworkPermission()
-
- expect(alertSpy).toHaveBeenCalledWith(
- "Local Network Access",
- expect.stringContaining("local network"),
- expect.any(Array),
- expect.any(Object)
- )
- expect(result).toBe(true)
+ expect(await ensureLocalNetworkPermission()).toBe(false)
+ expect(requestSpy).not.toHaveBeenCalled()
})
it("returns false on unexpected error", async () => {