2013-04-27 Mark Holland <mark@mark-holland.me.uk>

* src/pandroid/agent/Core.java: Reverted to previous commit
	SharedPreferences.

	* src/pandroid/agent/PandroidAgent.java: Reverted to previous commit
	SharedPreferences.

	* src/pandroid/agent/PandroidAgentListener.java: Notification only
	shows when attempting to send xml, can't work out how to have it 
	persistent and not dissapear when Pandroid activity is destroyed.

	* src/pandroid/agent/SMSBroadcastReceiver.java: Reverted to previous 
	commit SharedPreferences.

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8071 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
markholland 2013-04-27 17:52:04 +00:00
parent 9cd18ec26a
commit 39d07d2090
8 changed files with 499 additions and 260 deletions

View File

@ -1,3 +1,18 @@
2013-04-27 Mark Holland <mark@mark-holland.me.uk>
* src/pandroid/agent/Core.java: Reverted to previous commit
SharedPreferences.
* src/pandroid/agent/PandroidAgent.java: Reverted to previous commit
SharedPreferences.
* src/pandroid/agent/PandroidAgentListener.java: Notification only
shows when attempting to send xml, can't work out how to have it
persistent and not dissapear when Pandroid activity is destroyed.
* src/pandroid/agent/SMSBroadcastReceiver.java: Reverted to previous
commit SharedPreferences.
2013-04-27 Mark Holland <mark@mark-holland.me.uk>
* assets/database/pandroid.zip: Added buffer size initial value.

View File

@ -19,7 +19,7 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
//import android.util.Log;
@ -42,9 +42,9 @@ public class Core {
// DEFAULT CONFIGURATION MODULES //
// //
static volatile public String defaultServerAddr = "firefly.artica.es"; //master address
static volatile public String defaultServerAddr = "192.168.1.45"; //master address
static volatile public String defaultServerPort = "41121";
static volatile public int defaultInterval = 300;
static volatile public int defaultInterval = 20;
static volatile public String defaultAgentName = "pandroid";
static volatile public String defaultmobileWebURL = "firefly.artica.es/pandora_demo/mobile";
static volatile public String defaultGpsStatus = "enabled"; // "disabled" or "enabled"
@ -98,6 +98,7 @@ public class Core {
static volatile public int defaultRoaming = 0;
static volatile public long defaultBufferSize = 256;
static volatile public String defaultPassword = "";
static volatile public Context con = null;
@ -179,6 +180,7 @@ public class Core {
public Core() {
}
@ -216,38 +218,39 @@ public class Core {
con = context;
}
SharedPreferences agentPreferences = con.getSharedPreferences(
con.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
latitude = HelperSharedPreferences.getSharedPreferencesFloat(con, "latitude", CONST_INVALID_COORDS);
longitude = HelperSharedPreferences.getSharedPreferencesFloat(con, "longitude", CONST_INVALID_COORDS);
batteryLevel = HelperSharedPreferences.getSharedPreferencesInt(con, "batteryLevel", CONST_INVALID_BATTERY_LEVEL);
orientation = HelperSharedPreferences.getSharedPreferencesFloat(con, "orientation", CONST_INVALID_ORIENTATION);
proximity = HelperSharedPreferences.getSharedPreferencesFloat(con, "proximity", CONST_INVALID_PROXIMITY);
taskStatus = HelperSharedPreferences.getSharedPreferencesString(con, "taskStatus", defaultTaskStatus);
task = HelperSharedPreferences.getSharedPreferencesString(con, "task", defaultTask);
taskHumanName = HelperSharedPreferences.getSharedPreferencesString(con, "taskHumanName", defaultTaskHumanName);
taskRun = HelperSharedPreferences.getSharedPreferencesString(con, "taskRun", defaultTaskRun);
memoryStatus = HelperSharedPreferences.getSharedPreferencesString(con, "memoryStatus", defaultMemoryStatus);
availableRamKb = HelperSharedPreferences.getSharedPreferencesLong(con, "availableRamKb", defaultRam);
totalRamKb = HelperSharedPreferences.getSharedPreferencesLong(con, "totalRamKb", defaultRam);
lastContact = HelperSharedPreferences.getSharedPreferencesLong(con, "lastContact", defaultContact);
contactError = HelperSharedPreferences.getSharedPreferencesInt(con, "contactError", defaultContactError);
simID = HelperSharedPreferences.getSharedPreferencesString(con, "simID", defaultSimID);
upTime = HelperSharedPreferences.getSharedPreferencesLong(con, "upTime", Core.defaultUpTime);
SMSReceived = HelperSharedPreferences.getSharedPreferencesInt(con, "SMSReceived", defaultSMSReceived);
SMSSent = HelperSharedPreferences.getSharedPreferencesInt(con, "SMSSent", defaultSMSSent);
networkOperator = HelperSharedPreferences.getSharedPreferencesString(con, "networkOperator", defaultNetworkOperator);
networkType = HelperSharedPreferences.getSharedPreferencesString(con, "networkType", defaultNetworkType);
phoneType = HelperSharedPreferences.getSharedPreferencesString(con, "phoneType", defaultPhoneType);
signalStrength = HelperSharedPreferences.getSharedPreferencesInt(con, "signalStrength", defaultSignalStrength);
incomingCalls = HelperSharedPreferences.getSharedPreferencesInt(con, "incomingCalls", defaultIncomingCalls);
missedCalls = HelperSharedPreferences.getSharedPreferencesInt(con, "missedCalls", defaultMissedCalls);
outgoingCalls = HelperSharedPreferences.getSharedPreferencesInt(con, "outgoingCalls", defaultOutgoingCalls);
receiveBytes = HelperSharedPreferences.getSharedPreferencesLong(con, "receiveBytes", defaultReceiveBytes);
transmitBytes = HelperSharedPreferences.getSharedPreferencesLong(con, "transmitBytes", defaultTransmitBytes);
helloSignal = HelperSharedPreferences.getSharedPreferencesInt(con, "helloSignal", defaultHelloSignal);
roaming = HelperSharedPreferences.getSharedPreferencesInt(con, "roaming", defaultRoaming);
bufferSize = HelperSharedPreferences.getSharedPreferencesLong(con, "bufferSize", defaultBufferSize);
latitude = agentPreferences.getFloat("latitude", CONST_INVALID_COORDS);
longitude = agentPreferences.getFloat("longitude", CONST_INVALID_COORDS);
batteryLevel = agentPreferences.getInt("batteryLevel", CONST_INVALID_BATTERY_LEVEL);
orientation = agentPreferences.getFloat("orientation", CONST_INVALID_ORIENTATION);
proximity = agentPreferences.getFloat("proximity", CONST_INVALID_PROXIMITY);
taskStatus = agentPreferences.getString("taskStatus", defaultTaskStatus);
task = agentPreferences.getString("task", defaultTask);
taskHumanName = agentPreferences.getString("taskHumanName", defaultTaskHumanName);
taskRun = agentPreferences.getString("taskRun", defaultTaskRun);
memoryStatus = agentPreferences.getString("memoryStatus", defaultMemoryStatus);
availableRamKb = agentPreferences.getLong("availableRamKb", defaultRam);
totalRamKb = agentPreferences.getLong("totalRamKb", defaultRam);
lastContact = agentPreferences.getLong("lastContact", defaultContact);
contactError = agentPreferences.getInt("contactError", defaultContactError);
simID = agentPreferences.getString("simID", defaultSimID);
upTime = agentPreferences.getLong("upTime", Core.defaultUpTime);
SMSReceived = agentPreferences.getInt("SMSReceived", defaultSMSReceived);
SMSSent = agentPreferences.getInt("SMSSent", defaultSMSSent);
networkOperator = agentPreferences.getString("networkOperator", defaultNetworkOperator);
networkType = agentPreferences.getString("networkType", defaultNetworkType);
phoneType = agentPreferences.getString("phoneType", defaultPhoneType);
signalStrength = agentPreferences.getInt("signalStrength", defaultSignalStrength);
incomingCalls = agentPreferences.getInt("incomingCalls", defaultIncomingCalls);
missedCalls = agentPreferences.getInt("missedCalls", defaultMissedCalls);
outgoingCalls = agentPreferences.getInt("outgoingCalls", defaultOutgoingCalls);
receiveBytes = agentPreferences.getLong("receiveBytes", defaultReceiveBytes);
transmitBytes = agentPreferences.getLong("transmitBytes", defaultTransmitBytes);
helloSignal = agentPreferences.getInt("helloSignal", defaultHelloSignal);
roaming = agentPreferences.getInt("roaming", defaultRoaming);
}// end loadLastValues
@ -256,40 +259,41 @@ public class Core {
con = context;
}
SharedPreferences agentPreferences = con.getSharedPreferences(
con.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
serverAddr = HelperSharedPreferences.getSharedPreferencesString(con, "serverAddr", defaultServerAddr);
serverPort = HelperSharedPreferences.getSharedPreferencesString(con, "serverPort", defaultServerPort);
interval = HelperSharedPreferences.getSharedPreferencesInt(con, "interval", defaultInterval);
agentName = HelperSharedPreferences.getSharedPreferencesString(con, "agentName", defaultAgentName+"_"+Installation.id(context));
mobileWebURL = HelperSharedPreferences.getSharedPreferencesString(con, "mobileWebURL", defaultmobileWebURL);
gpsStatus = HelperSharedPreferences.getSharedPreferencesString(con, "gpsStatus", defaultGpsStatus);
memoryStatus = HelperSharedPreferences.getSharedPreferencesString(con, "memoryStatus", defaultMemoryStatus);
taskStatus = HelperSharedPreferences.getSharedPreferencesString(con, "taskStatus", defaultTaskStatus);
task = HelperSharedPreferences.getSharedPreferencesString(con, "task", defaultTask);
taskHumanName = HelperSharedPreferences.getSharedPreferencesString(con, "taskHumanName", defaultTaskHumanName);
taskRun = HelperSharedPreferences.getSharedPreferencesString(con, "taskRun", defaultTaskRun);
password = HelperSharedPreferences.getSharedPreferencesString(con, "password", defaultPassword);
passwordCheck = HelperSharedPreferences.getSharedPreferencesString(con, "passwordCheck", defaultPasswordCheck);
simIDReport = HelperSharedPreferences.getSharedPreferencesString(con, "simIDReport", defaultSimIDReport);
DeviceUpTimeReport = HelperSharedPreferences.getSharedPreferencesString(con, "DeviceUpTimeReport", defaultDeviceUpTimeReport);
NetworkOperatorReport = HelperSharedPreferences.getSharedPreferencesString(con, "NetworkOperatorReport", defaultNetworkOperatorReport);
NetworkTypeReport = HelperSharedPreferences.getSharedPreferencesString(con, "NetworkTypeReport", defaultNetworkTypeReport);
PhoneTypeReport = HelperSharedPreferences.getSharedPreferencesString(con, "PhoneTypeReport", defaultPhoneTypeReport);
SignalStrengthReport = HelperSharedPreferences.getSharedPreferencesString(con, "SignalStrengthReport", defaultSignalStrengthReport);
ReceivedSMSReport = HelperSharedPreferences.getSharedPreferencesString(con, "ReceivedSMSReport", defaultReceivedSMSReport);
SentSMSReport = HelperSharedPreferences.getSharedPreferencesString(con, "SentSMSReport", defaultSentSMSReport);
IncomingCallsReport = HelperSharedPreferences.getSharedPreferencesString(con, "IncomingCallsReport", defaultIncomingCallsReport);
MissedCallsReport = HelperSharedPreferences.getSharedPreferencesString(con, "MissedCallsReport", defaultMissedCallsReport);
OutgoingCallsReport = HelperSharedPreferences.getSharedPreferencesString(con, "OutgoingCallsReport", defaultOutgoingCallsReport);
BytesReceivedReport = HelperSharedPreferences.getSharedPreferencesString(con, "BytesReceivedReport", defaultBytesReceivedReport);
BytesSentReport = HelperSharedPreferences.getSharedPreferencesString(con, "BytesSentReport", defaultBytesSentReport);
HelloSignalReport = HelperSharedPreferences.getSharedPreferencesString(con, "HelloSignalReport", defaultHelloSignalReport);
BatteryLevelReport = HelperSharedPreferences.getSharedPreferencesString(con, "BatteryLevelReport", defaultBatteryLevelReport);
RoamingReport = HelperSharedPreferences.getSharedPreferencesString(con, "RoamingReport", defaultRoamingReport);
InventoryReport = HelperSharedPreferences.getSharedPreferencesString(con, "InventoryReport", defaultInventoryReport);
NotificationCheck = HelperSharedPreferences.getSharedPreferencesString(con, "NotificationCheck", defaultNotificationCheck);
bufferSize = HelperSharedPreferences.getSharedPreferencesLong(con, "bufferSize", defaultBufferSize);
serverAddr = agentPreferences.getString("serverAddr", defaultServerAddr);
serverPort = agentPreferences.getString("serverPort", defaultServerPort);
interval = agentPreferences.getInt("interval", defaultInterval);
agentName = agentPreferences.getString("agentName", defaultAgentName+"_"+Installation.id(context));
mobileWebURL = agentPreferences.getString("mobileWebURL", defaultmobileWebURL);
gpsStatus = agentPreferences.getString("gpsStatus", defaultGpsStatus);
memoryStatus = agentPreferences.getString("memoryStatus", defaultMemoryStatus);
taskStatus = agentPreferences.getString("taskStatus", defaultTaskStatus);
task = agentPreferences.getString("task", defaultTask);
taskHumanName = agentPreferences.getString("taskHumanName", defaultTaskHumanName);
taskRun = agentPreferences.getString("taskRun", defaultTaskRun);
password = agentPreferences.getString("password", defaultPassword);
passwordCheck = agentPreferences.getString("passwordCheck", defaultPasswordCheck);
simIDReport = agentPreferences.getString("simIDReport", defaultSimIDReport);
DeviceUpTimeReport = agentPreferences.getString("DeviceUpTimeReport", defaultDeviceUpTimeReport);
NetworkOperatorReport = agentPreferences.getString("NetworkOperatorReport", defaultNetworkOperatorReport);
NetworkTypeReport = agentPreferences.getString("NetworkTypeReport", defaultNetworkTypeReport);
PhoneTypeReport = agentPreferences.getString("PhoneTypeReport", defaultPhoneTypeReport);
SignalStrengthReport = agentPreferences.getString("SignalStrengthReport", defaultSignalStrengthReport);
ReceivedSMSReport = agentPreferences.getString("ReceivedSMSReport", defaultReceivedSMSReport);
SentSMSReport = agentPreferences.getString("SentSMSReport", defaultSentSMSReport);
IncomingCallsReport = agentPreferences.getString("IncomingCallsReport", defaultIncomingCallsReport);
MissedCallsReport = agentPreferences.getString("MissedCallsReport", defaultMissedCallsReport);
OutgoingCallsReport = agentPreferences.getString("OutgoingCallsReport", defaultOutgoingCallsReport);
BytesReceivedReport = agentPreferences.getString("BytesReceivedReport", defaultBytesReceivedReport);
BytesSentReport = agentPreferences.getString("BytesSentReport", defaultBytesSentReport);
HelloSignalReport = agentPreferences.getString("HelloSignalReport", defaultHelloSignalReport);
BatteryLevelReport = agentPreferences.getString("BatteryLevelReport", defaultBatteryLevelReport);
RoamingReport = agentPreferences.getString("RoamingReport", defaultRoamingReport);
InventoryReport = agentPreferences.getString("InventoryReport", defaultInventoryReport);
NotificationCheck = agentPreferences.getString("NotificationCheck", defaultNotificationCheck);
}// end loadConf
static synchronized public boolean updateConf(Context context) {
@ -300,7 +304,7 @@ public class Core {
passwordCheck, DeviceUpTimeReport, NetworkOperatorReport, NetworkTypeReport, PhoneTypeReport,
SignalStrengthReport, ReceivedSMSReport, SentSMSReport, IncomingCallsReport, MissedCallsReport,
OutgoingCallsReport, BytesReceivedReport, BytesSentReport, HelloSignalReport, BatteryLevelReport,
RoamingReport, roaming, mobileWebURL, InventoryReport, NotificationCheck, bufferSize
RoamingReport, roaming, mobileWebURL, InventoryReport ,NotificationCheck, bufferSize
);
}// end updateConf
@ -321,60 +325,120 @@ public class Core {
con = context;
}
SharedPreferences agentPreferences = con.getSharedPreferences(
con.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = agentPreferences.edit();
editor.putString("serverAddr", _serverAddr);
editor.putString("serverPort", _serverPort);
editor.putInt("interval", _interval);
editor.putString("agentName", _agentName);
editor.putString("gpsStatus", _gpsStatus);
editor.putString("memoryStatus", _memoryStatus);
editor.putString("taskStatus", _taskStatus);
editor.putString("task", _task);
editor.putString("taskHumanName", _taskHumanName);
editor.putString("simID", _simID);
editor.putString("simIDReport", _simIDReport);
editor.putLong("UpTime", _upTime);
editor.putString("networkOperator", _networkOperator);
editor.putInt("SMSReceived", _smsReceived);
editor.putInt("SMSSent", _smsSent);
editor.putString("networkType", _networkType);
editor.putString("phoneType", _phoneType);
editor.putInt("signalStrength", _signalStrength);
editor.putInt("incomingCalls", _incomingCalls);
editor.putInt("missedCalls", _missedCalls);
editor.putInt("outgoingCalls", _outgoingCalls);
editor.putLong("receiveBytes", _receiveBytes);
editor.putLong("transmitBytes", _transmitBytes);
editor.putString("password", _password);
editor.putString("passwordCheck", _passwordCheck);
editor.putInt("helloSignal", _helloSignal);
editor.putInt("roaming", _roaming);
editor.putString("DeviceUpTimeReport", _DeviceUpTimeReport);
editor.putString("NetworkOperatorReport", _NetworkOperatorReport);
editor.putString("NetworkTypeReport", _NetworkTypeReport);
editor.putString("PhoneTypeReport", _PhoneTypeReport);
editor.putString("SignalStrengthReport", _SignalStrengthReport);
editor.putString("ReceivedSMSReport", _ReceivedSMSReport);
editor.putString("SentSMSReport", _SentSMSReport);
editor.putString("IncomingCallsReport", _IncomingCallsReport);
editor.putString("MissedCallsReport", _MissedCallsReport);
editor.putString("OutgoingCallsReport", _OutgoingCallsReport);
editor.putString("BytesReceivedReport", _BytesReceivedReport);
editor.putString("BytesSentReport", _BytesSentReport);
editor.putString("HelloSignalReport", _HelloSignalReport);
editor.putString("BatteryLevelReport", _BatteryLevelReport);
editor.putString("RoamingReport", _RoamingReport);
editor.putString("InventoryReport", _InventoryReport);
editor.putString("NotificationCheck", _NotificationCheck);
editor.putString("mobileWebURL", _mobileWebURL);
editor.putLong("bufferSize", _bufferSize);
HelperSharedPreferences.putSharedPreferencesString(con, "serverAddr", _serverAddr);
HelperSharedPreferences.putSharedPreferencesString(con, "serverPort", _serverPort);
HelperSharedPreferences.putSharedPreferencesInt(con, "interval", _interval);
HelperSharedPreferences.putSharedPreferencesString(con, "agentName", _agentName);
HelperSharedPreferences.putSharedPreferencesString(con, "gpsStatus", _gpsStatus);
HelperSharedPreferences.putSharedPreferencesString(con, "memoryStatus", _memoryStatus);
HelperSharedPreferences.putSharedPreferencesString(con, "taskStatus", _taskStatus);
HelperSharedPreferences.putSharedPreferencesString(con, "task", _task);
HelperSharedPreferences.putSharedPreferencesString(con, "taskHumanName", _taskHumanName);
HelperSharedPreferences.putSharedPreferencesString(con, "simID", _simID);
HelperSharedPreferences.putSharedPreferencesString(con, "simIDReport", _simIDReport);
HelperSharedPreferences.putSharedPreferencesLong(con, "upTime", _upTime);
HelperSharedPreferences.putSharedPreferencesString(con, "networkOperator", _networkOperator);
HelperSharedPreferences.putSharedPreferencesInt(con, "SMSReceived", _smsReceived);
HelperSharedPreferences.putSharedPreferencesInt(con, "SMSSent", _smsSent);
HelperSharedPreferences.putSharedPreferencesString(con, "networkType", _networkType);
HelperSharedPreferences.putSharedPreferencesString(con, "phoneType", _phoneType);
HelperSharedPreferences.putSharedPreferencesInt(con, "signalStrength", _signalStrength);
HelperSharedPreferences.putSharedPreferencesInt(con, "incomingCalls", _incomingCalls);
HelperSharedPreferences.putSharedPreferencesInt(con, "missedCalls", _missedCalls);
HelperSharedPreferences.putSharedPreferencesInt(con, "outgoingCalls", _outgoingCalls);
HelperSharedPreferences.putSharedPreferencesLong(con, "receiveBytes", _receiveBytes);
HelperSharedPreferences.putSharedPreferencesLong(con, "transmitBytes", _transmitBytes);
HelperSharedPreferences.putSharedPreferencesString(con, "password", _password);
HelperSharedPreferences.putSharedPreferencesString(con, "passwordCheck", _passwordCheck);
HelperSharedPreferences.putSharedPreferencesInt(con, "helloSignal", _helloSignal);
HelperSharedPreferences.putSharedPreferencesInt(con, "roaming", _roaming);
HelperSharedPreferences.putSharedPreferencesString(con, "DeviceUpTimeReport", _DeviceUpTimeReport);
HelperSharedPreferences.putSharedPreferencesString(con, "NetworkOperatorReport", _NetworkOperatorReport);
HelperSharedPreferences.putSharedPreferencesString(con, "NetworkTypeReport", _NetworkTypeReport);
HelperSharedPreferences.putSharedPreferencesString(con, "PhoneTypeReport", _PhoneTypeReport);
HelperSharedPreferences.putSharedPreferencesString(con, "SignalStrengthReport", _SignalStrengthReport);
HelperSharedPreferences.putSharedPreferencesString(con, "ReceivedSMSReport", _ReceivedSMSReport);
HelperSharedPreferences.putSharedPreferencesString(con, "SentSMSReport", _SentSMSReport);
HelperSharedPreferences.putSharedPreferencesString(con, "IncomingCallsReport", _IncomingCallsReport);
HelperSharedPreferences.putSharedPreferencesString(con, "MissedCallsReport", _MissedCallsReport);
HelperSharedPreferences.putSharedPreferencesString(con, "OutgoingCallsReport", _OutgoingCallsReport);
HelperSharedPreferences.putSharedPreferencesString(con, "BytesReceivedReport", _BytesReceivedReport);
HelperSharedPreferences.putSharedPreferencesString(con, "BytesSentReport", _BytesSentReport);
HelperSharedPreferences.putSharedPreferencesString(con, "HelloSignalReport", _HelloSignalReport);
HelperSharedPreferences.putSharedPreferencesString(con, "BatteryLevelReport", _BatteryLevelReport);
HelperSharedPreferences.putSharedPreferencesString(con, "RoamingReport", _RoamingReport);
HelperSharedPreferences.putSharedPreferencesString(con, "InventoryReport", _InventoryReport);
HelperSharedPreferences.putSharedPreferencesString(con, "NotificationCheck", _NotificationCheck);
HelperSharedPreferences.putSharedPreferencesString(con, "mobileWebURL", _mobileWebURL);
HelperSharedPreferences.putSharedPreferencesLong(con, "bufferSize", _bufferSize);
return true;
if (editor.commit()) {
return true;
}
return false;
}// end updateConf
public synchronized static void putSharedData(String preferenceName, String tokenName, String data, String type) {
int mode = Activity.MODE_PRIVATE;
SharedPreferences agentPreferences = con.getSharedPreferences(
con.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = agentPreferences.edit();
if(type == "boolean") {
editor.putBoolean(tokenName, Boolean.parseBoolean(data));
}
else if(type == "float") {
editor.putFloat(tokenName, Float.parseFloat(data));
}
else if(type == "integer") {
editor.putInt(tokenName, Integer.parseInt(data));
}
else if(type == "long") {
editor.putLong(tokenName, Long.parseLong(data));
}
else if(type == "string") {
editor.putString(tokenName, data);
}
editor.commit();
}
public synchronized static String getSharedData(String preferenceName, String tokenName, String defaultValue, String type) {
int mode = Activity.MODE_PRIVATE;
SharedPreferences agentPreferences = con.getSharedPreferences(
con.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if(type == "boolean") {
boolean a = agentPreferences.getBoolean(tokenName, Boolean.parseBoolean(defaultValue));
return Boolean.valueOf(a).toString();
}
else if(type == "float") {
float a = agentPreferences.getFloat(tokenName, Float.parseFloat(defaultValue));
return Float.valueOf(a).toString();
}
else if(type == "integer") {
int a = agentPreferences.getInt(tokenName, Integer.parseInt(defaultValue));
return Integer.valueOf(a).toString();
}
else if(type == "long") {
long a = agentPreferences.getLong(tokenName, Long.parseLong(defaultValue));
return Long.valueOf(a).toString();
}
else if(type == "string") {
return agentPreferences.getString(tokenName, defaultValue);
}
return "";
}
// //database//
@ -539,41 +603,5 @@ public class Core {
// return true;
// }// end updateConf
//
//
//
//// //Adds a new row "name" with the value "value"
//// public static void addValue(Context context, String name, String value){
//// db = new DataBaseHandler(con);
////
//// DataHandler dh = new DataHandler(name, value);
////
//// db.addValue(dh);
////
//// }
//
// //Updates a given row "name" with a "value"
// public static synchronized void updateDatabaseValue(Context context, String name, String value){
// db = new DataBaseHandler(con, "pandroid", null, 1);
// //Retrieve id of row to update
// int id = getDataHandler(con, name).get_id();
//
// DataHandler dh = new DataHandler(id, name, value);
//
// db.updateValue(dh);
// }
//
// //Returns the DataHandler object of the given row "name"
// public static synchronized DataHandler getDataHandler(Context context, String name){
// db = new DataBaseHandler(con, "pandroid", null, 1);
//
// return db.getValue(name);
// }
//
// //Returns the value of the given row "name"
// public static synchronized String getDatabaseValue(Context context, String name){
// db = new DataBaseHandler(con, "pandroid", null, 1);
//
// return db.getValue(name).get_value();
//
// }
}

View File

@ -0,0 +1,139 @@
package pandroid.agent;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
public class HelperSharedPreferences {
public static class SharedPreferencesKeys{
public static final String key1="key1";
public static final String key2="key2";
}
// public static void putSharedPreferencesInt(Context context, String key, int value){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// Editor edit=preferences.edit();
// edit.putInt(key, value);
// edit.commit();
// }
//
// public static void putSharedPreferencesBoolean(Context context, String key, boolean val){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// Editor edit=preferences.edit();
// edit.putBoolean(key, val);
// edit.commit();
// }
//
// public static void putSharedPreferencesString(Context context, String key, String val){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// Editor edit=preferences.edit();
// edit.putString(key, val);
// edit.commit();
// }
//
// public static void putSharedPreferencesFloat(Context context, String key, float val){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// Editor edit=preferences.edit();
// edit.putFloat(key, val);
// edit.commit();
// }
//
// public static void putSharedPreferencesLong(Context context, String key, long val){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// Editor edit=preferences.edit();
// edit.putLong(key, val);
// edit.commit();
// }
//
// public static int getSharedPreferencesInt(Context context, String key, int _default){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// return preferences.getInt(key, _default);
// }
//
// public static long getSharedPreferencesLong(Context context, String key, long _default){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// return preferences.getLong(key, _default);
// }
//
// public static float getSharedPreferencesFloat(Context context, String key, float _default){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// return preferences.getFloat(key, _default);
// }
//
// public static String getSharedPreferencesString(Context context, String key, String _default){
// SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
// return preferences.getString(key, _default);
// }
public synchronized static void putSharedPreferencesInt(Context context, String name, int value){
DataBaseHandler db = new DataBaseHandler(context);
int id = getDataHandler(context, name).get_id();
DataHandler dh = new DataHandler(id, name, ""+value);
db.updateValue(dh);
}
public synchronized static void putSharedPreferencesLong(Context context, String name, long value){
DataBaseHandler db = new DataBaseHandler(context);
int id = getDataHandler(context, name).get_id();
DataHandler dh = new DataHandler(id, name, ""+value);
db.updateValue(dh);
}
public synchronized static void putSharedPreferencesFloat(Context context, String name, float value){
DataBaseHandler db = new DataBaseHandler(context);
int id = getDataHandler(context, name).get_id();
DataHandler dh = new DataHandler(id, name, ""+value);
db.updateValue(dh);
}
public synchronized static void putSharedPreferencesString(Context context, String name, String value){
DataBaseHandler db = new DataBaseHandler(context);
int id = getDataHandler(context, name).get_id();
DataHandler dh = new DataHandler(id, name, value);
db.updateValue(dh);
}
public synchronized static int getSharedPreferencesInt(Context context, String name, int i){
DataBaseHandler db = new DataBaseHandler(context);
return Integer.parseInt(db.getValue(name).get_value());
}
public synchronized static long getSharedPreferencesLong(Context context, String name, long l){
DataBaseHandler db = new DataBaseHandler(context);
return Long.parseLong(db.getValue(name).get_value());
}
public synchronized static float getSharedPreferencesFloat(Context context, String name, float f){
DataBaseHandler db = new DataBaseHandler(context);
return Float.parseFloat(db.getValue(name).get_value());
}
public synchronized static String getSharedPreferencesString(Context context, String name, String s){
DataBaseHandler db = new DataBaseHandler(context);
return db.getValue(name).get_value();
}
//Returns the DataHandler object of the given row "name"
public static synchronized DataHandler getDataHandler(Context context, String name){
DataBaseHandler db = new DataBaseHandler(context);
return db.getValue(name);
}
}

View File

@ -20,6 +20,8 @@ import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
@ -36,7 +38,8 @@ public class PandroidAgent extends TabActivity {
int defaultInterval = 300;
TabHost tabHost;
static SharedPreferences agentPreferences;
static Editor editor;
@Override
@ -46,7 +49,11 @@ public class PandroidAgent extends TabActivity {
//database//
agentPreferences = this.getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
editor = agentPreferences.edit();
//Core.loadConfDatabase(this);
//Core.loadLastValuesDatabase(this);
@ -137,7 +144,15 @@ public class PandroidAgent extends TabActivity {
tabHost.setCurrentTab(tab);
}
public static SharedPreferences getSharedPrefs() {
// TODO Auto-generated method stub
return agentPreferences;
}
public static Editor getEditor() {
// TODO Auto-generated method stub
return editor;
}
}

View File

@ -63,7 +63,6 @@ import android.widget.Toast;
public class PandroidAgentListener extends Service {
private NotificationManager notificationManager;
private Notification notification;
Handler h = new Handler();
String lastGpsContactDateTime = "";
@ -72,22 +71,60 @@ public class PandroidAgentListener extends Service {
@Override
public void onCreate() {
try {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
} catch (Exception e) {
Log.e("notification", e.toString());
}
if(Core.NotificationCheck == "enabled"){
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
System.currentTimeMillis());
Intent notificationIntent = new Intent(this,PandroidAgent.class);
notificationIntent.setAction("android.intent.action.MAIN");
notificationIntent.addCategory("android.intent.category.LAUNCHER");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, Notification.FLAG_NO_CLEAR);
notification.setLatestEventInfo(this, getText(R.string.notification_title), getText(R.string.notification_message), pendingIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(1, notification);
}
else{
CancelNotification(getApplicationContext(),1);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();
updateValues();
contact();
try {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
} catch (Exception e) {
Log.e("notification", e.toString());
}
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
System.currentTimeMillis());
Intent notificationIntent = new Intent(this,PandroidAgent.class);
notificationIntent.setAction("android.intent.action.MAIN");
notificationIntent.addCategory("android.intent.category.LAUNCHER");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, Notification.FLAG_NO_CLEAR);
notification.setLatestEventInfo(this, getText(R.string.notification_title), getText(R.string.notification_message), pendingIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
if(Core.NotificationCheck == "enabled"){
notificationManager.notify(1, notification);
}
else{
CancelNotification(getApplicationContext(),1);
}
startForeground(42,notification);
wakeLock.release();
stopSelf(startId);
@ -162,7 +199,7 @@ public class PandroidAgentListener extends Service {
Date date = new Date();
HelperSharedPreferences.putSharedPreferencesLong(this, "lastContact", date.getTime() / 1000);
Core.putSharedData("PANDROID_DATA", "lastContact", Long.toString(date.getTime() / 1000), "long");
Boolean xmlBuilt = true;
String xml = "";
@ -212,7 +249,7 @@ public class PandroidAgentListener extends Service {
String[] tentacleData = {
"-a",
HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "serverAddr", ""),
Core.getSharedData("PANDROID_DATA", "serverAddr", "", "string"),
"-p",
Core.defaultServerPort,
"-v",
@ -223,7 +260,7 @@ public class PandroidAgentListener extends Service {
tentacleRet = new tentacle_client().tentacle_client(tentacleData);
if(tentacleRet == 0) {
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "contactError", 0);
Core.putSharedData("PANDROID_DATA", "contactError", "0", "integer");
// Deleting the file after send it
// move to only delete if sent successfully
File file = new File("/data/data/pandroid.agent/files/" + destFileName);
@ -235,7 +272,7 @@ public class PandroidAgentListener extends Service {
}
if(tentacleRet == -1){
//file not deleted
HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "contactError", 1);
Core.putSharedData("PANDROID_DATA", "contactError", "1", "integer");
contact = false;
}
i++;
@ -257,9 +294,10 @@ public class PandroidAgentListener extends Service {
String lastXML = buildXML();
String destFileName = "";
String agentName = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "agentName", Core.defaultAgentName);
String agentName = Core.getSharedData("PANDROID_DATA", "agentName", Core.defaultAgentName, "string");
destFileName = agentName + "." + System.currentTimeMillis() + ".data";
long bufferSize = 0;
String[] buffer = getApplicationContext().fileList();
@ -272,11 +310,11 @@ public class PandroidAgentListener extends Service {
//Check if size of buffer is less than a value
if((bufferSize/1024) < Core.bufferSize){
writeFile(destFileName, lastXML);
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "lastXML", lastXML);
Core.putSharedData("PANDROID_DATA", "lastXML", lastXML, "string");
}else{
//buffer full
}
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "lastXML", lastXML);
Core.putSharedData("PANDROID_DATA", "lastXML", lastXML, "string");
return lastXML;
@ -315,15 +353,15 @@ public class PandroidAgentListener extends Service {
String gpsData = "";
buffer += "<?xml version='1.0' encoding='iso-8859-1'?>\n";
String latitude = ""+HelperSharedPreferences.getSharedPreferencesFloat(getApplicationContext(), "latitude", 181);
String longitude = ""+HelperSharedPreferences.getSharedPreferencesFloat(getApplicationContext(), "longitude", 181);
String latitude = Core.getSharedData("PANDROID_DATA", "latitude", "181", "float");
String longitude = Core.getSharedData("PANDROID_DATA", "longitude", "181", "float");
if(!latitude.equals("181.0") && !longitude.equals("181.0")) {
gpsData = " latitude='" + latitude + "' longitude='" + longitude + "'";
}
String agentName = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "agentName", Core.defaultAgentName);
String interval = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "interval", Core.defaultInterval);
String agentName = Core.getSharedData("PANDROID_DATA", "agentName", Core.defaultAgentName, "string");
String interval = Core.getSharedData("PANDROID_DATA", "interval", Integer.toString(Core.defaultInterval), "integer");
buffer += "<agent_data " +
"description='' group='' os_name='android' os_version='"+Build.VERSION.RELEASE+"' " +
@ -335,51 +373,51 @@ public class PandroidAgentListener extends Service {
// MODULES //
// //
String orientation = ""+HelperSharedPreferences.getSharedPreferencesFloat(getApplicationContext(), "orientation", 361);
String proximity = ""+HelperSharedPreferences.getSharedPreferencesFloat(getApplicationContext(), "proximity", -1.0f);
String batteryLevel = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "batteryLevel", -1);
String taskStatus = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "taskStatus", "disabled");
String taskRun = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "taskRun", "false");
String taskHumanName = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "taskHumanName", "");
String orientation = Core.getSharedData("PANDROID_DATA", "orientation", "361", "float");
String proximity = Core.getSharedData("PANDROID_DATA", "proximity", "-1.0", "float");
String batteryLevel = Core.getSharedData("PANDROID_DATA", "batteryLevel", "-1", "integer");
String taskStatus = Core.getSharedData("PANDROID_DATA", "taskStatus", "disabled", "string");
String taskRun = Core.getSharedData("PANDROID_DATA", "taskRun", "false", "string");
String taskHumanName = Core.getSharedData("PANDROID_DATA", "taskHumanName", "", "string");
taskHumanName = StringEscapeUtils.escapeHtml4(taskHumanName);
String task = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "task", "");
String memoryStatus = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "memoryStatus", Core.defaultMemoryStatus);
String availableRamKb = ""+HelperSharedPreferences.getSharedPreferencesLong(getApplicationContext(), "availableRamKb", 0);
String totalRamKb = ""+HelperSharedPreferences.getSharedPreferencesLong(getApplicationContext(), "totalRamKb", 0);
String SimID = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "simID", Core.defaultSimID);
String upTime = ""+HelperSharedPreferences.getSharedPreferencesLong(getApplicationContext(), "upTime", Core.defaultUpTime);
String networkOperator = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "networkOperator", Core.defaultNetworkOperator);
String SMSReceived = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "SMSReceived", Core.defaultSMSReceived);
String SMSSent = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "SMSSent", Core.defaultSMSSent);
String networkType = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "networkType", Core.defaultNetworkType);
String phoneType = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "networkType", Core.defaultNetworkType);
String signalStrength = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "signalStrength", Core.defaultSignalStrength);
String incomingCalls = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "incomingCalls", Core.defaultIncomingCalls);
String missedCalls = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "missedCalls", Core.defaultMissedCalls);
String outgoingCalls = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "outgoingCalls", Core.defaultOutgoingCalls);
String receiveBytes = ""+HelperSharedPreferences.getSharedPreferencesLong(getApplicationContext(), "receiveBytes", Core.defaultReceiveBytes);
String transmitBytes = ""+HelperSharedPreferences.getSharedPreferencesLong(getApplicationContext(), "transmitBytes", Core.defaultTransmitBytes);
String helloSignal = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "helloSignal", Core.defaultHelloSignal);
String roaming = ""+HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "roaming", Core.defaultRoaming);
String task = Core.getSharedData("PANDROID_DATA", "task", "", "string");
String memoryStatus = Core.getSharedData("PANDROID_DATA", "memoryStatus", Core.defaultMemoryStatus, "string");
String availableRamKb = Core.getSharedData("PANDROID_DATA", "availableRamKb", "0" , "long");
String totalRamKb = Core.getSharedData("PANDROID_DATA", "totalRamKb", "0", "long");
String SimID = Core.getSharedData("PANDROID_DATA", "simID", Core.defaultSimID, "string");
String upTime = Core.getSharedData("PANDROID_DATA", "upTime", ""+Core.defaultUpTime, "long");
String networkOperator = Core.getSharedData("PANDROID_DATA", "networkOperator", Core.defaultNetworkOperator, "string");
String SMSReceived = Core.getSharedData("PANDROID_DATA", "SMSReceived", ""+Core.defaultSMSReceived, "integer");
String SMSSent = Core.getSharedData("PANDROID_DATA", "SMSSent", ""+Core.defaultSMSSent, "integer");
String networkType = Core.getSharedData("PANDROID_DATA", "networkType", Core.defaultNetworkType, "string");
String phoneType = Core.getSharedData("PANDROID_DATA", "networkType", Core.defaultNetworkType, "string");
String signalStrength = Core.getSharedData("PANDROID_DATA", "signalStrength", ""+Core.defaultSignalStrength, "integer");
String incomingCalls = Core.getSharedData("PANDROID_DATA", "incomingCalls", ""+Core.defaultIncomingCalls, "integer");
String missedCalls = Core.getSharedData("PANDROID_DATA", "missedCalls", ""+Core.defaultMissedCalls, "integer");
String outgoingCalls = Core.getSharedData("PANDROID_DATA", "outgoingCalls", ""+Core.defaultOutgoingCalls, "integer");
String receiveBytes = Core.getSharedData("PANDROID_DATA", "receiveBytes", ""+Core.defaultReceiveBytes, "long");
String transmitBytes = Core.getSharedData("PANDROID_DATA", "transmitBytes", ""+Core.defaultTransmitBytes, "long");
String helloSignal = Core.getSharedData("PANDROID_DATA", "helloSignal", ""+Core.defaultHelloSignal, "integer");
String roaming = Core.getSharedData("PANDROID_DATA", "roaming", ""+Core.defaultRoaming, "integer");
String simIDReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "simIDReport", Core.defaultSimIDReport);
String DeviceUpTimeReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "DeviceUpTimeReport", Core.defaultDeviceUpTimeReport);
String NetworkOperatorReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "NetworkOperatorReport", Core.defaultNetworkOperatorReport);
String NetworkTypeReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "NetworkTypeReport", Core.defaultNetworkTypeReport);
String PhoneTypeReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "PhoneTypeReport", Core.defaultPhoneTypeReport);
String SignalStrengthReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "SignalStrengthReport", Core.defaultSignalStrengthReport);
String ReceivedSMSReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "ReceivedSMSReport", Core.defaultReceivedSMSReport);
String SentSMSReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "SentSMSReport", Core.defaultSentSMSReport);
String IncomingCallsReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "IncomingCallsReport", Core.defaultIncomingCallsReport);
String MissedCallsReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "MissedCallsReport", Core.defaultMissedCallsReport);
String OutgoingCallsReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "OutgoingCallsReport", Core.defaultOutgoingCallsReport);
String BytesReceivedReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "BytesReceivedReport", Core.defaultBytesReceivedReport);
String BytesSentReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "BytesSentReport", Core.defaultBytesSentReport);
String HelloSignalReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "HelloSignalReport", Core.defaultHelloSignalReport);
String BatteryLevelReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "BatteryLevelReport", Core.defaultBatteryLevelReport);
String RoamingReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "RoamingReport", Core.defaultRoamingReport);
String InventoryReport = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "InventoryReport", Core.defaultInventoryReport);
String simIDReport = Core.getSharedData("PANDROID_DATA", "simIDReport", Core.defaultSimIDReport, "string");
String DeviceUpTimeReport = Core.getSharedData("PANDROID_DATA", "DeviceUpTimeReport", Core.defaultDeviceUpTimeReport, "string");
String NetworkOperatorReport = Core.getSharedData("PANDROID_DATA", "NetworkOperatorReport", Core.defaultNetworkOperatorReport, "string");
String NetworkTypeReport = Core.getSharedData("PANDROID_DATA", "NetworkTypeReport", Core.defaultNetworkTypeReport, "string");
String PhoneTypeReport = Core.getSharedData("PANDROID_DATA", "PhoneTypeReport", Core.defaultPhoneTypeReport, "string");
String SignalStrengthReport = Core.getSharedData("PANDROID_DATA", "SignalStrengthReport", Core.defaultSignalStrengthReport, "string");
String ReceivedSMSReport = Core.getSharedData("PANDROID_DATA", "ReceivedSMSReport", Core.defaultReceivedSMSReport, "string");
String SentSMSReport = Core.getSharedData("PANDROID_DATA", "SentSMSReport", Core.defaultSentSMSReport, "string");
String IncomingCallsReport = Core.getSharedData("PANDROID_DATA", "IncomingCallsReport", Core.defaultIncomingCallsReport, "string");
String MissedCallsReport = Core.getSharedData("PANDROID_DATA", "MissedCallsReport", Core.defaultMissedCallsReport, "string");
String OutgoingCallsReport = Core.getSharedData("PANDROID_DATA", "OutgoingCallsReport", Core.defaultOutgoingCallsReport, "string");
String BytesReceivedReport = Core.getSharedData("PANDROID_DATA", "BytesReceivedReport", Core.defaultBytesReceivedReport, "string");
String BytesSentReport = Core.getSharedData("PANDROID_DATA", "BytesSentReport", Core.defaultBytesSentReport, "string");
String HelloSignalReport = Core.getSharedData("PANDROID_DATA", "HelloSignalReport", Core.defaultHelloSignalReport, "string");
String BatteryLevelReport = Core.getSharedData("PANDROID_DATA", "BatteryLevelReport", Core.defaultBatteryLevelReport, "string");
String RoamingReport = Core.getSharedData("PANDROID_DATA", "RoamingReport", Core.defaultRoamingReport, "string");
String InventoryReport = Core.getSharedData("PANDROID_DATA", "InventoryReport", Core.defaultInventoryReport, "string");
if(InventoryReport.equals("enabled"))
{
@ -564,8 +602,8 @@ public class PandroidAgentListener extends Service {
//if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) {
lastGpsContactDateTime = getHumanDateTime(-1);
//}
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "latitude", (float) loc.getLatitude());
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "longitude", (float) loc.getLongitude());
Core.putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float");
Core.putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float");
}
else {
Criteria criteria = new Criteria();
@ -585,8 +623,10 @@ public class PandroidAgentListener extends Service {
lm.requestLocationUpdates(bestProvider, Core.defaultInterval, 1000,
new LocationListener() {
public void onLocationChanged(Location location) {
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "latitude",(float) location.getLatitude());
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "longitude",(float) location.getLongitude());
Core.putSharedData("PANDROID_DATA", "latitude",
Double.valueOf(location.getLatitude()).toString(), "float");
Core.putSharedData("PANDROID_DATA", "longitude",
Double.valueOf(location.getLongitude()).toString(), "float");
}
public void onStatusChanged(String s, int i, Bundle bundle) {
@ -595,7 +635,8 @@ public class PandroidAgentListener extends Service {
// try switching to a different provider
}
public void onProviderDisabled(String s) {
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "enabled_location_provider", "disabled");
Core.putSharedData("PANDROID_DATA", "enabled_location_provider",
"disabled", "string");
}
});
}
@ -609,7 +650,7 @@ public class PandroidAgentListener extends Service {
int scale = batteryIntent.getIntExtra("scale", -1);
//double level = -1;
if (rawlevel >= 0 && scale > 0) {
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "batteryLevel", (rawlevel * 100) / scale);
Core.putSharedData("PANDROID_DATA", "batteryLevel", Integer.valueOf((rawlevel * 100) / scale).toString(), "integer");
}
}
@ -676,7 +717,7 @@ public class PandroidAgentListener extends Service {
private void updateValues() {
batteryLevel();
String gpsStatus = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "gpsStatus", Core.defaultGpsStatus);
String gpsStatus = Core.getSharedData("PANDROID_DATA", "gpsStatus", Core.defaultGpsStatus, "string");
if(gpsStatus.equals("enabled")) {
Log.d("PANDROID AGENT", "ENABLED");
@ -684,8 +725,8 @@ public class PandroidAgentListener extends Service {
}
else {
Log.d("PANDROID AGENT", "DISABLED");
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "latitude", 181.0f);
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "longitude", 181.0f);
Core.putSharedData("PANDROID_DATA", "latitude", "181.0", "float");
Core.putSharedData("PANDROID_DATA", "longitude", "181.0", "float");
}
//sensors();
@ -708,7 +749,7 @@ public class PandroidAgentListener extends Service {
}
private void getMemoryStatus() {
String memoryStatus = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "memoryStatus", Core.defaultMemoryStatus);
String memoryStatus = Core.getSharedData("PANDROID_DATA", "memoryStatus", Core.defaultMemoryStatus, "string");
long availableRamKb = 0;
long totalRamKb = 0;
@ -734,14 +775,14 @@ public class PandroidAgentListener extends Service {
}
}
HelperSharedPreferences.putSharedPreferencesLong(getApplicationContext(), "availableRamKb", availableRamKb);
HelperSharedPreferences.putSharedPreferencesLong(getApplicationContext(), "totalRamKb", totalRamKb);
Core.putSharedData("PANDROID_DATA", "availableRamKb", "" + availableRamKb, "long");
Core.putSharedData("PANDROID_DATA", "totalRamKb", "" + totalRamKb, "long");
}// end getMemoryStatus
private void getTaskStatus() {
String taskStatus = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "taskStatus", Core.defaultTaskStatus);
String task = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "task", Core.defaultTask);
String taskHumanName = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "taskHumanName", Core.defaultTaskHumanName);
String taskStatus = Core.getSharedData("PANDROID_DATA", "taskStatus", Core.defaultTaskStatus, "string");
String task = Core.getSharedData("PANDROID_DATA", "task", Core.defaultTask, "string");
String taskHumanName = Core.getSharedData("PANDROID_DATA", "taskHumanName", Core.defaultTaskHumanName, "string");
String run = "false";
if (taskStatus.equals("enabled")) {
@ -761,7 +802,7 @@ public class PandroidAgentListener extends Service {
}
}
}
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "taskRun", run);
Core.putSharedData("PANDROID_DATA", "taskRun", run, "string");
}//end getTaskStatus
/**
@ -769,12 +810,12 @@ public class PandroidAgentListener extends Service {
*/
private void getSimID(){
String simID = HelperSharedPreferences.getSharedPreferencesString(getApplicationContext(), "simID", Core.defaultSimID);
String simID = Core.getSharedData("PANDROID_DATA", "simID", Core.defaultSimID, "string");
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(serviceName);
simID = telephonyManager.getSimSerialNumber();
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "simID", simID);
Core.putSharedData("PANDROID_DATA", "simID", simID, "string");
}
/**
* Retrieves the time in seconds since the device was switched on
@ -783,7 +824,7 @@ public class PandroidAgentListener extends Service {
long upTime = Core.defaultUpTime;
upTime = SystemClock.elapsedRealtime()/1000;
if(upTime != 0)
HelperSharedPreferences.putSharedPreferencesLong(getApplicationContext(), "upTime", upTime);
Core.putSharedData("PANDROID_DATA", "upTime", ""+upTime, "long");
}
/**
* Retrieve currently registered network operator, i.e. vodafone, movistar, etc...
@ -795,15 +836,15 @@ public class PandroidAgentListener extends Service {
networkOperator = telephonyManager.getNetworkOperatorName();
if(networkOperator != null)
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "networkOperator", networkOperator);
Core.putSharedData("PANDROID_DATA", "networkOperator", networkOperator, "string");
}
/**
* Retrieves the number of sent sms messages using the android messaging app only
*/
private void getSMSSent(){
int SMSSent = Core.defaultSMSSent;
SMSSent = HelperSharedPreferences.getSharedPreferencesInt(getApplicationContext(), "SMSSent", Core.defaultSMSSent);
String SMSSent = ""+Core.defaultSMSSent;
SMSSent = Core.getSharedData("PANDROID_DATA", "SMSSent", ""+Core.defaultSMSSent, "integer");
Uri allMessages = Uri.parse("content://sms/sent");
Cursor c = getContentResolver().query(allMessages, null, null, null, null);
int totalMessages = 0;
@ -819,10 +860,10 @@ public class PandroidAgentListener extends Service {
c.close();
SMSSent = totalMessages;
SMSSent =""+ totalMessages;
if(SMSSent != 0)
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "SMSSent", SMSSent);
if(SMSSent != null)
Core.putSharedData("PANDROID_DATA", "SMSSent", SMSSent, "integer");
}// end getSMSSent
/**
@ -886,7 +927,7 @@ public class PandroidAgentListener extends Service {
break;
}
if(networkType != null)
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "networkType", networkType);
Core.putSharedData("PANDROID_DATA", "networkType", networkType, "string");
}// end getNetworkType
@ -915,7 +956,7 @@ public class PandroidAgentListener extends Service {
break;
}
if(phoneType != null)
HelperSharedPreferences.putSharedPreferencesString(getApplicationContext(), "phoneType", phoneType);
Core.putSharedData("PANDROID_DATA", "phoneType", phoneType, "string");
}// end getPhoneType
/**
@ -949,9 +990,9 @@ public class PandroidAgentListener extends Service {
c.moveToNext();
}
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "incomingCalls", incoming);
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "missedCalls", missed);
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "outgoingCalls", outgoing);
Core.putSharedData("PANDROID_DATA", "incomingCalls", ""+incoming, "integer");
Core.putSharedData("PANDROID_DATA", "missedCalls", ""+missed, "integer");
Core.putSharedData("PANDROID_DATA", "outgoingCalls", ""+outgoing, "integer");
}
c.close();
@ -972,17 +1013,17 @@ public class PandroidAgentListener extends Service {
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
int signalStrengthValue = Core.defaultSignalStrength;
String signalStrengthValue = ""+Core.defaultSignalStrength;
if (signalStrength.isGsm()) {
if (signalStrength.getGsmSignalStrength() != 99)
signalStrengthValue = (signalStrength.getGsmSignalStrength() * 2 - 113);
signalStrengthValue =""+ (signalStrength.getGsmSignalStrength() * 2 - 113);
else
signalStrengthValue = (signalStrength.getGsmSignalStrength());
signalStrengthValue =""+ (signalStrength.getGsmSignalStrength());
}
else{
signalStrengthValue = (signalStrength.getCdmaDbm());
signalStrengthValue ="" + (signalStrength.getCdmaDbm());
}
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "signalStrength", signalStrengthValue);
Core.putSharedData("PANDROID_DATA", "signalStrength", signalStrengthValue, "integer");
}
};
/**
@ -996,8 +1037,8 @@ public class PandroidAgentListener extends Service {
if (receiveBytes != TrafficStats.UNSUPPORTED && transmitBytes != TrafficStats.UNSUPPORTED)
{
HelperSharedPreferences.putSharedPreferencesLong(getApplicationContext(), "receiveBytes", receiveBytes);
HelperSharedPreferences.putSharedPreferencesLong(getApplicationContext(), "transmitBytes", transmitBytes);
Core.putSharedData("PANDROID_DATA", "receiveBytes", ""+receiveBytes, "long" );
Core.putSharedData("PANDROID_DATA", "transmitBytes", ""+transmitBytes, "long" );
}
}
/**
@ -1009,9 +1050,9 @@ public class PandroidAgentListener extends Service {
boolean roaming = telephone.isNetworkRoaming();
if(roaming)
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "roaming", 1);
Core.putSharedData("PANDROID_DATA", "roaming", "1", "integer" );
else
HelperSharedPreferences.putSharedPreferencesInt(getApplicationContext(), "roaming", 0);
Core.putSharedData("PANDROID_DATA", "roaming", "0", "integer" );
}
@ -1075,8 +1116,8 @@ public class PandroidAgentListener extends Service {
@Override
public void onLocationChanged(Location loc) {
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "latitude", (float)loc.getLatitude());
HelperSharedPreferences.putSharedPreferencesFloat(getApplicationContext(), "longitude", (float)loc.getLongitude());
Core.putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float");
Core.putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float");
}
@Override

View File

@ -36,14 +36,14 @@ import android.util.Log;
int defaultSMSReceived = 0;
int mode = Activity.MODE_PRIVATE;
int sms = HelperSharedPreferences.getSharedPreferencesInt(context, "SMSReceived", defaultSMSReceived);
SharedPreferences pref = PandroidAgent.getSharedPrefs();
int sms = pref.getInt("SMSReceived", defaultSMSReceived);
sms++;
HelperSharedPreferences.putSharedPreferencesInt(context, "SMSReceived", sms);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("SMSReceived", sms);
editor.commit();
}//end if

View File

@ -745,4 +745,4 @@ public class Setup extends Activity {
nMgr.cancel(notifyId);
}
}
}

View File

@ -18,6 +18,7 @@ import java.util.Date;
import android.app.Activity;
import android.content.Intent;
//import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;