Skip to content

Commit e6da7d9

Browse files
authored
Merge pull request #47 from scottlandis/master
- SOS-T over IPC supported to include SOS-T over SqAN
2 parents f3780bf + bea6eec commit e6da7d9

7 files changed

Lines changed: 59 additions & 6 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
mavenLocal()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.3.0'
11+
classpath 'com.android.tools.build:gradle:3.3.1'
1212

1313

1414
// NOTE: Do not place your application dependencies here; they belong

sample/TORGIListener/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.3.0'
10+
classpath 'com.android.tools.build:gradle:3.3.1'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong

torgi/src/main/java/org/sofwerx/torgi/Config.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Config {
1717
public final static String PREFS_UUID = "callsign";
1818
public final static String PREFS_GPS_ONLY = "gpsonly";
1919
public final static String PREFS_BROADCAST = "broadcast";
20+
public final static String PREFS_SQAN = "sqan";
2021
public final static String PREFS_SEND_TO_SOS = "sendtosos";
2122
public final static String PREFS_SOS_URL = "sosurl";
2223
public final static String PREFS_SOS_ASSIGNED_PROCEDURE = "sosprocedure";
@@ -51,6 +52,10 @@ public static boolean isIpcBroadcastEnabled(Context context) {
5152
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_BROADCAST,true);
5253
}
5354

55+
public static boolean isSqAnBroadcastEnabled(Context context) {
56+
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_SQAN,true);
57+
}
58+
5459
public void loadPrefs() {
5560
gpsOnly = prefs.getBoolean(PREFS_GPS_ONLY,false);
5661
}

torgi/src/main/java/org/sofwerx/torgi/ogc/sos/HttpHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static String post(String serverURL, String body) throws IOException {
6060
}
6161

6262
conn.disconnect();
63+
Log.d(SosIpcTransceiver.TAG,"HttpURLConnection disconnected");
6364

6465
if ((response != null) && (response.length() < 1))
6566
response = null;

torgi/src/main/java/org/sofwerx/torgi/ogc/sos/SosIpcTransceiver.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
import android.util.Log;
77

88
import org.sofwerx.torgi.BuildConfig;
9+
import org.sofwerx.torgi.Config;
910
import org.w3c.dom.Document;
1011
import org.xml.sax.InputSource;
1112
import org.xml.sax.SAXException;
1213

1314
import java.io.ByteArrayInputStream;
1415
import java.io.IOException;
1516
import java.io.StringWriter;
17+
import java.io.UnsupportedEncodingException;
1618
import java.text.ParseException;
1719
import java.text.SimpleDateFormat;
1820
import java.util.Date;
21+
import java.util.Locale;
1922

2023
import javax.xml.parsers.DocumentBuilder;
2124
import javax.xml.parsers.DocumentBuilderFactory;
@@ -36,10 +39,15 @@
3639
public class SosIpcTransceiver extends BroadcastReceiver {
3740
public final static String TAG = "SosIpc";
3841
public final static String SOFWERX_LINK_PLACEHOLDER = "http://www.sofwerx.org/placeholder"; //this is used as a placeholder where a URL should be provided for a new standard or feature
39-
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
42+
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.US);
4043
public static final String ACTION_SOS = "org.sofwerx.ogc.ACTION_SOS";
4144
private static final String EXTRA_PAYLOAD = "SOS";
4245
private static final String EXTRA_ORIGIN = "src";
46+
public static final String ACTION_SQAN_BROADCAST = "org.sofwerx.sqan.pkt";
47+
private final static String SQAN_PACKET_BYTES = "bytes";
48+
private final static String SQAN_PACKET_ORIGIN = "src";
49+
private final static String SQAN_PACKET_CHANNEL = "channel";
50+
private final static String SQAN_CHANNEL = "torgi";
4351
private SosMessageListener listener;
4452

