Skip to content

Commit dde4345

Browse files
author
Ted Schmidt
committed
Merge pull request #92 from senseobservationsystems/develop
Merged from develop
2 parents 6e946f8 + b3fa147 commit dde4345

File tree

16 files changed

+718
-691
lines changed

16 files changed

+718
-691
lines changed

sense-android-library/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
package="nl.sense_os.service" >
4+
package="nl.sense_os.service"
5+
android:versionName="2.9.0">
56

67
<!-- <uses-sdk -->
78
<uses-sdk android:minSdkVersion="7"/>

sense-android-library/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ android.library=true
1414
# Indicates whether an apk should be generated for each density.
1515
split.density=false
1616
# Project target.
17-
target=android-17
17+
target=android-19

sense-android-library/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<string name="action_sense_send_data" translatable="false">nl.sense_os.platform.MsgHandler.SEND_DATA</string>
2121
<string name="action_sense_alive_check_alarm" translatable="false">nl.sense_os.platform.AliveCheck</string>
2222
<string name="action_sense_gcm_intent_service" translatable="false">nl.sense_os.service.push.GCMReceiver</string>
23-
23+
<string name="action_sense_service_broadcast" translatable="false">nl.sense_os.service.Broadcast</string>
24+
2425
<!-- actions for the app widget -->
2526
<string name="action_widget_update" translatable="false">nl.sense_os.platform.AppWidgetUpdate</string>
2627

