diff --git a/build.gradle b/build.gradle index 973e2af..fd53582 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ subprojects { substitute module('org.sensorhub:sensorhub-service-video') with project(':sensorhub-service-video') substitute module('org.vast.opengis:ogc-services-sps') with project(':ogc-services-sps') - // override objenesis version to get new android instantiatiors + // override objenesis version to get new android instantiators substitute module('uk.com.robust-it:cloning:1.9.1') with module('uk.com.robust-it:cloning:1.9.10') } } diff --git a/sensorhub-android-app/build.gradle b/sensorhub-android-app/build.gradle index 6deeaaa..9441e66 100644 --- a/sensorhub-android-app/build.gradle +++ b/sensorhub-android-app/build.gradle @@ -5,7 +5,6 @@ ext.details = 'OSH demo app for Android' dependencies { api project(':sensorhub-android-lib') - api 'javax.xml.stream:stax-api:1.0-2' } android { diff --git a/sensorhub-android-app/src/org/sensorhub/android/MainActivity.java b/sensorhub-android-app/src/org/sensorhub/android/MainActivity.java index cdbce2e..3ac55d2 100644 --- a/sensorhub-android-app/src/org/sensorhub/android/MainActivity.java +++ b/sensorhub-android-app/src/org/sensorhub/android/MainActivity.java @@ -138,8 +138,6 @@ protected void updateConfig(SharedPreferences prefs, String runName) if (sensorsConfig.activateBackCamera || sensorsConfig.activateFrontCamera) showVideo = true; sensorsConfig.videoCodec = prefs.getString("video_codec", AndroidSensorsConfig.JPEG_CODEC); - sensorsConfig.androidContext = this.getApplicationContext(); - sensorsConfig.camPreviewTexture = boundService.getVideoTexture(); sensorsConfig.runName = runName; sensorhubConfig.add(sensorsConfig); addSosTConfig(sensorsConfig, sosUser, sosPwd); diff --git a/sensorhub-android-lib/build.gradle b/sensorhub-android-lib/build.gradle index e68a7be..75f7ee9 100644 --- a/sensorhub-android-lib/build.gradle +++ b/sensorhub-android-lib/build.gradle @@ -9,22 +9,19 @@ dependencies { //compile 'org.sensorhub:sensorhub-comm-ble:' + oshCoreVersion //compile 'org.sensorhub:sensorhub-driver-trupulse:[0.1,2.0)' //compile 'org.sensorhub:sensorhub-driver-angelsensor:[0.1,2.0)' - api project(':sensorhub-core') - api project(':sensorhub-service-swe') - api project(':sensorhub-comm-ble') + api project(':sensorhub-android-service') api project(':sensorhub-driver-trupulse') api project(':sensorhub-driver-angelsensor') api project(':sensorhub-driver-android') api project(':sensorhub-android-flirone') //api project(':sensorhub-android-dji') implementation 'org.slf4j:slf4j-android:1.6.1-RC1' - api 'javax.xml.stream:stax-api:1.0-2' } configurations { compile { // exclude stuff from APK - exclude group: "javax.xml.stream" + //exclude group: "javax.xml.stream" exclude group: "javax.servlet" exclude group: "xml-apis" exclude group: "org.eclipse.jetty" diff --git a/sensorhub-android-service/AndroidManifest.xml b/sensorhub-android-service/AndroidManifest.xml new file mode 100644 index 0000000..903d4ef --- /dev/null +++ b/sensorhub-android-service/AndroidManifest.xml @@ -0,0 +1,5 @@ + + diff --git a/sensorhub-android-app/assets/stax-api-1.0-2.dex b/sensorhub-android-service/assets/stax-api-1.0-2.dex similarity index 100% rename from sensorhub-android-app/assets/stax-api-1.0-2.dex rename to sensorhub-android-service/assets/stax-api-1.0-2.dex diff --git a/sensorhub-android-service/build.gradle b/sensorhub-android-service/build.gradle new file mode 100644 index 0000000..854ca36 --- /dev/null +++ b/sensorhub-android-service/build.gradle @@ -0,0 +1,38 @@ +apply plugin: 'com.android.library' + +description = 'OSH Android Service' +ext.details = 'Android service encapsulating an OSH instance' + +dependencies { + //api 'org.sensorhub:sensorhub-core:' + oshCoreVersion + //api 'org.sensorhub:sensorhub-driver-videocam:[1.0,2.0)' + //api 'org.sensorhub:sensorhub-process-vecmath:[1.0,2.0)' + api project(':sensorhub-core') + api project(':sensorhub-comm-ble') + api project(':sensorhub-service-swe') + api 'javax.xml.stream:stax-api:1.0-2' +} + +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + } + + lintOptions { + abortOnError false + } + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + } +} + diff --git a/sensorhub-android-app/notes.txt b/sensorhub-android-service/notes.txt similarity index 100% rename from sensorhub-android-app/notes.txt rename to sensorhub-android-service/notes.txt diff --git a/sensorhub-android-lib/src/org/sensorhub/android/Dexter.java b/sensorhub-android-service/src/org/sensorhub/android/Dexter.java similarity index 99% rename from sensorhub-android-lib/src/org/sensorhub/android/Dexter.java rename to sensorhub-android-service/src/org/sensorhub/android/Dexter.java index 8067d94..7e8515a 100644 --- a/sensorhub-android-lib/src/org/sensorhub/android/Dexter.java +++ b/sensorhub-android-service/src/org/sensorhub/android/Dexter.java @@ -1,17 +1,17 @@ -/***************************** BEGIN LICENSE BLOCK *************************** - -The contents of this file are subject to the Mozilla Public License, v. 2.0. -If a copy of the MPL was not distributed with this file, You can obtain one -at http://mozilla.org/MPL/2.0/. - -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -for the specific language governing rights and limitations under the License. - -Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. - -******************************* END LICENSE BLOCK ***************************/ - +/***************************** BEGIN LICENSE BLOCK *************************** + +The contents of this file are subject to the Mozilla Public License, v. 2.0. +If a copy of the MPL was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +for the specific language governing rights and limitations under the License. + +Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. + +******************************* END LICENSE BLOCK ***************************/ + package org.sensorhub.android; import java.io.File; diff --git a/sensorhub-android-app/src/org/sensorhub/android/SensorHubService.java b/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java similarity index 87% rename from sensorhub-android-app/src/org/sensorhub/android/SensorHubService.java rename to sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java index 146e27a..c46056d 100644 --- a/sensorhub-android-app/src/org/sensorhub/android/SensorHubService.java +++ b/sensorhub-android-service/src/org/sensorhub/android/SensorHubService.java @@ -51,11 +51,13 @@ public class SensorHubService extends Service private HandlerThread msgThread; private Handler msgHandler; SensorHub sensorhub; - SurfaceTexture videoTex; boolean hasVideo; + static Context context; + static SurfaceTexture videoTex; - public class LocalBinder extends Binder { + public class LocalBinder extends Binder + { SensorHubService getService() { return SensorHubService.this; } @@ -67,6 +69,13 @@ public void onCreate() { try { + // keep handle to Android context so it can be retrieved by OSH components + SensorHubService.context = getApplicationContext(); + + // create video surface texture here so it's not destroyed when pausing the app + SensorHubService.videoTex = new SurfaceTexture(1); + SensorHubService.videoTex.detachFromGLContext(); + // load external dex file containing stax API //Dexter.loadFromAssets(this.getApplicationContext(), "stax-api-1.0-2.dex"); @@ -79,10 +88,6 @@ public void onCreate() { dbf.setNamespaceAware(true); XMLImplFinder.setDOMImplementation(dbf.newDocumentBuilder().getDOMImplementation()); - // create video surface texture here so it's not destroyed when pausing the app - videoTex = new SurfaceTexture(1); - videoTex.detachFromGLContext(); - // start handler thread msgThread = new HandlerThread("SensorHubService", Process.THREAD_PRIORITY_BACKGROUND); msgThread.start(); @@ -145,7 +150,9 @@ public void onDestroy() { stopSensorHub(); msgThread.quitSafely(); - videoTex.release(); + SensorHubService.videoTex.release(); + SensorHubService.videoTex = null; + SensorHubService.context = null; } @@ -162,15 +169,21 @@ public SensorHub getSensorHub() } - public SurfaceTexture getVideoTexture() + public boolean hasVideo() + { + return hasVideo; + } + + + public static SurfaceTexture getVideoTexture() { return videoTex; } - public boolean hasVideo() + public static Context getContext() { - return hasVideo; + return context; } } diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothCommProvider.java b/sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothCommProvider.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothCommProvider.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothCommProvider.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothCommProviderConfig.java b/sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothCommProviderConfig.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothCommProviderConfig.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothCommProviderConfig.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothManager.java b/sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothManager.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/BluetoothManager.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/BluetoothManager.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/BleConfig.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/BleConfig.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/BleConfig.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/BleConfig.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/BleNetwork.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/BleNetwork.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/BleNetwork.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/BleNetwork.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattCharacteristicImpl.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattCharacteristicImpl.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattCharacteristicImpl.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattCharacteristicImpl.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattClientImpl.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattClientImpl.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattClientImpl.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattClientImpl.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattDescriptorImpl.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattDescriptorImpl.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattDescriptorImpl.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattDescriptorImpl.java diff --git a/sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattServiceImpl.java b/sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattServiceImpl.java similarity index 100% rename from sensorhub-android-lib/src/org/sensorhub/android/comm/ble/GattServiceImpl.java rename to sensorhub-android-service/src/org/sensorhub/android/comm/ble/GattServiceImpl.java diff --git a/sensorhub-android-app/stax-api-1.0-2.jar b/sensorhub-android-service/stax-api-1.0-2.jar similarity index 100% rename from sensorhub-android-app/stax-api-1.0-2.jar rename to sensorhub-android-service/stax-api-1.0-2.jar diff --git a/sensorhub-driver-android/build.gradle b/sensorhub-driver-android/build.gradle index 6ff8e3f..265a37e 100644 --- a/sensorhub-driver-android/build.gradle +++ b/sensorhub-driver-android/build.gradle @@ -10,6 +10,7 @@ dependencies { api project(':sensorhub-core') api project(':sensorhub-driver-videocam') api project(':sensorhub-process-vecmath') + api project(':sensorhub-android-service') } android { diff --git a/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsConfig.java b/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsConfig.java index 834769d..016f60d 100644 --- a/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsConfig.java +++ b/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsConfig.java @@ -31,7 +31,7 @@ public class AndroidSensorsConfig extends SensorConfig { public final static String JPEG_CODEC = "JPEG"; - public final static String H264_CODEC = "H264"; + public final static String H264_CODEC = "H264"; public boolean activateAccelerometer = false; public boolean activateGyrometer = false; @@ -46,22 +46,11 @@ public class AndroidSensorsConfig extends SensorConfig public String deviceName; public String runName; - public String runDescription; - - public transient Context androidContext; - public transient SurfaceTexture camPreviewTexture; - + public String runDescription; public AndroidSensorsConfig() { this.moduleClass = AndroidSensorsDriver.class.getCanonicalName(); } - - - @Override - public ModuleConfig clone() - { - return this; // disable clone for now as it crashes Android app - } } diff --git a/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsDriver.java b/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsDriver.java index 24090ed..78331af 100644 --- a/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsDriver.java +++ b/sensorhub-driver-android/src/main/java/org/sensorhub/impl/sensor/android/AndroidSensorsDriver.java @@ -18,6 +18,7 @@ import java.util.List; import javax.xml.namespace.QName; +import android.graphics.SurfaceTexture; import android.os.Handler; import android.os.HandlerThread; import net.opengis.gml.v32.AbstractFeature; @@ -25,6 +26,8 @@ import net.opengis.sensorml.v20.PhysicalSystem; import net.opengis.sensorml.v20.SpatialFrame; import net.opengis.sensorml.v20.impl.SpatialFrameImpl; + +import org.sensorhub.android.SensorHubService; import org.sensorhub.api.common.SensorHubException; import org.sensorhub.api.sensor.ISensorDataInterface; import org.sensorhub.api.sensor.SensorException; @@ -71,7 +74,7 @@ public AndroidSensorsDriver() @Override public synchronized void init() throws SensorHubException { - Context androidContext = config.androidContext; + Context androidContext = SensorHubService.getContext(); // generate identifiers String deviceID = Secure.getString(androidContext.getContentResolver(), Secure.ANDROID_ID); @@ -185,10 +188,11 @@ protected void createCameraOutputs(Context androidContext) throws SensorExceptio if ( (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK && config.activateBackCamera) || (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT && config.activateFrontCamera)) { + SurfaceTexture camPreviewTexture = SensorHubService.getVideoTexture(); if (AndroidSensorsConfig.JPEG_CODEC.equals(config.videoCodec)) - useCamera(new AndroidCameraOutputMJPEG(this, cameraId, config.camPreviewTexture), cameraId); + useCamera(new AndroidCameraOutputMJPEG(this, cameraId, camPreviewTexture), cameraId); else if (AndroidSensorsConfig.H264_CODEC.equals(config.videoCodec)) - useCamera(new AndroidCameraOutputH264(this, cameraId, config.camPreviewTexture), cameraId); + useCamera(new AndroidCameraOutputH264(this, cameraId, camPreviewTexture), cameraId); else throw new SensorException("Unsupported codec " + config.videoCodec); }