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 @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion sensorhub-android-app/src/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
Expand Down Expand Up @@ -60,7 +61,7 @@
<service
android:name=".SensorHubService"
android:enabled="true"
android:foregroundServiceType="location|camera|microphone"
android:foregroundServiceType="dataSync|location|camera|microphone"
android:exported="false"
tools:ignore="ForegroundServicePermission" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,6 @@ public void onCreate() {
msgThread.start();
msgHandler = new Handler(msgThread.getLooper());

startForegroundService();
log.info("SensorHub Android service initialized");
}
catch (Exception e)
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading