Skip to content

Commit

Permalink
Add wifi wait limit and example wifi only
Browse files Browse the repository at this point in the history
  • Loading branch information
nlathia committed Jul 30, 2015
1 parent 2a20ff9 commit 826ecb0
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 21 deletions.
19 changes: 0 additions & 19 deletions README

This file was deleted.

11 changes: 9 additions & 2 deletions src/com/emotionsense/demo/data/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.view.View;
import android.widget.Toast;

import com.emotionsense.demo.data.loggers.StoreOnlyEncryptedDatabase;
import com.emotionsense.demo.data.loggers.AsyncEncryptedDatabase;
import com.ubhave.datahandler.ESDataManager;
import com.ubhave.datahandler.except.DataHandlerException;
import com.ubhave.datahandler.loggertypes.AbstractDataLogger;
Expand Down Expand Up @@ -42,7 +42,14 @@ protected void onCreate(Bundle savedInstanceState)
try
{
// TODO: change this line of code to change the type of data logger
logger = StoreOnlyEncryptedDatabase.getInstance();
logger = AsyncEncryptedDatabase.getInstance();
// logger = AsyncEncryptedFiles.getInstance();
// logger = AsyncUnencryptedDatabase.getInstance();
// logger = AsyncUnencryptedFiles.getInstance();
// logger = StoreOnlyEncryptedDatabase.getInstance();
// logger = StoreOnlyEncryptedFiles.getInstance();
// logger = StoreOnlyUnencryptedDatabase.getInstance();
// logger = StoreOnlyUnencryptedFiles.getInstance();

sensorManager = ESSensorManager.getSensorManager(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ protected String getEncryptionPassword()
// Note: return non-null password to encrypt data
return "password";
}

@Override
protected long getWaitForWiFiMillis()
{
// Note: wait for a Wi-Fi connection for a maximum of 4 hours
return 1000L * 60 * 60 * 4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ protected String getEncryptionPassword()
// Note: return non-null password to encrypt data
return "password";
}

@Override
protected long getWaitForWiFiMillis()
{
// Note: wait for a Wi-Fi connection for a maximum of 4 hours
return 1000L * 60 * 60 * 4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ protected String getEncryptionPassword()
// Note: return non-null password to encrypt data
return null;
}

@Override
protected long getWaitForWiFiMillis()
{
// Note: wait for a Wi-Fi connection for a maximum of 4 hours
return 1000L * 60 * 60 * 4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ protected String getEncryptionPassword()
// Note: return non-null password to encrypt data
return null;
}

@Override
protected long getWaitForWiFiMillis()
{
// Note: wait for a Wi-Fi connection for a maximum of 4 hours
return 1000L * 60 * 60 * 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.emotionsense.demo.data.loggers;

import java.util.HashMap;

import android.content.Context;

import com.emotionsense.demo.data.DemoApplication;
import com.ubhave.datahandler.config.DataStorageConfig;
import com.ubhave.datahandler.except.DataHandlerException;
import com.ubhave.datahandler.loggertypes.AbstractAsyncTransferLogger;
import com.ubhave.datahandler.loggertypes.AbstractDataLogger;
import com.ubhave.sensormanager.ESException;

public class AsyncWiFiOnlyEncryptedDatabase extends AbstractAsyncTransferLogger
{
private static AsyncWiFiOnlyEncryptedDatabase instance;

public static AbstractDataLogger getInstance() throws ESException, DataHandlerException
{
if (instance == null)
{
instance = new AsyncWiFiOnlyEncryptedDatabase(DemoApplication.getContext());
}
return instance;
}

protected AsyncWiFiOnlyEncryptedDatabase(final Context context) throws DataHandlerException, ESException
{
super(context, DataStorageConfig.STORAGE_TYPE_DB);
}

@Override
protected String getDataPostURL()
{
return RemoteServerDetails.FILE_POST_URL;
}

@Override
protected String getPostKey()
{
return RemoteServerDetails.FILE_KEY;
}

@Override
protected String getSuccessfulPostResponse()
{
return RemoteServerDetails.RESPONSE_ON_SUCCESS;
}

@Override
protected HashMap<String, String> getPostParameters()
{
// Note: any additional parameters (e.g., API key-value) that your URL
// requires
HashMap<String, String> params = new HashMap<String, String>();
params.put(RemoteServerDetails.API_KEY_KEY, RemoteServerDetails.API_KEY_VALUE);
return params;
}

@Override
protected long getDataLifeMillis()
{
// Note: all data that is more than 1 minute old will be transferred
return 1000L * 60 * 1;
}

@Override
protected long getTransferAlarmLengthMillis()
{
// Note: transfer alarm will fire every 2 minutes
return 1000L * 60 * 2;
}

@Override
protected long getWaitForWiFiMillis()
{
// Note: wait for a Wi-Fi connection
return Long.MAX_VALUE;
}

@Override
protected String getFileStorageName()
{
// Unused for database storage
return null;
}

@Override
protected String getUniqueUserId()
{
// Note: this should not be a static string
return "test-user-id";
}

@Override
protected String getDeviceId()
{
// Note: this should not be a static string
return "test-device-id";
}

@Override
protected boolean shouldPrintLogMessages()
{
// Note: return false to turn off Log.d messages
return true;
}

@Override
protected String getEncryptionPassword()
{
// Note: return non-null password to encrypt data
return "password";
}
}

0 comments on commit 826ecb0

Please sign in to comment.