4553
public SosIpcTransceiver(SosMessageListener listener) {
@@ -49,12 +57,28 @@ public SosIpcTransceiver(SosMessageListener listener) {
4957
@Override
5058
public void onReceive(Context context, Intent intent) {
5159
if ((context != null) && (intent != null)) {
52-
if (ACTION_SOS.equals(intent.getAction())) {
60+
String action = intent.getAction();
61+
if (ACTION_SOS.equalsIgnoreCase(action)) {
5362
String origin = intent.getStringExtra(EXTRA_ORIGIN);
5463
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(origin))
5564
onMessageReceived(context, origin, intent.getStringExtra(EXTRA_PAYLOAD));
65+
} else if (ACTION_SQAN_BROADCAST.equalsIgnoreCase(action)) { //forward traffic from SqAN
66+
String origin = intent.getStringExtra(EXTRA_ORIGIN);
67+
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(origin)) {
68+
String channel = intent.getStringExtra(SQAN_PACKET_CHANNEL);
69+
if (SQAN_CHANNEL.equalsIgnoreCase(channel)) { //only handle TORGI channel broadcasts
70+
try {
71+
byte[] bytes = intent.getByteArrayExtra(SQAN_PACKET_BYTES);
72+
if (bytes != null) {
73+
String payload = new String(bytes,"UTF-8");
74+
onMessageReceived(context,"sqan.torgi",payload);
75+
}
76+
} catch (UnsupportedEncodingException ignore) {
77+
}
78+
}
79+
}
5680
} else
57-
Log.e(TAG, "Unexpected action message received: " + intent.getAction());
81+
Log.e(TAG, "Unexpected action message received: " + action);
5882
}
5983
}
6084

@@ -146,8 +170,22 @@ private void broadcast(Context context, String sosOperation) {
146170
Intent intent = new Intent(ACTION_SOS);
147171
intent.putExtra(EXTRA_ORIGIN, BuildConfig.APPLICATION_ID);
148172
intent.putExtra(EXTRA_PAYLOAD,sosOperation);
149-
150173
context.sendBroadcast(intent);
174+
175+
//Broadcast of SqAN as well
176+
if (Config.isSqAnBroadcastEnabled(context)) {
177+
Log.d(TAG,"Broadcasting over SqAN as well");
178+
try {
179+
byte[] bytes = sosOperation.getBytes("UTF-8");
180+
Intent sqanIntent = new Intent(ACTION_SQAN_BROADCAST);
181+
sqanIntent.putExtra(EXTRA_ORIGIN, BuildConfig.APPLICATION_ID);
182+
sqanIntent.putExtra(SQAN_PACKET_BYTES, bytes);
183+
sqanIntent.putExtra(SQAN_PACKET_CHANNEL, SQAN_CHANNEL);
184+
context.sendBroadcast(sqanIntent);
185+
} catch (UnsupportedEncodingException ignore) {
186+
}
187+
}
188+
151189
Log.d(TAG,"Broadcast: "+sosOperation);
152190
}
153191

torgi/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<string name="pref_category_connectivity">Connectivity</string>
3636
<string name="pref_broadcast">Share with other apps</string>
3737
<string name="pref_broadcast_narrative">Automatically share with other apps on this device information about EW risk changes.</string>
38+
<string name="pref_broadcast_sqan">Broadcast over SqAN</string>
39+
<string name="pref_broadcast_sqan_narrative">Automatically share EW risk changes over the Squad Area Network (SqAN) if installed.</string>
3840
<string name="pref_torgi_dir">Saved file directory</string>
3941
<string name="pref_torgi_dir_narrative">TORGI will save files in this directory.</string>
4042
<string name="title_activity_b">Activity</string>

torgi/src/main/res/xml/prefs_app.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
android:summary="@string/pref_broadcast_narrative"
99
android:defaultValue="true"/>
1010

11+
<CheckBoxPreference
12+
android:key="sqan"
13+
android:title="@string/pref_broadcast_sqan"
14+
android:summary="@string/pref_broadcast_sqan_narrative"
15+
android:defaultValue="true"
16+
android:dependency="broadcast"/>
17+
1118
<EditTextPreference
1219
android:key="callsign"
1320
android:title="@string/device_callsign"

0 commit comments

Comments
 (0)