feat(core/service): Implement Android and JVM Location and File services

This commit is contained in:
James Rich 2026-03-16 10:30:43 -05:00
parent 30c1b598bb
commit 1ffa7d2f58
6 changed files with 273 additions and 0 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.repository
import okio.BufferedSink
import okio.BufferedSource
import org.meshtastic.core.common.util.MeshtasticUri
/**
* Abstracts file system operations (like reading from or writing to URIs)
* so that ViewModels can remain platform-independent.
*/
interface FileService {
/**
* Opens a file or URI for writing and provides a [BufferedSink].
* The sink is automatically closed after [block] execution.
* Returns true if successful, false otherwise.
*/
suspend fun write(uri: MeshtasticUri, block: suspend (BufferedSink) -> Unit): Boolean
/**
* Opens a file or URI for reading and provides a [BufferedSource].
* The source is automatically closed after [block] execution.
* Returns true if successful, false otherwise.
*/
suspend fun read(uri: MeshtasticUri, block: suspend (BufferedSource) -> Unit): Boolean
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.repository
/**
* Abstracts high-level location requests (such as one-off current location)
* that may require platform-specific permission checks or hardware interactions.
*/
interface LocationService {
/**
* Requests the current location, if permissions and hardware allow.
* Returns null if unavailable or if permissions are not granted.
*/
suspend fun getCurrentLocation(): Location?
}