3 Commits
Author SHA1 Message Date
handte 3f43df52e9 Release 1.0.21
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-09-20 16:11:20 +02:00
handte de8ad98f8d Improve robustness of SDK service on lower Android version.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Move buffer and upload task to serial queue.
Increase GPS timeout to 90 seconds on pre-24 devices.
Schedule restart of SDK service, if service is shutdown by Android.
Update Android Gradle plugin.
2021-09-20 15:47:07 +02:00
handte 0fc0605a85 Update to 1.0.21-SNAPSHOT
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-30 19:13:14 +02:00
8 changed files with 84 additions and 9 deletions
Vendored
+1 -1
View File
@@ -49,7 +49,7 @@ node {
if (env.BRANCH_NAME == "master" && release) {
echo "Deploying to production server ..."
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
// sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
// sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
}
} else if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "feat/auth") {
+1 -1
View File
@@ -100,7 +100,7 @@ android {
applicationId "com.mowesta.android.app"
minSdkVersion 19
targetSdkVersion 30
versionCode 20
versionCode 21
versionName "${versionApp}"
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -1,6 +1,11 @@
package com.mowesta.android.sdk;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -87,6 +92,7 @@ public abstract class SdkService extends Service {
private BroadcastReceiver timeTickReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
debugLog("Time tick received");
onStartCommand(null, 0, 0);
}
};
@@ -98,7 +104,9 @@ public abstract class SdkService extends Service {
private LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
debugLog("Location changed");
if (isLocationAccurate(location)) {
debugLog("Location is accurate enough");
setLocation(location);
}
}
@@ -137,6 +145,7 @@ public abstract class SdkService extends Service {
private boolean initialized = false;
@Override
public void onChanged(Boolean uploading) {
debugLog("Uploading is " + uploading);
if (currentState == State.IDLE) {
if (uploading) {
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_upload);
@@ -220,6 +229,7 @@ public abstract class SdkService extends Service {
@Override
@SuppressWarnings("deprecation")
public void onCreate() {
debugLog("Creating service");
Log.d(TAG, "Creating sdk service.");
super.onCreate();
channelManager = new ChannelManager(getApplication());
@@ -238,6 +248,10 @@ public abstract class SdkService extends Service {
@Override
public void onDestroy() {
debugLog("Destroying service in state: " + currentState);
if (currentState != State.IDLE) {
scheduleExecution(this, measurementTime);
}
Log.d(TAG, "Destroying sdk service.");
switch (currentState) {
case MEASURE:
@@ -260,9 +274,9 @@ public abstract class SdkService extends Service {
}
repository.getUploading().removeObserver(uploadListener);
unregisterReceiver(timeTickReceiver);
stopForeground(true);
Log.d(TAG, "Releasing wake lock.");
if (wakeLock != null && wakeLock.isHeld()) wakeLock.release();
stopForeground(true);
super.onDestroy();
}
@@ -295,6 +309,7 @@ public abstract class SdkService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!isEnabled()) {
debugLog("Service not enabled, stopping");
Log.d(TAG, "Stopping since the service is not enabled.");
cancelExecution(this);
stopSelf();
@@ -305,12 +320,15 @@ public abstract class SdkService extends Service {
if (currentState == State.IDLE) {
if (now - measurementTime > repository.getConstants().TIMEOUT_MEASUREMENT) {
Log.d(TAG, "Starting state machine since timeout has expired.");
debugLog("Starting state machine since timeout has expired.");
changeState();
} else {
Log.d(TAG, "Ignoring start request while timeout has not expired.");
debugLog("Ignoring start request while timeout has not expired.");
scheduleExecution(this, measurementTime);
}
} else {
debugLog("Ignoring start request while service is " + currentState + ".");
Log.d(TAG, "Ignoring start request while service is " + currentState + ".");
}
return START_STICKY;
@@ -321,6 +339,7 @@ public abstract class SdkService extends Service {
*/
private void changeState() {
Log.d(TAG, "Changing state from " + currentState);
debugLog("Changing state from " + currentState);
switch (currentState) {
case IDLE: {
// acquire a wake lock to keep the cpu running
@@ -404,6 +423,7 @@ public abstract class SdkService extends Service {
* an unrecoverable failure.
*/
private void resetState(boolean success) {
debugLog("Reset state with succes: " + success);
currentState = State.IDLE;
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_idle);
currentNetworks = null;
@@ -435,6 +455,7 @@ public abstract class SdkService extends Service {
* Starts the measurement.
*/
private void startMeasure() {
debugLog("Starting measurement.");
Log.d(TAG, "Starting measurement.");
currentState = State.MEASURE;
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_measure);
@@ -457,6 +478,8 @@ public abstract class SdkService extends Service {
*/
private void startGps() {
Log.d(TAG, "Starting gps localization.");
debugLog("Starting gps localization.");
currentState = State.GPS;
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_gps);
if (capabilityManager.hasLocationPermissions()) {
@@ -466,6 +489,7 @@ public abstract class SdkService extends Service {
@Override
public void run() {
Log.d(TAG, "Aborting gps localization.");
debugLog("Aborting gps localization (timeout).");
changeState();
}
};
@@ -473,9 +497,11 @@ public abstract class SdkService extends Service {
return;
} catch (SecurityException e) {
Log.d(TAG, "Security exception while accessing location.", e);
debugLog("Security exception while accessing location.");
}
}
Log.d(TAG, "Location permissions missing, changing state.");
debugLog("Location permissions missing, changing state.");
changeState();
}
@@ -484,6 +510,7 @@ public abstract class SdkService extends Service {
*/
private void startNet() {
Log.d(TAG, "Starting network localization.");
debugLog("Starting network localization.");
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_net);
currentState = State.NET;
if (capabilityManager.hasLocationPermissions()) {
@@ -493,6 +520,8 @@ public abstract class SdkService extends Service {
@Override
public void run() {
Log.d(TAG, "Aborting network localization.");
debugLog("Aborting network localization (timeout).");
changeState();
}
};
@@ -500,9 +529,12 @@ public abstract class SdkService extends Service {
return;
} catch (SecurityException e) {
Log.d(TAG, "Security exception while accessing location.", e);
debugLog("Security exception while accessing location.");
}
}
Log.d(TAG, "Location permissions missing, changing state.");
debugLog("Location permissions missing, changing state.");
changeState();
}
@@ -512,8 +544,10 @@ public abstract class SdkService extends Service {
@SuppressWarnings("deprecation")
private void startWifi() {
Log.d(TAG, "Acquiring wifi lock.");
debugLog("Acquiring wifi lock");
wifiLock.acquire();
Log.d(TAG, "Starting wifi scan.");
debugLog("Starting wifi scan.");
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_wifi);
currentState = State.WIFI;
registerReceiver(wifiListener, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
@@ -521,6 +555,7 @@ public abstract class SdkService extends Service {
@Override
public void run() {
Log.d(TAG, "Aborting wifi scan.");
debugLog("Aborting wifi scan (timeout).");
changeState();
}
};
@@ -533,19 +568,22 @@ public abstract class SdkService extends Service {
*/
private void startCache() {
Log.d(TAG, "Starting cache lookup.");
debugLog("Starting cache lookup.");
currentState = State.CACHE;
channelManager.updateNotification(R.string.mowesta_sdk_notification_content_cache);
lookupTask = new LookupTask(repository, currentNetworks, new LookupTask.OnCompletionListener() {
@Override
public void onCompletion(@Nullable LocationEntity entity) {
Log.d(TAG, "Cache lookup complete.");
Log.d(TAG, "Cache lookup complete with cached result.");
if (entity != null) {
debugLog("Cache lockup success");
Coordinate c = new Coordinate();
c.setLatitude(entity.getLatitude());
c.setLongitude(entity.getLongitude());
measurement.setCoordinate(c);
resetState(true);
} else {
debugLog("Cache lockup without cached result.");
changeState();
}
}
@@ -625,6 +663,7 @@ public abstract class SdkService extends Service {
}
this.currentNetworks = networks;
Log.d(TAG, "Found " + this.currentNetworks.size() + " wifi networks.");
debugLog("Found " + this.currentNetworks.size() + " wifi networks.");
changeState();
}
@@ -634,6 +673,7 @@ public abstract class SdkService extends Service {
* @param location The location.
*/
private void setLocation(Location location) {
debugLog("Set location");
// cleanup based on type
if (currentState == State.GPS) cleanupGps();
if (currentState == State.NET) cleanupNet();
@@ -647,6 +687,7 @@ public abstract class SdkService extends Service {
measurement.setCoordinate(c);
// store location in cache
if (hasMinimumNetworks()) {
debugLog("Store in cache");
LocationEntity entity = new LocationEntity();
entity.setAccuracy((double)location.getAccuracy());
entity.setLatitude(location.getLatitude());
@@ -694,6 +735,7 @@ public abstract class SdkService extends Service {
long now = SystemClock.elapsedRealtime();
long next = Math.max(5000, (lastTime + service.repository.getConstants().TIMEOUT_MEASUREMENT) - now);
Log.d(TAG, "Updating alarm to execute in " + next + " ms.");
service.debugLog("Updating alarm to execute in " + next + " ms.");
PendingIntent pending = createIntent(service);
manager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + next, service.repository.getConstants().TIMEOUT_MEASUREMENT, pending);
}
@@ -774,4 +816,30 @@ public abstract class SdkService extends Service {
}
/**
* Performs logging to a local file to debug issues with the service.
* This code and all calls to it can be removed safely, once the app
* is robust, until then we keep it to swap it in quickly.
*
* @param string The string to log.
*/
private void debugLog(String string) {
// uncomment to enable file-based debug log
/*
synchronized (SdkService.class) {
try {
long now = System.currentTimeMillis();
String message = now + " :: " + new Date(now).toString() + " :: " + string + "\n";
File dest = new File(getFilesDir(), "debug.log");
BufferedWriter w = new BufferedWriter(new FileWriter(dest.getAbsolutePath(), true));
w.write(message);
w.flush();
w.close();
} catch (IOException e) {
// nothing
}
}
*/
}
}
@@ -57,7 +57,7 @@ public class BufferTask extends AbstractTask<Void> {
* @param listener The listener to signal the completion.
*/
public BufferTask(@NonNull SdkRepository repository, @NonNull Measurement measurement, @NonNull OnCompletionListener listener) {
super(true);
super(false);
this.repository = repository;
this.measurement = measurement;
this.listener = listener;
@@ -62,7 +62,7 @@ public class UploadTask extends AbstractTask<Void> {
* @param client The api client to use.
*/
public UploadTask(@NonNull SdkRepository repository, @NonNull DefaultApi client) {
super(true);
super(false);
this.repository = repository;
this.client = client;
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The maximum time to wait for a gps location. Depends on the user's position (indoor/outdoor). -->
<integer name="mowesta_sdk_service_gps_timeout">60000</integer>
</resources>
+1 -1
View File
@@ -46,7 +46,7 @@
<!-- The maximum time to wait for a network location. Depends on the network connection. -->
<integer name="mowesta_sdk_service_network_timeout">45000</integer>
<!-- The maximum time to wait for a gps location. Depends on the user's position (indoor/outdoor). -->
<integer name="mowesta_sdk_service_gps_timeout">60000</integer>
<integer name="mowesta_sdk_service_gps_timeout">90000</integer>
<!-- The minimum location accuracy in meters required to use a gps or network position. -->
<integer name="mowesta_sdk_service_minimum_location_accuracy">75</integer>
<!-- The maximum age in milliseconds that we will use a cached location before we validate the cache. -->
+2 -2
View File
@@ -5,7 +5,7 @@ apply plugin: 'maven-publish'
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.0.1'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
classpath 'org.handte.gradle:gradle-android-eclipse:1.0.0'
classpath "org.openbakery:xcode-plugin:0.19.1"
@@ -24,7 +24,7 @@ allprojects {
// set version for our project
group = 'com.mowesta'
version = '1.0.20'
version = '1.0.21'
// set versions for our libraries
ext {