Skip to content

Commit a453908

Browse files
author
alexrobin
committed
Added support for HTTPS and new preferences to set SOS-T user name and
password
1 parent cd4dfb7 commit a453908

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

sensorhub-android-app/res/xml/pref_general.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,21 @@
1818
android:selectAllOnFocus="true"
1919
android:singleLine="true"
2020
android:title="SOS Endpoint URL" />
21+
22+
<EditTextPreference
23+
android:inputType="text"
24+
android:key="sos_username"
25+
android:maxLines="1"
26+
android:selectAllOnFocus="true"
27+
android:singleLine="true"
28+
android:title="SOS Username"
29+
android:summary="Enter your username or leave blank" />
30+
31+
<EditTextPreference
32+
android:inputType="textPassword"
33+
android:key="sos_password"
34+
android:selectAllOnFocus="true"
35+
android:title="SOS Password"
36+
android:summary="Enter your password or leave blank" />
2137

2238
</PreferenceScreen>

sensorhub-android-app/src/org/sensorhub/android/MainActivity.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ protected void updateConfig(SharedPreferences prefs, String runName)
137137

138138
// get SOS URL from config
139139
String sosUriConfig = prefs.getString("sos_uri", "");
140+
String sosUser = prefs.getString("sos_username", null);
141+
String sosPwd = prefs.getString("sos_password", null);
140142
if (sosUriConfig != null && sosUriConfig.trim().length() > 0)
141143
{
142144
try
@@ -175,7 +177,7 @@ protected void updateConfig(SharedPreferences prefs, String runName)
175177
sensorsConfig.camPreviewSurfaceHolder = this.camPreviewSurfaceHolder;
176178
sensorsConfig.runName = runName;
177179
sensorhubConfig.add(sensorsConfig);
178-
addSosTConfig(sensorsConfig);
180+
addSosTConfig(sensorsConfig, sosUser, sosPwd);
179181

180182
// TruPulse sensor
181183
boolean enabled = prefs.getBoolean("trupulse_enabled", false);
@@ -194,7 +196,7 @@ protected void updateConfig(SharedPreferences prefs, String runName)
194196
btConf.moduleClass = BluetoothCommProvider.class.getCanonicalName();
195197
trupulseConfig.commSettings = btConf;
196198
sensorhubConfig.add(trupulseConfig);
197-
addSosTConfig(trupulseConfig);
199+
addSosTConfig(trupulseConfig, sosUser, sosPwd);
198200
}
199201

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

223225
// FLIR One sensor
@@ -231,12 +233,12 @@ protected void updateConfig(SharedPreferences prefs, String runName)
231233
flironeConfig.androidContext = this.getApplicationContext();
232234
flironeConfig.camPreviewSurfaceHolder = this.camPreviewSurfaceHolder;
233235
sensorhubConfig.add(flironeConfig);
234-
addSosTConfig(flironeConfig);
236+
addSosTConfig(flironeConfig, sosUser, sosPwd);
235237
}
236238
}
237239

238240

239-
protected void addSosTConfig(SensorConfig sensorConf)
241+
protected void addSosTConfig(SensorConfig sensorConf, String sosUser, String sosPwd)
240242
{
241243
if (sosUrl == null)
242244
return;
@@ -249,6 +251,9 @@ protected void addSosTConfig(SensorConfig sensorConf)
249251
sosConfig.sos.remoteHost = sosUrl.getHost();
250252
sosConfig.sos.remotePort = sosUrl.getPort();
251253
sosConfig.sos.resourcePath = sosUrl.getPath();
254+
sosConfig.sos.enableTLS = sosUrl.getProtocol().equals("https");
255+
sosConfig.sos.user = sosUser;
256+
sosConfig.sos.password = sosPwd;
252257
sosConfig.connection.connectTimeout = 5000;
253258
sosConfig.connection.usePersistentConnection = true;
254259
sosConfig.connection.reconnectAttempts = 9;

sensorhub-android-app/src/org/sensorhub/android/UserSettingsActivity.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414

1515
package org.sensorhub.android;
1616

17-
import android.annotation.TargetApi;
17+
import android.annotation.TargetApi;
18+
import android.app.AlertDialog;
1819
import android.os.Build;
1920
import android.os.Bundle;
2021
import android.preference.ListPreference;
2122
import android.preference.Preference;
2223
import android.preference.PreferenceActivity;
2324
import android.preference.PreferenceFragment;
24-
import android.preference.PreferenceManager;
25+
import android.preference.PreferenceManager;
26+
import java.net.URL;
2527
import java.util.List;
2628

2729

@@ -54,6 +56,26 @@ public boolean onPreferenceChange(Preference preference, Object value)
5456
else
5557
{
5658
preference.setSummary(stringValue);
59+
}
60+
61+
// detect errors
62+
if (preference.getKey().equals("sos_uri"))
63+
{
64+
try
65+
{
66+
URL url = new URL(value.toString());
67+
if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https"))
68+
throw new Exception("SOS URL must be HTTP or HTTPS");
69+
}
70+
catch (Exception e)
71+
{
72+
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(preference.getContext());
73+
dlgAlert.setMessage("Invalid SOS URL");
74+
dlgAlert.setTitle(e.getMessage());
75+
dlgAlert.setPositiveButton("OK", null);
76+
dlgAlert.setCancelable(true);
77+
dlgAlert.create().show();
78+
}
5779
}
5880

5981
return true;
@@ -93,7 +115,8 @@ public void onCreate(Bundle savedInstanceState)
93115
super.onCreate(savedInstanceState);
94116
addPreferencesFromResource(R.xml.pref_general);
95117
bindPreferenceSummaryToValue(findPreference("device_name"));
96-
bindPreferenceSummaryToValue(findPreference("sos_uri"));
118+
bindPreferenceSummaryToValue(findPreference("sos_uri"));
119+
bindPreferenceSummaryToValue(findPreference("sos_username"));
97120
}
98121
}
99122

sensorhub-driver-android/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<parent>
44
<groupId>org.sensorhub</groupId>
55
<artifactId>sensorhub-all</artifactId>
6-
<version>1.1-SNAPSHOT</version>
6+
<version>1.1-beta1</version>
77
</parent>
88
<artifactId>sensorhub-driver-android</artifactId>
99
<version>0.1-SNAPSHOT</version>
1010
<name>SensorHub Android Driver</name>
11-
<description>Example driver for sensors accessible through Android API</description>
11+
<description>Driver for sensors accessible through Android API</description>
1212
<packaging>bundle</packaging>
1313
<dependencies>
1414
<dependency>

0 commit comments

Comments
 (0)