sense-android-library/src/com/phonegap/plugins/sense/SensePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ private void getSession(CordovaArgs data, CallbackContext callbackContext)
350350
if (null != service) {
351351

352352
// try the login
353-
String sessionId = SenseApi.getSessionId(cordova.getActivity());
353+
String sessionId = SenseApi.getCookie(cordova.getActivity());
354354

355355
// check the result
356356
if (null != sessionId) {

sense-android-library/src/nl/sense_os/service/DataTransmitter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
*************************************************************************************************/
44
package nl.sense_os.service;
55

6+
import nl.sense_os.service.constants.SensePrefs;
67
import nl.sense_os.service.constants.SensePrefs.Main;
8+
import nl.sense_os.service.constants.SensePrefs.Main.Advanced;
79
import nl.sense_os.service.scheduler.Scheduler;
810
import android.annotation.TargetApi;
911
import android.app.AlarmManager;
1012
import android.content.ComponentName;
1113
import android.content.Context;
1214
import android.content.Intent;
15+
import android.content.SharedPreferences;
1316
import android.net.ConnectivityManager;
1417
import android.net.NetworkInfo;
1518
import android.net.TrafficStats;
@@ -89,14 +92,20 @@ public void run() {
8992
transmissionService();
9093
}
9194
} else {
92-
// if there is no WiFi connection, postpone the transmission
95+
long interval = mTxInterval;
96+
97+
SharedPreferences mainPrefs = mContext.getSharedPreferences(SensePrefs.MAIN_PREFS, Context.MODE_PRIVATE);
98+
boolean energy_saving = mainPrefs.getBoolean(Advanced.MOBILE_INTERNET_ENERGY_SAVING_MODE, true);
99+
if(energy_saving)
100+
interval = ADAPTIVE_TX_INTERVAL; //if there is no WiFi connection, postpone the transmission
101+
93102
mLastTxBytes = TrafficStats.getMobileTxBytes() - mTxBytes;
94103
mTxBytes = TrafficStats.getMobileTxBytes();
95-
if ((SystemClock.elapsedRealtime() - mLastTxTime >= ADAPTIVE_TX_INTERVAL)) {
104+
if ((SystemClock.elapsedRealtime() - mLastTxTime >= interval)) {
96105
transmissionService();
97106
}
98107
// if any transmission took place recently, use the tail to transmit the sensor data
99-
else if ((mLastTxBytes >= 500)
108+
else if (energy_saving && (mLastTxBytes >= 500)
100109
&& (SystemClock.elapsedRealtime() - mLastTxTime >= ADAPTIVE_TX_INTERVAL
101110
- (long) (ADAPTIVE_TX_INTERVAL * 0.2))) {
102111
transmissionService();

sense-android-library/src/nl/sense_os/service/SenseService.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ public SenseServiceStub getService() {
9494
* Intent action to force a re-login attempt when the service is started.
9595
*/
9696
public static final String EXTRA_RELOGIN = "relogin";
97-
97+
9898
/**
99-
* Intent action for broadcasts that the service state has changed.
99+
* Intent action to notify that the service is started,
100+
* boolean extra for of the status changed broadcast R.string.action_sense_service_broadcast.
100101
*/
101-
public final static String ACTION_SERVICE_BROADCAST = "nl.sense_os.service.Broadcast";
102+
public static final String EXTRA_SERVICE_STARTED = "service_started";
102103

103104
private IBinder binder = new SenseBinder();
104105

@@ -403,6 +404,10 @@ public void run() {
403404
startForeground(ServiceStateHelper.NOTIF_ID, n);
404405
state.setForeground(true);
405406
AliveChecker.scheduleChecks(SenseService.this);
407+
Log.i(TAG, "Sending service started broadcast");
408+
Intent startService = new Intent(getString(R.string.action_sense_service_broadcast));
409+
startService.putExtra(EXTRA_SERVICE_STARTED, true);
410+
sendBroadcast(startService);
406411
}
407412

408413
// re-login if necessary
@@ -561,7 +566,7 @@ private synchronized void startSensorModules() {
561566
}
562567

563568
// send broadcast that something has changed in the status
564-
sendBroadcast(new Intent(ACTION_SERVICE_BROADCAST));
569+
sendBroadcast(new Intent(getString(R.string.action_sense_service_broadcast)));
565570
}
566571

567572
/**
@@ -580,7 +585,7 @@ private void stopSensorModules() {
580585
state.setStarted(false);
581586

582587
// send broadcast that something has changed in the status
583-
sendBroadcast(new Intent(ACTION_SERVICE_BROADCAST));
588+
sendBroadcast(new Intent(getString(R.string.action_sense_service_broadcast)));
584589
}
585590

586591
synchronized void toggleAmbience(boolean active) {
@@ -689,7 +694,7 @@ public void run() {
689694
noiseSensor = NoiseSensor.getInstance(SenseService.this);
690695
mSubscrMgr.registerProducer(SensorNames.NOISE, noiseSensor);
691696
mSubscrMgr.registerProducer(SensorNames.AUDIO_SPECTRUM, noiseSensor);
692-
mSubscrMgr.registerProducer(SensorNames.LOUDNESS, noiseSensor);
697+
mSubscrMgr.registerProducer(SensorNames.LOUDNESS, noiseSensor.getLoudnessSensor());
693698
mSubscrMgr.registerProducer(SensorNames.NOISE,
694699
noiseSensor.getAutoCalibratedNoiseSensor());
695700
noiseSensor.startSensing(finalInterval);
@@ -1105,9 +1110,7 @@ synchronized void toggleMain(boolean active) {
11051110
startService(new Intent(getString(R.string.action_sense_service)));
11061111

11071112
} else {
1108-
Log.i(TAG, "Stop service");
1109-
1110-
onLogOut();
1113+
Log.i(TAG, "Stop service");
11111114
stopSensorModules();
11121115

11131116
AliveChecker.stopChecks(this);

sense-android-library/src/nl/sense_os/service/SenseServiceStub.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public String getPrefString(String key, String defValue) {
128128
return defValue;
129129
}
130130
}
131+
132+
public String getCookie() throws IllegalAccessException {
133+
return SenseApi.getCookie(service);
134+
}
131135

132136
public String getSessionId() throws IllegalAccessException {
133137
return SenseApi.getSessionId(service);

sense-android-library/src/nl/sense_os/service/ambience/NoiseSensor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ public void doSample() {
620620
}
621621
}
622622

623+
public DataProducer getLoudnessSensor()
624+
{
625+
return loudnessSensor;
626+
}
623627
public DataProducer getAutoCalibratedNoiseSensor() {
624628
return autoCalibratedNoiseSensor;
625629
}

sense-android-library/src/nl/sense_os/service/commonsense/SenseApi.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,21 @@ public static String getSensorUrl(Context context, String name, String descripti
481481
return url.replaceFirst("%1", id);
482482
}
483483
}
484-
484+
485+
/**
486+
* @param context
487+
* Context for getting preferences
488+
* @return The current CommonSense session ID
489+
* @throws IllegalAccessException
490+
* if the app ID is not valid
491+
*/
492+
public static String getCookie(Context context) throws IllegalAccessException {
493+
if (null == sAuthPrefs) {
494+
sAuthPrefs = context.getSharedPreferences(SensePrefs.AUTH_PREFS, Context.MODE_PRIVATE);
495+
}
496+
return sAuthPrefs.getString(Auth.LOGIN_COOKIE, null);
497+
}
498+
485499
/**
486500
* @param context
487501
* Context for getting preferences
@@ -493,7 +507,7 @@ public static String getSessionId(Context context) throws IllegalAccessException
493507
if (null == sAuthPrefs) {
494508
sAuthPrefs = context.getSharedPreferences(SensePrefs.AUTH_PREFS, Context.MODE_PRIVATE);
495509
}
496-
return sAuthPrefs.getString(Auth.LOGIN_COOKIE, null);
510+
return sAuthPrefs.getString(Auth.LOGIN_SESSION_ID, null);
497511
}
498512

499513
/**
@@ -676,6 +690,7 @@ public static int login(Context context, String username, String password)
676690

677691
// get the cookie from the response
678692
String cookie = response.get("set-cookie");
693+
String session_id = response.get("x-session_id");
679694
if (result == 0 && response.get("set-cookie") == null) {
680695
// something went horribly wrong
681696
Log.w(TAG, "CommonSense login failed: no cookie received?!");
@@ -687,12 +702,14 @@ public static int login(Context context, String username, String password)
687702
switch (result) {
688703
case 0: // logged in
689704
authEditor.putString(Auth.LOGIN_COOKIE, cookie);
705+
authEditor.putString(Auth.LOGIN_SESSION_ID, session_id);
690706
authEditor.commit();
691707
break;
692708
case -1: // error
693709
break;
694710
case -2: // unauthorized
695711
authEditor.remove(Auth.LOGIN_COOKIE);
712+
authEditor.remove(Auth.LOGIN_SESSION_ID);
696713
authEditor.commit();
697714
break;
698715
default:

sense-android-library/src/nl/sense_os/service/constants/SensePrefs.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public static class Auth {
3939
* @see SensePrefs#AUTH_PREFS
4040
*/
4141
public static final String LOGIN_COOKIE = "login_cookie";
42+
/**
43+
*Key for login preference for session id.
44+
*
45+
* @see SensePrefs#AUTH_PREFS
46+
*/
47+
public static final String LOGIN_SESSION_ID = "session_id";
4248
/**
4349
* Key for login preference for email address.
4450
*
@@ -160,6 +166,12 @@ public static class Advanced {
160166
* Agostino's saliency test. Default is false.
161167
*/
162168
public static final String AGOSTINO = "agostino_mode";
169+
/**
170+
* Key for preference that enables energy saving mode when using mobile Internet.
171+
* When energy saving mode is on data will be uploaded every half an hour.
172+
* @see SensePrefs#MAIN_PREFS
173+
*/
174+
public static final String MOBILE_INTERNET_ENERGY_SAVING_MODE = "mobile_internet_energy_saving_mode";
163175
}
164176

165177
public static class Ambience {
@@ -403,6 +415,21 @@ public static class Motion {
403415
*
404416
* @see SensePrefs#MAIN_PREFS
405417
*/
418+
419+
/**
420+
* Key for preference that toggles whether to upload and store burst samples.
421+
*
422+
* @see SensePrefs#MAIN_PREFS
423+
*/
424+
public static final String DONT_UPLOAD_BURSTS = "don't upload bursts";
425+
426+
/**
427+
* Key for preference that determines the burst duration. Duration is in milliseconds.
428+
*
429+
* @see SensePrefs#MAIN_PREFS
430+
*/
431+
public static final String BURST_DURATION = "burst_duration";
432+
406433
public static final String UNREG = "motion_unregister";
407434
/**
408435
* Key for preference that toggles motion energy sensing, which measures average kinetic
@@ -510,7 +537,7 @@ public static class Quiz {
510537
*/
511538
public static final String SYNC_TIME = "popquiz_sync_time";
512539
}
513-
540+
514541
/**
515542
* Key for preference that controls sample frequency of the sensors.
516543
*
@@ -607,6 +634,12 @@ public static class Status {
607634
* @see SensePrefs#STATUS_PREFS
608635
*/
609636
public static final String AUTOSTART = "autostart";
637+
/**
638+
* Key for preference to pause sensing until the next charge.
639+
*
640+
* @see SensePrefs#STATUS_PREFS
641+
*/
642+
public static final String PAUSED_UNTIL_NEXT_CHARGE = "paused until next charge status";
610643
}
611644

612645
public static class SensorSpecifics {

0 commit comments

Comments
 (0)