Skip to content

Commit

Permalink
Added support for HTTPS and new preferences to set SOS-T user name and
Browse files Browse the repository at this point in the history
password
  • Loading branch information
alexrobin committed Oct 10, 2016
1 parent cd4dfb7 commit a453908
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
16 changes: 16 additions & 0 deletions sensorhub-android-app/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,21 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="SOS Endpoint URL" />

<EditTextPreference
android:inputType="text"
android:key="sos_username"
android:maxLines="1"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="SOS Username"
android:summary="Enter your username or leave blank" />

<EditTextPreference
android:inputType="textPassword"
android:key="sos_password"
android:selectAllOnFocus="true"
android:title="SOS Password"
android:summary="Enter your password or leave blank" />

</PreferenceScreen>
15 changes: 10 additions & 5 deletions sensorhub-android-app/src/org/sensorhub/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ protected void updateConfig(SharedPreferences prefs, String runName)

// get SOS URL from config
String sosUriConfig = prefs.getString("sos_uri", "");
String sosUser = prefs.getString("sos_username", null);
String sosPwd = prefs.getString("sos_password", null);
if (sosUriConfig != null && sosUriConfig.trim().length() > 0)
{
try
Expand Down Expand Up @@ -175,7 +177,7 @@ protected void updateConfig(SharedPreferences prefs, String runName)
sensorsConfig.camPreviewSurfaceHolder = this.camPreviewSurfaceHolder;
sensorsConfig.runName = runName;
sensorhubConfig.add(sensorsConfig);
addSosTConfig(sensorsConfig);
addSosTConfig(sensorsConfig, sosUser, sosPwd);

// TruPulse sensor
boolean enabled = prefs.getBoolean("trupulse_enabled", false);
Expand All @@ -194,7 +196,7 @@ protected void updateConfig(SharedPreferences prefs, String runName)
btConf.moduleClass = BluetoothCommProvider.class.getCanonicalName();
trupulseConfig.commSettings = btConf;
sensorhubConfig.add(trupulseConfig);
addSosTConfig(trupulseConfig);
addSosTConfig(trupulseConfig, sosUser, sosPwd);
}

// AngelSensor
Expand All @@ -217,7 +219,7 @@ protected void updateConfig(SharedPreferences prefs, String runName)
//angelConfig.btAddress = "00:07:80:03:0E:0A"; // mine
angelConfig.btAddress = prefs.getString("angel_address", null);
sensorhubConfig.add(angelConfig);
addSosTConfig(angelConfig);
addSosTConfig(angelConfig, sosUser, sosPwd);
}

// FLIR One sensor
Expand All @@ -231,12 +233,12 @@ protected void updateConfig(SharedPreferences prefs, String runName)
flironeConfig.androidContext = this.getApplicationContext();
flironeConfig.camPreviewSurfaceHolder = this.camPreviewSurfaceHolder;
sensorhubConfig.add(flironeConfig);
addSosTConfig(flironeConfig);
addSosTConfig(flironeConfig, sosUser, sosPwd);
}
}


protected void addSosTConfig(SensorConfig sensorConf)
protected void addSosTConfig(SensorConfig sensorConf, String sosUser, String sosPwd)
{
if (sosUrl == null)
return;
Expand All @@ -249,6 +251,9 @@ protected void addSosTConfig(SensorConfig sensorConf)
sosConfig.sos.remoteHost = sosUrl.getHost();
sosConfig.sos.remotePort = sosUrl.getPort();
sosConfig.sos.resourcePath = sosUrl.getPath();
sosConfig.sos.enableTLS = sosUrl.getProtocol().equals("https");
sosConfig.sos.user = sosUser;
sosConfig.sos.password = sosPwd;
sosConfig.connection.connectTimeout = 5000;
sosConfig.connection.usePersistentConnection = true;
sosConfig.connection.reconnectAttempts = 9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

package org.sensorhub.android;

import android.annotation.TargetApi;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceManager;
import java.net.URL;
import java.util.List;


Expand Down Expand Up @@ -54,6 +56,26 @@ public boolean onPreferenceChange(Preference preference, Object value)
else
{
preference.setSummary(stringValue);
}

// detect errors
if (preference.getKey().equals("sos_uri"))
{
try
{
URL url = new URL(value.toString());
if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https"))
throw new Exception("SOS URL must be HTTP or HTTPS");
}
catch (Exception e)
{
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(preference.getContext());
dlgAlert.setMessage("Invalid SOS URL");
dlgAlert.setTitle(e.getMessage());
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
}

return true;
Expand Down Expand Up @@ -93,7 +115,8 @@ public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
bindPreferenceSummaryToValue(findPreference("device_name"));
bindPreferenceSummaryToValue(findPreference("sos_uri"));
bindPreferenceSummaryToValue(findPreference("sos_uri"));
bindPreferenceSummaryToValue(findPreference("sos_username"));
}
}

Expand Down
4 changes: 2 additions & 2 deletions sensorhub-driver-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<groupId>org.sensorhub</groupId>
<artifactId>sensorhub-all</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.1-beta1</version>
</parent>
<artifactId>sensorhub-driver-android</artifactId>
<version>0.1-SNAPSHOT</version>
<name>SensorHub Android Driver</name>
<description>Example driver for sensors accessible through Android API</description>
<description>Driver for sensors accessible through Android API</description>
<packaging>bundle</packaging>
<dependencies>
<dependency>
Expand Down

0 comments on commit a453908

Please sign in to comment.