Skip to content

Commit

Permalink
Merge pull request #171 from senseobservationsystems/feature/timeSimu…
Browse files Browse the repository at this point in the history
…lation

Feature/time simulation
  • Loading branch information
RonaldOlsthoorn committed Aug 28, 2015
2 parents 35eee23 + 0ed8ab7 commit 2533fcc
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 111 deletions.
95 changes: 95 additions & 0 deletions sense-android-library/sense-android-library.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":sense-android-library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../../test/aim-android-sdk-test" external.system.id="GRADLE" external.system.module.group="aim-android-sdk-test" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":sense-android-library" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/res" />
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="cordova-3.6.4" level="project" />
<orderEntry type="library" exported="" name="sqlcipher" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-19.1.0" level="project" />
<orderEntry type="library" exported="" name="gcm" level="project" />
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
<orderEntry type="library" exported="" name="play-services-6.1.71" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void onLogIn() {

// store this login
SharedPreferences prefs = getSharedPreferences(SensePrefs.MAIN_PREFS, MODE_PRIVATE);
prefs.edit().putLong(SensePrefs.Main.LAST_LOGGED_IN, System.currentTimeMillis()).commit();
prefs.edit().putLong(SensePrefs.Main.LAST_LOGGED_IN, SNTP.getInstance().getTime()).commit();

checkVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {
@Override
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
if (System.currentTimeMillis() > lastSampleTimes[sensor.getType()] + getSampleRate()) {
lastSampleTimes[sensor.getType()] = System.currentTimeMillis();
if (SNTP.getInstance().getTime() > lastSampleTimes[sensor.getType()] + getSampleRate()) {
lastSampleTimes[sensor.getType()] = SNTP.getInstance().getTime();

String sensorName = "";
if (sensor.getType() == Sensor.TYPE_LIGHT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
*************************************************************************************************/
package nl.sense_os.service.ambience;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.media.MediaRecorder.OnInfoListener;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.math.BigDecimal;
import java.text.DateFormat;
Expand All @@ -11,7 +31,6 @@
import java.util.Date;
import java.util.Locale;

import nl.sense_os.service.ambience.FFT;
import nl.sense_os.service.MsgHandler;
import nl.sense_os.service.R;
import nl.sense_os.service.constants.SenseDataTypes;
Expand All @@ -29,26 +48,6 @@
import nl.sense_os.service.subscription.BaseSensor;
import nl.sense_os.service.subscription.DataProducer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.media.MediaRecorder.OnInfoListener;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
* Main sound sensor class. Uses Android MediaRecorder class to capture small bits of audio and
* convert it into sensor data. The AudioRecord is sampled periodically by setting an alarm
Expand Down Expand Up @@ -244,11 +243,11 @@ public void run() {

// schedule task to stop recording and calculate the
// noise
long now = System.currentTimeMillis();
long now = SNTP.getInstance().getTime();
byte[] totalBuffer = new byte[BUFFER_SIZE];
int readCount = 0;
while (audioRecord != null
&& System.currentTimeMillis() < now + RECORDING_TIME_NOISE) {
&& SNTP.getInstance().getTime() < now + RECORDING_TIME_NOISE) {
int chunkSize = Math.min(256, totalBuffer.length - readCount);
int readResult = audioRecord.read(totalBuffer, readCount, chunkSize);
if (readResult < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {
@Override
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
if (System.currentTimeMillis() > mLastSampleTimes[sensor.getType()] + getSampleRate()) {
mLastSampleTimes[sensor.getType()] = System.currentTimeMillis();
if (SNTP.getInstance().getTime() > mLastSampleTimes[sensor.getType()] + getSampleRate()) {
mLastSampleTimes[sensor.getType()] = SNTP.getInstance().getTime();

String sensorName = SensorNames.PRESSURE;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package nl.sense_os.service.commonsense;

import static nl.sense_os.service.push.GCMReceiver.SENDER_ID;

import java.io.IOException;

import nl.sense_os.service.constants.SensePrefs;

import org.json.JSONException;

import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import com.google.android.gcm.GCMRegistrar;

import org.json.JSONException;

import java.io.IOException;

import nl.sense_os.service.constants.SensePrefs;
import nl.sense_os.service.provider.SNTP;

import static nl.sense_os.service.push.GCMReceiver.SENDER_ID;

/**
* Service that checks if all the sensors on this phone are registered at CommonSense.<br/>
* <br/>
Expand All @@ -40,7 +41,7 @@ protected void onHandleIntent(Intent intent) {

SharedPreferences mainPrefs = getSharedPreferences(SensePrefs.MAIN_PREFS, MODE_PRIVATE);
long lastVerified = mainPrefs.getLong(SensePrefs.Main.LAST_VERIFIED_SENSORS, 0);
if (System.currentTimeMillis() - lastVerified < 1000l * 60) { // 1 minute
if (SNTP.getInstance().getTime() - lastVerified < 1000l * 60) { // 1 minute
// registered sensors were already recently checked
Log.v(TAG, "Sensor IDs were just verified already");
return;
Expand All @@ -59,7 +60,7 @@ protected void onHandleIntent(Intent intent) {
if (verifier.verifySensorIds(deviceType, deviceUuid)) {
Log.v(TAG, "Sensor IDs verified");
mainPrefs.edit()
.putLong(SensePrefs.Main.LAST_VERIFIED_SENSORS, System.currentTimeMillis())
.putLong(SensePrefs.Main.LAST_VERIFIED_SENSORS, SNTP.getInstance().getTime())
.commit();
} else {
// hopefully the IDs will be checked again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
import android.telephony.TelephonyManager;
import android.util.Log;

import nl.sense_os.service.SenseServiceStub;
import nl.sense_os.service.EncryptionHelper;
import nl.sense_os.service.constants.SenseDataTypes;
import nl.sense_os.service.constants.SensePrefs;
import nl.sense_os.service.constants.SensePrefs.Auth;
import nl.sense_os.service.constants.SensePrefs.Main.Advanced;
import nl.sense_os.service.constants.SenseUrls;
import nl.sense_os.service.constants.SensorData.SensorNames;
import nl.sense_os.service.push.GCMReceiver;

import org.apache.http.conn.ssl.SSLSocketFactory;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -45,6 +35,17 @@

import javax.net.ssl.HttpsURLConnection;

import nl.sense_os.service.EncryptionHelper;
import nl.sense_os.service.SenseServiceStub;
import nl.sense_os.service.constants.SenseDataTypes;
import nl.sense_os.service.constants.SensePrefs;
import nl.sense_os.service.constants.SensePrefs.Auth;
import nl.sense_os.service.constants.SensePrefs.Main.Advanced;
import nl.sense_os.service.constants.SenseUrls;
import nl.sense_os.service.constants.SensorData.SensorNames;
import nl.sense_os.service.provider.SNTP;
import nl.sense_os.service.push.GCMReceiver;

/**
* Main interface for communicating with the CommonSense API.
*
Expand Down Expand Up @@ -94,7 +95,7 @@ public static JSONArray getAllSensors(Context context) throws IOException, JSONE
try {
String cachedSensors = sAuthPrefs.getString(Auth.SENSOR_LIST_COMPLETE, null);
long cacheTime = sAuthPrefs.getLong(Auth.SENSOR_LIST_COMPLETE_TIME, 0);
boolean isOutdated = System.currentTimeMillis() - cacheTime > CACHE_REFRESH;
boolean isOutdated = SNTP.getInstance().getTime() - cacheTime > CACHE_REFRESH;

// return cached list of it is still valid
if (false == isOutdated && null != cachedSensors) {
Expand Down Expand Up @@ -155,7 +156,7 @@ public static JSONArray getAllSensors(Context context) throws IOException, JSONE
// store the new sensor list
Editor authEditor = sAuthPrefs.edit();
authEditor.putString(Auth.SENSOR_LIST_COMPLETE, result.toString());
authEditor.putLong(Auth.SENSOR_LIST_COMPLETE_TIME, System.currentTimeMillis());
authEditor.putLong(Auth.SENSOR_LIST_COMPLETE_TIME, SNTP.getInstance().getTime());
authEditor.commit();

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@ private boolean isPositionChanged(int distanceTraveled) {
Cursor data = null;
if (mPositionFlag == Flag.NOT_READY && (distanceTraveled == 0)) {
// Log.d(TAG, "1A");
mStartTime = System.currentTimeMillis();
mStartTime = SNTP.getInstance().getTime();
mPositionFlag = Flag.READY;
return moved;
} else if ((System.currentTimeMillis() - mStartTime) >= 4 * 60 * 1000
} else if ((SNTP.getInstance().getTime() - mStartTime) >= 4 * 60 * 1000
|| (distanceTraveled != 0)) {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
*************************************************************************************************/
package nl.sense_os.service.external_sensors;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.Set;
import java.util.UUID;

import nl.sense_os.service.subscription.BaseDataProducer;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
Expand All @@ -24,6 +14,17 @@
import android.os.HandlerThread;
import android.util.Log;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.Set;
import java.util.UUID;

import nl.sense_os.service.provider.SNTP;
import nl.sense_os.service.subscription.BaseDataProducer;

/**
* Generic class to represent an external sensor that needs to connect to the phone via Bluetooth.
*
Expand Down Expand Up @@ -259,13 +260,13 @@ public void run() {
// while the connection is alive, poll every updateInterval
long nextpoll, sleeptimer;
while (connected) {
nextpoll = System.currentTimeMillis() + updateinterval;
nextpoll = SNTP.getInstance().getTime() + updateinterval;
if (sensorinitialized)
pollSensor();
else
sensorinitialized = initializeSensor();
try {
if ((sleeptimer = nextpoll - System.currentTimeMillis()) > 0)
if ((sleeptimer = nextpoll - SNTP.getInstance().getTime()) > 0)
Thread.sleep(sleeptimer);
} catch (InterruptedException e) {
Log.w(TAG, "UpdateThread was interrupted in its sleep");
Expand Down
Loading

0 comments on commit 2533fcc

Please sign in to comment.