diff --git a/build.gradle b/build.gradle
index c2df6c26..83390026 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ ext.compileSdkVersion = 34
ext.minSdkVersion = 33
ext.targetSdkVersion = 34
ext.buildToolsVersion = "34.0.0"
-version = '5.0.1'
+version = '5.0.2'
buildscript {
ext.kotlin_version = '1.9.22'
diff --git a/sensorhub-android-app/src/AndroidManifest.xml b/sensorhub-android-app/src/AndroidManifest.xml
index bd1f2e2f..b891b165 100644
--- a/sensorhub-android-app/src/AndroidManifest.xml
+++ b/sensorhub-android-app/src/AndroidManifest.xml
@@ -27,6 +27,7 @@
+
@@ -60,7 +61,7 @@
diff --git a/sensorhub-android-app/src/org/sensorhub/android/ui/SensorHubViewModel.kt b/sensorhub-android-app/src/org/sensorhub/android/ui/SensorHubViewModel.kt
index 43380f18..2a643d0d 100644
--- a/sensorhub-android-app/src/org/sensorhub/android/ui/SensorHubViewModel.kt
+++ b/sensorhub-android-app/src/org/sensorhub/android/ui/SensorHubViewModel.kt
@@ -176,7 +176,12 @@ class SensorHubViewModel(private val application: Application) : AndroidViewMode
app.startService(Intent(app, SensorHubService::class.java))
activeSensors = SensorRegistry.enabledSensorEntries(snapshot).toList()
Log.i(TAG, "Requesting SensorHub start with ${activeSensors.size} enabled sensor(s)")
- current.startSensorHub(config.modules, config.cameraEnabled)
+ current.startSensorHub(
+ config.modules,
+ activeSensors.any { it.id == "gps" || it.id == "network" },
+ config.cameraEnabled,
+ activeSensors.any { it.id == "audio" }
+ )
} catch (e: Exception) {
Log.e(TAG, "Unable to prepare or request SensorHub startup", e)
reportError(e.message ?: application.getString(R.string.ui_unable_to_start_smart_hub))
diff --git a/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java b/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java
index a8157b67..505790a6 100644
--- a/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java
+++ b/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java
@@ -8,6 +8,7 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ServiceInfo;
import android.graphics.SurfaceTexture;
import android.location.LocationListener;
import android.location.LocationManager;
@@ -94,7 +95,6 @@ public void onCreate() {
msgThread.start();
msgHandler = new Handler(msgThread.getLooper());
- startForegroundService();
log.info("SensorHub Android service initialized");
}
catch (Exception e)
@@ -103,14 +103,7 @@ public void onCreate() {
}
}
-// private void startLocationManager() {
-// LocationRequest request = new LocationRequest.Builder(
-// Priority.PRIORITY_HIGH_ACCURACY,
-// 5000 // update interval (ms)
-// ).build();
-//
-// }
- private void startForegroundService() {
+ private void startForegroundService(boolean usesLocation, boolean usesCamera, boolean usesMicrophone) {
// Create notification channel for Android O and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
@@ -171,11 +164,27 @@ private void startForegroundService() {
.build();
}
+ int foregroundServiceTypes = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC;
+ if (usesLocation) {
+ foregroundServiceTypes |= ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION;
+ }
+ if (usesCamera) {
+ foregroundServiceTypes |= ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
+ }
+ if (usesMicrophone) {
+ foregroundServiceTypes |= ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
+ }
+
// Start foreground
- startForeground(NOTIFICATION_ID, notification);
+ startForeground(NOTIFICATION_ID, notification, foregroundServiceTypes);
}
- public synchronized void startSensorHub(final IModuleConfigRepository config, final boolean hasVideo)
+ public synchronized void startSensorHub(
+ final IModuleConfigRepository config,
+ final boolean usesLocation,
+ final boolean hasVideo,
+ final boolean usesMicrophone
+ )
{
Log.i(ANDROID_LOG_TAG, "SensorHub start requested; video=" + hasVideo);
if (hubState == HubState.STARTING || hubState == HubState.RUNNING || hubState == HubState.STOPPING) {
@@ -197,7 +206,7 @@ public synchronized void startSensorHub(final IModuleConfigRepository config, fi
try {
acquireWakeLocks();
- startForegroundService();
+ startForegroundService(usesLocation, hasVideo, usesMicrophone);
if (msgHandler == null)
throw new IllegalStateException("SensorHub service did not initialize");
} catch (RuntimeException e) {