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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
path = submodules/osh-core
url = git@github.com:kalynstricklin/osh-core.git
branch = update-moduleutils
[submodule "submodules/botts-addons"]
path = submodules/botts-addons
url = git@github.com:Botts-Innovative-Research/botts-addons.git
1 change: 1 addition & 0 deletions sensorhub-android-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {

implementation project(path: ':sensorhub-datastore-h2')
implementation project(path: ':sensorhub-service-consys')
implementation project(path: ':sensorhub-service-discovery')
implementation project(':sensorhub-android-ste')
implementation project(':sensorhub-android-meshtastic')
implementation project(':sensorhub-android-polar')
Expand Down
50 changes: 50 additions & 0 deletions sensorhub-android-app/res/layout/activity_app_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,56 @@
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

<!-- Discovery Service Status -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
app:cardCornerRadius="@dimen/card_corner_radius"
app:cardElevation="@dimen/card_elevation"
app:cardBackgroundColor="@color/md_theme_surface">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="@dimen/content_padding">

<View
android:id="@+id/discovery_status_dot"
android:layout_width="@dimen/status_dot_size"
android:layout_height="@dimen/status_dot_size"
android:background="@drawable/status_dot_background" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginStart="@dimen/content_padding">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/discoveryServiceStatusLabel"
android:textColor="@color/md_theme_onSurface"
android:textSize="16sp"
android:fontFamily="sans-serif-medium" />

<TextView
android:id="@+id/discovery_service_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/md_theme_onSurfaceVariant"
android:textSize="14sp"
android:layout_marginTop="4dp"
tools:text="Started" />

</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

<!-- HTTP Server Status -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions sensorhub-android-app/res/values/strings_app_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<string name="sosServiceStatusLabel">SOS Service Status</string>
<string name="conSysServiceStatusLabel">ConSys Service Status</string>
<string name="discoveryServiceStatusLabel">Discovery Service Status</string>
<string name="httpServerStatusLabel">HTTP Server Status</string>
<string name="sensorServiceStatusLabel">Android Sensor Status</string>
<string name="storageServiceStatusLabel">Android Sensor Storage Status</string>
Expand Down
14 changes: 14 additions & 0 deletions sensorhub-android-app/res/xml/pref_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@
android:defaultValue="true"
android:layout="@layout/preference_switch_item" />

<SwitchPreferenceCompat
android:id="@+id/discovery_service_switch"
android:key="discovery_service"
android:title="Enable Discovery Service"
android:defaultValue="true"
android:layout="@layout/preference_switch_item" />

<EditTextPreference
android:defaultValue="https://drive.google.com/uc?export=download&amp;id="
android:inputType="text"
android:key="rules_link"
android:singleLine="true"
android:title="URL to Discovery Rules.txt"
android:layout="@layout/preference_item"/>
</PreferenceCategory>

<!-- Clients -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,30 @@ protected void onCreate(Bundle savedInstanceState) {

String sosStatus = intent.getStringExtra("sosService");
String consSysStatus = intent.getStringExtra("conSysService");
String discoveryStatus = intent.getStringExtra("discoveryService");
String httpStatus = intent.getStringExtra("httpStatus");
String sensorStatus = intent.getStringExtra("androidSensorStatus");
String sensorStorageStatus = intent.getStringExtra("sensorStorageStatus");

// Set status text
TextView sosStatusView = findViewById(R.id.sos_service_state);
TextView conSysStatusView = findViewById(R.id.consys_service_state);
TextView discoveryStatusView = findViewById(R.id.discovery_service_state);
TextView httpStatusView = findViewById(R.id.http_service_state);
TextView sensorStatusView = findViewById(R.id.sensor_service_state);
TextView storageStatusView = findViewById(R.id.storage_service_state);

sosStatusView.setText(sosStatus);
conSysStatusView.setText(consSysStatus);
discoveryStatusView.setText(discoveryStatus);
httpStatusView.setText(httpStatus);
sensorStatusView.setText(sensorStatus);
storageStatusView.setText(sensorStorageStatus);

// Color the status indicator dots
setStatusDotColor(findViewById(R.id.sos_status_dot), sosStatus);
setStatusDotColor(findViewById(R.id.consys_status_dot), consSysStatus);
setStatusDotColor(findViewById(R.id.discovery_status_dot), discoveryStatus);
setStatusDotColor(findViewById(R.id.http_status_dot), httpStatus);
setStatusDotColor(findViewById(R.id.sensor_status_dot), sensorStatus);
setStatusDotColor(findViewById(R.id.storage_status_dot), sensorStorageStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.sensorhub.android;

import static org.sensorhub.android.SensorHubService.context;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
Expand Down Expand Up @@ -47,6 +49,8 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.botts.impl.service.discovery.DiscoveryService;
import com.botts.impl.service.discovery.DiscoveryServiceConfig;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
Expand Down Expand Up @@ -104,7 +108,11 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -118,6 +126,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.FutureTask;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -243,6 +252,7 @@ public void updateConfig(SharedPreferences prefs, String runName)

Boolean isApiServiceEnabled = prefs.getBoolean("api_service", true);
Boolean isSosServiceEnabled = prefs.getBoolean("sos_service", true);
Boolean isDiscoveryServiceEnabled = prefs.getBoolean("discovery_service", true);
Boolean isClientEnabled = prefs.getBoolean("enable_client", true);
Boolean isTLSEnabled = prefs.getBoolean("enable_tls", false);

Expand Down Expand Up @@ -372,6 +382,40 @@ public boolean verify(String arg0, SSLSession arg1) {
conSysApiService.enableTransactional = true;
conSysApiService.exposedResources = new ObsSystemDatabaseViewConfig();

// Discovery Service
DiscoveryServiceConfig discoveryServiceConfig = new DiscoveryServiceConfig();
discoveryServiceConfig.moduleClass = DiscoveryService.class.getCanonicalName();
discoveryServiceConfig.id = "DISCOVERY_SERVICE";
discoveryServiceConfig.name= "Discovery Service";
discoveryServiceConfig.autoStart = true;

File outFile = new File(context.getFilesDir(), "rules.txt");
String rulesLink = prefs.getString("rules_link", "");
FutureTask<Void> downloadTask = new java.util.concurrent.FutureTask<>(() -> {
URL rulesUrl = new URL(rulesLink);
HttpURLConnection conn = (HttpURLConnection) rulesUrl.openConnection();
conn.setInstanceFollowRedirects(true);
try (InputStream in = conn.getInputStream();
OutputStream out = new FileOutputStream(outFile)) {
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} finally {
conn.disconnect();
}
return null;
});
new Thread(downloadTask).start();
try {
downloadTask.get();
} catch (Exception e) {
Log.e("OSH - Discovery", "Failed to download rules file", e);
}
discoveryServiceConfig.rulesFilePath = outFile.getAbsolutePath();

// OAuth
ConSysOAuthConfig conSysOAuthConfig = new ConSysOAuthConfig();
conSysOAuthConfig.oAuthEnabled = isOAuthEnabled;
conSysOAuthConfig.tokenEndpoint = tokenEndpoint;
Expand Down Expand Up @@ -535,13 +579,17 @@ public boolean verify(String arg0, SSLSession arg1) {
sensorhubConfig.add(templateConfig);
}


//---------- SERVICES ---------------------
if (isApiServiceEnabled) {
sensorhubConfig.add(conSysApiService);
}
if (isSosServiceEnabled) {
sensorhubConfig.add(sosConfig);
}
if (isDiscoveryServiceEnabled) {
sensorhubConfig.add(discoveryServiceConfig);
}

}

protected void addSosTConfig(SensorConfig sensorConf, String user, String pwd)
Expand Down Expand Up @@ -691,6 +739,9 @@ else if(id == R.id.action_status) {
case "CON_SYS_SERVICE":
statusIntent.putExtra("conSysService", status);
break;
case "DISCOVERY_SERVICE":
statusIntent.putExtra("discoveryService", status);
break;
case "ANDROID_SENSORS":
statusIntent.putExtra("androidSensorStatus", status);
break;
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def repos = [
'sensors/health/sensorhub-driver-angelsensor',
'processing/sensorhub-process-vecmath',
'processing/sensorhub-process-geoloc'
],
'botts-addons' : [
'services/sensorhub-service-discovery'
]
]

Expand Down
1 change: 1 addition & 0 deletions submodules/botts-addons
Submodule botts-addons added at 7381f8