From 1fb509a49b597b256bbfadad0c2e75de19fd0735 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Mon, 22 Oct 2018 12:48:21 +0200 Subject: [PATCH] API: expose setting for e.g. RepeaterBook --- AndroidManifest.xml | 1 + doc/API.mdwn | 25 +++++++++++++++++++++++++ src/AprsService.scala | 16 ++++++++++++++++ src/PrefsWrapper.scala | 4 ++++ 4 files changed, 46 insertions(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9bdce81..d252c25 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -145,6 +145,7 @@ + diff --git a/doc/API.mdwn b/doc/API.mdwn index 055b758..bde1503 100644 --- a/doc/API.mdwn +++ b/doc/API.mdwn @@ -22,6 +22,8 @@ Intents ("actions"): * `ONCE` - send one position packet and stop * `SERVICE_STOP` - stop APRSdroid's tracking service * `SEND_PACKET` - send a (raw) APRS packet + * `FREQUENCY` - change the frequency announced in position packets (requires + APRSdroid 1.4.1) All uppercase strings mentioned in this document are suffixes to `"org.aprsdroid.app."` and need to be concatenated for the effective @@ -196,6 +198,29 @@ Example for sending a raw status packet: i.putExtra("data", ">third-party APRS status app"); startService(i); +### FREQUENCY (APRSdroid 1.4.1) + +Update the [frequency field](http://www.aprs.org/info/freqspec.txt) in the +position reports sent by APRSdroid. If the APRSdroid service is running, this +will immediately generate a position packet with the new frequency. + +Intent extras: + + * `frequency` (String): the new frequency value, e.g. "438.750MHz", "145.500" + or "" to disable, decimal separator must be a dot (".") + +Example for updating the frequency: + + // send raw status packet + Intent i = new Intent("org.aprsdroid.app.FREQUENCY").setPackage("org.aprsdroid.app"); + i.putExtra("frequency", "438.750"); + startService(i); + +Invocation from the adb shell: + + am startservice -a org.aprsdroid.app.FREQUENCY -e frequency "438.750" + + ## (In-)Security Currently, APRSdroid exposes the following personal information via diff --git a/src/AprsService.scala b/src/AprsService.scala index 89b557c..752a4e4 100644 --- a/src/AprsService.scala +++ b/src/AprsService.scala @@ -16,6 +16,7 @@ object AprsService { val SERVICE = PACKAGE + ".SERVICE" val SERVICE_ONCE = PACKAGE + ".ONCE" val SERVICE_SEND_PACKET = PACKAGE + ".SEND_PACKET" + val SERVICE_FREQUENCY = PACKAGE + ".FREQUENCY" val SERVICE_STOP = PACKAGE + ".SERVICE_STOP" // event intents val SERVICE_STARTED = PACKAGE + ".SERVICE_STARTED" @@ -122,8 +123,23 @@ class AprsService extends Service { data_field) sendPacket(p) return + } else + if (i.getAction() == SERVICE_FREQUENCY) { + val data_field = i.getStringExtra("frequency") + if (data_field == null) { + Log.d(TAG, "FREQUENCY ignored, 'frequency' extra is empty.") + return + } + val freq_cleaned = data_field.replace("MHz", "").trim + val freq = try { freq_cleaned.toFloat; freq_cleaned } catch { case _ : Throwable => "" } + if (prefs.getString("frequency", null) != freq) { + prefs.set("frequency", freq) + if (!running) return + // XXX: fall through into SERVICE_ONCE + } else return } + // display notification (even though we are not actually started yet, // but we need this to prevent error message reordering) val toastString = if (i.getAction() == SERVICE_ONCE) { diff --git a/src/PrefsWrapper.scala b/src/PrefsWrapper.scala index 6bf3df1..19835b1 100644 --- a/src/PrefsWrapper.scala +++ b/src/PrefsWrapper.scala @@ -41,6 +41,10 @@ class PrefsWrapper(val context : Context) { prefs.edit().putBoolean(name, new_val).commit() new_val } + def set(name : String, new_val : String) = { + prefs.edit().putString(name, new_val).commit() + new_val + } def getShowObjects() = prefs.getBoolean("show_objects", true) def getShowSatellite() = prefs.getBoolean("show_satellite", false)