Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion sample/TORGIListener/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
5 changes: 5 additions & 0 deletions torgi/src/main/java/org/sofwerx/torgi/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Config {
public final static String PREFS_UUID = "callsign";
public final static String PREFS_GPS_ONLY = "gpsonly";
public final static String PREFS_BROADCAST = "broadcast";
public final static String PREFS_SQAN = "sqan";
public final static String PREFS_SEND_TO_SOS = "sendtosos";
public final static String PREFS_SOS_URL = "sosurl";
public final static String PREFS_SOS_ASSIGNED_PROCEDURE = "sosprocedure";
Expand Down Expand Up @@ -51,6 +52,10 @@ public static boolean isIpcBroadcastEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_BROADCAST,true);
}

public static boolean isSqAnBroadcastEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_SQAN,true);
}

public void loadPrefs() {
gpsOnly = prefs.getBoolean(PREFS_GPS_ONLY,false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static String post(String serverURL, String body) throws IOException {
}

conn.disconnect();
Log.d(SosIpcTransceiver.TAG,"HttpURLConnection disconnected");

if ((response != null) && (response.length() < 1))
response = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
import android.util.Log;

import org.sofwerx.torgi.BuildConfig;
import org.sofwerx.torgi.Config;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -36,10 +39,15 @@
public class SosIpcTransceiver extends BroadcastReceiver {
public final static String TAG = "SosIpc";
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
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.US);
public static final String ACTION_SOS = "org.sofwerx.ogc.ACTION_SOS";
private static final String EXTRA_PAYLOAD = "SOS";
private static final String EXTRA_ORIGIN = "src";
public static final String ACTION_SQAN_BROADCAST = "org.sofwerx.sqan.pkt";
private final static String SQAN_PACKET_BYTES = "bytes";
private final static String SQAN_PACKET_ORIGIN = "src";
private final static String SQAN_PACKET_CHANNEL = "channel";
private final static String SQAN_CHANNEL = "torgi";
private SosMessageListener listener;

public SosIpcTransceiver(SosMessageListener listener) {
Expand All @@ -49,12 +57,28 @@ public SosIpcTransceiver(SosMessageListener listener) {
@Override
public void onReceive(Context context, Intent intent) {
if ((context != null) && (intent != null)) {
if (ACTION_SOS.equals(intent.getAction())) {
String action = intent.getAction();
if (ACTION_SOS.equalsIgnoreCase(action)) {
String origin = intent.getStringExtra(EXTRA_ORIGIN);
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(origin))
onMessageReceived(context, origin, intent.getStringExtra(EXTRA_PAYLOAD));
} else if (ACTION_SQAN_BROADCAST.equalsIgnoreCase(action)) { //forward traffic from SqAN
String origin = intent.getStringExtra(EXTRA_ORIGIN);
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(origin)) {
String channel = intent.getStringExtra(SQAN_PACKET_CHANNEL);
if (SQAN_CHANNEL.equalsIgnoreCase(channel)) { //only handle TORGI channel broadcasts
try {
byte[] bytes = intent.getByteArrayExtra(SQAN_PACKET_BYTES);
if (bytes != null) {
String payload = new String(bytes,"UTF-8");
onMessageReceived(context,"sqan.torgi",payload);
}
} catch (UnsupportedEncodingException ignore) {
}
}
}
} else
Log.e(TAG, "Unexpected action message received: " + intent.getAction());
Log.e(TAG, "Unexpected action message received: " + action);
}
}

Expand Down Expand Up @@ -146,8 +170,22 @@ private void broadcast(Context context, String sosOperation) {
Intent intent = new Intent(ACTION_SOS);
intent.putExtra(EXTRA_ORIGIN, BuildConfig.APPLICATION_ID);
intent.putExtra(EXTRA_PAYLOAD,sosOperation);

context.sendBroadcast(intent);

//Broadcast of SqAN as well
if (Config.isSqAnBroadcastEnabled(context)) {
Log.d(TAG,"Broadcasting over SqAN as well");
try {
byte[] bytes = sosOperation.getBytes("UTF-8");
Intent sqanIntent = new Intent(ACTION_SQAN_BROADCAST);
sqanIntent.putExtra(EXTRA_ORIGIN, BuildConfig.APPLICATION_ID);
sqanIntent.putExtra(SQAN_PACKET_BYTES, bytes);
sqanIntent.putExtra(SQAN_PACKET_CHANNEL, SQAN_CHANNEL);
context.sendBroadcast(sqanIntent);
} catch (UnsupportedEncodingException ignore) {
}
}

Log.d(TAG,"Broadcast: "+sosOperation);
}

Expand Down
2 changes: 2 additions & 0 deletions torgi/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<string name="pref_category_connectivity">Connectivity</string>
<string name="pref_broadcast">Share with other apps</string>
<string name="pref_broadcast_narrative">Automatically share with other apps on this device information about EW risk changes.</string>
<string name="pref_broadcast_sqan">Broadcast over SqAN</string>
<string name="pref_broadcast_sqan_narrative">Automatically share EW risk changes over the Squad Area Network (SqAN) if installed.</string>
<string name="pref_torgi_dir">Saved file directory</string>
<string name="pref_torgi_dir_narrative">TORGI will save files in this directory.</string>
<string name="title_activity_b">Activity</string>
Expand Down
7 changes: 7 additions & 0 deletions torgi/src/main/res/xml/prefs_app.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
android:summary="@string/pref_broadcast_narrative"
android:defaultValue="true"/>

<CheckBoxPreference
android:key="sqan"
android:title="@string/pref_broadcast_sqan"
android:summary="@string/pref_broadcast_sqan_narrative"
android:defaultValue="true"
android:dependency="broadcast"/>

<EditTextPreference
android:key="callsign"
android:title="@string/device_callsign"
Expand Down